ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/CmsHi/HafHistogram/src/HTuple.cc
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
Error occurred while calculating annotation data.
Log Message:
HafHistogram tool

File Contents

# Content
1
2 /** \class HTuple Ganzhur/HafHistogram/src/HTuple.cc
3 *
4 * Description:
5 * Analysis code of the CMS experiment;
6 * Original version is a part of HAF package developed for CMS: UserCode/HAF
7 * Nested class hierarchy to hold information about HTuple columns
8 *
9 * \author Marcel Kunze, Ruhr-University Bochum, Germany
10 * \author Serguei Ganjour, CEA-Saclay/IRFU, FR
11 *
12 * \version $Id: HTuple.cc,v 1.3 2009/11/19 09:40:31 ganzhur Exp $
13 *
14 */
15
16 #include "TTree.h"
17 #include "TBranch.h"
18 #include "TString.h"
19
20 #include "UserCode/HafHistogram/interface/HTuple.h"
21
22 using namespace std;
23
24 ClassImp(HTuple)
25
26 HTuple::HTuple()
27 {
28 fMap = new THashList();
29 }
30
31 // Constructor to create a tuple with name and title:
32 HTuple::HTuple(const char* name,const char* title) :
33 TNamed(name,title)
34 {
35 fMap = new THashList();
36 fTree = new TTree(name,title);
37 }
38
39 // Destructor:
40 HTuple::~HTuple()
41 {
42 delete fTree;
43 delete fMap;
44 }
45
46 // Column booking/filling. All these have the same name - Column(...)
47
48 // Specify the data for a Column. The string is to the key to
49 // the Column,so it must be unique.
50
51
52 // ===== = Bool type ======
53 // Make/fill Column with a single value
54 void HTuple::Column(const char* label,
55 Bool_t value,
56 Bool_t defval,
57 const char* block)
58 {
59 HColumn* colp = (HColumn*) fMap->FindObject(label);
60 if(colp) {
61 // Column exists,fill corresponding memory location with value:
62 colp->SetValue(&value);
63 colp->SetUseDefValue(0);
64 }
65 else {
66 // Create a new Column:
67 colp = new BoolColumn(label,value,defval,fTree);
68 fMap->Add(colp);
69 }
70
71 }
72
73 // Make/fill Column-array. Length is fixed at creation time.
74 void HTuple::Column(const char* label,
75 const HTAbsValVector<Bool_t> &vector,
76 Bool_t defval,
77 const char* block)
78 {
79 HColumn* colp = (HColumn*) fMap->FindObject(label);
80 if(colp) {
81 // Column exists,fill corresponding memory location with value:
82 colp->SetValue(&vector);
83 colp->SetUseDefValue(kFALSE);
84 }
85 else {
86 // Create a new Column:
87 colp = new BoolArrColumn(label,vector,defval,fTree);
88 fMap->Add(colp);
89 }
90
91 }
92
93 // Make/fill Column-array. Length is variable and is taken from
94 // another Column.
95 void HTuple::Column(const char* label,
96 const HTAbsValVector<Bool_t> &vector,
97 const char* ilab,
98 Bool_t defval,
99 const char* block)
100 {
101 HColumn* colp = (HColumn*) fMap->FindObject(label);
102 if(colp) {
103 // Column exists,fill corresponding memory location with value:
104 colp->SetValue(&vector,(HColumn*)fMap->FindObject(ilab));
105 colp->SetUseDefValue(kFALSE);
106 }
107 else {
108 // Create a new branch:
109 HColumn* indexPtr = (HColumn*) fMap->FindObject(ilab);
110 colp = new BoolDynArrColumn(label,vector,defval,indexPtr,fTree);
111 fMap->Add(colp);
112 }
113
114 }
115
116
117 // ===== = Int type ======
118 // Make/fill Column with a single value
119 void HTuple::Column(const char* label,
120 Int_t value,
121 Int_t defval,
122 const char* block,
123 const HTRange<Int_t> &range)
124 {
125 HColumn* colp = (HColumn*) fMap->FindObject(label);
126 if(colp) {
127 // Column exists,fill corresponding memory location with value:
128 colp->SetValue(&value);
129 colp->SetUseDefValue(0);
130 }
131 else {
132 // Create a new Column:
133 colp = new IntColumn(label,value,defval,fTree);
134 fMap->Add(colp);
135 }
136
137 }
138
139 // Make/fill Column-array. Length is fixed at creation time.
140 void HTuple::Column(const char* label,
141 const HTAbsValVector<Int_t> &vector,
142 Int_t defval,
143 const char* block,
144 const HTRange<Int_t> &range)
145 {
146 HColumn* colp = (HColumn*) fMap->FindObject(label);
147 if(colp) {
148 // Column exists,fill corresponding memory location with value:
149 colp->SetValue(&vector);
150 colp->SetUseDefValue(kFALSE);
151 }
152 else {
153 // Create a new Column:
154 colp = new IntArrColumn(label,vector,defval,fTree);
155 fMap->Add(colp);
156 }
157
158 }
159
160 // Make/fill Column-array. Length is variable and is taken from
161 // another Column.
162 void HTuple::Column(const char* label,
163 const HTAbsValVector<Int_t> &vector,
164 const char* ilab,
165 Int_t defval,
166 const char* block,
167 const HTRange<Int_t> &range)
168 {
169 HColumn* colp = (HColumn*) fMap->FindObject(label);
170 if(colp) {
171 // Column exists,fill corresponding memory location with value:
172 colp->SetValue(&vector,(HColumn*)fMap->FindObject(ilab));
173 colp->SetUseDefValue(kFALSE);
174 }
175 else {
176 // Create a new branch:
177 HColumn* indexPtr = (HColumn*) fMap->FindObject(ilab);
178 colp = new IntDynArrColumn(label,vector,defval,indexPtr,fTree);
179 fMap->Add(colp);
180 }
181
182 }
183
184
185 // ===== = Float type ======
186 // Make/fill Column with a single value
187 void HTuple::Column(const char* label,
188 Float_t value,
189 Float_t defval,
190 const char* block,
191 const HTRange<Float_t> &range)
192 {
193 HColumn* colp = (HColumn*) fMap->FindObject(label);
194 if(colp) {
195 // Column exists,fill corresponding memory location with value:
196 colp->SetValue(&value);
197 colp->SetUseDefValue(0);
198 }
199 else {
200 // Create a new Column:
201 colp = new FloatColumn(label,value,defval,fTree);
202 fMap->Add(colp);
203 }
204
205
206 }
207
208 // Make/fill Column-array. Length is fixed at creation time.
209 void HTuple::Column(const char* label,
210 const TVector &vector,
211 Float_t defval,
212 const char* block,
213 const HTRange<Float_t> &range)
214 {
215 HColumn* colp = (HColumn*) fMap->FindObject(label);
216 if(colp) {
217 // Column exists,fill corresponding memory location with value:
218 colp->SetValue(&vector);
219 colp->SetUseDefValue(0);
220 }
221 else {
222 // Create a new Column:
223 colp = new FloatArrColumn(label,vector,defval,fTree);
224 fMap->Add(colp);
225 }
226
227
228 }
229
230 // Make/fill Column-array. Length is variable and is taken from
231 // another Column.
232 void HTuple::Column(const char* label,
233 const TVector &vector,
234 const char *ilab,
235 Float_t defval,
236 const char* block,
237 const HTRange<Float_t> &range)
238 {
239 HColumn* colp = (HColumn*) fMap->FindObject(label);
240 if(colp) {
241 // Column exists,fill corresponding memory location with value:
242 colp->SetValue(&vector,(HColumn*)fMap->FindObject(ilab));
243 colp->SetUseDefValue(0);
244 }
245 else {
246 // Create a new branch:
247 HColumn* indexPtr = (HColumn*) fMap->FindObject(ilab);
248 colp = new FloatDynArrColumn(label,vector,defval,indexPtr,fTree);
249 fMap->Add(colp);
250 }
251
252 }
253
254 // Make/fill Column-array. Length is fixed at creation time.
255 void HTuple::Column(const char* label,
256 const HTAbsValVector<Float_t> &vector,
257 Float_t defval,
258 const char* block,
259 const HTRange<Float_t> &range)
260 {
261 HColumn* colp = (HColumn*) fMap->FindObject(label);
262 if(colp) {
263 // Column exists,fill corresponding memory location with value:
264 colp->SetValue(&vector);
265 colp->SetUseDefValue(kFALSE);
266 }
267 else {
268 // Create a new Column:
269 colp = new FloatArrColumn(label,vector,defval,fTree);
270 fMap->Add(colp);
271 }
272
273
274 }
275
276 // Make/fill Column-array. Length is variable and is taken from
277 // another Column.
278 void HTuple::Column(const char* label,
279 const HTAbsValVector<Float_t> &vector,
280 const char *ilab,
281 Float_t defval,
282 const char* block,
283 const HTRange<Float_t> &range)
284 {
285 HColumn* colp = (HColumn*) fMap->FindObject(label);
286 if(colp) {
287 // Column exists,fill corresponding memory location with value:
288 colp->SetValue(&vector,(HColumn*)fMap->FindObject(ilab));
289 colp->SetUseDefValue(kFALSE);
290 }
291 else {
292 // Create a new branch:
293 HColumn* indexPtr = (HColumn*) fMap->FindObject(ilab);
294 colp = new FloatDynArrColumn(label,vector,defval,indexPtr,fTree);
295 fMap->Add(colp);
296 }
297
298 }
299
300 // ===== = Double type ======
301 // Make/fill Column with a single value
302 void HTuple::Column(const char* label,
303 Double_t value,
304 Double_t defval,
305 const char* block,
306 const HTRange<Double_t> &range)
307 {
308 HColumn* colp = (HColumn*) fMap->FindObject(label);
309 if(colp) {
310 // Column exists,fill corresponding memory location with value:
311 colp->SetValue(&value);
312 colp->SetUseDefValue(0);
313 }
314 else {
315 // Create a new Column:
316 colp = new DoubleColumn(label,value,defval,fTree);
317 fMap->Add(colp);
318 }
319
320
321 }
322
323 // Make/fill Column-array. Length is fixed at creation time.
324 void HTuple::Column(const char* label,
325 const HTAbsValVector<Double_t> &vector,
326 Double_t defval,
327 const char* block,
328 const HTRange<Double_t> &range)
329 {
330 HColumn* colp = (HColumn*) fMap->FindObject(label);
331 if(colp) {
332 // Column exists,fill corresponding memory location with value:
333 colp->SetValue(&vector);
334 colp->SetUseDefValue(kFALSE);
335 }
336 else {
337 // Create a new Column:
338 colp = new DoubleArrColumn(label,vector,defval,fTree);
339 fMap->Add(colp);
340 }
341
342
343 }
344
345 // Make/fill Column-array. Length is variable and is taken from
346 // another Column.
347 void HTuple::Column(const char* label,
348 const HTAbsValVector<Double_t> &vector,
349 const char *ilab,
350 Double_t defval,
351 const char* block,
352 const HTRange<Double_t> &range)
353 {
354 HColumn* colp = (HColumn*) fMap->FindObject(label);
355 if(colp) {
356 // Column exists,fill corresponding memory location with value:
357 colp->SetValue(&vector,(HColumn*)fMap->FindObject(ilab));
358 colp->SetUseDefValue(kFALSE);
359 }
360 else {
361 // Create a new branch:
362 HColumn* indexPtr = (HColumn*) fMap->FindObject(ilab);
363 colp = new DoubleDynArrColumn(label,vector,defval,indexPtr,fTree);
364 fMap->Add(colp);
365 }
366
367 }
368
369 // ===== = string Columns ======
370 // Can actually be variable length in ROOT,N is ignored:
371 void HTuple::Column(const char* label,
372 const char* value,
373 Int_t N,
374 const char* defval,
375 const char* block)
376 {
377 HColumn* colp = (HColumn*) fMap->FindObject(label);
378 if(colp) {
379 // Branch exists,fill corresponding memory location with value:
380 Column(label,value);
381 }
382 else {
383 // Create a new branch:
384 colp = new StringColumn(label,value,defval,fTree);
385 fMap->Add(colp);
386 }
387
388 }
389
390 void HTuple::Column(const char* label,const char* value)
391 {
392 HColumn* colp = (HColumn*) fMap->FindObject(label);
393 if(colp) {
394 colp->SetValue(value);
395 colp->SetUseDefValue(0);
396 }
397 else {
398 cerr << "HTuple::Column: Column "<< label << " does not exist" << endl;
399 }
400
401 }
402
403
404 // Dump all the data into the ntuple and then clear
405 void HTuple::DumpData()
406 {
407 for (Int_t i=0;i<fMap->GetSize();i++)
408 {
409 HColumn *col = (HColumn*) fMap->At(i);
410 if(col->GetUseDefValue()) col->SetDefValue();
411 col->SetUseDefValue(1);
412 }
413 fTree->Fill();
414
415 }
416
417 // Set all the data to their default values:
418 void HTuple::ClearData()
419 {
420 for (Int_t i=0;i<fMap->GetSize();i++)
421 {
422 HColumn *col = (HColumn*) fMap->At(i);
423 col->SetDefValue();
424 col->SetUseDefValue(1);
425 }
426 return;
427
428 }
429
430 // Return title of ntuple:
431 const char* HTuple::Title() const
432 {
433 return fTree->GetTitle();
434 }
435
436 // number of Columns
437 Int_t HTuple::NColumns() const
438 {
439 return fMap->GetSize();
440 }
441
442 // Return label for a particular Column with index i:
443 const char* HTuple::Label(Int_t i) const
444 {
445 TString str;
446 if(i >= 0 && i < fMap->GetSize()) str = ((HColumn*)fMap->At(i))->GetLabel();
447 else str = "unknown Column index";
448 return str.Data();
449
450 }
451
452 // Print info about ntuple:
453 void HTuple::PrintOn(ostream & o) const
454 {
455 cout << "HTuple: ntuple " << Title() << " has " << NColumns()
456 << " Columns." << endl;
457 cout << "Complete printout follows: " << endl;
458 fTree->Print();
459 }