File indexing completed on 2025-09-16 08:55:42
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 #include "G4AccArray.hh"
0030 #include "G4AccMap.hh"
0031 #include "G4AccUnorderedMap.hh"
0032 #include "G4AccVector.hh"
0033
0034
0035 template <typename T>
0036 G4AccValue<T>*
0037 G4AccumulableManager::GetAccumulable(G4VAccumulable* accumulable, G4bool warn) const
0038 {
0039
0040 if (accumulable == nullptr) {
0041 return nullptr;
0042 }
0043
0044
0045 if (! CheckType(accumulable, G4AccType::kValue, warn)) {
0046 return nullptr;
0047 }
0048
0049 return static_cast<G4AccValue<T>*>(accumulable);
0050 }
0051
0052
0053 template <typename T, std::size_t N>
0054 G4AccArray<T, N>*
0055 G4AccumulableManager::GetAccArray(G4VAccumulable* accumulable, G4bool warn) const
0056 {
0057
0058 if (accumulable == nullptr) {
0059 return nullptr;
0060 }
0061
0062
0063 if (! CheckType(accumulable, G4AccType::kArray, warn)) {
0064 return nullptr;
0065 }
0066
0067 return static_cast<G4AccArray<T, N>*>(accumulable);
0068 }
0069
0070
0071 template <class Key, class T, class Compare, class Allocator>
0072 G4AccMap<Key, T, Compare, Allocator>*
0073 G4AccumulableManager::GetAccMap(G4VAccumulable* accumulable, G4bool warn) const
0074 {
0075
0076 if (accumulable == nullptr) {
0077 return nullptr;
0078 }
0079
0080
0081 if (! CheckType(accumulable, G4AccType::kMap, warn)) {
0082 return nullptr;
0083 }
0084
0085 return static_cast<G4AccMap<Key, T, Compare, Allocator>*>(accumulable);
0086 }
0087
0088
0089 template <typename Key, typename T, typename Hash, typename KeyEqual, typename Allocator>
0090 G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>*
0091 G4AccumulableManager::GetAccUnorderedMap(G4VAccumulable* accumulable, G4bool warn) const
0092 {
0093
0094 if (accumulable == nullptr) {
0095 return nullptr;
0096 }
0097
0098
0099 if (! CheckType(accumulable, G4AccType::kUnorderedMap, warn)) {
0100 return nullptr;
0101 }
0102
0103 return static_cast<G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>*>(accumulable);
0104 }
0105
0106
0107 template <class T, class Allocator>
0108 G4AccVector<T, Allocator>*
0109 G4AccumulableManager::GetAccVector(G4VAccumulable* accumulable, G4bool warn) const
0110 {
0111
0112 if (accumulable == nullptr) {
0113 return nullptr;
0114 }
0115
0116
0117 if (! CheckType(accumulable, G4AccType::kVector, warn)) {
0118 return nullptr;
0119 }
0120
0121 return static_cast<G4AccVector<T, Allocator>*>(accumulable);
0122 }
0123
0124
0125 template <typename T>
0126 G4AccValue<T>*
0127 G4AccumulableManager::CreateAccValue(
0128 const G4String& name, T value, G4MergeMode mergeMode)
0129 {
0130
0131 if (!CheckName(name, "CreateAccumulable")) {
0132 return 0;
0133 }
0134
0135
0136 auto accumulable = new G4AccValue<T>(name, value, mergeMode);
0137
0138
0139 Register(accumulable);
0140 fAccumulablesToDelete.push_back(accumulable);
0141
0142 return accumulable;
0143 }
0144
0145
0146 template <typename T>
0147 G4AccValue<T>*
0148 G4AccumulableManager::CreateAccValue(
0149 T value, G4MergeMode mergeMode)
0150 {
0151 return CreateAccValue<T>(G4String(), value, mergeMode);
0152 }
0153
0154
0155
0156 template <typename T>
0157 G4AccValue<T>*
0158 G4AccumulableManager::CreateAccumulable(
0159 const G4String& name, T value, G4MergeMode mergeMode)
0160 {
0161 return CreateAccValue<T>(name, value, mergeMode);
0162 }
0163
0164
0165
0166 template <typename T>
0167 G4AccValue<T>*
0168 G4AccumulableManager::CreateAccumulable(
0169 T value, G4MergeMode mergeMode)
0170 {
0171 return CreateAccValue<T>(value, mergeMode);
0172 }
0173
0174
0175 template <typename T>
0176 G4bool G4AccumulableManager::Register(G4AccValue<T>& accumulable)
0177 {
0178 return Register(&accumulable);
0179 }
0180
0181
0182 template <class T, std::size_t N>
0183 G4bool G4AccumulableManager::Register(G4AccArray<T, N>& accumulableArray)
0184 {
0185 return Register(&accumulableArray);
0186 }
0187
0188
0189 template <class Key, class T, class Compare, class Allocator>
0190 G4bool G4AccumulableManager::Register(
0191 G4AccMap<Key, T, Compare, Allocator>& accumulableMap)
0192 {
0193 return Register(&accumulableMap);
0194 }
0195
0196
0197 template <class Key, class T, class Hash, class KeyEqual, class Allocator>
0198 G4bool G4AccumulableManager::Register(
0199 G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>& accumulableUnorderedMap)
0200 {
0201 return Register(&accumulableUnorderedMap);
0202 }
0203
0204
0205 template <class T, class Allocator>
0206 G4bool G4AccumulableManager::Register(G4AccVector<T, Allocator>& accumulableVector)
0207 {
0208 return Register(&accumulableVector);
0209 }
0210
0211
0212
0213 template <typename T>
0214 G4bool G4AccumulableManager::RegisterAccumulable(G4AccValue<T>& accumulable)
0215 {
0216 return Register(&accumulable);
0217 }
0218
0219
0220 template <typename T>
0221 G4AccValue<T>*
0222 G4AccumulableManager::GetAccValue(const G4String& name, G4bool warn) const
0223 {
0224
0225 auto accumulable = GetAccumulable(name, warn);
0226 return GetAccumulable<T>(accumulable, warn);
0227 }
0228
0229
0230 template <class T, std::size_t N>
0231 G4AccArray<T, N>*
0232 G4AccumulableManager::GetAccArray(const G4String& name, G4bool warn) const
0233 {
0234
0235 auto accumulable = GetAccumulable(name, warn);
0236 return GetAccArray<T,N>(accumulable, warn);
0237 }
0238
0239
0240 template <class Key, class T, class Compare, class Allocator>
0241 G4AccMap<Key, T, Compare, Allocator>*
0242 G4AccumulableManager::GetAccMap(const G4String& name, G4bool warn) const
0243 {
0244
0245 auto accumulable = GetAccumulable(name, warn);
0246 return GetAccMap<Key, T, Compare, Allocator>(accumulable, warn);
0247 }
0248
0249
0250 template <typename Key, typename T, typename Hash, typename KeyEqual, typename Allocator>
0251 G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>*
0252 G4AccumulableManager::GetAccUnorderedMap(const G4String& name, G4bool warn) const
0253 {
0254
0255 auto accumulable = GetAccumulable(name, warn);
0256 return GetAccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>(accumulable, warn);
0257 }
0258
0259
0260 template <class T, class Allocator>
0261 G4AccVector<T, Allocator>*
0262 G4AccumulableManager::GetAccVector(const G4String& name, G4bool warn) const
0263 {
0264
0265 auto accumulable = GetAccumulable(name, warn);
0266 return GetAccVector<T,Allocator>(accumulable, warn);
0267 }
0268
0269
0270
0271 template <typename T>
0272 G4AccValue<T>*
0273 G4AccumulableManager::GetAccumulable(const G4String& name, G4bool warn) const
0274 {
0275 return GetAccValue<T>(name, warn);
0276 }
0277
0278
0279 template <typename T>
0280 G4AccValue<T>*
0281 G4AccumulableManager::GetAccValue(G4int id, G4bool warn) const
0282 {
0283
0284 auto accumulable = GetAccumulable(id, warn);
0285 return GetAccumulable<T>(accumulable, warn);
0286 }
0287
0288
0289 template <class T, std::size_t N>
0290 G4AccArray<T, N>*
0291 G4AccumulableManager::GetAccArray(G4int id, G4bool warn) const
0292 {
0293
0294 auto accumulable = GetAccumulable(id, warn);
0295 return GetAccArray<T,N>(accumulable, warn);
0296 }
0297
0298
0299 template <class Key, class T, class Compare, class Allocator>
0300 G4AccMap<Key, T, Compare, Allocator>*
0301 G4AccumulableManager::GetAccMap(G4int id, G4bool warn) const
0302 {
0303
0304 auto accumulable = GetAccumulable(id, warn);
0305 return GetAccMap<Key, T, Compare, Allocator>(accumulable, warn);
0306 }
0307
0308
0309 template <typename Key, typename T, typename Hash, typename KeyEqual, typename Allocator>
0310 G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>*
0311 G4AccumulableManager::GetAccUnorderedMap(G4int id, G4bool warn) const
0312 {
0313
0314 auto accumulable = GetAccumulable(id, warn);
0315 return GetAccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>(accumulable, warn);
0316 }
0317
0318
0319 template <class T, class Allocator>
0320 G4AccVector<T, Allocator>*
0321 G4AccumulableManager::GetAccVector(G4int id, G4bool warn) const
0322 {
0323
0324 auto accumulable = GetAccumulable(id, warn);
0325 return GetAccVector<T,Allocator>(accumulable, warn);
0326 }
0327
0328
0329
0330 template <typename T>
0331 G4AccValue<T>*
0332 G4AccumulableManager::GetAccumulable(G4int id, G4bool warn) const
0333 {
0334 return GetAccValue<T>(id, warn);
0335 }
0336
0337
0338 inline G4int G4AccumulableManager::GetNofAccumulables() const
0339 {
0340 return G4int(fVector.size());
0341 }
0342
0343
0344 inline std::vector<G4VAccumulable*>::iterator G4AccumulableManager::Begin()
0345 {
0346 return fVector.begin();
0347 }
0348
0349
0350 inline std::vector<G4VAccumulable*>::iterator G4AccumulableManager::End()
0351 {
0352 return fVector.end();
0353 }
0354
0355
0356 inline std::vector<G4VAccumulable*>::const_iterator
0357 G4AccumulableManager::BeginConst() const
0358 {
0359 return fVector.begin();
0360 }
0361
0362
0363 inline std::vector<G4VAccumulable*>::const_iterator
0364 G4AccumulableManager::EndConst() const
0365 {
0366 return fVector.end();
0367 }
0368
0369
0370 inline void G4AccumulableManager::SetVerboseLevel(G4int value)
0371 {
0372 G4Accumulables::VerboseLevel = value;
0373 }
0374
0375
0376 inline G4int G4AccumulableManager::GetVerboseLevel() const
0377 {
0378 return G4Accumulables::VerboseLevel;
0379 }