CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/DataFormats/HcalDigi/src/HODataFrame.cc

Go to the documentation of this file.
00001 #include "DataFormats/HcalDigi/interface/HODataFrame.h"
00002 
00003   
00004 HODataFrame::HODataFrame() : id_(0), 
00005                              size_(0),
00006                              hcalPresamples_(0)
00007 {
00008 }
00009 
00010 HODataFrame::HODataFrame(const HcalDetId& id) : 
00011   id_(id), 
00012   size_(0),
00013   hcalPresamples_(0)
00014 {
00015   // TODO : test id for HcalOuter
00016 }
00017   
00018 void HODataFrame::setSize(int size) {
00019   if (size>MAXSAMPLES) size_=MAXSAMPLES;
00020   else if (size<=0) size_=0;
00021   else size_=size;
00022 }
00023 void HODataFrame::setPresamples(int ps) {
00024    hcalPresamples_|=ps&0xF;
00025 }
00026 void HODataFrame::setReadoutIds(const HcalElectronicsId& eid) {
00027   electronicsId_=eid;
00028 }
00029 
00030 bool HODataFrame::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 HODataFrame::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 
00050 int HODataFrame::fiberIdleOffset() const {
00051   int val=(hcalPresamples_&0xF00)>>8;
00052   return (val==0)?(-1000):(((val&0x8)==0)?(-(val&0x7)):(val&0x7));
00053 }
00054 
00055 void HODataFrame::setFiberIdleOffset(int offset) {
00056   hcalPresamples_&=0xFFFF0FF;
00057   if (offset>=7) hcalPresamples_|=0xF00;
00058   else if (offset>=0) hcalPresamples_|=(0x800)|(offset<<8);
00059   else if (offset>=-7) hcalPresamples_|=((-offset)<<8);
00060   else hcalPresamples_|=0x700;
00061 }  
00062 
00063 std::ostream& operator<<(std::ostream& s, const HODataFrame& 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