]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/AliHLTTPCHWClusterTransformComponent.cxx
- fixed compilation warnings
[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 "AliTPCcalibDB.h"
35 #include "AliTPCTransform.h"
36 #include "AliTPCCalPad.h"
37
38 #include "AliCDBManager.h"
39 #include "AliCDBEntry.h"
40
41 #include "TMath.h"
42 #include "TObjString.h" 
43 #include <cstdlib>
44 #include <cerrno>
45 #include <sys/time.h>
46
47 ClassImp(AliHLTTPCHWClusterTransformComponent) //ROOT macro for the implementation of ROOT specific class methods
48
49 AliHLTTPCHWClusterTransformComponent::AliHLTTPCHWClusterTransformComponent()
50 :
51 fOfflineTransform(NULL),
52 fDataId(kFALSE)
53 {
54   // see header file for class documentation
55   // or
56   // refer to README to build package
57   // or
58   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt  
59 }
60
61 AliHLTTPCHWClusterTransformComponent::~AliHLTTPCHWClusterTransformComponent() { 
62 // see header file for class documentation
63 }
64
65 const char* AliHLTTPCHWClusterTransformComponent::GetComponentID() { 
66 // see header file for class documentation
67
68   return "TPCHWClusterTransform";
69 }
70
71 void AliHLTTPCHWClusterTransformComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list) { 
72   // see header file for class documentation
73
74   list.clear(); 
75   list.push_back( AliHLTTPCDefinitions::fgkHWClustersDataType );
76 }
77
78 AliHLTComponentDataType AliHLTTPCHWClusterTransformComponent::GetOutputDataType() { 
79   // see header file for class documentation
80
81   return AliHLTTPCDefinitions::fgkClustersDataType;
82 }
83
84 int AliHLTTPCHWClusterTransformComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList) { 
85   // see header file for class documentation
86
87   tgtList.clear();
88   tgtList.push_back(AliHLTTPCDefinitions::fgkClustersDataType);
89   return tgtList.size();
90 }
91
92 void AliHLTTPCHWClusterTransformComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) { 
93   // see header file for class documentation
94   constBase = 0;
95   inputMultiplier = 3.0;
96 }
97
98 AliHLTComponent* AliHLTTPCHWClusterTransformComponent::Spawn() { 
99   // see header file for class documentation
100
101   return new AliHLTTPCHWClusterTransformComponent();
102 }
103         
104 int AliHLTTPCHWClusterTransformComponent::DoInit( int argc, const char** argv ) { 
105 // see header file for class documentation
106
107   AliTPCcalibDB* pCalib=AliTPCcalibDB::Instance();
108   if(!pCalib ||
109      !(fOfflineTransform = AliTPCcalibDB::Instance()->GetTransform())){
110     HLTError("Cannot retrieve offline transform from AliTPCcalibDB (%p)", pCalib);
111     return -ENOENT;
112   }
113
114   //Int_t i = 0;
115   //Char_t* cpErr;
116
117   int iResult=0;
118
119   TString configuration="";
120   TString argument="";
121   for(int j=0; j<argc && iResult>=0; j++){
122       argument=argv[j];
123       if (!configuration.IsNull()) configuration+=" ";
124       configuration+=argument;  
125   }
126   
127   if (!configuration.IsNull()) {
128     iResult=Configure(configuration.Data());
129   } 
130   else {
131     //iResult=Reconfigure(NULL, NULL);
132   }
133
134   return 0;
135 } // end DoInit()
136
137 int AliHLTTPCHWClusterTransformComponent::DoDeinit() { 
138   // see header file for class documentation 
139    
140   return 0;
141 }
142
143 int AliHLTTPCHWClusterTransformComponent::DoEvent(const AliHLTComponentEventData& evtData, 
144                                                   const AliHLTComponentBlockData* blocks, 
145                                                   AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr, 
146                                                   AliHLTUInt32_t& size, 
147                                                   vector<AliHLTComponentBlockData>& outputBlocks ){
148   // see header file for class documentation
149     
150   if(GetFirstInputBlock( kAliHLTDataTypeSOR ) || GetFirstInputBlock( kAliHLTDataTypeEOR )){
151      size = 0;
152      return 0;
153   }
154
155   const AliHLTComponentBlockData *iter = NULL;    
156   unsigned long ndx;
157
158   AliHLTTPCClusterData* outPtr;
159
160   AliHLTUInt8_t* outBPtr;
161   UInt_t offset, mysize, nSize, tSize = 0;
162
163   outBPtr = outputPtr;
164   outPtr  = (AliHLTTPCClusterData*)outBPtr;
165   
166   AliHLTTPCSpacePointData *spacePoints = outPtr->fSpacePoints;
167
168   unsigned long maxPoints = 0;
169
170   for(ndx=0; ndx<evtData.fBlockCnt; ndx++){
171      
172      iter   = blocks+ndx;
173      mysize = 0;
174      offset = tSize;
175  
176      HLTDebug("Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
177                evtData.fEventID, evtData.fEventID, 
178                DataType2Text( iter->fDataType).c_str(), 
179                DataType2Text(AliHLTTPCDefinitions::fgkHWClustersDataType).c_str());                       
180  
181      if(iter->fDataType != AliHLTTPCDefinitions::fgkHWClustersDataType) continue;                        
182   
183      UInt_t minSlice     = AliHLTTPCDefinitions::GetMinSliceNr(*iter); 
184      UInt_t minPartition = AliHLTTPCDefinitions::GetMinPatchNr(*iter);
185      //UInt_t maxSlice     = AliHLTTPCDefinitions::GetMaxSliceNr(*iter); 
186      //UInt_t maxPartition = AliHLTTPCDefinitions::GetMaxPatchNr(*iter);
187      
188      HLTDebug("minSlice: %d, minPartition: %d", minSlice, minPartition);
189     
190      outPtr = (AliHLTTPCClusterData*)outBPtr;
191      maxPoints = (size-tSize-sizeof(AliHLTTPCClusterData))/sizeof(AliHLTTPCSpacePointData);
192      
193      AliHLTUInt32_t *buffer;     
194      buffer = (AliHLTUInt32_t*)iter->fPtr;  
195      
196      /*  
197      //cluster fabrication
198      buffer = new AliHLTUInt32_t[14];
199      //header
200      buffer[0]=0xffffffff;
201      buffer[1]=0xffffffff;
202      buffer[2]=0xffffffff;
203      buffer[3]=0xffffffff;
204      buffer[4]=0xffffffff;
205      buffer[5]=0xffffffff;
206      buffer[6]=0xffffffff;
207      buffer[7]=0xffffffff;
208      //cluster 1
209      buffer[8]=0xC60002EF;
210      buffer[9]=0x0;
211      buffer[10]=0x0;
212      buffer[11]=0x0;
213      buffer[12]=0x0;
214      //RCU trailer
215      buffer[13]=0x80000000;
216      */
217
218      Int_t sector=-99, thisrow=-99;
219
220      // PrintDebug(buffer, 14);
221      
222      // skip the first 8 32-bit CDH words
223      buffer += 8;
224
225      //PrintDebug(buffer, (Int_t)iter->fSize/sizeof(AliHLTUInt32_t));
226
227      unsigned long nAddedClusters = 0;
228      
229      for(UInt_t nWords=0; nWords<(iter->fSize/sizeof(AliHLTUInt32_t)); nWords+=5){
230      //     for(UInt_t nWords=0; nWords<5; nWords+=5){
231          
232         // check if bit 31 and 30 of the 32-bit word is 11 -> cluster (10 is RCU trailer)
233         AliHLTUInt32_t bit3130 = (buffer[nWords]>>30); // shift 30 to the right
234        
235         if(bit3130 == 0x3){ //beginning of a cluster
236
237            //PrintDebug(&buffer[nWords], 5);
238           
239            if(nAddedClusters>=maxPoints){
240               HLTWarning("No more space to add clusters, exiting!");
241               break;
242            }
243            
244            AliHLTTPCSpacePointData cluster = { 0.,0.,0.,0,0,0.,0.,0,0,kFALSE,0 };
245               
246            //get the first word
247            AliHLTUInt32_t  rowCharge = buffer[nWords];
248            AliHLTUInt8_t  *rowPtr    = reinterpret_cast<AliHLTUInt8_t*>(&rowCharge);      
249            rowPtr+=3; // this is to run for little endian architecture, the word is read from right to left
250         
251            cluster.fPadRow  = (UChar_t)((*rowPtr)&0x3f);
252            cluster.fCharge  = ((UInt_t)rowCharge&0xFFFFFF)>>6; //24-bit mask to get out the charge and division with 64(>>6) for the gain correction
253
254            Float_t tmpPad   = *((Float_t*)&buffer[nWords+1]);
255            Float_t tmpTime  = *((Float_t*)&buffer[nWords+2]);
256            //cluster.fSigmaY2 = *((Float_t*)&buffer[nWords+3]);
257            //cluster.fSigmaZ2 = *((Float_t*)&buffer[nWords+4]);
258            
259            // correct expressions for the error calculation
260
261            cluster.fSigmaY2 = TMath::Sqrt( *((Float_t*)&buffer[nWords+3]) - *((Float_t*)&buffer[nWords+1])* (*((Float_t*)&buffer[nWords+1])) );
262            cluster.fSigmaZ2 = TMath::Sqrt( *((Float_t*)&buffer[nWords+3]) - *((Float_t*)&buffer[nWords+1])* (*((Float_t*)&buffer[nWords+1])) );
263           
264            Float_t xyz[3]; xyz[0] = xyz[1] = xyz[2] = -99.;
265                    
266            HLTDebug("padrow: %d, charge: %f, pad: %f, time: %f, errY: %f, errZ: %f \n", cluster.fPadRow, (Float_t)cluster.fCharge, tmpPad, tmpTime, cluster.fSigmaY2, cluster.fSigmaZ2);                   
267            
268            if(fOfflineTransform == NULL){                  
269               cluster.fPadRow += AliHLTTPCTransform::GetFirstRow(minPartition);                    
270               AliHLTTPCTransform::Slice2Sector(minSlice, cluster.fPadRow, sector, thisrow);           
271               AliHLTTPCTransform::Raw2Local(xyz, sector, thisrow, tmpPad, tmpTime); 
272               if(minSlice>17) xyz[1]=(-1)*xyz[1];          
273               cluster.fX = xyz[0];
274               cluster.fY = xyz[1];
275               cluster.fZ = xyz[2]; 
276               
277            } else {
278              cluster.fPadRow += AliHLTTPCTransform::GetFirstRow(minPartition);                     
279              AliHLTTPCTransform::Slice2Sector(minSlice, (UInt_t)cluster.fPadRow, sector, thisrow);            
280              Double_t x[3] = {(Double_t)cluster.fPadRow,tmpPad+.5,tmpTime}; 
281              Int_t iSector[1]= {sector};
282              fOfflineTransform->Transform(x,iSector,0,1);
283              cluster.fX = x[0];
284              cluster.fY = x[1];
285              cluster.fZ = x[2];       
286            }
287            
288            HLTDebug("cluster X: %f, Y: %f, Z: %f \n", cluster.fX, cluster.fY, cluster.fZ);
289            spacePoints[nAddedClusters] = cluster;
290                    
291            nAddedClusters++; 
292         } // end of clusters starting with 11=0x3
293         else if(bit3130 == 0x2){ // we have reached the beginning of the RCU trailer - 10=0x2
294           break;
295         }
296      } // end of loop over clusters
297      
298      HLTDebug("Number of found clusters: %d", nAddedClusters);
299      
300      outPtr->fSpacePointCnt = nAddedClusters;
301      nSize = sizeof(AliHLTTPCSpacePointData)*outPtr->fSpacePointCnt;
302      mysize += nSize+sizeof(AliHLTTPCClusterData);
303  
304      AliHLTComponentBlockData bd;
305      FillBlockData( bd );
306      bd.fOffset = offset;
307      bd.fSize = mysize;
308      bd.fSpecification = iter->fSpecification;
309      
310      if(fDataId==kFALSE) bd.fDataType = AliHLTTPCDefinitions::fgkClustersDataType;
311      else                bd.fDataType = AliHLTTPCDefinitions::fgkAlterClustersDataType;
312      
313      //HLTDebug("datatype: %s", DataType2Text(bd.fDataType).c_str());
314      
315      outputBlocks.push_back( bd );
316      
317      tSize   += mysize;
318      outBPtr += mysize;
319      outPtr   = (AliHLTTPCClusterData*)outBPtr;
320   
321    } // end of loop over data blocks
322    size = tSize;
323    return 0;
324 } // end DoEvent()
325   
326 int AliHLTTPCHWClusterTransformComponent::Configure(const char* arguments) { 
327   // see header file for class documentation
328   
329   int iResult=0;
330   if (!arguments) return iResult;
331   HLTInfo("parsing configuration string \'%s\'", arguments);
332
333   TString allArgs=arguments;
334   TString argument;
335   int bMissingParam=0;
336
337   TObjArray* pTokens=allArgs.Tokenize(" ");
338   if (pTokens) {
339     for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
340       argument=((TObjString*)pTokens->At(i))->GetString();
341       if (argument.IsNull()) continue;
342      
343       if (argument.CompareTo("-change-dataId")==0) {
344         fDataId = kTRUE;
345         HLTInfo("got \'-change-dataId\': %s", ((TObjString*)pTokens->At(i))->GetString().Data());       
346       } 
347       else {
348         HLTError("unknown argument %s", argument.Data());
349         iResult=-EINVAL;
350         break;
351       }
352     } // end for
353   
354     delete pTokens;
355   
356   } // end if pTokens
357   
358   if (bMissingParam) {
359     HLTError("missing parameter for argument %s", argument.Data());
360     iResult=-EINVAL;
361   }
362   return iResult;
363 }
364
365 int AliHLTTPCHWClusterTransformComponent::Reconfigure(const char* cdbEntry, const char* chainId) { 
366   // see header file for class documentation
367
368   int iResult=0;
369   const char* path="HLT/ConfigTPC/TPCHWClusterTransform";
370   const char* defaultNotify="";
371   if (cdbEntry) {
372     path=cdbEntry;
373     defaultNotify=" (default)";
374   }
375   
376   if (path) {
377     HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
378     AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
379     if (pEntry) {
380       TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
381       if (pString) {
382         HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
383         iResult=Configure(pString->GetString().Data());
384       } else {
385         HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
386       }
387     } else {
388       HLTError("cannot fetch object \"%s\" from CDB", path);
389     }
390   }
391   return iResult;
392 }
393
394 void AliHLTTPCHWClusterTransformComponent::PrintDebug(AliHLTUInt32_t *buffer, Int_t size){
395 // see header file for class documentation 
396
397   HLTInfo("The size is: %d", size);
398   for(Int_t n32bit=0; n32bit<size; n32bit++){
399     
400     AliHLTUInt8_t *wordPtr = reinterpret_cast<AliHLTUInt8_t*>(&buffer[n32bit]);
401     //    cout << "word ptr initialized"<<endl;
402     for(Int_t w=3;w>=0;w--){
403       //     cout <<"accessing word"<<endl;
404       AliHLTUInt8_t word = wordPtr[w];
405       //     cout<< "word was accessed"<<endl; 
406       for(int n=7; n>=0; n--){
407         //print the byte values
408         if((((word>>n)<<7)&0x80) != 0){
409           printf("1");
410         }
411         else{
412           printf("0");
413         }
414       }
415       printf("  ");
416     }
417     printf("\n");
418   }
419 } // end of PrintDebug