]>
Commit | Line | Data |
---|---|---|
a6c02c85 | 1 | // @(#) $Id$ |
2 | ||
3 | // Author: C. Loizides <loizides@ikf.uni-frankfurt.de> | |
4 | //*-- Copyright © ALICE HLT Group | |
5 | ||
a6c02c85 | 6 | #include "AliHLTTPCRootTypes.h" |
7 | #include "AliHLTTPCLogging.h" | |
8 | #include "AliHLTTPCTransform.h" | |
9 | #include "AliHLTTPCMemHandler.h" | |
10 | #include "AliHLTTPCDigitData.h" | |
a6c02c85 | 11 | #include "AliRawReaderRoot.h" |
12 | #include "AliRawReaderDate.h" | |
a6c02c85 | 13 | #include "AliHLTTPCDDLDataFileHandler.h" |
14 | ||
db16520a | 15 | #if __GNUC__ >= 3 |
a6c02c85 | 16 | using namespace std; |
17 | #endif | |
18 | ||
19 | /** \class AliHLTTPCDDLDataFileHandler | |
20 | <pre> | |
21 | //_____________________________________________________________ | |
22 | // AliHLTTPCDDLDataFileHandler | |
23 | // | |
24 | // This class does converts from the DDL format of offline | |
25 | // into the memory I/O handling of the HLT binary files. | |
26 | // | |
27 | // Examples: see ddl2binary in exa and the general | |
28 | // AliHLTTPCMemHandler class description | |
29 | // | |
30 | </pre> | |
31 | */ | |
32 | ||
33 | ClassImp(AliHLTTPCDDLDataFileHandler) | |
34 | ||
35 | AliHLTTPCDDLDataFileHandler::AliHLTTPCDDLDataFileHandler() | |
36 | { | |
37 | // default constructor | |
38 | fReader=0; | |
39 | fTPCStream=0; | |
40 | } | |
41 | ||
42 | AliHLTTPCDDLDataFileHandler::~AliHLTTPCDDLDataFileHandler() | |
43 | { | |
44 | // destructor | |
45 | FreeAll(); | |
46 | } | |
47 | ||
48 | void AliHLTTPCDDLDataFileHandler::FreeAll() | |
49 | { | |
50 | // frees all heap memory | |
51 | if(fReader) delete fReader; | |
52 | fReader = 0; | |
53 | if(fTPCStream) delete fTPCStream; | |
54 | fTPCStream = 0; | |
55 | } | |
56 | ||
57 | ||
a6c02c85 | 58 | Bool_t AliHLTTPCDDLDataFileHandler::SetReaderInput(AliRawEvent *rawevent) |
59 | { | |
60 | // sets the input of the reader | |
61 | fEvent=-1; | |
62 | fFilename=""; | |
63 | if(fReader) delete fReader; | |
64 | fReader=new AliRawReaderRoot(rawevent); | |
65 | if(fTPCStream) delete fTPCStream; | |
66 | fTPCStream=new AliTPCRawStream(fReader); | |
67 | ||
68 | return kTRUE; | |
69 | } | |
70 | ||
71 | Bool_t AliHLTTPCDDLDataFileHandler::SetReaderInput(Char_t *name,Int_t event) | |
72 | { | |
73 | // sets the input of the reader | |
74 | fEvent=event; | |
75 | if(fReader) delete fReader; | |
76 | if(fTPCStream) delete fTPCStream; | |
77 | if(event>=0){ | |
78 | fFilename=name; | |
79 | fReader=new AliRawReaderRoot(name,event); | |
80 | } else { | |
81 | fFilename=""; | |
82 | fReader=new AliRawReaderDate((void *)name); | |
83 | } | |
84 | fTPCStream=new AliTPCRawStream(fReader); | |
85 | ||
86 | return kTRUE; | |
87 | } | |
a6c02c85 | 88 | |
89 | void AliHLTTPCDDLDataFileHandler::CloseReaderInput() | |
90 | { | |
91 | // closes the input of the reader | |
92 | if(!fReader){ | |
93 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCRawDataFileHandler::CloseReaderInput","File Close") | |
94 | <<"Nothing to Close"<<ENDLOG; | |
95 | return; | |
96 | } | |
97 | ||
98 | delete fReader; | |
99 | delete fTPCStream; | |
100 | fReader = 0; | |
101 | fTPCStream = 0; | |
102 | } | |
103 | ||
a6c02c85 | 104 | Bool_t AliHLTTPCDDLDataFileHandler::IsDigit(Int_t /*i*/) const |
105 | { | |
106 | // dummy | |
107 | return kTRUE; | |
108 | } | |
a6c02c85 | 109 | |
110 | #ifndef fast_raw | |
111 | AliHLTTPCDigitRowData * AliHLTTPCDDLDataFileHandler::DDLData2Memory(UInt_t &nrow,Int_t event) | |
112 | { | |
113 | // transfers the DDL data to the memory | |
a6c02c85 | 114 | if((fEvent>=0)&&(event!=fEvent)){ |
115 | fEvent=event; | |
116 | if(fReader) delete fReader; | |
117 | if(fTPCStream) delete fTPCStream; | |
118 | fReader=new AliRawReaderRoot(fFilename,event); | |
119 | fTPCStream=new AliTPCRawStream(fReader); | |
120 | } | |
a6c02c85 | 121 | AliHLTTPCDigitRowData *data = 0; |
122 | nrow=0; | |
123 | ||
124 | if(!fReader){ | |
125 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCDDLDataFileHandler::DDLData2Memory","File") | |
126 | <<"No Input avalible: no object AliHLTTPCDDLRawReaderFile"<<ENDLOG; | |
127 | return 0; | |
128 | } | |
129 | ||
130 | Int_t nrows=fRowMax-fRowMin+1; | |
131 | Int_t ndigitcount=0; | |
132 | Int_t * ndigits = new Int_t[nrows]; | |
133 | UShort_t ***charges=new UShort_t**[nrows]; | |
134 | for(Int_t r=fRowMin;r<=fRowMax;r++){ | |
135 | Int_t lrow=r-fRowMin; | |
136 | charges[lrow]=new UShort_t*[AliHLTTPCTransform::GetNPads(r)]; | |
137 | for(Int_t k=0;k<AliHLTTPCTransform::GetNPads(r);k++){ | |
138 | charges[lrow][k]=new UShort_t[AliHLTTPCTransform::GetNTimeBins()]; | |
139 | for(Int_t j=0;j<AliHLTTPCTransform::GetNTimeBins();j++) charges[lrow][k][j]=0; | |
140 | } | |
141 | } | |
142 | ||
143 | Int_t ddlsToSearch=0; | |
144 | Int_t ddls[9]={-1,-1,-1,-1,-1,-1,-1,-1,-1}; | |
145 | Int_t ddlid=-1,lddlid=-1; | |
146 | for(Int_t r=fRowMin;r<=fRowMax;r++){ | |
147 | ndigits[r-fRowMin] = 0; //now digits on row | |
148 | ||
149 | Int_t patch=AliHLTTPCTransform::GetPatch(r); | |
150 | Int_t sector,row; | |
151 | AliHLTTPCTransform::Slice2Sector(fSlice,r,sector,row); | |
152 | ||
153 | if(sector<36) //taken from AliTPCBuffer160.cxx | |
154 | ddlid=sector*2+patch; | |
155 | else | |
156 | ddlid=70+(sector-36)*4+patch; | |
157 | ||
158 | if((lddlid!=ddlid-1)&&(r==30)){ //dont forget the split row on the last ddl | |
159 | ddls[ddlsToSearch++]=ddlid-1; | |
160 | lddlid=ddlid-1; | |
161 | } | |
162 | ||
163 | if((lddlid==-1)||(ddlid!=lddlid)){ | |
164 | ddls[ddlsToSearch++]=ddlid; | |
165 | lddlid=ddlid; | |
166 | } | |
167 | if((r==90)||(r==139)){ //dont forget the split row on the next ddl | |
168 | ddls[ddlsToSearch++]=ddlid+1; | |
169 | lddlid=ddlid+1; | |
170 | } | |
171 | } | |
172 | ||
173 | // for(Int_t i=0;i<ddlsToSearch;i++) cout << ddls[i] <<endl; | |
174 | ||
175 | if(ddls[0]>ddls[ddlsToSearch-1]) { | |
176 | Int_t tempddl = ddls[0]; | |
177 | ddls[0] = ddls[ddlsToSearch-1]; | |
178 | ddls[ddlsToSearch-1] = tempddl; | |
179 | } | |
a6c02c85 | 180 | fReader->Reset(); |
181 | fReader->Select(0,ddls[0],ddls[ddlsToSearch-1]); | |
182 | fTPCStream->Reset(); | |
a6c02c85 | 183 | Int_t zerosup = AliHLTTPCTransform::GetZeroSup(); |
184 | Int_t adcsat = AliHLTTPCTransform::GetADCSat(); | |
185 | Int_t slice,srow; | |
186 | Int_t lrow=-1; | |
187 | ||
188 | while (fTPCStream->Next()){ | |
189 | ||
190 | if(fTPCStream->IsNewSector() || fTPCStream->IsNewRow()) { | |
191 | Int_t sector=fTPCStream->GetSector(); | |
192 | Int_t row=fTPCStream->GetRow(); | |
193 | AliHLTTPCTransform::Sector2Slice(slice,srow,sector,row); | |
194 | if(slice!=fSlice){ | |
195 | LOG(AliHLTTPCLog::kError,"AliHLTTPCDDLDataFileHandler::DDLDigits2Memory","Slice") | |
196 | <<AliHLTTPCLog::kDec<<"Found slice "<<slice<<", expected "<<fSlice<<ENDLOG; | |
197 | continue; | |
198 | } | |
199 | lrow=srow-fRowMin; | |
200 | } | |
201 | ||
202 | //test row criteria (patch boundaries) | |
203 | if((srow<fRowMin)||(srow>fRowMax))continue; | |
204 | ||
205 | Int_t pad=fTPCStream->GetPad(); | |
206 | if(fTPCStream->IsNewPad()) { | |
207 | if((pad<0)||(pad>=AliHLTTPCTransform::GetNPads(srow))){ | |
208 | LOG(AliHLTTPCLog::kError,"AliHLTTPCDDLDataFileHandler::DDLDigits2Memory","Pad") | |
209 | <<AliHLTTPCLog::kDec<<"Pad value out of bounds "<<pad<<" " | |
210 | <<AliHLTTPCTransform::GetNPads(srow)<<ENDLOG; | |
211 | continue; | |
212 | } | |
213 | } | |
214 | ||
215 | Int_t time=fTPCStream->GetTime(); | |
216 | if((time<0)||(time>=AliHLTTPCTransform::GetNTimeBins())){ | |
217 | LOG(AliHLTTPCLog::kError,"AliHLTTPCDDLDataFileHandler::DDLDigits2Memory","Time") | |
218 | <<AliHLTTPCLog::kDec<<"Time out of bounds "<<time<<" " | |
219 | <<AliHLTTPCTransform::GetNTimeBins()<<ENDLOG; | |
220 | continue; | |
221 | } | |
222 | ||
223 | //store digit | |
224 | UShort_t dig=fTPCStream->GetSignal(); | |
225 | if(dig <= zerosup) continue; | |
226 | if(dig >= adcsat) dig = adcsat; | |
227 | ||
228 | ndigits[lrow]++; //for this row only | |
229 | ndigitcount++; //total number of digits to be published | |
230 | ||
231 | charges[lrow][pad][time]=dig; | |
232 | } | |
233 | ||
234 | Int_t size = sizeof(AliHLTTPCDigitData)*ndigitcount | |
235 | + nrows*sizeof(AliHLTTPCDigitRowData); | |
236 | ||
237 | LOG(AliHLTTPCLog::kDebug,"AliHLTTPCDDLDataFileHandler::DDLDigits2Memory","Digits") | |
238 | <<AliHLTTPCLog::kDec<<"Found "<<ndigitcount<<" Digits"<<ENDLOG; | |
239 | ||
240 | data=(AliHLTTPCDigitRowData*) Allocate(size); | |
241 | nrow = (UInt_t)nrows; | |
242 | AliHLTTPCDigitRowData *tempPt = data; | |
243 | ||
244 | for(Int_t r=fRowMin;r<=fRowMax;r++){ | |
245 | Int_t lrow=r-fRowMin; | |
246 | tempPt->fRow = r; | |
247 | tempPt->fNDigit = ndigits[lrow]; | |
248 | ||
249 | Int_t localcount=0; | |
250 | for(Int_t pad=0;pad<AliHLTTPCTransform::GetNPads(r);pad++){ | |
251 | for(Int_t time=0;time<AliHLTTPCTransform::GetNTimeBins();time++){ | |
252 | UShort_t dig=charges[lrow][pad][time]; | |
253 | if(!dig) continue; | |
254 | ||
255 | if(localcount >= ndigits[lrow]) | |
256 | LOG(AliHLTTPCLog::kFatal,"AliHLTTPCDDLDataFileHandler::DDLDigits2Binary","Memory") | |
257 | <<AliHLTTPCLog::kDec<<"Mismatch: localcount "<<localcount<<" ndigits " | |
258 | <<ndigits[lrow]<<ENDLOG; | |
259 | ||
260 | ||
261 | tempPt->fDigitData[localcount].fCharge=dig; | |
262 | tempPt->fDigitData[localcount].fPad=pad; | |
263 | tempPt->fDigitData[localcount].fTime=time; | |
264 | #ifdef do_mc | |
265 | tempPt->fDigitData[localcount].fTrackID[0] = 0; | |
266 | tempPt->fDigitData[localcount].fTrackID[1] = 0; | |
267 | tempPt->fDigitData[localcount].fTrackID[2] = 0; | |
268 | #endif | |
269 | localcount++; | |
270 | } | |
271 | } | |
272 | ||
273 | if(localcount != ndigits[lrow]) | |
274 | LOG(AliHLTTPCLog::kFatal,"AliHLTTPCDDLDataFileHandler::DDLDigits2Binary","Memory") | |
275 | <<AliHLTTPCLog::kDec<<"Mismatch: localcount "<<localcount<<" ndigits " | |
276 | <<ndigits[lrow]<<ENDLOG; | |
277 | ||
278 | ||
279 | Byte_t *tmp = (Byte_t*)tempPt; | |
280 | Int_t size = sizeof(AliHLTTPCDigitRowData) | |
281 | + ndigits[lrow]*sizeof(AliHLTTPCDigitData); | |
282 | tmp += size; | |
283 | tempPt = (AliHLTTPCDigitRowData*)tmp; | |
284 | } | |
285 | ||
286 | //delete charge array | |
287 | for(Int_t r=fRowMin;r<=fRowMax;r++){ | |
288 | Int_t lrow=r-fRowMin; | |
289 | for(Int_t k=0;k<AliHLTTPCTransform::GetNPads(r);k++) | |
290 | delete charges[lrow][k]; | |
291 | delete charges[lrow]; | |
292 | } | |
293 | delete charges; | |
294 | delete [] ndigits; | |
295 | ||
296 | return data; | |
297 | } | |
298 | #else | |
299 | AliHLTTPCDigitRowData * AliHLTTPCDDLDataFileHandler::DDLData2Memory(UInt_t &nrow,Int_t event) | |
300 | { | |
301 | // transfers the DDL data to the memory | |
a6c02c85 | 302 | if((fEvent>=0)&&(event!=fEvent)){ |
303 | fEvent=event; | |
304 | if(fReader) delete fReader; | |
305 | if(fTPCStream) delete fTPCStream; | |
306 | fReader=new AliRawReaderRoot(fFilename,event); | |
307 | fTPCStream=new AliTPCRawStream(fReader); | |
308 | } | |
a6c02c85 | 309 | AliHLTTPCDigitRowData *data = 0; |
310 | nrow=0; | |
311 | ||
312 | if(!fReader){ | |
313 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCDDLDataFileHandler::DDLData2Memory","File") | |
314 | <<"No Input avalible: no object AliHLTTPCDDLRawReaderFile"<<ENDLOG; | |
315 | return 0; | |
316 | } | |
317 | ||
318 | Int_t nrows=fRowMax-fRowMin+1; | |
319 | ||
320 | Int_t ddlsToSearch=0; | |
321 | Int_t ddls[9]={-1,-1,-1,-1,-1,-1,-1,-1,-1}; | |
322 | Int_t ddlid=-1,lddlid=-1; | |
323 | for(Int_t r=fRowMin;r<=fRowMax;r++){ | |
324 | ||
325 | Int_t patch=AliHLTTPCTransform::GetPatch(r); | |
326 | Int_t sector,row; | |
327 | AliHLTTPCTransform::Slice2Sector(fSlice,r,sector,row); | |
328 | ||
329 | if(sector<36) //taken from AliTPCBuffer160.cxx | |
330 | ddlid=sector*2+patch; | |
331 | else | |
332 | ddlid=70+(sector-36)*4+patch; | |
333 | ||
334 | if((lddlid==-1)||(ddlid!=lddlid)){ | |
335 | ddls[ddlsToSearch++]=ddlid; | |
336 | lddlid=ddlid; | |
337 | } | |
338 | } | |
339 | ||
340 | // for(Int_t i=0;i<ddlsToSearch;i++) cout << ddls[i] <<endl; | |
341 | ||
a6c02c85 | 342 | fReader->Reset(); |
343 | fReader->Select(0,ddls[0],ddls[ddlsToSearch-1]); | |
344 | fTPCStream->Reset(); | |
a6c02c85 | 345 | |
346 | nrow = (UInt_t)nrows; | |
347 | ||
348 | return data; | |
349 | } | |
350 | #endif | |
351 | ||
352 | Bool_t AliHLTTPCDDLDataFileHandler::DDLData2CompBinary(Int_t event) | |
353 | { | |
354 | // transfers the DDL data to the memory and converts it | |
355 | // to comp binary | |
356 | Bool_t out = kTRUE; | |
357 | UInt_t ndigits=0; | |
358 | AliHLTTPCDigitRowData *digits=0; | |
359 | digits = DDLData2Memory(ndigits,event); | |
360 | out = Memory2CompBinary(ndigits,digits); | |
361 | Free(); | |
362 | return out; | |
363 | } |