Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-08-02 08:28:13

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