Geant4 Cross Reference |
1 // 1 2 // ******************************************* 3 // * License and Disclaimer 4 // * 5 // * The Geant4 software is copyright of th 6 // * the Geant4 Collaboration. It is provided 7 // * conditions of the Geant4 Software License 8 // * LICENSE and available at http://cern.ch/ 9 // * include a list of copyright holders. 10 // * 11 // * Neither the authors of this software syst 12 // * institutes,nor the agencies providing fin 13 // * work make any representation or warran 14 // * regarding this software system or assum 15 // * use. Please see the license in the file 16 // * for the full disclaimer and the limitatio 17 // * 18 // * This code implementation is the result 19 // * technical work of the GEANT4 collaboratio 20 // * By using, copying, modifying or distri 21 // * any work based on the software) you ag 22 // * use in resulting scientific publicati 23 // * acceptance of all terms of the Geant4 Sof 24 // ******************************************* 25 // 26 27 // Author: Ivana Hrivnacova, IJCLab IN2P3/CNRS 28 29 #include <algorithm> 30 31 // 32 // public functions 33 // 34 35 // Default constructor (1) 36 //____________________________________________ 37 template <class T, class Allocator> 38 G4AccVector<T, Allocator>::G4AccVector( 39 const G4String& name, 40 G4MergeMode mergeMode) 41 : G4VAccumulable(name, mergeMode), 42 fVector(), 43 fMergeFunction(GetMergeFunction<T>(mergeMode 44 { 45 if (G4Accumulables::VerboseLevel > 1 ) { 46 G4cout << "G4AccVector ctor1" << G4endl; 47 } 48 } 49 50 // Constructor (2) 51 //____________________________________________ 52 template <class T, class Allocator> 53 G4AccVector<T, Allocator>::G4AccVector( 54 const Allocator& allocator, 55 G4MergeMode mergeMode) 56 : G4VAccumulable(mergeMode), 57 fVector(allocator), 58 fMergeFunction(GetMergeFunction<T>(mergeMode 59 { 60 if (G4Accumulables::VerboseLevel > 1 ) { 61 G4cout << "G4AccVector ctor2" << G4endl; 62 } 63 } 64 65 // Constructor (2) with name 66 //____________________________________________ 67 template <class T, class Allocator> 68 G4AccVector<T, Allocator>::G4AccVector( 69 const G4String& name, 70 const Allocator& allocator, 71 G4MergeMode mergeMode) 72 : G4VAccumulable(name, mergeMode), 73 fVector(allocator), 74 fMergeFunction(GetMergeFunction<T>(mergeMode 75 { 76 if (G4Accumulables::VerboseLevel > 1 ) { 77 G4cout << "G4AccVector ctor2n" << G4endl; 78 } 79 } 80 81 // Constructor (3) 82 //____________________________________________ 83 template <class T, class Allocator> 84 G4AccVector<T, Allocator>::G4AccVector( 85 std::size_t count, const T& value, 86 G4MergeMode mergeMode, const Allocator& allo 87 : G4VAccumulable(mergeMode), 88 fVector(count, value, allocator), 89 fInitValue(value), 90 fMergeFunction(GetMergeFunction<T>(mergeMode 91 { 92 if (G4Accumulables::VerboseLevel > 1 ) { 93 G4cout << "G4AccVector ctor3" << G4endl; 94 } 95 } 96 97 // Constructor (3) with name 98 //____________________________________________ 99 template <class T, class Allocator> 100 G4AccVector<T, Allocator>::G4AccVector( 101 const G4String& name, 102 std::size_t count, const T& value, 103 G4MergeMode mergeMode, const Allocator& allo 104 : G4VAccumulable(name, mergeMode), 105 fVector(count, value, allocator), 106 fInitValue(value), 107 fMergeFunction(GetMergeFunction<T>(mergeMode 108 { 109 if (G4Accumulables::VerboseLevel > 1 ) { 110 G4cout << "G4AccVector ctor3n" << G4endl; 111 } 112 } 113 114 // Constructor (4) 115 //____________________________________________ 116 template <class T, class Allocator> 117 G4AccVector<T, Allocator>::G4AccVector( 118 std::size_t count, 119 G4MergeMode mergeMode, const Allocator& allo 120 : G4VAccumulable(mergeMode), 121 fVector(count, allocator), 122 fMergeFunction(GetMergeFunction<T>(mergeMode 123 { 124 if (G4Accumulables::VerboseLevel > 1 ) { 125 G4cout << "G4AccVector ctor4" << G4endl; 126 } 127 } 128 129 // Constructor (4) with name 130 //____________________________________________ 131 template <class T, class Allocator> 132 G4AccVector<T, Allocator>::G4AccVector( 133 const G4String& name, 134 std::size_t count, 135 G4MergeMode mergeMode, const Allocator& allo 136 : G4VAccumulable(name, mergeMode), 137 fVector(count, allocator), 138 fMergeFunction(GetMergeFunction<T>(mergeMode 139 { 140 if (G4Accumulables::VerboseLevel > 1 ) { 141 G4cout << "G4AccVector ctor4n" << G4endl; 142 } 143 } 144 145 // Constructor (10) 146 //____________________________________________ 147 template <class T, class Allocator> 148 G4AccVector<T, Allocator>::G4AccVector( 149 std::initializer_list<T> init, 150 G4MergeMode mergeMode, const Allocator& allo 151 : G4VAccumulable(mergeMode), 152 fVector(init, allocator), 153 fMergeFunction(GetMergeFunction<T>(mergeMode 154 { 155 if (G4Accumulables::VerboseLevel > 1 ) { 156 G4cout << "G4AccVector ctor10" << G4endl; 157 } 158 } 159 160 // Constructor (10) with name 161 //____________________________________________ 162 template <class T, class Allocator> 163 G4AccVector<T, Allocator>::G4AccVector( 164 const G4String& name, 165 std::initializer_list<T> init, 166 G4MergeMode mergeMode, const Allocator& allo 167 : G4VAccumulable(name, mergeMode), 168 fVector(init, allocator), 169 fMergeFunction(GetMergeFunction<T>(mergeMode 170 { 171 if (G4Accumulables::VerboseLevel > 1 ) { 172 G4cout << "G4AccVector ctor10n" << G4endl; 173 } 174 } 175 176 // Copy ctor 177 //____________________________________________ 178 template <class T, class Allocator> 179 G4AccVector<T, Allocator>::G4AccVector( 180 const G4AccVector& rhs, const Allocator& all 181 : G4VAccumulable(rhs), 182 fVector(rhs, allocator), 183 fMergeFunction(rhs.fMergeFunction) 184 {} 185 186 // Move ctor 187 //____________________________________________ 188 template <class T, class Allocator> 189 G4AccVector<T, Allocator>::G4AccVector( 190 G4AccVector&& rhs, const Allocator& allocat 191 : G4VAccumulable(std::move(rhs)), 192 fVector(std::move(rhs), allocator), 193 fMergeFunction(rhs.fMergeFunction) 194 {} 195 196 //____________________________________________ 197 template <class T, class Allocator> 198 void G4AccVector<T, Allocator>::Merge(const G4 199 { 200 const auto& otherVector = static_cast<const 201 202 if (G4Accumulables::VerboseLevel > 2 ) { 203 G4cout << "G4AccVector<T, Allocator>::Merg 204 G4cout << "destination: "; 205 for (const auto& v : fVector) { 206 G4cout << v << ", "; 207 } 208 G4cout << G4endl; 209 G4cout << "merged data: "; 210 for (const auto& v : otherVector.fVector) 211 G4cout << v << ", "; 212 } 213 G4cout << G4endl; 214 } 215 216 std::transform(fVector.begin(), fVector.end( 217 fVector.begin(), fMergeFuncti 218 } 219 220 //____________________________________________ 221 template <class T, class Allocator> 222 void G4AccVector<T, Allocator>::Reset() 223 { 224 for (auto& value : fVector) { 225 value = fInitValue; 226 } 227 } 228 229 //____________________________________________ 230 template <class T, class Allocator> 231 void G4AccVector<T, Allocator>::Print(G4PrintO 232 { 233 if (options.Has(G4PrintOptions::kType)) { 234 G4cout << "vector<" << typeid(T).name() << 235 } 236 237 PrintBase(options); 238 239 bool first = true; 240 for (const auto& value : fVector) { 241 if (! first) { G4cout << ", "; } 242 G4cout << value; 243 first = false; 244 } 245 G4cout << G4endl; 246 } 247 248 //____________________________________________ 249 template <class T, class Allocator> 250 void G4AccVector<T, Allocator>::SetMergeMode(G 251 { 252 G4VAccumulable::SetMergeMode(value); 253 fMergeFunction = GetMergeFunction<T>(fMergeM 254 } 255