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

G4AssemblyStore is a container for all assemblies, with functionality derived from std::vector<T>. The class is a singleton. All assemblies are registered with G4AssemblyStore, and removed on their destruction. More...

#include <G4AssemblyStore.hh>

Inheritance diagram for G4AssemblyStore:

Public Member Functions

G4AssemblyVolumeGetAssembly (unsigned int id, G4bool verbose=true) const

Static Public Member Functions

static void Register (G4AssemblyVolume *pAssembly)
static void DeRegister (G4AssemblyVolume *pAssembly)
static G4AssemblyStoreGetInstance ()
static void SetNotifier (G4VStoreNotifier *pNotifier)
static void Clean ()

Detailed Description

G4AssemblyStore is a container for all assemblies, with functionality derived from std::vector<T>. The class is a singleton. All assemblies are registered with G4AssemblyStore, and removed on their destruction.

Definition at line 61 of file G4AssemblyStore.hh.

Member Function Documentation

◆ Clean()

void G4AssemblyStore::Clean ( )
static

Deletes all assemblies from the store.

Definition at line 69 of file G4AssemblyStore.cc.

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

Referenced by G4RunManager::ReinitializeGeometry().

◆ DeRegister()

void G4AssemblyStore::DeRegister ( G4AssemblyVolume * pAssembly)
static

Removes the assembly from the collection.

Definition at line 121 of file G4AssemblyStore.cc.

122{
123 if (!locked) // Do not de-register if locked !
124 {
125 if (fgNotifier != nullptr) { fgNotifier->NotifyDeRegistration(); }
126 for (auto i=GetInstance()->cbegin(); i!=GetInstance()->cend(); ++i)
127 {
128 if (*i==pAssembly)
129 {
130 GetInstance()->erase(i);
131 break;
132 }
133 }
134 }
135}

Referenced by G4AssemblyVolume::~G4AssemblyVolume().

◆ GetAssembly()

G4AssemblyVolume * G4AssemblyStore::GetAssembly ( unsigned int id,
G4bool verbose = true ) const

Returns an assembly through its Id number specification.

Definition at line 156 of file G4AssemblyStore.cc.

157{
158 for (const auto & i : *GetInstance())
159 {
160 if (i->GetAssemblyID() == id) { return i; }
161 }
162 if (verbose)
163 {
164 std::ostringstream message;
165 message << "Assembly NOT found in store !" << G4endl
166 << " Assembly " << id << " NOT found in store !" << G4endl
167 << " Returning NULL pointer.";
168 G4Exception("G4AssemblyStore::GetAssembly()",
169 "GeomVol1001", JustWarning, message);
170 }
171 return nullptr;
172}
@ JustWarning
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)

Referenced by G4GDMLWriteStructure::AssemblyWrite(), G4AssemblyVolume::G4AssemblyVolume(), G4AssemblyVolume::G4AssemblyVolume(), and G4GDMLWriteStructure::TraverseVolumeTree().

◆ GetInstance()

G4AssemblyStore * G4AssemblyStore::GetInstance ( )
static

Gets a pointer to the unique G4AssemblyStore, creating it if necessary.

Definition at line 141 of file G4AssemblyStore.cc.

142{
143 static G4AssemblyStore assemblyStore;
144 if (fgInstance == nullptr)
145 {
146 fgInstance = &assemblyStore;
147 }
148 return fgInstance;
149}

Referenced by G4GDMLWriteStructure::AssemblyWrite(), Clean(), DeRegister(), G4AssemblyVolume::G4AssemblyVolume(), G4AssemblyVolume::G4AssemblyVolume(), GetAssembly(), Register(), G4RunManager::ReinitializeGeometry(), SetNotifier(), G4GDMLWriteStructure::StructureWrite(), G4GDMLWriteStructure::TraverseVolumeTree(), and G4AssemblyVolume::~G4AssemblyVolume().

◆ Register()

void G4AssemblyStore::Register ( G4AssemblyVolume * pAssembly)
static

Adds the assembly to the collection.

Definition at line 111 of file G4AssemblyStore.cc.

112{
113 GetInstance()->push_back(pAssembly);
114 if (fgNotifier != nullptr) { fgNotifier->NotifyRegistration(); }
115}

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

◆ SetNotifier()

void G4AssemblyStore::SetNotifier ( G4VStoreNotifier * pNotifier)
static

Assigns a notifier for allocation/deallocation of assemblies.

Definition at line 101 of file G4AssemblyStore.cc.

102{
103 GetInstance();
104 fgNotifier = pNotifier;
105}

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