]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG3/hfe/AliHFEcollection.cxx
Protection against division by 0
[u/mrichter/AliRoot.git] / PWG3 / hfe / AliHFEcollection.cxx
CommitLineData
809a4336 1/**************************************************************************
2* Copyright(c) 1998-1999, 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#include <iostream>
17
18#include <TH1F.h>
19#include <TH2F.h>
20#include <TList.h>
21#include <TString.h>
22#include <TBrowser.h>
23#include <TIterator.h>
24
25#include "AliLog.h"
26#include "AliHFEcollection.h"
27
28using namespace std;
29
30
31ClassImp(AliHFEcollection)
32
33//___________________________________________________________________
34AliHFEcollection::AliHFEcollection():
35 TNamed()
36 , fListE(0x0)
37{
38 //
39 // default constructor
40 //
41
42 fListE = new TList();
43 if(!fListE){
44 AliError("Initialization of the list failed");
45 }
46 else{
47 // list is owner of the objects. Once list is deleted, the objects
48 // it contains will be deleted too
49 fListE->SetOwner(kTRUE);
50 }
51 //Printf("%s:%d,%p",(char*)__FILE__,__LINE__,fInstance);
52
53}
54//___________________________________________________________________
55AliHFEcollection::AliHFEcollection(char* name, char* title):
56 TNamed(name, title)
57 , fListE(0x0)
58{
59
60 //
61 // constructor
62 //
63
64 fListE = new TList();
65 if(!fListE){
66 AliError("Initialization of the list failed");
67 }
68 else{
69 // list is owner of the objects. Once list is deleted, the objects
70 // it contains will be deleted too
71 fListE->SetOwner(kTRUE);
72 }
73}
74//___________________________________________________________________
75AliHFEcollection::AliHFEcollection(const AliHFEcollection &c) :
76 TNamed(c)
77 , fListE(0x0)
78{
79
80 //
81 // copy operator
82 //
83
84 c.Copy(*this);
85}
86//___________________________________________________________________
87AliHFEcollection &AliHFEcollection::operator=(const AliHFEcollection &ref)
88{
89 //
90 // Assignment operator
91 //
92
93 if(this != &ref){
94 ref.Copy(*this);
95 }
96 return *this;
97}
98//___________________________________________________________________
99void AliHFEcollection::Copy(TObject &ref) const {
100 //
101 // Performs the copying of the object
102 //
103 AliHFEcollection &target = dynamic_cast<AliHFEcollection &>(ref);
104
105 target.fListE = fListE;
106}
107//___________________________________________________________________
108AliHFEcollection::~AliHFEcollection(){
109 AliInfo("DESTRUCTOR");
110}
111//___________________________________________________________________
112Bool_t AliHFEcollection::CreateTH1F(const char* _name, const char* _title, Int_t _nBin, Float_t _nMin, Float_t _nMax){
113
114 if(!fListE){
115 AliError("No TList pointer ! ");
116 return kFALSE;
117 }
118 else{
119 fListE->Add(new TH1F(_name, _title, _nBin, _nMin, _nMax));
120 return CheckObject(_name);
121 }
122}
123//___________________________________________________________________
124Bool_t AliHFEcollection::CreateTH2F(const char* _name, const char* _title, Int_t _nBinX, Float_t _nMinX, Float_t _nMaxX, Int_t _nBinY, Float_t _nMinY, Float_t _nMaxY){
125
126 if(!fListE){
127 AliError("No TList pointer ! ");
128 return kFALSE;
129 }
130 fListE->Add(new TH2F(_name, _title, _nBinX, _nMinX, _nMaxX, _nBinY, _nMinY, _nMaxY));
131 return CheckObject(_name);
132}
133//___________________________________________________________________
134Bool_t AliHFEcollection::CreateTH1Fvector1(Int_t _X, const char* _name, const char* _title, Int_t _nBin, Float_t _nMin, Float_t _nMax){
135
136 // create a 1 dimensional array of size [_X]
137
138 if(!fListE){
139 AliError("No TList pointer ! ");
140 return kFALSE;
141 }
142 if(_X <=0){
143 AliError("can not create array with negative or zero size ");
144 return kFALSE;
145 }
146 TString name;
147 for(Int_t i=0; i<_X; ++i){
148 name = "";
149 name.Append(Form("%s_[%d]", _name, i));
150 //cout<<" -D: name: "<<name.str().c_str()<<endl;
151 //cout<<" -D: nBin: "<<_nBin<<" ,Min: "<<_nMin<<" , Max: "<<_nMax<<endl;
152 CreateTH1F(name.Data(), _title, _nBin, _nMin, _nMax);
153 if(!CheckObject(name.Data())){
154 AliError(Form("Not possible to create object: ", name.Data()));
155 return kFALSE;
156 }
157 }
158 return kTRUE;
159}
160//___________________________________________________________________
161Bool_t AliHFEcollection::CreateTH2Fvector1(Int_t _X, const char* _name, const char* _title, Int_t _nBinX, Float_t _nMinX, Float_t _nMaxX, Int_t _nBinY, Float_t _nMinY, Float_t _nMaxY){
162
163 // create a 1 dimensinal array of TH2F histograms with size [_X]
164 if(!fListE){
165 AliError("No TList pointer !");
166 return kFALSE;
167 }
168 if(_X <=0){
169 AliError("can not create array with negative or zero size ");
170 return kFALSE;
171 }
172 TString name;
173 for(Int_t i=0; i<_X; ++i){
174 name = "";
175 name.Append(Form("%s_[%d]", _name, i));
176 //cout<<" -D: name: "<<name<<endl;
177 //cout<<" -D: nBin: "<<_nBin<<" ,Min: "<<_nMin<<" , Max: "<<_nMax<<endl;
178 CreateTH2F(name.Data(), _title, _nBinX, _nMinX, _nMaxX, _nBinY, _nMinY, _nMaxY);
179 if(!CheckObject(name.Data())){
180 AliError(Form("Not possible to create object: %s", name.Data()));
181 return kFALSE;
182 }
183 }
184 return kTRUE;
185}
186//___________________________________________________________________
187Bool_t AliHFEcollection::CreateTH1Fvector2(Int_t _X, Int_t _Y, const char* _name, const char* _title, Int_t _nBin, Float_t _nMin, Float_t _nMax){
188
189 // create a 2 dimensional array of histograms of size [_X, _Y]
190 if(!fListE){
191 AliError("No TList pointer ! ");
192 return kFALSE;
193 }
194 if(_X <=0 || _Y <=0){
195 AliError("can not create array with negative or zero size ");
196 return kFALSE;
197 }
198 TString name;
199 for(Int_t i=0; i<_X; ++i){
200 for(Int_t j=0; j<_Y; ++j){
201 name = "";
202 name.Append(Form("%s_[%d][%d]", _name, i, j));
203 //cout<<" -D: name: "<<name.str().c_str()<<endl;
204 //cout<<" -D: nBin: "<<_nBin<<" ,Min: "<<_nMin<<" , Max: "<<_nMax<<endl;
205 CreateTH1F(name.Data(), _title, _nBin, _nMin, _nMax);
206 if(!CheckObject(name.Data())){
207 AliError(Form("Not possible to create object: %s", name.Data()));
208 return kFALSE;
209 }
210 }
211 }
212 return kTRUE;
213
214
215}
216//___________________________________________________________________
217TObject* AliHFEcollection::Get(const char* _name, Int_t _X){
218
219 TString name = _name;
220 name.Append(Form("_[%d]", _X));
221 if(!CheckObject(name.Data())){
222 AliError("No such object found in the list");
223 return 0x0;
224 }
225 else{
226 return Get(name.Data());
227 }
228}
229//___________________________________________________________________
230TObject* AliHFEcollection::Get(const char* _name, Int_t _X, Int_t _Y){
231
232 TString name = _name;
233 name.Append(Form("_[%d][%d]", _X, _Y));
234 if(!CheckObject(name.Data())){
235 AliError("No such object found in the list");
236 AliError(Form("name: %s", name.Data()));
237 return 0x0;
238 }
239 else{
240 return Get(name.Data());
241 }
242}
243//___________________________________________________________________
244Bool_t AliHFEcollection::CheckObject(const char* _name){
245
246 // check wheter the creation of the histogram was succesfull
247
248 if(!fListE){
249 AliError("No TList pointer ! ");
250 return kFALSE;
251 }
252
253 if(!fListE->FindObject(_name)){
254 AliError("Creating or Finding the object failed");
255 return kFALSE;
256 }
257 return kTRUE;
258}
259//___________________________________________________________________
260TObject* AliHFEcollection::Get(const char* _name){
261 return fListE->FindObject(_name);
262}
263//___________________________________________________________________
264Long64_t AliHFEcollection::Merge(TCollection *list){
265
266 if(!fListE){
267 AliError("AliHFEcollection::Merge : No TList pointer ! ");
268 return 0;
269 }
270
271 return fListE->Merge(list);
272
273}
274//____________________________________________________________________
275void AliHFEcollection::Browse(TBrowser *b)
276{
277 // Browse the content of the directory.
278
279 if (b) {
280 TObject *obj = 0;
281 TIter nextin(fListE);
282
283 //Add objects that are only in memory
284 while ((obj = nextin())) {
285 b->Add(obj, obj->GetName());
286 }
287 }
288}