]>
Commit | Line | Data |
---|---|---|
a6c02c85 | 1 | // @(#) $Id$ |
4aa41877 | 2 | // Original: AliHLTFileHandler.cxx,v 1.49 2005/06/23 17:46:55 hristov |
a6c02c85 | 3 | |
5578cf60 | 4 | /************************************************************************** |
5 | * This file is property of and copyright by the ALICE HLT Project * | |
6 | * ALICE Experiment at CERN, All rights reserved. * | |
7 | * * | |
8 | * Primary Authors: U. Frankenfeld, A. Vestbo, C. Loizides * | |
9 | * Matthias Richter <Matthias.Richter@ift.uib.no> * | |
10 | * for The ALICE HLT Project. * | |
11 | * * | |
12 | * Permission to use, copy, modify and distribute this software and its * | |
13 | * documentation strictly for non-commercial purposes is hereby granted * | |
14 | * without fee, provided that the above copyright notice appears in all * | |
15 | * copies and that both the copyright notice and this permission notice * | |
16 | * appear in the supporting documentation. The authors make no claims * | |
17 | * about the suitability of this software for any purpose. It is * | |
18 | * provided "as is" without express or implied warranty. * | |
19 | **************************************************************************/ | |
20 | ||
21 | /** @file AliHLTTPCFileHandler.cxx | |
22 | @author U. Frankenfeld, A. Vestbo, C. Loizides, maintained by | |
23 | Matthias Richter | |
24 | @date | |
25 | @brief file input for the TPC tracking code before migration to the | |
26 | HLT component framework | |
27 | ||
28 | // see below for class documentation | |
29 | // or | |
30 | // refer to README to build package | |
31 | // or | |
32 | // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt | |
33 | */ | |
a6c02c85 | 34 | |
a6c02c85 | 35 | #include <TClonesArray.h> |
36 | #include <TSystem.h> | |
37 | #include <TMath.h> | |
38 | ||
a6c02c85 | 39 | #include <AliRunLoader.h> |
95d48915 | 40 | #include <TObject.h> |
41 | #include <TFile.h> | |
42 | #include <TTree.h> | |
a6c02c85 | 43 | #include <AliTPCParamSR.h> |
44 | #include <AliTPCDigitsArray.h> | |
45 | #include <AliTPCClustersArray.h> | |
46 | #include <AliTPCcluster.h> | |
47 | #include <AliTPCClustersRow.h> | |
48 | #include <AliSimDigits.h> | |
49 | ||
50 | #include "AliHLTTPCLogging.h" | |
51 | #include "AliHLTTPCTransform.h" | |
a6c02c85 | 52 | #include "AliHLTTPCDigitData.h" |
95d48915 | 53 | //#include "AliHLTTPCTrackSegmentData.h" |
a6c02c85 | 54 | #include "AliHLTTPCSpacePointData.h" |
95d48915 | 55 | //#include "AliHLTTPCTrackArray.h" |
a6c02c85 | 56 | #include "AliHLTTPCFileHandler.h" |
57 | ||
58 | #if __GNUC__ >= 3 | |
59 | using namespace std; | |
60 | #endif | |
61 | ||
86268ca8 | 62 | /** |
a6c02c85 | 63 | <pre> |
64 | //_____________________________________________________________ | |
65 | // AliHLTTPCFileHandler | |
66 | // | |
67 | // The HLT ROOT <-> binary files handling class | |
68 | // | |
69 | // This class provides the interface between AliROOT files, | |
70 | // and HLT binary files. It should be used for converting | |
71 | // TPC data stored in AliROOT format (outputfile from a simulation), | |
72 | // into the data format currently used by in the HLT framework. | |
73 | // This enables the possibility to always use the same data format, | |
74 | // whether you are using a binary file as an input, or a AliROOT file. | |
75 | // | |
76 | // For example on how to create binary files from a AliROOT simulation, | |
77 | // see example macro exa/Binary.C. | |
78 | // | |
79 | // For reading a AliROOT file into HLT format in memory, do the following: | |
80 | // | |
81 | // AliHLTTPCFileHandler file; | |
82 | // file.Init(slice,patch); | |
83 | // file.SetAliInput("galice.root"); | |
84 | // AliHLTTPCDigitRowData *dataPt = (AliHLTTPCDigitRowData*)file.AliDigits2Memory(nrows,eventnr); | |
85 | // | |
86 | // All the data are then stored in memory and accessible via the pointer dataPt. | |
87 | // Accesing the data is then identical to the example 1) showed in AliHLTTPCMemHandler class. | |
88 | // | |
89 | // For converting the data back, and writing it to a new AliROOT file do: | |
90 | // | |
91 | // AliHLTTPCFileHandler file; | |
92 | // file.Init(slice,patch); | |
93 | // file.SetAliInput("galice.root"); | |
94 | // file.Init(slice,patch,NumberOfRowsInPatch); | |
95 | // file.AliDigits2RootFile(dataPt,"new_galice.root"); | |
96 | // file.CloseAliInput(); | |
97 | </pre> | |
98 | */ | |
99 | ||
100 | ClassImp(AliHLTTPCFileHandler) | |
101 | ||
600e6a1b | 102 | AliHLTTPCFileHandler::AliHLTTPCFileHandler(Bool_t b) |
103 | : | |
104 | fInAli(NULL), | |
600e6a1b | 105 | fUseRunLoader(kFALSE), |
600e6a1b | 106 | fParam(NULL), |
600e6a1b | 107 | fDigits(NULL), |
108 | fDigitsTree(NULL), | |
2a083ac4 | 109 | fMC(NULL), |
600e6a1b | 110 | fIndexCreated(kFALSE), |
111 | fUseStaticIndex(b) | |
112 | { | |
113 | //Default constructor | |
114 | ||
115 | for(Int_t i=0;i<AliHLTTPCTransform::GetNSlice();i++) | |
116 | for(Int_t j=0;j<AliHLTTPCTransform::GetNRows();j++) | |
117 | fIndex[i][j]=-1; | |
118 | ||
119 | if(fUseStaticIndex&&!fgStaticIndexCreated) CleanStaticIndex(); | |
120 | } | |
121 | ||
600e6a1b | 122 | AliHLTTPCFileHandler::~AliHLTTPCFileHandler() |
123 | { | |
124 | //Destructor | |
125 | if(fMC) CloseMCOutput(); | |
126 | FreeDigitsTree(); | |
127 | if(fInAli) CloseAliInput(); | |
128 | } | |
129 | ||
a6c02c85 | 130 | // of course on start up the index is not created |
131 | Bool_t AliHLTTPCFileHandler::fgStaticIndexCreated=kFALSE; | |
132 | Int_t AliHLTTPCFileHandler::fgStaticIndex[36][159]; | |
133 | ||
134 | void AliHLTTPCFileHandler::CleanStaticIndex() | |
135 | { | |
136 | // use this static call to clean static index after | |
137 | // running over one event | |
138 | for(Int_t i=0;i<AliHLTTPCTransform::GetNSlice();i++){ | |
139 | for(Int_t j=0;j<AliHLTTPCTransform::GetNRows();j++) | |
140 | fgStaticIndex[i][j]=-1; | |
141 | } | |
142 | fgStaticIndexCreated=kFALSE; | |
143 | } | |
144 | ||
145 | Int_t AliHLTTPCFileHandler::SaveStaticIndex(Char_t *prefix,Int_t event) | |
146 | { | |
147 | // use this static call to store static index after | |
148 | if(!fgStaticIndexCreated) return -1; | |
149 | ||
150 | Char_t fname[1024]; | |
151 | if(prefix) | |
152 | sprintf(fname,"%s-%d.txt",prefix,event); | |
153 | else | |
154 | sprintf(fname,"TPC.Digits.staticindex-%d.txt",event); | |
155 | ||
156 | ofstream file(fname,ios::trunc); | |
157 | if(!file.good()) return -1; | |
158 | ||
159 | for(Int_t i=0;i<AliHLTTPCTransform::GetNSlice();i++){ | |
160 | for(Int_t j=0;j<AliHLTTPCTransform::GetNRows();j++) | |
161 | file << fgStaticIndex[i][j] << " "; | |
162 | file << endl; | |
163 | } | |
164 | file.close(); | |
165 | return 0; | |
166 | } | |
167 | ||
168 | Int_t AliHLTTPCFileHandler::LoadStaticIndex(Char_t *prefix,Int_t event) | |
169 | { | |
170 | // use this static call to store static index after | |
171 | if(fgStaticIndexCreated){ | |
172 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCFileHandler::LoadStaticIndex","Inxed") | |
173 | <<"Static index already created, will overwrite"<<ENDLOG; | |
174 | CleanStaticIndex(); | |
175 | } | |
176 | ||
177 | Char_t fname[1024]; | |
178 | if(prefix) | |
179 | sprintf(fname,"%s-%d.txt",prefix,event); | |
180 | else | |
181 | sprintf(fname,"TPC.Digits.staticindex-%d.txt",event); | |
182 | ||
183 | ifstream file(fname); | |
184 | if(!file.good()) return -1; | |
185 | ||
186 | for(Int_t i=0;i<AliHLTTPCTransform::GetNSlice();i++){ | |
187 | for(Int_t j=0;j<AliHLTTPCTransform::GetNRows();j++) | |
188 | file >> fgStaticIndex[i][j]; | |
189 | } | |
190 | file.close(); | |
191 | ||
192 | fgStaticIndexCreated=kTRUE; | |
193 | return 0; | |
194 | } | |
195 | ||
a6c02c85 | 196 | void AliHLTTPCFileHandler::FreeDigitsTree() |
197 | { | |
198 | //free digits tree | |
61692dfa | 199 | if (fDigits) { |
200 | delete fDigits; | |
201 | } | |
a6c02c85 | 202 | fDigits=0; |
a6c02c85 | 203 | fDigitsTree=0; |
204 | ||
205 | for(Int_t i=0;i<AliHLTTPCTransform::GetNSlice();i++){ | |
206 | for(Int_t j=0;j<AliHLTTPCTransform::GetNRows();j++) | |
207 | fIndex[i][j]=-1; | |
208 | } | |
209 | fIndexCreated=kFALSE; | |
210 | } | |
211 | ||
212 | Bool_t AliHLTTPCFileHandler::SetMCOutput(Char_t *name) | |
213 | { | |
214 | //set mc input | |
215 | fMC = fopen(name,"w"); | |
216 | if(!fMC){ | |
217 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCFileHandler::SetMCOutput","File Open") | |
218 | <<"Pointer to File = 0x0 "<<ENDLOG; | |
219 | return kFALSE; | |
220 | } | |
221 | return kTRUE; | |
222 | } | |
223 | ||
224 | Bool_t AliHLTTPCFileHandler::SetMCOutput(FILE *file) | |
225 | { | |
226 | //set mc output | |
227 | fMC = file; | |
228 | if(!fMC){ | |
229 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCFileHandler::SetMCOutput","File Open") | |
230 | <<"Pointer to File = 0x0 "<<ENDLOG; | |
231 | return kFALSE; | |
232 | } | |
233 | return kTRUE; | |
234 | } | |
235 | ||
236 | void AliHLTTPCFileHandler::CloseMCOutput() | |
237 | { | |
238 | //close mc output | |
239 | if(!fMC){ | |
240 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCFileHandler::CloseMCOutPut","File Close") | |
241 | <<"Nothing to Close"<<ENDLOG; | |
242 | return; | |
243 | } | |
244 | fclose(fMC); | |
245 | fMC =0; | |
246 | } | |
247 | ||
248 | Bool_t AliHLTTPCFileHandler::SetAliInput() | |
249 | { | |
250 | //set ali input | |
a6c02c85 | 251 | fInAli->CdGAFile(); |
252 | fParam = (AliTPCParam*)gFile->Get("75x40_100x60_150x60"); | |
253 | if(!fParam){ | |
254 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCFileHandler::SetAliInput","File") | |
255 | <<"No TPC parameters found in \""<<gFile->GetName() | |
256 | <<"\", creating standard parameters " | |
257 | <<"which might not be what you want!"<<ENDLOG; | |
258 | fParam = new AliTPCParamSR; | |
259 | } | |
260 | if(!fParam){ | |
261 | LOG(AliHLTTPCLog::kError,"AliHLTTPCFileHandler::SetAliInput","File Open") | |
262 | <<"No AliTPCParam "<<AliHLTTPCTransform::GetParamName()<<" in File "<<gFile->GetName()<<ENDLOG; | |
263 | return kFALSE; | |
264 | } | |
a6c02c85 | 265 | |
266 | return kTRUE; | |
267 | } | |
268 | ||
269 | Bool_t AliHLTTPCFileHandler::SetAliInput(Char_t *name) | |
270 | { | |
271 | //Open the AliROOT file with name. | |
a6c02c85 | 272 | fInAli= AliRunLoader::Open(name); |
a6c02c85 | 273 | if(!fInAli){ |
274 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCFileHandler::SetAliInput","File Open") | |
275 | <<"Pointer to fInAli = 0x0 "<<ENDLOG; | |
276 | return kFALSE; | |
277 | } | |
278 | return SetAliInput(); | |
279 | } | |
280 | ||
a6c02c85 | 281 | Bool_t AliHLTTPCFileHandler::SetAliInput(AliRunLoader *runLoader) |
282 | { | |
283 | //set ali input as runloader | |
284 | fInAli=runLoader; | |
285 | fUseRunLoader = kTRUE; | |
286 | if(!fInAli){ | |
287 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCFileHandler::SetAliInput","File Open") | |
288 | <<"Pointer to AliRunLoader = 0x0 "<<ENDLOG; | |
289 | return kFALSE; | |
290 | } | |
291 | return SetAliInput(); | |
292 | } | |
a6c02c85 | 293 | |
294 | void AliHLTTPCFileHandler::CloseAliInput() | |
295 | { | |
296 | //close ali input | |
a6c02c85 | 297 | if(fUseRunLoader) return; |
a6c02c85 | 298 | if(!fInAli){ |
299 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCFileHandler::CloseAliInput","RunLoader") | |
300 | <<"Nothing to Close"<<ENDLOG; | |
301 | return; | |
302 | } | |
a6c02c85 | 303 | |
304 | delete fInAli; | |
305 | fInAli = 0; | |
306 | } | |
307 | ||
308 | Bool_t AliHLTTPCFileHandler::IsDigit(Int_t event) | |
309 | { | |
310 | //Check if there is a TPC digit tree in the current file. | |
311 | //Return kTRUE if tree was found, and kFALSE if not found. | |
312 | ||
313 | if(!fInAli){ | |
314 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCFileHandler::IsDigit","File") | |
315 | <<"Pointer to fInAli = 0x0 "<<ENDLOG; | |
316 | return kTRUE; //maybe you are using binary input which is Digits! | |
317 | } | |
a6c02c85 | 318 | AliLoader* tpcLoader = fInAli->GetLoader("TPCLoader"); |
319 | if(!tpcLoader){ | |
320 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCFileHandlerNewIO::IsDigit","File") | |
321 | <<"Pointer to AliLoader for TPC = 0x0 "<<ENDLOG; | |
322 | return kFALSE; | |
323 | } | |
324 | fInAli->GetEvent(event); | |
325 | tpcLoader->LoadDigits(); | |
326 | TTree *t=tpcLoader->TreeD(); | |
a6c02c85 | 327 | if(t){ |
328 | LOG(AliHLTTPCLog::kInformational,"AliHLTTPCFileHandlerNewIO::IsDigit","File Type") | |
329 | <<"Found Digit Tree -> Use Fast Cluster Finder"<<ENDLOG; | |
330 | return kTRUE; | |
331 | } | |
332 | else{ | |
333 | LOG(AliHLTTPCLog::kInformational,"AliHLTTPCFileHandlerNewIO::IsDigit","File Type") | |
334 | <<"No Digit Tree -> Use Cluster Tree"<<ENDLOG; | |
335 | return kFALSE; | |
336 | } | |
337 | } | |
338 | ||
339 | ///////////////////////////////////////// Digit IO | |
5578cf60 | 340 | Bool_t AliHLTTPCFileHandler::AliDigits2BinaryFile(Int_t event,Bool_t altro) |
a6c02c85 | 341 | { |
342 | //save alidigits as binary | |
343 | Bool_t out = kTRUE; | |
344 | UInt_t nrow; | |
345 | AliHLTTPCDigitRowData* data = 0; | |
346 | if(altro) | |
347 | data = AliAltroDigits2Memory(nrow,event); | |
348 | else | |
349 | data = AliDigits2Memory(nrow,event); | |
5578cf60 | 350 | out = Memory2BinaryFile(nrow,data); |
a6c02c85 | 351 | Free(); |
352 | return out; | |
353 | } | |
354 | ||
355 | Bool_t AliHLTTPCFileHandler::AliDigits2CompBinary(Int_t event,Bool_t altro) | |
356 | { | |
357 | //Convert AliROOT TPC data, into HLT data format. | |
358 | //event specifies the event you want in the aliroot file. | |
359 | ||
360 | Bool_t out = kTRUE; | |
361 | UInt_t ndigits=0; | |
362 | AliHLTTPCDigitRowData *digits=0; | |
363 | if(altro) | |
364 | digits = AliAltroDigits2Memory(ndigits,event); | |
365 | else | |
366 | digits = AliDigits2Memory(ndigits,event); | |
367 | out = Memory2CompBinary(ndigits,digits); | |
368 | Free(); | |
369 | return out; | |
370 | } | |
371 | ||
372 | Bool_t AliHLTTPCFileHandler::CreateIndex() | |
373 | { | |
374 | //create the access index or copy from static index | |
375 | fIndexCreated=kFALSE; | |
376 | ||
377 | if(!fgStaticIndexCreated || !fUseStaticIndex) { //we have to create index | |
378 | LOG(AliHLTTPCLog::kInformational,"AliHLTTPCFileHandler::CreateIndex","Index") | |
379 | <<"Starting to create index, this can take a while."<<ENDLOG; | |
380 | ||
381 | for(Int_t n=0; n<fDigitsTree->GetEntries(); n++) { | |
382 | Int_t sector, row; | |
383 | Int_t lslice,lrow; | |
384 | fDigitsTree->GetEvent(n); | |
385 | fParam->AdjustSectorRow(fDigits->GetID(),sector,row); | |
386 | if(!AliHLTTPCTransform::Sector2Slice(lslice,lrow,sector,row)){ | |
387 | LOG(AliHLTTPCLog::kError,"AliHLTTPCFileHandler::CreateIndex","Slice/Row") | |
388 | <<AliHLTTPCLog::kDec<<"Index could not be created. Wrong values " | |
389 | <<sector<<" "<<row<<ENDLOG; | |
390 | return kFALSE; | |
391 | } | |
392 | if(fIndex[lslice][lrow]==-1) { | |
393 | fIndex[lslice][lrow]=n; | |
394 | } | |
395 | } | |
396 | if(fUseStaticIndex) { // create static index | |
397 | for(Int_t i=0;i<AliHLTTPCTransform::GetNSlice();i++){ | |
398 | for(Int_t j=0;j<AliHLTTPCTransform::GetNRows();j++) | |
399 | fgStaticIndex[i][j]=fIndex[i][j]; | |
400 | } | |
401 | fgStaticIndexCreated=kTRUE; //remember that index has been created | |
402 | } | |
403 | ||
404 | LOG(AliHLTTPCLog::kInformational,"AliHLTTPCFileHandler::CreateIndex","Index") | |
405 | <<"Index successfully created."<<ENDLOG; | |
406 | ||
407 | } else if(fUseStaticIndex) { //simply copy static index | |
408 | for(Int_t i=0;i<AliHLTTPCTransform::GetNSlice();i++){ | |
409 | for(Int_t j=0;j<AliHLTTPCTransform::GetNRows();j++) | |
410 | fIndex[i][j]=fgStaticIndex[i][j]; | |
411 | } | |
412 | ||
413 | LOG(AliHLTTPCLog::kInformational,"AliHLTTPCFileHandler::CreateIndex","Index") | |
414 | <<"Index successfully taken from static copy."<<ENDLOG; | |
415 | } | |
416 | fIndexCreated=kTRUE; | |
417 | return kTRUE; | |
418 | } | |
419 | ||
5578cf60 | 420 | AliHLTTPCDigitRowData * AliHLTTPCFileHandler::AliDigits2Memory(UInt_t & nrow,Int_t event, Byte_t* tgtBuffer, UInt_t *pTgtSize) |
a6c02c85 | 421 | { |
5578cf60 | 422 | //Read data from AliROOT file into memory, and store it in the HLT data format |
423 | //in the provided buffer or an allocated buffer. | |
a6c02c85 | 424 | //Returns a pointer to the data. |
425 | ||
426 | AliHLTTPCDigitRowData *data = 0; | |
427 | nrow=0; | |
428 | ||
429 | if(!fInAli){ | |
430 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCFileHandler::AliDigits2Memory","File") | |
431 | <<"No Input avalible: Pointer to fInAli == NULL"<<ENDLOG; | |
432 | return 0; | |
433 | } | |
434 | ||
a6c02c85 | 435 | if(!fDigitsTree) |
436 | if(!GetDigitsTree(event)) return 0; | |
437 | ||
438 | UShort_t dig; | |
439 | Int_t time,pad,sector,row; | |
440 | Int_t lslice,lrow; | |
441 | Int_t nrows=0; | |
442 | Int_t ndigitcount=0; | |
443 | Int_t entries = (Int_t)fDigitsTree->GetEntries(); | |
444 | if(entries==0) { | |
445 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCFileHandler::AliDigits2Memory","ndigits") | |
446 | <<"No TPC digits (entries==0)!"<<ENDLOG; | |
447 | nrow = (UInt_t)(fRowMax-fRowMin+1); | |
448 | Int_t size = nrow*sizeof(AliHLTTPCDigitRowData); | |
5578cf60 | 449 | if (tgtBuffer!=NULL && pTgtSize!=NULL && *pTgtSize>0) { |
450 | if (size<=*pTgtSize) { | |
451 | data=reinterpret_cast<AliHLTTPCDigitRowData*>(tgtBuffer); | |
452 | } else { | |
453 | } | |
454 | } else { | |
455 | data=reinterpret_cast<AliHLTTPCDigitRowData*>(Allocate(size)); | |
456 | } | |
a6c02c85 | 457 | AliHLTTPCDigitRowData *tempPt = data; |
5578cf60 | 458 | if (data) { |
459 | if (pTgtSize) *pTgtSize=size; | |
a6c02c85 | 460 | for(Int_t r=fRowMin;r<=fRowMax;r++){ |
461 | tempPt->fRow = r; | |
462 | tempPt->fNDigit = 0; | |
463 | tempPt++; | |
464 | } | |
5578cf60 | 465 | } |
a6c02c85 | 466 | return data; |
467 | } | |
468 | ||
469 | Int_t * ndigits = new Int_t[fRowMax+1]; | |
470 | Float_t xyz[3]; | |
471 | ||
5578cf60 | 472 | // The digits of the current event have been indexed: all digits are organized in |
473 | // rows, all digits of one row are stored in a AliSimDigits object (fDigit) which | |
474 | // are stored in the digit tree. | |
475 | // The index map relates the AliSimDigits objects in the tree to dedicated pad rows | |
476 | // in the TPC | |
477 | // This loop filters the pad rows according to the slice no set via Init | |
a6c02c85 | 478 | for(Int_t r=fRowMin;r<=fRowMax;r++){ |
479 | Int_t n=fIndex[fSlice][r]; | |
5578cf60 | 480 | if(n!=-1){ // there is data on that row available |
a6c02c85 | 481 | fDigitsTree->GetEvent(n); |
482 | fParam->AdjustSectorRow(fDigits->GetID(),sector,row); | |
483 | AliHLTTPCTransform::Sector2Slice(lslice,lrow,sector,row); | |
484 | ||
485 | if(lrow!=r){ | |
486 | LOG(AliHLTTPCLog::kError,"AliHLTTPCFileHandler::AliDigits2Memory","Row") | |
487 | <<AliHLTTPCLog::kDec<<"Rows in slice " << fSlice << " dont match "<<lrow<<" "<<r<<ENDLOG; | |
488 | continue; | |
489 | } | |
490 | ||
491 | ndigits[lrow] = 0; | |
492 | fDigits->First(); | |
493 | do { | |
494 | time=fDigits->CurrentRow(); | |
495 | pad=fDigits->CurrentColumn(); | |
496 | dig = fDigits->GetDigit(time,pad); | |
497 | if(dig <= fParam->GetZeroSup()) continue; | |
498 | if(dig >= AliHLTTPCTransform::GetADCSat()) | |
499 | dig = AliHLTTPCTransform::GetADCSat(); | |
500 | ||
501 | AliHLTTPCTransform::Raw2Local(xyz,sector,row,pad,time); | |
502 | // if(fParam->GetPadRowRadii(sector,row)<230./250.*fabs(xyz[2])) | |
503 | // continue; // why 230??? | |
504 | ||
505 | ndigits[lrow]++; //for this row only | |
506 | ndigitcount++; //total number of digits to be published | |
507 | ||
508 | } while (fDigits->Next()); | |
509 | //cout << lrow << " " << ndigits[lrow] << " - " << ndigitcount << endl; | |
510 | } | |
511 | nrows++; | |
512 | } | |
513 | ||
514 | Int_t size = sizeof(AliHLTTPCDigitData)*ndigitcount | |
515 | + nrows*sizeof(AliHLTTPCDigitRowData); | |
516 | ||
517 | LOG(AliHLTTPCLog::kDebug,"AliHLTTPCFileHandler::AliDigits2Memory","Digits") | |
518 | <<AliHLTTPCLog::kDec<<"Found "<<ndigitcount<<" Digits"<<ENDLOG; | |
519 | ||
5578cf60 | 520 | if (tgtBuffer!=NULL && pTgtSize!=NULL && *pTgtSize>0) { |
521 | if (size<=*pTgtSize) { | |
522 | data=reinterpret_cast<AliHLTTPCDigitRowData*>(tgtBuffer); | |
523 | } else { | |
524 | } | |
525 | } else { | |
526 | data=reinterpret_cast<AliHLTTPCDigitRowData*>(Allocate(size)); | |
527 | } | |
528 | if (pTgtSize) *pTgtSize=size; | |
529 | if (data==NULL) return NULL; | |
a6c02c85 | 530 | nrow = (UInt_t)nrows; |
531 | AliHLTTPCDigitRowData *tempPt = data; | |
532 | ||
533 | for(Int_t r=fRowMin;r<=fRowMax;r++){ | |
534 | Int_t n=fIndex[fSlice][r]; | |
535 | tempPt->fRow = r; | |
536 | tempPt->fNDigit = 0; | |
537 | ||
538 | if(n!=-1){//data on that row | |
539 | fDigitsTree->GetEvent(n); | |
540 | fParam->AdjustSectorRow(fDigits->GetID(),sector,row); | |
541 | AliHLTTPCTransform::Sector2Slice(lslice,lrow,sector,row); | |
542 | if(lrow!=r){ | |
543 | LOG(AliHLTTPCLog::kError,"AliHLTTPCFileHandler::AliDigits2Memory","Row") | |
544 | <<AliHLTTPCLog::kDec<<"Rows on slice " << fSlice << " dont match "<<lrow<<" "<<r<<ENDLOG; | |
545 | continue; | |
546 | } | |
547 | ||
548 | tempPt->fNDigit = ndigits[lrow]; | |
549 | ||
550 | Int_t localcount=0; | |
551 | fDigits->First(); | |
552 | do { | |
553 | time=fDigits->CurrentRow(); | |
554 | pad=fDigits->CurrentColumn(); | |
555 | dig = fDigits->GetDigit(time,pad); | |
556 | if (dig <= fParam->GetZeroSup()) continue; | |
557 | if(dig >= AliHLTTPCTransform::GetADCSat()) | |
558 | dig = AliHLTTPCTransform::GetADCSat(); | |
559 | ||
560 | //Exclude data outside cone: | |
561 | AliHLTTPCTransform::Raw2Local(xyz,sector,row,pad,time); | |
562 | // if(fParam->GetPadRowRadii(sector,row)<230./250.*fabs(xyz[2])) | |
563 | // continue; // why 230??? | |
564 | ||
565 | if(localcount >= ndigits[lrow]) | |
566 | LOG(AliHLTTPCLog::kFatal,"AliHLTTPCFileHandler::AliDigits2Binary","Memory") | |
567 | <<AliHLTTPCLog::kDec<<"Mismatch: localcount "<<localcount<<" ndigits " | |
568 | <<ndigits[lrow]<<ENDLOG; | |
569 | ||
570 | tempPt->fDigitData[localcount].fCharge=dig; | |
571 | tempPt->fDigitData[localcount].fPad=pad; | |
572 | tempPt->fDigitData[localcount].fTime=time; | |
a6c02c85 | 573 | tempPt->fDigitData[localcount].fTrackID[0] = fDigits->GetTrackID(time,pad,0); |
574 | tempPt->fDigitData[localcount].fTrackID[1] = fDigits->GetTrackID(time,pad,1); | |
575 | tempPt->fDigitData[localcount].fTrackID[2] = fDigits->GetTrackID(time,pad,2); | |
a6c02c85 | 576 | localcount++; |
577 | } while (fDigits->Next()); | |
61692dfa | 578 | Byte_t *tmp = (Byte_t*)tempPt; |
579 | Int_t size = sizeof(AliHLTTPCDigitRowData) | |
580 | + ndigits[lrow]*sizeof(AliHLTTPCDigitData); | |
581 | tmp += size; | |
582 | tempPt = (AliHLTTPCDigitRowData*)tmp; | |
a6c02c85 | 583 | } |
a6c02c85 | 584 | } |
585 | delete [] ndigits; | |
586 | return data; | |
587 | } | |
588 | ||
589 | AliHLTTPCDigitRowData * AliHLTTPCFileHandler::AliAltroDigits2Memory(UInt_t & nrow,Int_t event,Bool_t eventmerge) | |
590 | { | |
591 | //Read data from AliROOT file into memory, and store it in the HLT data format. | |
592 | //Returns a pointer to the data. | |
593 | //This functions filter out single timebins, which is noise. The timebins which | |
594 | //are removed are timebins which have the 4 zero neighbours; | |
595 | //(pad-1,time),(pad+1,time),(pad,time-1),(pad,time+1). | |
596 | ||
597 | AliHLTTPCDigitRowData *data = 0; | |
598 | nrow=0; | |
599 | ||
600 | if(!fInAli){ | |
601 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCFileHandler::AliAltroDigits2Memory","File") | |
602 | <<"No Input avalible: Pointer to TFile == NULL"<<ENDLOG; | |
603 | return 0; | |
604 | } | |
a6c02c85 | 605 | if(eventmerge == kTRUE && event >= 1024) |
606 | { | |
607 | LOG(AliHLTTPCLog::kError,"AliHLTTPCFileHandler::AliAltroDigits2Memory","TrackIDs") | |
608 | <<"Too many events if you want to merge!"<<ENDLOG; | |
609 | return 0; | |
610 | } | |
611 | delete fDigits; | |
612 | fDigits=0; | |
a6c02c85 | 613 | /* Dont understand why we have to do |
614 | reload the tree, but otherwise the code crashes */ | |
615 | fDigitsTree=0; | |
616 | if(!GetDigitsTree(event)) return 0; | |
a6c02c85 | 617 | |
618 | UShort_t dig; | |
619 | Int_t time,pad,sector,row; | |
620 | Int_t nrows=0; | |
621 | Int_t ndigitcount=0; | |
622 | Int_t entries = (Int_t)fDigitsTree->GetEntries(); | |
623 | if(entries==0) { | |
624 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCFileHandler::AliAltroDigits2Memory","ndigits") | |
625 | <<"No TPC digits (entries==0)!"<<ENDLOG; | |
626 | nrow = (UInt_t)(fRowMax-fRowMin+1); | |
627 | Int_t size = nrow*sizeof(AliHLTTPCDigitRowData); | |
628 | data=(AliHLTTPCDigitRowData*) Allocate(size); | |
629 | AliHLTTPCDigitRowData *tempPt = data; | |
630 | for(Int_t r=fRowMin;r<=fRowMax;r++){ | |
631 | tempPt->fRow = r; | |
632 | tempPt->fNDigit = 0; | |
633 | tempPt++; | |
634 | } | |
635 | return data; | |
636 | } | |
637 | Int_t * ndigits = new Int_t[fRowMax+1]; | |
638 | Int_t lslice,lrow; | |
639 | Int_t zerosupval=AliHLTTPCTransform::GetZeroSup(); | |
640 | Float_t xyz[3]; | |
641 | ||
642 | for(Int_t r=fRowMin;r<=fRowMax;r++){ | |
643 | Int_t n=fIndex[fSlice][r]; | |
644 | ||
645 | ndigits[r] = 0; | |
646 | ||
647 | if(n!=-1){//data on that row | |
648 | fDigitsTree->GetEvent(n); | |
649 | fParam->AdjustSectorRow(fDigits->GetID(),sector,row); | |
650 | AliHLTTPCTransform::Sector2Slice(lslice,lrow,sector,row); | |
651 | //cout << lslice << " " << fSlice << " " << lrow << " " << r << " " << sector << " " << row << endl; | |
652 | if((lslice!=fSlice)||(lrow!=r)){ | |
653 | LOG(AliHLTTPCLog::kError,"AliHLTTPCFileHandler::AliAltroDigits2Memory","Row") | |
654 | <<AliHLTTPCLog::kDec<<"Rows on slice " << fSlice << " dont match "<<lrow<<" "<<r<<ENDLOG; | |
655 | continue; | |
656 | } | |
657 | ||
658 | fDigits->ExpandBuffer(); | |
659 | fDigits->ExpandTrackBuffer(); | |
660 | for(Int_t i=0; i<fDigits->GetNCols(); i++){ | |
661 | for(Int_t j=0; j<fDigits->GetNRows(); j++){ | |
662 | pad=i; | |
663 | time=j; | |
664 | dig = fDigits->GetDigitFast(time,pad); | |
665 | if(dig <= zerosupval) continue; | |
666 | if(dig >= AliHLTTPCTransform::GetADCSat()) | |
667 | dig = AliHLTTPCTransform::GetADCSat(); | |
668 | ||
669 | //Check for single timebins, and remove them because they are noise for sure. | |
670 | if(i>0 && i<fDigits->GetNCols()-1 && j>0 && j<fDigits->GetNRows()-1) | |
671 | if(fDigits->GetDigitFast(time,pad-1)<=zerosupval && | |
672 | fDigits->GetDigitFast(time-1,pad)<=zerosupval && | |
673 | fDigits->GetDigitFast(time+1,pad)<=zerosupval && | |
674 | fDigits->GetDigitFast(time,pad+1)<=zerosupval) | |
675 | continue; | |
676 | ||
677 | //Boundaries: | |
678 | if(i==0) //pad==0 | |
679 | { | |
680 | if(j < fDigits->GetNRows()-1 && j > 0) | |
681 | { | |
682 | if(fDigits->GetDigitFast(time-1,pad)<=zerosupval && | |
683 | fDigits->GetDigitFast(time+1,pad)<=zerosupval && | |
684 | fDigits->GetDigitFast(time,pad+1)<=zerosupval) | |
685 | continue; | |
686 | } | |
687 | else if(j > 0) | |
688 | { | |
689 | if(fDigits->GetDigitFast(time-1,pad)<=zerosupval && | |
690 | fDigits->GetDigitFast(time,pad+1)<=zerosupval) | |
691 | continue; | |
692 | } | |
693 | } | |
694 | if(j==0) | |
695 | { | |
696 | if(i < fDigits->GetNCols()-1 && i > 0) | |
697 | { | |
698 | if(fDigits->GetDigitFast(time,pad-1)<=zerosupval && | |
699 | fDigits->GetDigitFast(time,pad+1)<=zerosupval && | |
700 | fDigits->GetDigitFast(time+1,pad)<=zerosupval) | |
701 | continue; | |
702 | } | |
703 | else if(i > 0) | |
704 | { | |
705 | if(fDigits->GetDigitFast(time,pad-1)<=zerosupval && | |
706 | fDigits->GetDigitFast(time+1,pad)<=zerosupval) | |
707 | continue; | |
708 | } | |
709 | } | |
710 | ||
711 | if(i==fDigits->GetNCols()-1) | |
712 | { | |
713 | if(j>0 && j<fDigits->GetNRows()-1) | |
714 | { | |
715 | if(fDigits->GetDigitFast(time-1,pad)<=zerosupval && | |
716 | fDigits->GetDigitFast(time+1,pad)<=zerosupval && | |
717 | fDigits->GetDigitFast(time,pad-1)<=zerosupval) | |
718 | continue; | |
719 | } | |
720 | else if(j==0 && j<fDigits->GetNRows()-1) | |
721 | { | |
722 | if(fDigits->GetDigitFast(time+1,pad)<=zerosupval && | |
723 | fDigits->GetDigitFast(time,pad-1)<=zerosupval) | |
724 | continue; | |
725 | } | |
726 | else | |
727 | { | |
728 | if(fDigits->GetDigitFast(time-1,pad)<=zerosupval && | |
729 | fDigits->GetDigitFast(time,pad-1)<=zerosupval) | |
730 | continue; | |
731 | } | |
732 | } | |
733 | ||
734 | if(j==fDigits->GetNRows()-1) | |
735 | { | |
736 | if(i>0 && i<fDigits->GetNCols()-1) | |
737 | { | |
738 | if(fDigits->GetDigitFast(time,pad-1)<=zerosupval && | |
739 | fDigits->GetDigitFast(time,pad+1)<=zerosupval && | |
740 | fDigits->GetDigitFast(time-1,pad)<=zerosupval) | |
741 | continue; | |
742 | } | |
743 | else if(i==0 && fDigits->GetNCols()-1) | |
744 | { | |
745 | if(fDigits->GetDigitFast(time,pad+1)<=zerosupval && | |
746 | fDigits->GetDigitFast(time-1,pad)<=zerosupval) | |
747 | continue; | |
748 | } | |
749 | else | |
750 | { | |
751 | if(fDigits->GetDigitFast(time,pad-1)<=zerosupval && | |
752 | fDigits->GetDigitFast(time-1,pad)<=zerosupval) | |
753 | continue; | |
754 | } | |
755 | } | |
756 | ||
757 | AliHLTTPCTransform::Raw2Local(xyz,sector,row,pad,time); | |
758 | // if(fParam->GetPadRowRadii(sector,row)<230./250.*fabs(xyz[2])) | |
759 | // continue; | |
760 | ||
761 | ndigits[lrow]++; //for this row only | |
762 | ndigitcount++; //total number of digits to be published | |
763 | } | |
764 | } | |
765 | } | |
766 | nrows++; | |
767 | } | |
768 | ||
769 | Int_t size = sizeof(AliHLTTPCDigitData)*ndigitcount | |
770 | + nrows*sizeof(AliHLTTPCDigitRowData); | |
771 | ||
772 | LOG(AliHLTTPCLog::kDebug,"AliHLTTPCFileHandler::AliAltroDigits2Memory","Digits") | |
773 | <<AliHLTTPCLog::kDec<<"Found "<<ndigitcount<<" Digits"<<ENDLOG; | |
774 | ||
775 | data=(AliHLTTPCDigitRowData*) Allocate(size); | |
776 | nrow = (UInt_t)nrows; | |
777 | AliHLTTPCDigitRowData *tempPt = data; | |
778 | ||
779 | for(Int_t r=fRowMin;r<=fRowMax;r++){ | |
780 | Int_t n=fIndex[fSlice][r]; | |
781 | tempPt->fRow = r; | |
782 | tempPt->fNDigit = 0; | |
783 | if(n!=-1){ //no data on that row | |
784 | fDigitsTree->GetEvent(n); | |
785 | fParam->AdjustSectorRow(fDigits->GetID(),sector,row); | |
786 | AliHLTTPCTransform::Sector2Slice(lslice,lrow,sector,row); | |
787 | ||
788 | if(lrow!=r){ | |
789 | LOG(AliHLTTPCLog::kError,"AliHLTTPCFileHandler::AliAltroDigits2Memory","Row") | |
790 | <<AliHLTTPCLog::kDec<<"Rows on slice " << fSlice << " dont match "<<lrow<<" "<<r<<ENDLOG; | |
791 | continue; | |
792 | } | |
793 | ||
794 | tempPt->fNDigit = ndigits[lrow]; | |
795 | ||
796 | Int_t localcount=0; | |
797 | fDigits->ExpandBuffer(); | |
798 | fDigits->ExpandTrackBuffer(); | |
799 | for(Int_t i=0; i<fDigits->GetNCols(); i++){ | |
800 | for(Int_t j=0; j<fDigits->GetNRows(); j++){ | |
801 | pad=i; | |
802 | time=j; | |
803 | dig = fDigits->GetDigitFast(time,pad); | |
804 | if(dig <= zerosupval) continue; | |
805 | if(dig >= AliHLTTPCTransform::GetADCSat()) | |
806 | dig = AliHLTTPCTransform::GetADCSat(); | |
807 | ||
808 | //Check for single timebins, and remove them because they are noise for sure. | |
809 | if(i>0 && i<fDigits->GetNCols()-1 && j>0 && j<fDigits->GetNRows()-1) | |
810 | if(fDigits->GetDigitFast(time,pad-1)<=zerosupval && | |
811 | fDigits->GetDigitFast(time-1,pad)<=zerosupval && | |
812 | fDigits->GetDigitFast(time+1,pad)<=zerosupval && | |
813 | fDigits->GetDigitFast(time,pad+1)<=zerosupval) | |
814 | continue; | |
815 | ||
816 | //Boundaries: | |
817 | if(i==0) //pad ==0 | |
818 | { | |
819 | if(j < fDigits->GetNRows()-1 && j > 0) | |
820 | { | |
821 | if(fDigits->GetDigitFast(time-1,pad)<=zerosupval && | |
822 | fDigits->GetDigitFast(time+1,pad)<=zerosupval && | |
823 | fDigits->GetDigitFast(time,pad+1)<=zerosupval) | |
824 | continue; | |
825 | } | |
826 | else if(j > 0) | |
827 | { | |
828 | if(fDigits->GetDigitFast(time-1,pad)<=zerosupval && | |
829 | fDigits->GetDigitFast(time,pad+1)<=zerosupval) | |
830 | continue; | |
831 | } | |
832 | } | |
833 | if(j==0) | |
834 | { | |
835 | if(i < fDigits->GetNCols()-1 && i > 0) | |
836 | { | |
837 | if(fDigits->GetDigitFast(time,pad-1)<=zerosupval && | |
838 | fDigits->GetDigitFast(time,pad+1)<=zerosupval && | |
839 | fDigits->GetDigitFast(time+1,pad)<=zerosupval) | |
840 | continue; | |
841 | } | |
842 | else if(i > 0) | |
843 | { | |
844 | if(fDigits->GetDigitFast(time,pad-1)<=zerosupval && | |
845 | fDigits->GetDigitFast(time+1,pad)<=zerosupval) | |
846 | continue; | |
847 | } | |
848 | } | |
849 | ||
850 | if(i == fDigits->GetNCols()-1) | |
851 | { | |
852 | if(j>0 && j<fDigits->GetNRows()-1) | |
853 | { | |
854 | if(fDigits->GetDigitFast(time-1,pad)<=zerosupval && | |
855 | fDigits->GetDigitFast(time+1,pad)<=zerosupval && | |
856 | fDigits->GetDigitFast(time,pad-1)<=zerosupval) | |
857 | continue; | |
858 | } | |
859 | else if(j==0 && j<fDigits->GetNRows()-1) | |
860 | { | |
861 | if(fDigits->GetDigitFast(time+1,pad)<=zerosupval && | |
862 | fDigits->GetDigitFast(time,pad-1)<=zerosupval) | |
863 | continue; | |
864 | } | |
865 | else | |
866 | { | |
867 | if(fDigits->GetDigitFast(time-1,pad)<=zerosupval && | |
868 | fDigits->GetDigitFast(time,pad-1)<=zerosupval) | |
869 | continue; | |
870 | } | |
871 | } | |
872 | if(j==fDigits->GetNRows()-1) | |
873 | { | |
874 | if(i>0 && i<fDigits->GetNCols()-1) | |
875 | { | |
876 | if(fDigits->GetDigitFast(time,pad-1)<=zerosupval && | |
877 | fDigits->GetDigitFast(time,pad+1)<=zerosupval && | |
878 | fDigits->GetDigitFast(time-1,pad)<=zerosupval) | |
879 | continue; | |
880 | } | |
881 | else if(i==0 && fDigits->GetNCols()-1) | |
882 | { | |
883 | if(fDigits->GetDigitFast(time,pad+1)<=zerosupval && | |
884 | fDigits->GetDigitFast(time-1,pad)<=zerosupval) | |
885 | continue; | |
886 | } | |
887 | else | |
888 | { | |
889 | if(fDigits->GetDigitFast(time,pad-1)<=zerosupval && | |
890 | fDigits->GetDigitFast(time-1,pad)<=zerosupval) | |
891 | continue; | |
892 | } | |
893 | } | |
894 | ||
895 | AliHLTTPCTransform::Raw2Local(xyz,sector,row,pad,time); | |
896 | // if(fParam->GetPadRowRadii(sector,row)<230./250.*fabs(xyz[2])) | |
897 | // continue; | |
898 | ||
899 | if(localcount >= ndigits[lrow]) | |
900 | LOG(AliHLTTPCLog::kFatal,"AliHLTTPCFileHandler::AliAltroDigits2Binary","Memory") | |
901 | <<AliHLTTPCLog::kDec<<"Mismatch: localcount "<<localcount<<" ndigits " | |
902 | <<ndigits[lrow]<<ENDLOG; | |
903 | ||
904 | tempPt->fDigitData[localcount].fCharge=dig; | |
905 | tempPt->fDigitData[localcount].fPad=pad; | |
906 | tempPt->fDigitData[localcount].fTime=time; | |
a6c02c85 | 907 | tempPt->fDigitData[localcount].fTrackID[0] = (fDigits->GetTrackIDFast(time,pad,0)-2); |
908 | tempPt->fDigitData[localcount].fTrackID[1] = (fDigits->GetTrackIDFast(time,pad,1)-2); | |
909 | tempPt->fDigitData[localcount].fTrackID[2] = (fDigits->GetTrackIDFast(time,pad,2)-2); | |
910 | if(eventmerge == kTRUE) //careful track mc info will be touched | |
911 | {//Event are going to be merged, so event number is stored in the upper 10 bits. | |
912 | tempPt->fDigitData[localcount].fTrackID[0] += 128; //leave some room | |
913 | tempPt->fDigitData[localcount].fTrackID[1] += 128; //for neg. numbers | |
914 | tempPt->fDigitData[localcount].fTrackID[2] += 128; | |
915 | tempPt->fDigitData[localcount].fTrackID[0] += ((event&0x3ff)<<22); | |
916 | tempPt->fDigitData[localcount].fTrackID[1] += ((event&0x3ff)<<22); | |
917 | tempPt->fDigitData[localcount].fTrackID[2] += ((event&0x3ff)<<22); | |
918 | } | |
a6c02c85 | 919 | localcount++; |
920 | } | |
921 | } | |
922 | } | |
923 | Byte_t *tmp = (Byte_t*)tempPt; | |
924 | Int_t size = sizeof(AliHLTTPCDigitRowData) | |
925 | + ndigits[r]*sizeof(AliHLTTPCDigitData); | |
926 | tmp += size; | |
927 | tempPt = (AliHLTTPCDigitRowData*)tmp; | |
928 | } | |
929 | delete [] ndigits; | |
930 | return data; | |
931 | } | |
932 | ||
933 | Bool_t AliHLTTPCFileHandler::GetDigitsTree(Int_t event) | |
934 | { | |
935 | //Connects to the TPC digit tree in the AliROOT file. | |
a6c02c85 | 936 | AliLoader* tpcLoader = fInAli->GetLoader("TPCLoader"); |
937 | if(!tpcLoader){ | |
938 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCFileHandler::GetDigitsTree","File") | |
939 | <<"Pointer to AliLoader for TPC = 0x0 "<<ENDLOG; | |
940 | return kFALSE; | |
941 | } | |
942 | fInAli->GetEvent(event); | |
943 | tpcLoader->LoadDigits(); | |
944 | fDigitsTree = tpcLoader->TreeD(); | |
a6c02c85 | 945 | if(!fDigitsTree) |
946 | { | |
947 | LOG(AliHLTTPCLog::kError,"AliHLTTPCFileHandler::GetDigitsTree","Digits Tree") | |
948 | <<AliHLTTPCLog::kHex<<"Error getting digitstree "<<(void*)fDigitsTree<<ENDLOG; | |
949 | return kFALSE; | |
950 | } | |
951 | fDigitsTree->GetBranch("Segment")->SetAddress(&fDigits); | |
952 | ||
953 | if(!fIndexCreated) return CreateIndex(); | |
954 | else return kTRUE; | |
955 | } | |
956 | ||
95d48915 | 957 | void AliHLTTPCFileHandler::AliDigits2RootFile(AliHLTTPCDigitRowData *rowPt,Char_t *newDigitsfile) |
a6c02c85 | 958 | { |
959 | //Write the data stored in rowPt, into a new AliROOT file. | |
960 | //The data is stored in the AliROOT format | |
961 | //This is specially a nice thing if you have modified data, and wants to run it | |
962 | //through the offline reconstruction chain. | |
963 | //The arguments is a pointer to the data, and the name of the new AliROOT file. | |
964 | //Remember to pass the original AliROOT file (the one that contains the original | |
965 | //simulated data) to this object, in order to retrieve the MC id's of the digits. | |
966 | ||
967 | if(!fInAli) | |
968 | { | |
969 | LOG(AliHLTTPCLog::kError,"AliHLTTPCFileHandler::AliDigits2RootFile","File") | |
970 | <<"No rootfile "<<ENDLOG; | |
971 | return; | |
972 | } | |
973 | if(!fParam) | |
974 | { | |
975 | LOG(AliHLTTPCLog::kError,"AliHLTTPCFileHandler::AliDigits2RootFile","File") | |
976 | <<"No parameter object. Run on rootfile "<<ENDLOG; | |
977 | return; | |
978 | } | |
979 | ||
a6c02c85 | 980 | //Get the original digitstree: |
981 | AliLoader* tpcLoader = fInAli->GetLoader("TPCLoader"); | |
982 | if(!tpcLoader){ | |
983 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCFileHandler::AliDigits2RootFile","File") | |
984 | <<"Pointer to AliLoader for TPC = 0x0 "<<ENDLOG; | |
985 | return; | |
986 | } | |
987 | tpcLoader->LoadDigits(); | |
988 | TTree *t=tpcLoader->TreeD(); | |
989 | ||
95d48915 | 990 | AliTPCDigitsArray *oldArray = new AliTPCDigitsArray(); |
991 | oldArray->Setup(fParam); | |
992 | oldArray->SetClass("AliSimDigits"); | |
a6c02c85 | 993 | |
95d48915 | 994 | Bool_t ok = oldArray->ConnectTree(t); |
a6c02c85 | 995 | if(!ok) |
996 | { | |
997 | LOG(AliHLTTPCLog::kError,"AliHLTTPCFileHandler::AliDigits2RootFile","File") | |
998 | << "No digits tree object" << ENDLOG; | |
999 | return; | |
1000 | } | |
1001 | ||
95d48915 | 1002 | tpcLoader->SetDigitsFileName(newDigitsfile); |
a6c02c85 | 1003 | tpcLoader->MakeDigitsContainer(); |
1004 | ||
1005 | //setup a new one, or connect it to the existing one: | |
1006 | AliTPCDigitsArray *arr = new AliTPCDigitsArray(); | |
1007 | arr->SetClass("AliSimDigits"); | |
1008 | arr->Setup(fParam); | |
1009 | arr->MakeTree(tpcLoader->TreeD()); | |
a6c02c85 | 1010 | |
1011 | Int_t digcounter=0,trackID[3]; | |
1012 | ||
1013 | for(Int_t i=fRowMin; i<=fRowMax; i++) | |
1014 | { | |
1015 | ||
1016 | if((Int_t)rowPt->fRow != i) | |
1017 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCFileHandler::AliDigits2RootFile","Data") | |
1018 | <<"Mismatching row numbering "<<(Int_t)rowPt->fRow<<" "<<i<<ENDLOG; | |
1019 | ||
1020 | Int_t sector,row; | |
1021 | AliHLTTPCTransform::Slice2Sector(fSlice,i,sector,row); | |
1022 | ||
95d48915 | 1023 | AliSimDigits *oldDig = (AliSimDigits*)oldArray->LoadRow(sector,row); |
a6c02c85 | 1024 | AliSimDigits * dig = (AliSimDigits*)arr->CreateRow(sector,row); |
95d48915 | 1025 | oldDig->ExpandBuffer(); |
1026 | oldDig->ExpandTrackBuffer(); | |
a6c02c85 | 1027 | dig->ExpandBuffer(); |
1028 | dig->ExpandTrackBuffer(); | |
1029 | ||
95d48915 | 1030 | if(!oldDig) |
a6c02c85 | 1031 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCFileHandler::AliDigits2RootFile","Data") |
1032 | <<"No padrow " << sector << " " << row <<ENDLOG; | |
1033 | ||
1034 | AliHLTTPCDigitData *digPt = rowPt->fDigitData; | |
1035 | digcounter=0; | |
1036 | for(UInt_t j=0; j<rowPt->fNDigit; j++) | |
1037 | { | |
1038 | Short_t charge = (Short_t)digPt[j].fCharge; | |
1039 | Int_t pad = (Int_t)digPt[j].fPad; | |
1040 | Int_t time = (Int_t)digPt[j].fTime; | |
1041 | ||
1042 | if(charge == 0) //Only write the digits that has not been removed | |
1043 | { | |
1044 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCFileHandler::AliDigits2RootFile","Data") | |
1045 | <<"Zero charge" <<ENDLOG; | |
1046 | continue; | |
1047 | } | |
1048 | ||
1049 | digcounter++; | |
1050 | ||
1051 | //Tricks to get and set the correct track id's. | |
1052 | for(Int_t t=0; t<3; t++) | |
1053 | { | |
95d48915 | 1054 | Int_t label = oldDig->GetTrackIDFast(time,pad,t); |
a6c02c85 | 1055 | if(label > 1) |
1056 | trackID[t] = label - 2; | |
1057 | else if(label==0) | |
1058 | trackID[t] = -2; | |
1059 | else | |
1060 | trackID[t] = -1; | |
1061 | } | |
1062 | ||
1063 | dig->SetDigitFast(charge,time,pad); | |
1064 | ||
1065 | for(Int_t t=0; t<3; t++) | |
1066 | ((AliSimDigits*)dig)->SetTrackIDFast(trackID[t],time,pad,t); | |
1067 | ||
1068 | } | |
1069 | //cout<<"Wrote "<<digcounter<<" on row "<<i<<endl; | |
1070 | UpdateRowPointer(rowPt); | |
1071 | arr->StoreRow(sector,row); | |
1072 | arr->ClearRow(sector,row); | |
95d48915 | 1073 | oldArray->ClearRow(sector,row); |
a6c02c85 | 1074 | } |
1075 | ||
1076 | char treeName[100]; | |
1077 | sprintf(treeName,"TreeD_%s_0",fParam->GetTitle()); | |
1078 | ||
a6c02c85 | 1079 | arr->GetTree()->SetName(treeName); |
1080 | arr->GetTree()->AutoSave(); | |
1081 | tpcLoader->WriteDigits("OVERWRITE"); | |
a6c02c85 | 1082 | delete arr; |
95d48915 | 1083 | delete oldArray; |
a6c02c85 | 1084 | } |
1085 | ||
1086 | ///////////////////////////////////////// Point IO | |
1087 | Bool_t AliHLTTPCFileHandler::AliPoints2Binary(Int_t eventn) | |
1088 | { | |
1089 | //points to binary | |
1090 | Bool_t out = kTRUE; | |
1091 | UInt_t npoint; | |
1092 | AliHLTTPCSpacePointData *data = AliPoints2Memory(npoint,eventn); | |
1093 | out = Memory2Binary(npoint,data); | |
1094 | Free(); | |
1095 | return out; | |
1096 | } | |
1097 | ||
1098 | AliHLTTPCSpacePointData * AliHLTTPCFileHandler::AliPoints2Memory(UInt_t & npoint,Int_t eventn) | |
1099 | { | |
1100 | //points to memory | |
1101 | AliHLTTPCSpacePointData *data = 0; | |
1102 | npoint=0; | |
1103 | if(!fInAli){ | |
1104 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCFileHandler::AliPoints2Memory","File") | |
1105 | <<"No Input avalible: no object fInAli"<<ENDLOG; | |
1106 | return 0; | |
1107 | } | |
a6c02c85 | 1108 | |
1109 | TDirectory *savedir = gDirectory; | |
a6c02c85 | 1110 | AliLoader* tpcLoader = fInAli->GetLoader("TPCLoader"); |
1111 | if(!tpcLoader){ | |
1112 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCFileHandler::AliPoints2Memory","File") | |
1113 | <<"Pointer to AliLoader for TPC = 0x0 "<<ENDLOG; | |
1114 | return 0; | |
1115 | } | |
1116 | fInAli->GetEvent(eventn); | |
1117 | tpcLoader->LoadRecPoints(); | |
1118 | ||
1119 | AliTPCClustersArray carray; | |
1120 | carray.Setup(fParam); | |
1121 | carray.SetClusterType("AliTPCcluster"); | |
1122 | Bool_t clusterok = carray.ConnectTree(tpcLoader->TreeR()); | |
a6c02c85 | 1123 | |
1124 | if(!clusterok) return 0; | |
1125 | ||
1126 | AliTPCClustersRow ** clusterrow = | |
1127 | new AliTPCClustersRow*[ (int)carray.GetTree()->GetEntries()]; | |
1128 | Int_t *rows = new int[ (int)carray.GetTree()->GetEntries()]; | |
1129 | Int_t *sects = new int[ (int)carray.GetTree()->GetEntries()]; | |
1130 | Int_t sum=0; | |
1131 | ||
1132 | Int_t lslice,lrow; | |
1133 | for(Int_t i=0; i<carray.GetTree()->GetEntries(); i++){ | |
1134 | AliSegmentID *s = carray.LoadEntry(i); | |
1135 | Int_t sector,row; | |
1136 | fParam->AdjustSectorRow(s->GetID(),sector,row); | |
1137 | rows[i] = row; | |
1138 | sects[i] = sector; | |
1139 | clusterrow[i] = 0; | |
1140 | AliHLTTPCTransform::Sector2Slice(lslice,lrow,sector,row); | |
1141 | if(fSlice != lslice || lrow<fRowMin || lrow>fRowMax) continue; | |
1142 | clusterrow[i] = carray.GetRow(sector,row); | |
1143 | if(clusterrow[i]) | |
1144 | sum+=clusterrow[i]->GetArray()->GetEntriesFast(); | |
1145 | } | |
1146 | UInt_t size = sum*sizeof(AliHLTTPCSpacePointData); | |
1147 | ||
1148 | LOG(AliHLTTPCLog::kDebug,"AliHLTTPCFileHandler::AliPoints2Memory","File") | |
1149 | <<AliHLTTPCLog::kDec<<"Found "<<sum<<" SpacePoints"<<ENDLOG; | |
1150 | ||
1151 | data = (AliHLTTPCSpacePointData *) Allocate(size); | |
1152 | npoint = sum; | |
1153 | UInt_t n=0; | |
1154 | Int_t pat=fPatch; | |
1155 | if(fPatch==-1) | |
1156 | pat=0; | |
1157 | for(Int_t i=0; i<carray.GetTree()->GetEntries(); i++){ | |
1158 | if(!clusterrow[i]) continue; | |
1159 | Int_t row = rows[i]; | |
1160 | Int_t sector = sects[i]; | |
1161 | AliHLTTPCTransform::Sector2Slice(lslice,lrow,sector,row); | |
95d48915 | 1162 | Int_t entriesInRow = clusterrow[i]->GetArray()->GetEntriesFast(); |
1163 | for(Int_t j = 0;j<entriesInRow;j++){ | |
a6c02c85 | 1164 | AliTPCcluster *c = (AliTPCcluster*)(*clusterrow[i])[j]; |
1165 | data[n].fZ = c->GetZ(); | |
1166 | data[n].fY = c->GetY(); | |
1167 | data[n].fX = fParam->GetPadRowRadii(sector,row); | |
1168 | data[n].fCharge = (UInt_t)c->GetQ(); | |
1169 | data[n].fID = n+((fSlice&0x7f)<<25)+((pat&0x7)<<22);//uli | |
1170 | data[n].fPadRow = lrow; | |
1171 | data[n].fSigmaY2 = c->GetSigmaY2(); | |
1172 | data[n].fSigmaZ2 = c->GetSigmaZ2(); | |
1173 | #ifdef do_mc | |
1174 | data[n].fTrackID[0] = c->GetLabel(0); | |
1175 | data[n].fTrackID[1] = c->GetLabel(1); | |
1176 | data[n].fTrackID[2] = c->GetLabel(2); | |
1177 | #endif | |
1178 | if(fMC) fprintf(fMC,"%d %d\n",data[n].fID,c->GetLabel(0)); | |
1179 | n++; | |
1180 | } | |
1181 | } | |
1182 | for(Int_t i=0;i<carray.GetTree()->GetEntries();i++){ | |
1183 | Int_t row = rows[i]; | |
1184 | Int_t sector = sects[i]; | |
1185 | if(carray.GetRow(sector,row)) | |
1186 | carray.ClearRow(sector,row); | |
1187 | } | |
1188 | ||
1189 | delete [] clusterrow; | |
1190 | delete [] rows; | |
1191 | delete [] sects; | |
1192 | savedir->cd(); | |
1193 | ||
1194 | return data; | |
1195 | } | |
1196 |