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 HLTDebug( "NofBlocks %i", evtData.fBlockCnt );
215 AliHLTUInt32_t totalSize = 0, offset = 0;
217 //implement a usage of the following
218 // AliHLTUInt32_t triggerDataStructSize = trigData.fStructSize;
219 // AliHLTUInt32_t triggerDataSize = trigData.fDataSize;
220 // void *triggerData = trigData.fData;
221 //HLTDebug( "Trigger data received. Struct size %d Data size %d Data location 0x%x", trigData.fStructSize, trigData.fDataSize, (UInt_t*)trigData.fData);
223 // Loop over all input blocks in the event
224 AliHLTComponentDataType expectedDataType = (kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTRD);
225 for ( UInt_t iBlock = 0; iBlock < evtData.fBlockCnt; iBlock++ )
227 const AliHLTComponentBlockData &block = blocks[iBlock];
228 // lets not use the internal TRD data types here : AliHLTTRDDefinitions::fgkDDLRawDataType
229 // which is depreciated - we use HLT global defs instead
230 // if ( block.fDataType != (kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTRD) )
231 AliHLTComponentDataType inputDataType = block.fDataType;
232 if ( inputDataType != expectedDataType)
234 HLTDebug( "Block # %i/%i; Event 0x%08LX (%Lu) Wrong received datatype: %s - required datatype: %s; Skipping",
235 iBlock, evtData.fBlockCnt,
236 evtData.fEventID, evtData.fEventID,
237 DataType2Text(inputDataType).c_str(),
238 DataType2Text(expectedDataType).c_str());
239 if(block.fDataType == kAliHLTDataTypeEOR)
240 CALLGRIND_STOP_INSTRUMENTATION;
245 HLTDebug("We get the right data type: Block # %i/%i; Event 0x%08LX (%Lu) Received datatype: %s; Block Size: %i",
246 iBlock, evtData.fBlockCnt,
247 evtData.fEventID, evtData.fEventID,
248 DataType2Text(inputDataType).c_str(),
253 unsigned long constBase;
254 double inputMultiplier;
255 GetOutputDataSize(constBase,inputMultiplier);
256 if(size<(constBase+block.fSize*inputMultiplier)){
257 HLTWarning("Memory Block given might be too small: %i < %i; Event %Lu", size, constBase+block.fSize*inputMultiplier, evtData.fEventID);
261 // fMemReader->Reset();
262 fMemReader->SetMemory((UChar_t*) block.fPtr, block.fSize);
264 AliHLTUInt32_t spec = block.fSpecification;
266 Int_t id = AliHLTTRDUtils::GetSM(spec) + 1024;
268 fMemReader->SetEquipmentID(id);
270 fClusterizer->SetMemBlock(outputPtr+offset);
271 Bool_t bclustered = fClusterizer->Raw2ClustersChamber(fMemReader);
274 HLTDebug("Clustered successfully");
278 HLTError("Clustering ERROR");
282 AliHLTUInt32_t addedSize;
283 if(fReconstructor->IsProcessingTracklets()){
284 addedSize = fClusterizer->GetAddedTrSize();
285 totalSize += fClusterizer->GetTrMemBlockSize(); //if IsProcessingTracklets() is enabled we always reserve a data block of size GetTrMemBlockSize() for the tracklets
287 // Using low-level interface
288 // with interface classes
289 if ( totalSize > size )
291 HLTError("Too much data; Data written over allowed buffer. Amount written: %lu, allowed amount: %lu.",
297 AliHLTComponentBlockData bd;
300 bd.fSize = addedSize;
301 bd.fSpecification = block.fSpecification;
302 bd.fDataType = AliHLTTRDDefinitions::fgkMCMtrackletDataType;
303 outputBlocks.push_back( bd );
304 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);
309 addedSize = fClusterizer->GetAddedClSize();
312 Int_t* nTimeBins = (Int_t*)(outputPtr+offset+fClusterizer->GetAddedClSize());
313 *nTimeBins = fClusterizer->GetNTimeBins();
314 addedSize += sizeof(*nTimeBins);
316 totalSize += addedSize;
317 if ( totalSize > size )
319 HLTError("Too much data; Data written over allowed buffer. Amount written: %lu, allowed amount: %lu.",
325 AliHLTComponentBlockData bd;
328 bd.fSize = addedSize;
329 bd.fSpecification = block.fSpecification;
330 bd.fDataType = AliHLTTRDDefinitions::fgkClusterDataType;
331 outputBlocks.push_back( bd );
332 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);
336 HLTDebug("Array of clusters is empty!");
339 fReconstructor->SetClusters(0x0);
342 HLTDebug("Event is done. size written to the output is %i", size);
346 void AliHLTTRDClusterizerComponent::PrintObject( TClonesArray* inClustersArray)
348 AliTRDcluster* cluster=0x0;
350 for (Int_t i=0; i < inClustersArray->GetEntriesFast(); i++){
351 cluster = dynamic_cast<AliTRDcluster*>(inClustersArray->At(i));
352 HLTDebug("cluster[%i]",i);
353 HLTDebug(" PadCol = %i; PadRow = %i; PadTime = %i", cluster->GetPadCol(), cluster->GetPadRow(), cluster->GetPadTime());
354 HLTDebug(" Detector = %i, Amplitude = %f, Center = %f", cluster->GetDetector(), cluster->GetQ(), cluster->GetCenter());
355 HLTDebug(" LocalTimeBin = %i; NPads = %i; maskedPosition: %s, status: %s", cluster->GetLocalTimeBin(), cluster->GetNPads(),cluster->GetPadMaskedPosition(),cluster->GetPadMaskedPosition());
360 int AliHLTTRDClusterizerComponent::Configure(const char* arguments){
362 if (!arguments) return iResult;
364 TString allArgs=arguments;
368 TObjArray* pTokens=allArgs.Tokenize(" ");
370 for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
371 argument=((TObjString*)pTokens->At(i))->GetString();
372 if (argument.IsNull()) continue;
374 if (argument.CompareTo("output_percentage")==0) {
375 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
376 HLTInfo("Setting output percentage to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
377 fOutputPercentage=((TObjString*)pTokens->At(i))->GetString().Atoi();
380 else if (argument.CompareTo("-geometry")==0) {
381 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
382 HLTInfo("Setting geometry to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
383 fgeometryFileName=((TObjString*)pTokens->At(i))->GetString();
386 else if (argument.CompareTo("-lowflux")==0) {
388 HLTInfo("Low flux reconstruction selected");
391 else if (argument.CompareTo("-highflux")==0) {
393 HLTInfo("High flux reconstruction selected");
396 else if (argument.CompareTo("-cosmics")==0) {
398 HLTInfo("Cosmics reconstruction selected");
401 else if (argument.CompareTo("-simulation")==0) {
403 HLTInfo("Awaiting simulated data");
406 else if (argument.CompareTo("-experiment")==0) {
408 HLTInfo("Awaiting real data");
411 else if (argument.CompareTo("-processTracklets")==0) {
412 fProcessTracklets = kTRUE;
413 HLTInfo("Writing L1 tracklets to output");
416 else if (argument.CompareTo("-noZS")==0) {
417 fOutputPercentage = 10;
418 HLTInfo("Awaiting non zero surpressed data");
421 else if (argument.CompareTo("-HLTflag")==0) {
422 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
423 TString toCompareTo=((TObjString*)pTokens->At(i))->GetString();
424 if (toCompareTo.CompareTo("yes")==0){
425 HLTInfo("Setting HLTflag to: %s", toCompareTo.Data());
428 else if (toCompareTo.CompareTo("no")==0){
429 HLTInfo("Setting HLTflag to: %s", toCompareTo.Data());
433 HLTError("unknown argument for HLTflag: %s", toCompareTo.Data());
439 else if (argument.CompareTo("-faststreamer")==0) {
440 fHLTstreamer = kTRUE;
441 HLTInfo("Useing fast raw streamer");
444 else if (argument.CompareTo("-nofaststreamer")==0) {
445 fHLTstreamer = kFALSE;
446 HLTInfo("Don't use fast raw streamer");
449 else if (argument.CompareTo("-tailcancellation")==0) {
451 HLTInfo("Useing tailcancellation");
454 else if (argument.CompareTo("-rawver")==0) {
455 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
456 HLTInfo("Raw data version is: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
457 fRawDataVersion=((TObjString*)pTokens->At(i))->GetString().Atoi();
460 else if (argument.CompareTo("-highLevelOutput")==0) {
461 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
462 TString toCompareTo=((TObjString*)pTokens->At(i))->GetString();
463 if (toCompareTo.CompareTo("yes")==0){
464 HLTWarning("Setting highLevelOutput to: %s", toCompareTo.Data());
465 fHighLevelOutput=kTRUE;
467 else if (toCompareTo.CompareTo("no")==0){
468 HLTInfo("Setting highLevelOutput to: %s", toCompareTo.Data());
469 fHighLevelOutput=kFALSE;
472 HLTError("unknown argument for highLevelOutput: %s", toCompareTo.Data());
478 else if (argument.CompareTo("-emulateHLToutput")==0) {
479 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
480 TString toCompareTo=((TObjString*)pTokens->At(i))->GetString();
481 if (toCompareTo.CompareTo("yes")==0){
482 HLTWarning("Setting emulateHLToutput to: %s", toCompareTo.Data());
483 fEmulateHLTClusters=kTRUE;
485 else if (toCompareTo.CompareTo("no")==0){
486 HLTInfo("Setting emulateHLToutput to: %s", toCompareTo.Data());
487 fEmulateHLTClusters=kFALSE;
490 HLTError("unknown argument for emulateHLToutput: %s", toCompareTo.Data());
496 else if (argument.CompareTo("-yPosMethod")==0) {
497 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
498 TString toCompareTo=((TObjString*)pTokens->At(i))->GetString();
499 if (toCompareTo.CompareTo("COG")==0){
500 HLTInfo("Setting yPosMethod method to: %s", toCompareTo.Data());
503 else if (toCompareTo.CompareTo("LUT")==0){
504 HLTInfo("Setting yPosMethod method to: %s", toCompareTo.Data());
507 else if (toCompareTo.CompareTo("Gauss")==0){
508 HLTInfo("Setting yPosMethod method to: %s", toCompareTo.Data());
512 HLTError("unknown argument for yPosMethod: %s", toCompareTo.Data());
520 HLTError("unknown argument: %s", argument.Data());
528 HLTError("missing parameter for argument %s", argument.Data());
537 int AliHLTTRDClusterizerComponent::SetParams()
540 if(!AliCDBManager::Instance()->IsDefaultStorageSet()){
541 HLTError("DefaultStorage is not set in CDBManager");
544 if(AliCDBManager::Instance()->GetRun()<0){
545 HLTError("Run Number is not set in CDBManager");
548 HLTInfo("CDB default storage: %s; RunNo: %i", (AliCDBManager::Instance()->GetDefaultStorage()->GetBaseFolder()).Data(), AliCDBManager::Instance()->GetRun());
550 if(!AliGeomManager::GetGeometry()){
551 if(fgeometryFileName.CompareTo("")==0 || !TFile::Open(fgeometryFileName.Data())){
552 HLTInfo("Loading standard geometry file");
553 AliGeomManager::LoadGeometry();
555 HLTWarning("Loading NON-standard geometry file");
556 AliGeomManager::LoadGeometry(fgeometryFileName.Data());
558 if(!AliGeomManager::GetGeometry()){
559 HLTError("Could not load geometry");
562 HLTInfo("Applying Alignment from CDB object");
563 AliGeomManager::ApplyAlignObjsFromCDB("TRD");
566 HLTInfo("Geometry Already Loaded!");
569 if(fReconstructor->GetRecoParam()){
570 fRecoParam = new AliTRDrecoParam(*fReconstructor->GetRecoParam());
571 HLTInfo("RecoParam already set!");
573 if(fRecoParamType == 0){
574 HLTDebug("Low flux params init.");
575 fRecoParam = AliTRDrecoParam::GetLowFluxParam();
577 if(fRecoParamType == 1){
578 HLTDebug("High flux params init.");
579 fRecoParam = AliTRDrecoParam::GetHighFluxParam();
581 if(fRecoParamType == 2){
582 HLTDebug("Cosmic Test params init.");
583 fRecoParam = AliTRDrecoParam::GetCosmicTestParam();
589 HLTError("No reco params initialized. Sniffing big trouble!");
593 // backward compatibility to AliTRDrecoParam < r34995
594 # ifndef HAVE_NOT_ALITRDRECOPARAM_r34995
595 # define AliTRDRecoParamSetTailCancelation(b) fRecoParam->SetTailCancelation(b)
596 # define AliTRDRecoParamSetGAUS(b) fRecoParam->SetGAUS(b)
597 # define AliTRDRecoParamSetLUT(b) fRecoParam->SetLUT(b)
599 # define AliTRDRecoParamSetTailCancelation(b) fRecoParam->SetTailCancelation()
600 # define AliTRDRecoParamSetGAUS(b) fRecoParam->SetGAUS()
601 # define AliTRDRecoParamSetLUT(b) fRecoParam->SetLUT()
604 if(fTC){fRecoParam->SetTailCancelation(kTRUE); HLTDebug("Enableing Tail Cancelation"); }
605 else{fRecoParam->SetTailCancelation(kFALSE); HLTDebug("Disableing Tail Cancelation"); }
608 case 0: AliTRDRecoParamSetGAUS(kFALSE); AliTRDRecoParamSetLUT(kFALSE); break;
609 case 1: AliTRDRecoParamSetGAUS(kFALSE); AliTRDRecoParamSetLUT(kTRUE); break;
610 case 2: AliTRDRecoParamSetGAUS(kTRUE); AliTRDRecoParamSetLUT(kFALSE); break;
613 fRecoParam->SetStreamLevel(AliTRDrecoParam::kClusterizer, 0);
614 fReconstructor->SetRecoParam(fRecoParam);
616 TString recoOptions="!cw";
618 recoOptions += ",hlt";
619 if(fProcessTracklets) recoOptions += ",tp";
620 else recoOptions += ",!tp";
622 HLTDebug("Reconstructor options are: %s",recoOptions.Data());
623 fReconstructor->SetOption(recoOptions.Data());
625 if (fRecoDataType < 0 || fRecoDataType > 1)
627 HLTWarning("No data type selected. Use -simulation or -experiment flag. Defaulting to simulation.");
631 if (fRecoDataType == 0)
633 AliTRDrawStreamBase::SetRawStreamVersion(AliTRDrawStreamBase::kTRDsimStream);
634 HLTDebug("Data type expected is SIMULATION!");
637 if (fRecoDataType == 1)
639 AliTRDrawStreamBase::SetRawStreamVersion(AliTRDrawStreamBase::kTRDrealStream);
640 HLTDebug("Data type expected is EXPERIMENT!");
645 AliTRDrawStreamBase::SetRawStreamVersion("FAST");
646 HLTDebug("fast rawstreamer used");
650 fClusterizer = new AliHLTTRDClusterizer("TRDCclusterizer", "TRDCclusterizer");
651 HLTDebug("TRDClusterizer at 0x%x", fClusterizer);
654 fClusterizer->SetRawVersion(fRawDataVersion);
659 int AliHLTTRDClusterizerComponent::Reconfigure(const char* cdbEntry, const char* chainId)
661 // see header file for class documentation
664 const char* path="HLT/ConfigTRD/ClusterizerComponent";
665 const char* defaultNotify="";
668 defaultNotify=" (default)";
671 HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
672 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
674 TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
676 HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
677 iResult=Configure(pString->GetString().Data());
679 HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
682 HLTError("cannot fetch object \"%s\" from CDB", path);