Geant4  10.02.p02
G4TNtupleManager.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: G4CsvNtupleManager.hh 70604 2013-06-03 11:27:06Z ihrivnac $
27 
28 // Class template for ntuple managers for all output types.
29 //
30 // Author: Ivana Hrivnacova, 19/06/2015 (ivana@ipno.in2p3.fr)
31 
32 #ifndef G4TNtupleManager_h
33 #define G4TNtupleManager_h 1
34 
35 #include "G4VNtupleManager.hh"
36 #include "G4TNtupleDescription.hh"
37 #include "globals.hh"
38 
39 #include <vector>
40 
41 template <typename TNTUPLE>
43 
44  public:
45  explicit G4TNtupleManager(const G4AnalysisManagerState& state);
47 
48  protected:
49  // Methods to manipulate ntuples
51  G4bool IsEmpty() const;
52  G4bool Reset(G4bool deleteNtuple);
53 
54  // Methods to create ntuples
55  //
56  virtual G4int CreateNtuple(const G4String& name, const G4String& title) final;
57  // Create columns in the last created ntuple
58  virtual G4int CreateNtupleIColumn(
59  const G4String& name, std::vector<int>* vector) final;
60  virtual G4int CreateNtupleFColumn(
61  const G4String& name, std::vector<float>* vector) final;
62  virtual G4int CreateNtupleDColumn(
63  const G4String& name, std::vector<double>* vector) final;
64  virtual G4int CreateNtupleSColumn(const G4String& name) final;
65  virtual void FinishNtuple() final;
66  // Create columns in the ntuple with given id
67  virtual G4int CreateNtupleIColumn(G4int ntupleId,
68  const G4String& name, std::vector<int>* vector) final;
69  virtual G4int CreateNtupleFColumn(G4int ntupleId,
70  const G4String& name, std::vector<float>* vector) final;
71  virtual G4int CreateNtupleDColumn(G4int ntupleId,
72  const G4String& name, std::vector<double>* vector) final;
73  virtual G4int CreateNtupleSColumn(G4int ntupleId, const G4String& name) final;
74  virtual void FinishNtuple(G4int ntupleId) final;
75 
76  // Methods to fill ntuples
77  // Methods for ntuple with id = FirstNtupleId
78  virtual G4bool FillNtupleIColumn(G4int columnId, G4int value) final;
79  virtual G4bool FillNtupleFColumn(G4int columnId, G4float value) final;
80  virtual G4bool FillNtupleDColumn(G4int columnId, G4double value) final;
81  virtual G4bool FillNtupleSColumn(G4int columnId, const G4String& value) final;
82  virtual G4bool AddNtupleRow() final;
83  // Methods for ntuple with id > FirstNtupleId (when more ntuples exist)
84  virtual G4bool FillNtupleIColumn(G4int ntupleId, G4int columnId, G4int value) final;
85  virtual G4bool FillNtupleFColumn(G4int ntupleId, G4int columnId, G4float value) final;
86  virtual G4bool FillNtupleDColumn(G4int ntupleId, G4int columnId, G4double value) final;
87  virtual G4bool FillNtupleSColumn(G4int ntupleId, G4int columnId,
88  const G4String& value) final;
89  virtual G4bool AddNtupleRow(G4int ntupleId) final;
90 
91  // Activation option
92  //
93  virtual void SetActivation(G4bool activation) final;
94  virtual void SetActivation(G4int ntupleId, G4bool activation) final;
95  virtual G4bool GetActivation(G4int ntupleId) const final;
96 
97  // Access methods
98  TNTUPLE* GetNtuple() const;
99  TNTUPLE* GetNtuple(G4int ntupleId) const;
100  virtual G4int GetNofNtuples() const final;
101 
102  // Iterators
103  typename std::vector<TNTUPLE*>::iterator BeginNtuple();
104  typename std::vector<TNTUPLE*>::iterator EndNtuple();
105  typename std::vector<TNTUPLE*>::const_iterator BeginConstNtuple() const;
106  typename std::vector<TNTUPLE*>::const_iterator EndConstNtuple() const;
107 
108  // Data members
109  std::vector<G4TNtupleDescription<TNTUPLE>*> fNtupleDescriptionVector;
110  std::vector<TNTUPLE*> fNtupleVector;
111 
112  private:
113  // methods
114 
115  // Fuctions which are specific to output type
116  //
117  virtual void CreateTNtuple(
118  G4TNtupleDescription<TNTUPLE>* ntupleDescription,
119  const G4String& name, const G4String& title) = 0;
120  virtual void CreateTNtupleFromBooking(
121  G4TNtupleDescription<TNTUPLE>* ntupleDescription) = 0;
122 
123  virtual void FinishTNtuple(
124  G4TNtupleDescription<TNTUPLE>* ntupleDescription) = 0;
125 
126 
127  // Common implementation
128  //
129 
131  G4String function,
132  G4bool warn = true) const;
133  TNTUPLE* GetNtupleInFunction(G4int id,
134  G4String function,
135  G4bool warn = true) const;
136 
137  // template functions for creating/filling ntuple columns
138 
139  template <typename T>
141  G4TNtupleDescription<TNTUPLE>* ntupleDescription,
142  const G4String& name, std::vector<T>* vector);
143 
144  template <typename T>
145  G4int CreateNtupleTColumn(G4int ntupleId,
146  const G4String& name, std::vector<T>* vector);
147 
148  template <typename T>
150  const G4String& name, std::vector<T>* vector);
151 
152  template <typename T>
153  G4bool FillNtupleTColumn(G4int ntupleId, G4int columnId, const T& value);
154 
155  template <typename T>
156  G4bool FillNtupleTColumn(G4int columnId, const T& value);
157 };
158 
159 #include "G4TNtupleManager.icc"
160 
161 #endif
162 
virtual G4int CreateNtupleDColumn(const G4String &name, std::vector< double > *vector) final
G4bool FillNtupleTColumn(G4int ntupleId, G4int columnId, const T &value)
G4int CreateNtupleTColumn(G4int ntupleId, const G4String &name, std::vector< T > *vector)
virtual G4int CreateNtupleFColumn(const G4String &name, std::vector< float > *vector) final
G4String name
Definition: TRTMaterials.hh:40
virtual void CreateTNtupleFromBooking(G4TNtupleDescription< TNTUPLE > *ntupleDescription)=0
G4TNtupleDescription< TNTUPLE > * GetNtupleDescriptionInFunction(G4int id, G4String function, G4bool warn=true) const
float G4float
Definition: G4Types.hh:77
std::vector< G4TNtupleDescription< TNTUPLE > * > fNtupleDescriptionVector
void CreateNtuplesFromBooking()
virtual G4bool AddNtupleRow() final
int G4int
Definition: G4Types.hh:78
virtual G4bool FillNtupleFColumn(G4int columnId, G4float value) final
std::vector< TNTUPLE * >::iterator EndNtuple()
G4bool Reset(G4bool deleteNtuple)
virtual G4bool FillNtupleSColumn(G4int columnId, const G4String &value) final
std::vector< TNTUPLE * >::const_iterator EndConstNtuple() const
virtual G4int GetNofNtuples() const final
bool G4bool
Definition: G4Types.hh:79
virtual G4bool GetActivation(G4int ntupleId) const final
virtual G4int CreateNtupleSColumn(const G4String &name) final
std::vector< TNTUPLE * >::const_iterator BeginConstNtuple() const
G4TNtupleManager(const G4AnalysisManagerState &state)
virtual void CreateTNtuple(G4TNtupleDescription< TNTUPLE > *ntupleDescription, const G4String &name, const G4String &title)=0
virtual G4bool FillNtupleIColumn(G4int columnId, G4int value) final
virtual void SetActivation(G4bool activation) final
virtual void FinishNtuple() final
TNTUPLE * GetNtuple() const
std::vector< TNTUPLE * > fNtupleVector
virtual G4int CreateNtupleIColumn(const G4String &name, std::vector< int > *vector) final
std::vector< TNTUPLE * >::iterator BeginNtuple()
void CreateTColumnInNtuple(G4TNtupleDescription< TNTUPLE > *ntupleDescription, const G4String &name, std::vector< T > *vector)
double G4double
Definition: G4Types.hh:76
TNTUPLE * GetNtupleInFunction(G4int id, G4String function, G4bool warn=true) const
virtual void FinishTNtuple(G4TNtupleDescription< TNTUPLE > *ntupleDescription)=0
virtual G4int CreateNtuple(const G4String &name, const G4String &title) final
virtual G4bool FillNtupleDColumn(G4int columnId, G4double value) final
G4bool IsEmpty() const