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