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"
37 #include "TStopwatch.h"
40 const AliHLTComponentDataType AliHLTTPCCADefinitions::fgkCompressedInputDataType = AliHLTComponentDataTypeInitializer( "CAINPACK", kAliHLTDataOriginTPC );
42 /** ROOT macro for the implementation of ROOT specific class methods */
43 ClassImp( AliHLTTPCCAInputDataCompressorComponent )
45 AliHLTTPCCAInputDataCompressorComponent::AliHLTTPCCAInputDataCompressorComponent()
50 fTotalOutputSize( 0 ),
53 // see header file for class documentation
55 // refer to README to build package
57 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
60 AliHLTTPCCAInputDataCompressorComponent::AliHLTTPCCAInputDataCompressorComponent( const AliHLTTPCCAInputDataCompressorComponent& )
65 fTotalOutputSize( 0 ),
68 // see header file for class documentation
69 HLTFatal( "copy constructor untested" );
72 AliHLTTPCCAInputDataCompressorComponent& AliHLTTPCCAInputDataCompressorComponent::operator=( const AliHLTTPCCAInputDataCompressorComponent& )
74 // see header file for class documentation
75 HLTFatal( "assignment operator untested" );
79 AliHLTTPCCAInputDataCompressorComponent::~AliHLTTPCCAInputDataCompressorComponent()
81 // see header file for class documentation
85 // Public functions to implement AliHLTComponent's interface.
86 // These functions are required for the registration process
89 const char* AliHLTTPCCAInputDataCompressorComponent::GetComponentID()
91 // see header file for class documentation
92 return "TPCCAInputDataCompressor";
95 void AliHLTTPCCAInputDataCompressorComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list )
97 // see header file for class documentation
99 list.push_back( AliHLTTPCDefinitions::fgkClustersDataType );
102 AliHLTComponentDataType AliHLTTPCCAInputDataCompressorComponent::GetOutputDataType()
104 // see header file for class documentation
105 return AliHLTTPCCADefinitions::fgkCompressedInputDataType;
108 void AliHLTTPCCAInputDataCompressorComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
110 // define guess for the output data size
111 constBase = 200; // minimum size
112 inputMultiplier = 0.25; // size relative to input
115 AliHLTComponent* AliHLTTPCCAInputDataCompressorComponent::Spawn()
117 // see header file for class documentation
118 return new AliHLTTPCCAInputDataCompressorComponent;
124 int AliHLTTPCCAInputDataCompressorComponent::DoInit( int /*argc*/, const char** /*argv*/ )
126 // Configure the CA tracker component
129 fTotalOutputSize = 0;
135 int AliHLTTPCCAInputDataCompressorComponent::DoDeinit()
137 // see header file for class documentation
143 int AliHLTTPCCAInputDataCompressorComponent::Reconfigure( const char* /*cdbEntry*/, const char* /*chainId*/ )
145 // Reconfigure the component from OCDB .
151 int AliHLTTPCCAInputDataCompressorComponent::DoEvent
153 const AliHLTComponentEventData& evtData,
154 const AliHLTComponentBlockData* blocks,
155 AliHLTComponentTriggerData& /*trigData*/,
156 AliHLTUInt8_t* outputPtr,
157 AliHLTUInt32_t& size,
158 vector<AliHLTComponentBlockData>& outputBlocks )
162 AliHLTUInt32_t maxBufferSize = size;
163 size = 0; // output size
165 if ( GetFirstInputBlock( kAliHLTDataTypeSOR ) || GetFirstInputBlock( kAliHLTDataTypeEOR ) ) {
171 // Preprocess the data for CA Slice Tracker
173 if ( evtData.fBlockCnt <= 0 ) {
174 HLTWarning( "no blocks in event" );
180 Int_t inTotalSize = 0;
181 Int_t outTotalSize = 0;
182 Int_t minSlice = 100;
185 for ( unsigned long ndx = 0; ndx < evtData.fBlockCnt; ndx++ ) {
186 const AliHLTComponentBlockData* iter = blocks + ndx;
187 if ( iter->fDataType != AliHLTTPCDefinitions::fgkClustersDataType ) continue;
189 if( minSlice>AliHLTTPCDefinitions::GetMinSliceNr( *iter ) ) minSlice = AliHLTTPCDefinitions::GetMinSliceNr( *iter ) ;
190 if( maxSlice<AliHLTTPCDefinitions::GetMaxSliceNr( *iter ) ) maxSlice = AliHLTTPCDefinitions::GetMaxSliceNr( *iter ) ;
193 inTotalSize += iter->fSize;
195 AliHLTTPCClusterData* inPtrSP = ( AliHLTTPCClusterData* )( iter->fPtr );
197 AliHLTTPCCACompressedCluster *outCluster = (AliHLTTPCCACompressedCluster*)( outputPtr+outTotalSize );
198 AliHLTTPCCACompressedClusterRow *outRow = 0;
202 for ( unsigned int i = 0; i < inPtrSP->fSpacePointCnt; i++ ){
203 AliHLTTPCSpacePointData *cluster = &( inPtrSP->fSpacePoints[i] );
204 UInt_t origId = cluster->fID;
205 UInt_t patch = (origId>>22)&0x7;
206 UInt_t slice = origId>>25;
207 UInt_t row = cluster->fPadRow;
208 Double_t rowX = AliHLTTPCTransform::Row2X( row );
209 row = row - AliHLTTPCTransform::GetFirstRow( patch );
210 UShort_t id = (UShort_t)( (slice<<10) +(patch<<6) + row );
211 if( i==0 || id!= oldId ){
212 // fill new row header
213 outRow = (AliHLTTPCCACompressedClusterRow*) outCluster;
214 outCluster = outRow->fClusters;
215 dSize+= ( ( AliHLTUInt8_t * )outCluster ) - (( AliHLTUInt8_t * )outRow);
216 if ( outTotalSize + dSize > (int) maxBufferSize ) break;
217 outRow->fSlicePatchRowID = id;
218 outRow->fNClusters = 0;
220 //cout<<"Fill row: s "<<slice<<" p "<<patch<<" r "<<row<<" x "<<outRow->fX<<":"<<endl;
225 // get coordinates in [um]
227 Double_t x = (cluster->fX - rowX )*1.e4 + 32768.;
228 Double_t y = (cluster->fY)*1.e4 + 8388608.;
229 Double_t z = (cluster->fZ)*1.e4 + 8388608.;
231 // truncate if necessary
232 if( x<0 ) x = 0; else if( x > 0x0000FFFF ) x = 0x0000FFFF;
233 if( y<0 ) y = 0; else if( y > 0x00FFFFFF ) y = 0x00FFFFFF;
234 if( z<0 ) z = 0; else if( z > 0x00FFFFFF ) z = 0x00FFFFFF;
236 UInt_t ix0 = ( (UInt_t) x )&0x000000FF;
237 UInt_t ix1 = (( (UInt_t) x )&0x0000FF00 )>>8;
238 UInt_t iy = ( (UInt_t) y )&0x00FFFFFF;
239 UInt_t iz = ( (UInt_t) z )&0x00FFFFFF;
241 dSize+= sizeof( AliHLTTPCCACompressedCluster );
242 if ( outTotalSize + dSize > (int) maxBufferSize ) break;
243 outCluster->fP0 = (ix0<<24) + iy;
244 outCluster->fP1 = (ix1<<24) + iz;
246 outRow->fNClusters++;
247 //cout<<"clu "<<outRow->fNClusters-1<<": "<<cluster->fX<<" "<<cluster->fY<<" "<<cluster->fZ<<" "<<cluster->fID<<endl;
251 if ( outTotalSize + dSize > (int) maxBufferSize ) {
252 HLTWarning( "Output buffer size exceed (buffer size %d, current size %d)", maxBufferSize, outTotalSize+ dSize );
256 AliHLTComponentBlockData bd;
258 bd.fOffset = outTotalSize;
260 bd.fSpecification = iter->fSpecification;
261 bd.fDataType = GetOutputDataType();
262 outputBlocks.push_back( bd );
270 fTotalTime += timer.RealTime();
271 fTotalInputSize+= inTotalSize;
272 fTotalOutputSize+= outTotalSize;
275 if( maxSlice<0 ) minSlice = -1;
276 Int_t hz = ( int ) ( fTotalTime > 1.e-10 ? fNEvents / fTotalTime : 100000 );
278 if( fTotalOutputSize>0 ) ratio = (Float_t ) (fTotalInputSize/fTotalOutputSize);
280 // Set log level to "Warning" for on-line system monitoring
282 HLTInfo( "CAInputDataCompressor, slices %d-%d: speed %d Hz, ratio %f, %d events", minSlice, maxSlice, hz, ratio, fNEvents );