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 //
35 #include "AliHLTTRDClusterizerComponent.h"
36 #include "AliHLTTRDDefinitions.h"
37 #include "AliHLTTRDClusterizer.h"
38 #include "AliHLTTRDUtils.h"
40 #include "AliGeomManager.h"
41 #include "AliTRDReconstructor.h"
42 #include "AliCDBManager.h"
43 #include "AliCDBStorage.h"
44 #include "AliCDBEntry.h"
45 #include "AliTRDrecoParam.h"
46 #include "AliTRDrawStream.h"
47 #include "AliTRDcluster.h"
49 #include "AliRawReaderMemory.h"
51 #ifdef HAVE_VALGRIND_CALLGRIND_H
52 #include <valgrind/callgrind.h>
54 #define CALLGRIND_START_INSTRUMENTATION (void)0
55 #define CALLGRIND_STOP_INSTRUMENTATION (void)0
64 ClassImp(AliHLTTRDClusterizerComponent)
66 AliHLTTRDClusterizerComponent::AliHLTTRDClusterizerComponent()
68 fOutputPercentage(100),
78 fgeometryFileName(""),
79 fProcessTracklets(kFALSE),
83 fHighLevelOutput(kFALSE),
84 fEmulateHLTClusters(kFALSE)
86 // Default constructor
90 AliHLTTRDClusterizerComponent::~AliHLTTRDClusterizerComponent()
93 // Work is Done in DoDeInit()
97 const char* AliHLTTRDClusterizerComponent::GetComponentID()
99 // Return the component ID const char *
100 return "TRDClusterizer"; // The ID of this component
103 void AliHLTTRDClusterizerComponent::GetInputDataTypes( vector<AliHLTComponent_DataType>& list)
105 // Get the list of input data
106 list.clear(); // We do not have any requirements for our input data type(s).
107 list.push_back(kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTRD);
110 AliHLTComponentDataType AliHLTTRDClusterizerComponent::GetOutputDataType()
112 // Get the output data type
113 return kAliHLTMultipleDataType;
116 int AliHLTTRDClusterizerComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList)
118 // Get the output data type
120 tgtList.push_back(AliHLTTRDDefinitions::fgkClusterDataType);
121 tgtList.push_back(AliHLTTRDDefinitions::fgkMCMtrackletDataType);
122 return tgtList.size();
126 void AliHLTTRDClusterizerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
128 // Get the output data size
129 constBase = fOutputConst;
130 inputMultiplier = ((double)fOutputPercentage)*4/100.0;
133 AliHLTComponent* AliHLTTRDClusterizerComponent::Spawn()
135 // Spawn function, return new instance of this class
136 return new AliHLTTRDClusterizerComponent;
139 int AliHLTTRDClusterizerComponent::DoInit( int argc, const char** argv )
141 // perform initialization. We check whether our relative output size is specified in the arguments.
144 fReconstructor = new AliTRDReconstructor();
145 HLTDebug("TRDReconstructor at 0x%x", fReconstructor);
147 TString configuration="";
149 for (int i=0; i<argc && iResult>=0; i++) {
151 if (!configuration.IsNull()) configuration+=" ";
152 configuration+=argument;
155 if (!configuration.IsNull()) {
156 iResult=Configure(configuration.Data());
158 iResult=Reconfigure(NULL, NULL);
162 HLTFatal("Clusterizer was not initialized!");
166 if(iResult<0) return iResult;
168 fMemReader = new AliRawReaderMemory;
169 fClusterizer->SetReconstructor(fReconstructor);
170 fClusterizer->SetUseLabels(kFALSE);
172 if(fReconstructor->IsProcessingTracklets())
173 fOutputConst = fClusterizer->GetTrMemBlockSize();
178 int AliHLTTRDClusterizerComponent::DoDeinit()
180 // Deinitialization of the component
186 //fReconstructor->SetClusters(0x0);
187 delete fReconstructor;
188 fReconstructor = 0x0;
192 HLTDebug("Deleting fRecoParam");
200 int AliHLTTRDClusterizerComponent::DoEvent( const AliHLTComponentEventData& evtData,
201 const AliHLTComponentBlockData* blocks,
202 AliHLTComponent_TriggerData& /*trigData*/,
203 AliHLTUInt8_t* outputPtr,
204 AliHLTUInt32_t& size,
205 vector<AliHLTComponent_BlockData>& outputBlocks )
209 #ifdef HAVE_VALGRIND_CALLGRIND_H
210 if (evtData.fEventID == 10)
211 CALLGRIND_START_INSTRUMENTATION;
213 if(GetFirstInputBlock(kAliHLTDataTypeEOR))
214 CALLGRIND_STOP_INSTRUMENTATION;
217 if(!IsDataEvent())return 0;
219 HLTDebug( "NofBlocks %i", evtData.fBlockCnt );
221 AliHLTUInt32_t totalSize = 0, offset = 0;
223 //implement a usage of the following
224 // AliHLTUInt32_t triggerDataStructSize = trigData.fStructSize;
225 // AliHLTUInt32_t triggerDataSize = trigData.fDataSize;
226 // void *triggerData = trigData.fData;
227 //HLTDebug( "Trigger data received. Struct size %d Data size %d Data location 0x%x", trigData.fStructSize, trigData.fDataSize, (UInt_t*)trigData.fData);
229 // Loop over all input blocks in the event
230 AliHLTComponentDataType expectedDataType = (kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTRD);
231 for ( UInt_t iBlock = 0; iBlock < evtData.fBlockCnt; iBlock++ )
233 const AliHLTComponentBlockData &block = blocks[iBlock];
234 // lets not use the internal TRD data types here : AliHLTTRDDefinitions::fgkDDLRawDataType
235 // which is depreciated - we use HLT global defs instead
236 // if ( block.fDataType != (kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTRD) )
237 AliHLTComponentDataType inputDataType = block.fDataType;
238 if ( inputDataType != expectedDataType)
240 HLTDebug( "Block # %i/%i; Event 0x%08LX (%Lu) Wrong received datatype: %s - required datatype: %s; Skipping",
241 iBlock, evtData.fBlockCnt,
242 evtData.fEventID, evtData.fEventID,
243 DataType2Text(inputDataType).c_str(),
244 DataType2Text(expectedDataType).c_str());
249 HLTDebug("We get the right data type: Block # %i/%i; Event 0x%08LX (%Lu) Received datatype: %s; Block Size: %i",
250 iBlock, evtData.fBlockCnt,
251 evtData.fEventID, evtData.fEventID,
252 DataType2Text(inputDataType).c_str(),
257 unsigned long constBase;
258 double inputMultiplier;
259 GetOutputDataSize(constBase,inputMultiplier);
260 if(size<(constBase+block.fSize*inputMultiplier)){
261 HLTWarning("Memory Block given might be too small: %i < %i; Event %Lu", size, constBase+block.fSize*inputMultiplier, evtData.fEventID);
265 // fMemReader->Reset();
266 fMemReader->SetMemory((UChar_t*) block.fPtr, block.fSize);
268 AliHLTUInt32_t spec = block.fSpecification;
270 Int_t id = AliHLTTRDUtils::GetSM(spec) + 1024;
272 fMemReader->SetEquipmentID(id);
274 fClusterizer->SetMemBlock(outputPtr+offset);
275 Bool_t bclustered = fClusterizer->Raw2ClustersChamber(fMemReader);
278 HLTDebug("Clustered successfully");
282 HLTError("Clustering ERROR");
286 AliHLTUInt32_t addedSize;
287 if(fReconstructor->IsProcessingTracklets()){
288 addedSize = fClusterizer->GetAddedTrSize();
289 totalSize += fClusterizer->GetTrMemBlockSize(); //if IsProcessingTracklets() is enabled we always reserve a data block of size GetTrMemBlockSize() for the tracklets
291 // Using low-level interface
292 // with interface classes
293 if ( totalSize > size )
295 HLTError("Too much data; Data written over allowed buffer. Amount written: %lu, allowed amount: %lu.",
301 AliHLTComponentBlockData bd;
304 bd.fSize = addedSize;
305 bd.fSpecification = block.fSpecification;
306 bd.fDataType = AliHLTTRDDefinitions::fgkMCMtrackletDataType;
307 outputBlocks.push_back( bd );
308 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);
313 addedSize = fClusterizer->GetAddedClSize();
316 Int_t* nTimeBins = (Int_t*)(outputPtr+offset+fClusterizer->GetAddedClSize());
317 *nTimeBins = fClusterizer->GetNTimeBins();
318 addedSize += sizeof(*nTimeBins);
320 totalSize += addedSize;
321 if ( totalSize > size )
323 HLTError("Too much data; Data written over allowed buffer. Amount written: %lu, allowed amount: %lu.",
329 AliHLTComponentBlockData bd;
332 bd.fSize = addedSize;
333 bd.fSpecification = block.fSpecification;
334 bd.fDataType = AliHLTTRDDefinitions::fgkClusterDataType;
335 outputBlocks.push_back( bd );
336 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);
340 HLTDebug("Array of clusters is empty!");
343 //fReconstructor->SetClusters(0x0);
346 HLTDebug("Event is done. size written to the output is %i", size);
350 void AliHLTTRDClusterizerComponent::PrintObject(
352 TClonesArray* inClustersArray
359 AliTRDcluster* cluster=0x0;
361 for (Int_t i=0; i < inClustersArray->GetEntriesFast(); i++){
362 cluster = dynamic_cast<AliTRDcluster*>(inClustersArray->At(i));
363 HLTDebug("cluster[%i]",i);
364 HLTDebug(" PadCol = %i; PadRow = %i; PadTime = %i", cluster->GetPadCol(), cluster->GetPadRow(), cluster->GetPadTime());
365 HLTDebug(" Detector = %i, Amplitude = %f, Center = %f", cluster->GetDetector(), cluster->GetQ(), cluster->GetCenter());
366 HLTDebug(" LocalTimeBin = %i; NPads = %i; maskedPosition: %s, status: %s", cluster->GetLocalTimeBin(), cluster->GetNPads(),cluster->GetPadMaskedPosition(),cluster->GetPadMaskedPosition());
371 int AliHLTTRDClusterizerComponent::Configure(const char* arguments){
373 if (!arguments) return iResult;
375 TString allArgs=arguments;
379 TObjArray* pTokens=allArgs.Tokenize(" ");
381 for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
382 argument=((TObjString*)pTokens->At(i))->GetString();
383 if (argument.IsNull()) continue;
385 if (argument.CompareTo("output_percentage")==0) {
386 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
387 HLTInfo("Setting output percentage to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
388 fOutputPercentage=((TObjString*)pTokens->At(i))->GetString().Atoi();
391 else if (argument.CompareTo("-geometry")==0) {
392 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
393 HLTInfo("Setting geometry to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
394 fgeometryFileName=((TObjString*)pTokens->At(i))->GetString();
397 else if (argument.CompareTo("-lowflux")==0) {
399 HLTInfo("Low flux reconstruction selected");
402 else if (argument.CompareTo("-highflux")==0) {
404 HLTInfo("High flux reconstruction selected");
407 else if (argument.CompareTo("-cosmics")==0) {
409 HLTInfo("Cosmics reconstruction selected");
412 else if (argument.CompareTo("-simulation")==0) {
414 HLTInfo("Awaiting simulated data");
417 else if (argument.CompareTo("-experiment")==0) {
419 HLTInfo("Awaiting real data");
422 else if (argument.CompareTo("-processTracklets")==0) {
423 fProcessTracklets = kTRUE;
424 HLTInfo("Writing L1 tracklets to output");
427 else if (argument.CompareTo("-noZS")==0) {
428 fOutputPercentage = 10;
429 HLTInfo("Awaiting non zero surpressed data");
432 else if (argument.CompareTo("-HLTflag")==0) {
433 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
434 TString toCompareTo=((TObjString*)pTokens->At(i))->GetString();
435 if (toCompareTo.CompareTo("yes")==0){
436 HLTInfo("Setting HLTflag to: %s", toCompareTo.Data());
439 else if (toCompareTo.CompareTo("no")==0){
440 HLTInfo("Setting HLTflag to: %s", toCompareTo.Data());
444 HLTError("unknown argument for HLTflag: %s", toCompareTo.Data());
450 else if (argument.CompareTo("-faststreamer")==0) {
451 fHLTstreamer = kTRUE;
452 HLTInfo("Useing fast raw streamer");
455 else if (argument.CompareTo("-nofaststreamer")==0) {
456 fHLTstreamer = kFALSE;
457 HLTInfo("Don't use fast raw streamer");
460 else if (argument.CompareTo("-tailcancellation")==0) {
462 HLTInfo("Useing tailcancellation");
465 else if (argument.CompareTo("-rawver")==0) {
466 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
467 HLTInfo("Raw data version is: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
468 fRawDataVersion=((TObjString*)pTokens->At(i))->GetString().Atoi();
471 else if (argument.CompareTo("-highLevelOutput")==0) {
472 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
473 TString toCompareTo=((TObjString*)pTokens->At(i))->GetString();
474 if (toCompareTo.CompareTo("yes")==0){
475 HLTWarning("Setting highLevelOutput to: %s", toCompareTo.Data());
476 fHighLevelOutput=kTRUE;
478 else if (toCompareTo.CompareTo("no")==0){
479 HLTInfo("Setting highLevelOutput to: %s", toCompareTo.Data());
480 fHighLevelOutput=kFALSE;
483 HLTError("unknown argument for highLevelOutput: %s", toCompareTo.Data());
489 else if (argument.CompareTo("-emulateHLToutput")==0) {
490 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
491 TString toCompareTo=((TObjString*)pTokens->At(i))->GetString();
492 if (toCompareTo.CompareTo("yes")==0){
493 HLTWarning("Setting emulateHLToutput to: %s", toCompareTo.Data());
494 fEmulateHLTClusters=kTRUE;
496 else if (toCompareTo.CompareTo("no")==0){
497 HLTInfo("Setting emulateHLToutput to: %s", toCompareTo.Data());
498 fEmulateHLTClusters=kFALSE;
501 HLTError("unknown argument for emulateHLToutput: %s", toCompareTo.Data());
507 else if (argument.CompareTo("-yPosMethod")==0) {
508 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
509 TString toCompareTo=((TObjString*)pTokens->At(i))->GetString();
510 if (toCompareTo.CompareTo("COG")==0){
511 HLTInfo("Setting yPosMethod method to: %s", toCompareTo.Data());
514 else if (toCompareTo.CompareTo("LUT")==0){
515 HLTInfo("Setting yPosMethod method to: %s", toCompareTo.Data());
518 else if (toCompareTo.CompareTo("Gauss")==0){
519 HLTInfo("Setting yPosMethod method to: %s", toCompareTo.Data());
523 HLTError("unknown argument for yPosMethod: %s", toCompareTo.Data());
531 HLTError("unknown argument: %s", argument.Data());
539 HLTError("missing parameter for argument %s", argument.Data());
548 int AliHLTTRDClusterizerComponent::SetParams()
551 if(!AliCDBManager::Instance()->IsDefaultStorageSet()){
552 HLTError("DefaultStorage is not set in CDBManager");
555 if(AliCDBManager::Instance()->GetRun()<0){
556 HLTError("Run Number is not set in CDBManager");
559 HLTInfo("CDB default storage: %s; RunNo: %i", (AliCDBManager::Instance()->GetDefaultStorage()->GetBaseFolder()).Data(), AliCDBManager::Instance()->GetRun());
561 if(!AliGeomManager::GetGeometry()){
562 if(fgeometryFileName.CompareTo("")==0 || !TFile::Open(fgeometryFileName.Data())){
563 HLTInfo("Loading standard geometry file");
564 AliGeomManager::LoadGeometry();
566 HLTWarning("Loading NON-standard geometry file");
567 AliGeomManager::LoadGeometry(fgeometryFileName.Data());
569 if(!AliGeomManager::GetGeometry()){
570 HLTError("Could not load geometry");
573 HLTInfo("Applying Alignment from CDB object");
574 AliGeomManager::ApplyAlignObjsFromCDB("TRD");
577 HLTInfo("Geometry Already Loaded!");
580 if(fReconstructor->GetRecoParam()){
581 fRecoParam = new AliTRDrecoParam(*fReconstructor->GetRecoParam());
582 HLTInfo("RecoParam already set!");
584 if(fRecoParamType == 0){
585 #ifndef HAVE_NOT_ALITRD_RECOPARAM_r41621
587 HLTInfo("Low flux HLT params init.");
588 fRecoParam = AliTRDrecoParam::GetLowFluxHLTParam();
592 HLTInfo("Low flux params init.");
593 fRecoParam = AliTRDrecoParam::GetLowFluxParam();
596 if(fRecoParamType == 1){
597 #ifndef HAVE_NOT_ALITRD_RECOPARAM_r41621
599 HLTInfo("High flux HLT params init.");
600 fRecoParam = AliTRDrecoParam::GetHighFluxHLTParam();
604 HLTInfo("High flux params init.");
605 fRecoParam = AliTRDrecoParam::GetHighFluxParam();
608 if(fRecoParamType == 2){
609 HLTInfo("Cosmic Test params init.");
610 fRecoParam = AliTRDrecoParam::GetCosmicTestParam();
616 HLTError("No reco params initialized. Sniffing big trouble!");
620 if(fTC){fRecoParam->SetTailCancelation(kTRUE); HLTDebug("Enableing Tail Cancelation"); }
621 else{fRecoParam->SetTailCancelation(kFALSE); HLTDebug("Disableing Tail Cancelation"); }
624 case 0: fRecoParam->SetGAUS(kFALSE); fRecoParam->SetLUT(kFALSE); break;
625 case 1: fRecoParam->SetGAUS(kFALSE); fRecoParam->SetLUT(kTRUE); break;
626 case 2: fRecoParam->SetGAUS(kTRUE); fRecoParam->SetLUT(kFALSE); break;
629 fRecoParam->SetStreamLevel(AliTRDrecoParam::kClusterizer, 0);
630 fReconstructor->SetRecoParam(fRecoParam);
633 fClusterizer = new AliHLTTRDClusterizer("TRDCclusterizer", "TRDCclusterizer");
634 HLTDebug("TRDClusterizer at 0x%x", fClusterizer);
637 TString recoOptions="!cw";
639 recoOptions += ",hlt";
641 // we transfer clusters that do no contain the XYZ coodrinates (AliHLTTRDCluster),
642 // thus this coordinate transformation ist useless
643 #ifndef HAVE_NOT_ALITRD_CLUSTERIZER_r42837
644 fClusterizer->SetSkipTransform();
647 if(fProcessTracklets) recoOptions += ",tp";
648 else recoOptions += ",!tp";
650 HLTDebug("Reconstructor options are: %s",recoOptions.Data());
651 fReconstructor->SetOption(recoOptions.Data());
653 if (fRecoDataType < 0 || fRecoDataType > 1)
655 HLTWarning("No data type selected. Use -simulation or -experiment flag. Defaulting to simulation.");
659 if (fRecoDataType == 0)
661 HLTDebug("Data type expected is SIMULATION!");
664 if (fRecoDataType == 1)
666 HLTDebug("Data type expected is EXPERIMENT!");
669 fClusterizer->SetRawVersion(fRawDataVersion);
674 int AliHLTTRDClusterizerComponent::Reconfigure(const char* cdbEntry, const char* chainId)
676 // see header file for class documentation
679 const char* path="HLT/ConfigTRD/ClusterizerComponent";
680 const char* defaultNotify="";
683 defaultNotify=" (default)";
686 HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
687 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
689 TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
691 HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
692 iResult=Configure(pString->GetString().Data());
694 HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
697 HLTError("cannot fetch object \"%s\" from CDB", path);
704 void AliHLTTRDClusterizerComponent::GetOCDBObjectDescription(TMap* const targetMap){
705 // Get a list of OCDB object description needed for the particular component
706 if (!targetMap) return;
707 targetMap->Add(new TObjString("HLT/ConfigTRD/ClusterizerComponent"), new TObjString("component arguments"));
708 targetMap->Add(new TObjString("TRD/Calib/ChamberGainFactor"), new TObjString("gain factor of chambers"));
709 targetMap->Add(new TObjString("TRD/Calib/ChamberT0"), new TObjString("T0 of chambers"));
710 targetMap->Add(new TObjString("TRD/Calib/ChamberVdrift"), new TObjString("drift velocity of chambers"));
711 targetMap->Add(new TObjString("TRD/Calib/DetNoise"), new TObjString("noise of chambers"));
712 targetMap->Add(new TObjString("TRD/Calib/LocalGainFactor"), new TObjString("per pad gain factor"));
713 targetMap->Add(new TObjString("TRD/Calib/LocalT0"), new TObjString("per pad T0"));
714 targetMap->Add(new TObjString("TRD/Calib/LocalVdrift"), new TObjString("per pad drift velocity"));
715 targetMap->Add(new TObjString("TRD/Calib/PadNoise"), new TObjString("per pad noise"));
716 targetMap->Add(new TObjString("TRD/Calib/PadStatus"), new TObjString("pad status"));
717 targetMap->Add(new TObjString("TRD/Calib/PRFWidth"), new TObjString("pad response function"));