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 "AliL3DDLTPCRawStream.h"
14 #include "AliL3DDLRawReaderFile.h"
16 #include "AliL3DDLDataFileHandler.h"
22 /** \class AliL3DDLDataFileHandler
24 //_____________________________________________________________
25 // AliL3DDLDataFileHandler
27 // This class does converts from the DDL format of offline
28 // into the memory I/O handling of the HLT binary files.
30 // Examples: see ddl2binary in exa and the general
31 // AliL3MemHandler class description
36 ClassImp(AliL3DDLDataFileHandler)
38 AliL3DDLDataFileHandler::AliL3DDLDataFileHandler()
44 AliL3DDLDataFileHandler::~AliL3DDLDataFileHandler()
49 void AliL3DDLDataFileHandler::FreeAll()
51 if(fReader) delete fReader;
52 if(fTPCStream) delete fTPCStream;
58 Bool_t AliL3DDLDataFileHandler::SetReaderInput(Char_t *name, Bool_t add)
61 LOG(AliL3Log::kError,"AliL3DDLDataFileHandler::SetReaderInput","File Open")
62 <<"Reader ptr is already in use"<<ENDLOG;
66 fReader=new AliL3DDLRawReaderFile(name,add);
67 fTPCStream=new AliL3DDLTPCRawStream(fReader);
72 Bool_t AliL3DDLDataFileHandler::SetReaderInput(AliL3DDLRawReaderFile *rf)
75 LOG(AliL3Log::kError,"AliL3RawDataFileHandler::SetReaderInput","File Open")
76 <<"Reader ptr is already in use, delete it first"<<ENDLOG;
80 //Open the raw data file with given file.
82 fTPCStream=new AliL3DDLTPCRawStream(fReader);
87 void AliL3DDLDataFileHandler::CloseReaderInput()
90 LOG(AliL3Log::kWarning,"AliL3RawDataFileHandler::CloseReaderInput","File Close")
91 <<"Nothing to Close"<<ENDLOG;
101 AliL3DigitRowData * AliL3DDLDataFileHandler::DDLData2Memory(UInt_t &nrow,Int_t event)
102 { //event is not used
103 AliL3DigitRowData *data = 0;
107 LOG(AliL3Log::kWarning,"AliL3DDLDataFileHandler::DDLData2Memory","File")
108 <<"No Input avalible: no object AliL3DDLRawReaderFile"<<ENDLOG;
112 Int_t nrows=fRowMax-fRowMin+1;
114 Int_t ndigits[nrows];
115 UShort_t ***charges=new UShort_t**[nrows];
116 for(Int_t r=fRowMin;r<=fRowMax;r++){
117 Int_t lrow=r-fRowMin;
118 charges[lrow]=new UShort_t*[AliL3Transform::GetNPads(r)];
119 for(Int_t k=0;k<AliL3Transform::GetNPads(r);k++){
120 charges[lrow][k]=new UShort_t[AliL3Transform::GetNTimeBins()];
121 for(Int_t j=0;j<AliL3Transform::GetNTimeBins();j++) charges[lrow][k][j]=0;
125 Int_t ddls_to_search=0;
126 Int_t ddls[9]={-1,-1,-1,-1,-1,-1,-1,-1,-1};
127 Int_t ddlid=-1,lddlid=-1;
128 for(Int_t r=fRowMin;r<=fRowMax;r++){
129 ndigits[r-fRowMin] = 0; //now digits on row
131 Int_t patch=AliL3Transform::GetPatch(r);
133 AliL3Transform::Slice2Sector(fSlice,r,sector,row);
135 if(sector<36) //taken from AliTPCBuffer160.cxx
136 ddlid=sector*2+patch;
138 ddlid=70+(sector-36)*4+patch;
140 if((lddlid!=ddlid-1)&&(r==30)){ //dont forget the split row on the last ddl
141 ddls[ddls_to_search++]=ddlid-1;
144 if((lddlid==-1)||(ddlid!=lddlid)){
145 ddls[ddls_to_search++]=ddlid;
148 if((r==90)||(r==139)){ //dont forget the split row on the next ddl
149 ddls[ddls_to_search++]=ddlid+1;
153 //for(Int_t i=0;i<ddls_to_search;i++) cout << ddls[i] <<endl;
155 for(Int_t i=0;i<ddls_to_search;i++){
156 fTPCStream->SetDDLID(ddls[i]); //ddl to read out
157 while (fTPCStream->Next()){
158 UShort_t dig=fTPCStream->GetSignal();
159 if(dig <= AliL3Transform::GetZeroSup()) continue;
160 if(dig >= AliL3Transform::GetADCSat())
161 dig = AliL3Transform::GetADCSat();
163 Int_t time=fTPCStream->GetTime();
164 Int_t pad=fTPCStream->GetPad();
165 Int_t sector=fTPCStream->GetSector();
166 Int_t row=fTPCStream->GetRow();
169 //test row criteria (patch boundaries)
170 AliL3Transform::Sector2Slice(slice,srow,sector,row);
171 if((srow<fRowMin)||(srow>fRowMax))continue;
173 LOG(AliL3Log::kError,"AliL3DDLDataFileHandler::DDLDigits2Memory","Slice")
174 <<AliL3Log::kDec<<"Found slice "<<slice<<", expected "<<fSlice<<ENDLOG;
178 //cut out the inner cone
180 AliL3Transform::Raw2Local(xyz,sector,row,pad,time);
181 if(AliL3Transform::Row2X(srow)<230./250.*fabs(xyz[2]))
182 continue; // why 230???
184 Int_t lrow=srow-fRowMin;
185 if((lrow<0)||lrow>=nrows){
186 LOG(AliL3Log::kError,"AliL3DDLDataFileHandler::DDLDigits2Memory","Row")
187 <<AliL3Log::kDec<<"Row value out of bounds "<<lrow<<" "<<nrows<<ENDLOG;
190 if((pad<0)||(pad>=AliL3Transform::GetNPads(srow))){
191 LOG(AliL3Log::kError,"AliL3DDLDataFileHandler::DDLDigits2Memory","Pad")
192 <<AliL3Log::kDec<<"Pad value out of bounds "<<pad<<" "
193 <<AliL3Transform::GetNPads(srow)<<ENDLOG;
196 if((time<0)||(time>=AliL3Transform::GetNTimeBins())){
197 LOG(AliL3Log::kError,"AliL3DDLDataFileHandler::DDLDigits2Memory","Time")
198 <<AliL3Log::kDec<<"Time out of bounds "<<time<<" "
199 <<AliL3Transform::GetNTimeBins()<<ENDLOG;
204 ndigits[lrow]++; //for this row only
205 ndigitcount++; //total number of digits to be published
207 charges[lrow][pad][time]=dig;
211 Int_t size = sizeof(AliL3DigitData)*ndigitcount
212 + nrows*sizeof(AliL3DigitRowData);
214 LOG(AliL3Log::kDebug,"AliL3DDLDataFileHandler::DDLDigits2Memory","Digits")
215 <<AliL3Log::kDec<<"Found "<<ndigitcount<<" Digits"<<ENDLOG;
217 data=(AliL3DigitRowData*) Allocate(size);
218 nrow = (UInt_t)nrows;
219 AliL3DigitRowData *tempPt = data;
221 for(Int_t r=fRowMin;r<=fRowMax;r++){
222 Int_t lrow=r-fRowMin;
224 tempPt->fNDigit = ndigits[lrow];
227 for(Int_t pad=0;pad<AliL3Transform::GetNPads(r);pad++){
228 for(Int_t time=0;time<AliL3Transform::GetNTimeBins();time++){
229 UShort_t dig=charges[lrow][pad][time];
232 if(localcount >= ndigits[lrow])
233 LOG(AliL3Log::kFatal,"AliL3DDLDataFileHandler::DDLDigits2Binary","Memory")
234 <<AliL3Log::kDec<<"Mismatch: localcount "<<localcount<<" ndigits "
235 <<ndigits[lrow]<<ENDLOG;
238 tempPt->fDigitData[localcount].fCharge=dig;
239 tempPt->fDigitData[localcount].fPad=pad;
240 tempPt->fDigitData[localcount].fTime=time;
242 tempPt->fDigitData[localcount].fTrackID[0] = 0;
243 tempPt->fDigitData[localcount].fTrackID[1] = 0;
244 tempPt->fDigitData[localcount].fTrackID[2] = 0;
250 if(localcount != ndigits[lrow])
251 LOG(AliL3Log::kFatal,"AliL3DDLDataFileHandler::DDLDigits2Binary","Memory")
252 <<AliL3Log::kDec<<"Mismatch: localcount "<<localcount<<" ndigits "
253 <<ndigits[lrow]<<ENDLOG;
256 Byte_t *tmp = (Byte_t*)tempPt;
257 Int_t size = sizeof(AliL3DigitRowData)
258 + ndigits[lrow]*sizeof(AliL3DigitData);
260 tempPt = (AliL3DigitRowData*)tmp;
263 //delete charge array
264 for(Int_t r=fRowMin;r<=fRowMax;r++){
265 Int_t lrow=r-fRowMin;
266 for(Int_t k=0;k<AliL3Transform::GetNPads(r);k++)
267 delete charges[lrow][k];
268 delete charges[lrow];
276 Bool_t AliL3DDLDataFileHandler::DDLData2CompBinary(Int_t event)
280 AliL3DigitRowData *digits=0;
281 digits = DDLData2Memory(ndigits,event);
282 out = Memory2CompBinary(ndigits,digits);