Back to home page

EIC code displayed by LXR

 
 

    


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 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 
0027 // The common implementation of analysis manager classes.
0028 
0029 // Author: Ivana Hrivnacova, IJCLab IN2P3/CNRS, 07/09/2015
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     // Static methods
0062     static G4AccumulableManager* Instance();
0063 
0064     // Methods
0065 
0066     // Create accumulables
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     // Deprecated function using the old accumulable value name
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     // Register existing accumulables
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     // user defined accumulable
0111     G4bool Register(G4VAccumulable* accumulable);
0112 
0113     // Deprecated functions with long name
0114     //
0115     template <typename T>
0116     [[deprecated("Use `G4AccumulableManager::Register` instead")]]
0117     G4bool RegisterAccumulable(G4AccValue<T>& accumulable);
0118     // user defined accumulable
0119     [[deprecated("Use `G4AccumulableManager::Register` instead")]]
0120     G4bool RegisterAccumulable(G4VAccumulable* accumulable);
0121 
0122     // Access registered accumulables
0123     //
0124     // Via name
0125     // templated accumulable
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     // user defined accumulable
0149     G4VAccumulable*  GetAccumulable(const G4String& name, G4bool warn = true) const;
0150 
0151     // Deprecated function using the old accumulable value name
0152     template <typename T>
0153     [[deprecated("Use `G4AccumulableManager::GetAccValue<T>` instead")]]
0154     G4AccValue<T>* GetAccumulable(const G4String& name, G4bool warn = true) const;
0155 
0156     // Via id (in the order of registering)
0157     // templated accumulable
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     // user defined accumulable
0180     G4VAccumulable*  GetAccumulable(G4int id, G4bool warn = true) const;
0181 
0182     // Deprecated function using the old accumulable value name
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     // Via vector iterators
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     // Methods applied to all accumulables
0196     void Merge();
0197     void Reset();
0198     void Print(G4PrintOptions options = G4PrintOptions()) const;
0199 
0200     // Print a selected range
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     // Verbose level
0210     void SetVerboseLevel(G4int value);
0211     G4int GetVerboseLevel() const;
0212 
0213   private:
0214     // Hide singleton ctor
0215     G4AccumulableManager();
0216 
0217     // Methods
0218     // Generate generic accumulable name: accumulableN, where N is the actual number of accumulables
0219     G4String GenerateName() const;
0220     // Check if a name is already used in a map and print a warning
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     // Constants
0245     const G4String kBaseName = "accumulable";
0246 
0247     // Static data members
0248     inline static G4AccumulableManager* fgMasterInstance { nullptr };
0249 
0250     // Data members
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