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