1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
16 // Collection class for histograms
17 // Stores either histograms or vectors of histograms
20 // Matus Kalisky <matus.kalisky@cern.ch>
30 #include <TIterator.h>
33 #include "AliHFEcollection.h"
38 ClassImp(AliHFEcollection)
40 //___________________________________________________________________
41 AliHFEcollection::AliHFEcollection():
46 // default constructor
51 AliError("Initialization of the list failed");
54 // list is owner of the objects. Once list is deleted, the objects
55 // it contains will be deleted too
56 fListE->SetOwner(kTRUE);
58 //Printf("%s:%d,%p",(char*)__FILE__,__LINE__,fInstance);
61 //___________________________________________________________________
62 AliHFEcollection::AliHFEcollection(char* name, char* title):
73 AliError("Initialization of the list failed");
76 // list is owner of the objects. Once list is deleted, the objects
77 // it contains will be deleted too
78 fListE->SetOwner(kTRUE);
81 //___________________________________________________________________
82 AliHFEcollection::AliHFEcollection(const AliHFEcollection &c) :
93 //___________________________________________________________________
94 AliHFEcollection &AliHFEcollection::operator=(const AliHFEcollection &ref)
97 // Assignment operator
105 //___________________________________________________________________
106 void AliHFEcollection::Copy(TObject &ref) const {
108 // Performs the copying of the object
110 AliHFEcollection &target = dynamic_cast<AliHFEcollection &>(ref);
112 target.fListE = fListE;
114 //___________________________________________________________________
115 AliHFEcollection::~AliHFEcollection(){
119 AliInfo("DESTRUCTOR");
121 //___________________________________________________________________
122 Bool_t AliHFEcollection::CreateTH1F(const char* name, const char* title, Int_t nBin, Float_t nMin, Float_t nMax){
124 // Creates a TH1F histogram for the collection
127 AliError("No TList pointer ! ");
131 fListE->Add(new TH1F(name, title, nBin, nMin, nMax));
132 return CheckObject(name);
135 //___________________________________________________________________
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){
138 // Creates a TH2F histogram for the collection
141 AliError("No TList pointer ! ");
144 fListE->Add(new TH2F(name, title, nBinX, nMinX, nMaxX, nBinY, nMinY, nMaxY));
145 return CheckObject(name);
147 //___________________________________________________________________
148 Bool_t AliHFEcollection::CreateTH1Fvector1(Int_t X, const char* name, const char* title, Int_t nBin, Float_t nMin, Float_t nMax){
150 // create a 1 dimensional array of size [X]
153 AliError("No TList pointer ! ");
157 AliError("can not create array with negative or zero size ");
161 for(Int_t i=0; i<X; ++i){
163 hname.Append(Form("%s_[%d]", name, i));
164 //cout<<" -D: name: "<<name.str().c_str()<<endl;
165 //cout<<" -D: nBin: "<<_nBin<<" ,Min: "<<_nMin<<" , Max: "<<_nMax<<endl;
166 CreateTH1F(hname.Data(), title, nBin, nMin, nMax);
167 if(!CheckObject(hname.Data())){
168 AliError(Form("Not possible to create object: ", hname.Data()));
174 //___________________________________________________________________
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){
177 // create a 1 dimensinal array of TH2F histograms with size [X]
180 AliError("No TList pointer !");
184 AliError("can not create array with negative or zero size ");
188 for(Int_t i=0; i<X; ++i){
190 hname.Append(Form("%s_[%d]", name, i));
191 //cout<<" -D: name: "<<name<<endl;
192 //cout<<" -D: nBin: "<<_nBin<<" ,Min: "<<_nMin<<" , Max: "<<_nMax<<endl;
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()));
201 //___________________________________________________________________
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){
204 // create a 2 dimensional array of histograms of size [X, Y]
207 AliError("No TList pointer ! ");
211 AliError("can not create array with negative or zero size ");
215 for(Int_t i=0; i<X; ++i){
216 for(Int_t j=0; j<Y; ++j){
218 hname.Append(Form("%s_[%d][%d]", name, i, j));
219 //cout<<" -D: name: "<<name.str().c_str()<<endl;
220 //cout<<" -D: nBin: "<<_nBin<<" ,Min: "<<_nMin<<" , Max: "<<_nMax<<endl;
221 CreateTH1F(hname.Data(), title, nBin, nMin, nMax);
222 if(!CheckObject(hname.Data())){
223 AliError(Form("Not possible to create object: %s", hname.Data()));
232 //___________________________________________________________________
233 TObject* AliHFEcollection::Get(const char* name, Int_t X){
235 // Get the histogram from the vector
237 // name - vector name
238 // X - Number of the desired histogram
240 TString hname = name;
241 hname.Append(Form("_[%d]", X));
242 if(!CheckObject(hname.Data())){
243 AliError("No such object found in the list");
247 return Get(hname.Data());
250 //___________________________________________________________________
251 TObject* AliHFEcollection::Get(const char* name, Int_t X, Int_t Y){
253 // Get histogram from the 2D vector
255 // name - Name of the vector
256 // X,Y - Indices of the histogram
258 TString hname = name;
259 hname.Append(Form("_[%d][%d]", X, Y));
260 if(!CheckObject(hname.Data())){
261 AliError("No such object found in the list");
262 AliError(Form("name: %s", hname.Data()));
266 return Get(hname.Data());
269 //___________________________________________________________________
270 Bool_t AliHFEcollection::CheckObject(const char* name){
272 // check wheter the creation of the histogram was succesfull
276 AliError("No TList pointer ! ");
280 if(!fListE->FindObject(name)){
281 AliError("Creating or Finding the object failed");
286 //___________________________________________________________________
287 TObject* AliHFEcollection::Get(const char* name){
289 // Get histogram with the required name
291 return fListE->FindObject(name);
293 //___________________________________________________________________
294 Long64_t AliHFEcollection::Merge(TCollection *list){
296 // Merge the collections
299 AliError("AliHFEcollection::Merge : No TList pointer ! ");
303 return fListE->Merge(list);
306 //____________________________________________________________________
307 void AliHFEcollection::Browse(TBrowser *b)
310 // Browse the content of the directory.
315 TIter nextin(fListE);
317 //Add objects that are only in memory
318 while ((obj = nextin())) {
319 b->Add(obj, obj->GetName());