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
30 #include "AliHLTTPCLogging.h"
31 #include "AliHLTTPCClusterFinderComponent.h"
32 #include "AliHLTTPCDigitReaderPacked.h"
33 #include "AliHLTTPCDigitReaderUnpacked.h"
34 #include "AliHLTTPCDigitReaderRaw.h"
35 #include "AliHLTTPCClusterFinder.h"
36 #include "AliHLTTPCSpacePointData.h"
37 #include "AliHLTTPCRawDataFormat.h"
38 #include "AliHLTTPCClusterDataFormat.h"
39 #include "AliHLTTPCTransform.h"
40 #include "AliHLTTPCClusters.h"
44 #include "TStopwatch.h"
47 // this is a global object used for automatic component registration, do not use this
48 // use fPackedSwitch = true for packed inputtype "gkDDLPackedRawDataType"
49 // use fPackedSwitch = false for unpacked inputtype "gkUnpackedRawDataType"
50 AliHLTTPCClusterFinderComponent gAliHLTTPCClusterFinderComponentPacked(true);
51 AliHLTTPCClusterFinderComponent gAliHLTTPCClusterFinderComponentUnpacked(false);
53 ClassImp(AliHLTTPCClusterFinderComponent)
55 AliHLTTPCClusterFinderComponent::AliHLTTPCClusterFinderComponent(bool packed)
62 fPackedSwitch(packed),
67 // see header file for class documentation
69 // refer to README to build package
71 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
74 AliHLTTPCClusterFinderComponent::AliHLTTPCClusterFinderComponent(const AliHLTTPCClusterFinderComponent&)
86 // see header file for class documentation
87 HLTFatal("copy constructor untested");
90 AliHLTTPCClusterFinderComponent& AliHLTTPCClusterFinderComponent::operator=(const AliHLTTPCClusterFinderComponent&)
92 // see header file for class documentation
93 HLTFatal("assignment operator untested");
97 AliHLTTPCClusterFinderComponent::~AliHLTTPCClusterFinderComponent()
99 // see header file for class documentation
102 // Public functions to implement AliHLTComponent's interface.
103 // These functions are required for the registration process
105 const char* AliHLTTPCClusterFinderComponent::GetComponentID()
107 // see header file for class documentation
108 if (fPackedSwitch) return "TPCClusterFinderPacked";
109 else return "TPCClusterFinderUnpacked";
112 void AliHLTTPCClusterFinderComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
114 // see header file for class documentation
116 if (fPackedSwitch) list.push_back( AliHLTTPCDefinitions::fgkDDLPackedRawDataType );
117 else list.push_back( AliHLTTPCDefinitions::fgkUnpackedRawDataType );
121 AliHLTComponentDataType AliHLTTPCClusterFinderComponent::GetOutputDataType()
123 // see header file for class documentation
124 return AliHLTTPCDefinitions::fgkClustersDataType;
127 void AliHLTTPCClusterFinderComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
129 // see header file for class documentation
130 // XXX TODO: Find more realistic values.
132 if (fPackedSwitch) inputMultiplier = (6 * 0.4);
133 else inputMultiplier = 0.4;
136 AliHLTComponent* AliHLTTPCClusterFinderComponent::Spawn()
138 // see header file for class documentation
139 return new AliHLTTPCClusterFinderComponent(fPackedSwitch);
142 int AliHLTTPCClusterFinderComponent::DoInit( int argc, const char** argv )
144 // see header file for class documentation
145 if ( fClusterFinder )
148 fClusterFinder = new AliHLTTPCClusterFinder();
150 Int_t rawreadermode = -1;
151 Int_t sigthresh = -1;
152 Float_t occulimit = 1.0;
153 Int_t oldRCUFormat=0;
154 // Data Format version numbers:
155 // 0: RCU Data format as delivered during TPC commissioning, pads/padrows are sorted, RCU trailer is one 32 bit word.
156 // 1: As 0, but pads/padrows are delivered "as is", without sorting
157 // 2: As 0, but RCU trailer is 3 32 bit words.
158 // 3: As 1, but RCU trailer is 3 32 bit words.
159 // -1: use offline raw reader
166 // -- raw reader mode option
167 if ( !strcmp( argv[i], "rawreadermode" ) ) {
169 Logging( kHLTLogError, "HLT::TPCClusterFinder::DoInit", "Missing rawreadermode", "Raw Reader Mode not specified" );
173 // Decodes the rawreader mode: either number or string and returns the rawreadermode
174 // -1 on failure, -2 for offline
175 rawreadermode = AliHLTTPCDigitReaderRaw::DecodeMode( argv[i+1] );
177 if (rawreadermode == -1 ) {
178 Logging( kHLTLogError, "HLT::TPCClusterFinder::DoInit", "Missing rawreadermode", "Cannot convert rawreadermode specifier '%s'.", argv[i+1] );
187 if ( !strcmp( argv[i], "pp-run" ) ) {
188 fClusterDeconv = false;
193 // -- zero suppression threshold
194 if ( !strcmp( argv[i], "adc-threshold" ) ) {
195 sigthresh = strtoul( argv[i+1], &cpErr ,0);
197 HLTError("Cannot convert threshold specifier '%s'.", argv[i+1]);
204 // -- pad occupancy limit
205 if ( !strcmp( argv[i], "occupancy-limit" ) ) {
206 occulimit = strtof( argv[i+1], &cpErr);
208 HLTError("Cannot convert occupancy specifier '%s'.", argv[i+1]);
215 // -- number of timebins (default 1024)
216 if ( !strcmp( argv[i], "timebins" ) ) {
217 TString parameter(argv[i+1]);
218 parameter.Remove(TString::kLeading, ' '); // remove all blanks
219 if (parameter.IsDigit()) {
220 AliHLTTPCTransform::SetNTimeBins(parameter.Atoi());
221 HLTInfo("number of timebins set to %d", AliHLTTPCTransform::GetNTimeBins());
223 HLTError("Cannot timebin specifier '%s'.", argv[i+1]);
230 // -- checking for rcu format
231 if ( !strcmp( argv[i], "oldrcuformat" ) ) {
232 oldRCUFormat = strtoul( argv[i+1], &cpErr ,0);
234 HLTError("Cannot convert oldrcuformat specifier '%s'. Should be 0(off) or 1(on), must be integer", argv[i+1]);
241 // -- checking for unsorted clusterfinding
242 if ( !strcmp( argv[i], "unsorted" ) ) {
243 fUnsorted = strtoul( argv[i+1], &cpErr ,0);
245 HLTError("Cannot convert unsorted specifier '%s'. Should be 0(off) or 1(on), must be integer", argv[i+1]);
252 // -- checking for unsorted clusterfinding
253 if ( !strcmp( argv[i], "patch" ) ) {
254 fPatch = strtoul( argv[i+1], &cpErr ,0);
256 HLTError("Cannot convert patch specifier '%s'. Should be between 0 and 5, must be integer", argv[i+1]);
263 Logging(kHLTLogError, "HLT::TPCClusterFinder::DoInit", "Unknown Option", "Unknown option '%s'", argv[i] );
271 if (rawreadermode == -2) {
272 #if defined(HAVE_ALIRAWDATA) && defined(HAVE_ALITPCRAWSTREAM_H)
273 fReader = new AliHLTTPCDigitReaderPacked();
275 fReader->SetOldRCUFormat(kTRUE);
277 else if(oldRCUFormat!=0){
278 HLTWarning("Wrong oldrcuformat specifier %d; oldrcuformat set to default(kFALSE)",oldRCUFormat);
281 fReader->SetUnsorted(kTRUE);
283 fClusterFinder->SetReader(fReader);
284 #else // ! defined(HAVE_ALIRAWDATA) && defined(HAVE_ALITPCRAWSTREAM_H)
285 HLTFatal("DigitReaderPacked not available - check your build");
287 #endif // defined(HAVE_ALIRAWDATA) && defined(HAVE_ALITPCRAWSTREAM_H)
289 #if defined(HAVE_TPC_MAPPING)
290 fReader = new AliHLTTPCDigitReaderRaw(rawreadermode);
291 fClusterFinder->SetReader(fReader);
292 #else //! defined(HAVE_TPC_MAPPING)
293 HLTFatal("DigitReaderRaw not available - check your build");
295 #endif //defined(HAVE_TPC_MAPPING)
299 fReader = new AliHLTTPCDigitReaderUnpacked();
300 fClusterFinder->SetReader(fReader);
303 // if pp-run use occupancy limit else set to 1. ==> use all
304 if ( !fClusterDeconv )
305 fClusterFinder->SetOccupancyLimit(occulimit);
307 fClusterFinder->SetOccupancyLimit(1.0);
309 // Variables to setup the Clusterfinder
310 // TODO: this sounds strange and has to be verified; is the cluster finder not working when
311 // fClusterDeconv = false ?
312 fClusterDeconv = true;
313 fXYClusterError = -1;
317 fClusterFinder->SetDeconv( fClusterDeconv );
318 fClusterFinder->SetXYError( fXYClusterError );
319 fClusterFinder->SetZError( fZClusterError );
320 if ( (fXYClusterError>0) && (fZClusterError>0) )
321 fClusterFinder->SetCalcErr( false );
322 fClusterFinder->SetSignalThreshold(sigthresh);
324 if(fUnsorted&&fPatch>-1&&fPatch<6){
325 fPadArray = new AliHLTTPCPadArray(fPatch);
326 fPadArray->InitializeVector();
332 int AliHLTTPCClusterFinderComponent::DoDeinit()
334 // see header file for class documentation
336 if ( fClusterFinder )
337 delete fClusterFinder;
338 fClusterFinder = NULL;
347 int AliHLTTPCClusterFinderComponent::DoEvent( const AliHLTComponentEventData& evtData,
348 const AliHLTComponentBlockData* blocks,
349 AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr,
350 AliHLTUInt32_t& size,
351 vector<AliHLTComponentBlockData>& outputBlocks )
353 // see header file for class documentation
355 // == init iter (pointer to datablock)
356 const AliHLTComponentBlockData* iter = NULL;
359 // == OUTdatatype pointer
360 AliHLTTPCClusterData* outPtr;
362 AliHLTUInt8_t* outBPtr;
363 UInt_t offset, mysize, nSize, tSize = 0;
366 outPtr = (AliHLTTPCClusterData*)outBPtr;
368 Int_t slice, patch, row[2];
369 unsigned long maxPoints, realPoints = 0;
371 for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
379 char tmp1[14], tmp2[14];
380 DataType2Text( iter->fDataType, tmp1 );
381 DataType2Text( AliHLTTPCDefinitions::fgkDDLPackedRawDataType, tmp2 );
382 Logging( kHLTLogDebug, "HLT::TPCClusterFinder::DoEvent", "Event received",
383 "Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
384 evtData.fEventID, evtData.fEventID, tmp1, tmp2 );
386 if ( iter->fDataType != AliHLTTPCDefinitions::fgkDDLPackedRawDataType ) continue;
390 char tmp1[14], tmp2[14];
391 DataType2Text( iter->fDataType, tmp1 );
392 DataType2Text( AliHLTTPCDefinitions::fgkUnpackedRawDataType, tmp2 );
393 Logging( kHLTLogDebug, "HLT::TPCClusterFinder::DoEvent", "Event received",
394 "Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
395 evtData.fEventID, evtData.fEventID, tmp1, tmp2 );
397 if ( iter->fDataType != AliHLTTPCDefinitions::fgkUnpackedRawDataType ) continue;
401 slice = AliHLTTPCDefinitions::GetMinSliceNr( *iter );
402 patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
403 row[0] = AliHLTTPCTransform::GetFirstRow( patch );
404 row[1] = AliHLTTPCTransform::GetLastRow( patch );
406 Logging( kHLTLogDebug, "HLT::TPCClusterFinder::DoEvent", "Input Spacepoints",
407 "Input: Number of spacepoints: %lu Slice/Patch/RowMin/RowMax: %d/%d/%d/%d.",
408 realPoints, slice, patch, row[0], row[1] );
410 outPtr = (AliHLTTPCClusterData*)outBPtr;
413 maxPoints = (size-tSize-sizeof(AliHLTTPCClusterData))/sizeof(AliHLTTPCSpacePointData);
415 maxPoints = (size-tSize-sizeof(AliHLTTPCClusters))/sizeof(AliHLTTPCSpacePointData);
418 fClusterFinder->InitSlice( slice, patch, row[0], row[1], maxPoints );
419 fClusterFinder->SetOutputArray( outPtr->fSpacePoints );
424 fClusterFinder->SetPadArray(fPadArray);
427 struct timeval startT, endT;
428 gettimeofday( &startT, NULL );
430 fClusterFinder->ReadDataUnsorted(iter->fPtr, iter->fSize );
432 gettimeofday( &endT, NULL );
433 unsigned long long dt;
434 dt = endT.tv_sec-startT.tv_sec;
436 dt += endT.tv_usec-startT.tv_usec;
437 double dtd = ((double)dt);
439 // dtd = dtd / (double)eventIterations;
440 // if ( iterations<=1 )
442 printf( "Time needed to read data: %f microsec. / %f millisec. / %f s\n",
443 dtd, dtd/1000.0, dtd/1000000.0 );
446 fClusterFinder->FindClusters();
449 fClusterFinder->Read(iter->fPtr, iter->fSize );
450 fClusterFinder->ProcessDigits();
452 realPoints = fClusterFinder->GetNumberOfClusters();
454 Logging( kHLTLogDebug, "HLT::TPCClusterFinder::DoEvent", "Spacepoints",
455 "Number of spacepoints found: %lu.", realPoints );
457 outPtr->fSpacePointCnt = realPoints;
458 nSize = sizeof(AliHLTTPCSpacePointData)*realPoints;
460 mysize += nSize+sizeof(AliHLTTPCClusterData);
462 mysize += nSize+sizeof(AliHLTTPCClusters);
465 Logging( kHLTLogDebug, "HLT::TPCClusterFinder::DoEvent", "Input Spacepoints",
466 "Number of spacepoints: %lu Slice/Patch/RowMin/RowMax: %d/%d/%d/%d.",
467 realPoints, slice, patch, row[0], row[1] );
468 AliHLTComponentBlockData bd;
472 bd.fSpecification = iter->fSpecification;
473 //AliHLTSubEventDescriptor::FillBlockAttributes( bd.fAttributes );
474 outputBlocks.push_back( bd );
478 outPtr = (AliHLTTPCClusterData*)outBPtr;
482 Logging( kHLTLogFatal, "HLT::TPCClusterFinder::DoEvent", "Too much data",
483 "Data written over allowed buffer. Amount written: %lu, allowed amount: %lu.",