CMS 3D CMS Logo

PixelROCName.cc

Go to the documentation of this file.
00001 //
00002 // This class stores the name and related
00003 // hardware mapings for a ROC
00004 //
00005 
00006 
00007 #include "CalibFormats/SiPixelObjects/interface/PixelROCName.h"
00008 #include <string>
00009 #include <iostream>
00010 #include <sstream>
00011 #include <cctype>
00012 
00013 #include <assert.h>
00014 
00015 
00016 using namespace std;
00017 using namespace pos;
00018 
00019 PixelROCName::PixelROCName():
00020     id_(0)
00021 {}
00022 
00023 PixelROCName::PixelROCName(std::string rocname)
00024 {
00025 
00026     parsename(rocname);
00027 
00028 }
00029 
00030 void PixelROCName::setIdFPix(char np, char LR,int disk,
00031                          int blade, int panel, int plaquet, int roc){
00032 
00033     id_=0;
00034 
00035     //std::cout<<"PixelROCName::setId subdet:"<<subdet<<std::endl; 
00036     //std::cout<<"PixelROCName::setId np:"<<np<<std::endl; 
00037     //std::cout<<"PixelROCName::setId LR:"<<LR<<std::endl; 
00038     //std::cout<<"PixelROCName::setId disk:"<<disk<<std::endl; 
00039 
00040     
00041     assert(roc>=0&&roc<10);
00042 
00043     if (np=='p') id_=(id_|0x40000000);
00044     //std::cout<<"PixelROCName::setId 2 id_="<<std::hex<<id_<<std::dec<<std::endl; 
00045     if (LR=='I') id_=(id_|0x20000000);
00046     //std::cout<<"PixelROCName::setId 3 id_="<<std::hex<<id_<<std::dec<<std::endl; 
00047     id_=(id_|(disk<<12));
00048     //std::cout<<"PixelROCName::setId 4 id_="<<std::hex<<id_<<std::dec<<std::endl; 
00049     id_=(id_|(blade<<7));
00050     //std::cout<<"PixelROCName::setId 5 id_="<<std::hex<<id_<<std::dec<<std::endl; 
00051     id_=(id_|((panel-1)<<6));
00052     //std::cout<<"PixelROCName::setId 6 id_="<<std::hex<<id_<<std::dec<<std::endl; 
00053     id_=(id_|((plaquet-1)<<4));
00054     //std::cout<<"PixelROCName::setId 7 id_="<<std::hex<<id_<<std::dec<<std::endl; 
00055     id_=(id_|roc);
00056 
00057     //std::cout<<"PixelROCName::setIdFPix final id_="<<std::hex<<id_<<std::dec<<std::endl; 
00058 
00059 }
00060 
00061 
00062 void PixelROCName::setIdBPix(char np, char LR,int sec,
00063                              int layer, int ladder, char HF,
00064                              int module, int roc){
00065 
00066     id_=0;
00067 
00068     //std::cout<<"PixelROCName::setIdBPix ladder:"<<ladder<<std::endl; 
00069     //std::cout<<"PixelROCName::setId np:"<<np<<std::endl; 
00070     //std::cout<<"PixelROCName::setId LR:"<<LR<<std::endl; 
00071     //std::cout<<"PixelROCName::setId disk:"<<disk<<std::endl; 
00072 
00073     
00074     assert(roc>=0&&roc<16);
00075 
00076     id_=0x80000000;
00077 
00078     if (np=='p') id_=(id_|0x40000000);
00079     //std::cout<<"PixelROCName::setId 2 id_="<<std::hex<<id_<<std::dec<<std::endl; 
00080     if (LR=='I') id_=(id_|0x20000000);
00081     //std::cout<<"PixelROCName::setId 3 id_="<<std::hex<<id_<<std::dec<<std::endl; 
00082     id_=(id_|((sec-1)<<14));
00083     //std::cout<<"PixelROCName::setId 4 id_="<<std::hex<<id_<<std::dec<<std::endl; 
00084     if (HF=='F') id_=(id_|0x00000800);
00085 
00086     id_=(id_|(layer<<12));
00087     //std::cout<<"PixelROCName::setId 5 id_="<<std::hex<<id_<<std::dec<<std::endl; 
00088     id_=(id_|(ladder<<6));
00089     //std::cout<<"PixelROCName::setId 6 id_="<<std::hex<<id_<<std::dec<<std::endl; 
00090     id_=(id_|((module-1)<<4));
00091     //std::cout<<"PixelROCName::setId 7 id_="<<std::hex<<id_<<std::dec<<std::endl; 
00092     id_=(id_|roc);
00093 
00094     //std::cout<<"PixelROCName::setIdBPix final id_="<<std::hex<<id_<<std::dec<<std::endl; 
00095 
00096 }
00097 
00098 
00099 void PixelROCName::check(bool check, const string& name){
00100 
00101   if (check) return;
00102 
00103   cout << "ERROR tried to parse string:'"<<name;
00104   cout << "' as a ROC name. Will terminate."<<endl;
00105 
00106   ::abort();
00107 
00108 }
00109 
00110 
00111 
00112 void PixelROCName::parsename(std::string name){
00113 
00114    //
00115     // The name should be on the format
00116     //
00117     // FPix_BpR_D1_BLD1_PNL1_PLQ1_ROC1
00118     //
00119 
00120     
00121 //    std::cout << "[PixelROCName::parsename()]\t\tROC name:"<<name<<std::endl;
00122 
00123     check(name[0]=='F'||name[0]=='B',name);
00124 
00125     if (name[0]=='F'){
00126         check(name[0]=='F',name);
00127         check(name[1]=='P',name);
00128         check(name[2]=='i',name);
00129         check(name[3]=='x',name);
00130         check(name[4]=='_',name);
00131         check(name[5]=='B',name);
00132         check((name[6]=='m')||(name[6]=='p'),name);
00133         char np=name[6];
00134         check((name[7]=='I')||(name[7]=='O'),name);
00135         char LR=name[7];
00136         check(name[8]=='_',name);
00137         check(name[9]=='D',name);
00138         char digit[2]={0,0};
00139         digit[0]=name[10];
00140         int disk=atoi(digit);
00141         check(name[11]=='_',name);
00142         check(name[12]=='B',name);
00143         check(name[13]=='L',name);
00144         check(name[14]=='D',name);
00145         check(std::isdigit(name[15]),name);
00146         digit[0]=name[15];
00147         int bld=atoi(digit);
00148         unsigned int offset=0;
00149         if (std::isdigit(name[16])){
00150           digit[0]=name[16];
00151           bld=10*bld+atoi(digit);
00152             offset++;
00153         }
00154         check(name[16+offset]=='_',name);
00155         check(name[17+offset]=='P',name);
00156         check(name[18+offset]=='N',name);
00157         check(name[19+offset]=='L',name);
00158         check(std::isdigit(name[20+offset]),name);
00159         digit[0]=name[20+offset];
00160         int pnl=atoi(digit);
00161         check(name[21+offset]=='_',name);
00162         check(name[22+offset]=='P',name);
00163         check(name[23+offset]=='L',name);
00164         check(name[24+offset]=='Q',name);
00165         check(std::isdigit(name[25+offset]),name);
00166         digit[0]=name[25+offset];
00167         int plq=atoi(digit);
00168         check(name[26+offset]=='_',name);
00169         check(name[27+offset]=='R',name);
00170         check(name[28+offset]=='O',name);
00171         check(name[29+offset]=='C',name);
00172         check(std::isdigit(name[30+offset]),name);
00173         digit[0]=name[30+offset];
00174         int roc=atoi(digit);
00175         if (name.size()==32+offset){
00176             digit[0]=name[31+offset];
00177             roc=roc*10+atoi(digit);
00178         }
00179     
00180         setIdFPix(np,LR,disk,bld,pnl,plq,roc);
00181     }
00182     else{
00183         check(name[0]=='B',name);
00184         check(name[1]=='P',name);
00185         check(name[2]=='i',name);
00186         check(name[3]=='x',name);
00187         check(name[4]=='_',name);
00188         check(name[5]=='B',name);
00189         check((name[6]=='m')||(name[6]=='p'),name);
00190         char np=name[6];
00191         check((name[7]=='I')||(name[7]=='O'),name);
00192         char LR=name[7];
00193         check(name[8]=='_',name);
00194         check(name[9]=='S',name);
00195         check(name[10]=='E',name);
00196         check(name[11]=='C',name);
00197         char digit[2]={0,0};
00198         digit[0]=name[12];
00199         int sec=atoi(digit);
00200         check(name[13]=='_',name);
00201         check(name[14]=='L',name);
00202         check(name[15]=='Y',name);
00203         check(name[16]=='R',name);
00204         check(std::isdigit(name[17]),name);
00205         digit[0]=name[17];
00206         int layer=atoi(digit);
00207         check(name[18]=='_',name);
00208         check(name[19]=='L',name);
00209         check(name[20]=='D',name);
00210         check(name[21]=='R',name);
00211         check(std::isdigit(name[22]),name);
00212         digit[0]=name[22];
00213         int ladder=atoi(digit);
00214         unsigned int offset=0;
00215         if (std::isdigit(name[23])){
00216             offset++;
00217             digit[0]=name[22+offset];
00218             ladder=10*ladder+atoi(digit);
00219         }
00220         check(name[23+offset]=='H'||name[23+offset]=='F',name);
00221         char HF=name[23+offset];
00222         check(name[24+offset]=='_',name);
00223         check(name[25+offset]=='M',name);
00224         check(name[26+offset]=='O',name);
00225         check(name[27+offset]=='D',name);
00226         check(std::isdigit(name[28+offset]),name);
00227         digit[0]=name[28+offset];
00228         int module=atoi(digit);
00229         check(name[29+offset]=='_',name);
00230         check(name[30+offset]=='R',name);
00231         check(name[31+offset]=='O',name);
00232         check(name[32+offset]=='C',name);
00233         check(std::isdigit(name[33+offset]),name);
00234         digit[0]=name[33+offset];
00235         int roc=atoi(digit);
00236         if (name.size()==35+offset){
00237             digit[0]=name[34+offset];
00238             roc=roc*10+atoi(digit);
00239         }
00240     
00241         setIdBPix(np,LR,sec,layer,ladder,HF,module,roc);
00242     }
00243 
00244 }
00245 
00246 PixelROCName::PixelROCName(std::ifstream& s){
00247 
00248     std::string tmp;
00249 
00250     s >> tmp;
00251 
00252     parsename(tmp);
00253 
00254 }
00255     
00256 
00257 std::string PixelROCName::rocname() const{
00258 
00259     std::string s;
00260 
00261     std::ostringstream s1;
00262 
00263     if (detsub()=='F') {
00264         s1<<"FPix"; 
00265         s1<<"_B";
00266         s1<<mp();
00267         s1<<IO();
00268         s1<<"_D";
00269         s1<<disk();
00270         s1<<"_BLD";
00271         s1<<blade();
00272         s1<<"_PNL";
00273         s1<<panel();
00274         s1<<"_PLQ";
00275         s1<<plaquet();
00276         s1<<"_ROC";
00277         s1<<roc();
00278 
00279         assert(roc()>=0&&roc()<=10);
00280     }
00281     else{
00282         s1<<"BPix"; 
00283         s1<<"_B";
00284         s1<<mp();
00285         s1<<IO();
00286         s1<<"_SEC";
00287         s1<<sec();
00288         s1<<"_LYR";
00289         s1<<layer();
00290         s1<<"_LDR";
00291         s1<<ladder();
00292         s1<<HF();
00293         s1<<"_MOD";
00294         s1<<module();
00295         s1<<"_ROC";
00296         s1<<roc();
00297         
00298         assert(roc()>=0&&roc()<=15);
00299     }
00300 
00301     s=s1.str();
00302    
00303     return s;
00304 
00305 } 
00306 
00307 
00308 
00309 std::ostream& pos::operator<<(std::ostream& s, const PixelROCName& pixelroc){
00310 
00311 
00312     // FPix_BpR_D1_BLD1_PNL1_PLQ1_ROC1
00313 
00314     s<<pixelroc.rocname();
00315 
00316     return s;
00317 }
00318 
00319 
00320 const PixelROCName& PixelROCName::operator=(const PixelROCName& aROC){
00321     
00322     id_=aROC.id_;
00323 
00324     return *this;
00325 
00326 }

Generated on Tue Jun 9 17:25:25 2009 for CMSSW by  doxygen 1.5.4