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

Last change on this file since 208 was 208, checked in by barrand, 17 years ago
File size: 4.4 KB
Line 
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//using namespace snova;
28
29namespace snovis {
30  class mgr : public snova::snova_mgr {
31  public:
32    mgr(){}
33    virtual ~mgr(){}
34  public:
35    void run_sim(int argc , char** argv,const std::string& aTk = "") {
36      G4UImanager* UI = G4UImanager::GetUIpointer(); 
37
38      UI->ApplyCommand("/control/shell cp currentEvent.rndm currentRun.rndm");
39      UI->ApplyCommand("/random/setSavingFlag true");
40      UI->ApplyCommand("/random/resetEngineFrom currentRun.rndm");
41      UI->ApplyCommand("/tracking/storeTrajectory 1");
42      //UI->ApplyCommand("/tracking/verbose 1");
43 
44      //G4RunManager* runManager = __runManager;
45      G4RunManager* runManager = G4RunManager::GetRunManager();
46
47      std::string gui = "$SNOVISROOT/scripts/OnX/snovis_session.onx"; //UIOnX
48      G4Lab::UIOnX* session = 
49        new G4Lab::UIOnX(*runManager,gui,argc,argv); //UIOnX
50      session->createUI(aTk);
51      session->SessionStart();
52      delete session;
53    }
54  };
55}
56
57int main( int argc , char** argv ) 
58{
59  if(argc<=0) return EXIT_FAILURE;
60  if(!check_envs(argv[0])) return EXIT_FAILURE;
61
62  Lib::Printer printer;
63  Lib::Out out(printer);
64
65  std::string SNOVISROOT;
66  if(!Lib::System::getenv("SNOVISROOT",SNOVISROOT)) {
67    out << "snovis_session :"
68        << " Environment variable SNOVISROOT not defined."
69        << Lib::endl;
70    return EXIT_FAILURE;
71  }
72
73  std::string params;
74
75  // We cd to $HOME/snovis/session :
76  if(!Lib::dirmanip::goHome()) {
77    out << "snovis_session : can't go home." << Lib::endl;
78    return EXIT_FAILURE;
79  } else if(!Lib::dirmanip::mkcd("snovis")) {
80    out << "snovis_session : can't mkcd snovis." << Lib::endl;
81    return EXIT_FAILURE;
82  } else if(!Lib::dirmanip::mkcd("session")) {
83    out << "snovis_session : can't mkcd session." << Lib::endl;
84    return EXIT_FAILURE;
85  } else {
86    // If there is a snova.par file found under
87    //    $HOME/snovis/session :
88    // we take it, else we start with $SNOVISROOT/scripts/snova/snova.par
89    if(Lib::fmanip::exists("snova.par")) {
90      params = "snova.par";
91    } else {
92      params = "$SNOVISROOT/scripts/snova/snova.par";
93    }
94  }
95
96  bool is_Mac_app = Lib::main::isMacApp(argv[0]);
97
98  int error_code=EXIT_SUCCESS;
99  try {
100    //std::cerr << "snovis_session : startup" << std::endl;
101    std::cerr << "snovis_session : startup : 000" << std::endl; 
102 
103    // A snova manager:
104    snovis::mgr my_snova_mgr;
105
106    // Configure some properties of the snova manager:
107    my_snova_mgr.set_debug(false);
108    my_snova_mgr.set_params_filename(params);
109    //my_snova_mgr.set_G4_macro(G4_macro);
110
111    // Use a dedicated vertex generator factory:
112    snemo::base_VG_factory my_VG_factory;
113    my_VG_factory.add("CALO_basic",
114                      snemo::CALO_basic_VG::new_CALO_basic_VG );
115    my_VG_factory.add("source_simple",
116                      snemo::source_simple_VG::new_source_simple_VG);
117    // <here you may add more functors in the factory internal map... >
118    // NOT AVAILABLE YET!
119    //my_VG_factory.add("TC_nblocks",
120    //                  snemo::TC_nblocks_VG::new_TC_nblocks_VG );
121
122    my_VG_factory.init();
123    //if( debug ) my_VG_factory.dump(std::cerr);
124    my_snova_mgr.set_VG_factory(my_VG_factory);
125
126    // Build the guts of the simulation process within the snova manager:
127    //std::cerr << "snovis_session :"
128    //          << " mgr.init..." << std::endl;
129    my_snova_mgr.init();
130
131    // Run the simulation:
132    my_snova_mgr.run_sim(argc,argv,is_Mac_app?"Qt":"");
133
134    //std::cerr << "snovis_session :"
135    //          << " mgr.reset..." << std::endl;
136    my_snova_mgr.reset(); // not mandatory for we do it in the d-tor.
137
138    //std::cerr << "snovis_session :"
139    //          << " end." << std::endl;
140  }
141  catch(std::exception & x){
142    std::cerr << "snovis_session : error : " << x.what() << std::endl; 
143    error_code=EXIT_FAILURE;
144  }
145  catch(...){
146    std::cerr << "snovis_session : error : unexpected error!" << std::endl; 
147    error_code=EXIT_FAILURE;
148  }
149  return error_code;
150}
Note: See TracBrowser for help on using the repository browser.