1 /**************************************************************************
2 * Copyright(c) 1998-2007, 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 **************************************************************************/
18 //-------------------------------------------------------------------------
19 // ESD class to store calorimeter cell data
20 // Clone of AliAODCaloCells made by Markus Oldenburg, CERN
21 // Author: Gustavo Conesa Balbastre INFN-LNF
22 //-------------------------------------------------------------------------
24 #include "AliESDCaloCells.h"
26 ClassImp(AliESDCaloCells)
28 //_______________________________________________________________________
29 AliESDCaloCells::AliESDCaloCells() :
30 AliVCaloCells(), fNCells(0), fCellNumber(0), fAmplitude(0), fTime(0), fIsSorted(kTRUE), fType(kUndef)
32 // default constructor
34 //_______________________________________________________________________
35 AliESDCaloCells::AliESDCaloCells(const char* name, const char* title, VCells_t ttype) :
36 AliVCaloCells(name, title), fNCells(0), fCellNumber(0), fAmplitude(0), fTime(0), fIsSorted(kTRUE), fType(ttype)
38 // AliVCaloCells constructor
41 //_______________________________________________________________________
42 AliESDCaloCells::AliESDCaloCells(const AliESDCaloCells& c) :
43 AliVCaloCells(c), fNCells(c.fNCells), fCellNumber(0), fAmplitude(0), fTime(0), fIsSorted(c.fIsSorted), fType(c.fType)
47 fCellNumber = new Short_t[fNCells];
48 fAmplitude = new Double32_t[fNCells];
49 fTime = new Double32_t[fNCells];
51 for(Int_t i = 0; i < fNCells; i++){
52 fCellNumber[i] = c.fCellNumber[i];
53 fAmplitude[i] = c.fAmplitude[i];
54 fTime[i] = c.fTime[i];
55 fAmplitude[i] = c.fAmplitude[i];
60 //_______________________________________________________________________
61 AliESDCaloCells & AliESDCaloCells::operator =(const AliESDCaloCells& source)
63 // assignment operator
66 AliVCaloCells::operator=(source);
68 if(fNCells != source.fNCells) {
69 delete [] fCellNumber;
72 fNCells = source.fNCells;
73 fCellNumber = new Short_t[fNCells];
74 fAmplitude = new Double32_t[fNCells];
75 fTime = new Double32_t[fNCells];
77 memcpy(fCellNumber,source.fCellNumber,fNCells*sizeof(Short_t));
78 memcpy(fAmplitude,source.fAmplitude,fNCells*sizeof(Double32_t));
79 memcpy(fTime,source.fTime,fNCells*sizeof(Double32_t));
81 fIsSorted = source.fIsSorted;
89 //_______________________________________________________________________
90 void AliESDCaloCells::Copy(TObject &obj) const {
92 // this overwrites the virtual TOBject::Copy()
93 // to allow run time copying without casting
97 AliESDCaloCells *robj = dynamic_cast<AliESDCaloCells*>(&obj);
98 if(!robj)return; // not an AliESDCaloCells
103 //_______________________________________________________________________
104 AliVCaloCells* AliESDCaloCells::CopyCaloCells(Bool_t all = kTRUE) const {
106 // copy the calo cells into a new object. If option all=FALSE, just the object type,
109 AliVCaloCells *obj = new AliESDCaloCells();
112 obj->SetName (GetName()) ;
113 obj->SetTitle(GetTitle()) ;
114 obj->SetType (GetType()) ;
116 obj->SetNumberOfCells(fNCells);
117 for (Short_t i = 0; i < fNCells; i++)
118 obj->SetCell(i,fCellNumber[i],fAmplitude[i],fTime[i]);
125 //_______________________________________________________________________
126 AliESDCaloCells::~AliESDCaloCells()
133 //_______________________________________________________________________
134 void AliESDCaloCells::Clear(const Option_t*)
142 //_______________________________________________________________________
143 void AliESDCaloCells::CreateContainer(Short_t nCells)
145 // function that creates container to store calorimeter cell data
156 fCellNumber = new Short_t[fNCells];
157 fAmplitude = new Double32_t[fNCells];
158 fTime = new Double32_t[fNCells];
161 for(int i = 0;i<fNCells;++i){
162 fAmplitude[i] = fCellNumber[i] = 0 ;
166 //_______________________________________________________________________
167 void AliESDCaloCells::DeleteContainer()
169 // deletes allocated memory
173 delete[] fCellNumber;
193 //_______________________________________________________________________
194 void AliESDCaloCells::Sort()
196 // sort the cell array by cell number
198 Int_t *idxArray = new Int_t[fNCells];
199 TMath::Sort(fNCells,fCellNumber,idxArray,kFALSE);
201 Short_t *newIndex = new Short_t[fNCells];
202 Double32_t *newAmplitude = new Double32_t[fNCells];
203 Double32_t *newTime = new Double32_t[fNCells];
204 for (Int_t i=0; i < fNCells; i++) {
205 newIndex[i] = fCellNumber[idxArray[i]];
206 newAmplitude[i] = fAmplitude[idxArray[i]];
207 newTime[i] = fTime[idxArray[i]];
209 delete [] fCellNumber;
210 delete [] fAmplitude;
213 fCellNumber = newIndex;
214 fAmplitude = newAmplitude;
222 //_______________________________________________________________________
223 Bool_t AliESDCaloCells::SetCell(Short_t pos, Short_t cellNumber, Double32_t amplitude, Double32_t time)
225 // Sets a cell at the given position
227 if (pos>=0 && pos < fNCells) {
228 fCellNumber[pos] = cellNumber;
229 fAmplitude[pos] = amplitude;