Message: Re: Recommendations on inputting a filename Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

Idea Re: Recommendations on inputting a filename 

Forum: Run Management
Re: Question Recommendations on inputting a filename (Robert Penny)
Date: 17 Mar, 2011
From: Robert Penny <Robert Penny>

I hope it's not poor etiquette to be responding to my own message.

I mentioned one possible course of action was to take a local copy of and modify it.  I've done so, and this works like a charm.  

I know this is not a long term solution, but maybe I could request some
functionality like this get folded into future releases.  (Unless, of course,
there is some recommended way to do what I want which I'm not aware of.)

In my PrimaryGeneratorMessenger class I have the option of either calling the
standard void SetNewValue method, or of calling SetNewValueWithReturnStatus.
If the filename I input is not found, I flag the return status with 


void GC_TAG_PrimaryGeneratorMessenger::SetNewValue(G4UIcommand* command,G4String newValue)
  SetNewValueWithReturnStatus( command, newValue );

G4int GC_TAG_PrimaryGeneratorMessenger
    ::SetNewValueWithReturnStatus(G4UIcommand* command,G4String newValue)
    << __FILE__ << ':' << __LINE__
    << " Overloaded method called."
    << G4endl;

  G4int return_status = 0;
  if( command == ReplayModeCmd )
      ifstream* replayFile = new ifstream;
      replayFile->open( newValue );
      if( replayFile->is_open() )
	  G4cout << "Couldn't open replay file " << newValue << G4endl;
	  if( replayFile )
	    delete replayFile;

	  return_status = fParameterOutOfRange;
  return return_status;

I have taken a local copy of into my source tree and added the
following code to the end of the DoIt method.

G4int G4UIcommand::DoIt(G4String parameterList)

  if(CheckNewValue( correctParameters ))
  { return fParameterOutOfRange+99; }

  /*********** Modified code follows ***********/

  GC_TAG_PrimaryGeneratorMessenger *messenger_extended 
    = dynamic_cast<GC_TAG_PrimaryGeneratorMessenger*>( messenger );

  G4int return_status = 0;
  if( messenger_extended )
      return_status = messenger_extended
		    ->SetNewValueWithReturnStatus( this, correctParameters );
      messenger->SetNewValue( this, correctParameters );
  return return_status;

So... if the messenger class can be subclassed into my method which returns a
return status, it calls it.  Otherwise, it calls the standard method.

If the file I specify does not exist, the error status return causes an
executing script to abort, which is the functionality I wanted.

 Add Message Add Message
to: "Re: Recommendations on inputting a filename"

 Subscribe Subscribe

This site runs SLAC HyperNews version 1.11-slac-98, derived from the original HyperNews

[ Geant 4 Home | Geant 4 HyperNews | Search | Request New Forum | Feedback ]