#include "AliHLTTRDClusterizerComponent.h"
#include "AliHLTTRDDefinitions.h"
+#include "AliHLTTRDCluster.h"
#include "AliGeomManager.h"
#include "AliTRDReconstructor.h"
#include "AliCDBManager.h"
-#include "AliTRDclusterizerHLT.h"
+#include "AliCDBStorage.h"
+#include "AliHLTTRDClusterizer.h"
#include "AliTRDrecoParam.h"
#include "AliTRDrawStreamBase.h"
+#include "AliTRDcluster.h"
#include "AliRawReaderMemory.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)
- , fRecoParam(NULL)
- , fCDB(NULL)
- , fMemReader(NULL)
- , fGeometryFileName("")
- , fGeometryFile(NULL)
- , fReconstructor(NULL)
+AliHLTTRDClusterizerComponent::AliHLTTRDClusterizerComponent():
+ AliHLTProcessor(),
+ fOutputPercentage(500),
+ fOutputConst(0),
+ fClusterizer(NULL),
+ fRecoParam(NULL),
+ fMemReader(NULL),
+ fReconstructor(NULL)
{
// 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 *
{
// Get the list of input data
list.clear(); // We do not have any requirements for our input data type(s).
- list.push_back( AliHLTTRDDefinitions::fgkDDLRawDataType );
+ list.push_back( (kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTRD) );
}
AliHLTComponent_DataType AliHLTTRDClusterizerComponent::GetOutputDataType()
{
// Get the output data type
- return AliHLTTRDDefinitions::fgkClusterDataType;
+ return kAliHLTMultipleDataType;
}
+int AliHLTTRDClusterizerComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList)
+{
+ // Get the output data type
+ tgtList.clear();
+ tgtList.push_back(AliHLTTRDDefinitions::fgkClusterDataType);
+ tgtList.push_back(AliHLTTRDDefinitions::fgkMCMtrackletDataType);
+ return tgtList.size();
+}
+
+
void AliHLTTRDClusterizerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
{
// Get the output data size
- constBase = 0;
+ constBase = fOutputConst;
inputMultiplier = ((double)fOutputPercentage)/100.0;
}
int AliHLTTRDClusterizerComponent::DoInit( int argc, const char** argv )
{
// perform initialization. We check whether our relative output size is specified in the arguments.
- fOutputPercentage = 100;
Int_t iRawDataVersion = 2;
int i = 0;
char* cpErr;
// 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
+ Bool_t bProcessTracklets = kFALSE;
+ string geometryFileName = "";
while ( i < argc )
{
HLTError("Cannot convert output_percentage parameter '%s'", argv[i+1] );
return EINVAL;
}
- HLTInfo("Output percentage set to %lu %%", fOutputPercentage );
+ HLTInfo("Output percentage set to %i %%", fOutputPercentage );
i += 2;
- continue;
}
-
- if ( strcmp( argv[i], "-cdb" ) == 0)
- {
- if ( i+1 >= argc )
- {
- HLTError("Missing -cdb argument");
- return ENOTSUP;
- }
- fStrorageDBpath = argv[i+1];
- HLTInfo("DB storage is %s", fStrorageDBpath.c_str() );
- i += 2;
- continue;
- }
-
- // the flux parametrizations
- if ( strcmp( argv[i], "-lowflux" ) == 0)
+ else if ( strcmp( argv[i], "-lowflux" ) == 0)
{
iRecoParamType = 0;
HLTDebug("Low flux reco selected.");
i++;
- continue;
- }
-
- if ( strcmp( argv[i], "-highflux" ) == 0)
+ }
+ else if ( strcmp( argv[i], "-highflux" ) == 0)
{
iRecoParamType = 1;
HLTDebug("High flux reco selected.");
i++;
- continue;
- }
-
- if ( strcmp( argv[i], "-cosmics" ) == 0)
+ }
+ else if ( strcmp( argv[i], "-cosmics" ) == 0)
{
iRecoParamType = 2;
HLTDebug("Cosmic test reco selected.");
i++;
- continue;
- }
-
+ }
// raw data type - sim or experiment
- if ( strcmp( argv[i], "-simulation" ) == 0)
+ else if ( strcmp( argv[i], "-simulation" ) == 0)
{
iRecoDataType = 0;
i++;
- continue;
}
-
- if ( strcmp( argv[i], "-experiment" ) == 0)
+ else if ( strcmp( argv[i], "-experiment" ) == 0)
{
iRecoDataType = 1;
i++;
- continue;
}
-
- if ( strcmp( argv[i], "-rawver" ) == 0)
+ else if ( strcmp( argv[i], "-rawver" ) == 0)
{
if ( i+1 >= argc )
{
iRawDataVersion = atoi( argv[i+1] );
HLTInfo("Raw data version is %d", iRawDataVersion );
i += 2;
- continue;
+
}
- if ( strcmp( argv[i], "-geometry" ) == 0)
+ else if ( strcmp( argv[i], "-geometry" ) == 0)
{
if ( i+1 >= argc )
{
HLTError("Missing -geometry argument");
return ENOTSUP;
}
- fGeometryFileName = argv[i+1];
- HLTInfo("GeomFile storage is %s", fGeometryFileName.c_str() );
+ geometryFileName = argv[i+1];
+ HLTInfo("GeomFile storage is %s", geometryFileName.c_str() );
i += 2;
- continue;
- }
-
- HLTError("Unknown option '%s'", argv[i] );
- return EINVAL;
+ }
+ else if ( strcmp( argv[i], "-processTracklets" ) == 0)
+ {
+ bProcessTracklets = kTRUE;
+ i++;
+ }
+ 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 if ( strcmp( argv[i], "-noZS" ) == 0) //no zero surpression in the input data
+ {
+ fOutputPercentage = 100;
+ i++;
+ }
+
+ else{
+ HLTError("Unknown option '%s'", argv[i] );
+ return EINVAL;
+ }
+
}
// THE "REAL" INIT COMES HERE
- if (iRecoParamType < 0 || iRecoParamType > 2)
+if (iRecoParamType < 0 || iRecoParamType > 2)
{
HLTWarning("No reco param selected. Use -lowflux or -highflux flag. Defaulting to low flux.");
iRecoParamType = 0;
fReconstructor = new AliTRDReconstructor();
fReconstructor->SetRecoParam(fRecoParam);
fReconstructor->SetStreamLevel(0, AliTRDReconstructor::kClusterizer); // default value
- fReconstructor->SetOption("!cw");
- //fReconstructor->Init();
-
+ 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;
+ }
+ if(bProcessTracklets) recoOptions += ",tp";
+ else recoOptions += ",!tp";
+
+ HLTInfo("Reconstructor options: %s",recoOptions.Data());
+ 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
}
// the DATA BASE STUFF
- fCDB = AliCDBManager::Instance();
- if (!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());
- HLTDebug("CDB instance; fCDB 0x%x", fCDB);
- }
-
- fGeometryFile = TFile::Open(fGeometryFileName.c_str());
- if (fGeometryFile)
- {
- AliGeomManager::LoadGeometry(fGeometryFileName.c_str());
+
+ if(!AliCDBManager::Instance()->IsDefaultStorageSet()){
+ HLTError("DefaultStorage is not Set in CDBManager");
+ return -1;
+ }
+ if(AliCDBManager::Instance()->GetRun()<0){
+ AliCDBManager *cdb = AliCDBManager::Instance();
+ if (cdb)
+ {
+ cdb->SetRun(0);
+ HLTWarning("Setting CDB Runnumber to 0. CDB instance 0x%x", cdb);
+ }
+ else
+ {
+ HLTError("Could not get CDB instance", "cdb 0x%x", cdb);
+ return -1;
+ }
+ }
+ HLTInfo("CDB default storage: %s; RunNo: %i", (AliCDBManager::Instance()->GetDefaultStorage()->GetBaseFolder()).Data(), AliCDBManager::Instance()->GetRun());
+
+ if(!AliGeomManager::GetGeometry()){
+ if(!TFile::Open(geometryFileName.c_str())){
+ HLTInfo("Loading standard geometry file");
+ AliGeomManager::LoadGeometry();
+ }else{
+ HLTWarning("Loading non-standard geometry file");
+ AliGeomManager::LoadGeometry(geometryFileName.c_str());
}
- else
- {
- HLTError("Unable to open file. FATAL!");
- return -1;
+ if(!AliGeomManager::GetGeometry()){
+ HLTError("Cannot load geometry");
+ return EINVAL;
}
-
+ }
+ else{
+ HLTInfo("Geometry Already Loaded");
+ }
+
fMemReader = new AliRawReaderMemory;
- fClusterizer = new AliTRDclusterizerHLT("TRDCclusterizer", "TRDCclusterizer", fReconstructor);
+ fClusterizer = new AliHLTTRDClusterizer("TRDCclusterizer", "TRDCclusterizer");
+ fClusterizer->SetReconstructor(fReconstructor);
+ fClusterizer->SetUseLabels(kFALSE);
fClusterizer->SetRawVersion(iRawDataVersion);
- fClusterizer->InitClusterTree();
+
+ if(fReconstructor->IsProcessingTracklets())
+ fOutputConst = fClusterizer->GetTrMemBlockSize();
return 0;
}
fMemReader = 0;
delete fClusterizer;
fClusterizer = 0;
+
+ fReconstructor->SetClusters(0x0);
delete fReconstructor;
fReconstructor = 0x0;
return 0;
- if (fGeometryFile)
- {
- fGeometryFile->Close();
- delete fGeometryFile;
- fGeometryFile = 0;
- }
-
- if (fCDB)
- {
- HLTDebug("destroy fCDB");
- fCDB->Destroy();
- fCDB = 0;
- }
-
if (fRecoParam)
{
HLTDebug("Deleting fRecoParam");
int AliHLTTRDClusterizerComponent::DoEvent( const AliHLTComponentEventData& evtData,
const AliHLTComponentBlockData* blocks,
AliHLTComponent_TriggerData& /*trigData*/,
- AliHLTUInt8_t* /*outputPtr*/,
+ AliHLTUInt8_t* outputPtr,
AliHLTUInt32_t& size,
- vector<AliHLTComponent_BlockData>& /*outputBlocks*/ )
+ vector<AliHLTComponent_BlockData>& outputBlocks )
{
// Process an event
- HLTDebug( "NofBlocks %lu", evtData.fBlockCnt );
+
+ if (evtData.fEventID == 1)
+ CALLGRIND_START_INSTRUMENTATION;
+
+ HLTDebug( "NofBlocks %i", evtData.fBlockCnt );
// Process an event
+ AliHLTUInt32_t totalSize = 0, offset = 0;
//implement a usage of the following
// AliHLTUInt32_t triggerDataStructSize = trigData.fStructSize;
// Loop over all input blocks in the event
AliHLTComponentDataType expectedDataType = (kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTRD);
- for ( unsigned long i = 0; i < evtData.fBlockCnt; i++ )
- {
+ for ( UInt_t iBlock = 0; iBlock < evtData.fBlockCnt; iBlock++ )
+ {
+ const AliHLTComponentBlockData &block = blocks[iBlock];
// lets not use the internal TRD data types here : AliHLTTRDDefinitions::fgkDDLRawDataType
// which is depreciated - we use HLT global defs instead
- // if ( blocks[i].fDataType != (kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTRD) )
- AliHLTComponentDataType inputDataType = blocks[i].fDataType;
+ // if ( block.fDataType != (kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTRD) )
+ AliHLTComponentDataType inputDataType = block.fDataType;
if ( inputDataType != expectedDataType)
{
- HLTDebug( "Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
- evtData.fEventID, evtData.fEventID,
- DataType2Text(inputDataType).c_str(),
- DataType2Text(expectedDataType).c_str());
+ HLTDebug( "Block # %i/%i; Event 0x%08LX (%Lu) Wrong received datatype: %s - required datatype: %s; Skipping",
+ iBlock, evtData.fBlockCnt,
+ evtData.fEventID, evtData.fEventID,
+ DataType2Text(inputDataType).c_str(),
+ DataType2Text(expectedDataType).c_str());
continue;
}
-
+ else
+ {
+ HLTDebug("We get the right data type: Block # %i/%i; Event 0x%08LX (%Lu) Received datatype: %s; Block Size: %i",
+ iBlock, evtData.fBlockCnt,
+ evtData.fEventID, evtData.fEventID,
+ DataType2Text(inputDataType).c_str(),
+ block.fSize);
+ }
+
// fMemReader->Reset();
- fMemReader->SetMemory((UChar_t*) blocks[i].fPtr, blocks[i].fSize);
+ fMemReader->SetMemory((UChar_t*) block.fPtr, block.fSize);
- AliHLTUInt32_t spec = blocks[i].fSpecification;
+ AliHLTUInt32_t spec = block.fSpecification;
Int_t id = 1024;
}
spec = spec >> 1 ;
}
-
- fMemReader->SetEquipmentID( id );
- fClusterizer->ResetTree();
+ fMemReader->SetEquipmentID( id );
+
+ fClusterizer->SetMemBlock(outputPtr+offset);
Bool_t iclustered = fClusterizer->Raw2ClustersChamber(fMemReader);
if (iclustered == kTRUE)
{
return -1;
}
- // put the tree into output blocks
- TTree *fcTree = fClusterizer->GetClusterTree();
+ // put the tree into output
//fcTree->Print();
- PushBack(fcTree, AliHLTTRDDefinitions::fgkClusterDataType, blocks[i].fSpecification);
+ AliHLTUInt32_t addedSize;
+ if(fReconstructor->IsProcessingTracklets()){
+ addedSize = fClusterizer->GetAddedTrSize();
+ totalSize += fClusterizer->GetTrMemBlockSize(); //if IsProcessingTracklets() is enabled we always reserve a data block of size GetTrMemBlockSize() for the tracklets
+ if (addedSize > 0){
+ // Using low-level interface
+ // with interface classes
+ 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::fgkMCMtrackletDataType;
+ 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;
+ }
+ addedSize = fClusterizer->GetAddedClSize();
+ 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=0; // this function did not write data to the buffer directly
+ 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());
+ }
+
+}