Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
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 //
27 // $Id: G4SolidStore.cc 103345 2017-03-28 14:20:20Z gcosmo $
28 //
29 // G4SolidStore
30 //
31 // Implementation for singleton container
32 //
33 // History:
34 // 10.07.95 P.Kent Initial version
35 // --------------------------------------------------------------------
36 
37 #include "globals.hh"
38 #include "G4SolidStore.hh"
39 #include "G4GeometryManager.hh"
40 
41 // ***************************************************************************
42 // Static class variables
43 // ***************************************************************************
44 //
48 
49 // ***************************************************************************
50 // Protected constructor: Construct underlying container with
51 // initial size of 100 entries
52 // ***************************************************************************
53 //
55  : std::vector<G4VSolid*>()
56 {
57  reserve(100);
58 }
59 
60 // ***************************************************************************
61 // Destructor
62 // ***************************************************************************
63 //
65 {
66  Clean();
67 }
68 
69 // ***************************************************************************
70 // Delete all elements from the store
71 // ***************************************************************************
72 //
74 {
75  // Do nothing if geometry is closed
76  //
78  {
79  G4cout << "WARNING - Attempt to delete the solid store"
80  << " while geometry closed !" << G4endl;
81  return;
82  }
83 
84  // Locks store for deletion of solids. De-registration will be
85  // performed at this stage. G4VSolids will not de-register themselves.
86  //
87  locked = true;
88 
89  size_t i=0;
90  G4SolidStore* store = GetInstance();
91 
92 #ifdef G4GEOMETRY_VOXELDEBUG
93  G4cout << "Deleting Solids ... ";
94 #endif
95 
96  for(iterator pos=store->begin(); pos!=store->end(); pos++)
97  {
99  if (*pos) { delete *pos; }
100  i++;
101  }
102 
103 #ifdef G4GEOMETRY_VOXELDEBUG
104  if (store->size() < i-1)
105  { G4cout << "No solids deleted. Already deleted by user ?" << G4endl; }
106  else
107  { G4cout << i-1 << " solids deleted !" << G4endl; }
108 #endif
109 
110  locked = false;
111  store->clear();
112 }
113 
114 // ***************************************************************************
115 // Associate user notifier to the store
116 // ***************************************************************************
117 //
119 {
120  GetInstance();
121  fgNotifier = pNotifier;
122 }
123 
124 // ***************************************************************************
125 // Add Solid to container
126 // ***************************************************************************
127 //
129 {
130  GetInstance()->push_back(pSolid);
132 }
133 
134 // ***************************************************************************
135 // Remove Solid from container
136 // ***************************************************************************
137 //
139 {
140  if (!locked) // Do not de-register if locked !
141  {
143  for (iterator i=GetInstance()->begin(); i!=GetInstance()->end(); i++)
144  {
145  if (**i==*pSolid)
146  {
147  GetInstance()->erase(i);
148  break;
149  }
150  }
151  }
152 }
153 
154 // ***************************************************************************
155 // Retrieve the first solid pointer in the container having that name
156 // ***************************************************************************
157 //
159 {
160  for (iterator i=GetInstance()->begin(); i!=GetInstance()->end(); i++)
161  {
162  if ((*i)->GetName() == name) { return *i; }
163  }
164  if (verbose)
165  {
166  std::ostringstream message;
167  message << "Solid " << name << " not found in store !" << G4endl
168  << "Returning NULL pointer.";
169  G4Exception("G4SolidStore::GetSolid()",
170  "GeomMgt1001", JustWarning, message);
171  }
172  return 0;
173 }
174 
175 // ***************************************************************************
176 // Return ptr to Store, setting if necessary
177 // ***************************************************************************
178 //
180 {
181  static G4SolidStore worldStore;
182  if (!fgInstance)
183  {
184  fgInstance = &worldStore;
185  }
186  return fgInstance;
187 }
const XML_Char * name
Definition: expat.h:151
virtual void NotifyDeRegistration()=0
static void Clean()
Definition: G4SolidStore.cc:73
static const G4double pos
static G4SolidStore * fgInstance
Definition: G4SolidStore.hh:90
#define G4endl
Definition: G4ios.hh:61
void message(RunManager *runmanager)
Definition: ts_scorers.cc:72
static G4ThreadLocal G4VStoreNotifier * fgNotifier
Definition: G4SolidStore.hh:91
virtual ~G4SolidStore()
Definition: G4SolidStore.cc:64
#define G4ThreadLocal
Definition: tls.hh:69
virtual void NotifyRegistration()=0
static G4ThreadLocal G4bool locked
Definition: G4SolidStore.hh:92
bool G4bool
Definition: G4Types.hh:79
static void SetNotifier(G4VStoreNotifier *pNotifier)
static G4SolidStore * GetInstance()
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.hh:65
static void Register(G4VSolid *pSolid)
static G4bool IsGeometryClosed()
G4GLOB_DLL std::ostream G4cout
G4VSolid * GetSolid(const G4String &name, G4bool verbose=true) const
static void DeRegister(G4VSolid *pSolid)