]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/AliHLTTPCHWClusterTransformComponent.cxx
minor update of documentation
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCHWClusterTransformComponent.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: Kalliopi Kanaki <Kalliopi.Kanaki@ift.uib.no>          *
8 //*                  for The ALICE HLT Project.                            *
9 //*                                                                        *
10 //* Permission to use, copy, modify and distribute this software and its   *
11 //* documentation strictly for non-commercial purposes is hereby granted   *
12 //* without fee, provided that the above copyright notice appears in all   *
13 //* copies and that both the copyright notice and this permission notice   *
14 //* appear in the supporting documentation. The authors make no claims     *
15 //* about the suitability of this software for any purpose. It is          *
16 //* provided "as is" without express or implied warranty.                  *
17 //**************************************************************************
18
19 /** @file   AliHLTTPCHWClusterTransformComponent.cxx
20     @author Kalliopi Kanaki
21     @date   
22     @brief 
23 */
24
25 #if __GNUC__>= 3
26 using namespace std;
27 #endif
28 #include "AliHLTTPCHWClusterTransformComponent.h"
29 #include "AliHLTTPCDefinitions.h"
30 #include "AliHLTTPCTransform.h"
31 #include "AliHLTTPCSpacePointData.h"
32 #include "AliHLTTPCClusterDataFormat.h"
33
34 #include "AliCDBManager.h"
35 #include "AliCDBEntry.h"
36 #include "AliTPCcalibDB.h"
37
38 #include "TMath.h"
39 #include "TObjString.h" 
40 #include <cstdlib>
41 #include <cerrno>
42 #include <sys/time.h>
43
44 ClassImp(AliHLTTPCHWClusterTransformComponent) //ROOT macro for the implementation of ROOT specific class methods
45
46 const char* AliHLTTPCHWClusterTransformComponent::fgkOCDBEntryHWTransform="HLT/ConfigTPC/TPCHWClusterTransform";
47
48 AliHLTTPCHWClusterTransformComponent::AliHLTTPCHWClusterTransformComponent()
49 :
50 fDataId(kFALSE),
51 fChargeThreshold(10),
52 fTransform(),
53 fBenchmark("HWClusterTransform")
54 {
55   // see header file for class documentation
56   // or
57   // refer to README to build package
58   // or
59   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt  
60
61   fBenchmark.Reset();
62   fBenchmark.SetTimer(0,"total");
63 }
64
65 AliHLTTPCHWClusterTransformComponent::~AliHLTTPCHWClusterTransformComponent() { 
66 // see header file for class documentation
67 }
68
69 const char* AliHLTTPCHWClusterTransformComponent::GetComponentID() { 
70 // see header file for class documentation
71
72   return "TPCHWClusterTransform";
73 }
74
75 void AliHLTTPCHWClusterTransformComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list) { 
76   // see header file for class documentation
77
78   list.clear(); 
79   list.push_back( AliHLTTPCDefinitions::fgkHWClustersDataType );
80 }
81
82 AliHLTComponentDataType AliHLTTPCHWClusterTransformComponent::GetOutputDataType() { 
83   // see header file for class documentation
84
85   return AliHLTTPCDefinitions::fgkClustersDataType;
86 }
87
88 int AliHLTTPCHWClusterTransformComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList) { 
89   // see header file for class documentation
90
91   tgtList.clear();
92   tgtList.push_back(AliHLTTPCDefinitions::fgkClustersDataType);
93   return tgtList.size();
94 }
95
96 void AliHLTTPCHWClusterTransformComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) { 
97   // see header file for class documentation
98   constBase = 0;
99   inputMultiplier = 3.0;
100 }
101
102 AliHLTComponent* AliHLTTPCHWClusterTransformComponent::Spawn() { 
103   // see header file for class documentation
104
105   return new AliHLTTPCHWClusterTransformComponent();
106 }
107         
108 int AliHLTTPCHWClusterTransformComponent::DoInit( int argc, const char** argv ) { 
109 // see header file for class documentation
110   
111   int err = fTransform.Init( GetBz(), GetTimeStamp() );
112
113   if( err!=0 ){
114     HLTError("Cannot retrieve offline transform from AliTPCcalibDB");
115     return -ENOENT;
116   }
117
118   int iResult=0;
119   iResult = ConfigureFromCDBTObjString(fgkOCDBEntryHWTransform);
120
121   if (iResult>=0 && argc>0)
122     iResult=ConfigureFromArgumentString(argc, argv);
123
124   return iResult;
125 } // end DoInit()
126
127 int AliHLTTPCHWClusterTransformComponent::DoDeinit() { 
128   // see header file for class documentation   
129   return 0;
130 }
131
132 int AliHLTTPCHWClusterTransformComponent::DoEvent(const AliHLTComponentEventData& evtData, 
133                                                   const AliHLTComponentBlockData* blocks, 
134                                                   AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr, 
135                                                   AliHLTUInt32_t& size, 
136                                                   vector<AliHLTComponentBlockData>& outputBlocks ){
137   // see header file for class documentation
138    
139   if(GetFirstInputBlock( kAliHLTDataTypeSOR ) || GetFirstInputBlock( kAliHLTDataTypeEOR )){
140      size = 0;
141      return 0;
142   }
143
144   fBenchmark.StartNewEvent();
145   fBenchmark.Start(0);
146
147   fTransform.SetCurrentTimeStamp( GetTimeStamp() );
148
149   const AliHLTComponentBlockData *iter = NULL;    
150   unsigned long ndx; 
151
152   AliHLTUInt8_t* outBPtr;
153   UInt_t offset, mysize, nSize, tSize = 0;
154
155   outBPtr = outputPtr;
156       
157   for(ndx=0; ndx<evtData.fBlockCnt; ndx++){
158      
159      iter   = blocks+ndx;
160      mysize = 0;
161      offset = tSize;
162      
163      fBenchmark.AddInput(iter->fSize);
164
165      HLTDebug("Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
166                evtData.fEventID, evtData.fEventID, 
167                DataType2Text( iter->fDataType).c_str(), 
168                DataType2Text(AliHLTTPCDefinitions::fgkHWClustersDataType).c_str());                       
169  
170      if(iter->fDataType != AliHLTTPCDefinitions::fgkHWClustersDataType) continue;                        
171   
172      UInt_t minSlice     = AliHLTTPCDefinitions::GetMinSliceNr(*iter); 
173      UInt_t minPartition = AliHLTTPCDefinitions::GetMinPatchNr(*iter);
174      //UInt_t maxSlice     = AliHLTTPCDefinitions::GetMaxSliceNr(*iter); 
175      //UInt_t maxPartition = AliHLTTPCDefinitions::GetMaxPatchNr(*iter);
176
177      fBenchmark.SetName(Form("HWClusterTransform slice %d patch %d",minSlice,minPartition));
178
179      HLTDebug("minSlice: %d, minPartition: %d", minSlice, minPartition);
180     
181      AliHLTTPCClusterData* outPtr  = (AliHLTTPCClusterData*)outBPtr;
182
183      unsigned long maxPoints = (size-tSize-sizeof(AliHLTTPCClusterData))/sizeof(AliHLTTPCSpacePointData);
184      
185      AliHLTUInt32_t *buffer;     
186      buffer = (AliHLTUInt32_t*)iter->fPtr;  
187      
188      /*  
189      //cluster fabrication
190      buffer = new AliHLTUInt32_t[14];
191      //header
192      buffer[0]=0xffffffff;
193      buffer[1]=0xffffffff;
194      buffer[2]=0xffffffff;
195      buffer[3]=0xffffffff;
196      buffer[4]=0xffffffff;
197      buffer[5]=0xffffffff;
198      buffer[6]=0xffffffff;
199      buffer[7]=0xffffffff;
200      //cluster 1
201      buffer[8]=0xC60002EF;
202      buffer[9]=0x0;
203      buffer[10]=0x0;
204      buffer[11]=0x0;
205      buffer[12]=0x0;
206      //RCU trailer
207      buffer[13]=0x80000000;
208      */
209
210      // PrintDebug(buffer, 14);
211      
212      // skip the first 8 32-bit CDH words
213      buffer += 8;
214
215      //PrintDebug(buffer, (Int_t)iter->fSize/sizeof(AliHLTUInt32_t));
216
217      unsigned long nAddedClusters = 0;
218      
219      for(UInt_t nWords=0; nWords<(iter->fSize/sizeof(AliHLTUInt32_t)); nWords+=5){
220      //     for(UInt_t nWords=0; nWords<5; nWords+=5){
221
222         // check if bit 31 and 30 of the 32-bit word is 11 -> cluster (10 is RCU trailer)
223         AliHLTUInt32_t bit3130 = (buffer[nWords]>>30); // shift 30 to the right
224        
225
226         if(bit3130 == 0x3){ //beginning of a cluster
227
228            //PrintDebug(&buffer[nWords], 5);
229           
230            if(nAddedClusters>=maxPoints){
231               HLTWarning("No more space to add clusters, exiting!");
232               break;
233            }
234
235            
236            AliHLTTPCSpacePointData cluster = { 0.,0.,0.,0,0,0.,0.,0,0,kFALSE,0 };
237               
238            //get the first word
239            AliHLTUInt32_t  rowCharge = buffer[nWords];
240            AliHLTUInt8_t  *rowPtr    = reinterpret_cast<AliHLTUInt8_t*>(&rowCharge);      
241            rowPtr+=3; // this is to run for little endian architecture, the word is read from right to left
242         
243            cluster.fPadRow  = (UChar_t)((*rowPtr)&0x3f);
244            cluster.fCharge  = ((UInt_t)rowCharge&0xFFFFFF)>>6; //24-bit mask to get out the charge and division with 64(>>6) for the gain correction
245
246            Float_t tmpPad   = *((Float_t*)&buffer[nWords+1]);
247            Float_t tmpTime  = *((Float_t*)&buffer[nWords+2]);
248            cluster.fSigmaY2 = *((Float_t*)&buffer[nWords+3]);
249            cluster.fSigmaZ2 = *((Float_t*)&buffer[nWords+4]);
250            
251            
252            if(cluster.fCharge<fChargeThreshold) continue;
253            
254            // correct expressions for the error calculation
255            // Kenneth: 12.11.2009 I'm not sure if this is a correct calculation. Leave it out for now since it is anyway not used later since it caused segfaults.
256            // cluster.fSigmaY2 = TMath::Sqrt( *((Float_t*)&buffer[nWords+3]) - *((Float_t*)&buffer[nWords+1])* (*((Float_t*)&buffer[nWords+1])) );
257            // cluster.fSigmaZ2 = TMath::Sqrt( *((Float_t*)&buffer[nWords+3]) - *((Float_t*)&buffer[nWords+1])* (*((Float_t*)&buffer[nWords+1])) );
258                    
259            HLTDebug("padrow: %d, charge: %d, pad: %f, time: %f, errY: %f, errZ: %f \n", cluster.fPadRow, (UInt_t)cluster.fCharge, tmpPad, tmpTime, cluster.fSigmaY2, cluster.fSigmaZ2);            
260                     
261            cluster.fPadRow += AliHLTTPCTransform::GetFirstRow(minPartition);                 
262               
263            Float_t xyz[3];
264            fTransform.Transform( minSlice, cluster.fPadRow, tmpPad, tmpTime, xyz );
265            cluster.fX = xyz[0];
266            cluster.fY = xyz[1];
267            cluster.fZ = xyz[2];                            
268
269            // set the cluster ID so that the cluster dump printout is the same for FCF and SCF
270            cluster.SetID( minSlice, minPartition, nAddedClusters );
271
272            HLTDebug("Cluster number %d: %f, Y: %f, Z: %f, charge: %d \n", nAddedClusters, cluster.fX, cluster.fY, cluster.fZ, (UInt_t)cluster.fCharge);
273            outPtr->fSpacePoints[nAddedClusters] = cluster;
274                    
275            nAddedClusters++; 
276         } // end of clusters starting with 11=0x3
277         else if(bit3130 == 0x2){ // we have reached the beginning of the RCU trailer - 10=0x2
278           break;
279         }
280      } // end of loop over clusters
281      
282      HLTDebug("Number of found clusters: %d", nAddedClusters);
283      
284      outPtr->fSpacePointCnt = nAddedClusters;
285      nSize = sizeof(AliHLTTPCSpacePointData)*outPtr->fSpacePointCnt;
286      mysize += nSize+sizeof(AliHLTTPCClusterData);
287  
288      AliHLTComponentBlockData bd;
289      FillBlockData( bd );
290      bd.fOffset = offset;
291      bd.fSize = mysize;
292      bd.fSpecification = iter->fSpecification;
293      
294      if(fDataId==kFALSE) bd.fDataType = AliHLTTPCDefinitions::fgkClustersDataType;
295      else                bd.fDataType = AliHLTTPCDefinitions::fgkAlterClustersDataType;
296      
297      //HLTDebug("datatype: %s", DataType2Text(bd.fDataType).c_str());
298      
299      outputBlocks.push_back( bd );
300      
301      fBenchmark.AddOutput(bd.fSize);
302     
303      tSize   += mysize;
304      outBPtr += mysize;
305   
306    } // end of loop over data blocks
307
308   size = tSize;
309   
310   fBenchmark.Stop(0);
311   HLTInfo(fBenchmark.GetStatistics());
312
313   return 0;
314 } // end DoEvent()
315
316 int AliHLTTPCHWClusterTransformComponent::ScanConfigurationArgument(int argc, const char** argv){
317
318   // see header file for class documentation
319
320   if (argc<=0) return 0;
321   int i=0;
322   TString argument=argv[i];
323
324   if (argument.CompareTo("-solenoidBz")==0){
325     if (++i>=argc) return -EPROTO;
326     argument=argv[i];
327     AliTPCcalibDB*  calib=AliTPCcalibDB::Instance();
328     if(!calib){
329       HLTError("CalibDB not available");
330     }
331     Float_t magneticField = argument.Atof();
332     calib->SetExBField(magneticField);
333     HLTInfo("SolenoidBz is set to %f in the calibDB",magneticField);
334     return 2;
335   }
336
337   if (argument.CompareTo("-change-dataId")==0){
338     HLTDebug("Change data ID received.");
339     fDataId = kTRUE;
340     return 1;
341   }
342   
343   if (argument.CompareTo("-charge-threshold")==0) {
344     if (++i>=argc) return -EPROTO;
345     argument=argv[i];
346     fChargeThreshold=(UInt_t)argument.Atoi();
347     HLTInfo("The charge threshold has been set to %d.", fChargeThreshold);
348     return 2;
349   }    
350
351   // unknown argument
352   return -EINVAL;
353 }
354
355 int AliHLTTPCHWClusterTransformComponent::Reconfigure(const char* /*cdbEntry*/, const char* /*chainId*/) { 
356   // see header file for class documentation
357   return ConfigureFromCDBTObjString(fgkOCDBEntryHWTransform);
358 }
359
360 void AliHLTTPCHWClusterTransformComponent::PrintDebug(AliHLTUInt32_t *buffer, Int_t size){
361 // see header file for class documentation 
362
363   HLTInfo("The size is: %d", size);
364   for(Int_t n32bit=0; n32bit<size; n32bit++){
365     
366     AliHLTUInt8_t *wordPtr = reinterpret_cast<AliHLTUInt8_t*>(&buffer[n32bit]);
367     //    cout << "word ptr initialized"<<endl;
368     for(Int_t w=3;w>=0;w--){
369       //     cout <<"accessing word"<<endl;
370       AliHLTUInt8_t word = wordPtr[w];
371       //     cout<< "word was accessed"<<endl; 
372       for(int n=7; n>=0; n--){
373         //print the byte values
374         if((((word>>n)<<7)&0x80) != 0){
375           printf("1");
376         }
377         else{
378           printf("0");
379         }
380       }
381       printf("  ");
382     }
383     printf("\n");
384   }
385 } // end of PrintDebug
386
387 void AliHLTTPCHWClusterTransformComponent::GetOCDBObjectDescription( TMap* const targetMap){
388 // Get a list of OCDB object description needed for the particular component
389   if (!targetMap) return;
390   targetMap->Add(new TObjString("HLT/ConfigTPC/TPCHWClusterTransform"), new TObjString("component argument for the charge threshold"));
391 }