Geant4  10.01.p01
G4CsvNtupleManager.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 // Manager class for CSV ntuples.
29 //
30 // Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
31 
32 #ifndef G4CsvNtupleManager_h
33 #define G4CsvNtupleManager_h 1
34 
35 
36 #include "G4VNtupleManager.hh"
37 #include "globals.hh"
38 
39 #include "tools/wcsv_ntuple"
40 
41 #include <vector>
42 
43 class G4CsvFileManager;
45 
47 {
48  friend class G4CsvAnalysisManager;
49 
50  protected:
53 
54  // Functions specific to the output type
55  //
56 
57  // Methods to manipulate ntuples
59  G4bool IsEmpty() const;
60  G4bool Reset();
61 
62  // Set methods
63  void SetFileManager(G4CsvFileManager* fileManager);
64 
65  // Access methods
66  tools::wcsv::ntuple* GetNtuple() const;
67  tools::wcsv::ntuple* GetNtuple(G4int ntupleId) const;
68 
69  // Iterators
70  std::vector<tools::wcsv::ntuple*>::iterator BeginNtuple();
71  std::vector<tools::wcsv::ntuple*>::iterator EndNtuple();
72  std::vector<tools::wcsv::ntuple*>::const_iterator BeginConstNtuple() const;
73  std::vector<tools::wcsv::ntuple*>::const_iterator EndConstNtuple() const;
74 
75  // Access to ntuple vector (needed for Write())
76  const std::vector<G4CsvNtupleDescription*>& GetNtupleDescriptionVector() const;
77 
78  // Functions independent from the output type
79  //
80 
81  // Methods to create ntuples
82  virtual G4int CreateNtuple(const G4String& name, const G4String& title);
83  // Create columns in the last created ntuple
84  virtual G4int CreateNtupleIColumn(
85  const G4String& name, std::vector<int>* vector);
86  virtual G4int CreateNtupleFColumn(
87  const G4String& name, std::vector<float>* vector);
88  virtual G4int CreateNtupleDColumn(
89  const G4String& name, std::vector<double>* vector);
90  virtual G4int CreateNtupleSColumn(const G4String& name);
91  virtual void FinishNtuple();
92  // Create columns in the ntuple with given id
93  virtual G4int CreateNtupleIColumn(G4int ntupleId,
94  const G4String& name, std::vector<int>* vector);
95  virtual G4int CreateNtupleFColumn(G4int ntupleId,
96  const G4String& name, std::vector<float>* vector);
97  virtual G4int CreateNtupleDColumn(G4int ntupleId,
98  const G4String& name, std::vector<double>* vector);
99  virtual G4int CreateNtupleSColumn(G4int ntupleId, const G4String& name);
100  virtual void FinishNtuple(G4int ntupleId);
101 
102  // Methods to fill ntuples
103  // Methods for ntuple with id = FirstNtupleId
104  virtual G4bool FillNtupleIColumn(G4int columnId, G4int value);
105  virtual G4bool FillNtupleFColumn(G4int columnId, G4float value);
106  virtual G4bool FillNtupleDColumn(G4int columnId, G4double value);
107  virtual G4bool FillNtupleSColumn(G4int columnId, const G4String& value);
108  virtual G4bool AddNtupleRow();
109  // Methods for ntuple with id > FirstNtupleId (when more ntuples exist)
110  virtual G4bool FillNtupleIColumn(G4int ntupleId, G4int columnId, G4int value);
111  virtual G4bool FillNtupleFColumn(G4int ntupleId, G4int columnId, G4float value);
112  virtual G4bool FillNtupleDColumn(G4int ntupleId, G4int columnId, G4double value);
113  virtual G4bool FillNtupleSColumn(G4int ntupleId, G4int columnId,
114  const G4String& value);
115  virtual G4bool AddNtupleRow(G4int ntupleId);
116 
117  // Access methods
118  virtual G4int GetNofNtuples() const;
119 
120  // Csv format specific option
121  void SetIsCommentedHeader(G4bool isCommentedHeader);
122  void SetIsHippoHeader(G4bool isHippoHeader);
123 
124  private:
125  // methods
126  //
127  tools::wcsv::ntuple::column<int>*
128  GetNtupleIColumn(G4int ntupleId, G4int columnId) const;
129  tools::wcsv::ntuple::column<float>*
130  GetNtupleFColumn(G4int ntupleId, G4int columnId) const;
131  tools::wcsv::ntuple::column<double>*
132  GetNtupleDColumn(G4int ntupleId, G4int columnId) const;
133  tools::wcsv::ntuple::column<std::string>*
134  GetNtupleSColumn(G4int ntupleId, G4int columnId) const;
135 
137  G4String function,
138  G4bool warn = true,
139  G4bool onlyIfActive = true) const;
140 
141  G4bool WriteHeader(tools::wcsv::ntuple* ntuple) const;
142 
143  // data members
144  //
146  std::vector<G4CsvNtupleDescription*> fNtupleDescriptionVector;
147  std::vector<tools::wcsv::ntuple*> fNtupleVector;
150 };
151 
152 // inline functions
153 
155 { fFileManager = fileManager; }
156 
157 inline std::vector<tools::wcsv::ntuple*>::iterator
159 { return fNtupleVector.begin(); }
160 
161 inline std::vector<tools::wcsv::ntuple*>::iterator
163 { return fNtupleVector.end(); }
164 
165 inline std::vector<tools::wcsv::ntuple*>::const_iterator
167 { return fNtupleVector.begin(); }
168 
169 inline std::vector<tools::wcsv::ntuple*>::const_iterator
171 { return fNtupleVector.end(); }
172 
174 { return fNtupleDescriptionVector.size(); }
175 
176 inline const std::vector<G4CsvNtupleDescription*>&
178 { return fNtupleDescriptionVector; }
179 
180 inline void G4CsvNtupleManager::SetIsCommentedHeader(G4bool isCommentedHeader)
181 { fIsCommentedHeader = isCommentedHeader; }
182 
184 { fIsHippoHeader = isHippoHeader; }
185 
186 #endif
187 
void SetFileManager(G4CsvFileManager *fileManager)
virtual G4int CreateNtupleDColumn(const G4String &name, std::vector< double > *vector)
std::vector< tools::wcsv::ntuple * >::const_iterator BeginConstNtuple() const
std::vector< G4CsvNtupleDescription * > fNtupleDescriptionVector
G4String name
Definition: TRTMaterials.hh:40
virtual G4int CreateNtuple(const G4String &name, const G4String &title)
virtual G4int CreateNtupleFColumn(const G4String &name, std::vector< float > *vector)
float G4float
Definition: G4Types.hh:77
G4CsvNtupleManager(const G4AnalysisManagerState &state)
std::vector< tools::wcsv::ntuple * > fNtupleVector
int G4int
Definition: G4Types.hh:78
tools::wcsv::ntuple * GetNtuple() const
virtual G4CsvNtupleDescription * GetNtupleInFunction(G4int id, G4String function, G4bool warn=true, G4bool onlyIfActive=true) const
tools::wcsv::ntuple::column< float > * GetNtupleFColumn(G4int ntupleId, G4int columnId) const
G4CsvFileManager * fFileManager
std::vector< tools::wcsv::ntuple * >::iterator BeginNtuple()
virtual void FinishNtuple()
tools::wcsv::ntuple::column< double > * GetNtupleDColumn(G4int ntupleId, G4int columnId) const
bool G4bool
Definition: G4Types.hh:79
G4bool IsEmpty() const
virtual G4bool FillNtupleFColumn(G4int columnId, G4float value)
std::vector< tools::wcsv::ntuple * >::const_iterator EndConstNtuple() const
virtual G4int GetNofNtuples() const
virtual G4int CreateNtupleIColumn(const G4String &name, std::vector< int > *vector)
void SetIsHippoHeader(G4bool isHippoHeader)
virtual G4int CreateNtupleSColumn(const G4String &name)
const std::vector< G4CsvNtupleDescription * > & GetNtupleDescriptionVector() const
virtual G4bool FillNtupleIColumn(G4int columnId, G4int value)
tools::wcsv::ntuple::column< int > * GetNtupleIColumn(G4int ntupleId, G4int columnId) const
void SetIsCommentedHeader(G4bool isCommentedHeader)
virtual G4bool FillNtupleDColumn(G4int columnId, G4double value)
tools::wcsv::ntuple::column< std::string > * GetNtupleSColumn(G4int ntupleId, G4int columnId) const
double G4double
Definition: G4Types.hh:76
G4bool WriteHeader(tools::wcsv::ntuple *ntuple) const
std::vector< tools::wcsv::ntuple * >::iterator EndNtuple()
virtual G4bool AddNtupleRow()
virtual G4bool FillNtupleSColumn(G4int columnId, const G4String &value)