]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/AliHLTTPCClusterFinderComponent.cxx
Update from Timo: Initialisation of AliGeomManager added
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCClusterFinderComponent.cxx
1 // $Id$
2
3 //**************************************************************************
4 //* This file is property of and copyright by the ALICE HLT Project        * 
5 //* ALICE Experiment at CERN, All rights reserved.                         *
6 //*                                                                        *
7 //* Primary Authors: Timm Steinbeck, Matthias Richter                      *
8 //* Developers:      Kenneth Aamodt <kenneth.aamodt@student.uib.no>        *
9 //*                  for The ALICE HLT Project.                            *
10 //*                                                                        *
11 //* Permission to use, copy, modify and distribute this software and its   *
12 //* documentation strictly for non-commercial purposes is hereby granted   *
13 //* without fee, provided that the above copyright notice appears in all   *
14 //* copies and that both the copyright notice and this permission notice   *
15 //* appear in the supporting documentation. The authors make no claims     *
16 //* about the suitability of this software for any purpose. It is          *
17 //* provided "as is" without express or implied warranty.                  *
18 //**************************************************************************
19
20 /** @file   AliHLTTPCClusterFinderComponent.cxx
21     @author Kenneth Aamodt <kenneth.aamodt@student.uib.no>
22     @date   
23     @brief  The TPC cluster finder processing component
24 */
25
26 #if __GNUC__>= 3
27 using namespace std;
28 #endif
29 #include "AliHLTTPCClusterFinderComponent.h"
30 #include "AliHLTTPCDigitReaderPacked.h"
31 #include "AliHLTTPCDigitReaderUnpacked.h"
32 #include "AliHLTTPCDigitReaderDecoder.h"
33 #include "AliHLTTPCDigitReader32Bit.h"
34 #include "AliHLTTPCClusterFinder.h"
35 #include "AliHLTTPCSpacePointData.h"
36 #include "AliHLTTPCClusterDataFormat.h"
37 #include "AliHLTTPCTransform.h"
38 #include "AliHLTTPCClusters.h"
39 #include "AliHLTTPCDefinitions.h"
40 #include "AliCDBEntry.h"
41 #include "AliCDBManager.h"
42 #include "AliTPCcalibDB.h"
43 #include "AliTPCCalPad.h"
44 #include "AliTPCParam.h"
45 //#include "AliHLTTPCCAInputDataCompressorComponent.h"
46 //#include "AliHLTTPCCADef.h"
47
48 #include <cstdlib>
49 #include <cerrno>
50 #include "TString.h"
51 #include "TObjString.h"
52 #include "TObjArray.h"
53 #include "AliCDBEntry.h"
54 #include "AliCDBManager.h"
55 #include "AliCDBStorage.h"
56 #include "TGeoGlobalMagField.h"
57 #include "AliGeomManager.h"
58
59 #include <sys/time.h>
60
61 /** ROOT macro for the implementation of ROOT specific class methods */
62 ClassImp(AliHLTTPCClusterFinderComponent)
63
64 const char* AliHLTTPCClusterFinderComponent::fgkOCDBEntryPacked="HLT/ConfigTPC/TPCClusterFinderPacked";
65 const char* AliHLTTPCClusterFinderComponent::fgkOCDBEntryUnpacked="HLT/ConfigTPC/TPCClusterFinderUnpacked";
66 const char* AliHLTTPCClusterFinderComponent::fgkOCDBEntryDecoder="HLT/ConfigTPC/TPCClusterFinderDecoder";
67 const char* AliHLTTPCClusterFinderComponent::fgkOCDBEntry32Bit="HLT/ConfigTPC/TPCClusterFinder32Bit";
68
69 AliHLTTPCClusterFinderComponent::AliHLTTPCClusterFinderComponent(int mode)
70   :
71   fClusterFinder(NULL),
72   fReader(NULL),
73   fDeconvTime(kFALSE),
74   fDeconvPad(kFALSE),
75   fClusterDeconv(false),
76   fXYClusterError(-1),
77   fZClusterError(-1),
78   fModeSwitch(mode),
79   fUnsorted(1),
80   fPatch(0),
81   fGetActivePads(0),
82   fFirstTimeBin(-1),
83   fLastTimeBin(-1),
84   fDoMC(kFALSE),
85   fReleaseMemory( kFALSE ),
86   fBenchmark("TPCClusterFinder")
87 {
88   // see header file for class documentation
89   // or
90   // refer to README to build package
91   // or
92   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
93   if (fModeSwitch!=kClusterFinderPacked &&
94       fModeSwitch!=kClusterFinderUnpacked &&
95       fModeSwitch!=kClusterFinderDecoder &&
96       fModeSwitch!=kClusterFinder32Bit) {
97     HLTFatal("unknown digit reader type");
98   }
99 }
100
101 AliHLTTPCClusterFinderComponent::~AliHLTTPCClusterFinderComponent()
102 {
103   // see header file for class documentation
104 }
105
106 // Public functions to implement AliHLTComponent's interface.
107 // These functions are required for the registration process
108
109 const char* AliHLTTPCClusterFinderComponent::GetComponentID()
110 {
111   // see header file for class documentation
112   switch(fModeSwitch){
113   case kClusterFinderPacked:
114     return "TPCClusterFinderPacked";
115     break;
116   case kClusterFinderUnpacked:   
117     return "TPCClusterFinderUnpacked";   
118     break;
119   case kClusterFinderDecoder:
120     return "TPCClusterFinderDecoder";
121     break;
122   case kClusterFinder32Bit:
123     return "TPCClusterFinder32Bit";
124     break;
125   }
126   return "";
127 }
128
129 void AliHLTTPCClusterFinderComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
130 {
131   // see header file for class documentation
132   list.clear(); 
133   switch(fModeSwitch){
134   case kClusterFinderPacked:
135     list.push_back( kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTPC );
136     break;
137   case kClusterFinderUnpacked:   
138     list.push_back( AliHLTTPCDefinitions::fgkUnpackedRawDataType );      
139     break;
140   case kClusterFinderDecoder:
141     list.push_back( kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTPC );
142     break;
143   case kClusterFinder32Bit:
144     list.push_back( kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTPC );
145     break;
146   }
147 }
148
149 AliHLTComponentDataType AliHLTTPCClusterFinderComponent::GetOutputDataType()
150 {
151   // see header file for class documentation
152   return kAliHLTMultipleDataType;
153 }
154
155 int AliHLTTPCClusterFinderComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList)
156
157 {
158   // see header file for class documentation
159   tgtList.clear();
160   tgtList.push_back(AliHLTTPCDefinitions::fgkClustersDataType);
161   tgtList.push_back(kAliHLTDataTypeHwAddr16);
162   //tgtList.push_back(AliHLTTPCCADefinitions::fgkCompressedInputDataType);
163   return tgtList.size();
164 }
165
166 void AliHLTTPCClusterFinderComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
167 {
168   // see header file for class documentation
169   // XXX TODO: Find more realistic values.  
170   constBase = 0;
171   switch(fModeSwitch){
172   case kClusterFinderPacked:
173     inputMultiplier = (6 * 0.4);
174     break;
175   case kClusterFinderUnpacked:
176     inputMultiplier = 0.4;
177     break;
178   case kClusterFinderDecoder:
179     inputMultiplier = (6 * 0.4);
180     break;
181   case kClusterFinder32Bit:
182     inputMultiplier = (6 * 0.4);
183     break;
184   }
185 }
186
187 AliHLTComponent* AliHLTTPCClusterFinderComponent::Spawn()
188 {
189   // see header file for class documentation
190   return new AliHLTTPCClusterFinderComponent(fModeSwitch);
191 }
192         
193 int AliHLTTPCClusterFinderComponent::DoInit( int argc, const char** argv )
194 {
195   // see header file for class documentation
196   if ( fClusterFinder )
197     return -EINPROGRESS;
198
199   //Test if the OCDB entries used by AliTPCTransform is availible
200   AliTPCcalibDB*  calib=AliTPCcalibDB::Instance();  
201   //
202   if(!calib){
203     HLTError("AliTPCcalibDB does not exist");
204     return -ENOENT;
205   }
206   calib->SetRun(GetRunNo());
207   calib->UpdateRunInformations(GetRunNo());
208   AliTPCCalPad * time0TPC = calib->GetPadTime0(); 
209   if(!time0TPC){
210     HLTError("OCDB entry TPC/Calib/PadTime0 (AliTPCcalibDB::GetPadTime0()) is not available.");
211     return -ENOENT;
212   }
213
214   AliTPCParam  * param    = calib->GetParameters();
215   if(!param){
216     HLTError("OCDB entry TPC/Calib/Parameters (AliTPCcalibDB::GetParameters()) is not available.");
217     return -ENOENT;
218   }
219
220   // Check field
221   if (!TGeoGlobalMagField::Instance()) {
222     HLTError("magnetic field not initialized, please set up TGeoGlobalMagField and AliMagF");
223     return -ENODEV;
224   }
225   calib->SetExBField(GetBz());
226
227   if(!AliGeomManager::GetGeometry()){
228     AliGeomManager::LoadGeometry();
229   }
230
231   fClusterFinder = new AliHLTTPCClusterFinder();
232
233   // first configure the default
234   int iResult = 0;
235   switch(fModeSwitch){
236   case kClusterFinderPacked:
237     iResult=ConfigureFromCDBTObjString(fgkOCDBEntryPacked);
238     break;
239   case kClusterFinderUnpacked:   
240     iResult=ConfigureFromCDBTObjString(fgkOCDBEntryUnpacked);
241     break;
242   case kClusterFinderDecoder:
243     iResult=ConfigureFromCDBTObjString(fgkOCDBEntryDecoder);
244     break;
245   case kClusterFinder32Bit:
246     iResult=ConfigureFromCDBTObjString(fgkOCDBEntry32Bit);
247     break;
248   }
249
250   // configure from the command line parameters if specified
251   if (iResult>=0 && argc>0)
252     iResult=ConfigureFromArgumentString(argc, argv);
253   // return iResult;
254
255   /*
256   Int_t iResult=0;
257   TString configuration="";
258   TString argument="";
259   for (int i=0; i<argc && iResult>=0; i++) {
260     argument=argv[i];
261     if (!configuration.IsNull()) configuration+=" ";
262     configuration+=argument;
263   }
264   
265   if (!configuration.IsNull()) {
266     iResult=Configure(configuration.Data());
267   } else {
268     iResult=Reconfigure(NULL, NULL);
269   }
270   */
271
272   //Checking for conflicting arguments
273   if(fClusterDeconv){
274     if(fDeconvPad==kTRUE || fDeconvTime==kTRUE){
275       HLTWarning("Conflicting arguments: argument 'pp-run' will be ignored.");
276     }
277   }
278   if(fClusterFinder->GetOccupancyLimit()!=1.0 && fUnsorted){
279     HLTWarning("Argument 'occupancy-limit' is deprecated when doing unsorted data reading.");
280   }
281   if(fGetActivePads==kTRUE && fUnsorted==kFALSE){
282     HLTWarning("Argument '-active-pads' only work with unsorted data reading. Active pads list will not be produced.");
283   }
284   
285
286   // Choose reader
287   if (fModeSwitch==kClusterFinderPacked) {
288       HLTDebug("using AliHLTTPCDigitReaderPacked");
289       fReader = new AliHLTTPCDigitReaderPacked();
290       if(fUnsorted==1){ fReader->SetUnsorted(kTRUE); }
291       fClusterFinder->SetReader(fReader);
292   }
293   else if(fModeSwitch==kClusterFinderUnpacked){          
294     HLTDebug("using AliHLTTPCDigitReaderUnpacked");      
295     fReader = new AliHLTTPCDigitReaderUnpacked();        
296     if(fUnsorted==1){   fReader->SetUnsorted(kTRUE); }
297     fClusterFinder->SetReader(fReader);
298   } 
299   else if(fModeSwitch==kClusterFinderDecoder){
300     HLTDebug("using AliHLTTPCDigitReaderDecoder");
301     fReader = new AliHLTTPCDigitReaderDecoder();
302     fClusterFinder->SetReader(fReader);
303   }
304   else if(fModeSwitch==kClusterFinder32Bit){
305     HLTDebug("using AliHLTTPCDigitReader32Bit");
306     fReader = new AliHLTTPCDigitReader32Bit();
307     fClusterFinder->SetReader(fReader);
308     fClusterFinder->Set32BitFormat(kTRUE);
309   }
310   else{
311     HLTFatal("No mode set for clusterfindercomponent");
312   }
313
314   if(fClusterDeconv){
315     fClusterFinder->SetOccupancyLimit(1.0);
316   }
317   
318   fClusterFinder->SetDeconv(fClusterDeconv);
319   fClusterFinder->SetDeconvPad(fDeconvPad);
320   fClusterFinder->SetDeconvTime(fDeconvPad);
321   fClusterFinder->SetXYError( fXYClusterError );
322   fClusterFinder->SetZError( fZClusterError );
323   if ( (fXYClusterError>0) && (fZClusterError>0) ){
324     fClusterFinder->SetCalcErr( false );
325   }
326
327   if(fFirstTimeBin>0){
328     fClusterFinder->SetFirstTimeBin(fFirstTimeBin);
329   }
330   if(fLastTimeBin>0 && fLastTimeBin>fFirstTimeBin && fLastTimeBin<=AliHLTTPCTransform::GetNTimeBins()){
331     fClusterFinder->SetLastTimeBin(fLastTimeBin);
332   }
333   fBenchmark.Reset();
334   fBenchmark.SetTimer(0,"total");
335   fBenchmark.SetTimer(1,"reco");
336
337   return iResult;
338 }
339
340 int AliHLTTPCClusterFinderComponent::DoDeinit()
341 {
342   // see header file for class documentation
343
344   if ( fClusterFinder )
345     delete fClusterFinder;
346   fClusterFinder = NULL;
347  
348   if ( fReader )
349     delete fReader;
350   fReader = NULL;
351     
352   return 0;
353 }
354
355 int AliHLTTPCClusterFinderComponent::DoEvent( const AliHLTComponentEventData& evtData, 
356                                               const AliHLTComponentBlockData* blocks, 
357                                               AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr, 
358                                               AliHLTUInt32_t& size, 
359                                               vector<AliHLTComponentBlockData>& outputBlocks )
360 {
361   // see header file for class documentation
362   int iResult=0;
363   //SG!!!
364   //fDeconvTime = kTRUE;
365   //fClusterFinder->SetDeconvTime(fDeconvTime);
366   // fDeconvPad = kTRUE;
367   //fClusterFinder->SetDeconvPad(fDeconvPad);
368     
369
370   if(fReader == NULL){
371     HLTFatal("Digit reader not initialized, skipping HLT TPC cluster reconstruction.");
372     size=0;
373     return -ENODEV;    
374   }
375
376   if(!IsDataEvent()){
377     size=0;
378     return 0;
379   }
380
381   fBenchmark.StartNewEvent();
382   fBenchmark.Start(0);
383
384   //  == init iter (pointer to datablock)
385   const AliHLTComponentBlockData* iter = NULL;
386   unsigned long ndx;
387
388   //  == OUTdatatype pointer
389   AliHLTTPCClusterData* outPtr;
390
391   AliHLTUInt8_t* outBPtr;
392   UInt_t offset, mysize, nSize, tSize = 0;
393
394   outBPtr = outputPtr;
395   outPtr = (AliHLTTPCClusterData*)outBPtr;
396
397   Int_t slice, patch;
398   unsigned long maxPoints, realPoints = 0;
399
400   for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
401     {
402       iter = blocks+ndx;
403       mysize = 0;
404       offset = tSize;
405
406       // Kenneth 16. July 2009
407       // 32 byte is the size of the common data header (CDH)
408       // this is introduced as a protection of empty files
409       // normally when running with file publisher where 
410       // Timms script is used to create the missing files
411       if(iter->fSize <= 32){
412         continue;
413       }
414
415
416       if (fModeSwitch==0 || fModeSwitch==2 || fModeSwitch==3) {
417         HLTDebug("Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
418                  evtData.fEventID, evtData.fEventID, 
419                  DataType2Text( iter->fDataType).c_str(), 
420                  DataType2Text(kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTPC).c_str());
421
422         if (iter->fDataType == AliHLTTPCDefinitions::fgkDDLPackedRawDataType &&
423             GetEventCount()<2) {
424           HLTWarning("data type %s is depricated, use %s (kAliHLTDataTypeDDLRaw)!",
425                      DataType2Text(AliHLTTPCDefinitions::fgkDDLPackedRawDataType).c_str(),
426                      DataType2Text(kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTPC).c_str());
427           }
428
429         if ( iter->fDataType != (kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTPC) &&
430              iter->fDataType != AliHLTTPCDefinitions::fgkDDLPackedRawDataType ) continue;
431
432       }
433       else if(fModeSwitch==1){
434         HLTDebug("Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
435                  evtData.fEventID, evtData.fEventID, 
436                  DataType2Text( iter->fDataType).c_str(), 
437                  DataType2Text(AliHLTTPCDefinitions::fgkUnpackedRawDataType).c_str());
438
439         if ( iter->fDataType != AliHLTTPCDefinitions::fgkUnpackedRawDataType ) continue;
440
441       }
442
443       fBenchmark.AddInput(iter->fSize);
444
445       slice = AliHLTTPCDefinitions::GetMinSliceNr( *iter );
446       patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
447
448       if(fUnsorted){
449         fClusterFinder->SetUnsorted(fUnsorted);
450         fClusterFinder->SetPatch(patch);
451       }
452
453       outPtr = (AliHLTTPCClusterData*)outBPtr;
454
455       maxPoints = (size-tSize-sizeof(AliHLTTPCClusterData))/sizeof(AliHLTTPCSpacePointData);
456
457       fClusterFinder->InitSlice( slice, patch, maxPoints );
458       fClusterFinder->SetOutputArray( (AliHLTTPCSpacePointData*)outPtr->fSpacePoints );
459         
460       fBenchmark.Start(1);
461
462       if(fUnsorted){
463         if(fGetActivePads){
464           fClusterFinder->SetDoPadSelection(kTRUE);
465         }       
466         if(fDeconvTime){
467           fClusterFinder->ReadDataUnsortedDeconvoluteTime(iter->fPtr, iter->fSize);
468         }
469         else{
470           fClusterFinder->ReadDataUnsorted(iter->fPtr, iter->fSize);
471         }
472
473         fClusterFinder->FindClusters();
474       }
475       else{
476         fClusterFinder->Read(iter->fPtr, iter->fSize );
477         fClusterFinder->ProcessDigits();
478       }
479       fBenchmark.Stop(1);
480
481       fReader->Reset();
482
483       realPoints = fClusterFinder->GetNumberOfClusters();
484         
485       outPtr->fSpacePointCnt = realPoints;
486       nSize = sizeof(AliHLTTPCSpacePointData)*realPoints;
487       mysize += nSize+sizeof(AliHLTTPCClusterData);
488
489       Logging( kHLTLogDebug, "HLT::TPCClusterFinder::DoEvent", "Spacepoints", 
490                "Number of spacepoints: %lu Slice/Patch/RowMin/RowMax: %d/%d/%d/%d.",
491                realPoints, slice, patch,AliHLTTPCTransform::GetFirstRow( patch ) , AliHLTTPCTransform::GetLastRow( patch ) );
492       AliHLTComponentBlockData bd;
493       FillBlockData( bd );
494       bd.fOffset = offset;
495       bd.fSize = mysize;
496       bd.fSpecification = iter->fSpecification;
497       bd.fDataType = AliHLTTPCDefinitions::fgkClustersDataType;
498       outputBlocks.push_back( bd );
499
500       fBenchmark.AddOutput(bd.fSize);
501
502       tSize += mysize;
503       outBPtr += mysize;
504       outPtr = (AliHLTTPCClusterData*)outBPtr;
505         
506
507       if ( tSize > size )
508         {
509           Logging( kHLTLogFatal, "HLT::TPCClusterFinder::DoEvent", "Too much data", 
510                    "Data written over allowed buffer. Amount written: %lu, allowed amount: %lu.",
511                    tSize, size );
512           iResult=-ENOSPC;
513           break;
514         }
515         
516       if(fUnsorted && fGetActivePads){
517        Int_t maxNumberOfHW=(Int_t)((size-tSize)/sizeof(AliHLTUInt16_t)-1);
518        AliHLTUInt16_t* outputHWPtr= (AliHLTUInt16_t*)(outputPtr+tSize);
519        Int_t nHWAdd = fClusterFinder->FillHWAddressList(outputHWPtr, maxNumberOfHW);
520       
521        AliHLTComponentBlockData bdHW;
522        FillBlockData( bdHW );
523        bdHW.fOffset = tSize ;
524        bdHW.fSize = nHWAdd*sizeof(AliHLTUInt16_t);
525        bdHW.fSpecification = iter->fSpecification;
526        bdHW.fDataType = kAliHLTDataTypeHwAddr16;
527        outputBlocks.push_back( bdHW );
528        
529        fBenchmark.AddOutput(bdHW.fSize);
530        tSize+=nHWAdd*sizeof(AliHLTUInt16_t);
531       }
532
533       /*
534       { // compressed output for the CA tracker 
535
536         AliHLTUInt32_t dSize = 0;       
537
538         int ret = AliHLTTPCCAInputDataCompressorComponent::Compress(  (AliHLTTPCClusterData*)( outputPtr + bd.fOffset ),
539                                                                       size - tSize,
540                                                                       outputPtr+tSize,
541                                                                       dSize );
542         
543         if ( ret!=0 || tSize + dSize > size )
544           {
545             Logging( kHLTLogFatal, "HLT::TPCClusterFinder::DoEvent", "Too much data", 
546                      "Data written over allowed buffer. Amount written: %lu, allowed amount: %lu.",
547                      tSize + dSize, size );
548             iResult=-ENOSPC;
549             break;
550           }
551         
552         AliHLTComponentBlockData bdCompressed;
553         FillBlockData( bdCompressed );
554         bdCompressed.fOffset = tSize ;
555         bdCompressed.fSize = dSize;
556         bdCompressed.fSpecification = iter->fSpecification;
557         bdCompressed.fDataType = AliHLTTPCCADefinitions::fgkCompressedInputDataType;
558         outputBlocks.push_back( bdCompressed );
559         
560         tSize += dSize;
561         outBPtr += dSize;
562         outPtr = (AliHLTTPCClusterData*)outBPtr;        
563       }
564       */
565
566       if(fDoMC){
567         Int_t maxNumberOfClusterMCInfo = (Int_t)((size-tSize)/sizeof(AliHLTTPCClusterFinder::ClusterMCInfo)-1);
568         AliHLTTPCClusterFinder::ClusterMCInfo* outputMCInfo= (AliHLTTPCClusterFinder::ClusterMCInfo*)(outputPtr+tSize);
569         Int_t nMCInfo = fClusterFinder->FillOutputMCInfo(outputMCInfo, maxNumberOfClusterMCInfo);
570         
571         AliHLTComponentBlockData bdMCInfo;
572         FillBlockData( bdMCInfo );
573         bdMCInfo.fOffset = tSize ;
574         bdMCInfo.fSize = nMCInfo*sizeof(AliHLTTPCClusterFinder::ClusterMCInfo);
575         bdMCInfo.fSpecification = iter->fSpecification;
576         bdMCInfo.fDataType = AliHLTTPCDefinitions::fgkAliHLTDataTypeClusterMCInfo;
577         outputBlocks.push_back( bdMCInfo );
578         fBenchmark.AddOutput(bdMCInfo.fSize);
579
580         tSize+=nMCInfo*sizeof(AliHLTTPCClusterFinder::ClusterMCInfo);
581
582       }
583     }
584
585   if (iResult>=0)
586     size = tSize;
587
588   fBenchmark.Stop(0);  
589   HLTInfo(fBenchmark.GetStatistics());
590   return iResult;
591 }
592
593 int AliHLTTPCClusterFinderComponent::ScanConfigurationArgument(int argc, const char** argv){
594
595   // see header file for class documentation
596
597   if (argc<=0) return 0;
598   int i=0;
599   TString argument=argv[i];
600
601   if (argument.CompareTo("-solenoidBz")==0){
602     if (++i>=argc) return -EPROTO;
603     HLTWarning("argument -solenoidBz is deprecated, magnetic field set up globally (%f)", GetBz());
604     return 2;
605   }
606
607   if (argument.CompareTo("-update-calibdb")==0 || argument.CompareTo("-update-transform")==0 ){
608     if(fClusterFinder->UpdateCalibDB()){
609       HLTDebug("CalibDB and offline transform successfully updated.");
610     }
611     else{
612       HLTError("CalibDB could not be updated.");
613     }
614     return 1;
615   }
616
617   if (argument.CompareTo("-deconvolute-time")==0){
618     HLTDebug("Switching on deconvolution in time direction.");
619     fDeconvTime = kTRUE;
620     fClusterFinder->SetDeconvTime(fDeconvTime);
621     return 1;
622   }
623
624   if (argument.CompareTo("-deconvolute-pad")==0){
625     HLTDebug("Switching on deconvolution in pad direction.");
626     fDeconvPad = kTRUE;
627     fClusterFinder->SetDeconvPad(fDeconvPad);
628     return 1;
629   }
630
631   if (argument.CompareTo("-timebins")==0 || argument.CompareTo("timebins" )==0){
632     HLTWarning("Argument %s is depreciated after moving to the offline AliTPCTransform class for xyz calculations.",argument.Data());
633     /*
634       if (++i>=argc) return -EPROTO;
635       argument=argv[i];
636       AliHLTTPCTransform::SetNTimeBins(argument.Atoi());
637       fClusterFinder->UpdateLastTimeBin();
638       HLTInfo("number of timebins set to %d, zbin=%f", AliHLTTPCTransform::GetNTimeBins(), AliHLTTPCTransform::GetZWidth());
639       return 2;
640     */
641     if(argument.CompareTo("timebins")==0){
642       HLTWarning("Argument 'timebins' is old, please switch to new argument naming convention (-timebins). The timebins argument will still work, but please change anyway.");
643     }
644     return 2;
645   }
646   
647   if (argument.CompareTo("-first-timebin")==0){
648     if (++i>=argc) return -EPROTO;
649     argument=argv[i];
650     fFirstTimeBin = argument.Atoi();
651     if(fFirstTimeBin>=0){
652       HLTDebug("fFirstTimeBin set to %d",fFirstTimeBin);
653       fClusterFinder->SetFirstTimeBin(fFirstTimeBin);
654     }
655     else{
656       HLTError("-first-timebin specifier is negative: %d",fFirstTimeBin);
657     }
658     return 2;
659   }
660
661   if (argument.CompareTo("-last-timebin")==0){
662     if (++i>=argc) return -EPROTO;
663     argument=argv[i];
664     fLastTimeBin = argument.Atoi();
665     if(fLastTimeBin<AliHLTTPCTransform::GetNTimeBins()){
666       HLTDebug("fLastTimeBin set to %d",fLastTimeBin);
667     }
668     else{
669       HLTError("fLastTimeBins is too big: %d. Maximum: %d",fLastTimeBin,AliHLTTPCTransform::GetNTimeBins());
670     }
671     return 2;
672   }
673  
674   if (argument.CompareTo("-sorted")==0) {
675     fUnsorted=0;
676     HLTDebug("Swithching unsorted off.");
677     fClusterFinder->SetUnsorted(0);
678     return 1;
679   } 
680   
681   if (argument.CompareTo("-do-mc")==0) {
682     fDoMC=kTRUE;
683     fClusterFinder->SetDoMC(fDoMC);
684     HLTDebug("Setting fDoMC to true.");
685     return 1;
686   }
687   if (argument.CompareTo("-release-memory")==0) {
688     fReleaseMemory=kTRUE;
689     fClusterFinder->SetReleaseMemory( fReleaseMemory );
690     HLTDebug("Setting fReleaseMemory to true.");
691     return 1;
692   }
693
694   if (argument.CompareTo("-active-pads")==0 || argument.CompareTo("activepads")==0){
695     if(argument.CompareTo("activepads" )==0){
696       HLTWarning("Please change to new component argument naming scheme and use '-active-pads' instead of 'activepads'");
697     }
698     HLTDebug("Switching on ActivePads");
699     fGetActivePads = 1;
700     fClusterFinder->SetDoPadSelection(kTRUE);
701     return 1;
702   }
703
704   if (argument.CompareTo("-occupancy-limit")==0 || argument.CompareTo("occupancy-limit")==0){
705     if(argument.CompareTo("occupancy-limit" )==0){
706       HLTWarning("Please switch to new component argument naming convention, use '-occupancy-limit' instead of 'occupancy-limit'");
707     }
708     if (++i>=argc) return -EPROTO;
709     argument=argv[i];
710     fClusterFinder->SetOccupancyLimit(argument.Atof());
711     HLTDebug("Occupancy limit set to occulimit %f", argument.Atof());
712     return 2;
713   }
714
715   if (argument.CompareTo("rawreadermode")==0){
716     if (++i>=argc) return -EPROTO;
717     HLTWarning("Argument 'rawreadermode' is deprecated");
718     return 2;
719   }
720   
721   if (argument.CompareTo("pp-run")==0){
722     HLTWarning("Argument 'pp-run' is obsolete, deconvolution is swiched off in both time and pad directions by default.");
723     fClusterDeconv = false;
724     return 1;
725   }
726
727   if (argument.CompareTo("adc-threshold" )==0){
728     if (++i>=argc) return -EPROTO;
729     HLTWarning("'adc-threshold' is no longer a valid argument, please use TPCZeroSuppression component if you want to zerosuppress data.");
730     return 2;
731   } 
732   
733   if (argument.CompareTo("oldrcuformat" )==0){
734     if (++i>=argc) return -EPROTO;
735     HLTWarning("Argument 'oldrcuformat' is deprecated.");
736     return 2;
737   }
738   
739   if (argument.CompareTo("unsorted" )==0 || argument.CompareTo("-unsorted" )==0){
740     HLTWarning("Argument is obsolete, unsorted reading is default.");
741     //    fClusterFinder->SetUnsorted(1);
742     return 1;
743   }
744   if (argument.CompareTo("nsigma-threshold")==0){
745     if (++i>=argc) return -EPROTO;
746     HLTWarning("Argument 'nsigma-threshold' argument is obsolete.");
747     return 2;
748   }
749
750   // unknown argument
751   return -EINVAL;
752 }
753
754 int AliHLTTPCClusterFinderComponent::Reconfigure(const char* cdbEntry, const char* /*chainId*/)
755 {  
756   // see header file for class documentation
757
758   const char* entry=cdbEntry;
759   if (!entry || entry[0]==0){
760     switch(fModeSwitch){
761     case kClusterFinderPacked:
762       entry=fgkOCDBEntryPacked;
763       break;
764     case kClusterFinderUnpacked:         
765       entry=fgkOCDBEntryUnpacked;
766       break;
767     case kClusterFinderDecoder:
768       entry=fgkOCDBEntryDecoder;
769       break;
770     case kClusterFinder32Bit:
771       entry=fgkOCDBEntry32Bit;
772       break;
773     }
774   }
775
776   return ConfigureFromCDBTObjString(entry);
777
778   /*
779   int iResult=0;
780   
781   const char* path="HLT/ConfigTPC/ClusterFinderComponent";
782   if (cdbEntry) path=cdbEntry;
783   if (path) {
784     HLTInfo("reconfigure from entry %s, chain id %s", path, (chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
785     AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path);//,GetRunNo());
786     if (pEntry) {
787       TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
788       if (pString) {
789         HLTInfo("received configuration object: %s", pString->GetString().Data());
790         iResult = Configure(pString->GetString().Data());
791       } else {
792         HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
793       }
794     } else {
795       HLTError("can not fetch object \"%s\" from CDB", path);
796     }
797   }
798   return iResult;
799   */
800 }
801
802 int AliHLTTPCClusterFinderComponent::Configure(const char* arguments){
803   // see header file for class documentation
804   int iResult=0;
805   if (!arguments) return iResult;
806   
807   TString allArgs=arguments;
808   TString argument;
809   int bMissingParam=0;
810
811   TObjArray* pTokens=allArgs.Tokenize(" ");
812   if (pTokens) {
813     
814     for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
815       argument=((TObjString*)pTokens->At(i))->GetString();
816
817       if (argument.IsNull()) continue;
818       
819       // -- deconvolute-time option
820       if (argument.CompareTo("-deconvolute-time")==0){
821         HLTDebug("Switching on deconvolution in time direction.");
822         fDeconvTime = kTRUE;
823         fClusterFinder->SetDeconvTime(fDeconvTime);
824       }
825       else if (argument.CompareTo("-deconvolute-pad")==0){
826         HLTDebug("Switching on deconvolution in pad direction.");
827         fDeconvPad = kTRUE;
828         fClusterFinder->SetDeconvPad(fDeconvPad);
829       }
830       else if (argument.CompareTo("-timebins")==0 || argument.CompareTo("timebins" )==0){
831         HLTWarning("Argument %s is depreciated after moving to the offline AliTPCTransform class for xyz calculations.",argument.Data());
832         /*
833         if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
834         AliHLTTPCTransform::SetNTimeBins(((TObjString*)pTokens->At(i))->GetString().Atoi());
835         fClusterFinder->UpdateLastTimeBin();
836         HLTInfo("number of timebins set to %d, zbin=%f", AliHLTTPCTransform::GetNTimeBins(), AliHLTTPCTransform::GetZWidth());
837         */
838         if(argument.CompareTo("timebins")==0){
839           HLTWarning("Argument 'timebins' is old, please switch to new argument naming convention (-timebins). The timebins argument will still work, but please change anyway.");
840         }
841         
842       }
843       else if (argument.CompareTo("-first-timebin")==0){
844         if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
845         fFirstTimeBin = ((TObjString*)pTokens->At(i))->GetString().Atoi();
846         if(fFirstTimeBin>=0){
847           HLTDebug("fFirstTimeBin set to %d",fFirstTimeBin);
848           fClusterFinder->SetFirstTimeBin(fFirstTimeBin);
849         }
850         else{
851           HLTError("-first-timebin specifier is negative: %d",fFirstTimeBin);
852         }
853       }
854       else if (argument.CompareTo("-last-timebin")==0){
855         if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
856         fLastTimeBin = ((TObjString*)pTokens->At(i))->GetString().Atoi();
857         if(fLastTimeBin<AliHLTTPCTransform::GetNTimeBins()){
858           HLTDebug("fLastTimeBin set to %d",fLastTimeBin);
859         }
860         else{
861           HLTError("fLastTimeBins is too big: %d. Maximum: %d",fLastTimeBin,AliHLTTPCTransform::GetNTimeBins());
862         }
863       }
864       else if (argument.CompareTo("-sorted")==0) {
865         fUnsorted=0;
866         HLTDebug("Swithching unsorted off.");
867         fClusterFinder->SetUnsorted(0);
868       }
869       else if (argument.CompareTo("-do-mc")==0) {
870         fDoMC=kTRUE;
871         fClusterFinder->SetDoMC(fDoMC);
872         HLTInfo("Setting fDoMC to true.");
873       }
874       else if (argument.CompareTo("-release-memory")==0) {
875         fReleaseMemory = kTRUE;
876         fClusterFinder->SetReleaseMemory( kTRUE );
877         HLTInfo("Setting fReleaseMemory to true.");
878       }
879       else if (argument.CompareTo("-active-pads")==0 || argument.CompareTo("activepads")==0){
880         if(argument.CompareTo("activepads" )==0){
881           HLTWarning("Please change to new component argument naming scheme and use '-active-pads' instead of 'activepads'");
882         }
883         HLTDebug("Switching on ActivePads");
884         fGetActivePads = 1;
885         fClusterFinder->SetDoPadSelection(kTRUE);
886       }
887       else if (argument.CompareTo("-occupancy-limit")==0 || argument.CompareTo("occupancy-limit")==0){
888         if(argument.CompareTo("occupancy-limit" )==0){
889           HLTWarning("Please switch to new component argument naming convention, use '-occupancy-limit' instead of 'occupancy-limit'");
890         }
891         if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
892         fClusterFinder->SetOccupancyLimit(((TObjString*)pTokens->At(i))->GetString().Atof());
893         HLTDebug("Occupancy limit set to occulimit %f", ((TObjString*)pTokens->At(i))->GetString().Atof());
894       }
895       else if (argument.CompareTo("rawreadermode")==0){
896         if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
897         HLTWarning("Argument 'rawreadermode' is deprecated");      
898       }
899       else if (argument.CompareTo("pp-run")==0){
900         HLTWarning("Argument 'pp-run' is obsolete, deconvolution is swiched off in both time and pad directions by default.");
901         fClusterDeconv = false;
902       }
903       else if (argument.CompareTo("adc-threshold" )==0){
904         if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
905         HLTWarning("'adc-threshold' is no longer a valid argument, please use TPCZeroSuppression component if you want to zerosuppress data.");
906       }
907       else if (argument.CompareTo("oldrcuformat" )==0){
908         if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
909         HLTWarning("Argument 'oldrcuformat' is deprecated.");
910       }
911       else if (argument.CompareTo("unsorted" )==0){
912         if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
913         HLTDebug("Using unsorted reading.");
914         fClusterFinder->SetUnsorted(1);
915       }
916       else if (argument.CompareTo("nsigma-threshold")==0){
917         if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
918         HLTWarning("Argument 'nsigma-threshold' argument is obsolete.");
919       }
920       else if (argument.CompareTo("-update-calibdb")==0){
921         fClusterFinder->UpdateCalibDB();
922       }
923       else {
924         HLTError("unknown argument %s", argument.Data());
925         iResult=-EINVAL;
926         break;
927       }
928     }
929     delete pTokens;
930   }
931   if (bMissingParam) {
932     HLTError("missing parameter for argument %s", argument.Data());
933     iResult=-EINVAL;
934   }
935   return iResult;
936 }
937
938 void AliHLTTPCClusterFinderComponent::GetOCDBObjectDescription( TMap* const targetMap){
939 // Get a list of OCDB object description needed for the particular component
940   
941   if (!targetMap) return;
942   
943   // OCDB entries for component arguments
944   targetMap->Add(new TObjString("HLT/ConfigTPC/TPCClusterFinder32Bit"),    new TObjString("component arguments, empty at the moment"));
945   targetMap->Add(new TObjString("HLT/ConfigTPC/TPCClusterFinderPacked"),   new TObjString("component arguments, empty at the moment"));
946   targetMap->Add(new TObjString("HLT/ConfigTPC/TPCClusterFinderUnpacked"), new TObjString("component arguments, empty at the moment"));
947   targetMap->Add(new TObjString("HLT/ConfigTPC/TPCClusterFinderDecoder"),  new TObjString("component arguments, empty at the moment"));
948   
949   // OCDB entries to be fetched by the TAXI (access via the AliTPCcalibDB class)
950   targetMap->Add(new TObjString("TPC/Calib/Parameters"),    new TObjString("unknown content"));
951   targetMap->Add(new TObjString("TPC/Calib/TimeDrift"),     new TObjString("drift velocity calibration"));
952   targetMap->Add(new TObjString("TPC/Calib/Temperature"),   new TObjString("temperature map"));
953   targetMap->Add(new TObjString("TPC/Calib/PadGainFactor"), new TObjString("gain factor pad by pad"));
954   targetMap->Add(new TObjString("TPC/Calib/ClusterParam"),  new TObjString("cluster parameters"));
955   
956   // OCDB entries needed to be fetched by the Pendolino
957   targetMap->Add(new TObjString("TPC/Calib/AltroConfig"), new TObjString("contains the altro config, e.g. info about the L0 trigger timing"));
958   targetMap->Add(new TObjString("GRP/CTP/CTPtiming"),     new TObjString("content used in the cluster coordinate transformation in relation to the L0 trigger timing"));
959
960   // OCDB entries necessary for replaying data on the HLT cluster
961   targetMap->Add(new TObjString("GRP/GRP/Data"), new TObjString("contains magnetic field info"));  
962  
963   // OCDB entries needed to suppress fatals/errors/warnings during reconstruction
964   targetMap->Add(new TObjString("TPC/Calib/PadTime0"),    new TObjString("time0 offset pad by pad"));
965   targetMap->Add(new TObjString("TPC/Calib/PadNoise"),    new TObjString("pad noise values"));
966   targetMap->Add(new TObjString("TPC/Calib/Pedestals"),   new TObjString("pedestal info"));
967   targetMap->Add(new TObjString("TPC/Calib/Pulser"),      new TObjString("pulser info"));
968   targetMap->Add(new TObjString("TPC/Calib/CE"),          new TObjString("CE laser calibration result"));
969   targetMap->Add(new TObjString("TPC/Calib/Raw"),         new TObjString("unknown content"));
970   targetMap->Add(new TObjString("TPC/Calib/QA"),          new TObjString("not important"));
971   targetMap->Add(new TObjString("TPC/Calib/Mapping"),     new TObjString("unknown content"));
972   targetMap->Add(new TObjString("TPC/Calib/Goofie"),      new TObjString("Goofie values, not used at the moment (05.03.2010)"));
973   targetMap->Add(new TObjString("TPC/Calib/HighVoltage"), new TObjString("high voltage values, not used"));
974   targetMap->Add(new TObjString("TPC/Calib/Ref"),         new TObjString("unknown content"));
975 }