]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWGJE/EMCALJetTasks/UserTasks/AliEMCalHistoContainer.cxx
Use pass-aware container
[u/mrichter/AliRoot.git] / PWGJE / EMCALJetTasks / UserTasks / AliEMCalHistoContainer.cxx
CommitLineData
46f589c2 1/**************************************************************************
2 * Copyright(c) 1998-2007, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16/*
17 * Container class for histogram objects. Currenly can handle
18 * TH1
19 * TH2
20 * TH3
21 * THnSparse
22 * Histograms can be stored in groups. For this the parent group is
23 * included inside the histogram name, i.e. /base/inheriting/histogram.
24 * In case just the histogram name is given, it is assumed that the
25 * histogram is stored at the top level.
26 *
27 * Author: Markus Fasel
28 */
29
30#include <cstring>
31#include <vector>
32#include <TArrayD.h>
33#include <TAxis.h>
34#include <TH1.h>
35#include <TH2.h>
36#include <TH3.h>
37#include <THnSparse.h>
38#include <THashList.h>
39#include <TObjArray.h>
40#include <TObjString.h>
41#include <TString.h>
42
43#include "AliLog.h"
44
45#include "AliEMCalHistoContainer.h"
46
47ClassImp(EMCalTriggerPtAnalysis::AliEMCalHistoContainer)
48
49namespace EMCalTriggerPtAnalysis {
50
51 //______________________________________________________________________________
52 AliEMCalHistoContainer::AliEMCalHistoContainer():
53 TNamed(),
54 fHistos(NULL),
55 fIsOwner(true)
56 {
57 /*
58 * Default constructor, only initialising pointers with 0
59 */
60 }
61
62 //______________________________________________________________________________
63 AliEMCalHistoContainer::AliEMCalHistoContainer(const char *name):
64 TNamed(name, Form("Histogram container %s", name)),
65 fHistos(NULL),
66 fIsOwner(true)
67 {
68 /*
69 * Main constructor, creating also a list for the histograms
70 *
71 * @param name: Name of the object (list named accordingly)
72 */
73 fHistos = new THashList();
74 fHistos->SetName(Form("histos%s", name));
75 fHistos->SetOwner();
76 }
77
78 //______________________________________________________________________________
79 AliEMCalHistoContainer::~AliEMCalHistoContainer(){
80 /*
81 * Destructor, deletes the list of histograms if it is the owner
82 */
83 if(fHistos && fIsOwner) delete fHistos;
84 }
85
86 //______________________________________________________________________________
87 void AliEMCalHistoContainer::CreateHistoGroup(const char *groupname, const char *parent) throw(HistoContainerContentException) {
88 /*
89 * Create a new group of histograms within a parent group. Groups are represented as list. The default parent is
90 * always the top list. List name structure accouding to unix paths (i.e. top list /, hirarchies separated by /).
91 *
92 * @param groupname: Name of the new group
93 * @param parent (@default "/"): Name of the parent group
94 * @throw HistoContainerContentException
95 */
96 THashList *parentgroup = FindGroup(parent);
97 if(!parentgroup) throw HistoContainerContentException(NULL, parent, HistoContainerContentException::kGroupException);
98 THashList *childgroup = new THashList();
99 childgroup->SetName(groupname);
100 parentgroup->Add(childgroup);
101 }
102
103 //______________________________________________________________________________
104 void AliEMCalHistoContainer::CreateTH1(const char *name, const char *title, int nbins, double xmin, double xmax) throw(HistoContainerContentException){
105 /*
106 * Create a new TH1 within the container. The histogram name also contains the parent group(s) according to the common
107 * group notation.
108 *
109 * @param name: Name of the histogram
110 * @param title: Title of the histogram
111 * @param nbins: number of bins
112 * @param xmin: min. value of the range
113 * @param xmax: max. value of the range
114 * @throw HistoContainerContentException
115 */
116 TString dirname(basename(name)), hname(histname(name));
117 THashList *parent(FindGroup(dirname.Data()));
118 if(!parent)
119 throw HistoContainerContentException(NULL, dirname.Data(), HistoContainerContentException::kGroupException);
120 if(parent->FindObject(hname.Data()))
121 throw HistoContainerContentException(hname.Data(), dirname.Data(), HistoContainerContentException::kHistDuplicationException);
122 parent->Add(new TH1D(hname.Data(), title, nbins, xmin, xmax));
123 }
124
125 //______________________________________________________________________________
126 void AliEMCalHistoContainer::CreateTH1(const char *name, const char *title, int nbins, const double *xbins) throw(HistoContainerContentException){
127 /*
128 * Create a new TH1 within the container. The histogram name also contains the parent group(s) according to the common
129 * group notation.
130 *
131 * @param name: Name of the histogram
132 * @param title: Title of the histogram
133 * @param nbins: number of bins
134 * @param xbins: array of bin limits
135 * @throw HistoContainerContentException
136 */
137 TString dirname(basename(name)), hname(histname(name));
138 THashList *parent(FindGroup(dirname));
139 if(!parent)
140 throw HistoContainerContentException(NULL, dirname.Data(), HistoContainerContentException::kGroupException);
141 if(parent->FindObject(hname.Data()))
142 throw HistoContainerContentException(hname, dirname.Data(), HistoContainerContentException::kHistDuplicationException);
143 parent->Add(new TH1D(hname.Data(), title, nbins, xbins));
144 }
145
146 //______________________________________________________________________________
147 void AliEMCalHistoContainer::CreateTH1(const char *name, const char *title, const TArrayD &xbins) throw(HistoContainerContentException){
148 /*
149 * Create a new TH1 within the container. The histogram name also contains the parent group(s) according to the common
150 * group notation.
151 *
152 * @param name: Name of the histogram
153 * @param title: Title of the histogram
154 * @param xbins: array of bin limits (contains also number of bins)
155 * @throw HistoContainerContentException
156 */
157 TString dirname(basename(name)), hname(histname(name));
158 THashList *parent(FindGroup(dirname));
159 if(!parent)
160 throw HistoContainerContentException(NULL, dirname.Data(), HistoContainerContentException::kGroupException);
161 if(parent->FindObject(hname.Data()))
162 throw HistoContainerContentException(hname.Data(), dirname.Data(), HistoContainerContentException::kHistDuplicationException);
163 parent->Add(new TH1D(hname.Data(), title, xbins.GetSize()-1, xbins.GetArray()));
164 }
165
166 //______________________________________________________________________________
167 void AliEMCalHistoContainer::CreateTH2(const char *name, const char *title,
168 int nbinsx, double xmin, double xmax, int nbinsy, double ymin, double ymax) throw(HistoContainerContentException){
169 /*
170 * Create a new TH2 within the container. The histogram name also contains the parent group(s) according to the common
171 * group notation.
172 *
173 * @param name: Name of the histogram
174 * @param title: Title of the histogram
175 * @param nbinsx: number of bins in x-direction
176 * @param xmin: min. value of the range in x-direction
177 * @param xmax: max. value of the range in x-direction
178 * @param nbinsy: number of bins in y-direction
179 * @param ymin: min. value of the range in y-direction
180 * @param ymax: max. value of the range in y-direction
181 * @throw HistoContainerContentException
182 */
183 TString dirname(basename(name)), hname(histname(name));
184 THashList *parent(FindGroup(dirname.Data()));
185 if(!parent)
186 throw HistoContainerContentException(NULL, dirname.Data(), HistoContainerContentException::kGroupException);
187 if(parent->FindObject(hname.Data()))
188 throw HistoContainerContentException(hname.Data(), dirname.Data(), HistoContainerContentException::kHistDuplicationException);
189 parent->Add(new TH2D(hname.Data(), title, nbinsx, xmin, xmax, nbinsy, ymin, ymax));
190 }
191
192 //______________________________________________________________________________
193 void AliEMCalHistoContainer::CreateTH2(const char *name, const char *title,
194 int nbinsx, const double *xbins, int nbinsy, const double *ybins) throw(HistoContainerContentException){
195 /*
196 * Create a new TH2 within the container. The histogram name also contains the parent group(s) according to the common
197 * group notation.
198 *
199 * @param name: Name of the histogram
200 * @param title: Title of the histogram
201 * @param nbinsx: number of bins in x-direction
202 * @param xbins: array of bin limits in x-direction
203 * @param nbinsy: number of bins in y-direction
204 * @param ybins: array of bin limits in y-direction
205 * @throw HistoContainerContentException
206 */
207 TString dirname(basename(name)), hname(histname(name));
208 THashList *parent(FindGroup(dirname.Data()));
209 if(!parent)
210 throw HistoContainerContentException(NULL, dirname.Data(), HistoContainerContentException::kGroupException);
211 if(parent->FindObject(hname.Data()))
212 throw HistoContainerContentException(hname.Data(), dirname.Data(), HistoContainerContentException::kHistDuplicationException);
213 parent->Add(new TH2D(hname.Data(), title, nbinsx, xbins, nbinsy, ybins));
214 }
215
216 //______________________________________________________________________________
217 void AliEMCalHistoContainer::CreateTH2(const char *name, const char *title, const TArrayD &xbins, const TArrayD &ybins) throw(HistoContainerContentException){
218 /*
219 * Create a new TH2 within the container. The histogram name also contains the parent group(s) according to the common
220 * group notation.
221 *
222 * @param name: Name of the histogram
223 * @param title: Title of the histogram
224 * @param xbins: array of bin limits in x-direction (contains also the number of bins)
225 * @param ybins: array of bin limits in y-direction (contains also the number of bins)
226 * @throw HistoContainerContentException
227 */
228 TString dirname(basename(name)), hname(histname(name));
229 THashList *parent(FindGroup(dirname.Data()));
230 if(!parent)
231 throw HistoContainerContentException(NULL, dirname.Data(), HistoContainerContentException::kGroupException);
232 if(parent->FindObject(hname.Data()))
233 throw HistoContainerContentException(hname.Data(), dirname.Data(), HistoContainerContentException::kHistDuplicationException);
234 parent->Add(new TH2D(hname.Data(), title, xbins.GetSize() - 1, xbins.GetArray(), ybins.GetSize() - 1, ybins.GetArray()));
235 }
236
237 //______________________________________________________________________________
238 void AliEMCalHistoContainer::CreateTH3(const char* name, const char* title, int nbinsx, double xmin, double xmax,
239 int nbinsy, double ymin, double ymax, int nbinsz, double zmin, double zmax) throw (HistoContainerContentException) {
240 /*
241 * Create a new TH3 within the container. The histogram name also contains the parent group(s) according to the common
242 * group notation.
243 *
244 * @param nbinsx: number of bins in x-direction
245 * @param xmin: min. value of the range in x-direction
246 * @param xmax: max. value of the range in x-direction
247 * @param nbinsy: number of bins in y-direction
248 * @param ymin: min. value of the range in y-direction
249 * @param ymax: max. value of the range in y-direction
250 * @param nbinsz: number of bins in z-direction
251 * @param zmin: min. value of the range in z-direction
252 * @param zmax: max. value of the range in z-direction
253 * @throw HistoContainerContentException
254 */
255 TString dirname(basename(name)), hname(histname(name));
256 THashList *parent(FindGroup(dirname.Data()));
257 if(!parent)
258 throw HistoContainerContentException(NULL, dirname.Data(), HistoContainerContentException::kGroupException);
259 if(parent->FindObject(hname.Data()))
260 throw HistoContainerContentException(hname.Data(), dirname.Data(), HistoContainerContentException::kHistDuplicationException);
261 parent->Add(new TH3D(hname.Data(), title, nbinsx, xmin, xmax, nbinsy, ymin, ymax, nbinsz, zmin, zmax));
262 }
263
264 //______________________________________________________________________________
265 void AliEMCalHistoContainer::CreateTH3(const char* name, const char* title, int nbinsx, const double* xbins,
266 int nbinsy, const double* ybins, int nbinsz, const double* zbins) throw (HistoContainerContentException) {
267 /*
268 * Create a new TH3 within the container. The histogram name also contains the parent group(s) according to the common
269 * group notation.
270 *
271 * @param name: Name of the histogram
272 * @param title: Title of the histogram
273 * @param nbinsx: number of bins in x-direction
274 * @param xbins: array of bin limits in x-direction
275 * @param nbinsy: number of bins in y-direction
276 * @param ybins: array of bin limits in y-direction
277 * @param nbinsz: number of bins in z-direction
278 * @param zbins: array of bin limits in z-direction
279 * @throw HistoContainerContentException
280 */
281 TString dirname(basename(name)), hname(histname(name));
282 THashList *parent(FindGroup(dirname.Data()));
283 if(!parent)
284 throw HistoContainerContentException(NULL, dirname.Data(), HistoContainerContentException::kGroupException);
285 if(parent->FindObject(hname.Data()))
286 throw HistoContainerContentException(hname.Data(), dirname.Data(), HistoContainerContentException::kHistDuplicationException);
287 parent->Add(new TH3D(hname.Data(), title, nbinsx, xbins, nbinsy, ybins, nbinsz, zbins));
288 }
289
290 //______________________________________________________________________________
291 void AliEMCalHistoContainer::CreateTH3(const char* name, const char* title, const TArrayD& xbins, const TArrayD& ybins,
292 const TArrayD& zbins) throw (HistoContainerContentException) {
293 /*
294 * Create a new TH3 within the container. The histogram name also contains the parent group(s) according to the common
295 * group notation.
296 *
297 * @param name: Name of the histogram
298 * @param title: Title of the histogram
299 * @param xbins: array of bin limits in x-direction (contains also the number of bins)
300 * @param ybins: array of bin limits in y-direction (contains also the number of bins)
301 * @param zbins: array of bin limits in z-direction (contains also the number of bins)
302 * @throw HistoContainerContentException
303 */
304 TString dirname(basename(name)), hname(histname(name));
305 THashList *parent(FindGroup(dirname.Data()));
306 if(!parent)
307 throw HistoContainerContentException(NULL, dirname.Data(), HistoContainerContentException::kGroupException);
308 if(parent->FindObject(hname.Data()))
309 throw HistoContainerContentException(hname.Data(), dirname.Data(), HistoContainerContentException::kHistDuplicationException);
310 parent->Add(new TH3D(hname.Data(), title, xbins.GetSize()-1, xbins.GetArray(), ybins.GetSize()-1, ybins.GetArray(), zbins.GetSize()-1, zbins.GetArray()));
311 }
312
313 //______________________________________________________________________________
314 void AliEMCalHistoContainer::CreateTHnSparse(const char *name, const char *title,
315 int ndim, const int *nbins, const double *min, const double *max) throw(HistoContainerContentException){
316 /*
317 * Create a new THnSparse within the container. The histogram name also contains the parent group(s) according to the common
318 * group notation.
319 *
320 * @param name: Name of the histogram
321 * @param title: Title of the histogram
322 * @param ndim: Number of dimensions
323 * @param nbins: Number of bins per dimension
324 * @param min: min. value of the range for each dimension
325 * @param max: max. value of the range for each dimension
326 * @throw HistoContainerContentException
327 */
328 TString dirname(basename(name)), hname(histname(name));
329 THashList *parent(FindGroup(dirname.Data()));
330 if(!parent)
331 throw HistoContainerContentException(NULL, dirname.Data(), HistoContainerContentException::kGroupException);
332 if(parent->FindObject(hname.Data()))
333 throw HistoContainerContentException(hname.Data(), dirname.Data(), HistoContainerContentException::kHistDuplicationException);
334 parent->Add(new THnSparseD(hname.Data(), title, ndim, nbins, min, max));
335 }
336
337 //______________________________________________________________________________
338 void AliEMCalHistoContainer::CreateTHnSparse(const char *name, const char *title, int ndim, const TAxis **axes) throw(HistoContainerContentException){
339 /*
340 * Create a new THnSparse within the container. The histogram name also contains the parent group(s) according to the common
341 * group notation.
342 *
343 * @param name: Name of the histogram
344 * @param title: Title of the histogram
345 * @param ndim: Number of dimensions
346 * @param axes: Array of pointers to TAxis for containing the axis definition for each dimension
347 * @throw HistoContainerContentException
348 */
349 TString dirname(basename(name)), hname(histname(name));
350 THashList *parent(FindGroup(dirname.Data()));
351 if(!parent)
352 throw HistoContainerContentException(NULL, dirname.Data(), HistoContainerContentException::kGroupException);
353 if(parent->FindObject(hname))
354 throw HistoContainerContentException(hname.Data(), dirname.Data(), HistoContainerContentException::kHistDuplicationException);
355 TArrayD xmin(ndim), xmax(ndim);
356 TArrayI nbins(ndim);
357 for(int idim = 0; idim < ndim; ++idim){
358 const TAxis &myaxis = *(axes[idim]);
359 nbins[idim] = myaxis.GetNbins();
360 xmin[idim] = myaxis.GetXmin();
361 xmax[idim] = myaxis.GetXmax();
362 }
363 THnSparseD *hsparse = new THnSparseD(hname.Data(), title, ndim, nbins.GetArray(), xmin.GetArray(), xmax.GetArray());
364 for(int id = 0; id < ndim; ++id)
365 *(hsparse->GetAxis(id)) = *(axes[id]);
366 parent->Add(hsparse);
367 }
368
369 //______________________________________________________________________________
370 void AliEMCalHistoContainer::SetObject(TObject * const o, const char *group) throw(HistoContainerContentException){
371 /*
372 * Set a new group into the container into the parent group
373 *
374 * @param o: the object ot be included
375
376 */
377 THashList *parent(FindGroup(group));
378 if(!parent)
379 throw HistoContainerContentException(NULL, strcmp(group, "/") ? group : "", HistoContainerContentException::kGroupException);
380 if(parent->FindObject(o->GetName()))
381 throw HistoContainerContentException(o->GetName(), strcmp(group, "/") ? group : "", HistoContainerContentException::kHistDuplicationException);
382 if(!(dynamic_cast<THnBase *>(o) || dynamic_cast<TH1 *>(o)))
383 throw HistoContainerContentException(o->GetName(), strcmp(group, "/") ? group : "", HistoContainerContentException::kTypeException);
384 fHistos->Add(o);
385 }
386
387 //______________________________________________________________________________
388 void AliEMCalHistoContainer::FillTH1(const char *name, double x, double weight) throw(HistoContainerContentException){
389 /*
390 * Fill a 1D histogram within the container. The histogram name also contains the parent group(s) according to the common
391 * group notation.
392 *
393 * @param name: Name of the histogram
394 * @param x: x-coordinate
395 * @param weight (@default 1): optional weight of the entry
396 * @throw HistoContainerContentException
397 */
398 TString dirname(basename(name)), hname(histname(name));
399 THashList *parent(FindGroup(dirname.Data()));
400 if(!parent)
401 throw HistoContainerContentException(NULL, dirname.Data(), HistoContainerContentException::kGroupException);
402 TH1 *hist = dynamic_cast<TH1 *>(parent->FindObject(hname.Data()));
403 if(!hist)
404 throw HistoContainerContentException(hname.Data(), dirname.Data(), HistoContainerContentException::kHistNotFoundException);
405 hist->Fill(x, weight);
406 }
407
408 //______________________________________________________________________________
409 void AliEMCalHistoContainer::FillTH2(const char *name, double x, double y, double weight) throw(HistoContainerContentException){
410 /*
411 * Fill a 2D histogram within the container. The histogram name also contains the parent group(s) according to the common
412 * group notation.
413 *
414 * @param name: Name of the histogram
415 * @param x: x-coordinate
416 * @param y: y-coordinate
417 * @param weight (@default 1): optional weight of the entry
418 * @throw HistoContainerContentException
419 */
420 TString dirname(basename(name)), hname(histname(name));
421 THashList *parent(FindGroup(dirname.Data()));
422 if(!parent)
423 throw HistoContainerContentException(NULL, dirname.Data(), HistoContainerContentException::kGroupException);
424 TH2 *hist = dynamic_cast<TH2 *>(parent->FindObject(hname.Data()));
425 if(!hist)
426 throw HistoContainerContentException(hname.Data(), dirname.Data(), HistoContainerContentException::kHistNotFoundException);
427 hist->Fill(x, y, weight);
428 }
429
430 //______________________________________________________________________________
431 void AliEMCalHistoContainer::FillTH2(const char *name, double *point, double weight) throw(HistoContainerContentException){
432 /*
433 * Fill a 2D histogram within the container. The histogram name also contains the parent group(s) according to the common
434 * group notation.
435 *
436 * @param name: Name of the histogram
437 * @param point: coordinates of the data
438 * @param weight (@default 1): optional weight of the entry
439 * @throw HistoContainerContentException
440 */
441 TString dirname(basename(name)), hname(histname(name));
442 THashList *parent(FindGroup(dirname.Data()));
443 if(!parent)
444 throw HistoContainerContentException(NULL, dirname.Data(), HistoContainerContentException::kGroupException);
445 TH2 *hist = dynamic_cast<TH2 *>(parent->FindObject(hname.Data()));
446 if(!hist)
447 throw HistoContainerContentException(hname.Data(), dirname.Data(), HistoContainerContentException::kHistNotFoundException);
448 hist->Fill(point[0], point[1], weight);
449 }
450
451 //______________________________________________________________________________
452 void AliEMCalHistoContainer::FillTH3(const char* name, double x, double y, double z, double weight) throw (HistoContainerContentException) {
453 /*
454 * Fill a 3D histogram within the container. The histogram name also contains the parent group(s) according to the common
455 * group notation.
456 *
457 * @param name: Name of the histogram
458 * @param x: x-coordinate
459 * @param y: y-coordinate
460 * @param z: z-coordinate
461 * @param weight (@default 1): optional weight of the entry
462 * @throw HistoContainerContentException
463 */
464 TString dirname(basename(name)), hname(histname(name));
465 THashList *parent(FindGroup(dirname.Data()));
466 if(!parent)
467 throw HistoContainerContentException(NULL, dirname.Data(), HistoContainerContentException::kGroupException);
468 TH3 *hist = dynamic_cast<TH3 *>(parent->FindObject(hname.Data()));
469 if(!hist)
470 throw HistoContainerContentException(hname.Data(), dirname.Data(), HistoContainerContentException::kHistNotFoundException);
471 hist->Fill(x, y, z, weight);
472 }
473
474 //______________________________________________________________________________
475 void AliEMCalHistoContainer::FillTH3(const char* name, const double* point, double weight) throw (HistoContainerContentException) {
476 TString dirname(basename(name)), hname(histname(name));
477 THashList *parent(FindGroup(dirname.Data()));
478 if(!parent)
479 throw HistoContainerContentException(NULL, dirname.Data(), HistoContainerContentException::kGroupException);
480 TH3 *hist = dynamic_cast<TH3 *>(parent->FindObject(hname.Data()));
481 if(!hist)
482 throw HistoContainerContentException(hname.Data(), dirname.Data(), HistoContainerContentException::kHistNotFoundException);
483 hist->Fill(point[0], point[1], point[2], weight);
484 }
485
486
487 //______________________________________________________________________________
488 void AliEMCalHistoContainer::FillTHnSparse(const char *name, const double *x, double weight) throw(HistoContainerContentException){
489 /*
490 * Fill a nD histogram within the container. The histogram name also contains the parent group(s) according to the common
491 * group notation.
492 *
493 * @param name: Name of the histogram
494 * @param x: coordinates of the data
495 * @param weight (@default 1): optional weight of the entry
496 * @throw HistoContainerContentException
497 */
498 TString dirname(basename(name)), hname(histname(name));
499 THashList *parent(FindGroup(dirname.Data()));
500 if(!parent)
501 throw HistoContainerContentException(NULL, dirname.Data(), HistoContainerContentException::kGroupException);
502 THnSparseD *hist = dynamic_cast<THnSparseD *>(parent->FindObject(hname.Data()));
503 if(!hist)
504 throw HistoContainerContentException(hname.Data(), dirname.Data(), HistoContainerContentException::kHistNotFoundException);
505 hist->Fill(x, weight);
506 }
507
508 //______________________________________________________________________________
509 TObject *AliEMCalHistoContainer::FindObject(const char *name) const {
510 /*
511 * Find an object inside the container. The object can also be within a
512 * histogram group. For this the name has to follow the common notation
513 *
514 * @param name: Name of the object to find inside the container
515 * @return: pointer to the object (NULL if not found)
516 */
517 TString dirname(basename(name)), hname(histname(name));
518 THashList *parent(FindGroup(dirname.Data()));
519 if(!parent) return NULL;
d64dbcd4 520 return parent->FindObject(hname);
521 }
522
523 //______________________________________________________________________________
524 TObject* AliEMCalHistoContainer::FindObject(const TObject* obj) const {
525 /*
526 * Find and object inside the container. The object name is expected to contain the
527 * full path of the histogram object, including parent groups
528 *
529 * @param obj: the object to find
530 * @return: pointer to the object (NULL if not found)
531 */
532 TString dirname(basename(obj->GetName())), hname(histname(obj->GetName()));
533 THashList *parent(FindGroup(dirname.Data()));
534 if(!parent) return NULL;
535 return parent->FindObject(hname);
46f589c2 536 }
537
538 //______________________________________________________________________________
539 THashList *AliEMCalHistoContainer::FindGroup(const char *dirname) const {
540 /*
541 * Find histogram group. Name is using common notation
542 *
543 * @param dirname: Path of the group (treat empty path as top node
544 * @return: TList of objects (NULL if group does not exist)
545 */
546 if(!strlen(dirname) || !strcmp(dirname, "/")) return fHistos;
547 std::vector<std::string> tokens;
548 TokenizeFilename(dirname, "/", tokens);
549 THashList *currentdir(fHistos);
550 for(std::vector<std::string>::iterator it = tokens.begin(); it != tokens.end(); ++it){
551 currentdir = dynamic_cast<THashList *>(currentdir->FindObject(it->c_str()));
552 if(!currentdir) break;
553 }
554 return currentdir;
555 }
556
557 //______________________________________________________________________________
558 void AliEMCalHistoContainer::TokenizeFilename(const char *name, const char *delim, std::vector<std::string> &listoftokens) const {
559 /*
560 * Tokenizes a string. Results are stored inside the vector listoftokens
561 *
562 * @ param name: string to be tokenised
563 * @ param delim: delimiter string
564 * @ param listoftokens: list of tokens (C++ strings)
565 */
566 TString s(name);
567 TObjArray *arr = s.Tokenize(delim);
568 TObjString *ostr(NULL);
569 TIter toks(arr);
570 while((ostr = dynamic_cast<TObjString *>(toks()))){
571 listoftokens.push_back(std::string(ostr->String().Data()));
572 }
573 delete arr;
574 }
575
576 //______________________________________________________________________________
577 const char *AliEMCalHistoContainer::basename(const char *path) const {
578 /*
579 * Helper function extracting the basename from a given histogram path.
580 *
581 * @param path: histogram path
582 * @return: basename extracted
583 */
584 TString s(path);
585 int index = s.Last('/');
586 if(index < 0) return ""; // no directory structure
587 return TString(s(0, index)).Data();
588 }
589
590 //______________________________________________________________________________
591 const char *AliEMCalHistoContainer::histname(const char *path) const {
592 /*
593 * Helper function extracting the histogram name from a given histogram path.
594 *
595 * @param path: histogram path
596 * @return: basename extracted
597 */
598 TString s(path);
599 int index = s.Last('/');
600 if(index < 0) return path; // no directory structure
601 return TString(s(index+1, s.Length() - (index+1))).Data();
602 }
603}