FairRoot/PandaRoot
RhoTuple.h
Go to the documentation of this file.
1 #ifndef RHOTUPLE_H
2 #define RHOTUPLE_H
3 // //
5 // RhoTuple //
6 // //
7 // Nested class hierarchy to hold information about RhoTuple columns. //
8 // //
9 // Author List: //
10 // Marcel Kunze, RUB, Mar. 99 //
11 // Apr.2001 (MK), Faster implementation based on THashList //
12 // Copyright (C) 1999-2001, Ruhr-University Bochum. //
13 // Ralf Kliemt, HIM/GSI Feb.2013 (Cleanup & Restructuring) //
14 // //
16 
17 // Rho implementation of a Tuple.
18 //
19 // The member function "Column" provides the data for a Column of the ntuple.
20 // The string is the label of the Column as well as being a unique identifier
21 // of the Column. The second argument provides the data (Float_t or int) for
22 // one row in the Column. Note that only one line of code is needed to
23 // define the Column (if it has not been seen previously) and provide the
24 // data for each "event".
25 //
26 // The third argument of "Column()" provides the default value for that
27 // Column (if it not provided, it defaults to 0.0). On a particular "event",
28 // if no call is made to "Column" for a particular Column, that Column's
29 // default value is used when filling the ntuple. Therefore, the default
30 // value should be set to an "unphysical" number.
31 //
32 // At the end of an "event", a call should be made to either "dumpData()" or
33 // "clearData()". "dumpData()" dumps all the data it has stored internally
34 // into the ntuple and then calls "clearData()".
35 // "clearData()" sets all the internal Column values to their defaults,
36 // without changing the ntuple. Therefore, if you want to keep the data
37 // that is presently in an NTuple, call "dumpData()"; else, call
38 // "clearData()".
39 
40 #include <iosfwd>
41 #include "RhoHistogram/RhoColumn.h"
42 #include "THashList.h"
43 
44 class TTree;
45 class TBranch;
46 class TFile;
47 
48 class RhoTuple : public TNamed
49 {
50 
51  public:
52 
53  RhoTuple();
54 
55  // Constructor to create a ROOT tuple with name and title:
56  RhoTuple ( const char*, const char* );
57 
58  // Destructor:
59  virtual ~RhoTuple();
60 
61  // Column booking/filling. All these have the same name - Column(...)
62  // Specify the data for a Column. The string is to the key to
63  // the Column, so it must be unique. If an existing Column with the given
64  // label is not found, a new one is created. The third, optional, argument
65  // is the value to use if this Column is not otherwise filled in for a
66  // given row of the tuple.
67 
68 
69  // ====== Bool type ======
70  // Make/fill Column with a single value
71  void Column ( const char* label,
72  Bool_t value,
73  Bool_t defval = 0,
74  const char* block = 0 );
75  // Make/fill Column-array. Length is fixed at creation time.
76  virtual void Column ( const char* label,
77  const RhoHTAbsValVector<Bool_t> &vector,
78  Bool_t defval = kFALSE,
79  const char* block = 0 );
80  // Make/fill Column-array. Length is variable and is taken from
81  // another Column.
82  virtual void Column ( const char* label,
83  const RhoHTAbsValVector<Bool_t> &vector,
84  const char* ilab,
85  Bool_t defval = kFALSE,
86  const char* block = 0 );
87 
88 
89  // ====== Int type ======
90  // Make/fill Column with a single value
91  void Column ( const char* label,
92  Int_t value,
93  Int_t defval = 0,
94  const char* block = 0,
96  // Make/fill Column-array. Length is fixed at creation time.
97  virtual void Column ( const char* label,
98  const RhoHTAbsValVector<Int_t> &vector,
99  Int_t defval = 0,
100  const char* block = 0,
102  // Make/fill Column-array. Length is variable and is taken from
103  // another Column.
104  virtual void Column ( const char* label,
105  const RhoHTAbsValVector<Int_t> &vector,
106  const char* ilab,
107  Int_t defval = 0,
108  const char* block = 0,
110 
111 
112  // ====== Float type ======
113  // Make/fill Column with a single value
114  void Column ( const char* label,
115  Float_t value,
116  Float_t defval = 0.0f,
117  const char* block = 0,
119  // Make/fill Column-array. Length is fixed at creation time.
120  void Column ( const char* label,
121  const TVector& vec,
122  Float_t defval = 0.0f,
123  const char* block = 0,
125  // Make/fill Column-array. Length is variable and is taken from
126  // another Column.
127  void Column ( const char* label,
128  const TVector& vec,
129  const char* ilab,
130  Float_t defval = 0.0f,
131  const char* block = 0,
133  // Make/fill Column-array. Length is fixed at creation time.
134  virtual void Column ( const char* label,
135  const RhoHTAbsValVector<Float_t> &vector,
136  Float_t defval = 0.0f,
137  const char* block = 0,
139  // Make/fill Column-array. Length is variable and is taken from
140  // another Column.
141  virtual void Column ( const char* label,
142  const RhoHTAbsValVector<Float_t> &vector,
143  const char* ilab,
144  Float_t defval = 0.0f,
145  const char* block = 0,
147 
148 
149  // ====== Double type ======
150  // Make/fill Column with a single value
151  void Column ( const char* label,
152  Double_t value,
153  Double_t defval = 0.0,
154  const char* block = 0,
156  // Make/fill Column-array. Length is fixed at creation time.
157  virtual void Column ( const char* label,
158  const RhoHTAbsValVector<Double_t> &vector,
159  Double_t defval = 0.0,
160  const char* block = 0,
162  // Make/fill Column-array. Length is variable and is taken from
163  // another Column.
164  virtual void Column ( const char* label,
165  const RhoHTAbsValVector<Double_t> &vector,
166  const char* ilab,
167  Double_t defval = 0.0,
168  const char* block = 0,
170 
171  // ====== fixed-length string Columns ======
172  // ROOT ntuples allow variable length strings, thus N is ignored
173  void Column ( const char* label,
174  const char* value,
175  Int_t N,
176  const char* defval = 0,
177  const char* block = 0 );
178  void Column ( const char* label,
179  const char* value );
180 
181 
182  // Dump all the data into the ntuple and then clear:
183  void DumpData();
184 
185  // Set all the data to their default values:
186  void ClearData();
187 
188  // Return the title of the ntuple:
189  const char* Title() const;
190 
191  // Number of Columns:
192  Int_t NColumns() const ;
193 
194  // Label for a particular Column
195  const char* Label ( Int_t ) const ;
196 
197  // Print info about ntuple:
198  virtual void PrintOn ( std::ostream& ) const;
199 
201  return *this;
202  }
203 
204  void WriteToFile ( TString fname="ntpdata.root", TString opt="RECREATE" );
205  void AddToFile ( TString fname="ntpdata.root" );
206 
207  TTree* GetInternalTree() {
208  return fTree;
209  }
210 
211  private:
212 
213  // Data members of TTuple:
214  THashList* fMap;
215  TTree* fTree;
216  public:
217  ClassDef ( RhoTuple,1 ) // NTuple
218 };
219 
220 
221 
222 #endif
double range[]
Definition: evaltrig.C:67
RhoTuple & operator=(const RhoTuple &)
Definition: RhoTuple.h:200
RhoTuple()
Definition: RhoTuple.cxx:27
TTree * fTree
Do not stream.
Definition: RhoTuple.h:215
void WriteToFile(TString fname="ntpdata.root", TString opt="RECREATE")
Definition: RhoTuple.cxx:445
void ClearData()
Definition: RhoTuple.cxx:403
Double_t
void AddToFile(TString fname="ntpdata.root")
Definition: RhoTuple.cxx:453
const char * Title() const
Definition: RhoTuple.cxx:415
TFile * f
Definition: bump_analys.C:12
void Column(const char *label, Bool_t value, Bool_t defval=0, const char *block=0)
Definition: RhoTuple.cxx:56
THashList * fMap
Definition: RhoTuple.h:214
void DumpData()
Definition: RhoTuple.cxx:391
virtual ~RhoTuple()
Definition: RhoTuple.cxx:42
TTree * GetInternalTree()
Definition: RhoTuple.h:207
const char * Label(Int_t) const
Definition: RhoTuple.cxx:427
virtual void PrintOn(std::ostream &) const
Definition: RhoTuple.cxx:437
dble_vec_t vec[12]
Definition: ranlxd.cxx:380
Int_t NColumns() const
Definition: RhoTuple.cxx:421