]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/AliHLTTPCClusterFinderComponent.cxx
- code version from TPC commissioning merged
[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<AliHLTComponent_DataType>& list)
96     {
97     list.clear(); 
98     if (fPackedSwitch) list.push_back( AliHLTTPCDefinitions::gkDDLPackedRawDataType );
99     else list.push_back( AliHLTTPCDefinitions::gkUnpackedRawDataType );
100    
101     }
102
103 AliHLTComponent_DataType 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
130     // Data Format version numbers:
131     // 0: RCU Data format as delivered during TPC commissioning, pads/padrows are sorted, RCU trailer is one 32 bit word.
132     // 1: As 0, but pads/padrows are delivered "as is", without sorting
133     // 2: As 0, but RCU trailer is 3 32 bit words.
134     // 3: As 1, but RCU trailer is 3 32 bit words.
135     // -1: use offline raw reader
136
137     Int_t i = 0;
138     Char_t* cpErr;
139
140     while ( i < argc ) {      
141
142       // -- raw reader mode option
143       if ( !strcmp( argv[i], "rawreadermode" ) ) {
144         if ( argc <= i+1 ) {
145           Logging( kHLTLogError, "HLT::TPCClusterFinder::DoInit", "Missing rawreadermode", "Raw Reader Mode not specified" );
146           return ENOTSUP;
147         }
148         
149         if ( !strcmp( argv[i+1], "sorted_1_trailerword" ) ) {
150           rawreadermode = 0;
151         }
152         else if ( !strcmp( argv[i+1], "sorted_3_trailerword" ) ) {
153           rawreadermode = 2;
154         }
155         else if ( !strcmp( argv[i+1], "unsorted_1_trailerword" ) ) {
156           rawreadermode = 1;
157         }
158         else if ( !strcmp( argv[i+1], "unsorted_3_trailerword" ) ) {
159           rawreadermode = 3;
160         }
161         else if ( !strcmp( argv[i+1], "offline" ) ) {
162           rawreadermode = -1;
163         }
164         else {
165           rawreadermode = strtoul( argv[i+1], &cpErr ,0);
166             if ( *cpErr ) {
167               Logging( kHLTLogError, "HLT::TPCClusterFinder::DoInit", "Missing rawreadermode", "Cannot convert rawreadermode specifier '%s'.", argv[i+1] );
168               return EINVAL;
169             }
170         }
171
172         i += 2;
173         continue;
174       }
175
176       // -- pp run option
177       if ( !strcmp( argv[i], "pp-run" ) ) {
178         fClusterDeconv = false;
179         i++;
180         continue;
181       }
182
183       Logging(kHLTLogError, "HLT::TPCClusterFinder::DoInit", "Unknown Option", "Unknown option '%s'", argv[i] );
184       return EINVAL;
185
186     }
187
188     // Choose reader
189
190     if (fPackedSwitch) { 
191       if (rawreadermode == -1) {
192 #if defined(HAVE_ALIRAWDATA) && defined(HAVE_ALITPCRAWSTREAM_H)
193         fReader = new AliHLTTPCDigitReaderPacked();
194         fClusterFinder->SetReader(fReader);
195 #else // ! defined(HAVE_ALIRAWDATA) && defined(HAVE_ALITPCRAWSTREAM_H)
196         HLTFatal("DigitReaderPacked not available - check your build");
197         return -ENODEV;
198 #endif //  defined(HAVE_ALIRAWDATA) && defined(HAVE_ALITPCRAWSTREAM_H)
199       } else {
200 #if defined(HAVE_TPC_MAPPING)
201         fReader = new AliHLTTPCDigitReaderRaw(rawreadermode);
202         fClusterFinder->SetReader(fReader);
203 #else //! defined(HAVE_TPC_MAPPING)
204       HLTFatal("DigitReaderRaw not available - check your build");
205       return -ENODEV;
206 #endif //defined(HAVE_TPC_MAPPING)
207       }
208     }
209     else {
210       fReader = new AliHLTTPCDigitReaderUnpacked();
211       fClusterFinder->SetReader(fReader);
212     }
213       
214     // Variables to setup the Clusterfinder
215     fClusterDeconv = true;
216     fXYClusterError = -1;
217     fZClusterError = -1;
218
219  
220     fClusterFinder->SetDeconv( fClusterDeconv );
221     fClusterFinder->SetXYError( fXYClusterError );
222     fClusterFinder->SetZError( fZClusterError );
223     if ( (fXYClusterError>0) && (fZClusterError>0) )
224       fClusterFinder->SetCalcErr( false );
225     
226     return 0;
227     }
228
229 int AliHLTTPCClusterFinderComponent::DoDeinit()
230     {
231
232     if ( fClusterFinder )
233         delete fClusterFinder;
234     fClusterFinder = NULL;
235  
236     if ( fReader )
237         delete fReader;
238     fReader = NULL;
239     
240     return 0;
241     }
242
243 int AliHLTTPCClusterFinderComponent::DoEvent( const AliHLTComponent_EventData& evtData, 
244                                               const AliHLTComponent_BlockData* blocks, 
245                                               AliHLTComponent_TriggerData& trigData, AliHLTUInt8_t* outputPtr, 
246                                               AliHLTUInt32_t& size, 
247                                               vector<AliHLTComponent_BlockData>& outputBlocks )
248     {
249
250     //  == init iter (pointer to datablock)
251     const AliHLTComponent_BlockData* iter = NULL;
252     unsigned long ndx;
253
254     //  == OUTdatatype pointer
255     AliHLTTPCClusterData* outPtr;
256
257     AliHLTUInt8_t* outBPtr;
258     UInt_t offset, mysize, nSize, tSize = 0;
259
260     outBPtr = outputPtr;
261     outPtr = (AliHLTTPCClusterData*)outBPtr;
262
263     Int_t slice, patch, row[2];
264     unsigned long maxPoints, realPoints = 0;
265
266     for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
267         {
268         iter = blocks+ndx;
269         mysize = 0;
270         offset = tSize;
271
272
273         if (fPackedSwitch) {    
274           char tmp1[14], tmp2[14];
275           DataType2Text( iter->fDataType, tmp1 );
276           DataType2Text( AliHLTTPCDefinitions::gkDDLPackedRawDataType, tmp2 );
277           Logging( kHLTLogDebug, "HLT::TPCClusterFinder::DoEvent", "Event received", 
278                    "Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
279                    evtData.fEventID, evtData.fEventID, tmp1, tmp2 );
280
281           if ( iter->fDataType != AliHLTTPCDefinitions::gkDDLPackedRawDataType ) continue;
282
283         }
284         else {
285           char tmp1[14], tmp2[14];
286           DataType2Text( iter->fDataType, tmp1 );
287           DataType2Text( AliHLTTPCDefinitions::gkUnpackedRawDataType, tmp2 );
288           Logging( kHLTLogDebug, "HLT::TPCClusterFinder::DoEvent", "Event received", 
289                    "Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
290                    evtData.fEventID, evtData.fEventID, tmp1, tmp2 );
291
292           if ( iter->fDataType != AliHLTTPCDefinitions::gkUnpackedRawDataType ) continue;
293
294         }
295         
296         slice = AliHLTTPCDefinitions::GetMinSliceNr( *iter );
297         patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
298         row[0] = AliHLTTPCTransform::GetFirstRow( patch );
299         row[1] = AliHLTTPCTransform::GetLastRow( patch );
300         
301         Logging( kHLTLogDebug, "HLT::TPCClusterFinder::DoEvent", "Input Spacepoints", 
302                  "Input: Number of spacepoints: %lu Slice/Patch/RowMin/RowMax: %d/%d/%d/%d.",
303                  realPoints, slice, patch, row[0], row[1] );
304         
305         outPtr = (AliHLTTPCClusterData*)outBPtr;
306
307         maxPoints = (size-tSize-sizeof(AliHLTTPCClusterData))/sizeof(AliHLTTPCSpacePointData);
308
309         fClusterFinder->InitSlice( slice, patch, row[0], row[1], maxPoints );
310         fClusterFinder->SetOutputArray( outPtr->fSpacePoints );
311         fClusterFinder->Read(iter->fPtr, iter->fSize );
312         fClusterFinder->ProcessDigits();
313         realPoints = fClusterFinder->GetNumberOfClusters();
314         
315         Logging( kHLTLogDebug, "HLT::TPCClusterFinder::DoEvent", "Spacepoints", 
316                  "Number of spacepoints found: %lu.", realPoints );
317         
318         outPtr->fSpacePointCnt = realPoints;
319         nSize = sizeof(AliHLTTPCSpacePointData)*realPoints;
320         mysize += nSize+sizeof(AliHLTTPCClusterData);
321         
322         Logging( kHLTLogDebug, "HLT::TPCClusterFinder::DoEvent", "Input Spacepoints", 
323                  "Number of spacepoints: %lu Slice/Patch/RowMin/RowMax: %d/%d/%d/%d.",
324                  realPoints, slice, patch, row[0], row[1] );
325         AliHLTComponent_BlockData bd;
326         FillBlockData( bd );
327         bd.fOffset = offset;
328         bd.fSize = mysize;
329         bd.fSpecification = iter->fSpecification;
330         //AliHLTSubEventDescriptor::FillBlockAttributes( bd.fAttributes );
331         outputBlocks.push_back( bd );
332         
333         tSize += mysize;
334         outBPtr += mysize;
335         outPtr = (AliHLTTPCClusterData*)outBPtr;
336         
337         if ( tSize > size )
338             {
339             Logging( kHLTLogFatal, "HLT::TPCClusterFinder::DoEvent", "Too much data", 
340                      "Data written over allowed buffer. Amount written: %lu, allowed amount: %lu.",
341                      tSize, size );
342             return EMSGSIZE;
343             }
344         }
345     
346     size = tSize;
347
348     return 0;
349     }
350
351