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 ClassImp(AliHLTTRDClusterizerComponent)
68 AliHLTTRDClusterizerComponent::AliHLTTRDClusterizerComponent():
70 fOutputPercentage(500),
80 fgeometryFileName(""),
81 fProcessTracklets(kFALSE),
84 // Default constructor
88 AliHLTTRDClusterizerComponent::~AliHLTTRDClusterizerComponent()
91 // Work is Done in DoDeInit()
95 const char* AliHLTTRDClusterizerComponent::GetComponentID()
97 // Return the component ID const char *
98 return "TRDClusterizer"; // The ID of this component
101 void AliHLTTRDClusterizerComponent::GetInputDataTypes( vector<AliHLTComponent_DataType>& list)
103 // Get the list of input data
104 list.clear(); // We do not have any requirements for our input data type(s).
105 list.push_back( (kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTRD) );
108 AliHLTComponent_DataType AliHLTTRDClusterizerComponent::GetOutputDataType()
110 // Get the output data type
111 return kAliHLTMultipleDataType;
114 int AliHLTTRDClusterizerComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList)
116 // Get the output data type
118 tgtList.push_back(AliHLTTRDDefinitions::fgkClusterDataType);
119 tgtList.push_back(AliHLTTRDDefinitions::fgkMCMtrackletDataType);
120 return tgtList.size();
124 void AliHLTTRDClusterizerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
126 // Get the output data size
127 constBase = fOutputConst;
128 inputMultiplier = ((double)fOutputPercentage)/100.0;
131 AliHLTComponent* AliHLTTRDClusterizerComponent::Spawn()
133 // Spawn function, return new instance of this class
134 return new AliHLTTRDClusterizerComponent;
137 int AliHLTTRDClusterizerComponent::DoInit( int argc, const char** argv )
139 // perform initialization. We check whether our relative output size is specified in the arguments.
142 fReconstructor = new AliTRDReconstructor();
143 HLTDebug("TRDReconstructor at 0x%x", fReconstructor);
145 TString configuration="";
147 for (int i=0; i<argc && iResult>=0; i++) {
149 if (!configuration.IsNull()) configuration+=" ";
150 configuration+=argument;
153 if (!configuration.IsNull()) {
154 iResult=Configure(configuration.Data());
156 iResult=Reconfigure(NULL, NULL);
160 HLTFatal("Clusterizer was not initialized!");
164 if(iResult<0) return iResult;
166 fMemReader = new AliRawReaderMemory;
167 fClusterizer->SetReconstructor(fReconstructor);
168 fClusterizer->SetUseLabels(kFALSE);
170 if(fReconstructor->IsProcessingTracklets())
171 fOutputConst = fClusterizer->GetTrMemBlockSize();
176 int AliHLTTRDClusterizerComponent::DoDeinit()
178 // Deinitialization of the component
184 fReconstructor->SetClusters(0x0);
185 delete fReconstructor;
186 fReconstructor = 0x0;
191 HLTDebug("Deleting fRecoParam");
197 int AliHLTTRDClusterizerComponent::DoEvent( const AliHLTComponentEventData& evtData,
198 const AliHLTComponentBlockData* blocks,
199 AliHLTComponent_TriggerData& /*trigData*/,
200 AliHLTUInt8_t* outputPtr,
201 AliHLTUInt32_t& size,
202 vector<AliHLTComponent_BlockData>& outputBlocks )
206 if (evtData.fEventID == 1)
207 CALLGRIND_START_INSTRUMENTATION;
209 HLTDebug( "NofBlocks %i", evtData.fBlockCnt );
211 AliHLTUInt32_t totalSize = 0, offset = 0;
213 //implement a usage of the following
214 // AliHLTUInt32_t triggerDataStructSize = trigData.fStructSize;
215 // AliHLTUInt32_t triggerDataSize = trigData.fDataSize;
216 // void *triggerData = trigData.fData;
217 //HLTDebug( "Trigger data received. Struct size %d Data size %d Data location 0x%x", trigData.fStructSize, trigData.fDataSize, (UInt_t*)trigData.fData);
219 // Loop over all input blocks in the event
220 AliHLTComponentDataType expectedDataType = (kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTRD);
221 for ( UInt_t iBlock = 0; iBlock < evtData.fBlockCnt; iBlock++ )
223 const AliHLTComponentBlockData &block = blocks[iBlock];
224 // lets not use the internal TRD data types here : AliHLTTRDDefinitions::fgkDDLRawDataType
225 // which is depreciated - we use HLT global defs instead
226 // if ( block.fDataType != (kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTRD) )
227 AliHLTComponentDataType inputDataType = block.fDataType;
228 if ( inputDataType != expectedDataType)
230 HLTDebug( "Block # %i/%i; Event 0x%08LX (%Lu) Wrong received datatype: %s - required datatype: %s; Skipping",
231 iBlock, evtData.fBlockCnt,
232 evtData.fEventID, evtData.fEventID,
233 DataType2Text(inputDataType).c_str(),
234 DataType2Text(expectedDataType).c_str());
239 HLTDebug("We get the right data type: Block # %i/%i; Event 0x%08LX (%Lu) Received datatype: %s; Block Size: %i",
240 iBlock, evtData.fBlockCnt,
241 evtData.fEventID, evtData.fEventID,
242 DataType2Text(inputDataType).c_str(),
247 unsigned long constBase;
248 double inputMultiplier;
249 GetOutputDataSize(constBase,inputMultiplier);
250 if(size<(constBase+block.fSize*inputMultiplier)){
251 HLTWarning("Memory Block given might be too small: %i < %i; Event %Lu", size, constBase+block.fSize*inputMultiplier, evtData.fEventID);
255 // fMemReader->Reset();
256 fMemReader->SetMemory((UChar_t*) block.fPtr, block.fSize);
258 AliHLTUInt32_t spec = block.fSpecification;
262 for ( Int_t ii = 0; ii < 18 ; ii++ ) {
270 fMemReader->SetEquipmentID( id );
272 fClusterizer->SetMemBlock(outputPtr+offset);
273 Bool_t iclustered = fClusterizer->Raw2ClustersChamber(fMemReader);
274 if (iclustered == kTRUE)
276 HLTDebug( "Clustered successfully");
280 HLTError("Clustering ERROR");
284 // put the tree into output
287 AliHLTUInt32_t addedSize;
288 if(fReconstructor->IsProcessingTracklets()){
289 addedSize = fClusterizer->GetAddedTrSize();
290 totalSize += fClusterizer->GetTrMemBlockSize(); //if IsProcessingTracklets() is enabled we always reserve a data block of size GetTrMemBlockSize() for the tracklets
292 // Using low-level interface
293 // with interface classes
294 if ( totalSize > size )
296 HLTError("Too much data; Data written over allowed buffer. Amount written: %lu, allowed amount: %lu.",
302 AliHLTComponentBlockData bd;
305 bd.fSize = addedSize;
306 bd.fSpecification = block.fSpecification;
307 bd.fDataType = AliHLTTRDDefinitions::fgkMCMtrackletDataType;
308 outputBlocks.push_back( bd );
309 HLTDebug( "BD fPtr 0x%x, fOffset %i, size %i, dataType %s, spec 0x%x ", bd.fPtr, bd.fOffset, bd.fSize, DataType2Text(bd.fDataType).c_str(), spec);
314 addedSize = fClusterizer->GetAddedClSize();
316 // Using low-level interface
317 // with interface classes
318 totalSize += addedSize;
319 if ( totalSize > size )
321 HLTError("Too much data; Data written over allowed buffer. Amount written: %lu, allowed amount: %lu.",
327 AliHLTComponentBlockData bd;
330 bd.fSize = addedSize;
331 bd.fSpecification = block.fSpecification;
332 bd.fDataType = AliHLTTRDDefinitions::fgkClusterDataType;
333 outputBlocks.push_back( bd );
334 HLTDebug( "BD fPtr 0x%x, fOffset %i, size %i, dataType %s, spec 0x%x ", bd.fPtr, bd.fOffset, bd.fSize, DataType2Text(bd.fDataType).c_str(), spec);
339 HLTDebug("Array of clusters is empty!");
341 fReconstructor->SetClusters(0x0);
344 HLTDebug("Event is done. size written to the output is %i", size);
348 void AliHLTTRDClusterizerComponent::PrintObject( TClonesArray* inClustersArray)
350 AliTRDcluster* cluster=0x0;
352 for (Int_t i=0; i < inClustersArray->GetEntriesFast(); i++){
353 cluster = dynamic_cast<AliTRDcluster*>(inClustersArray->At(i));
354 HLTDebug("cluster[%i]",i);
355 HLTDebug(" PadCol = %i; PadRow = %i; PadTime = %i", cluster->GetPadCol(), cluster->GetPadRow(), cluster->GetPadTime());
356 HLTDebug(" Detector = %i, Amplitude = %f, Center = %f", cluster->GetDetector(), cluster->GetQ(), cluster->GetCenter());
357 HLTDebug(" LocalTimeBin = %i; NPads = %i; maskedPosition: %s, status: %s", cluster->GetLocalTimeBin(), cluster->GetNPads(),cluster->GetPadMaskedPosition(),cluster->GetPadMaskedPosition());
362 int AliHLTTRDClusterizerComponent::Configure(const char* arguments){
364 if (!arguments) return iResult;
366 TString allArgs=arguments;
370 TObjArray* pTokens=allArgs.Tokenize(" ");
372 for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
373 argument=((TObjString*)pTokens->At(i))->GetString();
374 if (argument.IsNull()) continue;
376 if (argument.CompareTo("output_percentage")==0) {
377 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
378 HLTInfo("Setting output percentage to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
379 fOutputPercentage=((TObjString*)pTokens->At(i))->GetString().Atoi();
382 else if (argument.CompareTo("-geometry")==0) {
383 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
384 HLTInfo("Setting geometry to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
385 fgeometryFileName=((TObjString*)pTokens->At(i))->GetString();
388 if (argument.CompareTo("-lowflux")==0) {
390 HLTInfo("Low flux reconstruction selected");
393 if (argument.CompareTo("-highflux")==0) {
395 HLTInfo("High flux reconstruction selected");
398 if (argument.CompareTo("-cosmics")==0) {
400 HLTInfo("Cosmics reconstruction selected");
403 if (argument.CompareTo("-simulation")==0) {
405 HLTInfo("Awaiting simulated data");
408 if (argument.CompareTo("-experiment")==0) {
410 HLTInfo("Awaiting real data");
413 if (argument.CompareTo("-processTracklets")==0) {
414 fProcessTracklets = kTRUE;
415 HLTInfo("Processing L1 Tracklets");
418 if (argument.CompareTo("-noZS")==0) {
419 fOutputPercentage = 100;
420 HLTInfo("Awaiting non zero surpressed data");
423 if (argument.CompareTo("-faststreamer")==0) {
424 fHLTstreamer = kTRUE;
425 HLTInfo("Useing fast raw streamer");
428 else if (argument.CompareTo("-rawver")==0) {
429 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
430 HLTInfo("Raw data version is: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
431 fRawDataVersion=((TObjString*)pTokens->At(i))->GetString().Atoi();
434 else if (argument.CompareTo("-yPosMethod")==0) {
435 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
436 TString toCompareTo=((TObjString*)pTokens->At(i))->GetString();
437 if (toCompareTo.CompareTo("COG")==0){
438 HLTInfo("Setting yPosMethod method to: %s", toCompareTo.Data());
441 else if (toCompareTo.CompareTo("LUT")==0){
442 HLTInfo("Setting yPosMethod method to: %s", toCompareTo.Data());
445 else if (toCompareTo.CompareTo("Gauss")==0){
446 HLTInfo("Setting yPosMethod method to: %s", toCompareTo.Data());
450 HLTError("unknown argument for yPosMethod: %s", toCompareTo.Data());
458 HLTError("unknown argument: %s", argument.Data());
466 HLTError("missing parameter for argument %s", argument.Data());
475 int AliHLTTRDClusterizerComponent::SetParams()
478 if(!AliCDBManager::Instance()->IsDefaultStorageSet()){
479 HLTError("DefaultStorage is not set in CDBManager");
482 if(AliCDBManager::Instance()->GetRun()<0){
483 HLTError("Run Number is not set in CDBManager");
486 HLTInfo("CDB default storage: %s; RunNo: %i", (AliCDBManager::Instance()->GetDefaultStorage()->GetBaseFolder()).Data(), AliCDBManager::Instance()->GetRun());
488 if(!AliGeomManager::GetGeometry()){
489 if(fgeometryFileName.CompareTo("")==0 || !TFile::Open(fgeometryFileName.Data())){
490 HLTInfo("Loading standard geometry file");
491 AliGeomManager::LoadGeometry();
493 HLTWarning("Loading NON-standard geometry file");
494 AliGeomManager::LoadGeometry(fgeometryFileName.Data());
496 if(!AliGeomManager::GetGeometry()){
497 HLTError("Could not load geometry");
502 HLTInfo("Geometry Already Loaded!");
505 TString recoOptions="hlt,!cw,sl_cl_0";
507 switch(fRecoDataType){
508 case 0: recoOptions += ",tc"; break;
509 case 1: recoOptions += ",!tc"; break;
512 case 0: recoOptions += ",!gs,!lut"; break;
513 case 1: recoOptions += ",!gs,lut"; break;
514 case 2: recoOptions += ",gs,!lut"; break;
516 if(fProcessTracklets) recoOptions += ",tp";
517 else recoOptions += ",!tp";
520 if (fRecoParamType == 0)
522 HLTDebug("Low flux params init.");
523 fRecoParam = AliTRDrecoParam::GetLowFluxParam();
526 if (fRecoParamType == 1)
528 HLTDebug("High flux params init.");
529 fRecoParam = AliTRDrecoParam::GetHighFluxParam();
532 if (fRecoParamType == 2)
534 HLTDebug("Cosmic Test params init.");
535 fRecoParam = AliTRDrecoParam::GetCosmicTestParam();
540 HLTError("No reco params initialized. Sniffing big trouble!");
544 fRecoParam->SetStreamLevel(AliTRDrecoParam::kClusterizer, 0);
545 fReconstructor->SetRecoParam(fRecoParam);
547 HLTDebug("Reconstructor options are: %s",recoOptions.Data());
548 fReconstructor->SetOption(recoOptions.Data());
550 if (fRecoDataType < 0 || fRecoDataType > 1)
552 HLTWarning("No data type selected. Use -simulation or -experiment flag. Defaulting to simulation.");
556 if (fRecoDataType == 0)
558 AliTRDrawStreamBase::SetRawStreamVersion(AliTRDrawStreamBase::kTRDsimStream);
559 HLTDebug("Data type expected is SIMULATION!");
562 if (fRecoDataType == 1)
564 AliTRDrawStreamBase::SetRawStreamVersion(AliTRDrawStreamBase::kTRDrealStream);
565 HLTDebug("Data type expected is EXPERIMENT!");
570 AliTRDrawStreamBase::SetRawStreamVersion("FAST");
571 HLTDebug("fast rawstreamer used");
575 fClusterizer = new AliHLTTRDClusterizer("TRDCclusterizer", "TRDCclusterizer");
576 HLTDebug("TRDClusterizer at 0x%x", fClusterizer);
579 fClusterizer->SetRawVersion(fRawDataVersion);
584 int AliHLTTRDClusterizerComponent::Reconfigure(const char* cdbEntry, const char* chainId)
586 // see header file for class documentation
589 const char* path="HLT/ConfigTRD/ClusterizerComponent";
590 const char* defaultNotify="";
593 defaultNotify=" (default)";
596 HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
597 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
599 TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
601 HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
602 iResult=Configure(pString->GetString().Data());
604 HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
607 HLTError("cannot fetch object \"%s\" from CDB", path);