]>
Commit | Line | Data |
---|---|---|
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 | ||
25 | ClassImp(AliAODCaloCells) | |
26 | ||
27 | AliAODCaloCells::AliAODCaloCells() : TNamed(), fNCells(0), fCellNumber(0), fAmplitude(0), fIsSorted(kTRUE), fType(kUndef) | |
28 | { | |
29 | // default constructor | |
30 | } | |
31 | ||
e649177a | 32 | AliAODCaloCells::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 | 37 | AliAODCaloCells::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 | ||
56 | AliAODCaloCells& 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 | 69 | AliAODCaloCells::~AliAODCaloCells() |
70 | { | |
71 | // destructor | |
72 | ||
73 | DeleteContainer(); | |
74 | } | |
75 | ||
76 | void 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]; | |
341952b8 | 91 | // set to zero |
92 | for(int i = 0;i<fNCells;++i){ | |
93 | fAmplitude[i] = fCellNumber[i] = 0; | |
94 | } | |
8d122774 | 95 | } |
96 | ||
97 | void AliAODCaloCells::DeleteContainer() | |
98 | { | |
99 | // deletes allocated memory | |
100 | ||
101 | if (fCellNumber) | |
102 | { | |
103 | delete[] fCellNumber; | |
104 | fCellNumber = 0; | |
105 | } | |
106 | ||
107 | if (fAmplitude) | |
108 | { | |
109 | delete[] fAmplitude; | |
110 | fAmplitude = 0; | |
111 | } | |
112 | ||
113 | fNCells = 0; | |
114 | fIsSorted = kFALSE; | |
115 | } | |
116 | ||
117 | void AliAODCaloCells::Sort() | |
118 | { | |
119 | // sort the cell array by cell number | |
120 | ||
121 | Int_t *idxArray = new Int_t[fNCells]; | |
122 | TMath::Sort(fNCells,fCellNumber,idxArray,kFALSE); | |
123 | ||
124 | Short_t *newIndex = new Short_t[fNCells]; | |
125 | Double32_t *newAmplitude = new Double32_t[fNCells]; | |
126 | for (Int_t i=0; i < fNCells; i++) { | |
127 | newIndex[i] = fCellNumber[idxArray[i]]; | |
128 | newAmplitude[i] = fAmplitude[idxArray[i]]; | |
129 | } | |
130 | delete [] fCellNumber; | |
131 | delete [] fAmplitude; | |
132 | fCellNumber = newIndex; | |
133 | fAmplitude = newAmplitude; | |
134 | ||
135 | delete [] idxArray; | |
136 | ||
137 | fIsSorted = kTRUE; | |
138 | } | |
139 | ||
140 | Bool_t AliAODCaloCells::SetCell(Short_t pos, Short_t cellNumber, Double32_t amplitude) | |
141 | { | |
142 | // Sets a cell at the given position | |
143 | ||
144 | if (pos>=0 && pos < fNCells) { | |
145 | fCellNumber[pos] = cellNumber; | |
146 | fAmplitude[pos] = amplitude; | |
147 | fIsSorted = kFALSE; | |
148 | return kTRUE; | |
149 | } else { | |
150 | return kFALSE; | |
151 | } | |
152 | } |