Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:57:51

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, 07/09/2015  (ivana@ipno.in2p3.fr)
0030 
0031 #ifndef G4AccumulableManager_h
0032 #define G4AccumulableManager_h 1
0033 
0034 #include "G4Accumulable.hh"
0035 #include "globals.hh"
0036 
0037 #include <map>
0038 #include <vector>
0039 
0040 class G4AccumulableManager;
0041 class G4AnalysisManagerState;
0042 class G4VAccumulable;
0043 template <class T>
0044 class G4ThreadLocalSingleton;
0045 
0046 class G4AccumulableManager
0047 {
0048   friend class G4ThreadLocalSingleton<G4AccumulableManager>;
0049 
0050   public:
0051     virtual ~G4AccumulableManager();
0052 
0053     // Static methods
0054     static G4AccumulableManager* Instance();
0055 
0056     // Methods
0057 
0058     // Create accumulables
0059     //
0060     template <typename T>
0061     G4Accumulable<T>*
0062     CreateAccumulable(const G4String& name, T value,
0063                       G4MergeMode mergeMode = G4MergeMode::kAddition);
0064 
0065     template <typename T>
0066     G4Accumulable<T>*
0067     CreateAccumulable(T value,
0068                       G4MergeMode mergeMode = G4MergeMode::kAddition);
0069 
0070     // Register existing accumulables
0071     //
0072     // templated accumulable
0073     template <typename T>
0074     G4bool RegisterAccumulable(G4Accumulable<T>& accumulable);
0075     // user defined accumulable
0076     G4bool RegisterAccumulable(G4VAccumulable* accumulable);
0077 
0078     // Access registered accumulables
0079     //
0080     // Via name
0081     // templated accumulable
0082     template <typename T>
0083     G4Accumulable<T>*  GetAccumulable(const G4String& name, G4bool warn = true) const;
0084     // user defined accumulable
0085     G4VAccumulable*  GetAccumulable(const G4String& name, G4bool warn = true) const;
0086 
0087     // Via id (in the order of registering)
0088     //  templated accumulable
0089     template <typename T>
0090     G4Accumulable<T>*  GetAccumulable(G4int id, G4bool warn = true) const;
0091     // user defined accumulable
0092     G4VAccumulable*  GetAccumulable(G4int id, G4bool warn = true) const;
0093     G4int GetNofAccumulables() const;
0094 
0095     // Via vector iterators
0096     std::vector<G4VAccumulable*>::iterator Begin();
0097     std::vector<G4VAccumulable*>::iterator End();
0098     std::vector<G4VAccumulable*>::const_iterator BeginConst() const;
0099     std::vector<G4VAccumulable*>::const_iterator EndConst() const;
0100 
0101     // Methods applied to all accumulables
0102     void Merge();
0103     void Reset();
0104 
0105   private:
0106     // Hide singleton ctor
0107     G4AccumulableManager();
0108 
0109     // Methods
0110     // Generate generic accumulable name: accumulableN, where N is the actual number of accumulables
0111     G4String GenerateName() const;
0112     // Check if a name is already used in a map and print a warning
0113     G4bool CheckName(const G4String& name, const G4String& where) const;
0114 
0115     template <typename T>
0116     G4Accumulable<T>*  GetAccumulable(G4VAccumulable* accumulable, G4bool warn) const;
0117 
0118     // Constants
0119     const G4String kBaseName = "accumulable";
0120 
0121     // Static data members
0122     inline static G4AccumulableManager* fgMasterInstance { nullptr };
0123 
0124     // Data members
0125     std::vector<G4VAccumulable*>        fVector;
0126     std::map<G4String, G4VAccumulable*> fMap;
0127     std::vector<G4VAccumulable*>        fAccumulablesToDelete;
0128  };
0129 
0130 #include "G4AccumulableManager.icc"
0131 
0132 #endif
0133