]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/tracking-ca/AliHLTTPCCASliceOutput.cxx
output of the slice tracker is compressed in order to minimize the network traffic
[u/mrichter/AliRoot.git] / HLT / TPCLib / tracking-ca / AliHLTTPCCASliceOutput.cxx
1 // @(#) $Id$
2 // **************************************************************************
3 // This file is property of and copyright by the ALICE HLT Project          *
4 // ALICE Experiment at CERN, All rights reserved.                           *
5 //                                                                          *
6 // Primary Authors: Sergey Gorbunov <sergey.gorbunov@kip.uni-heidelberg.de> *
7 //                  Ivan Kisel <kisel@kip.uni-heidelberg.de>                *
8 //                  for The ALICE HLT Project.                              *
9 //                                                                          *
10 // Permission to use, copy, modify and distribute this software and its     *
11 // documentation strictly for non-commercial purposes is hereby granted     *
12 // without fee, provided that the above copyright notice appears in all     *
13 // copies and that both the copyright notice and this permission notice     *
14 // appear in the supporting documentation. The authors make no claims       *
15 // about the suitability of this software for any purpose. It is            *
16 // provided "as is" without express or implied warranty.                    *
17 //                                                                          *
18 //***************************************************************************
19
20 #include "AliHLTTPCCASliceOutput.h"
21 #include "MemoryAssignmentHelpers.h"
22
23
24 GPUhd() int AliHLTTPCCASliceOutput::EstimateSize( int nOfTracks, int nOfTrackClusters )
25 {
26   // calculate the amount of memory [bytes] needed for the event
27
28   const int kClusterDataSize = sizeof(  int ) + sizeof( unsigned short ) + sizeof( float2 ) + sizeof( float ) + sizeof( UChar_t ) + sizeof( UChar_t );
29
30   return sizeof( AliHLTTPCCASliceOutput ) + sizeof( AliHLTTPCCASliceTrack )*nOfTracks + kClusterDataSize*nOfTrackClusters;
31 }
32
33 #ifndef HLTCA_GPUCODE
34
35 inline void AssignNoAlignment( int &dst, int &size, int count )
36 {
37   // assign memory to the pointer dst
38   dst = size;
39   size = dst + count ;
40 }
41
42 void AliHLTTPCCASliceOutput::SetPointers(int nTracks, int nTrackClusters, const outputControlStruct* outputControl)
43 {
44   // set all pointers
45         if (nTracks == -1) nTracks = fNTracks;
46         if (nTrackClusters == -1) nTrackClusters = fNTrackClusters;
47
48   int size = 0;
49
50   if (outputControl == NULL || outputControl->fDefaultOutput)
51   {
52     AssignNoAlignment( fTracksOffset,            size, nTracks*sizeof(AliHLTTPCCASliceTrack) );
53     AssignNoAlignment( fClusterIdOffset,         size, nTrackClusters*sizeof(int) );
54     AssignNoAlignment( fClusterRowOffset,        size, nTrackClusters*sizeof(float) );
55     AssignNoAlignment( fClusterPackedXYZOffset, size, nTrackClusters*sizeof(AliHLTTPCCACompressedCluster) );
56    }
57
58   char *mem = fMemory + size;
59
60   if (outputControl == NULL || outputControl->fObsoleteOutput)
61   {
62           // memory for output tracks
63           AssignMemory( fOutTracks, mem, nTracks );
64           // arrays for track hits
65           AssignMemory( fOutTrackHits, mem, nTrackClusters );
66   }
67   if ((size_t) (mem - fMemory) + sizeof(AliHLTTPCCASliceOutput) > fMemorySize)
68   {
69           fMemorySize = NULL;
70           //printf("\nINTERNAL ERROR IN AliHLTTPCCASliceOutput MEMORY MANAGEMENT req: %d avail: %d\n", (int) ((size_t) (mem - fMemory) + sizeof(AliHLTTPCCASliceOutput)), (int) fMemorySize);
71   }
72 }
73
74 void AliHLTTPCCASliceOutput::Allocate(AliHLTTPCCASliceOutput* &ptrOutput, int nTracks, int nTrackHits, outputControlStruct* outputControl)
75 {
76         //Allocate All memory needed for slice output
77   const int memsize = (outputControl->fDefaultOutput ? EstimateSize(nTracks, nTrackHits) : sizeof(AliHLTTPCCASliceOutput)) +
78           (outputControl->fObsoleteOutput? (nTracks * sizeof(AliHLTTPCCAOutTrack) + nTrackHits * sizeof(int)) : 0);
79   if (outputControl->fOutputPtr)
80   {
81           if (outputControl->fOutputMaxSize < memsize)
82           {
83                   outputControl->fEndOfSpace = 1;
84                   ptrOutput = NULL;
85                   return;
86           }
87         ptrOutput = (AliHLTTPCCASliceOutput*) outputControl->fOutputPtr;
88         outputControl->fOutputPtr += memsize;
89         outputControl->fOutputMaxSize -= memsize;
90   }
91   else
92   {
93     if (ptrOutput) free(ptrOutput);
94         ptrOutput = (AliHLTTPCCASliceOutput*) malloc(memsize);
95   }
96   ptrOutput->SetMemorySize(memsize);
97   ptrOutput->SetPointers(nTracks, nTrackHits, outputControl); // set pointers
98 }
99 #endif