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