[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 | |
---|
[85] | 11 | #include <G4Runmanager.hh> |
---|
| 12 | #include <G4UImanager.hh> |
---|
[6] | 13 | |
---|
| 14 | // G4Lab : |
---|
| 15 | #include <G4Lab/UIOnX.h> //UIOnX |
---|
| 16 | #include "Environment.h" |
---|
| 17 | |
---|
| 18 | using namespace snova; |
---|
| 19 | |
---|
[85] | 20 | namespace snovis { |
---|
| 21 | class mgr : public snova::snova_mgr { |
---|
| 22 | public: |
---|
| 23 | mgr(){} |
---|
| 24 | virtual ~mgr(){} |
---|
| 25 | public: |
---|
| 26 | void run_sim(int argc , char** argv) { |
---|
| 27 | G4UImanager* UI = G4UImanager::GetUIpointer(); |
---|
| 28 | |
---|
| 29 | UI->ApplyCommand("/control/shell cp currentEvent.rndm currentRun.rndm"); |
---|
| 30 | UI->ApplyCommand("/random/setSavingFlag true"); |
---|
| 31 | UI->ApplyCommand("/random/resetEngineFrom currentRun.rndm"); |
---|
| 32 | UI->ApplyCommand("/tracking/storeTrajectory 1"); |
---|
| 33 | UI->ApplyCommand("/tracking/verbose 1"); |
---|
| 34 | |
---|
| 35 | //G4RunManager* runManager = __runManager; |
---|
| 36 | G4RunManager* runManager = G4RunManager::GetRunManager(); |
---|
| 37 | |
---|
| 38 | std::string gui = "$SNOVISROOT/scripts/OnX/snovis_session.onx"; //UIOnX |
---|
| 39 | G4UIsession* session = |
---|
| 40 | new G4Lab::UIOnX(*runManager,gui,argc,argv); //UIOnX |
---|
| 41 | session->SessionStart(); |
---|
| 42 | delete session; |
---|
| 43 | } |
---|
| 44 | }; |
---|
| 45 | } |
---|
| 46 | |
---|
[6] | 47 | int main( int argc , char** argv ) |
---|
| 48 | { |
---|
| 49 | if(argc<=0) return 1; |
---|
| 50 | if(!check_envs(argv[0])) return 1; |
---|
| 51 | |
---|
| 52 | //std::string params_filename = snova::constants::DEF_PARAMS_FILENAME; |
---|
| 53 | std::string SNOVISROOT; |
---|
| 54 | if(!Lib::System::getenv("SNOVISROOT",SNOVISROOT)) { |
---|
| 55 | G4cout << "snovis_session :" |
---|
| 56 | << " Environment variable SNOVISROOT not defined." |
---|
| 57 | << G4endl; |
---|
| 58 | return 1; |
---|
| 59 | } |
---|
| 60 | |
---|
[85] | 61 | int error_code=EXIT_SUCCESS; |
---|
| 62 | try { |
---|
[6] | 63 | |
---|
[85] | 64 | std::cout << "Hello, this is a sample program for class 'snova_mgr'!" << std::endl; |
---|
[6] | 65 | |
---|
[85] | 66 | bool debug = false; |
---|
| 67 | //std::string params_filename = snova::constants::DEF_PARAMS_FILENAME; |
---|
| 68 | std::string params_filename = SNOVISROOT+"/scripts/snova.par"; |
---|
| 69 | //G4String geom_filename = SNOVISROOT+"/scripts/snemo.geom"; |
---|
| 70 | std::string G4_macro = ""; |
---|
| 71 | bool visual_mode = false; |
---|
| 72 | |
---|
| 73 | // A snova manager: |
---|
| 74 | snovis::mgr my_snova_mgr; |
---|
[6] | 75 | |
---|
[85] | 76 | // Configure some properties of the snova manager: |
---|
| 77 | my_snova_mgr.set_debug(debug); // debug verbosity |
---|
| 78 | my_snova_mgr.set_params_filename(params_filename); // the main simulation configuration file |
---|
| 79 | my_snova_mgr.set_visual_mode(visual_mode); // use X11 display |
---|
| 80 | my_snova_mgr.set_G4_macro(G4_macro); // run G4 macro |
---|
[6] | 81 | |
---|
[85] | 82 | // Use a dedicated vertex generator factory: |
---|
| 83 | snemo::base_VG_factory my_VG_factory; |
---|
| 84 | my_VG_factory.add("CALO_basic", snemo::CALO_basic_VG::new_CALO_basic_VG ); |
---|
| 85 | my_VG_factory.add("source_simple", snemo::source_simple_VG::new_source_simple_VG ); |
---|
| 86 | // <here you may add more functors in the factory internal map... > |
---|
| 87 | //my_VG_factory.add("TC_nblocks", snemo::TC_nblocks_VG::new_TC_nblocks_VG ); // NOT AVAILABLE YET! |
---|
[6] | 88 | |
---|
[85] | 89 | my_VG_factory.init(); |
---|
| 90 | if( debug ) my_VG_factory.dump(std::cerr); |
---|
| 91 | my_snova_mgr.set_VG_factory(my_VG_factory); |
---|
[6] | 92 | |
---|
[85] | 93 | // Build the guts of the simulation process within the snova manager: |
---|
| 94 | std::cerr << "prog_snova2: debug: " |
---|
| 95 | << "Build the guts" << std::endl; |
---|
| 96 | my_snova_mgr.init(); // from this point 'set_XXXX' methods failed (manager is locked!) |
---|
[6] | 97 | |
---|
[85] | 98 | // Run the simulation: |
---|
| 99 | std::cerr << "prog_snova2: debug: " |
---|
| 100 | << "Run the simulation" << std::endl; |
---|
| 101 | my_snova_mgr.run_sim(argc,argv); |
---|
[6] | 102 | |
---|
[85] | 103 | // Clean the snova manager |
---|
| 104 | std::cerr << "prog_snova2: debug: " |
---|
| 105 | << "Clean the snova manager" << std::endl; |
---|
| 106 | my_snova_mgr.reset(); // not mandatory for we do it in the d-tor. |
---|
[6] | 107 | |
---|
[85] | 108 | std::cerr << "prog_snova2: debug: " |
---|
| 109 | << "Done" << std::endl; |
---|
| 110 | } |
---|
| 111 | catch(std::exception & x){ |
---|
| 112 | std::cerr << "prog_snova2: error: " << x.what() << std::endl; |
---|
| 113 | error_code=EXIT_FAILURE; |
---|
| 114 | } |
---|
| 115 | catch(...){ |
---|
| 116 | std::cerr << "prog_snova2: error: " << "unexpected error!" << std::endl; |
---|
| 117 | error_code=EXIT_FAILURE; |
---|
| 118 | } |
---|
| 119 | return error_code; |
---|
[6] | 120 | } |
---|