2 // ********************************************************************
3 // * License and Disclaimer *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
36 using namespace G4Accumulables;
38 //_____________________________________________________________________________
40 G4Accumulable<T>::G4Accumulable(const G4String& name, T initValue, G4MergeMode mergeMode)
41 : G4VAccumulable(name),
43 fInitValue(initValue),
44 fMergeMode(mergeMode),
45 fMergeFunction(GetMergeFunction<T>(mergeMode))
48 //_____________________________________________________________________________
50 G4Accumulable<T>::G4Accumulable(T initValue, G4MergeMode mergeMode)
53 fInitValue(initValue),
54 fMergeMode(mergeMode),
55 fMergeFunction(GetMergeFunction<T>(mergeMode))
58 //_____________________________________________________________________________
60 G4Accumulable<T>::G4Accumulable(const G4Accumulable& rhs)
61 : G4VAccumulable(rhs),
63 fInitValue(rhs.fInitValue),
64 fMergeMode(rhs.fMergeMode),
65 fMergeFunction(rhs.fMergeFunction)
68 //_____________________________________________________________________________
70 G4Accumulable<T>::~G4Accumulable()
73 //_____________________________________________________________________________
76 G4Accumulable<T>::operator=(const G4Accumulable<T>& rhs)
78 // check assignment to self
79 if (this == &rhs) return *this;
81 // base class assignment
82 G4VAccumulable::operator=(rhs);
84 // this class data assignment
86 fInitValue = rhs.fInitValue;
87 fMergeMode = rhs.fMergeMode;
88 fMergeFunction = rhs.fMergeFunction;
93 //_____________________________________________________________________________
96 G4Accumulable<T>::operator+=(const G4Accumulable<T>& rhs)
98 // only update the value from rhs
103 //_____________________________________________________________________________
104 template <typename T>
106 G4Accumulable<T>::operator*=(const G4Accumulable<T>& rhs)
108 // only update the value from rhs
109 fValue *= rhs.fValue;
113 //_____________________________________________________________________________
114 template <typename T>
116 G4Accumulable<T>::operator=(const T& value)
118 // only update the value
123 //_____________________________________________________________________________
124 template <typename T>
126 G4Accumulable<T>::operator+=(const T& value)
128 // only update the value
133 //_____________________________________________________________________________
134 template <typename T>
136 G4Accumulable<T>::operator*=(const T& value)
138 // only update the value from rhs
143 //_____________________________________________________________________________
144 template <typename T>
146 G4Accumulable<T>::operator++(int)
149 G4Accumulable<T> temp = *this;
154 //_____________________________________________________________________________
155 template <typename T>
157 G4Accumulable<T>::operator++()
164 //_____________________________________________________________________________
165 template <typename T>
166 void G4Accumulable<T>::Merge(const G4VAccumulable& other)
168 // G4cout << "Merging other: " << other.GetName() << " " << static_cast<const G4Accumulable<T>&>(other).fValue << G4endl;
169 // G4cout << " to master: " << fName << " " << fValue << G4endl;
170 fValue = fMergeFunction(fValue, static_cast<const G4Accumulable<T>&>(other).fValue);
171 // G4cout << " new value: " << fName << " " << fValue << G4endl;
174 //_____________________________________________________________________________
175 template <typename T>
176 void G4Accumulable<T>::Reset()
181 //_____________________________________________________________________________
182 template <typename T>
183 T G4Accumulable<T>::GetValue() const