CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/src/DataFormats/HcalDigi/src/CastorDataFrame.cc

Go to the documentation of this file.
00001 #include "DataFormats/HcalDigi/interface/CastorDataFrame.h"
00002 
00003 CastorDataFrame::CastorDataFrame() : id_(0), 
00004                              size_(0),
00005                              hcalPresamples_(0)
00006 {
00007 }
00008 
00009 CastorDataFrame::CastorDataFrame(const HcalCastorDetId& id) : 
00010   id_(id), 
00011   size_(0),
00012   hcalPresamples_(0)
00013 {
00014   // TODO : test id for CASTOR
00015 }
00016   
00017 void CastorDataFrame::setSize(int size) {
00018   if (size>MAXSAMPLES) size_=MAXSAMPLES;
00019   else if (size<=0) size_=0;
00020   else size_=size;
00021 }
00022 
00023 void CastorDataFrame::setPresamples(int ps) {
00024   hcalPresamples_|=ps&0xF;
00025 }
00026 //void CastorDataFrame::setReadoutIds(const HcalElectronicsId& eid) {
00027 //  electronicsId_=eid;
00028 //}
00029 
00030 bool CastorDataFrame::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 CastorDataFrame::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 CastorDataFrame::fiberIdleOffset() const {
00050   int val=(hcalPresamples_&0xF00)>>8;
00051   return (val==0)?(-1000):(((val&0x8)==0)?(-(val&0x7)):(val&0x7));
00052 }
00053 
00054 void CastorDataFrame::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 std::ostream& operator<<(std::ostream& s, const CastorDataFrame& digi) {
00062   s << digi.id() << " " << digi.size() << " samples  " << digi.presamples() << " presamples " << std::endl;
00063   if (digi.fiberIdleOffset()!=0) {
00064     if (digi.fiberIdleOffset()==-1000) s << " nofiberOffset";
00065     else s << " fiberOffset=" << digi.fiberIdleOffset();
00066   }
00067   for (int i=0; i<digi.size(); i++) 
00068     s << "  " << digi.sample(i) << std::endl;
00069   return s;
00070 }
00071   
00072