3 // Author: C. Loizides <loizides@ikf.uni-frankfurt.de>
4 //*-- Copyright © ALICE HLT Group
6 #include "AliL3StandardIncludes.h"
8 #include "AliL3RootTypes.h"
9 #include "AliL3Logging.h"
10 #include "AliL3Transform.h"
11 #include "AliL3MemHandler.h"
12 #include "AliL3DigitData.h"
13 #include "../RAW/AliRawReaderRoot.h"
15 #include "AliL3DDLDataFileHandler.h"
21 /** \class AliL3DDLDataFileHandler
23 //_____________________________________________________________
24 // AliL3DDLDataFileHandler
26 // This class does converts from the DDL format of offline
27 // into the memory I/O handling of the HLT binary files.
29 // Examples: see ddl2binary in exa and the general
30 // AliL3MemHandler class description
35 ClassImp(AliL3DDLDataFileHandler)
37 AliL3DDLDataFileHandler::AliL3DDLDataFileHandler()
43 AliL3DDLDataFileHandler::~AliL3DDLDataFileHandler()
48 void AliL3DDLDataFileHandler::FreeAll()
50 if(fReader) delete fReader;
51 if(fTPCStream) delete fTPCStream;
57 Bool_t AliL3DDLDataFileHandler::SetReaderInput(Char_t *name,Int_t event)
61 if(fReader) delete fReader;
62 if(fTPCStream) delete fTPCStream;
63 fReader=new AliRawReaderRoot(name,event);
64 fTPCStream=new AliTPCRawStream(fReader);
69 void AliL3DDLDataFileHandler::CloseReaderInput()
72 LOG(AliL3Log::kWarning,"AliL3RawDataFileHandler::CloseReaderInput","File Close")
73 <<"Nothing to Close"<<ENDLOG;
83 Bool_t AliL3DDLDataFileHandler::IsDigit(Int_t i)
88 AliL3DigitRowData * AliL3DDLDataFileHandler::DDLData2Memory(UInt_t &nrow,Int_t event)
92 if(fReader) delete fReader;
93 if(fTPCStream) delete fTPCStream;
94 fReader=new AliRawReaderRoot(fFilename,event);
95 fTPCStream=new AliTPCRawStream(fReader);
98 AliL3DigitRowData *data = 0;
102 LOG(AliL3Log::kWarning,"AliL3DDLDataFileHandler::DDLData2Memory","File")
103 <<"No Input avalible: no object AliL3DDLRawReaderFile"<<ENDLOG;
107 Int_t nrows=fRowMax-fRowMin+1;
109 Int_t ndigits[nrows];
110 UShort_t ***charges=new UShort_t**[nrows];
111 for(Int_t r=fRowMin;r<=fRowMax;r++){
112 Int_t lrow=r-fRowMin;
113 charges[lrow]=new UShort_t*[AliL3Transform::GetNPads(r)];
114 for(Int_t k=0;k<AliL3Transform::GetNPads(r);k++){
115 charges[lrow][k]=new UShort_t[AliL3Transform::GetNTimeBins()];
116 for(Int_t j=0;j<AliL3Transform::GetNTimeBins();j++) charges[lrow][k][j]=0;
120 Int_t ddls_to_search=0;
121 Int_t ddls[9]={-1,-1,-1,-1,-1,-1,-1,-1,-1};
122 Int_t ddlid=-1,lddlid=-1;
123 for(Int_t r=fRowMin;r<=fRowMax;r++){
124 ndigits[r-fRowMin] = 0; //now digits on row
126 Int_t patch=AliL3Transform::GetPatch(r);
128 AliL3Transform::Slice2Sector(fSlice,r,sector,row);
130 if(sector<36) //taken from AliTPCBuffer160.cxx
131 ddlid=sector*2+patch;
133 ddlid=70+(sector-36)*4+patch;
135 if((lddlid!=ddlid-1)&&(r==30)){ //dont forget the split row on the last ddl
136 ddls[ddls_to_search++]=ddlid-1;
139 if((lddlid==-1)||(ddlid!=lddlid)){
140 ddls[ddls_to_search++]=ddlid;
143 if((r==90)||(r==139)){ //dont forget the split row on the next ddl
144 ddls[ddls_to_search++]=ddlid+1;
148 //for(Int_t i=0;i<ddls_to_search;i++) cout << ddls[i] <<endl;
150 for(Int_t i=0;i<ddls_to_search;i++){
152 fReader->Select(0,ddls[i],ddls[i]+1);
153 while (fTPCStream->Next()){
156 UShort_t dig=fTPCStream->GetSignal();
157 if(dig <= AliL3Transform::GetZeroSup()) continue;
158 if(dig >= AliL3Transform::GetADCSat())
159 dig = AliL3Transform::GetADCSat();
161 Int_t time=fTPCStream->GetTime();
162 Int_t pad=fTPCStream->GetPad();
163 Int_t sector=fTPCStream->GetSector();
164 Int_t row=fTPCStream->GetRow();
167 //test row criteria (patch boundaries)
168 AliL3Transform::Sector2Slice(slice,srow,sector,row);
169 if((srow<fRowMin)||(srow>fRowMax))continue;
171 LOG(AliL3Log::kError,"AliL3DDLDataFileHandler::DDLDigits2Memory","Slice")
172 <<AliL3Log::kDec<<"Found slice "<<slice<<", expected "<<fSlice<<ENDLOG;
176 //cut out the inner cone
178 AliL3Transform::Raw2Local(xyz,sector,row,pad,time);
179 if(AliL3Transform::Row2X(srow)<230./250.*fabs(xyz[2]))
180 continue; // why 230???
182 Int_t lrow=srow-fRowMin;
183 if((lrow<0)||lrow>=nrows){
184 LOG(AliL3Log::kError,"AliL3DDLDataFileHandler::DDLDigits2Memory","Row")
185 <<AliL3Log::kDec<<"Row value out of bounds "<<lrow<<" "<<nrows<<ENDLOG;
188 if((pad<0)||(pad>=AliL3Transform::GetNPads(srow))){
189 LOG(AliL3Log::kError,"AliL3DDLDataFileHandler::DDLDigits2Memory","Pad")
190 <<AliL3Log::kDec<<"Pad value out of bounds "<<pad<<" "
191 <<AliL3Transform::GetNPads(srow)<<ENDLOG;
194 if((time<0)||(time>=AliL3Transform::GetNTimeBins())){
195 LOG(AliL3Log::kError,"AliL3DDLDataFileHandler::DDLDigits2Memory","Time")
196 <<AliL3Log::kDec<<"Time out of bounds "<<time<<" "
197 <<AliL3Transform::GetNTimeBins()<<ENDLOG;
202 ndigits[lrow]++; //for this row only
203 ndigitcount++; //total number of digits to be published
205 charges[lrow][pad][time]=dig;
209 Int_t size = sizeof(AliL3DigitData)*ndigitcount
210 + nrows*sizeof(AliL3DigitRowData);
212 LOG(AliL3Log::kDebug,"AliL3DDLDataFileHandler::DDLDigits2Memory","Digits")
213 <<AliL3Log::kDec<<"Found "<<ndigitcount<<" Digits"<<ENDLOG;
215 data=(AliL3DigitRowData*) Allocate(size);
216 nrow = (UInt_t)nrows;
217 AliL3DigitRowData *tempPt = data;
219 for(Int_t r=fRowMin;r<=fRowMax;r++){
220 Int_t lrow=r-fRowMin;
222 tempPt->fNDigit = ndigits[lrow];
225 for(Int_t pad=0;pad<AliL3Transform::GetNPads(r);pad++){
226 for(Int_t time=0;time<AliL3Transform::GetNTimeBins();time++){
227 UShort_t dig=charges[lrow][pad][time];
230 if(localcount >= ndigits[lrow])
231 LOG(AliL3Log::kFatal,"AliL3DDLDataFileHandler::DDLDigits2Binary","Memory")
232 <<AliL3Log::kDec<<"Mismatch: localcount "<<localcount<<" ndigits "
233 <<ndigits[lrow]<<ENDLOG;
236 tempPt->fDigitData[localcount].fCharge=dig;
237 tempPt->fDigitData[localcount].fPad=pad;
238 tempPt->fDigitData[localcount].fTime=time;
240 tempPt->fDigitData[localcount].fTrackID[0] = 0;
241 tempPt->fDigitData[localcount].fTrackID[1] = 0;
242 tempPt->fDigitData[localcount].fTrackID[2] = 0;
248 if(localcount != ndigits[lrow])
249 LOG(AliL3Log::kFatal,"AliL3DDLDataFileHandler::DDLDigits2Binary","Memory")
250 <<AliL3Log::kDec<<"Mismatch: localcount "<<localcount<<" ndigits "
251 <<ndigits[lrow]<<ENDLOG;
254 Byte_t *tmp = (Byte_t*)tempPt;
255 Int_t size = sizeof(AliL3DigitRowData)
256 + ndigits[lrow]*sizeof(AliL3DigitData);
258 tempPt = (AliL3DigitRowData*)tmp;
261 //delete charge array
262 for(Int_t r=fRowMin;r<=fRowMax;r++){
263 Int_t lrow=r-fRowMin;
264 for(Int_t k=0;k<AliL3Transform::GetNPads(r);k++)
265 delete charges[lrow][k];
266 delete charges[lrow];
274 Bool_t AliL3DDLDataFileHandler::DDLData2CompBinary(Int_t event)
278 AliL3DigitRowData *digits=0;
279 digits = DDLData2Memory(ndigits,event);
280 out = Memory2CompBinary(ndigits,digits);