]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/TPCLib/AliHLTTPCClusterFinderComponent.cxx
- code version from TPC commissioning merged
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCClusterFinderComponent.cxx
CommitLineData
71d7c760 1// $Id$
2
3/**************************************************************************
4 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
5 * *
6 * Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
7 * Timm Steinbeck <timm@kip.uni-heidelberg.de> *
a38a7850 8 * Jochen Thaeder <thaeder@kip.uni-heidelberg.de> *
71d7c760 9 * for The ALICE Off-line Project. *
10 * *
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 **************************************************************************/
19
20///////////////////////////////////////////////////////////////////////////////
21// //
22// a TPC cluster finder processing component for the HLT //
a38a7850 23// useable for packed data or unpacked data //
71d7c760 24// //
25///////////////////////////////////////////////////////////////////////////////
26
a38a7850 27
db16520a 28#if __GNUC__>= 3
71d7c760 29using namespace std;
30#endif
db16520a 31#include "AliHLTTPCLogging.h"
71d7c760 32#include "AliHLTTPCClusterFinderComponent.h"
a38a7850 33#include "AliHLTTPCDigitReaderPacked.h"
34#include "AliHLTTPCDigitReaderUnpacked.h"
db16520a 35#include "AliHLTTPCDigitReaderRaw.h"
a38a7850 36#include "AliHLTTPCClusterFinder.h"
a6c02c85 37#include "AliHLTTPCSpacePointData.h"
71d7c760 38#include "AliHLTTPCRawDataFormat.h"
39#include "AliHLTTPCClusterDataFormat.h"
a6c02c85 40#include "AliHLTTPCTransform.h"
71d7c760 41#include <stdlib.h>
42#include <errno.h>
43
44// this is a global object used for automatic component registration, do not use this
a38a7850 45AliHLTTPCClusterFinderComponent gAliHLTTPCClusterFinderComponentPacked(true);
46AliHLTTPCClusterFinderComponent gAliHLTTPCClusterFinderComponentUnpacked(false);
71d7c760 47
48ClassImp(AliHLTTPCClusterFinderComponent)
49
a38a7850 50AliHLTTPCClusterFinderComponent::AliHLTTPCClusterFinderComponent(bool packed)
74c73e5a 51 :
52 // use fPackedSwitch = true for packed inputtype "gkDDLPackedRawDataType"
53 // use fPackedSwitch = false for unpacked inputtype "gkUnpackedRawDataType"
54 fPackedSwitch(packed),
55
56 fClusterFinder(NULL),
57 fReader(NULL),
58 fClusterDeconv(true),
59 fXYClusterError(-1),
60 fZClusterError(-1)
61{
62}
63
64AliHLTTPCClusterFinderComponent::AliHLTTPCClusterFinderComponent(const AliHLTTPCClusterFinderComponent&)
65 :
66 fPackedSwitch(0),
67 fClusterFinder(NULL),
68 fReader(NULL),
69 fClusterDeconv(true),
70 fXYClusterError(-1),
71 fZClusterError(-1)
72{
73 HLTFatal("copy constructor untested");
74}
75
76AliHLTTPCClusterFinderComponent& AliHLTTPCClusterFinderComponent::operator=(const AliHLTTPCClusterFinderComponent&)
77{
78 HLTFatal("assignment operator untested");
79 return *this;
80}
71d7c760 81
82AliHLTTPCClusterFinderComponent::~AliHLTTPCClusterFinderComponent()
83 {
84 }
85
86// Public functions to implement AliHLTComponent's interface.
87// These functions are required for the registration process
88
89const char* AliHLTTPCClusterFinderComponent::GetComponentID()
90 {
a38a7850 91 if (fPackedSwitch) return "TPCClusterFinderPacked";
92 else return "TPCClusterFinderUnpacked";
71d7c760 93 }
94
95void AliHLTTPCClusterFinderComponent::GetInputDataTypes( vector<AliHLTComponent_DataType>& list)
96 {
a38a7850 97 list.clear();
98 if (fPackedSwitch) list.push_back( AliHLTTPCDefinitions::gkDDLPackedRawDataType );
99 else list.push_back( AliHLTTPCDefinitions::gkUnpackedRawDataType );
100
71d7c760 101 }
102
103AliHLTComponent_DataType AliHLTTPCClusterFinderComponent::GetOutputDataType()
104 {
105 return AliHLTTPCDefinitions::gkClustersDataType;
106 }
107
108void AliHLTTPCClusterFinderComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
109 {
a38a7850 110 // XXX TODO: Find more realistic values.
71d7c760 111 constBase = 0;
a38a7850 112 if (fPackedSwitch) inputMultiplier = (6 * 0.4);
113 else inputMultiplier = 0.4;
71d7c760 114 }
115
116AliHLTComponent* AliHLTTPCClusterFinderComponent::Spawn()
117 {
a38a7850 118 return new AliHLTTPCClusterFinderComponent(fPackedSwitch);
71d7c760 119 }
120
121int AliHLTTPCClusterFinderComponent::DoInit( int argc, const char** argv )
122 {
123 if ( fClusterFinder )
124 return EINPROGRESS;
a38a7850 125
126 fClusterFinder = new AliHLTTPCClusterFinder();
127
db16520a 128 Int_t rawreadermode = -1;
129
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
136
137 Int_t i = 0;
138 Char_t* cpErr;
139
140 while ( i < argc ) {
141
142 // -- raw reader mode option
143 if ( !strcmp( argv[i], "rawreadermode" ) ) {
144 if ( argc <= i+1 ) {
145 Logging( kHLTLogError, "HLT::TPCClusterFinder::DoInit", "Missing rawreadermode", "Raw Reader Mode not specified" );
146 return ENOTSUP;
147 }
148
149 if ( !strcmp( argv[i+1], "sorted_1_trailerword" ) ) {
150 rawreadermode = 0;
151 }
152 else if ( !strcmp( argv[i+1], "sorted_3_trailerword" ) ) {
153 rawreadermode = 2;
154 }
155 else if ( !strcmp( argv[i+1], "unsorted_1_trailerword" ) ) {
156 rawreadermode = 1;
157 }
158 else if ( !strcmp( argv[i+1], "unsorted_3_trailerword" ) ) {
159 rawreadermode = 3;
160 }
161 else if ( !strcmp( argv[i+1], "offline" ) ) {
162 rawreadermode = -1;
163 }
164 else {
165 rawreadermode = strtoul( argv[i+1], &cpErr ,0);
166 if ( *cpErr ) {
167 Logging( kHLTLogError, "HLT::TPCClusterFinder::DoInit", "Missing rawreadermode", "Cannot convert rawreadermode specifier '%s'.", argv[i+1] );
168 return EINVAL;
169 }
170 }
171
172 i += 2;
173 continue;
174 }
175
176 // -- pp run option
177 if ( !strcmp( argv[i], "pp-run" ) ) {
178 fClusterDeconv = false;
179 i++;
180 continue;
181 }
182
183 Logging(kHLTLogError, "HLT::TPCClusterFinder::DoInit", "Unknown Option", "Unknown option '%s'", argv[i] );
184 return EINVAL;
185
186 }
187
188 // Choose reader
189
190 if (fPackedSwitch) {
191 if (rawreadermode == -1) {
74c73e5a 192#if defined(HAVE_ALIRAWDATA) && defined(HAVE_ALITPCRAWSTREAM_H)
db16520a 193 fReader = new AliHLTTPCDigitReaderPacked();
194 fClusterFinder->SetReader(fReader);
74c73e5a 195#else // ! defined(HAVE_ALIRAWDATA) && defined(HAVE_ALITPCRAWSTREAM_H)
db16520a 196 HLTFatal("DigitReaderPacked not available - check your build");
197 return -ENODEV;
74c73e5a 198#endif // defined(HAVE_ALIRAWDATA) && defined(HAVE_ALITPCRAWSTREAM_H)
db16520a 199 } else {
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");
205 return -ENODEV;
206#endif //defined(HAVE_TPC_MAPPING)
207 }
a38a7850 208 }
209 else {
74c73e5a 210 fReader = new AliHLTTPCDigitReaderUnpacked();
211 fClusterFinder->SetReader(fReader);
a38a7850 212 }
db16520a 213
a38a7850 214 // Variables to setup the Clusterfinder
71d7c760 215 fClusterDeconv = true;
216 fXYClusterError = -1;
217 fZClusterError = -1;
a38a7850 218
db16520a 219
a38a7850 220 fClusterFinder->SetDeconv( fClusterDeconv );
221 fClusterFinder->SetXYError( fXYClusterError );
222 fClusterFinder->SetZError( fZClusterError );
223 if ( (fXYClusterError>0) && (fZClusterError>0) )
224 fClusterFinder->SetCalcErr( false );
225
71d7c760 226 return 0;
227 }
228
229int AliHLTTPCClusterFinderComponent::DoDeinit()
230 {
a38a7850 231
71d7c760 232 if ( fClusterFinder )
233 delete fClusterFinder;
234 fClusterFinder = NULL;
a38a7850 235
74c73e5a 236 if ( fReader )
237 delete fReader;
238 fReader = NULL;
a38a7850 239
71d7c760 240 return 0;
241 }
242
a38a7850 243int AliHLTTPCClusterFinderComponent::DoEvent( const AliHLTComponent_EventData& evtData,
244 const AliHLTComponent_BlockData* blocks,
71d7c760 245 AliHLTComponent_TriggerData& trigData, AliHLTUInt8_t* outputPtr,
a38a7850 246 AliHLTUInt32_t& size,
247 vector<AliHLTComponent_BlockData>& outputBlocks )
71d7c760 248 {
db16520a 249
a38a7850 250 // == init iter (pointer to datablock)
71d7c760 251 const AliHLTComponent_BlockData* iter = NULL;
252 unsigned long ndx;
a38a7850 253
254 // == OUTdatatype pointer
71d7c760 255 AliHLTTPCClusterData* outPtr;
a38a7850 256
71d7c760 257 AliHLTUInt8_t* outBPtr;
258 UInt_t offset, mysize, nSize, tSize = 0;
a38a7850 259
71d7c760 260 outBPtr = outputPtr;
261 outPtr = (AliHLTTPCClusterData*)outBPtr;
a38a7850 262
71d7c760 263 Int_t slice, patch, row[2];
264 unsigned long maxPoints, realPoints = 0;
a38a7850 265
71d7c760 266 for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
267 {
268 iter = blocks+ndx;
269 mysize = 0;
270 offset = tSize;
a38a7850 271
272
273 if (fPackedSwitch) {
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 );
280
281 if ( iter->fDataType != AliHLTTPCDefinitions::gkDDLPackedRawDataType ) continue;
282
283 }
284 else {
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 );
291
292 if ( iter->fDataType != AliHLTTPCDefinitions::gkUnpackedRawDataType ) continue;
293
294 }
295
71d7c760 296 slice = AliHLTTPCDefinitions::GetMinSliceNr( *iter );
297 patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
a6c02c85 298 row[0] = AliHLTTPCTransform::GetFirstRow( patch );
299 row[1] = AliHLTTPCTransform::GetLastRow( patch );
71d7c760 300
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] );
304
305 outPtr = (AliHLTTPCClusterData*)outBPtr;
a38a7850 306
a6c02c85 307 maxPoints = (size-tSize-sizeof(AliHLTTPCClusterData))/sizeof(AliHLTTPCSpacePointData);
db16520a 308
71d7c760 309 fClusterFinder->InitSlice( slice, patch, row[0], row[1], maxPoints );
71d7c760 310 fClusterFinder->SetOutputArray( outPtr->fSpacePoints );
a38a7850 311 fClusterFinder->Read(iter->fPtr, iter->fSize );
71d7c760 312 fClusterFinder->ProcessDigits();
313 realPoints = fClusterFinder->GetNumberOfClusters();
314
315 Logging( kHLTLogDebug, "HLT::TPCClusterFinder::DoEvent", "Spacepoints",
316 "Number of spacepoints found: %lu.", realPoints );
317
318 outPtr->fSpacePointCnt = realPoints;
a6c02c85 319 nSize = sizeof(AliHLTTPCSpacePointData)*realPoints;
71d7c760 320 mysize += nSize+sizeof(AliHLTTPCClusterData);
321
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] );
71d7c760 325 AliHLTComponent_BlockData bd;
326 FillBlockData( bd );
327 bd.fOffset = offset;
328 bd.fSize = mysize;
329 bd.fSpecification = iter->fSpecification;
330 //AliHLTSubEventDescriptor::FillBlockAttributes( bd.fAttributes );
331 outputBlocks.push_back( bd );
332
333 tSize += mysize;
334 outBPtr += mysize;
335 outPtr = (AliHLTTPCClusterData*)outBPtr;
336
337 if ( tSize > size )
338 {
339 Logging( kHLTLogFatal, "HLT::TPCClusterFinder::DoEvent", "Too much data",
340 "Data written over allowed buffer. Amount written: %lu, allowed amount: %lu.",
341 tSize, size );
342 return EMSGSIZE;
343 }
344 }
345
346 size = tSize;
db16520a 347
71d7c760 348 return 0;
349 }
350
a38a7850 351