]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/TRD/AliHLTTRDClusterizerComponent.cxx
HLT TRD code update by Theodor
[u/mrichter/AliRoot.git] / HLT / TRD / AliHLTTRDClusterizerComponent.cxx
index 5f05fd468b92b99598bae7c445380059948a7880..2fbf81e5a4d7297dae59695aee3313324bb18c56 100644 (file)
@@ -42,6 +42,7 @@ using namespace std;
 #include "AliGeomManager.h"
 #include "AliTRDReconstructor.h"
 #include "AliCDBManager.h"
+#include "AliCDBStorage.h"
 #include "AliHLTTRDClusterizer.h"
 #include "AliTRDrecoParam.h"
 #include "AliTRDrawStreamBase.h"
@@ -52,31 +53,27 @@ using namespace std;
 #ifdef HAVE_VALGRIND_CALLGRIND_H
 #include <valgrind/callgrind.h>
 #else
-#define CALLGRIND_START_INSTRUMENTATION() do { } while (0)
-#define CALLGRIND_STOP_INSTRUMENTATION() do { } while (0)
+#define CALLGRIND_START_INSTRUMENTATION do { } while (0)
+#define CALLGRIND_STOP_INSTRUMENTATION do { } while (0)
 #endif
 
 #include <cstdlib>
 #include <cerrno>
 #include <string>
 
-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/OCDB"),
+  fOutputPercentage(500),
+  fOutputConst(0),
   fClusterizer(NULL),
   fRecoParam(NULL),
-  fCDB(NULL),
   fMemReader(NULL),
-  fReconstructor(NULL),
-  fGeometryFileName("")
+  fReconstructor(NULL)
 {
   // Default constructor
 
-  fGeometryFileName = getenv("ALICE_ROOT");
-  fGeometryFileName += "/HLT/TRD/geometry.root";
 }
 
 AliHLTTRDClusterizerComponent::~AliHLTTRDClusterizerComponent()
@@ -96,19 +93,29 @@ void AliHLTTRDClusterizerComponent::GetInputDataTypes( vector<AliHLTComponent_Da
 {
   // 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;
 }
 
@@ -121,7 +128,6 @@ AliHLTComponent* AliHLTTRDClusterizerComponent::Spawn()
 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;
@@ -130,6 +136,9 @@ int AliHLTTRDClusterizerComponent::DoInit( int argc, const char** argv )
 
   // 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 )
     {
@@ -148,61 +157,38 @@ int AliHLTTRDClusterizerComponent::DoInit( int argc, const char** argv )
              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;
        }
-      else 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;
-         
-       }      
-
       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 )
@@ -223,10 +209,40 @@ int AliHLTTRDClusterizerComponent::DoInit( int argc, const char** argv )
              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;
-       }      
+       } 
+      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;
@@ -236,7 +252,7 @@ int AliHLTTRDClusterizerComponent::DoInit( int argc, const char** argv )
 
   // 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;
@@ -270,8 +286,21 @@ int AliHLTTRDClusterizerComponent::DoInit( int argc, const char** argv )
   fReconstructor->SetRecoParam(fRecoParam);
   fReconstructor->SetStreamLevel(0, AliTRDReconstructor::kClusterizer); // default value
   HLTInfo("Not writing clusters. I.e. output is a TClonesArray of clusters");
-  fReconstructor->SetOption("hlt,!cw,sl_cf_0");
-  
+  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 
@@ -295,37 +324,52 @@ int AliHLTTRDClusterizerComponent::DoInit( int argc, const char** argv )
     }
 
   // 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);
-    }
-
-  if((AliGeomManager::GetGeometry()) == NULL){
-    
-    if ( TFile::Open(fGeometryFileName.c_str())) {
-      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("Cannot load geometry from file %s",fGeometryFileName.c_str());
+    if(!AliGeomManager::GetGeometry()){
+      HLTError("Cannot load geometry");
       return EINVAL;
     }
   }
-  else
+  else{
     HLTInfo("Geometry Already Loaded");
+  }  
   
   fMemReader = new AliRawReaderMemory;
 
   fClusterizer = new AliHLTTRDClusterizer("TRDCclusterizer", "TRDCclusterizer");
   fClusterizer->SetReconstructor(fReconstructor);
-  fClusterizer->SetAddLabels(kFALSE);
+  fClusterizer->SetUseLabels(kFALSE);
   fClusterizer->SetRawVersion(iRawDataVersion);
+
+  if(fReconstructor->IsProcessingTracklets())
+    fOutputConst = fClusterizer->GetTrMemBlockSize();
   return 0;
 }
 
@@ -342,14 +386,6 @@ int AliHLTTRDClusterizerComponent::DoDeinit()
   fReconstructor = 0x0;
   return 0;
 
-
-  if (fCDB)
-    {
-      HLTDebug("destroy fCDB");
-      fCDB->Destroy();
-      fCDB = 0;
-    }
-
   if (fRecoParam)
     {
       HLTDebug("Deleting fRecoParam");
@@ -366,7 +402,11 @@ int AliHLTTRDClusterizerComponent::DoEvent( const AliHLTComponentEventData& evtD
                                            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;
 
@@ -378,21 +418,17 @@ int AliHLTTRDClusterizerComponent::DoEvent( const AliHLTComponentEventData& evtD
 
   // Loop over all input blocks in the event
   AliHLTComponentDataType expectedDataType = (kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTRD);
-  for ( unsigned long i = 0; i < evtData.fBlockCnt; i++ )
-    {
-      if (evtData.fEventID == 1)
-       CALLGRIND_START_INSTRUMENTATION();
-      
-      const AliHLTComponentBlockData &block = blocks[i];
-      offset = totalSize;
+  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 ( block.fDataType != (kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTRD) )
       AliHLTComponentDataType inputDataType = block.fDataType;
       if ( inputDataType != expectedDataType)
        {
-         HLTDebug( "Block # %i/%i; Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s; Skipping",
-                   i, evtData.fBlockCnt,
+         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());
@@ -400,10 +436,11 @@ int AliHLTTRDClusterizerComponent::DoEvent( const AliHLTComponentEventData& evtD
        }
       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());
+         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();
@@ -423,7 +460,7 @@ int AliHLTTRDClusterizerComponent::DoEvent( const AliHLTComponentEventData& evtD
 
       fMemReader->SetEquipmentID( id ); 
       
-      fClusterizer->SetMemBlock(outputPtr);
+      fClusterizer->SetMemBlock(outputPtr+offset);
       Bool_t iclustered = fClusterizer->Raw2ClustersChamber(fMemReader);
       if (iclustered == kTRUE)
        {
@@ -438,18 +475,20 @@ int AliHLTTRDClusterizerComponent::DoEvent( const AliHLTComponentEventData& evtD
       // put the tree into output
       //fcTree->Print();
       
-      AliHLTUInt32_t addedSize = fClusterizer->GetAddedSize();
+      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
-         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 );
@@ -457,14 +496,40 @@ int AliHLTTRDClusterizerComponent::DoEvent( const AliHLTComponentEventData& evtD
          bd.fSize = addedSize;
          //bd.fSpecification = spec;
          bd.fSpecification = gkAliEventTypeData;
-         bd.fDataType = AliHLTTRDDefinitions::fgkClusterDataType;
+         bd.fDataType = AliHLTTRDDefinitions::fgkMCMtrackletDataType;
          outputBlocks.push_back( bd );
-         HLTDebug( "Block ; size %i; dataType %s; spec 0x%x ",
-                   bd.fSize, DataType2Text(bd.fDataType).c_str(), spec);
-             
+         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);
        }
-       else 
-         HLTWarning("Array of clusters is empty!");
+       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);
 
@@ -473,7 +538,6 @@ int AliHLTTRDClusterizerComponent::DoEvent( const AliHLTComponentEventData& evtD
   return 0;
 }
 
-
 void AliHLTTRDClusterizerComponent::PrintObject( TClonesArray* inClustersArray)
 {
   AliTRDcluster* cluster=0x0;
@@ -487,4 +551,3 @@ void AliHLTTRDClusterizerComponent::PrintObject( TClonesArray* inClustersArray)
   }
   
 }
-