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

#include <G4SolidStore.hh>

+ Inheritance diagram for G4SolidStore:

Public Member Functions

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 ()
 
virtual ~G4SolidStore ()
 
 G4SolidStore (const G4SolidStore &)=delete
 
G4SolidStoreoperator= (const G4SolidStore &)=delete
 

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

Definition at line 54 of file G4SolidStore.hh.

Constructor & Destructor Documentation

◆ ~G4SolidStore()

G4SolidStore::~G4SolidStore ( )
virtual

Definition at line 65 of file G4SolidStore.cc.

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

◆ G4SolidStore() [1/2]

G4SolidStore::G4SolidStore ( const G4SolidStore & )
delete

◆ G4SolidStore() [2/2]

G4SolidStore::G4SolidStore ( )
protected

Definition at line 55 of file G4SolidStore.cc.

57{
58 reserve(100);
59}

Member Function Documentation

◆ Clean()

void G4SolidStore::Clean ( )
static

Definition at line 74 of file G4SolidStore.cc.

75{
76 // Do nothing if geometry is closed
77 //
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(auto pos=store->cbegin(); pos!=store->cend(); ++pos)
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 G4bool IsGeometryClosed()
static G4SolidStore * GetInstance()
virtual void NotifyDeRegistration()=0

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

◆ DeRegister()

void G4SolidStore::DeRegister ( G4VSolid * pSolid)
static

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

◆ GetMap()

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

Definition at line 79 of file G4SolidStore.hh.

79{ return bmap; }

◆ GetSolid()

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

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 else
231 {
232 return pos->second[0];
233 }
234 }
235 if (verbose)
236 {
237 std::ostringstream message;
238 message << "Solid " << name << " not found in store !" << G4endl
239 << "Returning NULL pointer.";
240 G4Exception("G4SolidStore::GetSolid()",
241 "GeomMgt1001", JustWarning, message);
242 }
243 return nullptr;
244}
@ 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

Definition at line 75 of file G4SolidStore.hh.

75{ return mvalid; }

◆ operator=()

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

◆ Register()

void G4SolidStore::Register ( G4VSolid * pSolid)
static

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}
virtual void NotifyRegistration()=0

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

◆ SetMapValid()

void G4SolidStore::SetMapValid ( G4bool val)
inline

Definition at line 76 of file G4SolidStore.hh.

76{ mvalid = val; }

Referenced by G4VSolid::SetName().

◆ SetNotifier()

void G4SolidStore::SetNotifier ( G4VStoreNotifier * pNotifier)
static

Definition at line 107 of file G4SolidStore.cc.

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

◆ UpdateMap()

void G4SolidStore::UpdateMap ( )

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(auto pos=GetInstance()->cbegin(); pos!=GetInstance()->cend(); ++pos)
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}

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


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