Geant4  10.01
G4RootNtupleManager.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: G4RootNtupleManager.hh 70604 2013-06-03 11:27:06Z ihrivnac $
27 
28 // Manager class for Root ntuples.
29 // It implements functions specific to Root ntuples.
30 //
31 // Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
32 
33 #ifndef G4RootNtupleManager_h
34 #define G4RootNtupleManager_h 1
35 
36 #include "G4VNtupleManager.hh"
37 #include "globals.hh"
38 
39 #include "tools/wroot/ntuple"
40 
41 #include <vector>
42 
44 
45 namespace tools {
46 namespace wroot {
47 class directory;
48 }
49 }
50 
52 {
53  friend class G4RootAnalysisManager;
54 
55  protected:
57  virtual ~G4RootNtupleManager();
58 
59  // Functions specific to the output type
60  //
61 
62  // Methods to manipulate ntuples
64  G4bool IsEmpty() const;
65  G4bool Reset();
66 
67  // Set methods
68  void SetNtupleDirectory(tools::wroot::directory* directory);
69 
70  // Access methods
71  tools::wroot::ntuple* GetNtuple() const;
72  tools::wroot::ntuple* GetNtuple(G4int ntupleId) const;
73 
74  // Iterators
75  std::vector<tools::wroot::ntuple*>::iterator BeginNtuple();
76  std::vector<tools::wroot::ntuple*>::iterator EndNtuple();
77  std::vector<tools::wroot::ntuple*>::const_iterator BeginConstNtuple() const;
78  std::vector<tools::wroot::ntuple*>::const_iterator EndConstNtuple() const;
79 
80  // Functions independent from the output type
81  //
82 
83  // Methods to create ntuples
84  virtual G4int CreateNtuple(const G4String& name, const G4String& title);
85  // Create columns in the last created ntuple
86  virtual G4int CreateNtupleIColumn(
87  const G4String& name, std::vector<int>* vector);
88  virtual G4int CreateNtupleFColumn(
89  const G4String& name, std::vector<float>* vector);
90  virtual G4int CreateNtupleDColumn(
91  const G4String& name, std::vector<double>* vector);
92  virtual G4int CreateNtupleSColumn(const G4String& name);
93  virtual void FinishNtuple();
94  // Create columns in the ntuple with given id
95  virtual G4int CreateNtupleIColumn(G4int ntupleId,
96  const G4String& name, std::vector<int>* vector);
97  virtual G4int CreateNtupleFColumn(G4int ntupleId,
98  const G4String& name, std::vector<float>* vector);
99  virtual G4int CreateNtupleDColumn(G4int ntupleId,
100  const G4String& name, std::vector<double>* vector);
101  virtual G4int CreateNtupleSColumn(G4int ntupleId, const G4String& name);
102  virtual void FinishNtuple(G4int ntupleId);
103 
104  // Methods to fill ntuples
105  // Methods for ntuple with id = FirstNtupleId
106  virtual G4bool FillNtupleIColumn(G4int columnId, G4int value);
107  virtual G4bool FillNtupleFColumn(G4int columnId, G4float value);
108  virtual G4bool FillNtupleDColumn(G4int columnId, G4double value);
109  virtual G4bool FillNtupleSColumn(G4int columnId, const G4String& value);
110  virtual G4bool AddNtupleRow();
111  // Methods for ntuple with id > FirstNtupleId (when more ntuples exist)
112  virtual G4bool FillNtupleIColumn(G4int ntupleId, G4int columnId, G4int value);
113  virtual G4bool FillNtupleFColumn(G4int ntupleId, G4int columnId, G4float value);
114  virtual G4bool FillNtupleDColumn(G4int ntupleId, G4int columnId, G4double value);
115  virtual G4bool FillNtupleSColumn(G4int ntupleId, G4int columnId,
116  const G4String& value);
117  virtual G4bool AddNtupleRow(G4int ntupleId);
118 
119  // Access methods
120  virtual G4int GetNofNtuples() const;
121 
122  private:
123  // methods
124  //
125  tools::wroot::ntuple::column<int>*
126  GetNtupleIColumn(G4int ntupleId, G4int columnId) const;
127  tools::wroot::ntuple::column<float>*
128  GetNtupleFColumn(G4int ntupleId, G4int columnId) const;
129  tools::wroot::ntuple::column<double>*
130  GetNtupleDColumn(G4int ntupleId, G4int columnId) const;
131  tools::wroot::ntuple::column_string*
132  GetNtupleSColumn(G4int ntupleId, G4int columnId) const;
133 
135  G4String function,
136  G4bool warn = true,
137  G4bool onlyIfActive = true) const;
138 
139  // data members
140  //
141  tools::wroot::directory* fNtupleDirectory;
142  std::vector<G4RootNtupleDescription*> fNtupleDescriptionVector;
143  std::vector<tools::wroot::ntuple*> fNtupleVector;
144 };
145 
146 // inline functions
147 
149  tools::wroot::directory* directory)
150 { fNtupleDirectory = directory; }
151 
152 inline std::vector<tools::wroot::ntuple*>::iterator
154 { return fNtupleVector.begin(); }
155 
156 inline std::vector<tools::wroot::ntuple*>::iterator
158 { return fNtupleVector.end(); }
159 
160 inline std::vector<tools::wroot::ntuple*>::const_iterator
162 { return fNtupleVector.begin(); }
163 
164 inline std::vector<tools::wroot::ntuple*>::const_iterator
166 { return fNtupleVector.end(); }
167 
169 { return fNtupleVector.size(); }
170 
171 
172 #endif
173 
tools::wroot::ntuple::column< int > * GetNtupleIColumn(G4int ntupleId, G4int columnId) const
virtual G4bool FillNtupleFColumn(G4int columnId, G4float value)
G4String name
Definition: TRTMaterials.hh:40
std::vector< tools::wroot::ntuple * >::iterator EndNtuple()
float G4float
Definition: G4Types.hh:77
tools::wroot::directory * fNtupleDirectory
virtual G4int CreateNtupleSColumn(const G4String &name)
std::vector< tools::wroot::ntuple * >::iterator BeginNtuple()
virtual G4int CreateNtupleFColumn(const G4String &name, std::vector< float > *vector)
tools::wroot::ntuple::column< float > * GetNtupleFColumn(G4int ntupleId, G4int columnId) const
int G4int
Definition: G4Types.hh:78
virtual G4bool FillNtupleIColumn(G4int columnId, G4int value)
std::vector< tools::wroot::ntuple * > fNtupleVector
std::vector< G4RootNtupleDescription * > fNtupleDescriptionVector
bool G4bool
Definition: G4Types.hh:79
tools::wroot::ntuple::column_string * GetNtupleSColumn(G4int ntupleId, G4int columnId) const
virtual G4RootNtupleDescription * GetNtupleInFunction(G4int id, G4String function, G4bool warn=true, G4bool onlyIfActive=true) const
tools::wroot::ntuple * GetNtuple() const
virtual G4int GetNofNtuples() const
std::vector< tools::wroot::ntuple * >::const_iterator BeginConstNtuple() const
virtual G4bool AddNtupleRow()
virtual G4bool FillNtupleSColumn(G4int columnId, const G4String &value)
tools::wroot::ntuple::column< double > * GetNtupleDColumn(G4int ntupleId, G4int columnId) const
virtual G4int CreateNtuple(const G4String &name, const G4String &title)
virtual G4int CreateNtupleIColumn(const G4String &name, std::vector< int > *vector)
double G4double
Definition: G4Types.hh:76
G4RootNtupleManager(const G4AnalysisManagerState &state)
virtual G4bool FillNtupleDColumn(G4int columnId, G4double value)
virtual G4int CreateNtupleDColumn(const G4String &name, std::vector< double > *vector)
std::vector< tools::wroot::ntuple * >::const_iterator EndConstNtuple() const
void SetNtupleDirectory(tools::wroot::directory *directory)