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

G4RegionStore is a singleton class, acting as container for all geometrical regions, with functionality derived from std::vector<T>. All regions should be registered with G4RegionStore, and removed on their destruction. The underlying container initially has a capacity of 20. A map indexed by volume names is also recorded for fast search; pointers to regions with same name are stored in buckets. More...

#include <G4RegionStore.hh>

Inheritance diagram for G4RegionStore:

Public Member Functions

virtual ~G4RegionStore ()
 G4RegionStore (const G4RegionStore &)=delete
G4RegionStoreoperator= (const G4RegionStore &)=delete
G4bool IsModified () const
void ResetRegionModified ()
void UpdateMaterialList (G4VPhysicalVolume *currentWorld=nullptr)
G4RegionGetRegion (const G4String &name, G4bool verbose=true) const
G4bool IsMapValid () const
void SetMapValid (G4bool val)
const std::map< G4String, std::vector< G4Region * > > & GetMap () const
void UpdateMap ()
G4RegionFindOrCreateRegion (const G4String &name)
void SetWorldVolume ()

Static Public Member Functions

static void Register (G4Region *pRegion)
static void DeRegister (G4Region *pRegion)
static G4RegionStoreGetInstance ()
static void SetNotifier (G4VStoreNotifier *pNotifier)
static void Clean ()

Protected Member Functions

 G4RegionStore ()

Detailed Description

G4RegionStore is a singleton class, acting as container for all geometrical regions, with functionality derived from std::vector<T>. All regions should be registered with G4RegionStore, and removed on their destruction. The underlying container initially has a capacity of 20. A map indexed by volume names is also recorded for fast search; pointers to regions with same name are stored in buckets.

Definition at line 67 of file G4RegionStore.hh.

Constructor & Destructor Documentation

◆ ~G4RegionStore()

G4RegionStore::~G4RegionStore ( )
virtual

Destructor: takes care to delete allocated regions.

Definition at line 68 of file G4RegionStore.cc.

69{
70 Clean(); // Delete all regions in the store
71 G4Region::Clean(); // Delete allocated sub-instance data
72}
static void Clean()
static void Clean()
Definition G4Region.cc:369

◆ G4RegionStore() [1/2]

G4RegionStore::G4RegionStore ( const G4RegionStore & )
delete

Copy constructor and assignment operator not allowed.

Referenced by Clean(), DeRegister(), G4RegionStore(), GetInstance(), GetRegion(), operator=(), and Register().

◆ G4RegionStore() [2/2]

G4RegionStore::G4RegionStore ( )
protected

Protected singleton constructor.

Definition at line 58 of file G4RegionStore.cc.

60{
61 reserve(20);
62}

Member Function Documentation

◆ Clean()

void G4RegionStore::Clean ( )
static

Deletes all regions from the store, except for the world region.

Definition at line 78 of file G4RegionStore.cc.

79{
80 // Do nothing if geometry is closed
81 //
82 if (G4GeometryManager::GetInstance()->IsGeometryClosed())
83 {
84 G4cout << "WARNING - Attempt to delete the region store"
85 << " while geometry closed !" << G4endl;
86 return;
87 }
88
89 // Locks store for deletion of regions. De-registration will be
90 // performed at this stage. G4Regions will not de-register themselves.
91 //
92 locked = true;
93
94 G4RegionStore* store = GetInstance();
95
96 for(const auto & pos : *store)
97 {
98 if (fgNotifier != nullptr) { fgNotifier->NotifyDeRegistration(); }
99 delete pos;
100 }
101
102 store->bmap.clear(); store->mvalid = false;
103 locked = false;
104 store->clear();
105}
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout
static G4GeometryManager * GetInstance()
static G4RegionStore * GetInstance()
G4RegionStore(const G4RegionStore &)=delete

Referenced by ~G4RegionStore().

◆ DeRegister()

void G4RegionStore::DeRegister ( G4Region * pRegion)
static

Removes the region 'pRegion' from the collection.

Definition at line 171 of file G4RegionStore.cc.

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

Referenced by G4Region::~G4Region().

◆ FindOrCreateRegion()

G4Region * G4RegionStore::FindOrCreateRegion ( const G4String & name)

Returns a pointer to a region through its name specification, if it exists. If it does not exist, it will allocate one, delegating ownership to the client.

Definition at line 303 of file G4RegionStore.cc.

304{
305 G4Region* target = GetRegion(name,false);
306 if (target == nullptr)
307 {
308 target = new G4Region(name);
309 }
310 return target;
311}
G4Region * GetRegion(const G4String &name, G4bool verbose=true) const

◆ GetInstance()

G4RegionStore * G4RegionStore::GetInstance ( )
static

Returns a pointer to the unique instance of G4RegionStore, creating it if necessary.

Definition at line 212 of file G4RegionStore.cc.

213{
214 static G4RegionStore worldStore;
215 if (fgInstance == nullptr)
216 {
217 fgInstance = &worldStore;
218 }
219 return fgInstance;
220}

Referenced by G4EmBiasingManager::ActivateForcedInteraction(), G4EmBiasingManager::ActivateSecondaryBiasing(), G4LowECapture::BuildPhysicsTable(), G4MicroElecCapture::BuildPhysicsTable(), G4RunManagerKernel::CheckRegions(), Clean(), G4CoherentPairProductionPhysics::ConstructProcess(), G4TheRayTracer::CreateBitMap(), G4EmExtraParameters::DefineRegParamForLoss(), DeRegister(), G4RunManagerKernel::DumpRegion(), G4RunManagerKernel::DumpRegion(), G4EmUtility::FillFluctFlags(), G4EmCalculator::FindCouple(), G4EmUtility::FindRegion(), G4ProductionCutsTable::G4ProductionCutsTable(), G4Region::G4Region(), G4Region::G4Region(), G4RunManagerKernel::G4RunManagerKernel(), G4VUserPhysicsList::GetCutValue(), GetRegion(), G4EmModelManager::Initialise(), G4PAIModel::Initialise(), G4PAIPhotModel::Initialise(), G4VAtomDeexcitation::InitialiseAtomicDeexcitation(), IsModified(), Register(), G4RunManager::ReinitializeGeometry(), ResetRegionModified(), G4VUserPhysicsList::SetCutValue(), G4VAtomDeexcitation::SetDeexcitationActiveRegion(), G4ScoringProbe::SetMaterial(), G4Region::SetName(), SetNotifier(), G4VUserPhysicsList::SetParticleCuts(), G4MaterialScanner::SetRegionName(), G4ScoringProbe::SetupGeometry(), SetWorldVolume(), G4GlobalFastSimulationManager::ShowSetup(), G4WorkerThread::UpdateGeometryAndPhysicsVectorFromMaster(), UpdateMap(), UpdateMaterialList(), G4RunManagerKernel::UpdateRegion(), and G4Region::~G4Region().

◆ GetMap()

const std::map< G4String, std::vector< G4Region * > > & G4RegionStore::GetMap ( ) const
inline

Returns the internal map.

Definition at line 142 of file G4RegionStore.hh.

142{ return bmap; }

◆ GetRegion()

G4Region * G4RegionStore::GetRegion ( const G4String & name,
G4bool verbose = true ) const

Returns a pointer to a region through its name specification. It uses the internal map for fast search and warns if a region in the collection is not unique or not found.

Definition at line 267 of file G4RegionStore.cc.

268{
269 G4RegionStore* store = GetInstance();
270 if (!store->mvalid) { store->UpdateMap(); }
271 auto pos = store->bmap.find(name);
272 if(pos != store->bmap.cend())
273 {
274 if ((verbose) && (pos->second.size()>1))
275 {
276 std::ostringstream message;
277 message << "There exists more than ONE region in store named: "
278 << name << "!" << G4endl
279 << "Returning the first found.";
280 G4Exception("G4RegionStore::GetSolid()",
281 "GeomMgt1001", JustWarning, message);
282 }
283 return pos->second[0];
284 }
285 if (verbose)
286 {
287 std::ostringstream message;
288 message << "Region NOT found in store !" << G4endl
289 << " Region " << name << " NOT found in store !" << G4endl
290 << " Returning NULL pointer.";
291 G4Exception("G4RegionStore::GetRegion()",
292 "GeomMgt1001", JustWarning, message);
293 }
294 return nullptr;
295}
@ JustWarning
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
const char * name(G4int ptype)

Referenced by G4EmBiasingManager::ActivateForcedInteraction(), G4EmBiasingManager::ActivateSecondaryBiasing(), G4LowECapture::BuildPhysicsTable(), G4CoherentPairProductionPhysics::ConstructProcess(), G4EmExtraParameters::DefineRegParamForLoss(), G4RunManagerKernel::DumpRegion(), G4EmUtility::FillFluctFlags(), FindOrCreateRegion(), G4EmUtility::FindRegion(), G4Region::G4Region(), G4RunManagerKernel::G4RunManagerKernel(), G4VUserPhysicsList::GetCutValue(), G4EmModelManager::Initialise(), G4VAtomDeexcitation::InitialiseAtomicDeexcitation(), G4VUserPhysicsList::SetCutValue(), G4ScoringProbe::SetMaterial(), G4VUserPhysicsList::SetParticleCuts(), G4MaterialScanner::SetRegionName(), and G4ScoringProbe::SetupGeometry().

◆ IsMapValid()

G4bool G4RegionStore::IsMapValid ( ) const
inline

Accessor and modifier to assess validity of the internal map.

Definition at line 135 of file G4RegionStore.hh.

135{ return mvalid; }

◆ IsModified()

G4bool G4RegionStore::IsModified ( ) const

Loops through all regions to verify if a region has been modified.

Returns
true if just one region is modified.

Definition at line 227 of file G4RegionStore.cc.

228{
229 for (const auto & i : *GetInstance())
230 {
231 if (i->IsModified()) { return true; }
232 }
233 return false;
234}

◆ operator=()

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

◆ Register()

void G4RegionStore::Register ( G4Region * pRegion)
static

Adds the region 'pRegion' to the collection.

Definition at line 148 of file G4RegionStore.cc.

149{
150 G4RegionStore* store = GetInstance();
151 store->push_back(pRegion);
152 const G4String& reg_name = pRegion->GetName();
153 auto it = store->bmap.find(reg_name);
154 if (it != store->bmap.cend())
155 {
156 it->second.push_back(pRegion);
157 }
158 else
159 {
160 std::vector<G4Region*> reg_vec { pRegion };
161 store->bmap.insert(std::make_pair(reg_name, reg_vec));
162 }
163 if (fgNotifier != nullptr) { fgNotifier->NotifyRegistration(); }
164 store->mvalid = true;
165}

Referenced by G4Region::G4Region(), and G4Region::G4Region().

◆ ResetRegionModified()

void G4RegionStore::ResetRegionModified ( )

Loops through all regions to reset the flag for modification to false. Used by the run manager to notify that the physics table has been updated.

Definition at line 241 of file G4RegionStore.cc.

242{
243 for (const auto & i : *GetInstance())
244 {
245 i->RegionModified(false);
246 }
247}

◆ SetMapValid()

void G4RegionStore::SetMapValid ( G4bool val)
inline

Definition at line 136 of file G4RegionStore.hh.

136{ mvalid = val; }

Referenced by G4Region::SetName().

◆ SetNotifier()

void G4RegionStore::SetNotifier ( G4VStoreNotifier * pNotifier)
static

Assigns a notifier for allocation/deallocation of regions.

Definition at line 111 of file G4RegionStore.cc.

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

◆ SetWorldVolume()

void G4RegionStore::SetWorldVolume ( )

Sets a world volume pointer to a region that belongs to it. Scans over all world volumes. This method should be exclusively used by G4RunManagerKernel.

Definition at line 318 of file G4RegionStore.cc.

319{
320 // Reset all pointers first
321 //
322 for (const auto & i : *GetInstance())
323 { i->SetWorld(nullptr); }
324
325 // Find world volumes
326 //
327 G4PhysicalVolumeStore* fPhysicalVolumeStore
329 std::size_t nPhys = fPhysicalVolumeStore->size();
330 for(std::size_t iPhys=0; iPhys<nPhys; ++iPhys)
331 {
332 G4VPhysicalVolume* fPhys = (*fPhysicalVolumeStore)[iPhys];
333 if(fPhys->GetMotherLogical() != nullptr) { continue; } // not a world volume
334
335 // Now 'fPhys' is a world volume, set it to regions that belong to it.
336 //
337 for (const auto & i : *GetInstance())
338 { i->SetWorld(fPhys); }
339 }
340}
static G4PhysicalVolumeStore * GetInstance()
G4LogicalVolume * GetMotherLogical() const

◆ UpdateMap()

void G4RegionStore::UpdateMap ( )

Brings contents of the internal map up to date and resets validity flag.

Definition at line 121 of file G4RegionStore.cc.

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

Referenced by GetRegion().

◆ UpdateMaterialList()

void G4RegionStore::UpdateMaterialList ( G4VPhysicalVolume * currentWorld = nullptr)

Forces recomputation of the material lists in all regions in the store.

Definition at line 253 of file G4RegionStore.cc.

254{
255 for (const auto & i : *GetInstance())
256 {
257 if(i->IsInMassGeometry() || i->IsInParallelGeometry()
258 || (currentWorld != nullptr))
259 { i->UpdateMaterialList(); }
260 }
261}

Referenced by G4TheRayTracer::CreateBitMap(), and G4RunManagerKernel::UpdateRegion().


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