]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/TPCLib/AliHLTTPCClusterFinderComponent.cxx
bugfix: invalid index due to conditional statement
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCClusterFinderComponent.cxx
CommitLineData
71d7c760 1// $Id$
2
3/**************************************************************************
9be2600f 4 * This file is property of and copyright by the ALICE HLT Project *
5 * ALICE Experiment at CERN, All rights reserved. *
71d7c760 6 * *
9be2600f 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. *
71d7c760 11 * *
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 **************************************************************************/
20
96bda103 21/** @file AliHLTTPCClusterFinderComponent.cxx
27f5f8ed 22 @author Timm Steinbeck, Matthias Richter, Jochen Thaeder, Kenneth Aamodt
de554e07 23 @date
24 @brief The TPC cluster finder processing component
25*/
a38a7850 26
db16520a 27#if __GNUC__>= 3
71d7c760 28using namespace std;
29#endif
db16520a 30#include "AliHLTTPCLogging.h"
71d7c760 31#include "AliHLTTPCClusterFinderComponent.h"
a38a7850 32#include "AliHLTTPCDigitReaderPacked.h"
33#include "AliHLTTPCDigitReaderUnpacked.h"
db16520a 34#include "AliHLTTPCDigitReaderRaw.h"
a38a7850 35#include "AliHLTTPCClusterFinder.h"
a6c02c85 36#include "AliHLTTPCSpacePointData.h"
71d7c760 37#include "AliHLTTPCClusterDataFormat.h"
a6c02c85 38#include "AliHLTTPCTransform.h"
01f43166 39#include "AliHLTTPCClusters.h"
71d7c760 40#include <stdlib.h>
41#include <errno.h>
ecefc48a 42#include "TString.h"
01f43166 43#include "TStopwatch.h"
44#include <sys/time.h>
71d7c760 45
46// this is a global object used for automatic component registration, do not use this
2a083ac4 47// use fPackedSwitch = true for packed inputtype "gkDDLPackedRawDataType"
48// use fPackedSwitch = false for unpacked inputtype "gkUnpackedRawDataType"
a38a7850 49AliHLTTPCClusterFinderComponent gAliHLTTPCClusterFinderComponentPacked(true);
50AliHLTTPCClusterFinderComponent gAliHLTTPCClusterFinderComponentUnpacked(false);
71d7c760 51
52ClassImp(AliHLTTPCClusterFinderComponent)
53
a38a7850 54AliHLTTPCClusterFinderComponent::AliHLTTPCClusterFinderComponent(bool packed)
74c73e5a 55 :
74c73e5a 56 fClusterFinder(NULL),
57 fReader(NULL),
58 fClusterDeconv(true),
59 fXYClusterError(-1),
2a083ac4 60 fZClusterError(-1),
01f43166 61 fPackedSwitch(packed),
62 fPatch(0),
63 fUnsorted(0),
64 fPadArray(NULL)
74c73e5a 65{
2a083ac4 66 // see header file for class documentation
67 // or
68 // refer to README to build package
69 // or
70 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
74c73e5a 71}
72
73AliHLTTPCClusterFinderComponent::AliHLTTPCClusterFinderComponent(const AliHLTTPCClusterFinderComponent&)
74 :
74c73e5a 75 fClusterFinder(NULL),
76 fReader(NULL),
77 fClusterDeconv(true),
78 fXYClusterError(-1),
2a083ac4 79 fZClusterError(-1),
01f43166 80 fPackedSwitch(0),
81 fPatch(0),
82 fUnsorted(0),
83 fPadArray(NULL)
74c73e5a 84{
2a083ac4 85 // see header file for class documentation
74c73e5a 86 HLTFatal("copy constructor untested");
87}
88
89AliHLTTPCClusterFinderComponent& AliHLTTPCClusterFinderComponent::operator=(const AliHLTTPCClusterFinderComponent&)
90{
2a083ac4 91 // see header file for class documentation
74c73e5a 92 HLTFatal("assignment operator untested");
93 return *this;
94}
71d7c760 95
96AliHLTTPCClusterFinderComponent::~AliHLTTPCClusterFinderComponent()
7e99beb3 97{
2a083ac4 98 // see header file for class documentation
7e99beb3 99}
71d7c760 100
101// Public functions to implement AliHLTComponent's interface.
102// These functions are required for the registration process
103
104const char* AliHLTTPCClusterFinderComponent::GetComponentID()
7e99beb3 105{
2a083ac4 106 // see header file for class documentation
7e99beb3 107 if (fPackedSwitch) return "TPCClusterFinderPacked";
108 else return "TPCClusterFinderUnpacked";
109}
71d7c760 110
8ede8717 111void AliHLTTPCClusterFinderComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
7e99beb3 112{
2a083ac4 113 // see header file for class documentation
7e99beb3 114 list.clear();
115 if (fPackedSwitch) list.push_back( AliHLTTPCDefinitions::fgkDDLPackedRawDataType );
116 else list.push_back( AliHLTTPCDefinitions::fgkUnpackedRawDataType );
a38a7850 117
7e99beb3 118}
71d7c760 119
8ede8717 120AliHLTComponentDataType AliHLTTPCClusterFinderComponent::GetOutputDataType()
7e99beb3 121{
2a083ac4 122 // see header file for class documentation
7e99beb3 123 return AliHLTTPCDefinitions::fgkClustersDataType;
124}
71d7c760 125
126void AliHLTTPCClusterFinderComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
7e99beb3 127{
2a083ac4 128 // see header file for class documentation
7e99beb3 129 // XXX TODO: Find more realistic values.
130 constBase = 0;
131 if (fPackedSwitch) inputMultiplier = (6 * 0.4);
132 else inputMultiplier = 0.4;
133}
71d7c760 134
135AliHLTComponent* AliHLTTPCClusterFinderComponent::Spawn()
7e99beb3 136{
2a083ac4 137 // see header file for class documentation
7e99beb3 138 return new AliHLTTPCClusterFinderComponent(fPackedSwitch);
139}
71d7c760 140
141int AliHLTTPCClusterFinderComponent::DoInit( int argc, const char** argv )
7e99beb3 142{
2a083ac4 143 // see header file for class documentation
7e99beb3 144 if ( fClusterFinder )
145 return EINPROGRESS;
146
147 fClusterFinder = new AliHLTTPCClusterFinder();
148
149 Int_t rawreadermode = -1;
150 Int_t sigthresh = -1;
151 Float_t occulimit = 1.0;
152 Int_t oldRCUFormat=0;
153 // Data Format version numbers:
154 // 0: RCU Data format as delivered during TPC commissioning, pads/padrows are sorted, RCU trailer is one 32 bit word.
155 // 1: As 0, but pads/padrows are delivered "as is", without sorting
156 // 2: As 0, but RCU trailer is 3 32 bit words.
157 // 3: As 1, but RCU trailer is 3 32 bit words.
158 // -1: use offline raw reader
159
160 Int_t i = 0;
161 Char_t* cpErr;
162
163 while ( i < argc ) {
164
165 // -- raw reader mode option
166 if ( !strcmp( argv[i], "rawreadermode" ) ) {
167 if ( argc <= i+1 ) {
168 Logging( kHLTLogError, "HLT::TPCClusterFinder::DoInit", "Missing rawreadermode", "Raw Reader Mode not specified" );
169 return ENOTSUP;
170 }
f3f599e0 171
7e99beb3 172 // Decodes the rawreader mode: either number or string and returns the rawreadermode
173 // -1 on failure, -2 for offline
174 rawreadermode = AliHLTTPCDigitReaderRaw::DecodeMode( argv[i+1] );
f3f599e0 175
7e99beb3 176 if (rawreadermode == -1 ) {
177 Logging( kHLTLogError, "HLT::TPCClusterFinder::DoInit", "Missing rawreadermode", "Cannot convert rawreadermode specifier '%s'.", argv[i+1] );
178 return EINVAL;
db16520a 179 }
180
7e99beb3 181 i += 2;
182 continue;
183 }
db16520a 184
7e99beb3 185 // -- pp run option
186 if ( !strcmp( argv[i], "pp-run" ) ) {
187 fClusterDeconv = false;
188 i++;
189 continue;
190 }
191
192 // -- zero suppression threshold
193 if ( !strcmp( argv[i], "adc-threshold" ) ) {
194 sigthresh = strtoul( argv[i+1], &cpErr ,0);
195 if ( *cpErr ) {
196 HLTError("Cannot convert threshold specifier '%s'.", argv[i+1]);
197 return EINVAL;
84645eb0 198 }
7e99beb3 199 i+=2;
200 continue;
201 }
84645eb0 202
7e99beb3 203 // -- pad occupancy limit
204 if ( !strcmp( argv[i], "occupancy-limit" ) ) {
d0173e83 205 occulimit = strtod( argv[i+1], &cpErr);
7e99beb3 206 if ( *cpErr ) {
207 HLTError("Cannot convert occupancy specifier '%s'.", argv[i+1]);
208 return EINVAL;
5235c3e9 209 }
7e99beb3 210 i+=2;
211 continue;
212 }
5235c3e9 213
7e99beb3 214 // -- number of timebins (default 1024)
215 if ( !strcmp( argv[i], "timebins" ) ) {
216 TString parameter(argv[i+1]);
217 parameter.Remove(TString::kLeading, ' '); // remove all blanks
218 if (parameter.IsDigit()) {
219 AliHLTTPCTransform::SetNTimeBins(parameter.Atoi());
220 HLTInfo("number of timebins set to %d", AliHLTTPCTransform::GetNTimeBins());
221 } else {
222 HLTError("Cannot timebin specifier '%s'.", argv[i+1]);
223 return EINVAL;
ecefc48a 224 }
7e99beb3 225 i+=2;
226 continue;
227 }
ecefc48a 228
7e99beb3 229 // -- checking for rcu format
230 if ( !strcmp( argv[i], "oldrcuformat" ) ) {
231 oldRCUFormat = strtoul( argv[i+1], &cpErr ,0);
232 if ( *cpErr ){
233 HLTError("Cannot convert oldrcuformat specifier '%s'. Should be 0(off) or 1(on), must be integer", argv[i+1]);
234 return EINVAL;
27f5f8ed 235 }
7e99beb3 236 i+=2;
237 continue;
238 }
27f5f8ed 239
01f43166 240 // -- checking for unsorted clusterfinding
241 if ( !strcmp( argv[i], "unsorted" ) ) {
242 fUnsorted = strtoul( argv[i+1], &cpErr ,0);
243 if ( *cpErr ){
244 HLTError("Cannot convert unsorted specifier '%s'. Should be 0(off) or 1(on), must be integer", argv[i+1]);
245 return EINVAL;
246 }
247 i+=2;
248 continue;
249 }
250
251 // -- checking for unsorted clusterfinding
252 if ( !strcmp( argv[i], "patch" ) ) {
253 fPatch = strtoul( argv[i+1], &cpErr ,0);
254 if ( *cpErr ){
255 HLTError("Cannot convert patch specifier '%s'. Should be between 0 and 5, must be integer", argv[i+1]);
256 return EINVAL;
257 }
258 i+=2;
259 continue;
260 }
261
7e99beb3 262 Logging(kHLTLogError, "HLT::TPCClusterFinder::DoInit", "Unknown Option", "Unknown option '%s'", argv[i] );
263 return EINVAL;
27f5f8ed 264
7e99beb3 265 }
db16520a 266
7e99beb3 267 // Choose reader
db16520a 268
7e99beb3 269 if (fPackedSwitch) {
270 if (rawreadermode == -2) {
74c73e5a 271#if defined(HAVE_ALIRAWDATA) && defined(HAVE_ALITPCRAWSTREAM_H)
7e99beb3 272 fReader = new AliHLTTPCDigitReaderPacked();
273 if(oldRCUFormat==1){
274 fReader->SetOldRCUFormat(kTRUE);
275 }
276 else if(oldRCUFormat!=0){
277 HLTWarning("Wrong oldrcuformat specifier %d; oldrcuformat set to default(kFALSE)",oldRCUFormat);
278 }
01f43166 279 if(fUnsorted){
280 fReader->SetUnsorted(kTRUE);
281 }
7e99beb3 282 fClusterFinder->SetReader(fReader);
74c73e5a 283#else // ! defined(HAVE_ALIRAWDATA) && defined(HAVE_ALITPCRAWSTREAM_H)
7e99beb3 284 HLTFatal("DigitReaderPacked not available - check your build");
285 return -ENODEV;
74c73e5a 286#endif // defined(HAVE_ALIRAWDATA) && defined(HAVE_ALITPCRAWSTREAM_H)
7e99beb3 287 } else {
db16520a 288#if defined(HAVE_TPC_MAPPING)
7e99beb3 289 fReader = new AliHLTTPCDigitReaderRaw(rawreadermode);
290 fClusterFinder->SetReader(fReader);
db16520a 291#else //! defined(HAVE_TPC_MAPPING)
292 HLTFatal("DigitReaderRaw not available - check your build");
293 return -ENODEV;
294#endif //defined(HAVE_TPC_MAPPING)
a38a7850 295 }
7e99beb3 296 }
297 else {
298 fReader = new AliHLTTPCDigitReaderUnpacked();
299 fClusterFinder->SetReader(fReader);
300 }
301
302 // if pp-run use occupancy limit else set to 1. ==> use all
303 if ( !fClusterDeconv )
304 fClusterFinder->SetOccupancyLimit(occulimit);
305 else
306 fClusterFinder->SetOccupancyLimit(1.0);
db16520a 307
7e99beb3 308 // Variables to setup the Clusterfinder
309 // TODO: this sounds strange and has to be verified; is the cluster finder not working when
310 // fClusterDeconv = false ?
311 fClusterDeconv = true;
312 fXYClusterError = -1;
313 fZClusterError = -1;
a38a7850 314
db16520a 315
7e99beb3 316 fClusterFinder->SetDeconv( fClusterDeconv );
317 fClusterFinder->SetXYError( fXYClusterError );
318 fClusterFinder->SetZError( fZClusterError );
319 if ( (fXYClusterError>0) && (fZClusterError>0) )
320 fClusterFinder->SetCalcErr( false );
321 fClusterFinder->SetSignalThreshold(sigthresh);
a38a7850 322
01f43166 323 if(fUnsorted&&fPatch>-1&&fPatch<6){
324 fPadArray = new AliHLTTPCPadArray(fPatch);
325 fPadArray->InitializeVector();
326 }
327
7e99beb3 328 return 0;
329}
71d7c760 330
331int AliHLTTPCClusterFinderComponent::DoDeinit()
7e99beb3 332{
2a083ac4 333 // see header file for class documentation
a38a7850 334
7e99beb3 335 if ( fClusterFinder )
336 delete fClusterFinder;
337 fClusterFinder = NULL;
a38a7850 338
7e99beb3 339 if ( fReader )
340 delete fReader;
341 fReader = NULL;
a38a7850 342
7e99beb3 343 return 0;
344}
71d7c760 345
8ede8717 346int AliHLTTPCClusterFinderComponent::DoEvent( const AliHLTComponentEventData& evtData,
347 const AliHLTComponentBlockData* blocks,
348 AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr,
a38a7850 349 AliHLTUInt32_t& size,
8ede8717 350 vector<AliHLTComponentBlockData>& outputBlocks )
7e99beb3 351{
2a083ac4 352 // see header file for class documentation
db16520a 353
7e99beb3 354 // == init iter (pointer to datablock)
355 const AliHLTComponentBlockData* iter = NULL;
356 unsigned long ndx;
a38a7850 357
7e99beb3 358 // == OUTdatatype pointer
359 AliHLTTPCClusterData* outPtr;
a38a7850 360
7e99beb3 361 AliHLTUInt8_t* outBPtr;
362 UInt_t offset, mysize, nSize, tSize = 0;
a38a7850 363
7e99beb3 364 outBPtr = outputPtr;
365 outPtr = (AliHLTTPCClusterData*)outBPtr;
a38a7850 366
7e99beb3 367 Int_t slice, patch, row[2];
368 unsigned long maxPoints, realPoints = 0;
a38a7850 369
7e99beb3 370 for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
371 {
372 iter = blocks+ndx;
373 mysize = 0;
374 offset = tSize;
a38a7850 375
376
7e99beb3 377 if (fPackedSwitch) {
378 char tmp1[14], tmp2[14];
379 DataType2Text( iter->fDataType, tmp1 );
380 DataType2Text( AliHLTTPCDefinitions::fgkDDLPackedRawDataType, tmp2 );
381 Logging( kHLTLogDebug, "HLT::TPCClusterFinder::DoEvent", "Event received",
382 "Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
383 evtData.fEventID, evtData.fEventID, tmp1, tmp2 );
a38a7850 384
7e99beb3 385 if ( iter->fDataType != AliHLTTPCDefinitions::fgkDDLPackedRawDataType ) continue;
a38a7850 386
7e99beb3 387 }
388 else {
389 char tmp1[14], tmp2[14];
390 DataType2Text( iter->fDataType, tmp1 );
391 DataType2Text( AliHLTTPCDefinitions::fgkUnpackedRawDataType, tmp2 );
392 Logging( kHLTLogDebug, "HLT::TPCClusterFinder::DoEvent", "Event received",
393 "Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
394 evtData.fEventID, evtData.fEventID, tmp1, tmp2 );
a38a7850 395
7e99beb3 396 if ( iter->fDataType != AliHLTTPCDefinitions::fgkUnpackedRawDataType ) continue;
a38a7850 397
7e99beb3 398 }
a38a7850 399
7e99beb3 400 slice = AliHLTTPCDefinitions::GetMinSliceNr( *iter );
401 patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
402 row[0] = AliHLTTPCTransform::GetFirstRow( patch );
403 row[1] = AliHLTTPCTransform::GetLastRow( patch );
71d7c760 404
7e99beb3 405 Logging( kHLTLogDebug, "HLT::TPCClusterFinder::DoEvent", "Input Spacepoints",
406 "Input: Number of spacepoints: %lu Slice/Patch/RowMin/RowMax: %d/%d/%d/%d.",
407 realPoints, slice, patch, row[0], row[1] );
71d7c760 408
7e99beb3 409 outPtr = (AliHLTTPCClusterData*)outBPtr;
a38a7850 410
01f43166 411#ifndef KENNETH
7e99beb3 412 maxPoints = (size-tSize-sizeof(AliHLTTPCClusterData))/sizeof(AliHLTTPCSpacePointData);
01f43166 413#else
414 maxPoints = (size-tSize-sizeof(AliHLTTPCClusters))/sizeof(AliHLTTPCSpacePointData);
415#endif
db16520a 416
7e99beb3 417 fClusterFinder->InitSlice( slice, patch, row[0], row[1], maxPoints );
e83e889b 418 fClusterFinder->SetOutputArray( (AliHLTTPCSpacePointData*)outPtr->fSpacePoints );
01f43166 419
420 if(fUnsorted){
421
422
423 fClusterFinder->SetPadArray(fPadArray);
424
425 double totalT=0;
426 struct timeval startT, endT;
427 gettimeofday( &startT, NULL );
428
429 fClusterFinder->ReadDataUnsorted(iter->fPtr, iter->fSize );
430
431 gettimeofday( &endT, NULL );
432 unsigned long long dt;
433 dt = endT.tv_sec-startT.tv_sec;
434 dt *= 1000000ULL;
435 dt += endT.tv_usec-startT.tv_usec;
436 double dtd = ((double)dt);
437 totalT += dtd;
438 // dtd = dtd / (double)eventIterations;
439 // if ( iterations<=1 )
440 cout<<endl;
441 printf( "Time needed to read data: %f microsec. / %f millisec. / %f s\n",
442 dtd, dtd/1000.0, dtd/1000000.0 );
443
444 cout<<endl;
445 fClusterFinder->FindClusters();
446 }
447 else{
448 fClusterFinder->Read(iter->fPtr, iter->fSize );
449 fClusterFinder->ProcessDigits();
450 }
7e99beb3 451 realPoints = fClusterFinder->GetNumberOfClusters();
71d7c760 452
7e99beb3 453 Logging( kHLTLogDebug, "HLT::TPCClusterFinder::DoEvent", "Spacepoints",
454 "Number of spacepoints found: %lu.", realPoints );
71d7c760 455
7e99beb3 456 outPtr->fSpacePointCnt = realPoints;
457 nSize = sizeof(AliHLTTPCSpacePointData)*realPoints;
01f43166 458#ifndef KENNETH
7e99beb3 459 mysize += nSize+sizeof(AliHLTTPCClusterData);
01f43166 460#else
461 mysize += nSize+sizeof(AliHLTTPCClusters);
462#endif
71d7c760 463
7e99beb3 464 Logging( kHLTLogDebug, "HLT::TPCClusterFinder::DoEvent", "Input Spacepoints",
465 "Number of spacepoints: %lu Slice/Patch/RowMin/RowMax: %d/%d/%d/%d.",
466 realPoints, slice, patch, row[0], row[1] );
467 AliHLTComponentBlockData bd;
468 FillBlockData( bd );
469 bd.fOffset = offset;
470 bd.fSize = mysize;
471 bd.fSpecification = iter->fSpecification;
472 //AliHLTSubEventDescriptor::FillBlockAttributes( bd.fAttributes );
473 outputBlocks.push_back( bd );
71d7c760 474
7e99beb3 475 tSize += mysize;
476 outBPtr += mysize;
477 outPtr = (AliHLTTPCClusterData*)outBPtr;
71d7c760 478
7e99beb3 479 if ( tSize > size )
480 {
481 Logging( kHLTLogFatal, "HLT::TPCClusterFinder::DoEvent", "Too much data",
482 "Data written over allowed buffer. Amount written: %lu, allowed amount: %lu.",
483 tSize, size );
484 return EMSGSIZE;
71d7c760 485 }
71d7c760 486 }
7e99beb3 487
488 size = tSize;
71d7c760 489
7e99beb3 490 return 0;
491}