]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliESDCaloCells.cxx
First version of esd input handler reading recpoints in parallel.
[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   TNamed(), 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, ESDCells_t ttype) : 
36    TNamed(name, title), fNCells(0), fCellNumber(0), fAmplitude(0),  fTime(0), fIsSorted(kTRUE), fType(ttype)
37  {
38    // TNamed constructor
39  }
40
41 //_______________________________________________________________________
42 AliESDCaloCells::AliESDCaloCells(const AliESDCaloCells& c) : 
43   TNamed(c), fNCells(c.fNCells),  fCellNumber(), fAmplitude(), fTime(), fIsSorted(c.fIsSorted), fType(c.fType)
44 {
45   // copy constructor
46
47   for(Int_t i = 0; i < fNCells; i++){
48     fCellNumber[i] = c.fCellNumber[i];
49     fAmplitude[i] = c.fAmplitude[i];
50     fTime[i] = c.fTime[i];
51   }
52 }
53
54 //_______________________________________________________________________
55 AliESDCaloCells & AliESDCaloCells::operator =(const AliESDCaloCells& source)  
56 {
57   // assignment operator
58
59   if(&source == this) return *this;
60   TNamed::operator=(source);
61
62   fNCells = source.fNCells; 
63   fIsSorted = source.fIsSorted;
64   fType = source.fType;
65   
66   for(Int_t i = 0; i < fNCells; i++){
67     fCellNumber[i] = source.fCellNumber[i];
68     fAmplitude[i] = source.fAmplitude[i];
69     fTime[i] = source.fTime[i];
70   }
71
72   return *this;
73
74 }
75
76 //_______________________________________________________________________
77 AliESDCaloCells::~AliESDCaloCells()
78 {
79   // destructor
80
81   DeleteContainer();
82 }
83
84 //_______________________________________________________________________
85 void AliESDCaloCells::CreateContainer(Short_t nCells)
86 {
87   // function that creates container to store calorimeter cell data
88
89   DeleteContainer();
90   
91   if (nCells <= 0) {
92     fNCells = 0;
93     return;
94   }
95
96   fNCells = nCells;
97
98   fCellNumber = new Short_t[fNCells];
99   fAmplitude = new Double32_t[fNCells];
100   fTime = new Double32_t[fNCells];
101 }
102
103 //_______________________________________________________________________
104 void AliESDCaloCells::DeleteContainer()
105 {
106   // deletes allocated memory
107
108   if (fCellNumber)
109   {
110     delete[] fCellNumber;
111     fCellNumber = 0;
112   }
113
114   if (fAmplitude)
115   {
116     delete[] fAmplitude;
117     fAmplitude = 0;
118   }
119
120   if (fTime)
121   {
122     delete[] fTime;
123     fTime = 0;
124   }
125
126   fNCells = 0;
127   fIsSorted = kFALSE;
128 }
129
130 //_______________________________________________________________________
131 void AliESDCaloCells::Sort() 
132 {
133   // sort the cell array by cell number
134   
135   Int_t *idxArray = new Int_t[fNCells];
136   TMath::Sort(fNCells,fCellNumber,idxArray,kFALSE);
137   
138   Short_t *newIndex = new Short_t[fNCells];
139   Double32_t *newAmplitude = new Double32_t[fNCells];
140   Double32_t *newTime = new Double32_t[fNCells];
141   for (Int_t i=0; i < fNCells; i++) {
142     newIndex[i] = fCellNumber[idxArray[i]];
143     newAmplitude[i] = fAmplitude[idxArray[i]];
144     newTime[i] = fTime[idxArray[i]];
145   }
146   delete [] fCellNumber;
147   delete [] fAmplitude;
148   delete [] fTime;
149   fCellNumber = newIndex;
150   fAmplitude = newAmplitude;
151   fTime = newTime;
152
153   delete [] idxArray;
154   
155   fIsSorted = kTRUE;
156
157
158 //_______________________________________________________________________
159 Bool_t AliESDCaloCells::SetCell(Short_t pos, Short_t cellNumber, Double32_t amplitude, Double32_t  time)
160 {
161   // Sets a cell at the given position
162
163   if (pos>=0 && pos < fNCells) {
164     fCellNumber[pos] = cellNumber;
165     fAmplitude[pos] = amplitude;
166     fTime[pos] = time;
167     fIsSorted = kFALSE;
168     return kTRUE;
169   } else {
170     return kFALSE;
171   }
172 }