1 | // -*- mode: c++; -*- |
---|
2 | // prog_snova2.cxx |
---|
3 | |
---|
4 | #include <cstdlib> |
---|
5 | #include <iostream> |
---|
6 | #include <string> |
---|
7 | #include <exception> |
---|
8 | |
---|
9 | #include <snova/snova_mgr_ui.h> |
---|
10 | |
---|
11 | #include <SNvertex/base_VG_factory.h> |
---|
12 | #include <SNvertex/CALO_basic_VG.h> |
---|
13 | #include <SNvertex/source_simple_VG.h> |
---|
14 | |
---|
15 | int main( int argc_ , char ** argv_ ) |
---|
16 | { |
---|
17 | int error_code=EXIT_SUCCESS; |
---|
18 | try { |
---|
19 | |
---|
20 | std::cout << "Hello, this is program for class 'snova::mgr_ui'!" << std::endl; |
---|
21 | |
---|
22 | bool debug = false; |
---|
23 | std::string params_filename = snova::constants::DEF_PARAMS_FILENAME; |
---|
24 | std::string G4_macro = ""; |
---|
25 | bool visual_mode = false; |
---|
26 | |
---|
27 | int iarg=1; |
---|
28 | while ( iarg<argc_ ) { |
---|
29 | |
---|
30 | std::string arg=argv_[iarg]; |
---|
31 | |
---|
32 | if ( arg[0] == '-' ) { |
---|
33 | |
---|
34 | if ( arg == "-d" || arg == "--debug" ) debug=true; |
---|
35 | |
---|
36 | if ( arg == "-p" || arg == "--params" ) { |
---|
37 | iarg++; |
---|
38 | if (iarg==argc_) { |
---|
39 | throw std::runtime_error("Missing simulation parameters file!"); |
---|
40 | } |
---|
41 | params_filename=argv_[iarg]; |
---|
42 | } |
---|
43 | |
---|
44 | } |
---|
45 | else { |
---|
46 | G4cerr << "arg=" << arg << G4endl; |
---|
47 | |
---|
48 | if ( arg == "vis" || arg == "visual" ) { |
---|
49 | visual_mode = true; |
---|
50 | } |
---|
51 | else { |
---|
52 | G4_macro=arg; |
---|
53 | } |
---|
54 | |
---|
55 | } |
---|
56 | |
---|
57 | iarg++; |
---|
58 | } |
---|
59 | |
---|
60 | // A snova manager: |
---|
61 | snova::mgr_ui my_snova_mgr; |
---|
62 | |
---|
63 | // Configure some properties of the snova manager: |
---|
64 | my_snova_mgr.set_debug(debug); // debug verbosity |
---|
65 | my_snova_mgr.set_params_filename(params_filename); // the main simulation configuration file |
---|
66 | //my_snova_mgr.set_params_filename("${HOME}/my_snova.par"); |
---|
67 | my_snova_mgr.set_G4_macro(G4_macro); // run G4 macro |
---|
68 | my_snova_mgr.set_visual_mode(visual_mode); // use X11 display |
---|
69 | |
---|
70 | // Use a dedicated vertex generator factory: |
---|
71 | snemo::base_VG_factory my_VG_factory; |
---|
72 | my_VG_factory.add("CALO_basic", snemo::CALO_basic_VG::new_CALO_basic_VG ); |
---|
73 | my_VG_factory.add("source_simple", snemo::source_simple_VG::new_source_simple_VG ); |
---|
74 | // <here you may add more functors in the factory internal map... > |
---|
75 | //my_VG_factory.add("TC_nblocks", snemo::TC_nblocks_VG::new_TC_nblocks_VG ); // NOT AVAILABLE YET! |
---|
76 | |
---|
77 | my_VG_factory.init(); |
---|
78 | if( debug ) my_VG_factory.dump(std::cerr); |
---|
79 | my_snova_mgr.set_VG_factory(my_VG_factory); |
---|
80 | |
---|
81 | // Use a dedicated event generator factory: |
---|
82 | /* 2007-01-31, FM: snova V2 beta release |
---|
83 | * |
---|
84 | * In a near future (SNevgen package?) I hope we will be able to plug here |
---|
85 | * any (E)vent (G)enerator factory; such code could look like: |
---|
86 | * |
---|
87 | * snemo::base_EG_factory my_EG_factory; |
---|
88 | * my_EG_factory.add("single_particle", snemo::single_particle_EG::new_single_particle_VG ); |
---|
89 | * my_EG_factory.add("from_genbb_file", snemo::from_genbb_file_EG::new_from_genbb_file_VG ); |
---|
90 | * my_EG_factory.add("cosmics", snemo::cosmics_EG::cosmics_VG ); |
---|
91 | * my_EG_factory.init(); |
---|
92 | * my_snova_mgr.set_EG_factory(my_EG_factory); |
---|
93 | * |
---|
94 | * Now only support for a GENBB file reader is available, |
---|
95 | * and hardcoded in the generator class... |
---|
96 | * |
---|
97 | */ |
---|
98 | |
---|
99 | // Build the guts of the simulation process within the snova manager: |
---|
100 | std::cerr << "prog_snova2: debug: " |
---|
101 | << "Build the guts" << std::endl; |
---|
102 | my_snova_mgr.init(); // from this point 'set_XXXX' methods failed (manager is locked!) |
---|
103 | |
---|
104 | // Run the simulation: |
---|
105 | std::cerr << "prog_snova2: debug: " |
---|
106 | << "Run the simulation" << std::endl; |
---|
107 | my_snova_mgr.run_sim(); |
---|
108 | |
---|
109 | // Clean the snova manager |
---|
110 | std::cerr << "prog_snova2: debug: " |
---|
111 | << "Clean the snova manager" << std::endl; |
---|
112 | my_snova_mgr.reset(); // not mandatory for we do it in the d-tor. |
---|
113 | |
---|
114 | std::cerr << "prog_snova2: debug: " |
---|
115 | << "Done" << std::endl; |
---|
116 | } |
---|
117 | catch(std::exception & x){ |
---|
118 | std::cerr << "prog_snova2: error: " << x.what() << std::endl; |
---|
119 | error_code=EXIT_FAILURE; |
---|
120 | } |
---|
121 | catch(...){ |
---|
122 | std::cerr << "prog_snova2: error: " << "unexpected error!" << std::endl; |
---|
123 | error_code=EXIT_FAILURE; |
---|
124 | } |
---|
125 | return error_code; |
---|
126 | } |
---|
127 | |
---|
128 | // end of prog_snova2.cxx |
---|