]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/comp/AliHLTTPCCompModelDeflaterComponent.cxx
access AliHLTTPCSpacePointData members through functions
[u/mrichter/AliRoot.git] / HLT / TPCLib / comp / AliHLTTPCCompModelDeflaterComponent.cxx
1 // $Id$
2
3 //**************************************************************************
4 //* This file is property of and copyright by the ALICE HLT Project        * 
5 //* ALICE Experiment at CERN, All rights reserved.                         *
6 //*                                                                        *
7 //* Primary Authors: Timm Steinbeck <timm@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 /** @file   AliHLTTPCCompModelDeflaterComponent.cxx
20     @author Timm Steinbeck
21     @date   
22     @brief  A copy processing component for the HLT. */
23
24 #if __GNUC__ >= 3
25 using namespace std;
26 #endif
27
28 #include "AliHLTTPCCompModelDeflaterComponent.h"
29 #include "AliHLTTPCDefinitions.h"
30 #include <stdlib.h>
31 #include <errno.h>
32
33 /** ROOT macro for the implementation of ROOT specific class methods */
34 ClassImp(AliHLTTPCCompModelDeflaterComponent);
35     
36 AliHLTTPCCompModelDeflaterComponent::AliHLTTPCCompModelDeflaterComponent():
37   fModelDeflater(),
38   fConverter(),
39   fForwardIfUncompressed(true)
40     {
41       // see header file for class documentation
42     }
43
44 AliHLTTPCCompModelDeflaterComponent::~AliHLTTPCCompModelDeflaterComponent()
45     {
46       // see header file for class documentation
47     }
48
49 const char* AliHLTTPCCompModelDeflaterComponent::GetComponentID()
50     {
51       // see header file for class documentation
52       return "TPCCompModelDeflater"; // The ID of this component
53     }
54
55 void AliHLTTPCCompModelDeflaterComponent::GetInputDataTypes( vector<AliHLTComponent_DataType>& list)
56     {
57       // see header file for class documentation
58       list.clear(); // We do not have any requirements for our input data type(s).
59       list.push_back( AliHLTTPCDefinitions::fgkClusterTracksModelDataType );
60       list.push_back( AliHLTTPCDefinitions::fgkRemainingClustersModelDataType );
61     }
62
63 AliHLTComponent_DataType AliHLTTPCCompModelDeflaterComponent::GetOutputDataType()
64     {
65       // see header file for class documentation
66       return AliHLTTPCDefinitions::fgkClusterTracksCompressedDataType;
67     }
68
69 void AliHLTTPCCompModelDeflaterComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
70     {
71       // see header file for class documentation
72       constBase = 1+1+216; // Format versions + cluster count per patch
73       inputMultiplier = 4.;
74       //#warning Adapt input Multiplier to something more realistic
75     }
76
77 // Spawn function, return new instance of this class
78 AliHLTComponent* AliHLTTPCCompModelDeflaterComponent::Spawn()
79     {
80       // see header file for class documentation
81       return new AliHLTTPCCompModelDeflaterComponent;
82     };
83
84 int AliHLTTPCCompModelDeflaterComponent::DoInit( int argc, const char** argv )
85     {
86       // see header file for class documentation
87       //char* cpErr;
88       if ( argc )
89         {
90           Logging( kHLTLogDebug, "HLT::TPCCompModelDeflater::DoInit", "Arguments", "argv[0] == %s", argv[0] );
91           Logging(kHLTLogError, "HLT::TPCCompModelDeflater::DoInit", "Unknown Option", "Unknown option '%s'", argv[0] );
92           return EINVAL;
93         }
94     return 0;
95     }
96
97 int AliHLTTPCCompModelDeflaterComponent::DoDeinit()
98     {
99       // see header file for class documentation
100       return 0;
101     }
102
103 int AliHLTTPCCompModelDeflaterComponent::DoEvent( const AliHLTComponent_EventData& evtData, const AliHLTComponent_BlockData* blocks, 
104                                                    AliHLTComponent_TriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr, 
105                                       AliHLTUInt32_t& size, vector<AliHLTComponent_BlockData>& outputBlocks )
106     {
107       // see header file for class documentation
108       // Process an event
109       // Loop over all input blocks in the event
110       AliHLTUInt8_t* writePtr = outputPtr;
111       AliHLTUInt32_t outputSize = 0, blockSize;
112       int ret;
113       AliHLTComponent_BlockData ob;
114       AliHLTUInt8_t minSlice=0xFF, maxSlice=0xFF, minPatch=0xFF, maxPatch=0xFF;
115       fConverter.Init();
116       unsigned long long totalNonModelDataSize=0;
117       
118       for ( unsigned long n = 0; n < evtData.fBlockCnt; n++ )
119         {
120           if ( blocks[n].fDataType == AliHLTTPCDefinitions::fgkClusterTracksModelDataType )
121             {
122               blockSize = size-outputSize;
123               ret = fModelDeflater.CompressTracks( (AliHLTUInt8_t*)blocks[n].fPtr, blocks[n].fSize, writePtr, blockSize );
124               if ( !ret && blockSize<blocks[n].fSize )
125                 {
126                   // Let the structure be filled with the default values.
127                   // This takes care of setting the shared memory and data type values to default values,
128                   // so that they can be filled in by the calling code.
129                   FillBlockData( ob );
130                   // This block's start (offset) is after all other blocks written so far
131                   ob.fOffset = outputSize;
132                   // the size of this block's data.
133                   ob.fSize = blockSize;
134                   // The specification of the data is copied from the input block.
135                   ob.fSpecification = blocks[n].fSpecification;
136                   // The type of the data is copied from the input block.
137                   ob.fDataType = AliHLTTPCDefinitions::fgkClusterTracksCompressedDataType;
138                   // Place this block into the list of output blocks
139                   outputBlocks.push_back( ob );
140                   writePtr += blockSize;
141                 outputSize += blockSize;
142                 }
143               else if ( fForwardIfUncompressed )
144                 {
145                   outputBlocks.push_back( blocks[n] );
146                 }
147               continue;
148             }
149           if ( blocks[n].fDataType == AliHLTTPCDefinitions::fgkRemainingClustersModelDataType )
150             {
151             blockSize = size-outputSize;
152             ret = fModelDeflater.CompressRemainingClusters( (AliHLTUInt8_t*)blocks[n].fPtr, blocks[n].fSize, writePtr, blockSize );
153             HLTDebug( "ret: %d - blockSize: %u - blocks[%u].fSize: %u", ret, (unsigned)blockSize, (unsigned)n, (unsigned)blocks[n].fSize );
154             if ( !ret && blockSize<blocks[n].fSize )
155               {
156                 // Let the structure be filled with the default values.
157                 // This takes care of setting the shared memory and data type values to default values,
158                 // so that they can be filled in by the calling code.
159                 FillBlockData( ob );
160                 // This block's start (offset) is after all other blocks written so far
161                 ob.fOffset = outputSize;
162                 // the size of this block's data.
163                 ob.fSize = blockSize;
164                 // The specification of the data is copied from the input block.
165                 ob.fSpecification = blocks[n].fSpecification;
166                 // The type of the data is copied from the input block.
167                 ob.fDataType = AliHLTTPCDefinitions::fgkRemainingClustersCompressedDataType;
168                 // Place this block into the list of output blocks
169                 outputBlocks.push_back( ob );
170                 writePtr += blockSize;
171                 outputSize += blockSize;
172               }
173             else if ( fForwardIfUncompressed )
174               {
175                 outputBlocks.push_back( blocks[n] );
176               }
177             continue;
178             }
179           AliHLTUInt8_t slice = 0;
180           AliHLTUInt8_t patch = 0;
181           if ( blocks[n].fDataType == AliHLTTPCDefinitions::fgkClustersDataType ||
182                blocks[n].fDataType == AliHLTTPCDefinitions::fgkTracksDataType )
183             {
184               slice = AliHLTTPCDefinitions::GetMinSliceNr( blocks[n].fSpecification );
185               patch = AliHLTTPCDefinitions::GetMinPatchNr( blocks[n].fSpecification );
186               if ( minSlice==0xFF || slice<minSlice )
187                 minSlice = slice;
188               if ( maxSlice==0xFF || slice>maxSlice )
189                 maxSlice = slice;
190               if ( minPatch==0xFF || patch<minPatch )
191                 minPatch = patch;
192               if ( maxPatch==0xFF || patch>maxPatch )
193                 maxPatch = patch;
194               totalNonModelDataSize += blocks[n].fSize;
195             }
196           if ( blocks[n].fDataType == AliHLTTPCDefinitions::fgkClustersDataType )
197             {
198             fConverter.SetInputClusters( (AliHLTTPCClusterData*)blocks[n].fPtr, slice, patch );
199             }
200           if ( blocks[n].fDataType == AliHLTTPCDefinitions::fgkTracksDataType )
201             {
202               fConverter.SetInputTracks( (AliHLTTPCTrackletData*)blocks[n].fPtr );
203             }
204           
205         }
206       
207       if ( totalNonModelDataSize>0 )
208         {
209           fConverter.Convert();
210           
211           unsigned long trackSize = fConverter.GetOutputModelDataSize();
212           AliHLTUInt8_t* trackModelData = new AliHLTUInt8_t[ trackSize ];
213           if ( !trackModelData )
214             {
215               HLTError( "Out of memory trying to allocate %lu bytes of trackmodeldata", trackSize );
216               return ENOMEM;
217             }
218           
219           fConverter.OutputModelData( trackModelData );
220           
221           unsigned long clusterSize = fConverter.GetRemainingClustersOutputDataSize();
222           AliHLTUInt8_t* remainingClustersModelData = new AliHLTUInt8_t[ clusterSize ];
223           if ( !remainingClustersModelData )
224             {
225               HLTError( "Out of memory trying to allocate %lu bytes of remaining cluster model data", clusterSize );
226               delete [] trackModelData;
227               return ENOMEM;
228             }
229           
230           fConverter.GetRemainingClusters( remainingClustersModelData, clusterSize );
231           
232           bool forwardUncompressed = false;
233           
234           blockSize = size-outputSize;
235           ret = fModelDeflater.CompressTracks( trackModelData, trackSize, writePtr, blockSize );
236           unsigned long long totalCompressedModelData = blockSize;
237           if ( !ret )
238             {
239               // Let the structure be filled with the default values.
240               // This takes care of setting the shared memory and data type values to default values,
241               // so that they can be filled in by the calling code.
242               FillBlockData( ob );
243               // This block's start (offset) is after all other blocks written so far
244               ob.fOffset = outputSize;
245               // the size of this block's data.
246               ob.fSize = blockSize;
247               // The specification of the data is copied from the input block.
248               ob.fSpecification = AliHLTTPCDefinitions::EncodeDataSpecification( minSlice, maxSlice, minPatch, maxPatch );
249               // The type of the data is copied from the input block.
250               ob.fDataType = AliHLTTPCDefinitions::fgkClusterTracksCompressedDataType;
251               // Place this block into the list of output blocks
252               outputBlocks.push_back( ob );
253               writePtr += blockSize;
254               outputSize += blockSize;
255               
256               blockSize = size-outputSize;
257               ret = fModelDeflater.CompressRemainingClusters( remainingClustersModelData, clusterSize, writePtr, blockSize );
258               totalCompressedModelData += blockSize;
259               if ( !ret && totalCompressedModelData<totalNonModelDataSize )
260                 {
261                   // Let the structure be filled with the default values.
262                   // This takes care of setting the shared memory and data type values to default values,
263                   // so that they can be filled in by the calling code.
264                   FillBlockData( ob );
265                   // This block's start (offset) is after all other blocks written so far
266                   ob.fOffset = outputSize;
267                   // the size of this block's data.
268                   ob.fSize = blockSize;
269                   // The specification of the data is copied from the input block.
270                   ob.fSpecification = AliHLTTPCDefinitions::EncodeDataSpecification( minSlice, maxSlice, minPatch, maxPatch );
271                   // The type of the data is copied from the input block.
272                   ob.fDataType = AliHLTTPCDefinitions::fgkRemainingClustersCompressedDataType;
273                   // Place this block into the list of output blocks
274                   outputBlocks.push_back( ob );
275                   writePtr += blockSize;
276                   outputSize += blockSize;
277                 }
278               else if ( fForwardIfUncompressed )
279                 {
280                   outputSize -= (outputBlocks.end()-1)->fSize;
281                   outputBlocks.erase( outputBlocks.end()-1 );
282                   forwardUncompressed = true;
283                 }
284               
285               
286             }
287           else if ( fForwardIfUncompressed )
288             forwardUncompressed = true;
289           
290           delete [] trackModelData;
291           delete [] remainingClustersModelData;
292           
293           if ( forwardUncompressed )
294             {
295               for ( unsigned long n = 0; n < evtData.fBlockCnt; n++ )
296                 {
297                   if ( blocks[n].fDataType == AliHLTTPCDefinitions::fgkClustersDataType ||
298                        blocks[n].fDataType == AliHLTTPCDefinitions::fgkTracksDataType )
299                     {
300                       outputBlocks.push_back( blocks[n] );
301                     }
302                   
303                 }
304             }
305         }
306       
307       // Finally we set the total size of output memory we consumed.
308       size = outputSize;
309       return 0;
310     }