Loading...
Searching...
No Matches
Public Types | Public Member Functions | Private Attributes | Static Private Attributes | List of all members
TSRun Class Reference

#include <Doxymodules_parallel.h>

Inheritance diagram for TSRun:
G4Run

Public Types

typedef std::map< G4int, G4double > MutexHitsMap_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
 
G4StatContainer< G4StatAnalysis > * GetStatMap (const G4String &collname) const
 
G4StatContainer< G4ConvergenceTester > * GetConvMap (const G4String &) const
 
void ConstructMFD (const G4String &)
 
virtual void Merge (const G4Run *)
 

Private Attributes

std::vector< G4StringfCollNames
 
std::vector< G4int > fCollIDs
 
std::vector< G4THitsMap< G4double > * > fRunMaps
 
std::vector< G4StatContainer< G4StatAnalysis > * > fStatMaps
 

Static Private Attributes

static std::vector< G4TAtomicHitsMap< G4double > * > fAtomicRunMaps
 TSRun contains five hits collections types: 1) a thread-local hits map, 2) a global atomic hits map 3) a global "mutex" hits map 4) a global G4StatAnalysis hits deque 5) a global G4ConvergenceTester hits deque.
 
static std::map< G4String, MutexHitsMap_tfMutexRunMaps
 
static std::vector< G4StatContainer< G4ConvergenceTester > * > fConvMaps
 

Detailed Description

Definition at line 149 of file Doxymodules_parallel.h.

Member Typedef Documentation

◆ MutexHitsMap_t

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

Definition at line 79 of file TSRun.hh.

Constructor & Destructor Documentation

◆ TSRun()

TSRun::TSRun ( const G4String mfd_name)

Definition at line 89 of file TSRun.cc.

90 : G4Run()
91{
92 ConstructMFD(mfd_name);
93}
void ConstructMFD(const G4String &)
Definition TSRun.cc:120

◆ ~TSRun()

TSRun::~TSRun ( )
virtual

Definition at line 97 of file TSRun.cc.

98{
99 //--- Clear HitsMap for RUN
100 for(unsigned i = 0; i < fRunMaps.size(); ++i)
101 delete fRunMaps[i];
102
103 if(!G4Threading::IsWorkerThread())
104 {
105 for(unsigned i = 0; i < fAtomicRunMaps.size(); ++i)
106 delete fAtomicRunMaps[i];
107
108 for(auto& itr : fConvMaps)
109 delete itr;
110
111 fAtomicRunMaps.clear();
112 fMutexRunMaps.clear();
113 fConvMaps.clear();
114 }
115}
static std::map< G4String, MutexHitsMap_t > fMutexRunMaps
Definition TSRun.hh:107
static std::vector< G4TAtomicHitsMap< G4double > * > fAtomicRunMaps
TSRun contains five hits collections types: 1) a thread-local hits map, 2) a global atomic hits map 3...
Definition TSRun.hh:106
std::vector< G4THitsMap< G4double > * > fRunMaps
Definition TSRun.hh:104
static std::vector< G4StatContainer< G4ConvergenceTester > * > fConvMaps
Definition TSRun.hh:108

Member Function Documentation

◆ RecordEvent()

void TSRun::RecordEvent ( const G4Event aEvent)
virtual

Definition at line 182 of file TSRun.cc.

183{
184 G4Run::RecordEvent(aEvent);
185
186 //=============================
187 // HitsCollection of This Event
188 //============================
189 G4HCofThisEvent* HCE = aEvent->GetHCofThisEvent();
190 if(!HCE)
191 return;
192
193 for(unsigned i = 0; i < fCollIDs.size(); ++i)
194 {
195 G4int fCollID = fCollIDs.at(i);
196 //=======================================================
197 // Sum up HitsMap of this Event into HitsMap of this RUN
198 //=======================================================
199 G4THitsMap<G4double>* EvtMap = 0;
200 if(fCollID >= 0) // Collection is attached to HCE
201 EvtMap = static_cast<G4THitsMap<G4double>*>(HCE->GetHC(fCollID));
202 else
203 G4cout << " Error EvtMap Not Found " << G4endl;
204
205 G4USER_SCOPED_PROFILE(fCollNames.at(i));
206 if(EvtMap)
207 {
208 //=== Sum up HitsMap of this event to HitsMap of RUN.===
209 {
210 G4USER_SCOPED_PROFILE("ThreadLocal");
211 *fRunMaps[fCollID] += *EvtMap;
212 }
213 //=== Sum up HitsMap of this event to StatMap of RUN.===
214 {
215 G4USER_SCOPED_PROFILE("ThreadLocal/G4StatAnalysis");
216 // G4StatAnalysis map
217 *fStatMaps[fCollID] += *EvtMap;
218 }
219 //=== Sum up HitsMap of this event to atomic HitsMap of RUN.===
220 {
221 G4USER_SCOPED_PROFILE("Global/Atomic");
222 *fAtomicRunMaps[fCollID] += *EvtMap;
223 }
224 //=== Sum up HitsMap of this event to MutexMap of RUN.===
225 {
226 G4USER_SCOPED_PROFILE("Global/Mutex");
227 // mutex run map
228 static G4Mutex mtx = G4MUTEX_INITIALIZER;
229 G4AutoLock lock(&mtx);
230 for(const auto& itr : *EvtMap)
231 fMutexRunMaps[fCollNames[fCollID]][itr.first] += *itr.second;
232 }
233 //=== Sum up HitsMap of this event to MutexMap of RUN.===
234 {
235 G4USER_SCOPED_PROFILE("Global/Mutex/G4ConvergenceTester");
236 // G4ConvergenceTester run map
237 static G4Mutex mtx = G4MUTEX_INITIALIZER;
238 G4AutoLock lock(&mtx);
239 *fConvMaps[fCollID] += *EvtMap;
240 }
241 }
242 }
243}
std::vector< G4String > fCollNames
Definition TSRun.hh:102
std::vector< G4int > fCollIDs
Definition TSRun.hh:103
std::vector< G4StatContainer< G4StatAnalysis > * > fStatMaps
Definition TSRun.hh:105

◆ GetHitsMap()

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

Definition at line 266 of file TSRun.cc.

267{
268 for(unsigned i = 0; i < fCollNames.size(); ++i)
269 {
270 if(collName == fCollNames[i])
271 return fRunMaps[i];
272 }
273
274 G4Exception("TSRun", collName.c_str(), JustWarning,
275 "GetHitsMap failed to locate the requested HitsMap");
276 return nullptr;
277}

◆ GetAtomicHitsMap()

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

Definition at line 284 of file TSRun.cc.

286{
287 for(unsigned i = 0; i < fCollNames.size(); ++i)
288 {
289 if(collName == fCollNames[i])
290 return fAtomicRunMaps[i];
291 }
292
293 G4Exception("TSRun", collName.c_str(), JustWarning,
294 "GetHitsMap failed to locate the requested AtomicHitsMap");
295 return nullptr;
296}

◆ GetMutexHitsMap()

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

Definition at line 303 of file TSRun.cc.

304{
305 if(fMutexRunMaps.find(collName) != fMutexRunMaps.end())
306 return &fMutexRunMaps[collName];
307
308 G4Exception("TSRun", collName.c_str(), JustWarning,
309 "GetHitsMap failed to locate the requested MutexHitsMap");
310 return nullptr;
311}

◆ GetStatMap()

G4StatContainer< G4StatAnalysis > * TSRun::GetStatMap ( const G4String collname) const

Definition at line 318 of file TSRun.cc.

320{
321 for(unsigned i = 0; i < fCollNames.size(); ++i)
322 {
323 if(collName == fCollNames[i])
324 return fStatMaps[i];
325 }
326
327 G4Exception("TSRun", collName.c_str(), JustWarning,
328 "GetStatMap failed to locate the requested StatMap");
329 return nullptr;
330}

◆ GetConvMap()

G4StatContainer< G4ConvergenceTester > * TSRun::GetConvMap ( const G4String collName) const

Definition at line 334 of file TSRun.cc.

336{
337 for(unsigned i = 0; i < fCollNames.size(); ++i)
338 {
339 if(collName == fCollNames[i])
340 return fConvMaps[i];
341 }
342
343 G4Exception("TSRun", collName.c_str(), JustWarning,
344 "GetHitsMap failed to locate the requested AtomicHitsMap");
345 return nullptr;
346}

◆ ConstructMFD()

void TSRun::ConstructMFD ( const G4String mfdName)

Definition at line 120 of file TSRun.cc.

121{
122 G4SDManager* SDman = G4SDManager::GetSDMpointer();
123 //=================================================
124 // Initalize RunMaps for accumulation.
125 // Get CollectionIDs for HitCollections.
126 //=================================================
128 (G4MultiFunctionalDetector*) (SDman->FindSensitiveDetector(mfdName));
129 //
130 if(mfd)
131 {
132 //--- Loop over the registered primitive scorers.
133 for(G4int icol = 0; icol < mfd->GetNumberOfPrimitives(); icol++)
134 {
135 // Get Primitive Scorer object.
136 G4VPrimitiveScorer* scorer = mfd->GetPrimitive(icol);
137 // collection name and collectionID for HitsCollection,
138 // where type of HitsCollection is G4THitsMap in case
139 // of primitive scorer.
140 // The collection name is given by <MFD name>/<Primitive
141 // Scorer name>.
142 G4String collectionName = scorer->GetName();
143 G4String fullCollectionName = mfdName + "/" + collectionName;
144 G4int collectionID = SDman->GetCollectionID(fullCollectionName);
145 //
146 if(collectionID >= 0)
147 {
148 G4cout << "++ " << fullCollectionName << " id " << collectionID
149 << G4endl;
150 // Store obtained HitsCollection information into data members.
151 // And, creates new G4THitsMap for accumulating quantities during RUN.
152 fCollNames.push_back(fullCollectionName);
153 fCollIDs.push_back(collectionID);
154 fRunMaps.push_back(new G4THitsMap<G4double>(mfdName, collectionName));
156 mfdName, collectionName,
157 TSDetectorConstruction::Instance()->GetTotalTargets()));
158 if(!G4Threading::IsWorkerThread())
159 {
160 fAtomicRunMaps.push_back(
161 new G4TAtomicHitsMap<G4double>(mfdName, collectionName));
162 fMutexRunMaps[fCollNames[collectionID]].clear();
164 mfdName, collectionName,
165 TSDetectorConstruction::Instance()->GetTotalTargets()));
166 }
167 }
168 else
169 {
170 G4cout << "** collection " << fullCollectionName << " not found. "
171 << G4endl;
172 }
173 }
174 }
175}
G4THitsDeque< _Tp > G4StatContainer
Definition TSRun.hh:74
This is an implementation of G4THitsMap<T> where the underlying type is G4atomic<T>,...
static TSDetectorConstruction * Instance()

◆ Merge()

void TSRun::Merge ( const G4Run aTSRun)
virtual

Definition at line 248 of file TSRun.cc.

249{
250 const TSRun* localTSRun = static_cast<const TSRun*>(aTSRun);
251
252 for(unsigned i = 0; i < fRunMaps.size(); ++i)
253 {
254 *fRunMaps[i] += *localTSRun->fRunMaps[i];
255 *fStatMaps[i] += *localTSRun->fStatMaps[i];
256 }
257
258 G4Run::Merge(aTSRun);
259}

Member Data Documentation

◆ fCollNames

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

Definition at line 102 of file TSRun.hh.

◆ fCollIDs

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

Definition at line 103 of file TSRun.hh.

◆ fRunMaps

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

Definition at line 104 of file TSRun.hh.

◆ fStatMaps

std::vector<G4StatContainer<G4StatAnalysis>*> TSRun::fStatMaps
private

Definition at line 105 of file TSRun.hh.

◆ fAtomicRunMaps

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

TSRun contains five hits collections types: 1) a thread-local hits map, 2) a global atomic hits map 3) a global "mutex" hits map 4) a global G4StatAnalysis hits deque 5) a global G4ConvergenceTester hits deque.

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 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 (2) It does not need to, nor should be, summed in G4Run::Merge() (3) destruction – it should only be cleared by the master thread since there is only one instance.

The "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

The "G4StatAnalysis" and "G4ConvergenceTester" hits deques are memory-efficient version of the standard G4THitsMap. While maps are ideal for scoring at the G4Event-level, where sparsity w.r.t. indices is common; at the G4Run-level, these data structures require much less memory overhead. Due to a lack of G4ConvergenceTester::operator+=(G4ConvergenceTester), the static version of G4ConvergenceTester is the only valid way to use G4ConvergenceTester in a scoring container. This is not the case for G4StatAnalysis, which can be used in lieu of G4double.

Definition at line 106 of file TSRun.hh.

◆ fMutexRunMaps

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

Definition at line 107 of file TSRun.hh.

◆ fConvMaps

std::vector< G4StatContainer< G4ConvergenceTester > * > TSRun::fConvMaps
staticprivate

Definition at line 108 of file TSRun.hh.


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

Applications | User Support | Publications | Collaboration