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