]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/PHOS/AliHLTPHOSDigitMakerComponent.cxx
ALIROOT-5600 - skip non-participating detector modules
[u/mrichter/AliRoot.git] / HLT / PHOS / AliHLTPHOSDigitMakerComponent.cxx
index 34a94113076109fb965112824b7d6acf1f0109d1..997a499094317630a0a8e2d606ec90b85a6980fc 100644 (file)
  **************************************************************************/
 
 #include "AliHLTPHOSDigitMakerComponent.h"
-#include "AliHLTPHOSDigitMaker.h"
-#include "TTree.h"
-#include "AliHLTPHOSProcessor.h"
-#include "AliHLTPHOSRcuCellEnergyDataStruct.h"
-#include "AliHLTPHOSDigitDataStruct.h"
-#include "AliHLTPHOSChannelDataHeaderStruct.h"
-#include "AliHLTPHOSChannelDataStruct.h"
-#include "TClonesArray.h"
+#include "AliHLTCaloDigitMaker.h"
+#include "AliHLTCaloDigitDataStruct.h"
+#include "AliHLTPHOSMapper.h"
+#include "AliHLTCaloChannelDataHeaderStruct.h"
+#include "AliHLTCaloChannelDataStruct.h"
+#include "AliPHOSEmcBadChannelsMap.h"
+#include "AliPHOSEmcCalibData.h"
 #include "TFile.h"
+#include "AliCDBEntry.h"
+#include "AliCDBPath.h"
+#include "AliCDBManager.h"
 #include <sys/stat.h>
 #include <sys/types.h>
 
 // or
 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
 
-
-const AliHLTComponentDataType AliHLTPHOSDigitMakerComponent::fgkInputDataTypes[]={kAliHLTVoidDataType,{0,"",""}};
-
-AliHLTPHOSDigitMakerComponent gAliHLTPHOSDigitMakerComponent;
+ClassImp(AliHLTPHOSDigitMakerComponent);
 
 AliHLTPHOSDigitMakerComponent::AliHLTPHOSDigitMakerComponent() :
-  AliHLTPHOSProcessor(),
+  AliHLTCaloProcessor(),
+  AliHLTCaloConstantsHandler("PHOS"),
   fDigitMakerPtr(0),
-  fDigitContainerPtr(0)
-  //  fEvtCnt(0)
+  fDigitContainerPtr(0),
+  fBadChannelMap(0),
+  fCalibData(0),
+  fBCMInitialised(true),
+  fGainsInitialised(true)
 {
   //see header file for documentation
 }
@@ -88,12 +91,6 @@ AliHLTPHOSDigitMakerComponent::GetInputDataTypes(vector<AliHLTComponentDataType>
   //see header file for documentation
   list.clear();
   list.push_back(AliHLTPHOSDefinitions::fgkChannelDataType);
-
-//   const AliHLTComponentDataType* pType=fgkInputDataTypes;
-//   while (pType->fID!=0) {
-//     list.push_back(*pType); 
-//     pType++;
-//   }
 }
 
 AliHLTComponentDataType 
@@ -109,7 +106,7 @@ AliHLTPHOSDigitMakerComponent::GetOutputDataSize(unsigned long& constBase, doubl
 {
   //see header file for documentation
   constBase = 0;
-  inputMultiplier = (float)sizeof(AliHLTPHOSDigitDataStruct)/sizeof(AliHLTPHOSChannelDataStruct) + 1;
+  inputMultiplier = (float)sizeof(AliHLTCaloDigitDataStruct)/sizeof(AliHLTCaloChannelDataStruct) + 1;
 }
 
 int 
@@ -123,30 +120,65 @@ AliHLTPHOSDigitMakerComponent::DoEvent(const AliHLTComponentEventData& evtData,
   Int_t digitCount        = 0;
   Int_t ret               = 0;
 
-  AliHLTUInt8_t* outBPtr;
-  outBPtr = outputPtr;
   const AliHLTComponentBlockData* iter = 0; 
   unsigned long ndx; 
 
   UInt_t specification = 0;
-  AliHLTPHOSChannelDataHeaderStruct* tmpChannelData = 0;
+  AliHLTCaloChannelDataHeaderStruct* tmpChannelData = 0;
   
-  fDigitMakerPtr->SetDigitDataPtr(reinterpret_cast<AliHLTPHOSDigitDataStruct*>(outputPtr));
+  //  fDigitMakerPtr->SetDigitHeaderPtr(reinterpret_cast<AliHLTCaloDigitHeaderStruct*>(outputPtr));
+
+  fDigitMakerPtr->SetDigitDataPtr(reinterpret_cast<AliHLTCaloDigitDataStruct*>(outputPtr));
 
   for( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
     {
+      
       iter = blocks+ndx;
       
       if(iter->fDataType != AliHLTPHOSDefinitions::fgkChannelDataType)
        {
-         HLTDebug("Data block is not of type fgkChannelDataType");
+//       HLTDebug("Data block is not of type fgkChannelDataType");
          continue;
        }
+      if(!fBCMInitialised)
+      {
+        AliHLTPHOSMapper mapper;
+        Int_t module = mapper.GetModuleFromSpec(iter->fSpecification);
+        if(module >= 0)
+          {
+            for(Int_t x = 0; x < fCaloConstants->GetNXCOLUMNSMOD(); x++)
+              {
+                for(Int_t z = 0; z < fCaloConstants->GetNZROWSMOD(); z++)
+                  {
+                    fDigitMakerPtr->SetBadChannel(x, z, fBadChannelMap->IsBadChannel(5-module, z+1, x+1));
+                  }
+              }
+        }
+        //delete fBadChannelMap;
+        fBCMInitialised = true;
+      }
+      if(!fGainsInitialised)
+      {
+        AliHLTPHOSMapper mapper;
+        Int_t module = mapper.GetModuleFromSpec(iter->fSpecification);
+        if(module >= 0 && module < 5)
+          {
+            for(Int_t x = 0; x < fCaloConstants->GetNXCOLUMNSMOD(); x++)
+              {
+                for(Int_t z = 0; z < fCaloConstants->GetNZROWSMOD(); z++)
+                  {
+                    fDigitMakerPtr->SetGain(x, z, fCalibData->GetHighLowRatioEmc(5-module, z+1, x+1), fCalibData->GetADCchannelEmc(5-module, z+1, x+1));
+                  }
+              }
+            fGainsInitialised = true;
+        }
+
+      }
 
       specification |= iter->fSpecification;
-      tmpChannelData = reinterpret_cast<AliHLTPHOSChannelDataHeaderStruct*>(iter->fPtr);
+      tmpChannelData = reinterpret_cast<AliHLTCaloChannelDataHeaderStruct*>(iter->fPtr);
     
-      ret = fDigitMakerPtr->MakeDigits(tmpChannelData, size-(digitCount*sizeof(AliHLTPHOSDigitDataStruct)));
+      ret = fDigitMakerPtr->MakeDigits(tmpChannelData, size-(digitCount*sizeof(AliHLTCaloDigitDataStruct)));
       if(ret == -1) 
        {
          HLTError("Trying to write over buffer size");
@@ -155,11 +187,10 @@ AliHLTPHOSDigitMakerComponent::DoEvent(const AliHLTComponentEventData& evtData,
       digitCount += ret; 
     }
   
-  mysize += digitCount*sizeof(AliHLTPHOSDigitDataStruct);
+  mysize += digitCount*sizeof(AliHLTCaloDigitDataStruct);
 
   HLTDebug("# of digits: %d, used memory size: %d, available size: %d", digitCount, mysize, size);
 
-
   if(mysize > 0) 
     {
       AliHLTComponentBlockData bd;
@@ -170,6 +201,7 @@ AliHLTPHOSDigitMakerComponent::DoEvent(const AliHLTComponentEventData& evtData,
       bd.fSpecification = specification;
       outputBlocks.push_back(bd);
     }
+
   fDigitMakerPtr->Reset();
 
   size = mysize; 
@@ -177,13 +209,18 @@ AliHLTPHOSDigitMakerComponent::DoEvent(const AliHLTComponentEventData& evtData,
   return 0;
 }
 
-
 int
 AliHLTPHOSDigitMakerComponent::DoInit(int argc, const char** argv )
 {
   //see header file for documentation
 
-  fDigitMakerPtr = new AliHLTPHOSDigitMaker();
+  fDigitMakerPtr = new AliHLTCaloDigitMaker("PHOS");
+
+  AliHLTCaloMapper *mapper = new AliHLTPHOSMapper();
+  fDigitMakerPtr->SetMapper(mapper);
+  
+  Float_t mintime = 0.;
+  Float_t maxtime =50.;
   
   for(int i = 0; i < argc; i++)
     {
@@ -195,17 +232,80 @@ AliHLTPHOSDigitMakerComponent::DoInit(int argc, const char** argv )
        {
          fDigitMakerPtr->SetGlobalHighGainFactor(atof(argv[i+1]));
        }
-      if(!strcmp("-reverseorder", argv[i]))
+       if(!strcmp("-mintime", argv[i]))
        {
-         fDigitMakerPtr->SetOrdered(false);
+          mintime = atof(argv[i+1]);
+       }
+       if(!strcmp("-maxtime", argv[i]))
+       {
+          maxtime = atof(argv[i+1]);
        }
     }
  
+ fDigitMakerPtr->SetTimeWindow(mintime, maxtime);
+
+ if(GetBCMFromCDB()) return -1;
+ if(GetGainsFromCDB()) return -1;
+  
   //fDigitMakerPtr->SetDigitThreshold(2);
 
   return 0;
 }
 
+
+int AliHLTPHOSDigitMakerComponent::GetBCMFromCDB()
+{
+   fBCMInitialised = false;
+   
+//   HLTInfo("Getting bad channel map...");
+
+  AliCDBPath path("PHOS","Calib","EmcBadChannels");
+  if(path.GetPath())
+    {
+      //      HLTInfo("configure from entry %s", path.GetPath());
+      AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
+       if (pEntry) 
+       {
+           fBadChannelMap = (AliPHOSEmcBadChannelsMap*)pEntry->GetObject();
+       }
+      else
+       {
+           HLTError("can not fetch object \"%s\" from CDB", path.GetPath().Data());
+           return -1;
+       }
+    }
+   if(!fBadChannelMap) return -1;
+   return 0;
+}
+
+int AliHLTPHOSDigitMakerComponent::GetGainsFromCDB()
+{
+   fGainsInitialised = false;
+   
+//   HLTInfo("Getting bad channel map...");
+
+  AliCDBPath path("PHOS","Calib","EmcGainPedestals");
+  if(path.GetPath())
+    {
+      //      HLTInfo("configure from entry %s", path.GetPath());*/
+      AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
+      if (pEntry) 
+       {
+           fCalibData = (AliPHOSEmcCalibData*)pEntry->GetObject();
+       }
+      else     
+       {
+           HLTError("can not fetch object \"%s\" from CDB", path.GetPath().Data());
+           return -1;
+       }
+    }
+    
+    if(!fCalibData) return -1;
+   return 0;
+   
+}
+
+
 AliHLTComponent*
 AliHLTPHOSDigitMakerComponent::Spawn()
 {