source: snovis/trunk/applications/snovis_main.cxx@ 302

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