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