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 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

  1 //
  2 // ********************************************************************
  3 // * License and Disclaimer                                           *
  4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.                             *
 10 // *                                                                  *
 11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                                                  *
 18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // ********************************************************************
 25 //
 26 
 27 // Author: Ivana Hrivnacova, IJCLab IN2P3/CNRS, 07/09/2015
 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(G4VAccumulable* accumulable, G4bool warn) const
 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::kValue, warn)) {
 46     return nullptr;
 47   }
 48 
 49   return static_cast<G4AccValue<T>*>(accumulable);
 50 }
 51 
 52 //_____________________________________________________________________________
 53 template <typename T, std::size_t N>
 54 G4AccArray<T, N>*
 55 G4AccumulableManager::GetAccArray(G4VAccumulable* accumulable, G4bool warn) const
 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::kArray, warn)) {
 64     return nullptr;
 65   }
 66 
 67   return  static_cast<G4AccArray<T, N>*>(accumulable);
 68 }
 69 
 70 //_____________________________________________________________________________
 71 template <class Key, class T, class Compare, class Allocator>
 72 G4AccMap<Key, T, Compare, Allocator>*
 73 G4AccumulableManager::GetAccMap(G4VAccumulable* accumulable, G4bool warn) const
 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, warn)) {
 82     return nullptr;
 83   }
 84 
 85   return static_cast<G4AccMap<Key, T, Compare, Allocator>*>(accumulable);
 86 }
 87 
 88 //_____________________________________________________________________________
 89 template <typename Key, typename T, typename Hash, typename KeyEqual, typename Allocator>
 90 G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>*
 91 G4AccumulableManager::GetAccUnorderedMap(G4VAccumulable* accumulable, G4bool warn) const
 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::kUnorderedMap, warn)) {
100     return nullptr;
101   }
102 
103   return static_cast<G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>*>(accumulable);
104 }
105 
106 //_____________________________________________________________________________
107 template <class T, class Allocator>
108 G4AccVector<T, Allocator>*
109 G4AccumulableManager::GetAccVector(G4VAccumulable* accumulable, G4bool warn) const
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::kVector, warn)) {
118     return nullptr;
119   }
120 
121   return  static_cast<G4AccVector<T, Allocator>*>(accumulable);
122 }
123 
124 //_____________________________________________________________________________
125 template <typename T>
126 G4AccValue<T>*
127 G4AccumulableManager::CreateAccValue(
128   const G4String& name, T value, G4MergeMode mergeMode)
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, value, mergeMode);
137 
138   // register accumulable in the map and vector
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, mergeMode);
152 }
153 
154 // Deprecated function using the old accumulable value name
155 //_____________________________________________________________________________
156 template <typename T>
157 G4AccValue<T>*
158 G4AccumulableManager::CreateAccumulable(
159   const G4String& name, T value, G4MergeMode mergeMode)
160 {
161   return CreateAccValue<T>(name, value, mergeMode);
162 }
163 
164 // Deprecated function using the old accumulable value name
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(G4AccValue<T>& accumulable)
177 {
178   return Register(&accumulable);
179 }
180 
181 //_____________________________________________________________________________
182 template <class T, std::size_t N>
183 G4bool G4AccumulableManager::Register(G4AccArray<T, N>& accumulableArray)
184 {
185   return Register(&accumulableArray);
186 }
187 
188 //_____________________________________________________________________________
189 template <class Key, class T, class Compare, class Allocator>
190 G4bool G4AccumulableManager::Register(
191   G4AccMap<Key, T, Compare, Allocator>& accumulableMap)
192 {
193   return Register(&accumulableMap);
194 }
195 
196 //_____________________________________________________________________________
197 template <class Key, class T, class Hash, class KeyEqual, class Allocator>
198 G4bool G4AccumulableManager::Register(
199   G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>& accumulableUnorderedMap)
200 {
201   return Register(&accumulableUnorderedMap);
202 }
203 
204 //_____________________________________________________________________________
205 template <class T, class Allocator>
206 G4bool G4AccumulableManager::Register(G4AccVector<T, Allocator>& accumulableVector)
207 {
208   return Register(&accumulableVector);
209 }
210 
211 // Deprecated functions with long name
212 //_____________________________________________________________________________
213 template <typename T>
214 G4bool  G4AccumulableManager::RegisterAccumulable(G4AccValue<T>& accumulable)
215 {
216   return Register(&accumulable);
217 }
218 
219 //_____________________________________________________________________________
220 template <typename T>
221 G4AccValue<T>*
222 G4AccumulableManager::GetAccValue(const G4String& name, G4bool warn) const
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 G4String& name, 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, class Allocator>
241 G4AccMap<Key, T, Compare, Allocator>*
242 G4AccumulableManager::GetAccMap(const G4String& name, G4bool warn) const
243 {
244   // get G4VAccummulable from the map
245   auto accumulable = GetAccumulable(name, warn);
246   return GetAccMap<Key, T, Compare, Allocator>(accumulable, warn);
247 }
248 
249 //_____________________________________________________________________________
250 template <typename Key, typename T, typename Hash, typename KeyEqual, typename Allocator>
251 G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>*
252 G4AccumulableManager::GetAccUnorderedMap(const G4String& name, G4bool warn) const
253 {
254   // get G4VAccummulable from the map
255   auto accumulable = GetAccumulable(name, warn);
256   return GetAccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>(accumulable, warn);
257 }
258 
259 //_____________________________________________________________________________
260 template <class T, class Allocator>
261 G4AccVector<T, Allocator>*
262 G4AccumulableManager::GetAccVector(const G4String& name, G4bool warn) const
263 {
264   // get G4VAccummulable from the map
265   auto accumulable = GetAccumulable(name, warn);
266   return GetAccVector<T,Allocator>(accumulable, warn);
267 }
268 
269 // Deprecated function using the old accumulable value name
270 //_____________________________________________________________________________
271 template <typename T>
272 G4AccValue<T>*
273 G4AccumulableManager::GetAccumulable(const G4String& name, G4bool warn) const
274 {
275   return GetAccValue<T>(name, warn);
276 }
277 
278 //_____________________________________________________________________________
279 template <typename T>
280 G4AccValue<T>*
281 G4AccumulableManager::GetAccValue(G4int id, G4bool warn) const
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, G4bool warn) const
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, class Allocator>
300 G4AccMap<Key, T, Compare, Allocator>*
301 G4AccumulableManager::GetAccMap(G4int id, G4bool warn) const
302 {
303   // get G4VAccummulable from the map
304   auto accumulable = GetAccumulable(id, warn);
305   return GetAccMap<Key, T, Compare, Allocator>(accumulable, warn);
306 }
307 
308 //_____________________________________________________________________________
309 template <typename Key, typename T, typename Hash, typename KeyEqual, typename Allocator>
310 G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>*
311 G4AccumulableManager::GetAccUnorderedMap(G4int id, G4bool warn) const
312 {
313   // get G4VAccummulable from the map
314   auto accumulable = GetAccumulable(id, warn);
315   return GetAccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>(accumulable, warn);
316 }
317 
318 //_____________________________________________________________________________
319 template <class T, class Allocator>
320 G4AccVector<T, Allocator>*
321 G4AccumulableManager::GetAccVector(G4int id, G4bool warn) const
322 {
323   // get G4VAccummulable from the map
324   auto accumulable = GetAccumulable(id, warn);
325   return GetAccVector<T,Allocator>(accumulable, warn);
326 }
327 
328 // Deprecated function using the old accumulable value name
329 //_____________________________________________________________________________
330 template <typename T>
331 G4AccValue<T>*
332 G4AccumulableManager::GetAccumulable(G4int id, G4bool warn) const
333 {
334   return GetAccValue<T>(id, warn);
335 }
336 
337 //_____________________________________________________________________________
338 inline G4int G4AccumulableManager::GetNofAccumulables() const
339 {
340   return G4int(fVector.size());
341 }
342 
343 //_____________________________________________________________________________
344 inline std::vector<G4VAccumulable*>::iterator G4AccumulableManager::Begin()
345 {
346   return fVector.begin();
347 }
348 
349 //_____________________________________________________________________________
350 inline std::vector<G4VAccumulable*>::iterator G4AccumulableManager::End()
351 {
352   return fVector.end();
353 }
354 
355 //_____________________________________________________________________________
356 inline std::vector<G4VAccumulable*>::const_iterator
357 G4AccumulableManager::BeginConst() const
358 {
359   return fVector.begin();
360 }
361 
362 //_____________________________________________________________________________
363 inline std::vector<G4VAccumulable*>::const_iterator
364 G4AccumulableManager::EndConst() const
365 {
366   return fVector.end();
367 }
368 
369 //_____________________________________________________________________________
370 inline void G4AccumulableManager::SetVerboseLevel(G4int value)
371 {
372   G4Accumulables::VerboseLevel = value;
373 }
374 
375 //_____________________________________________________________________________
376 inline G4int G4AccumulableManager::GetVerboseLevel() const
377 {
378   return G4Accumulables::VerboseLevel;
379 }
380