Since it contains fixes of coding rule violations, all classes are involved. Further...
[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//___________________________________________________________________
75d81601 112Bool_t AliHFEcollection::CreateTH1F(const char* name, const char* title, Int_t nBin, Float_t nMin, Float_t nMax){
809a4336 113
114 if(!fListE){
115 AliError("No TList pointer ! ");
116 return kFALSE;
117 }
118 else{
75d81601 119 fListE->Add(new TH1F(name, title, nBin, nMin, nMax));
120 return CheckObject(name);
809a4336 121 }
122}
123//___________________________________________________________________
75d81601 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){
809a4336 125
126 if(!fListE){
127 AliError("No TList pointer ! ");
128 return kFALSE;
129 }
75d81601 130 fListE->Add(new TH2F(name, title, nBinX, nMinX, nMaxX, nBinY, nMinY, nMaxY));
131 return CheckObject(name);
809a4336 132}
133//___________________________________________________________________
75d81601 134Bool_t AliHFEcollection::CreateTH1Fvector1(Int_t X, const char* name, const char* title, Int_t nBin, Float_t nMin, Float_t nMax){
809a4336 135
75d81601 136 // create a 1 dimensional array of size [X]
809a4336 137
138 if(!fListE){
139 AliError("No TList pointer ! ");
140 return kFALSE;
141 }
75d81601 142 if(X <=0){
809a4336 143 AliError("can not create array with negative or zero size ");
144 return kFALSE;
145 }
75d81601 146 TString hname;
147 for(Int_t i=0; i<X; ++i){
148 hname = "";
149 hname.Append(Form("%s_[%d]", name, i));
809a4336 150 //cout<<" -D: name: "<<name.str().c_str()<<endl;
151 //cout<<" -D: nBin: "<<_nBin<<" ,Min: "<<_nMin<<" , Max: "<<_nMax<<endl;
75d81601 152 CreateTH1F(hname.Data(), title, nBin, nMin, nMax);
153 if(!CheckObject(hname.Data())){
154 AliError(Form("Not possible to create object: ", hname.Data()));
809a4336 155 return kFALSE;
156 }
157 }
158 return kTRUE;
159}
160//___________________________________________________________________
75d81601 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){
809a4336 162
75d81601 163 // create a 1 dimensinal array of TH2F histograms with size [X]
809a4336 164 if(!fListE){
165 AliError("No TList pointer !");
166 return kFALSE;
167 }
75d81601 168 if(X <=0){
809a4336 169 AliError("can not create array with negative or zero size ");
170 return kFALSE;
171 }
75d81601 172 TString hname;
173 for(Int_t i=0; i<X; ++i){
174 hname = "";
175 hname.Append(Form("%s_[%d]", name, i));
809a4336 176 //cout<<" -D: name: "<<name<<endl;
177 //cout<<" -D: nBin: "<<_nBin<<" ,Min: "<<_nMin<<" , Max: "<<_nMax<<endl;
75d81601 178 CreateTH2F(hname.Data(), title, nBinX, nMinX, nMaxX, nBinY, nMinY, nMaxY);
179 if(!CheckObject(hname.Data())){
180 AliError(Form("Not possible to create object: %s", hname.Data()));
809a4336 181 return kFALSE;
182 }
183 }
184 return kTRUE;
185}
186//___________________________________________________________________
75d81601 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){
809a4336 188
75d81601 189 // create a 2 dimensional array of histograms of size [X, Y]
809a4336 190 if(!fListE){
191 AliError("No TList pointer ! ");
192 return kFALSE;
193 }
75d81601 194 if(X <=0 || Y <=0){
809a4336 195 AliError("can not create array with negative or zero size ");
196 return kFALSE;
197 }
75d81601 198 TString hname;
199 for(Int_t i=0; i<X; ++i){
200 for(Int_t j=0; j<Y; ++j){
201 hname = "";
202 hname.Append(Form("%s_[%d][%d]", name, i, j));
809a4336 203 //cout<<" -D: name: "<<name.str().c_str()<<endl;
204 //cout<<" -D: nBin: "<<_nBin<<" ,Min: "<<_nMin<<" , Max: "<<_nMax<<endl;
75d81601 205 CreateTH1F(hname.Data(), title, nBin, nMin, nMax);
206 if(!CheckObject(hname.Data())){
207 AliError(Form("Not possible to create object: %s", hname.Data()));
809a4336 208 return kFALSE;
209 }
210 }
211 }
212 return kTRUE;
213
214
215}
216//___________________________________________________________________
75d81601 217TObject* AliHFEcollection::Get(const char* name, Int_t X){
809a4336 218
75d81601 219 TString hname = name;
220 hname.Append(Form("_[%d]", X));
221 if(!CheckObject(hname.Data())){
809a4336 222 AliError("No such object found in the list");
223 return 0x0;
224 }
225 else{
75d81601 226 return Get(hname.Data());
809a4336 227 }
228}
229//___________________________________________________________________
75d81601 230TObject* AliHFEcollection::Get(const char* name, Int_t X, Int_t Y){
809a4336 231
75d81601 232 TString hname = name;
233 hname.Append(Form("_[%d][%d]", X, Y));
234 if(!CheckObject(hname.Data())){
809a4336 235 AliError("No such object found in the list");
75d81601 236 AliError(Form("name: %s", hname.Data()));
809a4336 237 return 0x0;
238 }
239 else{
75d81601 240 return Get(hname.Data());
809a4336 241 }
242}
243//___________________________________________________________________
75d81601 244Bool_t AliHFEcollection::CheckObject(const char* name){
809a4336 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
75d81601 253 if(!fListE->FindObject(name)){
809a4336 254 AliError("Creating or Finding the object failed");
255 return kFALSE;
256 }
257 return kTRUE;
258}
259//___________________________________________________________________
75d81601 260TObject* AliHFEcollection::Get(const char* name){
261 return fListE->FindObject(name);
809a4336 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}