]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/TRD/AliHLTTRDClusterizerComponent.cxx
- protection added (AM)
[u/mrichter/AliRoot.git] / HLT / TRD / AliHLTTRDClusterizerComponent.cxx
CommitLineData
0af7cb2e 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> *
8 * for The ALICE Off-line Project. *
9 * *
10 * Permission to use, copy, modify and distribute this software and its *
11 * documentation strictly for non-commercial purposes is hereby granted *
12 * without fee, provided that the above copyright notice appears in all *
13 * copies and that both the copyright notice and this permission notice *
14 * appear in the supporting documentation. The authors make no claims *
15 * about the suitability of this software for any purpose. It is *
16 * provided "as is" without express or implied warranty. *
17 **************************************************************************/
18
19/** @file AliHLTTRDClusterizerComponent.cxx
20 @author Timm Steinbeck, Matthias Richter
21 @date
22 @brief A TRDClusterizer processing component for the HLT. */
23
c7500dae 24// see header file for class documentation //
25// or //
26// refer to README to build package //
27// or //
28// visit http://web.ift.uib.no/~kjeks/doc/alice-hlt //
29
0af7cb2e 30#if __GNUC__ >= 3
31using namespace std;
32#endif
33
051a0e2d 34#include "TTree.h"
35#include "TFile.h"
36#include "TBranch.h"
37
0af7cb2e 38#include "AliHLTTRDClusterizerComponent.h"
39#include "AliHLTTRDDefinitions.h"
d679dd6c 40#include "AliHLTTRDCluster.h"
0af7cb2e 41
886e8d3d 42#include "AliGeomManager.h"
43#include "AliTRDReconstructor.h"
0af7cb2e 44#include "AliCDBManager.h"
775f67d7 45#include "AliCDBStorage.h"
dc2e6604 46#include "AliHLTTRDClusterizer.h"
519f385f 47#include "AliTRDrecoParam.h"
48#include "AliTRDrawStreamBase.h"
d679dd6c 49#include "AliTRDcluster.h"
519f385f 50
0af7cb2e 51#include "AliRawReaderMemory.h"
52
d679dd6c 53#ifdef HAVE_VALGRIND_CALLGRIND_H
54#include <valgrind/callgrind.h>
55#else
e3e5ac39 56#define CALLGRIND_START_INSTRUMENTATION do { } while (0)
57#define CALLGRIND_STOP_INSTRUMENTATION do { } while (0)
d679dd6c 58#endif
59
0af7cb2e 60#include <cstdlib>
61#include <cerrno>
62#include <string>
63
18ada816 64ClassImp(AliHLTTRDClusterizerComponent)
3b021c25 65
d679dd6c 66AliHLTTRDClusterizerComponent::AliHLTTRDClusterizerComponent():
67 AliHLTProcessor(),
775f67d7 68 fOutputPercentage(500),
69 fOutputConst(0),
d679dd6c 70 fClusterizer(NULL),
71 fRecoParam(NULL),
d679dd6c 72 fMemReader(NULL),
775f67d7 73 fReconstructor(NULL)
0af7cb2e 74{
3b021c25 75 // Default constructor
051a0e2d 76
0af7cb2e 77}
78
79AliHLTTRDClusterizerComponent::~AliHLTTRDClusterizerComponent()
80{
3b021c25 81 // Destructor
886e8d3d 82 // Work is Done in DoDeInit()
0af7cb2e 83}
d679dd6c 84
d679dd6c 85
0af7cb2e 86const char* AliHLTTRDClusterizerComponent::GetComponentID()
87{
3b021c25 88 // Return the component ID const char *
0af7cb2e 89 return "TRDClusterizer"; // The ID of this component
90}
91
92void AliHLTTRDClusterizerComponent::GetInputDataTypes( vector<AliHLTComponent_DataType>& list)
93{
3b021c25 94 // Get the list of input data
0af7cb2e 95 list.clear(); // We do not have any requirements for our input data type(s).
775f67d7 96 list.push_back( (kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTRD) );
0af7cb2e 97}
98
99AliHLTComponent_DataType AliHLTTRDClusterizerComponent::GetOutputDataType()
100{
3b021c25 101 // Get the output data type
775f67d7 102 return kAliHLTMultipleDataType;
0af7cb2e 103}
104
775f67d7 105int AliHLTTRDClusterizerComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList)
106{
107 // Get the output data type
108 tgtList.clear();
109 tgtList.push_back(AliHLTTRDDefinitions::fgkClusterDataType);
110 tgtList.push_back(AliHLTTRDDefinitions::fgkMCMtrackletDataType);
111 return tgtList.size();
112}
113
114
0af7cb2e 115void AliHLTTRDClusterizerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
116{
3b021c25 117 // Get the output data size
775f67d7 118 constBase = fOutputConst;
0af7cb2e 119 inputMultiplier = ((double)fOutputPercentage)/100.0;
120}
121
0af7cb2e 122AliHLTComponent* AliHLTTRDClusterizerComponent::Spawn()
123{
3b021c25 124 // Spawn function, return new instance of this class
0af7cb2e 125 return new AliHLTTRDClusterizerComponent;
126};
127
128int AliHLTTRDClusterizerComponent::DoInit( int argc, const char** argv )
129{
130 // perform initialization. We check whether our relative output size is specified in the arguments.
d137c50b 131 Int_t iRawDataVersion = 2;
0af7cb2e 132 int i = 0;
133 char* cpErr;
519f385f 134
135 Int_t iRecoParamType = -1; // default will be the low flux
136
137 // the data type will become obsolete as soon as the formats are established
138 Int_t iRecoDataType = -1; // default will be simulation
18ada816 139 Int_t iyPosMethod = 1; // 0=COG 1=LUT 2=Gauss
775f67d7 140 Bool_t bProcessTracklets = kFALSE;
141 string geometryFileName = "";
519f385f 142
0af7cb2e 143 while ( i < argc )
144 {
886e8d3d 145 HLTDebug("argv[%d] == %s", i, argv[i] );
0af7cb2e 146 if ( !strcmp( argv[i], "output_percentage" ) )
147 {
148 if ( i+1>=argc )
149 {
886e8d3d 150 HLTError("Missing output_percentage parameter");
0af7cb2e 151 return ENOTSUP;
152 }
886e8d3d 153 HLTDebug("argv[%d+1] == %s", i, argv[i+1] );
0af7cb2e 154 fOutputPercentage = strtoul( argv[i+1], &cpErr, 0 );
155 if ( *cpErr )
156 {
886e8d3d 157 HLTError("Cannot convert output_percentage parameter '%s'", argv[i+1] );
0af7cb2e 158 return EINVAL;
159 }
775f67d7 160 HLTInfo("Output percentage set to %i %%", fOutputPercentage );
0af7cb2e 161 i += 2;
18ada816 162 }
9aea5deb 163 else if ( strcmp( argv[i], "-lowflux" ) == 0)
519f385f 164 {
165 iRecoParamType = 0;
166 HLTDebug("Low flux reco selected.");
167 i++;
18ada816 168 }
9aea5deb 169 else if ( strcmp( argv[i], "-highflux" ) == 0)
519f385f 170 {
171 iRecoParamType = 1;
886e8d3d 172 HLTDebug("High flux reco selected.");
173 i++;
18ada816 174 }
9aea5deb 175 else if ( strcmp( argv[i], "-cosmics" ) == 0)
886e8d3d 176 {
177 iRecoParamType = 2;
178 HLTDebug("Cosmic test reco selected.");
519f385f 179 i++;
18ada816 180 }
519f385f 181 // raw data type - sim or experiment
9aea5deb 182 else if ( strcmp( argv[i], "-simulation" ) == 0)
519f385f 183 {
184 iRecoDataType = 0;
185 i++;
519f385f 186 }
9aea5deb 187 else if ( strcmp( argv[i], "-experiment" ) == 0)
519f385f 188 {
189 iRecoDataType = 1;
190 i++;
519f385f 191 }
9aea5deb 192 else if ( strcmp( argv[i], "-rawver" ) == 0)
0af7cb2e 193 {
194 if ( i+1 >= argc )
195 {
886e8d3d 196 HLTError("Missing -rawver argument");
0af7cb2e 197 return ENOTSUP;
198 }
d137c50b 199 iRawDataVersion = atoi( argv[i+1] );
886e8d3d 200 HLTInfo("Raw data version is %d", iRawDataVersion );
0af7cb2e 201 i += 2;
9aea5deb 202
0af7cb2e 203 }
204
9aea5deb 205 else if ( strcmp( argv[i], "-geometry" ) == 0)
051a0e2d 206 {
207 if ( i+1 >= argc )
208 {
886e8d3d 209 HLTError("Missing -geometry argument");
051a0e2d 210 return ENOTSUP;
211 }
775f67d7 212 geometryFileName = argv[i+1];
213 HLTInfo("GeomFile storage is %s", geometryFileName.c_str() );
051a0e2d 214 i += 2;
775f67d7 215 }
216 else if ( strcmp( argv[i], "-processTracklets" ) == 0)
217 {
218 bProcessTracklets = kTRUE;
219 i++;
220 }
18ada816 221 else if ( strcmp( argv[i], "-yPosMethod" ) == 0)
222 {
223 if ( i+1 >= argc )
224 {
225 HLTError("Missing -yPosMethod argument");
226 return ENOTSUP;
227 }
228 if( strcmp(argv[i], "COG") )
229 iyPosMethod=0;
230 else if( strcmp(argv[i], "LUT") )
231 iyPosMethod=1;
232 else if( strcmp(argv[i], "Gauss") )
233 iyPosMethod=2;
234 else {
235 HLTError("Unknown -yPosMethod argument");
236 return ENOTSUP;
237 }
238 i += 2;
239 }
775f67d7 240 else if ( strcmp( argv[i], "-noZS" ) == 0) //no zero surpression in the input data
241 {
242 fOutputPercentage = 100;
243 i++;
244 }
18ada816 245
9aea5deb 246 else{
247 HLTError("Unknown option '%s'", argv[i] );
248 return EINVAL;
249 }
250
0af7cb2e 251 }
252
519f385f 253 // THE "REAL" INIT COMES HERE
254
775f67d7 255if (iRecoParamType < 0 || iRecoParamType > 2)
519f385f 256 {
257 HLTWarning("No reco param selected. Use -lowflux or -highflux flag. Defaulting to low flux.");
258 iRecoParamType = 0;
259 }
260
261 if (iRecoParamType == 0)
262 {
263 fRecoParam = AliTRDrecoParam::GetLowFluxParam();
264 HLTDebug("Low flux params init.");
265 }
266
267 if (iRecoParamType == 1)
268 {
269 fRecoParam = AliTRDrecoParam::GetHighFluxParam();
270 HLTDebug("High flux params init.");
271 }
272
886e8d3d 273 if (iRecoParamType == 2)
274 {
275 fRecoParam = AliTRDrecoParam::GetCosmicTestParam();
276 HLTDebug("Cosmic Test params init.");
277 }
278
519f385f 279 if (fRecoParam == 0)
280 {
281 HLTError("No reco params initialized. Sniffing big trouble!");
282 return -1;
283 }
284
0d66dbf5 285 fReconstructor = new AliTRDReconstructor();
286 fReconstructor->SetRecoParam(fRecoParam);
0134491a 287 fReconstructor->SetStreamLevel(0, AliTRDReconstructor::kClusterizer); // default value
dc2e6604 288 HLTInfo("Not writing clusters. I.e. output is a TClonesArray of clusters");
18ada816 289 TString recoOptions="hlt,!cw,sl_cf_0";
e3e5ac39 290 switch(iRecoDataType){
291 case 0: recoOptions += ",tc"; break;
292 case 1: recoOptions += ",!tc"; break;
293 }
18ada816 294 switch(iyPosMethod){
295 case 0: recoOptions += ",!gs,!lut"; break;
296 case 1: recoOptions += ",!gs,lut"; break;
297 case 2: recoOptions += ",gs,!lut"; break;
298 }
775f67d7 299 if(bProcessTracklets) recoOptions += ",tp";
300 else recoOptions += ",!tp";
301
302 HLTInfo("Reconstructor options: %s",recoOptions.Data());
e3e5ac39 303 fReconstructor->SetOption(recoOptions.Data());
0134491a 304
519f385f 305 // init the raw data type to be used...
306 // the switch here will become obsolete as soon as the data structures is fixed
307 // both: in sim and reality
308 if (iRecoDataType < 0 || iRecoDataType > 1)
309 {
310 HLTWarning("No data type selected. Use -simulation or -experiment flag. Defaulting to simulation.");
311 iRecoDataType = 0;
312 }
313
314 if (iRecoDataType == 0)
315 {
316 AliTRDrawStreamBase::SetRawStreamVersion(AliTRDrawStreamBase::kTRDsimStream);
317 HLTDebug("Data type expected is SIMULATION!");
318 }
319
320 if (iRecoDataType == 1)
321 {
322 AliTRDrawStreamBase::SetRawStreamVersion(AliTRDrawStreamBase::kTRDrealStream);
323 HLTDebug("Data type expected is EXPERIMENT!");
324 }
325
326 // the DATA BASE STUFF
775f67d7 327
328 if(!AliCDBManager::Instance()->IsDefaultStorageSet()){
329 HLTError("DefaultStorage is not Set in CDBManager");
330 return -1;
331 }
332 if(AliCDBManager::Instance()->GetRun()<0){
333 AliCDBManager *cdb = AliCDBManager::Instance();
334 if (cdb)
335 {
336 cdb->SetRun(0);
337 HLTWarning("Setting CDB Runnumber to 0. CDB instance 0x%x", cdb);
338 }
339 else
340 {
341 HLTError("Could not get CDB instance", "cdb 0x%x", cdb);
342 return -1;
343 }
344 }
345 HLTInfo("CDB default storage: %s; RunNo: %i", (AliCDBManager::Instance()->GetDefaultStorage()->GetBaseFolder()).Data(), AliCDBManager::Instance()->GetRun());
346
347 if(!AliGeomManager::GetGeometry()){
348 if(!TFile::Open(geometryFileName.c_str())){
349 HLTInfo("Loading standard geometry file");
350 AliGeomManager::LoadGeometry();
351 }else{
352 HLTWarning("Loading non-standard geometry file");
353 AliGeomManager::LoadGeometry(geometryFileName.c_str());
051a0e2d 354 }
775f67d7 355 if(!AliGeomManager::GetGeometry()){
356 HLTError("Cannot load geometry");
d679dd6c 357 return EINVAL;
051a0e2d 358 }
d679dd6c 359 }
775f67d7 360 else{
d679dd6c 361 HLTInfo("Geometry Already Loaded");
775f67d7 362 }
d679dd6c 363
3b021c25 364 fMemReader = new AliRawReaderMemory;
051a0e2d 365
dc2e6604 366 fClusterizer = new AliHLTTRDClusterizer("TRDCclusterizer", "TRDCclusterizer");
9aea5deb 367 fClusterizer->SetReconstructor(fReconstructor);
56397b53 368 fClusterizer->SetUseLabels(kFALSE);
d137c50b 369 fClusterizer->SetRawVersion(iRawDataVersion);
775f67d7 370
371 if(fReconstructor->IsProcessingTracklets())
372 fOutputConst = fClusterizer->GetTrMemBlockSize();
0af7cb2e 373 return 0;
374}
375
376int AliHLTTRDClusterizerComponent::DoDeinit()
377{
3b021c25 378 // Deinitialization of the component
379 delete fMemReader;
380 fMemReader = 0;
381 delete fClusterizer;
382 fClusterizer = 0;
9aea5deb 383
384 fReconstructor->SetClusters(0x0);
0d66dbf5 385 delete fReconstructor;
386 fReconstructor = 0x0;
0af7cb2e 387 return 0;
388
519f385f 389 if (fRecoParam)
390 {
391 HLTDebug("Deleting fRecoParam");
392 delete fRecoParam;
393 fRecoParam = 0;
394 }
0af7cb2e 395}
396
886e8d3d 397int AliHLTTRDClusterizerComponent::DoEvent( const AliHLTComponentEventData& evtData,
398 const AliHLTComponentBlockData* blocks,
399 AliHLTComponent_TriggerData& /*trigData*/,
d679dd6c 400 AliHLTUInt8_t* outputPtr,
a28bfa0d 401 AliHLTUInt32_t& size,
d679dd6c 402 vector<AliHLTComponent_BlockData>& outputBlocks )
0af7cb2e 403{
3b021c25 404 // Process an event
775f67d7 405
406 if (evtData.fEventID == 1)
407 CALLGRIND_START_INSTRUMENTATION;
408
409 HLTDebug( "NofBlocks %i", evtData.fBlockCnt );
0af7cb2e 410 // Process an event
d679dd6c 411 AliHLTUInt32_t totalSize = 0, offset = 0;
0af7cb2e 412
051a0e2d 413 //implement a usage of the following
519f385f 414 // AliHLTUInt32_t triggerDataStructSize = trigData.fStructSize;
415 // AliHLTUInt32_t triggerDataSize = trigData.fDataSize;
416 // void *triggerData = trigData.fData;
886e8d3d 417 //HLTDebug( "Trigger data received. Struct size %d Data size %d Data location 0x%x", trigData.fStructSize, trigData.fDataSize, (UInt_t*)trigData.fData);
051a0e2d 418
0af7cb2e 419 // Loop over all input blocks in the event
886e8d3d 420 AliHLTComponentDataType expectedDataType = (kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTRD);
775f67d7 421 for ( UInt_t iBlock = 0; iBlock < evtData.fBlockCnt; iBlock++ )
422 {
423 const AliHLTComponentBlockData &block = blocks[iBlock];
519f385f 424 // lets not use the internal TRD data types here : AliHLTTRDDefinitions::fgkDDLRawDataType
425 // which is depreciated - we use HLT global defs instead
d679dd6c 426 // if ( block.fDataType != (kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTRD) )
427 AliHLTComponentDataType inputDataType = block.fDataType;
886e8d3d 428 if ( inputDataType != expectedDataType)
0af7cb2e 429 {
775f67d7 430 HLTDebug( "Block # %i/%i; Event 0x%08LX (%Lu) Wrong received datatype: %s - required datatype: %s; Skipping",
431 iBlock, evtData.fBlockCnt,
9aea5deb 432 evtData.fEventID, evtData.fEventID,
433 DataType2Text(inputDataType).c_str(),
434 DataType2Text(expectedDataType).c_str());
0af7cb2e 435 continue;
436 }
9aea5deb 437 else
438 {
775f67d7 439 HLTDebug("We get the right data type: Block # %i/%i; Event 0x%08LX (%Lu) Received datatype: %s; Block Size: %i",
440 iBlock, evtData.fBlockCnt,
441 evtData.fEventID, evtData.fEventID,
442 DataType2Text(inputDataType).c_str(),
443 block.fSize);
9aea5deb 444 }
445
886e8d3d 446 // fMemReader->Reset();
d679dd6c 447 fMemReader->SetMemory((UChar_t*) block.fPtr, block.fSize);
886e8d3d 448
d679dd6c 449 AliHLTUInt32_t spec = block.fSpecification;
886e8d3d 450
451 Int_t id = 1024;
452
453 for ( Int_t ii = 0; ii < 18 ; ii++ ) {
454 if ( spec & 0x00000001 ) {
455 id += ii;
456 break;
457 }
458 spec = spec >> 1 ;
459 }
886e8d3d 460
d679dd6c 461 fMemReader->SetEquipmentID( id );
462
775f67d7 463 fClusterizer->SetMemBlock(outputPtr+offset);
886e8d3d 464 Bool_t iclustered = fClusterizer->Raw2ClustersChamber(fMemReader);
465 if (iclustered == kTRUE)
0af7cb2e 466 {
886e8d3d 467 HLTDebug( "Clustered successfully");
468 }
469 else
470 {
471 HLTError("Clustering ERROR");
0af7cb2e 472 return -1;
473 }
519f385f 474
d679dd6c 475 // put the tree into output
886e8d3d 476 //fcTree->Print();
dc2e6604 477
775f67d7 478 AliHLTUInt32_t addedSize;
479 if(fReconstructor->IsProcessingTracklets()){
480 addedSize = fClusterizer->GetAddedTrSize();
481 totalSize += fClusterizer->GetTrMemBlockSize(); //if IsProcessingTracklets() is enabled we always reserve a data block of size GetTrMemBlockSize() for the tracklets
dc2e6604 482 if (addedSize > 0){
483 // Using low-level interface
484 // with interface classes
dc2e6604 485 if ( totalSize > size )
0134491a 486 {
dc2e6604 487 HLTError("Too much data; Data written over allowed buffer. Amount written: %lu, allowed amount: %lu.",
488 totalSize, size );
489 return EMSGSIZE;
0134491a 490 }
775f67d7 491
dc2e6604 492 // Fill block
493 AliHLTComponentBlockData bd;
494 FillBlockData( bd );
495 bd.fOffset = offset;
496 bd.fSize = addedSize;
497 //bd.fSpecification = spec;
498 bd.fSpecification = gkAliEventTypeData;
775f67d7 499 bd.fDataType = AliHLTTRDDefinitions::fgkMCMtrackletDataType;
dc2e6604 500 outputBlocks.push_back( bd );
18ada816 501 HLTDebug( "BD fPtr 0x%x, fOffset %i, size %i, dataType %s, spec 0x%x ", bd.fPtr, bd.fOffset, bd.fSize, DataType2Text(bd.fDataType).c_str(), spec);
0134491a 502 }
775f67d7 503 offset = totalSize;
504 }
505
506 addedSize = fClusterizer->GetAddedClSize();
507 if (addedSize > 0){
508 // Using low-level interface
509 // with interface classes
510 totalSize += addedSize;
511 if ( totalSize > size )
512 {
513 HLTError("Too much data; Data written over allowed buffer. Amount written: %lu, allowed amount: %lu.",
514 totalSize, size );
515 return EMSGSIZE;
516 }
517
518 // Fill block
519 AliHLTComponentBlockData bd;
520 FillBlockData( bd );
521 bd.fOffset = offset;
522 bd.fSize = addedSize;
523 //bd.fSpecification = spec;
524 bd.fSpecification = gkAliEventTypeData;
525 bd.fDataType = AliHLTTRDDefinitions::fgkClusterDataType;
526 outputBlocks.push_back( bd );
527 HLTDebug( "BD fPtr 0x%x, fOffset %i, size %i, dataType %s, spec 0x%x ", bd.fPtr, bd.fOffset, bd.fSize, DataType2Text(bd.fDataType).c_str(), spec);
528 offset = totalSize;
529
530 }
531 else
532 HLTWarning("Array of clusters is empty!");
dc2e6604 533 }
d679dd6c 534 fReconstructor->SetClusters(0x0);
b39f18ce 535
d679dd6c 536 size = totalSize;
537 HLTDebug("Event is done. size written to the output is %i", size);
538 return 0;
539}
540
d679dd6c 541void AliHLTTRDClusterizerComponent::PrintObject( TClonesArray* inClustersArray)
542{
543 AliTRDcluster* cluster=0x0;
9aea5deb 544
d679dd6c 545 for (Int_t i=0; i < inClustersArray->GetEntriesFast(); i++){
546 cluster = dynamic_cast<AliTRDcluster*>(inClustersArray->At(i));
547 HLTDebug("cluster[%i]",i);
548 HLTDebug(" PadCol = %i; PadRow = %i; PadTime = %i", cluster->GetPadCol(), cluster->GetPadRow(), cluster->GetPadTime());
549 HLTDebug(" Detector = %i, Amplitude = %f, Center = %f", cluster->GetDetector(), cluster->GetQ(), cluster->GetCenter());
550 HLTDebug(" LocalTimeBin = %i; NPads = %i; maskedPosition: %s, status: %s", cluster->GetLocalTimeBin(), cluster->GetNPads(),cluster->GetPadMaskedPosition(),cluster->GetPadMaskedPosition());
551 }
9aea5deb 552
0af7cb2e 553}