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 // utilities
0029 //
0030 
0031 //
0032 // public functions
0033 //
0034 
0035 using namespace G4Accumulables;
0036 
0037 //_____________________________________________________________________________
0038 template <typename T>
0039 G4Accumulable<T>::G4Accumulable(const G4String& name, T initValue, G4MergeMode mergeMode)
0040  : G4VAccumulable(name),
0041    fValue(initValue),
0042    fInitValue(initValue),
0043    fMergeMode(mergeMode),
0044    fMergeFunction(GetMergeFunction<T>(mergeMode))
0045 {}
0046 
0047 //_____________________________________________________________________________
0048 template <typename T>
0049 G4Accumulable<T>::G4Accumulable(T initValue, G4MergeMode mergeMode)
0050  : G4VAccumulable(),
0051    fValue(initValue),
0052    fInitValue(initValue),
0053    fMergeMode(mergeMode),
0054    fMergeFunction(GetMergeFunction<T>(mergeMode))
0055 {}
0056 
0057 //_____________________________________________________________________________
0058 template <typename T>
0059 G4Accumulable<T>::G4Accumulable(const G4Accumulable& rhs)
0060   : G4VAccumulable(rhs),
0061     fValue(rhs.fValue),
0062     fInitValue(rhs.fInitValue),
0063     fMergeMode(rhs.fMergeMode),
0064     fMergeFunction(rhs.fMergeFunction)
0065 {}
0066 
0067 //_____________________________________________________________________________
0068 template <typename T>
0069 G4Accumulable<T>::G4Accumulable(G4Accumulable&& rhs) noexcept
0070   : G4VAccumulable(rhs),
0071     fValue(std::move(rhs.fValue)),
0072     fInitValue(std::move(rhs.fInitValue)),
0073     fMergeMode(rhs.fMergeMode),
0074     fMergeFunction(rhs.fMergeFunction)
0075 {}
0076 
0077 //_____________________________________________________________________________
0078 template <typename T>
0079 G4Accumulable<T>&
0080 G4Accumulable<T>::operator=(const G4Accumulable<T>& rhs)
0081 {
0082   // check assignment to self
0083   if (this == &rhs) return *this;
0084 
0085   // base class assignment
0086   G4VAccumulable::operator=(rhs);
0087 
0088   // this class data assignment
0089   fValue = rhs.fValue;
0090   fInitValue = rhs.fInitValue;
0091   fMergeMode = rhs.fMergeMode;
0092   fMergeFunction = rhs.fMergeFunction;
0093 
0094   return *this;
0095 }
0096 
0097 //_____________________________________________________________________________
0098 template <typename T>
0099 G4Accumulable<T>& G4Accumulable<T>::operator=(G4Accumulable<T>&& rhs) noexcept
0100 {
0101   // check assignment to self
0102   if (this == &rhs) return *this;
0103 
0104   // base class assignment
0105   G4VAccumulable::operator=(rhs);
0106 
0107   // this class data assignment
0108   fValue = std::move(rhs.fValue);
0109   fInitValue = std::move(rhs.fInitValue);
0110   fMergeMode = rhs.fMergeMode;
0111   fMergeFunction = rhs.fMergeFunction;
0112 
0113   return *this;
0114 }
0115 
0116 //_____________________________________________________________________________
0117 template <typename T>
0118 G4Accumulable<T>&
0119 G4Accumulable<T>::operator+=(const G4Accumulable<T>& rhs)
0120 {
0121   // only update the value from rhs
0122   fValue += rhs.fValue;
0123   return *this;
0124 }
0125 
0126 //_____________________________________________________________________________
0127 template <typename T>
0128 G4Accumulable<T>&
0129 G4Accumulable<T>::operator*=(const G4Accumulable<T>& rhs)
0130 {
0131   // only update the value from rhs
0132   fValue *= rhs.fValue;
0133   return *this;
0134 }
0135 
0136 //_____________________________________________________________________________
0137 template <typename T>
0138 G4Accumulable<T>&
0139 G4Accumulable<T>::operator=(const T& value)
0140 {
0141   // only update the value
0142   fValue = value;
0143   return *this;
0144 }
0145 
0146 //_____________________________________________________________________________
0147 template <typename T>
0148 G4Accumulable<T>&
0149 G4Accumulable<T>::operator+=(const T& value)
0150 {
0151   // only update the value
0152   fValue += value;
0153   return *this;
0154 }
0155 
0156 //_____________________________________________________________________________
0157 template <typename T>
0158 G4Accumulable<T>&
0159 G4Accumulable<T>::operator*=(const T& value)
0160 {
0161   // only update the value from rhs
0162   fValue *= value;
0163   return *this;
0164 }
0165 
0166 //_____________________________________________________________________________
0167 template <typename T>
0168 G4Accumulable<T>
0169 G4Accumulable<T>::operator++(int)
0170 {
0171   // postfix increment
0172   G4Accumulable<T> temp = *this;
0173   fValue++;
0174   return temp;
0175 }
0176 
0177 //_____________________________________________________________________________
0178 template <typename T>
0179 G4Accumulable<T>&
0180 G4Accumulable<T>::operator++()
0181 {
0182   // prefix increment
0183   fValue++;
0184   return *this;
0185 }
0186 
0187 //_____________________________________________________________________________
0188 template <typename T>
0189 void G4Accumulable<T>::Merge(const G4VAccumulable& other)
0190 {
0191   // G4cout << "Merging other: " << other.GetName() << " " << static_cast<const G4Accumulable<T>&>(other).fValue << G4endl;
0192   // G4cout << "    to master: " << fName << " " << fValue << G4endl;
0193   fValue = fMergeFunction(fValue, static_cast<const G4Accumulable<T>&>(other).fValue);
0194   // G4cout << "    new value: " << fName << " " << fValue << G4endl;
0195 }
0196 
0197 //_____________________________________________________________________________
0198 template <typename T>
0199 void G4Accumulable<T>::Reset()
0200 {
0201   fValue = fInitValue;
0202 }
0203 
0204 //_____________________________________________________________________________
0205 template <typename T>
0206 T  G4Accumulable<T>::GetValue() const
0207 {
0208   return fValue;
0209 }