]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/misc/AliL3DDLDataFileHandler.cxx
Taking into account the dE/dx crossing points in the TPC (Yu.Belikov)
[u/mrichter/AliRoot.git] / HLT / misc / AliL3DDLDataFileHandler.cxx
CommitLineData
240d63be 1// @(#) $Id$
2
3// Author: C. Loizides <loizides@ikf.uni-frankfurt.de>
4//*-- Copyright &copy ALICE HLT Group
5
6#include "AliL3StandardIncludes.h"
7
8#include "AliL3RootTypes.h"
9#include "AliL3Logging.h"
10#include "AliL3Transform.h"
11#include "AliL3MemHandler.h"
12#include "AliL3DigitData.h"
b2a02bce 13#ifdef use_newio
a27af97b 14#include "../RAW/AliRawReaderRoot.h"
045549b7 15#include "../RAW/AliRawReaderDate.h"
b2a02bce 16#else
17#include "AliL3DDLTPCRawStream.h"
18#include "AliL3DDLRawReaderFile.h"
19#endif
240d63be 20#include "AliL3DDLDataFileHandler.h"
21
0bd0c1ef 22#if __GNUC__ == 3
240d63be 23using namespace std;
24#endif
25
26/** \class AliL3DDLDataFileHandler
27<pre>
28//_____________________________________________________________
29// AliL3DDLDataFileHandler
30//
31// This class does converts from the DDL format of offline
32// into the memory I/O handling of the HLT binary files.
33//
34// Examples: see ddl2binary in exa and the general
35// AliL3MemHandler class description
36//
37</pre>
38*/
39
40ClassImp(AliL3DDLDataFileHandler)
41
42AliL3DDLDataFileHandler::AliL3DDLDataFileHandler()
43{
44 fReader=0;
45 fTPCStream=0;
46}
47
48AliL3DDLDataFileHandler::~AliL3DDLDataFileHandler()
49{
50 FreeAll();
51}
52
53void AliL3DDLDataFileHandler::FreeAll()
54{
55 if(fReader) delete fReader;
56 if(fTPCStream) delete fTPCStream;
57 fReader = 0;
58 fTPCStream = 0;
59}
60
61
b2a02bce 62#ifdef use_newio
a27af97b 63Bool_t AliL3DDLDataFileHandler::SetReaderInput(Char_t *name,Int_t event)
240d63be 64{
a27af97b 65 fEvent=event;
66 if(fReader) delete fReader;
67 if(fTPCStream) delete fTPCStream;
045549b7 68 if(event>=0){
69 fFilename=name;
70 fReader=new AliRawReaderRoot(name,event);
71 } else {
72 fFilename="";
73 fReader=new AliRawReaderDate(name);
74 }
a27af97b 75 fTPCStream=new AliTPCRawStream(fReader);
240d63be 76
77 return kTRUE;
78}
b2a02bce 79#else
80Bool_t AliL3DDLDataFileHandler::SetReaderInput(Char_t *name, Bool_t add)
81{
82 if(fReader){
83 LOG(AliL3Log::kError,"AliL3DDLDataFileHandler::SetReaderInput","File Open")
84 <<"Reader ptr is already in use"<<ENDLOG;
85 return kFALSE;
86 }
87
88 fReader=new AliL3DDLRawReaderFile(name,add);
89 fTPCStream=new AliL3DDLTPCRawStream(fReader);
90
91 return kTRUE;
92}
93Bool_t AliL3DDLDataFileHandler::SetReaderInput(AliL3DDLRawReaderFile *rf)
94{
95 if(fReader){
96 LOG(AliL3Log::kError,"AliL3RawDataFileHandler::SetReaderInput","File Open")
97 <<"Reader ptr is already in use, delete it first"<<ENDLOG;
98 return kFALSE;
99 }
100
101 //Open the raw data file with given file.
102 fReader = rf;
103 fTPCStream=new AliL3DDLTPCRawStream(fReader);
104
105 return kTRUE;
106}
107#endif
240d63be 108
109void AliL3DDLDataFileHandler::CloseReaderInput()
110{
111 if(!fReader){
112 LOG(AliL3Log::kWarning,"AliL3RawDataFileHandler::CloseReaderInput","File Close")
113 <<"Nothing to Close"<<ENDLOG;
114 return;
115 }
116
117 delete fReader;
118 delete fTPCStream;
119 fReader = 0;
120 fTPCStream = 0;
121}
122
b2a02bce 123#ifdef use_newio
dd7d3870 124Bool_t AliL3DDLDataFileHandler::IsDigit(Int_t /*i*/)
a27af97b 125{
126 return kTRUE;
127}
b2a02bce 128#endif
a27af97b 129
240d63be 130AliL3DigitRowData * AliL3DDLDataFileHandler::DDLData2Memory(UInt_t &nrow,Int_t event)
a27af97b 131{
b2a02bce 132#ifdef use_newio
045549b7 133 if((fEvent>=0)&&(event!=fEvent)){
a27af97b 134 fEvent=event;
135 if(fReader) delete fReader;
136 if(fTPCStream) delete fTPCStream;
137 fReader=new AliRawReaderRoot(fFilename,event);
138 fTPCStream=new AliTPCRawStream(fReader);
139 }
b2a02bce 140#endif
240d63be 141 AliL3DigitRowData *data = 0;
142 nrow=0;
143
144 if(!fReader){
145 LOG(AliL3Log::kWarning,"AliL3DDLDataFileHandler::DDLData2Memory","File")
146 <<"No Input avalible: no object AliL3DDLRawReaderFile"<<ENDLOG;
147 return 0;
148 }
149
150 Int_t nrows=fRowMax-fRowMin+1;
151 Int_t ndigitcount=0;
62bb4b3d 152 Int_t * ndigits = new Int_t[nrows];
240d63be 153 UShort_t ***charges=new UShort_t**[nrows];
154 for(Int_t r=fRowMin;r<=fRowMax;r++){
155 Int_t lrow=r-fRowMin;
156 charges[lrow]=new UShort_t*[AliL3Transform::GetNPads(r)];
157 for(Int_t k=0;k<AliL3Transform::GetNPads(r);k++){
158 charges[lrow][k]=new UShort_t[AliL3Transform::GetNTimeBins()];
159 for(Int_t j=0;j<AliL3Transform::GetNTimeBins();j++) charges[lrow][k][j]=0;
160 }
161 }
162
163 Int_t ddls_to_search=0;
164 Int_t ddls[9]={-1,-1,-1,-1,-1,-1,-1,-1,-1};
165 Int_t ddlid=-1,lddlid=-1;
166 for(Int_t r=fRowMin;r<=fRowMax;r++){
167 ndigits[r-fRowMin] = 0; //now digits on row
168
169 Int_t patch=AliL3Transform::GetPatch(r);
170 Int_t sector,row;
171 AliL3Transform::Slice2Sector(fSlice,r,sector,row);
172
173 if(sector<36) //taken from AliTPCBuffer160.cxx
174 ddlid=sector*2+patch;
175 else
176 ddlid=70+(sector-36)*4+patch;
177
178 if((lddlid!=ddlid-1)&&(r==30)){ //dont forget the split row on the last ddl
179 ddls[ddls_to_search++]=ddlid-1;
180 lddlid=ddlid-1;
181 }
182 if((lddlid==-1)||(ddlid!=lddlid)){
183 ddls[ddls_to_search++]=ddlid;
184 lddlid=ddlid;
185 }
186 if((r==90)||(r==139)){ //dont forget the split row on the next ddl
187 ddls[ddls_to_search++]=ddlid+1;
188 lddlid=ddlid+1;
189 }
190 }
191 //for(Int_t i=0;i<ddls_to_search;i++) cout << ddls[i] <<endl;
192
193 for(Int_t i=0;i<ddls_to_search;i++){
b2a02bce 194#ifdef use_newio
a27af97b 195 fReader->Reset();
196 fReader->Select(0,ddls[i],ddls[i]+1);
b2a02bce 197#else
198 fTPCStream->SetDDLID(ddls[i]); //ddl to read out
199#endif
a27af97b 200
b2a02bce 201 while (fTPCStream->Next()){
202
240d63be 203 UShort_t dig=fTPCStream->GetSignal();
204 if(dig <= AliL3Transform::GetZeroSup()) continue;
205 if(dig >= AliL3Transform::GetADCSat())
206 dig = AliL3Transform::GetADCSat();
207
208 Int_t time=fTPCStream->GetTime();
209 Int_t pad=fTPCStream->GetPad();
210 Int_t sector=fTPCStream->GetSector();
211 Int_t row=fTPCStream->GetRow();
212 Int_t slice,srow;
213
214 //test row criteria (patch boundaries)
215 AliL3Transform::Sector2Slice(slice,srow,sector,row);
216 if((srow<fRowMin)||(srow>fRowMax))continue;
217 if(slice!=fSlice){
218 LOG(AliL3Log::kError,"AliL3DDLDataFileHandler::DDLDigits2Memory","Slice")
219 <<AliL3Log::kDec<<"Found slice "<<slice<<", expected "<<fSlice<<ENDLOG;
220 continue;
221 }
222
223 //cut out the inner cone
224 Float_t xyz[3];
225 AliL3Transform::Raw2Local(xyz,sector,row,pad,time);
226 if(AliL3Transform::Row2X(srow)<230./250.*fabs(xyz[2]))
227 continue; // why 230???
228
229 Int_t lrow=srow-fRowMin;
230 if((lrow<0)||lrow>=nrows){
231 LOG(AliL3Log::kError,"AliL3DDLDataFileHandler::DDLDigits2Memory","Row")
232 <<AliL3Log::kDec<<"Row value out of bounds "<<lrow<<" "<<nrows<<ENDLOG;
233 continue;
234 }
235 if((pad<0)||(pad>=AliL3Transform::GetNPads(srow))){
236 LOG(AliL3Log::kError,"AliL3DDLDataFileHandler::DDLDigits2Memory","Pad")
237 <<AliL3Log::kDec<<"Pad value out of bounds "<<pad<<" "
238 <<AliL3Transform::GetNPads(srow)<<ENDLOG;
239 continue;
240 }
241 if((time<0)||(time>=AliL3Transform::GetNTimeBins())){
242 LOG(AliL3Log::kError,"AliL3DDLDataFileHandler::DDLDigits2Memory","Time")
243 <<AliL3Log::kDec<<"Time out of bounds "<<time<<" "
244 <<AliL3Transform::GetNTimeBins()<<ENDLOG;
245 continue;
246 }
247
248 //store digit
249 ndigits[lrow]++; //for this row only
250 ndigitcount++; //total number of digits to be published
251
252 charges[lrow][pad][time]=dig;
253 }
254 }
255
256 Int_t size = sizeof(AliL3DigitData)*ndigitcount
257 + nrows*sizeof(AliL3DigitRowData);
258
259 LOG(AliL3Log::kDebug,"AliL3DDLDataFileHandler::DDLDigits2Memory","Digits")
260 <<AliL3Log::kDec<<"Found "<<ndigitcount<<" Digits"<<ENDLOG;
261
262 data=(AliL3DigitRowData*) Allocate(size);
263 nrow = (UInt_t)nrows;
264 AliL3DigitRowData *tempPt = data;
265
266 for(Int_t r=fRowMin;r<=fRowMax;r++){
267 Int_t lrow=r-fRowMin;
268 tempPt->fRow = r;
269 tempPt->fNDigit = ndigits[lrow];
270
271 Int_t localcount=0;
272 for(Int_t pad=0;pad<AliL3Transform::GetNPads(r);pad++){
273 for(Int_t time=0;time<AliL3Transform::GetNTimeBins();time++){
274 UShort_t dig=charges[lrow][pad][time];
275 if(!dig) continue;
276
277 if(localcount >= ndigits[lrow])
278 LOG(AliL3Log::kFatal,"AliL3DDLDataFileHandler::DDLDigits2Binary","Memory")
279 <<AliL3Log::kDec<<"Mismatch: localcount "<<localcount<<" ndigits "
280 <<ndigits[lrow]<<ENDLOG;
281
282
283 tempPt->fDigitData[localcount].fCharge=dig;
284 tempPt->fDigitData[localcount].fPad=pad;
285 tempPt->fDigitData[localcount].fTime=time;
286#ifdef do_mc
287 tempPt->fDigitData[localcount].fTrackID[0] = 0;
288 tempPt->fDigitData[localcount].fTrackID[1] = 0;
289 tempPt->fDigitData[localcount].fTrackID[2] = 0;
290#endif
291 localcount++;
292 }
293 }
294
295 if(localcount != ndigits[lrow])
296 LOG(AliL3Log::kFatal,"AliL3DDLDataFileHandler::DDLDigits2Binary","Memory")
297 <<AliL3Log::kDec<<"Mismatch: localcount "<<localcount<<" ndigits "
298 <<ndigits[lrow]<<ENDLOG;
299
300
301 Byte_t *tmp = (Byte_t*)tempPt;
302 Int_t size = sizeof(AliL3DigitRowData)
303 + ndigits[lrow]*sizeof(AliL3DigitData);
304 tmp += size;
305 tempPt = (AliL3DigitRowData*)tmp;
306 }
307
308 //delete charge array
309 for(Int_t r=fRowMin;r<=fRowMax;r++){
310 Int_t lrow=r-fRowMin;
311 for(Int_t k=0;k<AliL3Transform::GetNPads(r);k++)
312 delete charges[lrow][k];
313 delete charges[lrow];
314 }
315 delete charges;
62bb4b3d 316 delete [] ndigits;
240d63be 317
318 return data;
319}
320
321
322Bool_t AliL3DDLDataFileHandler::DDLData2CompBinary(Int_t event)
323{
324 Bool_t out = kTRUE;
325 UInt_t ndigits=0;
326 AliL3DigitRowData *digits=0;
327 digits = DDLData2Memory(ndigits,event);
328 out = Memory2CompBinary(ndigits,digits);
329 Free();
330 return out;
331}