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

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

#include <G4SolidStore.hh>

Inheritance diagram for G4SolidStore:

Public Member Functions

virtual ~G4SolidStore ()
 G4SolidStore (const G4SolidStore &)=delete
G4SolidStoreoperator= (const G4SolidStore &)=delete
G4VSolidGetSolid (const G4String &name, G4bool verbose=true, G4bool reverseSearch=false) const
G4bool IsMapValid () const
void SetMapValid (G4bool val)
const std::map< G4String, std::vector< G4VSolid * > > & GetMap () const
void UpdateMap ()

Static Public Member Functions

static void Register (G4VSolid *pSolid)
static void DeRegister (G4VSolid *pSolid)
static G4SolidStoreGetInstance ()
static void SetNotifier (G4VStoreNotifier *pNotifier)
static void Clean ()

Protected Member Functions

 G4SolidStore ()

Detailed Description

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

Definition at line 63 of file G4SolidStore.hh.

Constructor & Destructor Documentation

◆ ~G4SolidStore()

G4SolidStore::~G4SolidStore ( )
virtual

Destructor: takes care to delete allocated solids.

Definition at line 65 of file G4SolidStore.cc.

66{
67 Clean();
68}
static void Clean()

◆ G4SolidStore() [1/2]

G4SolidStore::G4SolidStore ( const G4SolidStore & )
delete

Copy constructor and assignment operator not allowed.

Referenced by Clean(), DeRegister(), G4SolidStore(), GetInstance(), GetSolid(), operator=(), and Register().

◆ G4SolidStore() [2/2]

G4SolidStore::G4SolidStore ( )
protected

Protected singleton constructor.

Definition at line 55 of file G4SolidStore.cc.

57{
58 reserve(100);
59}

Member Function Documentation

◆ Clean()

void G4SolidStore::Clean ( )
static

Deletes all solids from the store.

Definition at line 74 of file G4SolidStore.cc.

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

Referenced by G4RunManager::ReinitializeGeometry(), and ~G4SolidStore().

◆ DeRegister()

void G4SolidStore::DeRegister ( G4VSolid * pSolid)
static

Removes the solid 'pSolid' from the collection.

Definition at line 167 of file G4SolidStore.cc.

168{
169 G4SolidStore* store = GetInstance();
170 if (!locked) // Do not de-register if locked !
171 {
172 if (fgNotifier != nullptr) { fgNotifier->NotifyDeRegistration(); }
173 for (auto i=store->crbegin(); i!=store->crend(); ++i)
174 {
175 if (**i==*pSolid)
176 {
177 store->erase(std::next(i).base());
178 store->mvalid = false;
179 break;
180 }
181 }
182 const G4String& sol_name = pSolid->GetName();
183 auto it = store->bmap.find(sol_name);
184 if (it != store->bmap.cend())
185 {
186 if (it->second.size() > 1)
187 {
188 for (auto i=it->second.cbegin(); i!=it->second.cend(); ++i)
189 {
190 if (**i==*pSolid)
191 {
192 it->second.erase(i);
193 break;
194 }
195 }
196 }
197 else
198 {
199 store->bmap.erase(it);
200 }
201 }
202 }
203}
G4String GetName() const

Referenced by G4Voxelizer::G4Voxelizer(), and G4VSolid::~G4VSolid().

◆ GetInstance()

G4SolidStore * G4SolidStore::GetInstance ( )
static

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

Definition at line 247 of file G4SolidStore.cc.

248{
249 static G4SolidStore worldStore;
250 if (fgInstance == nullptr)
251 {
252 fgInstance = &worldStore;
253 }
254 return fgInstance;
255}

Referenced by Clean(), DeRegister(), G4Voxelizer::G4Voxelizer(), G4VSolid::G4VSolid(), G4VSolid::G4VSolid(), G4VSolid::G4VSolid(), G4GDMLReadSolids::GetSolid(), GetSolid(), Register(), G4RunManager::ReinitializeGeometry(), G4VSolid::SetName(), SetNotifier(), G4GeometryManager::SetWorldMaximumExtent(), G4GDMLRead::StripNames(), UpdateMap(), and G4VSolid::~G4VSolid().

◆ GetMap()

const std::map< G4String, std::vector< G4VSolid * > > & G4SolidStore::GetMap ( ) const
inline

Returns the internal map.

Definition at line 125 of file G4SolidStore.hh.

125{ return bmap; }

◆ GetSolid()

G4VSolid * G4SolidStore::GetSolid ( const G4String & name,
G4bool verbose = true,
G4bool reverseSearch = false ) const

Returns a pointer to the first or last solid in the collection having that name. Uses the internal map for fast search and warns if a solid in the collection is not unique or not found.

Parameters
[in]nameThe name of the solid to search.
[in]verboseFlag for enabling verbosity (default true).
[in]reverseSearchFlag to enable inverse search (default false).

Definition at line 209 of file G4SolidStore.cc.

211{
212 G4SolidStore* store = GetInstance();
213 if (!store->mvalid) { store->UpdateMap(); }
214 auto pos = store->bmap.find(name);
215 if(pos != store->bmap.cend())
216 {
217 if ((verbose) && (pos->second.size()>1))
218 {
219 std::ostringstream message;
220 message << "There exists more than ONE solid in store named: "
221 << name << "!" << G4endl
222 << "Returning the first found.";
223 G4Exception("G4SolidStore::GetSolid()",
224 "GeomMgt1001", JustWarning, message);
225 }
226 if(reverseSearch)
227 {
228 return pos->second[pos->second.size()-1];
229 }
230 return pos->second[0];
231 }
232 if (verbose)
233 {
234 std::ostringstream message;
235 message << "Solid " << name << " not found in store !" << G4endl
236 << "Returning NULL pointer.";
237 G4Exception("G4SolidStore::GetSolid()",
238 "GeomMgt1001", JustWarning, message);
239 }
240 return nullptr;
241}
@ JustWarning
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
const char * name(G4int ptype)

Referenced by G4GDMLReadSolids::GetSolid().

◆ IsMapValid()

G4bool G4SolidStore::IsMapValid ( ) const
inline

Accessor and modifier to assess validity of the internal map.

Definition at line 118 of file G4SolidStore.hh.

118{ return mvalid; }

◆ operator=()

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

◆ Register()

void G4SolidStore::Register ( G4VSolid * pSolid)
static

Adds the solid 'pSolid' to the collection.

Definition at line 144 of file G4SolidStore.cc.

145{
146 G4SolidStore* store = GetInstance();
147 store->push_back(pSolid);
148 const G4String& sol_name = pSolid->GetName();
149 auto it = store->bmap.find(sol_name);
150 if (it != store->bmap.cend())
151 {
152 it->second.push_back(pSolid);
153 }
154 else
155 {
156 std::vector<G4VSolid*> sol_vec { pSolid };
157 store->bmap.insert(std::make_pair(sol_name, sol_vec));
158 }
159 if (fgNotifier != nullptr) { fgNotifier->NotifyRegistration(); }
160 store->mvalid = true;
161}

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

◆ SetMapValid()

void G4SolidStore::SetMapValid ( G4bool val)
inline

Definition at line 119 of file G4SolidStore.hh.

119{ mvalid = val; }

Referenced by G4VSolid::SetName().

◆ SetNotifier()

void G4SolidStore::SetNotifier ( G4VStoreNotifier * pNotifier)
static

Assigns a notifier for allocation/deallocation of the solids.

Definition at line 107 of file G4SolidStore.cc.

108{
109 GetInstance();
110 fgNotifier = pNotifier;
111}

◆ UpdateMap()

void G4SolidStore::UpdateMap ( )

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

Definition at line 117 of file G4SolidStore.cc.

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

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


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