source: snovis/trunk/applications/snovis_session.cc @ 204

Last change on this file since 204 was 204, checked in by barrand, 17 years ago
File size: 5.2 KB
Line 
1/*
2 * Version of prog_snova.cc to handle a G4Lab::UIOnX session
3 */
4
5#include <snova/snova_mgr.h>
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
24using namespace snova;
25
26namespace 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
54int 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_G4_macro(G4_macro);               // run G4 macro
122
123    // Use a dedicated vertex generator factory:
124    snemo::base_VG_factory my_VG_factory;
125    my_VG_factory.add("CALO_basic",    snemo::CALO_basic_VG::new_CALO_basic_VG );
126    my_VG_factory.add("source_simple", snemo::source_simple_VG::new_source_simple_VG );
127    // <here you may add more functors in the factory internal map... >
128    //my_VG_factory.add("TC_nblocks", snemo::TC_nblocks_VG::new_TC_nblocks_VG ); // NOT AVAILABLE YET!
129
130    my_VG_factory.init();
131    if( debug ) my_VG_factory.dump(std::cerr);
132    my_snova_mgr.set_VG_factory(my_VG_factory);
133
134    // Build the guts of the simulation process within the snova manager:
135    std::cerr << "prog_snova2: debug: " 
136              << "Build the guts" << std::endl; 
137    my_snova_mgr.init(); // from this point 'set_XXXX' methods failed (manager is locked!)
138
139    // Run the simulation:
140    std::cerr << "prog_snova2: debug: " 
141              << "Run the simulation" << std::endl; 
142    my_snova_mgr.run_sim(argc,argv,is_Mac_app?"Qt":"");
143
144    // Clean the snova manager
145    std::cerr << "prog_snova2: debug: " 
146              << "Clean the snova manager" << std::endl; 
147    my_snova_mgr.reset(); // not mandatory for we do it in the d-tor.
148
149    std::cerr << "prog_snova2: debug: " 
150              << "Done" << std::endl; 
151  }
152  catch(std::exception & x){
153    std::cerr << "prog_snova2: error: " << x.what() << std::endl; 
154    error_code=EXIT_FAILURE;
155  }
156  catch(...){
157    std::cerr << "prog_snova2: error: " << "unexpected error!" << std::endl; 
158    error_code=EXIT_FAILURE;
159  }
160  return error_code;
161}
Note: See TracBrowser for help on using the repository browser.