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
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 "AliHLTTRDCluster.h"
43 #include "AliGeomManager.h"
44 #include "AliTRDReconstructor.h"
45 #include "AliCDBManager.h"
46 #include "AliCDBStorage.h"
47 #include "AliCDBEntry.h"
48 #include "AliHLTTRDClusterizer.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 do { } while (0)
59 #define CALLGRIND_STOP_INSTRUMENTATION do { } while (0)
66 #include "AliTRDrawStream.h"
67 #include "AliTRDrawFastStream.h"
69 ClassImp(AliHLTTRDClusterizerComponent)
71 AliHLTTRDClusterizerComponent::AliHLTTRDClusterizerComponent()
73 fOutputPercentage(500),
83 fgeometryFileName(""),
84 fProcessTracklets(kFALSE),
89 // Default constructor
93 AliHLTTRDClusterizerComponent::~AliHLTTRDClusterizerComponent()
96 // Work is Done in DoDeInit()
100 const char* AliHLTTRDClusterizerComponent::GetComponentID()
102 // Return the component ID const char *
103 return "TRDClusterizer"; // The ID of this component
106 void AliHLTTRDClusterizerComponent::GetInputDataTypes( vector<AliHLTComponent_DataType>& list)
108 // Get the list of input data
109 list.clear(); // We do not have any requirements for our input data type(s).
110 list.push_back(kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTRD);
113 AliHLTComponentDataType AliHLTTRDClusterizerComponent::GetOutputDataType()
115 // Get the output data type
116 return kAliHLTMultipleDataType;
119 int AliHLTTRDClusterizerComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList)
121 // Get the output data type
123 tgtList.push_back(AliHLTTRDDefinitions::fgkClusterDataType);
124 tgtList.push_back(AliHLTTRDDefinitions::fgkMCMtrackletDataType);
125 return tgtList.size();
129 void AliHLTTRDClusterizerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
131 // Get the output data size
132 constBase = fOutputConst;
133 inputMultiplier = ((double)fOutputPercentage)/100.0;
136 AliHLTComponent* AliHLTTRDClusterizerComponent::Spawn()
138 // Spawn function, return new instance of this class
139 return new AliHLTTRDClusterizerComponent;
142 int AliHLTTRDClusterizerComponent::DoInit( int argc, const char** argv )
144 // perform initialization. We check whether our relative output size is specified in the arguments.
147 fReconstructor = new AliTRDReconstructor();
148 HLTDebug("TRDReconstructor at 0x%x", fReconstructor);
150 TString configuration="";
152 for (int i=0; i<argc && iResult>=0; i++) {
154 if (!configuration.IsNull()) configuration+=" ";
155 configuration+=argument;
158 if (!configuration.IsNull()) {
159 iResult=Configure(configuration.Data());
161 iResult=Reconfigure(NULL, NULL);
165 HLTFatal("Clusterizer was not initialized!");
169 if(iResult<0) return iResult;
171 fMemReader = new AliRawReaderMemory;
172 fClusterizer->SetReconstructor(fReconstructor);
173 fClusterizer->SetUseLabels(kFALSE);
175 if(fReconstructor->IsProcessingTracklets())
176 fOutputConst = fClusterizer->GetTrMemBlockSize();
181 int AliHLTTRDClusterizerComponent::DoDeinit()
183 // Deinitialization of the component
189 fReconstructor->SetClusters(0x0);
190 delete fReconstructor;
191 fReconstructor = 0x0;
196 HLTDebug("Deleting fRecoParam");
202 int AliHLTTRDClusterizerComponent::DoEvent( const AliHLTComponentEventData& evtData,
203 const AliHLTComponentBlockData* blocks,
204 AliHLTComponent_TriggerData& /*trigData*/,
205 AliHLTUInt8_t* outputPtr,
206 AliHLTUInt32_t& size,
207 vector<AliHLTComponent_BlockData>& outputBlocks )
211 if (evtData.fEventID == 1)
212 CALLGRIND_START_INSTRUMENTATION;
214 HLTDebug( "NofBlocks %i", evtData.fBlockCnt );
216 AliHLTUInt32_t totalSize = 0, offset = 0;
218 //implement a usage of the following
219 // AliHLTUInt32_t triggerDataStructSize = trigData.fStructSize;
220 // AliHLTUInt32_t triggerDataSize = trigData.fDataSize;
221 // void *triggerData = trigData.fData;
222 //HLTDebug( "Trigger data received. Struct size %d Data size %d Data location 0x%x", trigData.fStructSize, trigData.fDataSize, (UInt_t*)trigData.fData);
224 // Loop over all input blocks in the event
225 AliHLTComponentDataType expectedDataType = (kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTRD);
226 for ( UInt_t iBlock = 0; iBlock < evtData.fBlockCnt; iBlock++ )
228 const AliHLTComponentBlockData &block = blocks[iBlock];
229 // lets not use the internal TRD data types here : AliHLTTRDDefinitions::fgkDDLRawDataType
230 // which is depreciated - we use HLT global defs instead
231 // if ( block.fDataType != (kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTRD) )
232 AliHLTComponentDataType inputDataType = block.fDataType;
233 if ( inputDataType != expectedDataType)
235 HLTDebug( "Block # %i/%i; Event 0x%08LX (%Lu) Wrong received datatype: %s - required datatype: %s; Skipping",
236 iBlock, evtData.fBlockCnt,
237 evtData.fEventID, evtData.fEventID,
238 DataType2Text(inputDataType).c_str(),
239 DataType2Text(expectedDataType).c_str());
244 HLTDebug("We get the right data type: Block # %i/%i; Event 0x%08LX (%Lu) Received datatype: %s; Block Size: %i",
245 iBlock, evtData.fBlockCnt,
246 evtData.fEventID, evtData.fEventID,
247 DataType2Text(inputDataType).c_str(),
252 unsigned long constBase;
253 double inputMultiplier;
254 GetOutputDataSize(constBase,inputMultiplier);
255 if(size<(constBase+block.fSize*inputMultiplier)){
256 HLTWarning("Memory Block given might be too small: %i < %i; Event %Lu", size, constBase+block.fSize*inputMultiplier, evtData.fEventID);
260 // fMemReader->Reset();
261 fMemReader->SetMemory((UChar_t*) block.fPtr, block.fSize);
263 AliHLTUInt32_t spec = block.fSpecification;
267 for ( Int_t ii = 0; ii < 18 ; ii++ ) {
275 fMemReader->SetEquipmentID( id );
277 fClusterizer->SetMemBlock(outputPtr+offset);
278 Bool_t bclustered = fClusterizer->Raw2ClustersChamber(fMemReader);
281 HLTDebug("Clustered successfully");
285 HLTError("Clustering ERROR");
289 AliHLTUInt32_t addedSize;
290 if(fReconstructor->IsProcessingTracklets()){
291 addedSize = fClusterizer->GetAddedTrSize();
292 totalSize += fClusterizer->GetTrMemBlockSize(); //if IsProcessingTracklets() is enabled we always reserve a data block of size GetTrMemBlockSize() for the tracklets
294 // Using low-level interface
295 // with interface classes
296 if ( totalSize > size )
298 HLTError("Too much data; Data written over allowed buffer. Amount written: %lu, allowed amount: %lu.",
304 AliHLTComponentBlockData bd;
307 bd.fSize = addedSize;
308 bd.fSpecification = block.fSpecification;
309 bd.fDataType = AliHLTTRDDefinitions::fgkMCMtrackletDataType;
310 outputBlocks.push_back( bd );
311 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);
316 addedSize = fClusterizer->GetAddedClSize();
319 Int_t* nTimeBins = (Int_t*)(outputPtr+offset+fClusterizer->GetAddedClSize());
320 *nTimeBins = fClusterizer->GetNTimeBins();
321 addedSize += sizeof(*nTimeBins);
323 totalSize += addedSize;
324 if ( totalSize > size )
326 HLTError("Too much data; Data written over allowed buffer. Amount written: %lu, allowed amount: %lu.",
332 AliHLTComponentBlockData bd;
335 bd.fSize = addedSize;
336 bd.fSpecification = block.fSpecification;
337 bd.fDataType = AliHLTTRDDefinitions::fgkClusterDataType;
338 outputBlocks.push_back( bd );
339 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);
343 HLTDebug("Array of clusters is empty!");
346 fReconstructor->SetClusters(0x0);
349 HLTDebug("Event is done. size written to the output is %i", size);
353 void AliHLTTRDClusterizerComponent::PrintObject( TClonesArray* inClustersArray)
355 AliTRDcluster* cluster=0x0;
357 for (Int_t i=0; i < inClustersArray->GetEntriesFast(); i++){
358 cluster = dynamic_cast<AliTRDcluster*>(inClustersArray->At(i));
359 HLTDebug("cluster[%i]",i);
360 HLTDebug(" PadCol = %i; PadRow = %i; PadTime = %i", cluster->GetPadCol(), cluster->GetPadRow(), cluster->GetPadTime());
361 HLTDebug(" Detector = %i, Amplitude = %f, Center = %f", cluster->GetDetector(), cluster->GetQ(), cluster->GetCenter());
362 HLTDebug(" LocalTimeBin = %i; NPads = %i; maskedPosition: %s, status: %s", cluster->GetLocalTimeBin(), cluster->GetNPads(),cluster->GetPadMaskedPosition(),cluster->GetPadMaskedPosition());
367 int AliHLTTRDClusterizerComponent::Configure(const char* arguments){
369 if (!arguments) return iResult;
371 TString allArgs=arguments;
375 TObjArray* pTokens=allArgs.Tokenize(" ");
377 for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
378 argument=((TObjString*)pTokens->At(i))->GetString();
379 if (argument.IsNull()) continue;
381 if (argument.CompareTo("output_percentage")==0) {
382 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
383 HLTInfo("Setting output percentage to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
384 fOutputPercentage=((TObjString*)pTokens->At(i))->GetString().Atoi();
387 else if (argument.CompareTo("-geometry")==0) {
388 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
389 HLTInfo("Setting geometry to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
390 fgeometryFileName=((TObjString*)pTokens->At(i))->GetString();
393 else if (argument.CompareTo("-lowflux")==0) {
395 HLTInfo("Low flux reconstruction selected");
398 else if (argument.CompareTo("-highflux")==0) {
400 HLTInfo("High flux reconstruction selected");
403 else if (argument.CompareTo("-cosmics")==0) {
405 HLTInfo("Cosmics reconstruction selected");
408 else if (argument.CompareTo("-simulation")==0) {
410 HLTInfo("Awaiting simulated data");
413 else if (argument.CompareTo("-experiment")==0) {
415 HLTInfo("Awaiting real data");
418 else if (argument.CompareTo("-processTracklets")==0) {
419 fProcessTracklets = kTRUE;
420 HLTInfo("Writing L1 tracklets to output");
423 else if (argument.CompareTo("-noZS")==0) {
424 fOutputPercentage = 100;
425 HLTInfo("Awaiting non zero surpressed data");
428 else if (argument.CompareTo("-faststreamer")==0) {
429 fHLTstreamer = kTRUE;
430 HLTInfo("Useing fast raw streamer");
433 else if (argument.CompareTo("-nofaststreamer")==0) {
434 fHLTstreamer = kFALSE;
435 HLTInfo("Don't use fast raw streamer");
438 else if (argument.CompareTo("-tailcancellation")==0) {
440 HLTInfo("Useing tailcancellation");
443 else if (argument.CompareTo("-rawver")==0) {
444 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
445 HLTInfo("Raw data version is: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
446 fRawDataVersion=((TObjString*)pTokens->At(i))->GetString().Atoi();
449 else if (argument.CompareTo("-yPosMethod")==0) {
450 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
451 TString toCompareTo=((TObjString*)pTokens->At(i))->GetString();
452 if (toCompareTo.CompareTo("COG")==0){
453 HLTInfo("Setting yPosMethod method to: %s", toCompareTo.Data());
456 else if (toCompareTo.CompareTo("LUT")==0){
457 HLTInfo("Setting yPosMethod method to: %s", toCompareTo.Data());
460 else if (toCompareTo.CompareTo("Gauss")==0){
461 HLTInfo("Setting yPosMethod method to: %s", toCompareTo.Data());
465 HLTError("unknown argument for yPosMethod: %s", toCompareTo.Data());
473 HLTError("unknown argument: %s", argument.Data());
481 HLTError("missing parameter for argument %s", argument.Data());
490 int AliHLTTRDClusterizerComponent::SetParams()
493 if(!AliCDBManager::Instance()->IsDefaultStorageSet()){
494 HLTError("DefaultStorage is not set in CDBManager");
497 if(AliCDBManager::Instance()->GetRun()<0){
498 HLTError("Run Number is not set in CDBManager");
501 HLTInfo("CDB default storage: %s; RunNo: %i", (AliCDBManager::Instance()->GetDefaultStorage()->GetBaseFolder()).Data(), AliCDBManager::Instance()->GetRun());
503 if(!AliGeomManager::GetGeometry()){
504 if(fgeometryFileName.CompareTo("")==0 || !TFile::Open(fgeometryFileName.Data())){
505 HLTInfo("Loading standard geometry file");
506 AliGeomManager::LoadGeometry();
508 HLTWarning("Loading NON-standard geometry file");
509 AliGeomManager::LoadGeometry(fgeometryFileName.Data());
511 if(!AliGeomManager::GetGeometry()){
512 HLTError("Could not load geometry");
515 HLTInfo("Applying Alignment from CDB object");
516 AliGeomManager::ApplyAlignObjsFromCDB("TRD");
519 HLTInfo("Geometry Already Loaded!");
522 if (fRecoParamType == 0)
524 HLTDebug("Low flux params init.");
525 fRecoParam = AliTRDrecoParam::GetLowFluxParam();
528 if (fRecoParamType == 1)
530 HLTDebug("High flux params init.");
531 fRecoParam = AliTRDrecoParam::GetHighFluxParam();
534 if (fRecoParamType == 2)
536 HLTDebug("Cosmic Test params init.");
537 fRecoParam = AliTRDrecoParam::GetCosmicTestParam();
542 HLTError("No reco params initialized. Sniffing big trouble!");
546 // backward compatibility to AliTRDrecoParam < r34995
547 # ifndef HAVE_NOT_ALITRDRECOPARAM_r34995
548 # define AliTRDRecoParamSetTailCancelation(b) fRecoParam->SetTailCancelation(b)
549 # define AliTRDRecoParamSetGAUS(b) fRecoParam->SetGAUS(b)
550 # define AliTRDRecoParamSetLUT(b) fRecoParam->SetLUT(b)
552 # define AliTRDRecoParamSetTailCancelation(b) fRecoParam->SetTailCancelation()
553 # define AliTRDRecoParamSetGAUS(b) fRecoParam->SetGAUS()
554 # define AliTRDRecoParamSetLUT(b) fRecoParam->SetLUT()
557 if(fTC){AliTRDRecoParamSetTailCancelation(kTRUE); HLTDebug("Enableing Tail Cancelation"); }
558 else{AliTRDRecoParamSetTailCancelation(kFALSE); HLTDebug("Enableing Tail Cancelation"); }
561 case 0: AliTRDRecoParamSetGAUS(kFALSE); AliTRDRecoParamSetLUT(kFALSE); break;
562 case 1: AliTRDRecoParamSetGAUS(kFALSE); AliTRDRecoParamSetLUT(kTRUE); break;
563 case 2: AliTRDRecoParamSetGAUS(kTRUE); AliTRDRecoParamSetLUT(kFALSE); break;
566 fRecoParam->SetStreamLevel(AliTRDrecoParam::kClusterizer, 0);
567 fReconstructor->SetRecoParam(fRecoParam);
569 TString recoOptions="hlt,!cw";
570 if(fProcessTracklets) recoOptions += ",tp";
571 else recoOptions += ",!tp";
573 HLTDebug("Reconstructor options are: %s",recoOptions.Data());
574 fReconstructor->SetOption(recoOptions.Data());
576 if (fRecoDataType < 0 || fRecoDataType > 1)
578 HLTWarning("No data type selected. Use -simulation or -experiment flag. Defaulting to simulation.");
582 if (fRecoDataType == 0)
584 AliTRDrawStreamBase::SetRawStreamVersion(AliTRDrawStreamBase::kTRDsimStream);
585 HLTDebug("Data type expected is SIMULATION!");
588 if (fRecoDataType == 1)
590 AliTRDrawStreamBase::SetRawStreamVersion(AliTRDrawStreamBase::kTRDrealStream);
591 HLTDebug("Data type expected is EXPERIMENT!");
596 AliTRDrawStreamBase::SetRawStreamVersion("FAST");
597 HLTDebug("fast rawstreamer used");
601 fClusterizer = new AliHLTTRDClusterizer("TRDCclusterizer", "TRDCclusterizer");
602 HLTDebug("TRDClusterizer at 0x%x", fClusterizer);
605 fClusterizer->SetRawVersion(fRawDataVersion);
610 int AliHLTTRDClusterizerComponent::Reconfigure(const char* cdbEntry, const char* chainId)
612 // see header file for class documentation
615 const char* path="HLT/ConfigTRD/ClusterizerComponent";
616 const char* defaultNotify="";
619 defaultNotify=" (default)";
622 HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
623 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
625 TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
627 HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
628 iResult=Configure(pString->GetString().Data());
630 HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
633 HLTError("cannot fetch object \"%s\" from CDB", path);