3 //**************************************************************************
4 //* This file is property of and copyright by the ALICE HLT Project *
5 //* ALICE Experiment at CERN, All rights reserved. *
8 //* for The ALICE HLT 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 Theodor Rascanu
22 @brief A TRDClusterizer processing component for the HLT.
25 // see header file for class documentation //
27 // refer to README to build package //
29 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt //
39 #include "AliHLTTRDClusterizerComponent.h"
40 #include "AliHLTTRDDefinitions.h"
41 #include "AliHLTTRDClusterizer.h"
42 #include "AliHLTTRDUtils.h"
44 #include "AliGeomManager.h"
45 #include "AliTRDReconstructor.h"
46 #include "AliCDBManager.h"
47 #include "AliCDBStorage.h"
48 #include "AliCDBEntry.h"
49 #include "AliTRDrecoParam.h"
50 #include "AliTRDrawStreamBase.h"
51 #include "AliTRDcluster.h"
53 #include "AliRawReaderMemory.h"
55 #ifdef HAVE_VALGRIND_CALLGRIND_H
56 #include <valgrind/callgrind.h>
58 #define CALLGRIND_START_INSTRUMENTATION (void)0
59 #define CALLGRIND_STOP_INSTRUMENTATION (void)0
66 ClassImp(AliHLTTRDClusterizerComponent)
68 AliHLTTRDClusterizerComponent::AliHLTTRDClusterizerComponent()
70 fOutputPercentage(100),
80 fgeometryFileName(""),
81 fProcessTracklets(kFALSE),
85 fHighLevelOutput(kFALSE),
86 fEmulateHLTClusters(kFALSE)
88 // Default constructor
92 AliHLTTRDClusterizerComponent::~AliHLTTRDClusterizerComponent()
95 // Work is Done in DoDeInit()
99 const char* AliHLTTRDClusterizerComponent::GetComponentID()
101 // Return the component ID const char *
102 return "TRDClusterizer"; // The ID of this component
105 void AliHLTTRDClusterizerComponent::GetInputDataTypes( vector<AliHLTComponent_DataType>& list)
107 // Get the list of input data
108 list.clear(); // We do not have any requirements for our input data type(s).
109 list.push_back(kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTRD);
112 AliHLTComponentDataType AliHLTTRDClusterizerComponent::GetOutputDataType()
114 // Get the output data type
115 return kAliHLTMultipleDataType;
118 int AliHLTTRDClusterizerComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList)
120 // Get the output data type
122 tgtList.push_back(AliHLTTRDDefinitions::fgkClusterDataType);
123 tgtList.push_back(AliHLTTRDDefinitions::fgkMCMtrackletDataType);
124 return tgtList.size();
128 void AliHLTTRDClusterizerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
130 // Get the output data size
131 constBase = fOutputConst;
132 inputMultiplier = ((double)fOutputPercentage)*4/100.0;
135 AliHLTComponent* AliHLTTRDClusterizerComponent::Spawn()
137 // Spawn function, return new instance of this class
138 return new AliHLTTRDClusterizerComponent;
141 int AliHLTTRDClusterizerComponent::DoInit( int argc, const char** argv )
143 // perform initialization. We check whether our relative output size is specified in the arguments.
146 fReconstructor = new AliTRDReconstructor();
147 HLTDebug("TRDReconstructor at 0x%x", fReconstructor);
149 TString configuration="";
151 for (int i=0; i<argc && iResult>=0; i++) {
153 if (!configuration.IsNull()) configuration+=" ";
154 configuration+=argument;
157 if (!configuration.IsNull()) {
158 iResult=Configure(configuration.Data());
160 iResult=Reconfigure(NULL, NULL);
164 HLTFatal("Clusterizer was not initialized!");
168 if(iResult<0) return iResult;
170 fMemReader = new AliRawReaderMemory;
171 fClusterizer->SetReconstructor(fReconstructor);
172 fClusterizer->SetUseLabels(kFALSE);
174 if(fReconstructor->IsProcessingTracklets())
175 fOutputConst = fClusterizer->GetTrMemBlockSize();
180 int AliHLTTRDClusterizerComponent::DoDeinit()
182 // Deinitialization of the component
188 fReconstructor->SetClusters(0x0);
189 delete fReconstructor;
190 fReconstructor = 0x0;
195 HLTDebug("Deleting fRecoParam");
201 int AliHLTTRDClusterizerComponent::DoEvent( const AliHLTComponentEventData& evtData,
202 const AliHLTComponentBlockData* blocks,
203 AliHLTComponent_TriggerData& /*trigData*/,
204 AliHLTUInt8_t* outputPtr,
205 AliHLTUInt32_t& size,
206 vector<AliHLTComponent_BlockData>& outputBlocks )
210 if (evtData.fEventID == 10)
211 CALLGRIND_START_INSTRUMENTATION;
213 if(!IsDataEvent())return 0;
215 HLTDebug( "NofBlocks %i", evtData.fBlockCnt );
217 AliHLTUInt32_t totalSize = 0, offset = 0;
219 //implement a usage of the following
220 // AliHLTUInt32_t triggerDataStructSize = trigData.fStructSize;
221 // AliHLTUInt32_t triggerDataSize = trigData.fDataSize;
222 // void *triggerData = trigData.fData;
223 //HLTDebug( "Trigger data received. Struct size %d Data size %d Data location 0x%x", trigData.fStructSize, trigData.fDataSize, (UInt_t*)trigData.fData);
225 // Loop over all input blocks in the event
226 AliHLTComponentDataType expectedDataType = (kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTRD);
227 for ( UInt_t iBlock = 0; iBlock < evtData.fBlockCnt; iBlock++ )
229 const AliHLTComponentBlockData &block = blocks[iBlock];
230 // lets not use the internal TRD data types here : AliHLTTRDDefinitions::fgkDDLRawDataType
231 // which is depreciated - we use HLT global defs instead
232 // if ( block.fDataType != (kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTRD) )
233 AliHLTComponentDataType inputDataType = block.fDataType;
234 if ( inputDataType != expectedDataType)
236 HLTDebug( "Block # %i/%i; Event 0x%08LX (%Lu) Wrong received datatype: %s - required datatype: %s; Skipping",
237 iBlock, evtData.fBlockCnt,
238 evtData.fEventID, evtData.fEventID,
239 DataType2Text(inputDataType).c_str(),
240 DataType2Text(expectedDataType).c_str());
241 if(block.fDataType == kAliHLTDataTypeEOR)
242 CALLGRIND_STOP_INSTRUMENTATION;
247 HLTDebug("We get the right data type: Block # %i/%i; Event 0x%08LX (%Lu) Received datatype: %s; Block Size: %i",
248 iBlock, evtData.fBlockCnt,
249 evtData.fEventID, evtData.fEventID,
250 DataType2Text(inputDataType).c_str(),
255 unsigned long constBase;
256 double inputMultiplier;
257 GetOutputDataSize(constBase,inputMultiplier);
258 if(size<(constBase+block.fSize*inputMultiplier)){
259 HLTWarning("Memory Block given might be too small: %i < %i; Event %Lu", size, constBase+block.fSize*inputMultiplier, evtData.fEventID);
263 // fMemReader->Reset();
264 fMemReader->SetMemory((UChar_t*) block.fPtr, block.fSize);
266 AliHLTUInt32_t spec = block.fSpecification;
268 Int_t id = AliHLTTRDUtils::GetSM(spec) + 1024;
270 fMemReader->SetEquipmentID(id);
272 fClusterizer->SetMemBlock(outputPtr+offset);
273 Bool_t bclustered = fClusterizer->Raw2ClustersChamber(fMemReader);
276 HLTDebug("Clustered successfully");
280 HLTError("Clustering ERROR");
284 AliHLTUInt32_t addedSize;
285 if(fReconstructor->IsProcessingTracklets()){
286 addedSize = fClusterizer->GetAddedTrSize();
287 totalSize += fClusterizer->GetTrMemBlockSize(); //if IsProcessingTracklets() is enabled we always reserve a data block of size GetTrMemBlockSize() for the tracklets
289 // Using low-level interface
290 // with interface classes
291 if ( totalSize > size )
293 HLTError("Too much data; Data written over allowed buffer. Amount written: %lu, allowed amount: %lu.",
299 AliHLTComponentBlockData bd;
302 bd.fSize = addedSize;
303 bd.fSpecification = block.fSpecification;
304 bd.fDataType = AliHLTTRDDefinitions::fgkMCMtrackletDataType;
305 outputBlocks.push_back( bd );
306 HLTDebug( "BD ptr 0x%x, offset %i, size %i, dataType %s, spec 0x%x ", bd.fPtr, bd.fOffset, bd.fSize, DataType2Text(bd.fDataType).c_str(), spec);
311 addedSize = fClusterizer->GetAddedClSize();
314 Int_t* nTimeBins = (Int_t*)(outputPtr+offset+fClusterizer->GetAddedClSize());
315 *nTimeBins = fClusterizer->GetNTimeBins();
316 addedSize += sizeof(*nTimeBins);
318 totalSize += addedSize;
319 if ( totalSize > size )
321 HLTError("Too much data; Data written over allowed buffer. Amount written: %lu, allowed amount: %lu.",
327 AliHLTComponentBlockData bd;
330 bd.fSize = addedSize;
331 bd.fSpecification = block.fSpecification;
332 bd.fDataType = AliHLTTRDDefinitions::fgkClusterDataType;
333 outputBlocks.push_back( bd );
334 HLTDebug( "BD ptr 0x%x, offset %i, size %i, dataType %s, spec 0x%x ", bd.fPtr, bd.fOffset, bd.fSize, DataType2Text(bd.fDataType).c_str(), spec);
338 HLTDebug("Array of clusters is empty!");
341 fReconstructor->SetClusters(0x0);
344 HLTDebug("Event is done. size written to the output is %i", size);
348 void AliHLTTRDClusterizerComponent::PrintObject(
350 TClonesArray* inClustersArray
357 AliTRDcluster* cluster=0x0;
359 for (Int_t i=0; i < inClustersArray->GetEntriesFast(); i++){
360 cluster = dynamic_cast<AliTRDcluster*>(inClustersArray->At(i));
361 HLTDebug("cluster[%i]",i);
362 HLTDebug(" PadCol = %i; PadRow = %i; PadTime = %i", cluster->GetPadCol(), cluster->GetPadRow(), cluster->GetPadTime());
363 HLTDebug(" Detector = %i, Amplitude = %f, Center = %f", cluster->GetDetector(), cluster->GetQ(), cluster->GetCenter());
364 HLTDebug(" LocalTimeBin = %i; NPads = %i; maskedPosition: %s, status: %s", cluster->GetLocalTimeBin(), cluster->GetNPads(),cluster->GetPadMaskedPosition(),cluster->GetPadMaskedPosition());
369 int AliHLTTRDClusterizerComponent::Configure(const char* arguments){
371 if (!arguments) return iResult;
373 TString allArgs=arguments;
377 TObjArray* pTokens=allArgs.Tokenize(" ");
379 for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
380 argument=((TObjString*)pTokens->At(i))->GetString();
381 if (argument.IsNull()) continue;
383 if (argument.CompareTo("output_percentage")==0) {
384 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
385 HLTInfo("Setting output percentage to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
386 fOutputPercentage=((TObjString*)pTokens->At(i))->GetString().Atoi();
389 else if (argument.CompareTo("-geometry")==0) {
390 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
391 HLTInfo("Setting geometry to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
392 fgeometryFileName=((TObjString*)pTokens->At(i))->GetString();
395 else if (argument.CompareTo("-lowflux")==0) {
397 HLTInfo("Low flux reconstruction selected");
400 else if (argument.CompareTo("-highflux")==0) {
402 HLTInfo("High flux reconstruction selected");
405 else if (argument.CompareTo("-cosmics")==0) {
407 HLTInfo("Cosmics reconstruction selected");
410 else if (argument.CompareTo("-simulation")==0) {
412 HLTInfo("Awaiting simulated data");
415 else if (argument.CompareTo("-experiment")==0) {
417 HLTInfo("Awaiting real data");
420 else if (argument.CompareTo("-processTracklets")==0) {
421 fProcessTracklets = kTRUE;
422 HLTInfo("Writing L1 tracklets to output");
425 else if (argument.CompareTo("-noZS")==0) {
426 fOutputPercentage = 10;
427 HLTInfo("Awaiting non zero surpressed data");
430 else if (argument.CompareTo("-HLTflag")==0) {
431 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
432 TString toCompareTo=((TObjString*)pTokens->At(i))->GetString();
433 if (toCompareTo.CompareTo("yes")==0){
434 HLTInfo("Setting HLTflag to: %s", toCompareTo.Data());
437 else if (toCompareTo.CompareTo("no")==0){
438 HLTInfo("Setting HLTflag to: %s", toCompareTo.Data());
442 HLTError("unknown argument for HLTflag: %s", toCompareTo.Data());
448 else if (argument.CompareTo("-faststreamer")==0) {
449 fHLTstreamer = kTRUE;
450 HLTInfo("Useing fast raw streamer");
453 else if (argument.CompareTo("-nofaststreamer")==0) {
454 fHLTstreamer = kFALSE;
455 HLTInfo("Don't use fast raw streamer");
458 else if (argument.CompareTo("-tailcancellation")==0) {
460 HLTInfo("Useing tailcancellation");
463 else if (argument.CompareTo("-rawver")==0) {
464 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
465 HLTInfo("Raw data version is: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
466 fRawDataVersion=((TObjString*)pTokens->At(i))->GetString().Atoi();
469 else if (argument.CompareTo("-highLevelOutput")==0) {
470 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
471 TString toCompareTo=((TObjString*)pTokens->At(i))->GetString();
472 if (toCompareTo.CompareTo("yes")==0){
473 HLTWarning("Setting highLevelOutput to: %s", toCompareTo.Data());
474 fHighLevelOutput=kTRUE;
476 else if (toCompareTo.CompareTo("no")==0){
477 HLTInfo("Setting highLevelOutput to: %s", toCompareTo.Data());
478 fHighLevelOutput=kFALSE;
481 HLTError("unknown argument for highLevelOutput: %s", toCompareTo.Data());
487 else if (argument.CompareTo("-emulateHLToutput")==0) {
488 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
489 TString toCompareTo=((TObjString*)pTokens->At(i))->GetString();
490 if (toCompareTo.CompareTo("yes")==0){
491 HLTWarning("Setting emulateHLToutput to: %s", toCompareTo.Data());
492 fEmulateHLTClusters=kTRUE;
494 else if (toCompareTo.CompareTo("no")==0){
495 HLTInfo("Setting emulateHLToutput to: %s", toCompareTo.Data());
496 fEmulateHLTClusters=kFALSE;
499 HLTError("unknown argument for emulateHLToutput: %s", toCompareTo.Data());
505 else if (argument.CompareTo("-yPosMethod")==0) {
506 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
507 TString toCompareTo=((TObjString*)pTokens->At(i))->GetString();
508 if (toCompareTo.CompareTo("COG")==0){
509 HLTInfo("Setting yPosMethod method to: %s", toCompareTo.Data());
512 else if (toCompareTo.CompareTo("LUT")==0){
513 HLTInfo("Setting yPosMethod method to: %s", toCompareTo.Data());
516 else if (toCompareTo.CompareTo("Gauss")==0){
517 HLTInfo("Setting yPosMethod method to: %s", toCompareTo.Data());
521 HLTError("unknown argument for yPosMethod: %s", toCompareTo.Data());
529 HLTError("unknown argument: %s", argument.Data());
537 HLTError("missing parameter for argument %s", argument.Data());
546 int AliHLTTRDClusterizerComponent::SetParams()
549 if(!AliCDBManager::Instance()->IsDefaultStorageSet()){
550 HLTError("DefaultStorage is not set in CDBManager");
553 if(AliCDBManager::Instance()->GetRun()<0){
554 HLTError("Run Number is not set in CDBManager");
557 HLTInfo("CDB default storage: %s; RunNo: %i", (AliCDBManager::Instance()->GetDefaultStorage()->GetBaseFolder()).Data(), AliCDBManager::Instance()->GetRun());
559 if(!AliGeomManager::GetGeometry()){
560 if(fgeometryFileName.CompareTo("")==0 || !TFile::Open(fgeometryFileName.Data())){
561 HLTInfo("Loading standard geometry file");
562 AliGeomManager::LoadGeometry();
564 HLTWarning("Loading NON-standard geometry file");
565 AliGeomManager::LoadGeometry(fgeometryFileName.Data());
567 if(!AliGeomManager::GetGeometry()){
568 HLTError("Could not load geometry");
571 HLTInfo("Applying Alignment from CDB object");
572 AliGeomManager::ApplyAlignObjsFromCDB("TRD");
575 HLTInfo("Geometry Already Loaded!");
578 if(fReconstructor->GetRecoParam()){
579 fRecoParam = new AliTRDrecoParam(*fReconstructor->GetRecoParam());
580 HLTInfo("RecoParam already set!");
582 if(fRecoParamType == 0){
583 #ifndef HAVE_NOT_ALITRD_RECOPARAM_r41621
585 HLTInfo("Low flux HLT params init.");
586 fRecoParam = AliTRDrecoParam::GetLowFluxHLTParam();
590 HLTInfo("Low flux params init.");
591 fRecoParam = AliTRDrecoParam::GetLowFluxParam();
594 if(fRecoParamType == 1){
595 #ifndef HAVE_NOT_ALITRD_RECOPARAM_r41621
597 HLTInfo("High flux HLT params init.");
598 fRecoParam = AliTRDrecoParam::GetHighFluxHLTParam();
602 HLTInfo("High flux params init.");
603 fRecoParam = AliTRDrecoParam::GetHighFluxParam();
606 if(fRecoParamType == 2){
607 HLTInfo("Cosmic Test params init.");
608 fRecoParam = AliTRDrecoParam::GetCosmicTestParam();
614 HLTError("No reco params initialized. Sniffing big trouble!");
618 if(fTC){fRecoParam->SetTailCancelation(kTRUE); HLTDebug("Enableing Tail Cancelation"); }
619 else{fRecoParam->SetTailCancelation(kFALSE); HLTDebug("Disableing Tail Cancelation"); }
622 case 0: fRecoParam->SetGAUS(kFALSE); fRecoParam->SetLUT(kFALSE); break;
623 case 1: fRecoParam->SetGAUS(kFALSE); fRecoParam->SetLUT(kTRUE); break;
624 case 2: fRecoParam->SetGAUS(kTRUE); fRecoParam->SetLUT(kFALSE); break;
627 fRecoParam->SetStreamLevel(AliTRDrecoParam::kClusterizer, 0);
628 fReconstructor->SetRecoParam(fRecoParam);
630 TString recoOptions="!cw";
632 recoOptions += ",hlt";
633 if(fProcessTracklets) recoOptions += ",tp";
634 else recoOptions += ",!tp";
636 HLTDebug("Reconstructor options are: %s",recoOptions.Data());
637 fReconstructor->SetOption(recoOptions.Data());
639 if (fRecoDataType < 0 || fRecoDataType > 1)
641 HLTWarning("No data type selected. Use -simulation or -experiment flag. Defaulting to simulation.");
645 if (fRecoDataType == 0)
647 AliTRDrawStreamBase::SetRawStreamVersion(AliTRDrawStreamBase::kTRDsimStream);
648 HLTDebug("Data type expected is SIMULATION!");
651 if (fRecoDataType == 1)
653 AliTRDrawStreamBase::SetRawStreamVersion(AliTRDrawStreamBase::kTRDrealStream);
654 HLTDebug("Data type expected is EXPERIMENT!");
657 #ifndef HAVE_NOT_ALITRD_RAWSTREAM_r39608
659 AliTRDrawStreamBase::SetRawStreamVersion("default");
660 HLTDebug("fast rawstreamer used");
662 AliTRDrawStreamBase::SetRawStreamVersion("FAST");
663 HLTDebug("old rawstreamer used");
667 AliTRDrawStreamBase::SetRawStreamVersion("FAST");
668 HLTDebug("fast rawstreamer used");
673 fClusterizer = new AliHLTTRDClusterizer("TRDCclusterizer", "TRDCclusterizer");
674 HLTDebug("TRDClusterizer at 0x%x", fClusterizer);
677 fClusterizer->SetRawVersion(fRawDataVersion);
682 int AliHLTTRDClusterizerComponent::Reconfigure(const char* cdbEntry, const char* chainId)
684 // see header file for class documentation
687 const char* path="HLT/ConfigTRD/ClusterizerComponent";
688 const char* defaultNotify="";
691 defaultNotify=" (default)";
694 HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
695 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
697 TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
699 HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
700 iResult=Configure(pString->GetString().Data());
702 HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
705 HLTError("cannot fetch object \"%s\" from CDB", path);
712 void AliHLTTRDClusterizerComponent::GetOCDBObjectDescription(TMap* const targetMap){
713 // Get a list of OCDB object description needed for the particular component
714 if (!targetMap) return;
715 targetMap->Add(new TObjString("HLT/ConfigTRD/ClusterizerComponent"), new TObjString("component arguments"));
716 targetMap->Add(new TObjString("TRD/Calib/ChamberGainFactor"), new TObjString("gain factor of chambers"));
717 targetMap->Add(new TObjString("TRD/Calib/ChamberT0"), new TObjString("T0 of chambers"));
718 targetMap->Add(new TObjString("TRD/Calib/ChamberVdrift"), new TObjString("drift velocity of chambers"));
719 targetMap->Add(new TObjString("TRD/Calib/DetNoise"), new TObjString("noise of chambers"));
720 targetMap->Add(new TObjString("TRD/Calib/LocalGainFactor"), new TObjString("per pad gain factor"));
721 targetMap->Add(new TObjString("TRD/Calib/LocalT0"), new TObjString("per pad T0"));
722 targetMap->Add(new TObjString("TRD/Calib/LocalVdrift"), new TObjString("per pad drift velocity"));
723 targetMap->Add(new TObjString("TRD/Calib/PadNoise"), new TObjString("per pad noise"));
724 targetMap->Add(new TObjString("TRD/Calib/PadStatus"), new TObjString("pad status"));
725 targetMap->Add(new TObjString("TRD/Calib/PRFWidth"), new TObjString("pad response function"));