@date
@brief A TRDClusterizer processing component for the HLT. */
+// see header file for class documentation //
+// or //
+// refer to README to build package //
+// or //
+// visit http://web.ift.uib.no/~kjeks/doc/alice-hlt //
+
#if __GNUC__ >= 3
using namespace std;
#endif
+#include "TTree.h"
+#include "TFile.h"
+#include "TBranch.h"
+
#include "AliHLTTRDClusterizerComponent.h"
#include "AliHLTTRDDefinitions.h"
+#include "AliHLTTRDCluster.h"
+#include "AliGeomManager.h"
+#include "AliTRDReconstructor.h"
#include "AliCDBManager.h"
-#include "AliTRDclusterizerV1HLT.h"
+#include "AliHLTTRDClusterizer.h"
+#include "AliTRDrecoParam.h"
+#include "AliTRDrawStreamBase.h"
+#include "AliTRDcluster.h"
+
#include "AliRawReaderMemory.h"
-#include "TTree.h"
-#include "TBranch.h"
+#ifdef HAVE_VALGRIND_CALLGRIND_H
+#include <valgrind/callgrind.h>
+#else
+#define CALLGRIND_START_INSTRUMENTATION do { } while (0)
+#define CALLGRIND_STOP_INSTRUMENTATION do { } while (0)
+#endif
#include <cstdlib>
#include <cerrno>
#include <string>
-// this is a global object used for automatic component registration, do not use this
-AliHLTTRDClusterizerComponent gAliHLTTRDClusterizerComponent;
-
-ClassImp(AliHLTTRDClusterizerComponent);
+ClassImp(AliHLTTRDClusterizerComponent)
-AliHLTTRDClusterizerComponent::AliHLTTRDClusterizerComponent()
- : AliHLTProcessor()
- , fOutputPercentage(100) // By default we copy to the output exactly what we got as input
- , fStrorageDBpath("local://$ALICE_ROOT")
- , fClusterizer(NULL)
- , fCDB(NULL)
- , fMemReader(NULL)
+AliHLTTRDClusterizerComponent::AliHLTTRDClusterizerComponent():
+ AliHLTProcessor(),
+ fOutputPercentage(100), // By default we copy to the output exactly what we got as input
+ fStrorageDBpath("local://$ALICE_ROOT/OCDB"),
+ fClusterizer(NULL),
+ fRecoParam(NULL),
+ fCDB(NULL),
+ fMemReader(NULL),
+ fReconstructor(NULL),
+ fGeometryFileName("")
{
// Default constructor
+
+ fGeometryFileName = getenv("ALICE_ROOT");
+ fGeometryFileName += "/HLT/TRD/geometry.root";
}
AliHLTTRDClusterizerComponent::~AliHLTTRDClusterizerComponent()
{
// Destructor
- ;
+ // Work is Done in DoDeInit()
}
+
const char* AliHLTTRDClusterizerComponent::GetComponentID()
{
// Return the component ID const char *
{
// perform initialization. We check whether our relative output size is specified in the arguments.
fOutputPercentage = 100;
- Int_t fRawDataVersion = 2;
+ Int_t iRawDataVersion = 2;
int i = 0;
char* cpErr;
+
+ Int_t iRecoParamType = -1; // default will be the low flux
+
+ // the data type will become obsolete as soon as the formats are established
+ Int_t iRecoDataType = -1; // default will be simulation
+ Int_t iyPosMethod = 1; // 0=COG 1=LUT 2=Gauss
+
while ( i < argc )
{
- Logging( kHLTLogDebug, "HLT::TRDClusterizer::DoInit", "Arguments", "argv[%d] == %s", i, argv[i] );
+ HLTDebug("argv[%d] == %s", i, argv[i] );
if ( !strcmp( argv[i], "output_percentage" ) )
{
if ( i+1>=argc )
{
- Logging(kHLTLogError, "HLT::TRDClusterizer::DoInit", "Missing Argument", "Missing output_percentage parameter");
+ HLTError("Missing output_percentage parameter");
return ENOTSUP;
}
- Logging( kHLTLogDebug, "HLT::TRDClusterizer::DoInit", "Arguments", "argv[%d+1] == %s", i, argv[i+1] );
+ HLTDebug("argv[%d+1] == %s", i, argv[i+1] );
fOutputPercentage = strtoul( argv[i+1], &cpErr, 0 );
if ( *cpErr )
{
- Logging(kHLTLogError, "HLT::TRDClusterizer::DoInit", "Wrong Argument", "Cannot convert output_percentage parameter '%s'", argv[i+1] );
+ HLTError("Cannot convert output_percentage parameter '%s'", argv[i+1] );
return EINVAL;
}
- Logging( kHLTLogInfo, "HLT::TRDClusterizer::DoInit", "Output percentage set", "Output percentage set to %lu %%", fOutputPercentage );
+ HLTInfo("Output percentage set to %lu %%", fOutputPercentage );
i += 2;
- continue;
}
-
- if ( strcmp( argv[i], "-cdb" ) == 0)
+ else if ( strcmp( argv[i], "-cdb" ) == 0)
{
if ( i+1 >= argc )
{
- Logging(kHLTLogError, "HLT::TRDClusterizer::DoInit", "Missing Argument", "Missing -cdb argument");
+ HLTError("Missing -cdb argument");
return ENOTSUP;
}
fStrorageDBpath = argv[i+1];
- Logging( kHLTLogInfo, "HLT::TRDClusterizer::DoInit", "DB storage set", "DB storage is %s", fStrorageDBpath.c_str() );
+ HLTInfo("DB storage is %s", fStrorageDBpath.c_str() );
i += 2;
- continue;
+ }
+ else if ( strcmp( argv[i], "-lowflux" ) == 0)
+ {
+ iRecoParamType = 0;
+ HLTDebug("Low flux reco selected.");
+ i++;
+ }
+ else if ( strcmp( argv[i], "-highflux" ) == 0)
+ {
+ iRecoParamType = 1;
+ HLTDebug("High flux reco selected.");
+ i++;
+ }
+ else if ( strcmp( argv[i], "-cosmics" ) == 0)
+ {
+ iRecoParamType = 2;
+ HLTDebug("Cosmic test reco selected.");
+ i++;
+ }
+ // raw data type - sim or experiment
+ else if ( strcmp( argv[i], "-simulation" ) == 0)
+ {
+ iRecoDataType = 0;
+ i++;
+ }
+ else if ( strcmp( argv[i], "-experiment" ) == 0)
+ {
+ iRecoDataType = 1;
+ i++;
+ }
+ else if ( strcmp( argv[i], "-rawver" ) == 0)
+ {
+ if ( i+1 >= argc )
+ {
+ HLTError("Missing -rawver argument");
+ return ENOTSUP;
+ }
+ iRawDataVersion = atoi( argv[i+1] );
+ HLTInfo("Raw data version is %d", iRawDataVersion );
+ i += 2;
+
}
- if ( strcmp( argv[i], "-rawver" ) == 0)
+ else if ( strcmp( argv[i], "-geometry" ) == 0)
{
if ( i+1 >= argc )
{
- Logging(kHLTLogError, "HLT::TRDClusterizer::DoInit", "Missing Argument", "Missing -rawver argument");
+ HLTError("Missing -geometry argument");
return ENOTSUP;
}
- fRawDataVersion = atoi( argv[i+1] );
- Logging( kHLTLogInfo, "HLT::TRDClusterizer::DoInit", "Raw Data", "Version is %d", fRawDataVersion );
+ fGeometryFileName = argv[i+1];
+ HLTInfo("GeomFile storage is %s", fGeometryFileName.c_str() );
i += 2;
- continue;
- }
+ }
- Logging(kHLTLogError, "HLT::TRDClusterizer::DoInit", "Unknown Option", "Unknown option '%s'", argv[i] );
- return EINVAL;
+ else if ( strcmp( argv[i], "-yPosMethod" ) == 0)
+ {
+ if ( i+1 >= argc )
+ {
+ HLTError("Missing -yPosMethod argument");
+ return ENOTSUP;
+ }
+ if( strcmp(argv[i], "COG") )
+ iyPosMethod=0;
+ else if( strcmp(argv[i], "LUT") )
+ iyPosMethod=1;
+ else if( strcmp(argv[i], "Gauss") )
+ iyPosMethod=2;
+ else {
+ HLTError("Unknown -yPosMethod argument");
+ return ENOTSUP;
+ }
+ i += 2;
+ }
+
+ else{
+ HLTError("Unknown option '%s'", argv[i] );
+ return EINVAL;
+ }
+
+ }
+
+ // THE "REAL" INIT COMES HERE
+
+ if (iRecoParamType < 0 || iRecoParamType > 2)
+ {
+ HLTWarning("No reco param selected. Use -lowflux or -highflux flag. Defaulting to low flux.");
+ iRecoParamType = 0;
+ }
+
+ if (iRecoParamType == 0)
+ {
+ fRecoParam = AliTRDrecoParam::GetLowFluxParam();
+ HLTDebug("Low flux params init.");
+ }
+
+ if (iRecoParamType == 1)
+ {
+ fRecoParam = AliTRDrecoParam::GetHighFluxParam();
+ HLTDebug("High flux params init.");
+ }
+
+ if (iRecoParamType == 2)
+ {
+ fRecoParam = AliTRDrecoParam::GetCosmicTestParam();
+ HLTDebug("Cosmic Test params init.");
+ }
+
+ if (fRecoParam == 0)
+ {
+ HLTError("No reco params initialized. Sniffing big trouble!");
+ return -1;
+ }
+
+ fReconstructor = new AliTRDReconstructor();
+ fReconstructor->SetRecoParam(fRecoParam);
+ fReconstructor->SetStreamLevel(0, AliTRDReconstructor::kClusterizer); // default value
+ HLTInfo("Not writing clusters. I.e. output is a TClonesArray of clusters");
+ TString recoOptions="hlt,!cw,sl_cf_0";
+ switch(iRecoDataType){
+ case 0: recoOptions += ",tc"; break;
+ case 1: recoOptions += ",!tc"; break;
+ }
+ switch(iyPosMethod){
+ case 0: recoOptions += ",!gs,!lut"; break;
+ case 1: recoOptions += ",!gs,lut"; break;
+ case 2: recoOptions += ",gs,!lut"; break;
+ }
+
+ fReconstructor->SetOption(recoOptions.Data());
+
+ // init the raw data type to be used...
+ // the switch here will become obsolete as soon as the data structures is fixed
+ // both: in sim and reality
+ if (iRecoDataType < 0 || iRecoDataType > 1)
+ {
+ HLTWarning("No data type selected. Use -simulation or -experiment flag. Defaulting to simulation.");
+ iRecoDataType = 0;
+ }
+
+ if (iRecoDataType == 0)
+ {
+ AliTRDrawStreamBase::SetRawStreamVersion(AliTRDrawStreamBase::kTRDsimStream);
+ HLTDebug("Data type expected is SIMULATION!");
}
+ if (iRecoDataType == 1)
+ {
+ AliTRDrawStreamBase::SetRawStreamVersion(AliTRDrawStreamBase::kTRDrealStream);
+ HLTDebug("Data type expected is EXPERIMENT!");
+ }
+
+ // the DATA BASE STUFF
fCDB = AliCDBManager::Instance();
if (!fCDB)
{
- Logging(kHLTLogError, "HLT::TRDCalibration::DoInit", "Could not get CDB instance", "fCDB 0x%x", fCDB);
+ HLTError("Could not get CDB instance", "fCDB 0x%x", fCDB);
}
else
{
fCDB->SetRun(0); // THIS HAS TO BE RETRIEVED !!!
fCDB->SetDefaultStorage(fStrorageDBpath.c_str());
- Logging(kHLTLogDebug, "HLT::TRDCalibration::DoInit", "CDB instance", "fCDB 0x%x", fCDB);
+ HLTDebug("CDB instance; fCDB 0x%x", fCDB);
}
+ if((AliGeomManager::GetGeometry()) == NULL){
+
+ if ( TFile::Open(fGeometryFileName.c_str())) {
+ AliGeomManager::LoadGeometry(fGeometryFileName.c_str());
+ }
+ else {
+ HLTError("Cannot load geometry from file %s",fGeometryFileName.c_str());
+ return EINVAL;
+ }
+ }
+ else
+ HLTInfo("Geometry Already Loaded");
+
fMemReader = new AliRawReaderMemory;
- fClusterizer = new AliTRDclusterizerV1HLT("TRDCclusterizer", "TRDCclusterizer");
- fClusterizer->SetRawDataVersion(fRawDataVersion);
- fClusterizer->InitClusterTree();
+
+ fClusterizer = new AliHLTTRDClusterizer("TRDCclusterizer", "TRDCclusterizer");
+ fClusterizer->SetReconstructor(fReconstructor);
+ fClusterizer->SetUseLabels(kFALSE);
+ fClusterizer->SetRawVersion(iRawDataVersion);
return 0;
}
fMemReader = 0;
delete fClusterizer;
fClusterizer = 0;
+
+ fReconstructor->SetClusters(0x0);
+ delete fReconstructor;
+ fReconstructor = 0x0;
return 0;
+
if (fCDB)
{
- Logging( kHLTLogDebug, "HLT::TRDCalibration::DoDeinit", "destroy", "fCDB");
+ HLTDebug("destroy fCDB");
fCDB->Destroy();
fCDB = 0;
}
+
+ if (fRecoParam)
+ {
+ HLTDebug("Deleting fRecoParam");
+ delete fRecoParam;
+ fRecoParam = 0;
+ }
}
-int AliHLTTRDClusterizerComponent::DoEvent( const AliHLTComponent_EventData& evtData, const AliHLTComponent_BlockData* blocks,
- AliHLTComponent_TriggerData& trigData, AliHLTUInt8_t* outputPtr,
- AliHLTUInt32_t& size, vector<AliHLTComponent_BlockData>& outputBlocks )
+int AliHLTTRDClusterizerComponent::DoEvent( const AliHLTComponentEventData& evtData,
+ const AliHLTComponentBlockData* blocks,
+ AliHLTComponent_TriggerData& /*trigData*/,
+ AliHLTUInt8_t* outputPtr,
+ AliHLTUInt32_t& size,
+ vector<AliHLTComponent_BlockData>& outputBlocks )
{
// Process an event
- Logging( kHLTLogInfo, "HLT::TRDClusterizer::DoEvent", "Output percentage set", "Output percentage set to %lu %%", fOutputPercentage );
- Logging( kHLTLogInfo, "HLT::TRDClusterizer::DoEvent", "BLOCKS", "NofBlocks %lu", evtData.fBlockCnt );
+ HLTDebug( "NofBlocks %lu", evtData.fBlockCnt );
// Process an event
- unsigned long totalSize = 0;
- AliHLTUInt32_t fDblock_Specification = 0;
+ AliHLTUInt32_t totalSize = 0, offset = 0;
+
+ //implement a usage of the following
+ // AliHLTUInt32_t triggerDataStructSize = trigData.fStructSize;
+ // AliHLTUInt32_t triggerDataSize = trigData.fDataSize;
+ // void *triggerData = trigData.fData;
+ //HLTDebug( "Trigger data received. Struct size %d Data size %d Data location 0x%x", trigData.fStructSize, trigData.fDataSize, (UInt_t*)trigData.fData);
// Loop over all input blocks in the event
+ AliHLTComponentDataType expectedDataType = (kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTRD);
for ( unsigned long i = 0; i < evtData.fBlockCnt; i++ )
{
- char tmp1[14], tmp2[14];
- DataType2Text( blocks[i].fDataType, tmp1 );
- DataType2Text( AliHLTTRDDefinitions::fgkDDLRawDataType, tmp2 );
- Logging( kHLTLogDebug, "HLT::TRDClusterizer::DoEvent", "Event received",
- "Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
- evtData.fEventID, evtData.fEventID, tmp1, tmp2 );
-
- if ( blocks[i].fDataType != AliHLTTRDDefinitions::fgkDDLRawDataType )
+ if (evtData.fEventID == 1)
+ CALLGRIND_START_INSTRUMENTATION;
+
+ const AliHLTComponentBlockData &block = blocks[i];
+ // lets not use the internal TRD data types here : AliHLTTRDDefinitions::fgkDDLRawDataType
+ // which is depreciated - we use HLT global defs instead
+ // if ( block.fDataType != (kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTRD) )
+ AliHLTComponentDataType inputDataType = block.fDataType;
+ if ( inputDataType != expectedDataType)
{
- Logging (kHLTLogError, "HLT::TRDClusterizer::DoEvent", "COMPARE FAILED", "type=%d is type=%d",
- blocks[i].fDataType, AliHLTTRDDefinitions::fgkDDLRawDataType);
+ HLTDebug( "Block # %i/%i; Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s; Skipping",
+ i, evtData.fBlockCnt,
+ evtData.fEventID, evtData.fEventID,
+ DataType2Text(inputDataType).c_str(),
+ DataType2Text(expectedDataType).c_str());
continue;
}
- fDblock_Specification = blocks[i].fSpecification;
- unsigned long blockSize = blocks[i].fSize;
- totalSize += blockSize;
- }
-
- void *memBufIn = calloc(totalSize, 1);
- AliHLTUInt8_t *pBuf = (AliHLTUInt8_t *)memBufIn;
- if (memBufIn == NULL)
- {
- Logging( kHLTLogError, "HLT::TRDClusterizer::DoEvent", "MEMORY", "Unable to allocate %lu bytes", totalSize);
- return -1;
- }
-
- // Make the memory continuous
- unsigned long copied = 0;
- for ( unsigned long i = 0; i < evtData.fBlockCnt; i++ )
- {
- if ( blocks[i].fDataType != AliHLTTRDDefinitions::fgkDDLRawDataType )
- continue;
-
- void *pos = (void*)(pBuf + copied);
- void *copyret = memcpy(pos, blocks[i].fPtr, blocks[i].fSize);
- if (copyret < 0)
+ else
+ {
+ HLTDebug("We get the right data type: Block # %i/%i; Event 0x%08LX (%Lu) Received datatype: %s",
+ i, evtData.fBlockCnt,
+ evtData.fEventID, evtData.fEventID,
+ DataType2Text(inputDataType).c_str());
+ }
+
+ // fMemReader->Reset();
+ fMemReader->SetMemory((UChar_t*) block.fPtr, block.fSize);
+
+ AliHLTUInt32_t spec = block.fSpecification;
+
+ Int_t id = 1024;
+
+ for ( Int_t ii = 0; ii < 18 ; ii++ ) {
+ if ( spec & 0x00000001 ) {
+ id += ii;
+ break;
+ }
+ spec = spec >> 1 ;
+ }
+
+ fMemReader->SetEquipmentID( id );
+
+ fClusterizer->SetMemBlock((AliHLTUInt8_t*)(outputPtr+offset));
+ Bool_t iclustered = fClusterizer->Raw2ClustersChamber(fMemReader);
+ if (iclustered == kTRUE)
+ {
+ HLTDebug( "Clustered successfully");
+ }
+ else
{
- Logging( kHLTLogError, "HLT::TRDClusterizer::DoEvent", "MEMORY", "Unable to copy %lu bytes", blocks[i].fSize);
+ HLTError("Clustering ERROR");
return -1;
}
- copied += blocks[i].fSize;
- }
- Logging( kHLTLogInfo, "HLT::TRDClusterizer::DoEvent", "COPY STATS", "total=%lu copied=%lu", totalSize, copied);
-
- fMemReader->Reset();
- fMemReader->SetMemory((UChar_t*)memBufIn, totalSize);
- //fMemReader->Reset();
- Bool_t ihead = fMemReader->ReadHeader();
- if (ihead == kTRUE)
- {
- Logging( kHLTLogInfo, "HLT::TRDClusterizer::DoEvent", "HEADER", "Header read successfully");
- }
- else
- {
- Logging( kHLTLogError, "HLT::TRDClusterizer::DoEvent", "HEADER", "Header read ERROR");
- //return -1; -- not FATAL
- }
-
- fClusterizer->ResetTree();
- Bool_t ireadD = fClusterizer->ReadDigits(fMemReader);
- if (ireadD == kTRUE)
- {
- Logging( kHLTLogInfo, "HLT::TRDClusterizer::DoEvent", "DIGITS", "Digits read successfully");
- }
- else
- {
- Logging( kHLTLogError, "HLT::TRDClusterizer::DoEvent", "DIGITS", "Digits read ERROR");
- return -1;
- }
-
- Bool_t iclustered = fClusterizer->MakeClusters();
- if (iclustered == kTRUE)
- {
- Logging( kHLTLogInfo, "HLT::TRDClusterizer::DoEvent", "CLUSTERS", "Clustered successfully");
- }
- else
- {
- Logging( kHLTLogError, "HLT::TRDClusterizer::DoEvent", "CLUSTERS", "Clustering ERROR");
- return -1;
- }
-
- free(memBufIn);
-
- //UInt_t memBufOutSize = 0;
- // void *memBufOut = fClusterizer->WriteClustersToMemory(memBufOut, memBufOutSize);
- Int_t iNclusters = fClusterizer->GetNclusters();
- Logging( kHLTLogInfo, "HLT::TRDClusterizer::DoEvent", "COUNT", "N of Clusters = %d", iNclusters);
-
- // put the tree into output blocks of TObjArrays
- TTree *fcTree = fClusterizer->GetClusterTree();
- TList *lt = (TList*)fcTree->GetListOfBranches();
- TIter it(lt);
- it.Reset();
- TBranch *tb = 0;
- while ((tb = (TBranch*)it.Next()) != 0)
- {
- TObjArray *clusters = 0;
- tb->SetAddress(&clusters);
- for (Int_t icb = 0; icb < tb->GetEntries(); icb++)
- {
- tb->GetEntry(icb);
- PushBack(clusters, AliHLTTRDDefinitions::fgkClusterDataType, fDblock_Specification);
+ // put the tree into output
+ //fcTree->Print();
+
+ AliHLTUInt32_t addedSize = fClusterizer->GetAddedSize();
+ if (addedSize > 0){
+ // Using low-level interface
+ // with interface classes
+ totalSize += addedSize;
+ if ( totalSize > size )
+ {
+ HLTError("Too much data; Data written over allowed buffer. Amount written: %lu, allowed amount: %lu.",
+ totalSize, size );
+ return EMSGSIZE;
+ }
+
+ // Fill block
+ AliHLTComponentBlockData bd;
+ FillBlockData( bd );
+ bd.fOffset = offset;
+ bd.fSize = addedSize;
+ //bd.fSpecification = spec;
+ bd.fSpecification = gkAliEventTypeData;
+ bd.fDataType = AliHLTTRDDefinitions::fgkClusterDataType;
+ outputBlocks.push_back( bd );
+ 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);
+ offset = totalSize;
+
}
+ else
+ HLTWarning("Array of clusters is empty!");
}
+ fReconstructor->SetClusters(0x0);
+ size = totalSize;
+ HLTDebug("Event is done. size written to the output is %i", size);
return 0;
}
+
+void AliHLTTRDClusterizerComponent::PrintObject( TClonesArray* inClustersArray)
+{
+ AliTRDcluster* cluster=0x0;
+
+ for (Int_t i=0; i < inClustersArray->GetEntriesFast(); i++){
+ cluster = dynamic_cast<AliTRDcluster*>(inClustersArray->At(i));
+ HLTDebug("cluster[%i]",i);
+ HLTDebug(" PadCol = %i; PadRow = %i; PadTime = %i", cluster->GetPadCol(), cluster->GetPadRow(), cluster->GetPadTime());
+ HLTDebug(" Detector = %i, Amplitude = %f, Center = %f", cluster->GetDetector(), cluster->GetQ(), cluster->GetCenter());
+ HLTDebug(" LocalTimeBin = %i; NPads = %i; maskedPosition: %s, status: %s", cluster->GetLocalTimeBin(), cluster->GetNPads(),cluster->GetPadMaskedPosition(),cluster->GetPadMaskedPosition());
+ }
+
+}
+