]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/TPCLib/AliHLTTPCHWClusterTransformComponent.cxx
ALIROOT-5433 Transition to CDHv3 in HLT
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCHWClusterTransformComponent.cxx
index f8b55a1ce42831db864a07badb5d7488fee18c9c..328229379206abc1a8640a54585484a0b4067104 100644 (file)
     @brief 
 */
 
-#if __GNUC__>= 3
-using namespace std;
-#endif
 #include "AliHLTTPCHWClusterTransformComponent.h"
 #include "AliHLTTPCDefinitions.h"
 #include "AliHLTTPCTransform.h"
 #include "AliHLTTPCSpacePointData.h"
 #include "AliHLTTPCClusterDataFormat.h"
-#include "AliRawDataHeader.h"
+#include "AliHLTCDHWrapper.h"
 #include "AliHLTTPCRawCluster.h"
 #include "AliHLTTPCHWCFEmulator.h"
 #include "AliHLTTPCHWCFData.h"
 #include "AliHLTErrorGuard.h"
+#include "AliTPCTransform.h"
 
 #include "AliCDBManager.h"
 #include "AliCDBEntry.h"
@@ -46,15 +44,18 @@ using namespace std;
 #include <cerrno>
 #include <sys/time.h>
 
+using namespace std;
+
 ClassImp(AliHLTTPCHWClusterTransformComponent) //ROOT macro for the implementation of ROOT specific class methods
 
 const char* AliHLTTPCHWClusterTransformComponent::fgkOCDBEntryHWTransform="HLT/ConfigTPC/TPCHWClusterTransform";
 
+AliHLTTPCClusterTransformation AliHLTTPCHWClusterTransformComponent::fgTransform;
+Bool_t AliHLTTPCHWClusterTransformComponent::fgTimeInitialisedFromEvent = 0;
+
 AliHLTTPCHWClusterTransformComponent::AliHLTTPCHWClusterTransformComponent()
 :
 fDataId(kFALSE),
-fChargeThreshold(10),
-fTransform(),
 fPublishRawClusters(kFALSE),
 fpDecoder(NULL),
 fBenchmark("HWClusterTransform")
@@ -117,8 +118,9 @@ AliHLTComponent* AliHLTTPCHWClusterTransformComponent::Spawn() {
   return new AliHLTTPCHWClusterTransformComponent();
 }
        
-int AliHLTTPCHWClusterTransformComponent::DoInit( int argc, const char** argv ) { 
-// see header file for class documentation
+int AliHLTTPCHWClusterTransformComponent::DoInit( int argc, const char** argv ) 
+{ 
+  // see header file for class documentation
   
   AliTPCcalibDB *calib=AliTPCcalibDB::Instance();  
   if(!calib){
@@ -127,12 +129,13 @@ int AliHLTTPCHWClusterTransformComponent::DoInit( int argc, const char** argv )
   }
   calib->SetRun(GetRunNo());
   calib->UpdateRunInformations(GetRunNo());
-
-  int err = fTransform.Init( GetBz(), GetTimeStamp() );
-
-  if( err!=0 ){
-    HLTError("Cannot retrieve offline transform from AliTPCcalibDB");
-    return -ENOENT;
+  
+  if( !fgTransform.IsInitialised() ){
+    int err = fgTransform.Init( GetBz(), GetTimeStamp() );
+    if( err!=0 ){
+      HLTError(Form("Cannot retrieve offline transform from AliTPCcalibDB, AliHLTTPCClusterTransformation returns %d",err));
+      return -ENOENT;
+    }
   }
 
   int iResult=0;
@@ -153,7 +156,7 @@ int AliHLTTPCHWClusterTransformComponent::DoDeinit() {
   // see header file for class documentation   
   if (!fpDecoder) delete fpDecoder;
   fpDecoder=NULL;
-
+  fgTransform.DeInit();
   return 0;
 }
 
@@ -163,20 +166,37 @@ int AliHLTTPCHWClusterTransformComponent::DoEvent(const AliHLTComponentEventData
                                                  AliHLTUInt32_t& size, 
                                                  vector<AliHLTComponentBlockData>& outputBlocks ){
   // see header file for class documentation
-   
   UInt_t maxOutSize = size;
   size = 0;
   int iResult = 0;
   if(!IsDataEvent()) return 0;
 
   if (!fpDecoder) return -ENODEV;
+  if( !fgTransform.IsInitialised() ){
+    HLTError(" TPC Transformation is not initialised ");
+    return -ENOENT;    
+  }
 
   fBenchmark.StartNewEvent();
   fBenchmark.Start(0);
 
-  fTransform.SetCurrentTimeStamp( GetTimeStamp() );
-  
-  for( unsigned long ndx=0; ndx<evtData.fBlockCnt; ndx++ ){
+  // Initialise the transformation here once more for the case of off-line reprocessing
+  if( !fgTimeInitialisedFromEvent ){
+    Long_t currentTime = static_cast<AliHLTUInt32_t>(time(NULL));
+    Long_t eventTimeStamp = GetTimeStamp();
+    if( TMath::Abs( fgTransform.GetCurrentTimeStamp() - eventTimeStamp )>60 && 
+       TMath::Abs( currentTime - eventTimeStamp)>60*60*5 ){
+      int err = fgTransform.SetCurrentTimeStamp( eventTimeStamp );
+      if( err!=0 ){
+       HLTError(Form("Cannot set time stamp, AliHLTTPCClusterTransformation returns %d",err));
+       return -ENOENT;
+      }
+    }
+    fgTimeInitialisedFromEvent = 1;
+  }
+
+ for( unsigned long ndx=0; ndx<evtData.fBlockCnt; ndx++ ){
      
     const AliHLTComponentBlockData *iter   = blocks+ndx;
     
@@ -234,15 +254,15 @@ int AliHLTTPCHWClusterTransformComponent::DoEvent(const AliHLTComponentEventData
     long maxPoints = ((long)maxOutSize-size-sizeof(AliHLTTPCClusterData))/sizeof(AliHLTTPCSpacePointData);
 
     AliHLTUInt32_t *buffer;     
-    buffer = (AliHLTUInt32_t*)iter->fPtr;  
+    buffer = (AliHLTUInt32_t*)iter->fPtr;
+    AliHLTCDHWrapper cdh(iter->fPtr);
      
      // skip the first 8 32-bit CDH words
-     buffer += 8;
-     UInt_t bufferSize32 = ((Int_t)iter->fSize - sizeof(AliRawDataHeader) )/sizeof(AliHLTUInt32_t);
+    buffer += cdh.GetHeaderSize()/sizeof(AliHLTUInt32_t);
+    UInt_t bufferSize32 = ((Int_t)iter->fSize - cdh.GetHeaderSize() )/sizeof(AliHLTUInt32_t);
 
      if (fpDecoder->Init(reinterpret_cast<AliHLTUInt8_t*>(buffer), bufferSize32*sizeof(AliHLTUInt32_t))>=0 && fpDecoder->CheckVersion()>=0) {
-       UInt_t nofClusters=fpDecoder->GetNumberOfClusters();
-       for (UInt_t cl=0; cl<nofClusters; cl++) {
+       for (AliHLTTPCHWCFData::iterator cl=fpDecoder->begin(); cl!=fpDecoder->end(); ++cl) {
         if(outPtr->fSpacePointCnt>=maxPoints){
           HLTWarning("No more space to add clusters, exiting!");
           iResult  = -ENOSPC;
@@ -250,35 +270,35 @@ int AliHLTTPCHWClusterTransformComponent::DoEvent(const AliHLTComponentEventData
         }
 
         AliHLTTPCSpacePointData& c=outPtr->fSpacePoints[outPtr->fSpacePointCnt];
-        int padrow=fpDecoder->GetPadRow(cl);
+        int padrow=cl.GetPadRow();
         if (padrow<0) {
           // something wrong here, padrow is stored in the cluster header
           // word which has bit pattern 0x3 in bits bit 30 and 31 which was
           // not recognized
-          ALIHLTERRORGUARD(1, "can not read cluster header word, skipping %d of %d cluster(s)", nofClusters-cl, nofClusters);
+          ALIHLTERRORGUARD(1, "can not read cluster header word");
           break;
         }
         padrow+=AliHLTTPCTransform::GetFirstRow(minPartition);
-        AliHLTUInt32_t charge=fpDecoder->GetCharge(cl);
-        // skip clusters below threshold  
-        if( charge<fChargeThreshold ) continue;  
-
-        float pad=fpDecoder->GetPad(cl);
-        float time=fpDecoder->GetTime(cl);
-        float sigmaY2=fpDecoder->GetSigmaY2(cl);
-        float sigmaZ2=fpDecoder->GetSigmaZ2(cl);
-        sigmaY2-=pad*pad;
+        AliHLTUInt32_t charge=cl.GetCharge();
+
+        float pad=cl.GetPad();
+        float time=cl.GetTime();
+        float sigmaY2=cl.GetSigmaY2();
+        float sigmaZ2=cl.GetSigmaZ2();
         sigmaY2*=padpitch*padpitch;
-        sigmaZ2-=time*time;
         sigmaZ2*=zwidth*zwidth;
         c.SetPadRow(padrow);
         c.SetCharge(charge);
         c.SetSigmaY2(sigmaY2);
         c.SetSigmaZ2(sigmaZ2);
-        c.SetQMax(fpDecoder->GetQMax(cl));
+        c.SetQMax(cl.GetQMax());
 
         Float_t xyz[3];
-        fTransform.Transform( minSlice, padrow, pad + 0.5, time, xyz );
+        int err = fgTransform.Transform( minSlice, padrow, pad, time, xyz );    
+        if( err!=0 ){
+          HLTWarning(Form("Cannot transform the cluster, AliHLTTPCClusterTransformation returns error %d, %s",err, fgTransform.GetLastError()));
+          continue;
+        }
         c.SetX(xyz[0]);
         c.SetY(xyz[1]);
         c.SetZ(xyz[2]);
@@ -327,15 +347,17 @@ int AliHLTTPCHWClusterTransformComponent::DoEvent(const AliHLTComponentEventData
         outputRaw->fVersion = 0;
         outputRaw->fCount = 0;
 
-        UInt_t nofClusters=fpDecoder->GetNumberOfClusters();
-        for (UInt_t cl=0; cl<nofClusters; cl++) {
+        // check if there are clusters available, if not the format might
+        // not even been decoded at that moment 
+        if (fpDecoder->GetNumberOfClusters()>0) {
+        for (AliHLTTPCHWCFData::iterator cl=fpDecoder->begin(); cl!=fpDecoder->end(); ++cl) {
           if(outputRaw->fCount>=maxRawClusters){
             HLTWarning("No more space to add clusters, exiting!");
             iResult  = -ENOSPC;
             break;
           }
           AliHLTTPCRawCluster &c = outputRaw->fClusters[outputRaw->fCount];
-          int padrow=fpDecoder->GetPadRow(cl);
+          int padrow=cl.GetPadRow();
           if (padrow<0) {
             // something wrong here, padrow is stored in the cluster header
             // word which has bit pattern 0x3 in bits bit 30 and 31 which was
@@ -343,27 +365,24 @@ int AliHLTTPCHWClusterTransformComponent::DoEvent(const AliHLTComponentEventData
             break;
           }
           padrow+=AliHLTTPCTransform::GetFirstRow(minPartition);
-          AliHLTUInt32_t charge= fpDecoder->GetCharge(cl);
-          // skip clusters below threshold  
-          if( charge<fChargeThreshold ) continue;  
-
-          float pad =fpDecoder->GetPad(cl);
-          float time =fpDecoder->GetTime(cl);
-          float sigmaP2=fpDecoder->GetSigmaY2(cl);
-          float sigmaT2=fpDecoder->GetSigmaZ2(cl);
-          sigmaP2-=pad*pad;
-          sigmaT2-=time*time;
+          AliHLTUInt32_t charge= cl.GetCharge();
+
+          float pad =cl.GetPad();
+          float time =cl.GetTime();
+          float sigmaP2=cl.GetSigmaY2();
+          float sigmaT2=cl.GetSigmaZ2();
           c.SetPadRow(padrow);
           c.SetCharge(charge);
           c.SetPad(pad);  
           c.SetTime(time);
           c.SetSigmaY2(sigmaP2);
           c.SetSigmaZ2(sigmaT2);
-          c.SetQMax(fpDecoder->GetQMax(cl));
+          c.SetQMax(cl.GetQMax());
 
           // store cluster and continue
           outputRaw->fCount++;
         }
+        }
 
         // fill into HLT output data
         AliHLTComponentBlockData bdRawClusters;
@@ -416,9 +435,8 @@ int AliHLTTPCHWClusterTransformComponent::ScanConfigurationArgument(int argc, co
   
   if (argument.CompareTo("-charge-threshold")==0) {
     if (++i>=argc) return -EPROTO;
-    argument=argv[i];
-    fChargeThreshold=(UInt_t)argument.Atoi();
-    HLTInfo("The charge threshold has been set to %d.", fChargeThreshold);
+    argument=argv[i];    
+    HLTInfo("The argument -charge-threshold is deprecated.");
     return 2;
   }    
 
@@ -475,10 +493,13 @@ void AliHLTTPCHWClusterTransformComponent::GetOCDBObjectDescription( TMap* const
   // OCDB entries to be fetched by the TAXI (access via the AliTPCcalibDB class)
   targetMap->Add(new TObjString("TPC/Calib/Parameters"),    new TObjString("unknown content"));
   targetMap->Add(new TObjString("TPC/Calib/TimeDrift"),     new TObjString("drift velocity calibration"));
+  targetMap->Add(new TObjString("TPC/Calib/TimeGain"),     new TObjString("time gain  calibration"));
   targetMap->Add(new TObjString("TPC/Calib/Temperature"),   new TObjString("temperature map"));
   targetMap->Add(new TObjString("TPC/Calib/PadGainFactor"), new TObjString("gain factor pad by pad"));
   targetMap->Add(new TObjString("TPC/Calib/ClusterParam"),  new TObjString("cluster parameters"));
-  
+  targetMap->Add(new TObjString("TPC/Calib/Correction"),  new TObjString("coreection"));
+  targetMap->Add(new TObjString("TPC/Calib/RecoParam"),  new TObjString("reconstruction parameters"));
   // OCDB entries needed to be fetched by the Pendolino
   targetMap->Add(new TObjString("TPC/Calib/AltroConfig"), new TObjString("contains the altro config, e.g. info about the L0 trigger timing"));
   targetMap->Add(new TObjString("GRP/CTP/CTPtiming"),     new TObjString("content used in the cluster coordinate transformation in relation to the L0 trigger timing"));
@@ -487,6 +508,8 @@ void AliHLTTPCHWClusterTransformComponent::GetOCDBObjectDescription( TMap* const
   targetMap->Add(new TObjString("GRP/GRP/Data"), new TObjString("contains magnetic field info"));  
  
   // OCDB entries needed to suppress fatals/errors/warnings during reconstruction
+  targetMap->Add(new TObjString("TPC/Calib/Distortion"),  new TObjString("distortion map"));
+  targetMap->Add(new TObjString("TPC/Calib/GainFactorDedx"), new TObjString("gain factor dedx"));
   targetMap->Add(new TObjString("TPC/Calib/PadTime0"),    new TObjString("time0 offset pad by pad"));
   targetMap->Add(new TObjString("TPC/Calib/PadNoise"),    new TObjString("pad noise values"));
   targetMap->Add(new TObjString("TPC/Calib/Pedestals"),   new TObjString("pedestal info"));