Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 44 of file G4AccumulableManager.hh.

Constructor & Destructor Documentation

G4AccumulableManager::~G4AccumulableManager ( )
virtual

Definition at line 74 of file G4AccumulableManager.cc.

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

Member Function Documentation

std::vector<G4VAccumulable*>::iterator G4AccumulableManager::Begin ( )
std::vector<G4VAccumulable*>::const_iterator G4AccumulableManager::BeginConst ( ) const
template<typename T >
G4Accumulable<T>* G4AccumulableManager::CreateAccumulable ( const G4String name,
value,
G4MergeMode  mergeMode = G4MergeMode::kAddition 
)
template<typename T >
G4Accumulable<T>* G4AccumulableManager::CreateAccumulable ( value,
G4MergeMode  mergeMode = G4MergeMode::kAddition 
)
std::vector<G4VAccumulable*>::iterator G4AccumulableManager::End ( )
std::vector<G4VAccumulable*>::const_iterator G4AccumulableManager::EndConst ( ) const
template<typename T >
G4VAccumulable * G4AccumulableManager::GetAccumulable ( const G4String name,
G4bool  warn = true 
) const

Definition at line 136 of file G4AccumulableManager.cc.

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

Here is the call graph for this function:

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

Definition at line 155 of file G4AccumulableManager.cc.

156 {
157  // get G4VParammeter from the vector
158  if ( id < 0 || id >= G4int(fVector.size()) ) {
159  if ( warn) {
160  G4ExceptionDescription description;
161  description << " " << "accumulable " << id << " does not exist.";
162  G4Exception("G4AccumulableManager::GetAccumulable",
163  "Analysis_W011", JustWarning, description);
164  }
165  return nullptr;
166  }
167 
168  return fVector[id];
169 }
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
int G4int
Definition: G4Types.hh:78
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41

Here is the call graph for this function:

G4VAccumulable* G4AccumulableManager::GetAccumulable ( G4int  id,
G4bool  warn = true 
) const
G4int G4AccumulableManager::GetNofAccumulables ( ) const
G4AccumulableManager * G4AccumulableManager::Instance ( void  )
static

Definition at line 45 of file G4AccumulableManager.cc.

46 {
47  if ( fgInstance == nullptr ) {
48  G4bool isMaster = ! G4Threading::IsWorkerThread();
49  fgInstance = new G4AccumulableManager(isMaster);
50  }
51 
52  return fgInstance;
53 }
bool G4bool
Definition: G4Types.hh:79
G4bool IsWorkerThread()
Definition: G4Threading.cc:145

Here is the call graph for this function:

Here is the caller graph for this function:

void G4AccumulableManager::Merge ( )

Definition at line 172 of file G4AccumulableManager.cc.

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Here is the caller graph for this function:

G4bool G4AccumulableManager::RegisterAccumulable ( G4VAccumulable accumulable)

Definition at line 116 of file G4AccumulableManager.cc.

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

Here is the call graph for this function:

void G4AccumulableManager::Reset ( )

Definition at line 207 of file G4AccumulableManager.cc.

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

Here is the caller graph for this function:


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