ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4SolidStore.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4SolidStore.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 // G4SolidStore implementation for singleton container
27 //
28 // 18.04.01, G.Cosmo - Migrated to STL vector
29 // 10.07.95, P.Kent - Initial version
30 // --------------------------------------------------------------------
31 
32 #include "globals.hh"
33 #include "G4SolidStore.hh"
34 #include "G4GeometryManager.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<G4VSolid*>()
51 {
52  reserve(100);
53 }
54 
55 // ***************************************************************************
56 // Destructor
57 // ***************************************************************************
58 //
60 {
61  Clean();
62 }
63 
64 // ***************************************************************************
65 // Delete all elements from the store
66 // ***************************************************************************
67 //
69 {
70  // Do nothing if geometry is closed
71  //
73  {
74  G4cout << "WARNING - Attempt to delete the solid store"
75  << " while geometry closed !" << G4endl;
76  return;
77  }
78 
79  // Locks store for deletion of solids. De-registration will be
80  // performed at this stage. G4VSolids will not de-register themselves.
81  //
82  locked = true;
83 
84  size_t i = 0;
85  G4SolidStore* store = GetInstance();
86 
87 #ifdef G4GEOMETRY_VOXELDEBUG
88  G4cout << "Deleting Solids ... ";
89 #endif
90 
91  for(auto pos=store->cbegin(); pos!=store->cend(); ++pos)
92  {
93  if (fgNotifier != nullptr) { fgNotifier->NotifyDeRegistration(); }
94  delete *pos; ++i;
95  }
96 
97 #ifdef G4GEOMETRY_VOXELDEBUG
98  if (store->size() < i-1)
99  { G4cout << "No solids deleted. Already deleted by user ?" << G4endl; }
100  else
101  { G4cout << i-1 << " solids deleted !" << G4endl; }
102 #endif
103 
104  locked = false;
105  store->clear();
106 }
107 
108 // ***************************************************************************
109 // Associate user notifier to the store
110 // ***************************************************************************
111 //
113 {
114  GetInstance();
115  fgNotifier = pNotifier;
116 }
117 
118 // ***************************************************************************
119 // Add Solid to container
120 // ***************************************************************************
121 //
123 {
124  GetInstance()->push_back(pSolid);
125  if (fgNotifier != nullptr) { fgNotifier->NotifyRegistration(); }
126 }
127 
128 // ***************************************************************************
129 // Remove Solid from container
130 // ***************************************************************************
131 //
133 {
134  if (!locked) // Do not de-register if locked !
135  {
136  if (fgNotifier != nullptr) { fgNotifier->NotifyDeRegistration(); }
137  for (auto i=GetInstance()->crbegin(); i!=GetInstance()->crend(); ++i)
138  {
139  if (**i==*pSolid)
140  {
141  GetInstance()->erase(std::next(i).base());
142  break;
143  }
144  }
145  }
146 }
147 
148 // ***************************************************************************
149 // Retrieve the first solid pointer in the container having that name
150 // ***************************************************************************
151 //
153 {
154  for (auto i=GetInstance()->cbegin(); i!=GetInstance()->cend(); ++i)
155  {
156  if ((*i)->GetName() == name) { return *i; }
157  }
158  if (verbose)
159  {
160  std::ostringstream message;
161  message << "Solid " << name << " not found in store !" << G4endl
162  << "Returning NULL pointer.";
163  G4Exception("G4SolidStore::GetSolid()",
164  "GeomMgt1001", JustWarning, message);
165  }
166  return nullptr;
167 }
168 
169 // ***************************************************************************
170 // Return ptr to Store, setting if necessary
171 // ***************************************************************************
172 //
174 {
175  static G4SolidStore worldStore;
176  if (fgInstance == nullptr)
177  {
178  fgInstance = &worldStore;
179  }
180  return fgInstance;
181 }