Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:21:22

0001 #include "IORawData/CaloPatterns/interface/HcalFiberPattern.h"
0002 #include "FWCore/Utilities/interface/Exception.h"
0003 
0004 static inline int setIf(const std::string& name, const std::map<std::string, std::string>& params) {
0005   std::map<std::string, std::string>::const_iterator j = params.find(name);
0006   if (j == params.end())
0007     throw cms::Exception("InvalidFormat") << "Missing parameter '" << name << "'";
0008   else
0009     return strtol(j->second.c_str(), nullptr, 0);
0010 }
0011 
0012 HcalFiberPattern::HcalFiberPattern(const std::map<std::string, std::string>& params, const std::vector<uint32_t>& data)
0013     : pattern_(data) {
0014   crate_ = setIf("CRATE", params);
0015   slot_ = setIf("SLOT", params);
0016   fiber_ = setIf("FIBER", params);
0017   dcc_ = setIf("DCC", params);
0018   spigot_ = setIf("SPIGOT", params);
0019   tb_ = setIf("TOPBOTTOM", params);
0020 }
0021 
0022 HcalQIESample HcalFiberPattern::unpack(int bc, int fc) {
0023   uint32_t w1 = pattern_[bc * 2];      // lsw
0024   uint32_t w2 = pattern_[bc * 2 + 1];  // msw
0025 
0026   int adc = 0, capid = 0;
0027   bool dv = (w1 & 0x10000) != 0;
0028   bool er = (w1 & 0x20000) != 0;
0029 
0030   switch (fc) {
0031     case (0):
0032       adc = (w2 & 0xFE00) >> 9;
0033       capid = (w1 & 0x0180) >> 7;
0034       break;
0035     case (1):
0036       adc = (w2 & 0xFE) >> 1;
0037       capid = (w1 & 0x0060) >> 5;
0038       break;
0039     case (2):
0040       adc = (w1 & 0xFE00) >> 9;
0041       capid = (w1 & 0x0018) >> 3;
0042       break;
0043     default:
0044       break;
0045   }
0046   return HcalQIESample(adc, capid, fiber_, fc, dv, er);
0047 }
0048 
0049 std::vector<HcalQIESample> HcalFiberPattern::getSamples(int bunch, int npresamples, int nsamples, int fiberChan) {
0050   if (bunch < npresamples)
0051     throw cms::Exception("InvalidArgument")
0052         << "Asked for " << npresamples << " presamples with event at bunch " << bunch;
0053   if (nsamples - npresamples + bunch >= (int)(pattern_.size() / 2))
0054     throw cms::Exception("InvalidArgument")
0055         << "Asked for " << nsamples << " with event at " << bunch << " and " << npresamples << " presamples, but only "
0056         << pattern_.size() / 2 << " bunches are available";
0057 
0058   std::vector<HcalQIESample> retval;
0059   retval.reserve(nsamples);
0060 
0061   for (int i = 0; i < nsamples; i++) {
0062     int bc = bunch + i - npresamples;
0063     retval.push_back(unpack(bc, fiberChan));
0064   }
0065   return retval;
0066 }
0067 
0068 HcalElectronicsId HcalFiberPattern::getId(int fiberChan) {
0069   HcalElectronicsId retval(fiberChan, fiber_, spigot_, dcc_);
0070   retval.setHTR(crate_, slot_, tb_);
0071   return retval;
0072 }