]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/tracking-ca/AliHLTTPCCAInputDataCompressorComponent.cxx
extra benchmarks are added
[u/mrichter/AliRoot.git] / HLT / TPCLib / tracking-ca / AliHLTTPCCAInputDataCompressorComponent.cxx
1 // **************************************************************************
2 // This file is property of and copyright by the ALICE HLT Project          *
3 // ALICE Experiment at CERN, All rights reserved.                           *
4 //                                                                          *
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.                              *
8 //                                                                          *
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.                    *
16 //                                                                          *
17 //***************************************************************************
18
19
20 ///////////////////////////////////////////////////////////////////////////////
21 //                                                                           //
22 // a TPC tracker processing component for the HLT based on CA by Ivan Kisel  //
23 //                                                                           //
24 ///////////////////////////////////////////////////////////////////////////////
25
26 #if __GNUC__>= 3
27 using namespace std;
28 #endif
29
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
38
39 const AliHLTComponentDataType AliHLTTPCCADefinitions::fgkCompressedInputDataType = AliHLTComponentDataTypeInitializer( "CAINPACK", kAliHLTDataOriginTPC );
40
41 /** ROOT macro for the implementation of ROOT specific class methods */
42 ClassImp( AliHLTTPCCAInputDataCompressorComponent )
43
44 AliHLTTPCCAInputDataCompressorComponent::AliHLTTPCCAInputDataCompressorComponent()
45   :
46   AliHLTProcessor(),
47   fBenchmark("CAInputCompressor")
48 {
49   // see header file for class documentation
50   // or
51   // refer to README to build package
52   // or
53   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
54 }
55
56 AliHLTTPCCAInputDataCompressorComponent::AliHLTTPCCAInputDataCompressorComponent( const AliHLTTPCCAInputDataCompressorComponent& )
57   :
58   AliHLTProcessor(),
59   fBenchmark("CAInputCompressor")
60 {
61   // see header file for class documentation
62   HLTFatal( "copy constructor untested" );
63 }
64
65 AliHLTTPCCAInputDataCompressorComponent& AliHLTTPCCAInputDataCompressorComponent::operator=( const AliHLTTPCCAInputDataCompressorComponent& )
66 {
67   // see header file for class documentation
68   HLTFatal( "assignment operator untested" );
69   return *this;
70 }
71
72 AliHLTTPCCAInputDataCompressorComponent::~AliHLTTPCCAInputDataCompressorComponent()
73 {
74   // see header file for class documentation  
75 }
76
77 //
78 // Public functions to implement AliHLTComponent's interface.
79 // These functions are required for the registration process
80 //
81
82 const char* AliHLTTPCCAInputDataCompressorComponent::GetComponentID()
83 {
84   // see header file for class documentation
85   return "TPCCAInputDataCompressor";
86 }
87
88 void AliHLTTPCCAInputDataCompressorComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list )
89 {
90   // see header file for class documentation
91   list.clear();
92   list.push_back( AliHLTTPCDefinitions::fgkClustersDataType );
93 }
94
95 AliHLTComponentDataType AliHLTTPCCAInputDataCompressorComponent::GetOutputDataType()
96 {
97   // see header file for class documentation
98   return AliHLTTPCCADefinitions::fgkCompressedInputDataType;
99 }
100
101 void AliHLTTPCCAInputDataCompressorComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
102 {
103   // define guess for the output data size
104   constBase = 200;       // minimum size
105   inputMultiplier = 0.25; // size relative to input
106 }
107
108 AliHLTComponent* AliHLTTPCCAInputDataCompressorComponent::Spawn()
109 {
110   // see header file for class documentation
111   return new AliHLTTPCCAInputDataCompressorComponent;
112 }
113
114
115
116
117 int AliHLTTPCCAInputDataCompressorComponent::DoInit( int /*argc*/, const char** /*argv*/ )
118 {
119   // Configure the CA tracker component
120   fBenchmark.Reset();
121   fBenchmark.SetTimer(0,"total");
122   fBenchmark.SetTimer(1,"reco");
123   return 0;
124 }
125
126
127 int AliHLTTPCCAInputDataCompressorComponent::DoDeinit()
128 {
129   // see header file for class documentation
130   return 0;
131 }
132
133
134
135 int AliHLTTPCCAInputDataCompressorComponent::Reconfigure( const char* /*cdbEntry*/, const char* /*chainId*/ )
136 {
137   // Reconfigure the component from OCDB .
138   return 0;
139 }
140
141
142
143 int AliHLTTPCCAInputDataCompressorComponent::DoEvent
144 (
145   const AliHLTComponentEventData& evtData,
146   const AliHLTComponentBlockData* blocks,
147   AliHLTComponentTriggerData& /*trigData*/,
148   AliHLTUInt8_t* outputPtr,
149   AliHLTUInt32_t& size,
150   vector<AliHLTComponentBlockData>& outputBlocks )
151 {
152   //* process event
153
154   AliHLTUInt32_t maxBufferSize = size;
155   size = 0; // output size
156
157   if ( GetFirstInputBlock( kAliHLTDataTypeSOR ) || GetFirstInputBlock( kAliHLTDataTypeEOR ) ) {
158     return 0;
159   }
160
161   fBenchmark.StartNewEvent();
162   fBenchmark.Start(0);
163
164   // Preprocess the data for CA Slice Tracker
165
166   if ( evtData.fBlockCnt <= 0 ) {
167     HLTWarning( "no blocks in event" );
168     return 0;
169   }
170
171   Int_t ret = 0;
172
173   Int_t outTotalSize = 0;
174   Int_t minSlice = 100;
175   Int_t maxSlice = -1;
176
177   for ( unsigned long ndx = 0; ndx < evtData.fBlockCnt; ndx++ ) {
178     const AliHLTComponentBlockData* iter = blocks + ndx;
179     if ( iter->fDataType != AliHLTTPCDefinitions::fgkClustersDataType ) continue;    
180
181     fBenchmark.AddInput(iter->fSize);
182
183     if( minSlice>AliHLTTPCDefinitions::GetMinSliceNr( *iter ) ) minSlice = AliHLTTPCDefinitions::GetMinSliceNr( *iter ) ;
184     if( maxSlice<AliHLTTPCDefinitions::GetMaxSliceNr( *iter ) ) maxSlice = AliHLTTPCDefinitions::GetMaxSliceNr( *iter ) ;
185       
186
187     AliHLTUInt32_t dSize = 0;
188
189     fBenchmark.Start(1);
190   
191     ret = Compress( ( AliHLTTPCClusterData* )( iter->fPtr ), maxBufferSize - outTotalSize,
192                     outputPtr+outTotalSize,
193                     dSize );
194     fBenchmark.Stop(1);
195
196     if ( ret!=0 ){
197       HLTWarning( "Output buffer size exceed (buffer size %d, current size %d)", maxBufferSize );     
198       break;
199     }    
200    
201     AliHLTComponentBlockData bd;
202     FillBlockData( bd );
203     bd.fOffset = outTotalSize;
204     bd.fSize = dSize;
205     bd.fSpecification = iter->fSpecification;
206     bd.fDataType = GetOutputDataType();
207     outputBlocks.push_back( bd );
208     outTotalSize+=dSize;      
209     fBenchmark.AddOutput(bd.fSize);
210   }
211
212   size = outTotalSize;
213   
214   fBenchmark.Stop(0);
215   
216   if( maxSlice<0 ) minSlice = -1;
217
218   // Set log level to "Warning" for on-line system monitorin  
219
220   if( minSlice!=maxSlice ) fBenchmark.SetName(Form("CAInputDataCompressor, slices %d-%d", minSlice, maxSlice));
221   else fBenchmark.SetName(Form("CAInputDataCompressor, slice %d", minSlice));
222  
223   HLTInfo( fBenchmark.GetStatistics());
224   return ret;
225 }
226
227
228
229 int AliHLTTPCCAInputDataCompressorComponent::Compress( AliHLTTPCClusterData* inputPtr,
230                                                        AliHLTUInt32_t maxBufferSize,
231                                                        AliHLTUInt8_t* outputPtr,
232                                                        AliHLTUInt32_t& outputSize
233                                                        )
234 {
235   // Preprocess the data for CA Slice Tracker
236
237   Int_t ret = 0;
238   outputSize = 0;
239
240   AliHLTTPCCACompressedCluster *outCluster = (AliHLTTPCCACompressedCluster*)( outputPtr );
241   AliHLTTPCCACompressedClusterRow *outRow = 0;
242
243   UShort_t oldId = 0;
244
245   for ( unsigned int i = 0; i < inputPtr->fSpacePointCnt; i++ ){ 
246     AliHLTTPCSpacePointData *cluster = &( inputPtr->fSpacePoints[i] );
247     UInt_t origId = cluster->fID;
248     UInt_t patch = (origId>>22)&0x7;
249     UInt_t slice = origId>>25;
250     UInt_t row = cluster->fPadRow;
251     Double_t rowX = AliHLTTPCTransform::Row2X( row );
252     row = row - AliHLTTPCTransform::GetFirstRow( patch );
253     UShort_t id = (UShort_t)( (slice<<10) +(patch<<6) + row );
254     if( i==0 || id!= oldId ){ 
255       // fill new row header    
256       outRow = (AliHLTTPCCACompressedClusterRow*) outCluster;
257       outCluster = outRow->fClusters;  
258       outputSize+= ( ( AliHLTUInt8_t * )outCluster ) -  (( AliHLTUInt8_t * )outRow);
259       if ( outputSize >  maxBufferSize ){
260         ret = -ENOSPC;
261         outputSize=0;
262         break;
263       }
264       outRow->fSlicePatchRowID = id;    
265       outRow->fNClusters = 0;
266       oldId = id;
267       //cout<<"Fill row: s "<<slice<<" p "<<patch<<" r "<<row<<" x "<<outRow->fX<<":"<<endl;
268     }
269     
270     // pack the cluster
271     {
272       // get coordinates in [um]
273         
274       Double_t x = (cluster->fX - rowX )*1.e4 + 32768.;
275       Double_t y = (cluster->fY)*1.e4 + 8388608.;
276       Double_t z = (cluster->fZ)*1.e4 + 8388608.;
277       
278       // truncate if necessary
279       if( x<0 ) x = 0; else if( x > 0x0000FFFF ) x = 0x0000FFFF;
280       if( y<0 ) y = 0; else if( y > 0x00FFFFFF ) y = 0x00FFFFFF;
281       if( z<0 ) z = 0; else if( z > 0x00FFFFFF ) z = 0x00FFFFFF;
282       
283       UInt_t ix0 =  ( (UInt_t) x )&0x000000FF;
284       UInt_t ix1 = (( (UInt_t) x )&0x0000FF00 )>>8;
285       UInt_t iy = ( (UInt_t) y )&0x00FFFFFF;
286       UInt_t iz = ( (UInt_t) z )&0x00FFFFFF;
287       
288       outputSize+= sizeof( AliHLTTPCCACompressedCluster );
289       if ( outputSize > maxBufferSize ){
290         outputSize = 0;
291         ret = -ENOSPC;
292         break;      
293       }
294       outCluster->fP0 = (ix0<<24) + iy;
295       outCluster->fP1 = (ix1<<24) + iz;      
296       outCluster++;
297       outRow->fNClusters++;
298       //cout<<"clu "<<outRow->fNClusters-1<<": "<<cluster->fX<<" "<<cluster->fY<<" "<<cluster->fZ<<" "<<cluster->fID<<endl;
299     }
300   }
301     
302   return ret;
303 }