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