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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 // The common implementation of analysis manager classes.
 28 
 29 // Author: Ivana Hrivnacova, IJCLab IN2P3/CNRS, 07/09/2015
 30 
 31 #ifndef G4AccumulableManager_h
 32 #define G4AccumulableManager_h 1
 33 
 34 #include "G4AccValue.hh"
 35 #include "G4AccType.hh"
 36 #include "globals.hh"
 37 
 38 #include <map>
 39 #include <vector>
 40 
 41 class G4AccumulableManager;
 42 class G4VAccumulable;
 43 template <class T>
 44 class G4ThreadLocalSingleton;
 45 template <class T, std::size_t N>
 46 class G4AccArray;
 47 template <class Key, class T, class Compare, class Allocator>
 48 class G4AccMap;
 49 template <class Key, class T, class Hash, class KeyEqual, class Allocator>
 50 class G4AccUnorderedMap;
 51 template <class T, class Allocator>
 52 class G4AccVector;
 53 
 54 class G4AccumulableManager
 55 {
 56   friend class G4ThreadLocalSingleton<G4AccumulableManager>;
 57 
 58   public:
 59     virtual ~G4AccumulableManager();
 60 
 61     // Static methods
 62     static G4AccumulableManager* Instance();
 63 
 64     // Methods
 65 
 66     // Create accumulables
 67     //
 68     template <typename T>
 69     G4AccValue<T>*
 70     CreateAccValue(const G4String& name, T value,
 71                    G4MergeMode mergeMode = G4MergeMode::kAddition);
 72 
 73     template <typename T>
 74     G4AccValue<T>*
 75     CreateAccValue(T value,
 76                    G4MergeMode mergeMode = G4MergeMode::kAddition);
 77 
 78     // Deprecated function using the old accumulable value name
 79     //
 80 
 81     template <typename T>
 82     [[deprecated("Use `G4AccumulableManager::CreateAccValue<T>` instead")]]
 83     G4AccValue<T>*
 84     CreateAccumulable(const G4String& name, T value,
 85                       G4MergeMode mergeMode = G4MergeMode::kAddition);
 86 
 87     template <typename T>
 88     [[deprecated("Use `G4AccumulableManager::CreateAccValue<T>` instead")]]
 89     G4AccValue<T>*
 90     CreateAccumulable(T value,
 91                       G4MergeMode mergeMode = G4MergeMode::kAddition);
 92 
 93     // Register existing accumulables
 94     //
 95     template <typename T>
 96     G4bool Register(G4AccValue<T>& accumulable);
 97 
 98     template <class T, std::size_t N>
 99     G4bool Register(G4AccArray<T, N>& accumulableArray);
100 
101     template <class Key, class T, class Compare, class Allocator>
102     G4bool Register(G4AccMap<Key, T, Compare, Allocator>& accumulableMap);
103 
104     template <class Key, class T, class Hash, class KeyEqual, class Allocator>
105     G4bool Register(G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>& accumulableUnorderedMap);
106 
107     template <class T, class Allocator>
108     G4bool Register(G4AccVector<T, Allocator>& accumulableVector);
109 
110     // user defined accumulable
111     G4bool Register(G4VAccumulable* accumulable);
112 
113     // Deprecated functions with long name
114     //
115     template <typename T>
116     [[deprecated("Use `G4AccumulableManager::Register` instead")]]
117     G4bool RegisterAccumulable(G4AccValue<T>& accumulable);
118     // user defined accumulable
119     [[deprecated("Use `G4AccumulableManager::Register` instead")]]
120     G4bool RegisterAccumulable(G4VAccumulable* accumulable);
121 
122     // Access registered accumulables
123     //
124     // Via name
125     // templated accumulable
126     //
127     template <typename T>
128     G4AccValue<T>* GetAccValue(const G4String& name, G4bool warn = true) const;
129 
130     template <class T, std::size_t N>
131     G4AccArray<T, N>*
132     GetAccArray(const G4String& name, G4bool warn = true) const;
133 
134     template <class Key, class T, class Compare = std::less<Key>,
135               class Allocator  = std::allocator<std::pair<const Key, T>>>
136     G4AccMap<Key, T, Compare, Allocator>*
137     GetAccMap(const G4String& name, G4bool warn = true) const;
138 
139     template <class Key, class T, class Hash = std::hash<Key>, class KeyEqual = std::equal_to<Key>,
140               class Allocator  = std::allocator<std::pair<const Key, T>>>
141     G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>*
142     GetAccUnorderedMap(const G4String& name, G4bool warn = true) const;
143 
144     template <class T, class Allocator = std::allocator<T>>
145     G4AccVector<T, Allocator>*
146     GetAccVector(const G4String& name, G4bool warn = true) const;
147 
148     // user defined accumulable
149     G4VAccumulable*  GetAccumulable(const G4String& name, G4bool warn = true) const;
150 
151     // Deprecated function using the old accumulable value name
152     template <typename T>
153     [[deprecated("Use `G4AccumulableManager::GetAccValue<T>` instead")]]
154     G4AccValue<T>* GetAccumulable(const G4String& name, G4bool warn = true) const;
155 
156     // Via id (in the order of registering)
157     // templated accumulable
158     //
159     template <typename T>
160     G4AccValue<T>*  GetAccValue(G4int id, G4bool warn = true) const;
161 
162     template <class T, std::size_t N>
163     G4AccArray<T, N>* GetAccArray(G4int id, G4bool warn = true) const;
164 
165     template <class Key, class T, class Compare = std::less<Key>,
166               class Allocator = std::allocator<std::pair<const Key, T>>>
167     G4AccMap<Key, T, Compare, Allocator>*
168     GetAccMap(G4int id, G4bool warn = true) const;
169 
170     template <class Key, class T, class Hash = std::hash<Key>, class KeyEqual = std::equal_to<Key>,
171               class Allocator = std::allocator<std::pair<const Key, T>>>
172     G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>*
173     GetAccUnorderedMap(G4int id, G4bool warn = true) const;
174 
175     template <class T, class Allocator = std::allocator<T>>
176     G4AccVector<T, Allocator>*
177     GetAccVector(G4int id, G4bool warn = true) const;
178 
179     // user defined accumulable
180     G4VAccumulable*  GetAccumulable(G4int id, G4bool warn = true) const;
181 
182     // Deprecated function using the old accumulable value name
183     template <typename T>
184     [[deprecated("Use `G4AccumulableManager::GetAccValue<T>` instead")]]
185     G4AccValue<T>*  GetAccumulable(G4int id, G4bool warn = true) const;
186 
187     G4int GetNofAccumulables() const;
188 
189     // Via vector iterators
190     std::vector<G4VAccumulable*>::iterator Begin();
191     std::vector<G4VAccumulable*>::iterator End();
192     std::vector<G4VAccumulable*>::const_iterator BeginConst() const;
193     std::vector<G4VAccumulable*>::const_iterator EndConst() const;
194 
195     // Methods applied to all accumulables
196     void Merge();
197     void Reset();
198     void Print(G4PrintOptions options = G4PrintOptions()) const;
199 
200     // Print a selected range
201     void Print(G4int startId, G4int count,
202                G4PrintOptions options = G4PrintOptions()) const;
203     void Print(std::vector<G4VAccumulable*>::iterator startIt, std::size_t count,
204                G4PrintOptions options = G4PrintOptions()) const;
205     void Print(std::vector<G4VAccumulable*>::iterator startIt,
206                std::vector<G4VAccumulable*>::iterator endIt,
207                G4PrintOptions options = G4PrintOptions()) const;
208 
209     // Verbose level
210     void SetVerboseLevel(G4int value);
211     G4int GetVerboseLevel() const;
212 
213   private:
214     // Hide singleton ctor
215     G4AccumulableManager();
216 
217     // Methods
218     // Generate generic accumulable name: accumulableN, where N is the actual number of accumulables
219     G4String GenerateName() const;
220     // Check if a name is already used in a map and print a warning
221     G4bool CheckName(const G4String& name, const G4String& where) const;
222     G4bool CheckType(G4VAccumulable* accumulable, G4AccType type, G4bool warn) const;
223 
224     template <typename T>
225     G4AccValue<T>*  GetAccumulable(G4VAccumulable* accumulable, G4bool warn) const;
226 
227     template <typename T, std::size_t N>
228     G4AccArray<T, N>* GetAccArray(G4VAccumulable* accumulable, G4bool warn) const;
229 
230     template <typename Key, typename T, typename Compare = std::less<Key>,
231               typename Allocator = std::allocator<std::pair<const Key, T>>>
232     G4AccMap<Key, T, Compare, Allocator>*
233     GetAccMap(G4VAccumulable* accumulable, G4bool warn = true) const;
234 
235     template <typename Key, typename T, typename Hash = std::hash<Key>, typename KeyEqual = std::equal_to<Key>,
236               typename Allocator = std::allocator<std::pair<const Key, T>>>
237     G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>*
238     GetAccUnorderedMap(G4VAccumulable* accumulable, G4bool warn = true) const;
239 
240     template <typename T, typename Allocator = std::allocator<T>>
241     G4AccVector<T, Allocator>*
242     GetAccVector(G4VAccumulable* accumulable, G4bool warn) const;
243 
244     // Constants
245     const G4String kBaseName = "accumulable";
246 
247     // Static data members
248     inline static G4AccumulableManager* fgMasterInstance { nullptr };
249 
250     // Data members
251     std::vector<G4VAccumulable*>        fVector;
252     std::map<G4String, G4VAccumulable*> fMap;
253     std::vector<G4VAccumulable*>        fAccumulablesToDelete;
254  };
255 
256 #include "G4AccumulableManager.icc"
257 
258 #endif
259 
260