CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_8_patch3/src/IORawData/CaloPatterns/src/HcalFiberPattern.cc

Go to the documentation of this file.
00001 #include "IORawData/CaloPatterns/interface/HcalFiberPattern.h"
00002 #include "FWCore/Utilities/interface/Exception.h"
00003 
00004 static inline int setIf(const std::string& name,const std::map<std::string, std::string>& params) {
00005   std::map<std::string, std::string>::const_iterator j=params.find(name);
00006   if (j==params.end()) throw cms::Exception("InvalidFormat") << "Missing parameter '" << name << "'";
00007   else return strtol(j->second.c_str(),0,0);
00008 } 
00009 
00010 HcalFiberPattern::HcalFiberPattern(const std::map<std::string, std::string>& params, const std::vector<uint32_t>& data) : pattern_(data) {
00011   crate_=setIf("CRATE",params);
00012   slot_=setIf("SLOT",params);
00013   fiber_=setIf("FIBER",params);
00014   dcc_=setIf("DCC",params);
00015   spigot_=setIf("SPIGOT",params);
00016   tb_=setIf("TOPBOTTOM",params);
00017 }
00018 
00019 HcalQIESample HcalFiberPattern::unpack(int bc, int fc) {
00020   uint32_t w1=pattern_[bc*2]; // lsw
00021   uint32_t w2=pattern_[bc*2+1]; // msw
00022 
00023   int adc=0, capid=0;
00024   bool dv=(w1&0x10000)!=0;
00025   bool er=(w1&0x20000)!=0;
00026   
00027   switch (fc) {
00028   case (0):
00029     adc=(w2&0xFE00)>>9;
00030     capid=(w1&0x0180)>>7;
00031     break;
00032   case (1):
00033     adc=(w2&0xFE)>>1;
00034     capid=(w1&0x0060)>>5;
00035     break;
00036   case (2):
00037     adc=(w1&0xFE00)>>9;
00038     capid=(w1&0x0018)>>3;
00039     break;
00040   default:
00041     break;
00042   }
00043   return HcalQIESample(adc,capid,fiber_,fc,dv,er);
00044 }
00045 
00046 std::vector<HcalQIESample> HcalFiberPattern::getSamples(int bunch, int npresamples, int nsamples, int fiberChan) {
00047   if (bunch<npresamples) throw cms::Exception("InvalidArgument") << "Asked for " << npresamples << " presamples with event at bunch " << bunch;
00048   if (nsamples-npresamples+bunch>=(int)(pattern_.size()/2)) throw cms::Exception("InvalidArgument") << "Asked for " << nsamples << " with event at " << bunch << " and " << npresamples << " presamples, but only " << pattern_.size()/2 << " bunches are available";
00049 
00050   std::vector<HcalQIESample> retval;
00051   retval.reserve(nsamples);
00052 
00053   for (int i=0; i<nsamples; i++) {
00054     int bc=bunch+i-npresamples;
00055     retval.push_back(unpack(bc,fiberChan));
00056   }
00057   return retval;
00058 }
00059 
00060 HcalElectronicsId HcalFiberPattern::getId(int fiberChan) {
00061   HcalElectronicsId retval(fiberChan,fiber_,spigot_,dcc_);
00062   retval.setHTR(crate_,slot_,tb_);
00063   return retval;
00064 }