source: snovis/trunk/applications/prog_snova2.cxx @ 84

Last change on this file since 84 was 81, checked in by barrand, 17 years ago
  • Property svn:eol-style set to native
File size: 3.8 KB
Line 
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.hh>
10
11#include <SNvertex/base_VG_factory.h>
12#include <SNvertex/CALO_basic_VG.h>
13#include <SNvertex/source_simple_VG.h>
14
15int main( int argc_ , char ** argv_ )
16{
17  int error_code=EXIT_SUCCESS;
18  try {
19
20    std::cout << "Hello, this is a sample program for class 'snova_mgr'!" << 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::snova_mgr 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_visual_mode(visual_mode);         // use X11 display
67    my_snova_mgr.set_G4_macro(G4_macro);               // run G4 macro
68
69    // Use a dedicated vertex generator factory:
70    snemo::base_VG_factory my_VG_factory;
71    my_VG_factory.add("CALO_basic",    snemo::CALO_basic_VG::new_CALO_basic_VG );
72    my_VG_factory.add("source_simple", snemo::source_simple_VG::new_source_simple_VG );
73    // <here you may add more functors in the factory internal map... >
74    //my_VG_factory.add("TC_nblocks", snemo::TC_nblocks_VG::new_TC_nblocks_VG ); // NOT AVAILABLE YET!
75
76    my_VG_factory.init();
77    if( debug ) my_VG_factory.dump(std::cerr);
78    my_snova_mgr.set_VG_factory(my_VG_factory);
79
80    // Use a dedicated event generator factory:
81    /* 2007-01-31, FM: snova V2 beta release
82     *
83     * In a near future (SNevgen package?) I hope we will be able to plug here
84     * any (E)vent (G)enerator factory; such code could look like:
85     *
86     *  snemo::base_EG_factory my_EG_factory;
87     *  my_EG_factory.add("single_particle", snemo::single_particle_EG::new_single_particle_VG );
88     *  my_EG_factory.add("from_genbb_file", snemo::from_genbb_file_EG::new_from_genbb_file_VG );
89     *  my_EG_factory.add("cosmics", snemo::cosmics_EG::cosmics_VG );
90     *  my_EG_factory.init();
91     *  my_snova_mgr.set_EG_factory(my_EG_factory);
92     *
93     * Now only support for a GENBB file reader is available,
94     * and hardcoded in the generator class...
95     *
96     */
97
98    // Build the guts of the simulation process within the snova manager:
99    std::cerr << "prog_snova2: debug: " 
100              << "Build the guts" << std::endl; 
101    my_snova_mgr.init(); // from this point 'set_XXXX' methods failed (manager is locked!)
102
103    // Run the simulation:
104    std::cerr << "prog_snova2: debug: " 
105              << "Run the simulation" << std::endl; 
106    my_snova_mgr.run_sim();
107
108    // Clean the snova manager
109    std::cerr << "prog_snova2: debug: " 
110              << "Clean the snova manager" << std::endl; 
111    my_snova_mgr.reset(); // not mandatory for we do it in the d-tor.
112
113    std::cerr << "prog_snova2: debug: " 
114              << "Done" << std::endl; 
115  }
116  catch(std::exception & x){
117    std::cerr << "prog_snova2: error: " << x.what() << std::endl; 
118    error_code=EXIT_FAILURE;
119  }
120  catch(...){
121    std::cerr << "prog_snova2: error: " << "unexpected error!" << std::endl; 
122    error_code=EXIT_FAILURE;
123  }
124  return error_code;
125}
126
127// end of prog_snova2.cxx
Note: See TracBrowser for help on using the repository browser.