Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
G4LogicalVolumeStore.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: G4LogicalVolumeStore.cc 103235 2017-03-22 15:53:48Z gcosmo $
28 //
29 // G4LogicalVolumeStore
30 //
31 // Implementation for singleton container
32 //
33 // History:
34 // 10.07.95 P.Kent Initial version
35 // --------------------------------------------------------------------
36 
37 #include "G4Types.hh"
38 #include "G4LogicalVolumeStore.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<G4LogicalVolume*>()
56 {
57  reserve(100);
58 }
59 
60 // ***************************************************************************
61 // Destructor
62 // ***************************************************************************
63 //
65 {
66  Clean(); // Delete all volumes in the store
67  G4LogicalVolume::Clean(); // Delete allocated sub-instance data
68 }
69 
70 // ***************************************************************************
71 // Delete all elements from the store
72 // ***************************************************************************
73 //
75 {
76  // Do nothing if geometry is closed
77  //
79  {
80  G4cout << "WARNING - Attempt to delete the logical volume store"
81  << " while geometry closed !" << G4endl;
82  return;
83  }
84 
85  // Locks store for deletion of volumes. De-registration will be
86  // performed at this stage. G4LogicalVolumes will not de-register themselves.
87  //
88  locked = true;
89 
90  size_t i=0;
92 
93 #ifdef G4GEOMETRY_VOXELDEBUG
94  G4cout << "Deleting Logical Volumes ... ";
95 #endif
96 
97  for(iterator pos=store->begin(); pos!=store->end(); pos++)
98  {
100  if (*pos) { (*pos)->Lock(); delete *pos; }
101  i++;
102  }
103 
104 #ifdef G4GEOMETRY_VOXELDEBUG
105  if (store->size() < i-1)
106  { G4cout << "No volumes deleted. Already deleted by user ?" << G4endl; }
107  else
108  { G4cout << i-1 << " volumes deleted !" << G4endl; }
109 #endif
110 
111  locked = false;
112  store->clear();
113 }
114 
115 // ***************************************************************************
116 // Associate user notifier to the store
117 // ***************************************************************************
118 //
120 {
121  GetInstance();
122  fgNotifier = pNotifier;
123 }
124 
125 // ***************************************************************************
126 // Add volume to container
127 // ***************************************************************************
128 //
130 {
131  GetInstance()->push_back(pVolume);
133 }
134 
135 // ***************************************************************************
136 // Remove volume from container
137 // ***************************************************************************
138 //
140 {
141  if (!locked) // Do not de-register if locked !
142  {
144  for (iterator i=GetInstance()->begin(); i!=GetInstance()->end(); i++)
145  {
146  if (**i==*pVolume)
147  {
148  GetInstance()->erase(i);
149  break;
150  }
151  }
152  }
153 }
154 
155 // ***************************************************************************
156 // Retrieve the first volume pointer in the container having that name
157 // ***************************************************************************
158 //
161 {
162  for (iterator i=GetInstance()->begin(); i!=GetInstance()->end(); i++)
163  {
164  if ((*i)->GetName() == name) { return *i; }
165  }
166  if (verbose)
167  {
168  std::ostringstream message;
169  message << "Volume NOT found in store !" << G4endl
170  << " Volume " << name << " NOT found in store !" << G4endl
171  << " Returning NULL pointer.";
172  G4Exception("G4LogicalVolumeStore::GetVolume()",
173  "GeomMgt1001", JustWarning, message);
174  }
175  return 0;
176 }
177 
178 // ***************************************************************************
179 // Return ptr to Store, setting if necessary
180 // ***************************************************************************
181 //
183 {
184  static G4LogicalVolumeStore worldStore;
185  if (!fgInstance)
186  {
187  fgInstance = &worldStore;
188  }
189  return fgInstance;
190 }
const XML_Char * name
Definition: expat.h:151
virtual void NotifyDeRegistration()=0
static const G4double pos
#define G4endl
Definition: G4ios.hh:61
void message(RunManager *runmanager)
Definition: ts_scorers.cc:72
static G4ThreadLocal G4VStoreNotifier * fgNotifier
static void DeRegister(G4LogicalVolume *pVolume)
#define G4ThreadLocal
Definition: tls.hh:69
static void SetNotifier(G4VStoreNotifier *pNotifier)
static void Register(G4LogicalVolume *pVolume)
virtual void NotifyRegistration()=0
bool G4bool
Definition: G4Types.hh:79
static void Clean()
static G4LogicalVolumeStore * fgInstance
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.hh:65
static G4bool IsGeometryClosed()
G4GLOB_DLL std::ostream G4cout
static G4LogicalVolumeStore * GetInstance()
static G4ThreadLocal G4bool locked
G4LogicalVolume * GetVolume(const G4String &name, G4bool verbose=true) const