SToGS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
SToGS_GenericsDF.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 // G4 includes
29 #include "G4LogicalVolume.hh"
30 #include "G4UnitsTable.hh"
31 #include "G4Version.hh"
32 
33 // Project includes
34 #include "SToGS_GenericsDF.hh"
35 #include "SToGSConfig.hh"
36 
37 // Specific to the Generic Factory
39 #include "SToGS_AGATA.hh"
40 
41 // list of all specific factories
42 namespace {
43  // all scintillators
44  SToGS::GenericsDF theGenericFactory("Generics/");
45 }
46 
47 G4String SToGS::GenericsDF::GetConf(G4String path_in_factory) const
48 {
49  G4String result(""), tmp = path_in_factory;
50  if ( !tmp.contains("$") ) {
51  return result;
52  }
53  else { result = GetFactoryName(); }
54 
55  G4int start = tmp.last('$'); tmp.remove(0,start+1);
56  result += tmp;
57 
58  return result;
59 }
60 
61 G4VPhysicalVolume *SToGS::GenericsDF::Get(G4String basename)
62 {
63  G4VUserDetectorConstruction *theConstructor = 0x0; G4VPhysicalVolume *theDetector = 0x0; G4String conffile;
64 
65  // check is already loaded
66  for (size_t i = 0; i < fLoadedPhysical.size(); i++) {
67  if ( fLoadedPhysical[i].first == basename ) {
68  theDetector = fLoadedPhysical[i].second;
69  break;
70  }
71  }
72  if ( theDetector ) {
73  return theDetector;
74  }
75  else { // get conf name. If null call default constructor otherwise call constructor with string parameter
76  conffile = GetConf(basename);
77  }
78  // load using the g4 facility
79  if ( basename.contains("/TwoShells") ) {
80  if ( conffile == "" ) {
81  theConstructor = new SToGS::TwoShellsDetectorConstruction(conffile);
82  }
83  else theConstructor = new SToGS::TwoShellsDetectorConstruction(conffile);
84  theDetector = theConstructor->Construct();
85  }
86  if ( basename.contains("/AGATA") ) {
87  theConstructor = new SToGS::AGATA();
88  theDetector = theConstructor->Construct();
89  }
90 #ifdef HAS_MYDET
91  // based on My plugins defined in SToGSConfig, it build the detector name in factory
92  if ( basename.contains(MYDET_) ) {
93  if ( conffile == "" ) {
94  theConstructor = new MYDET_CLASSTYPE();
95  }
96  else theConstructor = new MYDET_CLASSTYPE(conffile);
97  theDetector = theConstructor->Construct();
98  }
99 #endif
100  if ( theDetector ) {
101  std::pair < G4String, G4VPhysicalVolume *> p1(basename,theDetector); // add the new loaded detector to the list
102  fLoadedPhysical.push_back(p1);
103  std::pair < G4String, G4VUserDetectorConstruction *> p2(basename,theConstructor);
104  fLoadedUserDetectorConstruction.push_back(p2);
105  }
106 
107  GetAttributes(basename,true, true);
108 
109  return theDetector;
110 }
111 
112 void SToGS::GenericsDF::GetAttributes(G4String basename, G4bool do_amap, G4bool do_dmap)
113 {
114  // check is already loaded
115 #if G4VERSION_NUMBER < 1000
116 #else
117  if ( do_amap ) {
118  for (size_t i = 0; i < fLoadedUserDetectorConstruction.size(); i++) {
119  if ( fLoadedUserDetectorConstruction[i].first == basename ) {
120  fLoadedUserDetectorConstruction[i].second->ConstructSDandField();
121  break;
122  }
123  }
124  }
125 #endif
126 }
127 
128 
129 
130 
131 
132 
G4String GetConf(G4String path_in_factory) const
return from the full path in the factory the configuration file which is following $ ...
Class to build AGATA from the same configuration files [asolid, acluster, aeuler] that the ones in th...
Definition: SToGS_AGATA.hh:58
Factory which is an interface to G4VUserDetectorConstruction.
G4String GetFactoryName() const
virtual void GetAttributes(G4String basename, G4bool do_amap=true, G4bool do_dmap=false)
Read attrbiutes by calling COnstructSDandFileds.
Detector composed of a set of concentric shells with two (possibly one) active shells.
virtual G4VPhysicalVolume * Get(G4String basename)
overwrite the Get method to retrieve the detector from the standard G4 way i.e. by calling Construct ...