Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:04:18

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