Geant4-11
Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Attributes | Static Private Attributes
G4PhysicalVolumeStore Class Reference

#include <G4PhysicalVolumeStore.hh>

Inheritance diagram for G4PhysicalVolumeStore:

Public Member Functions

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

Static Public Member Functions

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

Protected Member Functions

 G4PhysicalVolumeStore ()
 

Private Attributes

std::map< G4String, std::vector< G4VPhysicalVolume * > > bmap
 
G4bool mvalid = false
 

Static Private Attributes

static G4PhysicalVolumeStorefgInstance = nullptr
 
static G4ThreadLocal G4VStoreNotifierfgNotifier = nullptr
 
static G4ThreadLocal G4bool locked = false
 

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}

References Clean(), and G4VPhysicalVolume::Clean().

◆ 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
93 std::size_t i=0;
95
96#ifdef G4GEOMETRY_VOXELDEBUG
97 G4cout << "Deleting Physical Volumes ... ";
98#endif
99
100 for(auto pos=store->cbegin(); pos!=store->cend(); ++pos)
101 {
102 if (fgNotifier != nullptr) { fgNotifier->NotifyDeRegistration(); }
103 delete *pos; ++i;
104 }
105
106#ifdef G4GEOMETRY_VOXELDEBUG
107 if (store->size() < i-1)
108 { G4cout << "No volumes deleted. Already deleted by user ?" << G4endl; }
109 else
110 { G4cout << i-1 << " volumes deleted !" << G4endl; }
111#endif
112
113 store->bmap.clear(); store->mvalid = false;
114 locked = false;
115 store->clear();
116}
static const G4double pos
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
static G4bool IsGeometryClosed()
static G4PhysicalVolumeStore * GetInstance()
static G4ThreadLocal G4VStoreNotifier * fgNotifier
std::map< G4String, std::vector< G4VPhysicalVolume * > > bmap
static G4ThreadLocal G4bool locked
virtual void NotifyDeRegistration()=0

References bmap, fgNotifier, G4cout, G4endl, GetInstance(), G4GeometryManager::IsGeometryClosed(), locked, mvalid, G4VNotifier::NotifyDeRegistration(), and pos.

Referenced by ExN03DetectorConstruction::ConstructCalorimeter(), DetectorConstruction::ConstructVolumes(), G4RunManager::ReinitializeGeometry(), and ~G4PhysicalVolumeStore().

◆ DeRegister()

void G4PhysicalVolumeStore::DeRegister ( G4VPhysicalVolume pSolid)
static

Definition at line 183 of file G4PhysicalVolumeStore.cc.

184{
186 if (!locked) // Do not de-register if locked !
187 {
188 if (fgNotifier != nullptr) { fgNotifier->NotifyDeRegistration(); }
189 G4LogicalVolume* motherLogical = pVolume->GetMotherLogical();
190 if (motherLogical != nullptr) { motherLogical->RemoveDaughter(pVolume); }
191 for (auto i=store->cbegin(); i!=store->cend(); ++i)
192 {
193 if (**i==*pVolume)
194 {
195 store->erase(i);
196 break;
197 }
198 }
199 const G4String& vol_name = pVolume->GetName();
200 auto it = store->bmap.find(vol_name);
201 if (it != store->bmap.cend())
202 {
203 if (it->second.size() > 1)
204 {
205 for (auto i=it->second.cbegin(); i!=it->second.cend(); ++i)
206 {
207 if (**i==*pVolume)
208 {
209 it->second.erase(i);
210 break;
211 }
212 }
213 }
214 else
215 {
216 store->bmap.erase(it);
217 }
218 }
219 }
220}
void RemoveDaughter(const G4VPhysicalVolume *p)

References bmap, fgNotifier, GetInstance(), G4VPhysicalVolume::GetMotherLogical(), G4VPhysicalVolume::GetName(), locked, G4VNotifier::NotifyDeRegistration(), and G4LogicalVolume::RemoveDaughter().

Referenced by G4VPhysicalVolume::~G4VPhysicalVolume().

◆ GetInstance()

G4PhysicalVolumeStore * G4PhysicalVolumeStore::GetInstance ( )
static

◆ GetMap()

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

Definition at line 81 of file G4PhysicalVolumeStore.hh.

81{ return bmap; }

References bmap.

◆ GetVolume()

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

Definition at line 227 of file G4PhysicalVolumeStore.cc.

229{
231 if (!store->mvalid) { store->UpdateMap(); }
232 auto pos = store->bmap.find(name);
233 if(pos != store->bmap.cend())
234 {
235 if ((verbose) && (pos->second.size()>1))
236 {
237 std::ostringstream message;
238 message << "There exists more than ONE physical volume in store named: "
239 << name << "!" << G4endl
240 << "Returning the first found.";
241 G4Exception("G4PhysicalVolumeStore::GetVolume()",
242 "GeomMgt1001", JustWarning, message);
243 }
244 if(reverseSearch)
245 {
246 return pos->second[pos->second.size()-1];
247 }
248 else
249 {
250 return pos->second[0];
251 }
252 }
253 if (verbose)
254 {
255 std::ostringstream message;
256 message << "Volume NOT found in store !" << G4endl
257 << " Volume " << name << " NOT found in store !" << G4endl
258 << " Returning NULL pointer.";
259 G4Exception("G4PhysicalVolumeStore::GetVolume()",
260 "GeomMgt1001", JustWarning, message);
261 }
262 return nullptr;
263}
@ JustWarning
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
const char * name(G4int ptype)

References bmap, G4endl, G4Exception(), GetInstance(), JustWarning, mvalid, G4InuclParticleNames::name(), pos, and UpdateMap().

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; }

References mvalid.

◆ operator=()

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

◆ Register()

void G4PhysicalVolumeStore::Register ( G4VPhysicalVolume pSolid)
static

Definition at line 159 of file G4PhysicalVolumeStore.cc.

160{
162 store->push_back(pVolume);
163 const G4String& vol_name = pVolume->GetName();
164 auto it = store->bmap.find(vol_name);
165 if (it != store->bmap.cend())
166 {
167 it->second.push_back(pVolume);
168 }
169 else
170 {
171 std::vector<G4VPhysicalVolume*> vol_vec { pVolume };
172 store->bmap.insert(std::make_pair(vol_name, vol_vec));
173 }
175 store->mvalid = true;
176}
virtual void NotifyRegistration()=0

References bmap, fgNotifier, GetInstance(), G4VPhysicalVolume::GetName(), mvalid, and G4VNotifier::NotifyRegistration().

Referenced by G4VPhysicalVolume::G4VPhysicalVolume().

◆ SetMapValid()

void G4PhysicalVolumeStore::SetMapValid ( G4bool  val)
inline

Definition at line 78 of file G4PhysicalVolumeStore.hh.

78{ mvalid = val; }

References mvalid.

Referenced by G4VPhysicalVolume::SetName().

◆ SetNotifier()

void G4PhysicalVolumeStore::SetNotifier ( G4VStoreNotifier pNotifier)
static

Definition at line 122 of file G4PhysicalVolumeStore.cc.

123{
124 GetInstance();
125 fgNotifier = pNotifier;
126}

References fgNotifier, and GetInstance().

◆ UpdateMap()

void G4PhysicalVolumeStore::UpdateMap ( )

Definition at line 132 of file G4PhysicalVolumeStore.cc.

133{
134 G4AutoLock l(&mapMutex); // to avoid thread contention at initialisation
135 if (mvalid) return;
136 bmap.clear();
137 for(auto pos=GetInstance()->cbegin(); pos!=GetInstance()->cend(); ++pos)
138 {
139 const G4String& vol_name = (*pos)->GetName();
140 auto it = bmap.find(vol_name);
141 if (it != bmap.cend())
142 {
143 it->second.push_back(*pos);
144 }
145 else
146 {
147 std::vector<G4VPhysicalVolume*> vol_vec { *pos };
148 bmap.insert(std::make_pair(vol_name, vol_vec));
149 }
150 }
151 mvalid = true;
152 l.unlock();
153}

References bmap, GetInstance(), anonymous_namespace{G4PhysicalVolumeStore.cc}::mapMutex, mvalid, pos, and G4TemplateAutoLock< _Mutex_t >::unlock().

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

Field Documentation

◆ bmap

std::map<G4String, std::vector<G4VPhysicalVolume*> > G4PhysicalVolumeStore::bmap
private

Definition at line 103 of file G4PhysicalVolumeStore.hh.

Referenced by Clean(), DeRegister(), GetMap(), GetVolume(), Register(), and UpdateMap().

◆ fgInstance

G4PhysicalVolumeStore * G4PhysicalVolumeStore::fgInstance = nullptr
staticprivate

Definition at line 99 of file G4PhysicalVolumeStore.hh.

Referenced by GetInstance().

◆ fgNotifier

G4ThreadLocal G4VStoreNotifier * G4PhysicalVolumeStore::fgNotifier = nullptr
staticprivate

Definition at line 100 of file G4PhysicalVolumeStore.hh.

Referenced by Clean(), DeRegister(), Register(), and SetNotifier().

◆ locked

G4ThreadLocal G4bool G4PhysicalVolumeStore::locked = false
staticprivate

Definition at line 101 of file G4PhysicalVolumeStore.hh.

Referenced by Clean(), and DeRegister().

◆ mvalid

G4bool G4PhysicalVolumeStore::mvalid = false
private

Definition at line 104 of file G4PhysicalVolumeStore.hh.

Referenced by Clean(), GetVolume(), IsMapValid(), Register(), SetMapValid(), and UpdateMap().


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