Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4RegionStore.hh
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26// G4RegionStore
27//
28// Class description:
29//
30// Container for all regions, with functionality derived from
31// std::vector<T>. The class is a 'singleton', in that only
32// one can exist, and access is provided via the static method
33// G4RegionStore::GetInstance().
34//
35// All regions should be registered with G4RegionStore, and removed on their
36// destruction. The underlying container initially has a capacity of 20.
37// A map indexed by volume names is also recorded for fast search;
38// pointers to regions with same name are stored in buckets.
39//
40// If much additional functionality is added, should consider containment
41// instead of inheritance for std::vector<T>.
42
43// Author: Gabriele Cosmo (CERN), 18.09.2002
44// --------------------------------------------------------------------
45#ifndef G4REGIONSTORE_HH
46#define G4REGIONSTORE_HH
47
48#include <vector>
49#include <map>
50
51#include "G4Types.hh"
52#include "G4String.hh"
53#include "G4VStoreNotifier.hh"
54
55class G4Region;
57
58/**
59 * @brief G4RegionStore is a singleton class, acting as container
60 * for all geometrical regions, with functionality derived from std::vector<T>.
61 * All regions should be registered with G4RegionStore, and removed on their
62 * destruction. The underlying container initially has a capacity of 20.
63 * A map indexed by volume names is also recorded for fast search; pointers
64 * to regions with same name are stored in buckets.
65*/
66
67class G4RegionStore : public std::vector<G4Region*>
68{
69 public:
70
71 /**
72 * Destructor: takes care to delete allocated regions.
73 */
74 virtual ~G4RegionStore();
75
76 /**
77 * Copy constructor and assignment operator not allowed.
78 */
79 G4RegionStore(const G4RegionStore&) = delete;
81
82 /**
83 * Adds the region 'pRegion' to the collection.
84 */
85 static void Register(G4Region* pRegion);
86
87 /**
88 * Removes the region 'pRegion' from the collection.
89 */
90 static void DeRegister(G4Region* pRegion);
91
92 /**
93 * Returns a pointer to the unique instance of G4RegionStore,
94 * creating it if necessary.
95 */
96 static G4RegionStore* GetInstance();
97
98 /**
99 * Assigns a notifier for allocation/deallocation of regions.
100 */
101 static void SetNotifier(G4VStoreNotifier* pNotifier);
102
103 /**
104 * Deletes all regions from the store, except for the world region.
105 */
106 static void Clean();
107
108 /**
109 * Loops through all regions to verify if a region has been modified.
110 * @returns true if just one region is modified.
111 */
112 G4bool IsModified() const;
113
114 /**
115 * Loops through all regions to reset the flag for modification to false.
116 * Used by the run manager to notify that the physics table has been updated.
117 */
118 void ResetRegionModified();
119
120 /**
121 * Forces recomputation of the material lists in all regions in the store.
122 */
123 void UpdateMaterialList(G4VPhysicalVolume* currentWorld = nullptr);
124
125 /**
126 * Returns a pointer to a region through its name specification.
127 * It uses the internal map for fast search and warns if a region in the
128 * collection is not unique or not found.
129 */
130 G4Region* GetRegion(const G4String& name, G4bool verbose = true) const;
131
132 /**
133 * Accessor and modifier to assess validity of the internal map.
134 */
135 inline G4bool IsMapValid() const { return mvalid; }
136 inline void SetMapValid(G4bool val) { mvalid = val; }
137
138 /**
139 * Returns the internal map.
140 */
141 inline const std::map<G4String,
142 std::vector<G4Region*> >& GetMap() const { return bmap; }
143
144 /**
145 * Brings contents of the internal map up to date and resets validity flag.
146 */
147 void UpdateMap();
148
149 /**
150 * Returns a pointer to a region through its name specification, if it
151 * exists. If it does not exist, it will allocate one, delegating ownership
152 * to the client.
153 */
155
156 /**
157 * Sets a world volume pointer to a region that belongs to it.
158 * Scans over all world volumes. This method should be exclusively
159 * used by G4RunManagerKernel.
160 */
161 void SetWorldVolume();
162
163 protected:
164
165 /**
166 * Protected singleton constructor.
167 */
169
170 private:
171
172 static G4RegionStore* fgInstance;
173 static G4ThreadLocal G4VStoreNotifier* fgNotifier;
174 static G4ThreadLocal G4bool locked;
175
176 std::map<G4String, std::vector<G4Region*> > bmap;
177 G4bool mvalid = false; // Flag to indicate if map is up to date or not
178};
179
180#endif
bool G4bool
Definition G4Types.hh:86
G4VNotifier G4VStoreNotifier
G4VStoreNotifier is a simple abstract class allowing for the implementation of user notifiers to be a...
G4RegionStore is a singleton class, acting as container for all geometrical regions,...
static void DeRegister(G4Region *pRegion)
static void Register(G4Region *pRegion)
static G4RegionStore * GetInstance()
static void SetNotifier(G4VStoreNotifier *pNotifier)
void UpdateMaterialList(G4VPhysicalVolume *currentWorld=nullptr)
virtual ~G4RegionStore()
const std::map< G4String, std::vector< G4Region * > > & GetMap() const
static void Clean()
G4Region * GetRegion(const G4String &name, G4bool verbose=true) const
G4bool IsMapValid() const
G4Region * FindOrCreateRegion(const G4String &name)
void SetMapValid(G4bool val)
void ResetRegionModified()
G4RegionStore & operator=(const G4RegionStore &)=delete
G4RegionStore(const G4RegionStore &)=delete
G4bool IsModified() const
G4Region defines a region or a group of regions in the detector geometry setup, sharing properties as...
Definition G4Region.hh:90
G4VPhysicalVolume is an abstract base class for the representation of a positioned volume....
#define G4ThreadLocal
Definition tls.hh:77