ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4AccumulableManager.hh
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4AccumulableManager.hh
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, 07/09/2015 (ivana@ipno.in2p3.fr)
30 
31 #ifndef G4AccumulableManager_h
32 #define G4AccumulableManager_h 1
33 
34 #include "G4Accumulable.hh"
35 #include "globals.hh"
36 
37 #include <map>
38 #include <vector>
39 
41 class G4VAccumulable;
42 
44 {
45  public:
46  virtual ~G4AccumulableManager();
47 
48  // static methods
50 
51  // Methods
52 
53  // Create accumulables
54  //
55  template <typename T>
58  G4MergeMode mergeMode = G4MergeMode::kAddition);
59 
60  template <typename T>
62  CreateAccumulable(T value,
63  G4MergeMode mergeMode = G4MergeMode::kAddition);
64 
65  // Register existing accumulables
66  //
67  // templated accumulable
68  template <typename T>
70  // user defined accumulable
72 
73  // Access registered accumulables
74  //
75  // Via name
76  // templated accumulable
77  template <typename T>
78  G4Accumulable<T>* GetAccumulable(const G4String& name, G4bool warn = true) const;
79  // user defined accumulable
80  G4VAccumulable* GetAccumulable(const G4String& name, G4bool warn = true) const;
81 
82  // Via id (in the order of registering)
83  // templated accumulable
84  template <typename T>
85  G4Accumulable<T>* GetAccumulable(G4int id, G4bool warn = true) const;
86  // user defined accumulable
87  G4VAccumulable* GetAccumulable(G4int id, G4bool warn = true) const;
88  G4int GetNofAccumulables() const;
89 
90  // Via vector iterators
91  std::vector<G4VAccumulable*>::iterator Begin();
92  std::vector<G4VAccumulable*>::iterator End();
93  std::vector<G4VAccumulable*>::const_iterator BeginConst() const;
94  std::vector<G4VAccumulable*>::const_iterator EndConst() const;
95 
96  // Methods applied to all accumulables
97  void Merge();
98  void Reset();
99 
100  private:
101  // hide ctor requiring master/worker specification
102  G4AccumulableManager(G4bool isMaster);
103 
104  // metods
105  // Generate generic accumulable name: accumulableN, where N is the actual number of accumulables
106  G4String GenerateName() const;
107  // Check if a name is already used in a map and print a warning
108  G4bool CheckName(const G4String& name, const G4String& where) const;
109 
110  template <typename T>
111  G4Accumulable<T>* GetAccumulable(G4VAccumulable* accumulable, G4bool warn) const;
112 
113  // constants
114  const G4String kBaseName = "accumulable";
115 
116  // static data members
119 
120  // data members
121  std::vector<G4VAccumulable*> fVector;
122  std::map<G4String, G4VAccumulable*> fMap;
123  std::vector<G4VAccumulable*> fAccumulablesToDelete;
124  };
125 
126 #include "G4AccumulableManager.icc"
127 
128 #endif
129