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 "AliHLTTPCClusterDataFormat.h"
38 #include "AliHLTTPCTransform.h"
39 #include "AliHLTTPCClusters.h"
43 #include "TStopwatch.h"
46 // this is a global object used for automatic component registration, do not use this
47 // use fPackedSwitch = true for packed inputtype "gkDDLPackedRawDataType"
48 // use fPackedSwitch = false for unpacked inputtype "gkUnpackedRawDataType"
49 AliHLTTPCClusterFinderComponent gAliHLTTPCClusterFinderComponentPacked(true);
50 AliHLTTPCClusterFinderComponent gAliHLTTPCClusterFinderComponentUnpacked(false);
52 ClassImp(AliHLTTPCClusterFinderComponent)
54 AliHLTTPCClusterFinderComponent::AliHLTTPCClusterFinderComponent(bool packed)
61 fPackedSwitch(packed),
66 // see header file for class documentation
68 // refer to README to build package
70 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
73 AliHLTTPCClusterFinderComponent::AliHLTTPCClusterFinderComponent(const AliHLTTPCClusterFinderComponent&)
85 // see header file for class documentation
86 HLTFatal("copy constructor untested");
89 AliHLTTPCClusterFinderComponent& AliHLTTPCClusterFinderComponent::operator=(const AliHLTTPCClusterFinderComponent&)
91 // see header file for class documentation
92 HLTFatal("assignment operator untested");
96 AliHLTTPCClusterFinderComponent::~AliHLTTPCClusterFinderComponent()
98 // see header file for class documentation
101 // Public functions to implement AliHLTComponent's interface.
102 // These functions are required for the registration process
104 const char* AliHLTTPCClusterFinderComponent::GetComponentID()
106 // see header file for class documentation
107 if (fPackedSwitch) return "TPCClusterFinderPacked";
108 else return "TPCClusterFinderUnpacked";
111 void AliHLTTPCClusterFinderComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
113 // see header file for class documentation
115 if (fPackedSwitch) list.push_back( AliHLTTPCDefinitions::fgkDDLPackedRawDataType );
116 else list.push_back( AliHLTTPCDefinitions::fgkUnpackedRawDataType );
120 AliHLTComponentDataType AliHLTTPCClusterFinderComponent::GetOutputDataType()
122 // see header file for class documentation
123 return AliHLTTPCDefinitions::fgkClustersDataType;
126 void AliHLTTPCClusterFinderComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
128 // see header file for class documentation
129 // XXX TODO: Find more realistic values.
131 if (fPackedSwitch) inputMultiplier = (6 * 0.4);
132 else inputMultiplier = 0.4;
135 AliHLTComponent* AliHLTTPCClusterFinderComponent::Spawn()
137 // see header file for class documentation
138 return new AliHLTTPCClusterFinderComponent(fPackedSwitch);
141 int AliHLTTPCClusterFinderComponent::DoInit( int argc, const char** argv )
143 // see header file for class documentation
144 if ( fClusterFinder )
147 fClusterFinder = new AliHLTTPCClusterFinder();
149 Int_t rawreadermode = -1;
150 Int_t sigthresh = -1;
151 Float_t occulimit = 1.0;
152 Int_t oldRCUFormat=0;
153 // Data Format version numbers:
154 // 0: RCU Data format as delivered during TPC commissioning, pads/padrows are sorted, RCU trailer is one 32 bit word.
155 // 1: As 0, but pads/padrows are delivered "as is", without sorting
156 // 2: As 0, but RCU trailer is 3 32 bit words.
157 // 3: As 1, but RCU trailer is 3 32 bit words.
158 // -1: use offline raw reader
165 // -- raw reader mode option
166 if ( !strcmp( argv[i], "rawreadermode" ) ) {
168 Logging( kHLTLogError, "HLT::TPCClusterFinder::DoInit", "Missing rawreadermode", "Raw Reader Mode not specified" );
172 // Decodes the rawreader mode: either number or string and returns the rawreadermode
173 // -1 on failure, -2 for offline
174 rawreadermode = AliHLTTPCDigitReaderRaw::DecodeMode( argv[i+1] );
176 if (rawreadermode == -1 ) {
177 Logging( kHLTLogError, "HLT::TPCClusterFinder::DoInit", "Missing rawreadermode", "Cannot convert rawreadermode specifier '%s'.", argv[i+1] );
186 if ( !strcmp( argv[i], "pp-run" ) ) {
187 fClusterDeconv = false;
192 // -- zero suppression threshold
193 if ( !strcmp( argv[i], "adc-threshold" ) ) {
194 sigthresh = strtoul( argv[i+1], &cpErr ,0);
196 HLTError("Cannot convert threshold specifier '%s'.", argv[i+1]);
203 // -- pad occupancy limit
204 if ( !strcmp( argv[i], "occupancy-limit" ) ) {
205 occulimit = strtod( argv[i+1], &cpErr);
207 HLTError("Cannot convert occupancy specifier '%s'.", argv[i+1]);
214 // -- number of timebins (default 1024)
215 if ( !strcmp( argv[i], "timebins" ) ) {
216 TString parameter(argv[i+1]);
217 parameter.Remove(TString::kLeading, ' '); // remove all blanks
218 if (parameter.IsDigit()) {
219 AliHLTTPCTransform::SetNTimeBins(parameter.Atoi());
220 HLTInfo("number of timebins set to %d", AliHLTTPCTransform::GetNTimeBins());
222 HLTError("Cannot timebin specifier '%s'.", argv[i+1]);
229 // -- checking for rcu format
230 if ( !strcmp( argv[i], "oldrcuformat" ) ) {
231 oldRCUFormat = strtoul( argv[i+1], &cpErr ,0);
233 HLTError("Cannot convert oldrcuformat specifier '%s'. Should be 0(off) or 1(on), must be integer", argv[i+1]);
240 // -- checking for unsorted clusterfinding
241 if ( !strcmp( argv[i], "unsorted" ) ) {
242 fUnsorted = strtoul( argv[i+1], &cpErr ,0);
244 HLTError("Cannot convert unsorted specifier '%s'. Should be 0(off) or 1(on), must be integer", argv[i+1]);
251 // -- checking for unsorted clusterfinding
252 if ( !strcmp( argv[i], "patch" ) ) {
253 fPatch = strtoul( argv[i+1], &cpErr ,0);
255 HLTError("Cannot convert patch specifier '%s'. Should be between 0 and 5, must be integer", argv[i+1]);
262 Logging(kHLTLogError, "HLT::TPCClusterFinder::DoInit", "Unknown Option", "Unknown option '%s'", argv[i] );
270 if (rawreadermode == -2) {
271 #if defined(HAVE_ALIRAWDATA) && defined(HAVE_ALITPCRAWSTREAM_H)
272 fReader = new AliHLTTPCDigitReaderPacked();
274 fReader->SetOldRCUFormat(kTRUE);
276 else if(oldRCUFormat!=0){
277 HLTWarning("Wrong oldrcuformat specifier %d; oldrcuformat set to default(kFALSE)",oldRCUFormat);
280 fReader->SetUnsorted(kTRUE);
282 fClusterFinder->SetReader(fReader);
283 #else // ! defined(HAVE_ALIRAWDATA) && defined(HAVE_ALITPCRAWSTREAM_H)
284 HLTFatal("DigitReaderPacked not available - check your build");
286 #endif // defined(HAVE_ALIRAWDATA) && defined(HAVE_ALITPCRAWSTREAM_H)
288 #if defined(HAVE_TPC_MAPPING)
289 fReader = new AliHLTTPCDigitReaderRaw(rawreadermode);
290 fClusterFinder->SetReader(fReader);
291 #else //! defined(HAVE_TPC_MAPPING)
292 HLTFatal("DigitReaderRaw not available - check your build");
294 #endif //defined(HAVE_TPC_MAPPING)
298 fReader = new AliHLTTPCDigitReaderUnpacked();
299 fClusterFinder->SetReader(fReader);
302 // if pp-run use occupancy limit else set to 1. ==> use all
303 if ( !fClusterDeconv )
304 fClusterFinder->SetOccupancyLimit(occulimit);
306 fClusterFinder->SetOccupancyLimit(1.0);
308 // Variables to setup the Clusterfinder
309 // TODO: this sounds strange and has to be verified; is the cluster finder not working when
310 // fClusterDeconv = false ?
311 fClusterDeconv = true;
312 fXYClusterError = -1;
316 fClusterFinder->SetDeconv( fClusterDeconv );
317 fClusterFinder->SetXYError( fXYClusterError );
318 fClusterFinder->SetZError( fZClusterError );
319 if ( (fXYClusterError>0) && (fZClusterError>0) )
320 fClusterFinder->SetCalcErr( false );
321 fClusterFinder->SetSignalThreshold(sigthresh);
323 if(fUnsorted&&fPatch>-1&&fPatch<6){
324 fPadArray = new AliHLTTPCPadArray(fPatch);
325 fPadArray->InitializeVector();
331 int AliHLTTPCClusterFinderComponent::DoDeinit()
333 // see header file for class documentation
335 if ( fClusterFinder )
336 delete fClusterFinder;
337 fClusterFinder = NULL;
346 int AliHLTTPCClusterFinderComponent::DoEvent( const AliHLTComponentEventData& evtData,
347 const AliHLTComponentBlockData* blocks,
348 AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr,
349 AliHLTUInt32_t& size,
350 vector<AliHLTComponentBlockData>& outputBlocks )
352 // see header file for class documentation
354 // == init iter (pointer to datablock)
355 const AliHLTComponentBlockData* iter = NULL;
358 // == OUTdatatype pointer
359 AliHLTTPCClusterData* outPtr;
361 AliHLTUInt8_t* outBPtr;
362 UInt_t offset, mysize, nSize, tSize = 0;
365 outPtr = (AliHLTTPCClusterData*)outBPtr;
367 Int_t slice, patch, row[2];
368 unsigned long maxPoints, realPoints = 0;
370 for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
378 char tmp1[14], tmp2[14];
379 DataType2Text( iter->fDataType, tmp1 );
380 DataType2Text( AliHLTTPCDefinitions::fgkDDLPackedRawDataType, tmp2 );
381 Logging( kHLTLogDebug, "HLT::TPCClusterFinder::DoEvent", "Event received",
382 "Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
383 evtData.fEventID, evtData.fEventID, tmp1, tmp2 );
385 if ( iter->fDataType != AliHLTTPCDefinitions::fgkDDLPackedRawDataType ) continue;
389 char tmp1[14], tmp2[14];
390 DataType2Text( iter->fDataType, tmp1 );
391 DataType2Text( AliHLTTPCDefinitions::fgkUnpackedRawDataType, tmp2 );
392 Logging( kHLTLogDebug, "HLT::TPCClusterFinder::DoEvent", "Event received",
393 "Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
394 evtData.fEventID, evtData.fEventID, tmp1, tmp2 );
396 if ( iter->fDataType != AliHLTTPCDefinitions::fgkUnpackedRawDataType ) continue;
400 slice = AliHLTTPCDefinitions::GetMinSliceNr( *iter );
401 patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
402 row[0] = AliHLTTPCTransform::GetFirstRow( patch );
403 row[1] = AliHLTTPCTransform::GetLastRow( patch );
405 Logging( kHLTLogDebug, "HLT::TPCClusterFinder::DoEvent", "Input Spacepoints",
406 "Input: Number of spacepoints: %lu Slice/Patch/RowMin/RowMax: %d/%d/%d/%d.",
407 realPoints, slice, patch, row[0], row[1] );
409 outPtr = (AliHLTTPCClusterData*)outBPtr;
412 maxPoints = (size-tSize-sizeof(AliHLTTPCClusterData))/sizeof(AliHLTTPCSpacePointData);
414 maxPoints = (size-tSize-sizeof(AliHLTTPCClusters))/sizeof(AliHLTTPCSpacePointData);
417 fClusterFinder->InitSlice( slice, patch, row[0], row[1], maxPoints );
418 fClusterFinder->SetOutputArray( (AliHLTTPCSpacePointData*)outPtr->fSpacePoints );
423 fClusterFinder->SetPadArray(fPadArray);
426 struct timeval startT, endT;
427 gettimeofday( &startT, NULL );
429 fClusterFinder->ReadDataUnsorted(iter->fPtr, iter->fSize );
431 gettimeofday( &endT, NULL );
432 unsigned long long dt;
433 dt = endT.tv_sec-startT.tv_sec;
435 dt += endT.tv_usec-startT.tv_usec;
436 double dtd = ((double)dt);
438 // dtd = dtd / (double)eventIterations;
439 // if ( iterations<=1 )
441 printf( "Time needed to read data: %f microsec. / %f millisec. / %f s\n",
442 dtd, dtd/1000.0, dtd/1000000.0 );
445 fClusterFinder->FindClusters();
448 fClusterFinder->Read(iter->fPtr, iter->fSize );
449 fClusterFinder->ProcessDigits();
451 realPoints = fClusterFinder->GetNumberOfClusters();
453 Logging( kHLTLogDebug, "HLT::TPCClusterFinder::DoEvent", "Spacepoints",
454 "Number of spacepoints found: %lu.", realPoints );
456 outPtr->fSpacePointCnt = realPoints;
457 nSize = sizeof(AliHLTTPCSpacePointData)*realPoints;
459 mysize += nSize+sizeof(AliHLTTPCClusterData);
461 mysize += nSize+sizeof(AliHLTTPCClusters);
464 Logging( kHLTLogDebug, "HLT::TPCClusterFinder::DoEvent", "Input Spacepoints",
465 "Number of spacepoints: %lu Slice/Patch/RowMin/RowMax: %d/%d/%d/%d.",
466 realPoints, slice, patch, row[0], row[1] );
467 AliHLTComponentBlockData bd;
471 bd.fSpecification = iter->fSpecification;
472 //AliHLTSubEventDescriptor::FillBlockAttributes( bd.fAttributes );
473 outputBlocks.push_back( bd );
477 outPtr = (AliHLTTPCClusterData*)outBPtr;
481 Logging( kHLTLogFatal, "HLT::TPCClusterFinder::DoEvent", "Too much data",
482 "Data written over allowed buffer. Amount written: %lu, allowed amount: %lu.",