Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:59:11

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 // Template base class the histograms/profiles objects managers.
0028 
0029 // Author: Ivana Hrivnacova, 23/06/2015  (ivana@ipno.in2p3.fr)
0030 
0031 #ifndef G4THnManager_h
0032 #define G4THnManager_h 1
0033 
0034 #include "G4Threading.hh"
0035 #include "G4Fcn.hh"
0036 #include "G4BinScheme.hh"
0037 #include "globals.hh"
0038 
0039 #include <vector>
0040 #include <map>
0041 #include <memory>
0042 #include <set>
0043 #include <string_view>
0044 
0045 class G4AnalysisManagerState;
0046 class G4HnManager;
0047 class G4HnInformation;
0048 
0049 template <typename HT>
0050 class G4THnManager
0051 {
0052   public:
0053     G4THnManager(const G4AnalysisManagerState& state);
0054     G4THnManager() = delete;
0055     virtual ~G4THnManager();
0056 
0057     G4int RegisterT(const G4String& name, HT* ht, G4HnInformation* info = nullptr);
0058 
0059     // Reset data
0060     G4bool Reset();
0061 
0062     // Clear data
0063     void ClearData();
0064 
0065     // Delete selected object
0066     G4bool DeleteT(G4int id, G4bool keepSetting);
0067 
0068     // Return true if the H1 vector is empty
0069     G4bool IsEmpty() const;
0070 
0071     // Method for merge (MT)
0072     void  AddTVector(const std::vector<HT*>& tVector);
0073 
0074     // New method for merge
0075     void  Merge(G4Mutex& mergeMutex, G4THnManager<HT>* masterInstance);
0076             // TO DO: change to shared_ptr<G4THnManager<HT>> masterInstance
0077 
0078     // Get method
0079     // HT*  GetT(G4int id) const;
0080     HT*  GetT(G4int id, G4bool warn = true, G4bool onlyIfActive = true) const;
0081 
0082     std::vector<HT*>*   GetTVector();
0083     const std::vector<HT*>&  GetTVectorRef() const;
0084     std::vector<std::pair<HT*, G4HnInformation*>>*   GetTHnVector();
0085     const std::vector<std::pair<HT*, G4HnInformation*>>&  GetTHnVectorRef() const;
0086     G4int GetNofHns(G4bool onlyIfExist) const;
0087 
0088     // Methods to list/print histograms
0089     G4bool List(std::ostream& output, G4bool onlyIfActive) const;
0090 
0091     // Iterators
0092     typename std::vector<HT*>::iterator BeginT();
0093     typename std::vector<HT*>::iterator EndT();
0094     typename std::vector<HT*>::const_iterator BeginConstT() const;
0095     typename std::vector<HT*>::const_iterator EndConstT() const;
0096 
0097   protected:
0098     std::pair<HT*, G4HnInformation*>  GetTHnInFunction(G4int id,
0099                        std::string_view functionName,
0100                        G4bool warn = true,
0101                        G4bool onlyIfActive = true) const;
0102 
0103     HT*  GetTInFunction(G4int id,
0104                        std::string_view functionName,
0105                        G4bool warn = true,
0106                        G4bool onlyIfActive = true) const;
0107 
0108     G4int GetTId(const G4String& name, G4bool warn = true) const;
0109 
0110     // Methods for verbose
0111     G4bool IsVerbose(G4int verboseLevel) const;
0112     void Message(G4int level,
0113                  const G4String& action,
0114                  const G4String& objectType,
0115                  const G4String& objectName = "",
0116                  G4bool success = true) const;
0117 
0118     // Static data members
0119     static constexpr std::string_view fkClass { "G4THnManager<T>" };
0120 
0121     // Data members
0122     const G4AnalysisManagerState& fState;
0123     std::vector<HT*>  fTVector;
0124     std::vector<std::pair<HT*, G4HnInformation*>> fTHnVector;
0125     std::set<G4int> fFreeIds;
0126     std::map<G4String, G4int>    fNameIdMap;
0127     std::shared_ptr<G4HnManager> fHnManager { nullptr };
0128 };
0129 
0130 // inline functions
0131 
0132 #include "G4THnManager.icc"
0133 
0134 #endif