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 "RhoColumn.h"
42 #include "THashList.h"
43 
44 class TTree;
45 class TBranch;
46 class TFile;
47 
48 class RhoTuple : public TNamed {
49 
50  public:
51  RhoTuple();
52 
53  // Constructor to create a ROOT tuple with name and title:
54  RhoTuple(const char *, const char *);
55 
56  // Destructor:
57  virtual ~RhoTuple();
58 
59  // Column booking/filling. All these have the same name - Column(...)
60  // Specify the data for a Column. The string is to the key to
61  // the Column, so it must be unique. If an existing Column with the given
62  // label is not found, a new one is created. The third, optional, argument
63  // is the value to use if this Column is not otherwise filled in for a
64  // given row of the tuple.
65 
66  // ====== Bool type ======
67  // Make/fill Column with a single value
68  void Column(const char *label, Bool_t value, Bool_t defval = 0, const char *block = nullptr);
69  // Make/fill Column-array. Length is fixed at creation time.
70  virtual void Column(const char *label, const RhoHTAbsValVector<Bool_t> &vector, Bool_t defval = kFALSE, const char *block = nullptr);
71  // Make/fill Column-array. Length is variable and is taken from
72  // another Column.
73  virtual void Column(const char *label, const RhoHTAbsValVector<Bool_t> &vector, const char *ilab, Bool_t defval = kFALSE, const char *block = nullptr);
74 
75  // ====== Int type ======
76  // Make/fill Column with a single value
77  void Column(const char *label, Int_t value, Int_t defval = 0, const char *block = nullptr, const RhoHTRange<Int_t> &range = RhoHTRange<Int_t>());
78  // Make/fill Column-array. Length is fixed at creation time.
79  virtual void
80  Column(const char *label, const RhoHTAbsValVector<Int_t> &vector, Int_t defval = 0, const char *block = nullptr, const RhoHTRange<Int_t> &range = RhoHTRange<Int_t>());
81  // Make/fill Column-array. Length is variable and is taken from
82  // another Column.
83  virtual void Column(const char *label, const RhoHTAbsValVector<Int_t> &vector, const char *ilab, Int_t defval = 0, const char *block = nullptr,
84  const RhoHTRange<Int_t> &range = RhoHTRange<Int_t>());
85 
86  // ====== Float type ======
87  // Make/fill Column with a single value
88  void Column(const char *label, Float_t value, Float_t defval = 0.0f, const char *block = nullptr, const RhoHTRange<Float_t> &range = RhoHTRange<Float_t>());
89  // Make/fill Column-array. Length is fixed at creation time.
90  void Column(const char *label, const TVector &vec, Float_t defval = 0.0f, const char *block = nullptr, const RhoHTRange<Float_t> &range = RhoHTRange<Float_t>());
91  // Make/fill Column-array. Length is variable and is taken from
92  // another Column.
93  void
94  Column(const char *label, const TVector &vec, const char *ilab, Float_t defval = 0.0f, const char *block = nullptr, const RhoHTRange<Float_t> &range = RhoHTRange<Float_t>());
95  // Make/fill Column-array. Length is fixed at creation time.
96  virtual void
97  Column(const char *label, const RhoHTAbsValVector<Float_t> &vector, Float_t defval = 0.0f, const char *block = nullptr, const RhoHTRange<Float_t> &range = RhoHTRange<Float_t>());
98  // Make/fill Column-array. Length is variable and is taken from
99  // another Column.
100  virtual void Column(const char *label, const RhoHTAbsValVector<Float_t> &vector, const char *ilab, Float_t defval = 0.0f, const char *block = nullptr,
101  const RhoHTRange<Float_t> &range = RhoHTRange<Float_t>());
102 
103  // ====== Double type ======
104  // Make/fill Column with a single value
105  void Column(const char *label, Double_t value, Double_t defval = 0.0, const char *block = nullptr, const RhoHTRange<Double_t> &range = RhoHTRange<Double_t>());
106  // Make/fill Column-array. Length is fixed at creation time.
107  virtual void Column(const char *label, const RhoHTAbsValVector<Double_t> &vector, Double_t defval = 0.0, const char *block = nullptr,
108  const RhoHTRange<Double_t> &range = RhoHTRange<Double_t>());
109  // Make/fill Column-array. Length is variable and is taken from
110  // another Column.
111  virtual void Column(const char *label, const RhoHTAbsValVector<Double_t> &vector, const char *ilab, Double_t defval = 0.0, const char *block = nullptr,
112  const RhoHTRange<Double_t> &range = RhoHTRange<Double_t>());
113 
114  // ====== fixed-length string Columns ======
115  // ROOT ntuples allow variable length strings, thus N is ignored
116  void Column(const char *label, const char *value, Int_t N, const char *defval = nullptr, const char *block = nullptr);
117  void Column(const char *label, const char *value);
118 
119  // Dump all the data into the ntuple and then clear:
120  void DumpData();
121 
122  // Set all the data to their default values:
123  void ClearData();
124 
125  // Return the title of the ntuple:
126  const char *Title() const;
127 
128  // Number of Columns:
129  Int_t NColumns() const;
130 
131  // Label for a particular Column
132  const char *Label(Int_t) const;
133 
134  // Print info about ntuple:
135  virtual void PrintOn(std::ostream &) const;
136 
137  RhoTuple &operator=(const RhoTuple &) { return *this; }
138 
139  void WriteToFile(TString fname = "ntpdata.root", TString opt = "RECREATE");
140  void AddToFile(TString fname = "ntpdata.root");
141 
142  TTree *GetInternalTree() { return fTree; }
143 
144  private:
145  // Data members of TTuple:
146  THashList *fMap;
147  TTree *fTree;
148  public:
149  ClassDef(RhoTuple, 1) // NTuple
150 };
151 
152 #endif
const char * Label(Int_t) const
RhoTuple & operator=(const RhoTuple &)
Definition: RhoTuple.h:137
Int_t NColumns() const
virtual void PrintOn(std::ostream &) const
void WriteToFile(TString fname="ntpdata.root", TString opt="RECREATE")
void Column(const char *label, Bool_t value, Bool_t defval=0, const char *block=nullptr)
virtual ~RhoTuple()
void ClearData()
void AddToFile(TString fname="ntpdata.root")
void DumpData()
float f
Definition: P4_F32vec4.h:20
TTree * GetInternalTree()
Definition: RhoTuple.h:142
const char * Title() const