]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/AliHLTTPCHWClusterTransformComponent.cxx
using constructor for initialization
[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 #include "AliRawDataHeader.h"
34
35 #include "AliCDBManager.h"
36 #include "AliCDBEntry.h"
37 #include "AliTPCcalibDB.h"
38
39 #include "TMath.h"
40 #include "TObjString.h" 
41 #include <cstdlib>
42 #include <cerrno>
43 #include <sys/time.h>
44
45 ClassImp(AliHLTTPCHWClusterTransformComponent) //ROOT macro for the implementation of ROOT specific class methods
46
47 const char* AliHLTTPCHWClusterTransformComponent::fgkOCDBEntryHWTransform="HLT/ConfigTPC/TPCHWClusterTransform";
48
49 AliHLTTPCHWClusterTransformComponent::AliHLTTPCHWClusterTransformComponent()
50 :
51 fDataId(kFALSE),
52 fChargeThreshold(10),
53 fTransform(),
54 fBenchmark("HWClusterTransform")
55 {
56   // see header file for class documentation
57   // or
58   // refer to README to build package
59   // or
60   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt  
61
62   fBenchmark.Reset();
63   fBenchmark.SetTimer(0,"total");
64 }
65
66 AliHLTTPCHWClusterTransformComponent::~AliHLTTPCHWClusterTransformComponent() { 
67 // see header file for class documentation
68 }
69
70 const char* AliHLTTPCHWClusterTransformComponent::GetComponentID() { 
71 // see header file for class documentation
72
73   return "TPCHWClusterTransform";
74 }
75
76 void AliHLTTPCHWClusterTransformComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list) { 
77   // see header file for class documentation
78
79   list.clear(); 
80   list.push_back( AliHLTTPCDefinitions::fgkHWClustersDataType );
81 }
82
83 AliHLTComponentDataType AliHLTTPCHWClusterTransformComponent::GetOutputDataType() { 
84   // see header file for class documentation
85
86   return AliHLTTPCDefinitions::fgkClustersDataType;
87 }
88
89 int AliHLTTPCHWClusterTransformComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList) { 
90   // see header file for class documentation
91
92   tgtList.clear();
93   tgtList.push_back(AliHLTTPCDefinitions::fgkClustersDataType| kAliHLTDataOriginTPC);
94   tgtList.push_back(AliHLTTPCDefinitions::fgkAliHLTDataTypeClusterMCInfo | kAliHLTDataOriginTPC );
95   return tgtList.size();
96 }
97
98 void AliHLTTPCHWClusterTransformComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) { 
99   // see header file for class documentation
100   constBase = 0;
101   inputMultiplier = 3.0;
102 }
103
104 AliHLTComponent* AliHLTTPCHWClusterTransformComponent::Spawn() { 
105   // see header file for class documentation
106
107   return new AliHLTTPCHWClusterTransformComponent();
108 }
109         
110 int AliHLTTPCHWClusterTransformComponent::DoInit( int argc, const char** argv ) { 
111 // see header file for class documentation
112   
113   AliTPCcalibDB *calib=AliTPCcalibDB::Instance();  
114   if(!calib){
115     HLTError("AliTPCcalibDB does not exist");
116     return -ENOENT;
117   }
118   calib->SetRun(GetRunNo());
119   calib->UpdateRunInformations(GetRunNo());
120
121   int err = fTransform.Init( GetBz(), GetTimeStamp() );
122
123   if( err!=0 ){
124     HLTError("Cannot retrieve offline transform from AliTPCcalibDB");
125     return -ENOENT;
126   }
127
128   int iResult=0;
129   iResult = ConfigureFromCDBTObjString(fgkOCDBEntryHWTransform);
130
131   if (iResult>=0 && argc>0)
132     iResult=ConfigureFromArgumentString(argc, argv);
133
134   return iResult;
135 } // end DoInit()
136
137 int AliHLTTPCHWClusterTransformComponent::DoDeinit() { 
138   // see header file for class documentation   
139   return 0;
140 }
141
142 int AliHLTTPCHWClusterTransformComponent::DoEvent(const AliHLTComponentEventData& evtData, 
143                                                   const AliHLTComponentBlockData* blocks, 
144                                                   AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr, 
145                                                   AliHLTUInt32_t& size, 
146                                                   vector<AliHLTComponentBlockData>& outputBlocks ){
147   // see header file for class documentation
148    
149   UInt_t maxOutSize = size;
150   size = 0;
151   int iResult = 0;
152   if(GetFirstInputBlock( kAliHLTDataTypeSOR ) || GetFirstInputBlock( kAliHLTDataTypeEOR )){
153      return 0;
154   }
155
156   fBenchmark.StartNewEvent();
157   fBenchmark.Start(0);
158
159   fTransform.SetCurrentTimeStamp( GetTimeStamp() );
160   
161   for( unsigned long ndx=0; ndx<evtData.fBlockCnt; ndx++ ){
162      
163     const AliHLTComponentBlockData *iter   = blocks+ndx;
164     
165     fBenchmark.AddInput(iter->fSize);
166     
167     HLTDebug("Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
168              evtData.fEventID, evtData.fEventID, 
169              DataType2Text( iter->fDataType).c_str(), 
170              DataType2Text(AliHLTTPCDefinitions::fgkHWClustersDataType).c_str());                       
171  
172     if(iter->fDataType == (AliHLTTPCDefinitions::fgkAliHLTDataTypeClusterMCInfo | kAliHLTDataOriginTPC) ){
173       // simply forward MC labels
174       
175       if( size+iter->fSize > maxOutSize ){
176         HLTWarning( "Output buffer (%db) is too small, required %db", maxOutSize, size+iter->fSize);
177         iResult  = -ENOSPC;
178         break;
179       }
180
181       memcpy( outputPtr, iter->fPtr, iter->fSize );
182       
183       AliHLTComponentBlockData bd;
184       FillBlockData( bd );
185       bd.fOffset = size;
186       bd.fSize = iter->fSize;
187       bd.fSpecification = iter->fSpecification;     
188       bd.fDataType = iter->fDataType;
189       outputBlocks.push_back( bd );     
190       fBenchmark.AddOutput(bd.fSize);    
191       size   += bd.fSize;
192       outputPtr += bd.fSize;
193       continue;
194     }
195
196     if(iter->fDataType != (AliHLTTPCDefinitions::fgkHWClustersDataType | kAliHLTDataOriginTPC)) continue;                        
197         
198     UInt_t minSlice     = AliHLTTPCDefinitions::GetMinSliceNr(*iter); 
199     UInt_t minPartition = AliHLTTPCDefinitions::GetMinPatchNr(*iter);
200     //UInt_t maxSlice     = AliHLTTPCDefinitions::GetMaxSliceNr(*iter); 
201     //UInt_t maxPartition = AliHLTTPCDefinitions::GetMaxPatchNr(*iter);
202
203     fBenchmark.SetName(Form("HWClusterTransform slice %d patch %d",minSlice,minPartition));
204
205     HLTDebug("minSlice: %d, minPartition: %d", minSlice, minPartition);
206     
207     AliHLTTPCClusterData* outPtr  = (AliHLTTPCClusterData*)outputPtr;
208
209     long maxPoints = ((long)maxOutSize-size-sizeof(AliHLTTPCClusterData))/sizeof(AliHLTTPCSpacePointData);
210     
211      
212     AliHLTUInt32_t *buffer;     
213     buffer = (AliHLTUInt32_t*)iter->fPtr;  
214      
215      /*  
216      //cluster fabrication
217      buffer = new AliHLTUInt32_t[14];
218      //header
219      buffer[0]=0xffffffff;
220      buffer[1]=0xffffffff;
221      buffer[2]=0xffffffff;
222      buffer[3]=0xffffffff;
223      buffer[4]=0xffffffff;
224      buffer[5]=0xffffffff;
225      buffer[6]=0xffffffff;
226      buffer[7]=0xffffffff;
227      //cluster 1
228      buffer[8]=0xC60002EF;
229      buffer[9]=0x0;
230      buffer[10]=0x0;
231      buffer[11]=0x0;
232      buffer[12]=0x0;
233      //RCU trailer
234      buffer[13]=0x80000000;
235      */
236
237      // PrintDebug(buffer, 14);
238      
239      // skip the first 8 32-bit CDH words
240      buffer += 8;
241      UInt_t bufferSize32 = ((Int_t)iter->fSize - sizeof(AliRawDataHeader) )/sizeof(AliHLTUInt32_t);
242
243      //PrintDebug(buffer, (Int_t)iter->fSize/sizeof(AliHLTUInt32_t));
244
245      long nAddedClusters = 0;
246      
247      for(UInt_t nWords=0; nWords<bufferSize32; nWords+=5){
248        //     for(UInt_t nWords=0; nWords<5; nWords+=5){
249
250        // check if bit 31 and 30 of the 32-bit word is 11 -> cluster (10 is RCU trailer)
251        AliHLTUInt32_t bit3130 = (buffer[nWords]>>30); // shift 30 to the right
252        
253        if(bit3130 == 0x3){ //beginning of a cluster
254          
255          //PrintDebug(&buffer[nWords], 5);
256          
257          if(nAddedClusters>=maxPoints){
258            HLTWarning("No more space to add clusters, exiting!");
259            iResult  = -ENOSPC;
260            break;
261          }
262            
263          AliHLTTPCSpacePointData cluster;
264               
265          //get the first word
266          AliHLTUInt32_t  rowCharge = buffer[nWords];
267          AliHLTUInt8_t  *rowPtr    = reinterpret_cast<AliHLTUInt8_t*>(&rowCharge);        
268          rowPtr+=3; // this is to run for little endian architecture, the word is read from right to left
269         
270          cluster.fPadRow  = (UChar_t)((*rowPtr)&0x3f);
271          cluster.fCharge  = ((UInt_t)rowCharge&0xFFFFFF)>>6; //24-bit mask to get out the charge and division with 64(>>6) for the gain correction
272          
273          Float_t tmpPad   = *((Float_t*)&buffer[nWords+1]);
274          Float_t tmpTime  = *((Float_t*)&buffer[nWords+2]);
275          cluster.fSigmaY2 = *((Float_t*)&buffer[nWords+3]);
276          cluster.fSigmaZ2 = *((Float_t*)&buffer[nWords+4]);
277            
278            
279          if(cluster.fCharge<fChargeThreshold) continue;
280            
281          // correct expressions for the error calculation
282          // 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.
283          // cluster.fSigmaY2 = TMath::Sqrt( *((Float_t*)&buffer[nWords+3]) - *((Float_t*)&buffer[nWords+1])* (*((Float_t*)&buffer[nWords+1])) );
284          // cluster.fSigmaZ2 = TMath::Sqrt( *((Float_t*)&buffer[nWords+3]) - *((Float_t*)&buffer[nWords+1])* (*((Float_t*)&buffer[nWords+1])) );
285          
286          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);              
287          
288          cluster.fPadRow += AliHLTTPCTransform::GetFirstRow(minPartition);                   
289          
290          Float_t xyz[3];
291          fTransform.Transform( minSlice, cluster.fPadRow, tmpPad, tmpTime, xyz );
292          cluster.fX = xyz[0];
293          cluster.fY = xyz[1];
294          cluster.fZ = xyz[2];                              
295          
296          // set the cluster ID so that the cluster dump printout is the same for FCF and SCF
297          cluster.SetID( minSlice, minPartition, nAddedClusters );
298          
299          HLTDebug("Cluster number %d: %f, Y: %f, Z: %f, charge: %d \n", nAddedClusters, cluster.fX, cluster.fY, cluster.fZ, (UInt_t)cluster.fCharge);
300          outPtr->fSpacePoints[nAddedClusters] = cluster;
301          
302          nAddedClusters++; 
303        } // end of clusters starting with 11=0x3
304        else if(bit3130 == 0x2){ // we have reached the beginning of the RCU trailer - 10=0x2
305          break;
306        }
307      } // end of loop over clusters
308      
309      HLTDebug("Number of found clusters: %d", nAddedClusters);
310      
311      outPtr->fSpacePointCnt = nAddedClusters;
312
313      UInt_t mysize = sizeof(AliHLTTPCClusterData) + sizeof(AliHLTTPCSpacePointData)*outPtr->fSpacePointCnt;
314  
315      AliHLTComponentBlockData bd;
316      FillBlockData( bd );
317      bd.fOffset = size;
318      bd.fSize = mysize;
319      bd.fSpecification = iter->fSpecification;     
320      if(fDataId==kFALSE) bd.fDataType = AliHLTTPCDefinitions::fgkClustersDataType;
321      else                bd.fDataType = AliHLTTPCDefinitions::fgkAlterClustersDataType;
322      
323      //HLTDebug("datatype: %s", DataType2Text(bd.fDataType).c_str());
324      
325      outputBlocks.push_back( bd );
326      
327      fBenchmark.AddOutput(bd.fSize);    
328      size   += mysize;
329      outputPtr += mysize;
330   
331    } // end of loop over data blocks  
332   
333   fBenchmark.Stop(0);
334   HLTInfo(fBenchmark.GetStatistics());
335
336   return iResult;
337 } // end DoEvent()
338
339 int AliHLTTPCHWClusterTransformComponent::ScanConfigurationArgument(int argc, const char** argv){
340
341   // see header file for class documentation
342
343   if (argc<=0) return 0;
344   int i=0;
345   TString argument=argv[i];
346
347   if (argument.CompareTo("-solenoidBz")==0){
348     if (++i>=argc) return -EPROTO;
349     argument=argv[i];
350     AliTPCcalibDB*  calib=AliTPCcalibDB::Instance();
351     if(!calib){
352       HLTError("CalibDB instance cannot be created.");
353       return 0;
354     }
355     Float_t magneticField = argument.Atof();
356     calib->SetExBField(magneticField);
357     HLTInfo("SolenoidBz is set to %f in the calibDB",magneticField);
358     return 2;
359   }
360
361   if (argument.CompareTo("-change-dataId")==0){
362     HLTDebug("Change data ID received.");
363     fDataId = kTRUE;
364     return 1;
365   }
366   
367   if (argument.CompareTo("-charge-threshold")==0) {
368     if (++i>=argc) return -EPROTO;
369     argument=argv[i];
370     fChargeThreshold=(UInt_t)argument.Atoi();
371     HLTInfo("The charge threshold has been set to %d.", fChargeThreshold);
372     return 2;
373   }    
374
375   // unknown argument
376   return -EINVAL;
377 }
378
379 int AliHLTTPCHWClusterTransformComponent::Reconfigure(const char* /*cdbEntry*/, const char* /*chainId*/) { 
380   // see header file for class documentation
381   return ConfigureFromCDBTObjString(fgkOCDBEntryHWTransform);
382 }
383
384 void AliHLTTPCHWClusterTransformComponent::PrintDebug(AliHLTUInt32_t *buffer, Int_t size){
385 // see header file for class documentation 
386
387   HLTInfo("The size is: %d", size);
388   for(Int_t n32bit=0; n32bit<size; n32bit++){
389     
390     AliHLTUInt8_t *wordPtr = reinterpret_cast<AliHLTUInt8_t*>(&buffer[n32bit]);
391     //    cout << "word ptr initialized"<<endl;
392     for(Int_t w=3;w>=0;w--){
393       //     cout <<"accessing word"<<endl;
394       AliHLTUInt8_t word = wordPtr[w];
395       //     cout<< "word was accessed"<<endl; 
396       for(int n=7; n>=0; n--){
397         //print the byte values
398         if((((word>>n)<<7)&0x80) != 0){
399           printf("1");
400         }
401         else{
402           printf("0");
403         }
404       }
405       printf("  ");
406     }
407     printf("\n");
408   }
409 } // end of PrintDebug
410
411 void AliHLTTPCHWClusterTransformComponent::GetOCDBObjectDescription( TMap* const targetMap)
412 {
413   // Get a list of OCDB object description needed for the particular component
414   if (!targetMap) return;
415   
416   // OCDB entries for component arguments
417
418   targetMap->Add(new TObjString("HLT/ConfigTPC/TPCHWClusterTransform"), new TObjString("component argument for the charge threshold"));
419   
420   // OCDB entries to be fetched by the TAXI (access via the AliTPCcalibDB class)
421   targetMap->Add(new TObjString("TPC/Calib/Parameters"),    new TObjString("unknown content"));
422   targetMap->Add(new TObjString("TPC/Calib/TimeDrift"),     new TObjString("drift velocity calibration"));
423   targetMap->Add(new TObjString("TPC/Calib/Temperature"),   new TObjString("temperature map"));
424   targetMap->Add(new TObjString("TPC/Calib/PadGainFactor"), new TObjString("gain factor pad by pad"));
425   targetMap->Add(new TObjString("TPC/Calib/ClusterParam"),  new TObjString("cluster parameters"));
426   
427   // OCDB entries needed to be fetched by the Pendolino
428   targetMap->Add(new TObjString("TPC/Calib/AltroConfig"), new TObjString("contains the altro config, e.g. info about the L0 trigger timing"));
429   targetMap->Add(new TObjString("GRP/CTP/CTPtiming"),     new TObjString("content used in the cluster coordinate transformation in relation to the L0 trigger timing"));
430
431   // OCDB entries necessary for replaying data on the HLT cluster
432   targetMap->Add(new TObjString("GRP/GRP/Data"), new TObjString("contains magnetic field info"));  
433  
434   // OCDB entries needed to suppress fatals/errors/warnings during reconstruction
435   targetMap->Add(new TObjString("TPC/Calib/PadTime0"),    new TObjString("time0 offset pad by pad"));
436   targetMap->Add(new TObjString("TPC/Calib/PadNoise"),    new TObjString("pad noise values"));
437   targetMap->Add(new TObjString("TPC/Calib/Pedestals"),   new TObjString("pedestal info"));
438   targetMap->Add(new TObjString("TPC/Calib/Pulser"),      new TObjString("pulser info"));
439   targetMap->Add(new TObjString("TPC/Calib/CE"),          new TObjString("CE laser calibration result"));
440   targetMap->Add(new TObjString("TPC/Calib/Raw"),         new TObjString("unknown content"));
441   targetMap->Add(new TObjString("TPC/Calib/QA"),          new TObjString("not important"));
442   targetMap->Add(new TObjString("TPC/Calib/Mapping"),     new TObjString("unknown content"));
443   targetMap->Add(new TObjString("TPC/Calib/Goofie"),      new TObjString("Goofie values, not used at the moment (05.03.2010)"));
444   targetMap->Add(new TObjString("TPC/Calib/HighVoltage"), new TObjString("high voltage values, not used"));
445   targetMap->Add(new TObjString("TPC/Calib/Ref"),         new TObjString("unknown content"));
446 }