]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/TPCLib/AliHLTTPCHWClusterTransformComponent.cxx
cmake update (Oystein)
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCHWClusterTransformComponent.cxx
index 7aa28d7b8ab78cdd8ee141130d32ae3de86607ae..86afeb5b70bef8eb0fcfeb3b88400cdea5a41bb9 100644 (file)
@@ -1,3 +1,4 @@
+// $Id$
 
 //**************************************************************************
 //* This file is property of and copyright by the ALICE HLT Project        *
@@ -30,19 +31,34 @@ using namespace std;
 #include "AliHLTTPCSpacePointData.h"
 #include "AliHLTTPCClusterDataFormat.h"
 
+#include "AliTPCcalibDB.h"
+#include "AliTPCTransform.h"
+#include "AliTPCCalPad.h"
+
+#include "AliCDBManager.h"
+#include "AliCDBEntry.h"
+
+#include "TMath.h"
+#include "TObjString.h" 
 #include <cstdlib>
 #include <cerrno>
 #include <sys/time.h>
 
 ClassImp(AliHLTTPCHWClusterTransformComponent) //ROOT macro for the implementation of ROOT specific class methods
 
+const char* AliHLTTPCHWClusterTransformComponent::fgkOCDBEntryHWTransform="HLT/ConfigTPC/TPCHWClusterTransform";
+
 AliHLTTPCHWClusterTransformComponent::AliHLTTPCHWClusterTransformComponent()
+:
+fOfflineTransform(NULL),
+fDataId(kFALSE),
+fOfflineTPCRecoParam()
 {
   // see header file for class documentation
   // or
   // refer to README to build package
   // or
-  // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
+  // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt  
 }
 
 AliHLTTPCHWClusterTransformComponent::~AliHLTTPCHWClusterTransformComponent() { 
@@ -78,9 +94,8 @@ int AliHLTTPCHWClusterTransformComponent::GetOutputDataTypes(AliHLTComponentData
 
 void AliHLTTPCHWClusterTransformComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) { 
   // see header file for class documentation
-
   constBase = 0;
-  inputMultiplier = 2.0;
+  inputMultiplier = 3.0;
 }
 
 AliHLTComponent* AliHLTTPCHWClusterTransformComponent::Spawn() { 
@@ -89,30 +104,52 @@ AliHLTComponent* AliHLTTPCHWClusterTransformComponent::Spawn() {
   return new AliHLTTPCHWClusterTransformComponent();
 }
        
-int AliHLTTPCHWClusterTransformComponent::DoInit( int /*argc*/, const char** /*argv*/ ) { 
+int AliHLTTPCHWClusterTransformComponent::DoInit( int argc, const char** argv ) { 
 // see header file for class documentation
 
-//   Int_t i = 0;
-//   Char_t* cpErr;
-//   
-//   int iResult=0;
-//   
-//   TString configuration="";
-//   TString argument="";
-//   for (int j=0; j<argc && iResult>=0; j++) {
-//     
-//     argument=argv[j];
-//     if (!configuration.IsNull()) configuration+=" ";
-//     configuration+=argument;    
-//   }
-//    
-//   if (!configuration.IsNull()) {
-//     iResult=Configure(configuration.Data());
-//   } else {
-//     iResult=Reconfigure(NULL, NULL);
-//   }
+  AliTPCcalibDB* pCalib=AliTPCcalibDB::Instance();
+  if(!pCalib ||
+     !(fOfflineTransform = AliTPCcalibDB::Instance()->GetTransform())){
+    HLTError("Cannot retrieve offline transform from AliTPCcalibDB (%p)", pCalib);
+    return -ENOENT;
+  }
+  // set the flags in the reco param
+  fOfflineTPCRecoParam.SetUseExBCorrection(1);
+  fOfflineTPCRecoParam.SetUseTOFCorrection(1);
+  fOfflineTransform->SetCurrentRecoParam(&fOfflineTPCRecoParam);
+  
+  pCalib->SetExBField(GetBz());
+  
+  //Int_t i = 0;
+  //Char_t* cpErr;
+
+  int iResult=0;
+
+  iResult = ConfigureFromCDBTObjString(fgkOCDBEntryHWTransform);
+
+  if (iResult>=0 && argc>0)
+    iResult=ConfigureFromArgumentString(argc, argv);
+
+  return iResult;
 
+  /*
+  TString configuration="";
+  TString argument="";
+  for(int j=0; j<argc && iResult>=0; j++){
+      argument=argv[j];
+      if (!configuration.IsNull()) configuration+=" ";
+      configuration+=argument; 
+  }
+  
+  if (!configuration.IsNull()) {
+    iResult=Configure(configuration.Data());
+  } 
+  else {
+    //iResult=Reconfigure(NULL, NULL);
+  }
+  
   return 0;
+  */
 } // end DoInit()
 
 int AliHLTTPCHWClusterTransformComponent::DoDeinit() { 
@@ -122,17 +159,15 @@ int AliHLTTPCHWClusterTransformComponent::DoDeinit() {
 }
 
 int AliHLTTPCHWClusterTransformComponent::DoEvent(const AliHLTComponentEventData& evtData, 
-                                             const AliHLTComponentBlockData* blocks, 
-                                             AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr, 
-                                             AliHLTUInt32_t& size, 
-                                             vector<AliHLTComponentBlockData>& outputBlocks ){
+                                                 const AliHLTComponentBlockData* blocks, 
+                                                 AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr, 
+                                                 AliHLTUInt32_t& size, 
+                                                 vector<AliHLTComponentBlockData>& outputBlocks ){
   // see header file for class documentation
-    
   if(GetFirstInputBlock( kAliHLTDataTypeSOR ) || GetFirstInputBlock( kAliHLTDataTypeEOR )){
      size = 0;
      return 0;
   }
-
   const AliHLTComponentBlockData *iter = NULL;    
   unsigned long ndx;
 
@@ -155,9 +190,9 @@ int AliHLTTPCHWClusterTransformComponent::DoEvent(const AliHLTComponentEventData
      offset = tSize;
  
      HLTDebug("Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
-             evtData.fEventID, evtData.fEventID, 
-             DataType2Text( iter->fDataType).c_str(), 
-             DataType2Text(AliHLTTPCDefinitions::fgkHWClustersDataType).c_str());                       
+              evtData.fEventID, evtData.fEventID, 
+              DataType2Text( iter->fDataType).c_str(), 
+              DataType2Text(AliHLTTPCDefinitions::fgkHWClustersDataType).c_str());                       
  
      if(iter->fDataType != AliHLTTPCDefinitions::fgkHWClustersDataType) continue;                        
   
@@ -165,6 +200,8 @@ int AliHLTTPCHWClusterTransformComponent::DoEvent(const AliHLTComponentEventData
      UInt_t minPartition = AliHLTTPCDefinitions::GetMinPatchNr(*iter);
      //UInt_t maxSlice     = AliHLTTPCDefinitions::GetMaxSliceNr(*iter); 
      //UInt_t maxPartition = AliHLTTPCDefinitions::GetMaxPatchNr(*iter);
+     
+     HLTDebug("minSlice: %d, minPartition: %d", minSlice, minPartition);
     
      outPtr = (AliHLTTPCClusterData*)outBPtr;
      maxPoints = (size-tSize-sizeof(AliHLTTPCClusterData))/sizeof(AliHLTTPCSpacePointData);
@@ -211,6 +248,7 @@ int AliHLTTPCHWClusterTransformComponent::DoEvent(const AliHLTComponentEventData
        // check if bit 31 and 30 of the 32-bit word is 11 -> cluster (10 is RCU trailer)
        AliHLTUInt32_t bit3130 = (buffer[nWords]>>30); // shift 30 to the right
        
+
        if(bit3130 == 0x3){ //beginning of a cluster
 
           //PrintDebug(&buffer[nWords], 5);
@@ -222,28 +260,56 @@ int AliHLTTPCHWClusterTransformComponent::DoEvent(const AliHLTComponentEventData
           
           AliHLTTPCSpacePointData cluster = { 0.,0.,0.,0,0,0.,0.,0,0,kFALSE,0 };
               
+
           //get the first word
           AliHLTUInt32_t  rowCharge = buffer[nWords];
           AliHLTUInt8_t  *rowPtr    = reinterpret_cast<AliHLTUInt8_t*>(&rowCharge);      
           rowPtr+=3; // this is to run for little endian architecture, the word is read from right to left
+
        
           cluster.fPadRow  = (UChar_t)((*rowPtr)&0x3f);
-          cluster.fCharge  = (UInt_t)rowCharge&0xFFFFFF; //24-bit mask to get out the charge
-          cluster.fSigmaY2 = (Float_t)buffer[nWords+3];
-          cluster.fSigmaZ2 = (Float_t)buffer[nWords+4];
-                  
+          cluster.fCharge  = ((UInt_t)rowCharge&0xFFFFFF)>>6; //24-bit mask to get out the charge and division with 64(>>6) for the gain correction
+
+
+          Float_t tmpPad   = *((Float_t*)&buffer[nWords+1]);
+          Float_t tmpTime  = *((Float_t*)&buffer[nWords+2]);
+          //cluster.fSigmaY2 = *((Float_t*)&buffer[nWords+3]);
+          //cluster.fSigmaZ2 = *((Float_t*)&buffer[nWords+4]);
+          
+          // correct expressions for the error calculation
+          // 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.
+          // cluster.fSigmaY2 = TMath::Sqrt( *((Float_t*)&buffer[nWords+3]) - *((Float_t*)&buffer[nWords+1])* (*((Float_t*)&buffer[nWords+1])) );
+          // cluster.fSigmaZ2 = TMath::Sqrt( *((Float_t*)&buffer[nWords+3]) - *((Float_t*)&buffer[nWords+1])* (*((Float_t*)&buffer[nWords+1])) );
+
           Float_t xyz[3]; xyz[0] = xyz[1] = xyz[2] = -99.;
-                  
-          cluster.fPadRow += AliHLTTPCTransform::GetFirstRow(minPartition);                       
-          AliHLTTPCTransform::Slice2Sector(minSlice, cluster.fPadRow, sector, thisrow);              
-          AliHLTTPCTransform::Raw2Local(xyz, sector, thisrow, (Float_t)buffer[nWords+1], (Float_t)buffer[nWords+2]);              
-          
-          cluster.fX = xyz[0];
-          cluster.fY = xyz[1];
-          cluster.fZ = xyz[2]; 
+                  
+          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);                   
           
-          HLTDebug("X: %f, Y: %f, Z: %f, Charge: %d", cluster.fX,cluster.fY,cluster.fZ, cluster.fCharge);           
+
+          if(fOfflineTransform == NULL){                  
+
+             cluster.fPadRow += AliHLTTPCTransform::GetFirstRow(minPartition);                    
+             AliHLTTPCTransform::Slice2Sector(minSlice, cluster.fPadRow, sector, thisrow);           
+             AliHLTTPCTransform::Raw2Local(xyz, sector, thisrow, tmpPad, tmpTime); 
+             if(minSlice>17) xyz[1]=(-1)*xyz[1];          
+             cluster.fX = xyz[0];
+             cluster.fY = xyz[1];
+             cluster.fZ = xyz[2]; 
+             
+
+          } else {
+            cluster.fPadRow += AliHLTTPCTransform::GetFirstRow(minPartition);                     
+            AliHLTTPCTransform::Slice2Sector(minSlice, (UInt_t)cluster.fPadRow, sector, thisrow);            
+            Double_t x[3] = {(Double_t)cluster.fPadRow,tmpPad+.5,tmpTime}; 
+            Int_t iSector[1]= {sector};
+            fOfflineTransform->Transform(x,iSector,0,1);
+            cluster.fX = x[0];
+            cluster.fY = x[1];
+            cluster.fZ = x[2];       
+          }
           
+
+          HLTDebug("cluster X: %f, Y: %f, Z: %f \n", cluster.fX, cluster.fY, cluster.fZ);
           spacePoints[nAddedClusters] = cluster;
                   
            nAddedClusters++; 
@@ -264,7 +330,12 @@ int AliHLTTPCHWClusterTransformComponent::DoEvent(const AliHLTComponentEventData
      bd.fOffset = offset;
      bd.fSize = mysize;
      bd.fSpecification = iter->fSpecification;
-     bd.fDataType = AliHLTTPCDefinitions::fgkClustersDataType;
+     
+     if(fDataId==kFALSE) bd.fDataType = AliHLTTPCDefinitions::fgkClustersDataType;
+     else                bd.fDataType = AliHLTTPCDefinitions::fgkAlterClustersDataType;
+     
+     //HLTDebug("datatype: %s", DataType2Text(bd.fDataType).c_str());
+     
      outputBlocks.push_back( bd );
      
      tSize   += mysize;
@@ -275,88 +346,83 @@ int AliHLTTPCHWClusterTransformComponent::DoEvent(const AliHLTComponentEventData
    size = tSize;
    return 0;
 } // end DoEvent()
+
+int AliHLTTPCHWClusterTransformComponent::ScanConfigurationArgument(int argc, const char** argv){
+
+  // see header file for class documentation
+
+  if (argc<=0) return 0;
+  int i=0;
+  TString argument=argv[i];
+
+  if (argument.CompareTo("-solenoidBz")==0){
+    if (++i>=argc) return -EPROTO;
+    argument=argv[i];
+    AliTPCcalibDB*  calib=AliTPCcalibDB::Instance();
+    if(!calib){
+      HLTError("CalibDB not availible");
+    }
+    Float_t magneticField = argument.Atof();
+    calib->SetExBField(magneticField);
+    HLTInfo("SolenoidBz is set to %f in the calibDB",magneticField);
+    return 2;
+  }
+
+  if (argument.CompareTo("-change-dataId")==0){
+    HLTDebug("Change data ID received.");
+    fDataId = kTRUE;
+    return 1;
+  }
+
+  // unknown argument
+  return -EINVAL;
+}
+
+
+  
+int AliHLTTPCHWClusterTransformComponent::Configure(const char* arguments) { 
+  // see header file for class documentation
+  
+  int iResult=0;
+  if (!arguments) return iResult;
+  HLTInfo("parsing configuration string \'%s\'", arguments);
+
+  TString allArgs=arguments;
+  TString argument;
+  int bMissingParam=0;
+
+  TObjArray* pTokens=allArgs.Tokenize(" ");
+  if (pTokens) {
+    for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
+      argument=((TObjString*)pTokens->At(i))->GetString();
+      if (argument.IsNull()) continue;
+     
+      if (argument.CompareTo("-change-dataId")==0) {
+       fDataId = kTRUE;
+       HLTInfo("got \'-change-dataId\': %s", ((TObjString*)pTokens->At(i))->GetString().Data());       
+      } 
+      else {
+       HLTError("unknown argument %s", argument.Data());
+       iResult=-EINVAL;
+       break;
+      }
+    } // end for
   
-// int AliHLTTPCHWClusterTransformComponent::Configure(const char* arguments) { 
-//   // see header file for class documentation
-//   
-//   int iResult=0;
-//   if (!arguments) return iResult;
-//   HLTInfo("parsing configuration string \'%s\'", arguments);
-// 
-//   TString allArgs=arguments;
-//   TString argument;
-//   int bMissingParam=0;
-// 
-//   TObjArray* pTokens=allArgs.Tokenize(" ");
-//   if (pTokens) {
-//     for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
-//       argument=((TObjString*)pTokens->At(i))->GetString();
-//       if (argument.IsNull()) continue;
-//      
-//       if (argument.CompareTo("-sum-noise-histograms")==0) {
-//     fNoiseHistograms = kTRUE;
-//     HLTInfo("got \'-sum-noise-histograms\': %s", ((TObjString*)pTokens->At(i))->GetString().Data());
-//     
-//       } else if (argument.CompareTo("-sum-krypton-histograms")==0) {
-//     fKryptonHistograms = kTRUE;
-//     HLTInfo("got \'-sum-krypton-histograms\': %s", ((TObjString*)pTokens->At(i))->GetString().Data());
-//     
-//       } else if (argument.CompareTo("-use-general")==0) {
-//     fUseGeneral = kTRUE;
-//     HLTInfo("got \'-use-general\': %s", ((TObjString*)pTokens->At(i))->GetString().Data());
-//     
-//       } else if (argument.CompareTo("-ignore-specification")==0) {
-//     fIgnoreSpecification = kTRUE;
-//     HLTInfo("got \'-ignore-specification\': %s", ((TObjString*)pTokens->At(i))->GetString().Data());
-//       }
-//       else {
-//     HLTError("unknown argument %s", argument.Data());
-//     iResult=-EINVAL;
-//     break;
-//       }
-//     } // end for
-//     
-//   
-//     delete pTokens;
-//   
-//   } // end if pTokens
-//   
-//   if (bMissingParam) {
-//     HLTError("missing parameter for argument %s", argument.Data());
-//     iResult=-EINVAL;
-//   }
-//   return iResult;
-// }
-
-// int AliHLTTPCHWClusterTransformComponent::Reconfigure(const char* /*cdbEntry*/, const char* /*chainId*/) { 
-//   // see header file for class documentation
-// 
-//   int iResult=0;
-//   const char* path="HLT/ConfigTPC/TPCHistogramHandlerComponent";
-//   const char* defaultNotify="";
-//   if (cdbEntry) {
-//     path=cdbEntry;
-//     defaultNotify=" (default)";
-//   }
-//   
-//   if (path) {
-//     HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
-//     AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
-//     if (pEntry) {
-//       TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
-//       if (pString) {
-//     HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
-//     iResult=Configure(pString->GetString().Data());
-//       } else {
-//     HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
-//       }
-//     } else {
-//       HLTError("cannot fetch object \"%s\" from CDB", path);
-//     }
-//   }
-//   return iResult;
-// }
+    delete pTokens;
+  
+  } // end if pTokens
+  
+  if (bMissingParam) {
+    HLTError("missing parameter for argument %s", argument.Data());
+    iResult=-EINVAL;
+  }
+  return iResult;
+}
 
+int AliHLTTPCHWClusterTransformComponent::Reconfigure(const char* /*cdbEntry*/, const char* /*chainId*/) { 
+  // see header file for class documentation
+  return ConfigureFromCDBTObjString(fgkOCDBEntryHWTransform);
+}
 
 void AliHLTTPCHWClusterTransformComponent::PrintDebug(AliHLTUInt32_t *buffer, Int_t size){
 // see header file for class documentation