]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/TPCLib/AliHLTTPCFileHandler.cxx
added TPC conformal mapping tracking to default simulation; improved robustness in...
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCFileHandler.cxx
CommitLineData
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 */
055fed30 34#include <cassert>
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
59using 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
100ClassImp(AliHLTTPCFileHandler)
101
600e6a1b 102AliHLTTPCFileHandler::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 122AliHLTTPCFileHandler::~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
131Bool_t AliHLTTPCFileHandler::fgStaticIndexCreated=kFALSE;
132Int_t AliHLTTPCFileHandler::fgStaticIndex[36][159];
133
134void 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
145Int_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
168Int_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 196void 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
212Bool_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
224Bool_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
236void 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
248Bool_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
269Bool_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 281Bool_t AliHLTTPCFileHandler::SetAliInput(AliRunLoader *runLoader)
282{
283 //set ali input as runloader
cae431d0 284 if(!runLoader){
a6c02c85 285 LOG(AliHLTTPCLog::kWarning,"AliHLTTPCFileHandler::SetAliInput","File Open")
cae431d0 286 <<"invalid agument: pointer to AliRunLoader NULL "<<ENDLOG;
287 return kFALSE;
288 }
289 if (fInAli!=NULL && fInAli!=runLoader) {
290 LOG(AliHLTTPCLog::kError,"AliHLTTPCFileHandler::SetAliInput","File Open")
291 <<"Pointer to AliRunLoader already set"<<ENDLOG;
a6c02c85 292 return kFALSE;
293 }
cae431d0 294 fInAli=runLoader;
295 fUseRunLoader = kTRUE;
a6c02c85 296 return SetAliInput();
297}
a6c02c85 298
299void AliHLTTPCFileHandler::CloseAliInput()
300{
301 //close ali input
a6c02c85 302 if(fUseRunLoader) return;
a6c02c85 303 if(!fInAli){
304 LOG(AliHLTTPCLog::kWarning,"AliHLTTPCFileHandler::CloseAliInput","RunLoader")
305 <<"Nothing to Close"<<ENDLOG;
306 return;
307 }
a6c02c85 308
309 delete fInAli;
310 fInAli = 0;
311}
312
313Bool_t AliHLTTPCFileHandler::IsDigit(Int_t event)
314{
315 //Check if there is a TPC digit tree in the current file.
316 //Return kTRUE if tree was found, and kFALSE if not found.
317
318 if(!fInAli){
319 LOG(AliHLTTPCLog::kWarning,"AliHLTTPCFileHandler::IsDigit","File")
320 <<"Pointer to fInAli = 0x0 "<<ENDLOG;
321 return kTRUE; //maybe you are using binary input which is Digits!
322 }
a6c02c85 323 AliLoader* tpcLoader = fInAli->GetLoader("TPCLoader");
324 if(!tpcLoader){
325 LOG(AliHLTTPCLog::kWarning,"AliHLTTPCFileHandlerNewIO::IsDigit","File")
326 <<"Pointer to AliLoader for TPC = 0x0 "<<ENDLOG;
327 return kFALSE;
328 }
329 fInAli->GetEvent(event);
330 tpcLoader->LoadDigits();
331 TTree *t=tpcLoader->TreeD();
a6c02c85 332 if(t){
333 LOG(AliHLTTPCLog::kInformational,"AliHLTTPCFileHandlerNewIO::IsDigit","File Type")
334 <<"Found Digit Tree -> Use Fast Cluster Finder"<<ENDLOG;
335 return kTRUE;
336 }
337 else{
338 LOG(AliHLTTPCLog::kInformational,"AliHLTTPCFileHandlerNewIO::IsDigit","File Type")
339 <<"No Digit Tree -> Use Cluster Tree"<<ENDLOG;
340 return kFALSE;
341 }
342}
343
344///////////////////////////////////////// Digit IO
5578cf60 345Bool_t AliHLTTPCFileHandler::AliDigits2BinaryFile(Int_t event,Bool_t altro)
a6c02c85 346{
347 //save alidigits as binary
348 Bool_t out = kTRUE;
349 UInt_t nrow;
350 AliHLTTPCDigitRowData* data = 0;
351 if(altro)
352 data = AliAltroDigits2Memory(nrow,event);
353 else
354 data = AliDigits2Memory(nrow,event);
5578cf60 355 out = Memory2BinaryFile(nrow,data);
a6c02c85 356 Free();
357 return out;
358}
359
360Bool_t AliHLTTPCFileHandler::AliDigits2CompBinary(Int_t event,Bool_t altro)
361{
362 //Convert AliROOT TPC data, into HLT data format.
363 //event specifies the event you want in the aliroot file.
364
365 Bool_t out = kTRUE;
366 UInt_t ndigits=0;
367 AliHLTTPCDigitRowData *digits=0;
368 if(altro)
369 digits = AliAltroDigits2Memory(ndigits,event);
370 else
371 digits = AliDigits2Memory(ndigits,event);
372 out = Memory2CompBinary(ndigits,digits);
373 Free();
374 return out;
375}
376
377Bool_t AliHLTTPCFileHandler::CreateIndex()
378{
379 //create the access index or copy from static index
380 fIndexCreated=kFALSE;
381
382 if(!fgStaticIndexCreated || !fUseStaticIndex) { //we have to create index
383 LOG(AliHLTTPCLog::kInformational,"AliHLTTPCFileHandler::CreateIndex","Index")
384 <<"Starting to create index, this can take a while."<<ENDLOG;
385
5d2abf3b 386 //Int_t lslice,lrow;
a6c02c85 387 for(Int_t n=0; n<fDigitsTree->GetEntries(); n++) {
388 Int_t sector, row;
389 Int_t lslice,lrow;
390 fDigitsTree->GetEvent(n);
391 fParam->AdjustSectorRow(fDigits->GetID(),sector,row);
392 if(!AliHLTTPCTransform::Sector2Slice(lslice,lrow,sector,row)){
393 LOG(AliHLTTPCLog::kError,"AliHLTTPCFileHandler::CreateIndex","Slice/Row")
394 <<AliHLTTPCLog::kDec<<"Index could not be created. Wrong values "
395 <<sector<<" "<<row<<ENDLOG;
396 return kFALSE;
397 }
0ba35c53 398 // this is just to make sure the same array dimensions are
399 // used as in the AliHLTTPCTransform class. The check for
400 // correct bounds is done in AliHLTTPCTransform::Sector2Slice
401 assert(lslice>=0 && lslice<fgkNSlice);
402 assert(lrow>=0 && lrow<fgkNRow);
a6c02c85 403 if(fIndex[lslice][lrow]==-1) {
404 fIndex[lslice][lrow]=n;
405 }
406 }
0ba35c53 407 assert(AliHLTTPCTransform::GetNSlice()==fgkNSlice);
408 assert(AliHLTTPCTransform::GetNRows()==fgkNRow);
a6c02c85 409 if(fUseStaticIndex) { // create static index
0ba35c53 410 for(Int_t islice=0;islice<AliHLTTPCTransform::GetNSlice() && islice<fgkNSlice;islice++){
411 for(Int_t irow=0;irow<AliHLTTPCTransform::GetNRows() && irow<fgkNRow;irow++)
412 fgStaticIndex[islice][irow]=fIndex[islice][irow];
a6c02c85 413 }
414 fgStaticIndexCreated=kTRUE; //remember that index has been created
415 }
416
417 LOG(AliHLTTPCLog::kInformational,"AliHLTTPCFileHandler::CreateIndex","Index")
418 <<"Index successfully created."<<ENDLOG;
419
420 } else if(fUseStaticIndex) { //simply copy static index
0ba35c53 421 for(Int_t islice=0;islice<AliHLTTPCTransform::GetNSlice() && islice<fgkNSlice;islice++){
422 for(Int_t irow=0;irow<AliHLTTPCTransform::GetNRows() && irow<fgkNRow;irow++)
423 fIndex[islice][irow]=fgStaticIndex[islice][irow];
a6c02c85 424 }
425
426 LOG(AliHLTTPCLog::kInformational,"AliHLTTPCFileHandler::CreateIndex","Index")
427 <<"Index successfully taken from static copy."<<ENDLOG;
428 }
429 fIndexCreated=kTRUE;
430 return kTRUE;
431}
432
5578cf60 433AliHLTTPCDigitRowData * AliHLTTPCFileHandler::AliDigits2Memory(UInt_t & nrow,Int_t event, Byte_t* tgtBuffer, UInt_t *pTgtSize)
a6c02c85 434{
5578cf60 435 //Read data from AliROOT file into memory, and store it in the HLT data format
436 //in the provided buffer or an allocated buffer.
a6c02c85 437 //Returns a pointer to the data.
438
439 AliHLTTPCDigitRowData *data = 0;
440 nrow=0;
441
442 if(!fInAli){
443 LOG(AliHLTTPCLog::kWarning,"AliHLTTPCFileHandler::AliDigits2Memory","File")
444 <<"No Input avalible: Pointer to fInAli == NULL"<<ENDLOG;
445 return 0;
446 }
447
a6c02c85 448 if(!fDigitsTree)
449 if(!GetDigitsTree(event)) return 0;
450
451 UShort_t dig;
452 Int_t time,pad,sector,row;
a6c02c85 453 Int_t nrows=0;
454 Int_t ndigitcount=0;
455 Int_t entries = (Int_t)fDigitsTree->GetEntries();
456 if(entries==0) {
457 LOG(AliHLTTPCLog::kWarning,"AliHLTTPCFileHandler::AliDigits2Memory","ndigits")
458 <<"No TPC digits (entries==0)!"<<ENDLOG;
459 nrow = (UInt_t)(fRowMax-fRowMin+1);
298ef463 460 UInt_t size = nrow*sizeof(AliHLTTPCDigitRowData);
5578cf60 461 if (tgtBuffer!=NULL && pTgtSize!=NULL && *pTgtSize>0) {
462 if (size<=*pTgtSize) {
463 data=reinterpret_cast<AliHLTTPCDigitRowData*>(tgtBuffer);
464 } else {
465 }
466 } else {
467 data=reinterpret_cast<AliHLTTPCDigitRowData*>(Allocate(size));
468 }
a6c02c85 469 AliHLTTPCDigitRowData *tempPt = data;
5578cf60 470 if (data) {
471 if (pTgtSize) *pTgtSize=size;
a6c02c85 472 for(Int_t r=fRowMin;r<=fRowMax;r++){
473 tempPt->fRow = r;
474 tempPt->fNDigit = 0;
475 tempPt++;
476 }
5578cf60 477 }
a6c02c85 478 return data;
479 }
480
481 Int_t * ndigits = new Int_t[fRowMax+1];
482 Float_t xyz[3];
483
5578cf60 484 // The digits of the current event have been indexed: all digits are organized in
485 // rows, all digits of one row are stored in a AliSimDigits object (fDigit) which
486 // are stored in the digit tree.
487 // The index map relates the AliSimDigits objects in the tree to dedicated pad rows
488 // in the TPC
489 // This loop filters the pad rows according to the slice no set via Init
0ba35c53 490 assert(fRowMax<fgkNRow);
491 for(Int_t r=fRowMin;r<=fRowMax && r<fgkNRow;r++){
a6c02c85 492 Int_t n=fIndex[fSlice][r];
5578cf60 493 if(n!=-1){ // there is data on that row available
055fed30 494 Int_t lslice,lrow;
a6c02c85 495 fDigitsTree->GetEvent(n);
496 fParam->AdjustSectorRow(fDigits->GetID(),sector,row);
497 AliHLTTPCTransform::Sector2Slice(lslice,lrow,sector,row);
055fed30 498// LOG(AliHLTTPCLog::kInformational,"AliHLTTPCFileHandler::AliDigits2Memory","Digits")
499// << "Sector "<<sector<<" Row " << row << " Slice " << lslice << " lrow " << lrow<<ENDLOG;
a6c02c85 500
501 if(lrow!=r){
502 LOG(AliHLTTPCLog::kError,"AliHLTTPCFileHandler::AliDigits2Memory","Row")
503 <<AliHLTTPCLog::kDec<<"Rows in slice " << fSlice << " dont match "<<lrow<<" "<<r<<ENDLOG;
504 continue;
505 }
506
507 ndigits[lrow] = 0;
508 fDigits->First();
509 do {
510 time=fDigits->CurrentRow();
511 pad=fDigits->CurrentColumn();
512 dig = fDigits->GetDigit(time,pad);
513 if(dig <= fParam->GetZeroSup()) continue;
514 if(dig >= AliHLTTPCTransform::GetADCSat())
515 dig = AliHLTTPCTransform::GetADCSat();
516
517 AliHLTTPCTransform::Raw2Local(xyz,sector,row,pad,time);
518 // if(fParam->GetPadRowRadii(sector,row)<230./250.*fabs(xyz[2]))
519 // continue; // why 230???
520
521 ndigits[lrow]++; //for this row only
522 ndigitcount++; //total number of digits to be published
523
524 } while (fDigits->Next());
525 //cout << lrow << " " << ndigits[lrow] << " - " << ndigitcount << endl;
526 }
055fed30 527 //see comment below//nrows++;
a6c02c85 528 }
055fed30 529 // Matthias 05.11.2007
530 // The question is whether we should always return a AliHLTTPCDigitRowData
531 // for each row, even the empty ones or only for the ones filled with data.
532 // the AliHLTTPCDigitReaderUnpacked as the counnterpart so far assumes
533 // empty RawData structs for empty rows. But some of the code here implies
534 // the latter approach, e.g. the count of nrows in the loop above (now
535 // commented). At least the two loops were not consistent, it's fixed now.
536 nrows=fRowMax-fRowMin+1;
537
538 UInt_t bufferSize = sizeof(AliHLTTPCDigitData)*ndigitcount
a6c02c85 539 + nrows*sizeof(AliHLTTPCDigitRowData);
540
541 LOG(AliHLTTPCLog::kDebug,"AliHLTTPCFileHandler::AliDigits2Memory","Digits")
055fed30 542 << "Found "<<ndigitcount<<" Digits in " << nrows << " rows out of [" << fRowMin << "," << fRowMax <<"]"<<ENDLOG;
543
5578cf60 544 if (tgtBuffer!=NULL && pTgtSize!=NULL && *pTgtSize>0) {
055fed30 545 if (bufferSize<=*pTgtSize) {
5578cf60 546 data=reinterpret_cast<AliHLTTPCDigitRowData*>(tgtBuffer);
547 } else {
548 }
055fed30 549 } else if (bufferSize>0) {
550 data=reinterpret_cast<AliHLTTPCDigitRowData*>(Allocate(bufferSize));
551 }
552 if (pTgtSize) *pTgtSize=bufferSize;
553 if (data==NULL) {
554 delete [] ndigits;
555 return NULL;
5578cf60 556 }
a6c02c85 557 nrow = (UInt_t)nrows;
558 AliHLTTPCDigitRowData *tempPt = data;
055fed30 559 memset(data, 0, bufferSize);
a6c02c85 560
0ba35c53 561 for(Int_t r=fRowMin;r<=fRowMax && r<fgkNRow;r++){
a6c02c85 562 Int_t n=fIndex[fSlice][r];
055fed30 563
564 AliHLTTPCTransform::Slice2Sector(fSlice,r,sector,row);
565 tempPt->fRow = row;
a6c02c85 566 tempPt->fNDigit = 0;
567
568 if(n!=-1){//data on that row
055fed30 569 Int_t lslice,lrow;
a6c02c85 570 fDigitsTree->GetEvent(n);
571 fParam->AdjustSectorRow(fDigits->GetID(),sector,row);
572 AliHLTTPCTransform::Sector2Slice(lslice,lrow,sector,row);
573 if(lrow!=r){
574 LOG(AliHLTTPCLog::kError,"AliHLTTPCFileHandler::AliDigits2Memory","Row")
575 <<AliHLTTPCLog::kDec<<"Rows on slice " << fSlice << " dont match "<<lrow<<" "<<r<<ENDLOG;
576 continue;
577 }
578
055fed30 579 // set the correct row no and digit count
580 tempPt->fRow = row;
a6c02c85 581 tempPt->fNDigit = ndigits[lrow];
582
583 Int_t localcount=0;
584 fDigits->First();
585 do {
586 time=fDigits->CurrentRow();
587 pad=fDigits->CurrentColumn();
588 dig = fDigits->GetDigit(time,pad);
589 if (dig <= fParam->GetZeroSup()) continue;
590 if(dig >= AliHLTTPCTransform::GetADCSat())
591 dig = AliHLTTPCTransform::GetADCSat();
592
593 //Exclude data outside cone:
594 AliHLTTPCTransform::Raw2Local(xyz,sector,row,pad,time);
595 // if(fParam->GetPadRowRadii(sector,row)<230./250.*fabs(xyz[2]))
596 // continue; // why 230???
597
598 if(localcount >= ndigits[lrow])
599 LOG(AliHLTTPCLog::kFatal,"AliHLTTPCFileHandler::AliDigits2Binary","Memory")
600 <<AliHLTTPCLog::kDec<<"Mismatch: localcount "<<localcount<<" ndigits "
601 <<ndigits[lrow]<<ENDLOG;
602
603 tempPt->fDigitData[localcount].fCharge=dig;
604 tempPt->fDigitData[localcount].fPad=pad;
605 tempPt->fDigitData[localcount].fTime=time;
a6c02c85 606 tempPt->fDigitData[localcount].fTrackID[0] = fDigits->GetTrackID(time,pad,0);
607 tempPt->fDigitData[localcount].fTrackID[1] = fDigits->GetTrackID(time,pad,1);
608 tempPt->fDigitData[localcount].fTrackID[2] = fDigits->GetTrackID(time,pad,2);
a6c02c85 609 localcount++;
610 } while (fDigits->Next());
611 }
055fed30 612
613 Byte_t *tmp = (Byte_t*)tempPt;
614 Int_t blockSize = sizeof(AliHLTTPCDigitRowData)
615 + tempPt->fNDigit*sizeof(AliHLTTPCDigitData);
616 tmp += blockSize;
617 tempPt = (AliHLTTPCDigitRowData*)tmp;
a6c02c85 618 }
055fed30 619 assert((Byte_t*)tempPt==((Byte_t*)data)+bufferSize);
a6c02c85 620 delete [] ndigits;
621 return data;
622}
623
624AliHLTTPCDigitRowData * AliHLTTPCFileHandler::AliAltroDigits2Memory(UInt_t & nrow,Int_t event,Bool_t eventmerge)
625{
626 //Read data from AliROOT file into memory, and store it in the HLT data format.
627 //Returns a pointer to the data.
628 //This functions filter out single timebins, which is noise. The timebins which
629 //are removed are timebins which have the 4 zero neighbours;
630 //(pad-1,time),(pad+1,time),(pad,time-1),(pad,time+1).
631
632 AliHLTTPCDigitRowData *data = 0;
633 nrow=0;
634
635 if(!fInAli){
636 LOG(AliHLTTPCLog::kWarning,"AliHLTTPCFileHandler::AliAltroDigits2Memory","File")
637 <<"No Input avalible: Pointer to TFile == NULL"<<ENDLOG;
638 return 0;
639 }
a6c02c85 640 if(eventmerge == kTRUE && event >= 1024)
641 {
642 LOG(AliHLTTPCLog::kError,"AliHLTTPCFileHandler::AliAltroDigits2Memory","TrackIDs")
643 <<"Too many events if you want to merge!"<<ENDLOG;
644 return 0;
645 }
646 delete fDigits;
647 fDigits=0;
a6c02c85 648 /* Dont understand why we have to do
649 reload the tree, but otherwise the code crashes */
650 fDigitsTree=0;
651 if(!GetDigitsTree(event)) return 0;
a6c02c85 652
653 UShort_t dig;
654 Int_t time,pad,sector,row;
655 Int_t nrows=0;
656 Int_t ndigitcount=0;
657 Int_t entries = (Int_t)fDigitsTree->GetEntries();
658 if(entries==0) {
659 LOG(AliHLTTPCLog::kWarning,"AliHLTTPCFileHandler::AliAltroDigits2Memory","ndigits")
660 <<"No TPC digits (entries==0)!"<<ENDLOG;
661 nrow = (UInt_t)(fRowMax-fRowMin+1);
662 Int_t size = nrow*sizeof(AliHLTTPCDigitRowData);
663 data=(AliHLTTPCDigitRowData*) Allocate(size);
664 AliHLTTPCDigitRowData *tempPt = data;
665 for(Int_t r=fRowMin;r<=fRowMax;r++){
666 tempPt->fRow = r;
667 tempPt->fNDigit = 0;
668 tempPt++;
669 }
670 return data;
671 }
672 Int_t * ndigits = new Int_t[fRowMax+1];
673 Int_t lslice,lrow;
674 Int_t zerosupval=AliHLTTPCTransform::GetZeroSup();
675 Float_t xyz[3];
676
0ba35c53 677 for(Int_t r=fRowMin;r<=fRowMax && r<fgkNRow;r++){
a6c02c85 678 Int_t n=fIndex[fSlice][r];
679
680 ndigits[r] = 0;
681
682 if(n!=-1){//data on that row
683 fDigitsTree->GetEvent(n);
684 fParam->AdjustSectorRow(fDigits->GetID(),sector,row);
685 AliHLTTPCTransform::Sector2Slice(lslice,lrow,sector,row);
686 //cout << lslice << " " << fSlice << " " << lrow << " " << r << " " << sector << " " << row << endl;
687 if((lslice!=fSlice)||(lrow!=r)){
688 LOG(AliHLTTPCLog::kError,"AliHLTTPCFileHandler::AliAltroDigits2Memory","Row")
689 <<AliHLTTPCLog::kDec<<"Rows on slice " << fSlice << " dont match "<<lrow<<" "<<r<<ENDLOG;
690 continue;
691 }
692
693 fDigits->ExpandBuffer();
694 fDigits->ExpandTrackBuffer();
695 for(Int_t i=0; i<fDigits->GetNCols(); i++){
696 for(Int_t j=0; j<fDigits->GetNRows(); j++){
697 pad=i;
698 time=j;
699 dig = fDigits->GetDigitFast(time,pad);
700 if(dig <= zerosupval) continue;
701 if(dig >= AliHLTTPCTransform::GetADCSat())
702 dig = AliHLTTPCTransform::GetADCSat();
703
704 //Check for single timebins, and remove them because they are noise for sure.
705 if(i>0 && i<fDigits->GetNCols()-1 && j>0 && j<fDigits->GetNRows()-1)
706 if(fDigits->GetDigitFast(time,pad-1)<=zerosupval &&
707 fDigits->GetDigitFast(time-1,pad)<=zerosupval &&
708 fDigits->GetDigitFast(time+1,pad)<=zerosupval &&
709 fDigits->GetDigitFast(time,pad+1)<=zerosupval)
710 continue;
711
712 //Boundaries:
713 if(i==0) //pad==0
714 {
715 if(j < fDigits->GetNRows()-1 && j > 0)
716 {
717 if(fDigits->GetDigitFast(time-1,pad)<=zerosupval &&
718 fDigits->GetDigitFast(time+1,pad)<=zerosupval &&
719 fDigits->GetDigitFast(time,pad+1)<=zerosupval)
720 continue;
721 }
722 else if(j > 0)
723 {
724 if(fDigits->GetDigitFast(time-1,pad)<=zerosupval &&
725 fDigits->GetDigitFast(time,pad+1)<=zerosupval)
726 continue;
727 }
728 }
729 if(j==0)
730 {
731 if(i < fDigits->GetNCols()-1 && i > 0)
732 {
733 if(fDigits->GetDigitFast(time,pad-1)<=zerosupval &&
734 fDigits->GetDigitFast(time,pad+1)<=zerosupval &&
735 fDigits->GetDigitFast(time+1,pad)<=zerosupval)
736 continue;
737 }
738 else if(i > 0)
739 {
740 if(fDigits->GetDigitFast(time,pad-1)<=zerosupval &&
741 fDigits->GetDigitFast(time+1,pad)<=zerosupval)
742 continue;
743 }
744 }
745
746 if(i==fDigits->GetNCols()-1)
747 {
748 if(j>0 && j<fDigits->GetNRows()-1)
749 {
750 if(fDigits->GetDigitFast(time-1,pad)<=zerosupval &&
751 fDigits->GetDigitFast(time+1,pad)<=zerosupval &&
752 fDigits->GetDigitFast(time,pad-1)<=zerosupval)
753 continue;
754 }
755 else if(j==0 && j<fDigits->GetNRows()-1)
756 {
757 if(fDigits->GetDigitFast(time+1,pad)<=zerosupval &&
758 fDigits->GetDigitFast(time,pad-1)<=zerosupval)
759 continue;
760 }
761 else
762 {
763 if(fDigits->GetDigitFast(time-1,pad)<=zerosupval &&
764 fDigits->GetDigitFast(time,pad-1)<=zerosupval)
765 continue;
766 }
767 }
768
769 if(j==fDigits->GetNRows()-1)
770 {
771 if(i>0 && i<fDigits->GetNCols()-1)
772 {
773 if(fDigits->GetDigitFast(time,pad-1)<=zerosupval &&
774 fDigits->GetDigitFast(time,pad+1)<=zerosupval &&
775 fDigits->GetDigitFast(time-1,pad)<=zerosupval)
776 continue;
777 }
778 else if(i==0 && fDigits->GetNCols()-1)
779 {
780 if(fDigits->GetDigitFast(time,pad+1)<=zerosupval &&
781 fDigits->GetDigitFast(time-1,pad)<=zerosupval)
782 continue;
783 }
784 else
785 {
786 if(fDigits->GetDigitFast(time,pad-1)<=zerosupval &&
787 fDigits->GetDigitFast(time-1,pad)<=zerosupval)
788 continue;
789 }
790 }
791
792 AliHLTTPCTransform::Raw2Local(xyz,sector,row,pad,time);
793 // if(fParam->GetPadRowRadii(sector,row)<230./250.*fabs(xyz[2]))
794 // continue;
795
796 ndigits[lrow]++; //for this row only
797 ndigitcount++; //total number of digits to be published
798 }
799 }
800 }
801 nrows++;
802 }
803
804 Int_t size = sizeof(AliHLTTPCDigitData)*ndigitcount
805 + nrows*sizeof(AliHLTTPCDigitRowData);
806
807 LOG(AliHLTTPCLog::kDebug,"AliHLTTPCFileHandler::AliAltroDigits2Memory","Digits")
808 <<AliHLTTPCLog::kDec<<"Found "<<ndigitcount<<" Digits"<<ENDLOG;
809
810 data=(AliHLTTPCDigitRowData*) Allocate(size);
811 nrow = (UInt_t)nrows;
812 AliHLTTPCDigitRowData *tempPt = data;
813
814 for(Int_t r=fRowMin;r<=fRowMax;r++){
815 Int_t n=fIndex[fSlice][r];
816 tempPt->fRow = r;
817 tempPt->fNDigit = 0;
818 if(n!=-1){ //no data on that row
819 fDigitsTree->GetEvent(n);
820 fParam->AdjustSectorRow(fDigits->GetID(),sector,row);
821 AliHLTTPCTransform::Sector2Slice(lslice,lrow,sector,row);
822
823 if(lrow!=r){
824 LOG(AliHLTTPCLog::kError,"AliHLTTPCFileHandler::AliAltroDigits2Memory","Row")
825 <<AliHLTTPCLog::kDec<<"Rows on slice " << fSlice << " dont match "<<lrow<<" "<<r<<ENDLOG;
826 continue;
827 }
828
829 tempPt->fNDigit = ndigits[lrow];
830
831 Int_t localcount=0;
832 fDigits->ExpandBuffer();
833 fDigits->ExpandTrackBuffer();
834 for(Int_t i=0; i<fDigits->GetNCols(); i++){
835 for(Int_t j=0; j<fDigits->GetNRows(); j++){
836 pad=i;
837 time=j;
838 dig = fDigits->GetDigitFast(time,pad);
839 if(dig <= zerosupval) continue;
840 if(dig >= AliHLTTPCTransform::GetADCSat())
841 dig = AliHLTTPCTransform::GetADCSat();
842
843 //Check for single timebins, and remove them because they are noise for sure.
844 if(i>0 && i<fDigits->GetNCols()-1 && j>0 && j<fDigits->GetNRows()-1)
845 if(fDigits->GetDigitFast(time,pad-1)<=zerosupval &&
846 fDigits->GetDigitFast(time-1,pad)<=zerosupval &&
847 fDigits->GetDigitFast(time+1,pad)<=zerosupval &&
848 fDigits->GetDigitFast(time,pad+1)<=zerosupval)
849 continue;
850
851 //Boundaries:
852 if(i==0) //pad ==0
853 {
854 if(j < fDigits->GetNRows()-1 && j > 0)
855 {
856 if(fDigits->GetDigitFast(time-1,pad)<=zerosupval &&
857 fDigits->GetDigitFast(time+1,pad)<=zerosupval &&
858 fDigits->GetDigitFast(time,pad+1)<=zerosupval)
859 continue;
860 }
861 else if(j > 0)
862 {
863 if(fDigits->GetDigitFast(time-1,pad)<=zerosupval &&
864 fDigits->GetDigitFast(time,pad+1)<=zerosupval)
865 continue;
866 }
867 }
868 if(j==0)
869 {
870 if(i < fDigits->GetNCols()-1 && i > 0)
871 {
872 if(fDigits->GetDigitFast(time,pad-1)<=zerosupval &&
873 fDigits->GetDigitFast(time,pad+1)<=zerosupval &&
874 fDigits->GetDigitFast(time+1,pad)<=zerosupval)
875 continue;
876 }
877 else if(i > 0)
878 {
879 if(fDigits->GetDigitFast(time,pad-1)<=zerosupval &&
880 fDigits->GetDigitFast(time+1,pad)<=zerosupval)
881 continue;
882 }
883 }
884
885 if(i == fDigits->GetNCols()-1)
886 {
887 if(j>0 && j<fDigits->GetNRows()-1)
888 {
889 if(fDigits->GetDigitFast(time-1,pad)<=zerosupval &&
890 fDigits->GetDigitFast(time+1,pad)<=zerosupval &&
891 fDigits->GetDigitFast(time,pad-1)<=zerosupval)
892 continue;
893 }
894 else if(j==0 && j<fDigits->GetNRows()-1)
895 {
896 if(fDigits->GetDigitFast(time+1,pad)<=zerosupval &&
897 fDigits->GetDigitFast(time,pad-1)<=zerosupval)
898 continue;
899 }
900 else
901 {
902 if(fDigits->GetDigitFast(time-1,pad)<=zerosupval &&
903 fDigits->GetDigitFast(time,pad-1)<=zerosupval)
904 continue;
905 }
906 }
907 if(j==fDigits->GetNRows()-1)
908 {
909 if(i>0 && i<fDigits->GetNCols()-1)
910 {
911 if(fDigits->GetDigitFast(time,pad-1)<=zerosupval &&
912 fDigits->GetDigitFast(time,pad+1)<=zerosupval &&
913 fDigits->GetDigitFast(time-1,pad)<=zerosupval)
914 continue;
915 }
916 else if(i==0 && fDigits->GetNCols()-1)
917 {
918 if(fDigits->GetDigitFast(time,pad+1)<=zerosupval &&
919 fDigits->GetDigitFast(time-1,pad)<=zerosupval)
920 continue;
921 }
922 else
923 {
924 if(fDigits->GetDigitFast(time,pad-1)<=zerosupval &&
925 fDigits->GetDigitFast(time-1,pad)<=zerosupval)
926 continue;
927 }
928 }
929
930 AliHLTTPCTransform::Raw2Local(xyz,sector,row,pad,time);
931 // if(fParam->GetPadRowRadii(sector,row)<230./250.*fabs(xyz[2]))
932 // continue;
933
934 if(localcount >= ndigits[lrow])
935 LOG(AliHLTTPCLog::kFatal,"AliHLTTPCFileHandler::AliAltroDigits2Binary","Memory")
936 <<AliHLTTPCLog::kDec<<"Mismatch: localcount "<<localcount<<" ndigits "
937 <<ndigits[lrow]<<ENDLOG;
938
939 tempPt->fDigitData[localcount].fCharge=dig;
940 tempPt->fDigitData[localcount].fPad=pad;
941 tempPt->fDigitData[localcount].fTime=time;
a6c02c85 942 tempPt->fDigitData[localcount].fTrackID[0] = (fDigits->GetTrackIDFast(time,pad,0)-2);
943 tempPt->fDigitData[localcount].fTrackID[1] = (fDigits->GetTrackIDFast(time,pad,1)-2);
944 tempPt->fDigitData[localcount].fTrackID[2] = (fDigits->GetTrackIDFast(time,pad,2)-2);
945 if(eventmerge == kTRUE) //careful track mc info will be touched
946 {//Event are going to be merged, so event number is stored in the upper 10 bits.
947 tempPt->fDigitData[localcount].fTrackID[0] += 128; //leave some room
948 tempPt->fDigitData[localcount].fTrackID[1] += 128; //for neg. numbers
949 tempPt->fDigitData[localcount].fTrackID[2] += 128;
950 tempPt->fDigitData[localcount].fTrackID[0] += ((event&0x3ff)<<22);
951 tempPt->fDigitData[localcount].fTrackID[1] += ((event&0x3ff)<<22);
952 tempPt->fDigitData[localcount].fTrackID[2] += ((event&0x3ff)<<22);
953 }
a6c02c85 954 localcount++;
955 }
956 }
957 }
958 Byte_t *tmp = (Byte_t*)tempPt;
959 Int_t size = sizeof(AliHLTTPCDigitRowData)
960 + ndigits[r]*sizeof(AliHLTTPCDigitData);
961 tmp += size;
962 tempPt = (AliHLTTPCDigitRowData*)tmp;
963 }
964 delete [] ndigits;
965 return data;
966}
967
968Bool_t AliHLTTPCFileHandler::GetDigitsTree(Int_t event)
969{
970 //Connects to the TPC digit tree in the AliROOT file.
a6c02c85 971 AliLoader* tpcLoader = fInAli->GetLoader("TPCLoader");
972 if(!tpcLoader){
973 LOG(AliHLTTPCLog::kWarning,"AliHLTTPCFileHandler::GetDigitsTree","File")
974 <<"Pointer to AliLoader for TPC = 0x0 "<<ENDLOG;
975 return kFALSE;
976 }
977 fInAli->GetEvent(event);
978 tpcLoader->LoadDigits();
979 fDigitsTree = tpcLoader->TreeD();
a6c02c85 980 if(!fDigitsTree)
981 {
982 LOG(AliHLTTPCLog::kError,"AliHLTTPCFileHandler::GetDigitsTree","Digits Tree")
983 <<AliHLTTPCLog::kHex<<"Error getting digitstree "<<(void*)fDigitsTree<<ENDLOG;
984 return kFALSE;
985 }
986 fDigitsTree->GetBranch("Segment")->SetAddress(&fDigits);
987
988 if(!fIndexCreated) return CreateIndex();
989 else return kTRUE;
990}
991
95d48915 992void AliHLTTPCFileHandler::AliDigits2RootFile(AliHLTTPCDigitRowData *rowPt,Char_t *newDigitsfile)
a6c02c85 993{
994 //Write the data stored in rowPt, into a new AliROOT file.
995 //The data is stored in the AliROOT format
996 //This is specially a nice thing if you have modified data, and wants to run it
997 //through the offline reconstruction chain.
998 //The arguments is a pointer to the data, and the name of the new AliROOT file.
999 //Remember to pass the original AliROOT file (the one that contains the original
1000 //simulated data) to this object, in order to retrieve the MC id's of the digits.
1001
1002 if(!fInAli)
1003 {
1004 LOG(AliHLTTPCLog::kError,"AliHLTTPCFileHandler::AliDigits2RootFile","File")
1005 <<"No rootfile "<<ENDLOG;
1006 return;
1007 }
1008 if(!fParam)
1009 {
1010 LOG(AliHLTTPCLog::kError,"AliHLTTPCFileHandler::AliDigits2RootFile","File")
1011 <<"No parameter object. Run on rootfile "<<ENDLOG;
1012 return;
1013 }
1014
a6c02c85 1015 //Get the original digitstree:
1016 AliLoader* tpcLoader = fInAli->GetLoader("TPCLoader");
1017 if(!tpcLoader){
1018 LOG(AliHLTTPCLog::kWarning,"AliHLTTPCFileHandler::AliDigits2RootFile","File")
1019 <<"Pointer to AliLoader for TPC = 0x0 "<<ENDLOG;
1020 return;
1021 }
1022 tpcLoader->LoadDigits();
1023 TTree *t=tpcLoader->TreeD();
1024
95d48915 1025 AliTPCDigitsArray *oldArray = new AliTPCDigitsArray();
1026 oldArray->Setup(fParam);
1027 oldArray->SetClass("AliSimDigits");
a6c02c85 1028
95d48915 1029 Bool_t ok = oldArray->ConnectTree(t);
a6c02c85 1030 if(!ok)
1031 {
1032 LOG(AliHLTTPCLog::kError,"AliHLTTPCFileHandler::AliDigits2RootFile","File")
1033 << "No digits tree object" << ENDLOG;
1034 return;
1035 }
1036
95d48915 1037 tpcLoader->SetDigitsFileName(newDigitsfile);
a6c02c85 1038 tpcLoader->MakeDigitsContainer();
1039
1040 //setup a new one, or connect it to the existing one:
1041 AliTPCDigitsArray *arr = new AliTPCDigitsArray();
1042 arr->SetClass("AliSimDigits");
1043 arr->Setup(fParam);
1044 arr->MakeTree(tpcLoader->TreeD());
a6c02c85 1045
1046 Int_t digcounter=0,trackID[3];
1047
1048 for(Int_t i=fRowMin; i<=fRowMax; i++)
1049 {
1050
1051 if((Int_t)rowPt->fRow != i)
1052 LOG(AliHLTTPCLog::kWarning,"AliHLTTPCFileHandler::AliDigits2RootFile","Data")
1053 <<"Mismatching row numbering "<<(Int_t)rowPt->fRow<<" "<<i<<ENDLOG;
1054
1055 Int_t sector,row;
1056 AliHLTTPCTransform::Slice2Sector(fSlice,i,sector,row);
1057
95d48915 1058 AliSimDigits *oldDig = (AliSimDigits*)oldArray->LoadRow(sector,row);
a6c02c85 1059 AliSimDigits * dig = (AliSimDigits*)arr->CreateRow(sector,row);
95d48915 1060 oldDig->ExpandBuffer();
1061 oldDig->ExpandTrackBuffer();
a6c02c85 1062 dig->ExpandBuffer();
1063 dig->ExpandTrackBuffer();
1064
95d48915 1065 if(!oldDig)
a6c02c85 1066 LOG(AliHLTTPCLog::kWarning,"AliHLTTPCFileHandler::AliDigits2RootFile","Data")
1067 <<"No padrow " << sector << " " << row <<ENDLOG;
1068
1069 AliHLTTPCDigitData *digPt = rowPt->fDigitData;
1070 digcounter=0;
1071 for(UInt_t j=0; j<rowPt->fNDigit; j++)
1072 {
1073 Short_t charge = (Short_t)digPt[j].fCharge;
1074 Int_t pad = (Int_t)digPt[j].fPad;
1075 Int_t time = (Int_t)digPt[j].fTime;
1076
1077 if(charge == 0) //Only write the digits that has not been removed
1078 {
1079 LOG(AliHLTTPCLog::kWarning,"AliHLTTPCFileHandler::AliDigits2RootFile","Data")
1080 <<"Zero charge" <<ENDLOG;
1081 continue;
1082 }
1083
1084 digcounter++;
1085
1086 //Tricks to get and set the correct track id's.
1087 for(Int_t t=0; t<3; t++)
1088 {
95d48915 1089 Int_t label = oldDig->GetTrackIDFast(time,pad,t);
a6c02c85 1090 if(label > 1)
1091 trackID[t] = label - 2;
1092 else if(label==0)
1093 trackID[t] = -2;
1094 else
1095 trackID[t] = -1;
1096 }
1097
1098 dig->SetDigitFast(charge,time,pad);
1099
1100 for(Int_t t=0; t<3; t++)
1101 ((AliSimDigits*)dig)->SetTrackIDFast(trackID[t],time,pad,t);
1102
1103 }
1104 //cout<<"Wrote "<<digcounter<<" on row "<<i<<endl;
1105 UpdateRowPointer(rowPt);
1106 arr->StoreRow(sector,row);
1107 arr->ClearRow(sector,row);
95d48915 1108 oldArray->ClearRow(sector,row);
a6c02c85 1109 }
1110
1111 char treeName[100];
1112 sprintf(treeName,"TreeD_%s_0",fParam->GetTitle());
1113
a6c02c85 1114 arr->GetTree()->SetName(treeName);
1115 arr->GetTree()->AutoSave();
1116 tpcLoader->WriteDigits("OVERWRITE");
a6c02c85 1117 delete arr;
95d48915 1118 delete oldArray;
a6c02c85 1119}
1120
1121///////////////////////////////////////// Point IO
1122Bool_t AliHLTTPCFileHandler::AliPoints2Binary(Int_t eventn)
1123{
1124 //points to binary
1125 Bool_t out = kTRUE;
1126 UInt_t npoint;
1127 AliHLTTPCSpacePointData *data = AliPoints2Memory(npoint,eventn);
1128 out = Memory2Binary(npoint,data);
1129 Free();
1130 return out;
1131}
1132
1133AliHLTTPCSpacePointData * AliHLTTPCFileHandler::AliPoints2Memory(UInt_t & npoint,Int_t eventn)
1134{
1135 //points to memory
1136 AliHLTTPCSpacePointData *data = 0;
1137 npoint=0;
1138 if(!fInAli){
1139 LOG(AliHLTTPCLog::kWarning,"AliHLTTPCFileHandler::AliPoints2Memory","File")
1140 <<"No Input avalible: no object fInAli"<<ENDLOG;
1141 return 0;
1142 }
a6c02c85 1143
1144 TDirectory *savedir = gDirectory;
a6c02c85 1145 AliLoader* tpcLoader = fInAli->GetLoader("TPCLoader");
1146 if(!tpcLoader){
1147 LOG(AliHLTTPCLog::kWarning,"AliHLTTPCFileHandler::AliPoints2Memory","File")
1148 <<"Pointer to AliLoader for TPC = 0x0 "<<ENDLOG;
1149 return 0;
1150 }
1151 fInAli->GetEvent(eventn);
1152 tpcLoader->LoadRecPoints();
1153
1154 AliTPCClustersArray carray;
1155 carray.Setup(fParam);
1156 carray.SetClusterType("AliTPCcluster");
1157 Bool_t clusterok = carray.ConnectTree(tpcLoader->TreeR());
a6c02c85 1158
1159 if(!clusterok) return 0;
1160
1161 AliTPCClustersRow ** clusterrow =
1162 new AliTPCClustersRow*[ (int)carray.GetTree()->GetEntries()];
1163 Int_t *rows = new int[ (int)carray.GetTree()->GetEntries()];
1164 Int_t *sects = new int[ (int)carray.GetTree()->GetEntries()];
1165 Int_t sum=0;
1166
1167 Int_t lslice,lrow;
1168 for(Int_t i=0; i<carray.GetTree()->GetEntries(); i++){
1169 AliSegmentID *s = carray.LoadEntry(i);
1170 Int_t sector,row;
1171 fParam->AdjustSectorRow(s->GetID(),sector,row);
1172 rows[i] = row;
1173 sects[i] = sector;
1174 clusterrow[i] = 0;
1175 AliHLTTPCTransform::Sector2Slice(lslice,lrow,sector,row);
1176 if(fSlice != lslice || lrow<fRowMin || lrow>fRowMax) continue;
1177 clusterrow[i] = carray.GetRow(sector,row);
1178 if(clusterrow[i])
1179 sum+=clusterrow[i]->GetArray()->GetEntriesFast();
1180 }
1181 UInt_t size = sum*sizeof(AliHLTTPCSpacePointData);
1182
1183 LOG(AliHLTTPCLog::kDebug,"AliHLTTPCFileHandler::AliPoints2Memory","File")
1184 <<AliHLTTPCLog::kDec<<"Found "<<sum<<" SpacePoints"<<ENDLOG;
1185
1186 data = (AliHLTTPCSpacePointData *) Allocate(size);
1187 npoint = sum;
1188 UInt_t n=0;
1189 Int_t pat=fPatch;
1190 if(fPatch==-1)
1191 pat=0;
1192 for(Int_t i=0; i<carray.GetTree()->GetEntries(); i++){
1193 if(!clusterrow[i]) continue;
1194 Int_t row = rows[i];
1195 Int_t sector = sects[i];
1196 AliHLTTPCTransform::Sector2Slice(lslice,lrow,sector,row);
95d48915 1197 Int_t entriesInRow = clusterrow[i]->GetArray()->GetEntriesFast();
1198 for(Int_t j = 0;j<entriesInRow;j++){
a6c02c85 1199 AliTPCcluster *c = (AliTPCcluster*)(*clusterrow[i])[j];
1200 data[n].fZ = c->GetZ();
1201 data[n].fY = c->GetY();
1202 data[n].fX = fParam->GetPadRowRadii(sector,row);
1203 data[n].fCharge = (UInt_t)c->GetQ();
1204 data[n].fID = n+((fSlice&0x7f)<<25)+((pat&0x7)<<22);//uli
1205 data[n].fPadRow = lrow;
1206 data[n].fSigmaY2 = c->GetSigmaY2();
1207 data[n].fSigmaZ2 = c->GetSigmaZ2();
1208#ifdef do_mc
1209 data[n].fTrackID[0] = c->GetLabel(0);
1210 data[n].fTrackID[1] = c->GetLabel(1);
1211 data[n].fTrackID[2] = c->GetLabel(2);
1212#endif
1213 if(fMC) fprintf(fMC,"%d %d\n",data[n].fID,c->GetLabel(0));
1214 n++;
1215 }
1216 }
1217 for(Int_t i=0;i<carray.GetTree()->GetEntries();i++){
1218 Int_t row = rows[i];
1219 Int_t sector = sects[i];
1220 if(carray.GetRow(sector,row))
1221 carray.ClearRow(sector,row);
1222 }
1223
1224 delete [] clusterrow;
1225 delete [] rows;
1226 delete [] sects;
1227 savedir->cd();
1228
1229 return data;
1230}
1231