1 // **************************************************************************
2 // This file is property of and copyright by the ALICE HLT Project *
3 // ALICE Experiment at CERN, All rights reserved. *
5 // Primary Authors: Sergey Gorbunov <sergey.gorbunov@kip.uni-heidelberg.de> *
6 // Ivan Kisel <kisel@kip.uni-heidelberg.de> *
7 // for The ALICE HLT Project. *
9 // Permission to use, copy, modify and distribute this software and its *
10 // documentation strictly for non-commercial purposes is hereby granted *
11 // without fee, provided that the above copyright notice appears in all *
12 // copies and that both the copyright notice and this permission notice *
13 // appear in the supporting documentation. The authors make no claims *
14 // about the suitability of this software for any purpose. It is *
15 // provided "as is" without express or implied warranty. *
17 //***************************************************************************
20 ///////////////////////////////////////////////////////////////////////////////
22 // a TPC tracker processing component for the HLT based on CA by Ivan Kisel //
24 ///////////////////////////////////////////////////////////////////////////////
30 #include "AliHLTTPCCAInputDataCompressorComponent.h"
31 #include "AliHLTTPCCACompressedInputData.h"
32 #include "AliHLTTPCTransform.h"
33 #include "AliHLTTPCClusterDataFormat.h"
34 #include "AliHLTTPCSpacePointData.h"
35 #include "AliHLTTPCDefinitions.h"
36 #include "AliHLTTPCCADef.h"
39 const AliHLTComponentDataType AliHLTTPCCADefinitions::fgkCompressedInputDataType = AliHLTComponentDataTypeInitializer( "CAINPACK", kAliHLTDataOriginTPC );
41 /** ROOT macro for the implementation of ROOT specific class methods */
42 ClassImp( AliHLTTPCCAInputDataCompressorComponent )
44 AliHLTTPCCAInputDataCompressorComponent::AliHLTTPCCAInputDataCompressorComponent()
47 fBenchmark("CAInputCompressor")
49 // see header file for class documentation
51 // refer to README to build package
53 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
56 AliHLTTPCCAInputDataCompressorComponent::AliHLTTPCCAInputDataCompressorComponent( const AliHLTTPCCAInputDataCompressorComponent& )
59 fBenchmark("CAInputCompressor")
61 // see header file for class documentation
62 HLTFatal( "copy constructor untested" );
65 AliHLTTPCCAInputDataCompressorComponent& AliHLTTPCCAInputDataCompressorComponent::operator=( const AliHLTTPCCAInputDataCompressorComponent& )
67 // see header file for class documentation
68 HLTFatal( "assignment operator untested" );
72 AliHLTTPCCAInputDataCompressorComponent::~AliHLTTPCCAInputDataCompressorComponent()
74 // see header file for class documentation
78 // Public functions to implement AliHLTComponent's interface.
79 // These functions are required for the registration process
82 const char* AliHLTTPCCAInputDataCompressorComponent::GetComponentID()
84 // see header file for class documentation
85 return "TPCCAInputDataCompressor";
88 void AliHLTTPCCAInputDataCompressorComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list )
90 // see header file for class documentation
92 list.push_back( AliHLTTPCDefinitions::fgkClustersDataType );
95 AliHLTComponentDataType AliHLTTPCCAInputDataCompressorComponent::GetOutputDataType()
97 // see header file for class documentation
98 return AliHLTTPCCADefinitions::fgkCompressedInputDataType;
101 void AliHLTTPCCAInputDataCompressorComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
103 // define guess for the output data size
104 constBase = 200; // minimum size
105 inputMultiplier = 0.25; // size relative to input
108 AliHLTComponent* AliHLTTPCCAInputDataCompressorComponent::Spawn()
110 // see header file for class documentation
111 return new AliHLTTPCCAInputDataCompressorComponent;
117 int AliHLTTPCCAInputDataCompressorComponent::DoInit( int /*argc*/, const char** /*argv*/ )
119 // Configure the CA tracker component
121 fBenchmark.SetTimer(0,"total");
122 fBenchmark.SetTimer(1,"reco");
127 int AliHLTTPCCAInputDataCompressorComponent::DoDeinit()
129 // see header file for class documentation
135 int AliHLTTPCCAInputDataCompressorComponent::Reconfigure( const char* /*cdbEntry*/, const char* /*chainId*/ )
137 // Reconfigure the component from OCDB .
143 int AliHLTTPCCAInputDataCompressorComponent::DoEvent
145 const AliHLTComponentEventData& evtData,
146 const AliHLTComponentBlockData* blocks,
147 AliHLTComponentTriggerData& /*trigData*/,
148 AliHLTUInt8_t* outputPtr,
149 AliHLTUInt32_t& size,
150 vector<AliHLTComponentBlockData>& outputBlocks )
154 AliHLTUInt32_t maxBufferSize = size;
155 size = 0; // output size
157 if ( GetFirstInputBlock( kAliHLTDataTypeSOR ) || GetFirstInputBlock( kAliHLTDataTypeEOR ) ) {
161 fBenchmark.StartNewEvent();
164 // Preprocess the data for CA Slice Tracker
166 if ( evtData.fBlockCnt <= 0 ) {
167 HLTWarning( "no blocks in event" );
173 Int_t outTotalSize = 0;
174 Int_t minSlice = 100;
177 for ( unsigned long ndx = 0; ndx < evtData.fBlockCnt; ndx++ ) {
178 const AliHLTComponentBlockData* iter = blocks + ndx;
179 if ( iter->fDataType != AliHLTTPCDefinitions::fgkClustersDataType ) continue;
181 fBenchmark.AddInput(iter->fSize);
183 if( minSlice>AliHLTTPCDefinitions::GetMinSliceNr( *iter ) ) minSlice = AliHLTTPCDefinitions::GetMinSliceNr( *iter ) ;
184 if( maxSlice<AliHLTTPCDefinitions::GetMaxSliceNr( *iter ) ) maxSlice = AliHLTTPCDefinitions::GetMaxSliceNr( *iter ) ;
187 AliHLTUInt32_t dSize = 0;
191 ret = Compress( ( AliHLTTPCClusterData* )( iter->fPtr ), maxBufferSize - outTotalSize,
192 outputPtr+outTotalSize,
197 HLTWarning( "Output buffer size exceed (buffer size %d, current size %d)", maxBufferSize );
201 AliHLTComponentBlockData bd;
203 bd.fOffset = outTotalSize;
205 bd.fSpecification = iter->fSpecification;
206 bd.fDataType = GetOutputDataType();
207 outputBlocks.push_back( bd );
209 fBenchmark.AddOutput(bd.fSize);
216 if( maxSlice<0 ) minSlice = -1;
218 // Set log level to "Warning" for on-line system monitorin
220 if( minSlice!=maxSlice ) fBenchmark.SetName(Form("CAInputDataCompressor, slices %d-%d", minSlice, maxSlice));
221 else fBenchmark.SetName(Form("CAInputDataCompressor, slice %d", minSlice));
223 HLTInfo( fBenchmark.GetStatistics());
229 int AliHLTTPCCAInputDataCompressorComponent::Compress( AliHLTTPCClusterData* inputPtr,
230 AliHLTUInt32_t maxBufferSize,
231 AliHLTUInt8_t* outputPtr,
232 AliHLTUInt32_t& outputSize
235 // Preprocess the data for CA Slice Tracker
240 AliHLTTPCCACompressedCluster *outCluster = (AliHLTTPCCACompressedCluster*)( outputPtr );
241 AliHLTTPCCACompressedClusterRow *outRow = 0;
245 for ( unsigned int i = 0; i < inputPtr->fSpacePointCnt; i++ ){
246 AliHLTTPCSpacePointData *cluster = &( inputPtr->fSpacePoints[i] );
247 UInt_t patch = cluster->GetPatch();
248 UInt_t slice = cluster->GetSlice();
249 UInt_t row = cluster->fPadRow;
250 Double_t rowX = AliHLTTPCTransform::Row2X( row );
251 row = row - AliHLTTPCTransform::GetFirstRow( patch );
252 UShort_t id = (UShort_t)( (slice<<10) +(patch<<6) + row );
253 if( i==0 || id!= oldId ){
254 // fill new row header
255 outRow = (AliHLTTPCCACompressedClusterRow*) outCluster;
256 outCluster = outRow->fClusters;
257 outputSize+= ( ( AliHLTUInt8_t * )outCluster ) - (( AliHLTUInt8_t * )outRow);
258 if ( outputSize > maxBufferSize ){
263 outRow->fSlicePatchRowID = id;
264 outRow->fNClusters = 0;
266 //cout<<"Fill row: s "<<slice<<" p "<<patch<<" r "<<row<<" x "<<outRow->fX<<":"<<endl;
271 // get coordinates in [um]
273 Double_t x = (cluster->fX - rowX )*1.e4 + 32768.;
274 Double_t y = (cluster->fY)*1.e4 + 8388608.;
275 Double_t z = (cluster->fZ)*1.e4 + 8388608.;
277 // truncate if necessary
278 if( x<0 ) x = 0; else if( x > 0x0000FFFF ) x = 0x0000FFFF;
279 if( y<0 ) y = 0; else if( y > 0x00FFFFFF ) y = 0x00FFFFFF;
280 if( z<0 ) z = 0; else if( z > 0x00FFFFFF ) z = 0x00FFFFFF;
282 UInt_t ix0 = ( (UInt_t) x )&0x000000FF;
283 UInt_t ix1 = (( (UInt_t) x )&0x0000FF00 )>>8;
284 UInt_t iy = ( (UInt_t) y )&0x00FFFFFF;
285 UInt_t iz = ( (UInt_t) z )&0x00FFFFFF;
287 outputSize+= sizeof( AliHLTTPCCACompressedCluster );
288 if ( outputSize > maxBufferSize ){
293 outCluster->fP0 = (ix0<<24) + iy;
294 outCluster->fP1 = (ix1<<24) + iz;
296 outRow->fNClusters++;
297 //cout<<"clu "<<outRow->fNClusters-1<<": "<<cluster->fX<<" "<<cluster->fY<<" "<<cluster->fZ<<" "<<cluster->fID<<endl;