File indexing completed on 2025-08-02 08:28:13
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
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
0076 if (this == &rhs) {
0077 return *this;
0078 }
0079
0080
0081 G4VAccumulable::operator=(rhs);
0082
0083
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
0096 if (this == &rhs) {
0097 return *this;
0098 }
0099
0100
0101 G4VAccumulable::operator=(rhs);
0102
0103
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
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
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
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
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
0157 fValue *= value;
0158 return *this;
0159 }
0160
0161
0162 template <typename T>
0163 G4AccValue<T>
0164 G4AccValue<T>::operator++(int)
0165 {
0166
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
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 }