CMS 3D CMS Logo

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