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