]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/AliHLTTPCClusterFinderComponent.cxx
changes according to coding conventions
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCClusterFinderComponent.cxx
1 // $Id$
2
3 /**************************************************************************
4  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
5  *                                                                        *
6  * Authors: Matthias Richter <Matthias.Richter@ift.uib.no>                *
7  *          Timm Steinbeck <timm@kip.uni-heidelberg.de>                   *
8  *          Jochen Thaeder <thaeder@kip.uni-heidelberg.de>                *
9  *          for The ALICE Off-line Project.                               *
10  *                                                                        *
11  * Permission to use, copy, modify and distribute this software and its   *
12  * documentation strictly for non-commercial purposes is hereby granted   *
13  * without fee, provided that the above copyright notice appears in all   *
14  * copies and that both the copyright notice and this permission notice   *
15  * appear in the supporting documentation. The authors make no claims     *
16  * about the suitability of this software for any purpose. It is          *
17  * provided "as is" without express or implied warranty.                  *
18  **************************************************************************/
19
20 ///////////////////////////////////////////////////////////////////////////////
21 //                                                                           //
22 // a TPC cluster finder processing component for the HLT                     //
23 // useable for packed data or unpacked data                                  //
24 //                                                                           //
25 ///////////////////////////////////////////////////////////////////////////////
26
27
28 #if __GNUC__>= 3
29 using namespace std;
30 #endif
31 #include "AliHLTTPCLogging.h"
32 #include "AliHLTTPCClusterFinderComponent.h"
33 #include "AliHLTTPCDigitReaderPacked.h"
34 #include "AliHLTTPCDigitReaderUnpacked.h"
35 #include "AliHLTTPCDigitReaderRaw.h"
36 #include "AliHLTTPCClusterFinder.h"
37 #include "AliHLTTPCSpacePointData.h"
38 #include "AliHLTTPCRawDataFormat.h"
39 #include "AliHLTTPCClusterDataFormat.h"
40 #include "AliHLTTPCTransform.h"
41 #include <stdlib.h>
42 #include <errno.h>
43
44 // this is a global object used for automatic component registration, do not use this
45 AliHLTTPCClusterFinderComponent gAliHLTTPCClusterFinderComponentPacked(true);
46 AliHLTTPCClusterFinderComponent gAliHLTTPCClusterFinderComponentUnpacked(false);
47
48 ClassImp(AliHLTTPCClusterFinderComponent)
49
50 AliHLTTPCClusterFinderComponent::AliHLTTPCClusterFinderComponent(bool packed)
51   :
52   // use fPackedSwitch = true for packed inputtype "gkDDLPackedRawDataType"
53   // use fPackedSwitch = false for unpacked inputtype "gkUnpackedRawDataType"
54   fPackedSwitch(packed),
55
56   fClusterFinder(NULL),
57   fReader(NULL),
58   fClusterDeconv(true),
59   fXYClusterError(-1),
60   fZClusterError(-1)
61 {
62 }
63
64 AliHLTTPCClusterFinderComponent::AliHLTTPCClusterFinderComponent(const AliHLTTPCClusterFinderComponent&)
65   :
66   fPackedSwitch(0),
67   fClusterFinder(NULL),
68   fReader(NULL),
69   fClusterDeconv(true),
70   fXYClusterError(-1),
71   fZClusterError(-1)
72 {
73   HLTFatal("copy constructor untested");
74 }
75
76 AliHLTTPCClusterFinderComponent& AliHLTTPCClusterFinderComponent::operator=(const AliHLTTPCClusterFinderComponent&)
77
78   HLTFatal("assignment operator untested");
79   return *this;
80 }
81
82 AliHLTTPCClusterFinderComponent::~AliHLTTPCClusterFinderComponent()
83     {
84     }
85
86 // Public functions to implement AliHLTComponent's interface.
87 // These functions are required for the registration process
88
89 const char* AliHLTTPCClusterFinderComponent::GetComponentID()
90     {
91       if (fPackedSwitch) return "TPCClusterFinderPacked";
92       else return "TPCClusterFinderUnpacked";
93     }
94
95 void AliHLTTPCClusterFinderComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
96     {
97     list.clear(); 
98     if (fPackedSwitch) list.push_back( AliHLTTPCDefinitions::gkDDLPackedRawDataType );
99     else list.push_back( AliHLTTPCDefinitions::gkUnpackedRawDataType );
100    
101     }
102
103 AliHLTComponentDataType AliHLTTPCClusterFinderComponent::GetOutputDataType()
104     {
105     return AliHLTTPCDefinitions::gkClustersDataType;
106     }
107
108 void AliHLTTPCClusterFinderComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
109     {
110     // XXX TODO: Find more realistic values.  
111     constBase = 0;
112     if (fPackedSwitch)  inputMultiplier = (6 * 0.4);
113     else  inputMultiplier = 0.4;
114     }
115
116 AliHLTComponent* AliHLTTPCClusterFinderComponent::Spawn()
117     {
118     return new AliHLTTPCClusterFinderComponent(fPackedSwitch);
119     }
120         
121 int AliHLTTPCClusterFinderComponent::DoInit( int argc, const char** argv )
122     {
123     if ( fClusterFinder )
124         return EINPROGRESS;
125
126     fClusterFinder = new AliHLTTPCClusterFinder();
127
128     Int_t rawreadermode =  -1;
129     Int_t sigthresh = -1;
130     Float_t occulimit = 1.0;
131
132     // Data Format version numbers:
133     // 0: RCU Data format as delivered during TPC commissioning, pads/padrows are sorted, RCU trailer is one 32 bit word.
134     // 1: As 0, but pads/padrows are delivered "as is", without sorting
135     // 2: As 0, but RCU trailer is 3 32 bit words.
136     // 3: As 1, but RCU trailer is 3 32 bit words.
137     // -1: use offline raw reader
138
139     Int_t i = 0;
140     Char_t* cpErr;
141
142     while ( i < argc ) {      
143
144       // -- raw reader mode option
145       if ( !strcmp( argv[i], "rawreadermode" ) ) {
146         if ( argc <= i+1 ) {
147           Logging( kHLTLogError, "HLT::TPCClusterFinder::DoInit", "Missing rawreadermode", "Raw Reader Mode not specified" );
148           return ENOTSUP;
149         }
150
151         // Decodes the rawreader mode: either number or string and returns the rawreadermode
152         // -1 on failure, -2 for offline
153         rawreadermode = AliHLTTPCDigitReaderRaw::DecodeMode( argv[i+1] );
154
155         if (rawreadermode == -1 ) {
156           Logging( kHLTLogError, "HLT::TPCClusterFinder::DoInit", "Missing rawreadermode", "Cannot convert rawreadermode specifier '%s'.", argv[i+1] );
157           return EINVAL;
158         }
159
160         i += 2;
161         continue;
162       }
163
164       // -- pp run option
165       if ( !strcmp( argv[i], "pp-run" ) ) {
166         fClusterDeconv = false;
167         i++;
168         continue;
169       }
170
171       // -- zero suppression threshold
172       if ( !strcmp( argv[i], "adc-threshold" ) ) {
173         sigthresh = strtoul( argv[i+1], &cpErr ,0);
174         if ( *cpErr ) {
175           HLTError("Cannot convert threshold specifier '%s'.", argv[i+1]);
176           return EINVAL;
177         }
178         i+=2;
179         continue;
180       }
181
182       // -- pad occupancy limit
183       if ( !strcmp( argv[i], "occupancy-limit" ) ) {
184         occulimit = strtof( argv[i+1], &cpErr);
185         if ( *cpErr ) {
186           HLTError("Cannot convert occupancy specifier '%s'.", argv[i+1]);
187           return EINVAL;
188         }
189         i+=2;
190         continue;
191       }
192
193       Logging(kHLTLogError, "HLT::TPCClusterFinder::DoInit", "Unknown Option", "Unknown option '%s'", argv[i] );
194       return EINVAL;
195
196     }
197
198     // Choose reader
199
200     if (fPackedSwitch) { 
201       if (rawreadermode == -2) {
202 #if defined(HAVE_ALIRAWDATA) && defined(HAVE_ALITPCRAWSTREAM_H)
203         fReader = new AliHLTTPCDigitReaderPacked();
204         fClusterFinder->SetReader(fReader);
205 #else // ! defined(HAVE_ALIRAWDATA) && defined(HAVE_ALITPCRAWSTREAM_H)
206         HLTFatal("DigitReaderPacked not available - check your build");
207         return -ENODEV;
208 #endif //  defined(HAVE_ALIRAWDATA) && defined(HAVE_ALITPCRAWSTREAM_H)
209       } else {
210 #if defined(HAVE_TPC_MAPPING)
211         fReader = new AliHLTTPCDigitReaderRaw(rawreadermode);
212         fClusterFinder->SetReader(fReader);
213 #else //! defined(HAVE_TPC_MAPPING)
214       HLTFatal("DigitReaderRaw not available - check your build");
215       return -ENODEV;
216 #endif //defined(HAVE_TPC_MAPPING)
217       }
218     }
219     else {
220       fReader = new AliHLTTPCDigitReaderUnpacked();
221       fClusterFinder->SetReader(fReader);
222     }
223
224     // if pp-run use occupancy limit else set to 1. ==> use all 
225     if ( !fClusterDeconv )
226       fClusterFinder->SetOccupancyLimit(occulimit);
227     else 
228       fClusterFinder->SetOccupancyLimit(1.0);
229       
230     // Variables to setup the Clusterfinder
231     // TODO: this sounds strange and has to be verified; is the cluster finder not working when
232     // fClusterDeconv = false ?
233     fClusterDeconv = true;
234     fXYClusterError = -1;
235     fZClusterError = -1;
236
237  
238     fClusterFinder->SetDeconv( fClusterDeconv );
239     fClusterFinder->SetXYError( fXYClusterError );
240     fClusterFinder->SetZError( fZClusterError );
241     if ( (fXYClusterError>0) && (fZClusterError>0) )
242       fClusterFinder->SetCalcErr( false );
243     fClusterFinder->SetSignalThreshold(sigthresh);
244     
245     return 0;
246     }
247
248 int AliHLTTPCClusterFinderComponent::DoDeinit()
249     {
250
251     if ( fClusterFinder )
252         delete fClusterFinder;
253     fClusterFinder = NULL;
254  
255     if ( fReader )
256         delete fReader;
257     fReader = NULL;
258     
259     return 0;
260     }
261
262 int AliHLTTPCClusterFinderComponent::DoEvent( const AliHLTComponentEventData& evtData, 
263                                               const AliHLTComponentBlockData* blocks, 
264                                               AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr, 
265                                               AliHLTUInt32_t& size, 
266                                               vector<AliHLTComponentBlockData>& outputBlocks )
267     {
268
269     //  == init iter (pointer to datablock)
270     const AliHLTComponentBlockData* iter = NULL;
271     unsigned long ndx;
272
273     //  == OUTdatatype pointer
274     AliHLTTPCClusterData* outPtr;
275
276     AliHLTUInt8_t* outBPtr;
277     UInt_t offset, mysize, nSize, tSize = 0;
278
279     outBPtr = outputPtr;
280     outPtr = (AliHLTTPCClusterData*)outBPtr;
281
282     Int_t slice, patch, row[2];
283     unsigned long maxPoints, realPoints = 0;
284
285     for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
286         {
287         iter = blocks+ndx;
288         mysize = 0;
289         offset = tSize;
290
291
292         if (fPackedSwitch) {    
293           char tmp1[14], tmp2[14];
294           DataType2Text( iter->fDataType, tmp1 );
295           DataType2Text( AliHLTTPCDefinitions::gkDDLPackedRawDataType, tmp2 );
296           Logging( kHLTLogDebug, "HLT::TPCClusterFinder::DoEvent", "Event received", 
297                    "Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
298                    evtData.fEventID, evtData.fEventID, tmp1, tmp2 );
299
300           if ( iter->fDataType != AliHLTTPCDefinitions::gkDDLPackedRawDataType ) continue;
301
302         }
303         else {
304           char tmp1[14], tmp2[14];
305           DataType2Text( iter->fDataType, tmp1 );
306           DataType2Text( AliHLTTPCDefinitions::gkUnpackedRawDataType, tmp2 );
307           Logging( kHLTLogDebug, "HLT::TPCClusterFinder::DoEvent", "Event received", 
308                    "Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
309                    evtData.fEventID, evtData.fEventID, tmp1, tmp2 );
310
311           if ( iter->fDataType != AliHLTTPCDefinitions::gkUnpackedRawDataType ) continue;
312
313         }
314         
315         slice = AliHLTTPCDefinitions::GetMinSliceNr( *iter );
316         patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
317         row[0] = AliHLTTPCTransform::GetFirstRow( patch );
318         row[1] = AliHLTTPCTransform::GetLastRow( patch );
319         
320         Logging( kHLTLogDebug, "HLT::TPCClusterFinder::DoEvent", "Input Spacepoints", 
321                  "Input: Number of spacepoints: %lu Slice/Patch/RowMin/RowMax: %d/%d/%d/%d.",
322                  realPoints, slice, patch, row[0], row[1] );
323         
324         outPtr = (AliHLTTPCClusterData*)outBPtr;
325
326         maxPoints = (size-tSize-sizeof(AliHLTTPCClusterData))/sizeof(AliHLTTPCSpacePointData);
327
328         fClusterFinder->InitSlice( slice, patch, row[0], row[1], maxPoints );
329         fClusterFinder->SetOutputArray( outPtr->fSpacePoints );
330         fClusterFinder->Read(iter->fPtr, iter->fSize );
331         fClusterFinder->ProcessDigits();
332         realPoints = fClusterFinder->GetNumberOfClusters();
333         
334         Logging( kHLTLogDebug, "HLT::TPCClusterFinder::DoEvent", "Spacepoints", 
335                  "Number of spacepoints found: %lu.", realPoints );
336         
337         outPtr->fSpacePointCnt = realPoints;
338         nSize = sizeof(AliHLTTPCSpacePointData)*realPoints;
339         mysize += nSize+sizeof(AliHLTTPCClusterData);
340         
341         Logging( kHLTLogDebug, "HLT::TPCClusterFinder::DoEvent", "Input Spacepoints", 
342                  "Number of spacepoints: %lu Slice/Patch/RowMin/RowMax: %d/%d/%d/%d.",
343                  realPoints, slice, patch, row[0], row[1] );
344         AliHLTComponentBlockData bd;
345         FillBlockData( bd );
346         bd.fOffset = offset;
347         bd.fSize = mysize;
348         bd.fSpecification = iter->fSpecification;
349         //AliHLTSubEventDescriptor::FillBlockAttributes( bd.fAttributes );
350         outputBlocks.push_back( bd );
351         
352         tSize += mysize;
353         outBPtr += mysize;
354         outPtr = (AliHLTTPCClusterData*)outBPtr;
355         
356         if ( tSize > size )
357             {
358             Logging( kHLTLogFatal, "HLT::TPCClusterFinder::DoEvent", "Too much data", 
359                      "Data written over allowed buffer. Amount written: %lu, allowed amount: %lu.",
360                      tSize, size );
361             return EMSGSIZE;
362             }
363         }
364     
365     size = tSize;
366
367     return 0;
368     }
369
370