3 /**************************************************************************
4 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
6 * Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
7 * Timm Steinbeck <timm@kip.uni-heidelberg.de> *
8 * Jochen Thaeder <thaeder@kip.uni-heidelberg.de> *
9 * for The ALICE Off-line Project. *
11 * Permission to use, copy, modify and distribute this software and its *
12 * documentation strictly for non-commercial purposes is hereby granted *
13 * without fee, provided that the above copyright notice appears in all *
14 * copies and that both the copyright notice and this permission notice *
15 * appear in the supporting documentation. The authors make no claims *
16 * about the suitability of this software for any purpose. It is *
17 * provided "as is" without express or implied warranty. *
18 **************************************************************************/
20 /** @file AliHLTTPCClusterFinderComponent.cxx
21 @author Timm Steinbeck, Matthias Richter, Jochen Thaeder
23 @brief The TPC cluster finder processing component
29 #include "AliHLTTPCLogging.h"
30 #include "AliHLTTPCClusterFinderComponent.h"
31 #include "AliHLTTPCDigitReaderPacked.h"
32 #include "AliHLTTPCDigitReaderUnpacked.h"
33 #include "AliHLTTPCDigitReaderRaw.h"
34 #include "AliHLTTPCClusterFinder.h"
35 #include "AliHLTTPCSpacePointData.h"
36 #include "AliHLTTPCRawDataFormat.h"
37 #include "AliHLTTPCClusterDataFormat.h"
38 #include "AliHLTTPCTransform.h"
43 // this is a global object used for automatic component registration, do not use this
44 // use fPackedSwitch = true for packed inputtype "gkDDLPackedRawDataType"
45 // use fPackedSwitch = false for unpacked inputtype "gkUnpackedRawDataType"
46 AliHLTTPCClusterFinderComponent gAliHLTTPCClusterFinderComponentPacked(true);
47 AliHLTTPCClusterFinderComponent gAliHLTTPCClusterFinderComponentUnpacked(false);
49 ClassImp(AliHLTTPCClusterFinderComponent)
51 AliHLTTPCClusterFinderComponent::AliHLTTPCClusterFinderComponent(bool packed)
60 // see header file for class documentation
62 // refer to README to build package
64 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
67 AliHLTTPCClusterFinderComponent::AliHLTTPCClusterFinderComponent(const AliHLTTPCClusterFinderComponent&)
76 // see header file for class documentation
77 HLTFatal("copy constructor untested");
80 AliHLTTPCClusterFinderComponent& AliHLTTPCClusterFinderComponent::operator=(const AliHLTTPCClusterFinderComponent&)
82 // see header file for class documentation
83 HLTFatal("assignment operator untested");
87 AliHLTTPCClusterFinderComponent::~AliHLTTPCClusterFinderComponent()
89 // see header file for class documentation
92 // Public functions to implement AliHLTComponent's interface.
93 // These functions are required for the registration process
95 const char* AliHLTTPCClusterFinderComponent::GetComponentID()
97 // see header file for class documentation
98 if (fPackedSwitch) return "TPCClusterFinderPacked";
99 else return "TPCClusterFinderUnpacked";
102 void AliHLTTPCClusterFinderComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
104 // see header file for class documentation
106 if (fPackedSwitch) list.push_back( AliHLTTPCDefinitions::fgkDDLPackedRawDataType );
107 else list.push_back( AliHLTTPCDefinitions::fgkUnpackedRawDataType );
111 AliHLTComponentDataType AliHLTTPCClusterFinderComponent::GetOutputDataType()
113 // see header file for class documentation
114 return AliHLTTPCDefinitions::fgkClustersDataType;
117 void AliHLTTPCClusterFinderComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
119 // see header file for class documentation
120 // XXX TODO: Find more realistic values.
122 if (fPackedSwitch) inputMultiplier = (6 * 0.4);
123 else inputMultiplier = 0.4;
126 AliHLTComponent* AliHLTTPCClusterFinderComponent::Spawn()
128 // see header file for class documentation
129 return new AliHLTTPCClusterFinderComponent(fPackedSwitch);
132 int AliHLTTPCClusterFinderComponent::DoInit( int argc, const char** argv )
134 // see header file for class documentation
135 if ( fClusterFinder )
138 fClusterFinder = new AliHLTTPCClusterFinder();
140 Int_t rawreadermode = -1;
141 Int_t sigthresh = -1;
142 Float_t occulimit = 1.0;
144 // Data Format version numbers:
145 // 0: RCU Data format as delivered during TPC commissioning, pads/padrows are sorted, RCU trailer is one 32 bit word.
146 // 1: As 0, but pads/padrows are delivered "as is", without sorting
147 // 2: As 0, but RCU trailer is 3 32 bit words.
148 // 3: As 1, but RCU trailer is 3 32 bit words.
149 // -1: use offline raw reader
156 // -- raw reader mode option
157 if ( !strcmp( argv[i], "rawreadermode" ) ) {
159 Logging( kHLTLogError, "HLT::TPCClusterFinder::DoInit", "Missing rawreadermode", "Raw Reader Mode not specified" );
163 // Decodes the rawreader mode: either number or string and returns the rawreadermode
164 // -1 on failure, -2 for offline
165 rawreadermode = AliHLTTPCDigitReaderRaw::DecodeMode( argv[i+1] );
167 if (rawreadermode == -1 ) {
168 Logging( kHLTLogError, "HLT::TPCClusterFinder::DoInit", "Missing rawreadermode", "Cannot convert rawreadermode specifier '%s'.", argv[i+1] );
177 if ( !strcmp( argv[i], "pp-run" ) ) {
178 fClusterDeconv = false;
183 // -- zero suppression threshold
184 if ( !strcmp( argv[i], "adc-threshold" ) ) {
185 sigthresh = strtoul( argv[i+1], &cpErr ,0);
187 HLTError("Cannot convert threshold specifier '%s'.", argv[i+1]);
194 // -- pad occupancy limit
195 if ( !strcmp( argv[i], "occupancy-limit" ) ) {
196 occulimit = strtof( argv[i+1], &cpErr);
198 HLTError("Cannot convert occupancy specifier '%s'.", argv[i+1]);
205 // -- number of timebins (default 1024)
206 if ( !strcmp( argv[i], "timebins" ) ) {
207 TString parameter(argv[i+1]);
208 parameter.Remove(TString::kLeading, ' '); // remove all blanks
209 if (parameter.IsDigit()) {
210 AliHLTTPCTransform::SetNTimeBins(parameter.Atoi());
211 HLTInfo("number of timebins set to %d", AliHLTTPCTransform::GetNTimeBins());
213 HLTError("Cannot timebin specifier '%s'.", argv[i+1]);
220 Logging(kHLTLogError, "HLT::TPCClusterFinder::DoInit", "Unknown Option", "Unknown option '%s'", argv[i] );
228 if (rawreadermode == -2) {
229 #if defined(HAVE_ALIRAWDATA) && defined(HAVE_ALITPCRAWSTREAM_H)
230 fReader = new AliHLTTPCDigitReaderPacked();
231 fClusterFinder->SetReader(fReader);
232 #else // ! defined(HAVE_ALIRAWDATA) && defined(HAVE_ALITPCRAWSTREAM_H)
233 HLTFatal("DigitReaderPacked not available - check your build");
235 #endif // defined(HAVE_ALIRAWDATA) && defined(HAVE_ALITPCRAWSTREAM_H)
237 #if defined(HAVE_TPC_MAPPING)
238 fReader = new AliHLTTPCDigitReaderRaw(rawreadermode);
239 fClusterFinder->SetReader(fReader);
240 #else //! defined(HAVE_TPC_MAPPING)
241 HLTFatal("DigitReaderRaw not available - check your build");
243 #endif //defined(HAVE_TPC_MAPPING)
247 fReader = new AliHLTTPCDigitReaderUnpacked();
248 fClusterFinder->SetReader(fReader);
251 // if pp-run use occupancy limit else set to 1. ==> use all
252 if ( !fClusterDeconv )
253 fClusterFinder->SetOccupancyLimit(occulimit);
255 fClusterFinder->SetOccupancyLimit(1.0);
257 // Variables to setup the Clusterfinder
258 // TODO: this sounds strange and has to be verified; is the cluster finder not working when
259 // fClusterDeconv = false ?
260 fClusterDeconv = true;
261 fXYClusterError = -1;
265 fClusterFinder->SetDeconv( fClusterDeconv );
266 fClusterFinder->SetXYError( fXYClusterError );
267 fClusterFinder->SetZError( fZClusterError );
268 if ( (fXYClusterError>0) && (fZClusterError>0) )
269 fClusterFinder->SetCalcErr( false );
270 fClusterFinder->SetSignalThreshold(sigthresh);
275 int AliHLTTPCClusterFinderComponent::DoDeinit()
277 // see header file for class documentation
279 if ( fClusterFinder )
280 delete fClusterFinder;
281 fClusterFinder = NULL;
290 int AliHLTTPCClusterFinderComponent::DoEvent( const AliHLTComponentEventData& evtData,
291 const AliHLTComponentBlockData* blocks,
292 AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr,
293 AliHLTUInt32_t& size,
294 vector<AliHLTComponentBlockData>& outputBlocks )
296 // see header file for class documentation
298 // == init iter (pointer to datablock)
299 const AliHLTComponentBlockData* iter = NULL;
302 // == OUTdatatype pointer
303 AliHLTTPCClusterData* outPtr;
305 AliHLTUInt8_t* outBPtr;
306 UInt_t offset, mysize, nSize, tSize = 0;
309 outPtr = (AliHLTTPCClusterData*)outBPtr;
311 Int_t slice, patch, row[2];
312 unsigned long maxPoints, realPoints = 0;
314 for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
322 char tmp1[14], tmp2[14];
323 DataType2Text( iter->fDataType, tmp1 );
324 DataType2Text( AliHLTTPCDefinitions::fgkDDLPackedRawDataType, tmp2 );
325 Logging( kHLTLogDebug, "HLT::TPCClusterFinder::DoEvent", "Event received",
326 "Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
327 evtData.fEventID, evtData.fEventID, tmp1, tmp2 );
329 if ( iter->fDataType != AliHLTTPCDefinitions::fgkDDLPackedRawDataType ) continue;
333 char tmp1[14], tmp2[14];
334 DataType2Text( iter->fDataType, tmp1 );
335 DataType2Text( AliHLTTPCDefinitions::fgkUnpackedRawDataType, tmp2 );
336 Logging( kHLTLogDebug, "HLT::TPCClusterFinder::DoEvent", "Event received",
337 "Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
338 evtData.fEventID, evtData.fEventID, tmp1, tmp2 );
340 if ( iter->fDataType != AliHLTTPCDefinitions::fgkUnpackedRawDataType ) continue;
344 slice = AliHLTTPCDefinitions::GetMinSliceNr( *iter );
345 patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
346 row[0] = AliHLTTPCTransform::GetFirstRow( patch );
347 row[1] = AliHLTTPCTransform::GetLastRow( patch );
349 Logging( kHLTLogDebug, "HLT::TPCClusterFinder::DoEvent", "Input Spacepoints",
350 "Input: Number of spacepoints: %lu Slice/Patch/RowMin/RowMax: %d/%d/%d/%d.",
351 realPoints, slice, patch, row[0], row[1] );
353 outPtr = (AliHLTTPCClusterData*)outBPtr;
355 maxPoints = (size-tSize-sizeof(AliHLTTPCClusterData))/sizeof(AliHLTTPCSpacePointData);
357 fClusterFinder->InitSlice( slice, patch, row[0], row[1], maxPoints );
358 fClusterFinder->SetOutputArray( outPtr->fSpacePoints );
359 fClusterFinder->Read(iter->fPtr, iter->fSize );
360 fClusterFinder->ProcessDigits();
361 realPoints = fClusterFinder->GetNumberOfClusters();
363 Logging( kHLTLogDebug, "HLT::TPCClusterFinder::DoEvent", "Spacepoints",
364 "Number of spacepoints found: %lu.", realPoints );
366 outPtr->fSpacePointCnt = realPoints;
367 nSize = sizeof(AliHLTTPCSpacePointData)*realPoints;
368 mysize += nSize+sizeof(AliHLTTPCClusterData);
370 Logging( kHLTLogDebug, "HLT::TPCClusterFinder::DoEvent", "Input Spacepoints",
371 "Number of spacepoints: %lu Slice/Patch/RowMin/RowMax: %d/%d/%d/%d.",
372 realPoints, slice, patch, row[0], row[1] );
373 AliHLTComponentBlockData bd;
377 bd.fSpecification = iter->fSpecification;
378 //AliHLTSubEventDescriptor::FillBlockAttributes( bd.fAttributes );
379 outputBlocks.push_back( bd );
383 outPtr = (AliHLTTPCClusterData*)outBPtr;
387 Logging( kHLTLogFatal, "HLT::TPCClusterFinder::DoEvent", "Too much data",
388 "Data written over allowed buffer. Amount written: %lu, allowed amount: %lu.",