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

Question Recommendations on inputting a filename 

Forum: Run Management
Date: 12 Mar, 2011
From: Robert Penny <Robert Penny>


I'm trying to replay a number of "interesting" events by reloading the random number generator from states stored in a file. I'm doing the reload prior to generation of the primary vertex in my PrimaryGeneratorAction class (derived from G4VUserPrimaryGeneratorAction).

I'm trying to be a little better about fitting into the existing class framework, rather than going maverick and patching in my own code. So, playing within the standard framework, I've derived a PrimaryGeneratorMessenger class to accept the input of a filename.

Now I could just accept my filename by instantiating a command such as:

 ReplayModeCmd = new G4UIcmdWithAString("/GC_TAG/gun/replayFile",this);

The problem I'm having is that this doesn't per se allow any validation that the string I've entered actually points to a valid file.

In my messenger class I have the following:

void GC_TAG_PrimaryGeneratorMessenger
  ::SetNewValue(G4UIcommand* command,G4String newValue)
  if( command == ReplayModeCmd )
      ifstream replayFile; newValue );
      if( replayFile.is_open() )
	  G4cout << "Couldn't open replay file " << newValue << G4endl;

That's fine... except it only gives me a textual indication of the error. I'd like to give some feedback to the script execution engine (if, say, I'm running this from a script file) that there's an error and the script should abort. Unfortunately, SetNewValue has return type void, so there's no way to return an error status from here.

In principle I could load the G4UIcmdWithAString with all filenames in the current directory as candidate strings. This seems a little kludgy. For one thing it wouldn't deal with me specifying a path outside the current directory.

I could subclass G4UIcmdWithAString to make my own G4UIcmdWithAFilename. This could override the base class G4UIcommand's DoIt method, which does its own validation of the input within its own limited sanity checks. However, it would be kind of nice to let the messenger have the option of throwing an error without having the hack the Geant code internals.

I would guess a good place to do it would be at the end of G4UIcommand::DoIt

   if(CheckNewValue( correctParameters ))
   { return fParameterOutOfRange+99; }
   messenger->SetNewValue( this, correctParameters );
   return 0;

If instead we could do a

     messenger_status = messenger->SetNewValue( this, correctParameters );
     return messenger_status;

this would add the requisite functionality.

I'd love it if I could just override the DoIt method and put in my own additions. DoIt isn't virtual though, so I'd probably not get the correct override functionality. (I can also just cheat and copy in my own local copy of and modify this. Again, not really playing within the framework.)

Any suggestions for a recommended way of approaching the problem?

Many thanks,


Inline Depth:
 1 1
 All All
Outline Depth:
 1 1
 2 2
 All All
Add message: (add)

1 Idea: Re: Recommendations on inputting a filename   (Robert Penny - 17 Mar, 2011)
 Add Message Add Message
to: "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 ]