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),
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)/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 == 1)
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());
243 HLTDebug("We get the right data type: Block # %i/%i; Event 0x%08LX (%Lu) Received datatype: %s; Block Size: %i",
244 iBlock, evtData.fBlockCnt,
245 evtData.fEventID, evtData.fEventID,
246 DataType2Text(inputDataType).c_str(),
251 unsigned long constBase;
252 double inputMultiplier;
253 GetOutputDataSize(constBase,inputMultiplier);
254 if(size<(constBase+block.fSize*inputMultiplier)){
255 HLTWarning("Memory Block given might be too small: %i < %i; Event %Lu", size, constBase+block.fSize*inputMultiplier, evtData.fEventID);
259 // fMemReader->Reset();
260 fMemReader->SetMemory((UChar_t*) block.fPtr, block.fSize);
262 AliHLTUInt32_t spec = block.fSpecification;
266 for ( Int_t ii = 0; ii < 18 ; ii++ ) {
274 fMemReader->SetEquipmentID( id );
276 fClusterizer->SetMemBlock(outputPtr+offset);
277 Bool_t bclustered = fClusterizer->Raw2ClustersChamber(fMemReader);
280 HLTDebug("Clustered successfully");
284 HLTError("Clustering ERROR");
288 AliHLTUInt32_t addedSize;
289 if(fReconstructor->IsProcessingTracklets()){
290 addedSize = fClusterizer->GetAddedTrSize();
291 totalSize += fClusterizer->GetTrMemBlockSize(); //if IsProcessingTracklets() is enabled we always reserve a data block of size GetTrMemBlockSize() for the tracklets
293 // Using low-level interface
294 // with interface classes
295 if ( totalSize > size )
297 HLTError("Too much data; Data written over allowed buffer. Amount written: %lu, allowed amount: %lu.",
303 AliHLTComponentBlockData bd;
306 bd.fSize = addedSize;
307 bd.fSpecification = block.fSpecification;
308 bd.fDataType = AliHLTTRDDefinitions::fgkMCMtrackletDataType;
309 outputBlocks.push_back( bd );
310 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);
315 addedSize = fClusterizer->GetAddedClSize();
318 Int_t* nTimeBins = (Int_t*)(outputPtr+offset+fClusterizer->GetAddedClSize());
319 *nTimeBins = fClusterizer->GetNTimeBins();
320 addedSize += sizeof(*nTimeBins);
322 totalSize += addedSize;
323 if ( totalSize > size )
325 HLTError("Too much data; Data written over allowed buffer. Amount written: %lu, allowed amount: %lu.",
331 AliHLTComponentBlockData bd;
334 bd.fSize = addedSize;
335 bd.fSpecification = block.fSpecification;
336 bd.fDataType = AliHLTTRDDefinitions::fgkClusterDataType;
337 outputBlocks.push_back( bd );
338 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);
342 HLTDebug("Array of clusters is empty!");
345 fReconstructor->SetClusters(0x0);
348 HLTDebug("Event is done. size written to the output is %i", size);
352 void AliHLTTRDClusterizerComponent::PrintObject( TClonesArray* inClustersArray)
354 AliTRDcluster* cluster=0x0;
356 for (Int_t i=0; i < inClustersArray->GetEntriesFast(); i++){
357 cluster = dynamic_cast<AliTRDcluster*>(inClustersArray->At(i));
358 HLTDebug("cluster[%i]",i);
359 HLTDebug(" PadCol = %i; PadRow = %i; PadTime = %i", cluster->GetPadCol(), cluster->GetPadRow(), cluster->GetPadTime());
360 HLTDebug(" Detector = %i, Amplitude = %f, Center = %f", cluster->GetDetector(), cluster->GetQ(), cluster->GetCenter());
361 HLTDebug(" LocalTimeBin = %i; NPads = %i; maskedPosition: %s, status: %s", cluster->GetLocalTimeBin(), cluster->GetNPads(),cluster->GetPadMaskedPosition(),cluster->GetPadMaskedPosition());
366 int AliHLTTRDClusterizerComponent::Configure(const char* arguments){
368 if (!arguments) return iResult;
370 TString allArgs=arguments;
374 TObjArray* pTokens=allArgs.Tokenize(" ");
376 for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
377 argument=((TObjString*)pTokens->At(i))->GetString();
378 if (argument.IsNull()) continue;
380 if (argument.CompareTo("output_percentage")==0) {
381 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
382 HLTInfo("Setting output percentage to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
383 fOutputPercentage=((TObjString*)pTokens->At(i))->GetString().Atoi();
386 else if (argument.CompareTo("-geometry")==0) {
387 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
388 HLTInfo("Setting geometry to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
389 fgeometryFileName=((TObjString*)pTokens->At(i))->GetString();
392 else if (argument.CompareTo("-lowflux")==0) {
394 HLTInfo("Low flux reconstruction selected");
397 else if (argument.CompareTo("-highflux")==0) {
399 HLTInfo("High flux reconstruction selected");
402 else if (argument.CompareTo("-cosmics")==0) {
404 HLTInfo("Cosmics reconstruction selected");
407 else if (argument.CompareTo("-simulation")==0) {
409 HLTInfo("Awaiting simulated data");
412 else if (argument.CompareTo("-experiment")==0) {
414 HLTInfo("Awaiting real data");
417 else if (argument.CompareTo("-processTracklets")==0) {
418 fProcessTracklets = kTRUE;
419 HLTInfo("Writing L1 tracklets to output");
422 else if (argument.CompareTo("-noZS")==0) {
423 fOutputPercentage = 100;
424 HLTInfo("Awaiting non zero surpressed data");
427 else if (argument.CompareTo("-faststreamer")==0) {
428 fHLTstreamer = kTRUE;
429 HLTInfo("Useing fast raw streamer");
432 else if (argument.CompareTo("-nofaststreamer")==0) {
433 fHLTstreamer = kFALSE;
434 HLTInfo("Don't use fast raw streamer");
437 else if (argument.CompareTo("-tailcancellation")==0) {
439 HLTInfo("Useing tailcancellation");
442 else if (argument.CompareTo("-rawver")==0) {
443 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
444 HLTInfo("Raw data version is: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
445 fRawDataVersion=((TObjString*)pTokens->At(i))->GetString().Atoi();
448 else if (argument.CompareTo("-yPosMethod")==0) {
449 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
450 TString toCompareTo=((TObjString*)pTokens->At(i))->GetString();
451 if (toCompareTo.CompareTo("COG")==0){
452 HLTInfo("Setting yPosMethod method to: %s", toCompareTo.Data());
455 else if (toCompareTo.CompareTo("LUT")==0){
456 HLTInfo("Setting yPosMethod method to: %s", toCompareTo.Data());
459 else if (toCompareTo.CompareTo("Gauss")==0){
460 HLTInfo("Setting yPosMethod method to: %s", toCompareTo.Data());
464 HLTError("unknown argument for yPosMethod: %s", toCompareTo.Data());
472 HLTError("unknown argument: %s", argument.Data());
480 HLTError("missing parameter for argument %s", argument.Data());
489 int AliHLTTRDClusterizerComponent::SetParams()
492 if(!AliCDBManager::Instance()->IsDefaultStorageSet()){
493 HLTError("DefaultStorage is not set in CDBManager");
496 if(AliCDBManager::Instance()->GetRun()<0){
497 HLTError("Run Number is not set in CDBManager");
500 HLTInfo("CDB default storage: %s; RunNo: %i", (AliCDBManager::Instance()->GetDefaultStorage()->GetBaseFolder()).Data(), AliCDBManager::Instance()->GetRun());
502 if(!AliGeomManager::GetGeometry()){
503 if(fgeometryFileName.CompareTo("")==0 || !TFile::Open(fgeometryFileName.Data())){
504 HLTInfo("Loading standard geometry file");
505 AliGeomManager::LoadGeometry();
507 HLTWarning("Loading NON-standard geometry file");
508 AliGeomManager::LoadGeometry(fgeometryFileName.Data());
510 if(!AliGeomManager::GetGeometry()){
511 HLTError("Could not load geometry");
516 HLTInfo("Geometry Already Loaded!");
519 if (fRecoParamType == 0)
521 HLTDebug("Low flux params init.");
522 fRecoParam = AliTRDrecoParam::GetLowFluxParam();
525 if (fRecoParamType == 1)
527 HLTDebug("High flux params init.");
528 fRecoParam = AliTRDrecoParam::GetHighFluxParam();
531 if (fRecoParamType == 2)
533 HLTDebug("Cosmic Test params init.");
534 fRecoParam = AliTRDrecoParam::GetCosmicTestParam();
539 HLTError("No reco params initialized. Sniffing big trouble!");
543 // backward compatibility to AliTRDrecoParam < r34995
544 # ifndef HAVE_NOT_ALITRDRECOPARAM_r34995
545 # define AliTRDRecoParamSetTailCancelation(b) fRecoParam->SetTailCancelation(b)
546 # define AliTRDRecoParamSetGAUS(b) fRecoParam->SetGAUS(b)
547 # define AliTRDRecoParamSetLUT(b) fRecoParam->SetLUT(b)
549 # define AliTRDRecoParamSetTailCancelation(b) fRecoParam->SetTailCancelation()
550 # define AliTRDRecoParamSetGAUS(b) fRecoParam->SetGAUS()
551 # define AliTRDRecoParamSetLUT(b) fRecoParam->SetLUT()
554 if(fTC){AliTRDRecoParamSetTailCancelation(kTRUE); HLTDebug("Enableing Tail Cancelation"); }
555 else{AliTRDRecoParamSetTailCancelation(kFALSE); HLTDebug("Enableing Tail Cancelation"); }
558 case 0: AliTRDRecoParamSetGAUS(kFALSE); AliTRDRecoParamSetLUT(kFALSE); break;
559 case 1: AliTRDRecoParamSetGAUS(kFALSE); AliTRDRecoParamSetLUT(kTRUE); break;
560 case 2: AliTRDRecoParamSetGAUS(kTRUE); AliTRDRecoParamSetLUT(kFALSE); break;
563 fRecoParam->SetStreamLevel(AliTRDrecoParam::kClusterizer, 0);
564 fReconstructor->SetRecoParam(fRecoParam);
566 TString recoOptions="hlt,!cw";
567 if(fProcessTracklets) recoOptions += ",tp";
568 else recoOptions += ",!tp";
570 HLTDebug("Reconstructor options are: %s",recoOptions.Data());
571 fReconstructor->SetOption(recoOptions.Data());
573 if (fRecoDataType < 0 || fRecoDataType > 1)
575 HLTWarning("No data type selected. Use -simulation or -experiment flag. Defaulting to simulation.");
579 if (fRecoDataType == 0)
581 AliTRDrawStreamBase::SetRawStreamVersion(AliTRDrawStreamBase::kTRDsimStream);
582 HLTDebug("Data type expected is SIMULATION!");
585 if (fRecoDataType == 1)
587 AliTRDrawStreamBase::SetRawStreamVersion(AliTRDrawStreamBase::kTRDrealStream);
588 HLTDebug("Data type expected is EXPERIMENT!");
593 AliTRDrawStreamBase::SetRawStreamVersion("FAST");
594 HLTDebug("fast rawstreamer used");
598 fClusterizer = new AliHLTTRDClusterizer("TRDCclusterizer", "TRDCclusterizer");
599 HLTDebug("TRDClusterizer at 0x%x", fClusterizer);
602 fClusterizer->SetRawVersion(fRawDataVersion);
607 int AliHLTTRDClusterizerComponent::Reconfigure(const char* cdbEntry, const char* chainId)
609 // see header file for class documentation
612 const char* path="HLT/ConfigTRD/ClusterizerComponent";
613 const char* defaultNotify="";
616 defaultNotify=" (default)";
619 HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
620 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
622 TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
624 HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
625 iResult=Configure(pString->GetString().Data());
627 HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
630 HLTError("cannot fetch object \"%s\" from CDB", path);