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> 55 #include <G4UIsession.hh> 56 #include <G4UIterminal.hh> 58 #include <G4UItcsh.hh> 65 #include <G4VisExecutive.hh> 67 #include "CexmcRunManager.hh" 68 #include "CexmcHistoManager.hh" 69 #include "CexmcSetup.hh" 70 #include "CexmcPhysicsList.hh" 71 #include "CexmcPhysicsManager.hh" 72 #include "CexmcPrimaryGeneratorAction.hh" 73 #include "CexmcTrackingAction.hh" 74 #include "CexmcSteppingAction.hh" 75 #include "CexmcEventAction.hh" 76 #include "CexmcRunAction.hh" 77 #include "CexmcMessenger.hh" 78 #include "CexmcException.hh" 79 #include "CexmcBasicPhysicsSettings.hh" 80 #include "CexmcCommon.hh" 85 const G4String CexmcVisManagerVerboseLevel(
"errors" );
111 #ifdef CEXMC_PROG_NAME 112 const char * progName( CEXMC_PROG_NAME );
114 const char * progName(
"cexmc" );
117 G4cout <<
"Usage: " << progName <<
" [-i] " 121 "[-p preinit_macro] [-m init_macro] " 122 #ifdef CEXMC_USE_PERSISTENCY 123 "[[-y] -w project]" << G4endl <<
125 #ifdef CEXMC_USE_CUSTOM_FILTER 126 "[-f filter_script] " 131 G4cout <<
"or " << progName <<
" [--help | -h]" << G4endl;
132 G4cout <<
" -i - run in interactive mode" << G4endl;
134 G4cout <<
" -g - start graphical interface (Qt), implies " 135 "interactive mode " << G4endl;
137 G4cout <<
" -p - use specified preinit macro file " << G4endl;
138 G4cout <<
" -m - use specified init macro file " << G4endl;
139 #ifdef CEXMC_USE_PERSISTENCY 140 G4cout <<
" -w - save data in specified project files" << G4endl;
141 G4cout <<
" -r - read data from specified project files" <<
143 #ifdef CEXMC_USE_CUSTOM_FILTER 144 G4cout <<
" -f - use specified custom filter script" << G4endl;
146 G4cout <<
" -o - comma-separated list of data to output, " 147 "possible values:" << G4endl <<
148 " run, geom, events" << G4endl;
149 G4cout <<
" -y - force project override" << G4endl;
151 G4cout <<
" --help | -h - print this message and exit " << G4endl;
160 for ( G4int i( 1 ); i < argc; ++i )
164 if (
G4String( argv[ i ] ) ==
"--help" )
168 if (
G4String( argv[ i ] ) ==
"-h" )
172 if (
G4String( argv[ i ], 2 ) ==
"-i" )
178 if (
G4String( argv[ i ], 2 ) ==
"-g" )
185 if (
G4String( argv[ i ], 2 ) ==
"-p" )
191 throw CexmcException( CexmcCmdLineParseException );
196 if (
G4String( argv[ i ], 2 ) ==
"-m" )
202 throw CexmcException( CexmcCmdLineParseException );
207 #ifdef CEXMC_USE_PERSISTENCY 208 if (
G4String( argv[ i ], 2 ) ==
"-w" )
210 cmdLineData.
wProject = argv[ i ] + 2;
214 throw CexmcException( CexmcCmdLineParseException );
219 if (
G4String( argv[ i ], 2 ) ==
"-r" )
221 cmdLineData.
rProject = argv[ i ] + 2;
225 throw CexmcException( CexmcCmdLineParseException );
230 if (
G4String( argv[ i ], 2 ) ==
"-y" )
235 if (
G4String( argv[ i ], 2 ) ==
"-o" )
238 if ( outputData ==
"" )
241 throw CexmcException( CexmcCmdLineParseException );
242 outputData = argv[ i ];
244 std::set< std::string > tokens;
245 boost::split( tokens, outputData, boost::is_any_of(
"," ) );
247 k != tokens.end(); ++k )
253 cmdLineData.
outputData.insert( CexmcOutputRun );
259 CexmcOutputGeometry );
262 if ( *k ==
"events" )
264 cmdLineData.
outputData.insert( CexmcOutputEvents );
267 throw CexmcException( CexmcCmdLineParseException );
272 #ifdef CEXMC_USE_CUSTOM_FILTER 273 if (
G4String( argv[ i ], 2 ) ==
"-f" )
279 throw CexmcException( CexmcCmdLineParseException );
287 throw CexmcException( CexmcCmdLineParseException );
296 int main(
int argc,
char ** argv )
303 #ifdef CEXMC_USE_PERSISTENCY 304 G4bool outputDataOnly(
false );
309 if ( !
parseArgs( argc, argv, cmdLineData ) )
314 #ifdef CEXMC_USE_PERSISTENCY 317 throw CexmcException( CexmcCmdLineParseException );
319 throw CexmcException( CexmcCmdLineParseException );
320 #ifdef CEXMC_USE_CUSTOM_FILTER 322 throw CexmcException( CexmcCmdLineParseException );
325 throw CexmcException( CexmcCmdLineParseException );
326 outputDataOnly = ! cmdLineData.
outputData.empty();
329 catch ( CexmcException &
e )
331 G4cout << e.what() << G4endl;
336 G4cout <<
"Unknown exception caught when parsing args" << G4endl;
340 CexmcRunManager * runManager( NULL );
341 CexmcMessenger::Instance();
343 G4VisManager * visManager( NULL );
345 #ifdef CEXMC_USE_ROOT 346 CexmcHistoManager::Instance();
351 runManager =
new CexmcRunManager( cmdLineData.
wProject,
354 #ifdef CEXMC_USE_PERSISTENCY 355 #ifdef CEXMC_USE_CUSTOM_FILTER 356 runManager->SetCustomFilter( cmdLineData.
customFilter );
359 if ( outputDataOnly )
364 cmdLineData.
outputData.find( CexmcOutputEvents ) );
366 runManager->SetUserInitialization(
367 CexmcChargeExchangePMFactory::
368 Create( CexmcPionZeroProduction ) );
369 runManager->PrintReadData( cmdLineData.
outputData );
375 G4UImanager * uiManager( G4UImanager::GetUIpointer() );
378 uiManager->ApplyCommand(
"/control/execute " +
381 CexmcProductionModelType productionModelType(
382 runManager->GetProductionModelType() );
384 if ( productionModelType == CexmcUnknownProductionModel )
385 throw CexmcException( CexmcPreinitException );
387 G4VUserPhysicsList * physicsList( CexmcChargeExchangePMFactory::
388 Create( productionModelType ) );
389 CexmcPhysicsManager * physicsManager(
390 dynamic_cast< CexmcPhysicsManager * >( physicsList ) );
391 CexmcProductionModel * productionModel(
392 physicsManager->GetProductionModel() );
394 if ( ! productionModel )
395 throw CexmcException( CexmcWeirdException );
397 G4cout << CEXMC_LINE_START <<
"Production model '" <<
398 productionModel->GetName() <<
"' instantiated" << G4endl;
400 runManager->SetUserInitialization( physicsList );
402 CexmcSetup * setup(
new CexmcSetup( runManager->GetGdmlFileName(),
403 runManager->ShouldGdmlFileBeValidated() ) );
405 runManager->SetUserInitialization( setup );
407 runManager->Initialize();
409 runManager->SetPhysicsManager( physicsManager );
411 runManager->SetUserAction(
new CexmcPrimaryGeneratorAction(
414 runManager->SetUserAction(
new CexmcEventAction( physicsManager ) );
416 runManager->SetUserAction(
new CexmcRunAction( physicsManager ) );
418 runManager->SetUserAction(
new CexmcTrackingAction( physicsManager ) );
420 runManager->SetUserAction(
new CexmcSteppingAction( physicsManager ) );
422 #ifdef CEXMC_USE_ROOT 423 CexmcHistoManager::Instance()->Initialize();
429 visManager =
new G4VisExecutive( CexmcVisManagerVerboseLevel );
430 visManager->Initialize();
434 #ifdef CEXMC_USE_PERSISTENCY 435 if ( runManager->ProjectIsRead() )
437 runManager->ReadProject();
438 runManager->PrintReadRunData();
443 uiManager->ApplyCommand(
"/control/execute " +
447 productionModel->PrintInitialData();
456 session =
new G4UIQt( 1, argv );
457 const G4String & guiMacroName( runManager->GetGuiMacroName() );
458 if ( guiMacroName !=
"" )
459 uiManager->ApplyCommand(
"/control/execute " +
461 #ifdef CEXMC_USE_ROOTQT 462 CexmcHistoManager::Instance()->EnableLiveHistograms( session );
469 session =
new G4UIterminal(
new G4UItcsh );
471 session =
new G4UIterminal;
475 session->SessionStart();
479 #ifdef CEXMC_USE_PERSISTENCY 480 if ( runManager->ProjectIsSaved() )
481 runManager->SaveProject();
484 catch ( CexmcException & e )
486 G4cout << e.what() << G4endl;
488 #ifdef CEXMC_USE_PERSISTENCY 489 catch ( boost::archive::archive_exception & e )
491 G4cout << CEXMC_LINE_START <<
"Serialization error: " << e.what() <<
494 #ifdef CEXMC_USE_CUSTOM_FILTER 495 catch ( boost::bad_get & e )
497 G4cout << CEXMC_LINE_START <<
"Custom filter error: " << e.what() <<
504 G4cout <<
"Unknown exception caught" << G4endl;
507 #ifdef CEXMC_USE_ROOT 508 CexmcHistoManager::Destroy();
513 CexmcMessenger::Destroy();
int main(int argc, char **argv)
static G4UIterminal * session
G4bool overrideExistingProject
CexmcOutputDataTypeSet outputData
G4bool parseArgs(int argc, char **argv, CexmcCmdLineData &cmdLineData)