Warning, file /include/Geant4/G4AccumulableManager.hh was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 
0002 
0003 
0004 
0005 
0006 
0007 
0008 
0009 
0010 
0011 
0012 
0013 
0014 
0015 
0016 
0017 
0018 
0019 
0020 
0021 
0022 
0023 
0024 
0025 
0026 
0027 
0028 
0029 
0030 
0031 #ifndef G4AccumulableManager_h
0032 #define G4AccumulableManager_h 1
0033 
0034 #include "G4AccValue.hh"
0035 #include "G4AccType.hh"
0036 #include "globals.hh"
0037 
0038 #include <map>
0039 #include <vector>
0040 
0041 class G4AccumulableManager;
0042 class G4VAccumulable;
0043 template <class T>
0044 class G4ThreadLocalSingleton;
0045 template <class T, std::size_t N>
0046 class G4AccArray;
0047 template <class Key, class T, class Compare, class Allocator>
0048 class G4AccMap;
0049 template <class Key, class T, class Hash, class KeyEqual, class Allocator>
0050 class G4AccUnorderedMap;
0051 template <class T, class Allocator>
0052 class G4AccVector;
0053 
0054 class G4AccumulableManager
0055 {
0056   friend class G4ThreadLocalSingleton<G4AccumulableManager>;
0057 
0058   public:
0059     virtual ~G4AccumulableManager();
0060 
0061     
0062     static G4AccumulableManager* Instance();
0063 
0064     
0065 
0066     
0067     
0068     template <typename T>
0069     G4AccValue<T>*
0070     CreateAccValue(const G4String& name, T value,
0071                    G4MergeMode mergeMode = G4MergeMode::kAddition);
0072 
0073     template <typename T>
0074     G4AccValue<T>*
0075     CreateAccValue(T value,
0076                    G4MergeMode mergeMode = G4MergeMode::kAddition);
0077 
0078     
0079     
0080 
0081     template <typename T>
0082     [[deprecated("Use `G4AccumulableManager::CreateAccValue<T>` instead")]]
0083     G4AccValue<T>*
0084     CreateAccumulable(const G4String& name, T value,
0085                       G4MergeMode mergeMode = G4MergeMode::kAddition);
0086 
0087     template <typename T>
0088     [[deprecated("Use `G4AccumulableManager::CreateAccValue<T>` instead")]]
0089     G4AccValue<T>*
0090     CreateAccumulable(T value,
0091                       G4MergeMode mergeMode = G4MergeMode::kAddition);
0092 
0093     
0094     
0095     template <typename T>
0096     G4bool Register(G4AccValue<T>& accumulable);
0097 
0098     template <class T, std::size_t N>
0099     G4bool Register(G4AccArray<T, N>& accumulableArray);
0100 
0101     template <class Key, class T, class Compare, class Allocator>
0102     G4bool Register(G4AccMap<Key, T, Compare, Allocator>& accumulableMap);
0103 
0104     template <class Key, class T, class Hash, class KeyEqual, class Allocator>
0105     G4bool Register(G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>& accumulableUnorderedMap);
0106 
0107     template <class T, class Allocator>
0108     G4bool Register(G4AccVector<T, Allocator>& accumulableVector);
0109 
0110     
0111     G4bool Register(G4VAccumulable* accumulable);
0112 
0113     
0114     
0115     template <typename T>
0116     [[deprecated("Use `G4AccumulableManager::Register` instead")]]
0117     G4bool RegisterAccumulable(G4AccValue<T>& accumulable);
0118     
0119     [[deprecated("Use `G4AccumulableManager::Register` instead")]]
0120     G4bool RegisterAccumulable(G4VAccumulable* accumulable);
0121 
0122     
0123     
0124     
0125     
0126     
0127     template <typename T>
0128     G4AccValue<T>* GetAccValue(const G4String& name, G4bool warn = true) const;
0129 
0130     template <class T, std::size_t N>
0131     G4AccArray<T, N>*
0132     GetAccArray(const G4String& name, G4bool warn = true) const;
0133 
0134     template <class Key, class T, class Compare = std::less<Key>,
0135               class Allocator  = std::allocator<std::pair<const Key, T>>>
0136     G4AccMap<Key, T, Compare, Allocator>*
0137     GetAccMap(const G4String& name, G4bool warn = true) const;
0138 
0139     template <class Key, class T, class Hash = std::hash<Key>, class KeyEqual = std::equal_to<Key>,
0140               class Allocator  = std::allocator<std::pair<const Key, T>>>
0141     G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>*
0142     GetAccUnorderedMap(const G4String& name, G4bool warn = true) const;
0143 
0144     template <class T, class Allocator = std::allocator<T>>
0145     G4AccVector<T, Allocator>*
0146     GetAccVector(const G4String& name, G4bool warn = true) const;
0147 
0148     
0149     G4VAccumulable*  GetAccumulable(const G4String& name, G4bool warn = true) const;
0150 
0151     
0152     template <typename T>
0153     [[deprecated("Use `G4AccumulableManager::GetAccValue<T>` instead")]]
0154     G4AccValue<T>* GetAccumulable(const G4String& name, G4bool warn = true) const;
0155 
0156     
0157     
0158     
0159     template <typename T>
0160     G4AccValue<T>*  GetAccValue(G4int id, G4bool warn = true) const;
0161 
0162     template <class T, std::size_t N>
0163     G4AccArray<T, N>* GetAccArray(G4int id, G4bool warn = true) const;
0164 
0165     template <class Key, class T, class Compare = std::less<Key>,
0166               class Allocator = std::allocator<std::pair<const Key, T>>>
0167     G4AccMap<Key, T, Compare, Allocator>*
0168     GetAccMap(G4int id, G4bool warn = true) const;
0169 
0170     template <class Key, class T, class Hash = std::hash<Key>, class KeyEqual = std::equal_to<Key>,
0171               class Allocator = std::allocator<std::pair<const Key, T>>>
0172     G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>*
0173     GetAccUnorderedMap(G4int id, G4bool warn = true) const;
0174 
0175     template <class T, class Allocator = std::allocator<T>>
0176     G4AccVector<T, Allocator>*
0177     GetAccVector(G4int id, G4bool warn = true) const;
0178 
0179     
0180     G4VAccumulable*  GetAccumulable(G4int id, G4bool warn = true) const;
0181 
0182     
0183     template <typename T>
0184     [[deprecated("Use `G4AccumulableManager::GetAccValue<T>` instead")]]
0185     G4AccValue<T>*  GetAccumulable(G4int id, G4bool warn = true) const;
0186 
0187     G4int GetNofAccumulables() const;
0188 
0189     
0190     std::vector<G4VAccumulable*>::iterator Begin();
0191     std::vector<G4VAccumulable*>::iterator End();
0192     std::vector<G4VAccumulable*>::const_iterator BeginConst() const;
0193     std::vector<G4VAccumulable*>::const_iterator EndConst() const;
0194 
0195     
0196     void Merge();
0197     void Reset();
0198     void Print(G4PrintOptions options = G4PrintOptions()) const;
0199 
0200     
0201     void Print(G4int startId, G4int count,
0202                G4PrintOptions options = G4PrintOptions()) const;
0203     void Print(std::vector<G4VAccumulable*>::iterator startIt, std::size_t count,
0204                G4PrintOptions options = G4PrintOptions()) const;
0205     void Print(std::vector<G4VAccumulable*>::iterator startIt,
0206                std::vector<G4VAccumulable*>::iterator endIt,
0207                G4PrintOptions options = G4PrintOptions()) const;
0208 
0209     
0210     void SetVerboseLevel(G4int value);
0211     G4int GetVerboseLevel() const;
0212 
0213   private:
0214     
0215     G4AccumulableManager();
0216 
0217     
0218     
0219     G4String GenerateName() const;
0220     
0221     G4bool CheckName(const G4String& name, const G4String& where) const;
0222     G4bool CheckType(G4VAccumulable* accumulable, G4AccType type, G4bool warn) const;
0223 
0224     template <typename T>
0225     G4AccValue<T>*  GetAccumulable(G4VAccumulable* accumulable, G4bool warn) const;
0226 
0227     template <typename T, std::size_t N>
0228     G4AccArray<T, N>* GetAccArray(G4VAccumulable* accumulable, G4bool warn) const;
0229 
0230     template <typename Key, typename T, typename Compare = std::less<Key>,
0231               typename Allocator = std::allocator<std::pair<const Key, T>>>
0232     G4AccMap<Key, T, Compare, Allocator>*
0233     GetAccMap(G4VAccumulable* accumulable, G4bool warn = true) const;
0234 
0235     template <typename Key, typename T, typename Hash = std::hash<Key>, typename KeyEqual = std::equal_to<Key>,
0236               typename Allocator = std::allocator<std::pair<const Key, T>>>
0237     G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>*
0238     GetAccUnorderedMap(G4VAccumulable* accumulable, G4bool warn = true) const;
0239 
0240     template <typename T, typename Allocator = std::allocator<T>>
0241     G4AccVector<T, Allocator>*
0242     GetAccVector(G4VAccumulable* accumulable, G4bool warn) const;
0243 
0244     
0245     const G4String kBaseName = "accumulable";
0246 
0247     
0248     inline static G4AccumulableManager* fgMasterInstance { nullptr };
0249 
0250     
0251     std::vector<G4VAccumulable*>        fVector;
0252     std::map<G4String, G4VAccumulable*> fMap;
0253     std::vector<G4VAccumulable*>        fAccumulablesToDelete;
0254  };
0255 
0256 #include "G4AccumulableManager.icc"
0257 
0258 #endif
0259