]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/misc/AliL3DDLDataFileHandler.cxx
Added Thomas Kuhr changes for datachallenge/aliroot tag v4-01-00.
[u/mrichter/AliRoot.git] / HLT / misc / AliL3DDLDataFileHandler.cxx
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"
13 #include "../RAW/AliRawReaderRoot.h"
14
15 #include "AliL3DDLDataFileHandler.h"
16
17 #if GCCVERSION == 3
18 using namespace std;
19 #endif
20
21 /** \class AliL3DDLDataFileHandler 
22 <pre>
23 //_____________________________________________________________
24 // AliL3DDLDataFileHandler
25 //
26 //  This class does converts from the DDL format of offline
27 //  into the memory I/O handling of the HLT binary files.
28 //  
29 //  Examples: see ddl2binary in exa and the general 
30 //            AliL3MemHandler class description
31 //
32 </pre>
33 */
34
35 ClassImp(AliL3DDLDataFileHandler)
36
37 AliL3DDLDataFileHandler::AliL3DDLDataFileHandler()
38 {
39   fReader=0;
40   fTPCStream=0;
41 }
42
43 AliL3DDLDataFileHandler::~AliL3DDLDataFileHandler()
44 {
45   FreeAll();
46 }
47
48 void AliL3DDLDataFileHandler::FreeAll()
49 {
50   if(fReader) delete fReader;
51   if(fTPCStream) delete fTPCStream;
52   fReader = 0;
53   fTPCStream = 0;
54 }
55
56
57 Bool_t AliL3DDLDataFileHandler::SetReaderInput(Char_t *name,Int_t event)
58 {
59   fFilename=name;
60   fEvent=event;
61   if(fReader) delete fReader;
62   if(fTPCStream) delete fTPCStream;
63   fReader=new AliRawReaderRoot(name,event);
64   fTPCStream=new AliTPCRawStream(fReader);
65
66   return kTRUE;
67 }
68
69 void AliL3DDLDataFileHandler::CloseReaderInput()
70 {
71   if(!fReader){
72     LOG(AliL3Log::kWarning,"AliL3RawDataFileHandler::CloseReaderInput","File Close")
73       <<"Nothing to Close"<<ENDLOG;
74     return;
75   }
76
77   delete fReader;
78   delete fTPCStream;
79   fReader = 0;
80   fTPCStream = 0;
81 }
82
83 Bool_t AliL3DDLDataFileHandler::IsDigit(Int_t i)
84 {
85   return kTRUE;
86 }
87
88 AliL3DigitRowData * AliL3DDLDataFileHandler::DDLData2Memory(UInt_t &nrow,Int_t event)
89 {
90   if(event!=fEvent){
91     fEvent=event;
92     if(fReader) delete fReader;
93     if(fTPCStream) delete fTPCStream;
94     fReader=new AliRawReaderRoot(fFilename,event);
95     fTPCStream=new AliTPCRawStream(fReader);
96   }
97
98   AliL3DigitRowData *data = 0;
99   nrow=0;
100
101   if(!fReader){
102     LOG(AliL3Log::kWarning,"AliL3DDLDataFileHandler::DDLData2Memory","File")
103     <<"No Input avalible: no object AliL3DDLRawReaderFile"<<ENDLOG;
104     return 0; 
105   }
106   
107   Int_t nrows=fRowMax-fRowMin+1;
108   Int_t ndigitcount=0;
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;
117     }
118   }
119   
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
125
126     Int_t patch=AliL3Transform::GetPatch(r);
127     Int_t sector,row;
128     AliL3Transform::Slice2Sector(fSlice,r,sector,row);
129
130     if(sector<36) //taken from AliTPCBuffer160.cxx
131       ddlid=sector*2+patch;
132     else
133       ddlid=70+(sector-36)*4+patch;
134
135     if((lddlid!=ddlid-1)&&(r==30)){ //dont forget the split row on the last ddl
136       ddls[ddls_to_search++]=ddlid-1;   
137       lddlid=ddlid-1;
138     }
139     if((lddlid==-1)||(ddlid!=lddlid)){
140       ddls[ddls_to_search++]=ddlid;
141       lddlid=ddlid;
142     }
143     if((r==90)||(r==139)){ //dont forget the split row on the next ddl
144       ddls[ddls_to_search++]=ddlid+1;   
145       lddlid=ddlid+1;
146     }
147   }
148   //for(Int_t i=0;i<ddls_to_search;i++) cout << ddls[i] <<endl;
149
150   for(Int_t i=0;i<ddls_to_search;i++){
151     fReader->Reset();
152     fReader->Select(0,ddls[i],ddls[i]+1);
153     while (fTPCStream->Next()){
154       
155
156       UShort_t dig=fTPCStream->GetSignal();
157       if(dig <= AliL3Transform::GetZeroSup()) continue;
158       if(dig >= AliL3Transform::GetADCSat())
159         dig = AliL3Transform::GetADCSat();
160
161       Int_t time=fTPCStream->GetTime();
162       Int_t pad=fTPCStream->GetPad();
163       Int_t sector=fTPCStream->GetSector();
164       Int_t row=fTPCStream->GetRow();
165       Int_t slice,srow;
166
167       //test row criteria (patch boundaries)
168       AliL3Transform::Sector2Slice(slice,srow,sector,row);
169       if((srow<fRowMin)||(srow>fRowMax))continue;
170       if(slice!=fSlice){
171         LOG(AliL3Log::kError,"AliL3DDLDataFileHandler::DDLDigits2Memory","Slice")
172           <<AliL3Log::kDec<<"Found slice "<<slice<<", expected "<<fSlice<<ENDLOG;
173         continue;
174       }
175
176       //cut out the inner cone
177       Float_t xyz[3];
178       AliL3Transform::Raw2Local(xyz,sector,row,pad,time);
179       if(AliL3Transform::Row2X(srow)<230./250.*fabs(xyz[2]))
180         continue; // why 230???
181
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;
186         continue;
187       }
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;
192         continue;
193       }
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;
198         continue;
199       }
200
201       //store digit
202       ndigits[lrow]++; //for this row only
203       ndigitcount++;   //total number of digits to be published
204
205       charges[lrow][pad][time]=dig;
206     }
207   }
208   
209   Int_t size = sizeof(AliL3DigitData)*ndigitcount
210     + nrows*sizeof(AliL3DigitRowData);
211
212   LOG(AliL3Log::kDebug,"AliL3DDLDataFileHandler::DDLDigits2Memory","Digits")
213     <<AliL3Log::kDec<<"Found "<<ndigitcount<<" Digits"<<ENDLOG;
214   
215   data=(AliL3DigitRowData*) Allocate(size);
216   nrow = (UInt_t)nrows;
217   AliL3DigitRowData *tempPt = data;
218
219   for(Int_t r=fRowMin;r<=fRowMax;r++){
220     Int_t lrow=r-fRowMin;
221     tempPt->fRow = r;
222     tempPt->fNDigit = ndigits[lrow];
223   
224     Int_t localcount=0;
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];
228         if(!dig) continue;
229
230         if(localcount >= ndigits[lrow])
231           LOG(AliL3Log::kFatal,"AliL3DDLDataFileHandler::DDLDigits2Binary","Memory")
232             <<AliL3Log::kDec<<"Mismatch: localcount "<<localcount<<" ndigits "
233             <<ndigits[lrow]<<ENDLOG;
234         
235
236         tempPt->fDigitData[localcount].fCharge=dig;
237         tempPt->fDigitData[localcount].fPad=pad;
238         tempPt->fDigitData[localcount].fTime=time;
239 #ifdef do_mc
240         tempPt->fDigitData[localcount].fTrackID[0] = 0;
241         tempPt->fDigitData[localcount].fTrackID[1] = 0;
242         tempPt->fDigitData[localcount].fTrackID[2] = 0;
243 #endif
244         localcount++;
245       }
246     }
247
248     if(localcount != ndigits[lrow])
249       LOG(AliL3Log::kFatal,"AliL3DDLDataFileHandler::DDLDigits2Binary","Memory")
250         <<AliL3Log::kDec<<"Mismatch: localcount "<<localcount<<" ndigits "
251         <<ndigits[lrow]<<ENDLOG;
252
253
254     Byte_t *tmp = (Byte_t*)tempPt;
255     Int_t size = sizeof(AliL3DigitRowData)
256                                       + ndigits[lrow]*sizeof(AliL3DigitData);
257     tmp += size;
258     tempPt = (AliL3DigitRowData*)tmp;
259   }
260
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];
267   }
268   delete charges;
269
270   return data;
271 }
272
273
274 Bool_t AliL3DDLDataFileHandler::DDLData2CompBinary(Int_t event)
275 {
276   Bool_t out = kTRUE;
277   UInt_t ndigits=0;
278   AliL3DigitRowData *digits=0;
279   digits = DDLData2Memory(ndigits,event);
280   out = Memory2CompBinary(ndigits,digits);
281   Free();
282   return out;
283 }