Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:58:17

0001 //
0002 // This class stores the name and related
0003 // hardware mapings for a ROC
0004 //
0005 
0006 #include "CalibFormats/SiPixelObjects/interface/PixelROCName.h"
0007 #include <string>
0008 #include <iostream>
0009 #include <sstream>
0010 #include <cctype>
0011 #include <cassert>
0012 #include <cstdlib>
0013 
0014 using namespace std;
0015 using namespace pos;
0016 
0017 PixelROCName::PixelROCName() : id_(0) {}
0018 
0019 PixelROCName::PixelROCName(std::string rocname) { parsename(rocname); }
0020 
0021 void PixelROCName::setIdFPix(char np, char LR, int disk, int blade, int panel, int plaquet, int roc) {
0022   std::string mthn = "[PixelROCName::setIdFPix()]\t\t\t\t    ";
0023   id_ = 0;
0024 
0025   //std::cout << __LINE__ << "]\t" << mthn << "subdet: " << subdet << std::endl;
0026   //std::cout << __LINE__ << "]\t" << mthn << "np    : " << np     << std::endl;
0027   //std::cout << __LINE__ << "]\t" << mthn << "LR    : " << LR     << std::endl;
0028   //std::cout << __LINE__ << "]\t" << mthn << "disk  : " << disk   << std::endl;
0029 
0030   assert(roc >= 0 && roc < 10);
0031 
0032   if (np == 'p')
0033     id_ = (id_ | 0x40000000);
0034   //std::cout<< __LINE__ << "]\t" << mthn <<"2 id_="<<std::hex<<id_<<std::dec<<std::endl;
0035   if (LR == 'I')
0036     id_ = (id_ | 0x20000000);
0037   //std::cout<< __LINE__ << "]\t" << mthn <<"3 id_="<<std::hex<<id_<<std::dec<<std::endl;
0038   id_ = (id_ | (disk << 12));
0039   //std::cout<< __LINE__ << "]\t" << mthn <<"4 id_="<<std::hex<<id_<<std::dec<<std::endl;
0040   id_ = (id_ | (blade << 7));
0041   //std::cout<< __LINE__ << "]\t" << mthn <<"5 id_="<<std::hex<<id_<<std::dec<<std::endl;
0042   id_ = (id_ | ((panel - 1) << 6));
0043   //std::cout<< __LINE__ << "]\t" << mthn <<"6 id_="<<std::hex<<id_<<std::dec<<std::endl;
0044   id_ = (id_ | ((plaquet - 1) << 4));
0045   //std::cout<< __LINE__ << "]\t" << mthn <<"7 id_="<<std::hex<<id_<<std::dec<<std::endl;
0046   id_ = (id_ | roc);
0047 
0048   //std::cout<< __LINE__ << "]\t" << mthn <<"final id_="<<std::hex<<id_<<std::dec<<std::endl;
0049 }
0050 
0051 void PixelROCName::setIdBPix(char np, char LR, int sec, int layer, int ladder, char HF, int module, int roc) {
0052   id_ = 0;
0053 
0054   //std::cout<< __LINE__ << "]\t" << mthn <<"BPix ladder:"<<ladder<<std::endl;
0055   //std::cout<< __LINE__ << "]\t" << mthn <<"np  : " << np   << std::endl;
0056   //std::cout<< __LINE__ << "]\t" << mthn <<"LR  : " << LR   << std::endl;
0057   //std::cout<< __LINE__ << "]\t" << mthn <<"disk: " << disk << std::endl;
0058 
0059   assert(roc >= 0 && roc < 16);
0060 
0061   id_ = 0x80000000;
0062 
0063   if (np == 'p')
0064     id_ = (id_ | 0x40000000);
0065   //std::cout<< __LINE__ << "]\t" << mthn <<"2 id_="<<std::hex<<id_<<std::dec<<std::endl;
0066   if (LR == 'I')
0067     id_ = (id_ | 0x20000000);
0068   //std::cout<< __LINE__ << "]\t" << mthn <<"3 id_="<<std::hex<<id_<<std::dec<<std::endl;
0069   id_ = (id_ | ((sec - 1) << 14));
0070   //std::cout<< __LINE__ << "]\t" << mthn <<"4 id_="<<std::hex<<id_<<std::dec<<std::endl;
0071   if (HF == 'F')
0072     id_ = (id_ | 0x00000800);
0073 
0074   id_ = (id_ | (layer << 12));
0075   //std::cout<< __LINE__ << "]\t" << mthn <<"5 id_="<<std::hex<<id_<<std::dec<<std::endl;
0076   id_ = (id_ | (ladder << 6));
0077   //std::cout<< __LINE__ << "]\t" << mthn <<"6 id_="<<std::hex<<id_<<std::dec<<std::endl;
0078   id_ = (id_ | ((module - 1) << 4));
0079   //std::cout<< __LINE__ << "]\t" << mthn <<"7 id_="<<std::hex<<id_<<std::dec<<std::endl;
0080   id_ = (id_ | roc);
0081 
0082   //std::cout<< __LINE__ << "]\t" << mthn <<"final id_="<<std::hex<<id_<<std::dec<<std::endl;
0083 }
0084 
0085 void PixelROCName::check(bool check, const string& name) {
0086   static std::string mthn = "[PixelROCName::check()]\t\t\t\t    ";
0087 
0088   if (check)
0089     return;
0090 
0091   cout << __LINE__ << "]\t" << mthn << "ERROR tried to parse string:'" << name;
0092   cout << "' as a ROC name. Will terminate." << endl;
0093 
0094   ::abort();
0095 }
0096 
0097 void PixelROCName::parsename(std::string name) {
0098   //
0099   // The name should be on the format
0100   //
0101   // FPix_BpR_D1_BLD1_PNL1_PLQ1_ROC1
0102   //
0103 
0104   //    std::cout << "[PixelROCName::parsename()]\t\tROC name:"<<name<<std::endl;
0105 
0106   check(name[0] == 'F' || name[0] == 'B', name);
0107 
0108   if (name[0] == 'F') {
0109     check(name[0] == 'F', name);
0110     check(name[1] == 'P', name);
0111     check(name[2] == 'i', name);
0112     check(name[3] == 'x', name);
0113     check(name[4] == '_', name);
0114     check(name[5] == 'B', name);
0115     check((name[6] == 'm') || (name[6] == 'p'), name);
0116     char np = name[6];
0117     check((name[7] == 'I') || (name[7] == 'O'), name);
0118     char LR = name[7];
0119     check(name[8] == '_', name);
0120     check(name[9] == 'D', name);
0121     char digit[2] = {0, 0};
0122     digit[0] = name[10];
0123     int disk = atoi(digit);
0124     check(name[11] == '_', name);
0125     check(name[12] == 'B', name);
0126     check(name[13] == 'L', name);
0127     check(name[14] == 'D', name);
0128     check(std::isdigit(name[15]), name);
0129     digit[0] = name[15];
0130     int bld = atoi(digit);
0131     unsigned int offset = 0;
0132     if (std::isdigit(name[16])) {
0133       digit[0] = name[16];
0134       bld = 10 * bld + atoi(digit);
0135       offset++;
0136     }
0137     check(name[16 + offset] == '_', name);
0138     check(name[17 + offset] == 'P', name);
0139     check(name[18 + offset] == 'N', name);
0140     check(name[19 + offset] == 'L', name);
0141     check(std::isdigit(name[20 + offset]), name);
0142     digit[0] = name[20 + offset];
0143     int pnl = atoi(digit);
0144     check(name[21 + offset] == '_', name);
0145     check(name[22 + offset] == 'P', name);
0146     check(name[23 + offset] == 'L', name);
0147     check(name[24 + offset] == 'Q', name);
0148     check(std::isdigit(name[25 + offset]), name);
0149     digit[0] = name[25 + offset];
0150     int plq = atoi(digit);
0151     check(name[26 + offset] == '_', name);
0152     check(name[27 + offset] == 'R', name);
0153     check(name[28 + offset] == 'O', name);
0154     check(name[29 + offset] == 'C', name);
0155     check(std::isdigit(name[30 + offset]), name);
0156     digit[0] = name[30 + offset];
0157     int roc = atoi(digit);
0158     if (name.size() == 32 + offset) {
0159       digit[0] = name[31 + offset];
0160       roc = roc * 10 + atoi(digit);
0161     }
0162 
0163     setIdFPix(np, LR, disk, bld, pnl, plq, roc);
0164   } else {
0165     check(name[0] == 'B', name);
0166     check(name[1] == 'P', name);
0167     check(name[2] == 'i', name);
0168     check(name[3] == 'x', name);
0169     check(name[4] == '_', name);
0170     check(name[5] == 'B', name);
0171     check((name[6] == 'm') || (name[6] == 'p'), name);
0172     char np = name[6];
0173     check((name[7] == 'I') || (name[7] == 'O'), name);
0174     char LR = name[7];
0175     check(name[8] == '_', name);
0176     check(name[9] == 'S', name);
0177     check(name[10] == 'E', name);
0178     check(name[11] == 'C', name);
0179     char digit[2] = {0, 0};
0180     digit[0] = name[12];
0181     int sec = atoi(digit);
0182     check(name[13] == '_', name);
0183     check(name[14] == 'L', name);
0184     check(name[15] == 'Y', name);
0185     check(name[16] == 'R', name);
0186     check(std::isdigit(name[17]), name);
0187     digit[0] = name[17];
0188     int layer = atoi(digit);
0189     check(name[18] == '_', name);
0190     check(name[19] == 'L', name);
0191     check(name[20] == 'D', name);
0192     check(name[21] == 'R', name);
0193     check(std::isdigit(name[22]), name);
0194     digit[0] = name[22];
0195     int ladder = atoi(digit);
0196     unsigned int offset = 0;
0197     if (std::isdigit(name[23])) {
0198       offset++;
0199       digit[0] = name[22 + offset];
0200       ladder = 10 * ladder + atoi(digit);
0201     }
0202     check(name[23 + offset] == 'H' || name[23 + offset] == 'F', name);
0203     char HF = name[23 + offset];
0204     check(name[24 + offset] == '_', name);
0205     check(name[25 + offset] == 'M', name);
0206     check(name[26 + offset] == 'O', name);
0207     check(name[27 + offset] == 'D', name);
0208     check(std::isdigit(name[28 + offset]), name);
0209     digit[0] = name[28 + offset];
0210     int module = atoi(digit);
0211     check(name[29 + offset] == '_', name);
0212     check(name[30 + offset] == 'R', name);
0213     check(name[31 + offset] == 'O', name);
0214     check(name[32 + offset] == 'C', name);
0215     check(std::isdigit(name[33 + offset]), name);
0216     digit[0] = name[33 + offset];
0217     int roc = atoi(digit);
0218     if (name.size() == 35 + offset) {
0219       digit[0] = name[34 + offset];
0220       roc = roc * 10 + atoi(digit);
0221     }
0222 
0223     setIdBPix(np, LR, sec, layer, ladder, HF, module, roc);
0224   }
0225 }
0226 
0227 PixelROCName::PixelROCName(std::ifstream& s) {
0228   std::string tmp;
0229 
0230   s >> tmp;
0231 
0232   parsename(tmp);
0233 }
0234 
0235 std::string PixelROCName::rocname() const {
0236   std::string s;
0237 
0238   std::ostringstream s1;
0239 
0240   if (detsub() == 'F') {
0241     s1 << "FPix";
0242     s1 << "_B";
0243     s1 << mp();
0244     s1 << IO();
0245     s1 << "_D";
0246     s1 << disk();
0247     s1 << "_BLD";
0248     s1 << blade();
0249     s1 << "_PNL";
0250     s1 << panel();
0251     s1 << "_PLQ";
0252     s1 << plaquet();
0253     s1 << "_ROC";
0254     s1 << roc();
0255 
0256     assert(roc() >= 0 && roc() <= 10);
0257   } else {
0258     s1 << "BPix";
0259     s1 << "_B";
0260     s1 << mp();
0261     s1 << IO();
0262     s1 << "_SEC";
0263     s1 << sec();
0264     s1 << "_LYR";
0265     s1 << layer();
0266     s1 << "_LDR";
0267     s1 << ladder();
0268     s1 << HF();
0269     s1 << "_MOD";
0270     s1 << module();
0271     s1 << "_ROC";
0272     s1 << roc();
0273 
0274     assert(roc() >= 0 && roc() <= 15);
0275   }
0276 
0277   s = s1.str();
0278 
0279   return s;
0280 }
0281 
0282 std::ostream& pos::operator<<(std::ostream& s, const PixelROCName& pixelroc) {
0283   // FPix_BpR_D1_BLD1_PNL1_PLQ1_ROC1
0284 
0285   s << pixelroc.rocname();
0286 
0287   return s;
0288 }