Geant4  10.01.p03
ExG4HbookNtupleManager.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$
27 //
30 
31 // Author: Ivana Hrivnacova, 15/06/2011 (ivana@ipno.in2p3.fr)
32 
33 #ifdef G4_USE_HBOOK
34 
35 #ifndef ExG4HbookNtupleManager_h
36 #define ExG4HbookNtupleManager_h 1
37 
38 #include "G4VNtupleManager.hh"
40 #include "globals.hh"
41 
42 #include <tools/hbook/wntuple>
43 
44 #include <vector>
45 #include <map>
46 
47 class ExG4HbookFileManager;
48 
54 
55 class ExG4HbookNtupleManager : public G4VNtupleManager
56 {
57  friend class ExG4HbookAnalysisManager;
58 
59  protected:
60  ExG4HbookNtupleManager(const G4AnalysisManagerState& state);
61  virtual ~ExG4HbookNtupleManager();
62 
63  // Functions specific to the output type
64  //
65 
66  // Set the offset of NTUPLE ID for ntuples
67  // ( default value = firstNtupleID if firstNtupleID > 0; otherwise = 1)
68  G4bool SetNtupleHbookIdOffset(G4int offset);
69  G4int GetNtupleHbookIdOffset() const;
70 
71  // Set methods
72  void SetFileManager(ExG4HbookFileManager* fileManager);
73 
74  // Access methods
75  tools::hbook::wntuple* GetNtuple() const;
76  tools::hbook::wntuple* GetNtuple(G4int ntupleId) const;
77 
78  // Iterators
79  std::vector<tools::hbook::wntuple*>::iterator BeginNtuple();
80  std::vector<tools::hbook::wntuple*>::iterator EndNtuple();
81  std::vector<tools::hbook::wntuple*>::const_iterator BeginConstNtuple() const;
82  std::vector<tools::hbook::wntuple*>::const_iterator EndConstNtuple() const;
83 
84  // Virtual functions from base class
85  //
86  // Methods to create ntuples
87  virtual G4int CreateNtuple(const G4String& name, const G4String& title);
88  // Create columns in the last created ntuple
89  virtual G4int CreateNtupleIColumn(
90  const G4String& name, std::vector<int>* vector);
91  virtual G4int CreateNtupleFColumn(
92  const G4String& name, std::vector<float>* vector);
93  virtual G4int CreateNtupleDColumn(
94  const G4String& name, std::vector<double>* vector);
95  virtual G4int CreateNtupleSColumn(const G4String& name);
96  virtual void FinishNtuple();
97  // Create columns in the ntuple with given id
98  virtual G4int CreateNtupleIColumn(G4int ntupleId,
99  const G4String& name, std::vector<int>* vector);
100  virtual G4int CreateNtupleFColumn(G4int ntupleId,
101  const G4String& name, std::vector<float>* vector);
102  virtual G4int CreateNtupleDColumn(G4int ntupleId,
103  const G4String& name, std::vector<double>* vector);
104  virtual G4int CreateNtupleSColumn(G4int ntupleId, const G4String& name);
105  virtual void FinishNtuple(G4int ntupleId);
106 
107  // Methods to fill ntuples
108  // Methods for ntuple with id = FirstNtupleId
109  virtual G4bool FillNtupleIColumn(G4int columnId, G4int value);
110  virtual G4bool FillNtupleFColumn(G4int columnId, G4float value);
111  virtual G4bool FillNtupleDColumn(G4int columnId, G4double value);
112  virtual G4bool FillNtupleSColumn(G4int columnId, const G4String& value);
113  virtual G4bool AddNtupleRow();
114  // Methods for ntuple with id > FirstNtupleId (when more ntuples exist)
115  virtual G4bool FillNtupleIColumn(
116  G4int ntupleId, G4int columnId, G4int value);
117  virtual G4bool FillNtupleFColumn(
118  G4int ntupleId, G4int columnId, G4float value);
119  virtual G4bool FillNtupleDColumn(
120  G4int ntupleId, G4int columnId, G4double value);
121  virtual G4bool FillNtupleSColumn(
122  G4int ntupleId, G4int columnId, const G4String& value);
123  virtual G4bool AddNtupleRow(G4int ntupleId);
124 
125  // Access methods
126  virtual G4int GetNofNtuples() const;
127 
128  private:
129  // methods
130  //
131  void SetNtupleHbookIdOffset();
132  void CreateNtuplesFromBooking();
133 
134  tools::hbook::wntuple::column<int>*
135  GetNtupleIColumn(G4int ntupleId, G4int columnId) const;
136  tools::hbook::wntuple::column<float>*
137  GetNtupleFColumn(G4int ntupleId, G4int columnId) const;
138  tools::hbook::wntuple::column<double>*
139  GetNtupleDColumn(G4int ntupleId, G4int columnId) const;
140 
141  void Reset();
142  ExG4HbookNtupleDescription* GetNtupleInFunction(G4int id,
143  G4String function,
144  G4bool warn = true,
145  G4bool onlyIfActive = true) const;
146 
147  // data members
148  //
149  ExG4HbookFileManager* fFileManager;
150  G4int fNtupleHbookIdOffset;
151  std::vector<ExG4HbookNtupleDescription*> fNtupleDescriptionVector;
152  std::vector<tools::hbook::wntuple*> fNtupleVector;
153 };
154 
155 // inline functions
156 
157 inline void ExG4HbookNtupleManager::SetFileManager(ExG4HbookFileManager* fileManager)
158 { fFileManager = fileManager; }
159 
160 inline G4int ExG4HbookNtupleManager::GetNtupleHbookIdOffset() const {
161  return fNtupleHbookIdOffset;
162 }
163 
164 inline std::vector<tools::hbook::wntuple*>::iterator
165 ExG4HbookNtupleManager::BeginNtuple()
166 { return fNtupleVector.begin(); }
167 
168 inline std::vector<tools::hbook::wntuple*>::iterator
169 ExG4HbookNtupleManager::EndNtuple()
170 { return fNtupleVector.end(); }
171 
172 inline std::vector<tools::hbook::wntuple*>::const_iterator
173 ExG4HbookNtupleManager::BeginConstNtuple() const
174 { return fNtupleVector.begin(); }
175 
176 inline std::vector<tools::hbook::wntuple*>::const_iterator
177 ExG4HbookNtupleManager::EndConstNtuple() const
178 { return fNtupleVector.end(); }
179 
180 inline G4int ExG4HbookNtupleManager::GetNofNtuples() const
181 { return fNtupleVector.size(); }
182 
183 
184 #endif
185 
186 #endif
virtual G4int GetNofNtuples() const =0
G4String name
Definition: TRTMaterials.hh:40
float G4float
Definition: G4Types.hh:77
virtual G4int CreateNtupleSColumn(const G4String &name)=0
virtual G4bool FillNtupleSColumn(G4int id, const G4String &value)=0
int G4int
Definition: G4Types.hh:78
virtual G4int CreateNtuple(const G4String &name, const G4String &title)=0
virtual void FinishNtuple()=0
bool G4bool
Definition: G4Types.hh:79
virtual G4int CreateNtupleFColumn(const G4String &name, std::vector< float > *vector)=0
virtual G4int CreateNtupleIColumn(const G4String &name, std::vector< int > *vector)=0
virtual G4bool FillNtupleIColumn(G4int id, G4int value)=0
virtual G4bool AddNtupleRow()=0
virtual G4bool FillNtupleFColumn(G4int id, G4float value)=0
virtual G4bool FillNtupleDColumn(G4int id, G4double value)=0
double G4double
Definition: G4Types.hh:76
virtual G4int CreateNtupleDColumn(const G4String &name, std::vector< double > *vector)=0
Definition of the ExG4HbookNtupleDescription structure.