CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/DataFormats/HcalDigi/src/ZDCDataFrame.cc

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