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<AliHLTComponent_DataType>& list)
98 if (fPackedSwitch) list.push_back( AliHLTTPCDefinitions::gkDDLPackedRawDataType );
99 else list.push_back( AliHLTTPCDefinitions::gkUnpackedRawDataType );
103 AliHLTComponent_DataType 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;
130 // Data Format version numbers:
131 // 0: RCU Data format as delivered during TPC commissioning, pads/padrows are sorted, RCU trailer is one 32 bit word.
132 // 1: As 0, but pads/padrows are delivered "as is", without sorting
133 // 2: As 0, but RCU trailer is 3 32 bit words.
134 // 3: As 1, but RCU trailer is 3 32 bit words.
135 // -1: use offline raw reader
142 // -- raw reader mode option
143 if ( !strcmp( argv[i], "rawreadermode" ) ) {
145 Logging( kHLTLogError, "HLT::TPCClusterFinder::DoInit", "Missing rawreadermode", "Raw Reader Mode not specified" );
149 if ( !strcmp( argv[i+1], "sorted_1_trailerword" ) ) {
152 else if ( !strcmp( argv[i+1], "sorted_3_trailerword" ) ) {
155 else if ( !strcmp( argv[i+1], "unsorted_1_trailerword" ) ) {
158 else if ( !strcmp( argv[i+1], "unsorted_3_trailerword" ) ) {
161 else if ( !strcmp( argv[i+1], "offline" ) ) {
165 rawreadermode = strtoul( argv[i+1], &cpErr ,0);
167 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 Logging(kHLTLogError, "HLT::TPCClusterFinder::DoInit", "Unknown Option", "Unknown option '%s'", argv[i] );
191 if (rawreadermode == -1) {
192 #if defined(HAVE_ALIRAWDATA) && defined(HAVE_ALITPCRAWSTREAM_H)
193 fReader = new AliHLTTPCDigitReaderPacked();
194 fClusterFinder->SetReader(fReader);
195 #else // ! defined(HAVE_ALIRAWDATA) && defined(HAVE_ALITPCRAWSTREAM_H)
196 HLTFatal("DigitReaderPacked not available - check your build");
198 #endif // defined(HAVE_ALIRAWDATA) && defined(HAVE_ALITPCRAWSTREAM_H)
200 #if defined(HAVE_TPC_MAPPING)
201 fReader = new AliHLTTPCDigitReaderRaw(rawreadermode);
202 fClusterFinder->SetReader(fReader);
203 #else //! defined(HAVE_TPC_MAPPING)
204 HLTFatal("DigitReaderRaw not available - check your build");
206 #endif //defined(HAVE_TPC_MAPPING)
210 fReader = new AliHLTTPCDigitReaderUnpacked();
211 fClusterFinder->SetReader(fReader);
214 // Variables to setup the Clusterfinder
215 fClusterDeconv = true;
216 fXYClusterError = -1;
220 fClusterFinder->SetDeconv( fClusterDeconv );
221 fClusterFinder->SetXYError( fXYClusterError );
222 fClusterFinder->SetZError( fZClusterError );
223 if ( (fXYClusterError>0) && (fZClusterError>0) )
224 fClusterFinder->SetCalcErr( false );
229 int AliHLTTPCClusterFinderComponent::DoDeinit()
232 if ( fClusterFinder )
233 delete fClusterFinder;
234 fClusterFinder = NULL;
243 int AliHLTTPCClusterFinderComponent::DoEvent( const AliHLTComponent_EventData& evtData,
244 const AliHLTComponent_BlockData* blocks,
245 AliHLTComponent_TriggerData& trigData, AliHLTUInt8_t* outputPtr,
246 AliHLTUInt32_t& size,
247 vector<AliHLTComponent_BlockData>& outputBlocks )
250 // == init iter (pointer to datablock)
251 const AliHLTComponent_BlockData* iter = NULL;
254 // == OUTdatatype pointer
255 AliHLTTPCClusterData* outPtr;
257 AliHLTUInt8_t* outBPtr;
258 UInt_t offset, mysize, nSize, tSize = 0;
261 outPtr = (AliHLTTPCClusterData*)outBPtr;
263 Int_t slice, patch, row[2];
264 unsigned long maxPoints, realPoints = 0;
266 for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
274 char tmp1[14], tmp2[14];
275 DataType2Text( iter->fDataType, tmp1 );
276 DataType2Text( AliHLTTPCDefinitions::gkDDLPackedRawDataType, tmp2 );
277 Logging( kHLTLogDebug, "HLT::TPCClusterFinder::DoEvent", "Event received",
278 "Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
279 evtData.fEventID, evtData.fEventID, tmp1, tmp2 );
281 if ( iter->fDataType != AliHLTTPCDefinitions::gkDDLPackedRawDataType ) continue;
285 char tmp1[14], tmp2[14];
286 DataType2Text( iter->fDataType, tmp1 );
287 DataType2Text( AliHLTTPCDefinitions::gkUnpackedRawDataType, tmp2 );
288 Logging( kHLTLogDebug, "HLT::TPCClusterFinder::DoEvent", "Event received",
289 "Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
290 evtData.fEventID, evtData.fEventID, tmp1, tmp2 );
292 if ( iter->fDataType != AliHLTTPCDefinitions::gkUnpackedRawDataType ) continue;
296 slice = AliHLTTPCDefinitions::GetMinSliceNr( *iter );
297 patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
298 row[0] = AliHLTTPCTransform::GetFirstRow( patch );
299 row[1] = AliHLTTPCTransform::GetLastRow( patch );
301 Logging( kHLTLogDebug, "HLT::TPCClusterFinder::DoEvent", "Input Spacepoints",
302 "Input: Number of spacepoints: %lu Slice/Patch/RowMin/RowMax: %d/%d/%d/%d.",
303 realPoints, slice, patch, row[0], row[1] );
305 outPtr = (AliHLTTPCClusterData*)outBPtr;
307 maxPoints = (size-tSize-sizeof(AliHLTTPCClusterData))/sizeof(AliHLTTPCSpacePointData);
309 fClusterFinder->InitSlice( slice, patch, row[0], row[1], maxPoints );
310 fClusterFinder->SetOutputArray( outPtr->fSpacePoints );
311 fClusterFinder->Read(iter->fPtr, iter->fSize );
312 fClusterFinder->ProcessDigits();
313 realPoints = fClusterFinder->GetNumberOfClusters();
315 Logging( kHLTLogDebug, "HLT::TPCClusterFinder::DoEvent", "Spacepoints",
316 "Number of spacepoints found: %lu.", realPoints );
318 outPtr->fSpacePointCnt = realPoints;
319 nSize = sizeof(AliHLTTPCSpacePointData)*realPoints;
320 mysize += nSize+sizeof(AliHLTTPCClusterData);
322 Logging( kHLTLogDebug, "HLT::TPCClusterFinder::DoEvent", "Input Spacepoints",
323 "Number of spacepoints: %lu Slice/Patch/RowMin/RowMax: %d/%d/%d/%d.",
324 realPoints, slice, patch, row[0], row[1] );
325 AliHLTComponent_BlockData bd;
329 bd.fSpecification = iter->fSpecification;
330 //AliHLTSubEventDescriptor::FillBlockAttributes( bd.fAttributes );
331 outputBlocks.push_back( bd );
335 outPtr = (AliHLTTPCClusterData*)outBPtr;
339 Logging( kHLTLogFatal, "HLT::TPCClusterFinder::DoEvent", "Too much data",
340 "Data written over allowed buffer. Amount written: %lu, allowed amount: %lu.",