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

#include <G4LogicalVolumeStore.hh>

Inheritance diagram for G4LogicalVolumeStore:

Public Member Functions

 G4LogicalVolumeStore (const G4LogicalVolumeStore &)=delete
 
const std::map< G4String, std::vector< G4LogicalVolume * > > & GetMap () const
 
G4LogicalVolumeGetVolume (const G4String &name, G4bool verbose=true, G4bool reverseSearch=false) const
 
G4bool IsMapValid () const
 
G4LogicalVolumeStoreoperator= (const G4LogicalVolumeStore &)=delete
 
void SetMapValid (G4bool val)
 
void UpdateMap ()
 
virtual ~G4LogicalVolumeStore ()
 

Static Public Member Functions

static void Clean ()
 
static void DeRegister (G4LogicalVolume *pVolume)
 
static G4LogicalVolumeStoreGetInstance ()
 
static void Register (G4LogicalVolume *pVolume)
 
static void SetNotifier (G4VStoreNotifier *pNotifier)
 

Protected Member Functions

 G4LogicalVolumeStore ()
 

Private Attributes

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

Static Private Attributes

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

Detailed Description

Definition at line 55 of file G4LogicalVolumeStore.hh.

Constructor & Destructor Documentation

◆ ~G4LogicalVolumeStore()

G4LogicalVolumeStore::~G4LogicalVolumeStore ( )
virtual

Definition at line 65 of file G4LogicalVolumeStore.cc.

66{
67 Clean(); // Delete all volumes in the store
68 G4LogicalVolume::Clean(); // Delete allocated sub-instance data
69}
static void Clean()

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

◆ G4LogicalVolumeStore() [1/2]

G4LogicalVolumeStore::G4LogicalVolumeStore ( const G4LogicalVolumeStore )
delete

◆ G4LogicalVolumeStore() [2/2]

G4LogicalVolumeStore::G4LogicalVolumeStore ( )
protected

Definition at line 55 of file G4LogicalVolumeStore.cc.

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

Member Function Documentation

◆ Clean()

void G4LogicalVolumeStore::Clean ( )
static

Definition at line 75 of file G4LogicalVolumeStore.cc.

76{
77 // Do nothing if geometry is closed
78 //
80 {
81 G4cout << "WARNING - Attempt to delete the logical volume store"
82 << " while geometry closed !" << G4endl;
83 return;
84 }
85
86 // Locks store for deletion of volumes. De-registration will be
87 // performed at this stage. G4LogicalVolumes will not de-register themselves.
88 //
89 locked = true;
90
91 std::size_t i = 0;
93
94#ifdef G4GEOMETRY_VOXELDEBUG
95 G4cout << "Deleting Logical Volumes ... ";
96#endif
97
98 for(auto pos=store->cbegin(); pos!=store->cend(); ++pos)
99 {
100 if (fgNotifier != nullptr) { fgNotifier->NotifyDeRegistration(); }
101 if (*pos != nullptr) { (*pos)->Lock(); delete *pos; }
102 ++i;
103 }
104
105#ifdef G4GEOMETRY_VOXELDEBUG
106 if (store->size() < i-1)
107 { G4cout << "No volumes deleted. Already deleted by user ?" << G4endl; }
108 else
109 { G4cout << i-1 << " volumes deleted !" << G4endl; }
110#endif
111
112 store->bmap.clear(); store->mvalid = false;
113 locked = false;
114 store->clear();
115}
static const G4double pos
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
static G4bool IsGeometryClosed()
static G4ThreadLocal G4bool locked
static G4ThreadLocal G4VStoreNotifier * fgNotifier
static G4LogicalVolumeStore * GetInstance()
std::map< G4String, std::vector< G4LogicalVolume * > > bmap
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 ~G4LogicalVolumeStore().

◆ DeRegister()

void G4LogicalVolumeStore::DeRegister ( G4LogicalVolume pVolume)
static

Definition at line 181 of file G4LogicalVolumeStore.cc.

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

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

Referenced by G4LogicalVolume::~G4LogicalVolume().

◆ GetInstance()

G4LogicalVolumeStore * G4LogicalVolumeStore::GetInstance ( )
static

Definition at line 265 of file G4LogicalVolumeStore.cc.

266{
267 static G4LogicalVolumeStore worldStore;
268 if (fgInstance == nullptr)
269 {
270 fgInstance = &worldStore;
271 }
272 return fgInstance;
273}
static G4LogicalVolumeStore * fgInstance

References fgInstance.

Referenced by G4GeometryManager::BuildOptimisations(), G4RunManagerKernel::CheckRegularGeometry(), checkVol(), Clean(), G4VUserDetectorConstruction::CloneF(), G4VUserDetectorConstruction::CloneSD(), ExN03DetectorConstruction::ConstructCalorimeter(), DetectorConstruction::ConstructVolumes(), G4GeometryManager::DeleteOptimisations(), DeRegister(), G4RadioactiveDecay::DeselectAVolume(), G4ScoringCylinder::DumpLogVols(), G4Region::GetParentRegion(), G4GDMLReadStructure::GetVolume(), GetVolume(), G4GDMLParser::ImportRegions(), Register(), G4RunManager::ReinitializeGeometry(), G4RadioactiveDecay::SelectAllVolumes(), G4RadioactiveDecay::SelectAVolume(), G4VVisCommandGeometrySet::Set(), G4LogicalVolume::SetName(), G4GDMLMessenger::SetNewValue(), G4VisCommandGeometryList::SetNewValue(), G4VisCommandGeometryRestore::SetNewValue(), G4VisCommandSceneAddLogicalVolume::SetNewValue(), SetNotifier(), G4VUserDetectorConstruction::SetSensitiveDetector(), G4VUserParallelWorld::SetSensitiveDetector(), G4ScoringProbe::SetupGeometry(), G4ScoringRealWorld::SetupGeometry(), G4GDMLRead::StripNames(), G4WorkerThread::UpdateGeometryAndPhysicsVectorFromMaster(), and UpdateMap().

◆ GetMap()

const std::map< G4String, std::vector< G4LogicalVolume * > > & G4LogicalVolumeStore::GetMap ( ) const
inline

◆ GetVolume()

G4LogicalVolume * G4LogicalVolumeStore::GetVolume ( const G4String name,
G4bool  verbose = true,
G4bool  reverseSearch = false 
) const

Definition at line 223 of file G4LogicalVolumeStore.cc.

225{
227 if (!store->mvalid) { store->UpdateMap(); }
228 auto pos = store->bmap.find(name);
229 if(pos != store->bmap.cend())
230 {
231 if ((verbose) && (pos->second.size()>1))
232 {
233 std::ostringstream message;
234 message << "There exists more than ONE logical volume in store named: "
235 << name << "!" << G4endl
236 << "Returning the first found.";
237 G4Exception("G4LogicalVolumeStore::GetVolume()",
238 "GeomMgt1001", JustWarning, message);
239 }
240 if(reverseSearch)
241 {
242 return pos->second[pos->second.size()-1];
243 }
244 else
245 {
246 return pos->second[0];
247 }
248 }
249 if (verbose)
250 {
251 std::ostringstream message;
252 message << "Volume NOT found in store !" << G4endl
253 << " Volume " << name << " NOT found in store !" << G4endl
254 << " Returning NULL pointer.";
255 G4Exception("G4LogicalVolumeStore::GetVolume()",
256 "GeomMgt1001", JustWarning, message);
257 }
258 return nullptr;
259}
@ 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 G4RadioactiveDecay::DeselectAVolume(), G4GDMLReadStructure::GetVolume(), G4RadioactiveDecay::SelectAVolume(), G4GDMLMessenger::SetNewValue(), G4VisCommandSceneAddLogicalVolume::SetNewValue(), and G4ScoringProbe::SetupGeometry().

◆ IsMapValid()

G4bool G4LogicalVolumeStore::IsMapValid ( ) const
inline

Definition at line 76 of file G4LogicalVolumeStore.hh.

76{ return mvalid; }

References mvalid.

◆ operator=()

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

◆ Register()

void G4LogicalVolumeStore::Register ( G4LogicalVolume pVolume)
static

Definition at line 158 of file G4LogicalVolumeStore.cc.

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

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

Referenced by G4LogicalVolume::G4LogicalVolume().

◆ SetMapValid()

void G4LogicalVolumeStore::SetMapValid ( G4bool  val)
inline

Definition at line 77 of file G4LogicalVolumeStore.hh.

77{ mvalid = val; }

References mvalid.

Referenced by G4LogicalVolume::SetName().

◆ SetNotifier()

void G4LogicalVolumeStore::SetNotifier ( G4VStoreNotifier pNotifier)
static

Definition at line 121 of file G4LogicalVolumeStore.cc.

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

References fgNotifier, and GetInstance().

◆ UpdateMap()

void G4LogicalVolumeStore::UpdateMap ( )

Definition at line 131 of file G4LogicalVolumeStore.cc.

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

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

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

Field Documentation

◆ bmap

std::map<G4String, std::vector<G4LogicalVolume*> > G4LogicalVolumeStore::bmap
private

Definition at line 102 of file G4LogicalVolumeStore.hh.

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

◆ fgInstance

G4LogicalVolumeStore * G4LogicalVolumeStore::fgInstance = nullptr
staticprivate

Definition at line 98 of file G4LogicalVolumeStore.hh.

Referenced by GetInstance().

◆ fgNotifier

G4ThreadLocal G4VStoreNotifier * G4LogicalVolumeStore::fgNotifier = nullptr
staticprivate

Definition at line 99 of file G4LogicalVolumeStore.hh.

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

◆ locked

G4ThreadLocal G4bool G4LogicalVolumeStore::locked = false
staticprivate

Definition at line 100 of file G4LogicalVolumeStore.hh.

Referenced by Clean(), and DeRegister().

◆ mvalid

G4bool G4LogicalVolumeStore::mvalid = false
private

Definition at line 103 of file G4LogicalVolumeStore.hh.

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


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