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