00001 #include "DataFormats/HcalDetId/interface/HcalFrontEndId.h"
00002 #include <iomanip>
00003 #include <sstream>
00004 #include <iostream>
00005 #include <cstdlib>
00006
00007
00008 HcalFrontEndId::HcalFrontEndId(const std::string& rbx,int rm,int pixel,int rmfiber,int fiberchannel,int qie,int adc)
00009 {
00010 hcalFrontEndId_=0;
00011
00012 if (rbx.size()<5) return;
00013 if (rm<1 || rm>5) return;
00014 if (pixel<0 || pixel>19) return;
00015 if (rmfiber<1 || rmfiber>8) return;
00016 if (fiberchannel<0 || fiberchannel>2) return;
00017 if (qie<1 || qie>4) return;
00018 if (adc<0 || adc>5) return;
00019
00020 int num=-1;
00021 if (!rbx.compare(0,3,"HBM" )) { num=0 + atoi(rbx.substr(3,2).c_str())-1; }
00022 else if (!rbx.compare(0,3,"HBP" )) { num=18 + atoi(rbx.substr(3,2).c_str())-1; }
00023 else if (!rbx.compare(0,3,"HEM" )) { num=18*2 + atoi(rbx.substr(3,2).c_str())-1; }
00024 else if (!rbx.compare(0,3,"HEP" )) { num=18*3 + atoi(rbx.substr(3,2).c_str())-1; }
00025 else if (!rbx.compare(0,4,"HO2M")) { num=18*4 + atoi(rbx.substr(4,2).c_str())-1; }
00026 else if (!rbx.compare(0,4,"HO1M")) { num=18*4+12 + atoi(rbx.substr(4,2).c_str())-1; }
00027 else if (!rbx.compare(0,3,"HO0" )) { num=18*4+12*2 + atoi(rbx.substr(3,2).c_str())-1; }
00028 else if (!rbx.compare(0,4,"HO1P")) { num=18*4+12*3 + atoi(rbx.substr(4,2).c_str())-1; }
00029 else if (!rbx.compare(0,4,"HO2P")) { num=18*4+12*4 + atoi(rbx.substr(4,2).c_str())-1; }
00030 else if (!rbx.compare(0,3,"HFM" )) { num=18*4+12*5 + atoi(rbx.substr(3,2).c_str())-1; }
00031 else if (!rbx.compare(0,3,"HFP" )) { num=18*4+12*6 + atoi(rbx.substr(3,2).c_str())-1; }
00032 else return;
00033
00034 hcalFrontEndId_|=((adc+1)&0x7);
00035 hcalFrontEndId_|=((qie-1)&0x3)<<3;
00036 hcalFrontEndId_|=(fiberchannel&0x3)<<5;
00037 hcalFrontEndId_|=((rmfiber-1)&0x7)<<7;
00038 hcalFrontEndId_|=(pixel&0x1F)<<10;
00039 hcalFrontEndId_|=((rm-1)&0x7)<<15;
00040 hcalFrontEndId_|=(num&0xFF)<<18;
00041 }
00042
00043 HcalFrontEndId::~HcalFrontEndId()
00044 {
00045 }
00046
00047 std::string HcalFrontEndId::rbx() const
00048 {
00049 std::string subdets[11]={"HBM","HBP","HEM","HEP","HO2M","HO1M","HO0","HO1P","HO2P","HFM","HFP"};
00050
00051 int box=hcalFrontEndId_>>18;
00052 int num=-1;
00053 int subdet_index=-1;
00054 if (box<18*4) {
00055 num=box%18;
00056 subdet_index=(box-num)/18;
00057 }
00058 else {
00059 num=(box-18*4)%12;
00060 subdet_index=4+(box-18*4-num)/12;
00061 }
00062 std::stringstream tempss;
00063 tempss << std::setw(2) << std::setfill('0') << num+1;
00064 return subdets[subdet_index]+tempss.str();
00065 }
00066
00067 std::ostream& operator<<(std::ostream& s,const HcalFrontEndId& id) {
00068 return s << id.rbx() << id.rm() << '[' << id.rmFiber() << '/' << id.fiberChannel()
00069 << "] pix=" << id.pixel()
00070 << " qiecard=" << id.qieCard() << " adc=" << id.adc();
00071 }