3 /**************************************************************************
4 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
6 * Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
7 * Timm Steinbeck <timm@kip.uni-heidelberg.de> *
8 * for The ALICE Off-line Project. *
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 **************************************************************************/
19 /** @file AliHLTTRDClusterizerComponent.cxx
20 @author Timm Steinbeck, Matthias Richter
22 @brief A TRDClusterizer processing component for the HLT. */
24 // see header file for class documentation //
26 // refer to README to build package //
28 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt //
38 #include "AliHLTTRDClusterizerComponent.h"
39 #include "AliHLTTRDDefinitions.h"
40 #include "AliHLTTRDCluster.h"
42 #include "AliGeomManager.h"
43 #include "AliTRDReconstructor.h"
44 #include "AliCDBManager.h"
45 #include "AliCDBStorage.h"
46 #include "AliHLTTRDClusterizer.h"
47 #include "AliTRDrecoParam.h"
48 #include "AliTRDrawStreamBase.h"
49 #include "AliTRDcluster.h"
51 #include "AliRawReaderMemory.h"
53 #ifdef HAVE_VALGRIND_CALLGRIND_H
54 #include <valgrind/callgrind.h>
56 #define CALLGRIND_START_INSTRUMENTATION do { } while (0)
57 #define CALLGRIND_STOP_INSTRUMENTATION do { } while (0)
64 ClassImp(AliHLTTRDClusterizerComponent)
66 AliHLTTRDClusterizerComponent::AliHLTTRDClusterizerComponent():
68 fOutputPercentage(500),
75 // Default constructor
79 AliHLTTRDClusterizerComponent::~AliHLTTRDClusterizerComponent()
82 // Work is Done in DoDeInit()
86 const char* AliHLTTRDClusterizerComponent::GetComponentID()
88 // Return the component ID const char *
89 return "TRDClusterizer"; // The ID of this component
92 void AliHLTTRDClusterizerComponent::GetInputDataTypes( vector<AliHLTComponent_DataType>& list)
94 // Get the list of input data
95 list.clear(); // We do not have any requirements for our input data type(s).
96 list.push_back( (kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTRD) );
99 AliHLTComponent_DataType AliHLTTRDClusterizerComponent::GetOutputDataType()
101 // Get the output data type
102 return kAliHLTMultipleDataType;
105 int AliHLTTRDClusterizerComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList)
107 // Get the output data type
109 tgtList.push_back(AliHLTTRDDefinitions::fgkClusterDataType);
110 tgtList.push_back(AliHLTTRDDefinitions::fgkMCMtrackletDataType);
111 return tgtList.size();
115 void AliHLTTRDClusterizerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
117 // Get the output data size
118 constBase = fOutputConst;
119 inputMultiplier = ((double)fOutputPercentage)/100.0;
122 AliHLTComponent* AliHLTTRDClusterizerComponent::Spawn()
124 // Spawn function, return new instance of this class
125 return new AliHLTTRDClusterizerComponent;
128 int AliHLTTRDClusterizerComponent::DoInit( int argc, const char** argv )
130 // perform initialization. We check whether our relative output size is specified in the arguments.
131 Int_t iRawDataVersion = 2;
135 Int_t iRecoParamType = -1; // default will be the low flux
137 // the data type will become obsolete as soon as the formats are established
138 Int_t iRecoDataType = -1; // default will be simulation
139 Int_t iyPosMethod = 1; // 0=COG 1=LUT 2=Gauss
140 Bool_t bProcessTracklets = kFALSE;
141 string geometryFileName = "";
145 HLTDebug("argv[%d] == %s", i, argv[i] );
146 if ( !strcmp( argv[i], "output_percentage" ) )
150 HLTError("Missing output_percentage parameter");
153 HLTDebug("argv[%d+1] == %s", i, argv[i+1] );
154 fOutputPercentage = strtoul( argv[i+1], &cpErr, 0 );
157 HLTError("Cannot convert output_percentage parameter '%s'", argv[i+1] );
160 HLTInfo("Output percentage set to %i %%", fOutputPercentage );
163 else if ( strcmp( argv[i], "-lowflux" ) == 0)
166 HLTDebug("Low flux reco selected.");
169 else if ( strcmp( argv[i], "-highflux" ) == 0)
172 HLTDebug("High flux reco selected.");
175 else if ( strcmp( argv[i], "-cosmics" ) == 0)
178 HLTDebug("Cosmic test reco selected.");
181 // raw data type - sim or experiment
182 else if ( strcmp( argv[i], "-simulation" ) == 0)
187 else if ( strcmp( argv[i], "-experiment" ) == 0)
192 else if ( strcmp( argv[i], "-rawver" ) == 0)
196 HLTError("Missing -rawver argument");
199 iRawDataVersion = atoi( argv[i+1] );
200 HLTInfo("Raw data version is %d", iRawDataVersion );
205 else if ( strcmp( argv[i], "-geometry" ) == 0)
209 HLTError("Missing -geometry argument");
212 geometryFileName = argv[i+1];
213 HLTInfo("GeomFile storage is %s", geometryFileName.c_str() );
216 else if ( strcmp( argv[i], "-processTracklets" ) == 0)
218 bProcessTracklets = kTRUE;
221 else if ( strcmp( argv[i], "-yPosMethod" ) == 0)
225 HLTError("Missing -yPosMethod argument");
228 if( strcmp(argv[i], "COG") )
230 else if( strcmp(argv[i], "LUT") )
232 else if( strcmp(argv[i], "Gauss") )
235 HLTError("Unknown -yPosMethod argument");
240 else if ( strcmp( argv[i], "-noZS" ) == 0) //no zero surpression in the input data
242 fOutputPercentage = 100;
247 HLTError("Unknown option '%s'", argv[i] );
253 // THE "REAL" INIT COMES HERE
255 if (iRecoParamType < 0 || iRecoParamType > 2)
257 HLTWarning("No reco param selected. Use -lowflux or -highflux flag. Defaulting to low flux.");
261 if (iRecoParamType == 0)
263 fRecoParam = AliTRDrecoParam::GetLowFluxParam();
264 HLTDebug("Low flux params init.");
267 if (iRecoParamType == 1)
269 fRecoParam = AliTRDrecoParam::GetHighFluxParam();
270 HLTDebug("High flux params init.");
273 if (iRecoParamType == 2)
275 fRecoParam = AliTRDrecoParam::GetCosmicTestParam();
276 HLTDebug("Cosmic Test params init.");
281 HLTError("No reco params initialized. Sniffing big trouble!");
285 fReconstructor = new AliTRDReconstructor();
286 fReconstructor->SetRecoParam(fRecoParam);
287 fReconstructor->SetStreamLevel(0, AliTRDReconstructor::kClusterizer); // default value
288 HLTInfo("Not writing clusters. I.e. output is a TClonesArray of clusters");
289 TString recoOptions="hlt,!cw,sl_cf_0";
290 switch(iRecoDataType){
291 case 0: recoOptions += ",tc"; break;
292 case 1: recoOptions += ",!tc"; break;
295 case 0: recoOptions += ",!gs,!lut"; break;
296 case 1: recoOptions += ",!gs,lut"; break;
297 case 2: recoOptions += ",gs,!lut"; break;
299 if(bProcessTracklets) recoOptions += ",tp";
300 else recoOptions += ",!tp";
302 HLTInfo("Reconstructor options: %s",recoOptions.Data());
303 fReconstructor->SetOption(recoOptions.Data());
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)
310 HLTWarning("No data type selected. Use -simulation or -experiment flag. Defaulting to simulation.");
314 if (iRecoDataType == 0)
316 AliTRDrawStreamBase::SetRawStreamVersion(AliTRDrawStreamBase::kTRDsimStream);
317 HLTDebug("Data type expected is SIMULATION!");
320 if (iRecoDataType == 1)
322 AliTRDrawStreamBase::SetRawStreamVersion(AliTRDrawStreamBase::kTRDrealStream);
323 HLTDebug("Data type expected is EXPERIMENT!");
326 // the DATA BASE STUFF
328 if(!AliCDBManager::Instance()->IsDefaultStorageSet()){
329 HLTError("DefaultStorage is not Set in CDBManager");
332 if(AliCDBManager::Instance()->GetRun()<0){
333 AliCDBManager *cdb = AliCDBManager::Instance();
337 HLTWarning("Setting CDB Runnumber to 0. CDB instance 0x%x", cdb);
341 HLTError("Could not get CDB instance", "cdb 0x%x", cdb);
345 HLTInfo("CDB default storage: %s; RunNo: %i", (AliCDBManager::Instance()->GetDefaultStorage()->GetBaseFolder()).Data(), AliCDBManager::Instance()->GetRun());
347 if(!AliGeomManager::GetGeometry()){
348 if(!TFile::Open(geometryFileName.c_str())){
349 HLTInfo("Loading standard geometry file");
350 AliGeomManager::LoadGeometry();
352 HLTWarning("Loading non-standard geometry file");
353 AliGeomManager::LoadGeometry(geometryFileName.c_str());
355 if(!AliGeomManager::GetGeometry()){
356 HLTError("Cannot load geometry");
361 HLTInfo("Geometry Already Loaded");
364 fMemReader = new AliRawReaderMemory;
366 fClusterizer = new AliHLTTRDClusterizer("TRDCclusterizer", "TRDCclusterizer");
367 fClusterizer->SetReconstructor(fReconstructor);
368 fClusterizer->SetUseLabels(kFALSE);
369 fClusterizer->SetRawVersion(iRawDataVersion);
371 if(fReconstructor->IsProcessingTracklets())
372 fOutputConst = fClusterizer->GetTrMemBlockSize();
376 int AliHLTTRDClusterizerComponent::DoDeinit()
378 // Deinitialization of the component
384 fReconstructor->SetClusters(0x0);
385 delete fReconstructor;
386 fReconstructor = 0x0;
391 HLTDebug("Deleting fRecoParam");
397 int AliHLTTRDClusterizerComponent::DoEvent( const AliHLTComponentEventData& evtData,
398 const AliHLTComponentBlockData* blocks,
399 AliHLTComponent_TriggerData& /*trigData*/,
400 AliHLTUInt8_t* outputPtr,
401 AliHLTUInt32_t& size,
402 vector<AliHLTComponent_BlockData>& outputBlocks )
406 if (evtData.fEventID == 1)
407 CALLGRIND_START_INSTRUMENTATION;
409 HLTDebug( "NofBlocks %i", evtData.fBlockCnt );
411 AliHLTUInt32_t totalSize = 0, offset = 0;
413 //implement a usage of the following
414 // AliHLTUInt32_t triggerDataStructSize = trigData.fStructSize;
415 // AliHLTUInt32_t triggerDataSize = trigData.fDataSize;
416 // void *triggerData = trigData.fData;
417 //HLTDebug( "Trigger data received. Struct size %d Data size %d Data location 0x%x", trigData.fStructSize, trigData.fDataSize, (UInt_t*)trigData.fData);
419 // Loop over all input blocks in the event
420 AliHLTComponentDataType expectedDataType = (kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTRD);
421 for ( UInt_t iBlock = 0; iBlock < evtData.fBlockCnt; iBlock++ )
423 const AliHLTComponentBlockData &block = blocks[iBlock];
424 // lets not use the internal TRD data types here : AliHLTTRDDefinitions::fgkDDLRawDataType
425 // which is depreciated - we use HLT global defs instead
426 // if ( block.fDataType != (kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTRD) )
427 AliHLTComponentDataType inputDataType = block.fDataType;
428 if ( inputDataType != expectedDataType)
430 HLTDebug( "Block # %i/%i; Event 0x%08LX (%Lu) Wrong received datatype: %s - required datatype: %s; Skipping",
431 iBlock, evtData.fBlockCnt,
432 evtData.fEventID, evtData.fEventID,
433 DataType2Text(inputDataType).c_str(),
434 DataType2Text(expectedDataType).c_str());
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(),
446 // fMemReader->Reset();
447 fMemReader->SetMemory((UChar_t*) block.fPtr, block.fSize);
449 AliHLTUInt32_t spec = block.fSpecification;
453 for ( Int_t ii = 0; ii < 18 ; ii++ ) {
454 if ( spec & 0x00000001 ) {
461 fMemReader->SetEquipmentID( id );
463 fClusterizer->SetMemBlock(outputPtr+offset);
464 Bool_t iclustered = fClusterizer->Raw2ClustersChamber(fMemReader);
465 if (iclustered == kTRUE)
467 HLTDebug( "Clustered successfully");
471 HLTError("Clustering ERROR");
475 // put the tree into output
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
483 // Using low-level interface
484 // with interface classes
485 if ( totalSize > size )
487 HLTError("Too much data; Data written over allowed buffer. Amount written: %lu, allowed amount: %lu.",
493 AliHLTComponentBlockData bd;
496 bd.fSize = addedSize;
497 //bd.fSpecification = spec;
498 bd.fSpecification = gkAliEventTypeData;
499 bd.fDataType = AliHLTTRDDefinitions::fgkMCMtrackletDataType;
500 outputBlocks.push_back( bd );
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);
506 addedSize = fClusterizer->GetAddedClSize();
508 // Using low-level interface
509 // with interface classes
510 totalSize += addedSize;
511 if ( totalSize > size )
513 HLTError("Too much data; Data written over allowed buffer. Amount written: %lu, allowed amount: %lu.",
519 AliHLTComponentBlockData bd;
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);
532 HLTWarning("Array of clusters is empty!");
534 fReconstructor->SetClusters(0x0);
537 HLTDebug("Event is done. size written to the output is %i", size);
541 void AliHLTTRDClusterizerComponent::PrintObject( TClonesArray* inClustersArray)
543 AliTRDcluster* cluster=0x0;
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());