Added methods for finding a given module in the DDL map (F. Prino)
[u/mrichter/AliRoot.git] / STEER / 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
27AliAODCaloCells::AliAODCaloCells() : TNamed(), fNCells(0), fCellNumber(0), fAmplitude(0), fIsSorted(kTRUE), fType(kUndef)
28{
29 // default constructor
30}
31
e649177a 32AliAODCaloCells::AliAODCaloCells(const char* name, const char* title, AODCells_t ttype) : TNamed(name, title), fNCells(0), fCellNumber(0), fAmplitude(0), fIsSorted(kTRUE), fType(ttype)
8d122774 33{
34 // TNamed constructor
35}
36
5c1dc41f 37AliAODCaloCells::AliAODCaloCells(const AliAODCaloCells& cells) :
38 TNamed(cells),
39 fNCells(cells.fNCells),
40 fCellNumber(0),
41 fAmplitude(0),
42 fIsSorted(cells.fIsSorted),
43 fType(cells.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] = cells.fCellNumber[i];
52 fAmplitude[i] = cells.fAmplitude[i];
53 }
54}
55
56AliAODCaloCells& AliAODCaloCells::operator=(const AliAODCaloCells& cells)
57{
58// Assignment operator
59 if(&cells == this) return *this;
60 TNamed::operator=(cells);
61 fNCells = cells.fNCells;
62 for (Int_t i = 0; i < fNCells; i++) {
63 fCellNumber[i] = cells.fCellNumber[i];
64 fAmplitude[i] = cells.fAmplitude[i];
65 }
66 return *this;
67}
68
8d122774 69AliAODCaloCells::~AliAODCaloCells()
70{
71 // destructor
72
73 DeleteContainer();
74}
75
76void AliAODCaloCells::CreateContainer(Short_t nCells)
77{
78 // function that creates container to store calorimeter cell data
79
80 DeleteContainer();
81
82 if (nCells <= 0) {
83 fNCells = 0;
84 return;
85 }
86
87 fNCells = nCells;
88
89 fCellNumber = new Short_t[fNCells];
90 fAmplitude = new Double32_t[fNCells];
91}
92
93void AliAODCaloCells::DeleteContainer()
94{
95 // deletes allocated memory
96
97 if (fCellNumber)
98 {
99 delete[] fCellNumber;
100 fCellNumber = 0;
101 }
102
103 if (fAmplitude)
104 {
105 delete[] fAmplitude;
106 fAmplitude = 0;
107 }
108
109 fNCells = 0;
110 fIsSorted = kFALSE;
111}
112
113void AliAODCaloCells::Sort()
114{
115 // sort the cell array by cell number
116
117 Int_t *idxArray = new Int_t[fNCells];
118 TMath::Sort(fNCells,fCellNumber,idxArray,kFALSE);
119
120 Short_t *newIndex = new Short_t[fNCells];
121 Double32_t *newAmplitude = new Double32_t[fNCells];
122 for (Int_t i=0; i < fNCells; i++) {
123 newIndex[i] = fCellNumber[idxArray[i]];
124 newAmplitude[i] = fAmplitude[idxArray[i]];
125 }
126 delete [] fCellNumber;
127 delete [] fAmplitude;
128 fCellNumber = newIndex;
129 fAmplitude = newAmplitude;
130
131 delete [] idxArray;
132
133 fIsSorted = kTRUE;
134}
135
136Bool_t AliAODCaloCells::SetCell(Short_t pos, Short_t cellNumber, Double32_t amplitude)
137{
138 // Sets a cell at the given position
139
140 if (pos>=0 && pos < fNCells) {
141 fCellNumber[pos] = cellNumber;
142 fAmplitude[pos] = amplitude;
143 fIsSorted = kFALSE;
144 return kTRUE;
145 } else {
146 return kFALSE;
147 }
148}