CMS 3D CMS Logo

PixelNameTranslation.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 
10 //#include "PixelUtilities/PixelTestStandUtilities/include/PixelTimer.h"
11 #include <fstream>
12 #include <sstream>
13 #include <map>
14 #include <string>
15 #include <vector>
16 #include <cassert>
17 #include <stdexcept>
18 
19 using namespace pos;
20 using namespace std;
21 
22 PixelNameTranslation::PixelNameTranslation(std::vector<std::vector<std::string> >& tableMat)
23  : PixelConfigBase(" ", " ", " ") {
24  std::string mthn = "[PixelNameTranslation::PixelNameTranslation()]\t\t ";
25  std::map<std::string, int> colM;
26  std::vector<std::string> colNames;
27 
28  /*
29  EXTENSION_TABLE_NAME: PIXEL_NAME_TRANS (VIEW: CONF_KEY_NAME_TRANS_V)
30 
31  CONFIG_KEY NOT NULL VARCHAR2(80)
32  KEY_TYPE NOT NULL VARCHAR2(80)
33  KEY_ALIAS NOT NULL VARCHAR2(80)
34  VERSION VARCHAR2(40)
35  KIND_OF_COND NOT NULL VARCHAR2(40)
36  ROC_NAME NOT NULL VARCHAR2(200)
37  PXLFEC_NAME NOT NULL NUMBER(38)
38  MFEC_POSN NOT NULL NUMBER(38)
39  MFEC_CHAN NOT NULL NUMBER(38)
40  HUB_ADDRS NUMBER(38)
41  PORT_NUM NOT NULL NUMBER(38)
42  ROC_I2C_ADDR NOT NULL NUMBER(38)
43  PXLFED_NAME NOT NULL NUMBER(38)
44  FED_CHAN NOT NULL NUMBER(38)
45  FED_ROC_NUM NOT NULL NUMBER(38)
46  TBM_MODE VARCHAR2(200)
47 */
48 
49  colNames.push_back("CONFIG_KEY"); //0
50  colNames.push_back("KEY_TYPE"); //1
51  colNames.push_back("KEY_ALIAS"); //2
52  colNames.push_back("VERSION"); //3
53  colNames.push_back("KIND_OF_COND"); //4
54  colNames.push_back("ROC_NAME"); //5
55  colNames.push_back("PXLFEC_NAME"); //6
56  colNames.push_back("MFEC_POSN"); //7
57  colNames.push_back("MFEC_CHAN"); //8
58  colNames.push_back("HUB_ADDRS"); //9
59  colNames.push_back("PORT_NUM"); //10
60  colNames.push_back("ROC_I2C_ADDR"); //11
61  colNames.push_back("PXLFED_NAME"); //12
62  colNames.push_back("FED_CHAN"); //13
63  colNames.push_back("FED_ROC_NUM"); //14
64  colNames.push_back("TBM_MODE"); //15
65 
66  for (unsigned int c = 0; c < tableMat[0].size(); c++) {
67  for (unsigned int n = 0; n < colNames.size(); n++) {
68  if (tableMat[0][c] == colNames[n]) {
69  colM[colNames[n]] = c;
70  break;
71  }
72  }
73  } //end for
74  /*
75  for(unsigned int n=0; n<colNames.size(); n++){
76  if(colM.find(colNames[n]) == colM.end()){
77  std::cerr << __LINE__ << "]\t" << mthn << "Couldn't find in the database the column with name " << colNames[n] << std::endl;
78  assert(0);
79  }
80  }
81  */
82 
83  for (unsigned int r = 1; r < tableMat.size(); r++) { //Goes to every row of the Matrix
84  std::string rocname = tableMat[r][colM["ROC_NAME"]];
85  std::string TBMChannel = tableMat[r][colM["TBM_MODE"]]; // assert(0); // need to add this to the input table
86  if (TBMChannel.empty()) {
87  TBMChannel = "A";
88  }
89  /* // modified by MR on 13-07-2008 11:32:50
90  Umesh changed the content of the column and
91  stripped out the FPix_Pxl_FEC_ part of the "number"
92  tableMat[r][colM["PXLFEC_NAME"]].erase(0 , 13);//PIXFEC
93  unsigned int fecnumber = (unsigned int)atoi(tableMat[r][colM["PXLFEC_NAME"]].c_str());
94  */
95  unsigned int fecnumber = (unsigned int)atoi(tableMat[r][colM["PXLFEC_NAME"]].c_str());
96  unsigned int mfec = (unsigned int)atoi(tableMat[r][colM["MFEC_POSN"]].c_str());
97  unsigned int mfecchannel = (unsigned int)atoi(tableMat[r][colM["MFEC_CHAN"]].c_str());
98  unsigned int hubaddress = (unsigned int)atoi(tableMat[r][colM["HUB_ADDRS"]].c_str());
99  unsigned int portaddress = (unsigned int)atoi(tableMat[r][colM["PORT_NUM"]].c_str());
100  unsigned int rocid = (unsigned int)atoi(tableMat[r][colM["ROC_I2C_ADDR"]].c_str());
101  // modified by MR on 13-07-2008 11:47:32
102  /* Umesh changed the content of the column and
103  stripped out the PxlFED_ part of the "number"
104 
105  tableMat[r][colM["PXLFED_NAME"]].erase(0,7);//FED
106  */
107  unsigned int fednumber = (unsigned int)atoi(tableMat[r][colM["PXLFED_NAME"]].c_str());
108  unsigned int fedchannel = (unsigned int)atoi(tableMat[r][colM["FED_CHAN"]].c_str());
109  unsigned int fedrocnumber = (unsigned int)(atoi(tableMat[r][colM["FED_ROC_NUM"]].c_str()));
110 
111  PixelROCName aROC(rocname);
112  if (aROC.rocname() != rocname) {
113  std::cout << __LINE__ << "]\t" << mthn << "Rocname : " << rocname << std::endl;
114  std::cout << __LINE__ << "]\t" << mthn << "Parsed to: " << aROC.rocname() << std::endl;
115  assert(0);
116  }
117 
118  if (ROCNameFromFEDChannelROCExists(fednumber, fedchannel, fedrocnumber)) {
119  std::cout << __LINE__ << "]\t" << mthn << "ROC with fednumber=" << fednumber << " fedchannel=" << fedchannel
120  << " roc number=" << fedrocnumber << " already exists" << std::endl;
121  std::cout << __LINE__ << "]\t" << mthn << "Fix this inconsistency in the name translation" << std::endl;
122  assert(0);
123  }
124 
125  PixelHdwAddress hdwAdd(
126  fecnumber, mfec, mfecchannel, hubaddress, portaddress, rocid, fednumber, fedchannel, fedrocnumber);
127  // std::cout << "[PixelNameTranslation::PixelNameTranslation()] aROC: " << aROC << std::endl;
128  translationtable_[aROC] = hdwAdd;
129  fedlookup_[hdwAdd] = aROC;
130 
131  PixelModuleName aModule(rocname);
132  PixelChannel aChannel(aModule, TBMChannel);
133 
134  hdwTranslationTable_[hdwAdd] = aChannel;
135 
136  // Look for this channel in channelTransaltionTable. If it is found, check that the hardware address agrees. If not, add it to the table. Also, if another channel on that module is found, check that the FEC part agrees, and the FED part doesn't.
137  bool foundChannel = false;
138 
139  std::map<PixelChannel, PixelHdwAddress>::const_iterator channelTranslationTable_itr =
140  channelTranslationTable_.find(aChannel);
141 
142  if (channelTranslationTable_itr != channelTranslationTable_.end()) {
143  if (!(channelTranslationTable_itr->second |= hdwAdd)) {
144  cout << "Found two ROCs on the same channe, but not same hdw" << endl;
145  cout << "Hdw1:" << endl << channelTranslationTable_itr->second << endl;
146  cout << "Hdw2:" << endl << hdwAdd << endl;
147  }
148  assert(channelTranslationTable_itr->second |= hdwAdd);
149  foundChannel = true;
150  } else if (channelTranslationTable_itr->first.module() == aModule) {
151  assert(channelTranslationTable_itr->second.fecnumber() == hdwAdd.fecnumber());
152  assert(channelTranslationTable_itr->second.mfec() == hdwAdd.mfec());
153  assert(channelTranslationTable_itr->second.mfecchannel() == hdwAdd.mfecchannel());
154  //assert( channelTranslationTable_itr->second.portaddress() == hdwAdd.portaddress() );
155  assert(channelTranslationTable_itr->second.hubaddress() == hdwAdd.hubaddress());
156  assert(channelTranslationTable_itr->second.fednumber() != hdwAdd.fednumber() ||
157  channelTranslationTable_itr->second.fedchannel() != hdwAdd.fedchannel());
158  }
159 
160  if (foundChannel == false) {
161  channelTranslationTable_[aChannel] = hdwAdd;
162  }
163 
164  } //end for r
165 
166  const std::map<unsigned int, std::set<unsigned int> > fedsAndChannels = getFEDsAndChannels();
167 
168  std::vector<PixelROCName> tmp(24);
169 
170  std::map<unsigned int, std::map<unsigned int, int> > counter;
171  // FED id FED channel
172 
173  std::map<unsigned int, std::map<unsigned int, int> > maxindex;
174 
175  std::map<PixelROCName, PixelHdwAddress>::const_iterator it = translationtable_.begin();
176 
177  for (; it != translationtable_.end(); ++it) {
178  int index = it->second.fedrocnumber();
179 
180  unsigned int fednumber = it->second.fednumber();
181  unsigned int fedchannel = it->second.fedchannel();
182 
183  std::vector<PixelROCName>& tmp = rocsFromFEDidAndChannel_[fednumber][fedchannel];
184 
185  if (tmp.empty()) {
186  tmp.resize(24);
187  counter[fednumber][fedchannel] = 0;
188  maxindex[fednumber][fedchannel] = 0;
189  }
190 
191  if (index > maxindex[fednumber][fedchannel])
192  maxindex[fednumber][fedchannel] = index;
193  tmp[index] = it->first;
194  counter[fednumber][fedchannel]++;
195  }
196 
197  it = translationtable_.begin();
198 
199  for (; it != translationtable_.end(); ++it) {
200  unsigned int fednumber = it->second.fednumber();
201  unsigned int fedchannel = it->second.fedchannel();
202 
203  std::vector<PixelROCName>& tmp = rocsFromFEDidAndChannel_[fednumber][fedchannel];
204 
205  assert(counter[fednumber][fedchannel] == maxindex[fednumber][fedchannel] + 1);
206 
207  tmp.resize(counter[fednumber][fedchannel]);
208  }
209 
210 } //end contructor
211 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
212 
214  static std::string mthn = "[PixelNameTranslation::PixelNameTranslation()]\t\t ";
215 
216  std::ifstream in(filename.c_str());
217 
218  if (!in.good()) {
219  std::cout << __LINE__ << "]\t" << mthn << "Could not open: " << filename << std::endl;
220  throw std::runtime_error("Failed to open file " + filename);
221  } else {
222  std::cout << __LINE__ << "]\t" << mthn << "Reading from: " << filename << std::endl;
223  }
224 
226 
227  getline(in, dummy); // skip the column headings
228 
229  do {
230  std::string rocname;
231  std::string TBMChannel;
232  unsigned int fecnumber;
233  unsigned int mfec;
234  unsigned int mfecchannel;
235  unsigned int hubaddress;
236  unsigned int portaddress;
237  unsigned int rocid;
238  unsigned int fednumber;
239  unsigned int fedchannel;
240  unsigned int fedrocnumber;
241 
242  in >> rocname;
243  in >> TBMChannel;
244  if (TBMChannel != "A" &&
245  TBMChannel !=
246  "B") // no TBM channel was specified, so default to A and set fecnumber to the value of this string
247  {
248  fecnumber = atoi(TBMChannel.c_str());
249  TBMChannel = "A";
250  } else // TBM channel was specified, now read fecnumber
251  {
252  in >> fecnumber;
253  }
254  in >> mfec >> mfecchannel >> hubaddress >> portaddress >> rocid >> fednumber >> fedchannel >> fedrocnumber;
255 
256  if (!in.eof()) {
257  PixelROCName aROC(rocname);
258 
259  //debug
260  //if (aROC.rocname()!=rocname){
261  //std::cout << __LINE__ << "]\t" << mthn << "Rocname : " << rocname << std::endl;
262  //std::cout << __LINE__ << "]\t" << mthn << "Parsed to: " << aROC.rocname() << std::endl;
263  //assert(0);
264  //}
265 
266  if (ROCNameFromFEDChannelROCExists(fednumber, fedchannel, fedrocnumber)) {
267  std::cout << __LINE__ << "]\t" << mthn << "ROC with fednumber=" << fednumber << " fedchannel=" << fedchannel
268  << " roc number=" << fedrocnumber << " already exists" << std::endl;
269  std::cout << __LINE__ << "]\t" << mthn << "Fix this inconsistency in the name translation" << std::endl;
270  assert(0);
271  }
272 
273  PixelHdwAddress hdwAdd(
274  fecnumber, mfec, mfecchannel, hubaddress, portaddress, rocid, fednumber, fedchannel, fedrocnumber);
275  //std::cout << aROC << std::endl;
276  // modified by MR on 18-01-2008 11:18:53
277  // std::cout << hdwAdd << std::endl ;
278  //cout << "[PixelNameTranslation::PixelNameTranslation()]\t\t-----------------------------" << endl ;
279  // A fecnumber
280  // B mfec
281  // C mfecchannel
282  // D hubaddress
283  // E portaddress
284  // F rocid
285  // G fednumber
286  // H fedchannel
287  // I fedrocnumber
288  //cout << "[PixelNameTranslation::PixelNameTranslation()]\t\t"
289  // << " A " << fecnumber
290  // << " B " << mfec
291  // << " C " << mfecchannel
292  // << " D " << hubaddress
293  // << " E " << portaddress
294  // << " F " << rocid
295  // << " G " << fednumber
296  // << " H " << fedchannel
297  // << " I " << fedrocnumber << endl ;
298 
299  translationtable_[aROC] = hdwAdd;
300  fedlookup_[hdwAdd] = aROC;
301 
302  PixelModuleName aModule(rocname);
303  PixelChannel aChannel(aModule, TBMChannel);
304 
305  hdwTranslationTable_[hdwAdd] = aChannel;
306 
307  // Look for this channel in channelTransaltionTable. If it is found,
308  // check that the hardware address agrees. If not, add it to the table.
309  // Also, if another channel on that module is found, check that the FEC
310  // part agrees, and the FED part doesn't.
311  bool foundChannel = false;
312 
313  std::map<PixelChannel, PixelHdwAddress>::const_iterator channelTranslationTable_itr =
314  channelTranslationTable_.find(aChannel);
315 
316  if (channelTranslationTable_itr != channelTranslationTable_.end()) {
317  if (!(channelTranslationTable_itr->second |= hdwAdd)) {
318  cout << __LINE__ << "]\t" << mthn << "Found two ROCs on the same channe, but not same hdw" << endl;
319  cout << __LINE__ << "]\t" << mthn << "Hdw1: " << endl << channelTranslationTable_itr->second << endl;
320  cout << __LINE__ << "]\t" << mthn << "Hdw2: " << endl << hdwAdd << endl;
321  }
322  assert(channelTranslationTable_itr->second |= hdwAdd);
323  foundChannel = true;
324  } else if (channelTranslationTable_itr->first.module() == aModule) {
325  assert(channelTranslationTable_itr->second.fecnumber() == hdwAdd.fecnumber());
326  assert(channelTranslationTable_itr->second.mfec() == hdwAdd.mfec());
327  assert(channelTranslationTable_itr->second.mfecchannel() == hdwAdd.mfecchannel());
328  //assert( channelTranslationTable_itr->second.portaddress() == hdwAdd.portaddress() );
329  assert(channelTranslationTable_itr->second.hubaddress() == hdwAdd.hubaddress());
330  assert(channelTranslationTable_itr->second.fednumber() != hdwAdd.fednumber() ||
331  channelTranslationTable_itr->second.fedchannel() != hdwAdd.fedchannel());
332  }
333 
334  if (foundChannel == false) {
335  channelTranslationTable_[aChannel] = hdwAdd;
336  }
337  }
338  } while (!in.eof());
339  in.close();
340 
341  const std::map<unsigned int, std::set<unsigned int> > fedsAndChannels = getFEDsAndChannels();
342 
343  std::vector<PixelROCName> tmp(24);
344 
345  std::map<unsigned int, std::map<unsigned int, int> > counter;
346  // FED id FED channel
347 
348  std::map<unsigned int, std::map<unsigned int, int> > maxindex;
349 
350  std::map<PixelROCName, PixelHdwAddress>::const_iterator it = translationtable_.begin();
351 
352  for (; it != translationtable_.end(); ++it) {
353  int index = it->second.fedrocnumber();
354 
355  unsigned int fednumber = it->second.fednumber();
356  unsigned int fedchannel = it->second.fedchannel();
357 
358  std::vector<PixelROCName>& tmp = rocsFromFEDidAndChannel_[fednumber][fedchannel];
359 
360  if (tmp.empty()) {
361  tmp.resize(24);
362  counter[fednumber][fedchannel] = 0;
363  maxindex[fednumber][fedchannel] = 0;
364  }
365 
366  if (index > maxindex[fednumber][fedchannel])
367  maxindex[fednumber][fedchannel] = index;
368  tmp[index] = it->first;
369  counter[fednumber][fedchannel]++;
370  }
371 
372  it = translationtable_.begin();
373 
374  for (; it != translationtable_.end(); ++it) {
375  unsigned int fednumber = it->second.fednumber();
376  unsigned int fedchannel = it->second.fedchannel();
377 
378  std::vector<PixelROCName>& tmp = rocsFromFEDidAndChannel_[fednumber][fedchannel];
379 
380  assert(counter[fednumber][fedchannel] == maxindex[fednumber][fedchannel] + 1);
381 
382  tmp.resize(counter[fednumber][fedchannel]);
383  }
384 }
385 
386 std::ostream& operator<<(std::ostream& s, const PixelNameTranslation& table) {
387  //for (unsigned int i=0;i<table.translationtable_.size();i++){
388  // s << table.translationtable_[i]<<std::endl;
389  // }
390  return s;
391 }
392 
393 std::list<const PixelROCName*> PixelNameTranslation::getROCs() const {
394  std::list<const PixelROCName*> listOfROCs;
395  for (std::map<PixelROCName, PixelHdwAddress>::const_iterator translationTableEntry = translationtable_.begin();
396  translationTableEntry != translationtable_.end();
397  ++translationTableEntry) {
398  listOfROCs.push_back(&(translationTableEntry->first));
399  }
400 
401  return listOfROCs;
402 }
403 
404 std::list<const PixelModuleName*> PixelNameTranslation::getModules() const {
405  std::list<const PixelModuleName*> listOfModules;
406  for (std::map<PixelChannel, PixelHdwAddress>::const_iterator channelTranslationTable_itr =
407  channelTranslationTable_.begin();
408  channelTranslationTable_itr != channelTranslationTable_.end();
409  ++channelTranslationTable_itr) {
410  bool foundOne = false;
411  for (std::list<const PixelModuleName*>::const_iterator listOfModules_itr = listOfModules.begin();
412  listOfModules_itr != listOfModules.end();
413  ++listOfModules_itr) {
414  if (*(*listOfModules_itr) == channelTranslationTable_itr->first.module()) {
415  foundOne = true;
416  break;
417  }
418  }
419  if (!foundOne)
420  listOfModules.push_back(&(channelTranslationTable_itr->first.module()));
421  }
422 
423  return listOfModules;
424 }
425 
426 std::set<PixelChannel> PixelNameTranslation::getChannels() const {
427  std::set<PixelChannel> channelSet;
428  for (std::map<PixelChannel, PixelHdwAddress>::const_iterator channelTranslationTable_itr =
429  channelTranslationTable_.begin();
430  channelTranslationTable_itr != channelTranslationTable_.end();
431  ++channelTranslationTable_itr) {
432  channelSet.insert(channelTranslationTable_itr->first);
433  }
434  return channelSet;
435 }
436 
437 std::set<PixelChannel> PixelNameTranslation::getChannels(const PixelDetectorConfig& aDetectorConfig) const {
438  std::set<PixelChannel> channelSet;
439  for (std::map<PixelChannel, PixelHdwAddress>::const_iterator channelTranslationTable_itr =
440  channelTranslationTable_.begin();
441  channelTranslationTable_itr != channelTranslationTable_.end();
442  ++channelTranslationTable_itr) {
443  if (aDetectorConfig.containsModule(channelTranslationTable_itr->first.module()))
444  channelSet.insert(channelTranslationTable_itr->first);
445  }
446  return channelSet;
447 }
448 
450  static std::string mthn = "[PixelNameTranslation::getHdwAddress()]\t\t ";
451  std::map<PixelROCName, PixelHdwAddress>::const_iterator it = translationtable_.find(aROC);
452 
453  if (it == translationtable_.end()) {
454  std::cout << __LINE__ << "]\t" << mthn << "Could not look up ROC: " << aROC << std::endl;
455  assert(0);
456  }
457 
458  return &(it->second);
459 }
460 
461 // Added for Debbie (used there only) to allow integrity checks (Dario)
463  std::string mthn = "[PixelNameTranslation::checkROCExistence()]\t\t ";
464  if (translationtable_.find(aROC) == translationtable_.end())
465  return false;
466  return true;
467 }
468 
469 const bool PixelNameTranslation::checkFor(const PixelROCName& aROC) const {
470  if (translationtable_.find(aROC) == translationtable_.end()) {
471  return false;
472  } else {
473  return true;
474  }
475 }
476 
478  std::map<PixelChannel, PixelHdwAddress>::const_iterator channelHdwAddress_itr =
479  channelTranslationTable_.find(aChannel);
480  assert(channelHdwAddress_itr != channelTranslationTable_.end());
481  return channelHdwAddress_itr->second;
482 }
483 
485  std::string mthn = "[PixelNameTranslation::firstHdwAddress()]\t\t ";
486  std::set<PixelChannel> channelsOnModule = getChannelsOnModule(aModule);
487  if (channelsOnModule.empty()) {
488  cout << __LINE__ << "]\t" << mthn << "module=" << aModule << " has zero channels!" << endl;
489  cout << __LINE__ << "]\t" << mthn << "Will terminate" << endl;
490  ::abort();
491  }
492  std::set<PixelChannel>::const_iterator firstChannel = channelsOnModule.begin();
493  assert(firstChannel != channelsOnModule.end());
494  return getHdwAddress(*firstChannel);
495 }
496 
498  std::map<PixelROCName, PixelHdwAddress>::const_iterator foundEntry = translationtable_.find(aROC);
499  assert(foundEntry != translationtable_.end());
500  return getChannelFromHdwAddress(foundEntry->second);
501 }
502 
503 std::set<PixelChannel> PixelNameTranslation::getChannelsOnModule(const PixelModuleName& aModule) const {
504  std::set<PixelChannel> returnThis;
505  for (std::map<PixelChannel, PixelHdwAddress>::const_iterator channelTranslationTable_itr =
506  channelTranslationTable_.begin();
507  channelTranslationTable_itr != channelTranslationTable_.end();
508  ++channelTranslationTable_itr) {
509  if (channelTranslationTable_itr->first.module() == aModule)
510  returnThis.insert(channelTranslationTable_itr->first);
511  }
512  assert(returnThis.size() <= 2);
513  return returnThis;
514 }
515 
516 const std::vector<PixelROCName>& PixelNameTranslation::getROCsFromFEDChannel(unsigned int fednumber,
517  unsigned int fedchannel) const {
518  std::map<unsigned int, std::map<unsigned int, std::vector<PixelROCName> > >::const_iterator it =
519  rocsFromFEDidAndChannel_.find(fednumber);
520 
521  assert(it != rocsFromFEDidAndChannel_.end());
522 
523  std::map<unsigned int, std::vector<PixelROCName> >::const_iterator it2 = it->second.find(fedchannel);
524 
525  assert(it2 != it->second.end());
526 
527  return it2->second;
528 }
529 
530 //Will return ROC names sorted by FED readout order.
531 //This (private) method will be called once to build this list
532 //when the data is read in.
533 
534 std::vector<PixelROCName> PixelNameTranslation::buildROCsFromFEDChannel(unsigned int fednumber,
535  unsigned int fedchannel) const {
536  std::vector<PixelROCName> tmp(24);
537 
538  int counter = 0;
539 
540  int maxindex = 0;
541 
542  std::map<PixelROCName, PixelHdwAddress>::const_iterator it = translationtable_.begin();
543 
544  for (; it != translationtable_.end(); ++it) {
545  if (it->second.fednumber() == fednumber && it->second.fedchannel() == fedchannel) {
546  int index = it->second.fedrocnumber();
547  if (index > maxindex)
548  maxindex = index;
549  //std::cout << "Found one:"<<index<<" "<<it->first<<std::endl;
550  tmp[index] = it->first;
551  counter++;
552  }
553  }
554 
555  assert(counter == maxindex + 1);
556 
557  tmp.resize(counter);
558 
559  return tmp;
560 }
561 
563  unsigned int channel,
564  unsigned int roc) const {
565  PixelHdwAddress tmp(0, 0, 0, 0, 0, 0, fednumber, channel, roc);
566 
567  return (fedlookup_.find(tmp) != fedlookup_.end());
568 }
569 
571  unsigned int channel,
572  unsigned int roc) const {
573  std::string mthn = "[PixelNameTranslation::ROCNameFromFEDChannelROC()]\t\t ";
574  PixelHdwAddress tmp(0, 0, 0, 0, 0, 0, fednumber, channel, roc);
575 
576  std::map<PixelHdwAddress, PixelROCName, PixelHdwAddress>::const_iterator it1 = fedlookup_.find(tmp);
577 
578  if (it1 != fedlookup_.end()) {
579  return it1->second;
580  }
581 
582  std::cout << __LINE__ << "]\t" << mthn << "could not find ROCName "
583  << " for FED#" << fednumber << " chan=" << channel << " roc#=" << roc << std::endl;
584 
585  assert(0);
586 
587  PixelROCName tmp1;
588 
589  return tmp1;
590 }
591 
592 PixelChannel PixelNameTranslation::ChannelFromFEDChannel(unsigned int fednumber, unsigned int fedchannel) const {
593  std::string mthn = "[PixelNameTranslation::ChannelFromFEDChannel()]\t\t ";
594  std::map<PixelChannel, PixelHdwAddress>::const_iterator toReturn;
595  bool foundOne = false;
596  for (std::map<PixelChannel, PixelHdwAddress>::const_iterator it = channelTranslationTable_.begin();
597  it != channelTranslationTable_.end();
598  ++it) {
599  if (it->second.fednumber() == fednumber && it->second.fedchannel() == fedchannel) {
600  if (foundOne) {
601  std::cout << __LINE__ << "]\t" << mthn << "ERROR: multiple channels on FED#" << fednumber
602  << ", chan=" << fedchannel << std::endl;
603  assert(0);
604  } else {
605  toReturn = it;
606  foundOne = true;
607  }
608  }
609  }
610 
611  if (!foundOne) {
612  std::cout << __LINE__ << "]\t" << mthn << "ERROR: no channel found for FED#" << fednumber << ", chan=" << fedchannel
613  << std::endl;
614  assert(0);
615  }
616 
617  return toReturn->first;
618 }
619 
620 bool PixelNameTranslation::FEDChannelExist(unsigned int fednumber, unsigned int fedchannel) const {
621  std::string mthn = "[PixelNameTranslation::FEDChannelExist()]\t\t ";
622  std::map<PixelChannel, PixelHdwAddress>::const_iterator toReturn;
623  bool foundOne = false;
624  for (std::map<PixelChannel, PixelHdwAddress>::const_iterator it = channelTranslationTable_.begin();
625  it != channelTranslationTable_.end();
626  ++it) {
627  if (it->second.fednumber() == fednumber && it->second.fedchannel() == fedchannel) {
628  if (foundOne) {
629  std::cout << __LINE__ << "]\t" << mthn << "ERROR: multiple channels on FED#" << fednumber
630  << ", chan=" << fedchannel << std::endl;
631  assert(0);
632  } else {
633  toReturn = it;
634  foundOne = true;
635  }
636  }
637  }
638  return foundOne;
639 }
640 
642  // modified by MR on 30-01-2008 10:38:22
643  std::string mthn = "[PixelNameTranslation::getChannelFromHdwAddress()]\t\t ";
644 
645  std::map<PixelHdwAddress, PixelChannel>::const_iterator it = hdwTranslationTable_.find(aHdwAddress);
646 
647  if (it == hdwTranslationTable_.end()) {
648  std::cout << __LINE__ << "]\t" << mthn << "ERROR: no channel found for hardware address " << aHdwAddress
649  << std::endl;
650  assert(0);
651  }
652 
653  return it->second;
654 
655  /*
656  for ( std::map<PixelChannel, PixelHdwAddress >::const_iterator channelTranslationTable_itr = channelTranslationTable_.begin();
657  channelTranslationTable_itr != channelTranslationTable_.end(); channelTranslationTable_itr++ )
658  {
659  if ( aHdwAddress |= channelTranslationTable_itr->second )
660  {
661  return channelTranslationTable_itr->first;
662  }
663  }
664 // modified by MR on 30-01-2008 13:56:34
665 // if you get here then there was NO match on the previous loop!!
666  std::cout << __LINE__ << "]\t" << mthn
667  << "ERROR: no channel found for hardware address " << aHdwAddress << std::endl;
668  assert(0);
669  */
670 }
671 
673  std::string mthn = "[PixelNameTranslation::writeASCII()]\t\t\t ";
674  if (!dir.empty())
675  dir += "/";
676  std::string filename = dir + "translation.dat";
677 
678  std::ofstream out(filename.c_str());
679 
680  //std::cout << "[PixelNameTranslation::writeASCII()]\t\tfilename: "
681  // << filename
682  // << " status: "
683  // << out
684  // << " "
685  // << out.is_open()
686  // <<endl ;
687 
688  out << "# name TBMchannel FEC mfec mfecchannel hubaddress portadd rocid FED "
689  "channel roc#"
690  << endl;
691 
692  std::map<PixelROCName, PixelHdwAddress>::const_iterator iroc = translationtable_.begin();
693 
694  for (; iroc != translationtable_.end(); ++iroc) {
695  // Find the PixelChannel for this ROC, in order to get the TBM channel.
696  std::string TBMChannel = getChannelFromHdwAddress(iroc->second).TBMChannelString();
697 
698  out << iroc->first.rocname() << " " << TBMChannel << " " << iroc->second.fecnumber() << " "
699  << iroc->second.mfec() << " " << iroc->second.mfecchannel() << " " << iroc->second.hubaddress()
700  << " " << iroc->second.portaddress() << " " << iroc->second.rocid() << " "
701  << iroc->second.fednumber() << " " << iroc->second.fedchannel() << " "
702  << iroc->second.fedrocnumber() << endl;
703  }
704 
705  out.close();
706 }
707 
708 //=============================================================================================
710  int version,
712  std::ofstream* outstream,
713  std::ofstream* out1stream,
714  std::ofstream* out2stream) const {
715  std::string mthn = "[PixelNameTranslation:::writeXMLHeader()]\t\t\t ";
716  std::stringstream fullPath;
717  fullPath << path << "/Pixel_NameTranslation_" << PixelTimeFormatter::getmSecTime() << ".xml";
718  cout << __LINE__ << "]\t" << mthn << "Writing to: " << fullPath.str() << endl;
719 
720  outstream->open(fullPath.str().c_str());
721  *outstream << "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>" << endl;
722  *outstream << "<ROOT xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>" << endl;
723  *outstream << " <HEADER>" << endl;
724  *outstream << " <TYPE>" << endl;
725  *outstream << " <EXTENSION_TABLE_NAME>PIXEL_NAME_TRANSLATION</EXTENSION_TABLE_NAME>" << endl;
726  *outstream << " <NAME>Pixel Name Translation</NAME>" << endl;
727  *outstream << " </TYPE>" << endl;
728  *outstream << " <RUN>" << endl;
729  *outstream << " <RUN_TYPE>Pixel Name Translation</RUN_TYPE>" << endl;
730  *outstream << " <RUN_NUMBER>1</RUN_NUMBER>" << endl;
731  *outstream << " <RUN_BEGIN_TIMESTAMP>" << pos::PixelTimeFormatter::getTime() << "</RUN_BEGIN_TIMESTAMP>" << endl;
732  *outstream << " <LOCATION>CERN P5</LOCATION>" << endl;
733  *outstream << " </RUN>" << endl;
734  *outstream << " </HEADER>" << endl;
735  *outstream << " " << endl;
736  *outstream << " <DATA_SET>" << endl;
737  *outstream << " <PART>" << endl;
738  *outstream << " <NAME_LABEL>CMS-PIXEL-ROOT</NAME_LABEL>" << endl;
739  *outstream << " <KIND_OF_PART>Detector ROOT</KIND_OF_PART>" << endl;
740  *outstream << " </PART>" << endl;
741  *outstream << " <VERSION>" << version << "</VERSION>" << endl;
742  *outstream << " <COMMENT_DESCRIPTION>" << getComment() << "</COMMENT_DESCRIPTION>" << endl;
743  *outstream << " <CREATED_BY_USER>" << getAuthor() << "</CREATED_BY_USER>" << endl;
744  *outstream << " " << endl;
745 }
746 
747 //=============================================================================================
748 void PixelNameTranslation::writeXML(std::ofstream* outstream,
749  std::ofstream* out1stream,
750  std::ofstream* out2stream) const {
751  std::string mthn = "[PixelNameTranslation::writeXML()]\t\t\t ";
752 
753  std::map<PixelROCName, PixelHdwAddress>::const_iterator iroc = translationtable_.begin();
754 
755  for (; iroc != translationtable_.end(); ++iroc) {
756  // Find the PixelChannel for this ROC, in order to get the TBM channel.
757  std::string TBMChannel = getChannelFromHdwAddress(iroc->second).TBMChannelString();
758 
759  *outstream << " <DATA>" << endl;
760  *outstream << " <ROC_NAME>" << iroc->first.rocname() << "</ROC_NAME>" << endl;
761  *outstream << " <TBM_MODE>" << TBMChannel << "</TBM_MODE>" << endl;
762  *outstream << " <PXLFEC_NAME>" << iroc->second.fecnumber() << "</PXLFEC_NAME>" << endl;
763  *outstream << " <MFEC_POSN>" << iroc->second.mfec() << "</MFEC_POSN>" << endl;
764  *outstream << " <MFEC_CHAN>" << iroc->second.mfecchannel() << "</MFEC_CHAN>" << endl;
765  *outstream << " <HUB_ADDRS>" << iroc->second.hubaddress() << "</HUB_ADDRS>" << endl;
766  *outstream << " <PORT_NUM>" << iroc->second.portaddress() << "</PORT_NUM>" << endl;
767  *outstream << " <ROC_I2C_ADDR>" << iroc->second.rocid() << "</ROC_I2C_ADDR>" << endl;
768  *outstream << " <PXLFED_NAME>" << iroc->second.fednumber() << "</PXLFED_NAME>" << endl;
769  *outstream << " <FED_CHAN>" << iroc->second.fedchannel() << "</FED_CHAN>" << endl;
770  *outstream << " <FED_ROC_NUM>" << iroc->second.fedrocnumber() << "</FED_ROC_NUM>" << endl;
771  *outstream << " </DATA>" << endl;
772  *outstream << "" << endl;
773  }
774 }
775 
776 //=============================================================================================
777 void PixelNameTranslation::writeXMLTrailer(std::ofstream* outstream,
778  std::ofstream* out1stream,
779  std::ofstream* out2stream) const {
780  std::string mthn = "[PixelNameTranslation::writeXMLTrailer()]\t\t\t ";
781 
782  *outstream << " </DATA_SET>" << endl;
783  *outstream << "</ROOT> " << endl;
784 
785  outstream->close();
786 }
787 
788 //=============================================================================================
790  std::string mthn = "[PixelNameTranslation::writeXML]\t\t\t ";
791  std::stringstream fullPath;
792 
793  fullPath << path << "/Pixel_NameTranslation.xml";
794  cout << __LINE__ << "]\t" << mthn << "Writing to: " << fullPath.str() << endl;
795 
796  std::ofstream out(fullPath.str().c_str());
797 
798  out << "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>" << endl;
799  out << "<ROOT xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>" << endl;
800  out << "" << endl;
801  out << " <HEADER>" << endl;
802  out << " <HINTS mode='only-det-root' />" << endl;
803  out << " <TYPE>" << endl;
804  out << " <EXTENSION_TABLE_NAME>PIXEL_NAME_TRANSLATION</EXTENSION_TABLE_NAME>" << endl;
805  out << " <NAME>Pixel Name Translation</NAME>" << endl;
806  out << " </TYPE>" << endl;
807  out << " <RUN>" << endl;
808  out << " <RUN_TYPE>Pixel Name Translation</RUN_TYPE>" << endl;
809  out << " <RUN_NUMBER>1</RUN_NUMBER>" << endl;
810  out << " <RUN_BEGIN_TIMESTAMP>" << pos::PixelTimeFormatter::getTime() << "</RUN_BEGIN_TIMESTAMP>" << endl;
811  out << " <COMMENT_DESCRIPTION>Test of Name Translation xml</COMMENT_DESCRIPTION>" << endl;
812  out << " <LOCATION>CERN TAC</LOCATION>" << endl;
813  out << " <CREATED_BY_USER>Dario Menasce</CREATED_BY_USER>" << endl;
814  out << " </RUN>" << endl;
815  out << " </HEADER>" << endl;
816  out << "" << endl;
817  out << " <DATA_SET>" << endl;
818  out << " <VERSION>" << version << "</VERSION>" << endl;
819  out << " <PART>" << endl;
820  out << " <NAME_LABEL>CMS-PIXEL-ROOT</NAME_LABEL>" << endl;
821  out << " <KIND_OF_PART>Detector ROOT</KIND_OF_PART>" << endl;
822  out << " </PART>" << endl;
823  out << "" << endl;
824 
825  std::map<PixelROCName, PixelHdwAddress>::const_iterator iroc = translationtable_.begin();
826 
827  for (; iroc != translationtable_.end(); ++iroc) {
828  // Find the PixelChannel for this ROC, in order to get the TBM channel.
829  std::string TBMChannel = getChannelFromHdwAddress(iroc->second).TBMChannelString();
830 
831  out << " <DATA>" << endl;
832  out << " <PXLFEC_NAME>" << iroc->second.fecnumber() << "</PXLFEC_NAME>" << endl;
833  out << " <MFEC_POSN>" << iroc->second.mfec() << "</MFEC_POSN>" << endl;
834  out << " <MFEC_CHAN>" << iroc->second.mfecchannel() << "</MFEC_CHAN>" << endl;
835  out << " <HUB_ADDRS>" << iroc->second.hubaddress() << "</HUB_ADDRS>" << endl;
836  out << " <PORT_NUM>" << iroc->second.portaddress() << "</PORT_NUM>" << endl;
837  out << " <ROC_I2C_ADDR>" << iroc->second.rocid() << "</ROC_I2C_ADDR>" << endl;
838  out << " <PXLFED_NAME>" << iroc->second.fednumber() << "</PXLFED_NAME>" << endl;
839  out << " <FED_CHAN>" << iroc->second.fedchannel() << "</FED_CHAN>" << endl;
840  out << " <FED_RO_NUM>" << iroc->second.fedrocnumber() << "</FED_ROC_NUM>" << endl;
841  out << " </DATA>" << endl;
842  out << "" << endl;
843  }
844  out << " </DATA_SET> " << endl;
845  out << "</ROOT> " << endl;
846  out.close();
847  assert(0);
848 }
849 
850 const std::vector<PixelROCName>& PixelNameTranslation::getROCsFromChannel(const PixelChannel& aChannel) const {
851  const PixelHdwAddress& channelHdwAddress = getHdwAddress(aChannel);
852  return getROCsFromFEDChannel(channelHdwAddress.fednumber(), channelHdwAddress.fedchannel());
853 }
854 
855 std::vector<PixelROCName> PixelNameTranslation::getROCsFromModule(const PixelModuleName& aModule) const {
856  std::vector<PixelROCName> returnThis;
857 
858  std::set<PixelChannel> channelsOnThisModule = getChannelsOnModule(aModule);
859  for (std::set<PixelChannel>::const_iterator channelsOnThisModule_itr = channelsOnThisModule.begin();
860  channelsOnThisModule_itr != channelsOnThisModule.end();
861  ++channelsOnThisModule_itr) {
862  std::vector<PixelROCName> ROCsOnThisChannel = getROCsFromChannel(*channelsOnThisModule_itr);
863  for (std::vector<PixelROCName>::const_iterator ROCsOnThisChannel_itr = ROCsOnThisChannel.begin();
864  ROCsOnThisChannel_itr != ROCsOnThisChannel.end();
865  ++ROCsOnThisChannel_itr) {
866  returnThis.push_back(*ROCsOnThisChannel_itr);
867  }
868  }
869 
870  return returnThis;
871 }
872 
873 //====================================================================================
874 // Added by Dario
876  if (translationtable_.find(theROC) == translationtable_.end()) {
877  return false;
878  }
879  return true;
880 }
881 
882 std::map<unsigned int, std::set<unsigned int> > PixelNameTranslation::getFEDsAndChannels() const {
883  std::map<unsigned int, std::set<unsigned int> > tmp;
884 
885  std::map<PixelChannel, PixelHdwAddress>::const_iterator channelTranslationTable_itr =
886  channelTranslationTable_.begin();
887 
888  for (; channelTranslationTable_itr != channelTranslationTable_.end(); ++channelTranslationTable_itr) {
889  unsigned int fednumber = channelTranslationTable_itr->second.fednumber();
890  unsigned int fedchannel = channelTranslationTable_itr->second.fedchannel();
891 
892  tmp[fednumber].insert(fedchannel);
893  }
894 
895  return tmp;
896 }
std::vector< PixelROCName > getROCsFromModule(const PixelModuleName &aModule) const
unsigned int mfec() const
const PixelHdwAddress * getHdwAddress(const PixelROCName &aROC) const
This class specifies which detector components are used in the configuration (and eventually should s...
std::list< const PixelModuleName * > getModules() const
This file contains the base class for "pixel configuration data" management.
void writeASCII(std::string dir="") const override
PixelChannel ChannelFromFEDChannel(unsigned int fednumber, unsigned int fedchannel) const
PixelNameTranslation(std::vector< std::vector< std::string > > &tableMat)
const PixelChannel & getChannelFromHdwAddress(const PixelHdwAddress &aHdwAddress) const
unsigned int fednumber() const
std::map< PixelROCName, PixelHdwAddress > translationtable_
void writeXMLTrailer(std::ofstream *out, std::ofstream *out1=nullptr, std::ofstream *out2=nullptr) const override
std::string TBMChannelString() const
Definition: PixelChannel.h:31
std::string rocname() const
bool checkROCExistence(const PixelROCName &aROC) const
unsigned int mfecchannel() const
std::set< PixelChannel > getChannels() const
This class provides a translation from the naming documents standard to specify the ROC to the corres...
static std::string getmSecTime(void)
std::map< PixelHdwAddress, PixelChannel > hdwTranslationTable_
bool FEDChannelExist(unsigned int fednumber, unsigned int fedchannel) const
PixelROCName ROCNameFromFEDChannelROC(unsigned int fednumber, unsigned int channel, unsigned int roc) const
static std::string getTime(void)
bool ROCNameFromFEDChannelROCExists(unsigned int fednumber, unsigned int channel, unsigned int roc) const
friend std::ostream & operator<<(std::ostream &s, const PixelNameTranslation &table)
std::string getComment() const
bool ROCexists(PixelROCName theROC)
unsigned int fedchannel() const
unsigned int hubaddress() const
const PixelHdwAddress & firstHdwAddress(const PixelModuleName &aModule) const
This is the documentation about PixelDetectorConfig...
This class provides utility methods to manipulate ASCII formatted timestamps.
Store mfec, mfecchannel etc.
std::string getAuthor() const
const bool checkFor(const PixelROCName &aROC) const
std::map< unsigned int, std::set< unsigned int > > getFEDsAndChannels() const
This class implements..
std::vector< PixelROCName > buildROCsFromFEDChannel(unsigned int fednumber, unsigned int fedchannel) const
std::list< const PixelROCName * > getROCs() const
std::set< PixelChannel > getChannelsOnModule(const PixelModuleName &aModule) const
This is the documentation about PixelNameTranslation...
std::map< PixelHdwAddress, PixelROCName, PixelHdwAddress > fedlookup_
const std::vector< PixelROCName > & getROCsFromFEDChannel(unsigned int fednumber, unsigned int fedchannel) const
This class implements..
This class implements..
Definition: PixelROCName.h:23
static std::atomic< unsigned int > counter
bool containsModule(const PixelModuleName &moduleToFind) const
const std::vector< PixelROCName > & getROCsFromChannel(const PixelChannel &aChannel) const
unsigned int fecnumber() const
void writeXML(pos::PixelConfigKey key, int version, std::string path) const override
std::map< unsigned int, std::map< unsigned int, std::vector< PixelROCName > > > rocsFromFEDidAndChannel_
tmp
align.sh
Definition: createJobs.py:716
void writeXMLHeader(pos::PixelConfigKey key, int version, std::string path, std::ofstream *out, std::ofstream *out1=nullptr, std::ofstream *out2=nullptr) const override
const PixelChannel & getChannelForROC(const PixelROCName &aROC) const
std::map< PixelChannel, PixelHdwAddress > channelTranslationTable_