Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4AccumulableManager.hh
Go to the documentation of this file.
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 // $Id: G4AccumulableManager.hh 91012 2015-06-15 10:38:07Z ihrivnac $
27 
28 // The common implementation of analysis manager classes.
29 
30 // Author: Ivana Hrivnacova, 07/09/2015 (ivana@ipno.in2p3.fr)
31 
32 #ifndef G4AccumulableManager_h
33 #define G4AccumulableManager_h 1
34 
35 #include "G4Accumulable.hh"
36 #include "globals.hh"
37 
38 #include <map>
39 #include <vector>
40 
42 class G4VAccumulable;
43 
45 {
46  public:
47  virtual ~G4AccumulableManager();
48 
49  // static methods
51 
52  // Methods
53 
54  // Create accumulables
55  //
56  template <typename T>
60 
61  template <typename T>
63  CreateAccumulable(T value,
65 
66  // Register existing accumulables
67  //
68  // templated accumulable
69  template <typename T>
71  // user defined accumulable
73 
74  // Access registered accumulables
75  //
76  // Via name
77  // templated accumulable
78  template <typename T>
79  G4Accumulable<T>* GetAccumulable(const G4String& name, G4bool warn = true) const;
80  // user defined accumulable
81  G4VAccumulable* GetAccumulable(const G4String& name, G4bool warn = true) const;
82 
83  // Via id (in the order of registering)
84  // templated accumulable
85  template <typename T>
86  G4Accumulable<T>* GetAccumulable(G4int id, G4bool warn = true) const;
87  // user defined accumulable
88  G4VAccumulable* GetAccumulable(G4int id, G4bool warn = true) const;
89  G4int GetNofAccumulables() const;
90 
91  // Via vector iterators
92  std::vector<G4VAccumulable*>::iterator Begin();
93  std::vector<G4VAccumulable*>::iterator End();
94  std::vector<G4VAccumulable*>::const_iterator BeginConst() const;
95  std::vector<G4VAccumulable*>::const_iterator EndConst() const;
96 
97  // Methods applied to all accumulables
98  void Merge();
99  void Reset();
100 
101  private:
102  // hide ctor requiring master/worker specification
103  G4AccumulableManager(G4bool isMaster);
104 
105  // metods
106  // Generate generic accumulable name: accumulableN, where N is the actual number of accumulables
107  G4String GenerateName() const;
108  // Check if a name is already used in a map and print a warning
109  G4bool CheckName(const G4String& name, const G4String& where) const;
110 
111  template <typename T>
112  G4Accumulable<T>* GetAccumulable(G4VAccumulable* accumulable, G4bool warn) const;
113 
114  // constants
115  const G4String kBaseName = "accumulable";
116 
117  // static data members
118  static G4AccumulableManager* fgMasterInstance;
119  static G4ThreadLocal G4AccumulableManager* fgInstance;
120 
121  // data members
122  std::vector<G4VAccumulable*> fVector;
123  std::map<G4String, G4VAccumulable*> fMap;
124  std::vector<G4VAccumulable*> fAccumulablesToDelete;
125  };
126 
127 #include "G4AccumulableManager.icc"
128 
129 #endif
130 
const XML_Char * name
Definition: expat.h:151
G4Accumulable< T > * GetAccumulable(const G4String &name, G4bool warn=true) const
std::vector< G4VAccumulable * >::const_iterator EndConst() const
std::vector< G4VAccumulable * >::iterator Begin()
#define G4ThreadLocal
Definition: tls.hh:89
int G4int
Definition: G4Types.hh:78
static G4AccumulableManager * Instance()
G4int GetNofAccumulables() const
G4bool RegisterAccumulable(G4Accumulable< T > &accumulable)
const XML_Char int const XML_Char * value
Definition: expat.h:331
bool G4bool
Definition: G4Types.hh:79
std::vector< G4VAccumulable * >::iterator End()
G4Accumulable< T > * CreateAccumulable(const G4String &name, T value, G4MergeMode mergeMode=G4MergeMode::kAddition)
std::vector< G4VAccumulable * >::const_iterator BeginConst() const
G4MergeMode
Definition: G4MergeMode.hh:40