ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4PhysicalVolumeStore.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4PhysicalVolumeStore.cc
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 // G4PhysicalVolumeStore implementation for singleton container
27 //
28 // 25.07.95, P.Kent - Initial version
29 // --------------------------------------------------------------------
30 
31 #include "G4Types.hh"
32 #include "G4PhysicalVolumeStore.hh"
33 #include "G4GeometryManager.hh"
34 #include "G4LogicalVolume.hh"
35 
36 // ***************************************************************************
37 // Static class variables
38 // ***************************************************************************
39 //
43 
44 // ***************************************************************************
45 // Protected constructor: Construct underlying container with
46 // initial size of 100 entries
47 // ***************************************************************************
48 //
50  : std::vector<G4VPhysicalVolume*>()
51 {
52  reserve(100);
53 }
54 
55 // ***************************************************************************
56 // Destructor
57 // ***************************************************************************
58 //
60 {
61  Clean(); // Delete all volumes in the store
62  G4VPhysicalVolume::Clean(); // Delete allocated sub-instance data
63 }
64 
65 // ***************************************************************************
66 // Delete all elements from the store
67 // ***************************************************************************
68 //
70 {
71  // Do nothing if geometry is closed
72  //
74  {
75  G4cout << "WARNING - Attempt to delete the physical volume store"
76  << " while geometry closed !" << G4endl;
77  return;
78  }
79 
80  // Locks store for deletion of volumes. De-registration will be
81  // performed at this stage. G4VPhysicalVolumes will not de-register
82  // themselves.
83  //
84  locked = true;
85 
86  size_t i=0;
88 
89 #ifdef G4GEOMETRY_VOXELDEBUG
90  G4cout << "Deleting Physical Volumes ... ";
91 #endif
92 
93  for(auto pos=store->cbegin(); pos!=store->cend(); ++pos)
94  {
95  if (fgNotifier != nullptr) { fgNotifier->NotifyDeRegistration(); }
96  delete *pos; ++i;
97  }
98 
99 #ifdef G4GEOMETRY_VOXELDEBUG
100  if (store->size() < i-1)
101  { G4cout << "No volumes deleted. Already deleted by user ?" << G4endl; }
102  else
103  { G4cout << i-1 << " volumes deleted !" << G4endl; }
104 #endif
105 
106  locked = false;
107  store->clear();
108 }
109 
110 // ***************************************************************************
111 // Associate user notifier to the store
112 // ***************************************************************************
113 //
115 {
116  GetInstance();
117  fgNotifier = pNotifier;
118 }
119 
120 // ***************************************************************************
121 // Add Volume to container
122 // ***************************************************************************
123 //
125 {
126  GetInstance()->push_back(pVolume);
128 }
129 
130 // ***************************************************************************
131 // Remove Volume from container and update the list of daughters
132 // of the mother's logical volume
133 // ***************************************************************************
134 //
136 {
137  if (!locked) // Do not de-register if locked !
138  {
139  if (fgNotifier != nullptr) { fgNotifier->NotifyDeRegistration(); }
140  G4LogicalVolume* motherLogical = pVolume->GetMotherLogical();
141  if (motherLogical != nullptr) { motherLogical->RemoveDaughter(pVolume); }
142  for (auto i=GetInstance()->cbegin(); i!=GetInstance()->cend(); ++i)
143  {
144  if (**i==*pVolume)
145  {
146  GetInstance()->erase(i);
147  break;
148  }
149  }
150  }
151 }
152 
153 // ***************************************************************************
154 // Retrieve the first volume pointer in the container having that name
155 // ***************************************************************************
156 //
159 {
160  for (auto i=GetInstance()->cbegin(); i!=GetInstance()->cend(); ++i)
161  {
162  if ((*i)->GetName() == name) { return *i; }
163  }
164  if (verbose)
165  {
166  std::ostringstream message;
167  message << "Volume NOT found in store !" << G4endl
168  << " Volume " << name << " NOT found in store !" << G4endl
169  << " Returning NULL pointer.";
170  G4Exception("G4PhysicalVolumeStore::GetVolume()",
171  "GeomMgt1001", JustWarning, message);
172  }
173  return nullptr;
174 }
175 
176 // ***************************************************************************
177 // Return ptr to Store, setting if necessary
178 // ***************************************************************************
179 //
181 {
182  static G4PhysicalVolumeStore worldStore;
183  if (fgInstance == nullptr)
184  {
185  fgInstance = &worldStore;
186  }
187  return fgInstance;
188 }