PandaRoot
RhoTuple.h
Go to the documentation of this file.
1 //****************************************************************************
2 //* This file is part of PandaRoot. *
3 //* *
4 //* PandaRoot is distributed under the terms of the *
5 //* GNU General Public License (GPL) version 3, *
6 //* copied verbatim in the file "LICENSE". *
7 //* *
8 //* Copyright (C) 2006 - 2024 FAIR GmbH and copyright holders of PandaRoot *
9 //* The copyright holders are listed in the file "COPYRIGHTHOLDERS". *
10 //* The authors are listed in the file "AUTHORS". *
11 //****************************************************************************
12 
13 #ifndef RHOTUPLE_H
14 #define RHOTUPLE_H
15 // //
17 // RhoTuple //
18 // //
19 // Nested class hierarchy to hold information about RhoTuple columns. //
20 // //
21 // Author List: //
22 // Marcel Kunze, RUB, Mar. 99 //
23 // Apr.2001 (MK), Faster implementation based on THashList //
24 // Copyright (C) 1999-2001, Ruhr-University Bochum. //
25 // Ralf Kliemt, HIM/GSI Feb.2013 (Cleanup & Restructuring) //
26 // //
28 
29 // Rho implementation of a Tuple.
30 //
31 // The member function "Column" provides the data for a Column of the ntuple.
32 // The string is the label of the Column as well as being a unique identifier
33 // of the Column. The second argument provides the data (Float_t or int) for
34 // one row in the Column. Note that only one line of code is needed to
35 // define the Column (if it has not been seen previously) and provide the
36 // data for each "event".
37 //
38 // The third argument of "Column()" provides the default value for that
39 // Column (if it not provided, it defaults to 0.0). On a particular "event",
40 // if no call is made to "Column" for a particular Column, that Column's
41 // default value is used when filling the ntuple. Therefore, the default
42 // value should be set to an "unphysical" number.
43 //
44 // At the end of an "event", a call should be made to either "dumpData()" or
45 // "clearData()". "dumpData()" dumps all the data it has stored internally
46 // into the ntuple and then calls "clearData()".
47 // "clearData()" sets all the internal Column values to their defaults,
48 // without changing the ntuple. Therefore, if you want to keep the data
49 // that is presently in an NTuple, call "dumpData()"; else, call
50 // "clearData()".
51 
52 #include <iosfwd>
53 #include "RhoColumn.h"
54 #include "THashList.h"
55 
56 class TTree;
57 class TBranch;
58 class TFile;
59 
60 class RhoTuple : public TNamed {
61 
62  public:
63  RhoTuple();
64 
65  // Constructor to create a ROOT tuple with name and title:
66  RhoTuple(const char *, const char *);
67 
68  // Destructor:
69  virtual ~RhoTuple();
70 
71  // Column booking/filling. All these have the same name - Column(...)
72  // Specify the data for a Column. The string is to the key to
73  // the Column, so it must be unique. If an existing Column with the given
74  // label is not found, a new one is created. The third, optional, argument
75  // is the value to use if this Column is not otherwise filled in for a
76  // given row of the tuple.
77 
78  // ====== Bool type ======
79  // Make/fill Column with a single value
80  void Column(const char *label, Bool_t value, Bool_t defval = 0, const char *block = nullptr);
81  // Make/fill Column-array. Length is fixed at creation time.
82  virtual void Column(const char *label, const RhoHTAbsValVector<Bool_t> &vector, Bool_t defval = kFALSE, const char *block = nullptr);
83  // Make/fill Column-array. Length is variable and is taken from
84  // another Column.
85  virtual void Column(const char *label, const RhoHTAbsValVector<Bool_t> &vector, const char *ilab, Bool_t defval = kFALSE, const char *block = nullptr);
86 
87  // ====== Int type ======
88  // Make/fill Column with a single value
89  void Column(const char *label, Int_t value, Int_t defval = 0, const char *block = nullptr, const RhoHTRange<Int_t> &range = RhoHTRange<Int_t>());
90  // Make/fill Column-array. Length is fixed at creation time.
91  virtual void
92  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>());
93  // Make/fill Column-array. Length is variable and is taken from
94  // another Column.
95  virtual void Column(const char *label, const RhoHTAbsValVector<Int_t> &vector, const char *ilab, Int_t defval = 0, const char *block = nullptr,
96  const RhoHTRange<Int_t> &range = RhoHTRange<Int_t>());
97 
98  // ====== Float type ======
99  // Make/fill Column with a single value
100  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>());
101  // Make/fill Column-array. Length is fixed at creation time.
102  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>());
103  // Make/fill Column-array. Length is variable and is taken from
104  // another Column.
105  void
106  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>());
107  // Make/fill Column-array. Length is fixed at creation time.
108  virtual void
109  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>());
110  // Make/fill Column-array. Length is variable and is taken from
111  // another Column.
112  virtual void Column(const char *label, const RhoHTAbsValVector<Float_t> &vector, const char *ilab, Float_t defval = 0.0f, const char *block = nullptr,
113  const RhoHTRange<Float_t> &range = RhoHTRange<Float_t>());
114 
115  // ====== Double type ======
116  // Make/fill Column with a single value
117  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>());
118  // Make/fill Column-array. Length is fixed at creation time.
119  virtual void Column(const char *label, const RhoHTAbsValVector<Double_t> &vector, Double_t defval = 0.0, const char *block = nullptr,
120  const RhoHTRange<Double_t> &range = RhoHTRange<Double_t>());
121  // Make/fill Column-array. Length is variable and is taken from
122  // another Column.
123  virtual void Column(const char *label, const RhoHTAbsValVector<Double_t> &vector, const char *ilab, Double_t defval = 0.0, const char *block = nullptr,
124  const RhoHTRange<Double_t> &range = RhoHTRange<Double_t>());
125 
126  // ====== fixed-length string Columns ======
127  // ROOT ntuples allow variable length strings, thus N is ignored
128  void Column(const char *label, const char *value, Int_t N, const char *defval = nullptr, const char *block = nullptr);
129  void Column(const char *label, const char *value);
130 
131  // Dump all the data into the ntuple and then clear:
132  void DumpData();
133 
134  // Set all the data to their default values:
135  void ClearData();
136 
137  // Return the title of the ntuple:
138  const char *Title() const;
139 
140  // Number of Columns:
141  Int_t NColumns() const;
142 
143  // Label for a particular Column
144  const char *Label(Int_t) const;
145 
146  // Print info about ntuple:
147  virtual void PrintOn(std::ostream &) const;
148 
149  RhoTuple &operator=(const RhoTuple &) { return *this; }
150 
151  void WriteToFile(TString fname = "ntpdata.root", TString opt = "RECREATE");
152  void AddToFile(TString fname = "ntpdata.root");
153 
154  TTree *GetInternalTree() { return fTree; }
155 
156  private:
157  // Data members of TTuple:
158  THashList *fMap;
159  TTree *fTree;
160  public:
161  ClassDef(RhoTuple, 1) // NTuple
162 };
163 
164 #endif
const char * Label(Int_t) const
RhoTuple & operator=(const RhoTuple &)
Definition: RhoTuple.h:149
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:32
TTree * GetInternalTree()
Definition: RhoTuple.h:154
const char * Title() const