]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/TRD/AliHLTTRDTrackerV1Component.cxx
Extacting the OCDB in a separate module. The detectors have write permission in the...
[u/mrichter/AliRoot.git] / HLT / TRD / AliHLTTRDTrackerV1Component.cxx
index 435d456e7bd4c98946edfa13f390be98958858d5..8296912930f9bd3a54ef847fde45a22dfb18ae68 100644 (file)
@@ -27,40 +27,47 @@ using namespace std;
 
 #include "AliHLTTRDTrackerV1Component.h"
 #include "AliHLTTRDDefinitions.h"
+#include "AliHLTTRDCluster.h"
+#include "AliHLTTRDTrack.h"
 
 #include "TFile.h"
 #include "TChain.h"
 
+#include "AliGeomManager.h"
 #include "AliCDBManager.h"
 #include "AliESDEvent.h"
-#include "AliMagFMaps.h"
+#include "AliMagF.h"
 #include "AliESDfriend.h"
 
+#include "AliTRDcalibDB.h"
 #include "AliTRDReconstructor.h"
 #include "AliTRDtrackerV1.h"
-#include "AliTRDcluster.h"
 #include "AliTRDrecoParam.h"
 
 #include <cstdlib>
 #include <cerrno>
 #include <string>
 
-// this is a global object used for automatic component registration, do not use this
-AliHLTTRDTrackerV1Component gAliHLTTRDTrackerV1Component;
+#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
 
 ClassImp(AliHLTTRDTrackerV1Component);
     
-AliHLTTRDTrackerV1Component::AliHLTTRDTrackerV1Component()
-  : AliHLTProcessor()
-  , fOutputPercentage(100) // By default we copy to the output exactly what we got as input  
-  , fStrorageDBpath("local://$ALICE_ROOT")
-  , fCDB(NULL)
-  , fField(NULL)
-  , fGeometryFileName("")
-  , fGeometryFile(NULL)
-  , fGeoManager(NULL)
-  , fTracker(NULL)
-  , fRecoParam(NULL)
+AliHLTTRDTrackerV1Component::AliHLTTRDTrackerV1Component():
+  AliHLTProcessor(),
+  fOutputPercentage(100), // By default we copy to the output exactly what we got as input  
+  fStrorageDBpath("local://$ALICE_ROOT/OCDB"),
+  fCDB(NULL),
+  fGeometryFileName(""),
+  fUseHLTClusters(kFALSE),
+  fUseHLTTracks(kFALSE),
+  fTracker(NULL),
+  fRecoParam(NULL),
+  fReconstructor(NULL)
 {
   // Default constructor
 
@@ -102,44 +109,81 @@ void AliHLTTRDTrackerV1Component::GetOutputDataSize( unsigned long& constBase, d
 // Spawn function, return new instance of this class
 AliHLTComponent* AliHLTTRDTrackerV1Component::Spawn()
 {
-  // Spawn function, return new instance of this class
   return new AliHLTTRDTrackerV1Component;
 };
 
+/**
+ * Convert AliTRDtrackV1 to AliHLTTRDTrack 
+ * Add HLTTrack to the output, defined by pointer
+ * Fill block desctiptors 
+ * Return size of the added to ouput objects
+ */
+//============================================================================
+AliHLTUInt32_t AliHLTTRDTrackerV1Component::AddToOutput(TClonesArray* inTrackArray, AliHLTUInt8_t* output)
+{
+  cout << "\nWriting tracks to the Memory\n ============= \n";
+  AliTRDtrackV1* track = 0;
+  AliHLTUInt32_t addedSize = 0;
+  AliHLTUInt8_t *iterPtr = output;
+  AliHLTTRDTrack * outPtr = (AliHLTTRDTrack*)iterPtr;
+  
+  if (inTrackArray){
+    Int_t nbTracks  = inTrackArray->GetEntries();
+    for (Int_t iTrack = 0; iTrack<nbTracks; iTrack++){
+      AliHLTUInt32_t trackSize=0;
+      
+      track = dynamic_cast<AliTRDtrackV1*>(inTrackArray->At(iTrack));
+      //track->Print();
+      
+      AliHLTTRDTrack *hltTrack = new (outPtr) AliHLTTRDTrack(track);
+      trackSize = hltTrack->GetSize();
+      addedSize += trackSize;
+      HLTDebug("addedSize %i, trackSize %i", addedSize, trackSize);
+      
+      iterPtr += trackSize;
+      outPtr = (AliHLTTRDTrack*)iterPtr;
+    }
+  }
+  return addedSize;
+  
+}
+
 int AliHLTTRDTrackerV1Component::DoInit( int argc, const char** argv )
 {
   // perform initialization. We check whether our relative output size is specified in the arguments.
   fOutputPercentage = 100;
   int i = 0;
   char* cpErr;
+  
 
   Int_t iRecoParamType = -1; // default will be the low flux
   Int_t iNtimeBins = -1;     // number of time bins for the tracker to use
   Int_t iMagneticField = -1; // magnetic field: 0==OFF and 1==ON
-
+  Bool_t bHLTMode = kTRUE, bWriteClusters = kFALSE;
+  
   while ( i < argc )
     {
-      Logging( kHLTLogDebug, "HLT::TRDTrackerV1::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::TRDTrackerV1::DoInit", "Missing Argument", "Missing output_percentage parameter");
+             HLTError("Missing output_percentage parameter");
              return ENOTSUP;
            }
-         Logging( kHLTLogDebug, "HLT::TRDTrackerV1::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::TRDTrackerV1::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::TRDTrackerV1::DoInit", "Output percentage set", "Output percentage set to %lu %%", fOutputPercentage );
+         HLTInfo("Output percentage set to %lu %%", fOutputPercentage );
          i += 2;
-         continue;
+         
        }
 
-      if ( !strcmp( argv[i], "-NTimeBins" ) )
+      else if ( !strcmp( argv[i], "-NTimeBins" ) )
        {
          if ( i+1>=argc )
            {
@@ -154,69 +198,98 @@ int AliHLTTRDTrackerV1Component::DoInit( int argc, const char** argv )
              return EINVAL;
            }     
          i += 2;
-         continue;
+         
        }
 
-      if ( strcmp( argv[i], "-cdb" ) == 0)
+      else if ( strcmp( argv[i], "-cdb" ) == 0)
        {
          if ( i+1 >= argc )
            {
-             Logging(kHLTLogError, "HLT::TRDTrackerV1::DoInit", "Missing Argument", "Missing -cdb argument");
+             HLTError( "Missing -cdb argument");
              return ENOTSUP;         
            }
          fStrorageDBpath = argv[i+1];
-         Logging( kHLTLogInfo, "HLT::TRDTrackerV1::DoInit", "DB storage set", "DB storage is %s", fStrorageDBpath.c_str() );     
+         HLTInfo("DB storage is %s", fStrorageDBpath.c_str() );          
          i += 2;
-         continue;
+         
        }      
 
-      if ( strcmp( argv[i], "-geometry" ) == 0)
+      else if ( strcmp( argv[i], "-geometry" ) == 0)
        {
          if ( i+1 >= argc )
            {
-             Logging(kHLTLogError, "HLT::TRDTrackerV1::DoInit", "Missing Argument", "Missing -geometry argument");
+             HLTError("Missing -geometry argument");
              return ENOTSUP;         
            }
          fGeometryFileName = argv[i+1];
-         Logging( kHLTLogInfo, "HLT::TRDTrackerV1::DoInit", "GeomFile storage set", "GeomFile storage is %s", 
-                  fGeometryFileName.c_str() );   
+         HLTInfo("GeomFile storage is %s", 
+                 fGeometryFileName.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("Low flux reco selected.");
          i++;
-         continue;
        }      
-      
-      if ( strcmp( argv[i], "-magnetic_field_ON" ) == 0)
+
+      else if ( strcmp( argv[i], "-cosmics" ) == 0)
+       {
+         iRecoParamType = 2;     
+         HLTDebug("Cosmic test reco selected.");
+         i++;
+       }      
+
+      else if ( strcmp( argv[i], "-magnetic_field_ON" ) == 0)
        {
          iMagneticField = 1;
          i++;
-         continue;
        }
-
-      if ( strcmp( argv[i], "-magnetic_field_OFF" ) == 0)
+      else if ( strcmp( argv[i], "-magnetic_field_OFF" ) == 0)
        {
          iMagneticField = 0;
          i++;
-         continue;
        }
-
-       Logging(kHLTLogError, "HLT::TRDTrackerV1::DoInit", "Unknown Option", "Unknown option '%s'", argv[i] );
-      return EINVAL;
+      else if ( strcmp( argv[i], "-writeClusters" ) == 0)
+       {
+         bWriteClusters = kTRUE;
+         HLTDebug("input clusters are expected to be in a TTree.");
+         i++;
+       }
+      else if ( strcmp( argv[i], "-offlineMode" ) == 0)
+       {
+         bHLTMode=kFALSE;
+         HLTDebug("Using standard offline tracking.");
+         i++;
+       }
+      else if ( strcmp( argv[i], "-useHLTClusters" ) == 0)
+       {
+         fUseHLTClusters = kTRUE;
+         i++;
+         HLTInfo("expecting AliHLTCluster as input");
+       }
+      else if ( strcmp( argv[i], "-useHLTTracks" ) == 0)
+       {
+         fUseHLTTracks = kTRUE;
+         i++;
+         HLTInfo("Using AliHLTTrack to pass data further in the chain");
+       }
+      else {
+       HLTError("Unknown option '%s'", argv[i] );
+       return EINVAL;
+      }
+      
     }
 
   // THE "REAL" INIT COMES HERE
@@ -224,14 +297,14 @@ int AliHLTTRDTrackerV1Component::DoInit( int argc, const char** argv )
   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);
       return -1;
     }
   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);
     }
 
   // check if the N of time bins make sense
@@ -258,33 +331,31 @@ int AliHLTTRDTrackerV1Component::DoInit( int argc, const char** argv )
       HLTWarning("No magnetic field switch stated. Use -magnetic_field_ON or -magnetic_field_OFF flag. Defaulting to OFF = NO MAGNETIC FIELD");
     }
   
-  if (iMagneticField == 0)
-    {
-      // magnetic field OFF
-      fField = new AliMagFMaps("Maps","Maps", 2, 0., 10., 1);
-      HLTDebug("Magnetic field is OFF.");
-    }
-
-  if (iMagneticField == 1)
-    {
-      // magnetic field ON
-      fField = new AliMagFMaps("Maps","Maps", 2, 1., 10., 1);
-      HLTDebug("Magnetic field is ON.");
-    }
-
-  if (fField == 0)
-    {
-      HLTError("Unable to init the field. Trouble at this point.");
-      return -1;
-    }
-
-  // kTRUE sets the map uniform
-  AliTracker::SetFieldMap(fField,kTRUE);
+  if (!TGeoGlobalMagField::Instance()->IsLocked()) {
+    if (iMagneticField == 0)
+      {
+       // magnetic field OFF
+       AliMagF* field = new AliMagF("Maps","Maps",2,0.,0., 10.,AliMagF::k5kGUniform);
+       TGeoGlobalMagField::Instance()->SetField(field);
+       HLTDebug("Magnetic field is OFF.");
+      }
+    
+    if (iMagneticField == 1)
+      {
+       // magnetic field ON
+       AliMagF* field = new AliMagF("Maps","Maps",2,1.,1., 10.,AliMagF::k5kG);
+       TGeoGlobalMagField::Instance()->SetField(field);
+       HLTDebug("Magnetic field is ON.");
+      }
+  }
+  else {
+    HLTError("Magnetic field is already set and locked, cannot redefine it." );
+  }
 
   // reconstruction parameters
-  if (iRecoParamType < 0 || iRecoParamType > 1)
+  if (iRecoParamType < 0 || iRecoParamType > 2)
     {
-      HLTWarning("No reco param selected. Use -lowflux or -highflux flag. Defaulting to low flux.");
+      HLTWarning("No reco param selected. Use -lowflux -highflux -cosmics flags. Defaulting to low flux.");
       iRecoParamType = 0;
     }
 
@@ -299,6 +370,12 @@ int AliHLTTRDTrackerV1Component::DoInit( int argc, const char** argv )
       fRecoParam = AliTRDrecoParam::GetHighFluxParam();
       HLTDebug("High flux params init.");
     }
+  
+  if (iRecoParamType == 2)
+    {
+      fRecoParam = AliTRDrecoParam::GetCosmicTestParam();
+      HLTDebug("Cosmic Test params init.");
+    }
 
   if (fRecoParam == 0)
     {
@@ -306,40 +383,54 @@ int AliHLTTRDTrackerV1Component::DoInit( int argc, const char** argv )
       return -1;
     }
 
-  // this is important in case we want to ::PropagateBack - see the TrackerV1.cxx
-  fRecoParam->SetSeeding(kTRUE);
-  // no debug stream -> no debug files! on HLT
-  fRecoParam->SetStreamLevel(0);
+  fReconstructor = new AliTRDReconstructor();
+  //   fRecoParam->SetChi2Y(.1);
+  //   fRecoParam->SetChi2Z(5.);
+  fReconstructor->SetRecoParam(fRecoParam);
+  // write clusters [cw] = true
+  // track seeding (stand alone tracking) [sa] = true
+  // PID method in reconstruction (NN) [nn] = true
+  // write online tracklets [tw] = false
+  // drift gas [ar] = false
+  // sl_tr_0 = StreamLevel_task_Level
+  //  fReconstructor->SetOption("sa,!cw,hlt,sl_tr_0");
+  TString recoOptions="sa,sl_tr_0";
   
-  AliTRDReconstructor::SetRecoParam(fRecoParam);
+  if (bWriteClusters)
+    {
+      recoOptions += ",cw";
+    } 
+  else
+    {
+      recoOptions += ",!cw";
+    }
+  if (bHLTMode)
+    recoOptions += ",hlt";
+  
+  fReconstructor->SetOption(recoOptions.Data());
+  HLTDebug("Reconstructor options are: %s",recoOptions.Data());
+  
+  if((AliGeomManager::GetGeometry()) == NULL){
     
-  // geometry:
-  // for some unknown at this point reason (30th of April 2008)
-  // the TrackerV1 initializes new TRDgeometry in the constructor
-  // we avoid it here
-  fGeometryFile = 0;
-  //   fGeometryFile = TFile::Open(fGeometryFileName.c_str());
-  //   if (fGeometryFile)
-  //     {
-  //       fGeoManager = (TGeoManager *)fGeometryFile->Get("Geometry");
-  //       // for the old tracker we would do this:
-  //       fTracker = new AliTRDtracker(fGeometryFile);
-  //     }
-  //   else
-  //     {
-  //       Logging(kHLTLogError, "HLT::TRDTrackerV1::DoInit", "fGeometryFile", "Unable to open file. FATAL!");
-  //       return -1;
-  //     }
+    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");
   
   // create the tracker
   fTracker = new AliTRDtrackerV1();
+  fTracker->SetReconstructor(fReconstructor);
   HLTDebug("TRDTracker at 0x%x", fTracker);
 
   if (fTracker == 0)
     {
       HLTError("Unable to create the tracker!");
-      // do we want a smarter return value here? probably yes
-      // answering your own questions is stupid but maybe helpful... ;)
       return -1;
     }
 
@@ -350,131 +441,233 @@ int AliHLTTRDTrackerV1Component::DoDeinit()
 {
   // Deinitialization of the component
 
-  delete fField;
-  fField = 0;
-
+  fTracker->SetClustersOwner(kFALSE);
   delete fTracker;
-  fTracker = 0;
+  fTracker = 0x0;
   
-  if (fGeometryFile)
-    {
-      fGeometryFile->Close();
-      delete fGeometryFile;
-      fGeometryFile = 0;
-    }
+  // We need to set clusters in Reconstructor to null to prevent from 
+  // double deleting, since we delete TClonesArray by ourself in DoEvent.
+  fReconstructor->SetClusters(0x0);
+  delete fReconstructor;
+  fReconstructor = 0x0;
+  
+  AliTRDcalibDB::Terminate();
 
   return 0;
 }
 
-int AliHLTTRDTrackerV1Component::DoEvent( const AliHLTComponentEventData & evtData,
-                                       AliHLTComponentTriggerData & trigData )
+int AliHLTTRDTrackerV1Component::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::TRDTrackerV1::DoEvent", "Output percentage set", "Output percentage set to %lu %%", fOutputPercentage );
-  Logging( kHLTLogInfo, "HLT::TRDTrackerV1::DoEvent", "BLOCKS", "NofBlocks %lu", evtData.fBlockCnt );
+  Bool_t bWriteClusters = fReconstructor->IsWritingClusters();
 
+  HLTDebug("NofBlocks %lu", evtData.fBlockCnt );
+  
+  AliHLTUInt32_t totalSize = 0, offset = 0;
   AliHLTUInt32_t dBlockSpecification = 0;
 
-  //implement a usage of the following
-  //   AliHLTUInt32_t triggerDataStructSize = trigData.fStructSize;
-  //   AliHLTUInt32_t triggerDataSize = trigData.fDataSize;
-  //   void *triggerData = trigData.fData;
-  Logging( kHLTLogDebug, "HLT::TRDTrackerV1::DoEvent", "Trigger data received", 
-          "Struct size %d Data size %d Data location 0x%x", trigData.fStructSize, trigData.fDataSize, (UInt_t*)trigData.fData);
-  
-  AliHLTComponentBlockData *dblock = (AliHLTComponentBlockData *)GetFirstInputBlock( AliHLTTRDDefinitions::fgkClusterDataType );
-  if (dblock != 0)
-    {
-      dBlockSpecification = dblock->fSpecification;
-    }
-  else
+  vector<AliHLTComponent_DataType> expectedDataTypes;
+  GetInputDataTypes(expectedDataTypes);
+  if (evtData.fEventID == 1)
+    CALLGRIND_START_INSTRUMENTATION();
+  for ( unsigned long iBlock = 0; iBlock < evtData.fBlockCnt; iBlock++ ) 
     {
-      Logging( kHLTLogWarning, "HLT::TRDTrackerV1::DoEvent", "DATAIN", "First Input Block not found! 0x%x", dblock);
-      return -1;
+      const AliHLTComponentBlockData &block = blocks[iBlock];
+      offset = totalSize;
+      AliHLTComponentDataType inputDataType = block.fDataType;
+      Bool_t correctDataType = kFALSE;
+      
+      for(UInt_t i = 0; i < expectedDataTypes.size(); i++)
+       if( expectedDataTypes.at(i) == inputDataType)
+         correctDataType = kTRUE;
+      if (!correctDataType)
+       {
+         HLTDebug( "Block # %i/%i; Event 0x%08LX (%Lu) Wrong received datatype: %s - Skipping",
+                   iBlock, evtData.fBlockCnt-1,
+                   evtData.fEventID, evtData.fEventID, 
+                   DataType2Text(inputDataType).c_str());
+         continue;
+       }
+      else 
+       HLTDebug("We get the right data type: Block # %i/%i; Event 0x%08LX (%Lu) Received datatype: %s",
+                   iBlock, evtData.fBlockCnt-1,
+                   evtData.fEventID, evtData.fEventID, 
+                   DataType2Text(inputDataType).c_str());
+      
+      
+      TTree *clusterTree = 0x0;
+      TClonesArray* clusterArray = 0x0;
+      ReadAndLoadClusters(clusterTree, clusterArray, &block);
+      
+      // maybe it is not so smart to create it each event? clear is enough ?
+      AliESDEvent *esd = new AliESDEvent();
+      esd->CreateStdContent();
+      fTracker->Clusters2Tracks(esd);
+
+      //here transport the esd tracks further
+      Int_t nTracks = esd->GetNumberOfTracks();
+      Int_t nTRDTracks = esd->GetNumberOfTrdTracks();
+      HLTInfo("Number of tracks  == %d == Number of TRD tracks %d", nTracks, nTRDTracks);  
+
+      TClonesArray* trdTracks = fTracker->GetListOfTracks();
+   
+      if (trdTracks)
+       totalSize += TransportTracks(trdTracks, outputPtr, outputBlocks, offset, dBlockSpecification);
+      else 
+       HLTDebug("Bad array trdTracks = 0x%x", trdTracks);
+      HLTDebug("totalSize: %i", totalSize);
+      
+//       if ( totalSize > allocSize )
+//     {
+//       HLTError("Too much data; Data written over allowed buffer. Amount written: %lu, allowed amount: %lu.",
+//       totalSize, size );
+//       return EMSGSIZE;
+//     }
+
+      //here we are deleting clusters (but not the TClonesArray itself)
+      fTracker->UnloadClusters();
+
+      AliTRDReconstructor::SetClusters(0x0);
+      delete esd;
+      if (bWriteClusters)
+       delete clusterTree;
+      else{
+       //clusterArray->Delete();
+       delete clusterArray;
+      }
+      
     }
+  size = totalSize;
+  HLTDebug("Event is done. size written to the output is %i", size);
+  //  CALLGRIND_STOP_INSTRUMENTATION();
+  return 0;
+}
 
-  int ibForce = 0;
-  
-  TObject *tobjin = (TObject *)GetFirstInputObject( AliHLTTRDDefinitions::fgkClusterDataType, "TTree", ibForce);
-  Logging( kHLTLogInfo, "HLT::TRDTrackerV1::DoEvent", "1stBLOCK", "Pointer = 0x%x", tobjin);
 
-  TTree *clusterTree = (TTree*)tobjin;
-  if (!clusterTree)
+/**
+ * ReadClusters from the component input and load them to the tracker
+ */
+//============================================================================
+void AliHLTTRDTrackerV1Component::ReadAndLoadClusters(TTree *inClusterTree, 
+                                                     TClonesArray *inClusterArray, const AliHLTComponentBlockData *inBlock)
+{
+  Bool_t bWriteClusters = fReconstructor->IsWritingClusters();
+  const AliHLTComponentBlockData &block = *inBlock;
+
+
+  TObject *tobjin = 0x0;
+  int ibForce = 0; // almost obsolet
+
+  if (bWriteClusters){
+    tobjin = (TObject *)GetFirstInputObject( AliHLTTRDDefinitions::fgkClusterDataType, "TTree", ibForce);
+    HLTDebug("1stBLOCK; Pointer = 0x%x", tobjin);
+    inClusterTree = (TTree*)tobjin;
+    if (inClusterTree)
+      {
+       HLTDebug("CLUSTERS; Pointer to TTree = 0x%x Name = %s", inClusterTree, inClusterTree->GetName());
+       HLTDebug("TTree of clusters: nbEntries = %i", inClusterTree->GetEntriesFast());
+       fTracker->LoadClusters(inClusterTree);
+      }
+    else
+      {
+       HLTError("First Input Block is not a TTree 0x%x", tobjin);
+      }
+  }
+  else if (fUseHLTClusters)
     {
-      Logging( kHLTLogWarning, "HLT::TRDTrackerV1::DoEvent", "DATAIN", "First Input Block not a tree! 0x%x", tobjin);
-      return -1;
+      inClusterArray = new TClonesArray("AliTRDcluster"); // would be nice to allocate memory for all clusters here.
+      ReadClusters(inClusterArray, block.fPtr, block.fSize);
+      HLTDebug("TClonesArray of clusters: nbEntries = %i", inClusterArray->GetEntriesFast());
+      fTracker->LoadClusters(inClusterArray);
     }
-
-  Logging( kHLTLogInfo, "HLT::TRDTrackerV1::DoEvent", "1stBLOCK", "Pointer = 0x%x Name = %s", clusterTree, clusterTree->GetName());
-
-  while (tobjin != 0)
+  else
     {
-      if (clusterTree)
+      tobjin = (TObject *)GetFirstInputObject( AliHLTTRDDefinitions::fgkClusterDataType, "TClonesArray", ibForce);
+      HLTDebug("1stBLOCK; Pointer = 0x%x", tobjin);
+      inClusterArray = (TClonesArray*)tobjin;
+      if (inClusterArray)
        {
-         Logging( kHLTLogInfo, "HLT::TRDTrackerV1::DoEvent", "CLUSTERS", "Pointer = 0x%x Name = %s", clusterTree, clusterTree->GetName());
-         Int_t iNentries = clusterTree->GetEntries();
-         Logging( kHLTLogInfo, "HLT::TRDTrackerV1::DoEvent", "COUNT", "N of tree entries = %d", iNentries);
-         fTracker->LoadClusters(clusterTree);
+         HLTDebug("CLUSTERS; Pointer to TClonesArray = 0x%x Name = %s", inClusterArray, inClusterArray->GetName());
+         HLTDebug("TClonesArray of clusters: nbEntries = %i", inClusterArray->GetEntriesFast());
+         fTracker->LoadClusters(inClusterArray);
        }
       else
        {
-         Logging( kHLTLogError, "HLT::TRDTrackerV1::DoEvent", "CLUSTERS", "Tree Pointer = 0x%x", clusterTree);
+         HLTError("First Input Block not a TClonesArray 0x%x", tobjin);
        }
-
-      tobjin = (TObject *)GetNextInputObject( ibForce );
-      Logging( kHLTLogInfo, "HLT::TRDTrackerV1::DoEvent", "nextBLOCK", "Pointer = 0x%x", tobjin);
-      clusterTree = (TTree*)tobjin;
     }
+}
 
-  // maybe it is not so smart to create it each event? clear is enough ?
-  AliESDEvent *esd = new AliESDEvent();
-  esd->CreateStdContent();
-
-  fTracker->Clusters2Tracks(esd);
-  // not necessary...
-  //fTracker->PropagateBack(esd);
-
-  //here transport the esd tracks further
-  Int_t nTracks = esd->GetNumberOfTracks();
-  Int_t nTRDTracks = esd->GetNumberOfTrdTracks();
-  HLTInfo("Number of tracks %d Number of TRD tracks %d", nTracks, nTRDTracks);  
-  //esd->Print();
-  PushBack(esd, AliHLTTRDDefinitions::fgkTRDSAEsdDataType);
-
-  // extract the friend ?
-  //   AliESDfriend *esdFriend = new AliESDfriend();
-  //   esd->GetESDfriend(esdFriend);
-  //   PushBack(esdFriend, AliHLTTRDDefinitions::fgkTRDSAEsdDataType);
-  //   delete esdFriend;
-
-  //HLTInfo("now deleting");
-  delete esd;
-
-  delete clusterTree;
-  fTracker->UnloadClusters();
-
-  HLTDebug("Event done.");
+/**
+ * Read cluster to the TClonesArray from the memory 
+ */
+//============================================================================
+Int_t AliHLTTRDTrackerV1Component::ReadClusters(TClonesArray *outArray, void* inputPtr, AliHLTUInt32_t size)
+{
+  //HLTDebug("\nReading clusters from the Memory\n ============= \n");
+  AliHLTTRDCluster * curCluster;
+  UInt_t clusterSize = sizeof(AliHLTTRDCluster), curSize = 0;
+  Int_t i=0;
+  
+  curCluster = (AliHLTTRDCluster*) inputPtr;
+  while (curSize + clusterSize <= size)
+    {
+      //  HLTDebug(" fX = %f; fY = %f; fZ = %f", curCluster->fX, curCluster->fY, curCluster->fZ);
+
+      AliTRDcluster* curTRDCluster = new((*outArray)[i]) AliTRDcluster();
+      curCluster->ExportTRDCluster(curTRDCluster);
+      //      HLTDebug(" fX = %f; fY = %f; fZ = %f", curTRDCluster->GetX(), curTRDCluster->GetY(), curTRDCluster->GetZ());
+      curSize += clusterSize; 
+      i++;
+      curCluster++;
+      //cout << " current readed size is " << curSize << "/" << size << endl;
+    }
+  
+  return i;
+}
+/**
+ * Transport tracks to the next component
+ * Return Numbers of bytes written to the output
+ */
+//============================================================================
+AliHLTUInt32_t AliHLTTRDTrackerV1Component::TransportTracks(TClonesArray *inTracksArray, AliHLTUInt8_t* output,
+                                                   vector<AliHLTComponent_BlockData>& outputBlocks, AliHLTUInt32_t inOffset, AliHLTUInt32_t inSpec)
+{
+  Int_t nbTracks=inTracksArray->GetEntriesFast();
+  if (nbTracks>0)
+    {
+      HLTDebug("We have an output array: pointer to inTracksArray = 0x%x, nbEntries = %i", inTracksArray, nbTracks);
+      if (fUseHLTTracks){
+       // Using low-level interface 
+       // with interface classes
+       AliHLTUInt32_t addedSize = AddToOutput(inTracksArray, output);
+       
+       // Fill block 
+       AliHLTComponentBlockData bd;
+       FillBlockData( bd );
+
+       bd.fPtr = output;
+       bd.fOffset = inOffset;
+       bd.fSize = addedSize;
+       bd.fSpecification = inSpec;
+       bd.fDataType = AliHLTTRDDefinitions::fgkTRDSATracksDataType;
+       outputBlocks.push_back( bd );
+       HLTDebug("BD fPtr 0x%x, fOffset %i, fSize %i, fSpec 0x%x", bd.fPtr, bd.fOffset, bd.fSize, bd.fSpecification);
+       
+       return addedSize;
+      }
+      else{
+       inTracksArray->BypassStreamer(kFALSE);
+       PushBack(inTracksArray, AliHLTTRDDefinitions::fgkTRDSATracksDataType);
+       return 0;
+      }
+         
+    }
   return 0;
+  
 }
-
-///////////////////////////////
-/*
-  consider transporting TRD tracks only as they might have signigicantly smaller size... on the other hand you will need to prodece ESDs at some point...
-
-// this is for ESDtrack
-//   for (Int_t it = 0; it < nTracks; it++)
-//     {
-//       AliESDtrack* track = esd->GetTrack(it);
-//       HLTInfo("Track %d 0x%x Pt %1.2f", it, track, track->Pt());
-//       //PushBack(track, AliHLTTRDDefinitions::fgkTRDSATracksDataType, ++dBlockSpecification);
-//       PushBack(track, AliHLTTRDDefinitions::fgkTRDSATracksDataType);
-//     }
-
-// one can do similar things with the TRDtrack
-esd->GetNumberOfTrdTracks();
-and then
-for (i;;)
-AliESDTrdTrack *trdtrack = esd->GetTrdTrack(i)
-*/
-