TPC track model compression added (Jenny)
authorrichterm <richterm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 24 Jan 2008 15:23:56 +0000 (15:23 +0000)
committerrichterm <richterm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 24 Jan 2008 15:23:56 +0000 (15:23 +0000)
25 files changed:
HLT/TPCLib/AliHLTTPCDefinitions.cxx
HLT/TPCLib/AliHLTTPCDefinitions.h
HLT/TPCLib/comp/AliHLTTPCCompDataCompressorHelper.cxx [new file with mode: 0644]
HLT/TPCLib/comp/AliHLTTPCCompDataCompressorHelper.h [new file with mode: 0644]
HLT/TPCLib/comp/AliHLTTPCCompDumpComponent.cxx [new file with mode: 0644]
HLT/TPCLib/comp/AliHLTTPCCompDumpComponent.h [new file with mode: 0644]
HLT/TPCLib/comp/AliHLTTPCCompModelAnalysis.cxx [new file with mode: 0644]
HLT/TPCLib/comp/AliHLTTPCCompModelAnalysis.h [new file with mode: 0644]
HLT/TPCLib/comp/AliHLTTPCCompModelConverter.cxx [new file with mode: 0644]
HLT/TPCLib/comp/AliHLTTPCCompModelConverter.h [new file with mode: 0644]
HLT/TPCLib/comp/AliHLTTPCCompModelConverterComponent.cxx [new file with mode: 0644]
HLT/TPCLib/comp/AliHLTTPCCompModelConverterComponent.h [new file with mode: 0644]
HLT/TPCLib/comp/AliHLTTPCCompModelDeconverter.cxx [new file with mode: 0644]
HLT/TPCLib/comp/AliHLTTPCCompModelDeconverter.h [new file with mode: 0644]
HLT/TPCLib/comp/AliHLTTPCCompModelDeconverterComponent.cxx [new file with mode: 0644]
HLT/TPCLib/comp/AliHLTTPCCompModelDeconverterComponent.h [new file with mode: 0644]
HLT/TPCLib/comp/AliHLTTPCCompModelDeflater.cxx [new file with mode: 0644]
HLT/TPCLib/comp/AliHLTTPCCompModelDeflater.h [new file with mode: 0644]
HLT/TPCLib/comp/AliHLTTPCCompModelDeflaterComponent.cxx [new file with mode: 0644]
HLT/TPCLib/comp/AliHLTTPCCompModelDeflaterComponent.h [new file with mode: 0644]
HLT/TPCLib/comp/AliHLTTPCCompModelInflater.cxx [new file with mode: 0644]
HLT/TPCLib/comp/AliHLTTPCCompModelInflater.h [new file with mode: 0644]
HLT/TPCLib/comp/AliHLTTPCCompModelInflaterComponent.cxx [new file with mode: 0644]
HLT/TPCLib/comp/AliHLTTPCCompModelInflaterComponent.h [new file with mode: 0644]
HLT/libAliHLTTPC.pkg

index 5126aa0..4a203fb 100644 (file)
@@ -46,6 +46,15 @@ const AliHLTComponentDataType AliHLTTPCDefinitions::fgkTrackSegmentsDataType =
   (AliHLTComponentDataType){sizeof(AliHLTComponentDataType),                          {'T','R','A','K','S','E','G','S'},  kAliHLTDataOriginAny} | kAliHLTDataOriginTPC;
 const AliHLTComponentDataType AliHLTTPCDefinitions::fgkTracksDataType =                                                                                              
   (AliHLTComponentDataType){sizeof(AliHLTComponentDataType),                          {'T','R','A','C','K','S',' ',' '},  kAliHLTDataOriginAny} | kAliHLTDataOriginTPC;
+
+const AliHLTComponentDataType AliHLTTPCDefinitions::fgkClusterTracksModelDataType =
+  (AliHLTComponentDataType){ sizeof(AliHLTComponentDataType),                         {'C','L','S','T','R','K','M','D'},  kAliHLTDataOriginAny} | kAliHLTDataOriginTPC;
+const AliHLTComponentDataType AliHLTTPCDefinitions::fgkRemainingClustersModelDataType =
+  (AliHLTComponentDataType) { sizeof(AliHLTComponentDataType),                        {'R','E','M','C','L','S','M','D'},  kAliHLTDataOriginAny} | kAliHLTDataOriginTPC;
+const AliHLTComponentDataType AliHLTTPCDefinitions::fgkClusterTracksCompressedDataType =
+  (AliHLTComponentDataType) { sizeof(AliHLTComponentDataType),                        {'C','L','S','T','R','K','C','M'},  kAliHLTDataOriginAny} | kAliHLTDataOriginTPC;
+const AliHLTComponentDataType AliHLTTPCDefinitions::fgkRemainingClustersCompressedDataType =
+  (AliHLTComponentDataType) { sizeof(AliHLTComponentDataType),                        {'R','E','M','C','L','S','C','M'},  kAliHLTDataOriginAny} | kAliHLTDataOriginTPC;
                                                                                                                                                              
 const AliHLTComponentDataType AliHLTTPCDefinitions::fgkCalibPedestalDataType =                                                                               
   (AliHLTComponentDataType){sizeof(AliHLTComponentDataType),                          {'C','A','L','_','P','E','D',' '},  kAliHLTDataOriginAny} | kAliHLTDataOriginTPC;
index 7366c51..63062c2 100644 (file)
@@ -76,6 +76,18 @@ public:
   static const AliHLTComponentDataType fgkTracksDataType;          // see above
   /** vertex data structure */
   static const AliHLTComponentDataType fgkVertexDataType;          // see above
+
+  // Cluster & Tracks model data
+  /** cluster tracks model data type */
+  static const AliHLTComponentDataType fgkClusterTracksModelDataType; // see above
+  /** remaining clusters model data type */
+  static const AliHLTComponentDataType fgkRemainingClustersModelDataType; // see above
+  /** cluster tracks compressed data type */
+  static const AliHLTComponentDataType fgkClusterTracksCompressedDataType; // see above
+  /** remaining clusters compressed data type */
+  static const AliHLTComponentDataType fgkRemainingClustersCompressedDataType; // see above
+
+  // Calibration data
   /** pedestal calibration data */
   static const AliHLTComponentDataType fgkCalibPedestalDataType;   // see above
   /** signal calibration data */
@@ -83,6 +95,7 @@ public:
   /** active pads data type, Used for cosmics test december 2007 */
   static const AliHLTComponentDataType fgkActivePadsDataType;     // see above
 
+
   ClassDef(AliHLTTPCDefinitions, 1);
 
 };
diff --git a/HLT/TPCLib/comp/AliHLTTPCCompDataCompressorHelper.cxx b/HLT/TPCLib/comp/AliHLTTPCCompDataCompressorHelper.cxx
new file mode 100644 (file)
index 0000000..e697bbb
--- /dev/null
@@ -0,0 +1,197 @@
+// @(#) $Id: AliHLTTPCCompDataCompressorHelper.cxx,v 1.1 2006/11/30 17:45:41 hristov Exp $
+
+/**************************************************************************
+ * TPCCompModelAnalysisright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Authors: Anders Vestbo <mailto:vestbo@fi.uib.no>                       *
+ *          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.                  *
+ **************************************************************************/
+
+/** @file   AliHLTTPCCompDataCompressorHelper.cxx
+    @author Anders Vestbo
+    @date   30-11-2006
+    @brief  The Data Compressor helper for the Vestbo-compression for the TPC
+*/
+
+#include "AliHLTStdIncludes.h"
+
+#include "AliHLTTPCTransform.h"
+
+#include "AliHLTTPCCompDataCompressorHelper.h"
+
+#if __GNUC__ >= 3
+using namespace std;
+#endif
+
+//_____________________________________________________________
+//
+//  AliHLTTPCCompDataCompression
+//
+// Interface class; binary <-> AliROOT handling of TPC data compression classes.
+//
+
+
+ClassImp(AliHLTTPCCompDataCompressorHelper)
+
+// see header file for more documentation
+// used variables for compression
+Int_t AliHLTTPCCompDataCompressorHelper::fgNumTimeBits = 12;
+Int_t AliHLTTPCCompDataCompressorHelper::fgNumPadBits = 12;
+Int_t AliHLTTPCCompDataCompressorHelper::fgNumChargeBits = 14;
+Int_t AliHLTTPCCompDataCompressorHelper::fgNumShapeBits = 14;
+Float_t AliHLTTPCCompDataCompressorHelper::fgXYResidualStep1 = 0.03;
+Float_t AliHLTTPCCompDataCompressorHelper::fgXYResidualStep2 = 0.03;
+Float_t AliHLTTPCCompDataCompressorHelper::fgXYResidualStep3 = 0.03;
+Float_t AliHLTTPCCompDataCompressorHelper::fgZResidualStep1 = 0.05;
+Float_t AliHLTTPCCompDataCompressorHelper::fgZResidualStep2 = 0.05;
+Float_t AliHLTTPCCompDataCompressorHelper::fgZResidualStep3 = 0.05;
+Float_t AliHLTTPCCompDataCompressorHelper::fgXYWidthStep = 0.005;
+Float_t AliHLTTPCCompDataCompressorHelper::fgZWidthStep = 0.005;
+Int_t AliHLTTPCCompDataCompressorHelper::fgClusterCharge = 100;
+Int_t AliHLTTPCCompDataCompressorHelper::fgNumPadBitsRemaining = 18;
+Int_t AliHLTTPCCompDataCompressorHelper::fgNumTimeBitsRemaining = 19;
+Int_t AliHLTTPCCompDataCompressorHelper::fgNumShapeBitsRemaining = 11;
+
+void AliHLTTPCCompDataCompressorHelper::SetBitNumbers(Int_t pad,Int_t time,Int_t charge,Int_t shape)
+{
+  // see header file for class documentation
+  // sets the numbers of bits
+  fgNumPadBits = pad;
+  fgNumTimeBits = time;
+  fgNumChargeBits = charge;
+  fgNumShapeBits = shape;
+}
+
+void AliHLTTPCCompDataCompressorHelper::SetTransverseResolutions(Float_t res1,Float_t res2,Float_t res3,Float_t width)
+{
+  // see header file for class documentation
+  // sets the transverse resolution
+  fgXYResidualStep1 = res1;
+  fgXYResidualStep2 = res2;
+  fgXYResidualStep3 = res3;
+  fgXYWidthStep = width;
+}
+
+void AliHLTTPCCompDataCompressorHelper::SetLongitudinalResolutions(Float_t res1,Float_t res2,Float_t res3,Float_t width)
+{
+  // see header file for class documentation
+  // sets the longitudinal resolution
+  fgZResidualStep1 = res1;
+  fgZResidualStep2 = res2;
+  fgZResidualStep3 = res3;
+  fgZWidthStep = width;
+}
+
+void AliHLTTPCCompDataCompressorHelper::SetRemainingBitNumbers(Int_t pad,Int_t time,Int_t shape)
+{
+  // see header file for class documentation
+  // sets the numbers of remaining bits
+  fgNumPadBitsRemaining = pad;
+  fgNumTimeBitsRemaining = time;
+  fgNumShapeBitsRemaining = shape;
+}
+
+Float_t AliHLTTPCCompDataCompressorHelper::GetXYResidualStep(Int_t row) 
+{
+  // see header file for class documentation
+  // gets the XY residual step
+  if(row < AliHLTTPCTransform::GetNRowLow())
+    return fgXYResidualStep1;
+  else if(row < AliHLTTPCTransform::GetNRowLow() + AliHLTTPCTransform::GetNRowUp1())
+    return fgXYResidualStep2;
+  else if(row < AliHLTTPCTransform::GetNRowLow() + AliHLTTPCTransform::GetNRowUp1() + AliHLTTPCTransform::GetNRowUp2())
+    return fgXYResidualStep3;
+  else
+    {
+      cerr<<"AliHLTTPCCompDataCompressorHelper::GetXYResidualStep : Wrong row number "<<row<<endl;
+      return -1;
+    }
+}
+
+Float_t AliHLTTPCCompDataCompressorHelper::GetZResidualStep(Int_t row) 
+{
+  // see header file for class documentation 
+  // gets the Z residual step
+  if(row < AliHLTTPCTransform::GetNRowLow())
+    return fgZResidualStep1;
+  else if(row < AliHLTTPCTransform::GetNRowLow() + AliHLTTPCTransform::GetNRowUp1())
+    return fgZResidualStep2;
+  else if(row < AliHLTTPCTransform::GetNRowLow() + AliHLTTPCTransform::GetNRowUp1() + AliHLTTPCTransform::GetNRowUp2())
+    return fgZResidualStep3;
+  else
+    {
+      cerr<<"AliHLTTPCCompDataCompressorHelper::GetXYResidualStep : Wrong row number "<<row<<endl;
+      return -1;
+    }
+}
+
+Float_t AliHLTTPCCompDataCompressorHelper::GetPadPrecisionFactor()
+{
+  // see header file for class documentation
+  // gets pad precision factor
+  Int_t nbits = fgNumPadBitsRemaining;
+  if(nbits >=21)
+    return 10000;
+  if(nbits >= 18)
+    return 1000;
+  if(nbits >= 14) 
+    return 100;
+  if(nbits >= 11)
+    return 10;
+  if(nbits >= 8)
+    return 1;
+  else 
+    {
+      cerr<<"AliHLTTPCCompDataCompressorHelper::GetRemainingPadFactor : Too few bits for the pad direction: "<<nbits<<endl;
+      return 1;
+    }
+}
+
+Float_t AliHLTTPCCompDataCompressorHelper::GetTimePrecisionFactor()
+{
+  // see header file for class documentation
+  // gest time precision factor
+  Int_t nbits = fgNumTimeBitsRemaining;
+  if(nbits >=23)
+    return 10000;
+  if(nbits >= 19)
+    return 1000;
+  if(nbits >= 16) 
+    return 100;
+  if(nbits >= 13)
+    return 10;
+  if(nbits >= 9)
+    return 1;
+  else 
+    {
+      cerr<<"AliHLTTPCCompDataCompressorHelper::GetRemainingPadFactor : Too few bits for the pad direction: "<<nbits<<endl;
+      return 1;
+    }
+}
+
+
+Int_t AliHLTTPCCompDataCompressorHelper::Nint(Double_t x)
+{
+  // see header file for class documentation 
+  // Round to nearest integer. Rounds half integers 
+  // to the nearest even integer.
+  
+   Int_t i=0;
+   if (x >= 0) {
+      i = Int_t(x + 0.5);
+      if (x + 0.5 == Double_t(i) && i & 1) i--;
+   } else {
+      i = Int_t(x - 0.5);
+      if (x - 0.5 == Double_t(i) && i & 1) i++;
+
+   }
+   return i;
+}
diff --git a/HLT/TPCLib/comp/AliHLTTPCCompDataCompressorHelper.h b/HLT/TPCLib/comp/AliHLTTPCCompDataCompressorHelper.h
new file mode 100644 (file)
index 0000000..797f6b1
--- /dev/null
@@ -0,0 +1,208 @@
+// @(#) $Id: AliHLTTPCCompDataCompressorHelper.h,v 1.1 2006/11/30 17:45:41 hristov Exp $
+
+/**************************************************************************
+ * TPCCompModelAnalysisright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Authors: Anders Vestbo <mailto:vestbo@fi.uib.no>                       *
+ *          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.                  *
+ **************************************************************************/
+
+/** @file   AliHLTTPCCompDataCompressorHelper.h
+    @author Anders Vestbo
+    @date   30-11-2006
+    @brief  The Data Compressor helper for the Vestbo-compression for the TPC
+*/
+
+#ifndef AliHLTTPCComp_DataCompressorHelper
+#define AliHLTTPCComp_DataCompressorHelper
+
+#include "AliHLTTPCRootTypes.h"
+
+/** @class   AliHLTTPCCompDataCompressorHelper
+    @author Anders Vestbo
+    @date   30-11-2006
+    @brief  Class to implement compression functions that will be used in Vestbo-compression  
+*/
+class AliHLTTPCCompDataCompressorHelper {
+  
+ public:
+
+  /** function to set numbers of bits for compression model 
+   * @param pad    integer to define pad
+   * @param time   integer to define time bin
+   * @param charge integer to define total charge of the cluster
+   * @param shape  integer to define shape of the cluster
+   */
+  static void SetBitNumbers(Int_t pad,Int_t time,Int_t charge,Int_t shape);
+
+  /** function to define transverse resolutions
+   * @param res1  float to define first resolution
+   * @param res2  float to define second resolution
+   * @param res3  float to define third resolution
+   * @param width float to define width (set to 0.005 if nothing is specified)
+   */
+  static void SetTransverseResolutions(Float_t res1,Float_t res2,Float_t res3,Float_t width=0.005);
+
+  /** function to define longitudinal resolutions
+   * @param res1  float to define first resolution
+   * @param res2  float to define second resolution
+   * @param res3  float to define third resolution
+   * @param width float to define width (set to 0.005 if nothing is specified)
+   */
+  static void SetLongitudinalResolutions(Float_t res1,Float_t res2,Float_t res3,Float_t width=0.005);
+
+  /** function to set number of bits for remaining clusters
+   * @param pad   integer to define pad
+   * @param time  integer to define time bin
+   * @param shape integer to define shape of the cluster
+   */ 
+  static void SetRemainingBitNumbers(Int_t pad,Int_t time,Int_t shape);
+
+  /** function to get number of pad bits
+   * @return fgNumPadBits integer for number of pad bits
+   */
+  static Int_t GetNPadBits() {return fgNumPadBits;}
+
+  /** function to get number of time bits
+   * @return fgNumTimeBits integer for number of time bin bits
+   */
+  static Int_t GetNTimeBits() {return fgNumTimeBits;}
+
+  /** function to get number of charge bits (total charge)
+   * @return fgNumChargeBits integer for number of charge bits
+   */
+  static Int_t GetNChargeBits() {return fgNumChargeBits;}
+
+  /** function to get number of shape bits
+   * @return fgNumShapeBits integer for number of shape bits
+   */
+  static Int_t GetNShapeBits() {return fgNumShapeBits;}
+
+  /** function to get detector xy width step
+   * @return fgXYWidthStep float for the x-y-width-step
+   */
+  static Float_t GetXYWidthStep() {return fgXYWidthStep;}
+
+  /** function to get detector z width step
+   * @return fgZWidthStep float for the z-width-step
+   */
+  static Float_t GetZWidthStep() {return fgZWidthStep;}
+
+  /** function to get the total charge of the cluster
+   * @return fgClusterCharge integer for the total charge of the cluster
+   */
+  static Int_t GetClusterCharge() {return fgClusterCharge;}
+
+  /** function to get detector xy residual step
+   * @param row integer to define the pad row 
+   * @return fgXYResidualStepX float for the x-y-residual-step (X stands for 1 to 3, depending on the step)
+   */
+  static Float_t GetXYResidualStep(Int_t row);
+
+  /** function to get detector z residual step
+   * @param row integer to define the pad row 
+   * @return fgZResidualStepX float for the z-residual-step (X stands for 1 to 3, depending on the step)
+   */
+  static Float_t GetZResidualStep(Int_t row);
+
+  /** function to get the number of bits for pads from remaining clusters
+   * @return fgNumPadBitsRemaining integer for the number of bits for pads from remaining clusters
+   */
+  static Int_t GetNPadBitsRemaining() {return fgNumPadBitsRemaining;}
+
+  /** function to get the number of bits for time bins from remaining clusters
+   * @return fgNumTimeBitsRemaining integer for the number of bits for time bins from remaining clusters
+   */
+  static Int_t GetNTimeBitsRemaining() {return fgNumTimeBitsRemaining;}
+
+  /** function to get the number of bits for shapes of remaining clusters
+   * @return fgNumShapeBitsRemaining integer for the number of bits for shapes of remaining clusters
+   */
+  static Int_t GetNShapeBitsRemaining() {return fgNumShapeBitsRemaining;}
+
+  /** function to get pad precision factor
+   * @return float that defines the number of bits (-> precision)
+   */
+  static Float_t GetPadPrecisionFactor();
+
+  /** function to get time precision factor
+   * @return float that defines the number of bits (-> precision)
+   */
+  static Float_t GetTimePrecisionFactor();
+
+  //taken from TMath:
+
+  /** function to convert double to int
+   * @param x double value to be converted
+   * @return integer created from double value
+   */
+  static Int_t Nint(Double_t x); 
+
+  /** function to calculate the absolute of an integer
+   * @param d integer to be taken absolute value from
+   * @return positive integer
+   */
+  static Int_t Abs(Int_t d) { return (d > 0) ? d : -d; }
+
+  /** function to calculate the absolute of a double
+   * @param d double to be taken absolute value from
+   * @return positive double
+   */
+  static Double_t Abs(Double_t d) { return (d > 0) ? d : -d; }
+
+ private:
+
+  /** standard constructor */
+  AliHLTTPCCompDataCompressorHelper() {};
+
+  /** standard destructor */
+  virtual ~AliHLTTPCCompDataCompressorHelper() {};
+
+  /** number of pad bits */
+  static Int_t fgNumPadBits; // Number of pad bits
+  /** number of time bits */
+  static Int_t fgNumTimeBits; // Number of time bits
+  /** number of charge bits */
+  static Int_t fgNumChargeBits; // Number of charge bits
+  /** number of shape bits */
+  static Int_t fgNumShapeBits; // Number of shape bits
+  /** number of remaining pad bits */
+  static Int_t fgNumPadBitsRemaining; // Number of remaining pad bits
+  /** number of remaining time bits */
+  static Int_t fgNumTimeBitsRemaining; // Number of remaining time bits
+  /** number of remaining shape bits */
+  static Int_t fgNumShapeBitsRemaining; // Number of remaining shape bits
+
+  /** xy residual at step 1 */
+  static Float_t fgXYResidualStep1; // XY residual at step 1
+  /** xy residual at step 2 */
+  static Float_t fgXYResidualStep2; // XY residual at step 2
+  /** xy residual at step 3 */
+  static Float_t fgXYResidualStep3; // XY residual at step 3
+  /** z residual at step 1 */
+  static Float_t fgZResidualStep1; // Z residual at step 1
+  /** z residual at step 2 */
+  static Float_t fgZResidualStep2; // Z residual at step 2
+  /** z residual at step 3 */
+  static Float_t fgZResidualStep3; // Z residual at step 3
+  /** width of xy step */
+  static Float_t fgXYWidthStep; // Width of XY step
+  /** width of z step */
+  static Float_t fgZWidthStep;  // Width of Z step
+  /** cluster charge */
+  static Int_t fgClusterCharge; // Cluster charge
+
+
+  ClassDef(AliHLTTPCCompDataCompressorHelper,1) 
+
+};
+
+#endif
diff --git a/HLT/TPCLib/comp/AliHLTTPCCompDumpComponent.cxx b/HLT/TPCLib/comp/AliHLTTPCCompDumpComponent.cxx
new file mode 100644 (file)
index 0000000..137cca2
--- /dev/null
@@ -0,0 +1,651 @@
+// $Id: AliHLTTPCCompDumpComponent.cxx,v 1.2 2006/08/10 09:46:51 richterm Exp $
+
+/**************************************************************************
+ * TPCCompDumpright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Authors: 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.                  *
+ **************************************************************************/
+
+/** @file   AliHLTTPCCompDumpComponent.cxx
+    @author Timm Steinbeck
+    @date   10-08-2006
+    @brief  A copy processing component for the HLT. */
+
+#if __GNUC__ >= 3
+using namespace std;
+#endif
+
+#include "AliHLTTPCCompDumpComponent.h"
+#include "AliHLTTPCDefinitions.h"
+#include "AliHLTTPCTrackletDataFormat.h"
+#include "AliHLTTPCClusterDataFormat.h"
+#include "AliHLTTPCModels.h"
+#include "AliHLTTPCTransform.h"
+#include "AliHLTTPCCompDataCompressorHelper.h"
+#include <stdlib.h>
+#include <errno.h>
+
+// this is a global object used for automatic component registration, do not use this
+AliHLTTPCCompDumpComponent gAliHLTTPCCompClusterDumpComponent;
+
+ClassImp(AliHLTTPCCompDumpComponent)
+    
+AliHLTTPCCompDumpComponent::AliHLTTPCCompDumpComponent()
+  :
+  fBitDataCurrentWord(0),
+  fBitDataCurrentPosInWord(0),
+  fBitDataCurrentInput(NULL),
+  fBitDataCurrentInputStart(NULL),
+  fBitDataCurrentInputEnd(NULL)
+    {
+      // see header file for class documentation
+    }
+
+AliHLTTPCCompDumpComponent::~AliHLTTPCCompDumpComponent()
+    {
+      // see header file for class documentation
+    }
+
+const char* AliHLTTPCCompDumpComponent::GetComponentID()
+    {
+      // see header file for class documentation
+    return "TPCCompDump"; // The ID of this component
+    }
+
+void AliHLTTPCCompDumpComponent::GetInputDataTypes( vector<AliHLTComponent_DataType>& list)
+    {
+      // see header file for class documentation
+      list.clear(); // We do not have any requirements for our input data type(s).
+      list.push_back( AliHLTTPCDefinitions::fgkClustersDataType );
+      list.push_back( AliHLTTPCDefinitions::fgkTrackSegmentsDataType );
+      list.push_back( AliHLTTPCDefinitions::fgkTracksDataType );
+      list.push_back( AliHLTTPCDefinitions::fgkClusterTracksModelDataType );
+      list.push_back( AliHLTTPCDefinitions::fgkRemainingClustersModelDataType );
+    }
+
+AliHLTComponent_DataType AliHLTTPCCompDumpComponent::GetOutputDataType()
+    {
+      // see header file for class documentation
+      return AliHLTTPCDefinitions::fgkClusterTracksModelDataType;
+    }
+
+void AliHLTTPCCompDumpComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
+    {
+      // see header file for class documentation
+      constBase = 0;
+      inputMultiplier = 1.;
+      //#warning Adapt input Multiplier to something more realistic
+    }
+
+
+// Spawn function, return new instance of this class
+AliHLTComponent* AliHLTTPCCompDumpComponent::Spawn()
+    {
+      // see header file for class documentation
+      return new AliHLTTPCCompDumpComponent;
+    };
+
+int AliHLTTPCCompDumpComponent::DoInit( int argc, const char** argv )
+    {
+      // see header file for class documentation
+      //char* cpErr;
+      if ( argc )
+       {
+         Logging( kHLTLogDebug, "HLT::TPCCompDump::DoInit", "Arguments", "argv[0] == %s", argv[0] );
+         Logging(kHLTLogError, "HLT::TPCCompDump::DoInit", "Unknown Option", "Unknown option '%s'", argv[0] );
+         return EINVAL;
+       }
+      return 0;
+    }
+
+int AliHLTTPCCompDumpComponent::DoDeinit()
+    {
+      // see header file for class documentation
+      return 0;
+    }
+
+int AliHLTTPCCompDumpComponent::DoEvent( const AliHLTComponent_EventData& evtData, const AliHLTComponent_BlockData* blocks, 
+                                                  AliHLTComponent_TriggerData& /*trigData*/, AliHLTUInt8_t* , 
+                                     AliHLTUInt32_t& size, vector<AliHLTComponent_BlockData>&  )
+    {
+      // see header file for class documentation
+      // Process an event
+      // Loop over all input blocks in the event
+      for ( unsigned long n = 0; n < evtData.fBlockCnt; n++ )
+       {
+         AliHLTUInt8_t slice, patch;
+         if ( blocks[n].fDataType == AliHLTTPCDefinitions::fgkClustersDataType )
+           {
+             slice = AliHLTTPCDefinitions::GetMinSliceNr( blocks[n].fSpecification );
+             patch = AliHLTTPCDefinitions::GetMinPatchNr( blocks[n].fSpecification );
+             AliHLTTPCClusterData* clusters = (AliHLTTPCClusterData*)blocks[n].fPtr;
+             HLTInfo( "Cluster block slice %u - patch %u - %lu clusters", (unsigned)slice, (unsigned)patch, (unsigned long)clusters->fSpacePointCnt );
+             for ( unsigned long ii=0; ii<clusters->fSpacePointCnt; ii++ )
+               {
+                 HLTInfo( "  Cluster % 5lu: fX: %f - fY: %f - fZ: %f - fZ - fID: %u (0x%08X) - fPadRow: %u - fSigmaY2: %f - fSigmaZ2: %f - fCharge: %u - fUsed: %s - fTrackN: %d", 
+                          ii, clusters->fSpacePoints[ii].fX, clusters->fSpacePoints[ii].fY, clusters->fSpacePoints[ii].fZ, clusters->fSpacePoints[ii].fID, clusters->fSpacePoints[ii].fID, (unsigned)clusters->fSpacePoints[ii].fPadRow, clusters->fSpacePoints[ii].fSigmaY2, clusters->fSpacePoints[ii].fSigmaZ2, clusters->fSpacePoints[ii].fCharge, (clusters->fSpacePoints[ii].fUsed ? "yes" : "no"), clusters->fSpacePoints[ii].fTrackN );
+#if 0
+                 Float_t xyzG[3] = { clusters->fSpacePoints[ii].fX, clusters->fSpacePoints[ii].fY, clusters->fSpacePoints[ii].fZ };
+                 Float_t xyzR[3] = { clusters->fSpacePoints[ii].fX, clusters->fSpacePoints[ii].fY, clusters->fSpacePoints[ii].fZ };
+                 AliHLTTPCTransform::LocHLT2Global( xyzG, slice, clusters->fSpacePoints[ii].fPadRow );
+                 AliHLTTPCTransform::LocHLT2Raw( xyzG, slice, clusters->fSpacePoints[ii].fPadRow );
+                 HLTInfo( "         Global: fX: %f - fY: %f - fZ: %f - fZ", 
+                          xyzG[0], xyzG[1], xyzG[2] );
+                 HLTInfo( "            Raw: fX: %f - fY: %f - fZ: %f - fZ", 
+                          xyzR[0], xyzR[1], xyzR[2] );
+#endif
+               }
+             HLTInfo( "" );
+           }
+         if ( blocks[n].fDataType == AliHLTTPCDefinitions::fgkTrackSegmentsDataType ||
+              blocks[n].fDataType == AliHLTTPCDefinitions::fgkTracksDataType)
+           {
+             //fConverter.SetInputTracks( (AliHLTTPCTrackletData*)blocks[n].fPtr );
+             AliHLTUInt8_t minSlice=0xFF, maxSlice=0xFF, minPatch=0xFF, maxPatch=0xFF;
+             minSlice = AliHLTTPCDefinitions::GetMinSliceNr( blocks[n].fSpecification );
+             maxSlice = AliHLTTPCDefinitions::GetMaxSliceNr( blocks[n].fSpecification );
+             minPatch = AliHLTTPCDefinitions::GetMinPatchNr( blocks[n].fSpecification );
+             maxPatch = AliHLTTPCDefinitions::GetMaxPatchNr( blocks[n].fSpecification );
+             AliHLTTPCTrackletData* tracks = (AliHLTTPCTrackletData*)blocks[n].fPtr;
+             AliHLTTPCTrackSegmentData* tracklet = tracks->fTracklets;
+             HLTInfo( "Track block slices %u-%u - patches %u-%u - %lu tracks", 
+                      (unsigned)minSlice, (unsigned)maxSlice, (unsigned)minPatch, (unsigned)maxPatch,
+                      (unsigned long)tracks->fTrackletCnt );
+             for ( unsigned long ii=0; ii<tracks->fTrackletCnt; ii++ )
+               {
+                 HLTInfo( "  Track % 5lu: fX: %f - fY: %f - fZ: %f - fLastX: %f - fLastY: %f - fLastZ: %f - fPt: %f - fPsi: %f - fTgl: %f - fPterr: %f - fPsierr: %f - fTglerr: %f - fCharge: %d - fNPoints: %u", 
+                          ii, tracklet->fX, tracklet->fY, tracklet->fZ, tracklet->fLastX, tracklet->fLastY, tracklet->fLastZ, tracklet->fPt, tracklet->fPsi, tracklet->fTgl, tracklet->fPterr, tracklet->fPsierr, tracklet->fTglerr, tracklet->fCharge, tracklet->fNPoints );
+                 for ( unsigned long jj=0; jj<tracklet->fNPoints; jj++ )
+                   {
+                     HLTInfo( "    Point % 5lu: %   8u / 0x%08X", jj, tracklet->fPointIDs[jj], tracklet->fPointIDs[jj] );
+                   }
+                 tracklet = (AliHLTTPCTrackSegmentData*) ( ((AliHLTUInt8_t*)tracklet)+sizeof(AliHLTTPCTrackSegmentData)+tracklet->fNPoints*sizeof(UInt_t) );
+               }
+             
+           }
+         if ( blocks[n].fDataType == AliHLTTPCDefinitions::fgkClusterTracksModelDataType )
+           {
+             AliHLTUInt8_t minSlice=0xFF, maxSlice=0xFF, minPatch=0xFF, maxPatch=0xFF;
+             minSlice = AliHLTTPCDefinitions::GetMinSliceNr( blocks[n].fSpecification );
+             maxSlice = AliHLTTPCDefinitions::GetMaxSliceNr( blocks[n].fSpecification );
+             minPatch = AliHLTTPCDefinitions::GetMinPatchNr( blocks[n].fSpecification );
+             maxPatch = AliHLTTPCDefinitions::GetMaxPatchNr( blocks[n].fSpecification );
+             unsigned long trackletCount = (blocks[n].fSize-sizeof(AliHLTUInt32_t)) / (sizeof(AliHLTTPCTrackModel)+AliHLTTPCTransform::GetNRows()*sizeof(AliHLTTPCClusterModel) );
+             HLTInfo( "Track model block version %u slices %u-%u - patches %u-%u - %lu tracks", 
+                      (unsigned)*(AliHLTUInt32_t*)blocks[n].fPtr,
+                      (unsigned)minSlice, (unsigned)maxSlice, (unsigned)minPatch, (unsigned)maxPatch,
+                      (unsigned long)trackletCount );
+             AliHLTTPCTrackModel* trackModel = (AliHLTTPCTrackModel*)(((AliHLTUInt8_t*)blocks[n].fPtr)+sizeof(AliHLTUInt32_t));
+             for ( unsigned long ii=0; ii<trackletCount; ii++ )
+               {
+                 unsigned clusterCount=0;
+                 AliHLTTPCClusterModel* clusters = (AliHLTTPCClusterModel*) ( ((AliHLTUInt8_t*)trackModel)+sizeof(AliHLTTPCTrackModel) );
+                 for ( unsigned long jj=0; jj<(unsigned long)AliHLTTPCTransform::GetNRows(); jj++ )
+                   {
+                     if ( clusters[jj].fPresent )
+                       clusterCount++;
+                   }
+                 HLTInfo( "  Track Model % 5lu fKappa: %f - fPhi: %f - fD: %f - fZ0: %f - fTgl: %f - #clusters: %u",
+                         ii, trackModel->fKappa, trackModel->fPhi, trackModel->fD, trackModel->fZ0, trackModel->fTgl, clusterCount );
+                 clusterCount=0;
+                 for ( unsigned long jj=0; jj<(unsigned long)AliHLTTPCTransform::GetNRows(); jj++ )
+                   {
+                     if ( clusters[jj].fPresent )
+                       {
+#ifdef MODELDEBUG
+                         HLTInfo( "    Cluster % 05u: fID: %u (0x%08X) - fDTime: %f - fDPad: %f - fDCharge: %f - fDSigmaY: %f - fDSigmaZ: %f - fNPads: %u - fSlice: %hd - padrow: %lu - fPresent: %u",
+                                  clusterCount, clusters[jj].fID, clusters[jj].fID, clusters[jj].fDTime, clusters[jj].fDPad, clusters[jj].fDCharge, clusters[jj].fDSigmaY, clusters[jj].fDSigmaZ, clusters[jj].fNPads, clusters[jj].fSlice, jj, (unsigned)clusters[jj].fPresent );
+#else
+                         HLTInfo( "    Cluster % 05u: fDTime: %f - fDPad: %f - fDCharge: %f - fDSigmaY: %f - fDSigmaZ: %f - fNPads: %u - fSlice: %hd - padrow: %lu - fPresent: %u",
+                                  clusterCount, clusters[jj].fDTime, clusters[jj].fDPad, clusters[jj].fDCharge, clusters[jj].fDSigmaY, clusters[jj].fDSigmaZ, clusters[jj].fNPads, clusters[jj].fSlice, jj, (unsigned)clusters[jj].fPresent );
+#endif
+                         clusterCount++;
+                       }
+                   }
+                 
+                 trackModel = (AliHLTTPCTrackModel*) ( ((AliHLTUInt8_t*)trackModel)+sizeof(AliHLTTPCTrackModel)+AliHLTTPCTransform::GetNRows()*sizeof(AliHLTTPCClusterModel) );
+               }
+             
+           }
+         if ( blocks[n].fDataType == AliHLTTPCDefinitions::fgkRemainingClustersModelDataType )
+           {
+             AliHLTUInt8_t minSlice=0xFF, maxSlice=0xFF, minPatch=0xFF, maxPatch=0xFF;
+             minSlice = AliHLTTPCDefinitions::GetMinSliceNr( blocks[n].fSpecification );
+             maxSlice = AliHLTTPCDefinitions::GetMaxSliceNr( blocks[n].fSpecification );
+             minPatch = AliHLTTPCDefinitions::GetMinPatchNr( blocks[n].fSpecification );
+             maxPatch = AliHLTTPCDefinitions::GetMaxPatchNr( blocks[n].fSpecification );
+             unsigned long clusterCount=0;
+             HLTInfo( "Remaining cluster model block version %u", 
+                      (unsigned)*(AliHLTUInt32_t*)blocks[n].fPtr );
+             AliHLTUInt8_t* readPtr = (AliHLTUInt8_t*)(((AliHLTUInt8_t*)blocks[n].fPtr)+sizeof(AliHLTUInt32_t));
+             for(Int_t slice=0; slice<36; slice++)
+               {
+                 for(Int_t patch=0; patch < 6; patch++)
+                   {
+                     if ( !readPtr )
+                       {
+                         readPtr++;
+                         continue;
+                       }
+                     unsigned rows = (unsigned)*readPtr;
+                     readPtr++;
+                     for ( unsigned ii=0; ii<rows; ii++ )
+                       {
+                         AliHLTTPCRemainingRow* thisRow = (AliHLTTPCRemainingRow*)readPtr;
+                         clusterCount += thisRow->fNClusters;
+                         readPtr += sizeof(AliHLTTPCRemainingRow) + thisRow->fNClusters*sizeof(AliHLTTPCRemainingCluster);
+                       }
+                   }
+               }
+             HLTInfo( "Remaining cluster model block slices %u-%u - patches %u-%u - %lu clusters", 
+                      (unsigned)minSlice, (unsigned)maxSlice, (unsigned)minPatch, (unsigned)maxPatch,
+                      clusterCount );
+             readPtr = (AliHLTUInt8_t*)(((AliHLTUInt8_t*)blocks[n].fPtr)+sizeof(AliHLTUInt32_t));
+             clusterCount = 0;
+             for(Int_t slice=0; slice<36; slice++)
+               {
+                 for(Int_t patch=0; patch < 6; patch++)
+                   {
+                     if ( !readPtr )
+                       {
+                         readPtr++;
+                         continue;
+                       }
+                     unsigned rows = (unsigned)*readPtr;
+                     readPtr++;
+                     if ( rows )
+                       HLTInfo( "  Slice %d - Partition %d", slice, patch );
+                     for ( unsigned ii=0; ii<rows; ii++ )
+                       {
+                         AliHLTTPCRemainingRow* thisRow = (AliHLTTPCRemainingRow*)readPtr;
+                         for ( unsigned jj=0; jj<thisRow->fNClusters; jj++ )
+                           {
+#ifdef MODELDEBUG
+                             HLTInfo( "    Cluster % 5lu: fID: %u (0x%08X) - fPadRow: %u - fPad: %f - fTime: %f - fSigmaY2: %f - fSigmaZ2: %f - fCharge: %hu",
+                                      clusterCount, thisRow->fClusters[jj].fID, thisRow->fClusters[jj].fID, (unsigned)thisRow->fPadRow, thisRow->fClusters[jj].fPad, thisRow->fClusters[jj].fTime, thisRow->fClusters[jj].fSigmaY2, thisRow->fClusters[jj].fSigmaZ2, thisRow->fClusters[jj].fCharge );
+#else
+                             HLTInfo( "    Cluster % 5lu: fPadRow: %u - fPad: %f - fTime: %f - fSigmaY2: %f - fSigmaZ2: %f - fCharge: %hu",
+                                      clusterCount, (unsigned)thisRow->fPadRow, thisRow->fClusters[jj].fPad, thisRow->fClusters[jj].fTime, thisRow->fClusters[jj].fSigmaY2, thisRow->fClusters[jj].fSigmaZ2, thisRow->fClusters[jj].fCharge );
+#endif
+                           }
+                         readPtr += sizeof(AliHLTTPCRemainingRow) + thisRow->fNClusters*sizeof(AliHLTTPCRemainingCluster);
+                       }
+                   }
+               }
+           }
+         if ( blocks[n].fDataType == AliHLTTPCDefinitions::fgkClusterTracksCompressedDataType )
+           {
+             AliHLTUInt8_t minSlice=0xFF, maxSlice=0xFF, minPatch=0xFF, maxPatch=0xFF;
+             minSlice = AliHLTTPCDefinitions::GetMinSliceNr( blocks[n].fSpecification );
+             maxSlice = AliHLTTPCDefinitions::GetMaxSliceNr( blocks[n].fSpecification );
+             minPatch = AliHLTTPCDefinitions::GetMinPatchNr( blocks[n].fSpecification );
+             maxPatch = AliHLTTPCDefinitions::GetMaxPatchNr( blocks[n].fSpecification );
+             HLTInfo( "Track model block slices %u-%u - patches %u-%u", 
+                     (unsigned)minSlice, (unsigned)maxSlice, (unsigned)minPatch, (unsigned)maxPatch );
+             InitBitDataInput( (AliHLTUInt8_t*)blocks[n].fPtr, blocks[n].fSize );
+             HLTInfo( "Input position: %lu / %u (0x%02X)", GetCurrentByteInputPosition(), GetCurrentBitInputPosition(), (unsigned)GetCurrentInputByte() );
+             AliHLTUInt8_t version;
+             if ( !InputBits( version, 4 ) ) // Version information
+               {
+                 HLTError( "Corrupt input data. Cannot read data version number at position %lu / %u",
+                           GetCurrentByteInputPosition(), GetCurrentBitInputPosition() );
+                 continue;
+               }
+             HLTInfo( "Data Format Version: %u", (unsigned)version );
+             HLTInfo( "Input position: %lu / %u (0x%02X)", GetCurrentByteInputPosition(), GetCurrentBitInputPosition(), (unsigned)GetCurrentInputByte() );
+             AliHLTUInt8_t readShape;
+             if ( !InputBit( readShape ) ) // Data format flag
+               {
+                 HLTError( "Corrupt input data. Cannot read shape flag at position %lu / %u",
+                         GetCurrentByteInputPosition(), GetCurrentBitInputPosition() );
+                 continue;
+               }
+             HLTInfo( "Read shape: %s (%u)", (readShape ? "yes" : "no"), (unsigned)readShape );
+             HLTInfo( "Input position: %lu / %u (0x%02X)", GetCurrentByteInputPosition(), GetCurrentBitInputPosition(), (unsigned)GetCurrentInputByte() );
+             Pad8Bits();
+             HLTInfo( "Input position: %lu / %u (0x%02X)", GetCurrentByteInputPosition(), GetCurrentBitInputPosition(), (unsigned)GetCurrentInputByte() );
+             
+             
+             
+             bool inputError=false;
+             unsigned trackCount=0;
+             
+             while ( !EndOfBitInput() )
+               {
+                 AliHLTTPCTrackModel trackModel;
+                 memset( &trackModel, 0, sizeof(trackModel) );
+                 if ( !InputBytes( (AliHLTUInt8_t*)&trackModel, sizeof(AliHLTTPCTrackModel) ) )
+                   {
+                     HLTError( "Corrupt input data. Cannot read track model data at position %lu / %u",
+                               GetCurrentByteInputPosition(), GetCurrentBitInputPosition() );
+                     inputError = true;
+                     break;
+                   }
+                 HLTInfo( "  Track Model % 5lu fKappa: %f - fPhi: %f - fD: %f - fZ0: %f - fTgl: %f",
+                          trackCount, trackModel.fKappa, trackModel.fPhi, trackModel.fD, trackModel.fZ0, trackModel.fTgl );
+                 HLTInfo( "Input position: %lu / %u (0x%02X)", GetCurrentByteInputPosition(), GetCurrentBitInputPosition(), (unsigned)GetCurrentInputByte() );
+                 
+                 Int_t clustercount=0;
+                 for(Int_t i=0; i<AliHLTTPCTransform::GetNRows(); i++)
+                   {
+                     AliHLTTPCClusterModel cluster;
+                     memset( &cluster, 0, sizeof(cluster) );
+                     AliHLTUInt8_t present;
+                     if ( !InputBit( present ) )
+                       {
+                         HLTError( "Corrupt input data. Cannot read  cluster presence bit at position %lu / %u",
+                                   GetCurrentByteInputPosition(), GetCurrentBitInputPosition() );
+                         inputError = true;
+                         break;
+                       }
+                     HLTInfo( "Cluster %u present: %s (%u)", (unsigned)i, (present ? "yes" : "no"), (unsigned)present );
+                     HLTInfo( "Input position: %lu / %u (0x%02X)", GetCurrentByteInputPosition(), GetCurrentBitInputPosition(), (unsigned)GetCurrentInputByte() );
+                     cluster.fPresent = present;
+                     if ( !present )
+                       continue;
+                     if ( clustercount==0 )
+                       {
+                         if ( !InputBits( slice,6 ) ) //Need 6 bits to encode slice number
+                           {
+                             HLTError( "Corrupt input data. Cannot read  cluster slice number at position %lu / %u",
+                                       GetCurrentByteInputPosition(), GetCurrentBitInputPosition() );
+                             inputError = true;
+                             break;
+                           }
+                         HLTInfo( "First cluster slice: %u", (unsigned)slice );
+                         HLTInfo( "Input position: %lu / %u (0x%02X)", GetCurrentByteInputPosition(), GetCurrentBitInputPosition(), (unsigned)GetCurrentInputByte() );
+                       }
+                     else
+                       {
+                       AliHLTUInt8_t sliceChange;
+                       if ( !InputBit( sliceChange ) )
+                           {
+                             HLTError( "Corrupt input data. Cannot read cluster slice change bit at position %lu / %u",
+                                     GetCurrentByteInputPosition(), GetCurrentBitInputPosition() );
+                             inputError = true;
+                           break;
+                           }
+                       HLTInfo( "Slice change: %s (%u)", (sliceChange ? "yes" : "no"), (unsigned)sliceChange );
+                       HLTInfo( "Input position: %lu / %u (0x%02X)", GetCurrentByteInputPosition(), GetCurrentBitInputPosition(), (unsigned)GetCurrentInputByte() );
+                       if ( sliceChange )
+                         {  //Change of slice
+                           if ( !InputBits( slice, 6 ) )
+                             {
+                               HLTError( "Corrupt input data. Cannot read  cluster slice number at position %lu / %u",
+                                         GetCurrentByteInputPosition(), GetCurrentBitInputPosition() );
+                               inputError = true;
+                               break;
+                               }
+                           HLTInfo( "Changed cluster slice: %u", (unsigned)slice );
+                           HLTInfo( "Input position: %lu / %u (0x%02X)", GetCurrentByteInputPosition(), GetCurrentBitInputPosition(), (unsigned)GetCurrentInputByte() );
+                         }
+                       }
+                   HLTInfo( "Slice. %d", slice );
+                   cluster.fSlice = slice;
+                   if ( cluster.fSlice<0 || cluster.fSlice>35 )
+                       {
+                         HLTError( "Inconsistent slice number %u (track %u, cluster %d)", cluster.fSlice, trackCount, i );
+                         inputError = true;
+                         break;
+                       }
+                   AliHLTUInt8_t signBit;
+                   Int_t sign;
+                   AliHLTUInt64_t temp;
+                   Int_t val;
+                   //Read time information:
+                   if ( !InputBit( signBit ) )
+                     {
+                       HLTError( "Corrupt input data. Cannot read DTime sign bit at position %lu / %u",
+                                 GetCurrentByteInputPosition(), GetCurrentBitInputPosition() );
+                       inputError = true;
+                       break;
+                     }
+                   HLTInfo( "Input position: %lu / %u (0x%02X)", GetCurrentByteInputPosition(), GetCurrentBitInputPosition(), (unsigned)GetCurrentInputByte() );
+                   sign = signBit;
+                   sign = -1+sign*2;
+                   if ( !InputBits( temp, AliHLTTPCCompDataCompressorHelper::GetNTimeBits()-1 ) )
+                     {
+                       HLTError( "Corrupt input data. Cannot read DTime data at position %lu / %u",
+                                 GetCurrentByteInputPosition(), GetCurrentBitInputPosition() );
+                       inputError = true;
+                       break;
+                     }
+                   HLTInfo( "Input position: %lu / %u (0x%02X)", GetCurrentByteInputPosition(), GetCurrentBitInputPosition(), (unsigned)GetCurrentInputByte() );
+                   val = (Int_t)temp;
+                   cluster.fDTime = val*sign;
+                   
+                   
+                   //Read pad information:
+                   if ( !InputBit( signBit ) )
+                     {
+                       HLTError( "Corrupt input data. Cannot read DPad sign bit at position %lu / %u",
+                                 GetCurrentByteInputPosition(), GetCurrentBitInputPosition() );
+                       inputError = true;
+                       break;
+                     }
+                   HLTInfo( "Input position: %lu / %u (0x%02X)", GetCurrentByteInputPosition(), GetCurrentBitInputPosition(), (unsigned)GetCurrentInputByte() );
+                   sign = signBit;
+                   sign = -1+sign*2;
+                   if ( !InputBits( temp, AliHLTTPCCompDataCompressorHelper::GetNPadBits()-1 ) )
+                     {
+                       HLTError( "Corrupt input data. Cannot read DPad data at position %lu / %u",
+                                 GetCurrentByteInputPosition(), GetCurrentBitInputPosition() );
+                       inputError = true;
+                       break;
+                     }
+                   HLTInfo( "Input position: %lu / %u (0x%02X)", GetCurrentByteInputPosition(), GetCurrentBitInputPosition(), (unsigned)GetCurrentInputByte() );
+                   val = (Int_t)temp;
+                   cluster.fDPad = val*sign;
+                   
+                   // Read charge information:
+                   if ( !InputBits( temp, AliHLTTPCCompDataCompressorHelper::GetNChargeBits() ) )
+                     {
+                       HLTError( "Corrupt input data. Cannot read charge data at position %lu / %u",
+                                 GetCurrentByteInputPosition(), GetCurrentBitInputPosition() );
+                       inputError = true;
+                       break;
+                     }
+                   HLTInfo( "Input position: %lu / %u (0x%02X)", GetCurrentByteInputPosition(), GetCurrentBitInputPosition(), (unsigned)GetCurrentInputByte() );
+                   cluster.fDCharge = temp;
+                   
+                   if ( readShape )
+                     {
+                       // Read shape information:
+                       if ( !InputBit( signBit ) )
+                         {
+                           HLTError( "Corrupt input data. Cannot read DSigmaY sign bit at position %lu / %u",
+                                     GetCurrentByteInputPosition(), GetCurrentBitInputPosition() );
+                           inputError = true;
+                           break;
+                         }
+                       HLTInfo( "Input position: %lu / %u (0x%02X)", GetCurrentByteInputPosition(), GetCurrentBitInputPosition(), (unsigned)GetCurrentInputByte() );
+                       sign = signBit;
+                       sign = -1+sign*2;
+                       if ( !InputBits( temp, AliHLTTPCCompDataCompressorHelper::GetNShapeBits()-1 ) )
+                         {
+                           HLTError( "Corrupt input data. Cannot read DSigmaY data at position %lu / %u",
+                                     GetCurrentByteInputPosition(), GetCurrentBitInputPosition() );
+                           inputError = true;
+                           break;
+                         }
+                       HLTInfo( "Input position: %lu / %u (0x%02X)", GetCurrentByteInputPosition(), GetCurrentBitInputPosition(), (unsigned)GetCurrentInputByte() );
+                       val = (Int_t)temp;
+                       cluster.fDSigmaY = val*sign;
+                       
+                       if ( !InputBit( signBit ) )
+                         {
+                           HLTError( "Corrupt input data. Cannot read DSigmaZ sign bit at position %lu / %u",
+                                     GetCurrentByteInputPosition(), GetCurrentBitInputPosition() );
+                           inputError = true;
+                           break;
+                         }
+                       HLTInfo( "Input position: %lu / %u (0x%02X)", GetCurrentByteInputPosition(), GetCurrentBitInputPosition(), (unsigned)GetCurrentInputByte() );
+                       sign = signBit;
+                       sign = -1+sign*2;
+                       if ( !InputBits( temp, AliHLTTPCCompDataCompressorHelper::GetNShapeBits()-1 ) )
+                         {
+                           HLTError( "Corrupt input data. Cannot read DSigmaZ data at position %lu / %u",
+                                     GetCurrentByteInputPosition(), GetCurrentBitInputPosition() );
+                           inputError = true;
+                           break;
+                         }
+                       HLTInfo( "Input position: %lu / %u (0x%02X)", GetCurrentByteInputPosition(), GetCurrentBitInputPosition(), (unsigned)GetCurrentInputByte() );
+                       val = (Int_t)temp;
+                       cluster.fDSigmaZ = val*sign;
+                     }
+                   
+                   
+                   HLTInfo( "    Cluster % 05u: fDTime: %f - fDPad: %f - fDCharge: %f - fDSigmaY: %f - fDSigmaZ: %f - fNPads: %u - fSlice: %hd - padrow: %lu - fPresent: %u",
+                            clustercount, cluster.fDTime, cluster.fDPad, cluster.fDCharge, cluster.fDSigmaY, cluster.fDSigmaZ, cluster.fNPads, cluster.fSlice, (unsigned long)i, (unsigned)cluster.fPresent );
+                   
+                   
+                   clustercount++;
+                   
+                   
+                   }
+                 if ( inputError )
+                   break;
+                 Pad8Bits();
+                 HLTInfo( "Input position: %lu / %u (0x%02X)", GetCurrentByteInputPosition(), GetCurrentBitInputPosition(), (unsigned)GetCurrentInputByte() );
+                 
+                 trackCount++;
+               }
+             if ( inputError )
+               continue;
+             
+           }
+         if ( blocks[n].fDataType == AliHLTTPCDefinitions::fgkRemainingClustersCompressedDataType )
+           {
+             AliHLTUInt8_t* inputPtr = (AliHLTUInt8_t*)blocks[n].fPtr;
+             
+             InitBitDataInput( inputPtr, blocks[n].fSize );
+             AliHLTUInt8_t version;
+             if ( !InputBits( version, 4 ) ) // Version information
+               {
+                 HLTError( "Corrupt input data. Cannot read data version number at position %u / %u",
+                           (unsigned)GetCurrentByteInputPosition(), (unsigned)GetCurrentBitInputPosition() );
+                 return EIO;
+               }
+             HLTInfo( "Remaining cluster data version: %u", (unsigned)version );
+             if ( version != 0 )
+               {
+                 HLTError( "Unsupported version %hu. Only version 0 supported currently.", version );
+               }
+           Pad8Bits();
+           
+           unsigned long clusterCount=0;
+           for(Int_t slice=0; slice<=35; slice++)
+             {
+               for(Int_t patch=0; patch < 6; patch++)
+                 {
+                   UInt_t i;
+                   //Write number of padrows with clusters
+                   UInt_t nRows;
+                   if ( !InputBits( nRows, 8 ) )
+                     {
+                       HLTError( "Corrupt input data. Cannot read padrow count at position %u / %u",
+                                 (unsigned)GetCurrentByteInputPosition(), (unsigned)GetCurrentBitInputPosition() );
+                       return EIO;
+                     }
+                   HLTInfo( "slice %u patch %u: %u padrows",
+                            (unsigned)slice, (unsigned)patch, (unsigned)nRows );
+                   if ( !nRows )
+                     {
+                       continue;
+                     }
+                   //HLTInfo( "  Slice %d - Partition %d", slice, patch );
+                   for ( UInt_t jj=0; jj<nRows; jj++ )
+                     {
+                       
+                       UInt_t padrow;
+                       if ( !InputBits(padrow,8) ) //Read padrow #
+                         {
+                           HLTError( "Corrupt input data. Cannot read padrow number at position %u / %u",
+                                     (unsigned)GetCurrentByteInputPosition(), (unsigned)GetCurrentBitInputPosition() );
+                           return EIO;
+                         }
+                       HLTInfo( "Padrow: %u", (unsigned)padrow );
+                       UInt_t nClusters;
+                       if ( !InputBits(nClusters,10) )//Read number of clusters on this padrow
+                         {
+                           HLTError( "Corrupt input data. Cannot read cluster count at position %u / %u",
+                                     (unsigned)GetCurrentByteInputPosition(), (unsigned)GetCurrentBitInputPosition() );
+                           return EIO;
+                         }
+                       HLTInfo( "  #Clusters: %u", (unsigned)nClusters );
+                       for ( i=0; i<nClusters; i++ )
+                           {
+                             //Read pad
+                             AliHLTTPCRemainingCluster cl;
+                             Int_t buff;
+                             if ( !InputBits(buff,AliHLTTPCCompDataCompressorHelper::GetNPadBitsRemaining()) )
+                               {
+                                 HLTError( "Corrupt input data. Cannot read cluster pad data at position %u / %u",
+                                           (unsigned)GetCurrentByteInputPosition(), (unsigned)GetCurrentBitInputPosition() );
+                                 return EIO;
+                               }
+                             cl.fPad = (Float_t)( ((double)buff) / AliHLTTPCCompDataCompressorHelper::GetPadPrecisionFactor() );
+                             
+                             //Read time
+                             if ( !InputBits(buff,AliHLTTPCCompDataCompressorHelper::GetNTimeBitsRemaining()) )
+                               {
+                                 HLTError( "Corrupt input data. Cannot read cluster time data at position %u / %u",
+                                           (unsigned)GetCurrentByteInputPosition(), (unsigned)GetCurrentBitInputPosition() );
+                                 return EIO;
+                               }
+                             cl.fTime = (Float_t)( ((double)buff) / AliHLTTPCCompDataCompressorHelper::GetTimePrecisionFactor() );
+                             
+                             //Read widths
+                             if ( !InputBits(buff,AliHLTTPCCompDataCompressorHelper::GetNShapeBitsRemaining()) )
+                               {
+                                 HLTError( "Corrupt input data. Cannot read cluster pad width data at position %u / %u",
+                                           (unsigned)GetCurrentByteInputPosition(), (unsigned)GetCurrentBitInputPosition() );
+                                 return EIO;
+                               }
+                             Float_t padw = (Float_t)( ((double)buff) / AliHLTTPCCompDataCompressorHelper::GetPadPrecisionFactor() );
+                           cl.fSigmaY2 = padw*padw;
+                           
+                           if ( !InputBits(buff,AliHLTTPCCompDataCompressorHelper::GetNShapeBitsRemaining()) )
+                             {
+                               HLTError( "Corrupt input data. Cannot read cluster time width data at position %u / %u",
+                                         (unsigned)GetCurrentByteInputPosition(), (unsigned)GetCurrentBitInputPosition() );
+                               return EIO;
+                             }
+                           Float_t timew = (Float_t)( ((double)buff) / AliHLTTPCCompDataCompressorHelper::GetTimePrecisionFactor() );
+                           cl.fSigmaZ2 = timew*timew;
+                           
+                           //Read charge 
+                           if ( !InputBits(buff,AliHLTTPCCompDataCompressorHelper::GetNChargeBits()) )
+                             {
+                               HLTError( "Corrupt input data. Cannot read cluster charge data at position %u / %u",
+                                         (unsigned)GetCurrentByteInputPosition(), (unsigned)GetCurrentBitInputPosition() );
+                               return EIO;
+                             }
+                           cl.fCharge = buff;
+                           
+                           HLTInfo( "  Cluster % 5lu (% 5u): fPadRow: %u - fPad: %f - fTime: %f - fSigmaY2: %f - fSigmaZ2: %f - fCharge: %hu",
+                                    clusterCount, (unsigned)i, (unsigned)padrow, cl.fPad, cl.fTime, cl.fSigmaY2, cl.fSigmaZ2, cl.fCharge );
+                           clusterCount++;
+                           }
+                     }
+                 }
+               
+             }
+           
+           
+           }
+         
+       }
+      
+      size = 0;
+      return 0;
+    }
diff --git a/HLT/TPCLib/comp/AliHLTTPCCompDumpComponent.h b/HLT/TPCLib/comp/AliHLTTPCCompDumpComponent.h
new file mode 100644 (file)
index 0000000..fde9678
--- /dev/null
@@ -0,0 +1,346 @@
+// XEmacs -*-C++-*-
+// $Id: AliHLTTPCCompDumpComponent.h,v 1.2 2006/08/10 09:46:51 richterm Exp $
+
+#ifndef ALIHLTTPCCOMPDUMPCOMPONENT_H
+#define ALIHLTTPCCOMPDUMPCOMPONENT_H
+/* TPCCompDumpright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full TPCCompDumpright notice                               */
+
+/** @file   AliHLTTPCCompDumpComponent.h
+    @author Timm Steinbeck
+    @date   
+    @brief  Declaration of a copy component. */
+
+
+#include "AliHLTProcessor.h"
+
+/**
+ * @class AliHLTTPCCompDumpComponent
+ * @author Timm Steinbeck
+ * @brief A dummy HLT processing component. 
+ *
+ * An implementiation of a copy component that just copies its input data
+ * to debug a components input data
+ * @ingroup alihlt_tutorial
+ */
+class AliHLTTPCCompDumpComponent : public AliHLTProcessor
+    {
+    public:
+      
+      /** standard constructor */
+      AliHLTTPCCompDumpComponent();
+
+      /** standard destructor */
+      virtual ~AliHLTTPCCompDumpComponent();
+
+       // Public functions to implement AliHLTComponent's interface.
+       // These functions are required for the registration process
+
+      /** function to get component id 
+       * @return const char* pointer to componentid
+       */
+      const char* GetComponentID();
+
+      /** function to get input data types
+       * @param list vecotr of AliHLTComponent_DataType
+       */
+      void GetInputDataTypes( vector<AliHLTComponent_DataType>& list);
+
+      /** function to get output data type
+       * @return AliHLTComponent_DataType
+       */
+      AliHLTComponent_DataType GetOutputDataType();
+
+      /** function to get output data size
+       * @param constBase address of an unsigned long
+       * @param inputMultiplier address of a double
+       */
+      virtual void GetOutputDataSize( unsigned long& constBase, double& inputMultiplier );
+
+      /** spawn function
+       * @return AliHLTComponent* pointer to instance
+       */
+      AliHLTComponent* Spawn();
+       
+    protected:
+       
+       // Protected functions to implement AliHLTComponent's interface.
+       // These functions provide initialization as well as the actual processing
+       // capabilities of the component. 
+
+      /** initialisation function
+       * @param argc integer counting number of input arguments
+       * @param argv const char** for parameter values
+       * @return zero upon success
+       */
+       int DoInit( int argc, const char** argv );
+
+      /** deinitialisation function
+       * @return zero upon success
+       */
+       int DoDeinit();
+
+      /** do event function
+       * @param evt Data     const AliHLTComponent_EventData& to event data
+       * @param blocks       const AliHLTComponent_BlockData* to blocks of event data
+       * @param trigData     AliHLTComponent_TriggerData& of trigger data
+       * @param outputPtr    AliHLTUInt8_t* pointer to output data
+       * @param size         AliHLTUInt32_t& of output size
+       * @param outputBlocks vector<AliHLTComponent_BlockData>& of output block data
+       * @return zero upon success
+      */
+      int DoEvent( const AliHLTComponent_EventData& evtData, const AliHLTComponent_BlockData* blocks, 
+                  AliHLTComponent_TriggerData& trigData, AliHLTUInt8_t* outputPtr, 
+                  AliHLTUInt32_t& size, vector<AliHLTComponent_BlockData>& outputBlocks );
+      
+      
+      /** function to initialise bit input
+       * @param input     AliHLTUInt8_t
+       * @param inputSize UInt_t
+       */
+      void InitBitDataInput( AliHLTUInt8_t* input, UInt_t inputSize )
+      {
+       fBitDataCurrentWord = 0;
+       fBitDataCurrentPosInWord = 7;
+       fBitDataCurrentInput = fBitDataCurrentInputStart = input;
+       fBitDataCurrentInputEnd = input+inputSize;
+       fBitDataCurrentWord = *fBitDataCurrentInput;
+      }
+
+      /** function to close bit data input */  
+      void CloseBitDataInput()
+      {
+      }
+
+      /** function to get current byte input position
+       * @return unsigned long value of current byte input position
+       */
+      unsigned long GetCurrentByteInputPosition() const
+      {
+       return (unsigned long)( fBitDataCurrentInput - fBitDataCurrentInputStart );
+      }
+      
+      /** function to get current bit input position
+       * @return fBitDataCurrentPosInWord unsigned value
+       */
+      unsigned GetCurrentBitInputPosition() const
+      {
+       return fBitDataCurrentPosInWord;
+      }
+
+      /** function to get current input byte
+       * @return fBitDataCurrentWord AliHLTUInt8_t value
+       */
+      AliHLTUInt8_t GetCurrentInputByte() const
+      {
+       return fBitDataCurrentWord;
+      }
+      
+      /** function to get end of bit input
+       * @return boolean if input is at end or not
+       */
+      bool EndOfBitInput() const
+      {
+       return (fBitDataCurrentInput>=fBitDataCurrentInputEnd);
+      }
+      
+      /** function got get bit data input size bytes
+       * @return UInt_t value
+       */
+      UInt_t GetBitDataInputSizeBytes() const
+      {
+       return fBitDataCurrentInput-fBitDataCurrentInputStart;
+      }
+      
+      /** function to determine input bit
+       * @param value  AliHLTUInt8_t &
+       * @return boolean (input bit = 1 or = 0)
+       */
+      bool InputBit( AliHLTUInt8_t & value )
+      {
+       if ( fBitDataCurrentInput>=fBitDataCurrentInputEnd )
+         return false;
+       value = (fBitDataCurrentWord >> fBitDataCurrentPosInWord) & 1;
+       if ( fBitDataCurrentPosInWord )
+         fBitDataCurrentPosInWord--;
+       else
+         {
+           fBitDataCurrentInput++;
+           if ( fBitDataCurrentInput<fBitDataCurrentInputEnd )
+             {
+               fBitDataCurrentWord = *fBitDataCurrentInput;
+               fBitDataCurrentPosInWord = 7;
+             }
+         }
+       return true;
+      }
+
+      /** function to determine input bits below 8 bits
+       * @param value     AliHLTUInt8_t &
+       * @param bitCount  UInt_t const &
+       * @return boolean
+       */
+      bool InputBits( AliHLTUInt8_t & value, UInt_t const & bitCount )
+      {
+       if ( bitCount>8 )
+         {
+           HLTFatal( "Internal error: Attempt to write more than 32 bits (%u)", (unsigned)bitCount );
+           return false;
+         }
+       AliHLTUInt64_t temp;
+       if ( !InputBits( temp, bitCount ) )
+         return false;
+       value = (AliHLTUInt8_t)( temp & (AliHLTUInt64_t)0xFFFFFFFFULL );
+       return true;
+      }
+
+      /** function to determine input bits between 8 and 16 bits
+       * @param value     AliHLTUInt16_t &
+       * @param bitCount  UInt_t const &
+       * @return boolean
+       */
+      bool InputBits( AliHLTUInt16_t & value, UInt_t const & bitCount )
+      {
+       if ( bitCount>16 )
+         {
+           HLTFatal( "Internal error: Attempt to write more than 32 bits (%u)", (unsigned)bitCount );
+           return false;
+         }
+       AliHLTUInt64_t temp;
+       if ( !InputBits( temp, bitCount ) )
+         return false;
+       value = (AliHLTUInt16_t)( temp & (AliHLTUInt64_t)0xFFFFFFFFULL );
+       return true;
+      }
+
+      /** function to determine input bits between 16 and 32 bits
+       * @param value     AliHLTUInt32_t &
+       * @param bitCount  UInt_t const &
+       * @return boolean
+       */
+      bool InputBits( AliHLTUInt32_t & value, UInt_t const & bitCount )
+      {
+       if ( bitCount>32 )
+         {
+           HLTFatal( "Internal error: Attempt to write more than 32 bits (%u)", (unsigned)bitCount );
+           return false;
+         }
+       AliHLTUInt64_t temp;
+       if ( !InputBits( temp, bitCount ) )
+         return false;
+       value = (AliHLTUInt32_t)( temp & (AliHLTUInt64_t)0xFFFFFFFFULL );
+       return true;
+      }
+
+      /** function to determine input bits between 16 and 32 bits II
+       * @param value     Int_t &
+       * @param bitCount  UInt_t const &
+       * @return boolean
+       */
+      bool InputBits( Int_t & value, UInt_t const & bitCount )
+      {
+       if ( bitCount>32 )
+         {
+           HLTFatal( "Internal error: Attempt to write more than 32 bits (%u)", (unsigned)bitCount );
+           return false;
+         }
+       AliHLTUInt64_t temp;
+       if ( !InputBits( temp, bitCount ) )
+         return false;
+       value = (Int_t)( temp & (AliHLTUInt64_t)0xFFFFFFFFULL );
+       return true;
+      }
+
+      /** function to determine input bits between 32 and 64 bits
+       * @param value     AliHLTUInt64_t &
+       * @param bitCount  UInt_t const &
+       * @return boolean
+       */
+      bool InputBits( AliHLTUInt64_t & value, UInt_t const & bitCount )
+      {
+       if ( bitCount>64 )
+         {
+           HLTFatal( "Internal error: Attempt to write more than 64 bits (%u)", (unsigned)bitCount );
+           return false;
+         }
+       UInt_t bitsToRead=bitCount;
+       UInt_t curBitCount;
+       value = 0;
+       while ( bitsToRead>0 )
+         {
+           if ( fBitDataCurrentInput>=fBitDataCurrentInputEnd )
+             return false;
+           if ( bitsToRead >= fBitDataCurrentPosInWord+1 )
+             curBitCount = fBitDataCurrentPosInWord+1;
+           else
+             curBitCount = bitsToRead;
+           value = (value << curBitCount) | ( (fBitDataCurrentWord >> (fBitDataCurrentPosInWord-curBitCount+1)) & ((1 << curBitCount)-1) );
+           if ( fBitDataCurrentPosInWord < curBitCount )
+             {
+               fBitDataCurrentInput++;
+               if ( fBitDataCurrentInput<fBitDataCurrentInputEnd )
+                 {
+                   fBitDataCurrentWord = *fBitDataCurrentInput;
+                   fBitDataCurrentPosInWord = 7;
+                 }
+             }
+           else
+             fBitDataCurrentPosInWord -= curBitCount;
+           bitsToRead -= curBitCount;
+         }
+       return true;
+      }
+
+      /** pad function for 8 bits */
+      void Pad8Bits()
+      {
+       if ( fBitDataCurrentPosInWord == 7 )
+         return;
+       fBitDataCurrentInput++;
+       if ( fBitDataCurrentInput<fBitDataCurrentInputEnd )
+         {
+           fBitDataCurrentWord = *fBitDataCurrentInput;
+           fBitDataCurrentPosInWord = 7;
+         }
+      }
+
+      /** function for input bytes 
+       * @param data      AliHLTUInt8_t*
+       * @param byteCount UInt_t const &
+       */
+      bool InputBytes( AliHLTUInt8_t* data, UInt_t const & byteCount )
+      {
+       Pad8Bits();
+       if ( fBitDataCurrentInput+byteCount>fBitDataCurrentInputEnd )
+         return false;
+       memcpy( data, fBitDataCurrentInput, byteCount );
+       fBitDataCurrentInput += byteCount;
+       if ( fBitDataCurrentInput<fBitDataCurrentInputEnd )
+         {
+           fBitDataCurrentWord = *fBitDataCurrentInput;
+           fBitDataCurrentPosInWord = 7;
+         }
+       return true;
+      }
+
+    private:
+      /** copy constructor prohibited */
+      AliHLTTPCCompDumpComponent(const AliHLTTPCCompDumpComponent&);
+      /** assignment operator prohibited */
+      AliHLTTPCCompDumpComponent& operator=(const AliHLTTPCCompDumpComponent&);
+      
+      /** member varibable for current bit data word */
+      AliHLTUInt8_t fBitDataCurrentWord;
+      /** member variable for current bit data position in word */
+      UInt_t fBitDataCurrentPosInWord;
+      /** member variable for current input bit data */
+      AliHLTUInt8_t *fBitDataCurrentInput;
+      /** member variable for current bit data input start */
+      AliHLTUInt8_t *fBitDataCurrentInputStart;
+      /** member variable for current bit data input end */
+      AliHLTUInt8_t *fBitDataCurrentInputEnd;
+
+      ClassDef(AliHLTTPCCompDumpComponent, 0)
+
+    };
+#endif
diff --git a/HLT/TPCLib/comp/AliHLTTPCCompModelAnalysis.cxx b/HLT/TPCLib/comp/AliHLTTPCCompModelAnalysis.cxx
new file mode 100644 (file)
index 0000000..00363d1
--- /dev/null
@@ -0,0 +1,1146 @@
+// $Id: AliHLTTPCCompModelAnalysis.cxx,v 1.2 2006/08/10 09:46:51 richterm Exp $
+
+/**************************************************************************
+ * TPCCompModelAnalysisright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Authors: J. Wagner <jwagner@cern.ch>                                   *
+ *          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.                  *
+ **************************************************************************/
+
+/** @file   AliHLTTPCCompModelAnalysis.cxx
+    @author J. Wagner jwagner@cern.ch
+    @date   17-11-2007
+    @brief  A processing analysis component for the HLT */
+
+#if __GNUC__ >= 3
+using namespace std;
+#endif
+
+#include "AliHLTTPCCompModelAnalysis.h"
+#include "AliHLTTPCTransform.h"
+#include "AliHLTTPCModelTrack.h"
+#include "AliHLTTPCCompDataCompressorHelper.h"
+#include "TFile.h"
+#include "TH1.h"
+#include <cerrno>
+
+/** constructor **/
+AliHLTTPCCompModelAnalysis::AliHLTTPCCompModelAnalysis(Bool_t modelanalysis, Bool_t trackanalysis, TString dumpfilename, TString graphfilename):
+  fModelAnalysis(modelanalysis),
+  fTrackAnalysis(trackanalysis),
+  fDumpFileName(dumpfilename),
+  fGraphFileName(graphfilename),
+  fFirstTrackArray(),
+  fSecondTrackArray(),
+  fFirstTrackList(NULL),
+  fSecondTrackList(NULL),
+  fFirstTrashTracks(0),
+  fSecondTrashTracks(0),
+  fTotalComparedTracks(0),
+  fMatchedFirstTrashTracks(0),
+  fMatchedSecondTrashTracks(0),
+  fFirstUnmatchedTracks(0),
+  fSecondUnmatchedTracks(0),
+  fToleranceDeviation(0.0),
+  fTrackListPointer(NULL),
+  fTotalDiscardedClusters(0),
+  fValuableDiscardedClusters(0),
+  fTrashTracks(0)
+{
+  // see header file for class documentation
+}
+
+/** destructor **/
+AliHLTTPCCompModelAnalysis::~AliHLTTPCCompModelAnalysis()
+    {
+    for ( UInt_t slice=0; slice<36; slice++ )
+       for ( UInt_t patch=0; patch<6; patch++ )
+           {
+           if ( fDiscardedClusters[slice][patch]->fSpacePoints )
+               {
+               delete [] fDiscardedClusters[slice][patch];
+               }
+           }
+    }
+
+/** initialise arrays for tracks/ discarded clusters depending on model-flags **/
+Int_t AliHLTTPCCompModelAnalysis::Init()
+{
+  // see header file for class documentation
+
+  if(fTrackAnalysis) // track quantities are to be initialised
+    {
+      fFirstTrackArray.Reset();
+      fSecondTrackArray.Reset();
+
+      fFirstTrackList = NULL;
+      fSecondTrackList = NULL;
+
+      fFirstTrashTracks = 0;
+      fSecondTrashTracks = 0;
+
+      fTotalComparedTracks = 0;
+      fMatchedFirstTrashTracks = 0;
+      fMatchedSecondTrashTracks = 0;
+
+      fFirstUnmatchedTracks = 0;
+      fSecondUnmatchedTracks = 0;
+
+      fToleranceDeviation = 0.001;
+
+    }
+  
+  if(fModelAnalysis) // cluster array to be initialised
+    {
+      for ( UInt_t slice=0; slice<36; slice++ )
+       {
+         for ( UInt_t patch=0; patch<6; patch++ )
+           {
+             fDiscardedClusters[slice][patch] = NULL;
+           }
+       }
+
+      // initialise trash track list to store discarded tracks
+      fTrackListPointer = NULL;
+
+      // set all counters to zero:
+      fTrashTracks = 0;
+      fTotalDiscardedClusters = 0;
+      fValuableDiscardedClusters = 0;
+    }
+
+  return 0;
+}
+
+Int_t AliHLTTPCCompModelAnalysis::DisplayResults()
+{
+  // see header file for class documentation
+  HLTInfo("--------------------DISPLAYING RESULTS---------------------");
+  // if model loss analysis, then display these results, else display track results
+  if (fModelAnalysis)
+    {
+      DisplayModelResults();
+    };
+
+  if (fTrackAnalysis)
+    {
+      DisplayTrackResults();
+    };
+
+  // error message: if no analysis flag is switched on
+  if( (!fModelAnalysis) && (!fTrackAnalysis) )
+    {
+      HLTError("Error! Display Results called without any analysis flag switched on.");
+      return 1;
+    }
+
+  return 0;
+}
+
+Int_t AliHLTTPCCompModelAnalysis::SetTracks(AliHLTTPCTrackletData* tracklets, Bool_t fillingfirsttracks)
+{
+  // see header file for class documentation
+  // if fFillingFirstTrackArray is true (i.e. first input file in component is processed)
+  // first input track array is filled
+  // else the second track array is filled
+
+  if(fillingfirsttracks)
+    {
+      HLTDebug( "Reading %u tracks in first array", (unsigned) tracklets->fTrackletCnt );
+      
+      if(tracklets->fTrackletCnt == 0)
+       {
+         HLTError("Error! No tracklets to fill into first track array!");
+         return EINVAL;
+       }
+      else
+       {
+         fFirstTrackArray.FillTracks(tracklets->fTrackletCnt, tracklets->fTracklets );
+       }
+
+    }
+  else
+    {
+      if(tracklets->fTrackletCnt == 0)
+       {
+         HLTError("Error! No tracklets to fill into second track array!");
+         return EINVAL;
+       }
+      else
+       {
+         fSecondTrackArray.FillTracks(tracklets->fTrackletCnt, tracklets->fTracklets );
+       }
+      // read in tracks in second array (tracks from clusters after Vestbo in second tracking process)
+      HLTDebug( "Reading %u tracks in second array", (unsigned) tracklets->fTrackletCnt );
+    
+    }
+
+  return 0;
+}
+
+Int_t AliHLTTPCCompModelAnalysis::CompareTracks()
+{
+  // see header file for class documentation
+  // define variables for number of tracks in track arrays:
+  Int_t firsttracks = fFirstTrackArray.GetNTracks();
+  Int_t secondtracks = fSecondTrackArray.GetNTracks();
+
+  // error checking: if second array has been filled or not:
+  if(firsttracks == 0)
+    {
+      HLTError("No tracks in first track array!");
+      return EINVAL;
+    };
+
+  if(secondtracks == 0)
+    {
+      HLTError("No tracks in second track array!");
+      return EINVAL;
+    };
+
+  // take track from first tracking,
+  for(Int_t ii=0; ii < firsttracks; ii++)
+    {
+      // build track list for all tracks in first array
+      AliHLTTPCTrackList* currenttrackentry = new AliHLTTPCTrackList;
+      currenttrackentry->track = *(fFirstTrackArray.GetCheckedTrack(ii));
+
+      // get its pythia information, 
+      currenttrackentry->pythiatrack = GetComparableTrackPythiaInfo(currenttrackentry->track);
+
+      currenttrackentry->matchingindicator = 0;
+
+      // put this element as first in list
+      currenttrackentry->next = fFirstTrackList;
+      fFirstTrackList = currenttrackentry;
+
+      // count tracks below 0.1GeV
+      if(currenttrackentry->track.GetPt()<0.1)
+       {
+         ++fFirstTrashTracks;
+       }
+
+    }
+
+ // take track from second tracking,
+  for(Int_t ii=0; ii < secondtracks; ii++)
+    {
+      // build track list for all tracks in second array
+      AliHLTTPCTrackList* currenttrackentry = new AliHLTTPCTrackList;
+      currenttrackentry->track = *(fSecondTrackArray.GetCheckedTrack(ii));
+
+      // get its pythia information, 
+      currenttrackentry->pythiatrack = GetComparableTrackPythiaInfo(currenttrackentry->track);
+
+      // put this element as first in list
+      currenttrackentry->next = fSecondTrackList;
+      fSecondTrackList = currenttrackentry;
+
+      // count tracks below 0.1GeV
+      if(currenttrackentry->track.GetPt()<0.1)
+       {
+         ++fSecondTrashTracks;
+       }
+
+    }
+
+  // search for matching track from secondary tracking
+  AliHLTTPCTrackList* firstmatchpointer = fFirstTrackList;
+  while(firstmatchpointer != NULL)
+   {
+     AliHLTTPCTrackList* secondmatchpointer = fSecondTrackList;
+
+     while(secondmatchpointer != NULL)
+       {
+       
+        // compare paramters of the two tracks, 
+        // match only when coincidence >= 50% in fToleranceDeviation range!
+        if ((CompareTrackInfo(firstmatchpointer, secondmatchpointer) > 4))
+          { 
+    
+            if((CompareTrackInfo(firstmatchpointer, secondmatchpointer) > firstmatchpointer->matchingindicator))
+              {
+                // look if current better matching track has already been matched before
+                if((CompareTrackInfo(firstmatchpointer, secondmatchpointer) > secondmatchpointer->matchingindicator))
+                  {
+                    
+                    // set previously assigned matchingindicator (if there was one) of secondary track back to zero
+                    if(firstmatchpointer->matchingindicator > 0)
+                      {
+                        firstmatchpointer->matchingtrack->matchingindicator = 0;
+                        firstmatchpointer->matchingtrack->matchingtrack = NULL;
+                      }
+
+                    if(secondmatchpointer->matchingindicator > 0)
+                      {
+                        secondmatchpointer->matchingtrack->matchingindicator = 0;
+                        secondmatchpointer->matchingtrack->matchingtrack = NULL;
+                      }
+                    
+                    // compare according to tracks themselves (other possibility: compare pythiatracks - better!)
+                    secondmatchpointer->matchingindicator = CompareTrackInfo(firstmatchpointer, secondmatchpointer) ;
+                    firstmatchpointer->matchingindicator = CompareTrackInfo(firstmatchpointer, secondmatchpointer);
+                    
+                    // remember which track matches which
+                    secondmatchpointer->matchingtrack = firstmatchpointer;
+                    firstmatchpointer->matchingtrack = secondmatchpointer;
+
+                  } // end if compare > second matching indicator
+
+              } // end if compare > first matching indicator
+            
+          }// end if compare > 4
+                
+        secondmatchpointer = secondmatchpointer->next;
+       }
+     
+     // go on with next original track
+     firstmatchpointer = firstmatchpointer->next;
+   }
+  
+  // count not matched tracks in first and second track list
+  AliHLTTPCTrackList* nomatchcounter = fFirstTrackList;
+
+  while(nomatchcounter != NULL)
+    {
+      if(nomatchcounter->matchingindicator == 0)
+       {
+         ++fFirstUnmatchedTracks;
+       }
+      else
+       {
+        ++fTotalComparedTracks;
+
+        // count matched trash tracks
+        if(nomatchcounter->track.GetPt() < 0.1)
+          {
+            ++fMatchedFirstTrashTracks;
+          };
+       }
+      nomatchcounter = nomatchcounter->next;
+    }
+
+  nomatchcounter = fSecondTrackList;
+  while(nomatchcounter != NULL)
+    {
+      if(nomatchcounter->matchingindicator == 0)
+       {
+         ++fSecondUnmatchedTracks;
+       }
+      else
+       {
+         // count matched trash tracks
+        if(nomatchcounter->track.GetPt() < 0.1)
+          {
+            ++fMatchedSecondTrashTracks;
+          };
+       }
+    
+      nomatchcounter = nomatchcounter->next;
+    }
+  // consistency check: fFirstUnmatchedTracks + fTotalComparedTracks = # of tracks in first array
+  // ...and analogously for second array:
+  if(fFirstUnmatchedTracks + fTotalComparedTracks !=  firsttracks)
+    {
+      HLTWarning("Warning! Possible inconsistency in original track array: Number of compared and unmatched tracks not equal to total number of tracks!");
+    };
+  
+  if(fSecondUnmatchedTracks + fTotalComparedTracks !=  secondtracks)
+    {
+      HLTWarning("Warning! Possible inconsistency in second track array: Number of compared and unmatched tracks not equal to total number of tracks!");
+    };
+  
+  return 0;
+}
+
+AliHLTTPCTrack AliHLTTPCCompModelAnalysis::GetComparableTrackPythiaInfo(AliHLTTPCTrack comparabletrack)
+{
+  // see headerfile for class documentation
+
+  AliHLTTPCTrack pythiatrack = comparabletrack;
+
+  return pythiatrack;
+}
+
+Int_t AliHLTTPCCompModelAnalysis::MarkTrashTrack(AliHLTTPCTrack *lowpttrack)
+{
+  // see header file for class documentation
+
+  // save track first in lowpttrack list (all lowpttracks are displayed in display function altogether)
+  AliHLTTPCTrackList* tracklistentry =  new AliHLTTPCTrackList;
+  tracklistentry->track = *lowpttrack;
+  tracklistentry->wronglydiscarded = GetTrashTrackPythiaInfo(lowpttrack);
+  tracklistentry->matchingindicator = 0; // not needed here, therefore initialised to zero
+  tracklistentry->next = fTrackListPointer;
+  tracklistentry->matchingtrack = NULL; // not needed here, therefore initialised to NULL
+  fTrackListPointer = tracklistentry;
+
+  ++fTrashTracks;
+
+  return 0;
+}
+
+Int_t AliHLTTPCCompModelAnalysis::MarkTrashCluster(AliHLTTPCClusterData *discardedcluster, UInt_t slice, UInt_t patch)
+{
+  // see header file for class documentation
+
+  // get Pythia information of discarded cluster
+  Bool_t wronglydiscarded = GetClusterPythiaInfo(discardedcluster);
+
+  // if cluster has been discarded wrongly, save information
+  if(wronglydiscarded)
+    {
+      // store cluster
+      fDiscardedClusters[slice][patch] = discardedcluster;
+      // increase number of valuable discarded clusters
+      ++fValuableDiscardedClusters;
+    }
+      
+      ++fTotalDiscardedClusters;   
+      
+  return 0;
+}
+
+Bool_t AliHLTTPCCompModelAnalysis::GetTrashTrackPythiaInfo(AliHLTTPCTrack* discardedtrack)
+{
+  // see header file for class documentation
+  // store information from pythia in current track list entry
+  // fTrackListPointer.pythiatrack = FillFromPythia...
+
+  return 0;
+}
+
+Bool_t AliHLTTPCCompModelAnalysis::GetClusterPythiaInfo(AliHLTTPCClusterData* discardedcluster)
+{
+  // see header file for class documentation
+  // Pythia information can be
+  // either: cluster belongs to discarded track with pt < 0.1 Gev (--> cluster correctly discarded)
+  //     or: cluster is discarded and does not belong to any pythia track (--> correctly discarded)
+  //     or: cluster is discarded but belongs to pythia track (--> cluster WRONGLY discarded!!!)
+
+  return 0;
+}
+Int_t AliHLTTPCCompModelAnalysis::CompareTrackInfo(AliHLTTPCTrackList* firsttracklistelement, AliHLTTPCTrackList* secondtracklistelement)
+{
+  // see header file for class documentation
+  // calculate matching indicator accoring to the track information
+  // ++matchingindicator for every paramter that matches
+
+  Int_t currentmatchingindicator = 0;
+
+  // tolerance range of 1 percent deviation for each quantity
+
+  // compare start point (x,y,z)
+  if(abs((firsttracklistelement->track.GetFirstPointX() - secondtracklistelement->track.GetFirstPointX()))/firsttracklistelement->track.GetFirstPointX() <= fToleranceDeviation)
+    ++currentmatchingindicator;
+
+  if(abs((firsttracklistelement->track.GetFirstPointY() - secondtracklistelement->track.GetFirstPointY()))/firsttracklistelement->track.GetFirstPointY() <= fToleranceDeviation)
+    ++currentmatchingindicator;
+
+  if(abs((firsttracklistelement->track.GetFirstPointZ() - secondtracklistelement->track.GetFirstPointZ()))/firsttracklistelement->track.GetFirstPointZ() <= fToleranceDeviation)
+    ++currentmatchingindicator;
+  
+  // compare end point
+  if(abs((firsttracklistelement->track.GetLastPointX() - secondtracklistelement->track.GetLastPointX()))/firsttracklistelement->track.GetLastPointX() <= fToleranceDeviation)
+    ++currentmatchingindicator;
+
+  if(abs((firsttracklistelement->track.GetLastPointY() - secondtracklistelement->track.GetLastPointY()))/firsttracklistelement->track.GetLastPointY() <= fToleranceDeviation)
+    ++currentmatchingindicator;
+
+  if(abs((firsttracklistelement->track.GetLastPointZ() - secondtracklistelement->track.GetLastPointZ()))/firsttracklistelement->track.GetLastPointZ() <= fToleranceDeviation)
+    ++currentmatchingindicator;
+
+  // compare pt, psi, tgl
+  if(abs((firsttracklistelement->track.GetPt() - secondtracklistelement->track.GetPt()))/firsttracklistelement->track.GetPt() <= fToleranceDeviation)
+    ++currentmatchingindicator;
+
+  if(abs((firsttracklistelement->track.GetPsi() - secondtracklistelement->track.GetPsi()))/firsttracklistelement->track.GetPsi() <= fToleranceDeviation)
+    ++currentmatchingindicator;
+
+  if(abs((firsttracklistelement->track.GetTgl() - secondtracklistelement->track.GetTgl()))/firsttracklistelement->track.GetTgl() <= fToleranceDeviation)
+    ++currentmatchingindicator;
+
+  // compare number of assigned cluster hits
+  if(abs((firsttracklistelement->track.GetNHits() - secondtracklistelement->track.GetNHits()))/firsttracklistelement->track.GetNHits() <= fToleranceDeviation)
+    ++currentmatchingindicator;
+
+  return currentmatchingindicator;
+}
+
+Int_t AliHLTTPCCompModelAnalysis::ComparePythiaTrackInfo(AliHLTTPCTrackList* firsttracklistelement, AliHLTTPCTrackList* secondtracklistelement)
+{
+  // see header file for class documentation
+  // calculate matching indicator accoring to the track information
+  // ++matchingindicator for every paramter that matches
+
+  Int_t currentmatchingindicator = 0;
+
+  // tolerance range of 1 percent deviation for each quantity
+
+  // compare start point (x,y,z)
+  if(firsttracklistelement->pythiatrack.GetFirstPointX() == secondtracklistelement->pythiatrack.GetFirstPointX())
+    ++currentmatchingindicator;
+
+  if(firsttracklistelement->pythiatrack.GetFirstPointY() == secondtracklistelement->pythiatrack.GetFirstPointY())
+    ++currentmatchingindicator;
+
+  if(firsttracklistelement->pythiatrack.GetFirstPointZ() == secondtracklistelement->pythiatrack.GetFirstPointZ())
+    ++currentmatchingindicator;
+  
+  // compare end point
+  if(firsttracklistelement->pythiatrack.GetLastPointX() == secondtracklistelement->pythiatrack.GetLastPointX())
+    ++currentmatchingindicator;
+
+  if(firsttracklistelement->pythiatrack.GetLastPointY() == secondtracklistelement->pythiatrack.GetLastPointY())
+    ++currentmatchingindicator;
+
+  if(firsttracklistelement->pythiatrack.GetLastPointZ() == secondtracklistelement->pythiatrack.GetLastPointZ())
+    ++currentmatchingindicator;
+
+  // compare pt, psi, tgl
+  if(firsttracklistelement->pythiatrack.GetPt() == secondtracklistelement->pythiatrack.GetPt())
+    ++currentmatchingindicator;
+
+  if(firsttracklistelement->pythiatrack.GetPsi() == secondtracklistelement->pythiatrack.GetPsi())
+    ++currentmatchingindicator;
+
+  if(firsttracklistelement->pythiatrack.GetTgl() == secondtracklistelement->pythiatrack.GetTgl())
+    ++currentmatchingindicator;
+
+  // compare number of assigned cluster hits
+  if(firsttracklistelement->pythiatrack.GetNHits() == secondtracklistelement->pythiatrack.GetNHits())
+    ++currentmatchingindicator;
+
+  return currentmatchingindicator;
+}
+
+Int_t AliHLTTPCCompModelAnalysis::CreateGraphs(Bool_t relativedifferences)
+{
+  // see header file for class documentation
+  AliHLTTPCTrackList* tracklistpointer = fFirstTrackList;
+
+  AliHLTTPCTrackList* trackmatchingpointer;
+
+  // set up histogram ranges
+  Double_t difffirstxmin, difffirstxmax;
+  Double_t difffirstymin, difffirstymax;
+  Double_t difffirstzmin, difffirstzmax;
+  Int_t difffirstxbins, difffirstybins, difffirstzbins;
+
+  Double_t difflastxmin, difflastxmax;
+  Double_t difflastymin, difflastymax;
+  Double_t difflastzmin, difflastzmax;
+  Int_t difflastxbins, difflastybins, difflastzbins; 
+
+  Double_t diffptmin, diffptmax;
+  Double_t diffpsimin, diffpsimax;
+  Double_t difftglmin, difftglmax;
+  Int_t diffptbins, diffpsibins, difftglbins;
+
+  Double_t diffclustermin, diffclustermax;
+  Int_t diffclusterbins;
+  // resolution histograms (currently not working since pterr = 0 for every track!)
+  Double_t diffpterrmin, diffpterrmax;
+  Double_t diffpsierrmin, diffpsierrmax;
+  Double_t difftglerrmin, difftglerrmax;
+  Int_t diffpterrbins, diffpsierrbins, difftglerrbins;
+
+  if(!relativedifferences)
+    {
+      difffirstxmin = -2;
+      difffirstxmax = +2;
+      difffirstxbins = (Int_t) ((difffirstxmax - difffirstxmin)/0.0001);
+
+      difffirstymin = -2;
+      difffirstymax = +2;
+      difffirstybins = (Int_t) ((difffirstymax - difffirstymin)/0.0001);
+
+      difffirstzmin = -2;
+      difffirstzmax = +2;
+      difffirstzbins = (Int_t) ((difffirstzmax - difffirstzmin)/0.0001);
+
+      difflastxmin = -2;
+      difflastxmax = +2;
+      difflastxbins = (Int_t) ((difflastxmax - difflastxmin)/0.0001);
+
+      difflastymin = -2;
+      difflastymax = +2;
+      difflastybins = (Int_t) ((difflastymax - difflastymin)/0.0001);
+
+      difflastzmin = -2;
+      difflastzmax = +2;
+      difflastzbins = (Int_t) ((difflastzmax - difflastzmin)/0.0001);
+
+      diffptmin = -1;
+      diffptmax = +1;
+      diffptbins = (Int_t) ((diffptmax - diffptmin)/0.0001);
+      
+      diffpsimin = -1;
+      diffpsimax = +1;
+      diffpsibins = (Int_t) ((diffpsimax - diffpsimin)/0.0001);
+
+      difftglmin = -1;
+      difftglmax = +1;
+      difftglbins = (Int_t) ((difftglmax - difftglmin)/0.0001);
+
+      diffclustermin = -50;
+      diffclustermax = +50;
+      diffclusterbins = (Int_t) ((diffclustermax - diffclustermin)/1);
+
+#if 0
+      diffpterrmin = -1;
+      diffpterrmax = 1;
+      diffpterrbins = (Int_t) ((diffpterrmax - diffpterrmin)/1);
+
+      diffpsierrmin = -1;
+      diffpsierrmax = 1;
+      diffpsierrbins = (Int_t) ((diffpsierrmax - diffpsierrmin)/1);
+
+      difftglerrmin = -1;
+      difftglerrmax = 1;
+      difftglerrbins = (Int_t) ((difftglerrmax - difftglerrmin)/1);
+#endif
+
+    }
+  else
+    {
+      difffirstxmin = -1;
+      difffirstxmax = +1;
+      difffirstxbins = (Int_t) ((difffirstxmax - difffirstxmin)/0.0001);
+
+      difffirstymin = -1;
+      difffirstymax = +1;
+      difffirstybins = (Int_t) ((difffirstymax - difffirstymin)/0.0001);
+
+      difffirstzmin = -1;
+      difffirstzmax = +1;
+      difffirstzbins = (Int_t) ((difffirstzmax - difffirstzmin)/0.0001);
+
+      difflastxmin = -1;
+      difflastxmax = +1;
+      difflastxbins = (Int_t) ((difflastxmax - difflastxmin)/0.0001);
+
+      difflastymin = -1;
+      difflastymax = +1;
+      difflastybins = (Int_t) ((difflastymax - difflastymin)/0.0001);
+
+      difflastzmin = -1;
+      difflastzmax = +1;
+      difflastzbins = (Int_t) ((difflastzmax - difflastzmin)/0.0001);
+
+      diffptmin = -1;
+      diffptmax = +1;
+      diffptbins = (Int_t) ((diffptmax - diffptmin)/0.0001);
+      
+      diffpsimin = -1;
+      diffpsimax = +1;
+      diffpsibins = (Int_t) ((diffpsimax - diffpsimin)/0.0001);
+
+      difftglmin = -1;
+      difftglmax = +1;
+      difftglbins = (Int_t) ((difftglmax - difftglmin)/0.0001);
+
+      diffclustermin = -1;
+      diffclustermax = +1;
+      diffclusterbins = (Int_t) ((diffclustermax - diffclustermin)/0.0001);
+
+#if 0
+      diffpterrmin = -1;
+      diffpterrmax = 1;
+      diffpterrbins = (Int_t) ((diffpterrmax - diffpterrmin)/0.0001);
+
+      diffpsierrmin = -1;
+      diffpsierrmax = 1;
+      diffpsierrbins = (Int_t) ((diffpsierrmax - diffpsierrmin)/0.0001);
+
+      difftglerrmin = -1;
+      difftglerrmax = 1;
+      difftglerrbins = (Int_t) ((difftglerrmax - difftglerrmin)/0.0001);
+#endif
+    }
+
+  // intialise histogramms
+  TH1F* firstxhisto = new TH1F("Differences of first x (original - secondary) track", "Differences of first x (original - secondary) track", difffirstxbins, difffirstxmin, difffirstxmax);
+  TH1F* firstyhisto = new TH1F("Differences of first y (original - secondary) track", "Differences of first y (original - secondary) track", difffirstybins, difffirstymin, difffirstymax);
+ TH1F* firstzhisto = new TH1F("Differences of first z (original - secondary) track", "Differences of first z (original - secondary) track", difffirstzbins, difffirstzmin, difffirstzmax);
+ TH1F* lastxhisto = new TH1F("Differences of last x (original - secondary) track", "Differences of last x (original - secondary) track", difflastxbins, difflastxmin, difflastxmax);
+ TH1F* lastyhisto = new TH1F("Differences of last y (original - secondary) track", "Differences of last y (original - secondary) track", difflastybins, difflastymin, difflastymax);
+ TH1F* lastzhisto = new TH1F("Differences of last z (original - secondary) track", "Differences of last z (original - secondary) track", difflastzbins, difflastzmin, difflastzmax);
+ TH1F* pthisto = new TH1F("Differences of pt (original - secondary) track", "Differences of pt (original - secondary) track", diffptbins, diffptmin, diffptmax);
+ TH1F* psihisto = new TH1F("Differences of psi (original - secondary) track", "Differences of psi (original - secondary) track", diffpsibins, diffpsimin, diffpsimax);
+ TH1F* tglhisto = new TH1F("Differences of tgl (original - secondary) track", "Differences of tgl (original - secondary) track", difftglbins, difftglmin, difftglmax);
+ TH1F* clusterhisto = new TH1F("Differences of asserted clusters (original - secondary) track", "Differences of asserted clusters (original - secondary) track", diffclusterbins, diffclustermin, diffclustermax);
+
+#if 0
+ // commented out since pterr is zero for every track!
+ TH1F* pterrhisto = new TH1F("Differences of pt error (original - secondary) track", "Differences of pt error (original - secondary) track", diffpterrbins, diffpterrmin, diffpterrmax);
+ TH1F* psierrhisto = new TH1F("Differences of psi error (original - secondary) track", "Differences of psi error (original - secondary) track", diffpsierrbins, diffpsierrmin, diffpsierrmax);
+ TH1F* tglerrhisto = new TH1F("Differences of tgl error (original - secondary) track", "Differences of tgl error (original - secondary) track", difftglerrbins, difftglerrmin, difftglerrmax);
+
+#endif
+
+ // evaluate quality of fit:
+ TH1I* matchinghisto = new TH1I("Matching indicator (5 - 10)", "Matching indicator (5 - 10)", 11, 0, 11);
+
+  while(tracklistpointer != NULL)
+    {
+      // if currently processed track is matched, store differences of their parameters in histogram
+      if(tracklistpointer->matchingindicator > 0)
+       {
+         // matching track
+         trackmatchingpointer = tracklistpointer->matchingtrack;
+
+         if(relativedifferences == 1) // fill histogram with relative differences
+           {
+             firstxhisto->Fill((tracklistpointer->track.GetFirstPointX()-trackmatchingpointer->track.GetFirstPointX())/tracklistpointer->track.GetFirstPointX(),1);
+             firstyhisto->Fill((tracklistpointer->track.GetFirstPointY()-trackmatchingpointer->track.GetFirstPointY())/tracklistpointer->track.GetFirstPointY(),1);
+             firstzhisto->Fill((tracklistpointer->track.GetFirstPointZ()-trackmatchingpointer->track.GetFirstPointZ())/tracklistpointer->track.GetFirstPointZ(),1);
+             lastxhisto->Fill((tracklistpointer->track.GetLastPointX()-trackmatchingpointer->track.GetLastPointX())/tracklistpointer->track.GetLastPointX(),1);
+             lastyhisto->Fill((tracklistpointer->track.GetLastPointY()-trackmatchingpointer->track.GetLastPointY())/tracklistpointer->track.GetLastPointY(),1);
+             lastzhisto->Fill((tracklistpointer->track.GetLastPointZ()-trackmatchingpointer->track.GetLastPointZ())/tracklistpointer->track.GetLastPointZ(),1);
+             pthisto->Fill((tracklistpointer->track.GetPt()-trackmatchingpointer->track.GetPt())/tracklistpointer->track.GetPt(),1);
+             psihisto->Fill((tracklistpointer->track.GetPsi()-trackmatchingpointer->track.GetPsi())/tracklistpointer->track.GetPsi(),1);
+             tglhisto->Fill((tracklistpointer->track.GetTgl()-trackmatchingpointer->track.GetTgl())/tracklistpointer->track.GetTgl(),1);
+             clusterhisto->Fill((tracklistpointer->track.GetNHits()-trackmatchingpointer->track.GetNHits())/tracklistpointer->track.GetNHits(),1);
+
+#if 0
+             pterrhisto->Fill((tracklistpointer->track.GetPterr()-trackmatchingpointer->track.GetPterr())/tracklistpointer->track.GetPterr(),1);
+             psierrhisto->Fill((tracklistpointer->track.GetPsierr()-trackmatchingpointer->track.GetPsierr())/tracklistpointer->track.GetPsierr(),1);
+             tglerrhisto->Fill((tracklistpointer->track.GetTglerr()-trackmatchingpointer->track.GetTglerr())/tracklistpointer->track.GetTglerr(),1);
+
+             HLTInfo("Pterr: 1st:%f  2nd:%f   value:%f",tracklistpointer->track.GetPterr(),trackmatchingpointer->track.GetPterr(),(tracklistpointer->track.GetPterr()-trackmatchingpointer->track.GetPterr())/tracklistpointer->track.GetPterr());
+             HLTInfo("Psierr: 1st:%f  2nd:%f   value:%f",tracklistpointer->track.GetPsierr(),trackmatchingpointer->track.GetPsierr(),(tracklistpointer->track.GetPsierr()-trackmatchingpointer->track.GetPsierr())/tracklistpointer->track.GetPsierr());
+             HLTInfo("Tglerr: 1st:%f  2nd:%f   value:%f",tracklistpointer->track.GetTglerr(),trackmatchingpointer->track.GetTglerr(),(tracklistpointer->track.GetTglerr()-trackmatchingpointer->track.GetTglerr())/tracklistpointer->track.GetTglerr());
+#endif
+           }
+         else // otherwise fill histogram with absolute differences
+           {
+             firstxhisto->Fill(tracklistpointer->track.GetFirstPointX()-trackmatchingpointer->track.GetFirstPointX(),1);
+             firstyhisto->Fill(tracklistpointer->track.GetFirstPointY()-trackmatchingpointer->track.GetFirstPointY(),1);
+             firstzhisto->Fill(tracklistpointer->track.GetFirstPointZ()-trackmatchingpointer->track.GetFirstPointZ(),1);
+             lastxhisto->Fill(tracklistpointer->track.GetLastPointX()-trackmatchingpointer->track.GetLastPointX(),1);
+             lastyhisto->Fill(tracklistpointer->track.GetLastPointY()-trackmatchingpointer->track.GetLastPointY(),1);
+             lastzhisto->Fill(tracklistpointer->track.GetLastPointZ()-trackmatchingpointer->track.GetLastPointZ(),1);
+             pthisto->Fill(tracklistpointer->track.GetPt()-trackmatchingpointer->track.GetPt(),1);
+             psihisto->Fill(tracklistpointer->track.GetPsi()-trackmatchingpointer->track.GetPsi(),1);
+             tglhisto->Fill(tracklistpointer->track.GetTgl()-trackmatchingpointer->track.GetTgl(),1);
+             clusterhisto->Fill(tracklistpointer->track.GetNHits()-trackmatchingpointer->track.GetNHits(),1);
+#if 0
+             // commented out since pterr is always zero for every track!
+             pterrhisto->Fill(tracklistpointer->track.GetPterr()-trackmatchingpointer->track.GetPterr(),1);
+             psierrhisto->Fill(tracklistpointer->track.GetPsierr()-trackmatchingpointer->track.GetPsierr(),1);
+             tglerrhisto->Fill(tracklistpointer->track.GetTglerr()-trackmatchingpointer->track.GetTglerr(),1);
+#endif
+           }
+
+         // fill histogram that determines the quality of the fit
+         matchinghisto->Fill(tracklistpointer->matchingindicator,1);
+       }
+
+      tracklistpointer = tracklistpointer->next;
+    }
+
+  // write histograms to root file specified in command line argument -graphs <filename>.ROOT
+  if(!fGraphFileName.IsNull())
+    {
+      TFile* graphrootfile = new TFile(fGraphFileName, "recreate");
+
+       graphrootfile->WriteObject(firstxhisto,"firstxhistogram");
+      //firstxhisto->Write();
+      graphrootfile->WriteObject(firstyhisto,"firstyhistogram");
+      //firstyhisto->Write();
+      graphrootfile->WriteObject(firstzhisto,"firstzhistogram");
+      //firstzhisto->Write();
+      graphrootfile->WriteObject(lastxhisto,"lastxhistogram");
+      //lastxhisto->Write();
+      graphrootfile->WriteObject(lastyhisto,"lastyhistogram");
+      //lastyhisto->Write();
+      graphrootfile->WriteObject(lastzhisto,"lastzhistogram");
+      //lastzhisto->Write();
+      graphrootfile->WriteObject(pthisto,"pthistogram");
+      //pthisto->Write();
+      graphrootfile->WriteObject(psihisto,"psihistogram");
+      //psihisto->Write();
+      graphrootfile->WriteObject(tglhisto,"tglhistogram");
+      //tglhisto->Write();
+      graphrootfile->WriteObject(clusterhisto,"clusterhistogram");
+      //clusterhisto->Write();
+      graphrootfile->WriteObject(matchinghisto,"matchinghistogram");
+      //matchinghisto->Write();
+#if 0
+      // errors in tracking (commented out since pterr is always 0 for every track!)
+      graphrootfile->WriteObject(pterrhisto, "pterrhistogram");
+      //pterrhisto->Write();
+      graphrootfile->WriteObject(psierrhisto, "psierrhistogram");
+      //psierrhisto->Write();
+      graphrootfile->WriteObject(tglerrhisto, "tglerrhistogram");
+      //tglerrhisto->Write();
+#endif
+      graphrootfile->Close();
+    }
+  else
+    {
+      HLTError("Error! No file for graphical output specified.");
+      return EINVAL;
+    }
+
+  return 0;
+}
+
+Int_t AliHLTTPCCompModelAnalysis::DisplayModelResults()
+{
+  // see header file for class documentation
+
+  //print out parameters of discarded track:
+  AliHLTTPCTrackList* trackprintpointer = fTrackListPointer;
+  AliHLTTPCTrackList* tracklistdeleter= trackprintpointer;
+
+ FILE* dumpfile = NULL;
+
+ if(!fDumpFileName.IsNull())
+   {
+     // open new file specified by command line argument
+     dumpfile = fopen(fDumpFileName.Data(),"a");
+     fprintf(dumpfile,"---------------MODEL ANALYSIS--------------- \n");
+     fprintf(dumpfile,"---------------DISCARDED TRACKS: %d --------------- \n", fTrashTracks);
+   };
+ if(fTrackListPointer == NULL)
+   {
+     HLTInfo("No tracks discarded");
+     HLTInfo("--------------");
+   }
+ else
+   {
+     
+     HLTInfo("---------------DISCARDED TRACKS: %d ---------------", fTrashTracks);
+     
+     Int_t trashtrackcounter = 1;
+     
+     while(trackprintpointer != NULL)
+       {
+        
+        // infos about found track
+        HLTInfo("%d : Discarding track with %d clusters.", trashtrackcounter, trackprintpointer->track.GetNHits());
+        //PYTHIA INFORMATION ABOUT PARTICLE ID
+        HLTInfo("Track parameters of discarded track:");       
+        HLTInfo("First x: %9.6f \t first y: %9.6f \t first z: %9.6f",trackprintpointer->track.GetFirstPointX(),trackprintpointer->track.GetFirstPointY(),trackprintpointer->track.GetFirstPointZ()); 
+        HLTInfo(" Last x: %9.6f \t  last y: %9.6f \t  last z: %9.6f", trackprintpointer->track.GetLastPointX(),trackprintpointer->track.GetLastPointY(),trackprintpointer->track.GetLastPointZ());
+        HLTInfo("     Pt: %9.6f \t     Psi: %9.6f \t     Tgl: %9.6f", trackprintpointer->track.GetPt(), trackprintpointer->track.GetPsi(), trackprintpointer->track.GetTgl());
+        
+        // write results to file if specified by command line argument
+        if(!fDumpFileName.IsNull())
+          {
+            fprintf(dumpfile,"%d : Discarding track with %d clusters. \n", trashtrackcounter, trackprintpointer->track.GetNHits());
+            fprintf(dumpfile,"Track parameters of discarded track: \n");       
+            fprintf(dumpfile,"First x: %9.6f \t first y: %9.6f \t first z: %9.6f \n",trackprintpointer->track.GetFirstPointX(),trackprintpointer->track.GetFirstPointY(),trackprintpointer->track.GetFirstPointZ()); 
+            fprintf(dumpfile," Last x: %9.6f \t  last y: %9.6f \t  last z: %9.6f \n", trackprintpointer->track.GetLastPointX(),trackprintpointer->track.GetLastPointY(),trackprintpointer->track.GetLastPointZ());
+            fprintf(dumpfile,"     Pt: %9.6f \t     Psi: %9.6f \t     Tgl: %9.6f \n", trackprintpointer->track.GetPt(), trackprintpointer->track.GetPsi(), trackprintpointer->track.GetTgl());
+          };
+        
+        // comparison with pythia information
+        if(trackprintpointer->wronglydiscarded)
+          {
+            HLTInfo("Found track has been wrongly discarded according to Pythia information.");
+            
+            // write results to file if specified by command line argument
+            if(!fDumpFileName.IsNull())
+              {
+                 fprintf(dumpfile,"Found track has been wrongly discarded accoring to Pythia information. \n");
+              };
+            
+           };
+        
+        // found pt must be in range pt_pythia \pm 10% to be accepted
+        Double_t ptmin = trackprintpointer->pythiatrack.GetPt() - 0.1*trackprintpointer->pythiatrack.GetPt();
+        Double_t ptmax = trackprintpointer->pythiatrack.GetPt() + 0.1*trackprintpointer->pythiatrack.GetPt();
+        
+        if( (trackprintpointer->track.GetPt() < ptmin) ||(trackprintpointer->track.GetPt() > ptmax) )
+          {
+            HLTInfo("Pt of found track %f differs more than 10 %% from pt of pythia track %f.",trackprintpointer->track.GetPt(), trackprintpointer->pythiatrack.GetPt());
+            
+            if(!fDumpFileName.IsNull())
+              {
+                // write result to file if specified by command line argument
+                fprintf(dumpfile,"Pt of found track %f differs more than 10 %% from pt of pythia track %f. \n",trackprintpointer->track.GetPt(), trackprintpointer->pythiatrack.GetPt());
+              };
+            
+          };
+        
+        HLTInfo("--------------");
+        
+        if(!fDumpFileName.IsNull())
+          {
+            fprintf(dumpfile,"-------------- \n");
+          }; 
+        
+        
+         // go to next element in trash track list
+        tracklistdeleter = trackprintpointer;
+        trackprintpointer = trackprintpointer->next;
+        
+        ++trashtrackcounter;
+        
+        // free space 
+        delete tracklistdeleter;
+        tracklistdeleter = NULL;
+        
+       } // end of while(trackpointer != NULL)
+
+   } // end of else
+ // print out number of noise clusters (not assigned to any track and not valid)
+ HLTInfo("Number of discarded clusters not assigned to any track: %d", fTotalDiscardedClusters);
+ HLTInfo("--------------");
+
+ // write results to file if specified by command line argument
+ if(!fDumpFileName.IsNull())
+   {
+     fprintf(dumpfile,"Number of discarded clusters not assigned to any track: %d \n", fTotalDiscardedClusters);
+     fprintf(dumpfile,"-------------- \n");
+   };
+ // print out paramters of discarded valuable clusters
+ HLTInfo("Number of discarded VALUABLE clusters: %d", fValuableDiscardedClusters);
+
+ HLTInfo("--------------");
+ if(!fDumpFileName.IsNull())
+   {
+
+     fprintf(dumpfile,"Number of discarded VALUABLE clusters: %d \n", fValuableDiscardedClusters);
+     fclose(dumpfile);
+   };
+  return 0;
+}
+
+Int_t AliHLTTPCCompModelAnalysis::DisplayTrackResults()
+{
+  // see header file for class documentation
+  // start with comparison
+  if(CompareTracks() != 0)
+    {
+      return EINVAL;
+    };
+
+  // if dumptofile is activated, append results to output analysis file
+  FILE* dumpfile = NULL;
+  
+  if(!fDumpFileName.IsNull())
+    {
+      // open new file specified by command line argument
+      dumpfile = fopen(fDumpFileName.Data(),"a");
+      
+      fprintf(dumpfile,"---------------TRACK ANALYSIS--------------- \n");
+      
+    }
+  
+  // print out number of compared tracks
+  HLTInfo("---------------ORIGINAL TRACKS: %d ---------------", fFirstTrackArray.GetNTracks());
+  HLTInfo("Number of tracks with pt < 0.1 GeV: %d", fFirstTrashTracks);
+  HLTInfo("Number of matched tracks with pt < 0.1 GeV: %d", fMatchedFirstTrashTracks);
+  //PYTHIA INFORMATION ABOUT PARTICLE IDs
+  HLTInfo("---------------2NDARY TRACKS: %d ---------------", fSecondTrackArray.GetNTracks());
+  HLTInfo("Number of tracks with pt < 0.1 GeV: %d", fSecondTrashTracks);
+  HLTInfo("Number of matched tracks with pt < 0.1 GeV: %d", fMatchedSecondTrashTracks);
+  //PYTHIA INFORMATION ABOUT PARTICLE IDs
+  HLTInfo("--------------");
+  HLTInfo("Comparison of tracks within parameter precision: %f", fToleranceDeviation);
+  HLTInfo("Number of compared tracks: %d", fTotalComparedTracks);
+  HLTInfo("Number of unmatched original tracks: %d", fFirstUnmatchedTracks);
+  HLTInfo("Number of unmatched secondary tracks: %d", fSecondUnmatchedTracks);
+  HLTInfo("--------------");
+  
+  // print results to file
+  if(!fDumpFileName.IsNull())
+    {
+      fprintf(dumpfile, "---------------%d ORIGINAL TRACKS---------------\n", fFirstTrackArray.GetNTracks());
+      fprintf(dumpfile,"Number of tracks with pt < 0.1 GeV: %d \n", fFirstTrashTracks);
+      fprintf(dumpfile,"Number of matched tracks with pt < 0.1 GeV: %d \n", fMatchedFirstTrashTracks);
+      fprintf(dumpfile,"---------------%d 2NDARY TRACKS---------------\n", fSecondTrackArray.GetNTracks());
+      fprintf(dumpfile,"Number of tracks with pt < 0.1 GeV: %d \n", fSecondTrashTracks);
+      fprintf(dumpfile,"Number of matched tracks with pt < 0.1 GeV: %d \n", fMatchedSecondTrashTracks);
+      fprintf(dumpfile,"--------------\n");
+      fprintf(dumpfile,"Comparison of tracks within parameter precision: %f \n", fToleranceDeviation);
+      fprintf(dumpfile,"Number of compared tracks: %d \n", fTotalComparedTracks); 
+      fprintf(dumpfile,"Number of unmatched original tracks: %d \n", fFirstUnmatchedTracks); 
+      fprintf(dumpfile,"Number of unmatched secondary tracks: %d \n", fSecondUnmatchedTracks); 
+      fprintf(dumpfile,"--------------\n");
+    }
+
+  //////////////////////////////////////////////////////////////////////
+  // additional files temporarily necessary for output information
+  FILE* infofile = fopen("/afsuser/jwagner/TrackerTest_25092007/cosmics/fullanalysis08012008/trackingefficiency.out","a");
+  FILE* info2file = fopen("/afsuser/jwagner/TrackerTest_25092007/cosmics/fullanalysis08012008/parameters.out", "a");
+
+  // consistent = 0 if tracks and second tracks match perfectly, i.e. no doubly assigned tracks,etc.
+  Int_t consistentfirst = fFirstTrackArray.GetNTracks() - fTotalComparedTracks - fFirstUnmatchedTracks;
+  Int_t consistentsecond = fSecondTrackArray.GetNTracks() - fTotalComparedTracks - fSecondUnmatchedTracks;
+
+  //fprintf(infofile, "1st tracks, 2nd tracks, compared, 1st uncompared, 2nd uncompared, cons.1st, cons.2nd \n");
+  fprintf(info2file, " %d \t %d \t %d \t %d \t %d \t %d \t %d \n", fFirstTrackArray.GetNTracks(), fSecondTrackArray.GetNTracks(), fTotalComparedTracks, fFirstUnmatchedTracks, fSecondUnmatchedTracks, consistentfirst, consistentsecond);
+
+  //fprintf(infofile, "1st trash tracks, 2nd trash tracks, 1st matched trash tracks, 2nd matched trash tracks \n");
+  fprintf(infofile, "%d \t %d \t %d \t %d \n", fFirstTrashTracks, fSecondTrashTracks, fMatchedFirstTrashTracks, fMatchedSecondTrashTracks);
+
+  fclose(infofile);
+  fclose(info2file);
+  ////////////////////////////////////////////////////////////////////
+
+  // print out deviations
+  Int_t tracknumber = 1;
+  AliHLTTPCTrackList* listprintpointer = fFirstTrackList;
+  while(listprintpointer != NULL)
+    {
+      // print out parameters of original track in comparison to secondary track:
+      
+      if(listprintpointer->matchingindicator != 0)
+       {
+         
+#if 0
+         HLTInfo("Track %d:", tracknumber);
+         HLTInfo("Original track matched to secondary track with matchingindicator %d", listprintpointer->matchingindicator);
+         
+         HLTInfo("Parameter comparison: Original vs. Secondary");
+
+         HLTInfo("Clusters: %d \t %d ",listprintpointer->track.GetNHits(), listprintpointer->matchingtrack->track.GetNHits());
+         HLTInfo("First x: %9.6f \t %9.6f", listprintpointer->track.GetFirstPointX(), listprintpointer->matchingtrack->track.GetFirstPointX());
+         HLTInfo("First y: %9.6f \t %9.6f", listprintpointer->track.GetFirstPointY(), listprintpointer->matchingtrack->track.GetFirstPointY());
+         HLTInfo("First z: %9.6f \t %9.6f", listprintpointer->track.GetFirstPointZ(), listprintpointer->matchingtrack->track.GetFirstPointZ()); 
+         HLTInfo("Last x: %9.6f \t %9.6f", listprintpointer->track.GetLastPointX(), listprintpointer->matchingtrack->track.GetLastPointX());
+         HLTInfo("Last y: %9.6f \t %9.6f", listprintpointer->track.GetLastPointY(), listprintpointer->matchingtrack->track.GetLastPointY());
+         HLTInfo("Last z: %9.6f \t %9.6f", listprintpointer->track.GetLastPointZ(), listprintpointer->matchingtrack->track.GetLastPointZ());
+         HLTInfo("    Pt: %9.6f \t %9.6f", listprintpointer->track.GetPt(), listprintpointer->matchingtrack->track.GetPt());  
+         HLTInfo("   Psi: %9.6f \t %9.6f", listprintpointer->track.GetPsi(), listprintpointer->matchingtrack->track.GetPsi());
+         HLTInfo("   Tgl: %9.6f \t %9.6f", listprintpointer->track.GetTgl(), listprintpointer->matchingtrack->track.GetTgl());
+
+         HLTInfo(" Pterr: %9.6f \t %9.6f", listprintpointer->track.GetPterr(), listprintpointer->matchingtrack->track.GetPterr());  
+         HLTInfo("Psierr: %9.6f \t %9.6f", listprintpointer->track.GetPsierr(), listprintpointer->matchingtrack->track.GetPsierr());
+         HLTInfo("Tglerr: %9.6f \t %9.6f", listprintpointer->track.GetTglerr(), listprintpointer->matchingtrack->track.GetTglerr());
+        
+         HLTInfo("--------------");
+#endif
+         // print these results to file
+         if(!fDumpFileName.IsNull())
+           {
+             fprintf(dumpfile, "Track %d: \n", tracknumber);
+             fprintf(dumpfile, "Original track matched to secondary track with matchingindicator %d \n", listprintpointer->matchingindicator); 
+             fprintf(dumpfile, "Parameter comparison: Original vs. Secondary \n"); 
+             fprintf(dumpfile, "Clusters: %d \t %d \n ",listprintpointer->track.GetNHits(), listprintpointer->matchingtrack->track.GetNHits());
+             fprintf(dumpfile, "First x: %9.6f \t %9.6f \n", listprintpointer->track.GetFirstPointX(), listprintpointer->matchingtrack->track.GetFirstPointX());
+             fprintf(dumpfile, "First y: %9.6f \t %9.6f \n", listprintpointer->track.GetFirstPointY(), listprintpointer->matchingtrack->track.GetFirstPointY()); 
+             fprintf(dumpfile, "First z: %9.6f \t %9.6f \n", listprintpointer->track.GetFirstPointZ(), listprintpointer->matchingtrack->track.GetFirstPointZ()); 
+             fprintf(dumpfile, "Last x: %9.6f \t %9.6f \n", listprintpointer->track.GetLastPointX(), listprintpointer->matchingtrack->track.GetLastPointX());  
+             fprintf(dumpfile, "Last y: %9.6f \t %9.6f \n", listprintpointer->track.GetLastPointY(), listprintpointer->matchingtrack->track.GetLastPointY());
+             fprintf(dumpfile, "Last z: %9.6f \t %9.6f \n", listprintpointer->track.GetLastPointZ(), listprintpointer->matchingtrack->track.GetLastPointZ());
+             fprintf(dumpfile, "    Pt: %9.6f \t %9.6f \n", listprintpointer->track.GetPt(), listprintpointer->matchingtrack->track.GetPt());  
+             fprintf(dumpfile, "   Psi: %9.6f \t %9.6f \n", listprintpointer->track.GetPsi(), listprintpointer->matchingtrack->track.GetPsi()); 
+             fprintf(dumpfile, "   Tgl: %9.6f \t %9.6f \n", listprintpointer->track.GetTgl(), listprintpointer->matchingtrack->track.GetTgl());
+             fprintf(dumpfile, "--------------\n");
+           }
+         ++tracknumber;
+       }
+     
+      listprintpointer = listprintpointer->next;
+    }
+
+
+  // print out not matched tracks from first track array:
+  listprintpointer = fFirstTrackList;
+  Int_t notmatchedtracknumber = 1;
+
+  while(listprintpointer != NULL)
+    {
+      if(listprintpointer->matchingindicator == 0)
+       {
+#if 0    
+         HLTInfo("Original Track, not matched with secondary track %d:", notmatchedtracknumber);
+         HLTInfo("Clusters: %d",listprintpointer->track.GetNHits());
+         //PYTHIA INFORMATION ABOUT PARTICLE ID
+         HLTInfo("First x: %9.6f \t first y: %9.6f \t first z: %9.6f",listprintpointer->track.GetFirstPointX(),listprintpointer->track.GetFirstPointY(),listprintpointer->track.GetFirstPointZ()); 
+         HLTInfo(" Last x: %9.6f \t  last y: %9.6f \t  last z: %9.6f", listprintpointer->track.GetLastPointX(),listprintpointer->track.GetLastPointY(),listprintpointer->track.GetLastPointZ());
+         HLTInfo("     Pt: %9.6f \t     Psi: %9.6f \t     Tgl: %9.6f", listprintpointer->track.GetPt(), listprintpointer->track.GetPsi(), listprintpointer->track.GetTgl());
+         HLTInfo("--------------");
+#endif
+         // print these results to file
+         if(!fDumpFileName.IsNull())
+           {
+             fprintf(dumpfile, "Original Track, not matched with secondary track %d: \n", notmatchedtracknumber); 
+             fprintf(dumpfile, "Clusters: %d \n",listprintpointer->track.GetNHits());
+             fprintf(dumpfile, "First x: %9.6f \t first y: %9.6f \t first z: %9.6f \n",listprintpointer->track.GetFirstPointX(),listprintpointer->track.GetFirstPointY(),listprintpointer->track.GetFirstPointZ());
+             fprintf(dumpfile, " Last x: %9.6f \t  last y: %9.6f \t  last z: %9.6f \n", listprintpointer->track.GetLastPointX(),listprintpointer->track.GetLastPointY(),listprintpointer->track.GetLastPointZ());
+             fprintf(dumpfile, "     Pt: %9.6f \t     Psi: %9.6f \t     Tgl: %9.6f \n", listprintpointer->track.GetPt(), listprintpointer->track.GetPsi(), listprintpointer->track.GetTgl()); 
+             fprintf(dumpfile, "--------------\n");
+           }
+
+         ++notmatchedtracknumber;
+       }
+
+      listprintpointer = listprintpointer->next;
+    }
+
+  // print out not matched tracks from second track array:
+  listprintpointer = fSecondTrackList;
+  notmatchedtracknumber = 1;
+
+  while(listprintpointer != NULL)
+    {
+      if(listprintpointer->matchingindicator == 0)
+       {
+#if 0    
+         HLTInfo("Secondary Track, not matched with original track %d:", notmatchedtracknumber);
+         HLTInfo("Clusters: %d",listprintpointer->track.GetNHits());
+         //PYTHIA INFORMATION ABOUT PARTICLE ID        
+         HLTInfo("First x: %9.6f \t first y: %9.6f \t first z: %9.6f",listprintpointer->track.GetFirstPointX(),listprintpointer->track.GetFirstPointY(),listprintpointer->track.GetFirstPointZ()); 
+         HLTInfo(" Last x: %9.6f \t  last y: %9.6f \t  last z: %9.6f", listprintpointer->track.GetLastPointX(),listprintpointer->track.GetLastPointY(),listprintpointer->track.GetLastPointZ());
+         HLTInfo("     Pt: %9.6f \t     Psi: %9.6f \t     Tgl: %9.6f", listprintpointer->track.GetPt(), listprintpointer->track.GetPsi(), listprintpointer->track.GetTgl());
+         HLTInfo("--------------");
+#endif 
+         // print these results to file
+         if(!fDumpFileName.IsNull())
+           {
+             fprintf(dumpfile, "Secondary Track, not matched with original track %d: \n", notmatchedtracknumber);
+             fprintf(dumpfile, "Clusters: %d \n",listprintpointer->track.GetNHits());
+             fprintf(dumpfile, "First x: %9.6f \t first y: %9.6f \t first z: %9.6f \n",listprintpointer->track.GetFirstPointX(),listprintpointer->track.GetFirstPointY(),listprintpointer->track.GetFirstPointZ()); 
+             fprintf(dumpfile, " Last x: %9.6f \t  last y: %9.6f \t  last z: %9.6f \n", listprintpointer->track.GetLastPointX(),listprintpointer->track.GetLastPointY(),listprintpointer->track.GetLastPointZ());
+             fprintf(dumpfile, "     Pt: %9.6f \t     Psi: %9.6f \t     Tgl: %9.6f \n", listprintpointer->track.GetPt(), listprintpointer->track.GetPsi(), listprintpointer->track.GetTgl());
+             fprintf(dumpfile, "--------------\n");
+           }
+
+         ++notmatchedtracknumber;
+       }
+
+      listprintpointer = listprintpointer->next;
+    }
+
+  // close output analysis file
+ if(!fDumpFileName.IsNull())
+   {
+     fclose(dumpfile);
+   };
+
+ // if results should be written to graphical output:
+ if(!fGraphFileName.IsNull())
+   {
+     CreateGraphs(1); // specifiy if absolute or rel. differences should be saved (CreateGraphs(0) or CreateGraphs()/ CreateGraphs(1)
+   };
+  // free reserved space
+  
+  return 0;
+}
diff --git a/HLT/TPCLib/comp/AliHLTTPCCompModelAnalysis.h b/HLT/TPCLib/comp/AliHLTTPCCompModelAnalysis.h
new file mode 100644 (file)
index 0000000..8885d71
--- /dev/null
@@ -0,0 +1,210 @@
+// XEmacs -*-C++-*-
+// $Id: AliHLTTPCCompModelAnalysis.h,v 1.2 2006/08/10 09:46:51 richterm Exp $
+
+#ifndef ALIHLTTPCCOMPMODELANALYSIS_H
+#define ALIHLTTPCCOMPMODELANALYSIS_H
+/* TPCCompModelAnalysisright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full TPCCompModelAnalysisright notice                               */
+
+/** @file   AliHLTTPCCompModelAnalysis.h
+    @author J. Wagner
+    @date   17-11-2007
+    @brief   A HLT processing component for the Vestbo-compression-model */
+
+#include "AliHLTTPCTrackArray.h"
+#include "AliHLTTPCTrackletDataFormat.h"
+#include "AliHLTTPCClusterDataFormat.h"
+#include "AliHLTTPCTrack.h"
+#include "AliHLTTPCModelTrack.h"
+#include "TFile.h"
+#include "TH1.h"
+#include "AliHLTLogging.h"
+
+/**
+ * @class AliHLTTPCCompModelAnalysis
+ * @brief A HLT processing component for the Vestbo-compression-model 
+ *
+ * An implementiation of a class that is used to analyse the 
+ * loss due to the conversion / compression in the Vestbo-model
+ * resolution change due to Vestbo-model on tracking performance
+ * @ingroup alihlt_tutorial
+ */
+class AliHLTTPCCompModelAnalysis: public AliHLTLogging
+{
+public:
+
+
+  /** type needed to build list with discarded tracks or tracks to compare */
+  struct AliHLTTPCTrackList
+  {
+    AliHLTTPCTrack track;       // store information of found discarded track   
+    AliHLTTPCTrack pythiatrack; // store pythia information about this found discarded track
+    Bool_t wronglydiscarded;    // flag to mark if track and pythia track information match together
+    Int_t matchingindicator;    // only for trackanalysis the higher the number, the more probable it is that tracks match
+    AliHLTTPCTrackList* next;   // pointer to next struct
+    AliHLTTPCTrackList* matchingtrack; // pointer to matching track (only used in trackanalysis)
+  };
+  typedef struct AliHLTTPCTrackList AliHLTTPCTrackList;
+
+  AliHLTTPCCompModelAnalysis(Bool_t modelanalysis, Bool_t trackanalysis, TString dumpfilename, TString graphfilename);
+  virtual ~AliHLTTPCCompModelAnalysis();
+
+  /** initialise track or cluster arrays depending on the analysis to be made
+   * @return 0 upon success
+   */  
+  Int_t Init();
+
+  /** display results for respective analysis type (track comparison or model loss analysis) 
+   * @return 0 upon success
+   */
+  Int_t DisplayResults();
+
+  /** function to retrieve private member variable fModelAnalysis used in ModelConverter 
+   * @return 0 if fModelAnalysis is switched off
+   * @return 1 if fModelAnalysis is switched on
+   */
+  Bool_t GetfModelAnalysis() {return fModelAnalysis;};
+
+  /** function to retrieve private member variable fTrackAnalysis used in ModelConverter
+   * @return 0 if fTrackAnalysis is switched off
+   * @return 1 if fTrackAnalysis is switched on
+   */
+  Bool_t GetfTrackAnalysis() {return fTrackAnalysis;};
+
+  /** fill track arrays with track data from original and secondary tracking 
+   * @param firsttracklets      pointer to track array to be filled
+   * @param fillingfirsttracks  boolean to decide which track array is to be filled (1 for first, 0 for second)
+   * @return 0 upon success
+   */
+  Int_t SetTracks(AliHLTTPCTrackletData* tracklets, Bool_t fillingfirsttracks);
+
+ /** store discarded tracks in model analysis to be displayed in @ref DisplayModelResults(),
+  * uses @ref GetTrashTrackPythiaInfo
+  * @param lowpttrack  pointer to discarded track which is to be remembered for analysis
+  * @return 0 upon success
+  */
+  Int_t MarkTrashTrack(AliHLTTPCTrack* lowpttrack);
+
+  /** store discarded cluster not assigned to any track in model analysis to be displayed in @ref DisplayModelResults(),
+   * uses @ref GetClusterPythiaInfo
+   * @param discardedcluster  cluster data of discarded cluster
+   * @param slice             slice where discarded cluster occurrs
+   * @param patch             patch where discarded cluster occurrs
+   * @return 0 upon success
+   */
+  Int_t MarkTrashCluster(AliHLTTPCClusterData *discardedcluster, UInt_t slice, UInt_t patch);
+private:
+  /** copy constructor prohibited */
+  AliHLTTPCCompModelAnalysis(const AliHLTTPCCompModelAnalysis&);
+  /** assignment operator prohibited */
+  AliHLTTPCCompModelAnalysis& operator=(const AliHLTTPCCompModelAnalysis&);
+
+  /** private function to display results from model loss analysis
+   * @return 0 upon success
+   */
+  Int_t DisplayModelResults();
+
+  /** private function to display results from track comparison 
+   * @return 0 upon success
+   */
+  Int_t DisplayTrackResults();
+
+ /** compare tracks and store differences to be displayed in @ref DisplayTrackResults() 
+  * @return 0 upon success
+  */
+  Int_t CompareTracks();
+
+  /** get Pythia information about tracks in track comparison
+   * @param comparabletrack track to look for pythia information
+   * @return pythiatrack    track information from pythia lookup
+   */
+  AliHLTTPCTrack GetComparableTrackPythiaInfo(AliHLTTPCTrack comparabletrack);
+
+  /** compare discarded track parameters with parameters from Pythia event
+   * @param discardedtrack  pointer to a discarded track (usually with low pt)
+   * @return 0 upon correct decision (track with low pt accoridng to Pythia, i.e. track = delta-electron or similar noise)
+   * @return 1 upon wrong decision (track wrongly discarded, should by taken into account according to Pythia information)
+   */
+  Bool_t GetTrashTrackPythiaInfo(AliHLTTPCTrack* discardedtrack);
+
+  /** compare information of a cluster not assigned to any track with its Pythia information
+   * @param discarded cluster  pointer to discarded cluster
+   * @return 0 upon correct decision (cluster not assigned to any track is true in Pythia, i.e. cluster = noise cluster)
+   * @return 1 upon wrong decision (cluster wrongly discarded, i.e. it belongs to a valuable track according to Pythia)
+   */
+  Bool_t GetClusterPythiaInfo(AliHLTTPCClusterData* discardedcluster);
+
+  /** compare two tracks in order to find if the match
+   * @param firsttracklistelement   track from orignal tracking, stored in AliHLTTPCTrackList
+   * @param secondtracklistelement  track from secondary tracking, stored in AliHLTTPCTrackList
+   * @return matchingindicator      if all parameters are equal: matchingindicator = 10
+   */
+  Int_t CompareTrackInfo(AliHLTTPCTrackList* firsttracklistelement, AliHLTTPCTrackList* secondtracklistelement);
+
+  /** compare two pythia tracks in order to find if the match
+   * @param firsttracklistelement   track from orignal tracking, stored in AliHLTTPCTrackList
+   * @param secondtracklistelement  track from secondary tracking, stored in AliHLTTPCTrackList
+   * @return matchingindicator      if all pythia parameters are equal: matchingindicator = 10 (should be so!)
+   */
+  Int_t ComparePythiaTrackInfo(AliHLTTPCTrackList* firsttracklistelement, AliHLTTPCTrackList* secondtracklistelement);
+
+  /** if -graphfile <filename>.root is given as input parameter, histrograms are created
+   * @param relativedifferences boolean to decide whether to plot histograms 
+   *                            with relative differences in track paramters (1) or not (0), 1 by default
+   * @return 0 upon success
+   */
+  Int_t CreateGraphs(Bool_t relativedifferences = 1);
+
+  /** flag to decide wheter to do track or model loss analysis */
+  Bool_t fModelAnalysis; // switch on model analysis
+  Bool_t fTrackAnalysis; // switch on track analysis
+
+  /** name of humanly readable dump file for analysis results */
+  TString fDumpFileName;
+  /** name of root file name to store histograms of track comparison */
+  TString fGraphFileName;
+  /** members for track analysis:  */
+  /** array with original tracks from first tracking */
+  AliHLTTPCTrackArray fFirstTrackArray;  // array to store tracks of first tracking
+  /** array with tracks from secondary tracking with Vestbo-decompressed clusters */
+  AliHLTTPCTrackArray fSecondTrackArray; // array to store tracks of second tracking (after compression/expansion of model)
+  /** pointer to first element of first track list containing tracks and their pythia information  */
+  AliHLTTPCTrackList* fFirstTrackList;
+  /** pointer to first element of second track list containing tracks and their pythia information */
+  AliHLTTPCTrackList* fSecondTrackList;
+  /** number of tracks with pt < 0.1GeV in first array */
+  Int_t fFirstTrashTracks;
+  /** number of tracks with pt < 0.1GeV in second array */
+  Int_t fSecondTrashTracks;
+  /** total number of compared tracks */
+  Int_t fTotalComparedTracks;
+  /** number of matched tracks under 0.1 GeV in first array */
+  Int_t fMatchedFirstTrashTracks;
+  /** number of matched tracks under 0.1 GeV in second array */
+  Int_t fMatchedSecondTrashTracks;
+  /** number of original tracks that do not have secondary track matches */
+  Int_t fFirstUnmatchedTracks;
+  /** number of secondary tracks that do not have original track matches */
+  Int_t fSecondUnmatchedTracks;
+  /** tolerance limits of relative deviation of compared track quantities, set in Init() */
+  Float_t fToleranceDeviation;  // (firstparameter - secondparameter)/firstparameter <= fToleranceDeviation
+
+  /** members for model analysis: */
+  /** pointer to list of discarded tracks */
+  AliHLTTPCTrackList* fTrackListPointer; // pointer to list of discarded tracks
+  /** array of discarded clusters */
+  AliHLTTPCClusterData* fDiscardedClusters[36][6]; // array of discarded valuable clusters
+  
+  /** total number of discarded clusters not assigned to any track per event */
+  Int_t fTotalDiscardedClusters;    // number of discarded clusters
+  /** total number of wrongly discarded clusters according to Pythia information per event */
+  Int_t fValuableDiscardedClusters; // number of discarded clusters which should be assigned to a track 
+  /** total number of discarded tracks per event */
+  Int_t fTrashTracks;               // number of discarded tracks (pt lower 0.1 GeV)
+
+  ClassDef(AliHLTTPCCompModelAnalysis, 1)
+  
+};
+#endif
diff --git a/HLT/TPCLib/comp/AliHLTTPCCompModelConverter.cxx b/HLT/TPCLib/comp/AliHLTTPCCompModelConverter.cxx
new file mode 100644 (file)
index 0000000..a30fefe
--- /dev/null
@@ -0,0 +1,827 @@
+// $Id: AliHLTTPCCompModelConverter.cxx,v 1.2 2006/08/10 09:46:51 richterm Exp $
+
+/**************************************************************************
+ * TPCCompModelConverterright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Authors: 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.                  *
+ **************************************************************************/
+
+/** @file   AliHLTTPCCompModelConverter.cxx
+    @author Timm Steinbeck
+    @author changed by J. Wagner
+    @date   17-11-2007
+    @brief  A copy processing component for the HLT. */
+
+#if __GNUC__ >= 3
+using namespace std;
+#endif
+
+#include "AliHLTTPCCompModelConverter.h"
+#include "AliHLTTPCTransform.h"
+#include "AliHLTTPCTrack.h"
+#include "AliHLTTPCModelTrack.h"
+#include "AliHLTTPCCompDataCompressorHelper.h"
+#include <cerrno>
+
+AliHLTTPCCompModelConverter::AliHLTTPCCompModelConverter():
+  fInputTrackArray(),
+  fOutputTrackArray("AliHLTTPCModelTrack"),
+  fMinHits(0),
+  fModelAnalysisInstance(NULL)
+    {
+      // see header file for class documentation
+      for ( UInt_t slice=0; slice<36; slice++ )
+       for ( UInt_t patch=0; patch<6; patch++ )
+         {
+           fClusterUsedSizes[slice][patch] = 0;
+           fClusterUsed[slice][patch] = NULL;
+         }
+      Init();
+      fMinHits = 5;
+    }
+
+AliHLTTPCCompModelConverter::AliHLTTPCCompModelConverter(AliHLTTPCCompModelAnalysis* modelanalysis):
+  fInputTrackArray(),
+  fOutputTrackArray("AliHLTTPCModelTrack"),
+  fMinHits(0),
+  fModelAnalysisInstance(modelanalysis)
+    {
+      // see header file for class documentation
+      for ( UInt_t slice=0; slice<36; slice++ )
+       for ( UInt_t patch=0; patch<6; patch++ )
+         {
+           fClusterUsedSizes[slice][patch] = 0;
+           fClusterUsed[slice][patch] = NULL;
+         }
+      Init();
+      fMinHits = 5;
+    }
+
+AliHLTTPCCompModelConverter::~AliHLTTPCCompModelConverter()
+    {
+      // see header file for class documentation
+      for ( UInt_t slice=0; slice<36; slice++ )
+       for ( UInt_t patch=0; patch<6; patch++ )
+         {
+           if ( fClusterUsed[slice][patch] )
+             {
+               delete [] fClusterUsed[slice][patch];
+               fClusterUsed[slice][patch] = NULL;
+             }
+         }
+    }
+
+int AliHLTTPCCompModelConverter::Init()
+    {
+      // see header file for class documentation
+      fInputTrackArray.Reset();
+      fOutputTrackArray.Reset();
+      for ( UInt_t slice=0; slice<36; slice++ )
+       for ( UInt_t patch=0; patch<6; patch++ )
+         fClusters[slice][patch] = NULL;
+      
+      return 0;
+    }
+
+int AliHLTTPCCompModelConverter::SetInputTracks( AliHLTTPCTrackletData* tracklets )
+    {
+      // see header file for class documentation
+      HLTDebug( "Filling %u tracks", (unsigned)tracklets->fTrackletCnt );
+      fInputTrackArray.FillTracks( tracklets->fTrackletCnt, tracklets->fTracklets );
+      return 0;
+    }
+
+int AliHLTTPCCompModelConverter::SetInputClusters( AliHLTTPCClusterData* clusters, UInt_t slice, UInt_t patch )
+    {
+      // see header file for class documentation
+      if ( slice>=36 || patch>=6 )
+       return EINVAL;
+      if ( fClusters[slice][patch] )
+       return EBUSY;
+      fClusters[slice][patch] = clusters;
+      if ( fClusterUsedSizes[slice][patch]<clusters->fSpacePointCnt ||
+          fClusterUsedSizes[slice][patch]>clusters->fSpacePointCnt*8 )
+       {
+         delete [] fClusterUsed[slice][patch];
+         fClusterUsed[slice][patch] = NULL;
+       }
+      if ( !fClusterUsed[slice][patch] )
+       {
+         fClusterUsed[slice][patch] = new bool[clusters->fSpacePointCnt];
+         if ( !fClusterUsed[slice][patch] )
+           {
+             HLTDebug( "Out of memory trying to allocate usage data for  %u clusters", (unsigned)clusters->fSpacePointCnt );
+             return ENOMEM;
+           }
+       }
+      for ( unsigned long nn=0; nn<clusters->fSpacePointCnt; nn++ )
+       fClusterUsed[slice][patch][nn]=false;
+      HLTDebug( "Filling %u clusters", (unsigned)clusters->fSpacePointCnt );
+      return 0;
+    }
+
+void AliHLTTPCCompModelConverter::Convert()
+    {
+      // see header file for class documentation
+      fInputTrackArray.QSort();
+      for(Int_t i=0; i<fInputTrackArray.GetNTracks(); i++)
+       {
+         AliHLTTPCTrack *intrack = fInputTrackArray.GetCheckedTrack(i);
+         
+         // NO WARNING IF intrack = NULL!
+         if(!intrack) continue;
+         
+         if((unsigned)intrack->GetNHits()<fMinHits) 
+           {
+             HLTDebug("Track %d with %d clusters is below minimum of %d clusters",i,intrack->GetNHits(),fMinHits);
+             break;
+           };
+         
+         // LOSS OF TRACKS due to following statement possible!
+         if(intrack->GetPt()<0.1)
+           {
+             HLTDebug("Discarding track with low pt.");
+             if(fModelAnalysisInstance)
+               {
+                 if(fModelAnalysisInstance->GetfModelAnalysis()) // analysis of model
+                   {
+                     fModelAnalysisInstance->MarkTrashTrack(intrack);
+                   }
+               }
+             
+             continue;
+           }
+         
+         intrack->CalculateHelix();
+         
+         AliHLTTPCModelTrack *outtrack = (AliHLTTPCModelTrack*)fOutputTrackArray.NextTrack();
+         outtrack->SetNHits(intrack->GetNHits());
+         outtrack->SetRowRange(intrack->GetFirstRow(),intrack->GetLastRow());
+         outtrack->SetFirstPoint(intrack->GetFirstPointX(),intrack->GetFirstPointY(),intrack->GetFirstPointZ());
+         outtrack->SetLastPoint(intrack->GetLastPointX(),intrack->GetLastPointY(),intrack->GetLastPointZ());
+         outtrack->SetPt(intrack->GetPt());
+         outtrack->SetPsi(intrack->GetPsi());
+         outtrack->SetTgl(intrack->GetTgl());
+         outtrack->SetCharge(intrack->GetCharge());
+         outtrack->CalculateHelix();
+         Int_t nhits = intrack->GetNHits();
+         UInt_t *hitids = intrack->GetHitNumbers();
+         Int_t origslice = (hitids[nhits-1]>>25)&0x7f;
+         outtrack->Init(origslice,-1);
+         
+         for(Int_t j=nhits-1; j>=0; j--)
+           {
+             UInt_t id=hitids[j];
+             Int_t slice = (id>>25)&0x7f;
+             Int_t patch = (id>>22)&0x7;
+             UInt_t pos = id&0x3fffff;      
+             
+             //UInt_t size;
+             if ( !fClusters[slice][patch] )
+               {
+                 //HLTWarning( "No clusters for slice %d, patch %d", slice, patch );
+                 continue;
+               }
+           if ( !fClusterUsed[slice][patch] )
+             {
+               HLTWarning( "No cluster used data for slice %d, patch %d", slice, patch );
+               continue;
+             }
+           if ( fClusters[slice][patch]->fSpacePointCnt<=pos )
+               {
+                 HLTWarning( "Clusters position %d too large in slice %d, patch %d (%u max.)", pos,
+                             slice, patch, fClusters[slice][patch]->fSpacePointCnt );
+                 continue;
+               }
+           
+           AliHLTTPCSpacePointData *points = fClusters[slice][patch]->fSpacePoints;
+           bool* clustersUsed = fClusterUsed[slice][patch];
+           Float_t xyz[3] = {points[pos].fX,points[pos].fY,points[pos].fZ};
+           Int_t padrow = points[pos].fPadRow;
+           
+           //Calculate the crossing point between track and padrow
+           Float_t angle = 0; //Perpendicular to padrow in local coordinates
+           AliHLTTPCTransform::Local2GlobalAngle(&angle,slice);
+           if(!intrack->CalculateReferencePoint(angle,AliHLTTPCTransform::Row2X(padrow)))
+             {
+               HLTError( "AliHLTDataCompressor::FillData : Error in crossing point calc on slice %d, padrow %d", slice, padrow );
+               break;
+               //outtrack->Print(kFALSE);
+               //exit(5);
+             }
+           
+           Float_t xyzCross[3] = {intrack->GetPointX(),intrack->GetPointY(),intrack->GetPointZ()};
+           
+           Int_t sector,row;
+           AliHLTTPCTransform::Slice2Sector(slice,padrow,sector,row);
+           AliHLTTPCTransform::Global2Raw(xyzCross,sector,row);
+#if 1
+           AliHLTTPCTransform::Local2Raw(xyz,sector,row);
+#else
+           AliHLTTPCTransform::Global2Raw(xyz,sector,row);
+#endif
+           
+           outtrack->SetPadHit(padrow,xyzCross[1]);
+           outtrack->SetTimeHit(padrow,xyzCross[2]);
+
+           outtrack->SetCrossingAngleLUT(padrow,intrack->GetCrossingAngle(padrow,slice));
+           outtrack->CalculateClusterWidths(padrow,kTRUE); // calculates parSigmas (with parametrisation) in raw coordinates
+           //HLTInfo("angle %f", outtrack->GetCrossingAngleLUT(padrow));
+           //HLTInfo("parsigma %f",outtrack->GetParSigmaY2(padrow));
+           patch = AliHLTTPCTransform::GetPatch(padrow);
+           // sigmay in units of pads (quantisation!) 
+           Float_t sigmaY2 = points[pos].fSigmaY2 / pow(AliHLTTPCTransform::GetPadPitchWidth(patch),2);
+           //HLTInfo("sigmaY conv.: %f", points[pos].fSigmaY2);
+
+           //HLTInfo("parSigmaY2 = %f",AliHLTTPCTransform::GetParSigmaY2(padrow, xyzCross[2],angle));
+           //Float_t testsigma = 0.0;
+           //outtrack->GetSigmaY2(padrow, testsigma);
+           //HLTInfo("DSigmaY2 = %f",testsigma);
+
+           //HLTInfo("sigmaY2 float: %f",sigmaY2);
+           Float_t sigmaZ2 = points[pos].fSigmaZ2 / pow(AliHLTTPCTransform::GetZWidth(),2);
+           outtrack->SetCluster(padrow,xyz[1],xyz[2],points[pos].fCharge,sigmaY2,sigmaZ2,3);
+           //AliHLTTPCClusterModel* test1 = outtrack->GetClusterModel(padrow);
+           //HLTInfo("Dsigma %f",test1->fDSigmaY);
+           
+           //IMPORTANT: Set the slice in which cluster is, you need it in AliHLTTPCModelTrack::FillTrack!
+           outtrack->GetClusterModel(padrow)->fSlice=slice;
+#ifdef MODELDEBUG
+           outtrack->GetClusterModel(padrow)->fID=points[pos].fID;
+           HLTDebug( "Track %d cluster for padrow %d ID: %u (0x%08X) - fSlice: %u", i, padrow, 
+                     outtrack->GetClusterModel(padrow)->fID, outtrack->GetClusterModel(padrow)->fID,
+                     (unsigned)outtrack->GetClusterModel(padrow)->fSlice );
+#endif
+           //points[pos].fCharge = 0;//Mark this cluster as used.
+           clustersUsed[pos] = true;//Mark this cluster as used.
+           //fNusedClusters++;
+           } //end of clusters for each track
+
+       //outtrack->SetNClusters(AliHLTTPCTransform::GetNRows(-1)); // Equivalent call in ExpandTrackData
+       } // end of track-loop
+    ExpandTrackData();
+
+    // validation test for clusternumbers of tracks:
+    //for(unsigned long jj = 0; jj < (unsigned long) fOutputTrackArray.GetNTracks(); jj++)
+    //  {
+    // AliHLTTPCModelTrack *track = (AliHLTTPCModelTrack*)fOutputTrackArray.GetCheckedTrack(jj);
+    // Int_t nhits = track->GetNHits();
+    // HLTInfo("Number of clusters for track %lu is %d",jj, nhits);
+    //  }
+
+    //comp->WriteFile(fOutputTrackArray);
+
+    }
+
+void AliHLTTPCCompModelConverter::ExpandTrackData()
+    {
+      // see header file for class documentation
+      //Loop over tracks and try to assign unused clusters.
+      //Only clusters which are closer than the max. residual are taken.
+      
+      HLTDebug( "Expanding %lu tracks", (unsigned long)fOutputTrackArray.GetNTracks() );
+      for(Int_t i=0; i<fOutputTrackArray.GetNTracks(); i++)
+       {
+         AliHLTTPCModelTrack *track = (AliHLTTPCModelTrack*)fOutputTrackArray.GetCheckedTrack(i);
+         
+         if(!track) continue;
+         
+         // tracks that hit every row already cannot be expanded in the current model!
+         if(track->GetNHits() == AliHLTTPCTransform::GetNRows()) continue;
+         
+         Int_t nhits = track->GetNHits();
+         
+         // validation test
+         //HLTInfo("Before expansion: track %u with number of clusters %d", i, nhits);
+         
+         Int_t lastSlice=-1;
+         for(Int_t padrow=AliHLTTPCTransform::GetNRows()-1; padrow>=0; padrow--)
+           {
+             if(track->IsPresent(padrow))
+               {
+                 lastSlice = track->GetClusterModel(padrow)->fSlice;
+                 continue;
+               }
+             
+             if(lastSlice < 0) //the outer cluster is missing, so skip it - it will be written anyhow.
+               continue;
+             
+             //Check the slice of the next padrow:
+             Int_t nextPadrow = padrow-1;
+             Int_t nextSlice = -1;
+             while(nextPadrow >=0)
+               {
+                 if(track->IsPresent(nextPadrow))
+                   {
+                     nextSlice = track->GetClusterModel(nextPadrow)->fSlice;
+                     break;
+                   }
+                 nextPadrow--;
+               }
+             if(nextSlice>=0)
+               if(nextSlice != lastSlice)//The track crosses a slice boundary here
+                 continue;
+             
+             //UInt_t size;
+             if ( !fClusters[lastSlice][0] )
+               {
+                 HLTWarning( "No clusters for slice %d, patch %d", lastSlice, 0 );
+                 continue;
+               }
+             if ( !fClusterUsed[lastSlice][0] )
+               {
+                 HLTWarning( "No cluster used data for slice %d, patch %d", lastSlice, 0 );
+                 continue;
+               }
+             AliHLTTPCSpacePointData *points = fClusters[lastSlice][0]->fSpacePoints;//->GetDataPointer(size);
+             bool* clustersUsed = fClusterUsed[lastSlice][0];
+             
+             Float_t angle = 0;
+             AliHLTTPCTransform::Local2GlobalAngle(&angle,lastSlice);
+             if(!track->CalculateReferencePoint(angle,AliHLTTPCTransform::Row2X(padrow)))
+               continue;
+             Float_t xyzCross[3] = {track->GetPointX(),track->GetPointY(),track->GetPointZ()};
+             AliHLTTPCTransform::Global2LocHLT(xyzCross,lastSlice);
+             Float_t mindist = 123456789;
+             AliHLTTPCSpacePointData *closest=0;
+             UInt_t closestJ=0;
+             for(UInt_t j=0; j<fClusters[lastSlice][0]->fSpacePointCnt; j++)
+               {
+                 //if(points[j].fCharge == 0) continue;// || points[j].fPadRow != padrow) continue;
+                 if (clustersUsed[j]) continue; // Cluster already used
+                 if(points[j].fPadRow < padrow) continue;
+                 if(points[j].fPadRow > padrow) break;
+                 Float_t xyz[3] = {points[j].fX,points[j].fY,points[j].fZ};
+#if 1
+#else
+                 AliHLTTPCTransform::Global2LocHLT(xyz,lastSlice);
+#endif
+                 
+                 //Check for overflow:
+                 Int_t temp = (Int_t)rint((xyzCross[1]-xyz[1])/AliHLTTPCCompDataCompressorHelper::GetXYResidualStep(padrow));
+                 if( abs(temp) > 1<<(AliHLTTPCCompDataCompressorHelper::GetNPadBits()-1))
+                   continue;
+                 
+                 temp = (Int_t)rint((xyzCross[2]-xyz[2])/AliHLTTPCCompDataCompressorHelper::GetZResidualStep(padrow));
+                 if( abs(temp) > 1<<(AliHLTTPCCompDataCompressorHelper::GetNTimeBits()-1))
+                   continue;
+                 
+                 Float_t dist = sqrt( pow(xyzCross[1]-xyz[1],2) + pow(xyzCross[2]-xyz[2],2) );
+                 if(dist < mindist)
+                   {
+                     closest = &points[j];
+                     closestJ = j;
+                     mindist = dist;
+                   }
+               }
+             if(closest) //there was a cluster assigned
+               {
+                 Int_t sector,row;
+                 Float_t xyz[3] = {closest->fX,closest->fY,closest->fZ};
+                 AliHLTTPCTransform::Slice2Sector(lastSlice,padrow,sector,row);
+                 AliHLTTPCTransform::Local2Raw(xyzCross,sector,row);
+#if 1
+                 AliHLTTPCTransform::Local2Raw(xyz,sector,row);
+#else
+                 AliHLTTPCTransform::Global2Raw(xyz,sector,row);
+#endif
+                 
+                 track->SetPadHit(padrow,xyzCross[1]);
+                 track->SetTimeHit(padrow,xyzCross[2]);
+                 
+                 Float_t angle = track->GetCrossingAngle(padrow,lastSlice);
+                 track->SetCrossingAngleLUT(padrow,angle);
+                 track->CalculateClusterWidths(padrow,kTRUE);
+                 Int_t patch = AliHLTTPCTransform::GetPatch(padrow);
+                 Float_t sigmaY2 = closest->fSigmaY2 / pow(AliHLTTPCTransform::GetPadPitchWidth(patch),2);
+                 Float_t sigmaZ2 = closest->fSigmaZ2 / pow(AliHLTTPCTransform::GetZWidth(),2);
+                 track->SetCluster(padrow,xyz[1],xyz[2],closest->fCharge,sigmaY2,sigmaZ2,3);
+                 //AliHLTTPCClusterModel* test1 = track->GetClusterModel(padrow);
+                 //HLTInfo("Dsigma %f",test1->fDSigmaY);
+                 
+                 nhits++;
+                 
+                 //IMPORTANT: Set the slice in which cluster is, you need it in AliHLTTPCModelTrack::FillTrack!
+                 track->GetClusterModel(padrow)->fSlice=lastSlice;
+#ifdef MODELDEBUG
+                 track->GetClusterModel(padrow)->fID=closest->fID;
+                 HLTDebug( "Track %d cluster for padrow %d ID: %u (0x%08X) - fSlice: %u", i, padrow, 
+                           track->GetClusterModel(padrow)->fID, track->GetClusterModel(padrow)->fID,
+                           track->GetClusterModel(padrow)->fSlice );
+#endif
+                 //closest->fCharge = 0;//Mark this cluster as used.
+                 clustersUsed[closestJ] = true;//Mark this cluster as used.
+               }
+           }
+         track->SetNClusters(AliHLTTPCTransform::GetNRows());
+         //cout<<"Track was assigned "<<nhits<<" clusters"<<endl;
+         
+         // validation test
+         //HLTInfo( "After expansion: track %d with clusters %u", i, nhits);
+       }
+  
+    }
+
+unsigned long AliHLTTPCCompModelConverter::GetOutputModelDataSize()
+    {
+      // see header file for class documentation
+      unsigned long dataSize=0;
+      Short_t ntracks = fOutputTrackArray.GetNTracks();
+      
+      dataSize += sizeof(AliHLTUInt32_t);
+      
+      for(Int_t i=0; i<ntracks; i++)
+       {
+         AliHLTTPCModelTrack *track = (AliHLTTPCModelTrack*)fOutputTrackArray.GetCheckedTrack(i);
+         if ( !track )
+           continue;
+         
+         dataSize += sizeof(AliHLTTPCTrackModel)+track->GetNClusters()*sizeof(AliHLTTPCClusterModel);
+       }
+      return dataSize;
+    }
+
+int AliHLTTPCCompModelConverter::OutputModelData( AliHLTUInt8_t* data )
+    {
+      // see header file for class documentation 
+      unsigned long dataOffset=0;
+      Short_t ntracks = fOutputTrackArray.GetNTracks();
+      
+      AliHLTTPCClusterModel *clusters=0;
+      AliHLTTPCTrackModel *model=0;
+      
+      *(AliHLTUInt32_t*)data = 0; // Write format version number
+      dataOffset += sizeof(AliHLTUInt32_t);
+      
+      for(Int_t i=0; i<ntracks; i++)
+       {
+         AliHLTTPCModelTrack *track = (AliHLTTPCModelTrack*)fOutputTrackArray.GetCheckedTrack(i);
+         if ( !track )
+           continue;
+         
+         track->FillModel();
+         model = track->GetModel();
+         
+         clusters = track->GetClusters();
+         
+         // validation test
+         //HLTInfo( "Track %d clusters: %u", i, (unsigned)track->GetNPresentClusters() );
+         
+         for ( Int_t jj=0; jj<track->GetNClusters(); jj++ )
+           {
+             //HLTDebug( "  Cluster %d fPresent: %u", jj, (unsigned)clusters[jj].fPresent );
+           }
+         
+         memcpy( data+dataOffset, model, sizeof(AliHLTTPCTrackModel) );
+         dataOffset += sizeof(AliHLTTPCTrackModel);
+         
+         memcpy( data+dataOffset, clusters, track->GetNClusters()*sizeof(AliHLTTPCClusterModel) );
+         dataOffset += track->GetNClusters()*sizeof(AliHLTTPCClusterModel);
+       }
+      return 0;
+    }
+
+void AliHLTTPCCompModelConverter::SelectRemainingClusters()
+    {
+      // see header file for class documentation
+      //Select which remaining clusters to write in addition to the compressed data.
+      //In particular one can here make sure that "important" clusters are not missed:
+      //The offline track finder perform seed finding in the outer padrows;
+      //the first seeding is using pair of points on outermost padrow and 
+      //0.125*nrows more rows towards the vertex. The second seeding uses pair
+      //of points on the outermost padrow-0.5*0.125*nrows and 0.125*nrows + 0.5*0.125*nrows
+      //more rows towards the vertex. In order to evaluate the seeds, the track offline
+      //track finder checks whether a certain amount of possible clusters (padrows) is 
+      //attached to the track, and then the kalman filtering starts.
+      //To ensure a minimal loss off efficiency, all clusters in this region should be
+      //intact.....
+      
+      Int_t nrows = AliHLTTPCTransform::GetNRows();
+      Int_t gap=(Int_t)(0.125*nrows), shift=(Int_t)(0.5*gap);
+      
+      for(Int_t slice=0; slice<36; slice++)
+       {
+         for(Int_t patch=0; patch<6; patch++)
+           {
+             if ( !fClusters[slice][patch] )
+               continue;
+             AliHLTTPCSpacePointData *points = fClusters[slice][patch]->fSpacePoints;
+             bool* clustersUsed = fClusterUsed[slice][patch];
+             for(UInt_t i=0; i<fClusters[slice][patch]->fSpacePointCnt; i++)
+               {
+                 //if(points[i].fCharge == 0) continue; //Already removed
+                 if (clustersUsed[i]) continue; //Already removed
+                 Int_t padrow = (Int_t)points[i].fPadRow;
+                 
+                 //Check the widths (errors) of the cluster, and remove big bastards:
+                 Float_t padw = sqrt(points[i].fSigmaY2) / AliHLTTPCTransform::GetPadPitchWidth(AliHLTTPCTransform::GetPatch(padrow));
+                 Float_t timew = sqrt(points[i].fSigmaZ2) / AliHLTTPCTransform::GetZWidth();
+                 if(padw >= 2.55 || timew >= 2.55)//Because we use 1 byte to store
+                   {
+                     //points[i].fCharge = 0;
+                     clustersUsed[i] = true;
+                     continue;
+                   }
+                 
+                 Float_t xyz[3] = {points[i].fX,points[i].fY,points[i].fZ};
+                 Int_t sector,row;
+                 AliHLTTPCTransform::Slice2Sector(slice,padrow,sector,row);
+                 AliHLTTPCTransform::Global2Raw(xyz,sector,row);
+                 
+                 if(padrow >= nrows-1-gap-shift) continue;//save all the clusters in this region
+                 
+                 //if(padrow >= nrows-1-shift) continue;
+                 
+                 //Save the clusters at the borders:
+                 //if(xyz[1] < 3 || xyz[1] >= AliHLTTPCTransform::GetNPads(padrow)-4)
+                 // continue;
+                 
+                 //Save clusters on padrows used for offline seeding:
+                 if(padrow == nrows - 1 || padrow == nrows - 1 - gap ||                 //First seeding
+                    padrow == nrows - 1 - shift || padrow == nrows - 1 - gap - shift)   //Second seeding
+                   continue;
+                 
+                 //Cluster did not meet any of the above criteria, so disregard it:
+                 //points[i].fCharge = 0;
+                 clustersUsed[i] = true;
+               }
+           }
+       }
+      
+    }
+
+unsigned long AliHLTTPCCompModelConverter::GetRemainingClustersOutputDataSize()
+    {
+      // see header file for class documentation
+#if 0
+    for ( UInt_t slice=0; slice<36; slice++ )
+       for ( UInt_t patch=0; patch<6; patch++ )
+           {
+           bool* clustersUsed = fClusterUsed[slice][patch];
+           if ( !clustersUsed || !fClusters[slice][patch] )
+               continue;
+           for ( UInt_t pos=0; pos<fClusters[slice][patch]->fSpacePointCnt; pos++ )
+               {
+               if ( !clustersUsed[pos] )
+                   clusterCnt++;
+               }
+           }
+    return clusterCnt*sizeof(AliHLTTPCClusterModel);
+#else
+    const Int_t nrows = AliHLTTPCTransform::GetNRows();
+    Int_t npoints[nrows];
+    unsigned long dataWritten = 0;
+
+    dataWritten += sizeof(AliHLTUInt32_t);
+
+    for(Int_t slice=0; slice<35; slice++)
+       {
+       for(Int_t patch=0; patch < 6; patch++)
+           {
+           if ( !fClusters[slice][patch] )
+               {
+               dataWritten++;
+               continue;
+               }
+           AliHLTTPCSpacePointData *points = fClusters[slice][patch]->fSpacePoints;
+           bool* clustersUsed = fClusterUsed[slice][patch];
+           if ( !clustersUsed )
+               continue;
+           memset(npoints,0,nrows*sizeof(Int_t));
+           Int_t nonZeroRows=0;
+         
+           for(UInt_t j=0; j<fClusters[slice][patch]->fSpacePointCnt; j++)
+               {
+               //if(points[j].fCharge == 0) continue; //has been used
+               if ( clustersUsed[j] ) continue; //has been used
+               if ( !npoints[points[j].fPadRow] )
+                   nonZeroRows++;
+               npoints[points[j].fPadRow]++;
+               }
+
+           dataWritten++;
+
+           Int_t size =0;
+           Byte_t *data = 0;
+           AliHLTTPCRemainingRow *tempPt=0;
+           
+           Int_t lastRow = -2;
+           Int_t localcounter=0;
+           
+           for(UInt_t j=0; j<fClusters[slice][patch]->fSpacePointCnt; j++)
+               {
+               //if(points[j].fCharge == 0) continue; //has been used
+               if ( clustersUsed[j] ) continue; //has been used
+               
+               Int_t padrow = points[j].fPadRow;
+               if(padrow != lastRow)
+                   {
+                   if(lastRow != -2)
+                       {
+                       if(!tempPt)
+                           {
+                           HLTError( "Zero row pointer " );
+                           return EINVAL;
+                           }
+                       if(localcounter != tempPt->fNClusters)
+                           {
+                           HLTError( "Mismatching clustercounter %lu - %d ", 
+                                     (unsigned long)localcounter, (Int_t)tempPt->fNClusters );
+                           return EINVAL;
+                           }
+                       dataWritten += size;
+                       }
+                   if(data)
+                       delete [] data;
+                   size = sizeof(AliHLTTPCRemainingRow) + npoints[padrow]*sizeof(AliHLTTPCRemainingCluster);
+                   data = new Byte_t[size];
+                   tempPt = (AliHLTTPCRemainingRow*)data;
+                   
+                   localcounter=0;
+                   tempPt->fPadRow = padrow;
+                   tempPt->fNClusters = npoints[padrow];
+                   lastRow = padrow;
+                   }
+               if(localcounter >= npoints[padrow])
+                   {
+                   HLTError( "Cluster counter out of range: %lu - %lu",
+                             (unsigned long)localcounter, (unsigned long)npoints[padrow] );
+                   return EINVAL;
+                   }
+             
+               localcounter++;
+               }
+           
+           //Write the last row:
+           if ( tempPt )
+               {
+               dataWritten += size;
+               if(data)
+                   delete [] data;
+               }
+           }
+       }
+    return dataWritten;
+#endif
+    }
+
+int AliHLTTPCCompModelConverter::GetRemainingClusters( AliHLTUInt8_t* const data, unsigned long& dataSize )
+    { 
+      // see header file for class documentation
+      
+      const Int_t nrows = AliHLTTPCTransform::GetNRows();
+      Int_t npoints[nrows];
+      unsigned long dataWritten = 0;
+      AliHLTUInt8_t* writePtr = data;
+      
+      *(AliHLTUInt32_t*)writePtr = 0; // Write format version
+      dataWritten += sizeof(AliHLTUInt32_t);
+      writePtr += sizeof(AliHLTUInt32_t);
+
+      for(Int_t slice=0; slice<=35; slice++)
+       {
+         for(Int_t patch=0; patch < 6; patch++)
+           {
+             if ( !fClusters[slice][patch] )
+               {
+                 *writePtr = (AliHLTUInt8_t)0;
+                 writePtr++;
+                 dataWritten++;
+                 continue;
+               }
+             AliHLTTPCSpacePointData *points = fClusters[slice][patch]->fSpacePoints;
+             bool* clustersUsed = fClusterUsed[slice][patch];
+             if ( !clustersUsed )
+               continue;
+             memset(npoints,0,nrows*sizeof(Int_t));
+             Int_t nonZeroRows=0;
+             
+             for(UInt_t j=0; j<fClusters[slice][patch]->fSpacePointCnt; j++)
+               {
+                 //if(points[j].fCharge == 0) continue; //has been used
+                 if ( clustersUsed[j] ) continue; //has been used
+                 if ( !npoints[points[j].fPadRow] )
+                   nonZeroRows++;
+                 npoints[points[j].fPadRow]++;
+               }
+             
+             *writePtr = (AliHLTUInt8_t)nonZeroRows;
+             writePtr++;
+             dataWritten++;
+             
+             Int_t size =0;
+             Byte_t *data = 0;
+             AliHLTTPCRemainingRow *tempPt=0;
+             
+             Int_t lastRow = -2;
+             Int_t localcounter=0;
+           
+             for(UInt_t j=0; j<fClusters[slice][patch]->fSpacePointCnt; j++)
+               {
+                 //if(points[j].fCharge == 0) continue; //has been used
+                 if ( clustersUsed[j] ) continue; //has been used
+                 
+                 Int_t padrow = points[j].fPadRow;
+                 if(padrow != lastRow)
+                   {
+                     if(lastRow != -2)
+                       {
+                         if(!tempPt)
+                           {
+                             HLTError( "Zero row pointer " );
+                             return EINVAL;
+                           }
+                         if(localcounter != tempPt->fNClusters)
+                           {
+                             HLTError( "Mismatching clustercounter %lu - %d ", 
+                                       (unsigned long)localcounter, (Int_t)tempPt->fNClusters );
+                             return EINVAL;
+                           }
+                         //cout<<"Writing row "<<(int)tempPt->fPadRow<<" with "<<(int)tempPt->fNClusters<<" clusters"<<endl;
+                         //fwrite(tempPt,size,1,outfile);
+                         if ( dataWritten+size > dataSize )
+                           {
+                             HLTWarning( "Cannot write remaining clusters to output. Data size too large (exceeding %lu bytes)", (unsigned long)dataSize );
+                             return ENOBUFS;
+                           }
+                         memcpy( writePtr, tempPt, size );
+                         dataWritten += size;
+                         writePtr += size;
+                       }
+                     if(data)
+                       delete [] data;
+                     size = sizeof(AliHLTTPCRemainingRow) + npoints[padrow]*sizeof(AliHLTTPCRemainingCluster);
+                     data = new Byte_t[size];
+                     tempPt = (AliHLTTPCRemainingRow*)data;
+                     
+                     localcounter=0;
+                     tempPt->fPadRow = padrow;
+                     tempPt->fNClusters = npoints[padrow];
+                     lastRow = padrow;
+                   }
+                 if(localcounter >= npoints[padrow])
+                   {
+                     HLTError( "Cluster counter out of range: %lu - %lu",
+                               (unsigned long)localcounter, (unsigned long)npoints[padrow] );
+                     return EINVAL;
+                   }
+                 
+                 Float_t xyz[3] = {points[j].fX,points[j].fY,points[j].fZ};
+                 Int_t sector,row;
+                 AliHLTTPCTransform::Slice2Sector(slice,padrow,sector,row);
+#if 1
+                 AliHLTTPCTransform::Local2Raw(xyz,sector,row);
+#else
+                 AliHLTTPCTransform::Global2Raw(xyz,sector,row);
+#endif
+                 
+                 Float_t padw = points[j].fSigmaY2 / pow(AliHLTTPCTransform::GetPadPitchWidth(AliHLTTPCTransform::GetPatch(padrow)),2);
+                 Float_t timew = points[j].fSigmaZ2 / pow(AliHLTTPCTransform::GetZWidth(),2);
+                 tempPt->fClusters[localcounter].fPad = xyz[1];
+                 tempPt->fClusters[localcounter].fTime = xyz[2];
+                 tempPt->fClusters[localcounter].fCharge = points[j].fCharge;
+                 tempPt->fClusters[localcounter].fSigmaY2 = padw;
+                 tempPt->fClusters[localcounter].fSigmaZ2 = timew;
+#ifdef MODELDEBUG
+                 tempPt->fClusters[localcounter].fID = points[j].fID;
+#endif
+                 localcounter++;
+                 if(fModelAnalysisInstance)
+                   {
+                     if(fModelAnalysisInstance->GetfModelAnalysis())
+                       {
+                         fModelAnalysisInstance->MarkTrashCluster(fClusters[slice][patch], slice, patch);
+                       }
+                   }
+               }
+             
+             
+             //Write the last row:
+             if ( dataWritten+size > dataSize )
+               {
+               HLTWarning( "Cannot write remaining clusters to output. Data size too large (exceeding %lu bytes)", (unsigned long)dataSize );
+               return ENOBUFS;
+               }
+             if ( tempPt )
+               {
+                 memcpy( writePtr, tempPt, size );
+                 dataWritten += size;
+                 writePtr += size;
+                 if(data)
+                   delete [] data;
+               }
+           }
+       }
+      dataSize = dataWritten;
+      
+      return 0;
+    }
diff --git a/HLT/TPCLib/comp/AliHLTTPCCompModelConverter.h b/HLT/TPCLib/comp/AliHLTTPCCompModelConverter.h
new file mode 100644 (file)
index 0000000..b8555b5
--- /dev/null
@@ -0,0 +1,127 @@
+// XEmacs -*-C++-*-
+// $Id: AliHLTTPCCompModelConverter.h,v 1.2 2006/08/10 09:46:51 richterm Exp $
+
+#ifndef ALIHLTTPCCOMPMODELCONVERTER_H
+#define ALIHLTTPCCOMPMODELCONVERTER_H
+/* TPCCompModelConverterright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full TPCCompModelConverterright notice                               */
+
+/** @file   AliHLTTPCCompModelConverter.h
+    @author Timm Steinbeck
+    @date   
+    @brief  Declaration of a copy component. */
+
+#include "AliHLTTPCTrackArray.h"
+#include "AliHLTTPCTrackletDataFormat.h"
+#include "AliHLTTPCClusterDataFormat.h"
+#include "AliHLTTPCCompModelAnalysis.h"
+#include "AliHLTLogging.h"
+
+/**
+ * @class AliHLTTPCCompModelConverter
+ * @brief A dummy HLT processing component. 
+ *
+ * An implementiation of a copy component that just copies its input data
+ * to debug a components input data
+ * @ingroup alihlt_tutorial
+ */
+class AliHLTTPCCompModelConverter: public AliHLTLogging
+    {
+    public:
+      /** standard constructor */
+      AliHLTTPCCompModelConverter();
+
+      /** constructor including model/track analysis */
+      AliHLTTPCCompModelConverter(AliHLTTPCCompModelAnalysis* modelanalysis);
+
+      /** standard destructor */
+      virtual ~AliHLTTPCCompModelConverter();
+      
+      /** initialisation function 
+       * @return zero upon success
+       */
+      int Init();
+      
+      /** function to set input tracks
+       * @param tracklets pointer to AliHLTTPCTrackletData
+       * @return zero upon success
+       */
+      int SetInputTracks( AliHLTTPCTrackletData* tracklets );
+
+      /** function to set input tracks
+       * @param clusters pointer to AliHLTTPCClusterData
+       * @param slice UInt_t slice number
+       * @param patch UInt_t patch number
+       * @return zero upon success
+       */
+      int SetInputClusters( AliHLTTPCClusterData* clusters, UInt_t slice, UInt_t patch );
+      
+      /** function to convert input to Vestbo-model (-> compression can then follow) */
+      void Convert();
+      
+      /** function to get output model data size
+       * @return unsigned long value of output model data size
+       */
+      unsigned long GetOutputModelDataSize();
+      
+      /** function to output model data
+       * @param data AliHLTUInt8_t* pointer to ouptut data
+       * @return zero upon success
+       */
+      int OutputModelData( AliHLTUInt8_t* data );
+      
+      /** function to select remaining clusters */
+      void SelectRemainingClusters();
+      
+      /** function to get remaining clusters output data size
+       * @return unsigned long value = size
+       */
+      unsigned long GetRemainingClustersOutputDataSize();
+
+      /** function to get remaining clusters
+       * @param data     AliHLTUInt8_t* const
+       * @param dataSize unsigned long& 
+       */
+      int GetRemainingClusters( AliHLTUInt8_t* const data, unsigned long& dataSize );
+      
+      /** function to define minimal hits for one track
+       * @param minHits unsigned
+       */
+      void SetMinHits( unsigned minHits )
+      {
+       fMinHits = minHits;
+      }
+
+    protected:
+
+      /** function to expand track data */
+      void ExpandTrackData();
+
+      /** member variable input track array */
+      AliHLTTPCTrackArray fInputTrackArray;
+      /** member variable output track array */
+      AliHLTTPCTrackArray fOutputTrackArray;
+      
+      /** pointer to instance of analysis model class */
+      AliHLTTPCCompModelAnalysis* fModelAnalysisInstance; // pointer to instance of analysis model class
+
+      /** array of cluster data */
+      AliHLTTPCClusterData* fClusters[36][6];
+
+      /** temporary array how of used cluster sizes */
+      unsigned long fClusterUsedSizes[36][6]; //! temporary, how many entries do we have in the following clusters used arrays
+      /** array to determine the used clusters in tracking */
+      bool* fClusterUsed[36][6]; //! keep track of which clusters have been used, can be transient.
+      /** number of minimal hit for one track */
+      unsigned fMinHits;
+      
+    private:
+      /** copy constructor prohibited */
+      AliHLTTPCCompModelConverter(const AliHLTTPCCompModelConverter&);
+      /** assignment operator prohibited */
+      AliHLTTPCCompModelConverter& operator=(const AliHLTTPCCompModelConverter&);
+     
+      ClassDef(AliHLTTPCCompModelConverter, 1)
+
+    };
+#endif
diff --git a/HLT/TPCLib/comp/AliHLTTPCCompModelConverterComponent.cxx b/HLT/TPCLib/comp/AliHLTTPCCompModelConverterComponent.cxx
new file mode 100644 (file)
index 0000000..497ca90
--- /dev/null
@@ -0,0 +1,330 @@
+// $Id: AliHLTTPCCompModelConverterComponent.cxx,v 1.2 2006/08/10 09:46:51 richterm Exp $
+
+/**************************************************************************
+ * TPCCompModelConverterright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Authors: 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.                  *
+ **************************************************************************/
+
+/** @file   AliHLTTPCCompModelConverterComponent.cxx
+    @author Timm Steinbeck
+    @author changed by J. Wagner
+    @date   17-11-2007
+    @brief  A copy processing component for the HLT. */
+
+#if __GNUC__ >= 3
+using namespace std;
+#endif
+
+#include "AliHLTTPCCompModelConverterComponent.h"
+#include "AliHLTTPCDefinitions.h"
+//#include "AliHLTTPCCompModelAnalysis.h"
+#include <errno.h>
+
+// this is a global object used for automatic component registration, do not use this
+AliHLTTPCCompModelConverterComponent gAliHLTTPCCompClusterModelConverterComponent;
+
+ClassImp(AliHLTTPCCompModelConverterComponent)
+    
+  AliHLTTPCCompModelConverterComponent::AliHLTTPCCompModelConverterComponent() :
+    fConverter(NULL),
+    fModelAnalysisInstance(NULL),
+    fDumpFileName(),
+    fGraphFileName(),
+    fModelAnalysis(0),
+    fTrackAnalysis(0),
+    fFillingFirstTrackArray(0)
+    {
+      // see header file for class documentation
+    }
+
+AliHLTTPCCompModelConverterComponent::~AliHLTTPCCompModelConverterComponent()
+    {
+      // see header file for class documentation
+    }
+
+const char* AliHLTTPCCompModelConverterComponent::GetComponentID()
+    {
+      // see header file for class documentation
+      return "TPCCompModelConverter"; // The ID of this component
+    }
+
+void AliHLTTPCCompModelConverterComponent::GetInputDataTypes( vector<AliHLTComponent_DataType>& list)
+    {
+      // see header file for class documentation
+      list.clear(); // We do not have any requirements for our input data type(s).
+      list.push_back( AliHLTTPCDefinitions::fgkClustersDataType );
+      list.push_back( AliHLTTPCDefinitions::fgkTracksDataType );
+    }
+
+AliHLTComponent_DataType AliHLTTPCCompModelConverterComponent::GetOutputDataType()
+    {
+      // see header file for class documentation
+      return AliHLTTPCDefinitions::fgkClusterTracksModelDataType;
+    }
+
+void AliHLTTPCCompModelConverterComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
+    {
+      // see header file for class documentation
+      constBase = 4+4+216; // Format versions + 1 byte per patch
+      inputMultiplier = 4.;
+      //#warning Adapt input Multiplier to something more realistic
+    }
+
+// Spawn function, return new instance of this class
+AliHLTComponent* AliHLTTPCCompModelConverterComponent::Spawn()
+    {
+      // see header file for class documentation
+      return new AliHLTTPCCompModelConverterComponent;
+    };
+
+int AliHLTTPCCompModelConverterComponent::DoInit( int argc, const char** argv )
+{
+  // see header file for class documentation
+  Int_t i = 0;
+  // get input argument either -modelanalysis or -trackanalysis
+  while(i < argc)
+    {
+      if ( !strcmp( argv[i], "-modelanalysis" ) ) 
+       {
+         fModelAnalysis = 1;
+         HLTInfo("Model analysis starting.");
+         ++i;
+         continue;
+       }
+       
+      if ( !strcmp( argv[i], "-trackanalysis" ) ) 
+       {
+         fTrackAnalysis = 1;
+         fFillingFirstTrackArray = 1;
+         HLTInfo("Tracking analysis starting.");
+         ++i;
+         continue;
+       }
+
+      if ( !strcmp( argv[i], "-dumptofile" ) ) 
+       {
+
+         //check if any analysis has been specified (otherwise -dumptofile makes no sense!)
+         if(!fTrackAnalysis && !fModelAnalysis)
+           {
+             HLTError("Dump to file called without any model analysis specified.");
+             return EINVAL;
+           }
+
+         // read in filename (including path)
+          if ( argc <= i+1 ) 
+           {
+             HLTError("Missing filename to write analysis results");
+             return ENOTSUP;
+           }
+          
+          fDumpFileName = argv[i+1];
+          HLTInfo("File name of dump file for results set to %s.", fDumpFileName.Data());
+         ++i;
+         ++i;
+         continue;
+       }
+
+      // specify if graphical output is wanted (histograms, saved in a root file)
+      if ( !strcmp( argv[i], "-graphs" ) ) 
+       {
+
+         //check if any analysis has been specified (otherwise -graphs makes no sense!)
+         if(!fTrackAnalysis && !fModelAnalysis)
+           {
+             HLTError("Creation of histgrams called without any model analysis specified.");
+             return EINVAL;
+           }
+
+         // read in filename (including path like /afsuser/johndoe/TrackModelHistograms.root)
+          if ( argc <= i+1 ) 
+           {
+             HLTError("Missing filename to write histograms");
+             return ENOTSUP;
+           }
+          
+          fGraphFileName = argv[i+1];
+          HLTInfo("File name of file for graphical results set to %s.", fGraphFileName.Data());
+         ++i;
+         ++i;
+         continue;
+       }
+
+      HLTError("Unknown Option '%s'", argv[i] );
+      return EINVAL;
+
+    }
+  
+  // start new analysis by intialising respective arrays
+  if(fModelAnalysis || fTrackAnalysis)
+    {
+      fModelAnalysisInstance = new AliHLTTPCCompModelAnalysis(fModelAnalysis, fTrackAnalysis, fDumpFileName, fGraphFileName);
+      fModelAnalysisInstance->Init(); 
+      fConverter = new AliHLTTPCCompModelConverter(fModelAnalysisInstance);
+
+      if(fModelAnalysis)
+       {
+         HLTInfo("Model Analysis initiated, calculating loss due to convertion to Vestbo-Model.");
+       }
+      else
+       {
+         HLTInfo("Track Analysis initiated, showing influence of Vestbo-Model on tracking.");
+       }
+    }
+  else
+    {
+      fConverter = new AliHLTTPCCompModelConverter();
+    }
+  /*if ( argc )
+    {
+    Logging( kHLTLogDebug, "HLT::TPCCompModelConverter::DoInit", "Arguments", "argv[0] == %s", argv[0] );
+    Logging(kHLTLogError, "HLT::TPCCompModelConverter::DoInit", "Unknown Option", "Unknown option '%s'", argv[0] );
+    return EINVAL;
+    }*/
+  
+  return 0;
+}
+
+int AliHLTTPCCompModelConverterComponent::DoDeinit()
+    {
+      // see header file for class documentation
+      // display results
+      if(fModelAnalysisInstance)
+       {
+         fModelAnalysisInstance->DisplayResults();
+
+         delete fModelAnalysisInstance;
+         fModelAnalysisInstance = NULL;
+       };
+
+      if(fConverter)
+       {
+         delete fConverter;
+         fConverter = NULL;
+       }
+
+    return 0;
+    }
+
+int AliHLTTPCCompModelConverterComponent::DoEvent( const AliHLTComponent_EventData& evtData, const AliHLTComponent_BlockData* blocks, 
+                                                  AliHLTComponent_TriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr, 
+                                     AliHLTUInt32_t& size, vector<AliHLTComponent_BlockData>& outputBlocks )
+    {
+      // see header file for class documentation
+      fConverter->Init();
+      // Process an event
+      // Loop over all input blocks in the event
+      AliHLTUInt8_t minSlice=0xFF, maxSlice=0xFF, minPatch=0xFF, maxPatch=0xFF;
+      for ( unsigned long n = 0; n < evtData.fBlockCnt; n++ )
+       {
+         AliHLTUInt8_t slice, patch;
+         if ( blocks[n].fDataType == AliHLTTPCDefinitions::fgkClustersDataType ||
+              blocks[n].fDataType == AliHLTTPCDefinitions::fgkTracksDataType )
+           {
+             slice = AliHLTTPCDefinitions::GetMinSliceNr( blocks[n].fSpecification );
+             patch = AliHLTTPCDefinitions::GetMinPatchNr( blocks[n].fSpecification );
+             if ( minSlice==0xFF || slice<minSlice )
+               minSlice = slice;
+             if ( maxSlice==0xFF || slice>maxSlice )
+               maxSlice = slice;
+             if ( minPatch==0xFF || patch<minPatch )
+               minPatch = patch;
+             if ( maxPatch==0xFF || patch>maxPatch )
+               maxPatch = patch;
+           }
+         if ( blocks[n].fDataType == AliHLTTPCDefinitions::fgkClustersDataType )
+           {
+             fConverter->SetInputClusters( (AliHLTTPCClusterData*)blocks[n].fPtr, slice, patch );
+           }
+         if ( blocks[n].fDataType == AliHLTTPCDefinitions::fgkTracksDataType )
+           {
+             fConverter->SetInputTracks( (AliHLTTPCTrackletData*)blocks[n].fPtr );
+             
+             // if track analysis is desired, fill tracklets into track arrays of ModelAnalysis class to be compared
+             if(fTrackAnalysis)
+               {
+                 fModelAnalysisInstance->SetTracks((AliHLTTPCTrackletData*)blocks[n].fPtr, fFillingFirstTrackArray);
+                 
+                 // set flag for filling first array to zero --> second array is filled then
+                 fFillingFirstTrackArray = 0;
+               }
+           }
+       }
+      
+      if(fTrackAnalysis)
+       {
+         if(fModelAnalysis == 0) // stop processing if not required
+           return 0;
+       };
+      
+      fConverter->Convert();
+      
+      unsigned long outputSize = fConverter->GetOutputModelDataSize();
+      if ( outputSize> size )
+       {
+         HLTError( "Not enough output memory size for clusters&tracks model data. %lu needed",
+                   outputSize );
+         return ENOBUFS;
+       }
+      
+      fConverter->OutputModelData( outputPtr );
+      
+      AliHLTComponent_BlockData ob;
+      // Let the structure be filled with the default values.
+      // This takes care of setting the shared memory and data type values to default values,
+      // so that they can be filled in by the calling code.
+      FillBlockData( ob );
+      // This block's start (offset) is after all other blocks written so far
+      ob.fOffset = 0;
+      // the size of this block's data.
+      ob.fSize = outputSize;
+      // The specification of the data is copied from the input block.
+      ob.fSpecification = AliHLTTPCDefinitions::EncodeDataSpecification( minSlice, maxSlice, minPatch, maxPatch );
+      // The type of the data is copied from the input block.
+      ob.fDataType = AliHLTTPCDefinitions::fgkClusterTracksModelDataType;
+      // Place this block into the list of output blocks
+      outputBlocks.push_back( ob );
+      
+      outputPtr += ob.fSize;
+      
+      if ( outputSize+fConverter->GetRemainingClustersOutputDataSize()>size )
+       {
+         HLTError( "Not enough output memory size for remaining clusters model data. %lu needed in total (clusters&tracks + rem. clusters)",
+                   outputSize+fConverter->GetRemainingClustersOutputDataSize() );
+         return ENOBUFS;
+       }
+      unsigned long clusterSize = size-outputSize;
+      printf( "clusterSize0: %lu\n", clusterSize );
+      fConverter->GetRemainingClusters( outputPtr, clusterSize );
+      printf( "clusterSize1: %lu\n", clusterSize );
+      
+      FillBlockData( ob );
+      // This block's start (offset) is after all other blocks written so far
+      ob.fOffset = outputSize;
+      // the size of this block's data.
+      ob.fSize = clusterSize;
+      // The specification of the data is copied from the input block.
+      ob.fSpecification = AliHLTTPCDefinitions::EncodeDataSpecification( minSlice, maxSlice, minPatch, maxPatch );
+      // The type of the data is copied from the input block.
+      ob.fDataType = AliHLTTPCDefinitions::fgkRemainingClustersModelDataType;
+      // Place this block into the list of output blocks
+      outputBlocks.push_back( ob );
+      
+      outputSize += ob.fSize;
+      
+      // Finally we set the total size of output memory we consumed.
+      size = outputSize;
+      return 0;
+    }
diff --git a/HLT/TPCLib/comp/AliHLTTPCCompModelConverterComponent.h b/HLT/TPCLib/comp/AliHLTTPCCompModelConverterComponent.h
new file mode 100644 (file)
index 0000000..d9da56f
--- /dev/null
@@ -0,0 +1,123 @@
+// XEmacs -*-C++-*-
+// $Id: AliHLTTPCCompModelConverterComponent.h,v 1.2 2006/08/10 09:46:51 richterm Exp $
+
+#ifndef ALIHLTTPCCOMPMODELCONVERTERCOMPONENT_H
+#define ALIHLTTPCCOMPMODELCONVERTERCOMPONENT_H
+/* TPCCompModelConverterright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full TPCCompModelConverterright notice                               */
+
+/** @file   AliHLTTPCCompModelConverterComponent.h
+    @author Timm Steinbeck
+    @author changed by J. Wagner
+    @date   17-11-2007
+    @brief  Declaration of a copy component. */
+
+
+#include "AliHLTProcessor.h"
+#include "AliHLTTPCCompModelConverter.h"
+#include "AliHLTStdIncludes.h"
+
+/**
+ * @class AliHLTTPCCompModelConverterComponent
+ * @brief A dummy HLT processing component. 
+ *
+ * An implementiation of a copy component that just copies its input data
+ * to debug a components input data
+ * @ingroup alihlt_tutorial
+ */
+class AliHLTTPCCompModelConverterComponent : public AliHLTProcessor
+{
+public:
+  /** standard constructor */
+  AliHLTTPCCompModelConverterComponent();
+  /** standard destructor */
+  virtual ~AliHLTTPCCompModelConverterComponent();
+  
+  // Public functions to implement AliHLTComponent's interface.
+  // These functions are required for the registration process
+  
+  /** function to get component id 
+   * @return const char* pointer to componentid
+   */
+  const char* GetComponentID();
+
+  /** function to get input data types
+   * @param list vecotr of AliHLTComponent_DataType
+   */
+  void GetInputDataTypes( vector<AliHLTComponent_DataType>& list);
+
+  /** function to get output data type
+   * @return AliHLTComponent_DataType
+   */
+  AliHLTComponent_DataType GetOutputDataType();
+
+  /** function to get output data size
+   * @param constBase address of an unsigned long
+   * @param inputMultiplier address of a double
+   */
+  virtual void GetOutputDataSize( unsigned long& constBase, double& inputMultiplier );
+
+  /** spawn function
+   * @return AliHLTComponent* pointer to instance
+   */
+  AliHLTComponent* Spawn();
+  
+protected:
+  
+  // Protected functions to implement AliHLTComponent's interface.
+  // These functions provide initialization as well as the actual processing
+  // capabilities of the component. 
+  
+  /** initialisation function
+   * @param argc integer counting number of input arguments
+   * @param argv const char** for parameter values
+   * @return zero upon success
+   */
+  int DoInit( int argc, const char** argv );
+
+  /** deinitialisation function
+   * @return zero upon success
+   */
+  int DoDeinit();
+
+  /** do event function
+   * @param evt Data     const AliHLTComponent_EventData& to event data
+   * @param blocks       const AliHLTComponent_BlockData* to blocks of event data
+   * @param trigData     AliHLTComponent_TriggerData& of trigger data
+   * @param outputPtr    AliHLTUInt8_t* pointer to output data
+   * @param size         AliHLTUInt32_t& of output size
+   * @param outputBlocks vector<AliHLTComponent_BlockData>& of output block data
+   * @return zero upon success
+   */
+  int DoEvent( const AliHLTComponent_EventData& evtData, const AliHLTComponent_BlockData* blocks, 
+              AliHLTComponent_TriggerData& trigData, AliHLTUInt8_t* outputPtr, 
+              AliHLTUInt32_t& size, vector<AliHLTComponent_BlockData>& outputBlocks );
+  
+  /** pointer to model converter instance */
+  AliHLTTPCCompModelConverter* fConverter;
+  /** pointer to model analysis instance */
+  AliHLTTPCCompModelAnalysis* fModelAnalysisInstance;
+  /** filename (including path) where to write model analysis results 
+      if set by command line argument -dumptofile result-folder/results */
+  TString fDumpFileName;
+  /** root file name for graphs from track comparison */
+  TString fGraphFileName;
+  
+private:
+  /** copy constructor prohibited */
+  AliHLTTPCCompModelConverterComponent(const AliHLTTPCCompModelConverterComponent&);
+  /** assignment operator prohibited */
+  AliHLTTPCCompModelConverterComponent& operator=(const AliHLTTPCCompModelConverterComponent&);
+
+  /** flags to decide wheter to do track or model loss analysis */
+  /** switch on model analysis */
+  Bool_t fModelAnalysis;            // switch on model analysis
+  /** switch on track analysis */
+  Bool_t fTrackAnalysis;           // switch on track analysis
+  /** flag to check if first or second array is filled */
+  Bool_t fFillingFirstTrackArray;  // 1 if first array is processed, 0 for second filling process
+  
+  ClassDef(AliHLTTPCCompModelConverterComponent, 0)
+    
+    };
+#endif
diff --git a/HLT/TPCLib/comp/AliHLTTPCCompModelDeconverter.cxx b/HLT/TPCLib/comp/AliHLTTPCCompModelDeconverter.cxx
new file mode 100644 (file)
index 0000000..a2db71a
--- /dev/null
@@ -0,0 +1,294 @@
+// $Id: AliHLTTPCCompModelDeconverter.cxx,v 1.2 2006/08/10 09:46:51 richterm Exp $
+
+/**************************************************************************
+ * TPCCompModelDeconverterright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Authors: 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.                  *
+ **************************************************************************/
+
+/** @file   AliHLTTPCCompModelDeconverter.cxx
+    @author Timm Steinbeck
+    @date   
+    @brief  A copy processing component for the HLT. */
+
+#if __GNUC__ >= 3
+using namespace std;
+#endif
+
+#include "AliHLTTPCCompModelDeconverter.h"
+#include "AliHLTTPCTransform.h"
+#include "AliHLTTPCTrack.h"
+#include "AliHLTTPCModelTrack.h"
+#include "AliHLTTPCCompDataCompressorHelper.h"
+#include <cerrno>
+
+AliHLTTPCCompModelDeconverter::AliHLTTPCCompModelDeconverter():
+    fInputTrackArray("AliHLTTPCModelTrack"),
+    fTrackClusterModelData(0),
+    fTrackClusterModelDataSize(0),
+    fRemainingClustersModelData(0),
+    fRemainingClustersModelDataSize(0)
+    {
+      // see header file for class documentation
+      Init();
+    }
+
+AliHLTTPCCompModelDeconverter::~AliHLTTPCCompModelDeconverter()
+    {
+      // see header file for class documentation
+    }
+
+int AliHLTTPCCompModelDeconverter::Init()
+    {
+      // see header file for class documentation
+      fInputTrackArray.Reset();
+      fTrackClusterModelData = 0;
+      fTrackClusterModelDataSize = 0;
+      fRemainingClustersModelData = 0;
+      fRemainingClustersModelDataSize = 0;
+      return 0;
+    }
+
+
+int AliHLTTPCCompModelDeconverter::SetTrackClusterModelInputData( AliHLTUInt8_t* data, UInt_t size )
+    {
+      // see header file for class documentation
+      fTrackClusterModelData = data;
+      fTrackClusterModelDataSize = size;
+      
+      AliHLTUInt8_t* inputPtr = fTrackClusterModelData;
+      AliHLTUInt8_t* inputEndPtr = fTrackClusterModelData+fTrackClusterModelDataSize;
+      
+      AliHLTUInt32_t version = *(AliHLTUInt32_t*)inputPtr;
+      inputPtr += sizeof(AliHLTUInt32_t);
+      if ( version != 0 )
+       {
+         HLTError( "Unsupported version %hu. Only version 0 supported currently.", version );
+         return EIO;
+       }
+      
+      while ( inputPtr+sizeof(AliHLTTPCTrackModel)+AliHLTTPCTransform::GetNRows()*sizeof(AliHLTTPCClusterModel) <= inputEndPtr )
+       {
+         AliHLTTPCModelTrack *track = (AliHLTTPCModelTrack*)fInputTrackArray.NextTrack();
+         if ( !track )
+           {
+             HLTError( "Error obtaining model track from track array." );
+             return EIO;
+           }
+         Int_t slice = ((AliHLTTPCClusterModel*)( inputPtr+sizeof(AliHLTTPCTrackModel) ))[ AliHLTTPCTransform::GetNRows()-1 ].fSlice;
+         track->Init(slice,-1);
+         AliHLTTPCTrackModel *model = track->GetModel();
+         AliHLTTPCClusterModel *clusters = track->GetClusters();
+         memcpy( model, inputPtr, sizeof(AliHLTTPCTrackModel) );
+         memcpy( clusters, inputPtr+sizeof(AliHLTTPCTrackModel), AliHLTTPCTransform::GetNRows()*sizeof(AliHLTTPCClusterModel) );
+         track->FillTrack();
+         
+         // validation test
+         //HLTInfo("track->GetNClusters() %d  GetNPresentClusters() %d", track->GetNClusters(), track->GetNPresentClusters());
+         
+         inputPtr += sizeof(AliHLTTPCTrackModel)+AliHLTTPCTransform::GetNRows()*sizeof(AliHLTTPCClusterModel);
+       }
+      
+      if ( inputPtr!=inputEndPtr )
+       {
+         HLTError( "Data format inconsistency on reading track model data." );
+         return EIO;
+       }
+      
+      return 0;
+    }
+
+int AliHLTTPCCompModelDeconverter::SetRemainingClustersModelInputData( AliHLTUInt8_t* data, UInt_t size )
+    {
+      // see header file for class documentation
+      fRemainingClustersModelData = data;
+      fRemainingClustersModelDataSize = size;
+      
+      AliHLTUInt32_t version = *(AliHLTUInt32_t*)data;
+      if ( version != 0 )
+       {
+         HLTError( "Unsupported version %hu. Only version 0 supported currently.", version );
+         return EIO;
+       }
+      return 0;
+    }
+
+int AliHLTTPCCompModelDeconverter::DeconvertTracks( AliHLTUInt8_t* data, UInt_t& size )
+    {
+      // see header file for class documentation
+      AliHLTTPCTrackletData* outPtr = (AliHLTTPCTrackletData*)data;
+      UInt_t blockSize = fInputTrackArray.WriteTracks( outPtr->fTrackletCnt, outPtr->fTracklets );
+      if ( blockSize >= size )
+       {
+         HLTError( "Output size is bigger than allowed (%u instead of %u)",
+                   (unsigned)blockSize, (unsigned)size );
+         size = 0;
+         return ENOBUFS;
+       }
+      size = blockSize;
+      
+      
+      UInt_t clusterCounts[36][6];
+      memset( clusterCounts, 0, sizeof(UInt_t)*36*6 );
+      
+      AliHLTTPCTrackSegmentData* tracklet = outPtr->fTracklets;
+      
+      // validation test
+      //HLTInfo("fTrackletCnt = %d", outPtr->fTrackletCnt);
+      //HLTInfo("tracklet Points = %d", tracklet->fNPoints);
+      
+      for ( UInt_t ii = 0; ii<outPtr->fTrackletCnt; ii++ )
+       {
+         // validation test
+         //HLTInfo("Tracklet points %d", tracklet->fNPoints);
+         for ( UInt_t jj=0; jj<tracklet->fNPoints; jj++ )
+           {
+             //validation test
+             //HLTInfo("Hello World %d !",jj);
+             UInt_t slice, partition;
+             slice = (tracklet->fPointIDs[jj]>>25) & 0x7f;
+             partition = (tracklet->fPointIDs[jj]>>22) & 0x7;
+             tracklet->fPointIDs[jj] = (clusterCounts[slice][partition] & ((1<<22)-1)) | ((partition & 0x7) << 22) | ((slice & 0x7F) << 25);
+             clusterCounts[slice][partition]++;
+           }
+         tracklet = (AliHLTTPCTrackSegmentData*) ( ((AliHLTUInt8_t*)tracklet)+sizeof(AliHLTTPCTrackSegmentData)+tracklet->fNPoints*sizeof(UInt_t) );
+       }
+      
+      return 0;
+    }
+
+int AliHLTTPCCompModelDeconverter::DeconvertClusters( UInt_t slice, UInt_t patch, AliHLTUInt8_t* data, UInt_t& size )
+    {
+      // see header file for class documentation
+      if ( size<sizeof(AliHLTTPCClusterData) )
+       return ENOBUFS;
+      Int_t charge;
+      Float_t pad,time,sigmaY2,sigmaZ2;
+      AliHLTTPCClusterData* clusterData = (AliHLTTPCClusterData*)data;
+      clusterData->fSpacePointCnt = 0;
+      AliHLTTPCSpacePointData* clusters = clusterData->fSpacePoints;
+      unsigned long outSize = sizeof(AliHLTTPCClusterData);
+      for(Int_t i=0; i<fInputTrackArray.GetNTracks(); i++)
+       {
+         AliHLTTPCModelTrack *track = (AliHLTTPCModelTrack*)fInputTrackArray.GetCheckedTrack(i);
+         if(!track)
+           continue;
+         for(Int_t padrow=AliHLTTPCTransform::GetFirstRow(patch); padrow <= AliHLTTPCTransform::GetLastRow(patch); padrow++)
+           {
+             if(!track->IsPresent(padrow))
+               continue;
+             UInt_t thisSlice = track->GetClusterModel(padrow)->fSlice;
+             if ( thisSlice != slice )
+               continue;
+             if ( clusterData->fSpacePointCnt >= (1<<22) )
+               {
+                 HLTError( "Too many clusters for slice %d patch %d", slice, patch );
+                 break;
+               }
+             if ( size<=outSize+sizeof(AliHLTTPCSpacePointData) )
+               {
+                 HLTError( "Not enough output space (%u bytes)", (unsigned)size );
+                 return ENOBUFS;
+               }
+             track->GetPad(padrow,pad);
+             track->GetTime(padrow,time);
+             track->GetClusterCharge(padrow,charge);
+             //NEW: Get parameters to create parSigma correctly
+             //track->GetCrossingAngleLUT(padrow);
+             //track->CalculateClusterWidths(padrow,kTRUE); // calculates parSigmas (with parametrisation) in raw coordinates
+             //HLTInfo("dangle %f", track->GetCrossingAngleLUT(padrow));
+             //HLTInfo("dparsigma %f",track->GetParSigmaY2(padrow));
+             track->GetSigmaY2(padrow,sigmaY2);
+             //AliHLTTPCClusterModel* test1 = track->GetClusterModel(padrow);
+             //HLTInfo("DsigmaY deconv. : %f",test1->fDSigmaY);
+             //HLTInfo("sigmaY2 deconv.: %f",sigmaY2);
+             track->GetSigmaZ2(padrow,sigmaZ2);
+             Float_t xyz[3];
+             AliHLTTPCTransform::RawHLT2Local( xyz, slice, padrow, pad, time );
+             clusters[clusterData->fSpacePointCnt].fX = xyz[0];
+             clusters[clusterData->fSpacePointCnt].fY = xyz[1];
+             clusters[clusterData->fSpacePointCnt].fZ = xyz[2];
+             clusters[clusterData->fSpacePointCnt].fPadRow = padrow;
+             clusters[clusterData->fSpacePointCnt].fSigmaY2 = sigmaY2*pow(AliHLTTPCTransform::GetPadPitchWidth(patch),2);
+             clusters[clusterData->fSpacePointCnt].fSigmaZ2 = sigmaZ2*pow(AliHLTTPCTransform::GetZWidth(),2);;
+             clusters[clusterData->fSpacePointCnt].fCharge = charge;
+             clusters[clusterData->fSpacePointCnt].fUsed = kTRUE;
+             clusters[clusterData->fSpacePointCnt].fTrackN = i;
+             clusters[clusterData->fSpacePointCnt].fID = (clusterData->fSpacePointCnt & ((1<<22)-1)) | ((patch & 0x7) << 22) | ((slice & 0x7F) << 25);
+             clusterData->fSpacePointCnt++;
+             outSize += sizeof(AliHLTTPCSpacePointData);
+           }
+       }
+      
+    if ( fRemainingClustersModelDataSize )
+      {
+       AliHLTUInt8_t* inputPtr = fRemainingClustersModelData+sizeof(AliHLTUInt32_t);
+       AliHLTUInt8_t* inputEndPtr = inputPtr+fRemainingClustersModelDataSize;
+       for ( UInt_t thisSlice=0; thisSlice<36; thisSlice++ )
+         {
+           for ( UInt_t thisPatch=0; thisPatch<6; thisPatch++ )
+             {
+               AliHLTUInt8_t rowCount = *inputPtr;
+               inputPtr++;
+               if ( !rowCount )
+                 {
+                   if ( thisSlice==slice && thisPatch==patch )
+                     break;
+                   continue;
+                 }
+               for ( UInt_t jj=0; jj < rowCount; jj++ )
+                   {
+                     AliHLTTPCRemainingRow *thisRow = (AliHLTTPCRemainingRow*)inputPtr;
+                     if ( inputPtr+sizeof(AliHLTTPCRemainingRow)>inputEndPtr )
+                       {
+                         HLTError( "Corrupt input data, cannot read row data for row %u of slice %u, partition %u", (unsigned)jj, (unsigned)thisSlice, (unsigned)thisPatch );
+                         return EIO;
+                       }
+                     AliHLTTPCRemainingCluster *cl = thisRow->fClusters;
+                     if ( inputPtr+sizeof(AliHLTTPCRemainingRow)+thisRow->fNClusters*sizeof(AliHLTTPCRemainingCluster)>inputEndPtr )
+                       {
+                         HLTError( "Corrupt input data, unable to read clusters for row %u, slice %u, partition %u", (unsigned)jj, (unsigned)thisSlice, (unsigned)thisPatch );
+                         return EIO;
+                       }
+                     Int_t padrow = thisRow->fPadRow;
+                     if ( slice==thisSlice && patch==thisPatch )
+                       {
+                         for ( UInt_t ii=0; ii<thisRow->fNClusters; ii++ )
+                           {
+                             Float_t xyz[3];
+                             AliHLTTPCTransform::RawHLT2Local( xyz, slice, padrow, cl[ii].fPad, cl[ii].fTime );
+                             clusters[clusterData->fSpacePointCnt].fX = xyz[0];
+                             clusters[clusterData->fSpacePointCnt].fY = xyz[1];
+                             clusters[clusterData->fSpacePointCnt].fZ = xyz[2];
+                             clusters[clusterData->fSpacePointCnt].fPadRow = padrow;
+                             clusters[clusterData->fSpacePointCnt].fSigmaY2 = cl[ii].fSigmaY2*pow(AliHLTTPCTransform::GetPadPitchWidth(patch),2);
+                             clusters[clusterData->fSpacePointCnt].fSigmaZ2 = cl[ii].fSigmaZ2*pow(AliHLTTPCTransform::GetZWidth(),2);;
+                             clusters[clusterData->fSpacePointCnt].fCharge = cl[ii].fCharge;
+                             clusters[clusterData->fSpacePointCnt].fUsed = kFALSE;
+                             clusters[clusterData->fSpacePointCnt].fTrackN = -1;
+                             clusters[clusterData->fSpacePointCnt].fID = (clusterData->fSpacePointCnt & ((1<<22)-1)) | ((patch & 0x7) << 22) | ((slice & 0x7F) << 25);
+                             clusterData->fSpacePointCnt++;
+                             outSize += sizeof(AliHLTTPCSpacePointData);
+                           }
+                       }
+                     inputPtr += sizeof(AliHLTTPCRemainingRow)+thisRow->fNClusters*sizeof(AliHLTTPCRemainingCluster);
+                   }
+               
+             }
+           if ( thisSlice==slice )
+             break;
+         }
+      }
+    
+    size = outSize;
+    return 0;
+    }
diff --git a/HLT/TPCLib/comp/AliHLTTPCCompModelDeconverter.h b/HLT/TPCLib/comp/AliHLTTPCCompModelDeconverter.h
new file mode 100644 (file)
index 0000000..2612d80
--- /dev/null
@@ -0,0 +1,90 @@
+// XEmacs -*-C++-*-
+// $Id: AliHLTTPCCompModelDeconverter.h,v 1.2 2006/08/10 09:46:51 richterm Exp $
+
+#ifndef ALIHLTTPCCOMPMODELDECONVERTER_H
+#define ALIHLTTPCCOMPMODELDECONVERTER_H
+/* TPCCompModelDeconverterright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full TPCCompModelDeconverterright notice                               */
+
+/** @file   AliHLTTPCCompModelDeconverter.h
+    @author Timm Steinbeck
+    @date   
+    @brief  Declaration of a copy component. */
+
+#include "AliHLTTPCTrackArray.h"
+#include "AliHLTTPCTrackletDataFormat.h"
+#include "AliHLTTPCClusterDataFormat.h"
+#include "AliHLTLogging.h"
+
+/**
+ * @class AliHLTTPCCompModelDeconverter
+ * @brief A dummy HLT processing component. 
+ *
+ * An implementiation of a copy component that just copies its input data
+ * to debug a components input data
+ * @ingroup alihlt_tutorial
+ */
+class AliHLTTPCCompModelDeconverter: public AliHLTLogging
+    {
+    public:
+
+      /** standard constructor */
+      AliHLTTPCCompModelDeconverter();
+
+      /** standard destructor */
+      virtual ~AliHLTTPCCompModelDeconverter();
+      
+      /** initialisation function */
+      int Init();
+      
+      /** function to set track cluster model input data
+       * @param data AliHLTUInt8_t* pointer to input data
+       * @param size UInt_t input size
+       * @return zero upon success
+       */      
+      int SetTrackClusterModelInputData( AliHLTUInt8_t* data, UInt_t size );
+
+      /** function to set remaining cluster model input data
+       * @param data AliHLTUInt8_t* pointer to input data
+       * @param size UInt_t input size
+       * @return zero upon success
+       */    
+      int SetRemainingClustersModelInputData( AliHLTUInt8_t* data, UInt_t size );
+
+      /** function to deconvert tracks
+       * @param data AliHLTUInt8_t* pointer to input data
+       * @param size UInt_t& input size
+       * @return zero upon success
+       */    
+      int DeconvertTracks( AliHLTUInt8_t* data, UInt_t& size );
+
+      /** function to deconvert clusters
+       * @param slice UInt_t slice number
+       * @param patch UInt_t patch number
+       * @param data AliHLTUInt8_t* pointer to input data
+       * @param size UInt_t& input size
+       * @return zero upon success
+       */    
+      int DeconvertClusters( UInt_t slice, UInt_t patch, AliHLTUInt8_t* data, UInt_t& size );
+
+    protected:
+
+      /** member variable of input track array */
+      AliHLTTPCTrackArray fInputTrackArray;
+       
+      /** member variable pointer to track cluster model data */
+      AliHLTUInt8_t* fTrackClusterModelData;
+      /** member variable for track cluster model data size */
+      UInt_t fTrackClusterModelDataSize;
+
+      /** member variable pointer to remaining clusters model data */
+      AliHLTUInt8_t* fRemainingClustersModelData;
+      /** member variable for remaining clusters model data size */
+      UInt_t fRemainingClustersModelDataSize;
+
+    private:
+
+       ClassDef(AliHLTTPCCompModelDeconverter, 1)
+
+    };
+#endif
diff --git a/HLT/TPCLib/comp/AliHLTTPCCompModelDeconverterComponent.cxx b/HLT/TPCLib/comp/AliHLTTPCCompModelDeconverterComponent.cxx
new file mode 100644 (file)
index 0000000..43df7a2
--- /dev/null
@@ -0,0 +1,239 @@
+// $Id: AliHLTTPCCompModelDeconverterComponent.cxx,v 1.2 2006/08/10 09:46:51 richterm Exp $
+
+/**************************************************************************
+ * TPCCompModelDeconverterright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Authors: 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.                  *
+ **************************************************************************/
+
+/** @file   AliHLTTPCCompModelDeconverterComponent.cxx
+    @author Timm Steinbeck
+    @date   
+    @brief  A copy processing component for the HLT. */
+
+#if __GNUC__ >= 3
+using namespace std;
+#endif
+
+#include "AliHLTTPCCompModelDeconverterComponent.h"
+#include "AliHLTTPCDefinitions.h"
+#include <stdlib.h>
+#include <errno.h>
+
+// this is a global object used for automatic component registration, do not use this
+AliHLTTPCCompModelDeconverterComponent gAliHLTTPCCompClusterModelDeconverterComponent;
+
+ClassImp(AliHLTTPCCompModelDeconverterComponent)
+    
+AliHLTTPCCompModelDeconverterComponent::AliHLTTPCCompModelDeconverterComponent():
+    fOutputTracks(kTRUE)
+    {
+      // see header file for class documentation
+    }
+
+AliHLTTPCCompModelDeconverterComponent::~AliHLTTPCCompModelDeconverterComponent()
+    {
+      // see header file for class documentation
+    }
+
+const char* AliHLTTPCCompModelDeconverterComponent::GetComponentID()
+    {
+      // see header file for class documentation
+      return "TPCCompModelDeconverter"; // The ID of this component
+    }
+
+void AliHLTTPCCompModelDeconverterComponent::GetInputDataTypes( vector<AliHLTComponent_DataType>& list)
+    {
+      // see header file for class documentation
+      list.clear(); // We do not have any requirements for our input data type(s).
+      list.push_back( AliHLTTPCDefinitions::fgkClusterTracksModelDataType );
+      list.push_back( AliHLTTPCDefinitions::fgkRemainingClustersModelDataType );
+    }
+
+AliHLTComponent_DataType AliHLTTPCCompModelDeconverterComponent::GetOutputDataType()
+    {
+      // see header file for class documentation
+      return AliHLTTPCDefinitions::fgkClustersDataType;
+    }
+
+void AliHLTTPCCompModelDeconverterComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
+    {
+      // see header file for class documentation
+      constBase = 8+216*4; // Track count + clusters count
+      inputMultiplier = 4.;
+#warning Adapt input Multiplier to something more realistic
+    }
+
+// Spawn function, return new instance of this class
+AliHLTComponent* AliHLTTPCCompModelDeconverterComponent::Spawn()
+    {
+      // see header file for class documentation
+      return new AliHLTTPCCompModelDeconverterComponent;
+    };
+
+int AliHLTTPCCompModelDeconverterComponent::DoInit( int argc, const char** argv )
+    {
+      // see header file for class documentation
+      Int_t i = 0;
+      Char_t* cpErr;
+      
+      while ( i < argc )
+       {      
+         if ( !strcmp( argv[i], "notracks" ) )
+           {
+             fOutputTracks = kFALSE;
+             ++i;
+             continue;
+           }
+         Logging(kHLTLogError, "HLT::TPCCompModelDeconverter::DoInit", "Unknown Option", "Unknown option '%s'", argv[i] );
+         return EINVAL;
+       }
+      return 0;
+    }
+
+int AliHLTTPCCompModelDeconverterComponent::DoDeinit()
+    {
+      // see header file for class documentation
+      return 0;
+    }
+
+int AliHLTTPCCompModelDeconverterComponent::DoEvent( const AliHLTComponent_EventData& evtData, const AliHLTComponent_BlockData* blocks, 
+                                                  AliHLTComponent_TriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr, 
+                                     AliHLTUInt32_t& size, vector<AliHLTComponent_BlockData>& outputBlocks )
+    {
+      // see header file for class documentation
+      fDeconverter.Init();
+      // Process an event
+      // Loop over all input blocks in the event
+      AliHLTUInt8_t minSlice=0xFF, maxSlice=0xFF, minPatch=0xFF, maxPatch=0xFF;
+      for ( unsigned long n = 0; n < evtData.fBlockCnt; n++ )
+       {
+         AliHLTUInt8_t slice, patch;
+         if ( blocks[n].fDataType == AliHLTTPCDefinitions::fgkRemainingClustersModelDataType ||
+              blocks[n].fDataType == AliHLTTPCDefinitions::fgkClusterTracksModelDataType )
+           {
+             slice = AliHLTTPCDefinitions::GetMinSliceNr( blocks[n].fSpecification );
+             patch = AliHLTTPCDefinitions::GetMinPatchNr( blocks[n].fSpecification );
+             if ( minSlice==0xFF || slice<minSlice )
+               minSlice = slice;
+             if ( maxSlice==0xFF || slice>maxSlice )
+               maxSlice = slice;
+             if ( minPatch==0xFF || patch<minPatch )
+               minPatch = patch;
+             if ( maxPatch==0xFF || patch>maxPatch )
+               maxPatch = patch;
+             HLTDebug( "Slice: %u - Patch: %u", (unsigned)slice, (unsigned)patch );
+             slice = AliHLTTPCDefinitions::GetMaxSliceNr( blocks[n].fSpecification );
+             patch = AliHLTTPCDefinitions::GetMaxPatchNr( blocks[n].fSpecification );
+             if ( minSlice==0xFF || slice<minSlice )
+               minSlice = slice;
+             if ( maxSlice==0xFF || slice>maxSlice )
+               maxSlice = slice;
+             if ( minPatch==0xFF || patch<minPatch )
+               minPatch = patch;
+             if ( maxPatch==0xFF || patch>maxPatch )
+               maxPatch = patch;
+             HLTDebug( "Slice: %u - Patch: %u", (unsigned)slice, (unsigned)patch );
+           }
+         if ( blocks[n].fDataType == AliHLTTPCDefinitions::fgkClusterTracksModelDataType )
+           {
+             HLTDebug( "Tracks" );
+             fDeconverter.SetTrackClusterModelInputData( (AliHLTUInt8_t*)blocks[n].fPtr, blocks[n].fSize );
+           }
+         if ( blocks[n].fDataType == AliHLTTPCDefinitions::fgkRemainingClustersModelDataType )
+           {
+             HLTDebug( "Clusters" );
+             fDeconverter.SetRemainingClustersModelInputData( (AliHLTUInt8_t*)blocks[n].fPtr, blocks[n].fSize );
+           }
+       }
+      
+      HLTDebug( "min slice: %u - max slice: %u - min patch: %u - max patch: %u",
+               (unsigned)minSlice, (unsigned)maxSlice, (unsigned)minPatch, (unsigned)maxPatch );
+      
+      UInt_t blockSize = size;
+      UInt_t outputSize = 0;
+      Int_t ret;
+      if ( fOutputTracks )
+       {
+         ret = fDeconverter.DeconvertTracks( outputPtr, blockSize );
+         if ( !ret )
+           {
+             if ( outputSize+blockSize > size )
+               {
+                 HLTError( "Output data too large. (%lu used instead of %u available)",
+                           (unsigned long)blockSize, (unsigned long)size );
+                 return ENOBUFS;
+               }
+             
+             AliHLTComponent_BlockData ob;
+             // Let the structure be filled with the default values.
+             // This takes care of setting the shared memory and data type values to default values,
+             // so that they can be filled in by the calling code.
+             FillBlockData( ob );
+             // This block's start (offset) is after all other blocks written so far
+             ob.fOffset = outputSize;
+             // the size of this block's data.
+             ob.fSize = blockSize;
+             // The specification of the data is copied from the input block.
+             ob.fSpecification = AliHLTTPCDefinitions::EncodeDataSpecification( minSlice, maxSlice, minPatch, maxPatch );
+             // The type of the data is copied from the input block.
+             ob.fDataType = AliHLTTPCDefinitions::fgkTracksDataType;
+             // Place this block into the list of output blocks
+             outputBlocks.push_back( ob );
+             outputSize += blockSize;
+           }
+         else
+           HLTError( "Error deconverting tracks: %s (%d)", strerror(ret), (int)ret );
+       }
+      
+      for ( UInt_t slice=minSlice; slice<=maxSlice; slice++ )
+       {
+         for ( UInt_t patch=minPatch; patch<=maxPatch; patch++ )
+           {
+             blockSize = size-outputSize;
+             ret = fDeconverter.DeconvertClusters( slice, patch, outputPtr+outputSize, blockSize );
+             if ( !ret )
+               {
+                 if ( outputSize+blockSize > size )
+                   {
+                     HLTError( "Output data too large. (%lu used instead of %u available)",
+                               (unsigned long)blockSize, (unsigned long)size );
+                     return ENOBUFS;
+                   }
+                 
+                 AliHLTComponent_BlockData ob;
+                 // Let the structure be filled with the default values.
+                 // This takes care of setting the shared memory and data type values to default values,
+                 // so that they can be filled in by the calling code.
+                 FillBlockData( ob );
+                 // This block's start (offset) is after all other blocks written so far
+                 ob.fOffset = outputSize;
+                 // the size of this block's data.
+                 ob.fSize = blockSize;
+                 // The specification of the data is copied from the input block.
+                 ob.fSpecification = AliHLTTPCDefinitions::EncodeDataSpecification( slice, slice, patch, patch );
+                 // The type of the data is copied from the input block.
+                 ob.fDataType = AliHLTTPCDefinitions::fgkClustersDataType;
+                 // Place this block into the list of output blocks
+                 outputBlocks.push_back( ob );
+                 outputSize += blockSize;
+               }
+             else
+               HLTError( "Error deconverting clusters for slice %u, patch %u: %s (%d)", 
+                         (unsigned)slice, (unsigned)patch, strerror(ret), (int)ret );
+           }
+       }
+      
+      // Finally we set the total size of output memory we consumed.
+      size = outputSize;
+      return 0;
+    }
diff --git a/HLT/TPCLib/comp/AliHLTTPCCompModelDeconverterComponent.h b/HLT/TPCLib/comp/AliHLTTPCCompModelDeconverterComponent.h
new file mode 100644 (file)
index 0000000..37e3028
--- /dev/null
@@ -0,0 +1,105 @@
+// XEmacs -*-C++-*-
+// $Id: AliHLTTPCCompModelDeconverterComponent.h,v 1.2 2006/08/10 09:46:51 richterm Exp $
+
+#ifndef ALIHLTTPCCOMPMODELDECONVERTERCOMPONENT_H
+#define ALIHLTTPCCOMPMODELDECONVERTERCOMPONENT_H
+/* TPCCompModelDeconverterright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full TPCCompModelDeconverterright notice                               */
+
+/** @file   AliHLTTPCCompModelDeconverterComponent.h
+    @author Timm Steinbeck
+    @date   
+    @brief  Declaration of a copy component. */
+
+
+#include "AliHLTProcessor.h"
+#include "AliHLTTPCCompModelDeconverter.h"
+
+/**
+ * @class AliHLTTPCCompModelDeconverterComponent
+ * @brief A dummy HLT processing component. 
+ *
+ * An implementiation of a copy component that just copies its input data
+ * to debug a components input data
+ * @ingroup alihlt_tutorial
+ */
+class AliHLTTPCCompModelDeconverterComponent : public AliHLTProcessor
+    {
+    public:
+
+      /** standard constructor */
+      AliHLTTPCCompModelDeconverterComponent();
+      /** standard deconstructor */
+      virtual ~AliHLTTPCCompModelDeconverterComponent();
+      
+      // Public functions to implement AliHLTComponent's interface.
+      // These functions are required for the registration process
+      
+      /** function to get component id 
+       * @return const char* pointer to componentid
+       */
+      const char* GetComponentID();
+
+      /** function to get input data types
+       * @param list vecotr of AliHLTComponent_DataType
+       */ 
+      void GetInputDataTypes( vector<AliHLTComponent_DataType>& list);
+
+      /** function to get output data type
+       * @return AliHLTComponent_DataType
+       */
+      AliHLTComponent_DataType GetOutputDataType();
+
+      /** function to get output data size
+       * @param constBase address of an unsigned long
+       * @param inputMultiplier address of a double
+       */
+      virtual void GetOutputDataSize( unsigned long& constBase, double& inputMultiplier );
+
+      /** spawn function
+       * @return AliHLTComponent* pointer to instance
+       */
+      AliHLTComponent* Spawn();
+       
+    protected:
+       
+       // Protected functions to implement AliHLTComponent's interface.
+       // These functions provide initialization as well as the actual processing
+       // capabilities of the component. 
+      
+      /** initialisation function
+       * @param argc integer counting number of input arguments
+       * @param argv const char** for parameter values
+       * @return zero upon success
+       */
+      int DoInit( int argc, const char** argv );
+
+      /** deinitialisation function
+       * @return zero upon success
+       */
+      int DoDeinit();
+
+      /** do event function
+       * @param evt Data     const AliHLTComponent_EventData& to event data
+       * @param blocks       const AliHLTComponent_BlockData* to blocks of event data
+       * @param trigData     AliHLTComponent_TriggerData& of trigger data
+       * @param outputPtr    AliHLTUInt8_t* pointer to output data
+       * @param size         AliHLTUInt32_t& of output size
+       * @param outputBlocks vector<AliHLTComponent_BlockData>& of output block data
+       * @return zero upon success
+       */
+      int DoEvent( const AliHLTComponent_EventData& evtData, const AliHLTComponent_BlockData* blocks, 
+                  AliHLTComponent_TriggerData& trigData, AliHLTUInt8_t* outputPtr, 
+                  AliHLTUInt32_t& size, vector<AliHLTComponent_BlockData>& outputBlocks );
+      
+      /** member variable for instance of deconverter class */
+      AliHLTTPCCompModelDeconverter fDeconverter;
+      /** memeber varible for output tracks */
+      bool fOutputTracks;
+
+    private:
+
+       ClassDef(AliHLTTPCCompModelDeconverterComponent, 0)
+
+    };
+#endif
diff --git a/HLT/TPCLib/comp/AliHLTTPCCompModelDeflater.cxx b/HLT/TPCLib/comp/AliHLTTPCCompModelDeflater.cxx
new file mode 100644 (file)
index 0000000..729703c
--- /dev/null
@@ -0,0 +1,570 @@
+// $Id: AliHLTTPCCompModelDeflater.cxx,v 1.2 2006/08/10 09:46:51 richterm Exp $
+
+/**************************************************************************
+ * TPCCompModelDeflaterright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Authors: 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.                  *
+ **************************************************************************/
+
+/** @file   AliHLTTPCCompModelDeflater.cxx
+    @author Timm Steinbeck
+    @date   
+    @brief  A copy processing component for the HLT. */
+
+#if __GNUC__ >= 3
+using namespace std;
+#endif
+
+#include "AliHLTTPCCompModelDeflater.h"
+#include "AliHLTTPCTransform.h"
+#include "AliHLTTPCTrack.h"
+#include "AliHLTTPCModelTrack.h"
+#include "AliHLTTPCCompDataCompressorHelper.h"
+#include "AliHLTDataTypes.h"
+#include <cerrno>
+
+AliHLTTPCCompModelDeflater::AliHLTTPCCompModelDeflater():
+    fWriteShape(true),
+    fBitDataCurrentWord(0),
+    fBitDataCurrentPosInWord(0),
+    fBitDataCurrentOutput(0),
+    fBitDataCurrentOutputStart(0),
+    fBitDataCurrentOutputEnd(0)
+    {
+      // see header file for class documentation
+    }
+
+AliHLTTPCCompModelDeflater::~AliHLTTPCCompModelDeflater()
+    {
+      // see header file for class documentation
+    }
+
+int AliHLTTPCCompModelDeflater::CompressTracks( AliHLTUInt8_t* inData, UInt_t const& inputSize, AliHLTUInt8_t* output, UInt_t& outputSize )
+    {
+      // see header file for class documentation
+      AliHLTUInt8_t* inputPtr = inData;
+      AliHLTUInt8_t* inputEndPtr = inData+inputSize;
+      
+      if ( inputPtr+sizeof(AliHLTUInt32_t)>inputEndPtr )
+       {
+         HLTError( "Cannot read input data version number" );
+         return EIO;
+       }
+      if ( *(AliHLTUInt32_t*)inputPtr != 0 )
+       {
+         HLTError( "Only input data format version 0 is supported. Found version: %u",
+                   (unsigned)*(AliHLTUInt32_t*)inputPtr );
+         return EINVAL;
+       }
+      inputPtr += sizeof(AliHLTUInt32_t);
+      
+      printf( "outuptSize: %lu\n", (unsigned long)outputSize );
+      
+      InitBitDataOutput( output, outputSize );
+      HLTDebug( "Output: Position: %lu / %u (0x%02X)", GetCurrentByteOutputPosition(), GetCurrentBitOutputPosition(), (unsigned)GetCurrentOutputByte() );
+      OutputBits( 0, 4 ); // Version information
+      HLTDebug( "Output: Position: %lu / %u (0x%02X)", GetCurrentByteOutputPosition(), GetCurrentBitOutputPosition(), (unsigned)GetCurrentOutputByte() );
+      OutputBit( fWriteShape ? 1 : 0 ); // Data format flag
+      HLTDebug( "Output: Position: %lu / %u (0x%02X)", GetCurrentByteOutputPosition(), GetCurrentBitOutputPosition(), (unsigned)GetCurrentOutputByte() );
+      Pad8Bits();
+      HLTDebug( "Output: Position: %lu / %u (0x%02X / 0x%02X)", GetCurrentByteOutputPosition(), GetCurrentBitOutputPosition(), (unsigned)GetCurrentOutputByte(-1), (unsigned)GetCurrentOutputByte() );
+      
+      AliHLTTPCClusterModel *cluster;
+      Int_t temp;
+      Int_t power;
+      
+      Int_t timeo,pado,chargeo,padshapeo,timeshapeo;
+      timeo=pado=chargeo=padshapeo=timeshapeo=0;
+      unsigned trackCnt=0;
+      while( inputPtr<inputEndPtr )
+       {
+         if ( !OutputBytes( inputPtr, sizeof(AliHLTTPCTrackModel) ) )
+           {
+             HLTError( "Not enough space to write compressed data. %lu already written",
+                       (unsigned long)GetBitDataOutputSizeBytes() );
+             printf( "TRACE: %s:%d\n", __FILE__, __LINE__ );
+             outputSize = GetBitDataOutputSizeBytes();
+             return ENOBUFS;
+           }
+         HLTDebug( "sizeof(AliHLTTPCTrackModel): %d", sizeof(AliHLTTPCTrackModel) );
+         HLTDebug( "Output: Position: %lu / %u (0x%02X / 0x%02X)", GetCurrentByteOutputPosition(), GetCurrentBitOutputPosition(), (unsigned)GetCurrentOutputByte(-1), (unsigned)GetCurrentOutputByte() );
+         inputPtr += sizeof(AliHLTTPCTrackModel);
+         
+         Int_t origslice=-1,slice,clustercount=0;
+         for(Int_t i=0; i<AliHLTTPCTransform::GetNRows(); i++)
+           {
+             cluster = (AliHLTTPCClusterModel*)inputPtr;
+             inputPtr += sizeof(AliHLTTPCClusterModel);
+             
+             //Write empty flag:
+             if ( !OutputBit( cluster->fPresent ? 1 : 0 ) )
+               {
+                 HLTError( "Not enough space to write compressed data. %lu already written",
+                           (unsigned long)GetBitDataOutputSizeBytes() );
+                 printf( "TRACE: %s:%d\n", __FILE__, __LINE__ );
+                 outputSize = GetBitDataOutputSizeBytes();
+                 return ENOBUFS;
+               }
+             HLTDebug( "Output: Position: %lu / %u (0x%02X / 0x%02X)", GetCurrentByteOutputPosition(), GetCurrentBitOutputPosition(), (unsigned)GetCurrentOutputByte(-1), (unsigned)GetCurrentOutputByte() );
+             if ( !cluster->fPresent )
+               continue;
+           
+             if ( cluster->fSlice<0 || cluster->fSlice>35 )
+               {
+                 HLTError( "Inconsistent slice number %u (track %u, cluster %d)", cluster->fSlice, trackCnt, i );
+                 printf( "TRACE: %s:%d\n", __FILE__, __LINE__ );
+                 return EINVAL;
+               }
+             
+             //Write slice number of first point
+             if ( clustercount==0 )
+               {
+                 origslice = cluster->fSlice;
+                 if ( !OutputBits( origslice,6 ) ) //Need 6 bits to encode slice number
+                   {
+                     HLTError( "Not enough space to write compressed data. %lu already written",
+                               (unsigned long)GetBitDataOutputSizeBytes() );
+                     printf( "TRACE: %s:%d\n", __FILE__, __LINE__ );
+                     outputSize = GetBitDataOutputSizeBytes();
+                     return ENOBUFS;
+                   }
+                 HLTDebug( "Output: Position: %lu / %u (0x%02X / 0x%02X)", GetCurrentByteOutputPosition(), GetCurrentBitOutputPosition(), (unsigned)GetCurrentOutputByte(-1), (unsigned)GetCurrentOutputByte() );
+               }
+             else
+               {
+                 slice = cluster->fSlice;
+                 if( slice == origslice )
+                   {
+                     if ( !OutputBit( 0 ) )  //No change of slice
+                       {
+                         HLTError( "Not enough space to write compressed data. %lu already written",
+                                   (unsigned long)GetBitDataOutputSizeBytes() );
+                         outputSize = GetBitDataOutputSizeBytes();
+                         printf( "TRACE: %s:%d\n", __FILE__, __LINE__ );
+                         return ENOBUFS;
+                       }
+                     HLTDebug( "No slice change (%d/%d)", (int)origslice, (int)slice );
+                     HLTDebug( "Output: Position: %lu / %u (0x%02X / 0x%02X)", GetCurrentByteOutputPosition(), GetCurrentBitOutputPosition(), (unsigned)GetCurrentOutputByte(-1), (unsigned)GetCurrentOutputByte() );
+                   }
+                 else
+                   {
+                     if ( !OutputBit( 1 ) )
+                       {
+                         HLTError( "Not enough space to write compressed data. %lu already written",
+                                   (unsigned long)GetBitDataOutputSizeBytes() );
+                         outputSize = GetBitDataOutputSizeBytes();
+                         printf( "TRACE: %s:%d\n", __FILE__, __LINE__ );
+                         return ENOBUFS;
+                       }
+                     HLTDebug( "Slice change (%d/%d)", (int)origslice, (int)slice );
+                     HLTDebug( "Output: Position: %lu / %u (0x%02X / 0x%02X)", GetCurrentByteOutputPosition(), GetCurrentBitOutputPosition(), (unsigned)GetCurrentOutputByte(-1), (unsigned)GetCurrentOutputByte() );
+                     if ( !OutputBits( slice, 6 ) )
+                       {
+                         HLTError( "Not enough space to write compressed data. %lu already written",
+                                   (unsigned long)GetBitDataOutputSizeBytes() );
+                         outputSize = GetBitDataOutputSizeBytes();
+                         printf( "TRACE: %s:%d\n", __FILE__, __LINE__ );
+                         return ENOBUFS;
+                       }
+                     HLTDebug( "Output: Position: %lu / %u (0x%02X / 0x%02X)", GetCurrentByteOutputPosition(), GetCurrentBitOutputPosition(), (unsigned)GetCurrentOutputByte(-1), (unsigned)GetCurrentOutputByte() );
+                     origslice=slice;
+                   }
+               }
+             
+             //Write time information:
+             temp = (Int_t)rint(cluster->fDTime);
+             if( temp<0 )
+               {
+               if ( !OutputBit( 0 ) )
+                 {
+                   HLTError( "Not enough space to write compressed data. %lu already written",
+                             (unsigned long)GetBitDataOutputSizeBytes() );
+                   outputSize = GetBitDataOutputSizeBytes();
+                   printf( "TRACE: %s:%d\n", __FILE__, __LINE__ );
+                   return ENOBUFS;
+                 }
+               HLTDebug( "Output: Position: %lu / %u (0x%02X / 0x%02X)", GetCurrentByteOutputPosition(), GetCurrentBitOutputPosition(), (unsigned)GetCurrentOutputByte(-1), (unsigned)GetCurrentOutputByte() );
+               }
+             else
+               {
+                 if ( !OutputBit( 1 ) )
+                   {
+                     HLTError( "Not enough space to write compressed data. %lu already written",
+                               (unsigned long)GetBitDataOutputSizeBytes() );
+                     printf( "TRACE: %s:%d\n", __FILE__, __LINE__ );
+                     outputSize = GetBitDataOutputSizeBytes();
+                     return ENOBUFS;
+                   }
+                 HLTDebug( "Output: Position: %lu / %u (0x%02X / 0x%02X)", GetCurrentByteOutputPosition(), GetCurrentBitOutputPosition(), (unsigned)GetCurrentOutputByte(-1), (unsigned)GetCurrentOutputByte() );
+               }
+             power = 1<<(AliHLTTPCCompDataCompressorHelper::GetNTimeBits()-1);
+             if ( abs(temp)>=power )
+               {
+                 //cout<<abs(temp)<<" "<<power<<endl;
+                 timeo++;
+                 temp=power - 1;
+               }
+             temp = abs(temp);
+             if ( !OutputBits(temp,(AliHLTTPCCompDataCompressorHelper::GetNTimeBits()-1)) )
+               {
+                 HLTError( "Not enough space to write compressed data. %lu already written",
+                           (unsigned long)GetBitDataOutputSizeBytes() );
+                 printf( "TRACE: %s:%d\n", __FILE__, __LINE__ );
+                 outputSize = GetBitDataOutputSizeBytes();
+                 return ENOBUFS;
+               }
+             HLTDebug( "Output: Position: %lu / %u (0x%02X / 0x%02X / 0x%02X)", GetCurrentByteOutputPosition(), GetCurrentBitOutputPosition(), (unsigned)GetCurrentOutputByte(-2), (unsigned)GetCurrentOutputByte(-1), (unsigned)GetCurrentOutputByte() );
+             
+             //Write pad information:
+             temp = (Int_t)rint(cluster->fDPad);
+             HLTDebug( "cluster->fDPad (%d): %f - temp: %d", clustercount, cluster->fDPad, temp );
+             if ( temp<0 )
+               {
+                 if ( !OutputBit( 0 ) )
+                   {
+                     HLTError( "Not enough space to write compressed data. %lu already written",
+                               (unsigned long)GetBitDataOutputSizeBytes() );
+                     outputSize = GetBitDataOutputSizeBytes();
+                     printf( "TRACE: %s:%d\n", __FILE__, __LINE__ );
+                     return ENOBUFS;
+                   }
+                 HLTDebug( "Output: Position: %lu / %u (0x%02X / 0x%02X)", GetCurrentByteOutputPosition(), GetCurrentBitOutputPosition(), (unsigned)GetCurrentOutputByte(-1), (unsigned)GetCurrentOutputByte() );
+               }
+             else
+               {
+               if ( !OutputBit( 1 ) )
+                 {
+                   HLTError( "Not enough space to write compressed data. %lu already written",
+                             (unsigned long)GetBitDataOutputSizeBytes() );
+                   outputSize = GetBitDataOutputSizeBytes();
+                   printf( "TRACE: %s:%d\n", __FILE__, __LINE__ );
+                   return ENOBUFS;
+                 }
+               HLTDebug( "Output: Position: %lu / %u (0x%02X / 0x%02X)", GetCurrentByteOutputPosition(), GetCurrentBitOutputPosition(), (unsigned)GetCurrentOutputByte(-1), (unsigned)GetCurrentOutputByte() );
+               }
+             power = 1<<(AliHLTTPCCompDataCompressorHelper::GetNPadBits()-1);
+             if ( abs(temp)>=power )
+               {
+                 pado++;
+                 temp=power - 1;
+               }
+             temp = abs(temp);
+             if ( !OutputBits(temp,(AliHLTTPCCompDataCompressorHelper::GetNPadBits()-1)) )
+               {
+                 HLTError( "Not enough space to write compressed data. %lu already written",
+                           (unsigned long)GetBitDataOutputSizeBytes() );
+                 outputSize = GetBitDataOutputSizeBytes();
+                 printf( "TRACE: %s:%d\n", __FILE__, __LINE__ );
+                 return ENOBUFS;
+               }
+             HLTDebug( "Output: Position: %lu / %u (0x%02X / 0x%02X / 0x%02X)", GetCurrentByteOutputPosition(), GetCurrentBitOutputPosition(), (unsigned)GetCurrentOutputByte(-2), (unsigned)GetCurrentOutputByte(-1), (unsigned)GetCurrentOutputByte() );
+             
+             //Write charge information:
+             temp = (Int_t)cluster->fDCharge;
+             power = 1<<(AliHLTTPCCompDataCompressorHelper::GetNChargeBits());
+             if ( abs(temp)>=power )
+               {
+                 chargeo++;
+                 temp=power - 1;
+               }
+             temp = abs(temp);
+             if ( !OutputBits(temp,(AliHLTTPCCompDataCompressorHelper::GetNChargeBits())) )
+               {
+                 HLTError( "Not enough space to write compressed data. %lu already written",
+                           (unsigned long)GetBitDataOutputSizeBytes() );
+                 outputSize = GetBitDataOutputSizeBytes();
+                 printf( "TRACE: %s:%d\n", __FILE__, __LINE__ );
+                 return ENOBUFS;
+               }
+             HLTDebug( "Output: Position: %lu / %u (0x%02X / 0x%02X / 0x%02X)", GetCurrentByteOutputPosition(), GetCurrentBitOutputPosition(), (unsigned)GetCurrentOutputByte(-2), (unsigned)GetCurrentOutputByte(-1), (unsigned)GetCurrentOutputByte() );
+             
+             if ( fWriteShape )
+               {
+                 //Write shape information:
+                 // HLTInfo("DSigmaY %f", cluster->fDSigmaY);
+                 temp = (Int_t)rint(cluster->fDSigmaY);
+                 // HLTInfo("temp %d", temp);
+                 if( temp<0 )
+                   {
+                     if ( !OutputBit( 0 ) )
+                       {
+                         HLTError( "Not enough space to write compressed data. %lu already written",
+                                   (unsigned long)GetBitDataOutputSizeBytes() );
+                         printf( "TRACE: %s:%d\n", __FILE__, __LINE__ );
+                         outputSize = GetBitDataOutputSizeBytes();
+                         return ENOBUFS;
+                       }
+                     HLTDebug( "Output: Position: %lu / %u (0x%02X / 0x%02X)", GetCurrentByteOutputPosition(), GetCurrentBitOutputPosition(), (unsigned)GetCurrentOutputByte(-1), (unsigned)GetCurrentOutputByte() );
+                   }
+                 else
+                   {
+                     if ( !OutputBit( 1 ) )
+                       {
+                         HLTError( "Not enough space to write compressed data. %lu already written",
+                                   (unsigned long)GetBitDataOutputSizeBytes() );
+                         outputSize = GetBitDataOutputSizeBytes();
+                         printf( "TRACE: %s:%d\n", __FILE__, __LINE__ );
+                         return ENOBUFS;
+                       }
+                     HLTDebug( "Output: Position: %lu / %u (0x%02X / 0x%02X)", GetCurrentByteOutputPosition(), GetCurrentBitOutputPosition(), (unsigned)GetCurrentOutputByte(-1), (unsigned)GetCurrentOutputByte() );
+                   }
+                 power = 1<<(AliHLTTPCCompDataCompressorHelper::GetNShapeBits()-1);
+                 if ( abs(temp) >= power )
+                   {
+                     padshapeo++;
+                     temp = power - 1;
+                   }
+                 temp = abs(temp);
+                 if ( !OutputBits(temp,(AliHLTTPCCompDataCompressorHelper::GetNShapeBits()-1)) )
+                   {
+                     HLTError( "Not enough space to write compressed data. %lu already written",
+                               (unsigned long)GetBitDataOutputSizeBytes() );
+                     printf( "TRACE: %s:%d\n", __FILE__, __LINE__ );
+                     outputSize = GetBitDataOutputSizeBytes();
+                     return ENOBUFS;
+                   }
+                 HLTDebug( "Output: Position: %lu / %u (0x%02X / 0x%02X / 0x%02X)", GetCurrentByteOutputPosition(), GetCurrentBitOutputPosition(), (unsigned)GetCurrentOutputByte(-2), (unsigned)GetCurrentOutputByte(-1), (unsigned)GetCurrentOutputByte() );
+                 
+                 temp = (Int_t)rint(cluster->fDSigmaZ);
+                 if ( temp<0 )
+                   {
+                     if ( !OutputBit( 0 ) )
+                       {
+                         HLTError( "Not enough space to write compressed data. %lu already written",
+                                   (unsigned long)GetBitDataOutputSizeBytes() );
+                         printf( "TRACE: %s:%d\n", __FILE__, __LINE__ );
+                         outputSize = GetBitDataOutputSizeBytes();
+                         return ENOBUFS;
+                       }
+                     HLTDebug( "Output: Position: %lu / %u (0x%02X / 0x%02X)", GetCurrentByteOutputPosition(), GetCurrentBitOutputPosition(), (unsigned)GetCurrentOutputByte(-1), (unsigned)GetCurrentOutputByte() );
+                   }
+                 else
+                   {
+                     if ( !OutputBit( 1 ) )
+                       {
+                         HLTError( "Not enough space to write compressed data. %lu already written",
+                                   (unsigned long)GetBitDataOutputSizeBytes() );
+                         printf( "TRACE: %s:%d\n", __FILE__, __LINE__ );
+                         outputSize = GetBitDataOutputSizeBytes();
+                         return ENOBUFS;
+                       }
+                     HLTDebug( "Output: Position: %lu / %u (0x%02X / 0x%02X)", GetCurrentByteOutputPosition(), GetCurrentBitOutputPosition(), (unsigned)GetCurrentOutputByte(-1), (unsigned)GetCurrentOutputByte() );
+                   }
+                 power = 1<<(AliHLTTPCCompDataCompressorHelper::GetNShapeBits()-1);
+                 if ( abs(temp) >= power )
+                   {
+                     timeshapeo++;
+                     temp=power - 1;
+                   }
+                 temp = abs(temp);
+                 if ( !OutputBits(temp,(AliHLTTPCCompDataCompressorHelper::GetNShapeBits()-1)) )
+                   {
+                     HLTError( "Not enough space to write compressed data. %lu already written",
+                               (unsigned long)GetBitDataOutputSizeBytes() );
+                     printf( "TRACE: %s:%d\n", __FILE__, __LINE__ );
+                     outputSize = GetBitDataOutputSizeBytes();
+                     return ENOBUFS;
+                   }
+                 HLTDebug( "Output: Position: %lu / %u (0x%02X / 0x%02X / 0x%02X)", GetCurrentByteOutputPosition(), GetCurrentBitOutputPosition(), (unsigned)GetCurrentOutputByte(-2), (unsigned)GetCurrentOutputByte(-1), (unsigned)GetCurrentOutputByte() );
+               }
+             
+             clustercount++;
+           }
+         trackCnt++;
+       }
+      
+      CloseBitDataOutput();
+      HLTDebug( "Output: Position: %lu / %u (0x%02X / 0x%02X)", GetCurrentByteOutputPosition(), GetCurrentBitOutputPosition(), (unsigned)GetCurrentOutputByte(-1), (unsigned)GetCurrentOutputByte() );
+      outputSize = GetBitDataOutputSizeBytes();
+      return 0;
+    }
+
+int AliHLTTPCCompModelDeflater::CompressRemainingClusters( AliHLTUInt8_t* inData, UInt_t const& inputSize, AliHLTUInt8_t* output, UInt_t& outputSize )
+    {
+      // see header file for class documentation
+      AliHLTUInt8_t* inputPtr = inData;
+      AliHLTUInt8_t* inputEndPtr = inData+inputSize;
+      
+      AliHLTUInt32_t version = *(AliHLTUInt32_t*)inputPtr;
+      inputPtr += sizeof(AliHLTUInt32_t);
+      if ( version != 0 )
+       {
+         HLTError( "Unsupported version %hu. Only version 0 supported currently.", version );
+         return EIO;
+       }
+      
+      InitBitDataOutput( output, outputSize );
+      OutputBits( 0, 4 ); // Version information
+      //OutputBit( fWriteShape ); // Data format flag
+      Pad8Bits();
+      
+      //Write the remaining clusters in a compressed format.
+      
+      for(Int_t slice=0; slice<=35; slice++)
+       {
+         for(Int_t patch=0; patch < 6; patch++)
+           {
+             UInt_t i;
+             HLTDebug( "slice %u patch %u: %u padrows",
+                       (unsigned)slice, (unsigned)patch, (unsigned)*inputPtr );
+             //Write number of padrows with clusters
+             if ( inputPtr>=inputEndPtr )
+               {
+                 HLTError( "Corrupt input data, cannot read row counter for slice %u, partition %u", (unsigned)slice, (unsigned)patch );
+                 return EIO;
+               }
+             if ( !OutputBits( *inputPtr,8 ) )
+               {
+                 HLTError( "Not enough space to write compressed data. %lu already written",
+                           (unsigned long)GetBitDataOutputSizeBytes() );
+                 outputSize = GetBitDataOutputSizeBytes();
+                 return ENOBUFS;
+               }
+             if ( !*inputPtr )
+               {
+                 inputPtr++;
+                 continue;
+               }
+             UInt_t nRows=(UInt_t)*inputPtr;
+             inputPtr++;
+             if ( inputPtr>=inputEndPtr )
+               {
+                 HLTError( "Corrupt input data, unexpected end of data after row counter for slice %u, partition %u", (unsigned)slice, (unsigned)patch );
+                 return EIO;
+               }
+             
+             for ( UInt_t jj=0; jj<nRows; jj++ )
+               {
+                 
+                 AliHLTTPCRemainingRow *thisRow = (AliHLTTPCRemainingRow*)inputPtr;
+                 if ( inputPtr+sizeof(AliHLTTPCRemainingRow)>inputEndPtr )
+                   {
+                     HLTError( "Corrupt input data, cannot read row data for row %u of slice %u, partition %u", (unsigned)jj, (unsigned)slice, (unsigned)patch );
+                     return EIO;
+                   }
+                 AliHLTTPCRemainingCluster *cl = thisRow->fClusters;
+                 HLTDebug( "Row %u: %u clusters", (unsigned)thisRow->fPadRow, (unsigned)thisRow->fNClusters );
+                 if ( inputPtr+sizeof(AliHLTTPCRemainingRow)+thisRow->fNClusters*sizeof(AliHLTTPCRemainingCluster)>inputEndPtr )
+                   {
+                     HLTError( "Corrupt input data, unable to read clusters for row %u, slice %u, partition %u", (unsigned)jj, (unsigned)slice, (unsigned)patch );
+                     return EIO;
+                   }
+                 Int_t padrow = thisRow->fPadRow;
+                 if ( !OutputBits(padrow,8) ) //Write padrow #
+                   {
+                     HLTError( "Not enough space to write compressed data. %lu already written",
+                               (unsigned long)GetBitDataOutputSizeBytes() );
+                     outputSize = GetBitDataOutputSizeBytes();
+                     return ENOBUFS;
+                   }
+                 if( thisRow->fNClusters >= 1<<10)
+                   {
+                     HLTError( "Too many remaining clusters (%u)", (unsigned)thisRow->fNClusters );
+                     return ERANGE;
+                   }
+                 if ( !OutputBits(thisRow->fNClusters,10) )//Write number of clusters on this padrow
+                   {
+                     HLTError( "Not enough space to write compressed data. %lu already written",
+                               (unsigned long)GetBitDataOutputSizeBytes() );
+                     outputSize = GetBitDataOutputSizeBytes();
+                     return ENOBUFS;
+                   }
+                 for ( i=0; i<thisRow->fNClusters; i++ )
+                   {
+                     
+                     Float_t padw = sqrt(cl[i].fSigmaY2);
+                     //HLTInfo( "padw0: %f", padw );
+                     Float_t timew = sqrt( cl[i].fSigmaZ2 );
+                     
+                     //Check for saturation in the widths.
+                     //Basically only store a certain number of decimals here, and cut the widths which is higher:
+                     if(padw >= (1<<AliHLTTPCCompDataCompressorHelper::GetNShapeBitsRemaining()) / AliHLTTPCCompDataCompressorHelper::GetPadPrecisionFactor())
+                       padw = (1<<AliHLTTPCCompDataCompressorHelper::GetNShapeBitsRemaining()) / AliHLTTPCCompDataCompressorHelper::GetPadPrecisionFactor() - 1/AliHLTTPCCompDataCompressorHelper::GetPadPrecisionFactor();
+                     //HLTInfo( "padw1: %f", padw );
+                     if(timew >= (1<<AliHLTTPCCompDataCompressorHelper::GetNShapeBitsRemaining()) / AliHLTTPCCompDataCompressorHelper::GetTimePrecisionFactor())
+                       timew = (1<<AliHLTTPCCompDataCompressorHelper::GetNShapeBitsRemaining()) / AliHLTTPCCompDataCompressorHelper::GetTimePrecisionFactor() - 1/AliHLTTPCCompDataCompressorHelper::GetTimePrecisionFactor();;
+                     
+                     //Write pad
+                     Int_t buff;
+                     buff = (Int_t)rint(cl[i].fPad*AliHLTTPCCompDataCompressorHelper::GetPadPrecisionFactor());
+                     if(buff<0)
+                       {
+                         HLTError( "Wrong pad value %d (%f, %f, row %u, i: %u)",buff, cl[i].fPad, AliHLTTPCCompDataCompressorHelper::GetPadPrecisionFactor(), (unsigned)thisRow->fNClusters, (unsigned)i );
+                         return EINVAL;
+                       }
+                     if ( !OutputBits(buff,AliHLTTPCCompDataCompressorHelper::GetNPadBitsRemaining()) )
+                       {
+                         HLTError( "Not enough space to write compressed data. %lu already written",
+                                   (unsigned long)GetBitDataOutputSizeBytes() );
+                       outputSize = GetBitDataOutputSizeBytes();
+                       return ENOBUFS;
+                       }
+                     
+                   
+                     //Write time
+                     buff = (Int_t)rint(cl[i].fTime*AliHLTTPCCompDataCompressorHelper::GetTimePrecisionFactor());
+                     if(buff<0)
+                       {
+                         HLTError( "Wrong time value %d",buff);
+                       return EINVAL;
+                       }
+                     if ( !OutputBits(buff,AliHLTTPCCompDataCompressorHelper::GetNTimeBitsRemaining()) )
+                       {
+                         HLTError( "Not enough space to write compressed data. %lu already written",
+                                   (unsigned long)GetBitDataOutputSizeBytes() );
+                         outputSize = GetBitDataOutputSizeBytes();
+                         return ENOBUFS;
+                       }
+                     
+                     //Write widths
+                     buff = (Int_t)rint(padw*AliHLTTPCCompDataCompressorHelper::GetPadPrecisionFactor());
+                     HLTDebug( "padw/buff: %d (%d / 0x%08X)", buff, 
+                               (buff & ((1<<AliHLTTPCCompDataCompressorHelper::GetNShapeBitsRemaining())-1)),
+                               (buff & ((1<<AliHLTTPCCompDataCompressorHelper::GetNShapeBitsRemaining())-1)) );
+                     
+                     if ( !OutputBits(buff,AliHLTTPCCompDataCompressorHelper::GetNShapeBitsRemaining()) )
+                       {
+                       HLTError( "Not enough space to write compressed data. %lu already written",
+                                 (unsigned long)GetBitDataOutputSizeBytes() );
+                       outputSize = GetBitDataOutputSizeBytes();
+                       return ENOBUFS;
+                       }
+                     buff = (Int_t)rint(timew*AliHLTTPCCompDataCompressorHelper::GetTimePrecisionFactor());
+                     if ( !OutputBits(buff,AliHLTTPCCompDataCompressorHelper::GetNShapeBitsRemaining()) )
+                       {
+                         HLTError( "Not enough space to write compressed data. %lu already written",
+                                   (unsigned long)GetBitDataOutputSizeBytes() );
+                         outputSize = GetBitDataOutputSizeBytes();
+                         return ENOBUFS;
+                       }
+                     
+                     //Write charge 
+                     buff = cl[i].fCharge;
+                     if(buff >= 1<<(AliHLTTPCCompDataCompressorHelper::GetNChargeBits()))
+                       buff = (1<<(AliHLTTPCCompDataCompressorHelper::GetNChargeBits()))-1;
+                     if ( !OutputBits(buff,AliHLTTPCCompDataCompressorHelper::GetNChargeBits()) )
+                       {
+                         HLTError( "Not enough space to write compressed data. %lu already written",
+                                   (unsigned long)GetBitDataOutputSizeBytes() );
+                         outputSize = GetBitDataOutputSizeBytes();
+                         return ENOBUFS;
+                       }
+                   }
+                 inputPtr += sizeof(AliHLTTPCRemainingRow)+thisRow->fNClusters*sizeof(AliHLTTPCRemainingCluster);
+               }
+           }
+         
+       }
+      CloseBitDataOutput();
+      outputSize = GetBitDataOutputSizeBytes();
+      return 0;
+    }
diff --git a/HLT/TPCLib/comp/AliHLTTPCCompModelDeflater.h b/HLT/TPCLib/comp/AliHLTTPCCompModelDeflater.h
new file mode 100644 (file)
index 0000000..f8b4562
--- /dev/null
@@ -0,0 +1,263 @@
+// XEmacs -*-C++-*-
+// $Id: AliHLTTPCCompModelDeflater.h,v 1.2 2006/08/10 09:46:51 richterm Exp $
+
+#ifndef ALIHLTTPCCOMPMODELDEFLATER_H
+#define ALIHLTTPCCOMPMODELDEFLATER_H
+/* TPCCompModelDeflaterright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full TPCCompModelDeflaterright notice                               */
+
+/** @file   AliHLTTPCCompModelDeflater.h
+    @author Timm Steinbeck
+    @date   
+    @brief  Declaration of a compressor class for TPC track data. */
+
+#include "AliHLTTPCTrackArray.h"
+#include "AliHLTTPCTrackletDataFormat.h"
+#include "AliHLTTPCClusterDataFormat.h"
+#include "AliHLTLogging.h"
+#include "AliHLTTPCModels.h"
+
+/**
+ * @class AliHLTTPCCompModelDeflater
+ * @brief A HLT TPC track compressor. 
+ *
+ * A class that can compress HLT TPC track model data
+ */
+class AliHLTTPCCompModelDeflater: public AliHLTLogging
+    {
+    public:
+      /** standard constructor */
+      AliHLTTPCCompModelDeflater();
+      /** standard destructor */
+      virtual ~AliHLTTPCCompModelDeflater();
+
+      /** function to write shape */
+      void WriteShape( bool write=true )
+      {
+       fWriteShape = write;
+      }
+
+      /** function to compress tracks
+       * @param inData     AliHLTUInt8_t* pointer to input data
+       * @param inputSize  UInt_t const& input size
+       * @param output     AliHLTUInt8_t* pointer to output data
+       * @param outputSize UInt_t& output size
+       * @return zero upon success
+      */
+       int CompressTracks( AliHLTUInt8_t* inData, UInt_t const& inputSize, AliHLTUInt8_t* output, UInt_t& outputSize );
+
+      /** function to compress remaining clusters
+       * @param inData     AliHLTUInt8_t* pointer to input data
+       * @param inputSize  UInt_t const& input size
+       * @param output     AliHLTUInt8_t* pointer to output data
+       * @param outputSize UInt_t& output size
+       * @return zero upon success
+       */
+       int CompressRemainingClusters( AliHLTUInt8_t* inData, UInt_t const& inputSize, AliHLTUInt8_t* output, UInt_t& outputSize );
+
+    protected:
+
+      /** member variable to write shape */
+      bool fWriteShape;
+      
+      /** function to initialise bit data output
+       * @param output AliHLTUInt8_t* pointer to output data
+       * @param outputSize UInt_t output size
+       */
+      void InitBitDataOutput( AliHLTUInt8_t* output, UInt_t outputSize )
+      {
+       fBitDataCurrentWord = 0;
+       fBitDataCurrentPosInWord = 7;
+       fBitDataCurrentOutput = fBitDataCurrentOutputStart = output;
+       fBitDataCurrentOutputEnd = output+outputSize;
+      }
+      
+      /** function to close bit data output */
+      void CloseBitDataOutput()
+      {
+       Pad8Bits();
+      }
+      
+      /** function to get current byte output position
+       * @return unsigned long value for current byte output position
+       */
+      unsigned long GetCurrentByteOutputPosition() const
+      {
+       return (unsigned long)( fBitDataCurrentOutput - fBitDataCurrentOutputStart );
+      }
+
+      /** function to get current bit output position
+       * @return unsigned long value for current bit output position
+       */
+      unsigned GetCurrentBitOutputPosition() const
+      {
+       return fBitDataCurrentPosInWord;
+      }
+
+      /** function to get current output byte
+       * @param offset Int_t (set to zero if not specified explicitly)
+       * @return AliHLTUInt8_t value for current output byte
+       */
+      AliHLTUInt8_t GetCurrentOutputByte( Int_t offset=0 ) const
+      {
+       if ( !offset )
+         return fBitDataCurrentWord;
+       else
+         return *(fBitDataCurrentOutput+offset);
+      }
+      
+      /** function to get bit data output size bytes
+       * @return UInt_t value of bit data output size bytes
+       */
+      UInt_t GetBitDataOutputSizeBytes() const
+      {
+       return fBitDataCurrentOutput-fBitDataCurrentOutputStart;
+      }
+      
+      /** function for output bit
+       * @param value  AliHLTUInt32_t const & input
+       * @return boolean (output bit)
+       */
+      bool OutputBit( AliHLTUInt32_t const & value )
+      {
+       if ( fBitDataCurrentOutput>=fBitDataCurrentOutputEnd )
+         return false;
+       fBitDataCurrentWord |= (value & 1) << fBitDataCurrentPosInWord;
+       if ( fBitDataCurrentPosInWord )
+         fBitDataCurrentPosInWord--;
+       else
+         {
+           *fBitDataCurrentOutput = fBitDataCurrentWord;
+           fBitDataCurrentPosInWord = 7;
+           fBitDataCurrentOutput++;
+           fBitDataCurrentWord = 0;
+         }
+       return true;
+      }
+
+      /** function to output bits 
+       * @param value     AliHLTUInt64_t const &
+       * @param bitCount  UInt_t const &
+       * @return zero upon success
+       */
+      bool OutputBits( AliHLTUInt64_t const & value, UInt_t const & bitCount )
+      {
+       if ( bitCount>64 )
+         {
+           HLTFatal( "Internal error: Attempt to write more than 64 bits (%u)", (unsigned)bitCount );
+           return false;
+         }
+       UInt_t bitsToWrite=bitCount;
+       UInt_t curBitCount;
+       while ( bitsToWrite>0 )
+         {
+           if ( fBitDataCurrentOutput>=fBitDataCurrentOutputEnd )
+             return false;
+#if 1
+           if ( bitsToWrite >= fBitDataCurrentPosInWord+1 )
+             curBitCount = fBitDataCurrentPosInWord+1;
+           else
+             curBitCount = bitsToWrite;
+           fBitDataCurrentWord |= ( (value >> (bitsToWrite-curBitCount)) & ((1<<curBitCount)-1) ) << (fBitDataCurrentPosInWord+1-curBitCount);
+           if ( fBitDataCurrentPosInWord < curBitCount )
+             {
+               *fBitDataCurrentOutput = fBitDataCurrentWord;
+               fBitDataCurrentPosInWord = 7;
+               fBitDataCurrentOutput++;
+               fBitDataCurrentWord = 0;
+             }
+           else
+             fBitDataCurrentPosInWord -= curBitCount;
+           bitsToWrite -= curBitCount;
+           
+#else
+           AliHLTUInt8_t curValue;
+           if ( bitsToWrite>=8 )
+             {
+               curBitCount=8;
+               curValue = (value >> bitsToWrite-8) & 0xFF;
+               bitsToWrite -= 8;
+             }
+           else
+             {
+               curBitCount=bitsToWrite;
+               curValue = value & ( (1<<bitsToWrite)-1 );
+               bitsToWrite = 0;
+             }
+           if ( fBitDataCurrentPosInWord+1>curBitCount )
+             {
+               fBitDataCurrentWord |= curValue << (fBitDataCurrentPosInWord-curBitCount+1);
+               fBitDataCurrentPosInWord -= curBitCount;
+             }
+           else if ( fBitDataCurrentPosInWord+1==curBitCount )
+             {
+               fBitDataCurrentWord |= curValue;
+               *fBitDataCurrentOutput = fBitDataCurrentWord;
+               fBitDataCurrentPosInWord = 7;
+               fBitDataCurrentOutput++;
+               fBitDataCurrentWord = 0;
+             }
+           else
+             {
+               const UInt_t first = fBitDataCurrentPosInWord+1; // Number of bits for first block
+               const UInt_t second = curBitCount-first; // Number of bits for second block
+               fBitDataCurrentWord |= ( curValue >> second ) & ((1<<first)-1);
+               *fBitDataCurrentOutput = fBitDataCurrentWord;
+               fBitDataCurrentOutput++;
+               if ( fBitDataCurrentOutput>=fBitDataCurrentOutputEnd )
+                 return false;
+               fBitDataCurrentWord = curValue & ((1<<second)-1) << (8-second);
+               fBitDataCurrentPosInWord = 7-second;
+             }
+#endif
+         }
+       return true;
+      }
+
+      /** function pad 8 bits */
+      void Pad8Bits()
+      {
+       if ( fBitDataCurrentPosInWord==7 )
+         return;
+       *fBitDataCurrentOutput = fBitDataCurrentWord;
+       fBitDataCurrentPosInWord = 7;
+       fBitDataCurrentOutput++;
+       fBitDataCurrentWord = 0;
+      }
+
+      /** function to output bytes
+       * @param data  AliHLTUInt8_t const *
+       * @param byteCount UInt_t const &
+       * @return boolean (output bytes)
+       */
+      bool OutputBytes( AliHLTUInt8_t const * data, UInt_t const & byteCount )
+      {
+       Pad8Bits();
+       if ( fBitDataCurrentOutput+byteCount>fBitDataCurrentOutputEnd )
+         return false;
+       memcpy( fBitDataCurrentOutput, data, byteCount );
+       fBitDataCurrentOutput += byteCount;
+       return true;
+      }
+      
+    private:
+      /** copy constructor prohibited */
+      AliHLTTPCCompModelDeflater(const AliHLTTPCCompModelDeflater&);
+      /** assignment operator prohibited */
+      AliHLTTPCCompModelDeflater& operator=(const AliHLTTPCCompModelDeflater&);
+      
+      /** member variable for bit data current word */
+      AliHLTUInt8_t fBitDataCurrentWord;
+      /** member variable for bit data current position in word */
+      UInt_t fBitDataCurrentPosInWord;
+      /** member variable for bit data current output */
+      AliHLTUInt8_t *fBitDataCurrentOutput;
+      /** member variable for bit data current output start */
+      AliHLTUInt8_t *fBitDataCurrentOutputStart;
+      /** member variable for bit data current output end */
+      AliHLTUInt8_t *fBitDataCurrentOutputEnd;
+      
+      ClassDef(AliHLTTPCCompModelDeflater, 0);     
+
+    };
+#endif
diff --git a/HLT/TPCLib/comp/AliHLTTPCCompModelDeflaterComponent.cxx b/HLT/TPCLib/comp/AliHLTTPCCompModelDeflaterComponent.cxx
new file mode 100644 (file)
index 0000000..6a32d40
--- /dev/null
@@ -0,0 +1,308 @@
+// $Id: AliHLTTPCCompModelDeflaterComponent.cxx,v 1.2 2006/08/10 09:46:51 richterm Exp $
+
+/**************************************************************************
+ * TPCCompModelDeflaterright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Authors: 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.                  *
+ **************************************************************************/
+
+/** @file   AliHLTTPCCompModelDeflaterComponent.cxx
+    @author Timm Steinbeck
+    @date   
+    @brief  A copy processing component for the HLT. */
+
+#if __GNUC__ >= 3
+using namespace std;
+#endif
+
+#include "AliHLTTPCCompModelDeflaterComponent.h"
+#include "AliHLTTPCDefinitions.h"
+#include <stdlib.h>
+#include <errno.h>
+
+// this is a global object used for automatic component registration, do not use this
+AliHLTTPCCompModelDeflaterComponent gAliHLTTPCCompClusterModelDeflaterComponent;
+
+ClassImp(AliHLTTPCCompModelDeflaterComponent);
+    
+AliHLTTPCCompModelDeflaterComponent::AliHLTTPCCompModelDeflaterComponent():
+    fForwardIfUncompressed(true)
+    {
+      // see header file for class documentation
+    }
+
+AliHLTTPCCompModelDeflaterComponent::~AliHLTTPCCompModelDeflaterComponent()
+    {
+      // see header file for class documentation
+    }
+
+const char* AliHLTTPCCompModelDeflaterComponent::GetComponentID()
+    {
+      // see header file for class documentation
+      return "TPCCompModelDeflater"; // The ID of this component
+    }
+
+void AliHLTTPCCompModelDeflaterComponent::GetInputDataTypes( vector<AliHLTComponent_DataType>& list)
+    {
+      // see header file for class documentation
+      list.clear(); // We do not have any requirements for our input data type(s).
+      list.push_back( AliHLTTPCDefinitions::fgkClusterTracksModelDataType );
+      list.push_back( AliHLTTPCDefinitions::fgkRemainingClustersModelDataType );
+    }
+
+AliHLTComponent_DataType AliHLTTPCCompModelDeflaterComponent::GetOutputDataType()
+    {
+      // see header file for class documentation
+      return AliHLTTPCDefinitions::fgkClusterTracksCompressedDataType;
+    }
+
+void AliHLTTPCCompModelDeflaterComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
+    {
+      // see header file for class documentation
+      constBase = 1+1+216; // Format versions + cluster count per patch
+      inputMultiplier = 4.;
+      //#warning Adapt input Multiplier to something more realistic
+    }
+
+// Spawn function, return new instance of this class
+AliHLTComponent* AliHLTTPCCompModelDeflaterComponent::Spawn()
+    {
+      // see header file for class documentation
+      return new AliHLTTPCCompModelDeflaterComponent;
+    };
+
+int AliHLTTPCCompModelDeflaterComponent::DoInit( int argc, const char** argv )
+    {
+      // see header file for class documentation
+      //char* cpErr;
+      if ( argc )
+       {
+         Logging( kHLTLogDebug, "HLT::TPCCompModelDeflater::DoInit", "Arguments", "argv[0] == %s", argv[0] );
+         Logging(kHLTLogError, "HLT::TPCCompModelDeflater::DoInit", "Unknown Option", "Unknown option '%s'", argv[0] );
+         return EINVAL;
+       }
+    return 0;
+    }
+
+int AliHLTTPCCompModelDeflaterComponent::DoDeinit()
+    {
+      // see header file for class documentation
+      return 0;
+    }
+
+int AliHLTTPCCompModelDeflaterComponent::DoEvent( const AliHLTComponent_EventData& evtData, const AliHLTComponent_BlockData* blocks, 
+                                                  AliHLTComponent_TriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr, 
+                                     AliHLTUInt32_t& size, vector<AliHLTComponent_BlockData>& outputBlocks )
+    {
+      // see header file for class documentation
+      // Process an event
+      // Loop over all input blocks in the event
+      AliHLTUInt8_t* writePtr = outputPtr;
+      AliHLTUInt32_t outputSize = 0, blockSize;
+      int ret;
+      AliHLTComponent_BlockData ob;
+      AliHLTUInt8_t minSlice=0xFF, maxSlice=0xFF, minPatch=0xFF, maxPatch=0xFF;
+      fConverter.Init();
+      unsigned long long totalNonModelDataSize=0;
+      
+      for ( unsigned long n = 0; n < evtData.fBlockCnt; n++ )
+       {
+         if ( blocks[n].fDataType == AliHLTTPCDefinitions::fgkClusterTracksModelDataType )
+           {
+             blockSize = size-outputSize;
+             ret = fModelDeflater.CompressTracks( (AliHLTUInt8_t*)blocks[n].fPtr, blocks[n].fSize, writePtr, blockSize );
+             if ( !ret && blockSize<blocks[n].fSize )
+               {
+                 // Let the structure be filled with the default values.
+                 // This takes care of setting the shared memory and data type values to default values,
+                 // so that they can be filled in by the calling code.
+                 FillBlockData( ob );
+                 // This block's start (offset) is after all other blocks written so far
+                 ob.fOffset = outputSize;
+                 // the size of this block's data.
+                 ob.fSize = blockSize;
+                 // The specification of the data is copied from the input block.
+                 ob.fSpecification = blocks[n].fSpecification;
+                 // The type of the data is copied from the input block.
+                 ob.fDataType = AliHLTTPCDefinitions::fgkClusterTracksCompressedDataType;
+                 // Place this block into the list of output blocks
+                 outputBlocks.push_back( ob );
+                 writePtr += blockSize;
+               outputSize += blockSize;
+               }
+             else if ( fForwardIfUncompressed )
+               {
+                 outputBlocks.push_back( blocks[n] );
+               }
+             continue;
+           }
+         if ( blocks[n].fDataType == AliHLTTPCDefinitions::fgkRemainingClustersModelDataType )
+           {
+           blockSize = size-outputSize;
+           ret = fModelDeflater.CompressRemainingClusters( (AliHLTUInt8_t*)blocks[n].fPtr, blocks[n].fSize, writePtr, blockSize );
+           HLTDebug( "ret: %d - blockSize: %u - blocks[%u].fSize: %u", ret, (unsigned)blockSize, (unsigned)n, (unsigned)blocks[n].fSize );
+           if ( !ret && blockSize<blocks[n].fSize )
+             {
+               // Let the structure be filled with the default values.
+               // This takes care of setting the shared memory and data type values to default values,
+               // so that they can be filled in by the calling code.
+               FillBlockData( ob );
+               // This block's start (offset) is after all other blocks written so far
+               ob.fOffset = outputSize;
+               // the size of this block's data.
+               ob.fSize = blockSize;
+               // The specification of the data is copied from the input block.
+               ob.fSpecification = blocks[n].fSpecification;
+               // The type of the data is copied from the input block.
+               ob.fDataType = AliHLTTPCDefinitions::fgkRemainingClustersCompressedDataType;
+               // Place this block into the list of output blocks
+               outputBlocks.push_back( ob );
+               writePtr += blockSize;
+               outputSize += blockSize;
+             }
+           else if ( fForwardIfUncompressed )
+             {
+               outputBlocks.push_back( blocks[n] );
+             }
+           continue;
+           }
+         AliHLTUInt8_t slice, patch;
+         if ( blocks[n].fDataType == AliHLTTPCDefinitions::fgkClustersDataType ||
+              blocks[n].fDataType == AliHLTTPCDefinitions::fgkTracksDataType )
+           {
+             slice = AliHLTTPCDefinitions::GetMinSliceNr( blocks[n].fSpecification );
+             patch = AliHLTTPCDefinitions::GetMinPatchNr( blocks[n].fSpecification );
+             if ( minSlice==0xFF || slice<minSlice )
+               minSlice = slice;
+             if ( maxSlice==0xFF || slice>maxSlice )
+               maxSlice = slice;
+             if ( minPatch==0xFF || patch<minPatch )
+               minPatch = patch;
+             if ( maxPatch==0xFF || patch>maxPatch )
+               maxPatch = patch;
+             totalNonModelDataSize += blocks[n].fSize;
+           }
+         if ( blocks[n].fDataType == AliHLTTPCDefinitions::fgkClustersDataType )
+           {
+           fConverter.SetInputClusters( (AliHLTTPCClusterData*)blocks[n].fPtr, slice, patch );
+           }
+         if ( blocks[n].fDataType == AliHLTTPCDefinitions::fgkTracksDataType )
+           {
+             fConverter.SetInputTracks( (AliHLTTPCTrackletData*)blocks[n].fPtr );
+           }
+         
+       }
+      
+      if ( totalNonModelDataSize>0 )
+       {
+         fConverter.Convert();
+         
+         unsigned long trackSize = fConverter.GetOutputModelDataSize();
+         AliHLTUInt8_t* trackModelData = new AliHLTUInt8_t[ trackSize ];
+         if ( !trackModelData )
+           {
+             HLTError( "Out of memory trying to allocate %lu bytes of trackmodeldata", trackSize );
+             return ENOMEM;
+           }
+         
+         fConverter.OutputModelData( trackModelData );
+         
+         unsigned long clusterSize = fConverter.GetRemainingClustersOutputDataSize();
+         AliHLTUInt8_t* remainingClustersModelData = new AliHLTUInt8_t[ clusterSize ];
+         if ( !remainingClustersModelData )
+           {
+             HLTError( "Out of memory trying to allocate %lu bytes of remaining cluster model data", clusterSize );
+             delete [] trackModelData;
+             return ENOMEM;
+           }
+         
+         fConverter.GetRemainingClusters( remainingClustersModelData, clusterSize );
+         
+         bool forwardUncompressed = false;
+         
+         blockSize = size-outputSize;
+         ret = fModelDeflater.CompressTracks( trackModelData, trackSize, writePtr, blockSize );
+         unsigned long long totalCompressedModelData = blockSize;
+         if ( !ret )
+           {
+             // Let the structure be filled with the default values.
+             // This takes care of setting the shared memory and data type values to default values,
+             // so that they can be filled in by the calling code.
+             FillBlockData( ob );
+             // This block's start (offset) is after all other blocks written so far
+             ob.fOffset = outputSize;
+             // the size of this block's data.
+             ob.fSize = blockSize;
+             // The specification of the data is copied from the input block.
+             ob.fSpecification = AliHLTTPCDefinitions::EncodeDataSpecification( minSlice, maxSlice, minPatch, maxPatch );
+             // The type of the data is copied from the input block.
+             ob.fDataType = AliHLTTPCDefinitions::fgkClusterTracksCompressedDataType;
+             // Place this block into the list of output blocks
+             outputBlocks.push_back( ob );
+             writePtr += blockSize;
+             outputSize += blockSize;
+             
+             blockSize = size-outputSize;
+             ret = fModelDeflater.CompressRemainingClusters( remainingClustersModelData, clusterSize, writePtr, blockSize );
+             totalCompressedModelData += blockSize;
+             if ( !ret && totalCompressedModelData<totalNonModelDataSize )
+               {
+                 // Let the structure be filled with the default values.
+                 // This takes care of setting the shared memory and data type values to default values,
+                 // so that they can be filled in by the calling code.
+                 FillBlockData( ob );
+                 // This block's start (offset) is after all other blocks written so far
+                 ob.fOffset = outputSize;
+                 // the size of this block's data.
+                 ob.fSize = blockSize;
+                 // The specification of the data is copied from the input block.
+                 ob.fSpecification = AliHLTTPCDefinitions::EncodeDataSpecification( minSlice, maxSlice, minPatch, maxPatch );
+                 // The type of the data is copied from the input block.
+                 ob.fDataType = AliHLTTPCDefinitions::fgkRemainingClustersCompressedDataType;
+                 // Place this block into the list of output blocks
+                 outputBlocks.push_back( ob );
+                 writePtr += blockSize;
+                 outputSize += blockSize;
+               }
+             else if ( fForwardIfUncompressed )
+               {
+                 outputSize -= (outputBlocks.end()-1)->fSize;
+                 outputBlocks.erase( outputBlocks.end()-1 );
+                 forwardUncompressed = true;
+               }
+             
+             
+           }
+         else if ( fForwardIfUncompressed )
+           forwardUncompressed = true;
+         
+         delete [] trackModelData;
+         delete [] remainingClustersModelData;
+         
+         if ( forwardUncompressed )
+           {
+             for ( unsigned long n = 0; n < evtData.fBlockCnt; n++ )
+               {
+                 if ( blocks[n].fDataType == AliHLTTPCDefinitions::fgkClustersDataType ||
+                      blocks[n].fDataType == AliHLTTPCDefinitions::fgkTracksDataType )
+                   {
+                     outputBlocks.push_back( blocks[n] );
+                   }
+                 
+               }
+           }
+       }
+      
+      // Finally we set the total size of output memory we consumed.
+      size = outputSize;
+      return 0;
+    }
diff --git a/HLT/TPCLib/comp/AliHLTTPCCompModelDeflaterComponent.h b/HLT/TPCLib/comp/AliHLTTPCCompModelDeflaterComponent.h
new file mode 100644 (file)
index 0000000..3ca8338
--- /dev/null
@@ -0,0 +1,109 @@
+// XEmacs -*-C++-*-
+// $Id: AliHLTTPCCompModelDeflaterComponent.h,v 1.2 2006/08/10 09:46:51 richterm Exp $
+
+#ifndef ALIHLTTPCCOMPMODELDEFLATERCOMPONENT_H
+#define ALIHLTTPCCOMPMODELDEFLATERCOMPONENT_H
+/* TPCCompModelDeflaterright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full TPCCompModelDeflaterright notice                               */
+
+/** @file   AliHLTTPCCompModelDeflaterComponent.h
+    @author Timm Steinbeck
+    @date   
+    @brief  Declaration of a copy component. */
+
+
+#include "AliHLTProcessor.h"
+#include "AliHLTTPCCompModelDeflater.h"
+#include "AliHLTTPCCompModelConverter.h"
+
+/**
+ * @class AliHLTTPCCompModelDeflaterComponent
+ * @brief A dummy HLT processing component. 
+ *
+ * An implementiation of a copy component that just copies its input data
+ * to debug a components input data
+ * @ingroup alihlt_tutorial
+ */
+class AliHLTTPCCompModelDeflaterComponent : public AliHLTProcessor
+    {
+    public:
+
+      /** standard constructor */
+      AliHLTTPCCompModelDeflaterComponent();
+      /** standard destructor */
+      virtual ~AliHLTTPCCompModelDeflaterComponent();
+      
+      // Public functions to implement AliHLTComponent's interface.
+      // These functions are required for the registration process
+      
+      /** function to get component id 
+       * @return const char* pointer to componentid
+       */
+      const char* GetComponentID();
+
+      /** function to get input data types
+       * @param list vecotr of AliHLTComponent_DataType
+       */
+      void GetInputDataTypes( vector<AliHLTComponent_DataType>& list);
+
+      /** function to get output data type
+       * @return AliHLTComponent_DataType
+       */
+      AliHLTComponent_DataType GetOutputDataType();
+
+      /** function to get output data size
+       * @param constBase address of an unsigned long
+       * @param inputMultiplier address of a double
+       */
+      virtual void GetOutputDataSize( unsigned long& constBase, double& inputMultiplier );
+
+      /** spawn function
+       * @return AliHLTComponent* pointer to instance
+       */
+      AliHLTComponent* Spawn();
+      
+    protected:
+      
+      // Protected functions to implement AliHLTComponent's interface.
+      // These functions provide initialization as well as the actual processing
+      // capabilities of the component. 
+      
+      /** initialisation function
+       * @param argc integer counting number of input arguments
+       * @param argv const char** for parameter values
+       * @return zero upon success
+       */
+      int DoInit( int argc, const char** argv );
+
+      /** deinitialisation function
+       * @return zero upon success
+       */
+      int DoDeinit();
+
+      /** do event function
+       * @param evt Data     const AliHLTComponent_EventData& to event data
+       * @param blocks       const AliHLTComponent_BlockData* to blocks of event data
+       * @param trigData     AliHLTComponent_TriggerData& of trigger data
+       * @param outputPtr    AliHLTUInt8_t* pointer to output data
+       * @param size         AliHLTUInt32_t& of output size
+       * @param outputBlocks vector<AliHLTComponent_BlockData>& of output block data
+       * @return zero upon success
+       */
+      int DoEvent( const AliHLTComponent_EventData& evtData, const AliHLTComponent_BlockData* blocks, 
+                  AliHLTComponent_TriggerData& trigData, AliHLTUInt8_t* outputPtr, 
+                  AliHLTUInt32_t& size, vector<AliHLTComponent_BlockData>& outputBlocks );
+      
+      /** member variable for instance of model deflater class */
+      AliHLTTPCCompModelDeflater fModelDeflater;
+      /** member variable for instance of model converter class */
+      AliHLTTPCCompModelConverter fConverter;
+      
+      /** member variable for forwarding if uncompressed */
+      bool fForwardIfUncompressed;
+      
+    private:
+
+       ClassDef(AliHLTTPCCompModelDeflaterComponent, 0)
+
+    };
+#endif
diff --git a/HLT/TPCLib/comp/AliHLTTPCCompModelInflater.cxx b/HLT/TPCLib/comp/AliHLTTPCCompModelInflater.cxx
new file mode 100644 (file)
index 0000000..9b47672
--- /dev/null
@@ -0,0 +1,440 @@
+// $Id: AliHLTTPCCompModelInflater.cxx,v 1.2 2006/08/10 09:46:51 richterm Exp $
+
+/**************************************************************************
+ * TPCCompModelInflaterright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Authors: 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.                  *
+ **************************************************************************/
+
+/** @file   AliHLTTPCCompModelInflater.cxx
+    @author Timm Steinbeck
+    @date   
+    @brief  A copy processing component for the HLT. */
+
+#if __GNUC__ >= 3
+using namespace std;
+#endif
+
+#include "AliHLTTPCCompModelInflater.h"
+#include "AliHLTTPCTransform.h"
+#include "AliHLTTPCTrack.h"
+#include "AliHLTTPCModelTrack.h"
+#include "AliHLTTPCCompDataCompressorHelper.h"
+#include "AliHLTDataTypes.h"
+#include <cerrno>
+
+AliHLTTPCCompModelInflater::AliHLTTPCCompModelInflater():
+    fBitDataCurrentWord(0),
+    fBitDataCurrentPosInWord(0),
+    fBitDataCurrentInput(0),
+    fBitDataCurrentInputStart(0),
+    fBitDataCurrentInputEnd(0)
+    {
+      // see header file for class documentation
+    }
+
+AliHLTTPCCompModelInflater::~AliHLTTPCCompModelInflater()
+    {
+      // see header file for class documentation
+    }
+
+int AliHLTTPCCompModelInflater::DecompressTracks( AliHLTUInt8_t* inData, UInt_t const& inputSize, AliHLTUInt8_t* output, UInt_t& outputSize )
+    {
+      // see header file for class documentation
+      AliHLTUInt8_t* inputPtr = inData;
+      //AliHLTUInt8_t* inputEndPtr = inData+inputSize;
+      AliHLTUInt8_t* outputPtr = output;
+      AliHLTUInt8_t* outputEndPtr = output+outputSize;
+      
+      printf( "outuptSize: %lu\n", (unsigned long)outputSize );
+      
+      InitBitDataInput( inputPtr, inputSize );
+      AliHLTUInt8_t version;
+      if ( !InputBits( version, 4 ) ) // Version information
+       {
+         HLTError( "Corrupt input data. Cannot read data version number at position %u",
+                   (unsigned)(inputPtr-inData) );
+         return EIO;
+       }
+      if ( version != 0 )
+       {
+         HLTError( "Unsupported version %hu. Only version 0 supported currently.", version );
+         return EIO;
+       }
+      AliHLTUInt8_t readShape;
+      if ( !InputBit( readShape ) ) // Data format flag
+       {
+         HLTError( "Corrupt input data. Cannot read shape flag at position %u",
+                   (unsigned)(inputPtr-inData) );
+         return EIO;
+       }
+      
+      if ( outputPtr+sizeof(AliHLTUInt32_t)>outputEndPtr )
+       {
+         HLTError( "Not enough space to write decompressed data. %lu already written",
+                   (unsigned)(outputPtr-output) );
+         return ENOBUFS;
+       }
+      *(AliHLTUInt32_t*)outputPtr = 0; // Write format version number
+      outputPtr += sizeof(AliHLTUInt32_t);
+      
+      Pad8Bits();
+      
+      AliHLTTPCClusterModel *cluster;
+      
+      Int_t timeo,pado,chargeo,padshapeo,timeshapeo;
+      timeo=pado=chargeo=padshapeo=timeshapeo=0;
+      unsigned trackCnt=0;
+      while( !EndOfBitInput() )
+       {
+         if ( outputPtr+sizeof(AliHLTTPCTrackModel)>outputEndPtr )
+           {
+             HLTError( "Not enough space to write decompressed data. %lu already written",
+                       (unsigned)(outputPtr-output) );
+             return ENOBUFS;
+           }
+         if ( !InputBytes( outputPtr, sizeof(AliHLTTPCTrackModel) ) )
+           {
+             HLTError( "Corrupt input data. Cannot read track model data at position %u",
+                       (unsigned)(inputPtr-inData) );
+             return EIO;
+           }
+         outputPtr += sizeof(AliHLTTPCTrackModel);
+         
+         Int_t clustercount=0;
+         AliHLTUInt32_t slice;
+         for(Int_t i=0; i<AliHLTTPCTransform::GetNRows(); i++)
+           {
+             if ( outputPtr+sizeof(AliHLTTPCClusterModel)>outputEndPtr )
+               {
+                 HLTError( "Not enough space to write decompressed data. %lu already written",
+                           (unsigned)(outputPtr-output) );
+                 return ENOBUFS;
+               }
+             cluster = (AliHLTTPCClusterModel*)outputPtr;
+             outputPtr += sizeof(AliHLTTPCClusterModel);
+             
+             // Read present flag:
+             AliHLTUInt8_t present;
+             if ( !InputBit( present ) )
+               {
+                 HLTError( "Corrupt input data. Cannot read cluster presence bit at position %u",
+                           (unsigned)(inputPtr-inData) );
+                 return EIO;
+               }
+             HLTDebug( "Cluster for row %d %s", i, (present ? "present" : "not present") );
+             cluster->fPresent = present;
+             if ( !present )
+               continue;
+             
+             
+             //Read slice number of first point
+             if ( clustercount==0 )
+               {
+                 if ( !InputBits( slice,6 ) ) //Need 6 bits to encode slice number
+                   {
+                     HLTError( "Corrupt input data. Cannot read cluster slice number at position %u",
+                               (unsigned)(inputPtr-inData) );
+                     return EIO;
+                   }
+               }
+             else
+               {
+                 AliHLTUInt8_t sliceChange;
+                 if ( !InputBit( sliceChange ) )
+                   {
+                     HLTError( "Corrupt input data. Cannot read cluster slice change bit at position %u",
+                               (unsigned)(inputPtr-inData) );
+                     return EIO;
+                   }
+                 if ( sliceChange )
+                   {  //Change of slice
+                     if ( !InputBits( slice, 6 ) )
+                       {
+                         HLTError( "Corrupt input data. Cannot read cluster slice number at position %u",
+                                   (unsigned)(inputPtr-inData) );
+                         return EIO;
+                       }
+                   }
+               }
+             HLTDebug( "Slice: %d", slice );
+             cluster->fSlice = slice;
+             if ( cluster->fSlice<0 || cluster->fSlice>35 )
+               {
+                 HLTError( "Inconsistent slice number %u (track %u, cluster %d)", cluster->fSlice, trackCnt, i );
+                 printf( "TRACE: %s:%d\n", __FILE__, __LINE__ );
+                 return EINVAL;
+               }
+             
+             AliHLTUInt8_t signBit;
+             Int_t sign;
+             AliHLTUInt64_t temp;
+             Int_t val;
+             //Read time information:
+             if ( !InputBit( signBit ) )
+               {
+                 HLTError( "Corrupt input data. Cannot read DTime sign bit at position %u",
+                           (unsigned)(inputPtr-inData) );
+                 return EIO;
+               }
+             sign = signBit;
+             sign = -1+sign*2;
+             if ( !InputBits( temp, AliHLTTPCCompDataCompressorHelper::GetNTimeBits()-1 ) )
+               {
+                 HLTError( "Corrupt input data. Cannot read DTime data at position %u",
+                           (unsigned)(inputPtr-inData) );
+                 return EIO;
+               }
+             val = (Int_t)temp;
+             cluster->fDTime = val*sign;
+             
+             //Read pad information:
+             if ( !InputBit( signBit ) )
+               {
+                 HLTError( "Corrupt input data. Cannot read DPad sign bit at position %u",
+                           (unsigned)(inputPtr-inData) );
+                 return EIO;
+               }
+             sign = signBit;
+             sign = -1+sign*2;
+             if ( !InputBits( temp, AliHLTTPCCompDataCompressorHelper::GetNPadBits()-1 ) )
+               {
+                 HLTError( "Corrupt input data. Cannot read DPad data at position %u",
+                           (unsigned)(inputPtr-inData) );
+                 return EIO;
+               }
+             
+             val = (Int_t)temp;
+             cluster->fDPad = val*sign;
+             
+             // Read charge information:
+             if ( !InputBits( temp, AliHLTTPCCompDataCompressorHelper::GetNChargeBits() ) )
+               {
+                 HLTError( "Corrupt input data. Cannot read charge data at position %u",
+                           (unsigned)(inputPtr-inData) );
+                 return EIO;
+               }
+             cluster->fDCharge = temp;
+             
+             if ( readShape )
+               {
+                 // Read shape information:
+                 if ( !InputBit( signBit ) )
+                   {
+                     HLTError( "Corrupt input data. Cannot read DSigmaY sign bit at position %u",
+                               (unsigned)(inputPtr-inData) );
+                     return EIO;
+                   }
+                 sign = signBit;
+                 sign = -1+sign*2;
+                 if ( !InputBits( temp, AliHLTTPCCompDataCompressorHelper::GetNShapeBits()-1 ) )
+                   {
+                     HLTError( "Corrupt input data. Cannot read DSigmaY data at position %u",
+                               (unsigned)(inputPtr-inData) );
+                     return EIO;
+                   }
+                 
+                 val = (Int_t)temp;
+                 cluster->fDSigmaY = val*sign;
+                 //HLTInfo("DSigmaY: %f", cluster->fDSigmaY);
+                 
+                 
+                 if ( !InputBit( signBit ) )
+                   {
+                     HLTError( "Corrupt input data. Cannot read DSigmaZ sign bit at position %u",
+                               (unsigned)(inputPtr-inData) );
+                     return EIO;
+                   }
+                 sign = signBit;
+                 sign = -1+sign*2;
+                 if ( !InputBits( temp, AliHLTTPCCompDataCompressorHelper::GetNShapeBits()-1 ) )
+                   {
+                     HLTError( "Corrupt input data. Cannot read DSigmaZ data at position %u",
+                               (unsigned)(inputPtr-inData) );
+                     return EIO;
+                   }
+                 val = (Int_t)temp;
+                 cluster->fDSigmaZ = val*sign;
+               }
+             
+             clustercount++;
+           }
+         Pad8Bits();
+         HLTDebug( "Track %u: %d clusters", trackCnt, clustercount );
+       }
+      
+      outputSize = (UInt_t)( outputPtr - output );
+      return 0;
+    }
+
+int AliHLTTPCCompModelInflater::DecompressRemainingClusters( AliHLTUInt8_t* inData, UInt_t const& inputSize, AliHLTUInt8_t* output, UInt_t& outputSize )
+    {
+      // see header file for class documentation
+      AliHLTUInt8_t* inputPtr = inData;
+      AliHLTUInt8_t* outputPtr = output;
+      AliHLTUInt8_t* outputEndPtr = output+outputSize;
+      
+      InitBitDataInput( inputPtr, inputSize );
+      AliHLTUInt8_t version;
+      if ( !InputBits( version, 4 ) ) // Version information
+       {
+         HLTError( "Corrupt input data. Cannot read data version number at position %u",
+                   (unsigned)(inputPtr-inData) );
+         return EIO;
+       }
+      if ( version != 0 )
+       {
+         HLTError( "Unsupported version %hu. Only version 0 supported currently.", version );
+       }
+      Pad8Bits();
+      
+      if ( outputPtr+sizeof(AliHLTUInt32_t)>outputEndPtr )
+       {
+         HLTError( "Not enough space to write uncompressed data. %lu already written",
+                   (unsigned long)(outputPtr-output) );
+         outputSize = (unsigned long)(outputPtr-output);
+         return ENOBUFS;
+       }
+      
+      *(AliHLTUInt32_t*)outputPtr = 0; // Write format version
+      outputPtr += sizeof(AliHLTUInt32_t);
+      
+      //Read the remaining clusters in a compressed format.
+      
+      for(Int_t slice=0; slice<=35; slice++)
+       {
+         for(Int_t patch=0; patch < 6; patch++)
+           {
+             UInt_t i;
+             HLTDebug( "slice %u patch %u: %u padrows",
+                       (unsigned)slice, (unsigned)patch, (unsigned)*inputPtr );
+             //Write number of padrows with clusters
+             if ( outputPtr>=outputEndPtr )
+               {
+                 HLTError( "Not enough space to write uncompressed data. %lu already written",
+                           (unsigned long)(outputPtr-output) );
+                 outputSize = (unsigned long)(outputPtr-output);
+                 return ENOBUFS;
+               }
+             if ( !InputBits( *outputPtr,8 ) )
+               {
+                 HLTError( "Corrupt input data. Cannot read padrow count at position %u",
+                           (unsigned)(inputPtr-inData) );
+                 return EIO;
+               }
+             if ( !*outputPtr )
+               {
+                 outputPtr++;
+                 continue;
+               }
+             UInt_t nRows=(UInt_t)*outputPtr;
+             outputPtr++;
+             if ( outputPtr>=outputEndPtr )
+               {
+                 HLTError( "Not enough space to write uncompressed data. %lu already written",
+                           (unsigned long)(outputPtr-output) );
+                 outputSize = (unsigned long)(outputPtr-output);
+                 return ENOBUFS;
+               }
+             
+             for ( UInt_t jj=0; jj<nRows; jj++ )
+               {
+                 
+                 AliHLTTPCRemainingRow *thisRow = (AliHLTTPCRemainingRow*)outputPtr;
+                 if ( outputPtr+sizeof(AliHLTTPCRemainingRow)>outputEndPtr )
+                   {
+                     HLTError( "Not enough space to write uncompressed data. %lu already written",
+                               (unsigned long)(outputPtr-output) );
+                     outputSize = (unsigned long)(outputPtr-output);
+                     return ENOBUFS;
+                   }
+                 AliHLTTPCRemainingCluster *cl = thisRow->fClusters;
+                 if ( !InputBits(thisRow->fPadRow,8) ) //Read padrow #
+                   {
+                     HLTError( "Corrupt input data. Cannot read padrow number at position %u",
+                               (unsigned)(inputPtr-inData) );
+                     return EIO;
+                   }
+                 if ( !InputBits(thisRow->fNClusters,10) )//Read number of clusters on this padrow
+                   {
+                     HLTError( "Corrupt input data. Cannot read cluster count at position %u",
+                               (unsigned)(inputPtr-inData) );
+                     return EIO;
+                   }
+                 if ( outputPtr+sizeof(AliHLTTPCRemainingRow)+thisRow->fNClusters*sizeof(AliHLTTPCRemainingCluster)>outputEndPtr )
+                   {
+                     HLTError( "Not enough space to write uncompressed data. %lu already written",
+                               (unsigned long)(outputPtr-output) );
+                     outputSize = (unsigned long)(outputPtr-output);
+                     return ENOBUFS;
+                   }
+                 for ( i=0; i<thisRow->fNClusters; i++ )
+                   {
+                     //Read pad
+                     Int_t buff;
+                     if ( !InputBits(buff,AliHLTTPCCompDataCompressorHelper::GetNPadBitsRemaining()) )
+                       {
+                         HLTError( "Corrupt input data. Cannot read cluster count at position %u",
+                                   (unsigned)(inputPtr-inData) );
+                         return EIO;
+                       }
+                     cl[i].fPad = (Float_t)( ((double)buff) / AliHLTTPCCompDataCompressorHelper::GetPadPrecisionFactor() );
+                     
+                     //Read time
+                     if ( !InputBits(buff,AliHLTTPCCompDataCompressorHelper::GetNTimeBitsRemaining()) )
+                       {
+                         HLTError( "Corrupt input data. Cannot read cluster count at position %u",
+                                   (unsigned)(inputPtr-inData) );
+                         return EIO;
+                       }
+                     cl[i].fTime = (Float_t)( ((double)buff) / AliHLTTPCCompDataCompressorHelper::GetTimePrecisionFactor() );
+                     
+                     //Read widths
+                     if ( !InputBits(buff,AliHLTTPCCompDataCompressorHelper::GetNShapeBitsRemaining()) )
+                       {
+                         HLTError( "Corrupt input data. Cannot read cluster count at position %u",
+                                   (unsigned)(inputPtr-inData) );
+                         return EIO;
+                       }
+                     
+                     //HLTInfo("fDSgimaY = %d",buff);
+                     
+                     Float_t padw = (Float_t)( ((double)buff) / AliHLTTPCCompDataCompressorHelper::GetPadPrecisionFactor() );
+                     cl[i].fSigmaY2 = padw*padw;
+                     //HLTInfo("sigmaY2: %f", cl[i].fSigmaY2);
+                     
+                     if ( !InputBits(buff,AliHLTTPCCompDataCompressorHelper::GetNShapeBitsRemaining()) )
+                       {
+                         HLTError( "Corrupt input data. Cannot read cluster count at position %u",
+                                   (unsigned)(inputPtr-inData) );
+                         return EIO;
+                       }
+                     Float_t timew = (Float_t)( ((double)buff) / AliHLTTPCCompDataCompressorHelper::GetTimePrecisionFactor() );
+                     cl[i].fSigmaZ2 = timew*timew;
+                     
+                     //Read charge 
+                     if ( !InputBits(buff,AliHLTTPCCompDataCompressorHelper::GetNChargeBits()) )
+                       {
+                         HLTError( "Corrupt input data. Cannot read cluster count at position %u",
+                                   (unsigned)(inputPtr-inData) );
+                         return EIO;
+                       }
+                     cl[i].fCharge = buff;
+                   }
+                 outputPtr += sizeof(AliHLTTPCRemainingRow)+thisRow->fNClusters*sizeof(AliHLTTPCRemainingCluster);
+               }
+           }
+         
+       }
+      outputSize = (UInt_t)( outputPtr - output );
+      return 0;
+    }
diff --git a/HLT/TPCLib/comp/AliHLTTPCCompModelInflater.h b/HLT/TPCLib/comp/AliHLTTPCCompModelInflater.h
new file mode 100644 (file)
index 0000000..5ccd456
--- /dev/null
@@ -0,0 +1,305 @@
+// XEmacs -*-C++-*-
+// $Id: AliHLTTPCCompModelInflater.h,v 1.2 2006/08/10 09:46:51 richterm Exp $
+
+#ifndef ALIHLTTPCCOMPMODELINFLATER_H
+#define ALIHLTTPCCOMPMODELINFLATER_H
+/* TPCCompModelInflaterright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full TPCCompModelInflaterright notice                               */
+
+/** @file   AliHLTTPCCompModelInflater.h
+    @author Timm Steinbeck
+    @date   
+    @brief  Declaration of an uncompressor class for TPC track data. */
+
+#include "AliHLTTPCTrackArray.h"
+#include "AliHLTTPCTrackletDataFormat.h"
+#include "AliHLTTPCClusterDataFormat.h"
+#include "AliHLTLogging.h"
+#include "AliHLTTPCModels.h"
+
+/**
+ * @class AliHLTTPCCompModelInflater
+ * @brief A HLT TPC track compressor. 
+ *
+ * A class that can compress HLT TPC track model data
+ */
+class AliHLTTPCCompModelInflater: public AliHLTLogging
+    {
+    public:
+      /** standard constructor */
+      AliHLTTPCCompModelInflater();
+      /** standard destructor */
+      virtual ~AliHLTTPCCompModelInflater();
+
+      /** function to decompress tracks 
+       * @param inData     AliHLTUInt8_t* pointer to input
+       * @param inputSize  UInt_t const& input data size
+       * @param output     AliHLTUInt8_t* pointer to output
+       * @param outputSize UInt_t& output data size
+       * @return zero upon success
+       */
+       int DecompressTracks( AliHLTUInt8_t* inData, UInt_t const& inputSize, AliHLTUInt8_t* output, UInt_t& outputSize );
+
+      /** function to decompress remaining clusters
+       * @param inData     AliHLTUInt8_t* pointer to input
+       * @param inputSize  UInt_t const& input data size
+       * @param output     AliHLTUInt8_t* pointer to output
+       * @param outputSize UInt_t& output data size
+       * @return zero upon success
+       */
+       int DecompressRemainingClusters( AliHLTUInt8_t* inData, UInt_t const& inputSize, AliHLTUInt8_t* output, UInt_t& outputSize );
+
+    protected:
+
+      /** function to initialise the bit data input
+       * @param input  AliHLTUInt8_t* pointer to input data
+       * @param inputSize UInt_t input data size
+       */
+      void InitBitDataInput( AliHLTUInt8_t* input, UInt_t inputSize )
+      {
+       fBitDataCurrentWord = 0;
+       fBitDataCurrentPosInWord = 7;
+       fBitDataCurrentInput = fBitDataCurrentInputStart = input;
+       fBitDataCurrentInputEnd = input+inputSize;
+       fBitDataCurrentWord = *fBitDataCurrentInput;
+      }
+
+      /** function to close bit data input */  
+      void CloseBitDataInput()
+      {
+      }
+      
+      /** function to get current byte input position 
+       * @return unsigned long value of current byte input position
+       */
+      unsigned long GetCurrentByteInputPosition() const
+      {
+       return (unsigned long)( fBitDataCurrentInput - fBitDataCurrentInputStart );
+      }
+
+      /** function to get current bit input position
+       * @return unsigned value of current bit input position
+       */
+      unsigned GetCurrentBitInputPosition() const
+      {
+       return fBitDataCurrentPosInWord;
+      }
+
+      /** function to get current input byte
+       * @return AliHLTUInt8_t value of current input byte
+       */
+      AliHLTUInt8_t GetCurrentInputByte() const
+      {
+               return fBitDataCurrentWord;
+      }
+
+      /** function to determine end of bit input
+       * @return boolean if end is reached or not
+       */
+      bool EndOfBitInput() const
+      {
+       return (fBitDataCurrentInput>=fBitDataCurrentInputEnd);
+      }
+      
+      /** function to get bit data input size bytes
+       * @return UInt_t value of bit data input size bytes
+       */
+      UInt_t GetBitDataInputSizeBytes() const
+      {
+       return fBitDataCurrentInput-fBitDataCurrentInputStart;
+      }
+
+      /** function to determine input bit
+       * @return boolean (if bit is 1 or 0)
+       */
+      bool InputBit( AliHLTUInt8_t & value )
+      {
+       if ( fBitDataCurrentInput>=fBitDataCurrentInputEnd )
+         return false;
+       value = (fBitDataCurrentWord >> fBitDataCurrentPosInWord) & 1;
+       if ( fBitDataCurrentPosInWord )
+         fBitDataCurrentPosInWord--;
+       else
+         {
+           fBitDataCurrentInput++;
+           if ( fBitDataCurrentInput<fBitDataCurrentInputEnd )
+             {
+               fBitDataCurrentWord = *fBitDataCurrentInput;
+               fBitDataCurrentPosInWord = 7;
+             }
+         }
+               return true;
+      }
+
+      /** function to determine input bits below 8 bits
+       * @param value    AliHLTUInt8_t &
+       * @param bitCount UInt_t const &
+       * @return boolean 
+       */
+      bool InputBits( AliHLTUInt8_t & value, UInt_t const & bitCount )
+      {
+       if ( bitCount>8 )
+         {
+           HLTFatal( "Internal error: Attempt to write more than 32 bits (%u)", (unsigned)bitCount );
+           return false;
+         }
+       AliHLTUInt64_t temp;
+       if ( !InputBits( temp, bitCount ) )
+         return false;
+       value = (AliHLTUInt8_t)( temp & (AliHLTUInt64_t)0xFFFFFFFFULL );
+       return true;
+      }
+
+      /** function to determine input bits between 8 and 16 bits
+       * @param value    AliHLTUInt16_t &
+       * @param bitCount UInt_t const &
+       * @return boolean 
+       */
+      bool InputBits( AliHLTUInt16_t & value, UInt_t const & bitCount )
+      {
+       if ( bitCount>16 )
+         {
+           HLTFatal( "Internal error: Attempt to write more than 32 bits (%u)", (unsigned)bitCount );
+           return false;
+         }
+       AliHLTUInt64_t temp;
+       if ( !InputBits( temp, bitCount ) )
+         return false;
+       value = (AliHLTUInt16_t)( temp & (AliHLTUInt64_t)0xFFFFFFFFULL );
+       return true;
+      }
+
+      /** function to determine input bits between 16 and 32 bits
+       * @param value    AliHLTUInt32_t &
+       * @param bitCount UInt_t const &
+       * @return boolean 
+       */
+      bool InputBits( AliHLTUInt32_t & value, UInt_t const & bitCount )
+      {
+       if ( bitCount>32 )
+         {
+           HLTFatal( "Internal error: Attempt to write more than 32 bits (%u)", (unsigned)bitCount );
+           return false;
+         }
+       AliHLTUInt64_t temp;
+       if ( !InputBits( temp, bitCount ) )
+         return false;
+       value = (AliHLTUInt32_t)( temp & (AliHLTUInt64_t)0xFFFFFFFFULL );
+       return true;
+      }
+
+      /** function to determine input bits between 16 and 32 bits
+       * @param value    Int_t_t &
+       * @param bitCount UInt_t const &
+       * @return boolean 
+       */
+      bool InputBits( Int_t & value, UInt_t const & bitCount )
+      {
+       if ( bitCount>32 )
+         {
+           HLTFatal( "Internal error: Attempt to write more than 32 bits (%u)", (unsigned)bitCount );
+           return false;
+         }
+       AliHLTUInt64_t temp;
+       if ( !InputBits( temp, bitCount ) )
+         return false;
+       value = (Int_t)( temp & (AliHLTUInt64_t)0xFFFFFFFFULL );
+       return true;
+      }
+
+      /** function to determine input bits between 32 and 64 bits
+       * @param value    AliHLTUInt64_t &
+       * @param bitCount UInt_t const &
+       * @return boolean 
+       */
+      bool InputBits( AliHLTUInt64_t & value, UInt_t const & bitCount )
+      {
+       if ( bitCount>64 )
+         {
+           HLTFatal( "Internal error: Attempt to write more than 64 bits (%u)", (unsigned)bitCount );
+           return false;
+         }
+       UInt_t bitsToRead=bitCount;
+       UInt_t curBitCount;
+       value = 0;
+       while ( bitsToRead>0 )
+         {
+           if ( fBitDataCurrentInput>=fBitDataCurrentInputEnd )
+             return false;
+           if ( bitsToRead >= fBitDataCurrentPosInWord+1 )
+             curBitCount = fBitDataCurrentPosInWord+1;
+           else
+             curBitCount = bitsToRead;
+           value = (value << curBitCount) | ( (fBitDataCurrentWord >> (fBitDataCurrentPosInWord-curBitCount+1)) & ((1 << curBitCount)-1) );
+           if ( fBitDataCurrentPosInWord < curBitCount )
+             {
+               fBitDataCurrentInput++;
+               if ( fBitDataCurrentInput<fBitDataCurrentInputEnd )
+                 {
+                   fBitDataCurrentWord = *fBitDataCurrentInput;
+                   fBitDataCurrentPosInWord = 7;
+                 }
+             }
+           else
+             fBitDataCurrentPosInWord -= curBitCount;
+           bitsToRead -= curBitCount;
+         }
+       return true;
+      }
+
+      /** function pad 8 bits */
+      void Pad8Bits()
+      {
+       if ( fBitDataCurrentPosInWord == 7 )
+         return;
+       fBitDataCurrentInput++;
+       if ( fBitDataCurrentInput<fBitDataCurrentInputEnd )
+         {
+           fBitDataCurrentWord = *fBitDataCurrentInput;
+           fBitDataCurrentPosInWord = 7;
+         }
+      }
+
+      /** function to determine input bytes
+       * @param data       AliHLTUInt8_t* pointer to input data
+       * @param byteCount  UInt_t const &
+       * @return boolean
+       */
+      bool InputBytes( AliHLTUInt8_t* data, UInt_t const & byteCount )
+      {
+       Pad8Bits();
+       if ( fBitDataCurrentInput+byteCount>fBitDataCurrentInputEnd )
+         return false;
+       memcpy( data, fBitDataCurrentInput, byteCount );
+       fBitDataCurrentInput += byteCount;
+       if ( fBitDataCurrentInput<fBitDataCurrentInputEnd )
+         {
+           fBitDataCurrentWord = *fBitDataCurrentInput;
+           fBitDataCurrentPosInWord = 7;
+         }
+       return true;
+      }
+      
+    private:
+      /** copy constructor prohibited */
+      AliHLTTPCCompModelInflater(const AliHLTTPCCompModelInflater&);
+      /** assignment operator prohibited */
+      AliHLTTPCCompModelInflater& operator=(const AliHLTTPCCompModelInflater&);
+
+      /** member variable for bit data current word */
+      AliHLTUInt8_t fBitDataCurrentWord;
+      /** member variable for bit data current position in word */
+      UInt_t fBitDataCurrentPosInWord;
+      /** member variable for bit data current input */
+      AliHLTUInt8_t *fBitDataCurrentInput;
+      /** member variable for bit data current input start */
+      AliHLTUInt8_t *fBitDataCurrentInputStart;
+      /** member variable for bit data current input end */
+      AliHLTUInt8_t *fBitDataCurrentInputEnd;
+      
+      ClassDef(AliHLTTPCCompModelInflater, 0);
+
+           
+
+    };
+#endif
diff --git a/HLT/TPCLib/comp/AliHLTTPCCompModelInflaterComponent.cxx b/HLT/TPCLib/comp/AliHLTTPCCompModelInflaterComponent.cxx
new file mode 100644 (file)
index 0000000..e1ebaa8
--- /dev/null
@@ -0,0 +1,174 @@
+// $Id: AliHLTTPCCompModelInflaterComponent.cxx,v 1.2 2006/08/10 09:46:51 richterm Exp $
+
+/**************************************************************************
+ * TPCCompModelInflaterright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Authors: 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.                  *
+ **************************************************************************/
+
+/** @file   AliHLTTPCCompModelInflaterComponent.cxx
+    @author Timm Steinbeck
+    @date   
+    @brief  A copy processing component for the HLT. */
+
+#if __GNUC__ >= 3
+using namespace std;
+#endif
+
+#include "AliHLTTPCCompModelInflaterComponent.h"
+#include "AliHLTTPCDefinitions.h"
+#include <stdlib.h>
+#include <errno.h>
+
+// this is a global object used for automatic component registration, do not use this
+AliHLTTPCCompModelInflaterComponent gAliHLTTPCCompClusterModelInflaterComponent;
+
+ClassImp(AliHLTTPCCompModelInflaterComponent);
+    
+AliHLTTPCCompModelInflaterComponent::AliHLTTPCCompModelInflaterComponent()
+  :
+  fModelInflater()
+    {
+      // see header file for class documentation
+    }
+
+AliHLTTPCCompModelInflaterComponent::~AliHLTTPCCompModelInflaterComponent()
+    {
+      // see header file for class documentation
+    }
+
+const char* AliHLTTPCCompModelInflaterComponent::GetComponentID()
+    {
+      // see header file for class documentation
+      return "TPCCompModelInflater"; // The ID of this component
+    }
+
+void AliHLTTPCCompModelInflaterComponent::GetInputDataTypes( vector<AliHLTComponent_DataType>& list)
+    {
+      // see header file for class documentation
+      list.clear(); // We do not have any requirements for our input data type(s).
+      list.push_back( AliHLTTPCDefinitions::fgkClusterTracksCompressedDataType );
+      list.push_back( AliHLTTPCDefinitions::fgkRemainingClustersCompressedDataType );
+    }
+
+AliHLTComponent_DataType AliHLTTPCCompModelInflaterComponent::GetOutputDataType()
+    {
+      // see header file for class documentation 
+      return AliHLTTPCDefinitions::fgkClusterTracksModelDataType;
+    }
+
+void AliHLTTPCCompModelInflaterComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
+    {
+      // see header file for class documentation
+      constBase = 4+4; // Format versions
+      inputMultiplier = 20.;
+      //#warning Adapt input Multiplier to something more realistic
+    }
+
+// Spawn function, return new instance of this class
+AliHLTComponent* AliHLTTPCCompModelInflaterComponent::Spawn()
+    {
+      // see header file for class documentation
+      return new AliHLTTPCCompModelInflaterComponent;
+    };
+
+int AliHLTTPCCompModelInflaterComponent::DoInit( int argc, const char** argv )
+    {
+      // see header file for class documentation
+      //char* cpErr;
+      if ( argc )
+       {
+         Logging( kHLTLogDebug, "HLT::TPCCompModelInflater::DoInit", "Arguments", "argv[0] == %s", argv[0] );
+         Logging(kHLTLogError, "HLT::TPCCompModelInflater::DoInit", "Unknown Option", "Unknown option '%s'", argv[0] );
+         return EINVAL;
+       }
+      return 0;
+    }
+
+int AliHLTTPCCompModelInflaterComponent::DoDeinit()
+    {
+      // see header file for class documentation
+      return 0;
+    }
+
+int AliHLTTPCCompModelInflaterComponent::DoEvent( const AliHLTComponent_EventData& evtData, const AliHLTComponent_BlockData* blocks, 
+                                                  AliHLTComponent_TriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr, 
+                                     AliHLTUInt32_t& size, vector<AliHLTComponent_BlockData>& outputBlocks )
+    {
+      // see header file for class documentation
+      // Process an event
+      // Loop over all input blocks in the event
+      AliHLTUInt8_t* writePtr = outputPtr;
+      AliHLTUInt32_t outputSize = 0, blockSize;
+      int ret;
+      AliHLTComponent_BlockData ob;
+      
+      for ( unsigned long n = 0; n < evtData.fBlockCnt; n++ )
+       {
+         if ( blocks[n].fDataType == AliHLTTPCDefinitions::fgkClusterTracksCompressedDataType )
+           {
+             blockSize = size-outputSize;
+             ret = fModelInflater.DecompressTracks( (AliHLTUInt8_t*)blocks[n].fPtr, blocks[n].fSize, writePtr, blockSize );
+             HLTDebug( "fModelInflater.DecompressTracks: ret: %d - blockSize: %u", ret, (unsigned)blockSize );
+             if ( !ret )
+               {
+                 // Let the structure be filled with the default values.
+                 // This takes care of setting the shared memory and data type values to default values,
+                 // so that they can be filled in by the calling code.
+                 FillBlockData( ob );
+                 // This block's start (offset) is after all other blocks written so far
+                 ob.fOffset = outputSize;
+                 // the size of this block's data.
+                 ob.fSize = blockSize;
+                 // The specification of the data is copied from the input block.
+                 ob.fSpecification = blocks[n].fSpecification;
+                 // The type of the data is copied from the input block.
+                 ob.fDataType = AliHLTTPCDefinitions::fgkClusterTracksModelDataType;
+                 // Place this block into the list of output blocks
+                 outputBlocks.push_back( ob );
+                 writePtr += blockSize;
+                 outputSize += blockSize;
+               }
+             continue;
+           }
+         if ( blocks[n].fDataType == AliHLTTPCDefinitions::fgkRemainingClustersCompressedDataType )
+           {
+             blockSize = size-outputSize;
+             ret = fModelInflater.DecompressRemainingClusters( (AliHLTUInt8_t*)blocks[n].fPtr, blocks[n].fSize, writePtr, blockSize );
+             HLTDebug( "ret: %d - blockSize: %u - blocks[%u].fSize: %u", ret, (unsigned)blockSize, (unsigned)n, (unsigned)blocks[n].fSize );
+             if ( !ret )
+               {
+                 // Let the structure be filled with the default values.
+                 // This takes care of setting the shared memory and data type values to default values,
+                 // so that they can be filled in by the calling code.
+                 FillBlockData( ob );
+                 // This block's start (offset) is after all other blocks written so far
+                 ob.fOffset = outputSize;
+                 // the size of this block's data.
+                 ob.fSize = blockSize;
+                 // The specification of the data is copied from the input block.
+                 ob.fSpecification = blocks[n].fSpecification;
+                 // The type of the data is copied from the input block.
+                 ob.fDataType = AliHLTTPCDefinitions::fgkRemainingClustersModelDataType;
+                 // Place this block into the list of output blocks
+                 outputBlocks.push_back( ob );
+                 writePtr += blockSize;
+                 outputSize += blockSize;
+               }
+             continue;
+           }
+       }
+      
+      // Finally we set the total size of output memory we consumed.
+      size = outputSize;
+      return 0;
+    }
diff --git a/HLT/TPCLib/comp/AliHLTTPCCompModelInflaterComponent.h b/HLT/TPCLib/comp/AliHLTTPCCompModelInflaterComponent.h
new file mode 100644 (file)
index 0000000..f8178e6
--- /dev/null
@@ -0,0 +1,104 @@
+// XEmacs -*-C++-*-
+// $Id: AliHLTTPCCompModelInflaterComponent.h,v 1.2 2006/08/10 09:46:51 richterm Exp $
+
+#ifndef ALIHLTTPCCOMPMODELINFLATERCOMPONENT_H
+#define ALIHLTTPCCOMPMODELINFLATERCOMPONENT_H
+/* TPCCompModelInflaterright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full TPCCompModelInflaterright notice                               */
+
+/** @file   AliHLTTPCCompModelInflaterComponent.h
+    @author Timm Steinbeck
+    @date   
+    @brief  Declaration of a copy component. */
+
+
+#include "AliHLTProcessor.h"
+#include "AliHLTTPCCompModelInflater.h"
+#include "AliHLTTPCCompModelConverter.h"
+
+/**
+ * @class AliHLTTPCCompModelInflaterComponent
+ * @brief A dummy HLT processing component. 
+ *
+ * An implementiation of a copy component that just copies its input data
+ * to debug a components input data
+ * @ingroup alihlt_tutorial
+ */
+class AliHLTTPCCompModelInflaterComponent : public AliHLTProcessor
+    {
+    public:
+
+      /** standard constructor */
+      AliHLTTPCCompModelInflaterComponent();
+      /** standard destructor */
+      virtual ~AliHLTTPCCompModelInflaterComponent();
+      
+      // Public functions to implement AliHLTComponent's interface.
+      // These functions are required for the registration process
+       
+      /** function to get component id 
+       * @return const char* pointer to componentid
+       */
+      const char* GetComponentID();
+
+      /** function to get input data types
+       * @param list vecotr of AliHLTComponent_DataType
+       */
+      void GetInputDataTypes( vector<AliHLTComponent_DataType>& list);
+
+      /** function to get output data type
+       * @return AliHLTComponent_DataType
+       */
+      AliHLTComponent_DataType GetOutputDataType();
+
+      /** function to get output data size
+       * @param constBase address of an unsigned long
+       * @param inputMultiplier address of a double
+       */
+      virtual void GetOutputDataSize( unsigned long& constBase, double& inputMultiplier );
+
+      /** spawn function
+       * @return AliHLTComponent* pointer to instance
+       */
+      AliHLTComponent* Spawn();
+       
+    protected:
+       
+       // Protected functions to implement AliHLTComponent's interface.
+       // These functions provide initialization as well as the actual processing
+       // capabilities of the component. 
+
+      /** initialisation function
+       * @param argc integer counting number of input arguments
+       * @param argv const char** for parameter values
+       * @return zero upon success
+       */
+      int DoInit( int argc, const char** argv );
+
+      /** deinitialisation function
+       * @return zero upon success
+       */
+      int DoDeinit();
+
+      /** do event function
+       * @param evt Data     const AliHLTComponent_EventData& to event data
+       * @param blocks       const AliHLTComponent_BlockData* to blocks of event data
+       * @param trigData     AliHLTComponent_TriggerData& of trigger data
+       * @param outputPtr    AliHLTUInt8_t* pointer to output data
+       * @param size         AliHLTUInt32_t& of output size
+       * @param outputBlocks vector<AliHLTComponent_BlockData>& of output block data
+       * @return zero upon success
+       */
+      int DoEvent( const AliHLTComponent_EventData& evtData, const AliHLTComponent_BlockData* blocks, 
+                  AliHLTComponent_TriggerData& trigData, AliHLTUInt8_t* outputPtr, 
+                  AliHLTUInt32_t& size, vector<AliHLTComponent_BlockData>& outputBlocks );
+      
+      /** member variable for instance of model inflater class */
+      AliHLTTPCCompModelInflater fModelInflater;
+      
+    private:
+
+       ClassDef(AliHLTTPCCompModelInflaterComponent, 0)
+
+    };
+#endif
index a3376dc..e080b3b 100644 (file)
@@ -54,6 +54,17 @@ CLASS_HDRS:=         AliHLTTPCTransform.h \
                tracking-ca/AliHLTTPCCATracker.h \
                tracking-ca/AliHLTTPCCATrack.h \
                tracking-ca/AliHLTTPCCATrackPar.h \
+               comp/AliHLTTPCCompDataCompressorHelper.h \
+               comp/AliHLTTPCCompDumpComponent.h \
+               comp/AliHLTTPCCompModelAnalysis.h \
+               comp/AliHLTTPCCompModelConverter.h \
+               comp/AliHLTTPCCompModelConverterComponent.h \
+               comp/AliHLTTPCCompModelDeconverter.h \
+               comp/AliHLTTPCCompModelDeconverterComponent.h \
+               comp/AliHLTTPCCompModelDeflater.h \
+               comp/AliHLTTPCCompModelDeflaterComponent.h \
+               comp/AliHLTTPCCompModelInflater.h \
+               comp/AliHLTTPCCompModelInflaterComponent.h \
                AliHLTTPCCalibPedestalComponent.h \
                AliHLTTPCCalibPulserComponent.h
 
@@ -99,4 +110,4 @@ PACKCXXFLAGS := ${HLTCXXFLAGS}
 PACKCFLAGS   := ${HLTCLFAGS}
 PACKDCXXFLAGS:= ${HLTDCXXFLAGS}
 
-EINCLUDE := HLT/TPCLib HLT/TPCLib/tracking HLT/TPCLib/tracking-ca HLT/BASE HLT/BASE/util TPC RAW STEER
+EINCLUDE := HLT/TPCLib HLT/TPCLib/tracking HLT/TPCLib/comp HLT/TPCLib/tracking-ca HLT/BASE HLT/BASE/util TPC RAW STEER