Line data Source code
1 : /**************************************************************************
2 : * Copyright(c) 1998-2016, 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 : #include <AliHLTEMCALCaloCells.h>
17 :
18 : /// \cond CLASSIMP
19 6 : ClassImp(AliHLTEMCALCaloCells);
20 : /// \endcond
21 :
22 : /// Default constructor.
23 : AliHLTEMCALCaloCells::AliHLTEMCALCaloCells() :
24 0 : AliVCaloCells(), fCapacity(0), fNCells(0),
25 0 : fAmplitude(0), fType(kUndef)
26 0 : {
27 0 : }
28 :
29 : /// Named constructor.
30 : /// \param name Name of the object
31 : /// \param title Title of the object
32 : /// \param ttype Cell type (EMCal, PHOS)
33 : AliHLTEMCALCaloCells::AliHLTEMCALCaloCells(const char* name, const char* title, VCells_t ttype) :
34 0 : AliVCaloCells(name, title), fCapacity(0), fNCells(0),
35 0 : fAmplitude(0), fType(kUndef)
36 0 : {
37 0 : }
38 :
39 : /// Copy constructor.
40 : /// \param c Const reference to copy from
41 : AliHLTEMCALCaloCells::AliHLTEMCALCaloCells(const AliHLTEMCALCaloCells& c) :
42 0 : AliVCaloCells(c), fCapacity(c.fCapacity), fNCells(c.fNCells),
43 0 : fAmplitude(0), fType(kUndef)
44 0 : {
45 0 : fAmplitude = new Double_t[fCapacity];
46 :
47 0 : memcpy(fAmplitude, c.fAmplitude, sizeof(Double_t)*fCapacity);
48 0 : }
49 :
50 :
51 : /// Assignment operator.
52 : /// \param source Const reference to copy from
53 : /// \return Reference to this
54 : AliHLTEMCALCaloCells & AliHLTEMCALCaloCells::operator =(const AliHLTEMCALCaloCells& source)
55 : {
56 0 : if (this != &source) {
57 0 : AliVCaloCells::operator=(source);
58 :
59 0 : if (fCapacity != source.fCapacity) {
60 0 : delete[] fAmplitude;
61 0 : fCapacity = source.fCapacity;
62 :
63 0 : fAmplitude = new Double_t[fCapacity];
64 0 : }
65 :
66 0 : fNCells = source.fNCells;
67 0 : memcpy(fAmplitude, source.fAmplitude, sizeof(Double_t)*fCapacity);
68 0 : }
69 :
70 0 : return *this;
71 : }
72 :
73 : /// This overwrites the virtual TObject::Copy()
74 : /// to allow run time copying without casting
75 : void AliHLTEMCALCaloCells::Copy(TObject &obj) const
76 : {
77 0 : if(this==&obj)return;
78 0 : AliHLTEMCALCaloCells *robj = dynamic_cast<AliHLTEMCALCaloCells*>(&obj);
79 0 : if (!robj) return; // not an AliHLTCaloCells
80 0 : *robj = *this;
81 0 : }
82 :
83 : /// Copy the calo cells into a new object. If option all=FALSE, just the object type,
84 : /// for mixing.
85 : AliVCaloCells* AliHLTEMCALCaloCells::CopyCaloCells(Bool_t all = kTRUE) const
86 : {
87 0 : AliVCaloCells *obj = new AliHLTEMCALCaloCells(*this);
88 :
89 0 : return obj;
90 0 : }
91 :
92 : /// Destructor.
93 : AliHLTEMCALCaloCells::~AliHLTEMCALCaloCells()
94 0 : {
95 0 : DeleteContainer();
96 0 : }
97 :
98 : /// Clear number of cells.
99 : void AliHLTEMCALCaloCells::Clear(Option_t*)
100 : {
101 0 : TObject::Clear();
102 :
103 0 : memset(fAmplitude, 0, sizeof(Double_t)*fCapacity);
104 :
105 0 : fNCells = 0;
106 0 : }
107 :
108 : /// Function that creates container to store calorimeter cell data.
109 : /// The current content of the container is reset.
110 : /// \param nCells capacity of the container
111 : void AliHLTEMCALCaloCells::CreateContainer(Short_t nCells)
112 : {
113 0 : if (fCapacity != nCells) {
114 0 : delete[] fAmplitude;
115 0 : fCapacity = nCells;
116 0 : fAmplitude = new Double_t[fCapacity];
117 0 : }
118 :
119 0 : Clear();
120 0 : }
121 :
122 : /// Deletes allocated memory
123 : void AliHLTEMCALCaloCells::DeleteContainer()
124 : {
125 0 : delete[] fAmplitude;
126 0 : fAmplitude = 0;
127 0 : fCapacity = 0;
128 0 : fNCells = 0;
129 0 : }
130 :
131 : /// Sets a cell at the given position.
132 : /// \param pos: cell position in array.
133 : /// \param amplitude: Cell signal (GeV).
134 : /// \return true on success
135 : Bool_t AliHLTEMCALCaloCells::SetCell(Short_t pos, Short_t /*cellNumber*/, Double_t amplitude,
136 : Double_t /*time*/, Int_t /*mclabel*/, Double_t /*efrac*/, Bool_t /*isHG*/)
137 : {
138 0 : if (pos < 0 || pos >= fCapacity) return kFALSE;
139 :
140 0 : if (amplitude == 0 && fAmplitude[pos] > 0 && fNCells > 0) {
141 0 : fNCells--;
142 0 : }
143 0 : else if (amplitude > 0 && fAmplitude[pos] == 0) {
144 0 : fNCells++;
145 0 : }
146 :
147 0 : fAmplitude[pos] = amplitude;
148 :
149 0 : return kTRUE;
150 0 : }
151 :
152 : /// Add energy to a cell at the given position.
153 : /// \param pos: cell position in array.
154 : /// \param amplitude: Cell signal (GeV).
155 : /// \return true on success
156 : Bool_t AliHLTEMCALCaloCells::AddCell(Short_t pos, Double_t amplitude)
157 : {
158 0 : if (pos < 0 || pos >= fCapacity) {
159 0 : Printf(Form("ERROR-AliHLTEMCALCaloCells::AddCell - Could not add energy of cell %d (capacity is %d)", pos, fCapacity));
160 0 : return kFALSE;
161 : }
162 :
163 0 : if (amplitude > 0 && fAmplitude[pos] == 0) {
164 0 : fNCells++;
165 0 : }
166 :
167 0 : fAmplitude[pos] += amplitude;
168 :
169 0 : return kTRUE;
170 0 : }
171 :
172 : /// Function that creates container to store calorimeter cell data.
173 : /// The current content of the container is reset.
174 : /// \param nCells capacity of the container
175 : void AliHLTEMCALCaloCells::SetNumberOfCells(Int_t n)
176 : {
177 0 : CreateContainer(n);
178 0 : }
|