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