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 ///////////////////////////////////////////////////////////////////////////////
22 // a TPC cluster finder processing component for the HLT //
23 // useable for packed data or unpacked data //
25 ///////////////////////////////////////////////////////////////////////////////
31 #include "AliHLTTPCLogging.h"
32 #include "AliHLTTPCClusterFinderComponent.h"
33 #include "AliHLTTPCDigitReaderPacked.h"
34 #include "AliHLTTPCDigitReaderUnpacked.h"
35 #include "AliHLTTPCDigitReaderRaw.h"
36 #include "AliHLTTPCClusterFinder.h"
37 #include "AliHLTTPCSpacePointData.h"
38 #include "AliHLTTPCRawDataFormat.h"
39 #include "AliHLTTPCClusterDataFormat.h"
40 #include "AliHLTTPCTransform.h"
44 // this is a global object used for automatic component registration, do not use this
45 AliHLTTPCClusterFinderComponent gAliHLTTPCClusterFinderComponentPacked(true);
46 AliHLTTPCClusterFinderComponent gAliHLTTPCClusterFinderComponentUnpacked(false);
48 ClassImp(AliHLTTPCClusterFinderComponent)
50 AliHLTTPCClusterFinderComponent::AliHLTTPCClusterFinderComponent(bool packed)
52 // use fPackedSwitch = true for packed inputtype "gkDDLPackedRawDataType"
53 // use fPackedSwitch = false for unpacked inputtype "gkUnpackedRawDataType"
54 fPackedSwitch(packed),
64 AliHLTTPCClusterFinderComponent::AliHLTTPCClusterFinderComponent(const AliHLTTPCClusterFinderComponent&)
73 HLTFatal("copy constructor untested");
76 AliHLTTPCClusterFinderComponent& AliHLTTPCClusterFinderComponent::operator=(const AliHLTTPCClusterFinderComponent&)
78 HLTFatal("assignment operator untested");
82 AliHLTTPCClusterFinderComponent::~AliHLTTPCClusterFinderComponent()
86 // Public functions to implement AliHLTComponent's interface.
87 // These functions are required for the registration process
89 const char* AliHLTTPCClusterFinderComponent::GetComponentID()
91 if (fPackedSwitch) return "TPCClusterFinderPacked";
92 else return "TPCClusterFinderUnpacked";
95 void AliHLTTPCClusterFinderComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
98 if (fPackedSwitch) list.push_back( AliHLTTPCDefinitions::gkDDLPackedRawDataType );
99 else list.push_back( AliHLTTPCDefinitions::gkUnpackedRawDataType );
103 AliHLTComponentDataType AliHLTTPCClusterFinderComponent::GetOutputDataType()
105 return AliHLTTPCDefinitions::gkClustersDataType;
108 void AliHLTTPCClusterFinderComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
110 // XXX TODO: Find more realistic values.
112 if (fPackedSwitch) inputMultiplier = (6 * 0.4);
113 else inputMultiplier = 0.4;
116 AliHLTComponent* AliHLTTPCClusterFinderComponent::Spawn()
118 return new AliHLTTPCClusterFinderComponent(fPackedSwitch);
121 int AliHLTTPCClusterFinderComponent::DoInit( int argc, const char** argv )
123 if ( fClusterFinder )
126 fClusterFinder = new AliHLTTPCClusterFinder();
128 Int_t rawreadermode = -1;
129 Int_t sigthresh = -1;
130 Float_t occulimit = 1.0;
132 // Data Format version numbers:
133 // 0: RCU Data format as delivered during TPC commissioning, pads/padrows are sorted, RCU trailer is one 32 bit word.
134 // 1: As 0, but pads/padrows are delivered "as is", without sorting
135 // 2: As 0, but RCU trailer is 3 32 bit words.
136 // 3: As 1, but RCU trailer is 3 32 bit words.
137 // -1: use offline raw reader
144 // -- raw reader mode option
145 if ( !strcmp( argv[i], "rawreadermode" ) ) {
147 Logging( kHLTLogError, "HLT::TPCClusterFinder::DoInit", "Missing rawreadermode", "Raw Reader Mode not specified" );
151 // Decodes the rawreader mode: either number or string and returns the rawreadermode
152 // -1 on failure, -2 for offline
153 rawreadermode = AliHLTTPCDigitReaderRaw::DecodeMode( argv[i+1] );
155 if (rawreadermode == -1 ) {
156 Logging( kHLTLogError, "HLT::TPCClusterFinder::DoInit", "Missing rawreadermode", "Cannot convert rawreadermode specifier '%s'.", argv[i+1] );
165 if ( !strcmp( argv[i], "pp-run" ) ) {
166 fClusterDeconv = false;
171 // -- zero suppression threshold
172 if ( !strcmp( argv[i], "adc-threshold" ) ) {
173 sigthresh = strtoul( argv[i+1], &cpErr ,0);
175 HLTError("Cannot convert threshold specifier '%s'.", argv[i+1]);
182 // -- pad occupancy limit
183 if ( !strcmp( argv[i], "occupancy-limit" ) ) {
184 occulimit = strtof( argv[i+1], &cpErr);
186 HLTError("Cannot convert occupancy specifier '%s'.", argv[i+1]);
193 Logging(kHLTLogError, "HLT::TPCClusterFinder::DoInit", "Unknown Option", "Unknown option '%s'", argv[i] );
201 if (rawreadermode == -2) {
202 #if defined(HAVE_ALIRAWDATA) && defined(HAVE_ALITPCRAWSTREAM_H)
203 fReader = new AliHLTTPCDigitReaderPacked();
204 fClusterFinder->SetReader(fReader);
205 #else // ! defined(HAVE_ALIRAWDATA) && defined(HAVE_ALITPCRAWSTREAM_H)
206 HLTFatal("DigitReaderPacked not available - check your build");
208 #endif // defined(HAVE_ALIRAWDATA) && defined(HAVE_ALITPCRAWSTREAM_H)
210 #if defined(HAVE_TPC_MAPPING)
211 fReader = new AliHLTTPCDigitReaderRaw(rawreadermode);
212 fClusterFinder->SetReader(fReader);
213 #else //! defined(HAVE_TPC_MAPPING)
214 HLTFatal("DigitReaderRaw not available - check your build");
216 #endif //defined(HAVE_TPC_MAPPING)
220 fReader = new AliHLTTPCDigitReaderUnpacked();
221 fClusterFinder->SetReader(fReader);
224 // if pp-run use occupancy limit else set to 1. ==> use all
225 if ( !fClusterDeconv )
226 fClusterFinder->SetOccupancyLimit(occulimit);
228 fClusterFinder->SetOccupancyLimit(1.0);
230 // Variables to setup the Clusterfinder
231 // TODO: this sounds strange and has to be verified; is the cluster finder not working when
232 // fClusterDeconv = false ?
233 fClusterDeconv = true;
234 fXYClusterError = -1;
238 fClusterFinder->SetDeconv( fClusterDeconv );
239 fClusterFinder->SetXYError( fXYClusterError );
240 fClusterFinder->SetZError( fZClusterError );
241 if ( (fXYClusterError>0) && (fZClusterError>0) )
242 fClusterFinder->SetCalcErr( false );
243 fClusterFinder->SetSignalThreshold(sigthresh);
248 int AliHLTTPCClusterFinderComponent::DoDeinit()
251 if ( fClusterFinder )
252 delete fClusterFinder;
253 fClusterFinder = NULL;
262 int AliHLTTPCClusterFinderComponent::DoEvent( const AliHLTComponentEventData& evtData,
263 const AliHLTComponentBlockData* blocks,
264 AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr,
265 AliHLTUInt32_t& size,
266 vector<AliHLTComponentBlockData>& outputBlocks )
269 // == init iter (pointer to datablock)
270 const AliHLTComponentBlockData* iter = NULL;
273 // == OUTdatatype pointer
274 AliHLTTPCClusterData* outPtr;
276 AliHLTUInt8_t* outBPtr;
277 UInt_t offset, mysize, nSize, tSize = 0;
280 outPtr = (AliHLTTPCClusterData*)outBPtr;
282 Int_t slice, patch, row[2];
283 unsigned long maxPoints, realPoints = 0;
285 for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
293 char tmp1[14], tmp2[14];
294 DataType2Text( iter->fDataType, tmp1 );
295 DataType2Text( AliHLTTPCDefinitions::gkDDLPackedRawDataType, tmp2 );
296 Logging( kHLTLogDebug, "HLT::TPCClusterFinder::DoEvent", "Event received",
297 "Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
298 evtData.fEventID, evtData.fEventID, tmp1, tmp2 );
300 if ( iter->fDataType != AliHLTTPCDefinitions::gkDDLPackedRawDataType ) continue;
304 char tmp1[14], tmp2[14];
305 DataType2Text( iter->fDataType, tmp1 );
306 DataType2Text( AliHLTTPCDefinitions::gkUnpackedRawDataType, tmp2 );
307 Logging( kHLTLogDebug, "HLT::TPCClusterFinder::DoEvent", "Event received",
308 "Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
309 evtData.fEventID, evtData.fEventID, tmp1, tmp2 );
311 if ( iter->fDataType != AliHLTTPCDefinitions::gkUnpackedRawDataType ) continue;
315 slice = AliHLTTPCDefinitions::GetMinSliceNr( *iter );
316 patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
317 row[0] = AliHLTTPCTransform::GetFirstRow( patch );
318 row[1] = AliHLTTPCTransform::GetLastRow( patch );
320 Logging( kHLTLogDebug, "HLT::TPCClusterFinder::DoEvent", "Input Spacepoints",
321 "Input: Number of spacepoints: %lu Slice/Patch/RowMin/RowMax: %d/%d/%d/%d.",
322 realPoints, slice, patch, row[0], row[1] );
324 outPtr = (AliHLTTPCClusterData*)outBPtr;
326 maxPoints = (size-tSize-sizeof(AliHLTTPCClusterData))/sizeof(AliHLTTPCSpacePointData);
328 fClusterFinder->InitSlice( slice, patch, row[0], row[1], maxPoints );
329 fClusterFinder->SetOutputArray( outPtr->fSpacePoints );
330 fClusterFinder->Read(iter->fPtr, iter->fSize );
331 fClusterFinder->ProcessDigits();
332 realPoints = fClusterFinder->GetNumberOfClusters();
334 Logging( kHLTLogDebug, "HLT::TPCClusterFinder::DoEvent", "Spacepoints",
335 "Number of spacepoints found: %lu.", realPoints );
337 outPtr->fSpacePointCnt = realPoints;
338 nSize = sizeof(AliHLTTPCSpacePointData)*realPoints;
339 mysize += nSize+sizeof(AliHLTTPCClusterData);
341 Logging( kHLTLogDebug, "HLT::TPCClusterFinder::DoEvent", "Input Spacepoints",
342 "Number of spacepoints: %lu Slice/Patch/RowMin/RowMax: %d/%d/%d/%d.",
343 realPoints, slice, patch, row[0], row[1] );
344 AliHLTComponentBlockData bd;
348 bd.fSpecification = iter->fSpecification;
349 //AliHLTSubEventDescriptor::FillBlockAttributes( bd.fAttributes );
350 outputBlocks.push_back( bd );
354 outPtr = (AliHLTTPCClusterData*)outBPtr;
358 Logging( kHLTLogFatal, "HLT::TPCClusterFinder::DoEvent", "Too much data",
359 "Data written over allowed buffer. Amount written: %lu, allowed amount: %lu.",