]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/TPCLib/tracking-ca/AliHLTTPCCATrackerComponent.cxx
GPU update from David Rohr
[u/mrichter/AliRoot.git] / HLT / TPCLib / tracking-ca / AliHLTTPCCATrackerComponent.cxx
index 425680ee10f0d06af50d55723187443d5af8780c..799e32a298ca7f8b3ee9239ad00b833d365e1aa4 100644 (file)
@@ -1,6 +1,6 @@
 // @(#) $Id$
 // **************************************************************************
-// This file is property of and copyright by the ALICE HLT Project          * 
+// This file is property of and copyright by the ALICE HLT Project          *
 // ALICE Experiment at CERN, All rights reserved.                           *
 //                                                                          *
 // Primary Authors: Sergey Gorbunov <sergey.gorbunov@kip.uni-heidelberg.de> *
@@ -17,7 +17,7 @@
 //                                                                          *
 //***************************************************************************
 
+
 ///////////////////////////////////////////////////////////////////////////////
 //                                                                           //
 // a TPC tracker processing component for the HLT based on CA by Ivan Kisel  //
@@ -30,13 +30,15 @@ using namespace std;
 
 #include "AliHLTTPCCATrackerComponent.h"
 #include "AliHLTTPCTransform.h"
-#include "AliHLTTPCCATracker.h"
+#include "AliHLTTPCCATrackerFramework.h"
 #include "AliHLTTPCCAOutTrack.h"
 #include "AliHLTTPCCAParam.h"
 #include "AliHLTTPCCATrackConvertor.h"
+#include "AliHLTArray.h"
 
 #include "AliHLTTPCSpacePointData.h"
 #include "AliHLTTPCClusterDataFormat.h"
+#include "AliHLTTPCCACompressedInputData.h"
 #include "AliHLTTPCTransform.h"
 #include "AliHLTTPCTrackSegmentData.h"
 #include "AliHLTTPCTrackArray.h"
@@ -50,30 +52,26 @@ using namespace std;
 #include "TObjString.h"
 #include "TObjArray.h"
 #include "AliHLTTPCCASliceOutput.h"
+#include "AliHLTTPCCAClusterData.h"
 
 const AliHLTComponentDataType AliHLTTPCCADefinitions::fgkTrackletsDataType = AliHLTComponentDataTypeInitializer( "CATRACKL", kAliHLTDataOriginTPC );
 
 /** ROOT macro for the implementation of ROOT specific class methods */
-ClassImp(AliHLTTPCCATrackerComponent)
-
-/** global object for registration 
- * Matthias 2009-01-13 temporarily using the global object approach again.
- * CA cade had to be disabled because of various compilation problems, so
- * the global object approach fits better for the moment.
- */
-  
-AliHLTTPCCATrackerComponent gAliHLTTPCCATrackerComponent;
+ClassImp( AliHLTTPCCATrackerComponent )
 
 AliHLTTPCCATrackerComponent::AliHLTTPCCATrackerComponent()
-  :
-  fTracker(NULL),
-  fSolenoidBz(0),
-  fMinNTrackClusters(0),
-  fClusterZCut(500.),
-  fFullTime(0),
-  fRecoTime(0),
-  fNEvents(0),
-  fNewOutputType(0)
+    :
+    fTracker( NULL ),
+    fSolenoidBz( 0 ),
+    fMinNTrackClusters( 0 ),
+    fClusterZCut( 500. ),
+    fNeighboursSearchArea( 0 ), 
+    fClusterErrorCorrectionY(0), 
+    fClusterErrorCorrectionZ(0),
+    fFullTime( 0 ),
+    fRecoTime( 0 ),
+    fNEvents( 0 ),
+    fOutputTRAKSEGS( 0 )
 {
   // see header file for class documentation
   // or
@@ -82,33 +80,36 @@ AliHLTTPCCATrackerComponent::AliHLTTPCCATrackerComponent()
   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
 }
 
-AliHLTTPCCATrackerComponent::AliHLTTPCCATrackerComponent(const AliHLTTPCCATrackerComponent&)
-  :
-  AliHLTProcessor(),
-  fTracker(NULL),
-  fSolenoidBz(0),
-  fMinNTrackClusters(30),
-  fClusterZCut(500.),
-  fFullTime(0),
-  fRecoTime(0),
-  fNEvents(0),
-  fNewOutputType(0)
+AliHLTTPCCATrackerComponent::AliHLTTPCCATrackerComponent( const AliHLTTPCCATrackerComponent& )
+    :
+    AliHLTProcessor(),
+    fTracker( NULL ),
+    fSolenoidBz( 0 ),
+    fMinNTrackClusters( 30 ),
+    fClusterZCut( 500. ),
+    fNeighboursSearchArea(0),
+    fClusterErrorCorrectionY(0), 
+    fClusterErrorCorrectionZ(0),
+    fFullTime( 0 ),
+    fRecoTime( 0 ),
+    fNEvents( 0 ),
+    fOutputTRAKSEGS( 0 )
 {
   // see header file for class documentation
-  HLTFatal("copy constructor untested");
+  HLTFatal( "copy constructor untested" );
 }
 
-AliHLTTPCCATrackerComponent& AliHLTTPCCATrackerComponent::operator=(const AliHLTTPCCATrackerComponent&)
+AliHLTTPCCATrackerComponent& AliHLTTPCCATrackerComponent::operator=( const AliHLTTPCCATrackerComponent& )
 {
   // see header file for class documentation
-  HLTFatal("assignment operator untested");
+  HLTFatal( "assignment operator untested" );
   return *this;
 }
 
 AliHLTTPCCATrackerComponent::~AliHLTTPCCATrackerComponent()
 {
   // see header file for class documentation
-  delete fTracker;
+  if (fTracker) delete fTracker;
 }
 
 //
@@ -116,612 +117,765 @@ AliHLTTPCCATrackerComponent::~AliHLTTPCCATrackerComponent()
 // These functions are required for the registration process
 //
 
-const char* AliHLTTPCCATrackerComponent::GetComponentID() 
+const char* AliHLTTPCCATrackerComponent::GetComponentID()
 {
   // see header file for class documentation
   return "TPCCATracker";
 }
 
-void AliHLTTPCCATrackerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list
+void AliHLTTPCCATrackerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list )
 {
   // see header file for class documentation
   list.clear();
   list.push_back( AliHLTTPCDefinitions::fgkClustersDataType );
+  list.push_back( AliHLTTPCCADefinitions::fgkCompressedInputDataType );
 }
 
-AliHLTComponentDataType AliHLTTPCCATrackerComponent::GetOutputDataType() 
+AliHLTComponentDataType AliHLTTPCCATrackerComponent::GetOutputDataType()
 {
   // see header file for class documentation
-  if( fNewOutputType ) return AliHLTTPCCADefinitions::fgkTrackletsDataType;
-  else return AliHLTTPCDefinitions::fgkTrackSegmentsDataType;
+  if ( fOutputTRAKSEGS ) return AliHLTTPCDefinitions::fgkTrackSegmentsDataType;
+  else return AliHLTTPCCADefinitions::fgkTrackletsDataType;
 }
 
-void AliHLTTPCCATrackerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) 
+void AliHLTTPCCATrackerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
 {
   // define guess for the output data size
   constBase = 200;       // minimum size
-  inputMultiplier = 0.5; // size relative to input 
+  inputMultiplier = 3.; // size relative to input
 }
 
-AliHLTComponent* AliHLTTPCCATrackerComponent::Spawn() 
+AliHLTComponent* AliHLTTPCCATrackerComponent::Spawn()
 {
   // see header file for class documentation
   return new AliHLTTPCCATrackerComponent;
 }
 
-Int_t AliHLTTPCCATrackerComponent::DoInit( Int_t argc, const char** argv )
+void AliHLTTPCCATrackerComponent::SetDefaultConfiguration()
 {
-  // Configure the CA tracker component 
+  // Set default configuration for the CA tracker component
+  // Some parameters can be later overwritten from the OCDB
 
-  fSolenoidBz = 5;
+  fSolenoidBz = -5.00668;
   fMinNTrackClusters = 0;
   fClusterZCut = 500.;
+  fNeighboursSearchArea = 0;
+  fClusterErrorCorrectionY = 0;
+  fClusterErrorCorrectionZ = 0;
+  fOutputTRAKSEGS = 0;
   fFullTime = 0;
   fRecoTime = 0;
   fNEvents = 0;
-  fNewOutputType = 0;
+}
 
-  if ( fTracker ) return EINPROGRESS;
-  fTracker = new AliHLTTPCCATracker();
+int AliHLTTPCCATrackerComponent::ReadConfigurationString(  const char* arguments )
+{
+  // Set configuration parameters for the CA tracker component from the string
+
+  int iResult = 0;
+  if ( !arguments ) return iResult;
+
+  TString allArgs = arguments;
+  TString argument;
+  int bMissingParam = 0;
+
+  TObjArray* pTokens = allArgs.Tokenize( " " );
+
+  int nArgs =  pTokens ? pTokens->GetEntries() : 0;
+
+  for ( int i = 0; i < nArgs; i++ ) {
+    argument = ( ( TObjString* )pTokens->At( i ) )->GetString();
+    if ( argument.IsNull() ) continue;
+
+    if ( argument.CompareTo( "-solenoidBz" ) == 0 ) {
+      if ( ( bMissingParam = ( ++i >= pTokens->GetEntries() ) ) ) break;
+      fSolenoidBz = ( ( TObjString* )pTokens->At( i ) )->GetString().Atof();
+      HLTInfo( "Magnetic Field set to: %f", fSolenoidBz );
+      continue;
+    }
+
+    if ( argument.CompareTo( "-minNClustersOnTrack" ) == 0 ) {
+      if ( ( bMissingParam = ( ++i >= pTokens->GetEntries() ) ) ) break;
+      fMinNTrackClusters = ( ( TObjString* )pTokens->At( i ) )->GetString().Atoi();
+      HLTInfo( "minNClustersOnTrack set to: %d", fMinNTrackClusters );
+      continue;
+    }
+
+    if ( argument.CompareTo( "-clusterZCut" ) == 0 ) {
+      if ( ( bMissingParam = ( ++i >= pTokens->GetEntries() ) ) ) break;
+      fClusterZCut = TMath::Abs( ( ( TObjString* )pTokens->At( i ) )->GetString().Atof() );
+      HLTInfo( "ClusterZCut set to: %f", fClusterZCut );
+      continue;
+    }
+   if ( argument.CompareTo( "-neighboursSearchArea" ) == 0 ) {
+      if ( ( bMissingParam = ( ++i >= pTokens->GetEntries() ) ) ) break;
+      fNeighboursSearchArea = TMath::Abs( ( ( TObjString* )pTokens->At( i ) )->GetString().Atof() );
+      HLTInfo( "NeighboursSearchArea set to: %f", fNeighboursSearchArea );
+      continue;
+    }
+
+   if ( argument.CompareTo( "-errorCorrectionY" ) == 0 ) {
+     if ( ( bMissingParam = ( ++i >= pTokens->GetEntries() ) ) ) break;
+     fClusterErrorCorrectionY = ( ( TObjString* )pTokens->At( i ) )->GetString().Atof();
+     HLTInfo( "Cluster Y error correction factor set to: %f", fClusterErrorCorrectionY );
+     continue;
+   }
+   
+   if ( argument.CompareTo( "-errorCorrectionZ" ) == 0 ) {
+     if ( ( bMissingParam = ( ++i >= pTokens->GetEntries() ) ) ) break;
+     fClusterErrorCorrectionZ = ( ( TObjString* )pTokens->At( i ) )->GetString().Atof();
+     HLTInfo( "Cluster Z error correction factor set to: %f", fClusterErrorCorrectionZ );
+     continue;
+   }
+
+   if ( argument.CompareTo( "-outputTRAKSEGS" ) == 0 ) {
+      fOutputTRAKSEGS = 1;
+      HLTInfo( "The special output type \"TRAKSEGS\" is set" );
+      continue;
+    }
 
-  Int_t iResult = 0;
+    HLTError( "Unknown option \"%s\"", argument.Data() );
+    iResult = -EINVAL;
+  }
+  delete pTokens;
 
-  TString arguments=""; 
-  for (int i=0; i<argc; i++) {
-    TString argument=argv[i];
-    if (!arguments.IsNull()) arguments+=" ";
-    arguments+=argument;
+  if ( bMissingParam ) {
+    HLTError( "Specifier missed for parameter \"%s\"", argument.Data() );
+    iResult = -EINVAL;
   }
-  if (!arguments.IsNull()) {
-    iResult=Configure(arguments.Data());
-  } else {
-    iResult=Reconfigure(NULL, NULL);
-  }  
+
   return iResult;
 }
 
 
-Int_t AliHLTTPCCATrackerComponent::DoDeinit()
+int AliHLTTPCCATrackerComponent::ReadCDBEntry( const char* cdbEntry, const char* chainId )
 {
   // see header file for class documentation
-  if ( fTracker ) delete fTracker;
-  fTracker = NULL;  
-  return 0;
-}
 
-Int_t AliHLTTPCCATrackerComponent::Reconfigure(const char* /*cdbEntry*/, const char* /*chainId*/)
-{
-  // see header file for class documentation
-  HLTWarning("TODO: dummy Reconfigure() method" );
+  const char* defaultNotify = "";
 
-  return 0;
+  if ( !cdbEntry ) {
+    cdbEntry = "HLT/ConfigTPC/TPCCATracker";
+    defaultNotify = " (default)";
+    chainId = 0;
+  }
 
-  /*
-  
-  Int_t iResult=0;
-  const char* path="HLT/ConfigTPC/CATrackerComponent";
-  const char* defaultNotify="";
-  if (cdbEntry) {
-    path=cdbEntry;
-    defaultNotify=" (default)";
+  HLTInfo( "configure from entry \"%s\"%s, chain id %s", cdbEntry, defaultNotify, ( chainId != NULL && chainId[0] != 0 ) ? chainId : "<none>" );
+  AliCDBEntry *pEntry = AliCDBManager::Instance()->Get( cdbEntry );//,GetRunNo());
+
+  if ( !pEntry ) {
+    HLTError( "cannot fetch object \"%s\" from CDB", cdbEntry );
+    return -EINVAL;
   }
-  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);
-    }
+
+  TObjString* pString = dynamic_cast<TObjString*>( pEntry->GetObject() );
+
+  if ( !pString ) {
+    HLTError( "configuration object \"%s\" has wrong type, required TObjString", cdbEntry );
+    return -EINVAL;
   }
-  
-  const char* pathBField=kAliHLTCDBSolenoidBz;
-  
-  if (pathBField) {
-    HLTInfo("reconfigure B-Field from entry %s, chain id %s", path,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
-    AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(pathBField);//,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;  
-*/
+
+  HLTInfo( "received configuration object string: \"%s\"", pString->GetString().Data() );
+
+  return  ReadConfigurationString( pString->GetString().Data() );
 }
 
 
-Bool_t AliHLTTPCCATrackerComponent::CompareClusters(AliHLTTPCSpacePointData *a, AliHLTTPCSpacePointData *b)
+int AliHLTTPCCATrackerComponent::Configure( const char* cdbEntry, const char* chainId, const char *commandLine )
 {
-  //* Comparison function for sorting clusters
-  if( a->fPadRow<b->fPadRow ) return 1;
-  if( a->fPadRow>b->fPadRow ) return 0;
-  return (a->fZ < b->fZ);
+  // Configure the component
+  // There are few levels of configuration,
+  // parameters which are set on one step can be overwritten on the next step
+
+  //* read hard-coded values
+
+  SetDefaultConfiguration();
+
+  //* read the default CDB entry
+
+  int iResult1 = ReadCDBEntry( NULL, chainId );
+
+  //* read magnetic field
+
+  int iResult2 = ReadCDBEntry( kAliHLTCDBSolenoidBz, chainId );
+
+  //* read the actual CDB entry if required
+
+  int iResult3 = ( cdbEntry ) ? ReadCDBEntry( cdbEntry, chainId ) : 0;
+
+  //* read extra parameters from input (if they are)
+
+  int iResult4 = 0;
+
+  if ( commandLine && commandLine[0] != '\0' ) {
+    HLTInfo( "received configuration string from HLT framework: \"%s\"", commandLine );
+    iResult4 = ReadConfigurationString( commandLine );
+  }
+
+  // Initialise the tracker here
+
+  return iResult1 ? iResult1 : ( iResult2 ? iResult2 : ( iResult3 ? iResult3 : iResult4 ) );
 }
 
 
-Int_t AliHLTTPCCATrackerComponent::Configure( const char* arguments )
+
+int AliHLTTPCCATrackerComponent::DoInit( int argc, const char** argv )
 {
-  //* Set parameters
+  // Configure the CA tracker component
 
-  Int_t iResult=0;
-  if (!arguments) return iResult;
-  
-  TString allArgs=arguments;
-  TString argument;
-  Int_t bMissingParam=0;
-  
-  TObjArray* pTokens=allArgs.Tokenize(" ");
+  if ( fTracker ) return EINPROGRESS;
 
-  Int_t nArgs =  pTokens ?pTokens->GetEntries() :0;
 
-  for (int i=0; i<nArgs; i++ ){
-    argument=((TObjString*)pTokens->At(i))->GetString();
-    if (argument.IsNull()){
-    }
-    else if (argument.CompareTo("-solenoidBz")==0 ){
-      if ((bMissingParam=(++i>=pTokens->GetEntries()))) break; 
-      fSolenoidBz = ((TObjString*)pTokens->At(i))->GetString().Atof();
-      HLTInfo("Magnetic Field set to: %f", fSolenoidBz );
-    }
-    else if ( argument.CompareTo("-minNClustersOnTrack")==0 ||
-             argument.CompareTo("-minNTrackClusters")==0 ){
-      if ((bMissingParam=(++i>=pTokens->GetEntries()))) break; 
-      fMinNTrackClusters = ((TObjString*)pTokens->At(i))->GetString().Atoi();
-      HLTInfo("minNClustersOnTrack set to: %d", fMinNTrackClusters );
-    }
-    else if ( argument.CompareTo("-clusterZCut")==0 ){
-      if ((bMissingParam=(++i>=pTokens->GetEntries()))) break; 
-      fClusterZCut = TMath::Abs( ((TObjString*)pTokens->At(i))->GetString().Atof());
-      HLTInfo("ClusterZCut set to: %f", fClusterZCut );
-    }
-    else if ( argument.CompareTo("-newOutputType")==0 ){
-      fNewOutputType = 1;
-      HLTInfo("NewOutputType is set");
-    }
-    else {
-      HLTError("Unknown option %s ", argument.Data());
-      iResult=-EINVAL;
-    }
-  }
-  delete pTokens;
+  //fTracker = new AliHLTTPCCATrackerFramework();
+  //Do not initialize the TrackerFramework here since the CUDA framework is thread local and DoInit is called from different thread than DoEvent
 
-  if (bMissingParam) {
-    HLTError("Specifier missed for %s", argument.Data());    
-    iResult=-EINVAL;
+  TString arguments = "";
+  for ( int i = 0; i < argc; i++ ) {
+    if ( !arguments.IsNull() ) arguments += " ";
+    arguments += argv[i];
   }
 
-  return iResult;
+  return Configure( NULL, NULL, arguments.Data() );
+}
+
+
+int AliHLTTPCCATrackerComponent::DoDeinit()
+{
+  // see header file for class documentation
+  if (fTracker) delete fTracker;
+  fTracker = NULL;
+  return 0;
+}
+
+
+
+int AliHLTTPCCATrackerComponent::Reconfigure( const char* cdbEntry, const char* chainId )
+{
+  // Reconfigure the component from OCDB .
+
+  return Configure( cdbEntry, chainId, NULL );
+}
+
+
+bool AliHLTTPCCATrackerComponent::CompareClusters( AliHLTTPCSpacePointData *a, AliHLTTPCSpacePointData *b )
+{
+  //* Comparison function for sort clusters
+
+  if ( a->fPadRow < b->fPadRow ) return 1;
+  if ( a->fPadRow > b->fPadRow ) return 0;
+  return ( a->fZ < b->fZ );
 }
-  
 
 
 
-Int_t AliHLTTPCCATrackerComponent::DoEvent
-( 
- const AliHLTComponentEventData& evtData, 
- const AliHLTComponentBlockData* blocks, 
- AliHLTComponentTriggerData& /*trigData*/, 
- AliHLTUInt8_t* outputPtr, 
- AliHLTUInt32_t& size, 
- vector<AliHLTComponentBlockData>& outputBlocks )
+int AliHLTTPCCATrackerComponent::DoEvent
+(
+  const AliHLTComponentEventData& evtData,
+  const AliHLTComponentBlockData* blocks,
+  AliHLTComponentTriggerData& /*trigData*/,
+  AliHLTUInt8_t* outputPtr,
+  AliHLTUInt32_t& size,
 vector<AliHLTComponentBlockData>& outputBlocks )
 {
- //* process event
+  //* process event
+
   AliHLTUInt32_t maxBufferSize = size;
   size = 0; // output size
 
-  if(GetFirstInputBlock( kAliHLTDataTypeSOR ) || GetFirstInputBlock( kAliHLTDataTypeEOR )){    
+  if ( GetFirstInputBlock( kAliHLTDataTypeSOR ) || GetFirstInputBlock( kAliHLTDataTypeEOR ) ) {
     return 0;
   }
 
   TStopwatch timer;
 
   // Event reconstruction in one TPC slice with CA Tracker
+
   //Logging( kHLTLogWarning, "HLT::TPCCATracker::DoEvent", "DoEvent", "CA::DoEvent()" );
-  if ( evtData.fBlockCnt<=0 )
-    {
-      HLTWarning("no blocks in event" );
-      return 0;
-    }
-  
+  if ( evtData.fBlockCnt <= 0 ) {
+    HLTWarning( "no blocks in event" );
+    return 0;
+  }
+
   const AliHLTComponentBlockData* iter = NULL;
   unsigned long ndx;
-  AliHLTTPCClusterData* inPtrSP; 
-  // Determine the slice number 
-  
-  Int_t slice=-1;
+
+  // Determine the slice number
+
+  //Find min and max slice number with now slice missing in between (for default output)
+  int minslice = -1, maxslice = -1;
+  int slice = -1;
   {
-    std::vector<Int_t> slices;
-    std::vector<Int_t>::iterator slIter;
+    std::vector<int> slices;
+    std::vector<int>::iterator slIter;
     std::vector<unsigned> sliceCnts;
     std::vector<unsigned>::iterator slCntIter;
-  
-    for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ ){
-      iter = blocks+ndx;
-      if ( iter->fDataType != AliHLTTPCDefinitions::fgkClustersDataType ) continue;
+
+    for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ ) {
+      iter = blocks + ndx;
+      if ( iter->fDataType != AliHLTTPCDefinitions::fgkClustersDataType
+          && iter->fDataType != AliHLTTPCCADefinitions::fgkCompressedInputDataType
+          ) continue;
 
       slice = AliHLTTPCDefinitions::GetMinSliceNr( *iter );
+         if (slice < minslice || minslice == -1) minslice = slice;
+         if (slice > maxslice) maxslice = slice;
 
-      Bool_t found = 0;
+      bool found = 0;
       slCntIter = sliceCnts.begin();
-      for( slIter = slices.begin(); slIter!=slices.end(); slIter++, slCntIter++ ){
-       if ( *slIter == slice ){
-         found = kTRUE;
-         break;
-       }
+      for ( slIter = slices.begin(); slIter != slices.end(); slIter++, slCntIter++ ) {
+        if ( *slIter == slice ) {
+          found = kTRUE;
+          break;
+        }
       }
-      if ( !found ){
-       slices.push_back( slice );
-       sliceCnts.push_back( 1 );
-      } else *slCntIter++;     
+      if ( !found ) {
+        slices.push_back( slice );
+        sliceCnts.push_back( 1 );
+      } else *slCntIter++;
     }
-  
-    
-    // Determine slice number to really use.
-    if ( slices.size()>1 )
-      {
-       Logging( kHLTLogError, "HLT::TPCSliceTracker::DoEvent", "Multiple slices found in event",
-                "Multiple slice numbers found in event 0x%08lX (%lu). Determining maximum occuring slice number...",
-                evtData.fEventID, evtData.fEventID );
-       unsigned maxCntSlice=0;
-       slCntIter = sliceCnts.begin();
-       for( slIter = slices.begin(); slIter != slices.end(); slIter++, slCntIter++ )
-         {
-           Logging( kHLTLogError, "HLT::TPCSliceTracker::DoEvent", "Multiple slices found in event",
-                    "Slice %lu found %lu times.", *slIter, *slCntIter );
-           if ( maxCntSlice<*slCntIter )
-             {
-               maxCntSlice = *slCntIter;
-               slice = *slIter;
-             }
+
+         if ( slices.size() == 0 ) {
+               HLTWarning( "no slices found in event" );
+               return 0;
          }
-       Logging( kHLTLogError, "HLT::TPCSliceTracker::DoEvent", "Multiple slices found in event",
-                "Using slice %lu.", slice );
+
+
+    // Determine slice number to really use. (for obsolete output)
+    if ( slices.size() > 1 ) {
+               Logging( fOutputTRAKSEGS ? kHLTLogError : kHLTLogDebug, "HLT::TPCSliceTracker::DoEvent", "Multiple slices found in event",
+               "Multiple slice numbers found in event 0x%08lX (%lu). Determining maximum occuring slice number...",
+               evtData.fEventID, evtData.fEventID );
+      unsigned maxCntSlice = 0;
+      slCntIter = sliceCnts.begin();
+      for ( slIter = slices.begin(); slIter != slices.end(); slIter++, slCntIter++ ) {
+        Logging( fOutputTRAKSEGS ? kHLTLogError : kHLTLogDebug, "HLT::TPCSliceTracker::DoEvent", "Multiple slices found in event",
+                 "Slice %lu found %lu times.", *slIter, *slCntIter );
+        if ( fOutputTRAKSEGS && maxCntSlice < *slCntIter ) {
+          maxCntSlice = *slCntIter;
+          slice = *slIter;
+        }
       }
-    else if ( slices.size()>0 )
+      if (fOutputTRAKSEGS)
       {
-       slice = *(slices.begin());
-      }
-  }
-  
-  if( slice<0 ){
-    HLTWarning("no slices found in event" );
-    return 0;
-  }
+           Logging( kHLTLogError, "HLT::TPCSliceTracker::DoEvent", "Multiple slices found in event",
+               "Using slice %lu.", slice );
+       }
+    } else if ( slices.size() > 0 ) {
+      slice = *( slices.begin() );
+    }
 
 
-  // Initialize the tracker
+         if (fOutputTRAKSEGS)
+         {
+                 minslice = maxslice = slice;
+         }
+         else
+         {
+                 for (int islice = minslice;islice <= maxslice;islice++)
+                 {
+                         bool found = false;
+                         for(slIter = slices.begin(); slIter != slices.end();slIter++)
+                         {
+                                 if (*slIter == islice)
+                                 {
+                                         found = true;
+                                         break;
+                                 }
+                         }
+                         if (!found)
+                         {
+                                 maxslice = islice - 1;
+                                 break;
+                         }
+                 }
+        }
+  }
 
-  
+  if ( !fTracker ) fTracker = new AliHLTTPCCATrackerFramework;
+
+  int slicecount = maxslice + 1 - minslice;
+  if (slicecount > fTracker->MaxSliceCount())
   {
-    if( !fTracker ) fTracker = new AliHLTTPCCATracker;
-    Int_t iSec = slice;
-    Float_t inRmin = 83.65; 
-    //    Float_t inRmax = 133.3;
-    //    Float_t outRmin = 133.5; 
-    Float_t outRmax = 247.7;
-    Float_t plusZmin = 0.0529937; 
-    Float_t plusZmax = 249.778; 
-    Float_t minusZmin = -249.645; 
-    Float_t minusZmax = -0.0799937; 
-    Float_t dalpha = 0.349066;
-    Float_t alpha = 0.174533 + dalpha*iSec;
-    
-    Bool_t zPlus = (iSec<18 );
-    Float_t zMin =  zPlus ?plusZmin :minusZmin;
-    Float_t zMax =  zPlus ?plusZmax :minusZmax;
-    //TPCZmin = -249.645, ZMax = 249.778    
-    //    Float_t rMin =  inRmin;
-    //    Float_t rMax =  outRmax;
-    Int_t nRows = AliHLTTPCTransform::GetNRows();
-        
-    Float_t padPitch = 0.4;
-    Float_t sigmaZ = 0.228808;
-    
-    Float_t *rowX = new Float_t [nRows];
-    for( Int_t irow=0; irow<nRows; irow++){
-      rowX[irow] = AliHLTTPCTransform::Row2X( irow );
-    }     
-     
-    AliHLTTPCCAParam param;
-    param.Initialize( iSec, nRows, rowX, alpha, dalpha,
-                     inRmin, outRmax, zMin, zMax, padPitch, sigmaZ, fSolenoidBz );
-    param.SetHitPickUpFactor( 2 );
-    param.Update();
-    fTracker->Initialize( param ); 
-    delete[] rowX;
+       maxslice = minslice + (slicecount = fTracker->MaxSliceCount());
   }
+  int nClustersTotalSum = 0;
+  AliHLTTPCCAClusterData* clusterData = new AliHLTTPCCAClusterData[slicecount];
+
 
-    
   // min and max patch numbers and row numbers
+  int* slicerow = new int[slicecount * 2];
+  int* sliceminPatch = new int[slicecount];
+  int* slicemaxPatch = new int[slicecount];
+  memset(slicerow, 0, slicecount * 2 * sizeof(int));
+  for (int i = 0;i < slicecount;i++)
+  {
+         sliceminPatch[i] = 100;
+         slicemaxPatch[i] = -1;
+  }
+
+  //Prepare everything for all slices
 
-  Int_t row[2] = {0,0};
-  Int_t minPatch=100, maxPatch = -1;
+  for (int islice = 0;islice < slicecount;islice++)
+  {
+         slice = minslice + islice;
 
-  // total n Hits
+         // Initialize the tracker slice
+         {
+               int iSec = slice;
+               float inRmin = 83.65;
+               //    float inRmax = 133.3;
+               //    float outRmin = 133.5;
+               float outRmax = 247.7;
+               float plusZmin = 0.0529937;
+               float plusZmax = 249.778;
+               float minusZmin = -249.645;
+               float minusZmax = -0.0799937;
+               float dalpha = 0.349066;
+               float alpha = 0.174533 + dalpha * iSec;
+
+               bool zPlus = ( iSec < 18 );
+               float zMin =  zPlus ? plusZmin : minusZmin;
+               float zMax =  zPlus ? plusZmax : minusZmax;
+               //TPCZmin = -249.645, ZMax = 249.778
+               //    float rMin =  inRmin;
+               //    float rMax =  outRmax;
+               int nRows = AliHLTTPCTransform::GetNRows();
+
+               float padPitch = 0.4;
+               float sigmaZ = 0.228808;
+
+               float *rowX = new float [nRows];
+               for ( int irow = 0; irow < nRows; irow++ ) {
+                 rowX[irow] = AliHLTTPCTransform::Row2X( irow );
+               }
+
+               AliHLTTPCCAParam param;
+
+               param.Initialize( iSec, nRows, rowX, alpha, dalpha,
+                                                 inRmin, outRmax, zMin, zMax, padPitch, sigmaZ, fSolenoidBz );
+               param.SetHitPickUpFactor( 2 );
+               if( fNeighboursSearchArea>0 ) param.SetNeighboursSearchArea( fNeighboursSearchArea );
+               if( fClusterErrorCorrectionY>1.e-4 ) param.SetClusterError2CorrectionY( fClusterErrorCorrectionY*fClusterErrorCorrectionY );
+               if( fClusterErrorCorrectionZ>1.e-4 ) param.SetClusterError2CorrectionZ( fClusterErrorCorrectionZ*fClusterErrorCorrectionZ );
+               param.Update();
+               fTracker->InitializeSliceParam( slice, param );
+               delete[] rowX;
+         }
 
-  Int_t nHitsTotal = 0;
+         // total n Hits
+         int nClustersTotal = 0;
+
+         // sort patches
+         std::vector<unsigned long> patchIndices;
+
+         for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ ) {
+               iter = blocks + ndx;
+               if ( slice != AliHLTTPCDefinitions::GetMinSliceNr( *iter ) ) continue;
+               if ( iter->fDataType == AliHLTTPCDefinitions::fgkClustersDataType ){
+                 AliHLTTPCClusterData* inPtrSP = ( AliHLTTPCClusterData* )( iter->fPtr );
+                 nClustersTotal += inPtrSP->fSpacePointCnt;
+               } 
+               else if ( iter->fDataType == AliHLTTPCCADefinitions::fgkCompressedInputDataType){
+                 const AliHLTUInt8_t * inPtr =  (const AliHLTUInt8_t *)iter->fPtr;
+                 while( inPtr< ((const AliHLTUInt8_t *) iter->fPtr) + iter->fSize ){
+                   AliHLTTPCCACompressedClusterRow *row = (AliHLTTPCCACompressedClusterRow*)inPtr;
+                   nClustersTotal+= row->fNClusters;     
+                   inPtr = (const AliHLTUInt8_t *)(row->fClusters+row->fNClusters);
+                 }
+               }
+               else continue;
+
+               int patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
+               if ( sliceminPatch[islice] > patch ) {
+                 sliceminPatch[islice] = patch;
+                 slicerow[2 * islice + 0] = AliHLTTPCTransform::GetFirstRow( patch );
+               }
+               if ( slicemaxPatch[islice] < patch ) {
+                 slicemaxPatch[islice] = patch;
+                 slicerow[2 * islice + 1] = AliHLTTPCTransform::GetLastRow( patch );
+               }
+               std::vector<unsigned long>::iterator pIter = patchIndices.begin();
+               while ( pIter != patchIndices.end() && AliHLTTPCDefinitions::GetMinPatchNr( blocks[*pIter] ) < patch ) {
+                 pIter++;
+               }
+               patchIndices.insert( pIter, ndx );
+         }
 
-  // sort patches
 
-  std::vector<unsigned long> patchIndices;
+         // pass event to CA Tracker
+
+
+         Logging( kHLTLogDebug, "HLT::TPCCATracker::DoEvent", "Reading hits",
+                          "Total %d hits to read for slice %d", nClustersTotal, slice );
+
+
+         clusterData[islice].StartReading( slice, nClustersTotal );
+
+         for ( std::vector<unsigned long>::iterator pIter = patchIndices.begin(); pIter != patchIndices.end(); pIter++ ) {
+               ndx = *pIter;
+               iter = blocks + ndx;
+               int patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
+               int nPatchClust = 0;
+               if ( iter->fDataType == AliHLTTPCDefinitions::fgkClustersDataType ){
+                 AliHLTTPCClusterData* inPtrSP = ( AliHLTTPCClusterData* )( iter->fPtr );
+                 nPatchClust = inPtrSP->fSpacePointCnt;
+                 for ( unsigned int i = 0; i < inPtrSP->fSpacePointCnt; i++ ) {
+                   AliHLTTPCSpacePointData *c = &( inPtrSP->fSpacePoints[i] );
+                   if ( CAMath::Abs( c->fZ ) > fClusterZCut ) continue;
+                   if ( c->fPadRow > 159 ) {
+                     HLTError( "Wrong TPC cluster with row number %d received", c->fPadRow );
+                     continue;
+                   }
+                   clusterData[islice].ReadCluster( c->fID, c->fPadRow, c->fX, c->fY, c->fZ, c->fCharge );
+                 }           
+               } 
+               else if ( iter->fDataType == AliHLTTPCCADefinitions::fgkCompressedInputDataType){
+                 const AliHLTUInt8_t * inPtr = (const AliHLTUInt8_t *)iter->fPtr;
+                 nPatchClust=0;
+                 while( inPtr< ((const AliHLTUInt8_t *)iter->fPtr) + iter->fSize ){
+                   AliHLTTPCCACompressedClusterRow *row = (AliHLTTPCCACompressedClusterRow*)inPtr;
+                   UInt_t id = row->fSlicePatchRowID;
+                   UInt_t jslice = id>>10;       
+                   UInt_t jpatch = (id>>6) & 0x7;
+                   UInt_t jrow   =  id     & 0x3F;     
+                   jrow+= AliHLTTPCTransform::GetFirstRow( jpatch );
+                   Double_t rowX = AliHLTTPCTransform::Row2X( jrow );
+                   //cout<<"Read row: s "<<jslice<<" p "<<jpatch<<" r "<<jrow<<" x "<<row->fX<<" nclu "<<row->fNClusters<<" :"<<endl;
+                   if( jrow > 159 ) {
+                     HLTError( "Wrong TPC cluster with row number %d received", jrow );
+                     continue;
+                   }
+                   for ( unsigned int i = 0; i < row->fNClusters; i++ ) {
+                     AliHLTTPCCACompressedCluster *c = &( row->fClusters[i] );
+                     
+                     UInt_t ix0 = c->fP0 >>24;
+                     UInt_t ix1 = c->fP1 >>24;
+                     Double_t x = (ix1<<8) + ix0;
+                     Double_t y = c->fP0 & 0x00FFFFFF;
+                     Double_t z = c->fP1 & 0x00FFFFFF;
+                     x = (x - 32768.)*1.e-4 + rowX;
+                     y = (y - 8388608.)*1.e-4;
+                     z = (z - 8388608.)*1.e-4;
+                     
+                     UInt_t cluId = nPatchClust + ((jslice&0x7f)<<25)+((jpatch&0x7)<<22);
+                     //cout<<"clu "<<i<<": "<<x<<" "<<y<<" "<<z<<" "<<cluId<<endl;
+                     if ( CAMath::Abs( z ) <= fClusterZCut ){
+                       clusterData[islice].ReadCluster( cluId, jrow, x, y, z, 0 );
+                     }
+                     nPatchClust++;              
+                   }
+                   inPtr = (const AliHLTUInt8_t *)(row->fClusters+row->fNClusters);
+                 }
+               }
+               Logging( kHLTLogInfo, "HLT::TPCCATracker::DoEvent", "Reading hits",
+                        "Read %d hits for slice %d - patch %d", nPatchClust, slice, patch );
+         }
 
-  for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ ){
-    iter = blocks+ndx;      
-    if( iter->fDataType != AliHLTTPCDefinitions::fgkClustersDataType ) continue;
-    if( slice!=AliHLTTPCDefinitions::GetMinSliceNr( *iter ) ) continue;
-    inPtrSP = (AliHLTTPCClusterData*)(iter->fPtr);
-    nHitsTotal+=inPtrSP->fSpacePointCnt;
-    Int_t patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
-    if ( minPatch>patch ){
-      minPatch = patch;
-      row[0] = AliHLTTPCTransform::GetFirstRow( patch );
-    }
-    if ( maxPatch<patch ){
-      maxPatch = patch;
-      row[1] = AliHLTTPCTransform::GetLastRow( patch );
-    }
-    std::vector<unsigned long>::iterator pIter = patchIndices.begin(); 
-    while( pIter!=patchIndices.end() && AliHLTTPCDefinitions::GetMinPatchNr( blocks[*pIter] ) < patch ){
-      pIter++;
-    }
-    patchIndices.insert( pIter, ndx );
+         clusterData[islice].FinishReading();
+         nClustersTotalSum += nClustersTotal;
   }
-           
 
-  // pass event to CA Tracker
+  //Prepare Output
+  AliHLTTPCCASliceOutput::outputControlStruct outputControl;
+  //Set tracker output so tracker does not have to output both formats!
+  outputControl.fObsoleteOutput = fOutputTRAKSEGS;
+  outputControl.fDefaultOutput = !fOutputTRAKSEGS;
+
+  //For new output we can write directly to output buffer
+  outputControl.fOutputPtr = fOutputTRAKSEGS ? NULL : (char*) outputPtr;
+  outputControl.fOutputMaxSize = maxBufferSize;
+
+  AliHLTTPCCASliceOutput** sliceOutput = new AliHLTTPCCASliceOutput*[slicecount];
+  memset(sliceOutput, 0, slicecount * sizeof(AliHLTTPCCASliceOutput*));
+
+  // reconstruct the event
+  TStopwatch timerReco;
+  fTracker->SetOutputControl(&outputControl);
+  fTracker->ProcessSlices(minslice, slicecount, clusterData, sliceOutput);
+  timerReco.Stop();
   
-  fTracker->StartEvent();
+  int ret = 0;
+  unsigned int mySize = 0;
+  int ntracks = 0;
+  int error = 0;
 
-  Logging( kHLTLogDebug, "HLT::TPCCATracker::DoEvent", "Reading hits",
-          "Total %d hits to read for slice %d", nHitsTotal, slice );
+  for (int islice = 0;islice < slicecount;islice++)
+  {
+         slice = minslice + islice;
 
+         if (sliceOutput[islice])
+         {
+                 // write reconstructed tracks
 
-  AliHLTTPCSpacePointData** vOrigClusters = new AliHLTTPCSpacePointData* [ nHitsTotal];
+                 if ( fOutputTRAKSEGS ) {
+
+                 Logging( kHLTLogDebug, "HLT::TPCCATracker::DoEvent", "Reconstruct",
+                                  "%d tracks found for slice %d", sliceOutput[islice]->NOutTracks(), slice );
 
-  Int_t nClusters=0;
+                       ntracks = sliceOutput[islice]->NOutTracks();
+
+                       AliHLTTPCTrackletData* outPtr = ( AliHLTTPCTrackletData* )( outputPtr );
 
-  for( std::vector<unsigned long>::iterator pIter = patchIndices.begin(); pIter!=patchIndices.end(); pIter++ ){
-    ndx = *pIter;
-    iter = blocks+ndx;
-      
-    Int_t patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
-    inPtrSP = (AliHLTTPCClusterData*)(iter->fPtr);
-      
-    Logging( kHLTLogDebug, "HLT::TPCCATracker::DoEvent", "Reading hits",
-            "Reading %d hits for slice %d - patch %d", inPtrSP->fSpacePointCnt, slice, patch );
-      
-    for (UInt_t i=0; i<inPtrSP->fSpacePointCnt; i++ ){ 
-      vOrigClusters[nClusters++] = &(inPtrSP->fSpacePoints[i]);
-    }
-  }
+                       AliHLTTPCTrackSegmentData* currOutTracklet = outPtr->fTracklets;
 
-  // sort clusters since they are not sorted fore some reason
+                       mySize =   ( ( AliHLTUInt8_t * )currOutTracklet ) -  ( ( AliHLTUInt8_t * )outputPtr );
 
-  sort( vOrigClusters, vOrigClusters+nClusters, CompareClusters );
+                       outPtr->fTrackletCnt = 0;
 
-  Float_t *vHitStoreX = new Float_t [nHitsTotal];       // hit X coordinates
-  Float_t *vHitStoreY = new Float_t [nHitsTotal];       // hit Y coordinates
-  Float_t *vHitStoreZ = new Float_t [nHitsTotal];       // hit Z coordinates
-  Int_t *vHitStoreIntID = new Int_t [nHitsTotal];            // hit ID's
-  Int_t *vHitStoreID = new Int_t [nHitsTotal];            // hit ID's
-  Int_t *vHitRowID = new Int_t [nHitsTotal];            // hit ID's
+                       for ( int itr = 0; itr < ntracks; itr++ ) {
 
-  Int_t nHits = 0;
+                         AliHLTTPCCAOutTrack &t = sliceOutput[islice]->OutTracks()[itr];
 
-  {
-    Int_t rowNHits[200];
-    Int_t rowFirstHits[200];
-    for( Int_t ir=0; ir<200; ir++ ) rowNHits[ir] = 0;
-    Int_t oldRow = -1;
-    for (Int_t i=0; i<nClusters; i++ ){
-      AliHLTTPCSpacePointData* pSP = vOrigClusters[i];
-      if( oldRow>=0 && pSP->fPadRow < oldRow )
-       HLTError("CA: clusters from row %d are readed twice",oldRow);      
-      
-      if( TMath::Abs(pSP->fZ)>fClusterZCut) continue;
-      
-      vHitStoreX[nHits] = pSP->fX;
-      vHitStoreY[nHits] = pSP->fY;
-      vHitStoreZ[nHits] = pSP->fZ;
-      vHitStoreIntID[nHits] = nHits;
-      vHitStoreID[nHits] = pSP->fID;
-      vHitRowID[nHits] = pSP->fPadRow;
-      nHits++;
-      rowNHits[pSP->fPadRow]++;
-    }  
-
-    Int_t firstRowHit = 0;
-    for( Int_t ir=0; ir<200; ir++ ){
-      rowFirstHits[ir] = firstRowHit;
-      firstRowHit+=rowNHits[ir];
-    }
+                         //Logging( kHLTLogDebug, "HLT::TPCCATracker::DoEvent", "Wrtite output","track %d with %d hits", itr, t.NHits());
 
-    fTracker->ReadEvent( rowFirstHits, rowNHits, vHitStoreX, vHitStoreY, vHitStoreZ, nHits );
-  }
+                         if ( t.NHits() < fMinNTrackClusters ) continue;
 
-  if( vOrigClusters ) delete[] vOrigClusters;
+                         // calculate output track size
 
-  // reconstruct the event  
+                         unsigned int dSize = sizeof( AliHLTTPCTrackSegmentData ) + t.NHits() * sizeof( unsigned int );
 
-  TStopwatch timerReco;
+                         if ( mySize + dSize > maxBufferSize ) {
+                               HLTWarning( "Output buffer size exceed (buffer size %d, current size %d), %d tracks are not stored", maxBufferSize, mySize, ntracks - itr + 1 );
+                               ret = -ENOSPC;
+                               error = 1;
+                               break;
+                         }
 
-  fTracker->Reconstruct();
+                         // convert CA track parameters to HLT Track Segment
 
-  timerReco.Stop();
+                         int iFirstRow = 1000;
+                         int iLastRow = -1;
+                         int iFirstHit = sliceOutput[islice]->OutTrackHit(t.FirstHitRef());
+                         int iLastHit = iFirstHit;
+                         for ( int ih = 0; ih < t.NHits(); ih++ ) {
+                               int hitID = sliceOutput[islice]->OutTrackHit(t.FirstHitRef() + ih);
+                               int iRow = clusterData[islice].RowNumber( hitID );
+                               if ( iRow < iFirstRow ) {  iFirstRow = iRow; iFirstHit = hitID; }
+                               if ( iRow > iLastRow ) { iLastRow = iRow; iLastHit = hitID; }
+                         }
 
-  Int_t ret = 0;
+                         AliHLTTPCCATrackParam par = t.StartPoint();
 
-  Logging( kHLTLogDebug, "HLT::TPCCATracker::DoEvent", "Reconstruct",
-          "%d tracks found for slice %d",fTracker->NOutTracks(), slice);
+                         par.TransportToX( clusterData[islice].X( iFirstHit ), .99 );
 
+                         AliExternalTrackParam tp;
+                         AliHLTTPCCATrackConvertor::GetExtParam( par, tp, 0 );
 
-  // write reconstructed tracks
+                         currOutTracklet->fX = tp.GetX();
+                         currOutTracklet->fY = tp.GetY();
+                         currOutTracklet->fZ = tp.GetZ();
+                         currOutTracklet->fCharge = ( int ) tp.GetSign();
+                         currOutTracklet->fPt = TMath::Abs( tp.GetSignedPt() );
+                         float snp =  tp.GetSnp() ;
+                         if ( snp > .999 ) snp = .999;
+                         if ( snp < -.999 ) snp = -.999;
+                         currOutTracklet->fPsi = TMath::ASin( snp );
+                         currOutTracklet->fTgl = tp.GetTgl();
 
-  UInt_t mySize = 0;
-  Int_t ntracks = *fTracker->NOutTracks();
+                         currOutTracklet->fY0err = tp.GetSigmaY2();
+                         currOutTracklet->fZ0err = tp.GetSigmaZ2();
+                         float h = -currOutTracklet->fPt * currOutTracklet->fPt;
+                         currOutTracklet->fPterr = h * h * tp.GetSigma1Pt2();
+                         h = 1. / TMath::Sqrt( 1 - snp * snp );
+                         currOutTracklet->fPsierr = h * h * tp.GetSigmaSnp2();
+                         currOutTracklet->fTglerr = tp.GetSigmaTgl2();
 
-  
-  if( !fNewOutputType ){
-
-    AliHLTTPCTrackletData* outPtr = (AliHLTTPCTrackletData*)(outputPtr);
-    
-    AliHLTTPCTrackSegmentData* currOutTracklet = outPtr->fTracklets;    
-    
-    mySize =   ((AliHLTUInt8_t *)currOutTracklet) -  ((AliHLTUInt8_t *)outputPtr);
-    
-    outPtr->fTrackletCnt = 0; 
-    
-    for( Int_t itr=0; itr<ntracks; itr++ ){
-      
-      AliHLTTPCCAOutTrack &t = fTracker->OutTracks()[itr];    
-      
-      //Logging( kHLTLogDebug, "HLT::TPCCATracker::DoEvent", "Wrtite output","track %d with %d hits", itr, t.NHits());
-      
-      if( t.NHits()<fMinNTrackClusters ) continue;
-      
-      // calculate output track size
-      
-      UInt_t dSize = sizeof(AliHLTTPCTrackSegmentData) + t.NHits()*sizeof(UInt_t);
-      
-      if( mySize + dSize > maxBufferSize ){
-       HLTWarning("Output buffer size exceed (buffer size %d, current size %d), %d tracks are not stored", maxBufferSize, mySize, ntracks-itr+1);
-       ret = -ENOSPC;
-       break;
-      }
-      
-      // convert CA track parameters to HLT Track Segment
-      
-      Int_t iFirstRow = 1000;
-      Int_t iLastRow = -1;
-      Int_t iFirstHit = fTracker->OutTrackHits()[t.FirstHitRef()];
-      Int_t iLastHit = iFirstHit;
-      for( Int_t ih=0; ih<t.NHits(); ih++ ){
-       Int_t hitID = fTracker->OutTrackHits()[t.FirstHitRef() + ih ];
-       Int_t iRow = vHitRowID[hitID];
-       if( iRow<iFirstRow ){  iFirstRow = iRow; iFirstHit = hitID; }
-       if( iRow>iLastRow ){ iLastRow = iRow; iLastHit = hitID; }
-      }   
-      
-      AliHLTTPCCATrackParam par = t.StartPoint();
-      
-      par.TransportToX( vHitStoreX[iFirstHit], .99 );
-      
-      AliExternalTrackParam tp;
-      AliHLTTPCCATrackConvertor::GetExtParam( par, tp, 0 );
-      
-      currOutTracklet->fX = tp.GetX();
-      currOutTracklet->fY = tp.GetY();
-      currOutTracklet->fZ = tp.GetZ();
-      currOutTracklet->fCharge = (Int_t ) tp.GetSign();
-      currOutTracklet->fPt = TMath::Abs(tp.GetSignedPt());
-      Float_t snp =  tp.GetSnp() ;
-      if( snp>.999 ) snp=.999;
-      if( snp<-.999 ) snp=-.999;
-      currOutTracklet->fPsi = TMath::ASin( snp );
-      currOutTracklet->fTgl = tp.GetTgl();
-      
-      currOutTracklet->fY0err = tp.GetSigmaY2();
-      currOutTracklet->fZ0err = tp.GetSigmaZ2();
-      Float_t h = -currOutTracklet->fPt*currOutTracklet->fPt;
-      currOutTracklet->fPterr = h*h*tp.GetSigma1Pt2();
-      h = 1./TMath::Sqrt(1-snp*snp);
-      currOutTracklet->fPsierr = h*h*tp.GetSigmaSnp2();
-      currOutTracklet->fTglerr = tp.GetSigmaTgl2();
-      
-      if( par.TransportToX( vHitStoreX[iLastHit],.99 ) ){     
-       currOutTracklet->fLastX = par.GetX();
-       currOutTracklet->fLastY = par.GetY();
-       currOutTracklet->fLastZ = par.GetZ();
-      } else {
-       currOutTracklet->fLastX = vHitStoreX[iLastHit];
-       currOutTracklet->fLastY = vHitStoreY[iLastHit];
-       currOutTracklet->fLastZ = vHitStoreZ[iLastHit];
-      }
-      //if( currOutTracklet->fLastX<10. ) {
-      //HLTError("CA last point: hitxyz=%f,%f,%f, track=%f,%f,%f, tracklet=%f,%f,%f, nhits=%d",vHitStoreX[iLastHit],vHitStoreY[iLastHit],vHitStoreZ[iLastHit],
-      //par.GetX(), par.GetY(),par.GetZ(),currOutTracklet->fLastX,currOutTracklet->fLastY ,currOutTracklet->fLastZ, t.NHits());
-      //}
-#ifdef INCLUDE_TPC_HOUGH
-#ifdef ROWHOUGHPARAMS
-      currOutTracklet->fTrackID = 0;
-      currOutTracklet->fRowRange1 = vHitRowID[iFirstHit];
-      currOutTracklet->fRowRange2 = vHitRowID[iLastHit];
-      currOutTracklet->fSector = slice;
-      currOutTracklet->fPID = 211;
-#endif
-#endif // INCLUDE_TPC_HOUGH
-      
-      
-      currOutTracklet->fNPoints = t.NHits();
-      
-      for( Int_t i=0; i<t.NHits(); i++ ){
-       currOutTracklet->fPointIDs[i] = vHitStoreID[fTracker->OutTrackHits()[t.FirstHitRef()+i]];
-      }
-      
-      currOutTracklet = (AliHLTTPCTrackSegmentData*)( (Byte_t *)currOutTracklet + dSize );
-      mySize+=dSize;
-      outPtr->fTrackletCnt++; 
-    }
-  } else { // new output type
-
-    mySize = fTracker->Output()->EstimateSize( fTracker->Output()->NTracks(), 
-                                              fTracker->Output()->NTrackClusters() );
-    if( mySize <= maxBufferSize ){
-      const AliHLTUInt8_t* outputevent = reinterpret_cast<const AliHLTUInt8_t*>(fTracker->Output());
-      for( UInt_t i=0; i<mySize; i++ ) outputPtr[i] = outputevent[i];
-    } else {    
-      HLTWarning("Output buffer size exceed (buffer size %d, current size %d), tracks are not stored", maxBufferSize, mySize );
-      mySize = 0;
-      ret = -ENOSPC;
-    }
+                         if ( par.TransportToX( clusterData[islice].X( iLastHit ), .99 ) ) {
+                               currOutTracklet->fLastX = par.GetX();
+                               currOutTracklet->fLastY = par.GetY();
+                               currOutTracklet->fLastZ = par.GetZ();
+                         } else {
+                               currOutTracklet->fLastX = clusterData[islice].X( iLastHit );
+                               currOutTracklet->fLastY = clusterData[islice].Y( iLastHit );
+                               currOutTracklet->fLastZ = clusterData[islice].Z( iLastHit );
+                         }
+                         //if( currOutTracklet->fLastX<10. ) {
+                         //HLTError("CA last point: hitxyz=%f,%f,%f, track=%f,%f,%f, tracklet=%f,%f,%f, nhits=%d",clusterData[islice].X( iLastHit ),clusterData[islice].Y( iLastHit],clusterData[islice].Z( iLastHit],
+                         //par.GetX(), par.GetY(),par.GetZ(),currOutTracklet->fLastX,currOutTracklet->fLastY ,currOutTracklet->fLastZ, t.NHits());
+                         //}
+               #ifdef INCLUDE_TPC_HOUGH
+               #ifdef ROWHOUGHPARAMS
+                         currOutTracklet->fTrackID = 0;
+                         currOutTracklet->fRowRange1 = clusterData[islice].RowNumber( iFirstHit );
+                         currOutTracklet->fRowRange2 = clusterData[islice].RowNumber( iLastHit );
+                         currOutTracklet->fSector = slice;
+                         currOutTracklet->fPID = 211;
+               #endif
+               #endif // INCLUDE_TPC_HOUGH
+
+
+                         currOutTracklet->fNPoints = t.NHits();
+
+                         for ( int i = 0; i < t.NHits(); i++ ) {
+                               currOutTracklet->fPointIDs[i] = clusterData[islice].Id( sliceOutput[islice]->OutTrackHit(t.FirstHitRef()+i) );
+                         }
+
+                         currOutTracklet = ( AliHLTTPCTrackSegmentData* )( ( Byte_t * )currOutTracklet + dSize );
+                         mySize += dSize;
+                         outPtr->fTrackletCnt++;
+                       }
+
+                 } else { // default output type
+
+                 Logging( kHLTLogDebug, "HLT::TPCCATracker::DoEvent", "Reconstruct",
+                                  "%d tracks found for slice %d", sliceOutput[islice]->NTracks(), slice );
+
+                         mySize += sliceOutput[islice]->OutputMemorySize();
+                         ntracks += sliceOutput[islice]->NTracks();
+                 }
+         }
+         else
+         {
+                 HLTWarning( "Output buffer size exceed (buffer size %d, current size %d), tracks are not stored", maxBufferSize, mySize );
+                 mySize = 0;
+                 ret = -ENOSPC;
+                 ntracks = 0;
+                 error = 1;
+                 break;
+         }
   }
-  if( vHitStoreX ) delete[] vHitStoreX;
-  if( vHitStoreY ) delete[] vHitStoreY;
-  if( vHitStoreZ ) delete[] vHitStoreZ;
-  if( vHitStoreIntID ) delete[] vHitStoreIntID;
-  if( vHitStoreID ) delete[] vHitStoreID;
-  if( vHitRowID ) delete[] vHitRowID;
-
-  if( mySize>0 ){
-    AliHLTComponentBlockData bd;
-    FillBlockData( bd );
-    bd.fOffset = 0;
-    bd.fSize = mySize;
-    bd.fSpecification = AliHLTTPCDefinitions::EncodeDataSpecification( slice, slice, minPatch, maxPatch ); 
-    outputBlocks.push_back( bd );
+
+  size = 0;
+  if (error == 0)
+  {
+         for (int islice = 0;islice < slicecount;islice++)
+         {
+                 slice = minslice + islice;
+                 if (!fOutputTRAKSEGS) mySize = sliceOutput[islice]->OutputMemorySize();
+                 if (mySize > 0)
+                 {
+                       AliHLTComponentBlockData bd;
+                       FillBlockData( bd );
+                       bd.fOffset = fOutputTRAKSEGS ? 0 : ((char*) sliceOutput[islice] - (char*) outputPtr);
+                       bd.fSize = mySize;
+                       bd.fSpecification = AliHLTTPCDefinitions::EncodeDataSpecification( slice, slice, sliceminPatch[islice], slicemaxPatch[islice] );
+                       bd.fDataType = GetOutputDataType();
+                       outputBlocks.push_back( bd );
+                       size += mySize;
+                 }
+         }
   }
-  size = mySize;
-  
+
+  //No longer needed
+  delete[] clusterData;
+  //These are only temporary pointers to the output and no longer needed
+  delete[] sliceOutput;
+
   timer.Stop();
 
-  fFullTime+= timer.RealTime();
-  fRecoTime+= timerReco.RealTime();
+  fFullTime += timer.RealTime();
+  fRecoTime += timerReco.RealTime();
   fNEvents++;
 
   // Set log level to "Warning" for on-line system monitoring
-  Int_t hz = (Int_t) (fFullTime>1.e-10 ?fNEvents/fFullTime :100000);
-  Int_t hz1 = (Int_t) (fRecoTime>1.e-10 ?fNEvents/fRecoTime :100000);
-  HLTWarning( "CATracker slice %d: output %d tracks;  input %d clusters, patches %d..%d, rows %d..%d; reco time %d/%d Hz", 
-           slice, ntracks, nClusters, minPatch, maxPatch, row[0], row[1], hz, hz1 );
+  int hz = ( int ) ( fFullTime > 1.e-10 ? fNEvents / fFullTime : 100000 );
+  int hz1 = ( int ) ( fRecoTime > 1.e-10 ? fNEvents / fRecoTime : 100000 );
+  //Min and Max Patch are taken for first slice processed...
+  HLTInfo( "CATracker slices %d-%d: output %d tracks;  input %d clusters, patches %d..%d, rows %d..%d; time: full %d / reco %d Hz",
+           minslice, maxslice, ntracks, nClustersTotalSum, sliceminPatch[0], slicemaxPatch[0], slicerow[0], slicerow[1], hz, hz1 );
 
   return ret;
 }
 
-       
+