]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EMCAL/AliEMCALHistoUtilities.cxx
Fixing memory leak (L.Gaudichet)
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALHistoUtilities.cxx
CommitLineData
315d1c64 1/**************************************************************************
2 * Copyright(c) 1998-2002, 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$Log$
d434833b 18Revision 1.2 2006/03/01 23:36:50 jklay
19suppress compiler warnings by correcting some hidden virtual methods
20
4800667c 21Revision 1.1 2006/02/28 21:55:11 jklay
22add histogram utilities class, correct package definitions
23
315d1c64 24*/
25
d434833b 26//_________________________________________________________________________
27// This is just set of static methods for common using
28//
315d1c64 29//*-- Authors: J.L. Klay (LLNL) & Aleksei Pavlinov (WSU)
30
d434833b 31#include "AliEMCALHistoUtilities.h"
315d1c64 32
315d1c64 33#include <TFile.h>
34#include <TList.h>
35#include <TH1.h>
36#include <TH2.h>
37#include <TROOT.h>
38#include <TString.h>
d434833b 39#include <TObjString.h>
40#include <TRegexp.h>
315d1c64 41
42ClassImp(AliEMCALHistoUtilities)
43
44AliEMCALHistoUtilities::AliEMCALHistoUtilities(const char *name, const char *tit) : TNamed(name,tit)
45{
d434833b 46 // constructor
315d1c64 47}
48
49AliEMCALHistoUtilities::~AliEMCALHistoUtilities()
50{
51 //destructor
52}
53
315d1c64 54TList* AliEMCALHistoUtilities::MoveHistsToList(const char* name, Bool_t putToBrowser)
55{
56 // Move HIST to list
57 gROOT->cd();
58 TIter nextHist(gDirectory->GetList());
59 TList *list = new TList;
60 list->SetName(name);
61 TObject *objHist;
62 while((objHist=nextHist())){
63 if (!objHist->InheritsFrom("TH1")) continue;
64 ((TH1*)objHist)->SetDirectory(0); // Remove from gROOT
65 list->Add(objHist);
66 }
67 if(putToBrowser) gROOT->GetListOfBrowsables()->Add((TObject*)list);
68 return list;
69}
70
71void AliEMCALHistoUtilities::FillH1(TList *l, Int_t ind, Double_t x, Double_t w)
72{
73 static TH1* hid=0;
74 if(l == 0) return;
75 if(ind < l->GetSize()){
76 hid = (TH1*)l->At(ind);
77 hid->Fill(x,w);
78 }
79}
80
81void AliEMCALHistoUtilities::FillH2(TList *l, Int_t ind, Double_t x, Double_t y, Double_t w)
82{
83 static TH2* hid=0;
84 if(l == 0) return;
85 if(ind < l->GetSize()){
86 hid = (TH2*)l->At(ind);
87 hid->Fill(x,y,w);
88 }
89}
90
4800667c 91int AliEMCALHistoUtilities::SaveListOfHists(TList *mylist,const char* name,Bool_t kSingleKey,const char* opt)
315d1c64 92{
93 printf(" Name of out file |%s|\n", name);
94 int save = 0;
4800667c 95 if(mylist && mylist->GetSize() && strlen(name)){
315d1c64 96 TString nf(name);
97 if(nf.Contains(".root") == kFALSE) nf += ".root";
98 TFile file(nf.Data(),opt);
4800667c 99 TIter nextHist(mylist);
315d1c64 100 TObject* objHist=0;
101 int nh=0;
102 if(kSingleKey) {
103 file.cd();
4800667c 104 mylist->Write(mylist->GetName(),TObject::kSingleKey);
105 mylist->ls();
315d1c64 106 save = 1;
107 } else {
108 while((objHist=nextHist())) { // loop over list
109 if(objHist->InheritsFrom("TH1")) {
110 TH1* hid = (TH1*)objHist;
111 file.cd();
112 hid->Write();
113 nh++;
114 printf("Save hist. %s \n",hid ->GetName());
115 }
116 }
117 printf("%i hists. save to file -> %s\n", nh,file.GetName());
118 if(nh>0) save = 1;
119 }
120 file.Close();
121 } else {
122 printf("AliEMCALHistoUtilities::SaveListOfHists : N O S A V I N G \n");
315d1c64 123 }
124 return save;
125}
d434833b 126
127// Moved from AliEMCALGeometry
128int AliEMCALHistoUtilities::ParseString(const TString &topt, TObjArray &Opt)
129{ // Feb 06, 2006
130 Ssiz_t begin, index, end, end2;
131 begin = index = end = end2 = 0;
132 TRegexp separator("[^ ;,\\t\\s/]+");
133 while ( (begin < topt.Length()) && (index != kNPOS) ) {
134 // loop over given options
135 index = topt.Index(separator,&end,begin);
136 if (index >= 0 && end >= 1) {
137 TString substring(topt(index,end));
138 Opt.Add(new TObjString(substring.Data()));
139 }
140 begin += end+1;
141 }
142 return Opt.GetEntries();
143}