[6] | 1 | /* |
---|
| 2 | * Version of prog_snova.cc to handle a G4Lab::UIOnX session |
---|
| 3 | */ |
---|
| 4 | |
---|
[208] | 5 | // snova : |
---|
[204] | 6 | #include <snova/snova_mgr.h> |
---|
[85] | 7 | #include <SNvertex/base_VG_factory.h> |
---|
| 8 | #include <SNvertex/CALO_basic_VG.h> |
---|
| 9 | #include <SNvertex/source_simple_VG.h> |
---|
[6] | 10 | |
---|
[208] | 11 | // Geant4 : |
---|
[187] | 12 | #include <G4RunManager.hh> |
---|
[85] | 13 | #include <G4UImanager.hh> |
---|
[6] | 14 | |
---|
| 15 | // G4Lab : |
---|
| 16 | #include <G4Lab/UIOnX.h> //UIOnX |
---|
[147] | 17 | |
---|
[208] | 18 | // Lib : |
---|
[147] | 19 | #include <Lib/Out.h> |
---|
| 20 | #include <Lib/sout.h> |
---|
| 21 | #include <Lib/fmanip.h> |
---|
| 22 | #include <Lib/dirmanip.h> |
---|
| 23 | #include <Lib/smanip.h> |
---|
[6] | 24 | |
---|
[208] | 25 | #include "Environment.h" |
---|
[6] | 26 | |
---|
[208] | 27 | //using namespace snova; |
---|
| 28 | |
---|
[85] | 29 | namespace snovis { |
---|
| 30 | class mgr : public snova::snova_mgr { |
---|
| 31 | public: |
---|
| 32 | mgr(){} |
---|
| 33 | virtual ~mgr(){} |
---|
| 34 | public: |
---|
[148] | 35 | void run_sim(int argc , char** argv,const std::string& aTk = "") { |
---|
[85] | 36 | G4UImanager* UI = G4UImanager::GetUIpointer(); |
---|
| 37 | |
---|
| 38 | UI->ApplyCommand("/control/shell cp currentEvent.rndm currentRun.rndm"); |
---|
| 39 | UI->ApplyCommand("/random/setSavingFlag true"); |
---|
| 40 | UI->ApplyCommand("/random/resetEngineFrom currentRun.rndm"); |
---|
| 41 | UI->ApplyCommand("/tracking/storeTrajectory 1"); |
---|
[98] | 42 | //UI->ApplyCommand("/tracking/verbose 1"); |
---|
[85] | 43 | |
---|
| 44 | //G4RunManager* runManager = __runManager; |
---|
| 45 | G4RunManager* runManager = G4RunManager::GetRunManager(); |
---|
| 46 | |
---|
| 47 | std::string gui = "$SNOVISROOT/scripts/OnX/snovis_session.onx"; //UIOnX |
---|
[148] | 48 | G4Lab::UIOnX* session = |
---|
[85] | 49 | new G4Lab::UIOnX(*runManager,gui,argc,argv); //UIOnX |
---|
[148] | 50 | session->createUI(aTk); |
---|
[85] | 51 | session->SessionStart(); |
---|
| 52 | delete session; |
---|
| 53 | } |
---|
| 54 | }; |
---|
| 55 | } |
---|
| 56 | |
---|
[6] | 57 | int main( int argc , char** argv ) |
---|
| 58 | { |
---|
[208] | 59 | if(argc<=0) return EXIT_FAILURE; |
---|
| 60 | if(!check_envs(argv[0])) return EXIT_FAILURE; |
---|
[6] | 61 | |
---|
[147] | 62 | Lib::Printer printer; |
---|
| 63 | Lib::Out out(printer); |
---|
| 64 | |
---|
[6] | 65 | std::string SNOVISROOT; |
---|
| 66 | if(!Lib::System::getenv("SNOVISROOT",SNOVISROOT)) { |
---|
[147] | 67 | out << "snovis_session :" |
---|
| 68 | << " Environment variable SNOVISROOT not defined." |
---|
| 69 | << Lib::endl; |
---|
[208] | 70 | return EXIT_FAILURE; |
---|
[6] | 71 | } |
---|
| 72 | |
---|
[208] | 73 | std::string params; |
---|
| 74 | |
---|
| 75 | // We cd to $HOME/snovis/session : |
---|
[147] | 76 | if(!Lib::dirmanip::goHome()) { |
---|
| 77 | out << "snovis_session : can't go home." << Lib::endl; |
---|
[208] | 78 | return EXIT_FAILURE; |
---|
[147] | 79 | } else if(!Lib::dirmanip::mkcd("snovis")) { |
---|
| 80 | out << "snovis_session : can't mkcd snovis." << Lib::endl; |
---|
[208] | 81 | return EXIT_FAILURE; |
---|
[147] | 82 | } else if(!Lib::dirmanip::mkcd("session")) { |
---|
| 83 | out << "snovis_session : can't mkcd session." << Lib::endl; |
---|
[208] | 84 | return EXIT_FAILURE; |
---|
[147] | 85 | } else { |
---|
[208] | 86 | // If there is a snova.par file found under |
---|
| 87 | // $HOME/snovis/session : |
---|
| 88 | // we take it, else we start with $SNOVISROOT/scripts/snova/snova.par |
---|
| 89 | if(Lib::fmanip::exists("snova.par")) { |
---|
| 90 | params = "snova.par"; |
---|
[147] | 91 | } else { |
---|
[208] | 92 | params = "$SNOVISROOT/scripts/snova/snova.par"; |
---|
[147] | 93 | } |
---|
| 94 | } |
---|
| 95 | |
---|
[148] | 96 | bool is_Mac_app = Lib::main::isMacApp(argv[0]); |
---|
[147] | 97 | |
---|
[85] | 98 | int error_code=EXIT_SUCCESS; |
---|
| 99 | try { |
---|
[208] | 100 | //std::cerr << "snovis_session : startup" << std::endl; |
---|
| 101 | std::cerr << "snovis_session : startup : 000" << std::endl; |
---|
[6] | 102 | |
---|
[85] | 103 | // A snova manager: |
---|
| 104 | snovis::mgr my_snova_mgr; |
---|
[6] | 105 | |
---|
[85] | 106 | // Configure some properties of the snova manager: |
---|
[208] | 107 | my_snova_mgr.set_debug(false); |
---|
| 108 | my_snova_mgr.set_params_filename(params); |
---|
| 109 | //my_snova_mgr.set_G4_macro(G4_macro); |
---|
[6] | 110 | |
---|
[85] | 111 | // Use a dedicated vertex generator factory: |
---|
| 112 | snemo::base_VG_factory my_VG_factory; |
---|
[208] | 113 | my_VG_factory.add("CALO_basic", |
---|
| 114 | snemo::CALO_basic_VG::new_CALO_basic_VG ); |
---|
| 115 | my_VG_factory.add("source_simple", |
---|
| 116 | snemo::source_simple_VG::new_source_simple_VG); |
---|
[85] | 117 | // <here you may add more functors in the factory internal map... > |
---|
[208] | 118 | // NOT AVAILABLE YET! |
---|
| 119 | //my_VG_factory.add("TC_nblocks", |
---|
| 120 | // snemo::TC_nblocks_VG::new_TC_nblocks_VG ); |
---|
[6] | 121 | |
---|
[85] | 122 | my_VG_factory.init(); |
---|
[208] | 123 | //if( debug ) my_VG_factory.dump(std::cerr); |
---|
[85] | 124 | my_snova_mgr.set_VG_factory(my_VG_factory); |
---|
[6] | 125 | |
---|
[85] | 126 | // Build the guts of the simulation process within the snova manager: |
---|
[208] | 127 | //std::cerr << "snovis_session :" |
---|
| 128 | // << " mgr.init..." << std::endl; |
---|
| 129 | my_snova_mgr.init(); |
---|
[6] | 130 | |
---|
[85] | 131 | // Run the simulation: |
---|
[147] | 132 | my_snova_mgr.run_sim(argc,argv,is_Mac_app?"Qt":""); |
---|
[6] | 133 | |
---|
[208] | 134 | //std::cerr << "snovis_session :" |
---|
| 135 | // << " mgr.reset..." << std::endl; |
---|
[85] | 136 | my_snova_mgr.reset(); // not mandatory for we do it in the d-tor. |
---|
[6] | 137 | |
---|
[208] | 138 | //std::cerr << "snovis_session :" |
---|
| 139 | // << " end." << std::endl; |
---|
[85] | 140 | } |
---|
| 141 | catch(std::exception & x){ |
---|
[208] | 142 | std::cerr << "snovis_session : error : " << x.what() << std::endl; |
---|
[85] | 143 | error_code=EXIT_FAILURE; |
---|
| 144 | } |
---|
| 145 | catch(...){ |
---|
[208] | 146 | std::cerr << "snovis_session : error : unexpected error!" << std::endl; |
---|
[85] | 147 | error_code=EXIT_FAILURE; |
---|
| 148 | } |
---|
| 149 | return error_code; |
---|
[6] | 150 | } |
---|