13#define TRG_SHORT_NAMES
14#define TRGCDC_SHORT_NAMES
16#include "trg/trg/Utilities.h"
17#include "trg/trg/Debug.h"
18#include "trg/trg/State.h"
19#include "trg/cdc/TRGCDC.h"
20#include "trg/cdc/FrontEnd.h"
21#include "trg/cdc/Wire.h"
55 return (
"TRGCDCFrontEnd version 0.01");
71 outfile <<
"-- inner type" << endl;
72 string cname =
"TRGCDCFrontEndInnerInside";
79 outfile <<
"--" << endl;
81 outfile <<
" component " << cname << endl;
83 outfile <<
" end component;" << endl;
85 outfile <<
"--------------------------------------------------------------"
88 outfile <<
"entity " << cname <<
"is" << endl;
90 outfile <<
"end " << cname <<
";" << endl;
92 outfile <<
"architecture Behavioral of " << cname <<
" is" << endl;
93 outfile <<
" -- local" << endl;
95 outfile <<
"begin" << endl;
96 outfile <<
"end Behavioral;" << endl;
105 outfile <<
" port (" << endl;
108 outfile <<
" -- 125MHz clock (TRG system clock)" << endl;
109 outfile <<
" clk : in std_logic;" << endl;
112 outfile <<
" -- Coarse timing (counter with 125MHz clock)" << endl;
113 outfile <<
" tmc : in std_logic_vector(0 to 12);" << endl;
116 outfile <<
" -- Hit pattern(48 bits for 48 wires)" << endl;
117 outfile <<
" ptn : in std_logic_vector(0 to 47);" << endl;
120 outfile <<
" -- Fine timing within 125MHz clock" << endl;
121 for (
unsigned i = 0; i < 48; i++) {
122 outfile <<
" w" << TRGUtil::itostring(i)
123 <<
" : in std_logic_vector(0 to 3);" << endl;
127 outfile <<
" -- Hit pattern output" << endl;
128 outfile <<
" hit : out std_logic_vector(0 to 47);" << endl;
129 outfile <<
" -- 4 bit fine timing for 16 priority wires" << endl;
130 outfile <<
" pri : out std_logic_vector(0 to 63);" << endl;
131 outfile <<
" -- 2 bit fine timing for the fastest hit in 16 TS"
133 outfile <<
" fst : out std_logic_vector(0 to 31)" << endl;
134 outfile <<
" );" << endl;
142 std::vector<const TRGCDCWire*>::push_back(a);
158 for (
unsigned i = 0; i <
_isb->size(); i++)
163 for (
unsigned i = 0; i <
_osb->size(); i++)
172 const unsigned nWires = size();
174 for (
unsigned i = 0; i < nWires; i++) {
177 input += (* this)[i]->signal();
181 const string ni =
name() +
"InputSignalBundle";
186 pattern->clock(dClock);
187 pattern->name(
name() +
"@dataClock");
188 _isb->push_back(pattern);
202 for (
unsigned i = 0; i < nWires; i++) {
205 const string n = s.name() +
":5bits";
209 if (!(* pattern)[i].active()) {
215 bit5->push_back(sig0);
216 bit5->push_back(sig1);
217 bit5->push_back(sig2);
218 bit5->push_back(sig3);
219 bit5->push_back(sig4);
233 const std::vector<int> timing = s.stateChanges();
234 const unsigned nStates = timing.size();
236 for (
unsigned j = 0; j < nStates; j++) {
237 const int pos = timing[j];
241 const double at = s.clock().absoluteTime(pos);
242 const int pos1 = dClock.
position(at);
243 const double phase = dClock.
phase(at);
244 const unsigned bits = unsigned(phase / (360. / 32.));
251 for (
unsigned k = 0; k < 5; k++) {
253 (*bit5)[k].set(pos1, pos1 + 1);
256 for (
unsigned k = 0; k < 5; k++) {
260 sig.
set(pos1, pos1 + 1);
299 _isb->push_back(bit5);
306 const string no =
name() +
"OutputSignalBundle";
307 if (
type() == innerInside)
312 TCFrontEnd::packerInnerInside);
313 else if (
type() == innerOutside)
318 TCFrontEnd::packerInnerOutside);
319 else if (
type() == outerInside)
324 TCFrontEnd::packerOuterInside);
325 else if (
type() == outerOutside)
330 TCFrontEnd::packerOuterOutside);
364 TRGState s(32 + 16 * 5 + 16 + 16 * 5 + 1 * 5 + 43);
367 bool* b =
new bool[input.size()];
371 const bool*
const hitptn = & b[16];
372 const bool*
const timing[32] = {
373 & b[128], & b[133], & b[138], & b[143],
374 & b[148], & b[153], & b[158], & b[163],
375 & b[168], & b[173], & b[178], & b[183],
376 & b[188], & b[193], & b[198], & b[203],
377 & b[208], & b[213], & b[218], & b[223],
378 & b[228], & b[233], & b[238], & b[243],
379 & b[248], & b[253], & b[258], & b[263],
380 & b[268], & b[273], & b[278], & b[283]
384 s.set(0, 32, hitptn);
391 for (
unsigned i = 0; i < 16; i++) {
395 s.set(p, 5, timing[i]);
404 s.set(p, 5, timing[16]);
405 secondPriority.
set(i,
true);
408 secondPriority.
set(i,
false);
416 if (hitptn[i + 15] && hitptn[i + 16]) {
420 s.set(p, 5, timing[i + 15]);
421 secondPriority.
set(i,
false);
423 s.set(p, 5, timing[i + 16]);
424 secondPriority.
set(i,
true);
429 else if (hitptn[i + 15]) {
430 s.set(p, 5, timing[i + 15]);
431 secondPriority.
set(i,
false);
435 else if (hitptn[i + 16]) {
436 s.set(p, 5, timing[i + 16]);
437 secondPriority.
set(i,
true);
451 s.set(p, secondPriority);
455 for (
unsigned i = 0; i < 16; i++) {
459 const bool h[2] = {hitptn[0], hitptn[16]};
471 s.set(p, 5, timing[0]);
472 }
else if (hh == 2) {
473 s.set(p, 5, timing[16]);
479 s.set(p, 5, timing[0]);
481 s.set(p, 5, timing[16]);
487 const unsigned i0 = i;
488 const unsigned i1 = i + 15;
489 const unsigned i2 = i + 16;
490 const bool h[3] = {hitptn[i0], hitptn[i1], hitptn[i2]};
507 s.set(p, 5, timing[i0]);
510 }
else if (hh == 2) {
512 s.set(p, 5, timing[i1]);
513 }
else if (hh == 4) {
515 s.set(p, 5, timing[i2]);
521 s.set(p, 5, timing[i0]);
523 s.set(p, 5, timing[i1]);
524 }
else if (hh == 5) {
526 s.set(p, 5, timing[i0]);
528 s.set(p, 5, timing[i2]);
529 }
else if (hh == 6) {
531 s.set(p, 5, timing[i1]);
533 s.set(p, 5, timing[i2]);
538 if ((t0 <= t1) && (t0 <= t2))
539 s.set(p, 5, timing[i0]);
541 s.set(p, 5, timing[i1]);
543 s.set(p, 5, timing[i2]);
552 s.set(p, 5, timing[31]);
594 TRGState s(48 + 16 * 5 + 4 * 5 + 108);
597 bool* b =
new bool[input.size()];
601 const bool*
const hitptn = & b[0];
602 const bool*
const timing[48] = {
603 & b[48], & b[53], & b[58], & b[63],
604 & b[68], & b[73], & b[78], & b[83],
605 & b[88], & b[93], & b[98], & b[103],
606 & b[108], & b[113], & b[118], & b[123],
607 & b[128], & b[133], & b[138], & b[143],
608 & b[148], & b[153], & b[158], & b[163],
609 & b[168], & b[173], & b[178], & b[183],
610 & b[188], & b[193], & b[198], & b[203],
611 & b[208], & b[213], & b[218], & b[223],
612 & b[228], & b[233], & b[238], & b[243],
613 & b[248], & b[253], & b[258], & b[263],
614 & b[268], & b[273], & b[278], & b[283]
618 s.set(0, 48, hitptn);
622 const bool dummy[6] = {
false,
false,
false,
false,
false,
true},
623 dummymax[5] = {
true,
true,
true,
true,
true};
624 const TRGState wtDummy(6, dummy), wtDummymax(5, dummymax);
625 for (
unsigned i = 0; i < 20; i++) {
643 if (! hitptn[0]) wt[1].
set(5,
true);
644 if (! hitptn[1]) wt[2].
set(5,
true);
645 if (! hitptn[16]) wt[5].
set(5,
true);
646 if (! hitptn[17]) wt[6].
set(5,
true);
647 if (! hitptn[32]) wt[9].
set(5,
true);
648 if (! hitptn[33]) wt[10].
set(5,
true);
649 if (! hitptn[34]) wt[11].
set(5,
true);
665 if (! hitptn[0]) wt[0].
set(5,
true);
666 if (! hitptn[1]) wt[1].
set(5,
true);
667 if (! hitptn[2]) wt[2].
set(5,
true);
668 if (! hitptn[16]) wt[4].
set(5,
true);
669 if (! hitptn[17]) wt[5].
set(5,
true);
670 if (! hitptn[18]) wt[6].
set(5,
true);
671 if (! hitptn[32]) wt[8].
set(5,
true);
672 if (! hitptn[33]) wt[9].
set(5,
true);
673 if (! hitptn[34]) wt[10].
set(5,
true);
674 if (! hitptn[35]) wt[11].
set(5,
true);
675 }
else if (i == 14) {
690 if (! hitptn[13]) wt[0].
set(5,
true);
691 if (! hitptn[14]) wt[1].
set(5,
true);
692 if (! hitptn[15]) wt[2].
set(5,
true);
693 if (! hitptn[28]) wt[3].
set(5,
true);
694 if (! hitptn[29]) wt[4].
set(5,
true);
695 if (! hitptn[30]) wt[5].
set(5,
true);
696 if (! hitptn[31]) wt[6].
set(5,
true);
697 if (! hitptn[44]) wt[7].
set(5,
true);
698 if (! hitptn[45]) wt[8].
set(5,
true);
699 if (! hitptn[46]) wt[9].
set(5,
true);
700 if (! hitptn[47]) wt[10].
set(5,
true);
701 }
else if (i == 15) {
716 if (! hitptn[14]) wt[0].
set(5,
true);
717 if (! hitptn[15]) wt[1].
set(5,
true);
718 if (! hitptn[29]) wt[3].
set(5,
true);
719 if (! hitptn[30]) wt[4].
set(5,
true);
720 if (! hitptn[31]) wt[5].
set(5,
true);
721 if (! hitptn[45]) wt[7].
set(5,
true);
722 if (! hitptn[46]) wt[8].
set(5,
true);
723 if (! hitptn[47]) wt[9].
set(5,
true);
724 }
else if (i == 16) {
739 if (! hitptn[32]) wt[11].
set(5,
true);
740 }
else if (i == 17) {
755 if (! hitptn[0]) wt[2].
set(5,
true);
756 if (! hitptn[16]) wt[6].
set(5,
true);
757 if (! hitptn[32]) wt[10].
set(5,
true);
758 if (! hitptn[33]) wt[11].
set(5,
true);
759 }
else if (i == 18) {
774 if (! hitptn[15]) wt[0].
set(5,
true);
775 if (! hitptn[30]) wt[3].
set(5,
true);
776 if (! hitptn[31]) wt[4].
set(5,
true);
777 if (! hitptn[46]) wt[7].
set(5,
true);
778 if (! hitptn[47]) wt[8].
set(5,
true);
779 }
else if (i == 19) {
794 if (! hitptn[31]) wt[3].
set(5,
true);
795 if (! hitptn[47]) wt[7].
set(5,
true);
800 wt[3] =
TRGState(5, timing[i + 14]);
801 wt[4] =
TRGState(5, timing[i + 15]);
802 wt[5] =
TRGState(5, timing[i + 16]);
803 wt[6] =
TRGState(5, timing[i + 17]);
804 wt[7] =
TRGState(5, timing[i + 30]);
805 wt[8] =
TRGState(5, timing[i + 31]);
806 wt[9] =
TRGState(5, timing[i + 32]);
807 wt[10] =
TRGState(5, timing[i + 33]);
808 wt[11] =
TRGState(5, timing[i + 34]);
811 if (! hitptn[i - 1]) wt[0].
set(5,
true);
812 if (! hitptn[i]) wt[1].
set(5,
true);
813 if (! hitptn[i + 1]) wt[2].
set(5,
true);
814 if (! hitptn[i + 14]) wt[3].
set(5,
true);
815 if (! hitptn[i + 15]) wt[4].
set(5,
true);
816 if (! hitptn[i + 16]) wt[5].
set(5,
true);
817 if (! hitptn[i + 17]) wt[6].
set(5,
true);
818 if (! hitptn[i + 30]) wt[7].
set(5,
true);
819 if (! hitptn[i + 31]) wt[8].
set(5,
true);
820 if (! hitptn[i + 32]) wt[9].
set(5,
true);
821 if (! hitptn[i + 33]) wt[10].
set(5,
true);
822 if (! hitptn[i + 34]) wt[11].
set(5,
true);
826 unsigned fastest0 = 0;
827 unsigned fastest1 = 0;
828 unsigned fastest2 = 0;
829 unsigned fastest3 = 0;
830 unsigned fastest4 = 0;
831 unsigned fastest5 = 0;
857 unsigned fastest10 = 0;
858 if (wt[fastest0] < wt[fastest1])
859 fastest10 = fastest0;
861 fastest10 = fastest1;
863 unsigned fastest11 = 0;
864 if (wt[fastest2] < wt[fastest3])
865 fastest11 = fastest2;
867 fastest11 = fastest3;
869 unsigned fastest12 = 0;
870 if (wt[fastest4] < wt[fastest5])
871 fastest12 = fastest4;
873 fastest12 = fastest5;
875 unsigned fastest101 = 0;
876 if (wt[fastest10] < wt[fastest11])
877 fastest101 = fastest10;
879 fastest101 = fastest11;
881 unsigned fastest102 = 0;
882 if (wt[fastest101] < wt[fastest12])
883 fastest102 = fastest101;
885 fastest102 = fastest12;
888 if (! wt[fastest102].active(5))
889 fastest = wt[fastest102].
subset(0, 5);
948 TRGState s(48 + 16 * 5 + 16 * 5 + 2 * 5 + 38);
951 bool* b =
new bool[input.size()];
955 const bool*
const hitptn = & b[0];
956 const bool*
const timing[48] = {
957 & b[48], & b[53], & b[58], & b[63],
958 & b[68], & b[73], & b[78], & b[83],
959 & b[88], & b[93], & b[98], & b[103],
960 & b[108], & b[113], & b[118], & b[123],
961 & b[128], & b[133], & b[138], & b[143],
962 & b[148], & b[153], & b[158], & b[163],
963 & b[168], & b[173], & b[178], & b[183],
964 & b[188], & b[193], & b[198], & b[203],
965 & b[208], & b[213], & b[218], & b[223],
966 & b[228], & b[233], & b[238], & b[243],
967 & b[248], & b[253], & b[258], & b[263],
968 & b[268], & b[273], & b[278], & b[283]
972 s.set(0, 48, hitptn);
976 for (
unsigned i = 0; i < 16; i++) {
977 s.set(p, 5, timing[32 + i]);
982 const bool dummy[6] = {
false,
false,
false,
false,
false,
true};
984 for (
unsigned i = 0; i < 18; i++) {
996 if (! hitptn[0]) wt[1].
set(5,
true);
997 if (! hitptn[1]) wt[2].
set(5,
true);
998 if (! hitptn[16]) wt[4].
set(5,
true);
999 if (! hitptn[32]) wt[5].
set(5,
true);
1000 }
else if (i == 15) {
1009 if (! hitptn[14]) wt[0].
set(5,
true);
1010 if (! hitptn[15]) wt[1].
set(5,
true);
1011 if (! hitptn[30]) wt[3].
set(5,
true);
1012 if (! hitptn[31]) wt[4].
set(5,
true);
1013 if (! hitptn[47]) wt[5].
set(5,
true);
1014 }
else if (i == 16) {
1023 if (! hitptn[0]) wt[2].
set(5,
true);
1024 }
else if (i == 17) {
1033 if (! hitptn[15]) wt[0].
set(5,
true);
1034 if (! hitptn[31]) wt[3].
set(5,
true);
1036 wt[0] =
TRGState(5, timing[i - 1]);
1038 wt[2] =
TRGState(5, timing[i + 1]);
1039 wt[3] =
TRGState(5, timing[i + 15]);
1040 wt[4] =
TRGState(5, timing[i + 16]);
1041 wt[5] =
TRGState(5, timing[i + 32]);
1044 if (! hitptn[i - 1]) wt[0].
set(5,
true);
1045 if (! hitptn[i]) wt[1].
set(5,
true);
1046 if (! hitptn[i + 1]) wt[2].
set(5,
true);
1047 if (! hitptn[i + 15]) wt[3].
set(5,
true);
1048 if (! hitptn[i + 16]) wt[4].
set(5,
true);
1049 if (! hitptn[i + 32]) wt[5].
set(5,
true);
1053 unsigned fastest0 = 0;
1054 unsigned fastest1 = 0;
1055 unsigned fastest2 = 0;
1069 unsigned fastest3 = 0;
1070 if (wt[fastest0] < wt[fastest1])
1071 fastest3 = fastest0;
1073 fastest3 = fastest1;
1075 unsigned fastest4 = 0;
1076 if (wt[fastest2] < wt[fastest3])
1077 fastest4 = fastest2;
1079 fastest4 = fastest3;
1082 if (! wt[fastest4].active(5))
1083 fastest = wt[fastest4].
subset(0, 5);
1129 TRGState s(48 + 16 * 5 + 16 * 5 + 2 * 5 + 38);
1133 bool* b =
new bool[input.size()];
1137 const bool*
const hitptn = & b[0];
1138 const bool*
const timing[48] = {
1139 & b[48], & b[53], & b[58], & b[63],
1140 & b[68], & b[73], & b[78], & b[83],
1141 & b[88], & b[93], & b[98], & b[103],
1142 & b[108], & b[113], & b[118], & b[123],
1143 & b[128], & b[133], & b[138], & b[143],
1144 & b[148], & b[153], & b[158], & b[163],
1145 & b[168], & b[173], & b[178], & b[183],
1146 & b[188], & b[193], & b[198], & b[203],
1147 & b[208], & b[213], & b[218], & b[223],
1148 & b[228], & b[233], & b[238], & b[243],
1149 & b[248], & b[253], & b[258], & b[263],
1150 & b[268], & b[273], & b[278], & b[283]
1154 s.set(0, 48, hitptn);
1159 for (
unsigned i = 0; i < 16; i++) {
1160 s.set(p, 5, timing[i]);
1165 const bool dummy[6] = {
false,
false,
false,
false,
false,
true};
1167 for (
unsigned i = 0; i < 18; i++) {
1178 if (! hitptn[0]) wt[1].
set(5,
true);
1179 if (! hitptn[16]) wt[3].
set(5,
true);
1180 if (! hitptn[17]) wt[4].
set(5,
true);
1181 }
else if (i == 15) {
1189 if (! hitptn[14]) wt[0].
set(5,
true);
1190 if (! hitptn[15]) wt[1].
set(5,
true);
1191 if (! hitptn[30]) wt[2].
set(5,
true);
1192 if (! hitptn[31]) wt[3].
set(5,
true);
1193 }
else if (i == 16) {
1200 if (! hitptn[16]) wt[4].
set(5,
true);
1201 }
else if (i == 17) {
1209 if (! hitptn[15]) wt[0].
set(5,
true);
1210 if (! hitptn[31]) wt[2].
set(5,
true);
1212 wt[0] =
TRGState(5, timing[i - 1]);
1214 wt[2] =
TRGState(5, timing[i + 15]);
1215 wt[3] =
TRGState(5, timing[i + 16]);
1216 wt[4] =
TRGState(5, timing[i + 17]);
1219 if (! hitptn[i - 1]) wt[0].
set(5,
true);
1220 if (! hitptn[i]) wt[1].
set(5,
true);
1221 if (! hitptn[i + 15]) wt[2].
set(5,
true);
1222 if (! hitptn[i + 16]) wt[3].
set(5,
true);
1223 if (! hitptn[i + 17]) wt[4].
set(5,
true);
1227 unsigned fastest0 = 0;
1228 unsigned fastest1 = 0;
1238 unsigned fastest2 = 0;
1239 if (wt[fastest0] < wt[fastest1])
1240 fastest2 = fastest0;
1242 fastest2 = fastest1;
1244 unsigned fastest3 = 0;
1245 if (wt[fastest2] < wt[4])
1246 fastest3 = fastest2;
1251 if (! wt[fastest3].active(5))
1252 fastest = wt[fastest3].
subset(0, 5);
1277 cout <<
"Input bit size=" << input.size() << endl;
1279 cout <<
"Input : wire hit pattern" << endl;
1281 for (
unsigned i = 0; i < 48; i++) {
1282 const unsigned j = 48 - i - 1;
1283 if (i && ((i % 8) == 0))
1291 cout <<
"Input : wire hit timing" << endl;
1293 for (
unsigned i = 0; i < 48; i++) {
1294 TRGState s = input.subset(o + i * 5, 5);
1297 cout << i <<
": " << s <<
" ";
1302 cout <<
"Output bit size=" << output.size() << endl;
1304 cout <<
"Output : wire hit pattern" << endl;
1306 for (
unsigned i = 0; i < 32; i++) {
1307 const unsigned j = 32 - i - 1;
1308 if (i && ((i % 8) == 0))
1317 cout <<
"Output : priority cell timing" << endl;
1319 for (
unsigned i = 0; i < 16; i++) {
1320 TRGState s = output.subset(o + i * 5, 5);
1323 cout << i <<
": " << s <<
" ";
1328 cout <<
"Output : second priority cell position" << endl;
1331 for (
unsigned i = 0; i < 16; i++) {
1332 TRGState s = output.subset(o + i, 1);
1333 if (i && ((i % 8) == 0))
1342 cout <<
"Output : fastest timing" << endl;
1344 for (
unsigned i = 0; i < 16; i++) {
1345 TRGState s = output.subset(o + i * 5, 5);
1348 cout << i <<
": " << s <<
" ";
1353 cout <<
"Output : timing of missing wires" << endl;
1355 for (
unsigned i = 0; i < 1; i++) {
1356 TRGState s = output.subset(o + i * 5, 5);
1359 cout << i <<
": " << s <<
" ";
1372 cout <<
"Input bit size=" << input.size() << endl;
1374 cout <<
"Input : wire hit pattern" << endl;
1376 for (
unsigned i = 0; i < 48; i++) {
1377 const unsigned j = 48 - i - 1;
1378 if (i && ((i % 8) == 0))
1386 cout <<
"Input : wire hit timing" << endl;
1388 for (
unsigned i = 0; i < 48; i++) {
1389 TRGState s = input.subset(o + i * 5, 5);
1392 cout << i <<
": " << s <<
" ";
1397 cout <<
"Output bit size=" << output.size() << endl;
1399 cout <<
"Output : wire hit pattern" << endl;
1401 for (
unsigned i = 0; i < 48; i++) {
1402 const unsigned j = 48 - i - 1;
1403 if (i && ((i % 8) == 0))
1412 cout <<
"Output : fastest timing" << endl;
1414 for (
unsigned i = 0; i < 16; i++) {
1415 TRGState s = output.subset(o + i * 5, 5);
1418 cout << i <<
": " << s <<
" ";
1423 cout <<
"Output : timing of missing wires" << endl;
1425 for (
unsigned i = 0; i < 4; i++) {
1426 TRGState s = output.subset(o + i * 5, 5);
1429 cout << i <<
": " << s <<
" ";
1442 cout <<
"Input bit size=" << input.size() << endl;
1444 cout <<
"Input : wire hit pattern" << endl;
1446 for (
unsigned i = 0; i < 48; i++) {
1447 const unsigned j = 48 - i - 1;
1448 if (i && ((i % 8) == 0))
1456 cout <<
"Input : wire hit timing" << endl;
1458 for (
unsigned i = 0; i < 48; i++) {
1459 TRGState s = input.subset(o + i * 5, 5);
1462 cout << i <<
": " << s <<
" ";
1467 cout <<
"Output bit size=" << output.size() << endl;
1469 cout <<
"Output : wire hit pattern" << endl;
1471 for (
unsigned i = 0; i < 48; i++) {
1472 const unsigned j = 48 - i - 1;
1473 if (i && ((i % 8) == 0))
1482 cout <<
"Output : priority cell timing" << endl;
1484 for (
unsigned i = 0; i < 16; i++) {
1485 TRGState s = output.subset(o + i * 5, 5);
1488 cout << i <<
": " << s <<
" ";
1493 cout <<
"Output : fastest timing" << endl;
1495 for (
unsigned i = 0; i < 16; i++) {
1496 TRGState s = output.subset(o + i * 5, 5);
1499 cout << i <<
": " << s <<
" ";
1504 cout <<
"Output : timing of missing wires" << endl;
1506 for (
unsigned i = 0; i < 2; i++) {
1507 TRGState s = output.subset(o + i * 5, 5);
1510 cout << i <<
": " << s <<
" ";
1523 cout <<
"Input bit size=" << input.size() << endl;
1525 cout <<
"Input : wire hit pattern" << endl;
1527 for (
unsigned i = 0; i < 48; i++) {
1528 const unsigned j = 48 - i - 1;
1529 if (i && ((i % 8) == 0))
1537 cout <<
"Input : wire hit timing" << endl;
1539 for (
unsigned i = 0; i < 48; i++) {
1540 TRGState s = input.subset(o + i * 5, 5);
1543 cout << i <<
": " << s <<
" ";
1548 cout <<
"Output bit size=" << output.size() << endl;
1550 cout <<
"Output : wire hit pattern" << endl;
1552 for (
unsigned i = 0; i < 48; i++) {
1553 const unsigned j = 48 - i - 1;
1554 if (i && ((i % 8) == 0))
1563 cout <<
"Output : Second priority cell timing" << endl;
1565 for (
unsigned i = 0; i < 16; i++) {
1566 TRGState s = output.subset(o + i * 5, 5);
1569 cout << i <<
": " << s <<
" ";
1574 cout <<
"Output : fastest timing" << endl;
1576 for (
unsigned i = 0; i < 16; i++) {
1577 TRGState s = output.subset(o + i * 5, 5);
1580 cout << i <<
": " << s <<
" ";
1585 cout <<
"Output : timing of missing wires" << endl;
1587 for (
unsigned i = 0; i < 2; i++) {
1588 TRGState s = output.subset(o + i * 5, 5);
1591 cout << i <<
": " << s <<
" ";
1615 ofstream output((
name() +
".log").c_str());
1617 output <<
"InnerInside FrontEnd output dump" << endl << endl;
1620 std::vector<vector<int>> boolvector(changetime.size());
1621 for (
unsigned ch_t = 0; ch_t < changetime.size(); ch_t++) {
1623 for (
unsigned b = 0; b < (* _osb)[0]->size(); b++) {
1624 boolvector[ch_t].push_back(((*
_osb)[0]->state(changetime[ch_t])[b]) ? 1 : 0);
1627 output <<
"# of clk: " << changetime[ch_t] <<
" (" << dClock.
absoluteTime(changetime[ch_t]) <<
" ns), signal vector: " << endl;
1629 output <<
"Hitmap: " << endl ;
1630 for (
unsigned b = 0; b < 32; b++) {
1631 output << boolvector[ch_t][31 - b] <<
" " ;
1632 if (b == 15) output << endl <<
" ";
1636 for (
unsigned b = 0; b < 16; b++) {
1637 output <<
"PT#" << b <<
": " << boolvector[ch_t][ 32 + 5 * b + 4 ] << boolvector[ch_t][ 32 + 5 * b + 3 ] << boolvector[ch_t][ 32 + 5
1639 << boolvector[ch_t][ 32 + 5 * b + 1 ] << boolvector[ch_t][ 32 + 5 * b] << endl;
1643 output <<
"Secondary: ";
1644 for (
int b = 0; b < 16; b++) {
1645 output << boolvector[ch_t][ 127 - b ] ;
1649 for (
unsigned b = 0; b < 16; b++) {
1650 output <<
"FT#" << b <<
": " << boolvector[ch_t][ 128 + 5 * b + 4 ] << boolvector[ch_t][ 128 + 5 * b + 3 ] << boolvector[ch_t][ 128
1652 << boolvector[ch_t][ 128 + 5 * b + 1 ] << boolvector[ch_t][ 128 + 5 * b] << endl;
1656 output <<
"ET#0(cell 31): " << endl << boolvector[ch_t][212] << boolvector[ch_t][211] << boolvector[ch_t][210]
1657 << boolvector[ch_t][209] << boolvector[ch_t][208] << endl;
1672 ofstream output((
name() +
".log").c_str());
1674 output <<
"InnerOutside FrontEnd output dump" << endl << endl;
1677 std::vector<vector<int>> boolvector(changetime.size());
1678 for (
unsigned ch_t = 0; ch_t < changetime.size(); ch_t++) {
1680 for (
unsigned b = 0; b < (* _osb)[0]->size(); b++) {
1681 boolvector[ch_t].push_back(((*
_osb)[0]->state(changetime[ch_t])[b]) ? 1 : 0);
1684 output <<
"# of clk: " << changetime[ch_t] <<
" (" << dClock.
absoluteTime(changetime[ch_t]) <<
" ns), signal vector: " << endl;
1686 output <<
"Hitmap: " << endl <<
" ";
1687 for (
unsigned b = 0; b < 48; b++) {
1688 output << boolvector[ch_t][47 - b] <<
" ";
1689 if (b == 15) output << endl ;
1690 else if (b == 31) output << endl <<
" ";
1694 for (
unsigned b = 0; b < 16; b++) {
1695 output <<
"FT#" << b <<
": " << boolvector[ch_t][ 48 + 5 * b + 4 ] << boolvector[ch_t][ 48 + 5 * b + 3 ] << boolvector[ch_t][ 48 + 5
1697 << boolvector[ch_t][ 48 + 5 * b + 1 ] << boolvector[ch_t][ 48 + 5 * b] << endl;
1701 output <<
"ET#0(cell 32): " << endl << boolvector[ch_t][132] << boolvector[ch_t][131] << boolvector[ch_t][130]
1702 << boolvector[ch_t][129] << boolvector[ch_t][128] << endl;
1703 output <<
"ET#1(cell 0, 16, 32, 33): " << endl << boolvector[ch_t][137] << boolvector[ch_t][136] << boolvector[ch_t][135]
1704 << boolvector[ch_t][134] << boolvector[ch_t][133] << endl;
1705 output <<
"ET#0(cell 15, 30, 31, 46, 47): " << endl << boolvector[ch_t][142] << boolvector[ch_t][141] << boolvector[ch_t][140]
1706 << boolvector[ch_t][139] << boolvector[ch_t][138] << endl;
1707 output <<
"ET#3(cell 31, 47): " << endl << boolvector[ch_t][147] << boolvector[ch_t][146] << boolvector[ch_t][145]
1708 << boolvector[ch_t][144] << boolvector[ch_t][143] << endl;
1722 ofstream output((
name() +
".log").c_str());
1724 output <<
"OuterInside FrontEnd output dump" << endl << endl;
1727 std::vector<vector<int>> boolvector(changetime.size());
1728 for (
unsigned ch_t = 0; ch_t < changetime.size(); ch_t++) {
1730 for (
unsigned b = 0; b < (* _osb)[0]->size(); b++) {
1731 boolvector[ch_t].push_back(((*
_osb)[0]->state(changetime[ch_t])[b]) ? 1 : 0);
1734 output <<
"# of clk: " << changetime[ch_t] <<
" (" << dClock.
absoluteTime(changetime[ch_t]) <<
" ns), signal vector: " << endl;
1736 output <<
"Hitmap: " << endl <<
" ";
1737 for (
unsigned b = 0; b < 48; b++) {
1738 output << boolvector[ch_t][47 - b] <<
" " ;
1739 if (b == 15) output << endl;
1740 else if (b == 31) output << endl <<
" ";
1744 for (
unsigned b = 0; b < 16; b++) {
1745 output <<
"PT#" << b <<
": " << boolvector[ch_t][ 48 + 5 * b + 4 ] << boolvector[ch_t][ 48 + 5 * b + 3 ] << boolvector[ch_t][ 48 + 5
1747 << boolvector[ch_t][ 48 + 5 * b + 1 ] << boolvector[ch_t][ 48 + 5 * b] << endl;
1751 for (
unsigned b = 0; b < 16; b++) {
1752 output <<
"FT#" << b <<
": " << boolvector[ch_t][ 128 + 5 * b + 4 ] << boolvector[ch_t][ 128 + 5 * b + 3 ] << boolvector[ch_t][ 128
1754 << boolvector[ch_t][ 128 + 5 * b + 1 ] << boolvector[ch_t][ 128 + 5 * b] << endl;
1758 output <<
"ET#0(cell 0): " << endl << boolvector[ch_t][212] << boolvector[ch_t][211] << boolvector[ch_t][210]
1759 << boolvector[ch_t][209] << boolvector[ch_t][208] << endl;
1760 output <<
"ET#1(cell 15, 31): " << endl << boolvector[ch_t][217] << boolvector[ch_t][216] << boolvector[ch_t][215]
1761 << boolvector[ch_t][214] << boolvector[ch_t][213] << endl;
1775 ofstream output((
name() +
".log").c_str());
1777 output <<
"OuterOutside FrontEnd output dump" << endl << endl;
1779 std::vector<vector<int>> boolvector(changetime.size());
1780 for (
unsigned ch_t = 0; ch_t < changetime.size(); ch_t++) {
1782 for (
unsigned b = 0; b < (* _osb)[0]->size(); b++) {
1783 boolvector[ch_t].push_back(((*
_osb)[0]->state(changetime[ch_t])[b]) ? 1 : 0);
1786 output <<
"# of clk: " << changetime[ch_t] <<
" (" << dClock.
absoluteTime(changetime[ch_t]) <<
" ns), signal vector: " << endl;
1788 output <<
"Hitmap: " << endl;
1789 for (
unsigned b = 0; b < 48; b++) {
1790 output << boolvector[ch_t][47 - b] <<
" ";
1791 if (b == 15) output << endl <<
" ";
1792 else if (b == 31) output << endl ;
1796 for (
unsigned b = 0; b < 16; b++) {
1797 output <<
"PT#" << b <<
": " << boolvector[ch_t][ 48 + 5 * b + 4 ] << boolvector[ch_t][ 48 + 5 * b + 3 ] << boolvector[ch_t][ 48 + 5
1799 << boolvector[ch_t][ 48 + 5 * b + 1 ] << boolvector[ch_t][ 48 + 5 * b] << endl;
1803 for (
unsigned b = 0; b < 16; b++) {
1804 output <<
"FT#" << b <<
": " << boolvector[ch_t][ 128 + 5 * b + 4 ] << boolvector[ch_t][ 128 + 5 * b + 3 ] << boolvector[ch_t][ 128
1806 << boolvector[ch_t][ 128 + 5 * b + 1 ] << boolvector[ch_t][ 128 + 5 * b] << endl;
1810 output <<
"ET#0(cell 16): " << endl << boolvector[ch_t][212] << boolvector[ch_t][211] << boolvector[ch_t][210]
1811 << boolvector[ch_t][209] << boolvector[ch_t][208] << endl;
1812 output <<
"ET#1(cell 15, 31): " << endl << boolvector[ch_t][217] << boolvector[ch_t][216] << boolvector[ch_t][215]
1813 << boolvector[ch_t][214] << boolvector[ch_t][213] << endl;
A class to represent a trigger board.
TRGSignalBundle * _isb
Input signal bundle.
boardType _type
Board type.
TRGSignalBundle * _osb
Output signal bundle.
A class to represent a wire in CDC.
A class to represent a digitized signal. Unit is nano second.
A class to represent a bundle of SignalVectors.
A class to represent a bundle of digitized signals.
A class to represent a digitized signal. Unit is nano second.
const TRGSignal & set(double t0, double t1)
makes a pulse with leading edge at t0 and with trailing edge at t1.
A class to represent a state of multi bits.
static std::string tab(void)
returns tab spaces.
static TRGCDC * getTRGCDC(void)
returns TRGCDC object.
static unsigned toUnsigned(unsigned n, const bool *array)
Coverts from bool array to unsigned.
TRGCDCFrontEnd(const std::string &name, boardType type, const TRGClock &systemClock, const TRGClock &dataClock, const TRGClock &userClock)
Constructor.
void dump_log_innerOutside(void) const
Dump all the details of _mosb into a .log file, for innerOutside FE.
double absoluteTime(int clockPosition) const
returns absolute time of clock position
static TRGState packerOuterInside(const TRGState &input)
Makes bit pattern using input bit pattern for the inner FE.
TRGState subset(unsigned i, unsigned n) const
returns subset from i with n bits.
const TRGClock & clockData(void) const
returns data clock.
static int implementationPort(const boardType &type, std::ofstream &)
writes a port map.
double phase(double timing) const
returns phase of given timing in degree (0 to 360).
static TRGState packerInnerInside(const TRGState &input)
Makes bit pattern using input bit pattern for the inner FE.
const std::string & name(void) const
returns name.
std::vector< int > stateChanges(void) const
returns a list of clock position of state change.
static void unpackerOuterOutside(const TRGState &input, const TRGState &output)
Unpacks TRGState.
static std::string itostring(int i)
converts int to string. (Use boost::lexical_cast)
void dump_log(void) const
Dump all the details of _mosb into a .log file, do it in the end of simulate()
static void unpackerInnerOutside(const TRGState &input, const TRGState &output)
Unpacks TRGState.
const TRGState & set(unsigned position, bool state=true)
sets state at bit i.
const TRGClock & dataClock(void) const
returns the data clock.
static TRGState packerInnerOutside(const TRGState &input)
Makes bit pattern using input bit pattern for the outer FE.
static void unpackerOuterInside(const TRGState &input, const TRGState &output)
Unpacks TRGState.
void dump_log_outerInside(void) const
Dump all the details of _mosb into a .log file, for outerInside FE.
boardType type(void) const
returns type.
static int level(void)
returns the debug level.
static int implementation(const boardType &type, std::ofstream &)
make a VHDL component file.
bool active(void) const
returns true if there is a signal.
int position(double timing) const
returns clock position.
static TRGState packerOuterOutside(const TRGState &input)
Makes bit pattern using input bit pattern for the outer FE.
static std::string version(void)
returns version.
void simulate(void)
simulates firmware.
virtual ~TRGCDCFrontEnd()
Destructor.
void dump_log_innerInside(void) const
Dump all the details of _mosb into a .log file, for innerInside FE.
void dump_log_outerOutside(void) const
Dump all the details of _mosb into a .log file, for outerOutside FE.
static void unpackerInnerInside(const TRGState &input, const TRGState &output)
Unpacks TRGState.
void push_back(const TRGCDCWire *)
push back TRGCDCWire for this Front-end
void dump(const std::string &message="", const std::string &pre="") const
dumps contents.
Abstract base class for different kinds of events.