ECCE @ EIC Software
Reference for
ECCE @ EIC
simulation and reconstruction software on GitHub
Home page
Related Pages
Modules
Namespaces
Classes
Files
External Links
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
G4AssemblyStore.cc
Go to the documentation of this file.
Or view
the newest version in sPHENIX GitHub for file G4AssemblyStore.cc
1
//
2
// ********************************************************************
3
// * License and Disclaimer *
4
// * *
5
// * The Geant4 software is copyright of the Copyright Holders of *
6
// * the Geant4 Collaboration. It is provided under the terms and *
7
// * conditions of the Geant4 Software License, included in the file *
8
// * LICENSE and available at http://cern.ch/geant4/license . These *
9
// * include a list of copyright holders. *
10
// * *
11
// * Neither the authors of this software system, nor their employing *
12
// * institutes,nor the agencies providing financial support for this *
13
// * work make any representation or warranty, express or implied, *
14
// * regarding this software system or assume any liability for its *
15
// * use. Please see the license in the file LICENSE and URL above *
16
// * for the full disclaimer and the limitation of liability. *
17
// * *
18
// * This code implementation is the result of the scientific and *
19
// * technical work of the GEANT4 collaboration. *
20
// * By using, copying, modifying or distributing the software (or *
21
// * any work based on the software) you agree to acknowledge its *
22
// * use in resulting scientific publications, and indicate your *
23
// * acceptance of all terms of the Geant4 Software license. *
24
// ********************************************************************
25
//
26
//
27
// G4AssemblyStore
28
//
29
// Implementation for singleton container
30
//
31
// History:
32
// 9.10.18 G.Cosmo Initial version
33
// --------------------------------------------------------------------
34
35
#include "
G4AssemblyVolume.hh
"
36
#include "
G4AssemblyStore.hh
"
37
#include "
G4GeometryManager.hh
"
38
#include "
G4ios.hh
"
39
40
// ***************************************************************************
41
// Static class variables
42
// ***************************************************************************
43
//
44
G4AssemblyStore
*
G4AssemblyStore::fgInstance
=
nullptr
;
45
G4ThreadLocal
G4VStoreNotifier
*
G4AssemblyStore::fgNotifier
=
nullptr
;
46
G4ThreadLocal
G4bool
G4AssemblyStore::locked
=
false
;
47
48
// ***************************************************************************
49
// Protected constructor: Construct underlying container with
50
// initial size of 20 entries
51
// ***************************************************************************
52
//
53
G4AssemblyStore::G4AssemblyStore
()
54
: std::vector<
G4AssemblyVolume
*>()
55
{
56
reserve(20);
57
}
58
59
// ***************************************************************************
60
// Destructor
61
// ***************************************************************************
62
//
63
G4AssemblyStore::~G4AssemblyStore
()
64
{
65
Clean
();
// Delete all assemblies in the store
66
}
67
68
// ***************************************************************************
69
// Delete all assemblies from the store
70
// ***************************************************************************
71
//
72
void
G4AssemblyStore::Clean
()
73
{
74
// Do nothing if geometry is closed
75
//
76
if
(
G4GeometryManager::IsGeometryClosed
())
77
{
78
G4cout
<<
"WARNING - Attempt to delete the assembly store"
79
<<
" while geometry closed !"
<<
G4endl
;
80
return
;
81
}
82
83
// Locks store for deletion of assemblies. De-registration will be
84
// performed at this stage. Assemblies will not de-register themselves.
85
//
86
locked
=
true
;
87
88
size_t
i=0;
89
G4AssemblyStore
* store =
GetInstance
();
90
91
#ifdef G4DEBUG_NAVIGATION
92
G4cout
<<
"Deleting Assemblies ... "
;
93
#endif
94
95
for
(
auto
pos
=store->cbegin();
pos
!=store->cend(); ++
pos
)
96
{
97
if
(
fgNotifier
!=
nullptr
) {
fgNotifier
->
NotifyDeRegistration
(); }
98
if
(*
pos
) {
delete
*
pos
; }
99
++i;
100
}
101
102
#ifdef G4DEBUG_NAVIGATION
103
if
(store->size() < i-1)
104
{
G4cout
<<
"No assembly deleted. Already deleted by user ?"
<<
G4endl
; }
105
else
106
{
G4cout
<< i-1 <<
" assemblies deleted !"
<<
G4endl
; }
107
#endif
108
109
locked
=
false
;
110
store->clear();
111
}
112
113
// ***************************************************************************
114
// Associate user notifier to the store
115
// ***************************************************************************
116
//
117
void
G4AssemblyStore::SetNotifier
(
G4VStoreNotifier
* pNotifier)
118
{
119
GetInstance
();
120
fgNotifier
= pNotifier;
121
}
122
123
// ***************************************************************************
124
// Add Assembly to container
125
// ***************************************************************************
126
//
127
void
G4AssemblyStore::Register
(
G4AssemblyVolume
* pAssembly)
128
{
129
GetInstance
()->push_back(pAssembly);
130
if
(
fgNotifier
!=
nullptr
) {
fgNotifier
->
NotifyRegistration
(); }
131
}
132
133
// ***************************************************************************
134
// Remove Assembly from container
135
// ***************************************************************************
136
//
137
void
G4AssemblyStore::DeRegister
(
G4AssemblyVolume
* pAssembly)
138
{
139
if
(!
locked
)
// Do not de-register if locked !
140
{
141
if
(
fgNotifier
!=
nullptr
) {
fgNotifier
->
NotifyDeRegistration
(); }
142
for
(
auto
i=
GetInstance
()->cbegin(); i!=
GetInstance
()->cend(); ++i)
143
{
144
if
(*i==pAssembly)
145
{
146
GetInstance
()->erase(i);
147
break
;
148
}
149
}
150
}
151
}
152
153
// ***************************************************************************
154
// Return ptr to Store, setting if necessary
155
// ***************************************************************************
156
//
157
G4AssemblyStore
*
G4AssemblyStore::GetInstance
()
158
{
159
static
G4AssemblyStore
assemblyStore;
160
if
(
fgInstance
==
nullptr
)
161
{
162
fgInstance
= &assemblyStore;
163
}
164
return
fgInstance
;
165
}
166
167
// ***************************************************************************
168
// Returns an assembly through its name specification.
169
// ***************************************************************************
170
//
171
G4AssemblyVolume
*
172
G4AssemblyStore::GetAssembly
(
unsigned
int
id
,
G4bool
verbose)
const
173
{
174
for
(
auto
i=
GetInstance
()->cbegin(); i!=
GetInstance
()->cend(); ++i)
175
{
176
if
((*i)->GetAssemblyID() == id) {
return
*i; }
177
}
178
if
(verbose)
179
{
180
std::ostringstream
message
;
181
message <<
"Assembly NOT found in store !"
<<
G4endl
182
<<
" Assembly "
<<
id
<<
" NOT found in store !"
<<
G4endl
183
<<
" Returning NULL pointer."
;
184
G4Exception
(
"G4AssemblyStore::GetAssembly()"
,
185
"GeomVol1001"
,
JustWarning
, message);
186
}
187
return
0;
188
}
geant4
tree
geant4-10.6-release
source
geometry
volumes
src
G4AssemblyStore.cc
Built by
Jin Huang
. updated:
Wed Jun 29 2022 17:25:20
using
1.8.2 with
ECCE GitHub integration