3 //**************************************************************************
4 //* This file is property of and copyright by the ALICE HLT Project *
5 //* ALICE Experiment at CERN, All rights reserved. *
7 //* Primary Authors: Timm Steinbeck <timm@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. *
17 //**************************************************************************
19 /** @file AliHLTTPCCompModelDeflaterComponent.cxx
20 @author Timm Steinbeck
22 @brief A copy processing component for the HLT. */
28 #include "AliHLTTPCCompModelDeflaterComponent.h"
29 #include "AliHLTTPCDefinitions.h"
33 /** ROOT macro for the implementation of ROOT specific class methods */
34 ClassImp(AliHLTTPCCompModelDeflaterComponent);
36 AliHLTTPCCompModelDeflaterComponent::AliHLTTPCCompModelDeflaterComponent():
39 fForwardIfUncompressed(true)
41 // see header file for class documentation
44 AliHLTTPCCompModelDeflaterComponent::~AliHLTTPCCompModelDeflaterComponent()
46 // see header file for class documentation
49 const char* AliHLTTPCCompModelDeflaterComponent::GetComponentID()
51 // see header file for class documentation
52 return "TPCCompModelDeflater"; // The ID of this component
55 void AliHLTTPCCompModelDeflaterComponent::GetInputDataTypes( vector<AliHLTComponent_DataType>& list)
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 );
63 AliHLTComponent_DataType AliHLTTPCCompModelDeflaterComponent::GetOutputDataType()
65 // see header file for class documentation
66 return AliHLTTPCDefinitions::fgkClusterTracksCompressedDataType;
69 void AliHLTTPCCompModelDeflaterComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
71 // see header file for class documentation
72 constBase = 1+1+216; // Format versions + cluster count per patch
74 //#warning Adapt input Multiplier to something more realistic
77 // Spawn function, return new instance of this class
78 AliHLTComponent* AliHLTTPCCompModelDeflaterComponent::Spawn()
80 // see header file for class documentation
81 return new AliHLTTPCCompModelDeflaterComponent;
84 int AliHLTTPCCompModelDeflaterComponent::DoInit( int argc, const char** argv )
86 // see header file for class documentation
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] );
97 int AliHLTTPCCompModelDeflaterComponent::DoDeinit()
99 // see header file for class documentation
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 )
107 // see header file for class documentation
109 // Loop over all input blocks in the event
110 AliHLTUInt8_t* writePtr = outputPtr;
111 AliHLTUInt32_t outputSize = 0, blockSize;
113 AliHLTComponent_BlockData ob;
114 AliHLTUInt8_t minSlice=0xFF, maxSlice=0xFF, minPatch=0xFF, maxPatch=0xFF;
116 unsigned long long totalNonModelDataSize=0;
118 for ( unsigned long n = 0; n < evtData.fBlockCnt; n++ )
120 if ( blocks[n].fDataType == AliHLTTPCDefinitions::fgkClusterTracksModelDataType )
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 )
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.
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;
143 else if ( fForwardIfUncompressed )
145 outputBlocks.push_back( blocks[n] );
149 if ( blocks[n].fDataType == AliHLTTPCDefinitions::fgkRemainingClustersModelDataType )
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 )
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.
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;
173 else if ( fForwardIfUncompressed )
175 outputBlocks.push_back( blocks[n] );
179 AliHLTUInt8_t slice = 0;
180 AliHLTUInt8_t patch = 0;
181 if ( blocks[n].fDataType == AliHLTTPCDefinitions::fgkClustersDataType ||
182 blocks[n].fDataType == AliHLTTPCDefinitions::fgkTracksDataType )
184 slice = AliHLTTPCDefinitions::GetMinSliceNr( blocks[n].fSpecification );
185 patch = AliHLTTPCDefinitions::GetMinPatchNr( blocks[n].fSpecification );
186 if ( minSlice==0xFF || slice<minSlice )
188 if ( maxSlice==0xFF || slice>maxSlice )
190 if ( minPatch==0xFF || patch<minPatch )
192 if ( maxPatch==0xFF || patch>maxPatch )
194 totalNonModelDataSize += blocks[n].fSize;
196 if ( blocks[n].fDataType == AliHLTTPCDefinitions::fgkClustersDataType )
198 fConverter.SetInputClusters( (AliHLTTPCClusterData*)blocks[n].fPtr, slice, patch );
200 if ( blocks[n].fDataType == AliHLTTPCDefinitions::fgkTracksDataType )
202 fConverter.SetInputTracks( (AliHLTTPCTrackletData*)blocks[n].fPtr );
207 if ( totalNonModelDataSize>0 )
209 fConverter.Convert();
211 unsigned long trackSize = fConverter.GetOutputModelDataSize();
212 AliHLTUInt8_t* trackModelData = new AliHLTUInt8_t[ trackSize ];
213 if ( !trackModelData )
215 HLTError( "Out of memory trying to allocate %lu bytes of trackmodeldata", trackSize );
219 fConverter.OutputModelData( trackModelData );
221 unsigned long clusterSize = fConverter.GetRemainingClustersOutputDataSize();
222 AliHLTUInt8_t* remainingClustersModelData = new AliHLTUInt8_t[ clusterSize ];
223 if ( !remainingClustersModelData )
225 HLTError( "Out of memory trying to allocate %lu bytes of remaining cluster model data", clusterSize );
226 delete [] trackModelData;
230 fConverter.GetRemainingClusters( remainingClustersModelData, clusterSize );
232 bool forwardUncompressed = false;
234 blockSize = size-outputSize;
235 ret = fModelDeflater.CompressTracks( trackModelData, trackSize, writePtr, blockSize );
236 unsigned long long totalCompressedModelData = blockSize;
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.
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;
256 blockSize = size-outputSize;
257 ret = fModelDeflater.CompressRemainingClusters( remainingClustersModelData, clusterSize, writePtr, blockSize );
258 totalCompressedModelData += blockSize;
259 if ( !ret && totalCompressedModelData<totalNonModelDataSize )
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.
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;
278 else if ( fForwardIfUncompressed )
280 outputSize -= (outputBlocks.end()-1)->fSize;
281 outputBlocks.erase( outputBlocks.end()-1 );
282 forwardUncompressed = true;
287 else if ( fForwardIfUncompressed )
288 forwardUncompressed = true;
290 delete [] trackModelData;
291 delete [] remainingClustersModelData;
293 if ( forwardUncompressed )
295 for ( unsigned long n = 0; n < evtData.fBlockCnt; n++ )
297 if ( blocks[n].fDataType == AliHLTTPCDefinitions::fgkClustersDataType ||
298 blocks[n].fDataType == AliHLTTPCDefinitions::fgkTracksDataType )
300 outputBlocks.push_back( blocks[n] );
307 // Finally we set the total size of output memory we consumed.