CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PixelROCName.cc
Go to the documentation of this file.
1 //
2 // This class stores the name and related
3 // hardware mapings for a ROC
4 //
5 
6 
8 #include <string>
9 #include <iostream>
10 #include <sstream>
11 #include <cctype>
12 #include <cassert>
13 #include <cstdlib>
14 
15 using namespace std;
16 using namespace pos;
17 
18 PixelROCName::PixelROCName():
19  id_(0)
20 {}
21 
22 PixelROCName::PixelROCName(std::string rocname)
23 {
24 
25  parsename(rocname);
26 
27 }
28 
29 void PixelROCName::setIdFPix(char np, char LR,int disk,
30  int blade, int panel, int plaquet, int roc){
31 
32  std::string mthn = "[PixelROCName::setIdFPix()]\t\t\t\t " ;
33  id_=0;
34 
35  //std::cout << __LINE__ << "]\t" << mthn << "subdet: " << subdet << std::endl;
36  //std::cout << __LINE__ << "]\t" << mthn << "np : " << np << std::endl;
37  //std::cout << __LINE__ << "]\t" << mthn << "LR : " << LR << std::endl;
38  //std::cout << __LINE__ << "]\t" << mthn << "disk : " << disk << std::endl;
39 
40 
41  assert(roc>=0&&roc<10);
42 
43  if (np=='p') id_=(id_|0x40000000);
44  //std::cout<< __LINE__ << "]\t" << mthn <<"2 id_="<<std::hex<<id_<<std::dec<<std::endl;
45  if (LR=='I') id_=(id_|0x20000000);
46  //std::cout<< __LINE__ << "]\t" << mthn <<"3 id_="<<std::hex<<id_<<std::dec<<std::endl;
47  id_=(id_|(disk<<12));
48  //std::cout<< __LINE__ << "]\t" << mthn <<"4 id_="<<std::hex<<id_<<std::dec<<std::endl;
49  id_=(id_|(blade<<7));
50  //std::cout<< __LINE__ << "]\t" << mthn <<"5 id_="<<std::hex<<id_<<std::dec<<std::endl;
51  id_=(id_|((panel-1)<<6));
52  //std::cout<< __LINE__ << "]\t" << mthn <<"6 id_="<<std::hex<<id_<<std::dec<<std::endl;
53  id_=(id_|((plaquet-1)<<4));
54  //std::cout<< __LINE__ << "]\t" << mthn <<"7 id_="<<std::hex<<id_<<std::dec<<std::endl;
55  id_=(id_|roc);
56 
57  //std::cout<< __LINE__ << "]\t" << mthn <<"final id_="<<std::hex<<id_<<std::dec<<std::endl;
58 
59 }
60 
61 
62 void PixelROCName::setIdBPix(char np, char LR,int sec,
63  int layer, int ladder, char HF,
64  int module, int roc){
65 
66  id_=0;
67 
68  //std::cout<< __LINE__ << "]\t" << mthn <<"BPix ladder:"<<ladder<<std::endl;
69  //std::cout<< __LINE__ << "]\t" << mthn <<"np : " << np << std::endl;
70  //std::cout<< __LINE__ << "]\t" << mthn <<"LR : " << LR << std::endl;
71  //std::cout<< __LINE__ << "]\t" << mthn <<"disk: " << disk << std::endl;
72 
73 
74  assert(roc>=0&&roc<16);
75 
76  id_=0x80000000;
77 
78  if (np=='p') id_=(id_|0x40000000);
79  //std::cout<< __LINE__ << "]\t" << mthn <<"2 id_="<<std::hex<<id_<<std::dec<<std::endl;
80  if (LR=='I') id_=(id_|0x20000000);
81  //std::cout<< __LINE__ << "]\t" << mthn <<"3 id_="<<std::hex<<id_<<std::dec<<std::endl;
82  id_=(id_|((sec-1)<<14));
83  //std::cout<< __LINE__ << "]\t" << mthn <<"4 id_="<<std::hex<<id_<<std::dec<<std::endl;
84  if (HF=='F') id_=(id_|0x00000800);
85 
86  id_=(id_|(layer<<12));
87  //std::cout<< __LINE__ << "]\t" << mthn <<"5 id_="<<std::hex<<id_<<std::dec<<std::endl;
88  id_=(id_|(ladder<<6));
89  //std::cout<< __LINE__ << "]\t" << mthn <<"6 id_="<<std::hex<<id_<<std::dec<<std::endl;
90  id_=(id_|((module-1)<<4));
91  //std::cout<< __LINE__ << "]\t" << mthn <<"7 id_="<<std::hex<<id_<<std::dec<<std::endl;
92  id_=(id_|roc);
93 
94  //std::cout<< __LINE__ << "]\t" << mthn <<"final id_="<<std::hex<<id_<<std::dec<<std::endl;
95 
96 }
97 
98 
99 void PixelROCName::check(bool check, const string& name){
100 
101  static std::string mthn = "[PixelROCName::check()]\t\t\t\t " ;
102 
103  if (check) return;
104 
105  cout << __LINE__ << "]\t" << mthn << "ERROR tried to parse string:'"<<name;
106  cout << "' as a ROC name. Will terminate."<<endl;
107 
108  ::abort();
109 
110 }
111 
112 
113 
114 void PixelROCName::parsename(std::string name){
115 
116  //
117  // The name should be on the format
118  //
119  // FPix_BpR_D1_BLD1_PNL1_PLQ1_ROC1
120  //
121 
122 
123  // std::cout << "[PixelROCName::parsename()]\t\tROC name:"<<name<<std::endl;
124 
125  check(name[0]=='F'||name[0]=='B',name);
126 
127  if (name[0]=='F'){
128  check(name[0]=='F',name);
129  check(name[1]=='P',name);
130  check(name[2]=='i',name);
131  check(name[3]=='x',name);
132  check(name[4]=='_',name);
133  check(name[5]=='B',name);
134  check((name[6]=='m')||(name[6]=='p'),name);
135  char np=name[6];
136  check((name[7]=='I')||(name[7]=='O'),name);
137  char LR=name[7];
138  check(name[8]=='_',name);
139  check(name[9]=='D',name);
140  char digit[2]={0,0};
141  digit[0]=name[10];
142  int disk=atoi(digit);
143  check(name[11]=='_',name);
144  check(name[12]=='B',name);
145  check(name[13]=='L',name);
146  check(name[14]=='D',name);
147  check(std::isdigit(name[15]),name);
148  digit[0]=name[15];
149  int bld=atoi(digit);
150  unsigned int offset=0;
151  if (std::isdigit(name[16])){
152  digit[0]=name[16];
153  bld=10*bld+atoi(digit);
154  offset++;
155  }
156  check(name[16+offset]=='_',name);
157  check(name[17+offset]=='P',name);
158  check(name[18+offset]=='N',name);
159  check(name[19+offset]=='L',name);
160  check(std::isdigit(name[20+offset]),name);
161  digit[0]=name[20+offset];
162  int pnl=atoi(digit);
163  check(name[21+offset]=='_',name);
164  check(name[22+offset]=='P',name);
165  check(name[23+offset]=='L',name);
166  check(name[24+offset]=='Q',name);
167  check(std::isdigit(name[25+offset]),name);
168  digit[0]=name[25+offset];
169  int plq=atoi(digit);
170  check(name[26+offset]=='_',name);
171  check(name[27+offset]=='R',name);
172  check(name[28+offset]=='O',name);
173  check(name[29+offset]=='C',name);
174  check(std::isdigit(name[30+offset]),name);
175  digit[0]=name[30+offset];
176  int roc=atoi(digit);
177  if (name.size()==32+offset){
178  digit[0]=name[31+offset];
179  roc=roc*10+atoi(digit);
180  }
181 
182  setIdFPix(np,LR,disk,bld,pnl,plq,roc);
183  }
184  else{
185  check(name[0]=='B',name);
186  check(name[1]=='P',name);
187  check(name[2]=='i',name);
188  check(name[3]=='x',name);
189  check(name[4]=='_',name);
190  check(name[5]=='B',name);
191  check((name[6]=='m')||(name[6]=='p'),name);
192  char np=name[6];
193  check((name[7]=='I')||(name[7]=='O'),name);
194  char LR=name[7];
195  check(name[8]=='_',name);
196  check(name[9]=='S',name);
197  check(name[10]=='E',name);
198  check(name[11]=='C',name);
199  char digit[2]={0,0};
200  digit[0]=name[12];
201  int sec=atoi(digit);
202  check(name[13]=='_',name);
203  check(name[14]=='L',name);
204  check(name[15]=='Y',name);
205  check(name[16]=='R',name);
206  check(std::isdigit(name[17]),name);
207  digit[0]=name[17];
208  int layer=atoi(digit);
209  check(name[18]=='_',name);
210  check(name[19]=='L',name);
211  check(name[20]=='D',name);
212  check(name[21]=='R',name);
213  check(std::isdigit(name[22]),name);
214  digit[0]=name[22];
215  int ladder=atoi(digit);
216  unsigned int offset=0;
217  if (std::isdigit(name[23])){
218  offset++;
219  digit[0]=name[22+offset];
220  ladder=10*ladder+atoi(digit);
221  }
222  check(name[23+offset]=='H'||name[23+offset]=='F',name);
223  char HF=name[23+offset];
224  check(name[24+offset]=='_',name);
225  check(name[25+offset]=='M',name);
226  check(name[26+offset]=='O',name);
227  check(name[27+offset]=='D',name);
228  check(std::isdigit(name[28+offset]),name);
229  digit[0]=name[28+offset];
230  int module=atoi(digit);
231  check(name[29+offset]=='_',name);
232  check(name[30+offset]=='R',name);
233  check(name[31+offset]=='O',name);
234  check(name[32+offset]=='C',name);
235  check(std::isdigit(name[33+offset]),name);
236  digit[0]=name[33+offset];
237  int roc=atoi(digit);
238  if (name.size()==35+offset){
239  digit[0]=name[34+offset];
240  roc=roc*10+atoi(digit);
241  }
242 
243  setIdBPix(np,LR,sec,layer,ladder,HF,module,roc);
244  }
245 
246 }
247 
249 
250  std::string tmp;
251 
252  s >> tmp;
253 
254  parsename(tmp);
255 
256 }
257 
258 
259 std::string PixelROCName::rocname() const{
260 
261  std::string s;
262 
263  std::ostringstream s1;
264 
265  if (detsub()=='F') {
266  s1<<"FPix";
267  s1<<"_B";
268  s1<<mp();
269  s1<<IO();
270  s1<<"_D";
271  s1<<disk();
272  s1<<"_BLD";
273  s1<<blade();
274  s1<<"_PNL";
275  s1<<panel();
276  s1<<"_PLQ";
277  s1<<plaquet();
278  s1<<"_ROC";
279  s1<<roc();
280 
281  assert(roc()>=0&&roc()<=10);
282  }
283  else{
284  s1<<"BPix";
285  s1<<"_B";
286  s1<<mp();
287  s1<<IO();
288  s1<<"_SEC";
289  s1<<sec();
290  s1<<"_LYR";
291  s1<<layer();
292  s1<<"_LDR";
293  s1<<ladder();
294  s1<<HF();
295  s1<<"_MOD";
296  s1<<module();
297  s1<<"_ROC";
298  s1<<roc();
299 
300  assert(roc()>=0&&roc()<=15);
301  }
302 
303  s=s1.str();
304 
305  return s;
306 
307 }
308 
309 
310 
311 std::ostream& pos::operator<<(std::ostream& s, const PixelROCName& pixelroc){
312 
313 
314  // FPix_BpR_D1_BLD1_PNL1_PLQ1_ROC1
315 
316  s<<pixelroc.rocname();
317 
318  return s;
319 }
320 
321 
323 
324  id_=aROC.id_;
325 
326  return *this;
327 
328 }
void setIdFPix(char np, char LR, int disk, int blade, int panel, int plaquet, int roc)
Definition: PixelROCName.cc:29
int plaquet() const
Definition: PixelROCName.h:45
int ladder() const
Definition: PixelROCName.h:50
const PixelROCName & operator=(const PixelROCName &aROC)
int panel() const
Definition: PixelROCName.h:44
unsigned int id_
Definition: PixelROCName.h:112
void setIdBPix(char np, char LR, int sec, int layer, int ladder, char HF, int module, int roc)
Definition: PixelROCName.cc:62
int layer() const
Definition: PixelROCName.h:49
int blade() const
Definition: PixelROCName.h:43
char IO() const
Definition: PixelROCName.h:38
std::string rocname() const
std::ostream & operator<<(std::ostream &s, const PixelCalibConfiguration &calib)
int np
Definition: AMPTWrapper.h:33
bool check(const DataFrame &df, bool capcheck, bool dvercheck)
char HF() const
Definition: PixelROCName.h:51
int module() const
Definition: PixelROCName.h:52
void check(bool check, const std::string &name)
Definition: PixelROCName.cc:99
int roc() const
Definition: PixelROCName.h:39
void parsename(std::string name)
int sec() const
Definition: PixelROCName.h:48
unsigned int offset(bool)
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
This class implements..
Definition: PixelROCName.h:23
int disk() const
Definition: PixelROCName.h:42
tuple cout
Definition: gather_cfg.py:121
char detsub() const
Definition: PixelROCName.h:36
Definition: vlib.h:209
char mp() const
Definition: PixelROCName.h:37
This class stores the name and related hardware mappings for a ROC.