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

#include <G4LogicalVolumeStore.hh>

+ Inheritance diagram for G4LogicalVolumeStore:

Public Member Functions

G4LogicalVolumeGetVolume (const G4String &name, G4bool verbose=true, G4bool reverseSearch=false) const
 
G4bool IsMapValid () const
 
void SetMapValid (G4bool val)
 
const std::map< G4String, std::vector< G4LogicalVolume * > > & GetMap () const
 
void UpdateMap ()
 
virtual ~G4LogicalVolumeStore ()
 
 G4LogicalVolumeStore (const G4LogicalVolumeStore &)=delete
 
G4LogicalVolumeStoreoperator= (const G4LogicalVolumeStore &)=delete
 

Static Public Member Functions

static void Register (G4LogicalVolume *pVolume)
 
static void DeRegister (G4LogicalVolume *pVolume)
 
static G4LogicalVolumeStoreGetInstance ()
 
static void SetNotifier (G4VStoreNotifier *pNotifier)
 
static void Clean ()
 

Protected Member Functions

 G4LogicalVolumeStore ()
 

Detailed Description

Definition at line 55 of file G4LogicalVolumeStore.hh.

Constructor & Destructor Documentation

◆ ~G4LogicalVolumeStore()

G4LogicalVolumeStore::~G4LogicalVolumeStore ( )
virtual

Definition at line 65 of file G4LogicalVolumeStore.cc.

66{
67 Clean(); // Delete all volumes in the store
68 G4LogicalVolume::Clean(); // Delete allocated sub-instance data
69}
static void Clean()

◆ G4LogicalVolumeStore() [1/2]

G4LogicalVolumeStore::G4LogicalVolumeStore ( const G4LogicalVolumeStore )
delete

◆ G4LogicalVolumeStore() [2/2]

G4LogicalVolumeStore::G4LogicalVolumeStore ( )
protected

Definition at line 55 of file G4LogicalVolumeStore.cc.

56 : std::vector<G4LogicalVolume*>()
57{
58 reserve(100);
59}

Member Function Documentation

◆ Clean()

void G4LogicalVolumeStore::Clean ( )
static

Definition at line 75 of file G4LogicalVolumeStore.cc.

76{
77 // Do nothing if geometry is closed
78 //
80 {
81 G4cout << "WARNING - Attempt to delete the logical volume store"
82 << " while geometry closed !" << G4endl;
83 return;
84 }
85
86 // Locks store for deletion of volumes. De-registration will be
87 // performed at this stage. G4LogicalVolumes will not de-register themselves.
88 //
89 locked = true;
90
92
93 for(auto pos=store->cbegin(); pos!=store->cend(); ++pos)
94 {
95 if (fgNotifier != nullptr) { fgNotifier->NotifyDeRegistration(); }
96 if (*pos != nullptr) { (*pos)->Lock(); delete *pos; }
97 }
98
99 store->bmap.clear(); store->mvalid = false;
100 locked = false;
101 store->clear();
102}
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
static G4bool IsGeometryClosed()
static G4LogicalVolumeStore * GetInstance()
virtual void NotifyDeRegistration()=0

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

◆ DeRegister()

void G4LogicalVolumeStore::DeRegister ( G4LogicalVolume pVolume)
static

Definition at line 168 of file G4LogicalVolumeStore.cc.

169{
171 if (!locked) // Do not de-register if locked !
172 {
173 if (fgNotifier != nullptr) { fgNotifier->NotifyDeRegistration(); }
174 for (auto i=store->cbegin(); i!=store->cend(); ++i)
175 {
176 if (**i==*pVolume)
177 {
178 store->erase(i);
179 break;
180 }
181 }
182 const G4String& vol_name = pVolume->GetName();
183 auto it = store->bmap.find(vol_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==*pVolume)
191 {
192 it->second.erase(i);
193 break;
194 }
195 }
196 }
197 else
198 {
199 store->bmap.erase(it);
200 }
201 }
202 }
203}
const G4String & GetName() const

Referenced by G4LogicalVolume::~G4LogicalVolume().

◆ GetInstance()

◆ GetMap()

const std::map< G4String, std::vector< G4LogicalVolume * > > & G4LogicalVolumeStore::GetMap ( ) const
inline

◆ GetVolume()

G4LogicalVolume * G4LogicalVolumeStore::GetVolume ( const G4String name,
G4bool  verbose = true,
G4bool  reverseSearch = false 
) const

Definition at line 210 of file G4LogicalVolumeStore.cc.

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

Referenced by G4RadioactiveDecay::DeselectAVolume(), G4GDMLReadStructure::GetVolume(), G4RadioactiveDecay::SelectAVolume(), G4GDMLMessenger::SetNewValue(), G4VisCommandSceneAddLogicalVolume::SetNewValue(), and G4ScoringProbe::SetupGeometry().

◆ IsMapValid()

G4bool G4LogicalVolumeStore::IsMapValid ( ) const
inline

Definition at line 76 of file G4LogicalVolumeStore.hh.

76{ return mvalid; }

◆ operator=()

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

◆ Register()

void G4LogicalVolumeStore::Register ( G4LogicalVolume pVolume)
static

Definition at line 145 of file G4LogicalVolumeStore.cc.

146{
148 store->push_back(pVolume);
149 const G4String& vol_name = pVolume->GetName();
150 auto it = store->bmap.find(vol_name);
151 if (it != store->bmap.cend())
152 {
153 it->second.push_back(pVolume);
154 }
155 else
156 {
157 std::vector<G4LogicalVolume*> vol_vec { pVolume };
158 store->bmap.insert(std::make_pair(vol_name, vol_vec));
159 }
160 if (fgNotifier) { fgNotifier->NotifyRegistration(); }
161 store->mvalid = true;
162}
virtual void NotifyRegistration()=0

Referenced by G4LogicalVolume::G4LogicalVolume().

◆ SetMapValid()

void G4LogicalVolumeStore::SetMapValid ( G4bool  val)
inline

Definition at line 77 of file G4LogicalVolumeStore.hh.

77{ mvalid = val; }

Referenced by G4LogicalVolume::SetName().

◆ SetNotifier()

void G4LogicalVolumeStore::SetNotifier ( G4VStoreNotifier pNotifier)
static

Definition at line 108 of file G4LogicalVolumeStore.cc.

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

◆ UpdateMap()

void G4LogicalVolumeStore::UpdateMap ( )

Definition at line 118 of file G4LogicalVolumeStore.cc.

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

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


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