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 "AliHLTTPCClusterFinder.h"
41 #include "AliHLTTPCSpacePointData.h"
42 #include "AliHLTTPCClusterDataFormat.h"
43 #include "AliHLTTPCTransform.h"
44 #include "AliHLTTPCClusters.h"
45 #include "AliHLTTPCDefinitions.h"
51 // this is a global object used for automatic component registration, do not use this
52 // use fPackedSwitch = true for packed inputtype "gkDDLPackedRawDataType"
53 // use fPackedSwitch = false for unpacked inputtype "gkUnpackedRawDataType"
54 AliHLTTPCClusterFinderComponent gAliHLTTPCClusterFinderComponentPacked(true);
55 AliHLTTPCClusterFinderComponent gAliHLTTPCClusterFinderComponentUnpacked(false);
57 ClassImp(AliHLTTPCClusterFinderComponent)
59 AliHLTTPCClusterFinderComponent::AliHLTTPCClusterFinderComponent(bool packed)
66 fPackedSwitch(packed),
71 // see header file for class documentation
73 // refer to README to build package
75 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
78 AliHLTTPCClusterFinderComponent::~AliHLTTPCClusterFinderComponent()
80 // see header file for class documentation
83 // Public functions to implement AliHLTComponent's interface.
84 // These functions are required for the registration process
86 const char* AliHLTTPCClusterFinderComponent::GetComponentID()
88 // see header file for class documentation
89 if (fPackedSwitch) return "TPCClusterFinderPacked";
90 else return "TPCClusterFinderUnpacked";
93 void AliHLTTPCClusterFinderComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
95 // see header file for class documentation
97 if (fPackedSwitch) list.push_back( AliHLTTPCDefinitions::fgkDDLPackedRawDataType );
98 else list.push_back( AliHLTTPCDefinitions::fgkUnpackedRawDataType );
102 AliHLTComponentDataType AliHLTTPCClusterFinderComponent::GetOutputDataType()
104 // see header file for class documentation
105 return AliHLTTPCDefinitions::fgkClustersDataType;
108 void AliHLTTPCClusterFinderComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
110 // see header file for class documentation
111 // XXX TODO: Find more realistic values.
113 if (fPackedSwitch) inputMultiplier = (6 * 0.4);
114 else inputMultiplier = 0.4;
117 AliHLTComponent* AliHLTTPCClusterFinderComponent::Spawn()
119 // see header file for class documentation
120 return new AliHLTTPCClusterFinderComponent(fPackedSwitch);
123 int AliHLTTPCClusterFinderComponent::DoInit( int argc, const char** argv )
125 // see header file for class documentation
126 if ( fClusterFinder )
129 fClusterFinder = new AliHLTTPCClusterFinder();
131 Int_t rawreadermode = -1;
132 Int_t sigthresh = -1;
133 Float_t occulimit = 1.0;
134 Int_t oldRCUFormat=0;
135 // Data Format version numbers:
136 // 0: RCU Data format as delivered during TPC commissioning, pads/padrows are sorted, RCU trailer is one 32 bit word.
137 // 1: As 0, but pads/padrows are delivered "as is", without sorting
138 // 2: As 0, but RCU trailer is 3 32 bit words.
139 // 3: As 1, but RCU trailer is 3 32 bit words.
140 // -1: use offline raw reader
147 // -- raw reader mode option
148 if ( !strcmp( argv[i], "rawreadermode" ) ) {
150 Logging( kHLTLogError, "HLT::TPCClusterFinder::DoInit", "Missing rawreadermode", "Raw Reader Mode not specified" );
154 // Decodes the rawreader mode: either number or string and returns the rawreadermode
155 // -1 on failure, -2 for offline
156 rawreadermode = AliHLTTPCDigitReaderRaw::DecodeMode( argv[i+1] );
158 if (rawreadermode == -1 ) {
159 Logging( kHLTLogError, "HLT::TPCClusterFinder::DoInit", "Missing rawreadermode", "Cannot convert rawreadermode specifier '%s'.", argv[i+1] );
168 if ( !strcmp( argv[i], "pp-run" ) ) {
169 fClusterDeconv = false;
174 // -- zero suppression threshold
175 if ( !strcmp( argv[i], "adc-threshold" ) ) {
176 sigthresh = strtoul( argv[i+1], &cpErr ,0);
178 HLTError("Cannot convert threshold specifier '%s'.", argv[i+1]);
185 // -- pad occupancy limit
186 if ( !strcmp( argv[i], "occupancy-limit" ) ) {
187 occulimit = strtod( argv[i+1], &cpErr);
189 HLTError("Cannot convert occupancy specifier '%s'.", argv[i+1]);
196 // -- number of timebins (default 1024)
197 if ( !strcmp( argv[i], "timebins" ) ) {
198 TString parameter(argv[i+1]);
199 parameter.Remove(TString::kLeading, ' '); // remove all blanks
200 if (parameter.IsDigit()) {
201 AliHLTTPCTransform::SetNTimeBins(parameter.Atoi());
202 HLTInfo("number of timebins set to %d, zbin=%f", AliHLTTPCTransform::GetNTimeBins(), AliHLTTPCTransform::GetZWidth());
204 HLTError("Cannot timebin specifier '%s'.", argv[i+1]);
211 // -- checking for rcu format
212 if ( !strcmp( argv[i], "oldrcuformat" ) ) {
213 oldRCUFormat = strtoul( argv[i+1], &cpErr ,0);
215 HLTError("Cannot convert oldrcuformat specifier '%s'. Should be 0(off) or 1(on), must be integer", argv[i+1]);
222 // -- checking for unsorted clusterfinding
223 if ( !strcmp( argv[i], "unsorted" ) ) {
224 fUnsorted = strtoul( argv[i+1], &cpErr ,0);
226 HLTError("Cannot convert unsorted specifier '%s'. Should be 0(off) or 1(on), must be integer", argv[i+1]);
233 // -- checking for unsorted clusterfinding
234 if ( !strcmp( argv[i], "patch" ) ) {
235 fPatch = strtoul( argv[i+1], &cpErr ,0);
237 HLTError("Cannot convert patch specifier '%s'. Should be between 0 and 5, must be integer", argv[i+1]);
244 Logging(kHLTLogError, "HLT::TPCClusterFinder::DoInit", "Unknown Option", "Unknown option '%s'", argv[i] );
252 if (rawreadermode == -2) {
253 #if defined(HAVE_ALIRAWDATA) && defined(HAVE_ALITPCRAWSTREAM_H)
254 fReader = new AliHLTTPCDigitReaderPacked();
256 fReader->SetOldRCUFormat(kTRUE);
258 else if(oldRCUFormat!=0){
259 HLTWarning("Wrong oldrcuformat specifier %d; oldrcuformat set to default(kFALSE)",oldRCUFormat);
262 fReader->SetUnsorted(kTRUE);
264 fClusterFinder->SetReader(fReader);
265 #else // ! defined(HAVE_ALIRAWDATA) && defined(HAVE_ALITPCRAWSTREAM_H)
266 HLTFatal("DigitReaderPacked not available - check your build");
268 #endif // defined(HAVE_ALIRAWDATA) && defined(HAVE_ALITPCRAWSTREAM_H)
270 #if defined(HAVE_TPC_MAPPING)
271 fReader = new AliHLTTPCDigitReaderRaw(rawreadermode);
272 fClusterFinder->SetReader(fReader);
273 #else //! defined(HAVE_TPC_MAPPING)
274 HLTFatal("DigitReaderRaw not available - check your build");
276 #endif //defined(HAVE_TPC_MAPPING)
280 fReader = new AliHLTTPCDigitReaderUnpacked();
281 fClusterFinder->SetReader(fReader);
284 // if pp-run use occupancy limit else set to 1. ==> use all
285 if ( !fClusterDeconv )
286 fClusterFinder->SetOccupancyLimit(occulimit);
288 fClusterFinder->SetOccupancyLimit(1.0);
290 // Variables to setup the Clusterfinder
291 // TODO: this sounds strange and has to be verified; is the cluster finder not working when
292 // fClusterDeconv = false ?
293 fClusterDeconv = true;
294 fXYClusterError = -1;
298 fClusterFinder->SetDeconv( fClusterDeconv );
299 fClusterFinder->SetXYError( fXYClusterError );
300 fClusterFinder->SetZError( fZClusterError );
301 if ( (fXYClusterError>0) && (fZClusterError>0) )
302 fClusterFinder->SetCalcErr( false );
303 fClusterFinder->SetSignalThreshold(sigthresh);
305 if(fUnsorted&&fPatch>-1&&fPatch<6){
306 fPadArray = new AliHLTTPCPadArray(fPatch);
307 fPadArray->InitializeVector();
313 int AliHLTTPCClusterFinderComponent::DoDeinit()
315 // see header file for class documentation
317 if ( fClusterFinder )
318 delete fClusterFinder;
319 fClusterFinder = NULL;
328 int AliHLTTPCClusterFinderComponent::DoEvent( const AliHLTComponentEventData& evtData,
329 const AliHLTComponentBlockData* blocks,
330 AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr,
331 AliHLTUInt32_t& size,
332 vector<AliHLTComponentBlockData>& outputBlocks )
334 // see header file for class documentation
336 // == init iter (pointer to datablock)
337 const AliHLTComponentBlockData* iter = NULL;
340 // == OUTdatatype pointer
341 AliHLTTPCClusterData* outPtr;
343 AliHLTUInt8_t* outBPtr;
344 UInt_t offset, mysize, nSize, tSize = 0;
347 outPtr = (AliHLTTPCClusterData*)outBPtr;
349 Int_t slice, patch, row[2];
350 unsigned long maxPoints, realPoints = 0;
352 for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
360 char tmp1[14], tmp2[14];
361 DataType2Text( iter->fDataType, tmp1 );
362 DataType2Text( AliHLTTPCDefinitions::fgkDDLPackedRawDataType, tmp2 );
363 Logging( kHLTLogDebug, "HLT::TPCClusterFinder::DoEvent", "Event received",
364 "Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
365 evtData.fEventID, evtData.fEventID, tmp1, tmp2 );
367 if ( iter->fDataType != AliHLTTPCDefinitions::fgkDDLPackedRawDataType ) continue;
371 char tmp1[14], tmp2[14];
372 DataType2Text( iter->fDataType, tmp1 );
373 DataType2Text( AliHLTTPCDefinitions::fgkUnpackedRawDataType, tmp2 );
374 Logging( kHLTLogDebug, "HLT::TPCClusterFinder::DoEvent", "Event received",
375 "Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
376 evtData.fEventID, evtData.fEventID, tmp1, tmp2 );
378 if ( iter->fDataType != AliHLTTPCDefinitions::fgkUnpackedRawDataType ) continue;
382 slice = AliHLTTPCDefinitions::GetMinSliceNr( *iter );
383 patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
384 row[0] = AliHLTTPCTransform::GetFirstRow( patch );
385 row[1] = AliHLTTPCTransform::GetLastRow( patch );
387 outPtr = (AliHLTTPCClusterData*)outBPtr;
390 maxPoints = (size-tSize-sizeof(AliHLTTPCClusterData))/sizeof(AliHLTTPCSpacePointData);
392 maxPoints = (size-tSize-sizeof(AliHLTTPCClusters))/sizeof(AliHLTTPCSpacePointData);
395 fClusterFinder->InitSlice( slice, patch, row[0], row[1], maxPoints );
396 fClusterFinder->SetOutputArray( (AliHLTTPCSpacePointData*)outPtr->fSpacePoints );
401 fClusterFinder->SetPadArray(fPadArray);
404 struct timeval startT, endT;
405 gettimeofday( &startT, NULL );
407 fClusterFinder->ReadDataUnsorted(iter->fPtr, iter->fSize );
409 gettimeofday( &endT, NULL );
410 unsigned long long dt;
411 dt = endT.tv_sec-startT.tv_sec;
413 dt += endT.tv_usec-startT.tv_usec;
414 double dtd = ((double)dt);
416 // dtd = dtd / (double)eventIterations;
417 // if ( iterations<=1 )
419 printf( "Time needed to read data: %f microsec. / %f millisec. / %f s\n",
420 dtd, dtd/1000.0, dtd/1000000.0 );
423 fClusterFinder->FindClusters();
426 fClusterFinder->Read(iter->fPtr, iter->fSize );
427 fClusterFinder->ProcessDigits();
429 realPoints = fClusterFinder->GetNumberOfClusters();
431 outPtr->fSpacePointCnt = realPoints;
432 nSize = sizeof(AliHLTTPCSpacePointData)*realPoints;
434 mysize += nSize+sizeof(AliHLTTPCClusterData);
436 mysize += nSize+sizeof(AliHLTTPCClusters);
439 Logging( kHLTLogDebug, "HLT::TPCClusterFinder::DoEvent", "Spacepoints",
440 "Number of spacepoints: %lu Slice/Patch/RowMin/RowMax: %d/%d/%d/%d.",
441 realPoints, slice, patch, row[0], row[1] );
442 AliHLTComponentBlockData bd;
446 bd.fSpecification = iter->fSpecification;
447 //AliHLTSubEventDescriptor::FillBlockAttributes( bd.fAttributes );
448 outputBlocks.push_back( bd );
452 outPtr = (AliHLTTPCClusterData*)outBPtr;
456 Logging( kHLTLogFatal, "HLT::TPCClusterFinder::DoEvent", "Too much data",
457 "Data written over allowed buffer. Amount written: %lu, allowed amount: %lu.",