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 #ifdef HAVE_VALGRIND_CALLGRIND_H
211 if (evtData.fEventID == 10)
212 CALLGRIND_START_INSTRUMENTATION;
214 if(GetFirstInputBlock(kAliHLTDataTypeEOR))
215 CALLGRIND_STOP_INSTRUMENTATION;
218 if(!IsDataEvent())return 0;
220 HLTDebug( "NofBlocks %i", evtData.fBlockCnt );
222 AliHLTUInt32_t totalSize = 0, offset = 0;
224 //implement a usage of the following
225 // AliHLTUInt32_t triggerDataStructSize = trigData.fStructSize;
226 // AliHLTUInt32_t triggerDataSize = trigData.fDataSize;
227 // void *triggerData = trigData.fData;
228 //HLTDebug( "Trigger data received. Struct size %d Data size %d Data location 0x%x", trigData.fStructSize, trigData.fDataSize, (UInt_t*)trigData.fData);
230 // Loop over all input blocks in the event
231 AliHLTComponentDataType expectedDataType = (kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTRD);
232 for ( UInt_t iBlock = 0; iBlock < evtData.fBlockCnt; iBlock++ )
234 const AliHLTComponentBlockData &block = blocks[iBlock];
235 // lets not use the internal TRD data types here : AliHLTTRDDefinitions::fgkDDLRawDataType
236 // which is depreciated - we use HLT global defs instead
237 // if ( block.fDataType != (kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTRD) )
238 AliHLTComponentDataType inputDataType = block.fDataType;
239 if ( inputDataType != expectedDataType)
241 HLTDebug( "Block # %i/%i; Event 0x%08LX (%Lu) Wrong received datatype: %s - required datatype: %s; Skipping",
242 iBlock, evtData.fBlockCnt,
243 evtData.fEventID, evtData.fEventID,
244 DataType2Text(inputDataType).c_str(),
245 DataType2Text(expectedDataType).c_str());
250 HLTDebug("We get the right data type: Block # %i/%i; Event 0x%08LX (%Lu) Received datatype: %s; Block Size: %i",
251 iBlock, evtData.fBlockCnt,
252 evtData.fEventID, evtData.fEventID,
253 DataType2Text(inputDataType).c_str(),
258 unsigned long constBase;
259 double inputMultiplier;
260 GetOutputDataSize(constBase,inputMultiplier);
261 if(size<(constBase+block.fSize*inputMultiplier)){
262 HLTWarning("Memory Block given might be too small: %i < %i; Event %Lu", size, constBase+block.fSize*inputMultiplier, evtData.fEventID);
266 // fMemReader->Reset();
267 fMemReader->SetMemory((UChar_t*) block.fPtr, block.fSize);
269 AliHLTUInt32_t spec = block.fSpecification;
271 Int_t id = AliHLTTRDUtils::GetSM(spec) + 1024;
273 fMemReader->SetEquipmentID(id);
275 fClusterizer->SetMemBlock(outputPtr+offset);
276 Bool_t bclustered = fClusterizer->Raw2ClustersChamber(fMemReader);
279 HLTDebug("Clustered successfully");
283 HLTError("Clustering ERROR");
287 AliHLTUInt32_t addedSize;
288 if(fReconstructor->IsProcessingTracklets()){
289 addedSize = fClusterizer->GetAddedTrSize();
290 totalSize += fClusterizer->GetTrMemBlockSize(); //if IsProcessingTracklets() is enabled we always reserve a data block of size GetTrMemBlockSize() for the tracklets
292 // Using low-level interface
293 // with interface classes
294 if ( totalSize > size )
296 HLTError("Too much data; Data written over allowed buffer. Amount written: %lu, allowed amount: %lu.",
302 AliHLTComponentBlockData bd;
305 bd.fSize = addedSize;
306 bd.fSpecification = block.fSpecification;
307 bd.fDataType = AliHLTTRDDefinitions::fgkMCMtrackletDataType;
308 outputBlocks.push_back( bd );
309 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);
314 addedSize = fClusterizer->GetAddedClSize();
317 Int_t* nTimeBins = (Int_t*)(outputPtr+offset+fClusterizer->GetAddedClSize());
318 *nTimeBins = fClusterizer->GetNTimeBins();
319 addedSize += sizeof(*nTimeBins);
321 totalSize += addedSize;
322 if ( totalSize > size )
324 HLTError("Too much data; Data written over allowed buffer. Amount written: %lu, allowed amount: %lu.",
330 AliHLTComponentBlockData bd;
333 bd.fSize = addedSize;
334 bd.fSpecification = block.fSpecification;
335 bd.fDataType = AliHLTTRDDefinitions::fgkClusterDataType;
336 outputBlocks.push_back( bd );
337 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);
341 HLTDebug("Array of clusters is empty!");
344 fReconstructor->SetClusters(0x0);
347 HLTDebug("Event is done. size written to the output is %i", size);
351 void AliHLTTRDClusterizerComponent::PrintObject(
353 TClonesArray* inClustersArray
360 AliTRDcluster* cluster=0x0;
362 for (Int_t i=0; i < inClustersArray->GetEntriesFast(); i++){
363 cluster = dynamic_cast<AliTRDcluster*>(inClustersArray->At(i));
364 HLTDebug("cluster[%i]",i);
365 HLTDebug(" PadCol = %i; PadRow = %i; PadTime = %i", cluster->GetPadCol(), cluster->GetPadRow(), cluster->GetPadTime());
366 HLTDebug(" Detector = %i, Amplitude = %f, Center = %f", cluster->GetDetector(), cluster->GetQ(), cluster->GetCenter());
367 HLTDebug(" LocalTimeBin = %i; NPads = %i; maskedPosition: %s, status: %s", cluster->GetLocalTimeBin(), cluster->GetNPads(),cluster->GetPadMaskedPosition(),cluster->GetPadMaskedPosition());
372 int AliHLTTRDClusterizerComponent::Configure(const char* arguments){
374 if (!arguments) return iResult;
376 TString allArgs=arguments;
380 TObjArray* pTokens=allArgs.Tokenize(" ");
382 for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
383 argument=((TObjString*)pTokens->At(i))->GetString();
384 if (argument.IsNull()) continue;
386 if (argument.CompareTo("output_percentage")==0) {
387 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
388 HLTInfo("Setting output percentage to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
389 fOutputPercentage=((TObjString*)pTokens->At(i))->GetString().Atoi();
392 else if (argument.CompareTo("-geometry")==0) {
393 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
394 HLTInfo("Setting geometry to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
395 fgeometryFileName=((TObjString*)pTokens->At(i))->GetString();
398 else if (argument.CompareTo("-lowflux")==0) {
400 HLTInfo("Low flux reconstruction selected");
403 else if (argument.CompareTo("-highflux")==0) {
405 HLTInfo("High flux reconstruction selected");
408 else if (argument.CompareTo("-cosmics")==0) {
410 HLTInfo("Cosmics reconstruction selected");
413 else if (argument.CompareTo("-simulation")==0) {
415 HLTInfo("Awaiting simulated data");
418 else if (argument.CompareTo("-experiment")==0) {
420 HLTInfo("Awaiting real data");
423 else if (argument.CompareTo("-processTracklets")==0) {
424 fProcessTracklets = kTRUE;
425 HLTInfo("Writing L1 tracklets to output");
428 else if (argument.CompareTo("-noZS")==0) {
429 fOutputPercentage = 10;
430 HLTInfo("Awaiting non zero surpressed data");
433 else if (argument.CompareTo("-HLTflag")==0) {
434 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
435 TString toCompareTo=((TObjString*)pTokens->At(i))->GetString();
436 if (toCompareTo.CompareTo("yes")==0){
437 HLTInfo("Setting HLTflag to: %s", toCompareTo.Data());
440 else if (toCompareTo.CompareTo("no")==0){
441 HLTInfo("Setting HLTflag to: %s", toCompareTo.Data());
445 HLTError("unknown argument for HLTflag: %s", toCompareTo.Data());
451 else if (argument.CompareTo("-faststreamer")==0) {
452 fHLTstreamer = kTRUE;
453 HLTInfo("Useing fast raw streamer");
456 else if (argument.CompareTo("-nofaststreamer")==0) {
457 fHLTstreamer = kFALSE;
458 HLTInfo("Don't use fast raw streamer");
461 else if (argument.CompareTo("-tailcancellation")==0) {
463 HLTInfo("Useing tailcancellation");
466 else if (argument.CompareTo("-rawver")==0) {
467 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
468 HLTInfo("Raw data version is: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
469 fRawDataVersion=((TObjString*)pTokens->At(i))->GetString().Atoi();
472 else if (argument.CompareTo("-highLevelOutput")==0) {
473 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
474 TString toCompareTo=((TObjString*)pTokens->At(i))->GetString();
475 if (toCompareTo.CompareTo("yes")==0){
476 HLTWarning("Setting highLevelOutput to: %s", toCompareTo.Data());
477 fHighLevelOutput=kTRUE;
479 else if (toCompareTo.CompareTo("no")==0){
480 HLTInfo("Setting highLevelOutput to: %s", toCompareTo.Data());
481 fHighLevelOutput=kFALSE;
484 HLTError("unknown argument for highLevelOutput: %s", toCompareTo.Data());
490 else if (argument.CompareTo("-emulateHLToutput")==0) {
491 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
492 TString toCompareTo=((TObjString*)pTokens->At(i))->GetString();
493 if (toCompareTo.CompareTo("yes")==0){
494 HLTWarning("Setting emulateHLToutput to: %s", toCompareTo.Data());
495 fEmulateHLTClusters=kTRUE;
497 else if (toCompareTo.CompareTo("no")==0){
498 HLTInfo("Setting emulateHLToutput to: %s", toCompareTo.Data());
499 fEmulateHLTClusters=kFALSE;
502 HLTError("unknown argument for emulateHLToutput: %s", toCompareTo.Data());
508 else if (argument.CompareTo("-yPosMethod")==0) {
509 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
510 TString toCompareTo=((TObjString*)pTokens->At(i))->GetString();
511 if (toCompareTo.CompareTo("COG")==0){
512 HLTInfo("Setting yPosMethod method to: %s", toCompareTo.Data());
515 else if (toCompareTo.CompareTo("LUT")==0){
516 HLTInfo("Setting yPosMethod method to: %s", toCompareTo.Data());
519 else if (toCompareTo.CompareTo("Gauss")==0){
520 HLTInfo("Setting yPosMethod method to: %s", toCompareTo.Data());
524 HLTError("unknown argument for yPosMethod: %s", toCompareTo.Data());
532 HLTError("unknown argument: %s", argument.Data());
540 HLTError("missing parameter for argument %s", argument.Data());
549 int AliHLTTRDClusterizerComponent::SetParams()
552 if(!AliCDBManager::Instance()->IsDefaultStorageSet()){
553 HLTError("DefaultStorage is not set in CDBManager");
556 if(AliCDBManager::Instance()->GetRun()<0){
557 HLTError("Run Number is not set in CDBManager");
560 HLTInfo("CDB default storage: %s; RunNo: %i", (AliCDBManager::Instance()->GetDefaultStorage()->GetBaseFolder()).Data(), AliCDBManager::Instance()->GetRun());
562 if(!AliGeomManager::GetGeometry()){
563 if(fgeometryFileName.CompareTo("")==0 || !TFile::Open(fgeometryFileName.Data())){
564 HLTInfo("Loading standard geometry file");
565 AliGeomManager::LoadGeometry();
567 HLTWarning("Loading NON-standard geometry file");
568 AliGeomManager::LoadGeometry(fgeometryFileName.Data());
570 if(!AliGeomManager::GetGeometry()){
571 HLTError("Could not load geometry");
574 HLTInfo("Applying Alignment from CDB object");
575 AliGeomManager::ApplyAlignObjsFromCDB("TRD");
578 HLTInfo("Geometry Already Loaded!");
581 if(fReconstructor->GetRecoParam()){
582 fRecoParam = new AliTRDrecoParam(*fReconstructor->GetRecoParam());
583 HLTInfo("RecoParam already set!");
585 if(fRecoParamType == 0){
586 #ifndef HAVE_NOT_ALITRD_RECOPARAM_r41621
588 HLTInfo("Low flux HLT params init.");
589 fRecoParam = AliTRDrecoParam::GetLowFluxHLTParam();
593 HLTInfo("Low flux params init.");
594 fRecoParam = AliTRDrecoParam::GetLowFluxParam();
597 if(fRecoParamType == 1){
598 #ifndef HAVE_NOT_ALITRD_RECOPARAM_r41621
600 HLTInfo("High flux HLT params init.");
601 fRecoParam = AliTRDrecoParam::GetHighFluxHLTParam();
605 HLTInfo("High flux params init.");
606 fRecoParam = AliTRDrecoParam::GetHighFluxParam();
609 if(fRecoParamType == 2){
610 HLTInfo("Cosmic Test params init.");
611 fRecoParam = AliTRDrecoParam::GetCosmicTestParam();
617 HLTError("No reco params initialized. Sniffing big trouble!");
621 if(fTC){fRecoParam->SetTailCancelation(kTRUE); HLTDebug("Enableing Tail Cancelation"); }
622 else{fRecoParam->SetTailCancelation(kFALSE); HLTDebug("Disableing Tail Cancelation"); }
625 case 0: fRecoParam->SetGAUS(kFALSE); fRecoParam->SetLUT(kFALSE); break;
626 case 1: fRecoParam->SetGAUS(kFALSE); fRecoParam->SetLUT(kTRUE); break;
627 case 2: fRecoParam->SetGAUS(kTRUE); fRecoParam->SetLUT(kFALSE); break;
630 fRecoParam->SetStreamLevel(AliTRDrecoParam::kClusterizer, 0);
631 fReconstructor->SetRecoParam(fRecoParam);
633 TString recoOptions="!cw";
635 recoOptions += ",hlt";
636 if(fProcessTracklets) recoOptions += ",tp";
637 else recoOptions += ",!tp";
639 HLTDebug("Reconstructor options are: %s",recoOptions.Data());
640 fReconstructor->SetOption(recoOptions.Data());
642 if (fRecoDataType < 0 || fRecoDataType > 1)
644 HLTWarning("No data type selected. Use -simulation or -experiment flag. Defaulting to simulation.");
648 if (fRecoDataType == 0)
650 AliTRDrawStreamBase::SetRawStreamVersion(AliTRDrawStreamBase::kTRDsimStream);
651 HLTDebug("Data type expected is SIMULATION!");
654 if (fRecoDataType == 1)
656 AliTRDrawStreamBase::SetRawStreamVersion(AliTRDrawStreamBase::kTRDrealStream);
657 HLTDebug("Data type expected is EXPERIMENT!");
660 #ifndef HAVE_NOT_ALITRD_RAWSTREAM_r39608
662 AliTRDrawStreamBase::SetRawStreamVersion("default");
663 HLTDebug("fast rawstreamer used");
665 AliTRDrawStreamBase::SetRawStreamVersion("FAST");
666 HLTDebug("old rawstreamer used");
670 AliTRDrawStreamBase::SetRawStreamVersion("FAST");
671 HLTDebug("fast rawstreamer used");
676 fClusterizer = new AliHLTTRDClusterizer("TRDCclusterizer", "TRDCclusterizer");
677 HLTDebug("TRDClusterizer at 0x%x", fClusterizer);
680 fClusterizer->SetRawVersion(fRawDataVersion);
685 int AliHLTTRDClusterizerComponent::Reconfigure(const char* cdbEntry, const char* chainId)
687 // see header file for class documentation
690 const char* path="HLT/ConfigTRD/ClusterizerComponent";
691 const char* defaultNotify="";
694 defaultNotify=" (default)";
697 HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
698 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
700 TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
702 HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
703 iResult=Configure(pString->GetString().Data());
705 HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
708 HLTError("cannot fetch object \"%s\" from CDB", path);
715 void AliHLTTRDClusterizerComponent::GetOCDBObjectDescription(TMap* const targetMap){
716 // Get a list of OCDB object description needed for the particular component
717 if (!targetMap) return;
718 targetMap->Add(new TObjString("HLT/ConfigTRD/ClusterizerComponent"), new TObjString("component arguments"));
719 targetMap->Add(new TObjString("TRD/Calib/ChamberGainFactor"), new TObjString("gain factor of chambers"));
720 targetMap->Add(new TObjString("TRD/Calib/ChamberT0"), new TObjString("T0 of chambers"));
721 targetMap->Add(new TObjString("TRD/Calib/ChamberVdrift"), new TObjString("drift velocity of chambers"));
722 targetMap->Add(new TObjString("TRD/Calib/DetNoise"), new TObjString("noise of chambers"));
723 targetMap->Add(new TObjString("TRD/Calib/LocalGainFactor"), new TObjString("per pad gain factor"));
724 targetMap->Add(new TObjString("TRD/Calib/LocalT0"), new TObjString("per pad T0"));
725 targetMap->Add(new TObjString("TRD/Calib/LocalVdrift"), new TObjString("per pad drift velocity"));
726 targetMap->Add(new TObjString("TRD/Calib/PadNoise"), new TObjString("per pad noise"));
727 targetMap->Add(new TObjString("TRD/Calib/PadStatus"), new TObjString("pad status"));
728 targetMap->Add(new TObjString("TRD/Calib/PRFWidth"), new TObjString("pad response function"));