Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:53:37

0001 #include "DataFormats/HcalDigi/interface/HcalCalibDataFrame.h"
0002 
0003 HcalCalibDataFrame::HcalCalibDataFrame() : id_(0), size_(0), hcalPresamples_(0) {}
0004 
0005 HcalCalibDataFrame::HcalCalibDataFrame(const HcalCalibDetId& id) : id_(id), size_(0), hcalPresamples_(0) {
0006   // TODO : test id for HcalForward
0007 }
0008 
0009 void HcalCalibDataFrame::setSize(int size) {
0010   if (size > MAXSAMPLES)
0011     size_ = MAXSAMPLES;
0012   else if (size <= 0)
0013     size_ = 0;
0014   else
0015     size_ = size;
0016 }
0017 void HcalCalibDataFrame::setPresamples(int ps) { hcalPresamples_ |= ps & 0xF; }
0018 void HcalCalibDataFrame::setReadoutIds(const HcalElectronicsId& eid) { electronicsId_ = eid; }
0019 
0020 bool HcalCalibDataFrame::validate(int firstSample, int nSamples) const {
0021   int capid = -1;
0022   bool ok = true;
0023   for (int i = 0; ok && i < nSamples && i + firstSample < size_; i++) {
0024     if (data_[i + firstSample].er() || !data_[i + firstSample].dv())
0025       ok = false;
0026     if (i == 0)
0027       capid = data_[i + firstSample].capid();
0028     if (capid != data_[i + firstSample].capid())
0029       ok = false;
0030     capid = (capid + 1) % 4;
0031   }
0032   return ok;
0033 }
0034 
0035 void HcalCalibDataFrame::setZSInfo(bool unsuppressed, bool markAndPass, uint32_t crossingMask) {
0036   hcalPresamples_ &= 0x7FC00F0F;  // preserve actual presamples and fiber idle offset
0037   if (markAndPass)
0038     hcalPresamples_ |= 0x10;
0039   if (unsuppressed)
0040     hcalPresamples_ |= 0x20;
0041   hcalPresamples_ |= (crossingMask & 0x3FF) << 12;
0042 }
0043 
0044 int HcalCalibDataFrame::fiberIdleOffset() const {
0045   int val = (hcalPresamples_ & 0xF00) >> 8;
0046   return (val == 0) ? (-1000) : (((val & 0x8) == 0) ? (-(val & 0x7)) : (val & 0x7));
0047 }
0048 
0049 void HcalCalibDataFrame::setFiberIdleOffset(int offset) {
0050   hcalPresamples_ &= 0x7FFFF0FF;
0051   if (offset >= 7)
0052     hcalPresamples_ |= 0xF00;
0053   else if (offset >= 0)
0054     hcalPresamples_ |= (0x800) | (offset << 8);
0055   else if (offset >= -7)
0056     hcalPresamples_ |= ((-offset) << 8);
0057   else
0058     hcalPresamples_ |= 0x700;
0059 }
0060 
0061 std::ostream& operator<<(std::ostream& s, const HcalCalibDataFrame& digi) {
0062   s << digi.id() << " " << digi.size() << " samples  " << digi.presamples() << " presamples ";
0063   if (digi.zsUnsuppressed())
0064     s << " zsUS ";
0065   if (digi.zsMarkAndPass())
0066     s << " zsM&P ";
0067   if (digi.fiberIdleOffset() != 0) {
0068     if (digi.fiberIdleOffset() == -1000)
0069       s << " nofiberOffset";
0070     else
0071       s << " fiberOffset=" << digi.fiberIdleOffset();
0072   }
0073   s << std::endl;
0074   for (int i = 0; i < digi.size(); i++)
0075     s << "  " << digi.sample(i) << std::endl;
0076   return s;
0077 }