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 "G4AccArray.hh" 30 #include "G4AccMap.hh" 31 #include "G4AccUnorderedMap.hh" 32 #include "G4AccVector.hh" 33 34 //____________________________________________ 35 template <typename T> 36 G4AccValue<T>* 37 G4AccumulableManager::GetAccumulable(G4VAccumu 38 { 39 // Do not check type if nullptr 40 if (accumulable == nullptr) { 41 return nullptr; 42 } 43 44 // check type 45 if (! CheckType(accumulable, G4AccType::kVal 46 return nullptr; 47 } 48 49 return static_cast<G4AccValue<T>*>(accumulab 50 } 51 52 //____________________________________________ 53 template <typename T, std::size_t N> 54 G4AccArray<T, N>* 55 G4AccumulableManager::GetAccArray(G4VAccumulab 56 { 57 // Do not check type if nullptr 58 if (accumulable == nullptr) { 59 return nullptr; 60 } 61 62 // check type 63 if (! CheckType(accumulable, G4AccType::kArr 64 return nullptr; 65 } 66 67 return static_cast<G4AccArray<T, N>*>(accum 68 } 69 70 //____________________________________________ 71 template <class Key, class T, class Compare, c 72 G4AccMap<Key, T, Compare, Allocator>* 73 G4AccumulableManager::GetAccMap(G4VAccumulable 74 { 75 // Do not check type if nullptr 76 if (accumulable == nullptr) { 77 return nullptr; 78 } 79 80 // check type 81 if (! CheckType(accumulable, G4AccType::kMap 82 return nullptr; 83 } 84 85 return static_cast<G4AccMap<Key, T, Compare, 86 } 87 88 //____________________________________________ 89 template <typename Key, typename T, typename H 90 G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allo 91 G4AccumulableManager::GetAccUnorderedMap(G4VAc 92 { 93 // Do not check type if nullptr 94 if (accumulable == nullptr) { 95 return nullptr; 96 } 97 98 // check type 99 if (! CheckType(accumulable, G4AccType::kUno 100 return nullptr; 101 } 102 103 return static_cast<G4AccUnorderedMap<Key, T, 104 } 105 106 //____________________________________________ 107 template <class T, class Allocator> 108 G4AccVector<T, Allocator>* 109 G4AccumulableManager::GetAccVector(G4VAccumula 110 { 111 // Do not check type if nullptr 112 if (accumulable == nullptr) { 113 return nullptr; 114 } 115 116 // check type 117 if (! CheckType(accumulable, G4AccType::kVec 118 return nullptr; 119 } 120 121 return static_cast<G4AccVector<T, Allocator 122 } 123 124 //____________________________________________ 125 template <typename T> 126 G4AccValue<T>* 127 G4AccumulableManager::CreateAccValue( 128 const G4String& name, T value, G4MergeMode m 129 { 130 // do not accept name if it is already used 131 if (!CheckName(name, "CreateAccumulable")) { 132 return 0; 133 } 134 135 // create accumulable 136 auto accumulable = new G4AccValue<T>(name, v 137 138 // register accumulable in the map and vecto 139 Register(accumulable); 140 fAccumulablesToDelete.push_back(accumulable) 141 142 return accumulable; 143 } 144 145 //____________________________________________ 146 template <typename T> 147 G4AccValue<T>* 148 G4AccumulableManager::CreateAccValue( 149 T value, G4MergeMode mergeMode) 150 { 151 return CreateAccValue<T>(G4String(), value, 152 } 153 154 // Deprecated function using the old accumulab 155 //____________________________________________ 156 template <typename T> 157 G4AccValue<T>* 158 G4AccumulableManager::CreateAccumulable( 159 const G4String& name, T value, G4MergeMode m 160 { 161 return CreateAccValue<T>(name, value, mergeM 162 } 163 164 // Deprecated function using the old accumulab 165 //____________________________________________ 166 template <typename T> 167 G4AccValue<T>* 168 G4AccumulableManager::CreateAccumulable( 169 T value, G4MergeMode mergeMode) 170 { 171 return CreateAccValue<T>(value, mergeMode); 172 } 173 174 //____________________________________________ 175 template <typename T> 176 G4bool G4AccumulableManager::Register(G4AccVa 177 { 178 return Register(&accumulable); 179 } 180 181 //____________________________________________ 182 template <class T, std::size_t N> 183 G4bool G4AccumulableManager::Register(G4AccArr 184 { 185 return Register(&accumulableArray); 186 } 187 188 //____________________________________________ 189 template <class Key, class T, class Compare, c 190 G4bool G4AccumulableManager::Register( 191 G4AccMap<Key, T, Compare, Allocator>& accumu 192 { 193 return Register(&accumulableMap); 194 } 195 196 //____________________________________________ 197 template <class Key, class T, class Hash, clas 198 G4bool G4AccumulableManager::Register( 199 G4AccUnorderedMap<Key, T, Hash, KeyEqual, Al 200 { 201 return Register(&accumulableUnorderedMap); 202 } 203 204 //____________________________________________ 205 template <class T, class Allocator> 206 G4bool G4AccumulableManager::Register(G4AccVec 207 { 208 return Register(&accumulableVector); 209 } 210 211 // Deprecated functions with long name 212 //____________________________________________ 213 template <typename T> 214 G4bool G4AccumulableManager::RegisterAccumula 215 { 216 return Register(&accumulable); 217 } 218 219 //____________________________________________ 220 template <typename T> 221 G4AccValue<T>* 222 G4AccumulableManager::GetAccValue(const G4Stri 223 { 224 // get G4VAccummulable from the map 225 auto accumulable = GetAccumulable(name, warn 226 return GetAccumulable<T>(accumulable, warn); 227 } 228 229 //____________________________________________ 230 template <class T, std::size_t N> 231 G4AccArray<T, N>* 232 G4AccumulableManager::GetAccArray(const G4Stri 233 { 234 // get G4VAccummulable from the map 235 auto accumulable = GetAccumulable(name, warn 236 return GetAccArray<T,N>(accumulable, warn); 237 } 238 239 //____________________________________________ 240 template <class Key, class T, class Compare, c 241 G4AccMap<Key, T, Compare, Allocator>* 242 G4AccumulableManager::GetAccMap(const G4String 243 { 244 // get G4VAccummulable from the map 245 auto accumulable = GetAccumulable(name, warn 246 return GetAccMap<Key, T, Compare, Allocator> 247 } 248 249 //____________________________________________ 250 template <typename Key, typename T, typename H 251 G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allo 252 G4AccumulableManager::GetAccUnorderedMap(const 253 { 254 // get G4VAccummulable from the map 255 auto accumulable = GetAccumulable(name, warn 256 return GetAccUnorderedMap<Key, T, Hash, KeyE 257 } 258 259 //____________________________________________ 260 template <class T, class Allocator> 261 G4AccVector<T, Allocator>* 262 G4AccumulableManager::GetAccVector(const G4Str 263 { 264 // get G4VAccummulable from the map 265 auto accumulable = GetAccumulable(name, warn 266 return GetAccVector<T,Allocator>(accumulable 267 } 268 269 // Deprecated function using the old accumulab 270 //____________________________________________ 271 template <typename T> 272 G4AccValue<T>* 273 G4AccumulableManager::GetAccumulable(const G4S 274 { 275 return GetAccValue<T>(name, warn); 276 } 277 278 //____________________________________________ 279 template <typename T> 280 G4AccValue<T>* 281 G4AccumulableManager::GetAccValue(G4int id, G4 282 { 283 // get G4VAccummulable from the map 284 auto accumulable = GetAccumulable(id, warn); 285 return GetAccumulable<T>(accumulable, warn); 286 } 287 288 //____________________________________________ 289 template <class T, std::size_t N> 290 G4AccArray<T, N>* 291 G4AccumulableManager::GetAccArray(G4int id, G4 292 { 293 // get G4VAccummulable from the map 294 auto accumulable = GetAccumulable(id, warn); 295 return GetAccArray<T,N>(accumulable, warn); 296 } 297 298 //____________________________________________ 299 template <class Key, class T, class Compare, c 300 G4AccMap<Key, T, Compare, Allocator>* 301 G4AccumulableManager::GetAccMap(G4int id, G4bo 302 { 303 // get G4VAccummulable from the map 304 auto accumulable = GetAccumulable(id, warn); 305 return GetAccMap<Key, T, Compare, Allocator> 306 } 307 308 //____________________________________________ 309 template <typename Key, typename T, typename H 310 G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allo 311 G4AccumulableManager::GetAccUnorderedMap(G4int 312 { 313 // get G4VAccummulable from the map 314 auto accumulable = GetAccumulable(id, warn); 315 return GetAccUnorderedMap<Key, T, Hash, KeyE 316 } 317 318 //____________________________________________ 319 template <class T, class Allocator> 320 G4AccVector<T, Allocator>* 321 G4AccumulableManager::GetAccVector(G4int id, G 322 { 323 // get G4VAccummulable from the map 324 auto accumulable = GetAccumulable(id, warn); 325 return GetAccVector<T,Allocator>(accumulable 326 } 327 328 // Deprecated function using the old accumulab 329 //____________________________________________ 330 template <typename T> 331 G4AccValue<T>* 332 G4AccumulableManager::GetAccumulable(G4int id, 333 { 334 return GetAccValue<T>(id, warn); 335 } 336 337 //____________________________________________ 338 inline G4int G4AccumulableManager::GetNofAccum 339 { 340 return G4int(fVector.size()); 341 } 342 343 //____________________________________________ 344 inline std::vector<G4VAccumulable*>::iterator 345 { 346 return fVector.begin(); 347 } 348 349 //____________________________________________ 350 inline std::vector<G4VAccumulable*>::iterator 351 { 352 return fVector.end(); 353 } 354 355 //____________________________________________ 356 inline std::vector<G4VAccumulable*>::const_ite 357 G4AccumulableManager::BeginConst() const 358 { 359 return fVector.begin(); 360 } 361 362 //____________________________________________ 363 inline std::vector<G4VAccumulable*>::const_ite 364 G4AccumulableManager::EndConst() const 365 { 366 return fVector.end(); 367 } 368 369 //____________________________________________ 370 inline void G4AccumulableManager::SetVerboseLe 371 { 372 G4Accumulables::VerboseLevel = value; 373 } 374 375 //____________________________________________ 376 inline G4int G4AccumulableManager::GetVerboseL 377 { 378 return G4Accumulables::VerboseLevel; 379 } 380