Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4PhysicalVolumeStore Class Reference

#include <G4PhysicalVolumeStore.hh>

+ Inheritance diagram for G4PhysicalVolumeStore:

Public Member Functions

G4VPhysicalVolumeGetVolume (const G4String &name, G4bool verbose=true, G4bool reverseSearch=false) const
 
G4bool IsMapValid () const
 
void SetMapValid (G4bool val)
 
const std::map< G4String, std::vector< G4VPhysicalVolume * > > & GetMap () const
 
void UpdateMap ()
 
virtual ~G4PhysicalVolumeStore ()
 
 G4PhysicalVolumeStore (const G4PhysicalVolumeStore &)=delete
 
G4PhysicalVolumeStoreoperator= (const G4PhysicalVolumeStore &)=delete
 

Static Public Member Functions

static void Register (G4VPhysicalVolume *pSolid)
 
static void DeRegister (G4VPhysicalVolume *pSolid)
 
static G4PhysicalVolumeStoreGetInstance ()
 
static void SetNotifier (G4VStoreNotifier *pNotifier)
 
static void Clean ()
 

Protected Member Functions

 G4PhysicalVolumeStore ()
 

Detailed Description

Definition at line 54 of file G4PhysicalVolumeStore.hh.

Constructor & Destructor Documentation

◆ ~G4PhysicalVolumeStore()

G4PhysicalVolumeStore::~G4PhysicalVolumeStore ( )
virtual

Definition at line 66 of file G4PhysicalVolumeStore.cc.

67{
68 Clean(); // Delete all volumes in the store
69 G4VPhysicalVolume::Clean(); // Delete allocated sub-instance data
70}

◆ G4PhysicalVolumeStore() [1/2]

G4PhysicalVolumeStore::G4PhysicalVolumeStore ( const G4PhysicalVolumeStore )
delete

◆ G4PhysicalVolumeStore() [2/2]

G4PhysicalVolumeStore::G4PhysicalVolumeStore ( )
protected

Definition at line 56 of file G4PhysicalVolumeStore.cc.

57 : std::vector<G4VPhysicalVolume*>()
58{
59 reserve(100);
60}

Member Function Documentation

◆ Clean()

void G4PhysicalVolumeStore::Clean ( )
static

Definition at line 76 of file G4PhysicalVolumeStore.cc.

77{
78 // Do nothing if geometry is closed
79 //
81 {
82 G4cout << "WARNING - Attempt to delete the physical volume store"
83 << " while geometry closed !" << G4endl;
84 return;
85 }
86
87 // Locks store for deletion of volumes. De-registration will be
88 // performed at this stage. G4VPhysicalVolumes will not de-register
89 // themselves.
90 //
91 locked = true;
92
94
95 for(auto pos=store->cbegin(); pos!=store->cend(); ++pos)
96 {
97 if (fgNotifier != nullptr) { fgNotifier->NotifyDeRegistration(); }
98 delete *pos;
99 }
100
101 store->bmap.clear(); store->mvalid = false;
102 locked = false;
103 store->clear();
104}
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
static G4bool IsGeometryClosed()
static G4PhysicalVolumeStore * GetInstance()
virtual void NotifyDeRegistration()=0

Referenced by G4RunManager::ReinitializeGeometry(), and ~G4PhysicalVolumeStore().

◆ DeRegister()

void G4PhysicalVolumeStore::DeRegister ( G4VPhysicalVolume pSolid)
static

Definition at line 171 of file G4PhysicalVolumeStore.cc.

172{
174 if (!locked) // Do not de-register if locked !
175 {
176 if (fgNotifier != nullptr) { fgNotifier->NotifyDeRegistration(); }
177 G4LogicalVolume* motherLogical = pVolume->GetMotherLogical();
178 if (motherLogical != nullptr) { motherLogical->RemoveDaughter(pVolume); }
179 for (auto i=store->cbegin(); i!=store->cend(); ++i)
180 {
181 if (**i==*pVolume)
182 {
183 store->erase(i);
184 break;
185 }
186 }
187 const G4String& vol_name = pVolume->GetName();
188 auto it = store->bmap.find(vol_name);
189 if (it != store->bmap.cend())
190 {
191 if (it->second.size() > 1)
192 {
193 for (auto i=it->second.cbegin(); i!=it->second.cend(); ++i)
194 {
195 if (**i==*pVolume)
196 {
197 it->second.erase(i);
198 break;
199 }
200 }
201 }
202 else
203 {
204 store->bmap.erase(it);
205 }
206 }
207 }
208}
void RemoveDaughter(const G4VPhysicalVolume *p)

Referenced by G4VPhysicalVolume::~G4VPhysicalVolume().

◆ GetInstance()

◆ GetMap()

const std::map< G4String, std::vector< G4VPhysicalVolume * > > & G4PhysicalVolumeStore::GetMap ( ) const
inline

Definition at line 81 of file G4PhysicalVolumeStore.hh.

81{ return bmap; }

◆ GetVolume()

G4VPhysicalVolume * G4PhysicalVolumeStore::GetVolume ( const G4String name,
G4bool  verbose = true,
G4bool  reverseSearch = false 
) const

Definition at line 215 of file G4PhysicalVolumeStore.cc.

217{
219 if (!store->mvalid) { store->UpdateMap(); }
220 auto pos = store->bmap.find(name);
221 if(pos != store->bmap.cend())
222 {
223 if ((verbose) && (pos->second.size()>1))
224 {
225 std::ostringstream message;
226 message << "There exists more than ONE physical volume in store named: "
227 << name << "!" << G4endl
228 << "Returning the first found.";
229 G4Exception("G4PhysicalVolumeStore::GetVolume()",
230 "GeomMgt1001", JustWarning, message);
231 }
232 if(reverseSearch)
233 {
234 return pos->second[pos->second.size()-1];
235 }
236 else
237 {
238 return pos->second[0];
239 }
240 }
241 if (verbose)
242 {
243 std::ostringstream message;
244 message << "Volume NOT found in store !" << G4endl
245 << " Volume " << name << " NOT found in store !" << G4endl
246 << " Returning NULL pointer.";
247 G4Exception("G4PhysicalVolumeStore::GetVolume()",
248 "GeomMgt1001", JustWarning, message);
249 }
250 return nullptr;
251}
@ JustWarning
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:59
const char * name(G4int ptype)

Referenced by G4AdjointCrossSurfChecker::AddanExtSurfaceOfAvolume(), G4AdjointCrossSurfChecker::AddaSphericalSurfaceWithCenterAtTheCenterOfAVolume(), G4SPSPosDistribution::ConfineSourceToVolume(), and G4GDMLReadStructure::GetPhysvol().

◆ IsMapValid()

G4bool G4PhysicalVolumeStore::IsMapValid ( ) const
inline

Definition at line 77 of file G4PhysicalVolumeStore.hh.

77{ return mvalid; }

◆ operator=()

G4PhysicalVolumeStore & G4PhysicalVolumeStore::operator= ( const G4PhysicalVolumeStore )
delete

◆ Register()

void G4PhysicalVolumeStore::Register ( G4VPhysicalVolume pSolid)
static

Definition at line 147 of file G4PhysicalVolumeStore.cc.

148{
150 store->push_back(pVolume);
151 const G4String& vol_name = pVolume->GetName();
152 auto it = store->bmap.find(vol_name);
153 if (it != store->bmap.cend())
154 {
155 it->second.push_back(pVolume);
156 }
157 else
158 {
159 std::vector<G4VPhysicalVolume*> vol_vec { pVolume };
160 store->bmap.insert(std::make_pair(vol_name, vol_vec));
161 }
162 if (fgNotifier) { fgNotifier->NotifyRegistration(); }
163 store->mvalid = true;
164}
virtual void NotifyRegistration()=0

Referenced by G4VPhysicalVolume::G4VPhysicalVolume().

◆ SetMapValid()

void G4PhysicalVolumeStore::SetMapValid ( G4bool  val)
inline

Definition at line 78 of file G4PhysicalVolumeStore.hh.

78{ mvalid = val; }

Referenced by G4VPhysicalVolume::SetName().

◆ SetNotifier()

void G4PhysicalVolumeStore::SetNotifier ( G4VStoreNotifier pNotifier)
static

Definition at line 110 of file G4PhysicalVolumeStore.cc.

111{
112 GetInstance();
113 fgNotifier = pNotifier;
114}

◆ UpdateMap()

void G4PhysicalVolumeStore::UpdateMap ( )

Definition at line 120 of file G4PhysicalVolumeStore.cc.

121{
122 G4AutoLock l(&mapMutex); // to avoid thread contention at initialisation
123 if (mvalid) return;
124 bmap.clear();
125 for(auto pos=GetInstance()->cbegin(); pos!=GetInstance()->cend(); ++pos)
126 {
127 const G4String& vol_name = (*pos)->GetName();
128 auto it = bmap.find(vol_name);
129 if (it != bmap.cend())
130 {
131 it->second.push_back(*pos);
132 }
133 else
134 {
135 std::vector<G4VPhysicalVolume*> vol_vec { *pos };
136 bmap.insert(std::make_pair(vol_name, vol_vec));
137 }
138 }
139 mvalid = true;
140 l.unlock();
141}

Referenced by GetVolume(), and G4GDMLRead::StripNames().


The documentation for this class was generated from the following files: