Fixes for Coverity defects
[u/mrichter/AliRoot.git] / STEER / AliESDCaloCells.cxx
CommitLineData
e649177a 1/**************************************************************************
2 * Copyright(c) 1998-2007, 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/* $Id$ */
17
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//-------------------------------------------------------------------------
23
24#include "AliESDCaloCells.h"
25
26ClassImp(AliESDCaloCells)
27
28//_______________________________________________________________________
29AliESDCaloCells::AliESDCaloCells() :
c8fe2783 30 AliVCaloCells(), fNCells(0), fCellNumber(0), fAmplitude(0), fTime(0), fIsSorted(kTRUE), fType(kUndef)
e649177a 31{
32 // default constructor
33}
34//_______________________________________________________________________
c8fe2783 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)
37{
38 // AliVCaloCells constructor
e649177a 39 }
40
41//_______________________________________________________________________
42AliESDCaloCells::AliESDCaloCells(const AliESDCaloCells& c) :
c8fe2783 43 AliVCaloCells(c), fNCells(c.fNCells), fCellNumber(0), fAmplitude(0), fTime(0), fIsSorted(c.fIsSorted), fType(c.fType)
e649177a 44{
45 // copy constructor
46
c8fe2783 47 fCellNumber = new Short_t[fNCells];
48 fAmplitude = new Double32_t[fNCells];
49
e649177a 50 for(Int_t i = 0; i < fNCells; i++){
c8fe2783 51 fCellNumber[i] = c.fCellNumber[i];
52 fAmplitude[i] = c.fAmplitude[i];
53 fTime[i] = c.fTime[i];
54 fAmplitude[i] = c.fAmplitude[i];
55
e649177a 56 }
57}
58
59//_______________________________________________________________________
60AliESDCaloCells & AliESDCaloCells::operator =(const AliESDCaloCells& source)
61{
62 // assignment operator
63
64 if(&source == this) return *this;
e649177a 65
732a24fe 66 if(fNCells != source.fNCells){
67 DeleteContainer();
68 CreateContainer(source.fNCells);
69 }
70
e649177a 71 fNCells = source.fNCells;
72 fIsSorted = source.fIsSorted;
73 fType = source.fType;
732a24fe 74
75
76
e649177a 77 for(Int_t i = 0; i < fNCells; i++){
c8fe2783 78 fCellNumber[i] = source.fCellNumber[i];
79 fAmplitude[i] = source.fAmplitude[i];
80 fTime[i] = source.fTime[i];
e649177a 81 }
82
83 return *this;
84
85}
86
ecff8f07 87//_______________________________________________________________________
732a24fe 88void AliESDCaloCells::Copy(TObject &obj) const {
89
90 // this overwrites the virtual TOBject::Copy()
91 // to allow run time copying without casting
92 // in AliESDEvent
93
94 if(this==&obj)return;
95 AliESDCaloCells *robj = dynamic_cast<AliESDCaloCells*>(&obj);
96 if(!robj)return; // not an AliESDCaloCells
97 *robj = *this;
98
99}
100
e649177a 101//_______________________________________________________________________
ecff8f07 102AliVCaloCells* AliESDCaloCells::CopyCaloCells(Bool_t all = kTRUE) const {
103
104 // copy the calo cells into a new object. If option all=FALSE, just the object type,
105 // for mixing
106
107 AliVCaloCells *obj = new AliESDCaloCells();
108
109 if(all){
110 obj->SetName (GetName()) ;
111 obj->SetTitle(GetTitle()) ;
112 obj->SetType (GetType()) ;
113
114 obj->SetNumberOfCells(fNCells);
115 for (Short_t i = 0; i < fNCells; i++)
116 obj->SetCell(i,fCellNumber[i],fAmplitude[i],fTime[i]);
117 }
118
119 return obj;
120}
121
122
123//_______________________________________________________________________
e649177a 124AliESDCaloCells::~AliESDCaloCells()
125{
126 // destructor
127
128 DeleteContainer();
129}
130
131//_______________________________________________________________________
8dd6eba0 132void AliESDCaloCells::Clear(const Option_t*)
133{
134 // clear
135
136 DeleteContainer();
137}
138
139
140//_______________________________________________________________________
e649177a 141void AliESDCaloCells::CreateContainer(Short_t nCells)
142{
143 // function that creates container to store calorimeter cell data
144
145 DeleteContainer();
146
147 if (nCells <= 0) {
148 fNCells = 0;
149 return;
150 }
151
152 fNCells = nCells;
153
154 fCellNumber = new Short_t[fNCells];
c8fe2783 155 fAmplitude = new Double32_t[fNCells];
156 fTime = new Double32_t[fNCells];
157
158 // set to zero
159 for(int i = 0;i<fNCells;++i){
160 fAmplitude[i] = fCellNumber[i] = 0 ;
161 }
e649177a 162}
163
164//_______________________________________________________________________
165void AliESDCaloCells::DeleteContainer()
166{
167 // deletes allocated memory
168
169 if (fCellNumber)
170 {
171 delete[] fCellNumber;
172 fCellNumber = 0;
173 }
174
175 if (fAmplitude)
176 {
177 delete[] fAmplitude;
c8fe2783 178 fAmplitude = NULL;
e649177a 179 }
180
181 if (fTime)
182 {
183 delete[] fTime;
c8fe2783 184 fTime = NULL;
e649177a 185 }
c8fe2783 186
e649177a 187 fNCells = 0;
188 fIsSorted = kFALSE;
189}
190
191//_______________________________________________________________________
192void AliESDCaloCells::Sort()
193{
194 // sort the cell array by cell number
195
196 Int_t *idxArray = new Int_t[fNCells];
197 TMath::Sort(fNCells,fCellNumber,idxArray,kFALSE);
198
c8fe2783 199 Short_t *newIndex = new Short_t[fNCells];
e649177a 200 Double32_t *newAmplitude = new Double32_t[fNCells];
c8fe2783 201 Double32_t *newTime = new Double32_t[fNCells];
e649177a 202 for (Int_t i=0; i < fNCells; i++) {
c8fe2783 203 newIndex[i] = fCellNumber[idxArray[i]];
e649177a 204 newAmplitude[i] = fAmplitude[idxArray[i]];
c8fe2783 205 newTime[i] = fTime[idxArray[i]];
e649177a 206 }
207 delete [] fCellNumber;
208 delete [] fAmplitude;
209 delete [] fTime;
c8fe2783 210
e649177a 211 fCellNumber = newIndex;
c8fe2783 212 fAmplitude = newAmplitude;
213 fTime = newTime;
e649177a 214
215 delete [] idxArray;
216
217 fIsSorted = kTRUE;
218}
219
220//_______________________________________________________________________
221Bool_t AliESDCaloCells::SetCell(Short_t pos, Short_t cellNumber, Double32_t amplitude, Double32_t time)
222{
223 // Sets a cell at the given position
224
225 if (pos>=0 && pos < fNCells) {
226 fCellNumber[pos] = cellNumber;
c8fe2783 227 fAmplitude[pos] = amplitude;
228 fTime[pos] = time;
229
e649177a 230 fIsSorted = kFALSE;
231 return kTRUE;
232 } else {
233 return kFALSE;
234 }
235}