Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:57:51

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 //_____________________________________________________________________________
0028 template <typename T>
0029 G4Accumulable<T>*
0030 G4AccumulableManager::GetAccumulable(G4VAccumulable* accumulable, G4bool warn) const
0031 {
0032   // Do not check type if nullptr
0033   if ( ! accumulable ) return nullptr;
0034 
0035   // check type
0036   auto taccumulable = dynamic_cast<G4Accumulable<T>*>(accumulable);
0037   if ( ! taccumulable && warn ) {
0038     G4ExceptionDescription description;
0039     description << "      " << "Accumulable " << accumulable->GetName()
0040                 << " has different type";
0041     G4Exception("G4AccumulableManager::GetAccumulable<T>",
0042                 "Analysis_W001", JustWarning, description);
0043     return nullptr;
0044   }
0045 
0046   return taccumulable;
0047 }
0048 
0049 //_____________________________________________________________________________
0050 template <typename T>
0051 G4Accumulable<T>*
0052 G4AccumulableManager::CreateAccumulable(
0053   const G4String& name, T value, G4MergeMode mergeMode)
0054 {
0055   // do not accept name if it is already used
0056   if ( ! CheckName(name, "CreateAccumulable") ) return 0;
0057 
0058   // create accumulable
0059   auto accumulable = new G4Accumulable<T>(name, value, mergeMode);
0060 
0061   // register accumulable in the map and vector
0062   RegisterAccumulable(accumulable);
0063   fAccumulablesToDelete.push_back(accumulable);
0064 
0065   return accumulable;
0066 }
0067 
0068 //_____________________________________________________________________________
0069 template <typename T>
0070 G4Accumulable<T>*
0071 G4AccumulableManager::CreateAccumulable(
0072   T value, G4MergeMode mergeMode)
0073 {
0074   return CreateAccumulable(G4String(), value, mergeMode);
0075 }
0076 
0077 //_____________________________________________________________________________
0078 template <typename T>
0079 G4bool  G4AccumulableManager::RegisterAccumulable(G4Accumulable<T>& accumulable)
0080 {
0081   return RegisterAccumulable(&accumulable);
0082 }
0083 
0084 //_____________________________________________________________________________
0085 template <typename T>
0086 G4Accumulable<T>*
0087 G4AccumulableManager::GetAccumulable(const G4String& name, G4bool warn) const
0088 {
0089   // get G4VParammeter from the map
0090   auto accumulable = GetAccumulable(name, warn);
0091   return GetAccumulable<T>(accumulable, warn);
0092 }
0093 
0094 //_____________________________________________________________________________
0095 template <typename T>
0096 G4Accumulable<T>*
0097 G4AccumulableManager::GetAccumulable(G4int id, G4bool warn) const
0098 {
0099   // get G4VParammeter from the map
0100   auto accumulable = GetAccumulable(id, warn);
0101   return GetAccumulable<T>(accumulable, warn);
0102 }
0103 
0104 //_____________________________________________________________________________
0105 inline G4int G4AccumulableManager::GetNofAccumulables() const
0106 {
0107   return G4int(fVector.size());
0108 }
0109 
0110 //_____________________________________________________________________________
0111 inline std::vector<G4VAccumulable*>::iterator G4AccumulableManager::Begin()
0112 {
0113   return fVector.begin();
0114 }
0115 
0116 //_____________________________________________________________________________
0117 inline std::vector<G4VAccumulable*>::iterator G4AccumulableManager::End()
0118 {
0119   return fVector.end();
0120 }
0121 
0122 //_____________________________________________________________________________
0123 inline std::vector<G4VAccumulable*>::const_iterator
0124 G4AccumulableManager::BeginConst() const
0125 {
0126   return fVector.begin();
0127 }
0128 
0129 //_____________________________________________________________________________
0130 inline std::vector<G4VAccumulable*>::const_iterator
0131 G4AccumulableManager::EndConst() const
0132 {
0133   return fVector.end();
0134 }