]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliAODCaloCells.cxx
Changes for report #69974: Virtual class for calorimeter analysis objects
[u/mrichter/AliRoot.git] / STEER / AliAODCaloCells.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 //     AOD class to store calorimeter cell data
20 //     Author: Markus Oldenburg, CERN
21 //-------------------------------------------------------------------------
22
23 #include "AliAODCaloCells.h"
24
25 ClassImp(AliAODCaloCells)
26
27 AliAODCaloCells::AliAODCaloCells() : AliVCaloCells(), fNCells(0), fCellNumber(0), fAmplitude(0), fIsSorted(kTRUE), fType(kUndef)
28 {
29   // default constructor
30 }
31
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)
34 {
35   //constructor
36 }
37
38 AliAODCaloCells::AliAODCaloCells(const AliAODCaloCells& cells) :
39     AliVCaloCells(cells),
40     fNCells(cells.fNCells),
41     fCellNumber(0),
42     fAmplitude(0),
43     fIsSorted(cells.fIsSorted),
44     fType(cells.fType)
45 {
46 // Copy constructor
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   }
54 }
55
56 AliAODCaloCells& AliAODCaloCells::operator=(const AliAODCaloCells& cells)
57 {
58     // Assignment operator
59   if(&cells == this) return *this;
60   fNCells = cells.fNCells;
61   for (Int_t i = 0; i < fNCells; i++) {
62     fCellNumber[i]    = cells.fCellNumber[i];
63     fAmplitude[i]     = cells.fAmplitude[i];
64   }
65   SetName(cells.GetName()) ; 
66   SetTitle(cells.GetTitle()) ; 
67   return *this;
68 }
69
70 AliAODCaloCells::~AliAODCaloCells()
71 {
72   // destructor
73
74   DeleteContainer();
75 }
76
77 void AliAODCaloCells::CreateContainer(Short_t nCells)
78 {
79   // function that creates container to store calorimeter cell data
80
81   DeleteContainer();
82   
83   if (nCells <= 0) {
84     fNCells = 0;
85     return;
86   }
87
88   fNCells = nCells;
89
90   fCellNumber = new Short_t[fNCells];
91   fAmplitude  = new Double32_t[fNCells];
92
93   // set to zero
94   for(int i = 0;i<fNCells;++i){
95     fAmplitude[i] = fCellNumber[i] = 0 ;
96   }
97 }
98
99 void AliAODCaloCells::DeleteContainer()
100 {
101   // deletes allocated memory
102
103   if (fCellNumber)
104   {
105     delete[] fCellNumber;
106     fCellNumber = NULL;
107   }
108
109   if (fAmplitude)
110   {
111     delete[] fAmplitude;
112     fAmplitude = NULL;
113   }
114   
115   fNCells = 0;
116   fIsSorted = kFALSE;
117 }
118
119 void AliAODCaloCells::Sort() 
120 {
121   // sort the cell array by cell number
122   
123   Int_t *idxArray = new Int_t[fNCells];
124   TMath::Sort(fNCells,fCellNumber,idxArray,kFALSE);
125   
126   Short_t    *newIndex     = new Short_t[fNCells];
127   Double32_t *newAmplitude = new Double32_t[fNCells];
128   for (Int_t i=0; i < fNCells; i++) {
129     newIndex[i]     = fCellNumber[idxArray[i]];
130     newAmplitude[i] = fAmplitude[idxArray[i]];
131   }
132   delete [] fCellNumber;
133   delete [] fAmplitude;
134   fCellNumber = newIndex;
135   fAmplitude  = newAmplitude;
136   
137   delete [] idxArray;
138   
139   fIsSorted = kTRUE;
140
141
142 Bool_t AliAODCaloCells::SetCell(Short_t pos, Short_t cellNumber, Double32_t amplitude, Double32_t /*time*/)
143 {
144   // Sets a cell at the given position
145
146   if (pos>=0 && pos < fNCells) {
147     fCellNumber[pos] = cellNumber;
148     fAmplitude[pos]  = amplitude;
149     fIsSorted = kFALSE;
150     return kTRUE;
151   } else {
152     return kFALSE;
153   }
154 }