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

#include <G4RegionStore.hh>

Inheritance diagram for G4RegionStore:

Public Member Functions

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

Static Public Member Functions

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

Protected Member Functions

 G4RegionStore ()
 

Private Attributes

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

Static Private Attributes

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

Detailed Description

Definition at line 58 of file G4RegionStore.hh.

Constructor & Destructor Documentation

◆ ~G4RegionStore()

G4RegionStore::~G4RegionStore ( )
virtual

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:356

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

◆ G4RegionStore() [1/2]

G4RegionStore::G4RegionStore ( const G4RegionStore )
delete

◆ G4RegionStore() [2/2]

G4RegionStore::G4RegionStore ( )
protected

Definition at line 58 of file G4RegionStore.cc.

59 : std::vector<G4Region*>()
60{
61 reserve(20);
62}

Member Function Documentation

◆ Clean()

void G4RegionStore::Clean ( )
static

Definition at line 78 of file G4RegionStore.cc.

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

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

Referenced by ~G4RegionStore().

◆ DeRegister()

void G4RegionStore::DeRegister ( G4Region pRegion)
static

Definition at line 183 of file G4RegionStore.cc.

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

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

Referenced by G4Region::~G4Region().

◆ FindOrCreateRegion()

G4Region * G4RegionStore::FindOrCreateRegion ( const G4String name)

Definition at line 315 of file G4RegionStore.cc.

316{
317 G4Region* target = GetRegion(name,false);
318 if (target == nullptr)
319 {
320 target = new G4Region(name);
321 }
322 return target;
323}
G4Region * GetRegion(const G4String &name, G4bool verbose=true) const
const char * name(G4int ptype)

References GetRegion(), and G4InuclParticleNames::name().

◆ GetInstance()

G4RegionStore * G4RegionStore::GetInstance ( )
static

Definition at line 224 of file G4RegionStore.cc.

225{
226 static G4RegionStore worldStore;
227 if (fgInstance == nullptr)
228 {
229 fgInstance = &worldStore;
230 }
231 return fgInstance;
232}
static G4RegionStore * fgInstance

References fgInstance.

Referenced by G4EmBiasingManager::ActivateForcedInteraction(), G4EmModelActivator::ActivatePAI(), G4EmBiasingManager::ActivateSecondaryBiasing(), G4LowECapture::BuildPhysicsTable(), G4RunManagerKernel::CheckRegions(), Clean(), G4TheRayTracer::CreateBitMap(), G4EmExtraParameters::DefineRegParamForLoss(), DeRegister(), G4RunManagerKernel::DumpRegion(), G4GDMLParser::ExportRegions(), G4EmCalculator::FindCouple(), G4EmCalculator::FindRegion(), G4EmConfigurator::FindRegion(), G4ProductionCutsTable::G4ProductionCutsTable(), G4Region::G4Region(), G4RunManagerKernel::G4RunManagerKernel(), G4VUserPhysicsList::GetCutValue(), GetRegion(), G4PAIModel::Initialise(), G4PAIPhotModel::Initialise(), G4EmModelManager::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

Definition at line 94 of file G4RegionStore.hh.

94{ return bmap; }

References bmap.

◆ GetRegion()

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

Definition at line 279 of file G4RegionStore.cc.

280{
281 G4RegionStore* store = GetInstance();
282 if (!store->mvalid) { store->UpdateMap(); }
283 auto pos = store->bmap.find(name);
284 if(pos != store->bmap.cend())
285 {
286 if ((verbose) && (pos->second.size()>1))
287 {
288 std::ostringstream message;
289 message << "There exists more than ONE region in store named: "
290 << name << "!" << G4endl
291 << "Returning the first found.";
292 G4Exception("G4RegionStore::GetSolid()",
293 "GeomMgt1001", JustWarning, message);
294 }
295 return pos->second[0];
296 }
297 if (verbose)
298 {
299 std::ostringstream message;
300 message << "Region NOT found in store !" << G4endl
301 << " Region " << name << " NOT found in store !" << G4endl
302 << " Returning NULL pointer.";
303 G4Exception("G4RegionStore::GetRegion()",
304 "GeomMgt1001", JustWarning, message);
305 }
306 return nullptr;
307}
@ JustWarning
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35

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

Referenced by G4EmBiasingManager::ActivateForcedInteraction(), G4EmModelActivator::ActivatePAI(), G4EmBiasingManager::ActivateSecondaryBiasing(), G4LowECapture::BuildPhysicsTable(), G4ProductionCutsTable::CheckMaterialCutsCoupleInfo(), G4EmExtraParameters::DefineRegParamForLoss(), G4RunManagerKernel::DumpRegion(), FindOrCreateRegion(), G4EmCalculator::FindRegion(), G4EmConfigurator::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

Definition at line 90 of file G4RegionStore.hh.

90{ return mvalid; }

References mvalid.

◆ IsModified()

G4bool G4RegionStore::IsModified ( ) const

Definition at line 239 of file G4RegionStore.cc.

240{
241 for (auto i=GetInstance()->cbegin(); i!=GetInstance()->cend(); ++i)
242 {
243 if ((*i)->IsModified()) { return true; }
244 }
245 return false;
246}

References GetInstance().

◆ operator=()

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

◆ Register()

void G4RegionStore::Register ( G4Region pRegion)
static

Definition at line 160 of file G4RegionStore.cc.

161{
162 G4RegionStore* store = GetInstance();
163 store->push_back(pRegion);
164 const G4String& reg_name = pRegion->GetName();
165 auto it = store->bmap.find(reg_name);
166 if (it != store->bmap.cend())
167 {
168 it->second.push_back(pRegion);
169 }
170 else
171 {
172 std::vector<G4Region*> reg_vec { pRegion };
173 store->bmap.insert(std::make_pair(reg_name, reg_vec));
174 }
176 store->mvalid = true;
177}
virtual void NotifyRegistration()=0

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

Referenced by G4Region::G4Region().

◆ ResetRegionModified()

void G4RegionStore::ResetRegionModified ( )

Definition at line 253 of file G4RegionStore.cc.

254{
255 for (auto i=GetInstance()->cbegin(); i!=GetInstance()->cend(); ++i)
256 {
257 (*i)->RegionModified(false);
258 }
259}

References GetInstance().

◆ SetMapValid()

void G4RegionStore::SetMapValid ( G4bool  val)
inline

Definition at line 91 of file G4RegionStore.hh.

91{ mvalid = val; }

References mvalid.

Referenced by G4Region::SetName().

◆ SetNotifier()

void G4RegionStore::SetNotifier ( G4VStoreNotifier pNotifier)
static

Definition at line 123 of file G4RegionStore.cc.

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

References fgNotifier, and GetInstance().

◆ SetWorldVolume()

void G4RegionStore::SetWorldVolume ( )

Definition at line 330 of file G4RegionStore.cc.

331{
332 // Reset all pointers first
333 //
334 for (auto i=GetInstance()->cbegin(); i!=GetInstance()->cend(); ++i)
335 { (*i)->SetWorld(nullptr); }
336
337 // Find world volumes
338 //
339 G4PhysicalVolumeStore* fPhysicalVolumeStore
341 size_t nPhys = fPhysicalVolumeStore->size();
342 for(size_t iPhys=0; iPhys<nPhys; ++iPhys)
343 {
344 G4VPhysicalVolume* fPhys = (*fPhysicalVolumeStore)[iPhys];
345 if(fPhys->GetMotherLogical() != nullptr) { continue; } // not a world volume
346
347 // Now 'fPhys' is a world volume, set it to regions that belong to it.
348 //
349 for (auto i=GetInstance()->cbegin(); i!=GetInstance()->cend(); ++i)
350 { (*i)->SetWorld(fPhys); }
351 }
352}
static G4PhysicalVolumeStore * GetInstance()
G4LogicalVolume * GetMotherLogical() const

References G4PhysicalVolumeStore::GetInstance(), GetInstance(), and G4VPhysicalVolume::GetMotherLogical().

◆ UpdateMap()

void G4RegionStore::UpdateMap ( )

Definition at line 133 of file G4RegionStore.cc.

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

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

Referenced by GetRegion().

◆ UpdateMaterialList()

void G4RegionStore::UpdateMaterialList ( G4VPhysicalVolume currentWorld = nullptr)

Definition at line 265 of file G4RegionStore.cc.

266{
267 for (auto i=GetInstance()->cbegin(); i!=GetInstance()->cend(); ++i)
268 {
269 if((*i)->IsInMassGeometry() || (*i)->IsInParallelGeometry()
270 || (currentWorld != nullptr))
271 { (*i)->UpdateMaterialList(); }
272 }
273}

References GetInstance().

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

Field Documentation

◆ bmap

std::map<G4String, std::vector<G4Region*> > G4RegionStore::bmap
private

Definition at line 127 of file G4RegionStore.hh.

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

◆ fgInstance

G4RegionStore * G4RegionStore::fgInstance = nullptr
staticprivate

Definition at line 123 of file G4RegionStore.hh.

Referenced by GetInstance().

◆ fgNotifier

G4ThreadLocal G4VStoreNotifier * G4RegionStore::fgNotifier = nullptr
staticprivate

Definition at line 124 of file G4RegionStore.hh.

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

◆ locked

G4ThreadLocal G4bool G4RegionStore::locked = false
staticprivate

Definition at line 125 of file G4RegionStore.hh.

Referenced by Clean(), and DeRegister().

◆ mvalid

G4bool G4RegionStore::mvalid = false
private

Definition at line 128 of file G4RegionStore.hh.

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


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