Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:14:56

0001 #include <EventFilter/EcalTBRawToDigi/interface/EcalDCCHeaderRuntypeDecoder.h>
0002 
0003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0004 
0005 #include <string>
0006 #include <iostream>
0007 
0008 EcalDCCTBHeaderRuntypeDecoder::EcalDCCTBHeaderRuntypeDecoder() { ; }
0009 EcalDCCTBHeaderRuntypeDecoder::~EcalDCCTBHeaderRuntypeDecoder() { ; }
0010 
0011 bool EcalDCCTBHeaderRuntypeDecoder::Decode(unsigned long headerWord, EcalDCCHeaderBlock* EcalDCCHeaderInfos) {
0012   //  unsigned long DCCNumberMask      = 63;//2^6-1
0013 
0014   unsigned long WhichHalfOffSet = 64;    //2^6
0015   unsigned long TypeOffSet = 256;        //2^8
0016   unsigned long SubTypeOffSet = 2048;    //2^11
0017   unsigned long SettingOffSet = 131072;  //2^17;
0018   unsigned long GainModeOffSet = 16384;  //2^14
0019 
0020   unsigned long TwoBitsMask = 3;
0021   unsigned long ThreeBitsMask = 7;
0022   unsigned long ThirdBitMask = 4;
0023 
0024   //  EcalDCCTBHeaderInfos->setId( int ( headerWord & DCCNumberMask) );
0025   EcalDCCHeaderInfos->setRtHalf(int((headerWord / WhichHalfOffSet) & TwoBitsMask));
0026   int type = int((headerWord / TypeOffSet) & ThreeBitsMask);
0027   int sequence = int((headerWord / SubTypeOffSet) & ThreeBitsMask);
0028   EcalDCCHeaderInfos->setMgpaGain(int((headerWord / GainModeOffSet) & TwoBitsMask));
0029   EcalDCCHeaderInfos->setMemGain(int((headerWord / GainModeOffSet) & ThirdBitMask) / ThirdBitMask);
0030   //  EcalDCCHeaderInfos.Setting       = int ( headerWord / SettingOffSet);
0031 
0032   if (type == 0 && sequence == 0) {
0033     EcalDCCHeaderInfos->setRunType(EcalDCCHeaderBlock::COSMIC);
0034   }
0035   // begin: added for XDAQ 3
0036   else if (type == 0 && sequence == 1) {
0037     EcalDCCHeaderInfos->setRunType(EcalDCCHeaderBlock::COSMIC);
0038   } else if (type == 0 && sequence == 2) {
0039     EcalDCCHeaderInfos->setRunType(EcalDCCHeaderBlock::BEAMH4);
0040   } else if (type == 0 && sequence == 3) {
0041     EcalDCCHeaderInfos->setRunType(EcalDCCHeaderBlock::BEAMH2);
0042   } else if (type == 0 && sequence == 4) {
0043     EcalDCCHeaderInfos->setRunType(EcalDCCHeaderBlock::MTCC);
0044   }
0045   // end: added for XDAQ 3
0046   else if (type == 1 && sequence == 0) {
0047     EcalDCCHeaderInfos->setRunType(EcalDCCHeaderBlock::LASER_STD);
0048   } else if (type == 1 && sequence == 1) {
0049     EcalDCCHeaderInfos->setRunType(EcalDCCHeaderBlock::LASER_POWER_SCAN);
0050   } else if (type == 1 && sequence == 2) {
0051     EcalDCCHeaderInfos->setRunType(EcalDCCHeaderBlock::LASER_DELAY_SCAN);
0052   } else if (type == 2 && sequence == 0) {
0053     EcalDCCHeaderInfos->setRunType(EcalDCCHeaderBlock::TESTPULSE_SCAN_MEM);
0054   } else if (type == 2 && sequence == 1) {
0055     EcalDCCHeaderInfos->setRunType(EcalDCCHeaderBlock::TESTPULSE_MGPA);
0056   } else if (type == 3 && sequence == 0) {
0057     EcalDCCHeaderInfos->setRunType(EcalDCCHeaderBlock::PEDESTAL_STD);
0058   } else if (type == 3 && sequence == 1) {
0059     EcalDCCHeaderInfos->setRunType(EcalDCCHeaderBlock::PEDESTAL_OFFSET_SCAN);
0060   } else if (type == 3 && sequence == 2) {
0061     EcalDCCHeaderInfos->setRunType(EcalDCCHeaderBlock::PEDESTAL_25NS_SCAN);
0062   } else if (type == 4 && sequence == 0) {
0063     EcalDCCHeaderInfos->setRunType(EcalDCCHeaderBlock::LED_STD);
0064   } else {
0065     edm::LogWarning("EcalTBRawToDigi") << "@SUB=EcalDCCHeaderRuntypeDecoder::Decode unrecognized runtype and sequence: "
0066                                        << type << " " << sequence;
0067     EcalDCCHeaderInfos->setRunType(-1);
0068     WasDecodingOk_ = false;
0069   }
0070 
0071   DecodeSetting(int(headerWord / SettingOffSet), EcalDCCHeaderInfos);
0072 
0073   return WasDecodingOk_;
0074 }
0075 
0076 void EcalDCCTBHeaderRuntypeDecoder::DecodeSetting(int Setting, EcalDCCHeaderBlock* theHeader) {
0077   EcalDCCHeaderBlock::EcalDCCEventSettings theSettings;  // = new EcalDCCEventSettings;
0078   CleanEcalDCCSettingsInfo(&theSettings);
0079 
0080   if (theHeader->getRunType() == EcalDCCHeaderBlock::COSMIC || theHeader->getRunType() == EcalDCCHeaderBlock::BEAMH2 ||
0081       theHeader->getRunType() == EcalDCCHeaderBlock::BEAMH4 || theHeader->getRunType() == EcalDCCHeaderBlock::MTCC) {
0082     ;
0083   }  //no settings foreseen
0084   else if (theHeader->getRunType() == EcalDCCHeaderBlock::LASER_STD) {
0085     theSettings.LaserPower = (Setting & 8128) / 64;
0086     theSettings.LaserFilter = (Setting & 56) / 8;
0087     theSettings.wavelength = Setting & 7;
0088   } else if (theHeader->getRunType() == EcalDCCHeaderBlock::LASER_POWER_SCAN) {
0089     theSettings.LaserPower = (Setting & 8128) / 64;
0090     theSettings.LaserFilter = (Setting & 56) / 8;
0091     theSettings.wavelength = Setting & 7;
0092   } else if (theHeader->getRunType() == EcalDCCHeaderBlock::LASER_DELAY_SCAN) {
0093     theSettings.wavelength = Setting & 7;
0094     theSettings.delay = (Setting & 2040) / 8;
0095   } else if (theHeader->getRunType() == EcalDCCHeaderBlock::TESTPULSE_SCAN_MEM) {
0096     theSettings.MEMVinj = Setting & 511;
0097   } else if (theHeader->getRunType() == EcalDCCHeaderBlock::TESTPULSE_MGPA) {
0098     theSettings.mgpa_content = Setting & 255;
0099   } else if (theHeader->getRunType() == EcalDCCHeaderBlock::PEDESTAL_STD) {
0100     ;
0101   }  //no settings foreseen
0102   else if (theHeader->getRunType() == EcalDCCHeaderBlock::PEDESTAL_OFFSET_SCAN) {
0103     theSettings.ped_offset = Setting;
0104   } else if (theHeader->getRunType() == EcalDCCHeaderBlock::PEDESTAL_25NS_SCAN) {
0105     theSettings.delay = (Setting & 255);
0106   } else if (theHeader->getRunType() == EcalDCCHeaderBlock::LED_STD) {
0107     theSettings.wavelength = Setting & 7;
0108   } else {
0109     edm::LogWarning("EcalTBRawToDigi") << "@SUB=EcalDCCTBHeaderRuntypeDecoder::DecodeSettings unrecognized run type: "
0110                                        << theHeader->getRunType();
0111     WasDecodingOk_ = false;
0112   }
0113   theHeader->setEventSettings(theSettings);
0114 }
0115 
0116 void EcalDCCTBHeaderRuntypeDecoder::CleanEcalDCCSettingsInfo(EcalDCCHeaderBlock::EcalDCCEventSettings* dummySettings) {
0117   dummySettings->LaserPower = -1;
0118   dummySettings->LaserFilter = -1;
0119   dummySettings->wavelength = -1;
0120   dummySettings->delay = -1;
0121   dummySettings->MEMVinj = -1;
0122   dummySettings->mgpa_content = -1;
0123   dummySettings->ped_offset = -1;
0124 }