SToGS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
SToGS_UserActionManager.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
27 //----------------------------------------------------------------------------------
28 
29 
31 #include "SToGSConfig.hh"
32 
33 #include "G4ios.hh"
34 #include <fstream>
35 
37  fImplementation(0x0),
38  fWhichGenerator("GPS","G4Macros/GPSPointLike.mac"),
39  fWhichGeometry("factory","DetectorFactory/Generics/Target"),
40  fWhichPhysics("stogs_m","general0;emstandard_opt0;"),
41  fWhichActionManager("PrintOut","run;event;track;step"),
42  fNbThreads(2)
43 {
44  G4cout << G4endl << " ------ INF ------ from UserActionManager::UserActionManager with " << filename << G4endl;
45 
46  // open the ascii file
47  std::ifstream file(filename);
48  if ( file.is_open() == false ) {
49  G4cout << " ** SToGS WARNING ** Cannot open file, Default parameters to be used "<< G4endl;
50  }
51  else {
52  std::string aline; getline(file,aline);
53  while ( file.good() && !file.eof() ) {
54 
55  if ( aline[0] == '#' ){
56  getline(file,aline);
57  continue;
58  } // this line is a comment
59 
60  std::string key, which, option; std::istringstream decode(aline); decode >> key;
61 
62  if ( key == "actions:" ) {
63  decode >> which >> option;
64  fWhichActionManager = std::pair<G4String, G4String> (which,option);
65  }
66  if ( key == "setup:" ) {
67  decode >> which >> option;
68  fWhichGeometry = std::pair<G4String, G4String> (which,option);
69  }
70  if ( key == "physics:" ) {
71  decode >> which >> option;
72  fWhichPhysics = std::pair<G4String, G4String> (which,option);
73  }
74  if ( key == "generator:" ) {
75  decode >> which >> option;
76  fWhichGenerator = std::pair<G4String, G4String> (which,option);
77  }
78  if ( key == "nbthread:" ) {
79  decode >> fNbThreads;
80  }
81  getline(file,aline);
82  }
83  file.close();
84  }
85 
86 
87  fImplementation = ProvideUserActionInitialization();
88  if ( fImplementation == 0x0 ) {
89  G4cout << " *** SToGS ERROR *** Action Manager is not known *** SToGS ERROR *** " << G4endl;
90  }
91  else {
92  fImplementation->SetWhichGenerator(fWhichGenerator.first,fWhichGenerator.second);
93  }
94 
95  G4cout << " ActionManager has been initiated with " << G4endl;
96  G4cout << " + generator " << fWhichGenerator.first << " " << fWhichGenerator.second << G4endl;
97  G4cout << " + physics list " << fWhichPhysics.first << " " << fWhichPhysics.second << G4endl;
98  G4cout << " + geometry used " << fWhichGeometry.first << " " << fWhichGeometry.second << G4endl;
99  G4cout << " + action manager " << fWhichActionManager.first << " " << fWhichActionManager.second << G4endl;
100 
101  G4cout << " ------ END ------ from UserActionManager::UserActionManager " << G4endl;
102 }
103 
104 #include "SToGS_PrintOut.hh"
105 #include "SToGS_Ascii.hh"
106 #ifdef HAS_STOGS_ROOT_EVENTS
108 #endif
109 
111 {
112  if ( fWhichActionManager.first == "printout" ) {
113  fImplementation = new SToGS::PrintOut(fWhichActionManager.second);
114  }
115  if ( fWhichActionManager.first == "ascii" ) {
116  fImplementation = new SToGS::Ascii(fWhichActionManager.second);
117  }
118 #ifdef HAS_STOGS_ROOT_EVENTS
119  if ( fWhichActionManager.first == "stogstree" ) {
120  fImplementation = new SToGS::BaseROOTEvents(fWhichActionManager.second);
121  }
122 #endif
123  // based on My plugins defined in SToGSConfig, it build the user actio
124 #ifdef HAS_MYACT
125  if ( fWhichActionManager.first.contains(MYACT_) ) {
126  fImplementation = new MYACT_CLASSTYPE(fWhichActionManager.second);
127  }
128 #endif
129  return fImplementation;
130 }
131 
133 
134 G4VUserDetectorConstruction *SToGS::UserActionManager::GetDetectorConstruction() const
135 {
136  G4VUserDetectorConstruction *detectorconstruction = 0x0;
137  if ( fWhichGeometry.first == "factory" ) {
138  detectorconstruction = new SToGS::LoadFromDetectorFactory(fWhichGeometry.second);
139  }
140 
141  return detectorconstruction;
142 }
143 
145 
146 G4VUserPhysicsList *SToGS::UserActionManager::GetPhysicsList() const
147 {
148  G4VUserPhysicsList *physics_list = 0x0;
149 
150  if ( fWhichPhysics.first == "stogs_m" ) {
151  physics_list = new SToGS::ModularPhysicsList(fWhichPhysics.second);
152  }
153 
154  return physics_list;
155 }
156 
SToGS::UserActionInitialization * ProvideUserActionInitialization()
depending of the configuration file, it returns the adapted UserActionInitialization ...
Extract informations from Geant4 using SToGS sensitives and write hits in ascii files.
Definition: SToGS_Ascii.hh:109
UserActionManager(G4String configurationfile="")
std::pair< G4String, G4String > fWhichGenerator
In principle in Geant4.10, geometry and physics are golbal so they are not provided by G4VUserActionI...
virtual G4VUserPhysicsList * GetPhysicsList() const
Return the physics list depending of the configuration file.
This class allows to select different physics using the information stores in the file given to the c...
This is the ActionInitialization class to handle PrintOut at different levels (run, events ...) from a unique AllAction event Class.
std::pair< G4String, G4String > fWhichGeometry
The BaseROOTEvents is use to init G4 kernel with the actions defined in BaseROOTEventsUserAction.
Base class to manage SToGS user's hooks + the generator.
to load a setup from the factory
std::pair< G4String, G4String > fWhichActionManager
Real stuff the G4VUserActionInitialization should deal with.
std::pair< G4String, G4String > SetWhichGenerator(G4String which_gene, G4String option)
once allocated the generator associated with a UserActionInititialization could be changed here befor...
virtual G4VUserDetectorConstruction * GetDetectorConstruction() const
Return the detector depending of the configuration file.
std::pair< G4String, G4String > fWhichPhysics