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// ********************************************************************
35using namespace G4Accumulables;
37//_____________________________________________________________________________
39G4Accumulable<T>::G4Accumulable(const G4String& name, T initValue, G4MergeMode mergeMode)
40 : G4VAccumulable(name),
42 fInitValue(initValue),
43 fMergeMode(mergeMode),
44 fMergeFunction(GetMergeFunction<T>(mergeMode))
47//_____________________________________________________________________________
49G4Accumulable<T>::G4Accumulable(T initValue, G4MergeMode mergeMode)
52 fInitValue(initValue),
53 fMergeMode(mergeMode),
54 fMergeFunction(GetMergeFunction<T>(mergeMode))
57//_____________________________________________________________________________
59G4Accumulable<T>::G4Accumulable(const G4Accumulable& rhs)
60 : G4VAccumulable(rhs),
62 fInitValue(rhs.fInitValue),
63 fMergeMode(rhs.fMergeMode),
64 fMergeFunction(rhs.fMergeFunction)
67//_____________________________________________________________________________
69G4Accumulable<T>::G4Accumulable(G4Accumulable&& rhs)
70 : G4VAccumulable(rhs),
71 fValue(std::move(rhs.fValue)),
72 fInitValue(std::move(rhs.fInitValue)),
73 fMergeMode(rhs.fMergeMode),
74 fMergeFunction(rhs.fMergeFunction)
77//_____________________________________________________________________________
80G4Accumulable<T>::operator=(const G4Accumulable<T>& rhs)
82 // check assignment to self
83 if (this == &rhs) return *this;
85 // base class assignment
86 G4VAccumulable::operator=(rhs);
88 // this class data assignment
90 fInitValue = rhs.fInitValue;
91 fMergeMode = rhs.fMergeMode;
92 fMergeFunction = rhs.fMergeFunction;
97//_____________________________________________________________________________
100G4Accumulable<T>::operator=(G4Accumulable<T>&& rhs)
102 // check assignment to self
103 if (this == &rhs) return *this;
105 // base class assignment
106 G4VAccumulable::operator=(rhs);
108 // this class data assignment
109 fValue = std::move(rhs.fValue);
110 fInitValue = std::move(rhs.fInitValue);
111 fMergeMode = rhs.fMergeMode;
112 fMergeFunction = rhs.fMergeFunction;
117//_____________________________________________________________________________
120G4Accumulable<T>::operator+=(const G4Accumulable<T>& rhs)
122 // only update the value from rhs
123 fValue += rhs.fValue;
127//_____________________________________________________________________________
130G4Accumulable<T>::operator*=(const G4Accumulable<T>& rhs)
132 // only update the value from rhs
133 fValue *= rhs.fValue;
137//_____________________________________________________________________________
140G4Accumulable<T>::operator=(const T& value)
142 // only update the value
147//_____________________________________________________________________________
150G4Accumulable<T>::operator+=(const T& value)
152 // only update the value
157//_____________________________________________________________________________
160G4Accumulable<T>::operator*=(const T& value)
162 // only update the value from rhs
167//_____________________________________________________________________________
170G4Accumulable<T>::operator++(int)
173 G4Accumulable<T> temp = *this;
178//_____________________________________________________________________________
181G4Accumulable<T>::operator++()
188//_____________________________________________________________________________
190void G4Accumulable<T>::Merge(const G4VAccumulable& other)
192 // G4cout << "Merging other: " << other.GetName() << " " << static_cast<const G4Accumulable<T>&>(other).fValue << G4endl;
193 // G4cout << " to master: " << fName << " " << fValue << G4endl;
194 fValue = fMergeFunction(fValue, static_cast<const G4Accumulable<T>&>(other).fValue);
195 // G4cout << " new value: " << fName << " " << fValue << G4endl;
198//_____________________________________________________________________________
200void G4Accumulable<T>::Reset()
205//_____________________________________________________________________________
207T G4Accumulable<T>::GetValue() const