2 // **************************************************************************
3 // This file is property of and copyright by the ALICE HLT Project *
4 // ALICE Experiment at CERN, All rights reserved. *
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. *
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. *
18 //***************************************************************************
20 #include "AliHLTTPCCASliceOutput.h"
21 #include "MemoryAssignmentHelpers.h"
24 GPUhd() int AliHLTTPCCASliceOutput::EstimateSize( int nOfTracks, int nOfTrackClusters )
26 // calculate the amount of memory [bytes] needed for the event
28 const int kClusterDataSize = sizeof( int ) + sizeof( unsigned short ) + sizeof( float2 ) + sizeof( float ) + sizeof( UChar_t ) + sizeof( UChar_t );
30 return sizeof( AliHLTTPCCASliceOutput ) + sizeof( AliHLTTPCCASliceTrack )*nOfTracks + kClusterDataSize*nOfTrackClusters;
35 template<typename T> inline void AssignNoAlignment( T *&dst, char *&mem, int count )
37 // assign memory to the pointer dst
39 mem = ( char * )( dst + count );
42 void AliHLTTPCCASliceOutput::SetPointers(int nTracks, int nTrackClusters, const outputControlStruct* outputControl)
45 if (nTracks == -1) nTracks = fNTracks;
46 if (nTrackClusters == -1) nTrackClusters = fNTrackClusters;
50 if (outputControl == NULL || outputControl->fDefaultOutput)
52 AssignNoAlignment( fTracks, mem, nTracks );
53 AssignNoAlignment( fClusterUnpackedYZ, mem, nTrackClusters );
54 AssignNoAlignment( fClusterUnpackedX, mem, nTrackClusters );
55 AssignNoAlignment( fClusterId, mem, nTrackClusters );
56 AssignNoAlignment( fClusterRow, mem, nTrackClusters );
59 if (outputControl == NULL || outputControl->fObsoleteOutput)
61 // memory for output tracks
62 AssignMemory( fOutTracks, mem, nTracks );
63 // arrays for track hits
64 AssignMemory( fOutTrackHits, mem, nTrackClusters );
66 if ((size_t) (mem - fMemory) + sizeof(AliHLTTPCCASliceOutput) > fMemorySize)
69 //printf("\nINTERNAL ERROR IN AliHLTTPCCASliceOutput MEMORY MANAGEMENT req: %d avail: %d\n", (int) ((size_t) (mem - fMemory) + sizeof(AliHLTTPCCASliceOutput)), (int) fMemorySize);
73 void AliHLTTPCCASliceOutput::Allocate(AliHLTTPCCASliceOutput* &ptrOutput, int nTracks, int nTrackHits, outputControlStruct* outputControl)
75 //Allocate All memory needed for slice output
76 const int memsize = (outputControl->fDefaultOutput ? EstimateSize(nTracks, nTrackHits) : sizeof(AliHLTTPCCASliceOutput)) +
77 (outputControl->fObsoleteOutput? (nTracks * sizeof(AliHLTTPCCAOutTrack) + nTrackHits * sizeof(int)) : 0);
78 if (outputControl->fOutputPtr)
80 if (outputControl->fOutputMaxSize < memsize)
82 outputControl->fEndOfSpace = 1;
86 ptrOutput = (AliHLTTPCCASliceOutput*) outputControl->fOutputPtr;
87 outputControl->fOutputPtr += memsize;
88 outputControl->fOutputMaxSize -= memsize;
92 if (ptrOutput) free(ptrOutput);
93 ptrOutput = (AliHLTTPCCASliceOutput*) malloc(memsize);
95 ptrOutput->SetMemorySize(memsize);
96 ptrOutput->SetPointers(nTracks, nTrackHits, outputControl); // set pointers