3 /**************************************************************************
4 * This file is property of and copyright by the ALICE HLT Project *
5 * ALICE Experiment at CERN, All rights reserved. *
7 * Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
8 * Timm Steinbeck <timm@kip.uni-heidelberg.de> *
9 * Jochen Thaeder <thaeder@kip.uni-heidelberg.de> *
10 * for The ALICE HLT Project. *
12 * Permission to use, copy, modify and distribute this software and its *
13 * documentation strictly for non-commercial purposes is hereby granted *
14 * without fee, provided that the above copyright notice appears in all *
15 * copies and that both the copyright notice and this permission notice *
16 * appear in the supporting documentation. The authors make no claims *
17 * about the suitability of this software for any purpose. It is *
18 * provided "as is" without express or implied warranty. *
19 **************************************************************************/
21 /** @file AliHLTTPCClusterFinderComponent.cxx
22 @author Timm Steinbeck, Matthias Richter, Jochen Thaeder, Kenneth Aamodt
24 @brief The TPC cluster finder processing component
27 // see header file for class documentation //
29 // refer to README to build package //
31 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt //
36 #include "AliHLTTPCClusterFinderComponent.h"
37 #include "AliHLTTPCDigitReaderPacked.h"
38 #include "AliHLTTPCDigitReaderUnpacked.h"
39 #include "AliHLTTPCDigitReaderRaw.h"
40 #include "AliHLTTPCDigitReaderDecoder.h"
41 #include "AliHLTTPCClusterFinder.h"
42 #include "AliHLTTPCSpacePointData.h"
43 #include "AliHLTTPCClusterDataFormat.h"
44 #include "AliHLTTPCTransform.h"
45 #include "AliHLTTPCClusters.h"
46 #include "AliHLTTPCDefinitions.h"
47 #include "AliCDBEntry.h"
48 #include "AliCDBManager.h"
53 #include "TObjString.h"
56 // this is a global object used for automatic component registration, do not use this
57 // use fPackedSwitch = true for packed inputtype "gkDDLPackedRawDataType"
58 // use fPackedSwitch = false for unpacked inputtype "gkUnpackedRawDataType"
59 AliHLTTPCClusterFinderComponent gAliHLTTPCClusterFinderComponentPacked(AliHLTTPCClusterFinderComponent::kClusterFinderPacked);
60 AliHLTTPCClusterFinderComponent gAliHLTTPCClusterFinderComponentUnpacked(AliHLTTPCClusterFinderComponent::kClusterFinderUnpacked);
61 AliHLTTPCClusterFinderComponent gAliHLTTPCClusterFinderComponentDecoder(AliHLTTPCClusterFinderComponent::kClusterFinderDecoder);
63 /** ROOT macro for the implementation of ROOT specific class methods */
64 ClassImp(AliHLTTPCClusterFinderComponent)
66 AliHLTTPCClusterFinderComponent::AliHLTTPCClusterFinderComponent(int mode)
79 // see header file for class documentation
81 // refer to README to build package
83 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
86 AliHLTTPCClusterFinderComponent::~AliHLTTPCClusterFinderComponent()
88 // see header file for class documentation
91 // Public functions to implement AliHLTComponent's interface.
92 // These functions are required for the registration process
94 const char* AliHLTTPCClusterFinderComponent::GetComponentID()
96 // see header file for class documentation
98 case kClusterFinderPacked:
99 return "TPCClusterFinderPacked";
101 case kClusterFinderUnpacked:
102 return "TPCClusterFinderUnpacked";
104 case kClusterFinderDecoder:
105 return "TPCClusterFinderDecoder";
110 void AliHLTTPCClusterFinderComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
112 // see header file for class documentation
115 case kClusterFinderPacked:
116 list.push_back( kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTPC );
118 case kClusterFinderUnpacked:
119 list.push_back( AliHLTTPCDefinitions::fgkUnpackedRawDataType );
121 case kClusterFinderDecoder:
122 list.push_back( kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTPC );
127 AliHLTComponentDataType AliHLTTPCClusterFinderComponent::GetOutputDataType()
129 // see header file for class documentation
130 return kAliHLTMultipleDataType;
133 int AliHLTTPCClusterFinderComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList)
136 // see header file for class documentation
138 tgtList.push_back(AliHLTTPCDefinitions::fgkClustersDataType);
139 tgtList.push_back(AliHLTTPCDefinitions::fgkActivePadsDataType);
140 return tgtList.size();
143 void AliHLTTPCClusterFinderComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
145 // see header file for class documentation
146 // XXX TODO: Find more realistic values.
150 inputMultiplier = (6 * 0.4);
153 inputMultiplier = 0.4;
156 inputMultiplier = (6 * 0.4);
161 AliHLTComponent* AliHLTTPCClusterFinderComponent::Spawn()
163 // see header file for class documentation
164 return new AliHLTTPCClusterFinderComponent(fModeSwitch);
167 int AliHLTTPCClusterFinderComponent::DoInit( int argc, const char** argv )
169 // see header file for class documentation
170 if ( fClusterFinder )
173 fClusterFinder = new AliHLTTPCClusterFinder();
175 Int_t rawreadermode = -1;
176 Int_t sigthresh = -1;
177 Double_t sigmathresh= -1;
178 Float_t occulimit = 1.0;
179 Int_t oldRCUFormat=0;
180 // Data Format version numbers:
181 // 0: RCU Data format as delivered during TPC commissioning, pads/padrows are sorted, RCU trailer is one 32 bit word.
182 // 1: As 0, but pads/padrows are delivered "as is", without sorting
183 // 2: As 0, but RCU trailer is 3 32 bit words.
184 // 3: As 1, but RCU trailer is 3 32 bit words.
185 // -1: use offline raw reader
192 // -- raw reader mode option
193 if ( !strcmp( argv[i], "rawreadermode" ) ) {
195 Logging( kHLTLogError, "HLT::TPCClusterFinder::DoInit", "Missing rawreadermode", "Raw Reader Mode not specified" );
199 // Decodes the rawreader mode: either number or string and returns the rawreadermode
200 // -1 on failure, -2 for offline
201 rawreadermode = AliHLTTPCDigitReaderRaw::DecodeMode( argv[i+1] );
203 if (rawreadermode == -1 ) {
204 Logging( kHLTLogError, "HLT::TPCClusterFinder::DoInit", "Missing rawreadermode", "Cannot convert rawreadermode specifier '%s'.", argv[i+1] );
213 if ( !strcmp( argv[i], "pp-run" ) ) {
214 fClusterDeconv = false;
219 // -- zero suppression threshold
220 if ( !strcmp( argv[i], "adc-threshold" ) ) {
221 sigthresh = strtoul( argv[i+1], &cpErr ,0);
223 HLTError("Cannot convert threshold specifier '%s'.", argv[i+1]);
230 // -- pad occupancy limit
231 if ( !strcmp( argv[i], "occupancy-limit" ) ) {
232 occulimit = strtod( argv[i+1], &cpErr);
234 HLTError("Cannot convert occupancy specifier '%s'.", argv[i+1]);
241 // -- number of timebins (default 1024)
242 if ( !strcmp( argv[i], "timebins" ) ) {
243 TString parameter(argv[i+1]);
244 parameter.Remove(TString::kLeading, ' '); // remove all blanks
245 if (parameter.IsDigit()) {
246 AliHLTTPCTransform::SetNTimeBins(parameter.Atoi());
247 HLTInfo("number of timebins set to %d, zbin=%f", AliHLTTPCTransform::GetNTimeBins(), AliHLTTPCTransform::GetZWidth());
249 HLTError("Cannot timebin specifier '%s'.", argv[i+1]);
256 // -- checking for rcu format
257 if ( !strcmp( argv[i], "oldrcuformat" ) ) {
258 oldRCUFormat = strtoul( argv[i+1], &cpErr ,0);
260 HLTError("Cannot convert oldrcuformat specifier '%s'. Should be 0(off) or 1(on), must be integer", argv[i+1]);
267 // -- checking for unsorted clusterfinding
268 if ( !strcmp( argv[i], "unsorted" ) ) {
269 fUnsorted = strtoul( argv[i+1], &cpErr ,0);
271 HLTError("Cannot convert unsorted specifier '%s'. Should be 0(off) or 1(on), must be integer", argv[i+1]);
278 // -- checking for active pads, used in 2007 December run
279 if ( !strcmp( argv[i], "activepads" ) ) {
280 fGetActivePads = strtoul( argv[i+1], &cpErr ,0);
282 HLTError("Cannot convert activepads specifier '%s'. Should be 0(off) or 1(on), must be integer", argv[i+1]);
289 // -- checking for nsigma-threshold, used in 2007 December run in ZeroSuppression
290 if ( !strcmp( argv[i], "nsigma-threshold" ) ) {
291 sigmathresh = strtoul( argv[i+1], &cpErr ,0);
293 HLTError("Cannot convert nsigma-threshold specifier '%s'. Must be integer", argv[i+1]);
300 Logging(kHLTLogError, "HLT::TPCClusterFinder::DoInit", "Unknown Option", "Unknown option '%s'", argv[i] );
306 if (fModeSwitch==kClusterFinderPacked) {
307 if (rawreadermode == -2) {
308 HLTDebug("using AliHLTTPCDigitReaderPacked");
309 fReader = new AliHLTTPCDigitReaderPacked();
311 fReader->SetOldRCUFormat(kTRUE);
313 else if(oldRCUFormat!=0){
314 HLTWarning("Wrong oldrcuformat specifier %d; oldrcuformat set to default(kFALSE)",oldRCUFormat);
317 fReader->SetUnsorted(kTRUE);
319 fClusterFinder->SetReader(fReader);
322 #if defined(HAVE_TPC_MAPPING)
323 HLTDebug("using AliHLTTPCDigitReaderRaw mode %d", rawreadermode);
324 fReader = new AliHLTTPCDigitReaderRaw(rawreadermode);
325 fClusterFinder->SetReader(fReader);
326 #else //! defined(HAVE_TPC_MAPPING)
327 HLTFatal("DigitReaderRaw not available - check your build");
329 #endif //defined(HAVE_TPC_MAPPING)
332 else if(fModeSwitch==kClusterFinderUnpacked){
333 HLTDebug("using AliHLTTPCDigitReaderUnpacked");
334 fReader = new AliHLTTPCDigitReaderUnpacked();
335 fClusterFinder->SetReader(fReader);
337 else if(fModeSwitch==kClusterFinderDecoder){
338 fReader = new AliHLTTPCDigitReaderDecoder();
339 fClusterFinder->SetReader(fReader);
342 HLTFatal("No mode set for clusterfindercomponent");
344 // if pp-run use occupancy limit else set to 1. ==> use all
345 if ( !fClusterDeconv )
346 fClusterFinder->SetOccupancyLimit(occulimit);
348 fClusterFinder->SetOccupancyLimit(1.0);
350 // Variables to setup the Clusterfinder
351 // TODO: this sounds strange and has to be verified; is the cluster finder not working when
352 // fClusterDeconv = false ?
353 fClusterDeconv = true;
354 fXYClusterError = -1;
358 fClusterFinder->SetDeconv( fClusterDeconv );
359 fClusterFinder->SetXYError( fXYClusterError );
360 fClusterFinder->SetZError( fZClusterError );
361 if ( (fXYClusterError>0) && (fZClusterError>0) )
362 fClusterFinder->SetCalcErr( false );
363 fClusterFinder->SetSignalThreshold(sigthresh);
364 fClusterFinder->SetNSigmaThreshold(sigmathresh);
369 int AliHLTTPCClusterFinderComponent::DoDeinit()
371 // see header file for class documentation
373 if ( fClusterFinder )
374 delete fClusterFinder;
375 fClusterFinder = NULL;
384 int AliHLTTPCClusterFinderComponent::DoEvent( const AliHLTComponentEventData& evtData,
385 const AliHLTComponentBlockData* blocks,
386 AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr,
387 AliHLTUInt32_t& size,
388 vector<AliHLTComponentBlockData>& outputBlocks )
390 // see header file for class documentation
392 // == init iter (pointer to datablock)
393 const AliHLTComponentBlockData* iter = NULL;
396 // == OUTdatatype pointer
397 AliHLTTPCClusterData* outPtr;
399 AliHLTUInt8_t* outBPtr;
400 UInt_t offset, mysize, nSize, tSize = 0;
403 outPtr = (AliHLTTPCClusterData*)outBPtr;
405 Int_t slice, patch, row[2];
406 unsigned long maxPoints, realPoints = 0;
408 for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
415 if (fModeSwitch==0 || fModeSwitch==2) {
416 HLTDebug("Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
417 evtData.fEventID, evtData.fEventID,
418 DataType2Text( iter->fDataType).c_str(),
419 DataType2Text(kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTPC).c_str());
421 if (iter->fDataType == AliHLTTPCDefinitions::fgkDDLPackedRawDataType &&
423 HLTWarning("data type %s is depricated, use %s (kAliHLTDataTypeDDLRaw)!",
424 DataType2Text(AliHLTTPCDefinitions::fgkDDLPackedRawDataType).c_str(),
425 DataType2Text(kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTPC).c_str());
428 if ( iter->fDataType != (kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTPC) &&
429 iter->fDataType != AliHLTTPCDefinitions::fgkDDLPackedRawDataType ) continue;
432 else if(fModeSwitch==1){
433 HLTDebug("Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
434 evtData.fEventID, evtData.fEventID,
435 DataType2Text( iter->fDataType).c_str(),
436 DataType2Text(AliHLTTPCDefinitions::fgkUnpackedRawDataType).c_str());
438 if ( iter->fDataType != AliHLTTPCDefinitions::fgkUnpackedRawDataType ) continue;
442 slice = AliHLTTPCDefinitions::GetMinSliceNr( *iter );
443 patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
444 row[0] = AliHLTTPCTransform::GetFirstRow( patch );
445 row[1] = AliHLTTPCTransform::GetLastRow( patch );
449 fClusterFinder->SetUnsorted(fUnsorted);
450 fClusterFinder->SetPatch(patch);
454 fClusterFinder->SetUnsorted(fUnsorted);
455 //fPadArray = new AliHLTTPCPadArray(patch);
456 //fPadArray->InitializeVector(fModeSwitch);
458 else if(fPadArray->GetPatch()!=patch||fPadArray->GetPatch()==-1){
459 if (GetEventCount()<3) {
460 HLTWarning("pad array not initialized for data of specification 0x%08x, block skipped", iter->fSpecification);
461 } else if ((GetEventCount()%5000)==0) { // assuming 0.5 to 1kHz this gives a message rate of 0.1 to 0.5 Hz
462 HLTWarning("reminder: pad array not initialized for data of specification 0x%08x", iter->fSpecification);
470 outPtr = (AliHLTTPCClusterData*)outBPtr;
472 maxPoints = (size-tSize-sizeof(AliHLTTPCClusterData))/sizeof(AliHLTTPCSpacePointData);
474 fClusterFinder->InitSlice( slice, patch, row[0], row[1], maxPoints );
475 fClusterFinder->SetOutputArray( (AliHLTTPCSpacePointData*)outPtr->fSpacePoints );
478 fClusterFinder->ReadDataUnsorted(iter->fPtr, iter->fSize, fModeSwitch);
480 fClusterFinder->FindClusters();
483 fClusterFinder->Read(iter->fPtr, iter->fSize );
484 fClusterFinder->ProcessDigits();
486 realPoints = fClusterFinder->GetNumberOfClusters();
488 outPtr->fSpacePointCnt = realPoints;
489 nSize = sizeof(AliHLTTPCSpacePointData)*realPoints;
490 mysize += nSize+sizeof(AliHLTTPCClusterData);
492 Logging( kHLTLogDebug, "HLT::TPCClusterFinder::DoEvent", "Spacepoints",
493 "Number of spacepoints: %lu Slice/Patch/RowMin/RowMax: %d/%d/%d/%d.",
494 realPoints, slice, patch, row[0], row[1] );
495 AliHLTComponentBlockData bd;
499 bd.fSpecification = iter->fSpecification;
500 bd.fDataType = AliHLTTPCDefinitions::fgkClustersDataType;
501 //AliHLTSubEventDescriptor::FillBlockAttributes( bd.fAttributes );
502 outputBlocks.push_back( bd );
506 outPtr = (AliHLTTPCClusterData*)outBPtr;
508 /* if(fGetActivePads){
509 AliHLTTPCPadArray::AliHLTTPCActivePads* outPtrActive;
510 UInt_t activePadsSize, activePadsN = 0;
511 outPtrActive = (AliHLTTPCPadArray::AliHLTTPCActivePads*)outBPtr;
513 Int_t maxActivePads = (size-tSize)/sizeof(AliHLTTPCPadArray::AliHLTTPCActivePads);
514 activePadsSize= fClusterFinder->GetActivePads((AliHLTTPCPadArray::AliHLTTPCActivePads*)outPtrActive,maxActivePads)*sizeof(AliHLTTPCPadArray::AliHLTTPCActivePads);
516 AliHLTComponentBlockData bdActive;
517 FillBlockData( bdActive );
518 bdActive.fOffset = offset;
519 bdActive.fSize = activePadsSize;
520 bdActive.fSpecification = iter->fSpecification;
521 bdActive.fDataType = AliHLTTPCDefinitions::fgkActivePadsDataType;
522 outputBlocks.push_back( bdActive );
524 tSize+=activePadsSize;
525 outBPtr += activePadsSize;
526 outPtrActive = (AliHLTTPCPadArray::AliHLTTPCActivePads*)outBPtr;
533 Logging( kHLTLogFatal, "HLT::TPCClusterFinder::DoEvent", "Too much data",
534 "Data written over allowed buffer. Amount written: %lu, allowed amount: %lu.",
545 int AliHLTTPCClusterFinderComponent::Reconfigure(const char* cdbEntry, const char* chainId)
547 // see header file for class documentation
548 const char* path="HLT/ConfigTPC";
549 if (cdbEntry) path=cdbEntry;
551 HLTInfo("reconfigure from entry %s, chain id %s", path, (chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
552 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
554 TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
556 HLTInfo("received configuration object: %s", pString->GetString().Data());
558 HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
561 HLTError("can not fetch object \"%s\" from CDB", path);