LCOV - code coverage report
Current view: top level - HLT/EMCAL - AliHLTEMCALDigitMakerComponent.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 15 115 13.0 %
Date: 2016-06-14 17:26:59 Functions: 7 17 41.2 %

          Line data    Source code
       1             : // $Id$
       2             : 
       3             : /**************************************************************************
       4             :  * This file is property of and copyright by the ALICE HLT Project        *
       5             :  * All rights reserved.                                                   *
       6             :  *                                                                        *
       7             :  * Primary Authors: Oystein Djuvsland                                     *
       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             : #include "AliHLTEMCALDigitMakerComponent.h"
      18             : #include "AliHLTCaloDigitMaker.h"
      19             : #include "AliHLTCaloDigitDataStruct.h"
      20             : #include "AliHLTCaloChannelDataHeaderStruct.h"
      21             : #include "AliHLTCaloChannelDataStruct.h"
      22             : #include "AliHLTEMCALMapper.h"
      23             : #include "AliHLTEMCALDefinitions.h"
      24             : #include "AliCaloCalibPedestal.h"
      25             : #include "AliEMCALCalibData.h"
      26             : #include "AliCDBEntry.h"
      27             : #include "AliCDBPath.h"
      28             : #include "AliCDBManager.h"
      29             : #include "TFile.h"
      30             : #include <sys/stat.h>
      31             : #include <sys/types.h>
      32             : 
      33             : //#include "AliHLTEMCALConstant.h"
      34             : #include "AliHLTCaloConstants.h"
      35             : 
      36             : using EMCAL::NZROWSMOD;
      37             : using EMCAL::NXCOLUMNSMOD;  
      38             : using EMCAL::NMODULES;
      39             : using CALO::HGLGFACTOR;
      40             : 
      41             : /** 
      42             :  * @file   AliHLTEMCALDigitMakerComponent.cxx
      43             :  * @author Oystein Djuvsland
      44             :  * @date   
      45             :  * @brief  A digit maker component for EMCAL HLT
      46             :  */
      47             : 
      48             : // see below for class documentation
      49             : // or
      50             : // refer to README to build package
      51             : // or
      52             : // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
      53             : 
      54             : 
      55           6 : ClassImp(AliHLTEMCALDigitMakerComponent)
      56             : 
      57           6 : AliHLTEMCALDigitMakerComponent gAliHLTEMCALDigitMakerComponent;
      58             : 
      59             : AliHLTEMCALDigitMakerComponent::AliHLTEMCALDigitMakerComponent() :
      60           6 :       AliHLTCaloProcessor(),
      61             :       //  AliHLTCaloConstantsHandler("EMCAL"),
      62           6 :       fDigitContainerPtr(0),
      63           6 :       fPedestalData(0),
      64           6 :       fCalibData(0)
      65          30 : {
      66             : 
      67             :   //see header file for documentation
      68         252 :   for(int imod = 0; imod < NMODULES; imod++){
      69         120 :     fDigitMakerPtr[imod] = NULL;
      70         120 :     fBCMInitialised[imod] = true;
      71         120 :     fGainsInitialised[imod] = true;
      72             :   }
      73          12 : }
      74             : 
      75             : 
      76             : AliHLTEMCALDigitMakerComponent::~AliHLTEMCALDigitMakerComponent()
      77           6 : {
      78             :   //see header file for documentation
      79           9 : }
      80             : 
      81             : int 
      82             : AliHLTEMCALDigitMakerComponent::Deinit()
      83             : { 
      84             :   //see header file for documentation
      85           0 :   for(int imod = 0; imod < NMODULES; imod++){
      86           0 :     if(fDigitMakerPtr[imod])
      87             :     {
      88           0 :       delete fDigitMakerPtr[imod];
      89           0 :       fDigitMakerPtr[imod] = 0;
      90           0 :     }
      91             :   }
      92           0 :   return 0;
      93             : }
      94             : 
      95             : const char*
      96             : AliHLTEMCALDigitMakerComponent::GetComponentID()
      97             : {
      98             :   //see header file for documentation
      99         360 :   return "EmcalDigitMaker";
     100             : }
     101             : 
     102             : 
     103             : void
     104             : AliHLTEMCALDigitMakerComponent::GetInputDataTypes(vector<AliHLTComponentDataType>& list)
     105             : { 
     106             :   //see header file for documentation
     107           0 :   list.clear();
     108           0 :   list.push_back(AliHLTEMCALDefinitions::fgkChannelDataType);
     109           0 : }
     110             : 
     111             : AliHLTComponentDataType 
     112             : AliHLTEMCALDigitMakerComponent::GetOutputDataType()
     113             : {
     114             :   //see header file for documentation
     115             :   //  return AliHLTCaloDefinitions::fgkDigitDataType|kAliHLTDataOriginEMCAL;
     116           0 :   return AliHLTEMCALDefinitions::fgkDigitDataType;
     117             : }
     118             : 
     119             : 
     120             : void 
     121             : AliHLTEMCALDigitMakerComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier)
     122             : {
     123             :   //see header file for documentation
     124           0 :   constBase = 0;
     125           0 :   inputMultiplier = (float)sizeof(AliHLTCaloDigitDataStruct)/sizeof(AliHLTCaloChannelDataStruct) + 1;
     126           0 : }
     127             : 
     128             : 
     129             : 
     130             : int 
     131             : AliHLTEMCALDigitMakerComponent::DoEvent(const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
     132             :     AliHLTComponentTriggerData& /* trigData */, AliHLTUInt8_t* outputPtr, AliHLTUInt32_t& size,
     133             :     std::vector<AliHLTComponentBlockData>& outputBlocks)
     134             : {
     135             :   //patch in order to skip calib events
     136           0 :   if(! IsDataEvent()) return 0;
     137             : 
     138             :   //see header file for documentation
     139             :   UInt_t offset           = 0; 
     140             :   UInt_t mysize           = 0;
     141             :   Int_t digitCount        = 0;
     142             :   Int_t ret               = 0;
     143             : 
     144             :   const AliHLTComponentBlockData* iter = 0; 
     145             :   unsigned long ndx; 
     146             : 
     147             :   UInt_t specification = 0;
     148             :   AliHLTCaloChannelDataHeaderStruct* tmpChannelData = 0;
     149             : 
     150             :   Int_t moduleID;
     151             : 
     152           0 :   for( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
     153             :   {
     154           0 :     iter = blocks+ndx;
     155             : 
     156           0 :     if(iter->fDataType != AliHLTEMCALDefinitions::fgkChannelDataType) continue;
     157             : 
     158           0 :     if(iter->fSpecification >= 40) continue;   // Do not use inactive DDLs
     159           0 :     moduleID = int(iter->fSpecification/2);
     160             : 
     161           0 :     if(!fBCMInitialised[moduleID]){
     162           0 :       if(moduleID > -1){
     163           0 :         for(Int_t x = 0; x < NXCOLUMNSMOD ; x++) // PTH
     164           0 :           for(Int_t z = 0; z <  NZROWSMOD ; z++) // PTH
     165           0 :             fDigitMakerPtr[moduleID]->SetBadChannel(x, z, fPedestalData->IsBadChannel(moduleID, z, x)); // FR
     166             :           //delete fBadChannelMap;
     167           0 :         fBCMInitialised[moduleID] = true;
     168           0 :       } else
     169           0 :         HLTError("Error setting pedestal with module value of %d", moduleID);
     170             :     }
     171             : 
     172           0 :     if(!fGainsInitialised[moduleID]){
     173           0 :       if(moduleID > -1){
     174           0 :         for(Int_t x = 0; x < NXCOLUMNSMOD; x++)   //PTH
     175           0 :           for(Int_t z = 0; z < NZROWSMOD; z++)   //PTH
     176             :             // FR setting gains
     177           0 :             fDigitMakerPtr[moduleID]->SetGain(x, z, HGLGFACTOR, fCalibData->GetADCchannel(moduleID, z, x));
     178             : 
     179           0 :         fGainsInitialised[moduleID] = true;
     180           0 :       }
     181             :       else
     182           0 :         HLTError("Error setting gains with module value of %d", moduleID);
     183             :     }
     184             : 
     185           0 :     tmpChannelData = reinterpret_cast<AliHLTCaloChannelDataHeaderStruct*>(iter->fPtr);
     186             : 
     187           0 :     fDigitMakerPtr[moduleID]->SetDigitDataPtr(reinterpret_cast<AliHLTCaloDigitDataStruct*>(outputPtr));
     188           0 :     ret = fDigitMakerPtr[moduleID]->MakeDigits(tmpChannelData, size-(digitCount*sizeof(AliHLTCaloDigitDataStruct)));
     189             : 
     190             :     HLTDebug("Found %d digits", ret);
     191             : 
     192           0 :     if(ret == -1) {
     193           0 :       HLTError("Trying to write over buffer size");
     194           0 :       return -ENOBUFS;
     195             :     }
     196           0 :     digitCount += ret;
     197           0 :     outputPtr += sizeof(AliHLTCaloDigitDataStruct) * ret; // forward pointer
     198           0 :   }
     199             : 
     200           0 :   mysize += digitCount*sizeof(AliHLTCaloDigitDataStruct);
     201             : 
     202             :   HLTDebug("# of digits: %d, used memory size: %d, available size: %d", digitCount, mysize, size);
     203             : 
     204           0 :   if(mysize > 0) {
     205           0 :     AliHLTComponentBlockData bd;
     206           0 :     FillBlockData( bd );
     207           0 :     bd.fOffset = offset;
     208           0 :     bd.fSize = mysize;
     209           0 :     bd.fDataType = AliHLTEMCALDefinitions::fgkDigitDataType;
     210           0 :     bd.fSpecification = 0;
     211           0 :     outputBlocks.push_back(bd);
     212           0 :   }
     213             : 
     214           0 :   for(Int_t imod = 0; imod < NMODULES; imod++) fDigitMakerPtr[imod]->Reset();
     215             : 
     216           0 :   size = mysize; 
     217             : 
     218           0 :   return 0;
     219           0 : }
     220             : 
     221             : 
     222             : int
     223             : AliHLTEMCALDigitMakerComponent::DoInit(int argc, const char** argv )
     224             : {
     225             :   //see header file for documentation
     226             : 
     227           0 :   for(Int_t imod = 0; imod < NMODULES; imod++){
     228           0 :     fDigitMakerPtr[imod] = new AliHLTCaloDigitMaker("EMCAL");
     229             : 
     230           0 :     AliHLTCaloMapper *mapper = new AliHLTEMCALMapper(2);
     231           0 :     fDigitMakerPtr[imod]->SetMapper(mapper);
     232             : 
     233           0 :     for(int i = 0; i < argc; i++) {
     234           0 :       if(!strcmp("-lowgainfactor", argv[i])) {
     235           0 :         fDigitMakerPtr[imod]->SetGlobalLowGainFactor(atof(argv[i+1]));
     236           0 :       }
     237           0 :       if(!strcmp("-highgainfactor", argv[i])) {
     238           0 :         fDigitMakerPtr[imod]->SetGlobalHighGainFactor(atof(argv[i+1]));
     239           0 :       }
     240             :     }
     241             :   }
     242             : 
     243             : 
     244           0 :   if (GetBCMFromCDB()) 
     245           0 :     return -1;
     246             : 
     247           0 :   if (GetGainsFromCDB()) 
     248           0 :     return -1; 
     249             : 
     250             :   //GetBCMFromCDB();
     251             :   //fDigitMakerPtr->SetDigitThreshold(2);
     252             : 
     253           0 :   return 0;
     254           0 : }
     255             : 
     256             : 
     257             : int AliHLTEMCALDigitMakerComponent::GetBCMFromCDB()
     258             : {
     259             :   // See header file for class documentation
     260           0 :   for(Int_t imod = 0; imod < 20; imod++) fBCMInitialised[imod] = false;
     261             :   //   HLTInfo("Getting bad channel map...");
     262           0 :   AliCDBPath path("EMCAL","Calib","Pedestals");
     263           0 :   if(path.GetPath())
     264             :   {
     265             :     //      HLTInfo("configure from entry %s", path.GetPath());
     266           0 :     AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
     267           0 :     if (pEntry)
     268             :     {
     269           0 :       fPedestalData = (AliCaloCalibPedestal*)pEntry->GetObject();
     270             :     }
     271             :     else
     272             :     {
     273             :       //            HLTError("can not fetch object \"%s\" from CDB", path);
     274           0 :       return -1;
     275             :     }
     276           0 :   }
     277           0 :   if(!fPedestalData)
     278             :   {
     279           0 :     return -1;
     280             :   }
     281             : 
     282           0 :   return 0;
     283           0 : }
     284             : 
     285             : 
     286             : int AliHLTEMCALDigitMakerComponent::GetGainsFromCDB()
     287             : {
     288             :   // See header file for class documentation
     289           0 :   for(Int_t imod = 0; imod < 20; imod++) fGainsInitialised[imod] = false;
     290             :   //  HLTInfo("Getting bad channel map...");
     291             : 
     292           0 :   AliCDBPath path("EMCAL","Calib","Data");
     293           0 :   if(path.GetPath())
     294             :   {
     295             :     //      HLTInfo("configure from entry %s", path.GetPath());
     296           0 :     AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
     297           0 :     if (pEntry)
     298             :     {
     299           0 :       fCalibData = (AliEMCALCalibData*)pEntry->GetObject();
     300             :     }
     301             :     else
     302             :     {
     303             :       //            HLTError("can not fetch object \"%s\" from CDB", path);
     304           0 :       return -1;
     305             :     }
     306           0 :   }
     307           0 :   if(!fCalibData) return -1;
     308           0 :   return 0;
     309           0 : }
     310             : 
     311             : 
     312             : AliHLTComponent*
     313             : AliHLTEMCALDigitMakerComponent::Spawn()
     314             : {
     315             :   //see header file for documentation
     316           0 :   return new AliHLTEMCALDigitMakerComponent();
     317           0 : }

Generated by: LCOV version 1.11