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