]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/AliHLTTPCClusterFinderComponent.cxx
Getting rid of trivial warnings.
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCClusterFinderComponent.cxx
1 // $Id$
2
3 /**************************************************************************
4  * This file is property of and copyright by the ALICE HLT Project        * 
5  * ALICE Experiment at CERN, All rights reserved.                         *
6  *                                                                        *
7  * Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no>        *
8  *                  Timm Steinbeck <timm@kip.uni-heidelberg.de>           *
9  *                  Jochen Thaeder <thaeder@kip.uni-heidelberg.de>        *
10  *                  for The ALICE HLT Project.                            *
11  *                                                                        *
12  * Permission to use, copy, modify and distribute this software and its   *
13  * documentation strictly for non-commercial purposes is hereby granted   *
14  * without fee, provided that the above copyright notice appears in all   *
15  * copies and that both the copyright notice and this permission notice   *
16  * appear in the supporting documentation. The authors make no claims     *
17  * about the suitability of this software for any purpose. It is          *
18  * provided "as is" without express or implied warranty.                  *
19  **************************************************************************/
20
21 /** @file   AliHLTTPCClusterFinderComponent.cxx
22     @author Timm Steinbeck, Matthias Richter, Jochen Thaeder, Kenneth Aamodt
23     @date   
24     @brief  The TPC cluster finder processing component
25 */
26
27 // see header file for class documentation                                   //
28 // or                                                                        //
29 // refer to README to build package                                          //
30 // or                                                                        //
31 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt                          //
32
33 #if __GNUC__>= 3
34 using namespace std;
35 #endif
36 #include "AliHLTTPCClusterFinderComponent.h"
37 #include "AliHLTTPCDigitReaderPacked.h"
38 #include "AliHLTTPCDigitReaderUnpacked.h"
39 #include "AliHLTTPCDigitReaderRaw.h"
40 #include "AliHLTTPCClusterFinder.h"
41 #include "AliHLTTPCSpacePointData.h"
42 #include "AliHLTTPCClusterDataFormat.h"
43 #include "AliHLTTPCTransform.h"
44 #include "AliHLTTPCClusters.h"
45 #include "AliHLTTPCDefinitions.h"
46 #include <cstdlib>
47 #include <cerrno>
48 #include "TString.h"
49 #include <sys/time.h>
50
51 // this is a global object used for automatic component registration, do not use this
52 // use fPackedSwitch = true for packed inputtype "gkDDLPackedRawDataType"
53 // use fPackedSwitch = false for unpacked inputtype "gkUnpackedRawDataType"
54 AliHLTTPCClusterFinderComponent gAliHLTTPCClusterFinderComponentPacked(true);
55 AliHLTTPCClusterFinderComponent gAliHLTTPCClusterFinderComponentUnpacked(false);
56
57 ClassImp(AliHLTTPCClusterFinderComponent)
58
59 AliHLTTPCClusterFinderComponent::AliHLTTPCClusterFinderComponent(bool packed)
60   :
61   fClusterFinder(NULL),
62   fReader(NULL),
63   fClusterDeconv(true),
64   fXYClusterError(-1),
65   fZClusterError(-1),
66   fPackedSwitch(packed),
67   fUnsorted(0),
68   fPatch(0),
69   fPadArray(NULL)
70 {
71   // see header file for class documentation
72   // or
73   // refer to README to build package
74   // or
75   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
76 }
77
78 AliHLTTPCClusterFinderComponent::~AliHLTTPCClusterFinderComponent()
79 {
80   // see header file for class documentation
81 }
82
83 // Public functions to implement AliHLTComponent's interface.
84 // These functions are required for the registration process
85
86 const char* AliHLTTPCClusterFinderComponent::GetComponentID()
87 {
88   // see header file for class documentation
89   if (fPackedSwitch) return "TPCClusterFinderPacked";
90   else return "TPCClusterFinderUnpacked";
91 }
92
93 void AliHLTTPCClusterFinderComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
94 {
95   // see header file for class documentation
96   list.clear(); 
97   if (fPackedSwitch) list.push_back( AliHLTTPCDefinitions::fgkDDLPackedRawDataType );
98   else list.push_back( AliHLTTPCDefinitions::fgkUnpackedRawDataType );
99    
100 }
101
102 AliHLTComponentDataType AliHLTTPCClusterFinderComponent::GetOutputDataType()
103 {
104   // see header file for class documentation
105   return AliHLTTPCDefinitions::fgkClustersDataType;
106 }
107
108 void AliHLTTPCClusterFinderComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
109 {
110   // see header file for class documentation
111   // XXX TODO: Find more realistic values.  
112   constBase = 0;
113   if (fPackedSwitch)  inputMultiplier = (6 * 0.4);
114   else  inputMultiplier = 0.4;
115 }
116
117 AliHLTComponent* AliHLTTPCClusterFinderComponent::Spawn()
118 {
119   // see header file for class documentation
120   return new AliHLTTPCClusterFinderComponent(fPackedSwitch);
121 }
122         
123 int AliHLTTPCClusterFinderComponent::DoInit( int argc, const char** argv )
124 {
125   // see header file for class documentation
126   if ( fClusterFinder )
127     return EINPROGRESS;
128
129   fClusterFinder = new AliHLTTPCClusterFinder();
130
131   Int_t rawreadermode =  -1;
132   Int_t sigthresh = -1;
133   Float_t occulimit = 1.0;
134   Int_t oldRCUFormat=0;
135   // Data Format version numbers:
136   // 0: RCU Data format as delivered during TPC commissioning, pads/padrows are sorted, RCU trailer is one 32 bit word.
137   // 1: As 0, but pads/padrows are delivered "as is", without sorting
138   // 2: As 0, but RCU trailer is 3 32 bit words.
139   // 3: As 1, but RCU trailer is 3 32 bit words.
140   // -1: use offline raw reader
141
142   Int_t i = 0;
143   Char_t* cpErr;
144
145   while ( i < argc ) {      
146
147     // -- raw reader mode option
148     if ( !strcmp( argv[i], "rawreadermode" ) ) {
149       if ( argc <= i+1 ) {
150         Logging( kHLTLogError, "HLT::TPCClusterFinder::DoInit", "Missing rawreadermode", "Raw Reader Mode not specified" );
151         return ENOTSUP;
152       }
153
154       // Decodes the rawreader mode: either number or string and returns the rawreadermode
155       // -1 on failure, -2 for offline
156       rawreadermode = AliHLTTPCDigitReaderRaw::DecodeMode( argv[i+1] );
157
158       if (rawreadermode == -1 ) {
159         Logging( kHLTLogError, "HLT::TPCClusterFinder::DoInit", "Missing rawreadermode", "Cannot convert rawreadermode specifier '%s'.", argv[i+1] );
160         return EINVAL;
161       }
162
163       i += 2;
164       continue;
165     }
166
167     // -- pp run option
168     if ( !strcmp( argv[i], "pp-run" ) ) {
169       fClusterDeconv = false;
170       i++;
171       continue;
172     }
173
174     // -- zero suppression threshold
175     if ( !strcmp( argv[i], "adc-threshold" ) ) {
176       sigthresh = strtoul( argv[i+1], &cpErr ,0);
177       if ( *cpErr ) {
178         HLTError("Cannot convert threshold specifier '%s'.", argv[i+1]);
179         return EINVAL;
180       }
181       i+=2;
182       continue;
183     }
184
185     // -- pad occupancy limit
186     if ( !strcmp( argv[i], "occupancy-limit" ) ) {
187       occulimit = strtod( argv[i+1], &cpErr);
188       if ( *cpErr ) {
189         HLTError("Cannot convert occupancy specifier '%s'.", argv[i+1]);
190         return EINVAL;
191       }
192       i+=2;
193       continue;
194     }
195
196     // -- number of timebins (default 1024)
197     if ( !strcmp( argv[i], "timebins" ) ) {
198       TString parameter(argv[i+1]);
199       parameter.Remove(TString::kLeading, ' '); // remove all blanks
200       if (parameter.IsDigit()) {
201         AliHLTTPCTransform::SetNTimeBins(parameter.Atoi());
202         HLTInfo("number of timebins set to %d, zbin=%f", AliHLTTPCTransform::GetNTimeBins(), AliHLTTPCTransform::GetZWidth());
203       } else {
204         HLTError("Cannot timebin specifier '%s'.", argv[i+1]);
205         return EINVAL;
206       }
207       i+=2;
208       continue;
209     }
210
211     // -- checking for rcu format
212     if ( !strcmp( argv[i], "oldrcuformat" ) ) {
213       oldRCUFormat = strtoul( argv[i+1], &cpErr ,0);
214       if ( *cpErr ){
215         HLTError("Cannot convert oldrcuformat specifier '%s'. Should  be 0(off) or 1(on), must be integer", argv[i+1]);
216         return EINVAL;
217       }
218       i+=2;
219       continue;
220     }
221       
222     // -- checking for unsorted clusterfinding
223     if ( !strcmp( argv[i], "unsorted" ) ) {
224       fUnsorted = strtoul( argv[i+1], &cpErr ,0);
225       if ( *cpErr ){
226         HLTError("Cannot convert unsorted specifier '%s'. Should  be 0(off) or 1(on), must be integer", argv[i+1]);
227         return EINVAL;
228       }
229       i+=2;
230       continue;
231     }
232       
233     // -- checking for unsorted clusterfinding
234     if ( !strcmp( argv[i], "patch" ) ) {
235       fPatch = strtoul( argv[i+1], &cpErr ,0);
236       if ( *cpErr ){
237         HLTError("Cannot convert patch specifier '%s'. Should  be between 0 and 5, must be integer", argv[i+1]);
238         return EINVAL;
239       }
240       i+=2;
241       continue;
242     }
243
244     Logging(kHLTLogError, "HLT::TPCClusterFinder::DoInit", "Unknown Option", "Unknown option '%s'", argv[i] );
245     return EINVAL;
246
247   }
248
249   // Choose reader
250
251   if (fPackedSwitch) { 
252     if (rawreadermode == -2) {
253 #if defined(HAVE_ALIRAWDATA) && defined(HAVE_ALITPCRAWSTREAM_H)
254       fReader = new AliHLTTPCDigitReaderPacked();
255       if(oldRCUFormat==1){
256         fReader->SetOldRCUFormat(kTRUE);
257       }
258       else if(oldRCUFormat!=0){
259         HLTWarning("Wrong oldrcuformat specifier %d; oldrcuformat set to default(kFALSE)",oldRCUFormat);
260       }
261       if(fUnsorted){
262         fReader->SetUnsorted(kTRUE);
263       }
264       fClusterFinder->SetReader(fReader);
265 #else // ! defined(HAVE_ALIRAWDATA) && defined(HAVE_ALITPCRAWSTREAM_H)
266       HLTFatal("DigitReaderPacked not available - check your build");
267       return -ENODEV;
268 #endif //  defined(HAVE_ALIRAWDATA) && defined(HAVE_ALITPCRAWSTREAM_H)
269     } else {
270 #if defined(HAVE_TPC_MAPPING)
271       fReader = new AliHLTTPCDigitReaderRaw(rawreadermode);
272       fClusterFinder->SetReader(fReader);
273 #else //! defined(HAVE_TPC_MAPPING)
274       HLTFatal("DigitReaderRaw not available - check your build");
275       return -ENODEV;
276 #endif //defined(HAVE_TPC_MAPPING)
277     }
278   }
279   else {
280     fReader = new AliHLTTPCDigitReaderUnpacked();
281     fClusterFinder->SetReader(fReader);
282   }
283
284   // if pp-run use occupancy limit else set to 1. ==> use all 
285   if ( !fClusterDeconv )
286     fClusterFinder->SetOccupancyLimit(occulimit);
287   else 
288     fClusterFinder->SetOccupancyLimit(1.0);
289       
290   // Variables to setup the Clusterfinder
291   // TODO: this sounds strange and has to be verified; is the cluster finder not working when
292   // fClusterDeconv = false ?
293   fClusterDeconv = true;
294   fXYClusterError = -1;
295   fZClusterError = -1;
296
297  
298   fClusterFinder->SetDeconv( fClusterDeconv );
299   fClusterFinder->SetXYError( fXYClusterError );
300   fClusterFinder->SetZError( fZClusterError );
301   if ( (fXYClusterError>0) && (fZClusterError>0) )
302     fClusterFinder->SetCalcErr( false );
303   fClusterFinder->SetSignalThreshold(sigthresh);
304     
305   if(fUnsorted&&fPatch>-1&&fPatch<6){
306     fPadArray = new AliHLTTPCPadArray(fPatch);
307     fPadArray->InitializeVector();
308   }
309
310   return 0;
311 }
312
313 int AliHLTTPCClusterFinderComponent::DoDeinit()
314 {
315   // see header file for class documentation
316
317   if ( fClusterFinder )
318     delete fClusterFinder;
319   fClusterFinder = NULL;
320  
321   if ( fReader )
322     delete fReader;
323   fReader = NULL;
324     
325   return 0;
326 }
327
328 int AliHLTTPCClusterFinderComponent::DoEvent( const AliHLTComponentEventData& evtData, 
329                                               const AliHLTComponentBlockData* blocks, 
330                                               AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr, 
331                                               AliHLTUInt32_t& size, 
332                                               vector<AliHLTComponentBlockData>& outputBlocks )
333 {
334   // see header file for class documentation
335
336   //  == init iter (pointer to datablock)
337   const AliHLTComponentBlockData* iter = NULL;
338   unsigned long ndx;
339
340   //  == OUTdatatype pointer
341   AliHLTTPCClusterData* outPtr;
342
343   AliHLTUInt8_t* outBPtr;
344   UInt_t offset, mysize, nSize, tSize = 0;
345
346   outBPtr = outputPtr;
347   outPtr = (AliHLTTPCClusterData*)outBPtr;
348
349   Int_t slice, patch, row[2];
350   unsigned long maxPoints, realPoints = 0;
351
352   for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
353     {
354       iter = blocks+ndx;
355       mysize = 0;
356       offset = tSize;
357
358
359       if (fPackedSwitch) {      
360         char tmp1[14], tmp2[14];
361         DataType2Text( iter->fDataType, tmp1 );
362         DataType2Text( AliHLTTPCDefinitions::fgkDDLPackedRawDataType, tmp2 );
363         Logging( kHLTLogDebug, "HLT::TPCClusterFinder::DoEvent", "Event received", 
364                  "Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
365                  evtData.fEventID, evtData.fEventID, tmp1, tmp2 );
366
367         if ( iter->fDataType != AliHLTTPCDefinitions::fgkDDLPackedRawDataType ) continue;
368
369       }
370       else {
371         char tmp1[14], tmp2[14];
372         DataType2Text( iter->fDataType, tmp1 );
373         DataType2Text( AliHLTTPCDefinitions::fgkUnpackedRawDataType, tmp2 );
374         Logging( kHLTLogDebug, "HLT::TPCClusterFinder::DoEvent", "Event received", 
375                  "Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
376                  evtData.fEventID, evtData.fEventID, tmp1, tmp2 );
377
378         if ( iter->fDataType != AliHLTTPCDefinitions::fgkUnpackedRawDataType ) continue;
379
380       }
381         
382       slice = AliHLTTPCDefinitions::GetMinSliceNr( *iter );
383       patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
384       row[0] = AliHLTTPCTransform::GetFirstRow( patch );
385       row[1] = AliHLTTPCTransform::GetLastRow( patch );
386         
387       outPtr = (AliHLTTPCClusterData*)outBPtr;
388
389 #ifndef KENNETH
390       maxPoints = (size-tSize-sizeof(AliHLTTPCClusterData))/sizeof(AliHLTTPCSpacePointData);
391 #else
392       maxPoints = (size-tSize-sizeof(AliHLTTPCClusters))/sizeof(AliHLTTPCSpacePointData);
393 #endif 
394
395       fClusterFinder->InitSlice( slice, patch, row[0], row[1], maxPoints );
396       fClusterFinder->SetOutputArray( (AliHLTTPCSpacePointData*)outPtr->fSpacePoints );
397         
398       if(fUnsorted){
399
400
401         fClusterFinder->SetPadArray(fPadArray);
402           
403         double totalT=0;
404         struct timeval startT, endT;
405         gettimeofday( &startT, NULL );
406
407         fClusterFinder->ReadDataUnsorted(iter->fPtr, iter->fSize );
408
409         gettimeofday( &endT, NULL );
410         unsigned long long dt;
411         dt = endT.tv_sec-startT.tv_sec;
412         dt *= 1000000ULL;
413         dt += endT.tv_usec-startT.tv_usec;
414         double dtd = ((double)dt);
415         totalT += dtd;
416         //        dtd = dtd / (double)eventIterations;
417         //        if ( iterations<=1 )
418         cout<<endl;
419         printf( "Time needed to read data: %f microsec. / %f millisec. / %f s\n", 
420                 dtd, dtd/1000.0, dtd/1000000.0 );
421           
422         cout<<endl;
423         fClusterFinder->FindClusters();
424       }
425       else{
426         fClusterFinder->Read(iter->fPtr, iter->fSize );
427         fClusterFinder->ProcessDigits();
428       }
429       realPoints = fClusterFinder->GetNumberOfClusters();
430         
431       outPtr->fSpacePointCnt = realPoints;
432       nSize = sizeof(AliHLTTPCSpacePointData)*realPoints;
433 #ifndef KENNETH
434       mysize += nSize+sizeof(AliHLTTPCClusterData);
435 #else
436       mysize += nSize+sizeof(AliHLTTPCClusters);
437 #endif 
438
439       Logging( kHLTLogDebug, "HLT::TPCClusterFinder::DoEvent", "Spacepoints", 
440                "Number of spacepoints: %lu Slice/Patch/RowMin/RowMax: %d/%d/%d/%d.",
441                realPoints, slice, patch, row[0], row[1] );
442       AliHLTComponentBlockData bd;
443       FillBlockData( bd );
444       bd.fOffset = offset;
445       bd.fSize = mysize;
446       bd.fSpecification = iter->fSpecification;
447       //AliHLTSubEventDescriptor::FillBlockAttributes( bd.fAttributes );
448       outputBlocks.push_back( bd );
449         
450       tSize += mysize;
451       outBPtr += mysize;
452       outPtr = (AliHLTTPCClusterData*)outBPtr;
453         
454       if ( tSize > size )
455         {
456           Logging( kHLTLogFatal, "HLT::TPCClusterFinder::DoEvent", "Too much data", 
457                    "Data written over allowed buffer. Amount written: %lu, allowed amount: %lu.",
458                    tSize, size );
459           return EMSGSIZE;
460         }
461     }
462     
463   size = tSize;
464
465   return 0;
466 }