1 | /* |
---|
2 | * Version of prog_snova.cc to handle a G4Lab::UIOnX session |
---|
3 | */ |
---|
4 | |
---|
5 | #include <snova/snova_mgr.hh> |
---|
6 | |
---|
7 | #include <SNvertex/base_VG_factory.h> |
---|
8 | #include <SNvertex/CALO_basic_VG.h> |
---|
9 | #include <SNvertex/source_simple_VG.h> |
---|
10 | |
---|
11 | #include <G4Runmanager.hh> |
---|
12 | #include <G4UImanager.hh> |
---|
13 | |
---|
14 | // G4Lab : |
---|
15 | #include <G4Lab/UIOnX.h> //UIOnX |
---|
16 | |
---|
17 | #include "Environment.h" |
---|
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> |
---|
23 | |
---|
24 | using namespace snova; |
---|
25 | |
---|
26 | namespace snovis { |
---|
27 | class mgr : public snova::snova_mgr { |
---|
28 | public: |
---|
29 | mgr(){} |
---|
30 | virtual ~mgr(){} |
---|
31 | public: |
---|
32 | void run_sim(int argc , char** argv,const std::string& aTk = "") { |
---|
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"); |
---|
39 | //UI->ApplyCommand("/tracking/verbose 1"); |
---|
40 | |
---|
41 | //G4RunManager* runManager = __runManager; |
---|
42 | G4RunManager* runManager = G4RunManager::GetRunManager(); |
---|
43 | |
---|
44 | std::string gui = "$SNOVISROOT/scripts/OnX/snovis_session.onx"; //UIOnX |
---|
45 | G4Lab::UIOnX* session = |
---|
46 | new G4Lab::UIOnX(*runManager,gui,argc,argv); //UIOnX |
---|
47 | session->createUI(aTk); |
---|
48 | session->SessionStart(); |
---|
49 | delete session; |
---|
50 | } |
---|
51 | }; |
---|
52 | } |
---|
53 | |
---|
54 | int main( int argc , char** argv ) |
---|
55 | { |
---|
56 | if(argc<=0) return 1; |
---|
57 | if(!check_envs(argv[0])) return 1; |
---|
58 | |
---|
59 | Lib::Printer printer; |
---|
60 | Lib::Out out(printer); |
---|
61 | |
---|
62 | std::string SNOVISROOT; |
---|
63 | if(!Lib::System::getenv("SNOVISROOT",SNOVISROOT)) { |
---|
64 | out << "snovis_session :" |
---|
65 | << " Environment variable SNOVISROOT not defined." |
---|
66 | << Lib::endl; |
---|
67 | return 1; |
---|
68 | } |
---|
69 | |
---|
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 | |
---|
101 | bool is_Mac_app = Lib::main::isMacApp(argv[0]); |
---|
102 | |
---|
103 | int error_code=EXIT_SUCCESS; |
---|
104 | try { |
---|
105 | |
---|
106 | std::cout << "Hello, this is a sample program for class 'snova_mgr'!" << std::endl; |
---|
107 | |
---|
108 | bool debug = false; |
---|
109 | std::string params_filename = snova::constants::DEF_PARAMS_FILENAME; |
---|
110 | //std::string params_filename = SNOVISROOT+"/scripts/snova.par"; |
---|
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; |
---|
117 | |
---|
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 |
---|
123 | |
---|
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! |
---|
130 | |
---|
131 | my_VG_factory.init(); |
---|
132 | if( debug ) my_VG_factory.dump(std::cerr); |
---|
133 | my_snova_mgr.set_VG_factory(my_VG_factory); |
---|
134 | |
---|
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!) |
---|
139 | |
---|
140 | // Run the simulation: |
---|
141 | std::cerr << "prog_snova2: debug: " |
---|
142 | << "Run the simulation" << std::endl; |
---|
143 | my_snova_mgr.run_sim(argc,argv,is_Mac_app?"Qt":""); |
---|
144 | |
---|
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. |
---|
149 | |
---|
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; |
---|
162 | } |
---|