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