]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/TPCLib/tracking-ca/AliHLTTPCCASliceOutput.h
bug fix: reconstruction crash when the output buffer size exceed
[u/mrichter/AliRoot.git] / HLT / TPCLib / tracking-ca / AliHLTTPCCASliceOutput.h
index 05a2a6267d37f66db42d18059079dd88437483fc..3f740d822df1950f6dcf4a8d212801fbe1f6071b 100644 (file)
@@ -1,6 +1,6 @@
 //-*- Mode: C++ -*-
 // ************************************************************************
-// This file is property of and copyright by the ALICE HLT Project        * 
+// This file is property of and copyright by the ALICE HLT Project        *
 // ALICE Experiment at CERN, All rights reserved.                         *
 // See cxx source for full Copyright notice                               *
 //                                                                        *
 #define ALIHLTTPCCASLICEOUTPUT_H
 
 #include "AliHLTTPCCADef.h"
-
+#include <cstdlib>
 #include "AliHLTTPCCASliceTrack.h"
+//Obsolete
+#include "AliHLTTPCCAOutTrack.h"
 
 /**
  * @class AliHLTTPCCASliceOutput
  * and transport the output to AliHLTTPCCAGBMerger{Component}
  *
  * The class contains all the necessary information about TPC tracks, reconstructed in one slice.
- * This includes the reconstructed track parameters and some compressed information 
+ * This includes the reconstructed track parameters and some compressed information
  * about the assigned clusters: clusterId, position and amplitude.
  *
  */
 class AliHLTTPCCASliceOutput
 {
- public:
-
-  GPUhd() Int_t NTracks()                    const { return fNTracks;              }
-  GPUhd() Int_t NTrackClusters()             const { return fNTrackClusters;       }
-
-  GPUhd() const AliHLTTPCCASliceTrack &Track( Int_t i ) const { return fTracks[i]; }
-  GPUhd() UInt_t   ClusterIDrc     ( Int_t i )  const { return fClusterIDrc[i]; }
-  GPUhd() UShort_t ClusterPackedYZ ( Int_t i )  const { return fClusterPackedYZ[i]; }
-  GPUhd() UChar_t  ClusterPackedAmp( Int_t i )  const { return fClusterPackedAmp[i]; }
-  GPUhd() float2   ClusterUnpackedYZ ( Int_t i )  const { return fClusterUnpackedYZ[i]; }
-  GPUhd() float    ClusterUnpackedX  ( Int_t i )  const { return fClusterUnpackedX[i]; }
-
-  GPUhd() static Int_t EstimateSize( Int_t nOfTracks, Int_t nOfTrackClusters );
-  GPUhd() void SetPointers();
-
-  GPUhd() void SetNTracks       ( Int_t v )  { fNTracks = v;        }
-  GPUhd() void SetNTrackClusters( Int_t v )  { fNTrackClusters = v; }
-
-  GPUhd() void SetTrack( Int_t i, const AliHLTTPCCASliceTrack &v ) {  fTracks[i] = v; }
-  GPUhd() void SetClusterIDrc( Int_t i, UInt_t v ) {  fClusterIDrc[i] = v; }
-  GPUhd() void SetClusterPackedYZ( Int_t i, UShort_t v ) {  fClusterPackedYZ[i] = v; }
-  GPUhd() void SetClusterPackedAmp( Int_t i, UChar_t v ) {  fClusterPackedAmp[i] = v; }
-  GPUhd() void SetClusterUnpackedYZ( Int_t i, float2 v ) {  fClusterUnpackedYZ[i] = v; }
-  GPUhd() void SetClusterUnpackedX( Int_t i, float v ) {  fClusterUnpackedX[i] = v; }
-
- private:
-
-  AliHLTTPCCASliceOutput( const AliHLTTPCCASliceOutput& )
-    : fNTracks(0),fNTrackClusters(0),fTracks(0),fClusterIDrc(0), fClusterPackedYZ(0),fClusterUnpackedYZ(0),fClusterUnpackedX(0),fClusterPackedAmp(0){}
-
-  const AliHLTTPCCASliceOutput& operator=( const AliHLTTPCCASliceOutput& ) const { return *this; }
-
-  Int_t fNTracks;                 // number of reconstructed tracks
-  Int_t fNTrackClusters;          // total number of track clusters
-  AliHLTTPCCASliceTrack *fTracks; // pointer to reconstructed tracks
-  UInt_t   *fClusterIDrc;         // pointer to cluster IDs ( packed IRow and ICluster)
-  UShort_t *fClusterPackedYZ;     // pointer to packed cluster YZ coordinates 
-  float2   *fClusterUnpackedYZ;   // pointer to cluster coordinates (temporary data, for debug proposes)
-  float    *fClusterUnpackedX;   // pointer to cluster coordinates (temporary data, for debug proposes)
-  UChar_t  *fClusterPackedAmp;    // pointer to packed cluster amplitudes
+  public:
+
+       struct outputControlStruct
+       {
+               outputControlStruct() : fObsoleteOutput( 1 ), fDefaultOutput( 1 ), fOutputPtr( NULL ), fOutputMaxSize ( 0 ), fEndOfSpace(0) {}
+               int fObsoleteOutput;    //Enable Obsolete Output
+               int fDefaultOutput;             //Enable Default Output
+               char* fOutputPtr;               //Pointer to Output Space, NULL to allocate output space
+               int fOutputMaxSize;             //Max Size of Output Data if Pointer to output space is given
+               bool fEndOfSpace; // end of space flag 
+       };
+
+    GPUhd() int NTracks()                    const { return fNTracks;              }
+    GPUhd() int NTrackClusters()             const { return fNTrackClusters;       }
+
+    GPUhd() const AliHLTTPCCASliceTrack &Track( int i ) const { return fTracks[i]; }
+    GPUhd() unsigned char   ClusterRow     ( int i )  const { return fClusterRow[i]; }
+    GPUhd()  int   ClusterId     ( int i )  const { return fClusterId[i]; }
+    GPUhd() float2   ClusterUnpackedYZ ( int i )  const { return fClusterUnpackedYZ[i]; }
+    GPUhd() float    ClusterUnpackedX  ( int i )  const { return fClusterUnpackedX[i]; }
+
+    GPUhd() static int EstimateSize( int nOfTracks, int nOfTrackClusters );
+    void SetPointers(int nTracks = -1, int nTrackClusters = -1, const outputControlStruct* outputControl = NULL);
+       static void Allocate(AliHLTTPCCASliceOutput* &ptrOutput, int nTracks, int nTrackHits, outputControlStruct* outputControl);
+
+    GPUhd() void SetNTracks       ( int v )  { fNTracks = v;        }
+    GPUhd() void SetNTrackClusters( int v )  { fNTrackClusters = v; }
+
+    GPUhd() void SetTrack( int i, const AliHLTTPCCASliceTrack &v ) {  fTracks[i] = v; }
+    GPUhd() void SetClusterRow( int i, unsigned char v ) {  fClusterRow[i] = v; }
+    GPUhd() void SetClusterId( int i, int v ) {  fClusterId[i] = v; }
+    GPUhd() void SetClusterUnpackedYZ( int i, float2 v ) {  fClusterUnpackedYZ[i] = v; }
+    GPUhd() void SetClusterUnpackedX( int i, float v ) {  fClusterUnpackedX[i] = v; }
+
+       GPUhd() size_t OutputMemorySize() const { return(fMemorySize); }
+
+       //Obsolete Output
+
+    GPUhd()  int NOutTracks() const { return(fNOutTracks); }
+       GPUhd()  void SetNOutTracks(int val) { fNOutTracks = val; }
+    GPUhd()  AliHLTTPCCAOutTrack *OutTracks() const { return  fOutTracks; }
+    GPUhd()  const AliHLTTPCCAOutTrack &OutTrack( int index ) const { return fOutTracks[index]; }
+    GPUhd()  int NOutTrackHits() const { return  fNOutTrackHits; }
+       GPUhd()  void SetNOutTrackHits(int val) { fNOutTrackHits = val; }
+    GPUhd()  void SetOutTrackHit(int n, int val) { fOutTrackHits[n] = val; }
+    GPUhd()  int OutTrackHit( int i ) const { return  fOutTrackHits[i]; }
+
+  private:
+    AliHLTTPCCASliceOutput()
+        : fNTracks( 0 ), fNTrackClusters( 0 ), fTracks( 0 ),  fClusterId( 0 ), fClusterRow( 0 ), fClusterUnpackedYZ( 0 ), fClusterUnpackedX( 0 ),
+               fMemorySize( 0 ), fNOutTracks(0), fNOutTrackHits(0), fOutTracks(0), fOutTrackHits(0) {}
+
+       ~AliHLTTPCCASliceOutput() {}
+    const AliHLTTPCCASliceOutput& operator=( const AliHLTTPCCASliceOutput& ) const { return *this; }
+    AliHLTTPCCASliceOutput( const AliHLTTPCCASliceOutput& );
+
+       GPUh() void SetMemorySize(size_t val) { fMemorySize = val; }
+
+    int fNTracks;                   // number of reconstructed tracks
+    int fNTrackClusters;            // total number of track clusters
+    AliHLTTPCCASliceTrack *fTracks; // pointer to reconstructed tracks
+    int   *fClusterId;              // pointer to cluster Id's ( packed slice, patch, cluster )
+    UChar_t  *fClusterRow;     // pointer to cluster row numbers
+    float2   *fClusterUnpackedYZ;    // pointer to cluster coordinates (temporary data, for debug proposes)
+    float    *fClusterUnpackedX;     // pointer to cluster coordinates (temporary data, for debug proposes)
+       size_t fMemorySize;                             // Amount of memory really used
+
+    // obsolete output
+
+       int fNOutTracks;
+       int fNOutTrackHits;
+    AliHLTTPCCAOutTrack *fOutTracks; // output array of the reconstructed tracks
+    int *fOutTrackHits;  // output array of ID's of the reconstructed hits
+
+       //Must be last element of this class, user has to make sure to allocate anough memory consecutive to class memory!
+       //This way the whole Slice Output is one consecutive Memory Segment
+    char fMemory[1]; // the memory where the pointers above point into
 
 };
 
-
-
-GPUhd() inline Int_t AliHLTTPCCASliceOutput::EstimateSize( Int_t nOfTracks, Int_t nOfTrackClusters )
-{
-  // calculate the amount of memory [bytes] needed for the event
-
-  const Int_t kClusterDataSize = sizeof(UInt_t) + sizeof(UShort_t) + sizeof(float2) + sizeof(float)+ sizeof(UChar_t);
-
-  return sizeof(AliHLTTPCCASliceOutput) + sizeof(AliHLTTPCCASliceTrack)*nOfTracks + kClusterDataSize*nOfTrackClusters;
-}
-
-
-GPUhd() inline void AliHLTTPCCASliceOutput::SetPointers()
-{
-  // set all pointers
-
-  fTracks            = (AliHLTTPCCASliceTrack*)((&fClusterPackedAmp)+1);
-  fClusterUnpackedYZ = (float2*)  ( fTracks   + fNTracks );
-  fClusterUnpackedX  = (float*)   ( fClusterUnpackedYZ + fNTrackClusters );
-  fClusterIDrc       = (UInt_t*)  ( fClusterUnpackedX  + fNTrackClusters );
-  fClusterPackedYZ   = (UShort_t*)( fClusterIDrc       + fNTrackClusters );
-  fClusterPackedAmp  = (UChar_t*) ( fClusterPackedYZ + fNTrackClusters );
-}
-
-#endif
+#endif //ALIHLTTPCCASLICEOUTPUT_H