Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-16 08:55:42

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 
0027 // Author: Ivana Hrivnacova, IJCLab IN2P3/CNRS, 07/09/2015
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   // Do not check type if nullptr
0040   if (accumulable == nullptr) {
0041     return nullptr;
0042   }
0043 
0044   // check type
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   // Do not check type if nullptr
0058   if (accumulable == nullptr) {
0059     return nullptr;
0060   }
0061 
0062   // check type
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   // Do not check type if nullptr
0076   if (accumulable == nullptr) {
0077     return nullptr;
0078   }
0079 
0080   // check type
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   // Do not check type if nullptr
0094   if (accumulable == nullptr) {
0095     return nullptr;
0096   }
0097 
0098   // check type
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   // Do not check type if nullptr
0112   if (accumulable == nullptr) {
0113     return nullptr;
0114   }
0115 
0116   // check type
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   // do not accept name if it is already used
0131   if (!CheckName(name, "CreateAccumulable")) {
0132     return 0;
0133   }
0134 
0135   // create accumulable
0136   auto accumulable = new G4AccValue<T>(name, value, mergeMode);
0137 
0138   // register accumulable in the map and vector
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 // Deprecated function using the old accumulable value name
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 // Deprecated function using the old accumulable value name
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 // Deprecated functions with long name
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   // get G4VAccummulable from the map
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   // get G4VAccummulable from the map
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   // get G4VAccummulable from the map
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   // get G4VAccummulable from the map
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   // get G4VAccummulable from the map
0265   auto accumulable = GetAccumulable(name, warn);
0266   return GetAccVector<T,Allocator>(accumulable, warn);
0267 }
0268 
0269 // Deprecated function using the old accumulable value name
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   // get G4VAccummulable from the map
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   // get G4VAccummulable from the map
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   // get G4VAccummulable from the map
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   // get G4VAccummulable from the map
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   // get G4VAccummulable from the map
0324   auto accumulable = GetAccumulable(id, warn);
0325   return GetAccVector<T,Allocator>(accumulable, warn);
0326 }
0327 
0328 // Deprecated function using the old accumulable value name
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 }