Geant4  10.02.p03
TSRun Class Reference

#include <TSRun.hh>

Inheritance diagram for TSRun:
Collaboration diagram for TSRun:

Public Types

typedef std::map< G4int, G4doubleMutexHitsMap_t
 
typedef std::vector< G4atomic< G4double > * > AtomicHitsSum_t
 

Public Member Functions

 TSRun (const G4String &)
 
virtual ~TSRun ()
 
virtual void RecordEvent (const G4Event *)
 
G4THitsMap< G4double > * GetHitsMap (const G4String &collname) const
 
G4TAtomicHitsMap< G4double > * GetAtomicHitsMap (const G4String &) const
 
MutexHitsMap_tGetMutexHitsMap (const G4String &) const
 
void ConstructMFD (const G4String &)
 
virtual void Merge (const G4Run *)
 
- Public Member Functions inherited from G4Run
 G4Run ()
 
virtual ~G4Run ()
 
G4int GetRunID () const
 
G4int GetNumberOfEvent () const
 
G4int GetNumberOfEventToBeProcessed () const
 
const G4HCtableGetHCtable () const
 
const G4DCtableGetDCtable () const
 
const G4StringGetRandomNumberStatus () const
 
void SetRunID (G4int id)
 
void SetNumberOfEventToBeProcessed (G4int n_ev)
 
void SetHCtable (G4HCtable *HCtbl)
 
void SetDCtable (G4DCtable *DCtbl)
 
void SetRandomNumberStatus (G4String &st)
 
void StoreEvent (G4Event *evt)
 
const std::vector< const G4Event * > * GetEventVector () const
 

Private Attributes

std::vector< G4StringfCollNames
 
std::vector< G4intfCollIDs
 
std::vector< G4THitsMap< G4double > * > fRunMaps
 

Static Private Attributes

static AtomicHitsSum_t fAtomicRunSums
 
static std::vector< G4TAtomicHitsMap< G4double > * > fAtomicRunMaps
 
static std::map< G4String, MutexHitsMap_tfMutexRunMaps
 

Additional Inherited Members

- Protected Attributes inherited from G4Run
G4int runID
 
G4int numberOfEvent
 
G4int numberOfEventToBeProcessed
 
G4HCtableHCtable
 
G4DCtableDCtable
 
G4String randomNumberStatus
 
std::vector< const G4Event * > * eventVector
 

Detailed Description

Definition at line 70 of file TSRun.hh.

Member Typedef Documentation

◆ AtomicHitsSum_t

typedef std::vector<G4atomic<G4double>*> TSRun::AtomicHitsSum_t

Definition at line 74 of file TSRun.hh.

◆ MutexHitsMap_t

typedef std::map<G4int, G4double> TSRun::MutexHitsMap_t

Definition at line 73 of file TSRun.hh.

Constructor & Destructor Documentation

◆ TSRun()

TSRun::TSRun ( const G4String mfd_name)

Definition at line 70 of file TSRun.cc.

71 : G4Run()
72 {
73  ConstructMFD(mfd_name);
74 }
G4Run()
Definition: G4Run.cc:34
void ConstructMFD(const G4String &)
Definition: TSRun.cc:93
Here is the call graph for this function:

◆ ~TSRun()

TSRun::~TSRun ( )
virtual

Definition at line 78 of file TSRun.cc.

79 {
80  //--- Clear HitsMap for RUN
81  for(unsigned i = 0; i < fRunMaps.size(); ++i)
82  fRunMaps[i]->clear();
83 
85  for(unsigned i = 0; i < fAtomicRunMaps.size(); ++i)
86  fAtomicRunMaps[i]->clear();
87 
88 }
static std::vector< G4TAtomicHitsMap< G4double > * > fAtomicRunMaps
Definition: TSRun.hh:99
std::vector< G4THitsMap< G4double > * > fRunMaps
Definition: TSRun.hh:97
G4bool IsWorkerThread()
Definition: G4Threading.cc:135
vec_iX clear()
Here is the call graph for this function:

Member Function Documentation

◆ ConstructMFD()

void TSRun::ConstructMFD ( const G4String mfdName)

Definition at line 93 of file TSRun.cc.

94 {
95 
97  //=================================================
98  // Initalize RunMaps for accumulation.
99  // Get CollectionIDs for HitCollections.
100  //=================================================
103  //
104  if ( mfd )
105  {
106  //--- Loop over the registered primitive scorers.
107  for (G4int icol = 0; icol < mfd->GetNumberOfPrimitives(); icol++){
108  // Get Primitive Scorer object.
109  G4VPrimitiveScorer* scorer = mfd->GetPrimitive(icol);
110  // collection name and collectionID for HitsCollection,
111  // where type of HitsCollection is G4THitsMap in case
112  // of primitive scorer.
113  // The collection name is given by <MFD name>/<Primitive
114  // Scorer name>.
115  G4String collectionName = scorer->GetName();
116  G4String fullCollectionName = mfdName+"/"+collectionName;
117  G4int collectionID = SDman->GetCollectionID(fullCollectionName);
118  //
119  if ( collectionID >= 0 ){
120  G4cout << "++ " << fullCollectionName<< " id " << collectionID
121  << G4endl;
122  // Store obtained HitsCollection information into data members.
123  // And, creates new G4THitsMap for accumulating quantities during RUN.
124  fCollNames.push_back(fullCollectionName);
125  fCollIDs.push_back(collectionID);
126  fRunMaps.push_back(new G4THitsMap<G4double>(mfdName,
127  collectionName));
129  {
131  (mfdName, collectionName));
132  }
133  } else {
134  G4cout << "** collection " << fullCollectionName << " not found. "
135  <<G4endl;
136  }
137  }
138  }
139 
140 }
G4int GetCollectionID(G4String colName)
Definition: G4SDManager.cc:135
int G4int
Definition: G4Types.hh:78
std::vector< G4String > fCollNames
Definition: TSRun.hh:95
G4String GetName() const
G4GLOB_DLL std::ostream G4cout
static std::vector< G4TAtomicHitsMap< G4double > * > fAtomicRunMaps
Definition: TSRun.hh:99
G4VPrimitiveScorer * GetPrimitive(G4int id) const
G4VSensitiveDetector * FindSensitiveDetector(G4String dName, G4bool warning=true)
Definition: G4SDManager.cc:128
std::vector< G4THitsMap< G4double > * > fRunMaps
Definition: TSRun.hh:97
G4bool IsWorkerThread()
Definition: G4Threading.cc:135
static G4SDManager * GetSDMpointer()
Definition: G4SDManager.cc:40
std::vector< G4int > fCollIDs
Definition: TSRun.hh:96
#define G4endl
Definition: G4ios.hh:61
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetAtomicHitsMap()

G4TAtomicHitsMap< G4double > * TSRun::GetAtomicHitsMap ( const G4String collName) const

Definition at line 231 of file TSRun.cc.

232 {
233  for(unsigned i = 0; i < fCollNames.size(); ++i)
234  {
235  if(collName == fCollNames[i])
236  return fAtomicRunMaps[i];
237  }
238 
239  G4Exception("TSRun", collName.c_str(), JustWarning,
240  "GetHitsMap failed to locate the requested AtomicHitsMap");
241  return nullptr;
242 }
std::vector< G4String > fCollNames
Definition: TSRun.hh:95
static std::vector< G4TAtomicHitsMap< G4double > * > fAtomicRunMaps
Definition: TSRun.hh:99
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:
Here is the caller graph for this function:

◆ GetHitsMap()

G4THitsMap< G4double > * TSRun::GetHitsMap ( const G4String collname) const

Definition at line 212 of file TSRun.cc.

213 {
214  for(unsigned i = 0; i < fCollNames.size(); ++i)
215  {
216  if(collName == fCollNames[i])
217  return fRunMaps[i];
218  }
219 
220  G4Exception("TSRun", collName.c_str(), JustWarning,
221  "GetHitsMap failed to locate the requested HitsMap");
222  return nullptr;
223 }
std::vector< G4String > fCollNames
Definition: TSRun.hh:95
std::vector< G4THitsMap< G4double > * > fRunMaps
Definition: TSRun.hh:97
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:
Here is the caller graph for this function:

◆ GetMutexHitsMap()

TSRun::MutexHitsMap_t * TSRun::GetMutexHitsMap ( const G4String collName) const

Definition at line 250 of file TSRun.cc.

251 {
252  if(fMutexRunMaps.find(collName) != fMutexRunMaps.end())
253  return &fMutexRunMaps[collName];
254 
255  G4Exception("TSRun", collName.c_str(), JustWarning,
256  "GetHitsMap failed to locate the requested MutexHitsMap");
257  return nullptr;
258 }
static std::map< G4String, MutexHitsMap_t > fMutexRunMaps
Definition: TSRun.hh:100
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:
Here is the caller graph for this function:

◆ Merge()

void TSRun::Merge ( const G4Run aTSRun)
virtual

Reimplemented from G4Run.

Definition at line 197 of file TSRun.cc.

198 {
199  const TSRun* localTSRun = static_cast<const TSRun*>(aTSRun);
200 
201  for(unsigned i = 0; i < fRunMaps.size(); ++i)
202  *fRunMaps[i] += *localTSRun->fRunMaps[i];
203 
204  G4Run::Merge(aTSRun);
205 }
virtual void Merge(const G4Run *)
Definition: G4Run.cc:54
Definition: TSRun.hh:70
std::vector< G4THitsMap< G4double > * > fRunMaps
Definition: TSRun.hh:97
Here is the call graph for this function:

◆ RecordEvent()

void TSRun::RecordEvent ( const G4Event aEvent)
virtual

Reimplemented from G4Run.

Definition at line 147 of file TSRun.cc.

148 {
149  numberOfEvent++; // This is an original line.
150 
151  //=============================
152  // HitsCollection of This Event
153  //============================
154  G4HCofThisEvent* HCE = aEvent->GetHCofThisEvent();
155  if (!HCE) return;
156 
157  for(unsigned i = 0; i < fCollIDs.size(); ++i)
158  {
159  G4int fCollID = fCollIDs.at(i);
160  //=======================================================
161  // Sum up HitsMap of this Event into HitsMap of this RUN
162  //=======================================================
163  G4THitsMap<G4double>* EvtMap = 0;
164  if ( fCollID >= 0 ) // Collection is attached to HCE
165  EvtMap = static_cast<G4THitsMap<G4double>*>(HCE->GetHC(fCollID));
166  else
167  G4cout <<" Error EvtMap Not Found " << G4endl;
168 
169  if ( EvtMap )
170  {
171  //=== Sum up HitsMap of this event to HitsMap of RUN.===
172  *fRunMaps[fCollID] += *EvtMap;
173  // atomic run map
174  *fAtomicRunMaps[fCollID] += *EvtMap;
175  // mutex run map
176  static G4Mutex mtx = G4MUTEX_INITIALIZER;
177  {
178  G4AutoLock lock(&mtx);
179  auto itr = EvtMap->GetMap()->begin();
180  for(; itr != EvtMap->GetMap()->end(); itr++)
181  {
182  fMutexRunMaps[fCollNames[fCollID]][itr->first] += *itr->second;
183  }
184  }
185  //----------------------------------------------------------------//
186  }
187 
188  }
189 
190  G4Run::RecordEvent(aEvent);
191 
192 }
G4int numberOfEvent
Definition: G4Run.hh:59
std::map< G4int, T * > * GetMap() const
Definition: G4THitsMap.hh:68
int G4int
Definition: G4Types.hh:78
std::vector< G4String > fCollNames
Definition: TSRun.hh:95
#define G4MUTEX_INITIALIZER
Definition: G4Threading.hh:175
static std::map< G4String, MutexHitsMap_t > fMutexRunMaps
Definition: TSRun.hh:100
G4GLOB_DLL std::ostream G4cout
static std::vector< G4TAtomicHitsMap< G4double > * > fAtomicRunMaps
Definition: TSRun.hh:99
std::vector< G4THitsMap< G4double > * > fRunMaps
Definition: TSRun.hh:97
G4int G4Mutex
Definition: G4Threading.hh:173
G4HCofThisEvent * GetHCofThisEvent() const
Definition: G4Event.hh:185
virtual void RecordEvent(const G4Event *)
Definition: G4Run.cc:51
std::vector< G4int > fCollIDs
Definition: TSRun.hh:96
#define G4endl
Definition: G4ios.hh:61
Here is the call graph for this function:

Member Data Documentation

◆ fAtomicRunMaps

std::vector< G4TAtomicHitsMap< G4double > * > TSRun::fAtomicRunMaps
staticprivate

TSRun contains three collections of hits maps: a thread-local hits map, a global atomic hits map (implemented as a static since TSRun is implemented as a thread-local instance), and a global "mutex" hits map (also implemented as a static). The thread-local hits map is the same as you will find in many other examples. The atomics hits map is the purpose of this example. Code-wise, the implementation looks extremely similar to the thread-local version with the 3 primary exceptions: (1) construction - there should only be one instance so it should be a static member variable or a pointer/reference to a single instance elsewhere in the code (stored in ActionInitialization, for instance); (2) It does not need to, nor should be, summed in G4Run::Merge(); and (3) destruction – it should only be cleared by the master thread since there is only one instance. A "mutex" hits map is also included as reference for checking the results accumulated by the thread-local hits maps and atomic hits maps. The differences w.r.t. this hits maps are computed in TSRunAction::EndOfRunAction

Definition at line 99 of file TSRun.hh.

◆ fAtomicRunSums

AtomicHitsSum_t TSRun::fAtomicRunSums
staticprivate

Definition at line 98 of file TSRun.hh.

◆ fCollIDs

std::vector<G4int> TSRun::fCollIDs
private

Definition at line 96 of file TSRun.hh.

◆ fCollNames

std::vector<G4String> TSRun::fCollNames
private

Definition at line 95 of file TSRun.hh.

◆ fMutexRunMaps

std::map< G4String, TSRun::MutexHitsMap_t > TSRun::fMutexRunMaps
staticprivate

Definition at line 100 of file TSRun.hh.

◆ fRunMaps

std::vector<G4THitsMap<G4double>*> TSRun::fRunMaps
private

Definition at line 97 of file TSRun.hh.


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