Geant4 11.1.1
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 ()
 

Friends

class G4ThreadLocalSingleton< G4AccumulableManager >
 

Detailed Description

Definition at line 46 of file G4AccumulableManager.hh.

Constructor & Destructor Documentation

◆ ~G4AccumulableManager()

G4AccumulableManager::~G4AccumulableManager ( )
virtual

Definition at line 55 of file G4AccumulableManager.cc.

56{
57 // delete only accumulables create by the mager itself
58 for ( auto it : fAccumulablesToDelete ) {
59 delete it;
60 }
61}

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 117 of file G4AccumulableManager.cc.

118{
119 // get G4VParammeter from the map
120 auto it = fMap.find(name);
121 if ( it == fMap.end() ) {
122 if ( warn) {
123 G4ExceptionDescription description;
124 description << "Accumulable " << name << " does not exist.";
125 G4Exception("G4AccumulableManager::GetAccumulable",
126 "Analysis_W001", JustWarning, description);
127 }
128 return nullptr;
129 }
130
131 return it->second;
132}
@ JustWarning
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:59
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 136 of file G4AccumulableManager.cc.

137{
138 // get G4VParammeter from the vector
139 if ( id < 0 || id >= G4int(fVector.size()) ) {
140 if ( warn) {
141 G4ExceptionDescription description;
142 description << "Accumulable " << id << " does not exist.";
143 G4Exception("G4AccumulableManager::GetAccumulable",
144 "Analysis_W001", JustWarning, description);
145 }
146 return nullptr;
147 }
148
149 return fVector[id];
150}
int G4int
Definition: G4Types.hh:85

◆ GetNofAccumulables()

G4int G4AccumulableManager::GetNofAccumulables ( ) const

◆ Instance()

G4AccumulableManager * G4AccumulableManager::Instance ( )
static

Definition at line 42 of file G4AccumulableManager.cc.

◆ Merge()

void G4AccumulableManager::Merge ( )

Definition at line 153 of file G4AccumulableManager.cc.

154{
155 // Do nothing if there are no accumulables registered
156 // or if master thread
157 if ((fVector.size() == 0u) || (! G4Threading::IsWorkerThread())) return;
158
159 // The manager on mastter must exist
160 if (fgMasterInstance == nullptr) {
161 G4ExceptionDescription description;
162 description
163 << "No master G4AccumulableManager instance exists." << G4endl
164 << "Accumulables will not be merged.";
165 G4Exception("G4AccumulableManager::Merge()",
166 "Analysis_W001", JustWarning, description);
167 return;
168 }
169
170 // The worker manager just merges its accumulables to the master
171 // This operation needs a lock
172 // G4cout << "Go to merge accumulables" << G4endl;
173 G4AutoLock lock(&mergeMutex);
174
175 // the other manager has the vector with the "same" accumulables
176 auto it = fVector.begin();
177 for ( auto itMaster : fgMasterInstance->fVector ) {
178 // G4VAccumulable* masterAccumulable = itMaster;
179 // G4VAccumulable* accumulable = *(it++);
180 // masterAccumulable->Merge(*(accumulable));
181 itMaster->Merge(*(*(it++)));
182 }
183 lock.unlock();
184}
#define G4endl
Definition: G4ios.hh:57
G4bool IsWorkerThread()
Definition: G4Threading.cc:123

◆ RegisterAccumulable() [1/2]

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

◆ RegisterAccumulable() [2/2]

G4bool G4AccumulableManager::RegisterAccumulable ( G4VAccumulable accumulable)

Definition at line 97 of file G4AccumulableManager.cc.

98{
99 auto name = accumulable->GetName();
100
101 // do not accept name if it is already used
102 if ( ! CheckName(name, "RegisterAccumulable") ) return false;
103
104 // generate name if empty
105 if (name.length() == 0u) {
106 name = GenerateName();
107 accumulable->fName = name;
108 }
109
110 fMap[name] = accumulable;
111 fVector.push_back(accumulable);
112 return true;
113}
G4String GetName() const

◆ Reset()

void G4AccumulableManager::Reset ( )

Definition at line 187 of file G4AccumulableManager.cc.

188{
189// Reset histograms and profiles
190
191 for ( auto it : fVector ) {
192 it->Reset();
193 }
194}

Friends And Related Function Documentation

◆ G4ThreadLocalSingleton< G4AccumulableManager >

Definition at line 1 of file G4AccumulableManager.hh.


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