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