]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/AliEMCALFixedWindowClusterInfo.cxx
a2b689a53b900b58a250a61bd8495afaa9d96482
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALFixedWindowClusterInfo.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, 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 // --- Root ---
19 #include <TNamed.h>
20 #include <TArrayI.h>
21
22 #include "AliEMCALFixedWindowClusterInfo.h"
23
24 ClassImp(AliEMCALFixedWindowClusterInfo)
25
26 //___________________________________________________________________________________________________________
27 AliEMCALFixedWindowClusterInfo::AliEMCALFixedWindowClusterInfo()
28   : TNamed(),
29     fLastPos(0),
30     fIds(new TArrayI()),
31     fIndexes(new TArrayI()),
32     fPhi(new TArrayI()),
33     fEta(new TArrayI())
34 {
35   // Constructor
36 }
37
38 //___________________________________________________________________________________________________________
39 AliEMCALFixedWindowClusterInfo::AliEMCALFixedWindowClusterInfo(const char* name, Int_t size)
40   : TNamed(name, name),
41     fLastPos(0),
42     fIds(new TArrayI(size)),
43     fIndexes(new TArrayI(size)),
44     fPhi(new TArrayI(size)),
45     fEta(new TArrayI(size))
46 {
47   // Constructor
48   
49   fIds->Reset(-1);
50   fIndexes->Reset(-1);
51   fPhi->Reset(-1);
52   fEta->Reset(-1);
53 }
54
55 //___________________________________________________________________________________________________________
56 AliEMCALFixedWindowClusterInfo::AliEMCALFixedWindowClusterInfo(const TString& name, Int_t size)
57   : TNamed(name, name),
58     fLastPos(0),
59     fIds(new TArrayI(size)),
60     fIndexes(new TArrayI(size)),
61     fPhi(new TArrayI(size)),
62     fEta(new TArrayI(size))
63 {
64   // Constructor
65   
66   fIds->Reset(-1);
67   fIndexes->Reset(-1);
68   fPhi->Reset(-1);
69   fEta->Reset(-1);
70 }
71
72 //___________________________________________________________________________________________________________
73 AliEMCALFixedWindowClusterInfo::~AliEMCALFixedWindowClusterInfo()
74 {
75   // Destructor
76
77   delete fIds;
78   delete fIndexes;
79   delete fPhi;
80   delete fEta;
81 }
82
83 //___________________________________________________________________________________________________________
84 Bool_t AliEMCALFixedWindowClusterInfo::GetInfoFromId(Int_t idclus, Int_t &index, Int_t &eta, Int_t &phi) const
85 {
86   // Search for the unique ID and return index, eta and phi
87   
88   Int_t i = GetPositionFromId(idclus);
89   if (i > -1){
90     index = fIndexes->At(i);
91     eta = fEta->At(i);
92     phi = fPhi->At(i);
93     return kTRUE;
94   }
95   return kFALSE;
96 }
97
98 //___________________________________________________________________________________________________________
99 Bool_t AliEMCALFixedWindowClusterInfo::GetInfoFromIndex(Int_t index, Int_t &idclus, Int_t &eta, Int_t &phi) const
100 {
101   // Search for the index and return unique ID, eta and phi
102   
103   Int_t i = GetPositionFromIndex(index);
104   if (i > -1){
105     idclus = fIds->At(i);
106     eta = fEta->At(i);
107     phi = fPhi->At(i);
108     return kTRUE;
109   }
110   return kFALSE;
111 }
112
113 //___________________________________________________________________________________________________________
114 Bool_t AliEMCALFixedWindowClusterInfo::SetIndexFromId(Int_t idclus, Int_t index)
115 {
116   // Search for the unique ID and set index
117   
118   Int_t i = GetPositionFromId(idclus);
119   if (i > -1){
120     fIndexes->AddAt(index, i);
121     return kTRUE;
122   }
123   return kFALSE;
124 }
125
126 //___________________________________________________________________________________________________________
127 void AliEMCALFixedWindowClusterInfo::Add(Int_t idclus, Int_t index, Int_t eta, Int_t phi)
128 {
129   // Add a new element to the arrays; if necessary expand the arrays
130   
131   if (fLastPos >= fIds->GetSize())
132     Expand(fIds->GetSize() * 2 + 1);
133   
134   fIds->AddAt(idclus, fLastPos);
135   fIndexes->AddAt(index, fLastPos);
136   fPhi->AddAt(phi, fLastPos);
137   fEta->AddAt(eta, fLastPos);
138   fLastPos++;
139 }
140
141 //___________________________________________________________________________________________________________
142 Bool_t AliEMCALFixedWindowClusterInfo::RemoveId(Int_t idclus)
143 {
144   // Search for the unique ID and remove the corresponding element from the arrays
145   
146   Int_t i = GetPositionFromId(idclus);
147   if (i > -1){
148     fIds->AddAt(-1, i);
149     fIndexes->AddAt(-1, i);
150     fPhi->AddAt(-1, i);
151     fEta->AddAt(-1, i);
152     return kTRUE;
153   }
154   return kFALSE;
155 }
156
157 //___________________________________________________________________________________________________________
158 Bool_t AliEMCALFixedWindowClusterInfo::RemoveIndex(Int_t index)
159 {
160   // Search for and index and remove the corresponding element from the arrays
161   
162   Int_t i = GetPositionFromIndex(index);
163   if (i > -1){
164     fIds->AddAt(-1, i);
165     fIndexes->AddAt(-1, i);
166     fPhi->AddAt(-1, i);
167     fEta->AddAt(-1, i);
168     return kTRUE;
169   }
170   return kFALSE;
171 }
172
173 //___________________________________________________________________________________________________________
174 void AliEMCALFixedWindowClusterInfo::Expand(Int_t size)
175 {
176   // Expand the arrays
177   
178   Int_t oldsize = fIds->GetSize();
179   
180   fIds->Set(size);
181   fIndexes->Set(size);
182   fPhi->Set(size);
183   fEta->Set(size);
184   
185   for (Int_t i = oldsize; i < size; i++){
186     fIds->AddAt(-1, i);
187     fIndexes->AddAt(-1, i);
188     fPhi->AddAt(-1, i);
189     fEta->AddAt(-1, i);
190   }
191 }
192
193 //___________________________________________________________________________________________________________
194 void AliEMCALFixedWindowClusterInfo::Clear(Option_t* option)
195 {
196   // Clear the arrays
197   
198   fIds->Reset(-1);
199   fIndexes->Reset(-1);
200   fPhi->Reset(-1);
201   fEta->Reset(-1);
202   fLastPos = 0;
203 }
204
205 //___________________________________________________________________________________________________________
206 Int_t AliEMCALFixedWindowClusterInfo::GetSize() const
207 {
208   // Return the size of the arrays
209   
210   return fIds->GetSize();
211 }
212
213 //___________________________________________________________________________________________________________
214 Bool_t AliEMCALFixedWindowClusterInfo::ContainsId(Int_t idclus) const
215 {
216   // Search for the unique ID and return whether or not it exists
217   
218   if(GetPositionFromId(idclus) > -1)
219     return kTRUE;
220   else
221     return kFALSE;
222 }
223
224 //___________________________________________________________________________________________________________
225 Bool_t AliEMCALFixedWindowClusterInfo::ContainsIndex(Int_t index) const
226 {
227   // Search for the index and return whether or not it exists
228   
229   if(GetPositionFromIndex(index) > -1)
230     return kTRUE;
231   else
232     return kFALSE;
233 }
234
235 //___________________________________________________________________________________________________________
236 Int_t AliEMCALFixedWindowClusterInfo::GetPositionFromId(Int_t idclus) const
237 {
238   // Return the the position corresponding to a given unique ID
239   
240   for (Int_t i = 0; i < fLastPos; i++){
241     if (fIds->At(i) == idclus)
242       return i;
243   }
244   return -1;
245 }
246
247 //___________________________________________________________________________________________________________
248 Int_t AliEMCALFixedWindowClusterInfo::GetPositionFromIndex(Int_t index) const
249 {
250   // Return the the position corresponding to a given index
251   
252   for (Int_t i = 0; i < fLastPos; i++){
253     if (fIndexes->At(i) == index)
254       return i;
255   }
256   return -1;
257 }
258
259 //___________________________________________________________________________________________________________
260 Int_t AliEMCALFixedWindowClusterInfo::GetLastElementPosition() const
261 {
262   // Return the position of the last non-empty element in the arrays
263   
264   return fLastPos;
265 }