00001 #include "DataFormats/HcalDigi/interface/HBHEDataFrame.h" 00002 00003 00004 HBHEDataFrame::HBHEDataFrame() : id_(0), 00005 size_(0), 00006 hcalPresamples_(0) 00007 { 00008 } 00009 00010 HBHEDataFrame::HBHEDataFrame(const HcalDetId& id) : 00011 id_(id), 00012 size_(0), 00013 hcalPresamples_(0) 00014 { 00015 // TODO : test id for HcalBarrel or HcalEndcap 00016 } 00017 00018 void HBHEDataFrame::setSize(int size) { 00019 if (size>MAXSAMPLES) size_=MAXSAMPLES; 00020 else if (size<=0) size_=0; 00021 else size_=size; 00022 } 00023 void HBHEDataFrame::setPresamples(int ps) { 00024 hcalPresamples_|=ps&0xF; 00025 } 00026 void HBHEDataFrame::setReadoutIds(const HcalElectronicsId& eid) { 00027 electronicsId_=eid; 00028 } 00029 00030 bool HBHEDataFrame::validate(int firstSample, int nSamples) const { 00031 int capid=-1; 00032 bool ok=true; 00033 for (int i=0; ok && i<nSamples && i+firstSample<size_; i++) { 00034 if (data_[i+firstSample].er() || !data_[i+firstSample].dv()) ok=false; 00035 if (i==0) capid=data_[i+firstSample].capid(); 00036 if (capid!=data_[i+firstSample].capid()) ok=false; 00037 capid=(capid+1)%4; 00038 } 00039 return ok; 00040 } 00041 00042 void HBHEDataFrame::setZSInfo(bool unsuppressed, bool markAndPass, uint32_t crossingMask) { 00043 hcalPresamples_&=0x7FC00F0F; // preserve actual presamples and fiber idle offset 00044 if (markAndPass) hcalPresamples_|=0x10; 00045 if (unsuppressed) hcalPresamples_|=0x20; 00046 hcalPresamples_|=(crossingMask&0x3FF)<<12; 00047 } 00048 00049 int HBHEDataFrame::fiberIdleOffset() const { 00050 int val=(hcalPresamples_&0xF00)>>8; 00051 return (val==0)?(-1000):(((val&0x8)==0)?(-(val&0x7)):(val&0x7)); 00052 } 00053 00054 void HBHEDataFrame::setFiberIdleOffset(int offset) { 00055 hcalPresamples_&=0x7FFFF0FF; 00056 if (offset>=7) hcalPresamples_|=0xF00; 00057 else if (offset>=0) hcalPresamples_|=(0x800)|(offset<<8); 00058 else if (offset>=-7) hcalPresamples_|=((-offset)<<8); 00059 else hcalPresamples_|=0x700; 00060 } 00061 00062 00063 std::ostream& operator<<(std::ostream& s, const HBHEDataFrame& digi) { 00064 s << digi.id() << " " << digi.size() << " samples " << digi.presamples() << " presamples "; 00065 if (digi.zsUnsuppressed()) s << " zsUS"; 00066 if (digi.zsMarkAndPass()) s << " zsM&P"; 00067 if (digi.fiberIdleOffset()!=0) { 00068 if (digi.fiberIdleOffset()==-1000) s << " nofiberOffset"; 00069 else s << " fiberOffset=" << digi.fiberIdleOffset(); 00070 } 00071 s << std::endl; 00072 for (int i=0; i<digi.size(); i++) 00073 s << " " << digi.sample(i) << std::endl; 00074 return s; 00075 } 00076 00077