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