Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:47:27

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