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