ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/CmsHi/HafHistogram/interface/HTuple.h
Revision: 1.1
Committed: Wed Sep 29 15:44:21 2010 UTC (14 years, 7 months ago) by yjlee
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Log Message:
HafHistogram tool

File Contents

# User Rev Content
1 yjlee 1.1 #ifndef HTUPLE_H
2     #define HTUPLE_H
3    
4     /** \class HTuple Ganzhur/HafHistogram/interface/HTuple.h
5     *
6     * Description:
7     * Analysis code of the CMS experiment;
8     * Original version is a part of HAF package developed for CMS: UserCode/HAF
9     * Nested class hierarchy to hold information about HTuple columns.
10     *
11     * Root implementation of a Tuple.
12     *
13     * The member function "Column" provides the data for a Column of the ntuple.
14     * The string is the label of the Column as well as being a unique identifier
15     * of the Column. The second argument provides the data (Float_t or int) for
16     * one row in the Column. Note that only one line of code is needed to
17     * define the Column (if it has not been seen previously) and provide the
18     * data for each "event".
19     *
20     * The third argument of "Column()" provides the default value for that
21     * Column (if it not provided, it defaults to 0.0). On a particular "event",
22     * if no call is made to "Column" for a particular Column, that Column's
23     * default value is used when filling the ntuple. Therefore, the default
24     * value should be set to an "unphysical" number.
25     *
26     * At the end of an "event", a call should be made to either "dumpData()" or
27     * "clearData()". "dumpData()" dumps all the data it has stored internally
28     * into the ntuple and then calls "clearData()".
29     * "clearData()" sets all the internal Column values to their defaults,
30     * without changing the ntuple. Therefore, if you want to keep the data
31     * that is presently in an NTuple, call "dumpData()"; else, call
32     * "clearData()".
33     *
34     *
35     * \author Marcel Kunze, Ruhr-University Bochum, Germany
36     * \author Serguei Ganjour, CEA-Saclay/IRFU, FR
37     *
38     * \version $Id: HTuple.h,v 1.4 2010/03/05 10:24:31 musella Exp $
39     *
40     */
41    
42     #include <iostream>
43     #include "UserCode/HafHistogram/interface/HColumn.h"
44     #include "THashList.h"
45    
46     class TTree;
47     class TBranch;
48    
49     class HTuple : public TNamed {
50    
51     public:
52    
53     HTuple();
54    
55     // Constructor to create a ROOT tuple with name and title:
56     HTuple(const char*, const char*);
57    
58     // Destructor:
59     virtual ~HTuple();
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 HTAbsValVector<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 HTAbsValVector<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,
95     const HTRange<Int_t>& range = HTRange<Int_t>());
96     // Make/fill Column-array. Length is fixed at creation time.
97     virtual void Column(const char* label,
98     const HTAbsValVector<Int_t> &vector,
99     Int_t defval = 0,
100     const char* block = 0,
101     const HTRange<Int_t>& range = HTRange<Int_t>());
102     // Make/fill Column-array. Length is variable and is taken from
103     // another Column.
104     virtual void Column(const char* label,
105     const HTAbsValVector<Int_t> &vector,
106     const char* ilab,
107     Int_t defval = 0,
108     const char* block = 0,
109     const HTRange<Int_t> &range = HTRange<Int_t>());
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,
118     const HTRange<Float_t> &range = HTRange<Float_t>());
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,
124     const HTRange<Float_t> &range = HTRange<Float_t>());
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,
132     const HTRange<Float_t> &range = HTRange<Float_t>());
133     // Make/fill Column-array. Length is fixed at creation time.
134     virtual void Column(const char* label,
135     const HTAbsValVector<Float_t> &vector,
136     Float_t defval = 0.0f,
137     const char* block = 0,
138     const HTRange<Float_t> &range = HTRange<Float_t>());
139     // Make/fill Column-array. Length is variable and is taken from
140     // another Column.
141     virtual void Column(const char* label,
142     const HTAbsValVector<Float_t> &vector,
143     const char* ilab,
144     Float_t defval = 0.0f,
145     const char* block = 0,
146     const HTRange<Float_t> &range = HTRange<Float_t>());
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,
155     const HTRange<Double_t> &range = HTRange<Double_t>());
156     // Make/fill Column-array. Length is fixed at creation time.
157     virtual void Column(const char *label,
158     const HTAbsValVector<Double_t> &vector,
159     Double_t defval = 0.0,
160     const char* block = 0,
161     const HTRange<Double_t> &range = HTRange<Double_t>());
162     // Make/fill Column-array. Length is variable and is taken from
163     // another Column.
164     virtual void Column(const char* label,
165     const HTAbsValVector<Double_t> &vector,
166     const char* ilab,
167     Double_t defval = 0.0,
168     const char* block = 0,
169     const HTRange<Double_t> &range = HTRange<Double_t>());
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     // ====== Generic Object ======
182     // Make/fill Column with a single value
183     template <class T>
184     void ObjColumn(const char* label,
185     T & value,
186     T & defval,
187     const char* block=0)
188     {
189     HColumn* colp = (HColumn*) fMap->FindObject(label);
190     if(colp) {
191     // Column exists,fill corresponding memory location with value:
192     colp->SetValue(&value);
193     colp->SetUseDefValue(0);
194     }
195     else {
196     // Create a new Column:
197     colp = new ClassColumn<T>(label,value,defval,fTree);
198     fMap->Add(colp);
199     }
200     }
201     // Make/fill Column-array
202     template <class T>
203     void ClnColumn(const char* label,
204     const HTAbsValVector<T> &v,
205     const char* ilab,
206     T & defval,
207     const char* block=0)
208     {
209     HColumn* colp = (HColumn*) fMap->FindObject(label);
210     if(colp) {
211     // Column exists,fill corresponding memory location with value:
212     colp->SetValue(&v,(HColumn*)fMap->FindObject(ilab));
213     colp->SetUseDefValue(kFALSE);
214     }
215     else {
216     // Create a new Column:
217     colp = new ClonesColumn<T>(label,v,defval,(HColumn*)fMap->FindObject(ilab),fTree);
218     fMap->Add(colp);
219     }
220     }
221    
222     void Column(const char* label, TVector3 value, TVector3 defval=TVector3(0,0,0), const char* block=0)
223     { ObjColumn( label, value, defval, block); }
224     void Column(const char* label, const HTAbsValVector<TVector3> &v, const char* ilab, TVector3 defval=TVector3(0,0,0), const char* block=0)
225     { ClnColumn( label, v, ilab, defval, block); }
226     void Column(const char* label, TLorentzVector value, TLorentzVector defval=TLorentzVector(0,0,0), const char* block=0)
227     { ObjColumn( label, value, defval, block); }
228     void Column(const char* label, const HTAbsValVector<TLorentzVector> &v, const char* ilab, TLorentzVector defval=TLorentzVector(0,0,0),
229     const char* block=0)
230     { ClnColumn( label, v, ilab, defval, block); }
231    
232     // Dump all the data into the ntuple and then clear:
233     void DumpData();
234    
235     // Set all the data to their default values:
236     void ClearData();
237    
238     // Return the title of the ntuple:
239     const char* Title() const;
240    
241     // Number of Columns:
242     Int_t NColumns() const ;
243    
244     // Label for a particular Column
245     const char* Label(Int_t) const ;
246    
247     // Print info about ntuple:
248     virtual void PrintOn(ostream &) const;
249    
250     HTuple& operator=(const HTuple &v) { return *this; }
251    
252     private:
253    
254     // Data members of HTuple:
255     THashList* fMap; //!Do not stream
256     TTree* fTree; //!Do not stream
257     public:
258     ClassDef(HTuple,1) // NTuple
259     };
260    
261    
262    
263     #endif