File indexing completed on 2024-04-06 12:04:18
0001 #include "DataFormats/HcalDigi/interface/ZDCDataFrame.h"
0002
0003 ZDCDataFrame::ZDCDataFrame() : id_(0), size_(0), hcalPresamples_(0) {}
0004
0005 ZDCDataFrame::ZDCDataFrame(const HcalZDCDetId& id) : id_(id), size_(0), hcalPresamples_(0) {
0006
0007 }
0008
0009 void ZDCDataFrame::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 ZDCDataFrame::setPresamples(int ps) { hcalPresamples_ |= ps & 0xF; }
0018 void ZDCDataFrame::setReadoutIds(const HcalElectronicsId& eid) { electronicsId_ = eid; }
0019
0020 bool ZDCDataFrame::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 ZDCDataFrame::setZSInfo(bool unsuppressed, bool markAndPass, uint32_t crossingMask) {
0036 hcalPresamples_ &= 0x7FC00F0F;
0037 if (markAndPass)
0038 hcalPresamples_ |= 0x10;
0039 if (unsuppressed)
0040 hcalPresamples_ |= 0x20;
0041 hcalPresamples_ |= (crossingMask & 0x3FF) << 12;
0042 }
0043
0044 int ZDCDataFrame::fiberIdleOffset() const {
0045 int val = (hcalPresamples_ & 0xF00) >> 8;
0046 return (val == 0) ? (-1000) : (((val & 0x8) == 0) ? (-(val & 0x7)) : (val & 0x7));
0047 }
0048
0049 void ZDCDataFrame::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 ZDCDataFrame& 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 }