]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliESDCaloCells.cxx
patch for GCC < 4.3
[u/mrichter/AliRoot.git] / STEER / AliESDCaloCells.cxx
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() : 
30   AliVCaloCells(), fNCells(0), fCellNumber(0), fAmplitude(0), fTime(0), fIsSorted(kTRUE), fType(kUndef)
31 {
32   // default constructor
33 }
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)
37 {
38    // AliVCaloCells constructor
39  }
40
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)
44 {
45   // copy constructor
46
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]    = c.fCellNumber[i];
52     fAmplitude[i]     = c.fAmplitude[i];
53     fTime[i]          = c.fTime[i];
54     fAmplitude[i]     = c.fAmplitude[i];
55
56   }
57 }
58
59 //_______________________________________________________________________
60 AliESDCaloCells & AliESDCaloCells::operator =(const AliESDCaloCells& source)  
61 {
62   // assignment operator
63
64   if(&source == this) return *this;
65
66   if(fNCells != source.fNCells){
67     DeleteContainer();
68     CreateContainer(source.fNCells);
69   }
70
71   fNCells = source.fNCells; 
72   fIsSorted = source.fIsSorted;
73   fType = source.fType;
74
75
76
77   for(Int_t i = 0; i < fNCells; i++){
78     fCellNumber[i]    = source.fCellNumber[i];
79     fAmplitude[i]     = source.fAmplitude[i];
80     fTime[i]          = source.fTime[i];
81   }
82
83   return *this;
84
85 }
86
87
88 void 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
101 //_______________________________________________________________________
102 AliESDCaloCells::~AliESDCaloCells()
103 {
104   // destructor
105
106   DeleteContainer();
107 }
108
109 //_______________________________________________________________________
110 void AliESDCaloCells::CreateContainer(Short_t nCells)
111 {
112   // function that creates container to store calorimeter cell data
113
114   DeleteContainer();
115   
116   if (nCells <= 0) {
117     fNCells = 0;
118     return;
119   }
120
121   fNCells = nCells;
122
123   fCellNumber = new Short_t[fNCells];
124   fAmplitude  = new Double32_t[fNCells];
125   fTime       = new Double32_t[fNCells];
126   
127     // set to zero
128   for(int i = 0;i<fNCells;++i){
129     fAmplitude[i] = fCellNumber[i] = 0 ;
130   }
131 }
132
133 //_______________________________________________________________________
134 void AliESDCaloCells::DeleteContainer()
135 {
136   // deletes allocated memory
137
138   if (fCellNumber)
139   {
140     delete[] fCellNumber;
141     fCellNumber = 0;
142   }
143
144   if (fAmplitude)
145   {
146     delete[] fAmplitude;
147     fAmplitude = NULL;
148   }
149
150   if (fTime)
151   {
152     delete[] fTime;
153     fTime = NULL;
154   }
155   
156   fNCells = 0;
157   fIsSorted = kFALSE;
158 }
159
160 //_______________________________________________________________________
161 void AliESDCaloCells::Sort() 
162 {
163   // sort the cell array by cell number
164   
165   Int_t *idxArray = new Int_t[fNCells];
166   TMath::Sort(fNCells,fCellNumber,idxArray,kFALSE);
167   
168   Short_t *newIndex        = new Short_t[fNCells];
169   Double32_t *newAmplitude = new Double32_t[fNCells];
170   Double32_t *newTime      = new Double32_t[fNCells];
171   for (Int_t i=0; i < fNCells; i++) {
172     newIndex[i]     = fCellNumber[idxArray[i]];
173     newAmplitude[i] = fAmplitude[idxArray[i]];
174     newTime[i]      = fTime[idxArray[i]];
175   }
176   delete [] fCellNumber;
177   delete [] fAmplitude;
178   delete [] fTime;
179
180   fCellNumber = newIndex;
181   fAmplitude  = newAmplitude;
182   fTime       = newTime;
183
184   delete [] idxArray;
185   
186   fIsSorted = kTRUE;
187
188
189 //_______________________________________________________________________
190 Bool_t AliESDCaloCells::SetCell(Short_t pos, Short_t cellNumber, Double32_t amplitude, Double32_t  time)
191 {
192   // Sets a cell at the given position
193
194   if (pos>=0 && pos < fNCells) {
195     fCellNumber[pos] = cellNumber;
196     fAmplitude[pos]  = amplitude;
197     fTime[pos]       = time;
198
199     fIsSorted = kFALSE;
200     return kTRUE;
201   } else {
202     return kFALSE;
203   }
204 }