SToGS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
SToGS_DetectorFactory.hh
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 #ifndef SToGS_DetectorFactory_h
28 #define SToGS_DetectorFactory_h 1
29 
30 #include "globals.hh"
31 #include "G4VUserDetectorConstruction.hh"
32 #include "G4RotationMatrix.hh"
33 #include "G4Transform3D.hh"
34 
35 // std includes
36 #include <iostream>
37 #include <sstream>
38 #include <fstream>
39 
40 class G4Box;
41 class G4Sphere;
42 class G4LogicalVolume;
43 class G4VPhysicalVolume;
44 class G4Material;
45 class G4AssemblyVolume;
46 class G4VSensitiveDetector;
47 
49 namespace SToGS {
50 
51  class DFMessenger;
52 
54 
61  {
63  private:
65  static DetectorFactory *pMainFactory;
66  private:
68  static DFMessenger *pMainMessanger;
69  private:
71 
74  static std::vector < DetectorFactory * > fSubFactory;
75  private:
77  static G4int gCopyNb;
78 
79  protected:
81  G4String fPath;
82  protected:
84  std::vector < std::pair < G4String, G4AssemblyVolume *> > fLoadedAssembly;
86  std::vector < std::pair < G4String, G4VPhysicalVolume *> > fLoadedPhysical;
87 
89  private:
91 
97  void Register(DetectorFactory *df)
98  {
99  fSubFactory.push_back(df);
100  }
101 
102  protected:
105  fPath("DetectorFactory/"),
106  fLoadedAssembly(0),
107  fLoadedPhysical(0)
108  {;}
110  DetectorFactory(G4String path):
111  fPath(path),
112  fLoadedAssembly(1000),
113  fLoadedPhysical(1000)
114  {
115  fPath.prepend(theMainFactory()->GetFactoryName().data());
116  theMainFactory()->Register(this) ;
117  }
118 
119  public:
120 // Main factory facilities
122  static G4int AddGCopyNb()
123  {
124  G4int val = gCopyNb++;
125  return val;
126  }
127  static G4int SetGCopyNb(G4int val)
128  {
129  G4int current = gCopyNb;
130  gCopyNb = val;
131  return current;
132  }
133  static G4int GetGCopyNb()
134  {
135  return gCopyNb;
136  }
138  static void ChangeCopyNb(G4VPhysicalVolume *top, G4String which_det, G4int which_nb);
139 
142 
144  static DetectorFactory *GetFactory(G4String fullname);
145 
147  static G4VPhysicalVolume *MakeVCR(
148  G4String name,
149  G4double HalfX = 5.0*CLHEP::m, G4double HalfY = 5.0*CLHEP::m, G4double HalfZ = 5.0*CLHEP::m,
150  G4int copy = -1);
151 
153 
157  static void SetActive(G4LogicalVolume *pv, const G4String &option = "*|*|*|0.5;0.5;0.5;0.5");
158 
160 
163  static void ChangeSD(G4String opt, G4VPhysicalVolume *top = 0x0);
165  static G4VSensitiveDetector * GetSD(G4String opt, const char sd_type = 'S');
166 
168 
171  static void CollectVolumes(G4VPhysicalVolume *theDetector,
172  std::vector<G4LogicalVolume *> &logical_stored,
173  std::vector<G4VPhysicalVolume *> &physical_stored, std::vector<G4VPhysicalVolume *> &physical_active);
174 
175  protected:
176 // Methods to be overwritten in particular factory
178  virtual G4VPhysicalVolume * Make(G4String /* name */, G4String /* version_string */)
179  {
180  return 0x0;
181  }
183  void StoreMap(std::ofstream &amap, std::ofstream &dmap,
184  std::vector<G4LogicalVolume *> &logical_stored,
185  std::vector<G4VPhysicalVolume *> &physical_stored,
186  std::vector<G4VPhysicalVolume *> &physical_active,
187  G4VPhysicalVolume *theDetector);
188 
190  void StreamTouchable(std::ofstream &dmap, G4String);
191 
193 
196  G4VPhysicalVolume *Import(G4String gdmlfile, G4String detname, const G4String &opt_amap, const G4String &opt_dmap);
197 
198 
199  public:
201  { /* what to delete ? ... the main factory .. */ ;}
202 
203  G4String GetFactoryName() const
204  {
205  return fPath;
206  }
207 
208  public:
210 
213  G4String GetDetName(const G4String &path) const;
214  G4String GetDetName(G4String name, G4String version) const;
215 
217  G4String GetFileName(G4String detname, G4String extention);
218 
220 
228  virtual G4VPhysicalVolume *Get(G4String basename);
229  G4AssemblyVolume *GetAssembly(G4String basename);
231  virtual void GetAttributes(G4String basename, G4bool do_amap = true, G4bool do_dmap = false);
232 
234  G4int Set(G4String basename, G4VPhysicalVolume *world, G4int copy_number_offset,
235  const G4ThreeVector *T = 0x0, const G4RotationMatrix *R = 0x0, G4int main_copy_number = 0);
236  G4int Set(G4String basename, G4VPhysicalVolume *world, G4int copy_number_offset,
237  const G4Transform3D *Tr, G4int main_copy_number = 0);
239  void Clean();
240 
241  protected:
243 
247  void MakeInStore(G4String name, G4String version_string);
248 
249  public:
251  virtual void MakeStore();
252 
254  virtual void Store(G4VPhysicalVolume *);
255 
257  void AssemblyRename(G4AssemblyVolume *assembly, const G4String &volume_to_find) const;
258 
260  /*
261  */
262  G4int DoMap(G4AssemblyVolume *assembly, G4VPhysicalVolume *volume_used_to_built_assembly, G4int copy_number_offset = 0
263  /*, G4String opt = "->" */) const;
265 
268  virtual G4int ReMap(G4VPhysicalVolume *adetector, G4int offset);
269 
271  /*
272  The volume are reas as they are and only the top physical volume has its copy number affected
273  */
274  virtual G4VPhysicalVolume * MakeAnArrayFromFactory(G4String input_file);
275 
276  };
277 } // SToGS Namespace
278 
279 
280 #include "G4UImessenger.hh"
281 
282 class G4UIdirectory;
283 class G4UIcmdWithAString;
284 
286 namespace SToGS {
288 
290  class DFMessenger: public G4UImessenger
291  {
292  public:
293  DFMessenger();
294  virtual ~DFMessenger();
295 
296  void SetNewValue(G4UIcommand*, G4String);
297 
298  private:
300  G4UIdirectory *theDirectory;
301 
303  G4UIcmdWithAString *cmdToChangeSD;
304  G4UIcmdWithAString *cmdToSaveInFactory;
305  };
306 
307 } // SToGS Namespace
308 
309 #endif
310 
311 
G4int Set(G4String basename, G4VPhysicalVolume *world, G4int copy_number_offset, const G4ThreeVector *T=0x0, const G4RotationMatrix *R=0x0, G4int main_copy_number=0)
to be used once a detector is fully contructed to simply place it in the world
static G4VPhysicalVolume * MakeVCR(G4String name, G4double HalfX=5.0 *CLHEP::m, G4double HalfY=5.0 *CLHEP::m, G4double HalfZ=5.0 *CLHEP::m, G4int copy=-1)
make a cubic world
the Messenger for the Detector Factory
static void ChangeCopyNb(G4VPhysicalVolume *top, G4String which_det, G4int which_nb)
change copy number of the physical volume contained in the top volume
void StoreMap(std::ofstream &amap, std::ofstream &dmap, std::vector< G4LogicalVolume * > &logical_stored, std::vector< G4VPhysicalVolume * > &physical_stored, std::vector< G4VPhysicalVolume * > &physical_active, G4VPhysicalVolume *theDetector)
recursively called in the tree struture
static DetectorFactory * GetFactory(G4String fullname)
get the specific factory for a full name to a file
void Clean()
clear factory i.e. in memory collections of physicals and assemblies
G4String GetDetName(const G4String &path) const
Get detector name from full path to the gdml file.
void MakeInStore(G4String name, G4String version_string)
build in store a particular detector from its names and version. i.e. call th Make method of the sub ...
virtual void Store(G4VPhysicalVolume *)
Store in the sub-factory the given physical volume.
virtual G4VPhysicalVolume * Make(G4String, G4String)
Should be implemented in any sub factory. It built (C++) a detector and return it.
virtual G4VPhysicalVolume * Get(G4String basename)
search for a detector in DetectorFactory
static G4VSensitiveDetector * GetSD(G4String opt, const char sd_type= 'S')
Get a particular SD. S means a SD while s is for Scorers.
static G4int AddGCopyNb()
global copy number, used to set copy number once building detector. Not protected for MT since in pri...
static DetectorFactory * theMainFactory()
to get the main factory
void SetNewValue(G4UIcommand *, G4String)
virtual G4VPhysicalVolume * MakeAnArrayFromFactory(G4String input_file)
built an array from the factory using the given input file
G4String GetFileName(G4String detname, G4String extention)
compute name of the file to store/read information
virtual G4int ReMap(G4VPhysicalVolume *adetector, G4int offset)
for the given volume, it changes all copy number of active volumes by starting with offset ...
static G4int SetGCopyNb(G4int val)
static void CollectVolumes(G4VPhysicalVolume *theDetector, std::vector< G4LogicalVolume * > &logical_stored, std::vector< G4VPhysicalVolume * > &physical_stored, std::vector< G4VPhysicalVolume * > &physical_active)
From the given physical volume, it collects into collection all logical (sensitive) and physical volu...
virtual void GetAttributes(G4String basename, G4bool do_amap=true, G4bool do_dmap=false)
Read the amap file and apply atributes to the detector. if not found, it creates a deefault one from ...
G4String fPath
Name of the factory, also used for the name of the directory containing the detectors handled by the ...
std::vector< std::pair< G4String, G4AssemblyVolume * > > fLoadedAssembly
in case a gdml file has already by loaded, it allows to get the assembly quickly
Base Factory. This is a container of sub-factories.
void AssemblyRename(G4AssemblyVolume *assembly, const G4String &volume_to_find) const
rename physical volume produced by the assembly
G4String GetFactoryName() const
virtual void MakeStore()
build the default store i.e. all the detectors. Here It calls MakeStore for all registered sub factor...
DetectorFactory(G4String path)
used for inheriting classes, it registers this in the factory
G4int DoMap(G4AssemblyVolume *assembly, G4VPhysicalVolume *volume_used_to_built_assembly, G4int copy_number_offset=0) const
remap all the physical volumes produced by the Imprint method.
G4VPhysicalVolume * Import(G4String gdmlfile, G4String detname, const G4String &opt_amap, const G4String &opt_dmap)
import a gdml file (extention to ascii ?) into factory. See Active for opt_amap option ...
void StreamTouchable(std::ofstream &dmap, G4String)
extrac from the name of the detector the touchable part
static void SetActive(G4LogicalVolume *pv, const G4String &option="*|*|*|0.5;0.5;0.5;0.5")
Set to the given logical volume some attributs (sensitive, color) depending of the given option...
DetectorFactory()
used only for the main, does not register this in the factory
static void ChangeSD(G4String opt, G4VPhysicalVolume *top=0x0)
Change some SD detector into an other type of SD. Opt is used eventually to filter on the name of the...
std::vector< std::pair< G4String, G4VPhysicalVolume * > > fLoadedPhysical
in case it has been loaded, keep a trace
G4AssemblyVolume * GetAssembly(G4String basename)