]>
Commit | Line | Data |
---|---|---|
46b33a24 | 1 | /************************************************************************** |
2 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
3 | * * | |
4 | * Authors: Matthias Richter <Matthias.Richter@ift.uib.no> * | |
5 | * for The ALICE Off-line Project. * | |
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 | /** @file AliHLTTPCPad.cxx | |
17 | @author Matthias Richter | |
18 | @date | |
19 | @brief Container Class for TPC Pads. | |
20 | */ | |
21 | ||
22 | #if __GNUC__>= 3 | |
23 | using namespace std; | |
24 | #endif | |
25 | ||
26 | #include <cerrno> | |
27 | #include "AliHLTTPCPad.h" | |
28 | ||
29 | /** margin for the base line be re-avaluated */ | |
30 | #define ALIHLTPAD_BASELINE_MARGIN (2*fAverage) | |
31 | ||
32 | /** ROOT macro for the implementation of ROOT specific class methods */ | |
33 | ClassImp(AliHLTTPCPad) | |
34 | ||
35 | AliHLTTPCPad::AliHLTTPCPad() | |
36 | : | |
37 | fRowNo(-1), | |
38 | fPadNo(-1), | |
39 | fThreshold(0), | |
40 | fAverage(-1), | |
41 | fNofEvents(0), | |
42 | fSum(0), | |
43 | fBLMax(-1), | |
44 | fBLMaxBin(-1), | |
45 | fCount(0), | |
46 | fTotal(0), | |
47 | fpRawData(NULL), | |
48 | fFirstBLBin(0), | |
49 | fNofBins(0), | |
50 | fReadPos(0) | |
51 | { | |
52 | } | |
53 | ||
54 | AliHLTTPCPad::AliHLTTPCPad(Int_t offset, Int_t nofBins) | |
55 | : | |
56 | fRowNo(-1), | |
57 | fPadNo(-1), | |
58 | fThreshold(0), | |
59 | fAverage(-1), | |
60 | fNofEvents(0), | |
61 | fSum(0), | |
62 | fBLMax(-1), | |
63 | fBLMaxBin(-1), | |
64 | fCount(0), | |
65 | fTotal(0), | |
66 | fpRawData(NULL), | |
67 | fFirstBLBin(offset), | |
68 | fNofBins(nofBins), | |
69 | fReadPos(0) | |
70 | { | |
71 | } | |
72 | ||
73 | AliHLTTPCPad::AliHLTTPCPad(const AliHLTTPCPad& srcPad) | |
74 | : | |
75 | fRowNo(srcPad.fRowNo), | |
76 | fPadNo(srcPad.fPadNo), | |
77 | fThreshold(0), | |
78 | fAverage(-1), | |
79 | fNofEvents(0), | |
80 | fSum(0), | |
81 | fBLMax(-1), | |
82 | fBLMaxBin(-1), | |
83 | fCount(0), | |
84 | fTotal(0), | |
85 | fpRawData(NULL), | |
86 | fFirstBLBin(0), | |
87 | fNofBins(0), | |
88 | fReadPos(0) | |
89 | { | |
90 | HLTFatal("copy constructor not implemented"); | |
91 | } | |
92 | ||
93 | AliHLTTPCPad& AliHLTTPCPad::operator=(const AliHLTTPCPad&) | |
94 | { | |
95 | HLTFatal("assignment operator not implemented"); | |
96 | return (*this); | |
97 | } | |
98 | ||
99 | AliHLTTPCPad::~AliHLTTPCPad() | |
100 | { | |
101 | if (fpRawData) { | |
102 | HLTWarning("event data acquisition not stopped"); | |
103 | StopEvent(); | |
104 | } | |
105 | } | |
106 | ||
107 | Int_t AliHLTTPCPad::SetID(Int_t rowno, Int_t padno) | |
108 | { | |
109 | fRowNo=rowno; | |
110 | fPadNo=padno; | |
111 | } | |
112 | ||
113 | Int_t AliHLTTPCPad::StartEvent() | |
114 | { | |
115 | Int_t iResult=0; | |
116 | if (fpRawData==NULL) { | |
117 | fBLMax=-1; | |
118 | fBLMaxBin=-1; | |
119 | fSum=0; | |
120 | fCount=0; | |
121 | fTotal=0; | |
122 | if (fNofBins>0) { | |
123 | fpRawData=new AliHLTTPCSignal_t[fNofBins]; | |
124 | if (fpRawData) { | |
125 | for (int i=0; i<fNofBins; i++) fpRawData[i]=-1; | |
126 | } else { | |
127 | HLTError("memory allocation failed"); | |
128 | iResult=-ENOMEM; | |
129 | } | |
130 | } | |
131 | } else { | |
132 | HLTWarning("event data acquisition already started"); | |
133 | iResult=-EALREADY; | |
134 | } | |
135 | return iResult; | |
136 | } | |
137 | ||
138 | Int_t AliHLTTPCPad::CalculateBaseLine(Int_t reqMinCount) | |
139 | { | |
140 | Int_t iResult=0; | |
141 | AliHLTTPCSignal_t avBackup=fAverage; | |
142 | if (fCount>=reqMinCount && fCount>=fTotal/2) { | |
143 | fAverage=fCount>0?fSum/fCount:0; | |
144 | if (fAverage>0) { | |
145 | HLTDebug("average for current event %f", fAverage); | |
146 | fCount=0;fSum=-1; | |
147 | if (fBLMax>ALIHLTPAD_BASELINE_MARGIN) { | |
148 | // calculate again | |
149 | HLTDebug("maximum value %f exceeds margin for base line %f " | |
150 | "-> re-evaluate base line", fBLMax, ALIHLTPAD_BASELINE_MARGIN); | |
151 | if (fpRawData) { | |
152 | for (Int_t i=fFirstBLBin; i<fNofBins; i++) | |
153 | if (fpRawData[i]>=0) AddBaseLineValue(i, fpRawData[i]); | |
154 | if (fCount>0 && fCount>=reqMinCount && fCount>=fTotal/2) { | |
155 | fAverage=fSum/fCount; | |
156 | HLTDebug("new average %f", fAverage); | |
157 | } else { | |
db16520a | 158 | HLTDebug("baseline re-eveluation skipped because of to few " |
46b33a24 | 159 | "contributing bins: total=%d, contributing=%d, req=%d" |
160 | "\ndata might be already zero suppressed" | |
161 | , fTotal, fCount, reqMinCount); | |
162 | iResult=-ENODATA; | |
163 | } | |
164 | fCount=0;fSum=-1; | |
165 | } else { | |
166 | HLTError("missing raw data for base line calculation"); | |
167 | iResult=-ENOBUFS; | |
168 | } | |
169 | } | |
170 | if (iResult>=0) { | |
171 | // calculate average for all events | |
172 | fAverage=((avBackup*fNofEvents)+fAverage)/(fNofEvents+1); | |
173 | HLTDebug("base line average for %d events: %f", fNofEvents+1, fAverage); | |
174 | } else { | |
175 | fAverage=avBackup; | |
176 | } | |
177 | } else { | |
178 | fAverage=avBackup; | |
179 | } | |
180 | } else { | |
db16520a | 181 | HLTDebug("baseline calculation skipped because of to few contributing " |
46b33a24 | 182 | "bins: total=%d, contributing=%d, required=%d \ndata might be " |
183 | "already zero suppressed", fTotal, fCount, reqMinCount); | |
184 | } | |
185 | ||
186 | return iResult; | |
187 | } | |
188 | ||
189 | Int_t AliHLTTPCPad::StopEvent() | |
190 | { | |
191 | Int_t iResult=0; | |
192 | if (fpRawData) { | |
193 | AliHLTTPCSignal_t* pData=fpRawData; | |
194 | fpRawData=NULL; | |
195 | delete [] pData; | |
196 | fTotal=0; | |
197 | fNofEvents++; | |
198 | Rewind(); | |
199 | } else if (fNofBins>0) { | |
200 | HLTError("event data acquisition not started"); | |
201 | iResult=-EBADF; | |
202 | } | |
203 | return iResult; | |
204 | } | |
205 | ||
206 | Int_t AliHLTTPCPad::ResetHistory() | |
207 | { | |
208 | Int_t iResult=0; | |
209 | fAverage=-1; | |
210 | fNofEvents=0; | |
211 | return iResult; | |
212 | } | |
213 | ||
214 | Int_t AliHLTTPCPad::SetThreshold(AliHLTTPCSignal_t thresh) | |
215 | { | |
216 | Int_t iResult=0; | |
217 | fThreshold=thresh; | |
218 | return iResult; | |
219 | } | |
220 | ||
221 | Int_t AliHLTTPCPad::AddBaseLineValue(Int_t bin, AliHLTTPCSignal_t value) | |
222 | { | |
223 | Int_t iResult=0; | |
224 | if (bin>=fFirstBLBin) { | |
225 | if (fAverage<0 || value<ALIHLTPAD_BASELINE_MARGIN) { | |
226 | // add to the current sum and count | |
227 | fSum+=value; | |
228 | fCount++; | |
229 | if (fBLMax<value) { | |
230 | // keep the maximum value for later quality control of the base | |
231 | // line calculation | |
232 | fBLMax=value; | |
233 | fBLMaxBin=bin; | |
234 | } | |
235 | } else { | |
236 | HLTDebug("ignoring value %f of bin %d for base line calculation " | |
237 | "- average %f", | |
238 | value, bin, fAverage); | |
239 | } | |
240 | } | |
241 | return iResult; | |
242 | } | |
243 | ||
244 | Int_t AliHLTTPCPad::SetRawData(Int_t bin, AliHLTTPCSignal_t value) | |
245 | { | |
246 | Int_t iResult=0; | |
247 | if (fpRawData) { | |
248 | if (bin<fNofBins) { | |
249 | if (value>=0) { | |
250 | if (fpRawData[bin]<0) { | |
251 | AddBaseLineValue(bin, value); | |
252 | fTotal++; | |
253 | } else { | |
254 | // ignore value for average calculation | |
255 | HLTWarning("overriding content of bin %d (%f)", bin, fpRawData[bin]); | |
256 | } | |
257 | fpRawData[bin]=value; | |
258 | } else { | |
259 | HLTWarning("ignoring neg. raw data"); | |
260 | } | |
261 | } else { | |
262 | HLTWarning("bin %d out of range (%d)", bin, fNofBins); | |
263 | iResult=-ERANGE; | |
264 | } | |
265 | } else if (fNofBins>0) { | |
266 | HLTError("event cycle not started"); | |
267 | iResult=-EBADF; | |
268 | } | |
269 | return iResult; | |
270 | } | |
271 | ||
272 | Int_t AliHLTTPCPad::Next(Int_t bZeroSuppression) | |
273 | { | |
274 | if (fpRawData==NULL) return 0; | |
275 | Int_t iResult=fReadPos<fNofBins; | |
276 | if (iResult>0 && (iResult=(++fReadPos<fNofBins))>0) { | |
277 | if (bZeroSuppression) { | |
278 | while ((iResult=(fReadPos<fNofBins))>0 && | |
279 | GetCorrectedData(fReadPos)<=0) | |
280 | fReadPos++; | |
281 | } | |
282 | } | |
283 | return iResult; | |
284 | } | |
285 | ||
286 | Int_t AliHLTTPCPad::Rewind(Int_t bZeroSuppression) | |
287 | { | |
288 | fReadPos=(bZeroSuppression>0?0:fFirstBLBin)-1; | |
289 | return Next(bZeroSuppression); | |
290 | } | |
291 | ||
292 | AliHLTTPCSignal_t AliHLTTPCPad::GetRawData(Int_t bin) const | |
293 | { | |
294 | AliHLTTPCSignal_t data=0; | |
295 | if (fpRawData) { | |
296 | if (bin<fNofBins) { | |
297 | data=fpRawData[bin]; | |
298 | } else { | |
299 | HLTWarning("requested bin %d out of range (%d)", bin, fNofBins); | |
300 | } | |
301 | } else if (fNofBins>0) { | |
302 | HLTWarning("data only available within event cycle"); | |
303 | } | |
304 | return data; | |
305 | } | |
306 | ||
307 | AliHLTTPCSignal_t AliHLTTPCPad::GetCorrectedData(Int_t bin) const | |
308 | { | |
309 | AliHLTTPCSignal_t data=GetRawData(bin)-GetBaseLine(bin); | |
310 | if (fThreshold>0) data-=fThreshold; | |
311 | if (data<0) data=0; | |
312 | if (bin<fFirstBLBin) data=0; | |
313 | return data; | |
314 | } | |
315 | ||
316 | AliHLTTPCSignal_t AliHLTTPCPad::GetBaseLine(Int_t bin) const | |
317 | { | |
318 | return fAverage>0?fAverage:0; | |
319 | } | |
320 | ||
321 | AliHLTTPCSignal_t AliHLTTPCPad::GetAverage() const | |
322 | { | |
323 | return fAverage>0?fAverage:0; | |
324 | } | |
325 |