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"
44 // this is a global object used for automatic component registration, do not use this
45 // use fPackedSwitch = true for packed inputtype "gkDDLPackedRawDataType"
46 // use fPackedSwitch = false for unpacked inputtype "gkUnpackedRawDataType"
47 AliHLTTPCClusterFinderComponent gAliHLTTPCClusterFinderComponentPacked(true);
48 AliHLTTPCClusterFinderComponent gAliHLTTPCClusterFinderComponentUnpacked(false);
50 ClassImp(AliHLTTPCClusterFinderComponent)
52 AliHLTTPCClusterFinderComponent::AliHLTTPCClusterFinderComponent(bool packed)
61 // see header file for class documentation
63 // refer to README to build package
65 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
68 AliHLTTPCClusterFinderComponent::AliHLTTPCClusterFinderComponent(const AliHLTTPCClusterFinderComponent&)
77 // see header file for class documentation
78 HLTFatal("copy constructor untested");
81 AliHLTTPCClusterFinderComponent& AliHLTTPCClusterFinderComponent::operator=(const AliHLTTPCClusterFinderComponent&)
83 // see header file for class documentation
84 HLTFatal("assignment operator untested");
88 AliHLTTPCClusterFinderComponent::~AliHLTTPCClusterFinderComponent()
90 // see header file for class documentation
93 // Public functions to implement AliHLTComponent's interface.
94 // These functions are required for the registration process
96 const char* AliHLTTPCClusterFinderComponent::GetComponentID()
98 // see header file for class documentation
99 if (fPackedSwitch) return "TPCClusterFinderPacked";
100 else return "TPCClusterFinderUnpacked";
103 void AliHLTTPCClusterFinderComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
105 // see header file for class documentation
107 if (fPackedSwitch) list.push_back( AliHLTTPCDefinitions::fgkDDLPackedRawDataType );
108 else list.push_back( AliHLTTPCDefinitions::fgkUnpackedRawDataType );
112 AliHLTComponentDataType AliHLTTPCClusterFinderComponent::GetOutputDataType()
114 // see header file for class documentation
115 return AliHLTTPCDefinitions::fgkClustersDataType;
118 void AliHLTTPCClusterFinderComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
120 // see header file for class documentation
121 // XXX TODO: Find more realistic values.
123 if (fPackedSwitch) inputMultiplier = (6 * 0.4);
124 else inputMultiplier = 0.4;
127 AliHLTComponent* AliHLTTPCClusterFinderComponent::Spawn()
129 // see header file for class documentation
130 return new AliHLTTPCClusterFinderComponent(fPackedSwitch);
133 int AliHLTTPCClusterFinderComponent::DoInit( int argc, const char** argv )
135 // see header file for class documentation
136 if ( fClusterFinder )
139 fClusterFinder = new AliHLTTPCClusterFinder();
141 Int_t rawreadermode = -1;
142 Int_t sigthresh = -1;
143 Float_t occulimit = 1.0;
144 Int_t oldRCUFormat=0;
145 // Data Format version numbers:
146 // 0: RCU Data format as delivered during TPC commissioning, pads/padrows are sorted, RCU trailer is one 32 bit word.
147 // 1: As 0, but pads/padrows are delivered "as is", without sorting
148 // 2: As 0, but RCU trailer is 3 32 bit words.
149 // 3: As 1, but RCU trailer is 3 32 bit words.
150 // -1: use offline raw reader
157 // -- raw reader mode option
158 if ( !strcmp( argv[i], "rawreadermode" ) ) {
160 Logging( kHLTLogError, "HLT::TPCClusterFinder::DoInit", "Missing rawreadermode", "Raw Reader Mode not specified" );
164 // Decodes the rawreader mode: either number or string and returns the rawreadermode
165 // -1 on failure, -2 for offline
166 rawreadermode = AliHLTTPCDigitReaderRaw::DecodeMode( argv[i+1] );
168 if (rawreadermode == -1 ) {
169 Logging( kHLTLogError, "HLT::TPCClusterFinder::DoInit", "Missing rawreadermode", "Cannot convert rawreadermode specifier '%s'.", argv[i+1] );
178 if ( !strcmp( argv[i], "pp-run" ) ) {
179 fClusterDeconv = false;
184 // -- zero suppression threshold
185 if ( !strcmp( argv[i], "adc-threshold" ) ) {
186 sigthresh = strtoul( argv[i+1], &cpErr ,0);
188 HLTError("Cannot convert threshold specifier '%s'.", argv[i+1]);
195 // -- pad occupancy limit
196 if ( !strcmp( argv[i], "occupancy-limit" ) ) {
197 occulimit = strtof( argv[i+1], &cpErr);
199 HLTError("Cannot convert occupancy specifier '%s'.", argv[i+1]);
206 // -- number of timebins (default 1024)
207 if ( !strcmp( argv[i], "timebins" ) ) {
208 TString parameter(argv[i+1]);
209 parameter.Remove(TString::kLeading, ' '); // remove all blanks
210 if (parameter.IsDigit()) {
211 AliHLTTPCTransform::SetNTimeBins(parameter.Atoi());
212 HLTInfo("number of timebins set to %d", AliHLTTPCTransform::GetNTimeBins());
214 HLTError("Cannot timebin specifier '%s'.", argv[i+1]);
221 // -- checking for rcu format
222 if ( !strcmp( argv[i], "oldrcuformat" ) ) {
223 oldRCUFormat = strtoul( argv[i+1], &cpErr ,0);
225 HLTError("Cannot convert oldrcuformat specifier '%s'. Should be 0(off) or 1(on), must be integer", argv[i+1]);
233 Logging(kHLTLogError, "HLT::TPCClusterFinder::DoInit", "Unknown Option", "Unknown option '%s'", argv[i] );
241 if (rawreadermode == -2) {
242 #if defined(HAVE_ALIRAWDATA) && defined(HAVE_ALITPCRAWSTREAM_H)
243 fReader = new AliHLTTPCDigitReaderPacked();
245 fReader->SetOldRCUFormat(kTRUE);
247 else if(oldRCUFormat!=0){
248 HLTWarning("Wrong oldrcuformat specifier %d; oldrcuformat set to default(kFALSE)",oldRCUFormat);
250 fClusterFinder->SetReader(fReader);
251 #else // ! defined(HAVE_ALIRAWDATA) && defined(HAVE_ALITPCRAWSTREAM_H)
252 HLTFatal("DigitReaderPacked not available - check your build");
254 #endif // defined(HAVE_ALIRAWDATA) && defined(HAVE_ALITPCRAWSTREAM_H)
256 #if defined(HAVE_TPC_MAPPING)
257 fReader = new AliHLTTPCDigitReaderRaw(rawreadermode);
258 fClusterFinder->SetReader(fReader);
259 #else //! defined(HAVE_TPC_MAPPING)
260 HLTFatal("DigitReaderRaw not available - check your build");
262 #endif //defined(HAVE_TPC_MAPPING)
266 fReader = new AliHLTTPCDigitReaderUnpacked();
267 fClusterFinder->SetReader(fReader);
270 // if pp-run use occupancy limit else set to 1. ==> use all
271 if ( !fClusterDeconv )
272 fClusterFinder->SetOccupancyLimit(occulimit);
274 fClusterFinder->SetOccupancyLimit(1.0);
276 // Variables to setup the Clusterfinder
277 // TODO: this sounds strange and has to be verified; is the cluster finder not working when
278 // fClusterDeconv = false ?
279 fClusterDeconv = true;
280 fXYClusterError = -1;
284 fClusterFinder->SetDeconv( fClusterDeconv );
285 fClusterFinder->SetXYError( fXYClusterError );
286 fClusterFinder->SetZError( fZClusterError );
287 if ( (fXYClusterError>0) && (fZClusterError>0) )
288 fClusterFinder->SetCalcErr( false );
289 fClusterFinder->SetSignalThreshold(sigthresh);
294 int AliHLTTPCClusterFinderComponent::DoDeinit()
296 // see header file for class documentation
298 if ( fClusterFinder )
299 delete fClusterFinder;
300 fClusterFinder = NULL;
309 int AliHLTTPCClusterFinderComponent::DoEvent( const AliHLTComponentEventData& evtData,
310 const AliHLTComponentBlockData* blocks,
311 AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr,
312 AliHLTUInt32_t& size,
313 vector<AliHLTComponentBlockData>& outputBlocks )
315 // see header file for class documentation
317 // == init iter (pointer to datablock)
318 const AliHLTComponentBlockData* iter = NULL;
321 // == OUTdatatype pointer
322 AliHLTTPCClusterData* outPtr;
324 AliHLTUInt8_t* outBPtr;
325 UInt_t offset, mysize, nSize, tSize = 0;
328 outPtr = (AliHLTTPCClusterData*)outBPtr;
330 Int_t slice, patch, row[2];
331 unsigned long maxPoints, realPoints = 0;
333 for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
341 char tmp1[14], tmp2[14];
342 DataType2Text( iter->fDataType, tmp1 );
343 DataType2Text( AliHLTTPCDefinitions::fgkDDLPackedRawDataType, tmp2 );
344 Logging( kHLTLogDebug, "HLT::TPCClusterFinder::DoEvent", "Event received",
345 "Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
346 evtData.fEventID, evtData.fEventID, tmp1, tmp2 );
348 if ( iter->fDataType != AliHLTTPCDefinitions::fgkDDLPackedRawDataType ) continue;
352 char tmp1[14], tmp2[14];
353 DataType2Text( iter->fDataType, tmp1 );
354 DataType2Text( AliHLTTPCDefinitions::fgkUnpackedRawDataType, tmp2 );
355 Logging( kHLTLogDebug, "HLT::TPCClusterFinder::DoEvent", "Event received",
356 "Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
357 evtData.fEventID, evtData.fEventID, tmp1, tmp2 );
359 if ( iter->fDataType != AliHLTTPCDefinitions::fgkUnpackedRawDataType ) continue;
363 slice = AliHLTTPCDefinitions::GetMinSliceNr( *iter );
364 patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
365 row[0] = AliHLTTPCTransform::GetFirstRow( patch );
366 row[1] = AliHLTTPCTransform::GetLastRow( patch );
368 Logging( kHLTLogDebug, "HLT::TPCClusterFinder::DoEvent", "Input Spacepoints",
369 "Input: Number of spacepoints: %lu Slice/Patch/RowMin/RowMax: %d/%d/%d/%d.",
370 realPoints, slice, patch, row[0], row[1] );
372 outPtr = (AliHLTTPCClusterData*)outBPtr;
374 maxPoints = (size-tSize-sizeof(AliHLTTPCClusterData))/sizeof(AliHLTTPCSpacePointData);
376 fClusterFinder->InitSlice( slice, patch, row[0], row[1], maxPoints );
377 fClusterFinder->SetOutputArray( outPtr->fSpacePoints );
378 fClusterFinder->Read(iter->fPtr, iter->fSize );
379 fClusterFinder->ProcessDigits();
380 realPoints = fClusterFinder->GetNumberOfClusters();
382 Logging( kHLTLogDebug, "HLT::TPCClusterFinder::DoEvent", "Spacepoints",
383 "Number of spacepoints found: %lu.", realPoints );
385 outPtr->fSpacePointCnt = realPoints;
386 nSize = sizeof(AliHLTTPCSpacePointData)*realPoints;
387 mysize += nSize+sizeof(AliHLTTPCClusterData);
389 Logging( kHLTLogDebug, "HLT::TPCClusterFinder::DoEvent", "Input Spacepoints",
390 "Number of spacepoints: %lu Slice/Patch/RowMin/RowMax: %d/%d/%d/%d.",
391 realPoints, slice, patch, row[0], row[1] );
392 AliHLTComponentBlockData bd;
396 bd.fSpecification = iter->fSpecification;
397 //AliHLTSubEventDescriptor::FillBlockAttributes( bd.fAttributes );
398 outputBlocks.push_back( bd );
402 outPtr = (AliHLTTPCClusterData*)outBPtr;
406 Logging( kHLTLogFatal, "HLT::TPCClusterFinder::DoEvent", "Too much data",
407 "Data written over allowed buffer. Amount written: %lu, allowed amount: %lu.",