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