45 #ifdef CEXMC_USE_PERSISTENCY 46 #include <boost/algorithm/string.hpp> 47 #include <boost/archive/archive_exception.hpp> 48 #ifdef CEXMC_USE_CUSTOM_FILTER 49 #include <boost/variant/get.hpp> 52 #include <G4UImanager.hh> 53 #include <G4String.hh> 54 #include <G4UIsession.hh> 55 #include <G4UIterminal.hh> 57 #include <G4UItcsh.hh> 62 #include <G4VisExecutive.hh> 63 #include "CexmcRunManager.hh" 64 #include "CexmcHistoManager.hh" 65 #include "CexmcSetup.hh" 66 #include "CexmcPhysicsList.hh" 67 #include "CexmcPhysicsManager.hh" 68 #include "CexmcPrimaryGeneratorAction.hh" 69 #include "CexmcTrackingAction.hh" 70 #include "CexmcSteppingAction.hh" 71 #include "CexmcEventAction.hh" 72 #include "CexmcRunAction.hh" 73 #include "CexmcMessenger.hh" 74 #include "CexmcException.hh" 75 #include "CexmcBasicPhysicsSettings.hh" 76 #include "CexmcCommon.hh" 81 const G4String CexmcVisManagerVerboseLevel(
"errors" );
107 #ifdef CEXMC_PROG_NAME 108 const char * progName( CEXMC_PROG_NAME );
110 const char * progName(
"cexmc" );
113 G4cout <<
"Usage: " << progName <<
" [-i] " 117 "[-p preinit_macro] [-m init_macro] " 118 #ifdef CEXMC_USE_PERSISTENCY 119 "[[-y] -w project]" << G4endl <<
121 #ifdef CEXMC_USE_CUSTOM_FILTER 122 "[-f filter_script] " 127 G4cout <<
"or " << progName <<
" [--help | -h]" << G4endl;
128 G4cout <<
" -i - run in interactive mode" << G4endl;
130 G4cout <<
" -g - start graphical interface (Qt), implies " 131 "interactive mode " << G4endl;
133 G4cout <<
" -p - use specified preinit macro file " << G4endl;
134 G4cout <<
" -m - use specified init macro file " << G4endl;
135 #ifdef CEXMC_USE_PERSISTENCY 136 G4cout <<
" -w - save data in specified project files" << G4endl;
137 G4cout <<
" -r - read data from specified project files" <<
139 #ifdef CEXMC_USE_CUSTOM_FILTER 140 G4cout <<
" -f - use specified custom filter script" << G4endl;
142 G4cout <<
" -o - comma-separated list of data to output, " 143 "possible values:" << G4endl <<
144 " run, geom, events" << G4endl;
145 G4cout <<
" -y - force project override" << G4endl;
147 G4cout <<
" --help | -h - print this message and exit " << G4endl;
156 for ( G4int i( 1 ); i < argc; ++i )
160 if (
G4String( argv[ i ] ) ==
"--help" )
164 if (
G4String( argv[ i ] ) ==
"-h" )
168 if (
G4String( argv[ i ], 2 ) ==
"-i" )
174 if (
G4String( argv[ i ], 2 ) ==
"-g" )
181 if (
G4String( argv[ i ], 2 ) ==
"-p" )
187 throw CexmcException( CexmcCmdLineParseException );
192 if (
G4String( argv[ i ], 2 ) ==
"-m" )
198 throw CexmcException( CexmcCmdLineParseException );
203 #ifdef CEXMC_USE_PERSISTENCY 204 if (
G4String( argv[ i ], 2 ) ==
"-w" )
206 cmdLineData.
wProject = argv[ i ] + 2;
210 throw CexmcException( CexmcCmdLineParseException );
215 if (
G4String( argv[ i ], 2 ) ==
"-r" )
217 cmdLineData.
rProject = argv[ i ] + 2;
221 throw CexmcException( CexmcCmdLineParseException );
226 if (
G4String( argv[ i ], 2 ) ==
"-y" )
231 if (
G4String( argv[ i ], 2 ) ==
"-o" )
234 if ( outputData ==
"" )
237 throw CexmcException( CexmcCmdLineParseException );
238 outputData = argv[ i ];
240 std::set< std::string > tokens;
241 boost::split( tokens, outputData, boost::is_any_of(
"," ) );
243 k != tokens.end(); ++k )
249 cmdLineData.
outputData.insert( CexmcOutputRun );
255 CexmcOutputGeometry );
258 if ( *k ==
"events" )
260 cmdLineData.
outputData.insert( CexmcOutputEvents );
263 throw CexmcException( CexmcCmdLineParseException );
268 #ifdef CEXMC_USE_CUSTOM_FILTER 269 if (
G4String( argv[ i ], 2 ) ==
"-f" )
275 throw CexmcException( CexmcCmdLineParseException );
283 throw CexmcException( CexmcCmdLineParseException );
292 int main(
int argc,
char ** argv )
299 #ifdef CEXMC_USE_PERSISTENCY 300 G4bool outputDataOnly(
false );
305 if ( !
parseArgs( argc, argv, cmdLineData ) )
310 #ifdef CEXMC_USE_PERSISTENCY 313 throw CexmcException( CexmcCmdLineParseException );
315 throw CexmcException( CexmcCmdLineParseException );
316 #ifdef CEXMC_USE_CUSTOM_FILTER 318 throw CexmcException( CexmcCmdLineParseException );
321 throw CexmcException( CexmcCmdLineParseException );
322 outputDataOnly = ! cmdLineData.
outputData.empty();
325 catch ( CexmcException &
e )
327 G4cout << e.what() << G4endl;
332 G4cout <<
"Unknown exception caught when parsing args" << G4endl;
336 CexmcRunManager * runManager( NULL );
337 CexmcMessenger::Instance();
339 G4VisManager * visManager( NULL );
341 #ifdef CEXMC_USE_ROOT 342 CexmcHistoManager::Instance();
347 runManager =
new CexmcRunManager( cmdLineData.
wProject,
350 #ifdef CEXMC_USE_PERSISTENCY 351 #ifdef CEXMC_USE_CUSTOM_FILTER 352 runManager->SetCustomFilter( cmdLineData.
customFilter );
355 if ( outputDataOnly )
360 cmdLineData.
outputData.find( CexmcOutputEvents ) );
362 runManager->SetUserInitialization(
363 CexmcChargeExchangePMFactory::
364 Create( CexmcPionZeroProduction ) );
365 runManager->PrintReadData( cmdLineData.
outputData );
371 G4UImanager * uiManager( G4UImanager::GetUIpointer() );
374 uiManager->ApplyCommand(
"/control/execute " +
377 CexmcProductionModelType productionModelType(
378 runManager->GetProductionModelType() );
380 if ( productionModelType == CexmcUnknownProductionModel )
381 throw CexmcException( CexmcPreinitException );
383 G4VUserPhysicsList * physicsList( CexmcChargeExchangePMFactory::
384 Create( productionModelType ) );
385 CexmcPhysicsManager * physicsManager(
386 dynamic_cast< CexmcPhysicsManager * >( physicsList ) );
387 CexmcProductionModel * productionModel(
388 physicsManager->GetProductionModel() );
390 if ( ! productionModel )
391 throw CexmcException( CexmcWeirdException );
393 G4cout << CEXMC_LINE_START <<
"Production model '" <<
394 productionModel->GetName() <<
"' instantiated" << G4endl;
396 runManager->SetUserInitialization( physicsList );
398 CexmcSetup * setup(
new CexmcSetup( runManager->GetGdmlFileName(),
399 runManager->ShouldGdmlFileBeValidated() ) );
401 runManager->SetUserInitialization( setup );
403 runManager->Initialize();
405 runManager->SetPhysicsManager( physicsManager );
407 runManager->SetUserAction(
new CexmcPrimaryGeneratorAction(
410 runManager->SetUserAction(
new CexmcEventAction( physicsManager ) );
412 runManager->SetUserAction(
new CexmcRunAction( physicsManager ) );
414 runManager->SetUserAction(
new CexmcTrackingAction( physicsManager ) );
416 runManager->SetUserAction(
new CexmcSteppingAction( physicsManager ) );
418 #ifdef CEXMC_USE_ROOT 419 CexmcHistoManager::Instance()->Initialize();
425 visManager =
new G4VisExecutive( CexmcVisManagerVerboseLevel );
426 visManager->Initialize();
430 #ifdef CEXMC_USE_PERSISTENCY 431 if ( runManager->ProjectIsRead() )
433 runManager->ReadProject();
434 runManager->PrintReadRunData();
439 uiManager->ApplyCommand(
"/control/execute " +
443 productionModel->PrintInitialData();
452 session =
new G4UIQt( 1, argv );
453 const G4String & guiMacroName( runManager->GetGuiMacroName() );
454 if ( guiMacroName !=
"" )
455 uiManager->ApplyCommand(
"/control/execute " +
457 #ifdef CEXMC_USE_ROOTQT 458 CexmcHistoManager::Instance()->EnableLiveHistograms( session );
465 session =
new G4UIterminal(
new G4UItcsh );
467 session =
new G4UIterminal;
471 session->SessionStart();
474 #ifdef CEXMC_USE_PERSISTENCY 475 if ( runManager->ProjectIsSaved() )
476 runManager->SaveProject();
479 catch ( CexmcException & e )
481 G4cout << e.what() << G4endl;
483 #ifdef CEXMC_USE_PERSISTENCY 484 catch ( boost::archive::archive_exception & e )
486 G4cout << CEXMC_LINE_START <<
"Serialization error: " << e.what() <<
489 #ifdef CEXMC_USE_CUSTOM_FILTER 490 catch ( boost::bad_get & e )
492 G4cout << CEXMC_LINE_START <<
"Custom filter error: " << e.what() <<
499 G4cout <<
"Unknown exception caught" << G4endl;
502 #ifdef CEXMC_USE_ROOT 503 CexmcHistoManager::Destroy();
508 CexmcMessenger::Destroy();
int main(int argc, char **argv)
static G4UIterminal * session
G4bool overrideExistingProject
CexmcOutputDataTypeSet outputData
G4bool parseArgs(int argc, char **argv, CexmcCmdLineData &cmdLineData)