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