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