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