]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/TRD/AliHLTTRDClusterizerComponent.cxx
fixing warnings
[u/mrichter/AliRoot.git] / HLT / TRD / AliHLTTRDClusterizerComponent.cxx
index c349d81421f6287150893e6155dc9107255ca498..a76d05ba2efaa5ee13d8e0c02dfa7508171f5219 100644 (file)
@@ -1,25 +1,26 @@
 // $Id$
 
-/**************************************************************************
- * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
- *                                                                        *
- * Authors: Matthias Richter <Matthias.Richter@ift.uib.no>                *
- *          Timm Steinbeck <timm@kip.uni-heidelberg.de>                   *
- *          for The ALICE Off-line Project.                               *
- *                                                                        *
- * Permission to use, copy, modify and distribute this software and its   *
- * documentation strictly for non-commercial purposes is hereby granted   *
- * without fee, provided that the above copyright notice appears in all   *
- * copies and that both the copyright notice and this permission notice   *
- * appear in the supporting documentation. The authors make no claims     *
- * about the suitability of this software for any purpose. It is          *
- * provided "as is" without express or implied warranty.                  *
- **************************************************************************/
+//**************************************************************************
+//* This file is property of and copyright by the ALICE HLT Project        * 
+//* ALICE Experiment at CERN, All rights reserved.                         *
+//*                                                                        *
+//* Primary Authors:                                                       *
+//*                  for The ALICE HLT Project.                            *
+//*                                                                        *
+//* Permission to use, copy, modify and distribute this software and its   *
+//* documentation strictly for non-commercial purposes is hereby granted   *
+//* without fee, provided that the above copyright notice appears in all   *
+//* copies and that both the copyright notice and this permission notice   *
+//* appear in the supporting documentation. The authors make no claims     *
+//* about the suitability of this software for any purpose. It is          *
+//* provided "as is" without express or implied warranty.                  *
+//**************************************************************************
 
 /** @file   AliHLTTRDClusterizerComponent.cxx
-    @author Timm Steinbeck, Matthias Richter
+    @author Theodor Rascanu
     @date   
-    @brief  A TRDClusterizer processing component for the HLT. */
+    @brief  A TRDClusterizer processing component for the HLT. 
+*/
 
 // see header file for class documentation                                   //
 // or                                                                        //
@@ -37,48 +38,64 @@ using namespace std;
 
 #include "AliHLTTRDClusterizerComponent.h"
 #include "AliHLTTRDDefinitions.h"
+#include "AliHLTTRDClusterizer.h"
+#include "AliHLTTRDUtils.h"
 
-#include "AliCDBManager.h"
-#include "AliTRDclusterizerHLT.h"
+#include "AliGeomManager.h"
 #include "AliTRDReconstructor.h"
+#include "AliCDBManager.h"
+#include "AliCDBStorage.h"
+#include "AliCDBEntry.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 (void)0
+#define CALLGRIND_STOP_INSTRUMENTATION (void)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)
-  , fGeoManager(NULL)
+: AliHLTProcessor(),
+  fOutputPercentage(100),
+  fOutputConst(0),
+  fClusterizer(NULL),
+  fRecoParam(NULL),
+  fMemReader(NULL),
+  fReconstructor(NULL),
+  fRecoParamType(-1),
+  fRecoDataType(-1),
+  fRawDataVersion(2),
+  fyPosMethod(1),
+  fgeometryFileName(""),
+  fProcessTracklets(kFALSE),
+  fHLTstreamer(kTRUE),
+  fTC(kFALSE),
+  fHLTflag(kTRUE),
+  fHighLevelOutput(kFALSE),
+  fEmulateHLTClusters(kFALSE)
 {
   // 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 *
@@ -89,20 +106,30 @@ 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()
+AliHLTComponentDataType 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;
-  inputMultiplier = ((double)fOutputPercentage)/100.0;
+  constBase = fOutputConst;
+  inputMultiplier = ((double)fOutputPercentage)*4/100.0;
 }
 
 AliHLTComponent* AliHLTTRDClusterizerComponent::Spawn()
@@ -114,193 +141,40 @@ 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;
-
-  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 iResult=0;
   
-  while ( i < argc )
-    {
-      Logging( kHLTLogDebug, "HLT::TRDClusterizer::DoInit", "Arguments", "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");
-             return ENOTSUP;
-           }
-         Logging( kHLTLogDebug, "HLT::TRDClusterizer::DoInit", "Arguments", "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] );
-             return EINVAL;
-           }
-         Logging( kHLTLogInfo, "HLT::TRDClusterizer::DoInit", "Output percentage set", "Output percentage set to %lu %%", fOutputPercentage );
-         i += 2;
-         continue;
-       }
-
-      if ( strcmp( argv[i], "-cdb" ) == 0)
-       {
-         if ( i+1 >= argc )
-           {
-             Logging(kHLTLogError, "HLT::TRDClusterizer::DoInit", "Missing Argument", "Missing -cdb argument");
-             return ENOTSUP;         
-           }
-         fStrorageDBpath = argv[i+1];
-         Logging( kHLTLogInfo, "HLT::TRDClusterizer::DoInit", "DB storage set", "DB storage is %s", fStrorageDBpath.c_str() );   
-         i += 2;
-         continue;
-       }      
-
-      // the flux parametrizations
-      if ( strcmp( argv[i], "-lowflux" ) == 0)
-       {
-         iRecoParamType = 0;     
-         HLTDebug("Low flux reco selected.");
-         i++;
-         continue;
-       }      
-
-      if ( strcmp( argv[i], "-highflux" ) == 0)
-       {
-         iRecoParamType = 1;     
-         HLTDebug("Low flux reco selected.");
-         i++;
-         continue;
-       }      
-
-      // raw data type - sim or experiment
-      if ( strcmp( argv[i], "-simulation" ) == 0)
-       {
-         iRecoDataType = 0;
-         i++;
-         continue;
-       }
-
-      if ( strcmp( argv[i], "-experiment" ) == 0)
-       {
-         iRecoDataType = 1;
-         i++;
-         continue;
-       }
-
-      if ( strcmp( argv[i], "-rawver" ) == 0)
-       {
-         if ( i+1 >= argc )
-           {
-             Logging(kHLTLogError, "HLT::TRDClusterizer::DoInit", "Missing Argument", "Missing -rawver argument");
-             return ENOTSUP;         
-           }
-         iRawDataVersion = atoi( argv[i+1] );
-         Logging( kHLTLogInfo, "HLT::TRDClusterizer::DoInit", "Raw Data", "Version is %d", iRawDataVersion );    
-         i += 2;
-         continue;
-       }      
-
-      if ( strcmp( argv[i], "-geometry" ) == 0)
-       {
-         if ( i+1 >= argc )
-           {
-             Logging(kHLTLogError, "HLT::TRDTracker::DoInit", "Missing Argument", "Missing -geometry argument");
-             return ENOTSUP;         
-           }
-         fGeometryFileName = argv[i+1];
-         Logging( kHLTLogInfo, "HLT::TRDTracker::DoInit", "GeomFile storage set", "GeomFile storage is %s", 
-                  fGeometryFileName.c_str() );   
-         i += 2;
-         continue;
-       }      
-
-      Logging(kHLTLogError, "HLT::TRDClusterizer::DoInit", "Unknown Option", "Unknown option '%s'", argv[i] );
-      return EINVAL;
-    }
-
-  // THE "REAL" INIT COMES HERE
-
-  if (iRecoParamType < 0 || iRecoParamType > 1)
-    {
-      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 (fRecoParam == 0)
-    {
-      HLTError("No reco params initialized. Sniffing big trouble!");
-      return -1;
-    }
-
-  AliTRDReconstructor reconstructor; reconstructor.SetRecoParam(fRecoParam);
-
-  // 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);
-    }
-  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);
-    }
-
-  fGeometryFile = TFile::Open(fGeometryFileName.c_str());
-  if (fGeometryFile)
-    {
-      fGeoManager = (TGeoManager *)fGeometryFile->Get("Geometry");
-    }
-  else
-    {
-      Logging(kHLTLogError, "HLT::TRDTracker::DoInit", "fGeometryFile", "Unable to open file. FATAL!");
-      return -1;
-    }
+  fReconstructor = new AliTRDReconstructor();
+  HLTDebug("TRDReconstructor at 0x%x", fReconstructor);
+
+  TString configuration="";
+  TString argument="";
+  for (int i=0; i<argc && iResult>=0; i++) {
+    argument=argv[i];
+    if (!configuration.IsNull()) configuration+=" ";
+    configuration+=argument;
+  }
+
+  if (!configuration.IsNull()) {
+    iResult=Configure(configuration.Data());
+  } else {
+    iResult=Reconfigure(NULL, NULL);
+  }
+
+  if(!fClusterizer){
+    HLTFatal("Clusterizer was not initialized!");
+    return -1;
+  }
+
+  if(iResult<0) return iResult;
 
   fMemReader = new AliRawReaderMemory;
+  fClusterizer->SetReconstructor(fReconstructor);
+  fClusterizer->SetUseLabels(kFALSE);
 
-  fClusterizer = new AliTRDclusterizerHLT("TRDCclusterizer", "TRDCclusterizer");
-  fClusterizer->SetRawVersion(iRawDataVersion);
-  fClusterizer->InitClusterTree();
-  return 0;
+  if(fReconstructor->IsProcessingTracklets())
+    fOutputConst = fClusterizer->GetTrMemBlockSize();
+
+  return iResult;
 }
 
 int AliHLTTRDClusterizerComponent::DoDeinit()
@@ -310,22 +184,12 @@ int AliHLTTRDClusterizerComponent::DoDeinit()
   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)
-    {
-      Logging( kHLTLogDebug, "HLT::TRDCalibration::DoDeinit", "destroy", "fCDB");
-      fCDB->Destroy();
-      fCDB = 0;
-    }
-
   if (fRecoParam)
     {
       HLTDebug("Deleting fRecoParam");
@@ -334,103 +198,529 @@ int AliHLTTRDClusterizerComponent::DoDeinit()
     }
 }
 
-int AliHLTTRDClusterizerComponent::DoEvent( const AliHLTComponent_EventData& evtData, 
-                                           const AliHLTComponent_BlockData* blocks, 
-                                           AliHLTComponent_TriggerData& trigData
-                                           AliHLTUInt8_t* /*outputPtr*/
+int AliHLTTRDClusterizerComponent::DoEvent( const AliHLTComponentEventData& evtData, 
+                                           const AliHLTComponentBlockData* blocks, 
+                                           AliHLTComponent_TriggerData& /*trigData*/
+                                           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 == 10)
+    CALLGRIND_START_INSTRUMENTATION;
+
+  if(!IsDataEvent())return 0;
+
+  HLTDebug( "NofBlocks %i", evtData.fBlockCnt );
   // Process an event
-  unsigned long totalSize = 0;
-  AliHLTUInt32_t dBlockSpecification = 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);
+  //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
-  for ( unsigned long i = 0; i < evtData.fBlockCnt; i++ )
-    {
+  AliHLTComponentDataType expectedDataType = (kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTRD);
+  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) )
+      //      if ( block.fDataType != (kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTRD) )
+      AliHLTComponentDataType inputDataType = block.fDataType;
+      if ( inputDataType != expectedDataType)
        {
-         HLTWarning("COMPARE FAILED received type=%d expected-or-type=%d",
-                    blocks[i].fDataType, kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTRD);
+         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());
+         if(block.fDataType == kAliHLTDataTypeEOR)
+           CALLGRIND_STOP_INSTRUMENTATION;
          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);
+       }
+      
+#ifndef NDEBUG
+      unsigned long constBase;
+      double inputMultiplier;
+      GetOutputDataSize(constBase,inputMultiplier);
+      if(size<(constBase+block.fSize*inputMultiplier)){
+       HLTWarning("Memory Block given might be too small: %i < %i; Event %Lu", size, constBase+block.fSize*inputMultiplier, evtData.fEventID);
+      }
+#endif
 
-      dBlockSpecification = blocks[i].fSpecification;
-      unsigned long blockSize = blocks[i].fSize;
-      totalSize += blockSize;
-    }
+      // fMemReader->Reset();
+      fMemReader->SetMemory((UChar_t*) block.fPtr, block.fSize);
 
-  void *memBufIn = calloc(totalSize, 1);
-  AliHLTUInt8_t *pBuf = (AliHLTUInt8_t *)memBufIn;
-  if (memBufIn == NULL)
-    {
-      HLTError("Unable to allocate %lu bytes", totalSize);
-      return -1;
+      AliHLTUInt32_t spec = block.fSpecification;
+      
+      Int_t id = AliHLTTRDUtils::GetSM(spec) + 1024;
+
+      fMemReader->SetEquipmentID(id);
+      
+      fClusterizer->SetMemBlock(outputPtr+offset);
+      Bool_t bclustered = fClusterizer->Raw2ClustersChamber(fMemReader);
+      if(bclustered)
+       {
+         HLTDebug("Clustered successfully");
+       }
+      else
+       {
+         HLTError("Clustering ERROR");
+         return -1;
+       }
+
+      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 = block.fSpecification;
+         bd.fDataType = AliHLTTRDDefinitions::fgkMCMtrackletDataType;
+         outputBlocks.push_back( bd );
+         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);
+       }
+       offset = totalSize;
+      }
+
+      addedSize = fClusterizer->GetAddedClSize();
+      if (addedSize > 0){
+       
+       Int_t* nTimeBins = (Int_t*)(outputPtr+offset+fClusterizer->GetAddedClSize());
+       *nTimeBins = fClusterizer->GetNTimeBins();
+       addedSize += sizeof(*nTimeBins);
+
+       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 = block.fSpecification;
+       bd.fDataType = AliHLTTRDDefinitions::fgkClusterDataType;
+       outputBlocks.push_back( bd );
+       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);
+       offset = totalSize;
+      }
+      else{
+       HLTDebug("Array of clusters is empty!");
+      }
     }
+  fReconstructor->SetClusters(0x0);
 
-  // Make the memory continuous
-  unsigned long copied = 0;
-  for ( unsigned long i = 0; i < evtData.fBlockCnt; i++ )
-    {
-      // we process only the raw data from TRD
-      if ( blocks[i].fDataType != (kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTRD) )
+  size = totalSize;
+  HLTDebug("Event is done. size written to the output is %i", size);
+  return 0;
+}
+
+void AliHLTTRDClusterizerComponent::PrintObject(
+#ifdef __DEBUG
+               TClonesArray* inClustersArray
+#else
+               TClonesArray*
+#endif
+       )
+{
+#ifdef __DEBUG
+  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());
+  }
+#endif
+}
+
+int AliHLTTRDClusterizerComponent::Configure(const char* arguments){
+  int iResult=0;
+  if (!arguments) return iResult;
+  
+  TString allArgs=arguments;
+  TString argument;
+  int bMissingParam=0;
+
+  TObjArray* pTokens=allArgs.Tokenize(" ");
+  if (pTokens) {
+    for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
+      argument=((TObjString*)pTokens->At(i))->GetString();
+      if (argument.IsNull()) continue;
+      
+      if (argument.CompareTo("output_percentage")==0) {
+       if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
+       HLTInfo("Setting output percentage to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
+       fOutputPercentage=((TObjString*)pTokens->At(i))->GetString().Atoi();
+       continue;
+      } 
+      else if (argument.CompareTo("-geometry")==0) {
+       if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
+       HLTInfo("Setting geometry to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
+       fgeometryFileName=((TObjString*)pTokens->At(i))->GetString();
+       continue;
+      } 
+      else if (argument.CompareTo("-lowflux")==0) {
+       fRecoParamType = 0;
+       HLTInfo("Low flux reconstruction selected");
+       continue;
+      }
+      else if (argument.CompareTo("-highflux")==0) {
+       fRecoParamType = 1;
+       HLTInfo("High flux reconstruction selected");
        continue;
+      }
+      else if (argument.CompareTo("-cosmics")==0) {
+       fRecoParamType = 2;
+       HLTInfo("Cosmics reconstruction selected");
+       continue;
+      }
+      else if (argument.CompareTo("-simulation")==0) {
+       fRecoDataType = 0;
+       HLTInfo("Awaiting simulated data");
+       continue;
+      }
+      else if (argument.CompareTo("-experiment")==0) {
+       fRecoDataType = 1;
+       HLTInfo("Awaiting real data");
+       continue;
+      }
+      else if (argument.CompareTo("-processTracklets")==0) {
+       fProcessTracklets = kTRUE;
+       HLTInfo("Writing L1 tracklets to output");
+       continue;
+      }
+      else if (argument.CompareTo("-noZS")==0) {
+       fOutputPercentage = 10;
+       HLTInfo("Awaiting non zero surpressed data");
+       continue;
+      }
+      else if (argument.CompareTo("-HLTflag")==0) {
+       if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
+       TString toCompareTo=((TObjString*)pTokens->At(i))->GetString();
+       if (toCompareTo.CompareTo("yes")==0){
+         HLTInfo("Setting HLTflag to: %s", toCompareTo.Data());
+         fHLTflag=kTRUE;
+       }
+       else if (toCompareTo.CompareTo("no")==0){
+         HLTInfo("Setting HLTflag to: %s", toCompareTo.Data());
+         fHLTflag=kFALSE;
+       }
+       else {
+         HLTError("unknown argument for HLTflag: %s", toCompareTo.Data());
+         iResult=-EINVAL;
+         break;
+       }
+       continue;
+      }
+      else if (argument.CompareTo("-faststreamer")==0) {
+       fHLTstreamer = kTRUE;
+       HLTInfo("Useing fast raw streamer");
+       continue;
+      }
+      else if (argument.CompareTo("-nofaststreamer")==0) {
+       fHLTstreamer = kFALSE;
+       HLTInfo("Don't use fast raw streamer");
+       continue;
+      }
+      else if (argument.CompareTo("-tailcancellation")==0) {
+       fTC = kTRUE;
+       HLTInfo("Useing tailcancellation");
+       continue;
+      }
+      else if (argument.CompareTo("-rawver")==0) {
+       if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
+       HLTInfo("Raw data version is: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
+       fRawDataVersion=((TObjString*)pTokens->At(i))->GetString().Atoi();
+       continue;
+      } 
+      else if (argument.CompareTo("-highLevelOutput")==0) {
+       if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
+       TString toCompareTo=((TObjString*)pTokens->At(i))->GetString();
+       if (toCompareTo.CompareTo("yes")==0){
+         HLTWarning("Setting highLevelOutput to: %s", toCompareTo.Data());
+         fHighLevelOutput=kTRUE;
+       }
+       else if (toCompareTo.CompareTo("no")==0){
+         HLTInfo("Setting highLevelOutput to: %s", toCompareTo.Data());
+         fHighLevelOutput=kFALSE;
+       }
+       else {
+         HLTError("unknown argument for highLevelOutput: %s", toCompareTo.Data());
+         iResult=-EINVAL;
+         break;
+       }
+       continue;
+      }
+      else if (argument.CompareTo("-emulateHLToutput")==0) {
+       if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
+       TString toCompareTo=((TObjString*)pTokens->At(i))->GetString();
+       if (toCompareTo.CompareTo("yes")==0){
+         HLTWarning("Setting emulateHLToutput to: %s", toCompareTo.Data());
+         fEmulateHLTClusters=kTRUE;
+       }
+       else if (toCompareTo.CompareTo("no")==0){
+         HLTInfo("Setting emulateHLToutput to: %s", toCompareTo.Data());
+         fEmulateHLTClusters=kFALSE;
+       }
+       else {
+         HLTError("unknown argument for emulateHLToutput: %s", toCompareTo.Data());
+         iResult=-EINVAL;
+         break;
+       }
+       continue;
+      }
+      else if (argument.CompareTo("-yPosMethod")==0) {
+       if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
+       TString toCompareTo=((TObjString*)pTokens->At(i))->GetString();
+       if (toCompareTo.CompareTo("COG")==0){
+         HLTInfo("Setting yPosMethod method to: %s", toCompareTo.Data());
+         fyPosMethod=0;
+       }
+       else if (toCompareTo.CompareTo("LUT")==0){
+         HLTInfo("Setting yPosMethod method to: %s", toCompareTo.Data());
+         fyPosMethod=1;
+       }
+       else if (toCompareTo.CompareTo("Gauss")==0){
+         HLTInfo("Setting yPosMethod method to: %s", toCompareTo.Data());
+         fyPosMethod=2;
+       }
+       else {
+         HLTError("unknown argument for yPosMethod: %s", toCompareTo.Data());
+         iResult=-EINVAL;
+         break;
+       }
+       continue;
+      }
+      
+      else {
+       HLTError("unknown argument: %s", argument.Data());
+       iResult=-EINVAL;
+       break;
+      }
+    }
+    delete pTokens;
+  }
+  if (bMissingParam) {
+    HLTError("missing parameter for argument %s", argument.Data());
+    iResult=-EINVAL;
+  }
+  if(iResult>=0){
+    iResult=SetParams();
+  }
+  return iResult;
+}
 
-      void *pos = (void*)(pBuf + copied);
-      void *copyret = memcpy(pos, blocks[i].fPtr, blocks[i].fSize);
-      if (copyret < 0)
+int AliHLTTRDClusterizerComponent::SetParams()
+{
+  Int_t iResult=0;
+  if(!AliCDBManager::Instance()->IsDefaultStorageSet()){
+    HLTError("DefaultStorage is not set in CDBManager");
+    return -EINVAL;
+  }
+  if(AliCDBManager::Instance()->GetRun()<0){
+    HLTError("Run Number is not set in CDBManager");
+    return -EINVAL;
+  }
+  HLTInfo("CDB default storage: %s; RunNo: %i", (AliCDBManager::Instance()->GetDefaultStorage()->GetBaseFolder()).Data(), AliCDBManager::Instance()->GetRun());
+
+  if(!AliGeomManager::GetGeometry()){
+    if(fgeometryFileName.CompareTo("")==0 || !TFile::Open(fgeometryFileName.Data())){
+      HLTInfo("Loading standard geometry file");
+      AliGeomManager::LoadGeometry();
+    }else{
+      HLTWarning("Loading NON-standard geometry file");
+      AliGeomManager::LoadGeometry(fgeometryFileName.Data());
+    }
+    if(!AliGeomManager::GetGeometry()){
+      HLTError("Could not load geometry");
+      return -EINVAL;
+    }
+    HLTInfo("Applying Alignment from CDB object");
+    AliGeomManager::ApplyAlignObjsFromCDB("TRD");
+  }
+  else{
+    HLTInfo("Geometry Already Loaded!");
+  }
+
+  if(fReconstructor->GetRecoParam()){
+    fRecoParam = new AliTRDrecoParam(*fReconstructor->GetRecoParam());
+    HLTInfo("RecoParam already set!");
+  }else{
+    if(fRecoParamType == 0){
+#ifndef HAVE_NOT_ALITRD_RECOPARAM_r41621
+      if(fHLTflag){
+       HLTInfo("Low flux HLT params init.");
+       fRecoParam = AliTRDrecoParam::GetLowFluxHLTParam();
+      }else
+#endif
        {
-         //Logging( kHLTLogError, "HLT::TRDClusterizer::DoEvent", "MEMORY", "Unable to copy %lu bytes", blocks[i].fSize);
-         // so here i am not sure which log scheme finaly to use...
-         HLTError("MEMORY Unable to copy %lu bytes", blocks[i].fSize);
-         // maybe put a reasonable return value here...
-         return -1;
+         HLTInfo("Low flux params init.");
+         fRecoParam = AliTRDrecoParam::GetLowFluxParam();
        }
-      copied += blocks[i].fSize;
     }
-  
-  // lets see what we copied...
-  HLTDebug("COPY STATS total=%lu copied=%lu", totalSize, copied);
+    if(fRecoParamType == 1){
+#ifndef HAVE_NOT_ALITRD_RECOPARAM_r41621
+      if(fHLTflag){
+       HLTInfo("High flux HLT params init.");
+       fRecoParam = AliTRDrecoParam::GetHighFluxHLTParam();
+      }else
+#endif
+       {
+         HLTInfo("High flux params init.");
+         fRecoParam = AliTRDrecoParam::GetHighFluxParam();
+       }
+    }
+    if(fRecoParamType == 2){
+      HLTInfo("Cosmic Test params init.");
+      fRecoParam = AliTRDrecoParam::GetCosmicTestParam();
+    }
+  }
+
+  if (!fRecoParam)
+    {
+      HLTError("No reco params initialized. Sniffing big trouble!");
+      return -EINVAL;
+    }
 
-  fMemReader->Reset();
-  fMemReader->SetMemory((UChar_t*)memBufIn, totalSize);
+  if(fTC){fRecoParam->SetTailCancelation(kTRUE); HLTDebug("Enableing Tail Cancelation"); }
+  else{fRecoParam->SetTailCancelation(kFALSE); HLTDebug("Disableing Tail Cancelation"); }
 
-  //fMemReader->SelectEquipment(0, 1024, 1041);
+  switch(fyPosMethod){
+  case 0: fRecoParam->SetGAUS(kFALSE); fRecoParam->SetLUT(kFALSE); break;
+  case 1: fRecoParam->SetGAUS(kFALSE); fRecoParam->SetLUT(kTRUE); break;
+  case 2: fRecoParam->SetGAUS(kTRUE); fRecoParam->SetLUT(kFALSE); break;
+  }
 
-  // 1024 is good for SM 0 - it should be good for any other too
-  // but in principle the EquipmentID should come with the data
-  fMemReader->SetEquipmentID(1024);
+  fRecoParam->SetStreamLevel(AliTRDrecoParam::kClusterizer, 0);
+  fReconstructor->SetRecoParam(fRecoParam);
 
-  fClusterizer->ResetTree();  
-  Bool_t iclustered = fClusterizer->Raw2ClustersChamber(fMemReader);
-  if (iclustered == kTRUE)
+  TString recoOptions="!cw";
+  if(fHLTflag)
+    recoOptions += ",hlt";
+  if(fProcessTracklets) recoOptions += ",tp";
+  else  recoOptions += ",!tp";
+
+  HLTDebug("Reconstructor options are: %s",recoOptions.Data());
+  fReconstructor->SetOption(recoOptions.Data());
+
+  if (fRecoDataType < 0 || fRecoDataType > 1)
     {
-      HLTDebug("Clustered successfully");
+      HLTWarning("No data type selected. Use -simulation or -experiment flag. Defaulting to simulation.");
+      fRecoDataType = 0;
     }
-  else
+
+  if (fRecoDataType == 0)
     {
-      HLTError("Clustering ERROR");
-      return -1;
+      AliTRDrawStreamBase::SetRawStreamVersion(AliTRDrawStreamBase::kTRDsimStream);
+      HLTDebug("Data type expected is SIMULATION!");
     }
 
-  // free the memory
-  free(memBufIn);
-  
-  // put the tree into output blocks
-  TTree *fcTree = fClusterizer->GetClusterTree();
-  
-  PushBack(fcTree, AliHLTTRDDefinitions::fgkClusterDataType, dBlockSpecification);
+  if (fRecoDataType == 1)
+    {
+      AliTRDrawStreamBase::SetRawStreamVersion(AliTRDrawStreamBase::kTRDrealStream);
+      HLTDebug("Data type expected is EXPERIMENT!");
+    }
 
-  size=0; // this function did not write data to the buffer directly
-  return 0;
+#ifndef HAVE_NOT_ALITRD_RAWSTREAM_r39608
+  if(fHLTstreamer){
+    AliTRDrawStreamBase::SetRawStreamVersion("default");
+    HLTDebug("fast rawstreamer used");
+  }else{
+    AliTRDrawStreamBase::SetRawStreamVersion("FAST");
+    HLTDebug("old rawstreamer used");
+  }
+#else
+  if(fHLTstreamer){
+      AliTRDrawStreamBase::SetRawStreamVersion("FAST");
+      HLTDebug("fast rawstreamer used");  
+    }
+#endif
+
+  if(!fClusterizer){
+    fClusterizer = new AliHLTTRDClusterizer("TRDCclusterizer", "TRDCclusterizer");  
+    HLTDebug("TRDClusterizer at 0x%x", fClusterizer);
+  }
+
+  fClusterizer->SetRawVersion(fRawDataVersion);
+
+  return iResult;
+}
+
+int AliHLTTRDClusterizerComponent::Reconfigure(const char* cdbEntry, const char* chainId)
+{
+  // see header file for class documentation
+
+  int iResult=0;
+  const char* path="HLT/ConfigTRD/ClusterizerComponent";
+  const char* defaultNotify="";
+  if (cdbEntry) {
+    path=cdbEntry;
+    defaultNotify=" (default)";
+  }
+  if (path) {
+    HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
+    AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
+    if (pEntry) {
+      TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
+      if (pString) {
+       HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
+       iResult=Configure(pString->GetString().Data());
+      } else {
+       HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
+      }
+    } else {
+      HLTError("cannot fetch object \"%s\" from CDB", path);
+    }
+  }
+
+  return iResult;
+}
+
+void AliHLTTRDClusterizerComponent::GetOCDBObjectDescription(TMap* const targetMap){
+  // Get a list of OCDB object description needed for the particular component
+  if (!targetMap) return;
+  targetMap->Add(new TObjString("HLT/ConfigTRD/ClusterizerComponent"), new TObjString("component arguments"));
+  targetMap->Add(new TObjString("TRD/Calib/ChamberGainFactor"), new TObjString("gain factor of chambers"));
+  targetMap->Add(new TObjString("TRD/Calib/ChamberT0"), new TObjString("T0 of chambers"));
+  targetMap->Add(new TObjString("TRD/Calib/ChamberVdrift"), new TObjString("drift velocity of chambers"));
+  targetMap->Add(new TObjString("TRD/Calib/DetNoise"), new TObjString("noise of chambers"));
+  targetMap->Add(new TObjString("TRD/Calib/LocalGainFactor"), new TObjString("per pad gain factor"));
+  targetMap->Add(new TObjString("TRD/Calib/LocalT0"), new TObjString("per pad T0"));
+  targetMap->Add(new TObjString("TRD/Calib/LocalVdrift"), new TObjString("per pad drift velocity"));
+  targetMap->Add(new TObjString("TRD/Calib/PadNoise"), new TObjString("per pad noise"));
+  targetMap->Add(new TObjString("TRD/Calib/PadStatus"), new TObjString("pad status"));
+  targetMap->Add(new TObjString("TRD/Calib/PRFWidth"), new TObjString("pad response function"));
 }