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"
43 #include "AliGeomManager.h"
44 #include "AliTRDReconstructor.h"
45 #include "AliCDBManager.h"
46 #include "AliCDBStorage.h"
47 #include "AliCDBEntry.h"
48 #include "AliTRDrecoParam.h"
49 #include "AliTRDrawStreamBase.h"
50 #include "AliTRDcluster.h"
52 #include "AliRawReaderMemory.h"
54 #ifdef HAVE_VALGRIND_CALLGRIND_H
55 #include <valgrind/callgrind.h>
57 #define CALLGRIND_START_INSTRUMENTATION (void)0
58 #define CALLGRIND_STOP_INSTRUMENTATION (void)0
65 #include "AliTRDrawStream.h"
66 #include "AliTRDrawFastStream.h"
68 ClassImp(AliHLTTRDClusterizerComponent)
70 AliHLTTRDClusterizerComponent::AliHLTTRDClusterizerComponent()
72 fOutputPercentage(100),
82 fgeometryFileName(""),
83 fProcessTracklets(kFALSE),
87 fHighLevelOutput(kFALSE),
88 fEmulateHLTClusters(kFALSE)
90 // Default constructor
94 AliHLTTRDClusterizerComponent::~AliHLTTRDClusterizerComponent()
97 // Work is Done in DoDeInit()
101 const char* AliHLTTRDClusterizerComponent::GetComponentID()
103 // Return the component ID const char *
104 return "TRDClusterizer"; // The ID of this component
107 void AliHLTTRDClusterizerComponent::GetInputDataTypes( vector<AliHLTComponent_DataType>& list)
109 // Get the list of input data
110 list.clear(); // We do not have any requirements for our input data type(s).
111 list.push_back(kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTRD);
114 AliHLTComponentDataType AliHLTTRDClusterizerComponent::GetOutputDataType()
116 // Get the output data type
117 return kAliHLTMultipleDataType;
120 int AliHLTTRDClusterizerComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList)
122 // Get the output data type
124 tgtList.push_back(AliHLTTRDDefinitions::fgkClusterDataType);
125 tgtList.push_back(AliHLTTRDDefinitions::fgkMCMtrackletDataType);
126 return tgtList.size();
130 void AliHLTTRDClusterizerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
132 // Get the output data size
133 constBase = fOutputConst;
134 inputMultiplier = ((double)fOutputPercentage)*4/100.0;
137 AliHLTComponent* AliHLTTRDClusterizerComponent::Spawn()
139 // Spawn function, return new instance of this class
140 return new AliHLTTRDClusterizerComponent;
143 int AliHLTTRDClusterizerComponent::DoInit( int argc, const char** argv )
145 // perform initialization. We check whether our relative output size is specified in the arguments.
148 fReconstructor = new AliTRDReconstructor();
149 HLTDebug("TRDReconstructor at 0x%x", fReconstructor);
151 TString configuration="";
153 for (int i=0; i<argc && iResult>=0; i++) {
155 if (!configuration.IsNull()) configuration+=" ";
156 configuration+=argument;
159 if (!configuration.IsNull()) {
160 iResult=Configure(configuration.Data());
162 iResult=Reconfigure(NULL, NULL);
166 HLTFatal("Clusterizer was not initialized!");
170 if(iResult<0) return iResult;
172 fMemReader = new AliRawReaderMemory;
173 fClusterizer->SetReconstructor(fReconstructor);
174 fClusterizer->SetUseLabels(kFALSE);
176 if(fReconstructor->IsProcessingTracklets())
177 fOutputConst = fClusterizer->GetTrMemBlockSize();
182 int AliHLTTRDClusterizerComponent::DoDeinit()
184 // Deinitialization of the component
190 fReconstructor->SetClusters(0x0);
191 delete fReconstructor;
192 fReconstructor = 0x0;
197 HLTDebug("Deleting fRecoParam");
203 int AliHLTTRDClusterizerComponent::DoEvent( const AliHLTComponentEventData& evtData,
204 const AliHLTComponentBlockData* blocks,
205 AliHLTComponent_TriggerData& /*trigData*/,
206 AliHLTUInt8_t* outputPtr,
207 AliHLTUInt32_t& size,
208 vector<AliHLTComponent_BlockData>& outputBlocks )
212 if (evtData.fEventID == 10)
213 CALLGRIND_START_INSTRUMENTATION;
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;
270 for ( Int_t ii = 0; ii < 18 ; ii++ ) {
278 fMemReader->SetEquipmentID( id );
280 fClusterizer->SetMemBlock(outputPtr+offset);
281 Bool_t bclustered = fClusterizer->Raw2ClustersChamber(fMemReader);
284 HLTDebug("Clustered successfully");
288 HLTError("Clustering ERROR");
292 AliHLTUInt32_t addedSize;
293 if(fReconstructor->IsProcessingTracklets()){
294 addedSize = fClusterizer->GetAddedTrSize();
295 totalSize += fClusterizer->GetTrMemBlockSize(); //if IsProcessingTracklets() is enabled we always reserve a data block of size GetTrMemBlockSize() for the tracklets
297 // Using low-level interface
298 // with interface classes
299 if ( totalSize > size )
301 HLTError("Too much data; Data written over allowed buffer. Amount written: %lu, allowed amount: %lu.",
307 AliHLTComponentBlockData bd;
310 bd.fSize = addedSize;
311 bd.fSpecification = block.fSpecification;
312 bd.fDataType = AliHLTTRDDefinitions::fgkMCMtrackletDataType;
313 outputBlocks.push_back( bd );
314 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);
319 addedSize = fClusterizer->GetAddedClSize();
322 Int_t* nTimeBins = (Int_t*)(outputPtr+offset+fClusterizer->GetAddedClSize());
323 *nTimeBins = fClusterizer->GetNTimeBins();
324 addedSize += sizeof(*nTimeBins);
326 totalSize += addedSize;
327 if ( totalSize > size )
329 HLTError("Too much data; Data written over allowed buffer. Amount written: %lu, allowed amount: %lu.",
335 AliHLTComponentBlockData bd;
338 bd.fSize = addedSize;
339 bd.fSpecification = block.fSpecification;
340 bd.fDataType = AliHLTTRDDefinitions::fgkClusterDataType;
341 outputBlocks.push_back( bd );
342 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);
346 HLTDebug("Array of clusters is empty!");
349 fReconstructor->SetClusters(0x0);
352 HLTDebug("Event is done. size written to the output is %i", size);
356 void AliHLTTRDClusterizerComponent::PrintObject( TClonesArray* inClustersArray)
358 AliTRDcluster* cluster=0x0;
360 for (Int_t i=0; i < inClustersArray->GetEntriesFast(); i++){
361 cluster = dynamic_cast<AliTRDcluster*>(inClustersArray->At(i));
362 HLTDebug("cluster[%i]",i);
363 HLTDebug(" PadCol = %i; PadRow = %i; PadTime = %i", cluster->GetPadCol(), cluster->GetPadRow(), cluster->GetPadTime());
364 HLTDebug(" Detector = %i, Amplitude = %f, Center = %f", cluster->GetDetector(), cluster->GetQ(), cluster->GetCenter());
365 HLTDebug(" LocalTimeBin = %i; NPads = %i; maskedPosition: %s, status: %s", cluster->GetLocalTimeBin(), cluster->GetNPads(),cluster->GetPadMaskedPosition(),cluster->GetPadMaskedPosition());
370 int AliHLTTRDClusterizerComponent::Configure(const char* arguments){
372 if (!arguments) return iResult;
374 TString allArgs=arguments;
378 TObjArray* pTokens=allArgs.Tokenize(" ");
380 for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
381 argument=((TObjString*)pTokens->At(i))->GetString();
382 if (argument.IsNull()) continue;
384 if (argument.CompareTo("output_percentage")==0) {
385 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
386 HLTInfo("Setting output percentage to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
387 fOutputPercentage=((TObjString*)pTokens->At(i))->GetString().Atoi();
390 else if (argument.CompareTo("-geometry")==0) {
391 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
392 HLTInfo("Setting geometry to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
393 fgeometryFileName=((TObjString*)pTokens->At(i))->GetString();
396 else if (argument.CompareTo("-lowflux")==0) {
398 HLTInfo("Low flux reconstruction selected");
401 else if (argument.CompareTo("-highflux")==0) {
403 HLTInfo("High flux reconstruction selected");
406 else if (argument.CompareTo("-cosmics")==0) {
408 HLTInfo("Cosmics reconstruction selected");
411 else if (argument.CompareTo("-simulation")==0) {
413 HLTInfo("Awaiting simulated data");
416 else if (argument.CompareTo("-experiment")==0) {
418 HLTInfo("Awaiting real data");
421 else if (argument.CompareTo("-processTracklets")==0) {
422 fProcessTracklets = kTRUE;
423 HLTInfo("Writing L1 tracklets to output");
426 else if (argument.CompareTo("-noZS")==0) {
427 fOutputPercentage = 10;
428 HLTInfo("Awaiting non zero surpressed data");
431 else if (argument.CompareTo("-HLTflag")==0) {
432 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
433 TString toCompareTo=((TObjString*)pTokens->At(i))->GetString();
434 if (toCompareTo.CompareTo("yes")==0){
435 HLTInfo("Setting HLTflag to: %s", toCompareTo.Data());
438 else if (toCompareTo.CompareTo("no")==0){
439 HLTInfo("Setting HLTflag to: %s", toCompareTo.Data());
443 HLTError("unknown argument for HLTflag: %s", toCompareTo.Data());
449 else if (argument.CompareTo("-faststreamer")==0) {
450 fHLTstreamer = kTRUE;
451 HLTInfo("Useing fast raw streamer");
454 else if (argument.CompareTo("-nofaststreamer")==0) {
455 fHLTstreamer = kFALSE;
456 HLTInfo("Don't use fast raw streamer");
459 else if (argument.CompareTo("-tailcancellation")==0) {
461 HLTInfo("Useing tailcancellation");
464 else if (argument.CompareTo("-rawver")==0) {
465 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
466 HLTInfo("Raw data version is: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
467 fRawDataVersion=((TObjString*)pTokens->At(i))->GetString().Atoi();
470 else if (argument.CompareTo("-highLevelOutput")==0) {
471 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
472 TString toCompareTo=((TObjString*)pTokens->At(i))->GetString();
473 if (toCompareTo.CompareTo("yes")==0){
474 HLTWarning("Setting highLevelOutput to: %s", toCompareTo.Data());
475 fHighLevelOutput=kTRUE;
477 else if (toCompareTo.CompareTo("no")==0){
478 HLTInfo("Setting highLevelOutput to: %s", toCompareTo.Data());
479 fHighLevelOutput=kFALSE;
482 HLTError("unknown argument for highLevelOutput: %s", toCompareTo.Data());
488 else if (argument.CompareTo("-emulateHLToutput")==0) {
489 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
490 TString toCompareTo=((TObjString*)pTokens->At(i))->GetString();
491 if (toCompareTo.CompareTo("yes")==0){
492 HLTWarning("Setting emulateHLToutput to: %s", toCompareTo.Data());
493 fEmulateHLTClusters=kTRUE;
495 else if (toCompareTo.CompareTo("no")==0){
496 HLTInfo("Setting emulateHLToutput to: %s", toCompareTo.Data());
497 fEmulateHLTClusters=kFALSE;
500 HLTError("unknown argument for emulateHLToutput: %s", toCompareTo.Data());
506 else if (argument.CompareTo("-yPosMethod")==0) {
507 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
508 TString toCompareTo=((TObjString*)pTokens->At(i))->GetString();
509 if (toCompareTo.CompareTo("COG")==0){
510 HLTInfo("Setting yPosMethod method to: %s", toCompareTo.Data());
513 else if (toCompareTo.CompareTo("LUT")==0){
514 HLTInfo("Setting yPosMethod method to: %s", toCompareTo.Data());
517 else if (toCompareTo.CompareTo("Gauss")==0){
518 HLTInfo("Setting yPosMethod method to: %s", toCompareTo.Data());
522 HLTError("unknown argument for yPosMethod: %s", toCompareTo.Data());
530 HLTError("unknown argument: %s", argument.Data());
538 HLTError("missing parameter for argument %s", argument.Data());
547 int AliHLTTRDClusterizerComponent::SetParams()
550 if(!AliCDBManager::Instance()->IsDefaultStorageSet()){
551 HLTError("DefaultStorage is not set in CDBManager");
554 if(AliCDBManager::Instance()->GetRun()<0){
555 HLTError("Run Number is not set in CDBManager");
558 HLTInfo("CDB default storage: %s; RunNo: %i", (AliCDBManager::Instance()->GetDefaultStorage()->GetBaseFolder()).Data(), AliCDBManager::Instance()->GetRun());
560 if(!AliGeomManager::GetGeometry()){
561 if(fgeometryFileName.CompareTo("")==0 || !TFile::Open(fgeometryFileName.Data())){
562 HLTInfo("Loading standard geometry file");
563 AliGeomManager::LoadGeometry();
565 HLTWarning("Loading NON-standard geometry file");
566 AliGeomManager::LoadGeometry(fgeometryFileName.Data());
568 if(!AliGeomManager::GetGeometry()){
569 HLTError("Could not load geometry");
572 HLTInfo("Applying Alignment from CDB object");
573 AliGeomManager::ApplyAlignObjsFromCDB("TRD");
576 HLTInfo("Geometry Already Loaded!");
579 if(fReconstructor->GetRecoParam()){
580 fRecoParam = new AliTRDrecoParam(*fReconstructor->GetRecoParam());
581 HLTInfo("RecoParam already set!");
583 if(fRecoParamType == 0){
584 HLTDebug("Low flux params init.");
585 fRecoParam = AliTRDrecoParam::GetLowFluxParam();
587 if(fRecoParamType == 1){
588 HLTDebug("High flux params init.");
589 fRecoParam = AliTRDrecoParam::GetHighFluxParam();
591 if(fRecoParamType == 2){
592 HLTDebug("Cosmic Test params init.");
593 fRecoParam = AliTRDrecoParam::GetCosmicTestParam();
599 HLTError("No reco params initialized. Sniffing big trouble!");
603 // backward compatibility to AliTRDrecoParam < r34995
604 # ifndef HAVE_NOT_ALITRDRECOPARAM_r34995
605 # define AliTRDRecoParamSetTailCancelation(b) fRecoParam->SetTailCancelation(b)
606 # define AliTRDRecoParamSetGAUS(b) fRecoParam->SetGAUS(b)
607 # define AliTRDRecoParamSetLUT(b) fRecoParam->SetLUT(b)
609 # define AliTRDRecoParamSetTailCancelation(b) fRecoParam->SetTailCancelation()
610 # define AliTRDRecoParamSetGAUS(b) fRecoParam->SetGAUS()
611 # define AliTRDRecoParamSetLUT(b) fRecoParam->SetLUT()
614 if(fTC){fRecoParam->SetTailCancelation(kTRUE); HLTDebug("Enableing Tail Cancelation"); }
615 else{fRecoParam->SetTailCancelation(kFALSE); HLTDebug("Disableing Tail Cancelation"); }
618 case 0: AliTRDRecoParamSetGAUS(kFALSE); AliTRDRecoParamSetLUT(kFALSE); break;
619 case 1: AliTRDRecoParamSetGAUS(kFALSE); AliTRDRecoParamSetLUT(kTRUE); break;
620 case 2: AliTRDRecoParamSetGAUS(kTRUE); AliTRDRecoParamSetLUT(kFALSE); break;
623 fRecoParam->SetStreamLevel(AliTRDrecoParam::kClusterizer, 0);
624 fReconstructor->SetRecoParam(fRecoParam);
626 TString recoOptions="!cw";
628 recoOptions += ",hlt";
629 if(fProcessTracklets) recoOptions += ",tp";
630 else recoOptions += ",!tp";
632 HLTDebug("Reconstructor options are: %s",recoOptions.Data());
633 fReconstructor->SetOption(recoOptions.Data());
635 if (fRecoDataType < 0 || fRecoDataType > 1)
637 HLTWarning("No data type selected. Use -simulation or -experiment flag. Defaulting to simulation.");
641 if (fRecoDataType == 0)
643 AliTRDrawStreamBase::SetRawStreamVersion(AliTRDrawStreamBase::kTRDsimStream);
644 HLTDebug("Data type expected is SIMULATION!");
647 if (fRecoDataType == 1)
649 AliTRDrawStreamBase::SetRawStreamVersion(AliTRDrawStreamBase::kTRDrealStream);
650 HLTDebug("Data type expected is EXPERIMENT!");
655 AliTRDrawStreamBase::SetRawStreamVersion("FAST");
656 HLTDebug("fast rawstreamer used");
660 fClusterizer = new AliHLTTRDClusterizer("TRDCclusterizer", "TRDCclusterizer");
661 HLTDebug("TRDClusterizer at 0x%x", fClusterizer);
664 fClusterizer->SetRawVersion(fRawDataVersion);
669 int AliHLTTRDClusterizerComponent::Reconfigure(const char* cdbEntry, const char* chainId)
671 // see header file for class documentation
674 const char* path="HLT/ConfigTRD/ClusterizerComponent";
675 const char* defaultNotify="";
678 defaultNotify=" (default)";
681 HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
682 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
684 TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
686 HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
687 iResult=Configure(pString->GetString().Data());
689 HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
692 HLTError("cannot fetch object \"%s\" from CDB", path);