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

#include <G4SolidStore.hh>

Inheritance diagram for G4SolidStore:

Public Member Functions

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

Static Public Member Functions

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

Protected Member Functions

 G4SolidStore ()
 

Private Attributes

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

Static Private Attributes

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

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()
Definition: G4SolidStore.cc:74

References Clean().

◆ G4SolidStore() [1/2]

G4SolidStore::G4SolidStore ( const G4SolidStore )
delete

◆ G4SolidStore() [2/2]

G4SolidStore::G4SolidStore ( )
protected

Definition at line 55 of file G4SolidStore.cc.

56 : std::vector<G4VSolid*>()
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 std::size_t i = 0;
91 G4SolidStore* store = GetInstance();
92
93#ifdef G4GEOMETRY_VOXELDEBUG
94 G4cout << "Deleting Solids ... ";
95#endif
96
97 for(auto pos=store->cbegin(); pos!=store->cend(); ++pos)
98 {
99 if (fgNotifier != nullptr) { fgNotifier->NotifyDeRegistration(); }
100 delete *pos; ++i;
101 }
102
103#ifdef G4GEOMETRY_VOXELDEBUG
104 if (store->size() < i-1)
105 { G4cout << "No solids deleted. Already deleted by user ?" << G4endl; }
106 else
107 { G4cout << i-1 << " solids deleted !" << G4endl; }
108#endif
109
110 store->bmap.clear(); store->mvalid = false;
111 locked = false;
112 store->clear();
113}
static const G4double pos
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
static G4bool IsGeometryClosed()
static G4ThreadLocal G4bool locked
Definition: G4SolidStore.hh:99
std::map< G4String, std::vector< G4VSolid * > > bmap
static G4ThreadLocal G4VStoreNotifier * fgNotifier
Definition: G4SolidStore.hh:98
static G4SolidStore * GetInstance()
virtual void NotifyDeRegistration()=0

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

Referenced by ExN03DetectorConstruction::ConstructCalorimeter(), DetectorConstruction::ConstructVolumes(), G4RunManager::ReinitializeGeometry(), and ~G4SolidStore().

◆ DeRegister()

void G4SolidStore::DeRegister ( G4VSolid pSolid)
static

Definition at line 179 of file G4SolidStore.cc.

180{
181 G4SolidStore* store = GetInstance();
182 if (!locked) // Do not de-register if locked !
183 {
184 if (fgNotifier != nullptr) { fgNotifier->NotifyDeRegistration(); }
185 for (auto i=store->crbegin(); i!=store->crend(); ++i)
186 {
187 if (**i==*pSolid)
188 {
189 store->erase(std::next(i).base());
190 store->mvalid = false;
191 break;
192 }
193 }
194 const G4String& sol_name = pSolid->GetName();
195 auto it = store->bmap.find(sol_name);
196 if (it != store->bmap.cend())
197 {
198 if (it->second.size() > 1)
199 {
200 for (auto i=it->second.cbegin(); i!=it->second.cend(); ++i)
201 {
202 if (**i==*pSolid)
203 {
204 it->second.erase(i);
205 break;
206 }
207 }
208 }
209 else
210 {
211 store->bmap.erase(it);
212 }
213 }
214 }
215}
G4String GetName() const

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

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; }

References bmap.

◆ GetSolid()

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

Definition at line 221 of file G4SolidStore.cc.

223{
224 G4SolidStore* store = GetInstance();
225 if (!store->mvalid) { store->UpdateMap(); }
226 auto pos = store->bmap.find(name);
227 if(pos != store->bmap.cend())
228 {
229 if ((verbose) && (pos->second.size()>1))
230 {
231 std::ostringstream message;
232 message << "There exists more than ONE solid in store named: "
233 << name << "!" << G4endl
234 << "Returning the first found.";
235 G4Exception("G4SolidStore::GetSolid()",
236 "GeomMgt1001", JustWarning, message);
237 }
238 if(reverseSearch)
239 {
240 return pos->second[pos->second.size()-1];
241 }
242 else
243 {
244 return pos->second[0];
245 }
246 }
247 if (verbose)
248 {
249 std::ostringstream message;
250 message << "Solid " << name << " not found in store !" << G4endl
251 << "Returning NULL pointer.";
252 G4Exception("G4SolidStore::GetSolid()",
253 "GeomMgt1001", JustWarning, message);
254 }
255 return nullptr;
256}
@ JustWarning
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
void UpdateMap()
const char * name(G4int ptype)

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

Referenced by G4GDMLReadSolids::GetSolid().

◆ IsMapValid()

G4bool G4SolidStore::IsMapValid ( ) const
inline

Definition at line 75 of file G4SolidStore.hh.

75{ return mvalid; }

References mvalid.

◆ operator=()

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

◆ Register()

void G4SolidStore::Register ( G4VSolid pSolid)
static

Definition at line 156 of file G4SolidStore.cc.

157{
158 G4SolidStore* store = GetInstance();
159 store->push_back(pSolid);
160 const G4String& sol_name = pSolid->GetName();
161 auto it = store->bmap.find(sol_name);
162 if (it != store->bmap.cend())
163 {
164 it->second.push_back(pSolid);
165 }
166 else
167 {
168 std::vector<G4VSolid*> sol_vec { pSolid };
169 store->bmap.insert(std::make_pair(sol_name, sol_vec));
170 }
172 store->mvalid = true;
173}
virtual void NotifyRegistration()=0

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

Referenced by G4VSolid::G4VSolid().

◆ SetMapValid()

void G4SolidStore::SetMapValid ( G4bool  val)
inline

Definition at line 76 of file G4SolidStore.hh.

76{ mvalid = val; }

References mvalid.

Referenced by G4VSolid::SetName().

◆ SetNotifier()

void G4SolidStore::SetNotifier ( G4VStoreNotifier pNotifier)
static

Definition at line 119 of file G4SolidStore.cc.

120{
121 GetInstance();
122 fgNotifier = pNotifier;
123}

References fgNotifier, and GetInstance().

◆ UpdateMap()

void G4SolidStore::UpdateMap ( )

Definition at line 129 of file G4SolidStore.cc.

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

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

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

Field Documentation

◆ bmap

std::map<G4String, std::vector<G4VSolid*> > G4SolidStore::bmap
private

Definition at line 101 of file G4SolidStore.hh.

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

◆ fgInstance

G4SolidStore * G4SolidStore::fgInstance = nullptr
staticprivate

Definition at line 97 of file G4SolidStore.hh.

Referenced by GetInstance().

◆ fgNotifier

G4ThreadLocal G4VStoreNotifier * G4SolidStore::fgNotifier = nullptr
staticprivate

Definition at line 98 of file G4SolidStore.hh.

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

◆ locked

G4ThreadLocal G4bool G4SolidStore::locked = false
staticprivate

Definition at line 99 of file G4SolidStore.hh.

Referenced by Clean(), and DeRegister().

◆ mvalid

G4bool G4SolidStore::mvalid = false
private

Definition at line 102 of file G4SolidStore.hh.

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


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