Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 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 //____________________________________________ 27 //_____________________________________________________________________________ 35 template <typename T> << 28 template <typename T> 36 G4AccValue<T>* << 29 G4Accumulable<T>* 37 G4AccumulableManager::GetAccumulable(G4VAccumu 30 G4AccumulableManager::GetAccumulable(G4VAccumulable* accumulable, G4bool warn) const 38 { 31 { 39 // Do not check type if nullptr 32 // Do not check type if nullptr 40 if (accumulable == nullptr) { << 33 if ( ! accumulable ) return nullptr; 41 return nullptr; << 42 } << 43 34 44 // check type 35 // check type 45 if (! CheckType(accumulable, G4AccType::kVal << 36 G4Accumulable<T>* taccumulable = dynamic_cast<G4Accumulable<T>*>(accumulable); >> 37 if ( ! taccumulable && warn ) { >> 38 G4ExceptionDescription description; >> 39 description << " " << "Accumulable " << accumulable->GetName() >> 40 << " has different type"; >> 41 G4Exception("G4AccumulableManager::GetAccumulable<T>", >> 42 "Analysis_W011", JustWarning, description); 46 return nullptr; 43 return nullptr; 47 } 44 } 48 45 49 return static_cast<G4AccValue<T>*>(accumulab << 46 return taccumulable; 50 } 47 } 51 48 52 //____________________________________________ 49 //_____________________________________________________________________________ 53 template <typename T, std::size_t N> << 50 template <typename T> 54 G4AccArray<T, N>* << 51 G4Accumulable<T>* 55 G4AccumulableManager::GetAccArray(G4VAccumulab << 52 G4AccumulableManager::CreateAccumulable( 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 53 const G4String& name, T value, G4MergeMode mergeMode) 129 { 54 { 130 // do not accept name if it is already used 55 // do not accept name if it is already used 131 if (!CheckName(name, "CreateAccumulable")) { << 56 if ( ! CheckName(name, "CreateAccumulable") ) return 0; 132 return 0; << 133 } << 134 57 135 // create accumulable 58 // create accumulable 136 auto accumulable = new G4AccValue<T>(name, v << 59 auto accumulable = new G4Accumulable<T>(name, value, mergeMode); 137 60 138 // register accumulable in the map and vecto 61 // register accumulable in the map and vector 139 Register(accumulable); << 62 RegisterAccumulable(accumulable); 140 fAccumulablesToDelete.push_back(accumulable) 63 fAccumulablesToDelete.push_back(accumulable); 141 64 142 return accumulable; 65 return accumulable; 143 } 66 } 144 67 145 //____________________________________________ 68 //_____________________________________________________________________________ 146 template <typename T> << 69 template <typename T> 147 G4AccValue<T>* << 70 G4Accumulable<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( 71 G4AccumulableManager::CreateAccumulable( 169 T value, G4MergeMode mergeMode) 72 T value, G4MergeMode mergeMode) 170 { 73 { 171 return CreateAccValue<T>(value, mergeMode); << 74 return CreateAccumulable(G4String(), 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 } 75 } 187 76 188 //____________________________________________ 77 //_____________________________________________________________________________ 189 template <class Key, class T, class Compare, c << 78 template <typename T> 190 G4bool G4AccumulableManager::Register( << 79 G4bool G4AccumulableManager::RegisterAccumulable(G4Accumulable<T>& accumulable) 191 G4AccMap<Key, T, Compare, Allocator>& accumu << 192 { 80 { 193 return Register(&accumulableMap); << 81 return RegisterAccumulable(&accumulable); 194 } 82 } 195 83 196 //____________________________________________ 84 //_____________________________________________________________________________ 197 template <class Key, class T, class Hash, clas << 85 template <typename T> 198 G4bool G4AccumulableManager::Register( << 86 G4Accumulable<T>* 199 G4AccUnorderedMap<Key, T, Hash, KeyEqual, Al << 87 G4AccumulableManager::GetAccumulable(const G4String& name, G4bool warn) const 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 { 88 { 224 // get G4VAccummulable from the map << 89 // get G4VParammeter from the map 225 auto accumulable = GetAccumulable(name, warn 90 auto accumulable = GetAccumulable(name, warn); 226 return GetAccumulable<T>(accumulable, warn); 91 return GetAccumulable<T>(accumulable, warn); 227 } 92 } 228 93 229 //____________________________________________ 94 //_____________________________________________________________________________ 230 template <class T, std::size_t N> << 95 template <typename T> 231 G4AccArray<T, N>* << 96 G4Accumulable<T>* 232 G4AccumulableManager::GetAccArray(const G4Stri << 97 G4AccumulableManager::GetAccumulable(G4int id, G4bool warn) const 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 { 98 { 283 // get G4VAccummulable from the map << 99 // get G4VParammeter from the map 284 auto accumulable = GetAccumulable(id, warn); 100 auto accumulable = GetAccumulable(id, warn); 285 return GetAccumulable<T>(accumulable, warn); 101 return GetAccumulable<T>(accumulable, warn); 286 } 102 } 287 103 288 //____________________________________________ 104 //_____________________________________________________________________________ 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 105 inline G4int G4AccumulableManager::GetNofAccumulables() const 339 { 106 { 340 return G4int(fVector.size()); 107 return G4int(fVector.size()); 341 } 108 } 342 109 343 //____________________________________________ 110 //_____________________________________________________________________________ 344 inline std::vector<G4VAccumulable*>::iterator 111 inline std::vector<G4VAccumulable*>::iterator G4AccumulableManager::Begin() 345 { 112 { 346 return fVector.begin(); 113 return fVector.begin(); 347 } 114 } 348 115 349 //____________________________________________ 116 //_____________________________________________________________________________ 350 inline std::vector<G4VAccumulable*>::iterator 117 inline std::vector<G4VAccumulable*>::iterator G4AccumulableManager::End() 351 { 118 { 352 return fVector.end(); 119 return fVector.end(); 353 } 120 } 354 121 355 //____________________________________________ 122 //_____________________________________________________________________________ 356 inline std::vector<G4VAccumulable*>::const_ite << 123 inline std::vector<G4VAccumulable*>::const_iterator 357 G4AccumulableManager::BeginConst() const 124 G4AccumulableManager::BeginConst() const 358 { 125 { 359 return fVector.begin(); 126 return fVector.begin(); 360 } 127 } 361 128 362 //____________________________________________ 129 //_____________________________________________________________________________ 363 inline std::vector<G4VAccumulable*>::const_ite << 130 inline std::vector<G4VAccumulable*>::const_iterator 364 G4AccumulableManager::EndConst() const 131 G4AccumulableManager::EndConst() const 365 { 132 { 366 return fVector.end(); 133 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 } 134 } 380 135