Warning, file /include/Geant4/G4AccVector.icc was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
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 #include <algorithm>
0030
0031
0032
0033
0034
0035
0036
0037 template <class T, class Allocator>
0038 G4AccVector<T, Allocator>::G4AccVector(
0039 const G4String& name,
0040 G4MergeMode mergeMode)
0041 : G4VAccumulable(name, mergeMode),
0042 fVector(),
0043 fMergeFunction(G4Accumulables::GetMergeFunction<T>(mergeMode))
0044 {
0045 if (G4Accumulables::VerboseLevel > 1 ) {
0046 G4cout << "G4AccVector ctor1" << G4endl;
0047 }
0048 }
0049
0050
0051
0052 template <class T, class Allocator>
0053 G4AccVector<T, Allocator>::G4AccVector(
0054 const Allocator& allocator,
0055 G4MergeMode mergeMode)
0056 : G4VAccumulable(mergeMode),
0057 fVector(allocator),
0058 fMergeFunction(G4Accumulables::GetMergeFunction<T>(mergeMode))
0059 {
0060 if (G4Accumulables::VerboseLevel > 1 ) {
0061 G4cout << "G4AccVector ctor2" << G4endl;
0062 }
0063 }
0064
0065
0066
0067 template <class T, class Allocator>
0068 G4AccVector<T, Allocator>::G4AccVector(
0069 const G4String& name,
0070 const Allocator& allocator,
0071 G4MergeMode mergeMode)
0072 : G4VAccumulable(name, mergeMode),
0073 fVector(allocator),
0074 fMergeFunction(G4Accumulables::GetMergeFunction<T>(mergeMode))
0075 {
0076 if (G4Accumulables::VerboseLevel > 1 ) {
0077 G4cout << "G4AccVector ctor2n" << G4endl;
0078 }
0079 }
0080
0081
0082
0083 template <class T, class Allocator>
0084 G4AccVector<T, Allocator>::G4AccVector(
0085 std::size_t count, const T& value,
0086 G4MergeMode mergeMode, const Allocator& allocator)
0087 : G4VAccumulable(mergeMode),
0088 fVector(count, value, allocator),
0089 fInitValue(value),
0090 fMergeFunction(G4Accumulables::GetMergeFunction<T>(mergeMode))
0091 {
0092 if (G4Accumulables::VerboseLevel > 1 ) {
0093 G4cout << "G4AccVector ctor3" << G4endl;
0094 }
0095 }
0096
0097
0098
0099 template <class T, class Allocator>
0100 G4AccVector<T, Allocator>::G4AccVector(
0101 const G4String& name,
0102 std::size_t count, const T& value,
0103 G4MergeMode mergeMode, const Allocator& allocator)
0104 : G4VAccumulable(name, mergeMode),
0105 fVector(count, value, allocator),
0106 fInitValue(value),
0107 fMergeFunction(G4Accumulables::GetMergeFunction<T>(mergeMode))
0108 {
0109 if (G4Accumulables::VerboseLevel > 1 ) {
0110 G4cout << "G4AccVector ctor3n" << G4endl;
0111 }
0112 }
0113
0114
0115
0116 template <class T, class Allocator>
0117 G4AccVector<T, Allocator>::G4AccVector(
0118 std::size_t count,
0119 G4MergeMode mergeMode, const Allocator& allocator)
0120 : G4VAccumulable(mergeMode),
0121 fVector(count, allocator),
0122 fMergeFunction(G4Accumulables::GetMergeFunction<T>(mergeMode))
0123 {
0124 if (G4Accumulables::VerboseLevel > 1 ) {
0125 G4cout << "G4AccVector ctor4" << G4endl;
0126 }
0127 }
0128
0129
0130
0131 template <class T, class Allocator>
0132 G4AccVector<T, Allocator>::G4AccVector(
0133 const G4String& name,
0134 std::size_t count,
0135 G4MergeMode mergeMode, const Allocator& allocator)
0136 : G4VAccumulable(name, mergeMode),
0137 fVector(count, allocator),
0138 fMergeFunction(G4Accumulables::GetMergeFunction<T>(mergeMode))
0139 {
0140 if (G4Accumulables::VerboseLevel > 1 ) {
0141 G4cout << "G4AccVector ctor4n" << G4endl;
0142 }
0143 }
0144
0145
0146
0147 template <class T, class Allocator>
0148 G4AccVector<T, Allocator>::G4AccVector(
0149 std::initializer_list<T> init,
0150 G4MergeMode mergeMode, const Allocator& allocator)
0151 : G4VAccumulable(mergeMode),
0152 fVector(init, allocator),
0153 fMergeFunction(G4Accumulables::GetMergeFunction<T>(mergeMode))
0154 {
0155 if (G4Accumulables::VerboseLevel > 1 ) {
0156 G4cout << "G4AccVector ctor10" << G4endl;
0157 }
0158 }
0159
0160
0161
0162 template <class T, class Allocator>
0163 G4AccVector<T, Allocator>::G4AccVector(
0164 const G4String& name,
0165 std::initializer_list<T> init,
0166 G4MergeMode mergeMode, const Allocator& allocator)
0167 : G4VAccumulable(name, mergeMode),
0168 fVector(init, allocator),
0169 fMergeFunction(G4Accumulables::GetMergeFunction<T>(mergeMode))
0170 {
0171 if (G4Accumulables::VerboseLevel > 1 ) {
0172 G4cout << "G4AccVector ctor10n" << G4endl;
0173 }
0174 }
0175
0176
0177
0178 template <class T, class Allocator>
0179 G4AccVector<T, Allocator>::G4AccVector(
0180 const G4AccVector& rhs, const Allocator& allocator)
0181 : G4VAccumulable(rhs),
0182 fVector(rhs, allocator),
0183 fMergeFunction(rhs.fMergeFunction)
0184 {}
0185
0186
0187
0188 template <class T, class Allocator>
0189 G4AccVector<T, Allocator>::G4AccVector(
0190 G4AccVector&& rhs, const Allocator& allocator)
0191 : G4VAccumulable(std::move(rhs)),
0192 fVector(std::move(rhs), allocator),
0193 fMergeFunction(rhs.fMergeFunction)
0194 {}
0195
0196
0197 template <class T, class Allocator>
0198 void G4AccVector<T, Allocator>::Merge(const G4VAccumulable& other)
0199 {
0200 const auto& otherVector = static_cast<const G4AccVector<T, Allocator>&>(other);
0201
0202 if (G4Accumulables::VerboseLevel > 2 ) {
0203 G4cout << "G4AccVector<T, Allocator>::Merge: " << G4endl;
0204 G4cout << "destination: ";
0205 for (const auto& v : fVector) {
0206 G4cout << v << ", ";
0207 }
0208 G4cout << G4endl;
0209 G4cout << "merged data: ";
0210 for (const auto& v : otherVector.fVector) {
0211 G4cout << v << ", ";
0212 }
0213 G4cout << G4endl;
0214 }
0215
0216 std::transform(fVector.begin(), fVector.end(), otherVector.fVector.begin(),
0217 fVector.begin(), fMergeFunction);
0218 }
0219
0220
0221 template <class T, class Allocator>
0222 void G4AccVector<T, Allocator>::Reset()
0223 {
0224 for (auto& value : fVector) {
0225 value = fInitValue;
0226 }
0227 }
0228
0229
0230 template <class T, class Allocator>
0231 void G4AccVector<T, Allocator>::Print(G4PrintOptions options) const
0232 {
0233 if (options.Has(G4PrintOptions::kType)) {
0234 G4cout << "vector<" << typeid(T).name() << ">: ";
0235 }
0236
0237 PrintBase(options);
0238
0239 bool first = true;
0240 for (const auto& value : fVector) {
0241 if (! first) { G4cout << ", "; }
0242 G4cout << value;
0243 first = false;
0244 }
0245 G4cout << G4endl;
0246 }
0247
0248
0249 template <class T, class Allocator>
0250 void G4AccVector<T, Allocator>::SetMergeMode(G4MergeMode value)
0251 {
0252 G4VAccumulable::SetMergeMode(value);
0253 fMergeFunction = G4Accumulables::GetMergeFunction<T>(fMergeMode);
0254 }