LcioMessenger.cc

Go to the documentation of this file.
00001 // $Header: /cvs/lcd/slic/src/LcioMessenger.cc,v 1.35 2007/09/12 19:40:49 jeremy Exp $
00002 #include "LcioMessenger.hh"
00003 
00004 // slic
00005 #include "LcioManager.hh"
00006 #include "LcioMcpManager.hh"
00007 #include "LcioFileNamer.hh"
00008 #include "TrajectoryManager.hh"
00009 
00010 // lcdd
00011 #include "StringUtil.hh"
00012 
00013 // geant4
00014 #include "G4UIcommand.hh"
00015 #include "G4UIcmdWithAnInteger.hh"
00016 #include "G4UIcmdWithABool.hh"
00017 #include "G4UIdirectory.hh"
00018 #include "G4UImanager.hh"
00019 
00020 // std
00021 #include <sstream>
00022 
00023 namespace slic
00024 {
00025 
00026   LcioMessenger::LcioMessenger(LcioManager* mgr)
00027     : m_mgr(mgr)
00028   {
00029     defineCommands();
00030   }
00031 
00032   LcioMessenger::~LcioMessenger()
00033   {
00034     delete m_lcioDir;
00035     delete m_pathCmd;
00036     delete m_filenameCmd;
00037   }
00038 
00039   void LcioMessenger::SetNewValue(G4UIcommand* cmd, G4String newVals)
00040   {
00041     std::istringstream is ( ( const char* ) newVals );
00042 
00043     std::string s;
00044     is >> s;
00045 
00046     // set output path
00047     if ( cmd == m_pathCmd ) {
00048       m_mgr->setPath( s );
00049     }
00050     // set filename
00051     else if ( cmd == m_filenameCmd ) {
00052       m_mgr->setFilename( s );
00053     }
00054     // fileExistsAction
00055     else if ( cmd == m_fileExistsActionCmd ) {
00056       m_mgr->setFileExistsAction( LcioManager::getFileExistsActionFromString( s ) );
00057     }
00058     // setRunNumber
00059     else if ( cmd == m_setRunNumberCmd ) {
00060       m_mgr->setRunNumber( StringUtil::toInt( s ) );
00061     }
00062     // autoname
00063     else if ( cmd == m_autonameCmd ) {
00064       std::vector<std::string> fields;
00065       StringUtil::split(newVals, " ", fields);
00066       m_mgr->setAutonameFields(fields);
00067     }
00068     /* dump event */
00069     else if ( cmd == m_dumpEventCmd ) {
00070       m_mgr->enableDumpEvent( m_dumpEventCmd->GetNewBoolValue( newVals.c_str() ) );
00071     }
00072     // flags
00073     else if ( cmd == m_setLongFlagCmd || cmd == m_setPDGFlagCmd ) {
00074 
00075       // no args then true
00076       bool flag_set = true;
00077 
00078       // get arg val if exists
00079       if ( s != std::string("") ) {
00080         flag_set = StringUtil::toBool( s );
00081       }
00082 
00083       LcioHitsCollectionBuilder* hcb = m_mgr->getHCBuilder();
00084 
00085       if ( hcb ) {
00086 
00087         // CHBIT_LONG for positions in hits
00088         if ( cmd == m_setLongFlagCmd ) {
00089           hcb->setLongFlag( flag_set );
00090         }
00091         // CHBIT_PDG for every PDG contribution in hits
00092         else if ( cmd == m_setPDGFlagCmd ) {
00093           hcb->setPDGFlag( flag_set );
00094         }
00095       }
00096       else {
00097         G4Exception( "FATAL ERROR: LcioHitsCollectionBuilder is null!" );
00098       }
00099     }
00100     // bad command; shouldn't happen
00101     else {
00102       G4Exception( "LcioMessenger::setNewValue() - Unknown command." );
00103     }
00104     return;
00105   }
00106 
00107   void LcioMessenger::defineCommands()
00108   {
00109     G4UIparameter* p;
00110 
00111     // Lcio dir
00112     m_lcioDir = new G4UIdirectory( "/lcio/" );
00113     m_lcioDir->SetGuidance( "LCIO output commands. [SLIC]" );
00114 
00115     // path
00116     m_pathCmd = new G4UIcommand( "/lcio/path", this );
00117     m_pathCmd->SetGuidance( "Set Lcio output path." );
00118     p = new G4UIparameter( "path", 's', false );
00119     m_pathCmd->SetParameter( p );
00120 
00121     // filename
00122     m_filenameCmd = new G4UIcommand( "/lcio/filename", this );
00123     m_filenameCmd->SetGuidance( "Set Lcio output filename." );
00124     p = new G4UIparameter ( "filename", 's', false );
00125     m_filenameCmd->SetParameter( p );
00126 
00127     // CHBIT_LONG
00128     m_setLongFlagCmd = new G4UIcommand( "/lcio/longFlag", this );
00129     m_setLongFlagCmd->SetGuidance( "Set CHBIT_LONG flag for hit positions in output (default = on)." );
00130     p = new G4UIparameter( "Value", 'b', true );
00131     m_setLongFlagCmd->SetParameter( p );
00132     m_setLongFlagCmd->AvailableForStates( G4State_PreInit );
00133 
00134     // CHBIT_PDG
00135     m_setPDGFlagCmd = new G4UIcommand( "/lcio/PDGFlag", this );
00136     m_setPDGFlagCmd->SetGuidance( "Set CHBIT_PDG flag for super-long output with all Mcp contribs (default is aggregated)." );
00137     p = new G4UIparameter( "Value", 'b', true );
00138     m_setPDGFlagCmd->SetParameter( p );
00139     m_setLongFlagCmd->AvailableForStates( G4State_PreInit );
00140 
00141     // fileExistsAction
00142     m_fileExistsActionCmd = new G4UIcommand( "/lcio/fileExists", this );
00143     m_fileExistsActionCmd->SetGuidance( "Set action when an Lcio output file exists: fail, overwrite/delete or append." );
00144     p = new G4UIparameter( "mode", 's', false );
00145     m_fileExistsActionCmd->SetParameter( p );
00146 
00147     // set the starting run number
00148     m_setRunNumberCmd = new G4UIcmdWithAnInteger( "/lcio/runNumber", this );
00149     m_setRunNumberCmd->SetGuidance( "Set starting run number for LCIO event." );
00150     m_setRunNumberCmd->SetParameterName( "RunNumber", false );
00151 
00152     // enable autonaming
00153     m_autonameCmd = new G4UIcommand( "/lcio/autoname", this );
00154     m_autonameCmd->SetGuidance( "Set autonaming parameters." );
00155     m_autonameCmd->SetGuidance("Valid autoname fields: application geometry event eventNumber run binary physics date geant4");
00156     p = new G4UIparameter("autoname", 's', true );
00157     m_autonameCmd->SetParameter(p);
00158 
00159     /* dumping of event data */
00160     m_dumpEventCmd = new G4UIcmdWithABool( "/lcio/dumpEvent", this );
00161     m_dumpEventCmd->SetGuidance( "Dump information about collections in the event" );
00162     m_dumpEventCmd->SetParameterName("enable", true);
00163     m_dumpEventCmd->SetDefaultValue(true);
00164   }
00165 }

Generated on Thu Nov 15 15:24:16 2007 for Simulator for the Linear Collider by  doxygen 1.5.4