]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/TPCLib/AliHLTTPCClusterFinderComponent.cxx
Typo corrected.
[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"
8252a538 40#include "AliHLTTPCDigitReaderDecoder.h"
a38a7850 41#include "AliHLTTPCClusterFinder.h"
a6c02c85 42#include "AliHLTTPCSpacePointData.h"
71d7c760 43#include "AliHLTTPCClusterDataFormat.h"
a6c02c85 44#include "AliHLTTPCTransform.h"
01f43166 45#include "AliHLTTPCClusters.h"
e67b0680 46#include "AliHLTTPCDefinitions.h"
c3cda394 47#include "AliCDBEntry.h"
48#include "AliCDBManager.h"
49
e67b0680 50#include <cstdlib>
51#include <cerrno>
ecefc48a 52#include "TString.h"
c3cda394 53#include "TObjString.h"
01f43166 54#include <sys/time.h>
71d7c760 55
c3cda394 56/** ROOT macro for the implementation of ROOT specific class methods */
71d7c760 57ClassImp(AliHLTTPCClusterFinderComponent)
58
8252a538 59AliHLTTPCClusterFinderComponent::AliHLTTPCClusterFinderComponent(int mode)
74c73e5a 60 :
74c73e5a 61 fClusterFinder(NULL),
62 fReader(NULL),
63 fClusterDeconv(true),
64 fXYClusterError(-1),
2a083ac4 65 fZClusterError(-1),
8252a538 66 fModeSwitch(mode),
01f43166 67 fUnsorted(0),
a1dbf058 68 fPatch(0),
b1c46961 69 fGetActivePads(0)
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
8252a538 89 switch(fModeSwitch){
2efb85be 90 case kClusterFinderPacked:
8252a538 91 return "TPCClusterFinderPacked";
92 break;
2efb85be 93 case kClusterFinderUnpacked:
8252a538 94 return "TPCClusterFinderUnpacked";
95 break;
2efb85be 96 case kClusterFinderDecoder:
8252a538 97 return "TPCClusterFinderDecoder";
98 break;
99 }
b0914d2e 100 HLTFatal("unknown digit reader type");
101 return "";
7e99beb3 102}
71d7c760 103
8ede8717 104void AliHLTTPCClusterFinderComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
7e99beb3 105{
2a083ac4 106 // see header file for class documentation
7e99beb3 107 list.clear();
8252a538 108 switch(fModeSwitch){
2efb85be 109 case kClusterFinderPacked:
8252a538 110 list.push_back( kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTPC );
111 break;
2efb85be 112 case kClusterFinderUnpacked:
8252a538 113 list.push_back( AliHLTTPCDefinitions::fgkUnpackedRawDataType );
114 break;
2efb85be 115 case kClusterFinderDecoder:
8252a538 116 list.push_back( kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTPC );
117 break;
118 }
7e99beb3 119}
71d7c760 120
8ede8717 121AliHLTComponentDataType AliHLTTPCClusterFinderComponent::GetOutputDataType()
7e99beb3 122{
2a083ac4 123 // see header file for class documentation
64defa03 124 return kAliHLTMultipleDataType;
125}
126
127int AliHLTTPCClusterFinderComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList)
128
129{
130 // see header file for class documentation
131 tgtList.clear();
132 tgtList.push_back(AliHLTTPCDefinitions::fgkClustersDataType);
64defa03 133 return tgtList.size();
7e99beb3 134}
71d7c760 135
136void AliHLTTPCClusterFinderComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
7e99beb3 137{
2a083ac4 138 // see header file for class documentation
7e99beb3 139 // XXX TODO: Find more realistic values.
140 constBase = 0;
8252a538 141 switch(fModeSwitch){
142 case 0:
143 inputMultiplier = (6 * 0.4);
144 break;
145 case 1:
146 inputMultiplier = 0.4;
147 break;
148 case 2:
149 inputMultiplier = (6 * 0.4);
150 break;
151 }
7e99beb3 152}
71d7c760 153
154AliHLTComponent* AliHLTTPCClusterFinderComponent::Spawn()
7e99beb3 155{
2a083ac4 156 // see header file for class documentation
8252a538 157 return new AliHLTTPCClusterFinderComponent(fModeSwitch);
7e99beb3 158}
71d7c760 159
160int AliHLTTPCClusterFinderComponent::DoInit( int argc, const char** argv )
7e99beb3 161{
2a083ac4 162 // see header file for class documentation
7e99beb3 163 if ( fClusterFinder )
164 return EINPROGRESS;
165
166 fClusterFinder = new AliHLTTPCClusterFinder();
167
168 Int_t rawreadermode = -1;
169 Int_t sigthresh = -1;
b1c46961 170 Double_t sigmathresh= -1;
7e99beb3 171 Float_t occulimit = 1.0;
172 Int_t oldRCUFormat=0;
173 // Data Format version numbers:
174 // 0: RCU Data format as delivered during TPC commissioning, pads/padrows are sorted, RCU trailer is one 32 bit word.
175 // 1: As 0, but pads/padrows are delivered "as is", without sorting
176 // 2: As 0, but RCU trailer is 3 32 bit words.
177 // 3: As 1, but RCU trailer is 3 32 bit words.
178 // -1: use offline raw reader
179
180 Int_t i = 0;
181 Char_t* cpErr;
182
183 while ( i < argc ) {
184
185 // -- raw reader mode option
186 if ( !strcmp( argv[i], "rawreadermode" ) ) {
187 if ( argc <= i+1 ) {
188 Logging( kHLTLogError, "HLT::TPCClusterFinder::DoInit", "Missing rawreadermode", "Raw Reader Mode not specified" );
189 return ENOTSUP;
190 }
f3f599e0 191
7e99beb3 192 // Decodes the rawreader mode: either number or string and returns the rawreadermode
193 // -1 on failure, -2 for offline
194 rawreadermode = AliHLTTPCDigitReaderRaw::DecodeMode( argv[i+1] );
f3f599e0 195
7e99beb3 196 if (rawreadermode == -1 ) {
197 Logging( kHLTLogError, "HLT::TPCClusterFinder::DoInit", "Missing rawreadermode", "Cannot convert rawreadermode specifier '%s'.", argv[i+1] );
198 return EINVAL;
db16520a 199 }
200
7e99beb3 201 i += 2;
202 continue;
203 }
db16520a 204
7e99beb3 205 // -- pp run option
206 if ( !strcmp( argv[i], "pp-run" ) ) {
207 fClusterDeconv = false;
208 i++;
209 continue;
210 }
211
212 // -- zero suppression threshold
213 if ( !strcmp( argv[i], "adc-threshold" ) ) {
214 sigthresh = strtoul( argv[i+1], &cpErr ,0);
215 if ( *cpErr ) {
216 HLTError("Cannot convert threshold specifier '%s'.", argv[i+1]);
217 return EINVAL;
84645eb0 218 }
7e99beb3 219 i+=2;
220 continue;
221 }
84645eb0 222
7e99beb3 223 // -- pad occupancy limit
224 if ( !strcmp( argv[i], "occupancy-limit" ) ) {
d0173e83 225 occulimit = strtod( argv[i+1], &cpErr);
7e99beb3 226 if ( *cpErr ) {
227 HLTError("Cannot convert occupancy specifier '%s'.", argv[i+1]);
228 return EINVAL;
5235c3e9 229 }
7e99beb3 230 i+=2;
231 continue;
232 }
5235c3e9 233
7e99beb3 234 // -- number of timebins (default 1024)
235 if ( !strcmp( argv[i], "timebins" ) ) {
236 TString parameter(argv[i+1]);
237 parameter.Remove(TString::kLeading, ' '); // remove all blanks
238 if (parameter.IsDigit()) {
239 AliHLTTPCTransform::SetNTimeBins(parameter.Atoi());
74511e22 240 HLTInfo("number of timebins set to %d, zbin=%f", AliHLTTPCTransform::GetNTimeBins(), AliHLTTPCTransform::GetZWidth());
7e99beb3 241 } else {
242 HLTError("Cannot timebin specifier '%s'.", argv[i+1]);
243 return EINVAL;
ecefc48a 244 }
7e99beb3 245 i+=2;
246 continue;
247 }
ecefc48a 248
7e99beb3 249 // -- checking for rcu format
250 if ( !strcmp( argv[i], "oldrcuformat" ) ) {
251 oldRCUFormat = strtoul( argv[i+1], &cpErr ,0);
252 if ( *cpErr ){
253 HLTError("Cannot convert oldrcuformat specifier '%s'. Should be 0(off) or 1(on), must be integer", argv[i+1]);
254 return EINVAL;
27f5f8ed 255 }
7e99beb3 256 i+=2;
257 continue;
258 }
27f5f8ed 259
01f43166 260 // -- checking for unsorted clusterfinding
261 if ( !strcmp( argv[i], "unsorted" ) ) {
262 fUnsorted = strtoul( argv[i+1], &cpErr ,0);
263 if ( *cpErr ){
264 HLTError("Cannot convert unsorted specifier '%s'. Should be 0(off) or 1(on), must be integer", argv[i+1]);
265 return EINVAL;
266 }
267 i+=2;
268 continue;
269 }
270
b1c46961 271 // -- checking for active pads, used in 2007 December run
272 if ( !strcmp( argv[i], "activepads" ) ) {
273 fGetActivePads = strtoul( argv[i+1], &cpErr ,0);
274 if ( *cpErr ){
275 HLTError("Cannot convert activepads specifier '%s'. Should be 0(off) or 1(on), must be integer", argv[i+1]);
276 return EINVAL;
277 }
278 i+=2;
279 continue;
280 }
281
282 // -- checking for nsigma-threshold, used in 2007 December run in ZeroSuppression
283 if ( !strcmp( argv[i], "nsigma-threshold" ) ) {
284 sigmathresh = strtoul( argv[i+1], &cpErr ,0);
285 if ( *cpErr ){
286 HLTError("Cannot convert nsigma-threshold specifier '%s'. Must be integer", argv[i+1]);
287 return EINVAL;
288 }
289 i+=2;
290 continue;
291 }
292
7e99beb3 293 Logging(kHLTLogError, "HLT::TPCClusterFinder::DoInit", "Unknown Option", "Unknown option '%s'", argv[i] );
294 return EINVAL;
27f5f8ed 295
7e99beb3 296 }
db16520a 297
7e99beb3 298 // Choose reader
2efb85be 299 if (fModeSwitch==kClusterFinderPacked) {
7e99beb3 300 if (rawreadermode == -2) {
f44e97dc 301 HLTDebug("using AliHLTTPCDigitReaderPacked");
7e99beb3 302 fReader = new AliHLTTPCDigitReaderPacked();
303 if(oldRCUFormat==1){
304 fReader->SetOldRCUFormat(kTRUE);
305 }
306 else if(oldRCUFormat!=0){
307 HLTWarning("Wrong oldrcuformat specifier %d; oldrcuformat set to default(kFALSE)",oldRCUFormat);
308 }
aff6e981 309 if(fUnsorted==1){
01f43166 310 fReader->SetUnsorted(kTRUE);
311 }
7e99beb3 312 fClusterFinder->SetReader(fReader);
8252a538 313 }
314 else {
db16520a 315#if defined(HAVE_TPC_MAPPING)
f44e97dc 316 HLTDebug("using AliHLTTPCDigitReaderRaw mode %d", rawreadermode);
7e99beb3 317 fReader = new AliHLTTPCDigitReaderRaw(rawreadermode);
318 fClusterFinder->SetReader(fReader);
db16520a 319#else //! defined(HAVE_TPC_MAPPING)
320 HLTFatal("DigitReaderRaw not available - check your build");
321 return -ENODEV;
322#endif //defined(HAVE_TPC_MAPPING)
a38a7850 323 }
7e99beb3 324 }
2efb85be 325 else if(fModeSwitch==kClusterFinderUnpacked){
f44e97dc 326 HLTDebug("using AliHLTTPCDigitReaderUnpacked");
7e99beb3 327 fReader = new AliHLTTPCDigitReaderUnpacked();
328 fClusterFinder->SetReader(fReader);
329 }
2efb85be 330 else if(fModeSwitch==kClusterFinderDecoder){
8252a538 331 fReader = new AliHLTTPCDigitReaderDecoder();
332 fClusterFinder->SetReader(fReader);
333 }
334 else{
335 HLTFatal("No mode set for clusterfindercomponent");
336 }
7e99beb3 337 // if pp-run use occupancy limit else set to 1. ==> use all
338 if ( !fClusterDeconv )
339 fClusterFinder->SetOccupancyLimit(occulimit);
340 else
341 fClusterFinder->SetOccupancyLimit(1.0);
db16520a 342
7e99beb3 343 // Variables to setup the Clusterfinder
344 // TODO: this sounds strange and has to be verified; is the cluster finder not working when
345 // fClusterDeconv = false ?
346 fClusterDeconv = true;
347 fXYClusterError = -1;
348 fZClusterError = -1;
a38a7850 349
db16520a 350
7e99beb3 351 fClusterFinder->SetDeconv( fClusterDeconv );
352 fClusterFinder->SetXYError( fXYClusterError );
353 fClusterFinder->SetZError( fZClusterError );
354 if ( (fXYClusterError>0) && (fZClusterError>0) )
355 fClusterFinder->SetCalcErr( false );
356 fClusterFinder->SetSignalThreshold(sigthresh);
b1c46961 357 fClusterFinder->SetNSigmaThreshold(sigmathresh);
01f43166 358
7e99beb3 359 return 0;
360}
71d7c760 361
362int AliHLTTPCClusterFinderComponent::DoDeinit()
7e99beb3 363{
2a083ac4 364 // see header file for class documentation
a38a7850 365
7e99beb3 366 if ( fClusterFinder )
367 delete fClusterFinder;
368 fClusterFinder = NULL;
a38a7850 369
7e99beb3 370 if ( fReader )
371 delete fReader;
372 fReader = NULL;
a38a7850 373
7e99beb3 374 return 0;
375}
71d7c760 376
8ede8717 377int AliHLTTPCClusterFinderComponent::DoEvent( const AliHLTComponentEventData& evtData,
378 const AliHLTComponentBlockData* blocks,
5d2abf3b 379 AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr,
a38a7850 380 AliHLTUInt32_t& size,
8ede8717 381 vector<AliHLTComponentBlockData>& outputBlocks )
7e99beb3 382{
2a083ac4 383 // see header file for class documentation
db16520a 384
7e99beb3 385 // == init iter (pointer to datablock)
386 const AliHLTComponentBlockData* iter = NULL;
387 unsigned long ndx;
a38a7850 388
7e99beb3 389 // == OUTdatatype pointer
390 AliHLTTPCClusterData* outPtr;
a38a7850 391
7e99beb3 392 AliHLTUInt8_t* outBPtr;
393 UInt_t offset, mysize, nSize, tSize = 0;
a38a7850 394
7e99beb3 395 outBPtr = outputPtr;
396 outPtr = (AliHLTTPCClusterData*)outBPtr;
a38a7850 397
7e99beb3 398 Int_t slice, patch, row[2];
399 unsigned long maxPoints, realPoints = 0;
a38a7850 400
7e99beb3 401 for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
402 {
403 iter = blocks+ndx;
404 mysize = 0;
405 offset = tSize;
a38a7850 406
407
8252a538 408 if (fModeSwitch==0 || fModeSwitch==2) {
f69743b7 409 HLTDebug("Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
410 evtData.fEventID, evtData.fEventID,
411 DataType2Text( iter->fDataType).c_str(),
412 DataType2Text(kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTPC).c_str());
a38a7850 413
f69743b7 414 if (iter->fDataType == AliHLTTPCDefinitions::fgkDDLPackedRawDataType &&
415 GetEventCount()<2) {
416 HLTWarning("data type %s is depricated, use %s (kAliHLTDataTypeDDLRaw)!",
417 DataType2Text(AliHLTTPCDefinitions::fgkDDLPackedRawDataType).c_str(),
418 DataType2Text(kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTPC).c_str());
419 }
420
421 if ( iter->fDataType != (kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTPC) &&
422 iter->fDataType != AliHLTTPCDefinitions::fgkDDLPackedRawDataType ) continue;
a38a7850 423
7e99beb3 424 }
8252a538 425 else if(fModeSwitch==1){
f69743b7 426 HLTDebug("Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
427 evtData.fEventID, evtData.fEventID,
428 DataType2Text( iter->fDataType).c_str(),
429 DataType2Text(AliHLTTPCDefinitions::fgkUnpackedRawDataType).c_str());
a38a7850 430
7e99beb3 431 if ( iter->fDataType != AliHLTTPCDefinitions::fgkUnpackedRawDataType ) continue;
a38a7850 432
7e99beb3 433 }
a38a7850 434
7e99beb3 435 slice = AliHLTTPCDefinitions::GetMinSliceNr( *iter );
436 patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
437 row[0] = AliHLTTPCTransform::GetFirstRow( patch );
438 row[1] = AliHLTTPCTransform::GetLastRow( patch );
8252a538 439
440
aff6e981 441 if(fUnsorted){
8252a538 442 fClusterFinder->SetUnsorted(fUnsorted);
443 fClusterFinder->SetPatch(patch);
aff6e981 444 }
445
7e99beb3 446 outPtr = (AliHLTTPCClusterData*)outBPtr;
a38a7850 447
7e99beb3 448 maxPoints = (size-tSize-sizeof(AliHLTTPCClusterData))/sizeof(AliHLTTPCSpacePointData);
db16520a 449
7e99beb3 450 fClusterFinder->InitSlice( slice, patch, row[0], row[1], maxPoints );
e83e889b 451 fClusterFinder->SetOutputArray( (AliHLTTPCSpacePointData*)outPtr->fSpacePoints );
01f43166 452
453 if(fUnsorted){
a74855c2 454 fClusterFinder->ReadDataUnsorted(iter->fPtr, iter->fSize);
01f43166 455
01f43166 456 fClusterFinder->FindClusters();
457 }
458 else{
459 fClusterFinder->Read(iter->fPtr, iter->fSize );
460 fClusterFinder->ProcessDigits();
461 }
7e99beb3 462 realPoints = fClusterFinder->GetNumberOfClusters();
71d7c760 463
7e99beb3 464 outPtr->fSpacePointCnt = realPoints;
465 nSize = sizeof(AliHLTTPCSpacePointData)*realPoints;
466 mysize += nSize+sizeof(AliHLTTPCClusterData);
74511e22 467
468 Logging( kHLTLogDebug, "HLT::TPCClusterFinder::DoEvent", "Spacepoints",
7e99beb3 469 "Number of spacepoints: %lu Slice/Patch/RowMin/RowMax: %d/%d/%d/%d.",
470 realPoints, slice, patch, row[0], row[1] );
471 AliHLTComponentBlockData bd;
472 FillBlockData( bd );
473 bd.fOffset = offset;
474 bd.fSize = mysize;
475 bd.fSpecification = iter->fSpecification;
64defa03 476 bd.fDataType = AliHLTTPCDefinitions::fgkClustersDataType;
7e99beb3 477 //AliHLTSubEventDescriptor::FillBlockAttributes( bd.fAttributes );
478 outputBlocks.push_back( bd );
71d7c760 479
7e99beb3 480 tSize += mysize;
481 outBPtr += mysize;
482 outPtr = (AliHLTTPCClusterData*)outBPtr;
71d7c760 483
b1c46961 484
7e99beb3 485 if ( tSize > size )
486 {
487 Logging( kHLTLogFatal, "HLT::TPCClusterFinder::DoEvent", "Too much data",
488 "Data written over allowed buffer. Amount written: %lu, allowed amount: %lu.",
489 tSize, size );
490 return EMSGSIZE;
71d7c760 491 }
71d7c760 492 }
7e99beb3 493
494 size = tSize;
71d7c760 495
7e99beb3 496 return 0;
497}
c3cda394 498
499int AliHLTTPCClusterFinderComponent::Reconfigure(const char* cdbEntry, const char* chainId)
500{
501 // see header file for class documentation
502 const char* path="HLT/ConfigTPC";
503 if (cdbEntry) path=cdbEntry;
504 if (path) {
505 HLTInfo("reconfigure from entry %s, chain id %s", path, (chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
506 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
507 if (pEntry) {
508 TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
509 if (pString) {
510 HLTInfo("received configuration object: %s", pString->GetString().Data());
511 } else {
512 HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
513 }
514 } else {
515 HLTError("can not fetch object \"%s\" from CDB", path);
516 }
517 }
b0914d2e 518 return 0;
c3cda394 519}