]>
Commit | Line | Data |
---|---|---|
8d122774 | 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 | // AOD class to store calorimeter cell data | |
20 | // Author: Markus Oldenburg, CERN | |
21 | //------------------------------------------------------------------------- | |
22 | ||
23 | #include "AliAODCaloCells.h" | |
24 | ||
25 | ClassImp(AliAODCaloCells) | |
26 | ||
c8fe2783 | 27 | AliAODCaloCells::AliAODCaloCells() : AliVCaloCells(), fNCells(0), fCellNumber(0), fAmplitude(0), fIsSorted(kTRUE), fType(kUndef) |
8d122774 | 28 | { |
29 | // default constructor | |
30 | } | |
31 | ||
c8fe2783 | 32 | AliAODCaloCells::AliAODCaloCells(const char* name, const char* title, VCells_t ttype) : |
33 | AliVCaloCells(name, title), fNCells(0), fCellNumber(0), fAmplitude(0), fIsSorted(kTRUE), fType(ttype) | |
8d122774 | 34 | { |
c8fe2783 | 35 | //constructor |
8d122774 | 36 | } |
37 | ||
5c1dc41f | 38 | AliAODCaloCells::AliAODCaloCells(const AliAODCaloCells& cells) : |
c8fe2783 | 39 | AliVCaloCells(cells), |
5c1dc41f | 40 | fNCells(cells.fNCells), |
41 | fCellNumber(0), | |
42 | fAmplitude(0), | |
43 | fIsSorted(cells.fIsSorted), | |
44 | fType(cells.fType) | |
45 | { | |
46 | // Copy constructor | |
c8fe2783 | 47 | fCellNumber = new Short_t[fNCells]; |
48 | fAmplitude = new Double32_t[fNCells]; | |
49 | ||
50 | for (Int_t i = 0; i < fNCells; i++) { | |
51 | fCellNumber[i] = cells.fCellNumber[i]; | |
52 | fAmplitude[i] = cells.fAmplitude[i]; | |
53 | } | |
5c1dc41f | 54 | } |
55 | ||
56 | AliAODCaloCells& AliAODCaloCells::operator=(const AliAODCaloCells& cells) | |
57 | { | |
c8fe2783 | 58 | // Assignment operator |
59 | if(&cells == this) return *this; | |
c4a461a7 | 60 | delete [] fCellNumber; |
61 | delete [] fAmplitude; | |
62 | ||
c8fe2783 | 63 | fNCells = cells.fNCells; |
c4a461a7 | 64 | |
65 | fCellNumber = new Short_t[fNCells]; | |
66 | fAmplitude = new Double32_t[fNCells]; | |
67 | ||
c8fe2783 | 68 | for (Int_t i = 0; i < fNCells; i++) { |
69 | fCellNumber[i] = cells.fCellNumber[i]; | |
70 | fAmplitude[i] = cells.fAmplitude[i]; | |
71 | } | |
13b378a1 | 72 | fIsSorted = cells.fIsSorted; |
73 | fType = cells.fType; | |
74 | ||
c8fe2783 | 75 | SetName(cells.GetName()) ; |
76 | SetTitle(cells.GetTitle()) ; | |
77 | return *this; | |
5c1dc41f | 78 | } |
79 | ||
8d122774 | 80 | AliAODCaloCells::~AliAODCaloCells() |
81 | { | |
82 | // destructor | |
83 | ||
84 | DeleteContainer(); | |
85 | } | |
86 | ||
8dd6eba0 | 87 | void AliAODCaloCells::Clear(const Option_t*) |
88 | { | |
89 | // clear | |
90 | ||
91 | DeleteContainer(); | |
92 | } | |
ecff8f07 | 93 | |
94 | void AliAODCaloCells::Copy(TObject &obj) const { | |
95 | ||
96 | // this overwrites the virtual TOBject::Copy() | |
97 | // to allow run time copying without casting | |
98 | // in AliESDEvent | |
99 | ||
100 | if(this==&obj)return; | |
101 | AliAODCaloCells *robj = dynamic_cast<AliAODCaloCells*>(&obj); | |
102 | if(!robj)return; // not an AliAODCaloCells | |
103 | *robj = *this; | |
104 | ||
105 | } | |
106 | ||
107 | AliVCaloCells *AliAODCaloCells::CopyCaloCells(Bool_t all = kTRUE) const { | |
108 | ||
109 | // copy the calo cells into a new object. If option all=FALSE, just the object type, | |
110 | // for mixing | |
111 | ||
112 | AliVCaloCells *obj = new AliAODCaloCells(); | |
113 | ||
114 | if(all){ | |
115 | obj->SetName (GetName()) ; | |
116 | obj->SetTitle(GetTitle()) ; | |
117 | obj->SetType (GetType()) ; | |
118 | ||
119 | obj->SetNumberOfCells(fNCells); | |
120 | for (Short_t i = 0; i < fNCells; i++) | |
121 | obj->SetCell(i,fCellNumber[i],fAmplitude[i],-1); | |
122 | } | |
123 | ||
124 | return obj; | |
125 | ||
126 | } | |
127 | ||
8d122774 | 128 | void AliAODCaloCells::CreateContainer(Short_t nCells) |
129 | { | |
130 | // function that creates container to store calorimeter cell data | |
131 | ||
132 | DeleteContainer(); | |
133 | ||
134 | if (nCells <= 0) { | |
135 | fNCells = 0; | |
136 | return; | |
137 | } | |
138 | ||
139 | fNCells = nCells; | |
140 | ||
141 | fCellNumber = new Short_t[fNCells]; | |
c8fe2783 | 142 | fAmplitude = new Double32_t[fNCells]; |
143 | ||
341952b8 | 144 | // set to zero |
145 | for(int i = 0;i<fNCells;++i){ | |
c8fe2783 | 146 | fAmplitude[i] = fCellNumber[i] = 0 ; |
341952b8 | 147 | } |
8d122774 | 148 | } |
149 | ||
150 | void AliAODCaloCells::DeleteContainer() | |
151 | { | |
152 | // deletes allocated memory | |
153 | ||
154 | if (fCellNumber) | |
155 | { | |
156 | delete[] fCellNumber; | |
c8fe2783 | 157 | fCellNumber = NULL; |
8d122774 | 158 | } |
159 | ||
160 | if (fAmplitude) | |
161 | { | |
162 | delete[] fAmplitude; | |
c8fe2783 | 163 | fAmplitude = NULL; |
8d122774 | 164 | } |
c8fe2783 | 165 | |
8d122774 | 166 | fNCells = 0; |
167 | fIsSorted = kFALSE; | |
168 | } | |
169 | ||
170 | void AliAODCaloCells::Sort() | |
171 | { | |
172 | // sort the cell array by cell number | |
173 | ||
174 | Int_t *idxArray = new Int_t[fNCells]; | |
175 | TMath::Sort(fNCells,fCellNumber,idxArray,kFALSE); | |
176 | ||
c8fe2783 | 177 | Short_t *newIndex = new Short_t[fNCells]; |
8d122774 | 178 | Double32_t *newAmplitude = new Double32_t[fNCells]; |
179 | for (Int_t i=0; i < fNCells; i++) { | |
c8fe2783 | 180 | newIndex[i] = fCellNumber[idxArray[i]]; |
8d122774 | 181 | newAmplitude[i] = fAmplitude[idxArray[i]]; |
182 | } | |
183 | delete [] fCellNumber; | |
184 | delete [] fAmplitude; | |
185 | fCellNumber = newIndex; | |
c8fe2783 | 186 | fAmplitude = newAmplitude; |
8d122774 | 187 | |
188 | delete [] idxArray; | |
189 | ||
190 | fIsSorted = kTRUE; | |
191 | } | |
192 | ||
c8fe2783 | 193 | Bool_t AliAODCaloCells::SetCell(Short_t pos, Short_t cellNumber, Double32_t amplitude, Double32_t /*time*/) |
8d122774 | 194 | { |
195 | // Sets a cell at the given position | |
196 | ||
197 | if (pos>=0 && pos < fNCells) { | |
198 | fCellNumber[pos] = cellNumber; | |
c8fe2783 | 199 | fAmplitude[pos] = amplitude; |
8d122774 | 200 | fIsSorted = kFALSE; |
201 | return kTRUE; | |
202 | } else { | |
203 | return kFALSE; | |
204 | } | |
205 | } |