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

#include <G4AccumulableManager.hh>

Public Member Functions

virtual ~G4AccumulableManager ()
 
template<typename T >
G4Accumulable< T > * CreateAccumulable (const G4String &name, T value, G4MergeMode mergeMode=G4MergeMode::kAddition)
 
template<typename T >
G4Accumulable< T > * CreateAccumulable (T value, G4MergeMode mergeMode=G4MergeMode::kAddition)
 
template<typename T >
G4bool RegisterAccumulable (G4Accumulable< T > &accumulable)
 
G4bool RegisterAccumulable (G4VAccumulable *accumulable)
 
template<typename T >
G4Accumulable< T > * GetAccumulable (const G4String &name, G4bool warn=true) const
 
G4VAccumulableGetAccumulable (const G4String &name, G4bool warn=true) const
 
template<typename T >
G4Accumulable< T > * GetAccumulable (G4int id, G4bool warn=true) const
 
G4VAccumulableGetAccumulable (G4int id, G4bool warn=true) const
 
G4int GetNofAccumulables () const
 
std::vector< G4VAccumulable * >::iterator Begin ()
 
std::vector< G4VAccumulable * >::iterator End ()
 
std::vector< G4VAccumulable * >::const_iterator BeginConst () const
 
std::vector< G4VAccumulable * >::const_iterator EndConst () const
 
void Merge ()
 
void Reset ()
 

Static Public Member Functions

static G4AccumulableManagerInstance ()
 

Detailed Description

Definition at line 43 of file G4AccumulableManager.hh.

Constructor & Destructor Documentation

◆ ~G4AccumulableManager()

G4AccumulableManager::~G4AccumulableManager ( )
virtual

Definition at line 73 of file G4AccumulableManager.cc.

74{
75 // delete only accumulables create by the mager itself
76 for ( auto it : fAccumulablesToDelete ) {
77 delete it;
78 }
79}

Member Function Documentation

◆ Begin()

std::vector< G4VAccumulable * >::iterator G4AccumulableManager::Begin ( )

◆ BeginConst()

std::vector< G4VAccumulable * >::const_iterator G4AccumulableManager::BeginConst ( ) const

◆ CreateAccumulable() [1/2]

template<typename T >
G4Accumulable< T > * G4AccumulableManager::CreateAccumulable ( const G4String name,
value,
G4MergeMode  mergeMode = G4MergeMode::kAddition 
)

◆ CreateAccumulable() [2/2]

template<typename T >
G4Accumulable< T > * G4AccumulableManager::CreateAccumulable ( value,
G4MergeMode  mergeMode = G4MergeMode::kAddition 
)

◆ End()

std::vector< G4VAccumulable * >::iterator G4AccumulableManager::End ( )

◆ EndConst()

std::vector< G4VAccumulable * >::const_iterator G4AccumulableManager::EndConst ( ) const

◆ GetAccumulable() [1/4]

template<typename T >
G4Accumulable< T > * G4AccumulableManager::GetAccumulable ( const G4String name,
G4bool  warn = true 
) const

◆ GetAccumulable() [2/4]

G4VAccumulable * G4AccumulableManager::GetAccumulable ( const G4String name,
G4bool  warn = true 
) const

Definition at line 135 of file G4AccumulableManager.cc.

136{
137 // get G4VParammeter from the map
138 auto it = fMap.find(name);
139 if ( it == fMap.end() ) {
140 if ( warn) {
141 G4ExceptionDescription description;
142 description << " " << "accumulable " << name << " does not exist.";
143 G4Exception("G4AccumulableManager::GetAccumulable",
144 "Analysis_W011", JustWarning, description);
145 }
146 return nullptr;
147 }
148
149 return it->second;
150}
@ JustWarning
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:40
const char * name(G4int ptype)

◆ GetAccumulable() [3/4]

template<typename T >
G4Accumulable< T > * G4AccumulableManager::GetAccumulable ( G4int  id,
G4bool  warn = true 
) const

◆ GetAccumulable() [4/4]

G4VAccumulable * G4AccumulableManager::GetAccumulable ( G4int  id,
G4bool  warn = true 
) const

Definition at line 154 of file G4AccumulableManager.cc.

155{
156 // get G4VParammeter from the vector
157 if ( id < 0 || id >= G4int(fVector.size()) ) {
158 if ( warn) {
159 G4ExceptionDescription description;
160 description << " " << "accumulable " << id << " does not exist.";
161 G4Exception("G4AccumulableManager::GetAccumulable",
162 "Analysis_W011", JustWarning, description);
163 }
164 return nullptr;
165 }
166
167 return fVector[id];
168}
int G4int
Definition: G4Types.hh:85

◆ GetNofAccumulables()

G4int G4AccumulableManager::GetNofAccumulables ( ) const

◆ Instance()

G4AccumulableManager * G4AccumulableManager::Instance ( )
static

Definition at line 44 of file G4AccumulableManager.cc.

45{
46 if ( fgInstance == nullptr ) {
48 fgInstance = new G4AccumulableManager(isMaster);
49 }
50
51 return fgInstance;
52}
bool G4bool
Definition: G4Types.hh:86
G4bool IsWorkerThread()
Definition: G4Threading.cc:123

◆ Merge()

void G4AccumulableManager::Merge ( )

Definition at line 171 of file G4AccumulableManager.cc.

172{
173 // Do nothing if there are no accumulables registered
174 // or if master thread
175 if ( (! fVector.size()) || (! G4Threading::IsWorkerThread()) ) return;
176
177 // The manager on mastter must exist
178 if ( ! fgMasterInstance ) {
179 G4ExceptionDescription description;
180 description
181 << " " << "No master G4AccumulableManager instance exists."
182 << G4endl
183 << " " << "Accumulables will not be merged.";
184 G4Exception("G4AccumulableManager::Merge()",
185 "Analysis_W031", JustWarning, description);
186 return;
187 }
188
189 // The worker manager just merges its accumulables to the master
190 // This operation needs a lock
191 // G4cout << "Go to merge accumulables" << G4endl;
192 G4AutoLock lock(&mergeMutex);
193
194 // the other manager has the vector with the "same" accumulables
195 auto it = fVector.begin();
196 for ( auto itMaster : fgMasterInstance->fVector ) {
197 // G4VAccumulable* masterAccumulable = itMaster;
198 // G4VAccumulable* accumulable = *(it++);
199 // masterAccumulable->Merge(*(accumulable));
200 itMaster->Merge(*(*(it++)));
201 }
202 lock.unlock();
203}
#define G4endl
Definition: G4ios.hh:57

◆ RegisterAccumulable() [1/2]

template<typename T >
G4bool G4AccumulableManager::RegisterAccumulable ( G4Accumulable< T > &  accumulable)

◆ RegisterAccumulable() [2/2]

G4bool G4AccumulableManager::RegisterAccumulable ( G4VAccumulable accumulable)

Definition at line 115 of file G4AccumulableManager.cc.

116{
117 auto name = accumulable->GetName();
118
119 // do not accept name if it is already used
120 if ( ! CheckName(name, "RegisterAccumulable") ) return false;
121
122 // generate name if empty
123 if ( ! name.length() ) {
124 name = GenerateName();
125 accumulable->fName = name;
126 }
127
128 fMap[name] = accumulable;
129 fVector.push_back(accumulable);
130 return true;
131}
G4String GetName() const

◆ Reset()

void G4AccumulableManager::Reset ( )

Definition at line 206 of file G4AccumulableManager.cc.

207{
208// Reset histograms and profiles
209
210 for ( auto it : fVector ) {
211 it->Reset();
212 }
213}

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