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