Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include <EventFilter/EcalRawToDigi/interface/EcalDCCHeaderRuntypeDecoder.h>
0002 #include "EventFilter/EcalRawToDigi/interface/DCCDataUnpacker.h"
0003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0004 
0005 #include <string>
0006 #include <iostream>
0007 
0008 EcalDCCHeaderRuntypeDecoder::EcalDCCHeaderRuntypeDecoder() { ; }
0009 EcalDCCHeaderRuntypeDecoder::~EcalDCCHeaderRuntypeDecoder() { ; }
0010 
0011 bool EcalDCCHeaderRuntypeDecoder::Decode(unsigned long TrigType,     // global header,     bits 56-59
0012                                          unsigned long detTrigType,  // dcc header word 2, bits 32-47
0013                                          unsigned long runType,      // dcc header word 2, bits  0-31
0014                                          EcalDCCHeaderBlock* EcalDCCHeaderInfos) {
0015   //  unsigned int DCCNumberMask   = 63;//2^6-1
0016 
0017   unsigned int WhichHalfOffSet = 64;    //2^6
0018   unsigned int TypeOffSet = 256;        //2^8
0019   unsigned int SubTypeOffSet = 2048;    //2^11
0020   unsigned int SettingOffSet = 131072;  //2^17;
0021   unsigned int GainModeOffSet = 16384;  //2^14
0022 
0023   unsigned int TwoBitsMask = 3;
0024   unsigned int ThreeBitsMask = 7;
0025   unsigned int ThirdBitMask = 4;
0026 
0027   EcalDCCHeaderInfos->setRtHalf(int((runType / WhichHalfOffSet) & TwoBitsMask));
0028   int type = int((runType / TypeOffSet) & ThreeBitsMask);
0029   int sequence = int((runType / SubTypeOffSet) & ThreeBitsMask);
0030   EcalDCCHeaderInfos->setMgpaGain(int((runType / GainModeOffSet) & TwoBitsMask));
0031   EcalDCCHeaderInfos->setMemGain(int((runType / GainModeOffSet) & ThirdBitMask) / ThirdBitMask);
0032   //  EcalDCCHeaderInfos.Setting       = int ( runType / SettingOffSet);
0033 
0034   if (type == 0 && sequence == 0) {
0035     EcalDCCHeaderInfos->setRunType(EcalDCCHeaderBlock::COSMIC);
0036   }
0037   // begin: added for XDAQ 3
0038   else if (type == 0 && sequence == 1) {
0039     EcalDCCHeaderInfos->setRunType(EcalDCCHeaderBlock::COSMIC);
0040   } else if (type == 0 && sequence == 2) {
0041     EcalDCCHeaderInfos->setRunType(EcalDCCHeaderBlock::BEAMH4);
0042   } else if (type == 0 && sequence == 3) {
0043     EcalDCCHeaderInfos->setRunType(EcalDCCHeaderBlock::BEAMH2);
0044   } else if (type == 0 && sequence == 4) {
0045     EcalDCCHeaderInfos->setRunType(EcalDCCHeaderBlock::MTCC);
0046   }
0047   // end: added for XDAQ 3
0048   else if (type == 1 && sequence == 0) {
0049     EcalDCCHeaderInfos->setRunType(EcalDCCHeaderBlock::LASER_STD);
0050   } else if (type == 1 && sequence == 1) {
0051     EcalDCCHeaderInfos->setRunType(EcalDCCHeaderBlock::LASER_POWER_SCAN);
0052   } else if (type == 1 && sequence == 2) {
0053     EcalDCCHeaderInfos->setRunType(EcalDCCHeaderBlock::LASER_DELAY_SCAN);
0054   } else if (type == 2 && sequence == 0) {
0055     EcalDCCHeaderInfos->setRunType(EcalDCCHeaderBlock::TESTPULSE_SCAN_MEM);
0056   } else if (type == 2 && sequence == 1) {
0057     EcalDCCHeaderInfos->setRunType(EcalDCCHeaderBlock::TESTPULSE_MGPA);
0058   } else if (type == 3 && sequence == 0) {
0059     EcalDCCHeaderInfos->setRunType(EcalDCCHeaderBlock::PEDESTAL_STD);
0060   } else if (type == 3 && sequence == 1) {
0061     EcalDCCHeaderInfos->setRunType(EcalDCCHeaderBlock::PEDESTAL_OFFSET_SCAN);
0062   } else if (type == 3 && sequence == 2) {
0063     EcalDCCHeaderInfos->setRunType(EcalDCCHeaderBlock::PEDESTAL_25NS_SCAN);
0064   } else if (type == 4 && sequence == 0) {
0065     EcalDCCHeaderInfos->setRunType(EcalDCCHeaderBlock::LED_STD);
0066   }
0067 
0068   else if (type == 5 && sequence == 0) {
0069     EcalDCCHeaderInfos->setRunType(EcalDCCHeaderBlock::PHYSICS_GLOBAL);
0070   } else if (type == 5 && sequence == 1) {
0071     EcalDCCHeaderInfos->setRunType(EcalDCCHeaderBlock::COSMICS_GLOBAL);
0072   } else if (type == 5 && sequence == 2) {
0073     EcalDCCHeaderInfos->setRunType(EcalDCCHeaderBlock::HALO_GLOBAL);
0074   }
0075   //
0076   // else if (type ==5 && sequence == 3){EcalDCCHeaderInfos->setRunType(EcalDCCHeaderBlock::CALIB_GLOBAL);}
0077 
0078   else if (type == 6 && sequence == 0) {
0079     EcalDCCHeaderInfos->setRunType(EcalDCCHeaderBlock::PHYSICS_LOCAL);
0080   } else if (type == 6 && sequence == 1) {
0081     EcalDCCHeaderInfos->setRunType(EcalDCCHeaderBlock::COSMICS_LOCAL);
0082   } else if (type == 6 && sequence == 2) {
0083     EcalDCCHeaderInfos->setRunType(EcalDCCHeaderBlock::HALO_LOCAL);
0084   } else if (type == 6 && sequence == 3) {
0085     EcalDCCHeaderInfos->setRunType(EcalDCCHeaderBlock::CALIB_LOCAL);
0086   }
0087 
0088   else {
0089     if (!DCCDataUnpacker::silentMode_) {
0090       edm::LogError("IncorrectHeader") << "Unrecognized runtype and sequence: " << type << " " << sequence;
0091     }
0092     EcalDCCHeaderInfos->setRunType(-1);
0093     WasDecodingOk_ = false;
0094     return WasDecodingOk_;
0095   }
0096 
0097   // decoding of settings depends on whether run is global or local
0098   if (type == 5 || type == 6) {
0099     DecodeSettingGlobal(TrigType, detTrigType, EcalDCCHeaderInfos);
0100   } else {
0101     DecodeSetting(int(runType / SettingOffSet), EcalDCCHeaderInfos);
0102   }
0103 
0104   return WasDecodingOk_;
0105 }
0106 
0107 void EcalDCCHeaderRuntypeDecoder::DecodeSettingGlobal(unsigned long TrigType,
0108                                                       unsigned long detTrigType,
0109                                                       EcalDCCHeaderBlock* theHeader) {
0110   // TCC commands are decoded both in global (type ==5) and in local (type ==6)
0111   // keep an eye on the possible: EcalDCCHeaderBlock::CALIB_GLOBAL
0112   bool isLocal = false;
0113   if (theHeader->getRunType() == EcalDCCHeaderBlock::CALIB_LOCAL)
0114     isLocal = true;
0115 
0116   // if Trigger_Type is physics, only dccIdInTTCCommand is meaningful
0117   if (TrigType == 1) {
0118     int dccIdInTTCCommand = (detTrigType >> H_DCCID_B) & H_DCCID_MASK;
0119     theHeader->setDccInTTCCommand(dccIdInTTCCommand);
0120     return;
0121   }
0122 
0123   // if calibration trigger (gap)
0124   else if (TrigType == 2) {
0125     EcalDCCHeaderBlock::EcalDCCEventSettings theSettings;
0126     CleanEcalDCCSettingsInfo(&theSettings);
0127 
0128     int dccIdInTTCCommand = (detTrigType >> H_DCCID_B) & H_DCCID_MASK;
0129     int halfInTTCCommand = (detTrigType >> H_HALF_B) & H_HALF_MASK;
0130     int detailedTriggerTypeInTTCCommand = (detTrigType >> H_TR_TYPE_B) & H_TR_TYPE_MASK;
0131     int wavelengthInTTCCommand = (detTrigType >> H_WAVEL_B) & H_WAVEL_MASK;
0132 
0133     theHeader->setRtHalf(halfInTTCCommand);
0134     theHeader->setDccInTTCCommand(dccIdInTTCCommand);
0135     if (detailedTriggerTypeInTTCCommand == EcalDCCHeaderBlock::TTC_LASER) {
0136       if (isLocal)
0137         theHeader->setRunType(EcalDCCHeaderBlock::LASER_STD);
0138       else
0139         theHeader->setRunType(EcalDCCHeaderBlock::LASER_GAP);
0140       theSettings.wavelength = wavelengthInTTCCommand;
0141     }
0142 
0143     else if (detailedTriggerTypeInTTCCommand == EcalDCCHeaderBlock::TTC_LED) {
0144       if (isLocal)
0145         theHeader->setRunType(EcalDCCHeaderBlock::LED_STD);
0146       else
0147         theHeader->setRunType(EcalDCCHeaderBlock::LED_GAP);
0148       theSettings.wavelength = wavelengthInTTCCommand;
0149     }
0150 
0151     else if (detailedTriggerTypeInTTCCommand == EcalDCCHeaderBlock::TTC_TESTPULSE) {
0152       if (isLocal)
0153         theHeader->setRunType(EcalDCCHeaderBlock::TESTPULSE_MGPA);
0154       else
0155         theHeader->setRunType(EcalDCCHeaderBlock::TESTPULSE_GAP);
0156     }
0157 
0158     else if (detailedTriggerTypeInTTCCommand == EcalDCCHeaderBlock::TTC_PEDESTAL) {
0159       if (isLocal)
0160         theHeader->setRunType(EcalDCCHeaderBlock::PEDESTAL_STD);
0161       else
0162         theHeader->setRunType(EcalDCCHeaderBlock::PEDESTAL_GAP);
0163     }
0164 
0165     else {
0166       if (!DCCDataUnpacker::silentMode_) {
0167         edm::LogError("IncorrectHeader") << "Unrecognized detailedTriggerTypeInTTCCommand: "
0168                                          << detailedTriggerTypeInTTCCommand;
0169       }
0170       theHeader->setRunType(-1);
0171       WasDecodingOk_ = false;
0172     }
0173 
0174     theHeader->setEventSettings(theSettings);
0175 
0176   }
0177 
0178   else {
0179     if (!DCCDataUnpacker::silentMode_) {
0180       edm::LogError("IncorrectHeader") << "Unrecognized detailed trigger type";
0181     }
0182     theHeader->setRunType(-1);
0183     WasDecodingOk_ = false;
0184   }
0185 }
0186 
0187 void EcalDCCHeaderRuntypeDecoder::DecodeSetting(int Setting, EcalDCCHeaderBlock* theHeader) {
0188   EcalDCCHeaderBlock::EcalDCCEventSettings theSettings;
0189   CleanEcalDCCSettingsInfo(&theSettings);
0190 
0191   if (theHeader->getRunType() == EcalDCCHeaderBlock::COSMIC || theHeader->getRunType() == EcalDCCHeaderBlock::BEAMH2 ||
0192       theHeader->getRunType() == EcalDCCHeaderBlock::BEAMH4 || theHeader->getRunType() == EcalDCCHeaderBlock::MTCC ||
0193       theHeader->getRunType() == EcalDCCHeaderBlock::PHYSICS_LOCAL ||
0194       theHeader->getRunType() == EcalDCCHeaderBlock::COSMICS_LOCAL ||
0195       theHeader->getRunType() == EcalDCCHeaderBlock::HALO_LOCAL) {
0196     ;
0197   }
0198   //no settings foreseen
0199 
0200   else if (theHeader->getRunType() == EcalDCCHeaderBlock::LASER_STD) {
0201     theSettings.LaserPower = (Setting & 8128) / 64;
0202     theSettings.LaserFilter = (Setting & 56) / 8;
0203     theSettings.wavelength = Setting & 7;
0204   }
0205 
0206   else if (theHeader->getRunType() == EcalDCCHeaderBlock::LASER_POWER_SCAN) {
0207     theSettings.LaserPower = (Setting & 8128) / 64;
0208     theSettings.LaserFilter = (Setting & 56) / 8;
0209     theSettings.wavelength = Setting & 7;
0210   }
0211 
0212   else if (theHeader->getRunType() == EcalDCCHeaderBlock::LASER_DELAY_SCAN) {
0213     theSettings.wavelength = Setting & 7;
0214     theSettings.delay = (Setting & 2040) / 8;
0215   }
0216 
0217   else if (theHeader->getRunType() == EcalDCCHeaderBlock::TESTPULSE_SCAN_MEM) {
0218     theSettings.MEMVinj = Setting & 511;
0219   }
0220 
0221   else if (theHeader->getRunType() == EcalDCCHeaderBlock::TESTPULSE_MGPA) {
0222     theSettings.mgpa_content = Setting & 255;
0223   }
0224 
0225   else if (theHeader->getRunType() == EcalDCCHeaderBlock::PEDESTAL_STD) {
0226     ;
0227   }  //no settings foreseen
0228 
0229   else if (theHeader->getRunType() == EcalDCCHeaderBlock::PEDESTAL_OFFSET_SCAN) {
0230     theSettings.ped_offset = Setting;
0231   }
0232 
0233   else if (theHeader->getRunType() == EcalDCCHeaderBlock::PEDESTAL_25NS_SCAN) {
0234     theSettings.delay = (Setting & 255);
0235   }
0236 
0237   else if (theHeader->getRunType() == EcalDCCHeaderBlock::LED_STD) {
0238     theSettings.wavelength = Setting & 7;
0239   } else {
0240     if (!DCCDataUnpacker::silentMode_) {
0241       edm::LogError("IncorrectHeader") << "Unrecognized run type: " << theHeader->getRunType();
0242     }
0243     WasDecodingOk_ = false;
0244   }
0245 
0246   theHeader->setEventSettings(theSettings);
0247 }
0248 
0249 void EcalDCCHeaderRuntypeDecoder::CleanEcalDCCSettingsInfo(EcalDCCHeaderBlock::EcalDCCEventSettings* dummySettings) {
0250   dummySettings->LaserPower = -1;
0251   dummySettings->LaserFilter = -1;
0252   dummySettings->wavelength = -1;
0253   dummySettings->delay = -1;
0254   dummySettings->MEMVinj = -1;
0255   dummySettings->mgpa_content = -1;
0256   dummySettings->ped_offset = -1;
0257 }