Belle II Software development
FrontEnd.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9//-----------------------------------------------------------------------------
10// Description : A class to represent a CDC front-end board
11//-----------------------------------------------------------------------------
12
13#define TRG_SHORT_NAMES
14#define TRGCDC_SHORT_NAMES
15
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"
22
23using namespace std;
24
25namespace Belle2 {
31 TRGCDCFrontEnd::TRGCDCFrontEnd(const std::string& name,
32 boardType type,
33 const TRGClock& systemClock,
34 const TRGClock& dataClock,
35 const TRGClock& userClockOutput)
36 : TRGBoard(name,
37 systemClock,
38 dataClock,
39 userClockOutput,
40 userClockOutput),
41 _type(type),
42 _isb(0),
43 _osb(0)
44 {
45
46 }
47
49 {
50 }
51
52 string
54 {
55 return ("TRGCDCFrontEnd version 0.01");
56 }
57
60 {
61 return _type;
62 }
63
64 int
66 ofstream& outfile)
67 {
68
69 //string cname = "UNKNOWN";
70 // if (_type == innerInside) {
71 outfile << "-- inner type" << endl;
72 string cname = "TRGCDCFrontEndInnerInside";
73 // }
74 // else {
75 // outfile << "-- outer type" << endl;
76 // cname = "TRGCDCFrontEndOuter";
77 // }
78
79 outfile << "--" << endl;
80 outfile << endl;
81 outfile << " component " << cname << endl;
82 // int err = implementationPort(type, outfile);
83 outfile << " end component;" << endl;
84
85 outfile << "--------------------------------------------------------------"
86 << endl;
87
88 outfile << "entity " << cname << "is" << endl;
89 int err = implementationPort(type, outfile);
90 outfile << "end " << cname << ";" << endl;
91 outfile << endl;
92 outfile << "architecture Behavioral of " << cname << " is" << endl;
93 outfile << " -- local" << endl;
94 outfile << endl;
95 outfile << "begin" << endl;
96 outfile << "end Behavioral;" << endl;
97
98 return err;
99 }
100
101 int
103 ofstream& outfile)
104 {
105 outfile << " port (" << endl;
106
107 //...125MHz clock (TRG system clock)...
108 outfile << " -- 125MHz clock (TRG system clock)" << endl;
109 outfile << " clk : in std_logic;" << endl;
110
111 //...Coarse timing...
112 outfile << " -- Coarse timing (counter with 125MHz clock)" << endl;
113 outfile << " tmc : in std_logic_vector(0 to 12);" << endl;
114
115 //...Hit pattern...
116 outfile << " -- Hit pattern(48 bits for 48 wires)" << endl;
117 outfile << " ptn : in std_logic_vector(0 to 47);" << endl;
118
119 //...Fine timing for each wire...
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;
124 }
125
126 //...Hit pattern output...
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"
132 << endl;
133 outfile << " fst : out std_logic_vector(0 to 31)" << endl;
134 outfile << " );" << endl;
135
136 return 0;
137 }
138
139 void
141 {
142 std::vector<const TRGCDCWire*>::push_back(a);
143 }
144
145 void
146 TRGCDCFrontEnd::dump(const string& message, const string& pre) const
147 {
148 TRGBoard::dump(message, pre);
149 }
150
151 void
153 {
154
155
156 //...Clear input signal bundle...
157 if (_isb) {
158 for (unsigned i = 0; i < _isb->size(); i++)
159 delete (* _isb)[i];
160 delete _isb;
161 }
162 if (_osb) {
163 for (unsigned i = 0; i < _osb->size(); i++)
164 delete (* _osb)[i];
165 delete _osb;
166 }
167
168 //...Clock...
169 const TRGClock& dClock = clockData();
170
171 //...Input from wires...
172 const unsigned nWires = size();
173 TRGSignalVector input(name() + "inputSignals", dClock);
174 for (unsigned i = 0; i < nWires; i++) {
175
176 //...This may be too expensive. There must be a class to hold pointers.
177 input += (* this)[i]->signal();
178 }
179
180 //...Make input signal bundle...
181 const string ni = name() + "InputSignalBundle";
182 _isb = new TRGSignalBundle(ni, dClock);
183
184 //...Create hit pattern bits...
185 TRGSignalVector* pattern = new TRGSignalVector(input);
186 pattern->clock(dClock);
187 pattern->name(name() + "@dataClock");
188 _isb->push_back(pattern);
189
190 // if (TRGDebug::level() > 1) {
191 // if (input.active()) {
192 // input.dump("", TRGDebug::tab());
193 // pattern->dump("", TRGDebug::tab());
194 // }
195 // }
196
197 // output wire hit info into a .log file
198 // ofstream wireinfo((name()+"_wireinfo.log").c_str());
199
200
201 //...Create Wire timing bits...
202 for (unsigned i = 0; i < nWires; i++) {
203
204 const TRGSignal& s = input[i];
205 const string n = s.name() + ":5bits";
206 TRGSignalVector* bit5 = new TRGSignalVector(n, dClock);
207
208 //...No hit case : only dummy data...
209 if (!(* pattern)[i].active()) {
210 TRGSignal sig0(n + "-0", dClock);
211 TRGSignal sig1(n + "-1", dClock);
212 TRGSignal sig2(n + "-2", dClock);
213 TRGSignal sig3(n + "-3", dClock);
214 TRGSignal sig4(n + "-4", dClock);
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);
220 }
221
222 //...Hit case...
223 else {
224
225 // wire hit info -> .log
226 /*
227 if (type() == innerInside) { wireinfo << endl << " #" << (i > 15 ? i - 16 : 99999 ) << " wire is hit" << endl; }
228 else { wireinfo << endl << " #" << i << " wire is hit" << endl; }
229 output << endl;
230 */
231
232 // s is wire signal which is hit.
233 const std::vector<int> timing = s.stateChanges();
234 const unsigned nStates = timing.size();
235 // Loop over all the changing timing.
236 for (unsigned j = 0; j < nStates; j++) {
237 const int pos = timing[j];
238
239 //...Look at leading edges only...
240 if (s.state(pos)) {
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.));
245
246 // cout << "at,phase,bits,pos1=" << at << "," << phase << ","
247 // << bits <<","<<pos1<< endl;
248
249 // Change priority timing from unsigned into SignalVector.
250 if (bit5->active()) {
251 for (unsigned k = 0; k < 5; k++) {
252 if ((bits >> k) & 1)
253 (*bit5)[k].set(pos1, pos1 + 1);
254 }
255 } else {
256 for (unsigned k = 0; k < 5; k++) {
257 const string n1 = n + "-" + TRGUtilities::itostring(k);
258 TRGSignal sig(n1, dClock);
259 if ((bits >> k) & 1)
260 sig.set(pos1, pos1 + 1);
261 (* bit5) += sig;
262 }
263 }
264
265
266 //wire info -> .log
267 /*
268 //timing = 00000 case:
269 if ( !(bit5->stateChanges()).size() ) {
270 output << "# of clk: " << pos1 << " (" << pos1*32 << " ns), signal vector: 0 0 0 0 0" << endl;
271 }
272
273 const std::vector<int> bit5_changetime = bit5->stateChanges();
274 std::vector<vector<int>> bit5_boolvector(bit5_changetime.size());
275 for (unsigned ch_t = 0; ch_t < bit5_changetime.size(); ch_t++) {
276
277 for (unsigned b = 0; b < bit5->size(); b++){
278 bit5_boolvector[ch_t].push_back( (bit5->state( bit5_changetime[ch_t])[b]) ? 1 : 0 );
279 }
280
281 wireinfo << "# of clk: " << bit5_changetime[ch_t] << " (" << dClock.absoluteTime(bit5_changetime[ch_t]) << " ns), signal vector: " ;
282
283 for (unsigned b = 0; b < bit5->size(); b++){
284 wireinfo << bit5_boolvector[ch_t][ bit5->size() - b - 1] << " " ;
285 }
286
287 wireinfo << endl;
288 }
289 */
290
291
292#ifdef TRG_DEBUG
293// bit5->dump("detail", TRGDebug::tab());
294#endif
295 }
296 }
297 }
298
299 _isb->push_back(bit5);
300 }
301
302 //...Data clock...
303 // Data clock position data is omitted. Is this problem?
304
305 //...Make output signal bundle...
306 const string no = name() + "OutputSignalBundle";
307 if (type() == innerInside)
308 _osb = new TRGSignalBundle(no,
309 dClock,
310 * _isb,
311 256,
312 TCFrontEnd::packerInnerInside);
313 else if (type() == innerOutside)
314 _osb = new TRGSignalBundle(no,
315 dClock,
316 * _isb,
317 256,
318 TCFrontEnd::packerInnerOutside);
319 else if (type() == outerInside)
320 _osb = new TRGSignalBundle(no,
321 dClock,
322 * _isb,
323 256,
324 TCFrontEnd::packerOuterInside);
325 else if (type() == outerOutside)
326 _osb = new TRGSignalBundle(no,
327 dClock,
328 * _isb,
329 256,
330 TCFrontEnd::packerOuterOutside);
331
332 if (TRGDebug::level() > 1) {
333 cout << TRGDebug::tab() << name() << " input bundle" << endl;
334 _isb->dump("", TRGDebug::tab() + " ");
335 cout << TRGDebug::tab() << name() << " output bundle" << endl;
336 _osb->dump("", TRGDebug::tab() + " ");
337 }
338 }
339
342 {
343
344 //...Input should be 48 hit pattern and 48x5 timing, total 288 bits...
345 //
346 // Wire numbers and TS ID
347 //
348 // outside
349 //
350 // +--+--+--+--+- -+--+--+--+--+--+--+
351 // | 31 | 30 | .... | 18 | 17 | 16 |
352 // +--+--+--+--+--+- -+--+--+--+--+--+--+
353 // | 15 | 14 | .....| 2 | 1 | 0 |
354 // +--+--+--+--+--+- -+--+--+--+--+--+--+
355 // | x | x | .... | x | x | x |
356 // +--+--+--+--+- -+--+--+--+--+--+--+
357 //
358 // 15 14 .... 2 1 0 <- partial TS ID
359 //
360 // inside
361 //
362
363 //...Prepare a state for output...
364 TRGState s(32 + 16 * 5 + 16 + 16 * 5 + 1 * 5 + 43); // 1*5 for missing wire + 43 bits to fill to 256 bits
365
366 //...Set up bool array...
367 bool* b = new bool[input.size()];
368 input.copy2bool(b);
369
370 //...Naming...
371 const bool* const hitptn = & b[16]; // 16x2 = 32 bits
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]
381 };
382
383 //...Store hit pattern...
384 s.set(0, 32, hitptn);
385 unsigned p = 32;
386
387 //bool true_5[5] = {true, true, true, true, true};
388
389 //...Priority timing...
390 TRGState secondPriority(16);
391 for (unsigned i = 0; i < 16; i++) {
392
393 //...Priority cell...
394 if (hitptn[i]) {
395 s.set(p, 5, timing[i]);
396 }
397
398 //...Second priority cells...
399 else {
400
401 //...Right side edge...
402 if (i == 0) {
403 if (hitptn[16]) {
404 s.set(p, 5, timing[16]);
405 secondPriority.set(i, true);
406 } else {
407 // s.set(p, 5, true_5);
408 secondPriority.set(i, false);
409 }
410 }
411
412 //...Others...
413 else {
414
415 //...Both secondarys have hit...
416 if (hitptn[i + 15] && hitptn[i + 16]) {
417 const unsigned t0 = TRGState::toUnsigned(5, timing[15]);
418 const unsigned t1 = TRGState::toUnsigned(5, timing[16]);
419 if (t0 < t1) {
420 s.set(p, 5, timing[i + 15]);
421 secondPriority.set(i, false);
422 } else {
423 s.set(p, 5, timing[i + 16]);
424 secondPriority.set(i, true);
425 }
426 }
427
428 //...Secondary at right side...
429 else if (hitptn[i + 15]) {
430 s.set(p, 5, timing[i + 15]);
431 secondPriority.set(i, false);
432 }
433
434 //...Secondary at left side...
435 else if (hitptn[i + 16]) {
436 s.set(p, 5, timing[i + 16]);
437 secondPriority.set(i, true);
438 }
439
440 // No secondary case. No action
441 else {
442 //s.set(p, 5, true_5);
443 //secondPriority.set(i, true);
444 }
445 }
446 }
447
448 p += 5;
449 }
450
451 s.set(p, secondPriority);
452 p += 16;
453
454 //...Fastest timing...
455 for (unsigned i = 0; i < 16; i++) {
456
457 //...Right side edge...
458 if (i == 0) {
459 const bool h[2] = {hitptn[0], hitptn[16]};
460 const unsigned hh = TRGState::toUnsigned(2, h);
461 const unsigned t0 = TRGState::toUnsigned(5, timing[0]);
462 const unsigned t1 = TRGState::toUnsigned(5, timing[16]);
463
464 //...No hit case : no action
465 if (hh == 0) {
466 //s.set(p, 5, true_5);
467 }
468
469 //...One hit case...
470 else if (hh == 1) {
471 s.set(p, 5, timing[0]);
472 } else if (hh == 2) {
473 s.set(p, 5, timing[16]);
474 }
475
476 //...Two hit case...
477 else {
478 if (t0 <= t1)
479 s.set(p, 5, timing[0]);
480 else
481 s.set(p, 5, timing[16]);
482 }
483 }
484
485 //...Others...
486 else {
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]};
491 const unsigned hh = TRGState::toUnsigned(3, h);
492 const unsigned t0 = TRGState::toUnsigned(5, timing[i0]);
493 const unsigned t1 = TRGState::toUnsigned(5, timing[i1]);
494 const unsigned t2 = TRGState::toUnsigned(5, timing[i2]);
495
496 //...No hit case : no action
497 if (hh == 0) {
498 //s.set(p, 5, true_5);
499 }
500
501 //...One hit case...
502 else if (hh == 1) {
503 // cout << "p=" << p << endl;
504 // cout << "one hit pri" << endl;
505 // s.dump("detail", "one hit pri ");
506 // s.subset(p, 5).dump("detail", "one hit pri ");
507 s.set(p, 5, timing[i0]);
508 // s.dump("detail", "one hit pri ");
509 // s.subset(p, 5).dump("detail", "one hit pri ");
510 } else if (hh == 2) {
511 // cout << "one hit sec0" << endl;
512 s.set(p, 5, timing[i1]);
513 } else if (hh == 4) {
514 // cout << "one hit sec1" << endl;
515 s.set(p, 5, timing[i2]);
516 }
517
518 //...Two hit case...
519 else if (hh == 3) {
520 if (t0 <= t1)
521 s.set(p, 5, timing[i0]);
522 else
523 s.set(p, 5, timing[i1]);
524 } else if (hh == 5) {
525 if (t0 <= t2)
526 s.set(p, 5, timing[i0]);
527 else
528 s.set(p, 5, timing[i2]);
529 } else if (hh == 6) {
530 if (t1 <= t2)
531 s.set(p, 5, timing[i1]);
532 else
533 s.set(p, 5, timing[i2]);
534 }
535
536 //...Three hit case...
537 else {
538 if ((t0 <= t1) && (t0 <= t2))
539 s.set(p, 5, timing[i0]);
540 else if (t1 <= t2)
541 s.set(p, 5, timing[i1]);
542 else
543 s.set(p, 5, timing[i2]);
544 }
545 }
546
547 p += 5;
548 }
549
550 //...Timing of missing wires on edge TS...
551 if (hitptn[31]) {
552 s.set(p, 5, timing[31]);
553 } else {
554 //s.set(p, 5, true_5);
555 }
556 // p+=5;
557
558 //...Debug...
559#ifdef TRG_DEBUG
560 // input.dump("detail", TRGDebug::tab() + "FrontEnd_II in ");
561 // s.dump("detail", TRGDebug::tab() + "FrontEnd_II out ");
562// unpackerInnerInside(input, s);
563#endif
564
565 //...Termination...
566 delete[] b;
567 return s;
568 }
569
572 {
573
574 //...Input should be 48 hit pattern and 48x5 timing, total 288 bits...
575 //
576 // Wire numbers and TS ID
577 //
578 // outside
579 //
580 // +--+--+--+--+- -+--+--+--+--+--+--+
581 // | 47 | 46 | .... | 34 | 33 | 32 |
582 // +--+--+--+--+--+- -+--+--+--+--+--+--+
583 // | 31 | 30 | ..... | 18 | 17 | 16 |
584 // +--+--+--+--+--+- -+--+--+--+--+--+--+
585 // | 15 | 14 | .... | 2 | 1 | 0 |
586 // +--+--+--+--+- -+--+--+--+--+--+--+
587 //
588 // 15 14 .... 2 1 0 <- partial TS ID
589 //
590 // inside
591 //
592
593 //...Prepare a state for output...
594 TRGState s(48 + 16 * 5 + 4 * 5 + 108); // 4*5 for missing area timings + 108 to fill to 256 bits
595
596 //...Set up bool array...
597 bool* b = new bool[input.size()];
598 input.copy2bool(b);
599
600 //...Naming...
601 const bool* const hitptn = & b[0]; // 16x3 = 48 bits
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]
615 };
616
617 //...Store hit pattern...
618 s.set(0, 48, hitptn);
619 unsigned p = 48;
620
621 //...Fastest timing...
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++) { // 0 ... 15 for 16 standard ones, 16...19 for four edge areas.
626 TRGState wt[12];
627
628 if (i == 0) { // TS ID 0 has missing wires
629 wt[0] = wtDummy;
630 wt[1] = TRGState(5, timing[0]);
631 wt[2] = TRGState(5, timing[1]);
632 wt[3] = wtDummy;
633 wt[4] = wtDummy;
634 wt[5] = TRGState(5, timing[16]);
635 wt[6] = TRGState(5, timing[17]);
636 wt[7] = wtDummy;
637 wt[8] = wtDummy;
638 wt[9] = TRGState(5, timing[32]);
639 wt[10] = TRGState(5, timing[33]);
640 wt[11] = TRGState(5, timing[34]);
641
642 //...Append 6th bit to indicate hit or not (no hit = 1)...
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);
650 } else if (i == 1) { // TS ID 1 has missing wires
651 wt[0] = TRGState(5, timing[0]);
652 wt[1] = TRGState(5, timing[1]);
653 wt[2] = TRGState(5, timing[2]);
654 wt[3] = wtDummy;
655 wt[4] = TRGState(5, timing[16]);
656 wt[5] = TRGState(5, timing[17]);
657 wt[6] = TRGState(5, timing[18]);
658 wt[7] = wtDummy;
659 wt[8] = TRGState(5, timing[32]);
660 wt[9] = TRGState(5, timing[33]);
661 wt[10] = TRGState(5, timing[34]);
662 wt[11] = TRGState(5, timing[35]);
663
664 //...Append 6th bit to indicate hit or not (no hit = 1)...
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) { // TS ID 14 has missing wires
676 wt[0] = TRGState(5, timing[13]);
677 wt[1] = TRGState(5, timing[14]);
678 wt[2] = TRGState(5, timing[15]);
679 wt[3] = TRGState(5, timing[28]);
680 wt[4] = TRGState(5, timing[29]);
681 wt[5] = TRGState(5, timing[30]);
682 wt[6] = TRGState(5, timing[31]);
683 wt[7] = TRGState(5, timing[44]);
684 wt[8] = TRGState(5, timing[45]);
685 wt[9] = TRGState(5, timing[46]);
686 wt[10] = TRGState(5, timing[47]);
687 wt[11] = wtDummy;
688
689 //...Append 6th bit to indicate hit or not (no hit = 1)...
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) { // TS ID 15 has missing wires
702 wt[0] = TRGState(5, timing[14]);
703 wt[1] = TRGState(5, timing[15]);
704 wt[2] = wtDummy;
705 wt[3] = TRGState(5, timing[29]);
706 wt[4] = TRGState(5, timing[30]);
707 wt[5] = TRGState(5, timing[31]);
708 wt[6] = wtDummy;
709 wt[7] = TRGState(5, timing[45]);
710 wt[8] = TRGState(5, timing[46]);
711 wt[9] = TRGState(5, timing[47]);
712 wt[10] = wtDummy;
713 wt[11] = wtDummy;
714
715 //...Append 6th bit to indicate hit or not (no hit = 1)...
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) { // edge area 1, only cell 32 at position 11
725 wt[0] = wtDummy;
726 wt[1] = wtDummy;
727 wt[2] = wtDummy;
728 wt[3] = wtDummy;
729 wt[4] = wtDummy;
730 wt[5] = wtDummy;
731 wt[6] = wtDummy;
732 wt[7] = wtDummy;
733 wt[8] = wtDummy;
734 wt[9] = wtDummy;
735 wt[10] = wtDummy;
736 wt[11] = TRGState(5, timing[32]);
737
738 //...Append 6th bit to indicate hit or not (no hit = 1)...
739 if (! hitptn[32]) wt[11].set(5, true);
740 } else if (i == 17) { // edge area 1, cell 0, 16, 32, 33 at position 2, 6, 10, 11
741 wt[0] = wtDummy;
742 wt[1] = wtDummy;
743 wt[2] = TRGState(5, timing[0]);
744 wt[3] = wtDummy;
745 wt[4] = wtDummy;
746 wt[5] = wtDummy;
747 wt[6] = TRGState(5, timing[16]);
748 wt[7] = wtDummy;
749 wt[8] = wtDummy;
750 wt[9] = wtDummy;
751 wt[10] = TRGState(5, timing[32]);
752 wt[11] = TRGState(5, timing[33]);
753
754 //...Append 6th bit to indicate hit or not (no hit = 1)...
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) { // edge area 3, cell 15, 30, 31, 46, 47 at position 0, 3, 4, 7, 8
760 wt[0] = TRGState(5, timing[15]);
761 wt[1] = wtDummy;
762 wt[2] = wtDummy;
763 wt[3] = TRGState(5, timing[30]);
764 wt[4] = TRGState(5, timing[31]);
765 wt[5] = wtDummy;
766 wt[6] = wtDummy;
767 wt[7] = TRGState(5, timing[46]);
768 wt[8] = TRGState(5, timing[47]);
769 wt[9] = wtDummy;
770 wt[10] = wtDummy;
771 wt[11] = wtDummy;
772
773 //...Append 6th bit to indicate hit or not (no hit = 1)...
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) { // edge area 4, only cell 31 and 47 at position 3 and 7
780 wt[0] = wtDummy;
781 wt[1] = wtDummy;
782 wt[2] = wtDummy;
783 wt[3] = TRGState(5, timing[31]);
784 wt[4] = wtDummy;
785 wt[5] = wtDummy;
786 wt[6] = wtDummy;
787 wt[7] = TRGState(5, timing[47]);
788 wt[8] = wtDummy;
789 wt[9] = wtDummy;
790 wt[10] = wtDummy;
791 wt[11] = wtDummy;
792
793 //...Append 6th bit to indicate hit or not (no hit = 1)...
794 if (! hitptn[31]) wt[3].set(5, true);
795 if (! hitptn[47]) wt[7].set(5, true);
796 } else {
797 wt[0] = TRGState(5, timing[i - 1]);
798 wt[1] = TRGState(5, timing[i]);
799 wt[2] = TRGState(5, timing[i + 1]);
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]);
809
810 //...Append 6th bit to indicate hit or not (no hit = 1)...
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);
823 }
824
825 //...Look for the fastest hit...
826 unsigned fastest0 = 0;
827 unsigned fastest1 = 0;
828 unsigned fastest2 = 0;
829 unsigned fastest3 = 0;
830 unsigned fastest4 = 0;
831 unsigned fastest5 = 0;
832 if (wt[0] < wt[1])
833 fastest0 = 0;
834 else
835 fastest0 = 1;
836 if (wt[2] < wt[3])
837 fastest1 = 2;
838 else
839 fastest1 = 3;
840 if (wt[4] < wt[5])
841 fastest2 = 4;
842 else
843 fastest2 = 5;
844 if (wt[6] < wt[7])
845 fastest3 = 6;
846 else
847 fastest3 = 7;
848 if (wt[8] < wt[9])
849 fastest4 = 8;
850 else
851 fastest4 = 9;
852 if (wt[10] < wt[11])
853 fastest5 = 10;
854 else
855 fastest5 = 11;
856
857 unsigned fastest10 = 0;
858 if (wt[fastest0] < wt[fastest1])
859 fastest10 = fastest0;
860 else
861 fastest10 = fastest1;
862
863 unsigned fastest11 = 0;
864 if (wt[fastest2] < wt[fastest3])
865 fastest11 = fastest2;
866 else
867 fastest11 = fastest3;
868
869 unsigned fastest12 = 0;
870 if (wt[fastest4] < wt[fastest5])
871 fastest12 = fastest4;
872 else
873 fastest12 = fastest5;
874
875 unsigned fastest101 = 0;
876 if (wt[fastest10] < wt[fastest11])
877 fastest101 = fastest10;
878 else
879 fastest101 = fastest11;
880
881 unsigned fastest102 = 0;
882 if (wt[fastest101] < wt[fastest12])
883 fastest102 = fastest101;
884 else
885 fastest102 = fastest12;
886
887 TRGState fastest(5);
888 if (! wt[fastest102].active(5))
889 fastest = wt[fastest102].subset(0, 5);
890
891 s.set(p, fastest);
892 p += 5;
893 }
894
896 //s.set(p, 5, timing[0]);
897 //p += 5;
898 //s.set(p, 5, timing[16]);
899 //p += 5;
900 //s.set(p, 5, timing[32]);
901 //p += 5;
902 //s.set(p, 5, timing[33]);
903 //p += 5;
904 //s.set(p, 5, timing[15]);
905 //p += 5;
906 //s.set(p, 5, timing[30]);
907 //p += 5;
908 //s.set(p, 5, timing[31]);
909 //p += 5;
910 //s.set(p, 5, timing[46]);
911 //p += 5;
912 //s.set(p, 5, timing[47]);
913
914#ifdef TRG_DEBUG
915// unpackerInnerOutside(input, s);
916#endif
917
918 delete[] b;
919 return s;
920 }
921
924 {
925
926 //...Input should be 48 hit pattern and 48x5 timing, total 288 bits...
927 //
928 // Wire numbers and TS ID
929 //
930 // outside
931 //
932 // +--+--+--+--+- -+--+--+--+--+--+--+
933 // | 47 | 46 | .... | 34 | 33 | 32 | <- priority wire layer
934 // +--+--+--+--+--+- -+--+--+--+--+--+--+
935 // | 31 | 30 | ..... | 18 | 17 | 16 |
936 // +--+--+--+--+--+- -+--+--+--+--+--+--+
937 // | 15 | 14 | .... | 2 | 1 | 0 |
938 // +--+--+--+--+- -+--+--+--+--+--+--+
939 //
940 // 15 14 .... 2 1 0 <- partial TS ID
941 //
942 // inside
943 //
944 //
945
946 //...Prepare a state for output...
947 //TRGState s(48 + 16 * 5 + 16 * 5 + 3 * 5); // 3*5 for missing wires
948 TRGState s(48 + 16 * 5 + 16 * 5 + 2 * 5 + 38); // 2*5 for edge fastest time, 38 dummy bits to fill to 256 bits
949
950 //...Set up bool array...
951 bool* b = new bool[input.size()];
952 input.copy2bool(b);
953
954 //...Naming...
955 const bool* const hitptn = & b[0]; // 16x3 = 48 bits
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]
969 };
970
971 //...Store hit pattern...
972 s.set(0, 48, hitptn);
973 unsigned p = 48;
974
975 //...Priority cell timing...
976 for (unsigned i = 0; i < 16; i++) {
977 s.set(p, 5, timing[32 + i]);
978 p += 5;
979 }
980
981 //...Fastest timing...
982 const bool dummy[6] = {false, false, false, false, false, true};
983 const TRGState wtDummy(6, dummy);
984 for (unsigned i = 0; i < 18; i++) { // 0 ... 15 for 16 standard ones, 16,17 for two edge areas.
985 TRGState wt[6];
986
987 if (i == 0) { // TS ID 0 has missing wires
988 wt[0] = wtDummy;
989 wt[1] = TRGState(5, timing[0]);
990 wt[2] = TRGState(5, timing[1]);
991 wt[3] = wtDummy;
992 wt[4] = TRGState(5, timing[16]);
993 wt[5] = TRGState(5, timing[32]);
994
995 //...Append 6th bit to indicate hit or not (no hit = 1)...
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) { // TS ID 15 has missing wires
1001 wt[0] = TRGState(5, timing[14]);
1002 wt[1] = TRGState(5, timing[15]);
1003 wt[2] = wtDummy;
1004 wt[3] = TRGState(5, timing[30]);
1005 wt[4] = TRGState(5, timing[31]);
1006 wt[5] = TRGState(5, timing[47]);
1007
1008 //...Append 6th bit to indicate hit or not (no hit = 1)...
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) { // edge area 1 only for cell 0
1015 wt[0] = wtDummy;
1016 wt[1] = wtDummy;
1017 //wt[2] = TRGState(5, timing[16]);
1018 wt[2] = TRGState(5, timing[0]);
1019 wt[3] = wtDummy;
1020 wt[4] = wtDummy;
1021 wt[5] = wtDummy;
1022 //...Append 6th bit to indicate hit or not (no hit = 1)...
1023 if (! hitptn[0]) wt[2].set(5, true);
1024 } else if (i == 17) { // edge area 2 for cell 15 and 31 only
1025 wt[0] = TRGState(5, timing[15]);
1026 wt[1] = wtDummy;
1027 wt[2] = wtDummy;
1028 wt[3] = TRGState(5, timing[31]);
1029 wt[4] = wtDummy;
1030 wt[5] = wtDummy;
1031
1032 //...Append 6th bit to indicate hit or not (no hit = 1)...
1033 if (! hitptn[15]) wt[0].set(5, true);
1034 if (! hitptn[31]) wt[3].set(5, true);
1035 } else {
1036 wt[0] = TRGState(5, timing[i - 1]);
1037 wt[1] = TRGState(5, timing[i]);
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]);
1042
1043 //...Append 6th bit to indicate hit or not (no hit = 1)...
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);
1050 }
1051
1052 //...Look for the fastest hit...
1053 unsigned fastest0 = 0;
1054 unsigned fastest1 = 0;
1055 unsigned fastest2 = 0;
1056 if (wt[0] < wt[1])
1057 fastest0 = 0;
1058 else
1059 fastest0 = 1;
1060 if (wt[2] < wt[3])
1061 fastest1 = 2;
1062 else
1063 fastest1 = 3;
1064 if (wt[4] < wt[5])
1065 fastest2 = 4;
1066 else
1067 fastest2 = 5;
1068
1069 unsigned fastest3 = 0;
1070 if (wt[fastest0] < wt[fastest1])
1071 fastest3 = fastest0;
1072 else
1073 fastest3 = fastest1;
1074
1075 unsigned fastest4 = 0;
1076 if (wt[fastest2] < wt[fastest3])
1077 fastest4 = fastest2;
1078 else
1079 fastest4 = fastest3;
1080
1081 TRGState fastest(5);
1082 if (! wt[fastest4].active(5))
1083 fastest = wt[fastest4].subset(0, 5);
1084
1085 s.set(p, fastest);
1086 p += 5;
1087 }
1088
1089 //s.set(p, 5, timing[0]);
1090 //p += 5;
1091 //s.set(p, 5, timing[15]);
1092 //p += 5;
1093 //s.set(p, 5, timing[31]);
1094
1095#ifdef TRG_DEBUG
1096// unpackerOuterInside(input, s);
1097#endif
1098
1099 delete[] b;
1100 return s;
1101 }
1102
1103 TRGState
1105 {
1106
1107 //...Input should be 48 hit pattern and 48x5 timing, total 288 bits...
1108 //
1109 // Wire numbers and TS ID
1110 //
1111 // outside
1112 //
1113 // +--+--+--+--+- -+--+--+--+--+--+--+
1114 // | 47 | 46 | .... | 34 | 33 | 32 |
1115 // +--+--+--+--+--+- -+--+--+--+--+--+--+
1116 // | 31 | 30 | ..... | 18 | 17 | 16 |
1117 // +--+--+--+--+--+- -+--+--+--+--+--+--+
1118 // | 15 | 14 | .... | 2 | 1 | 0 | <- second priority wire layer
1119 // +--+--+--+--+- -+--+--+--+--+--+--+
1120 //
1121 // 15 14 .... 2 1 0 <- partial TS ID
1122 //
1123 // inside
1124 //
1125 //
1126
1127 //...Prepare a state for output...
1128 //TRGState s(48 + 16 * 5 + 16 * 5 + 3 * 5); // 3*5 for missing wires
1129 TRGState s(48 + 16 * 5 + 16 * 5 + 2 * 5 + 38); // 2*5 for edge fastest time, 38 dummy bits to fill to 256 bits
1130
1131
1132 //...Set up bool array...
1133 bool* b = new bool[input.size()];
1134 input.copy2bool(b);
1135
1136 //...Naming...
1137 const bool* const hitptn = & b[0]; // 16x3 = 48 bits
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]
1151 };
1152
1153 //...Store hit pattern...
1154 s.set(0, 48, hitptn);
1155 unsigned p = 48;
1156
1157
1158 //...Second priority cell timing...
1159 for (unsigned i = 0; i < 16; i++) {
1160 s.set(p, 5, timing[i]);
1161 p += 5;
1162 }
1163
1164 //...Fastest timing...
1165 const bool dummy[6] = {false, false, false, false, false, true};
1166 const TRGState wtDummy(6, dummy);
1167 for (unsigned i = 0; i < 18; i++) { // 0 ... 15 for 16 standard ones, 16,17 for two edge areas.
1168 TRGState wt[5];
1169
1170 if (i == 0) { // TS ID 0 has missing wires
1171 wt[0] = wtDummy;
1172 wt[1] = TRGState(5, timing[0]);
1173 wt[2] = wtDummy;
1174 wt[3] = TRGState(5, timing[16]);
1175 wt[4] = TRGState(5, timing[17]);
1176
1177 //...Append 6th bit to indicate hit or not (no hit = 1)...
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) { // TS ID 15 has missing wires
1182 wt[0] = TRGState(5, timing[14]);
1183 wt[1] = TRGState(5, timing[15]);
1184 wt[2] = TRGState(5, timing[30]);
1185 wt[3] = TRGState(5, timing[31]);
1186 wt[4] = wtDummy;
1187
1188 //...Append 6th bit to indicate hit or not (no hit = 1)...
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) { // edge area 1 only for cell 16
1194 wt[0] = wtDummy;
1195 wt[1] = wtDummy;
1196 wt[2] = wtDummy;
1197 wt[3] = wtDummy;
1198 wt[4] = TRGState(5, timing[16]);
1199 //...Append 6th bit to indicate hit or not (no hit = 1)...
1200 if (! hitptn[16]) wt[4].set(5, true);
1201 } else if (i == 17) { // edge area 2 for cell 15 and 31 only
1202 wt[0] = TRGState(5, timing[15]);
1203 wt[1] = wtDummy;
1204 wt[2] = TRGState(5, timing[31]);
1205 wt[3] = wtDummy;
1206 wt[4] = wtDummy;
1207
1208 //...Append 6th bit to indicate hit or not (no hit = 1)...
1209 if (! hitptn[15]) wt[0].set(5, true);
1210 if (! hitptn[31]) wt[2].set(5, true);
1211 } else {
1212 wt[0] = TRGState(5, timing[i - 1]);
1213 wt[1] = TRGState(5, timing[i]);
1214 wt[2] = TRGState(5, timing[i + 15]);
1215 wt[3] = TRGState(5, timing[i + 16]);
1216 wt[4] = TRGState(5, timing[i + 17]);
1217
1218 //...Append 6th bit to indicate hit or not (no hit = 1)...
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);
1224 }
1225
1226 //...Look for the fastest hit...
1227 unsigned fastest0 = 0;
1228 unsigned fastest1 = 0;
1229 if (wt[0] < wt[1])
1230 fastest0 = 0;
1231 else
1232 fastest0 = 1;
1233 if (wt[2] < wt[3])
1234 fastest1 = 2;
1235 else
1236 fastest1 = 3;
1237
1238 unsigned fastest2 = 0;
1239 if (wt[fastest0] < wt[fastest1])
1240 fastest2 = fastest0;
1241 else
1242 fastest2 = fastest1;
1243
1244 unsigned fastest3 = 0;
1245 if (wt[fastest2] < wt[4])
1246 fastest3 = fastest2;
1247 else
1248 fastest3 = 4;
1249
1250 TRGState fastest(5);
1251 if (! wt[fastest3].active(5))
1252 fastest = wt[fastest3].subset(0, 5);
1253
1254 s.set(p, fastest);
1255 p += 5;
1256 }
1257
1258 //s.set(p, 5, timing[16]);
1259 //p += 5;
1260 //s.set(p, 5, timing[15]);
1261 //p += 5;
1262 //s.set(p, 5, timing[31]);
1263
1264#ifdef TRG_DEBUG
1265// unpackerOuterOutside(input, s);
1266#endif
1267
1268 delete[] b;
1269 return s;
1270 }
1271
1272 void
1274 const TRGState& output)
1275 {
1276
1277 cout << "Input bit size=" << input.size() << endl;
1278
1279 cout << "Input : wire hit pattern" << endl;
1280 cout << " ";
1281 for (unsigned i = 0; i < 48; i++) {
1282 const unsigned j = 48 - i - 1;
1283 if (i && ((i % 8) == 0))
1284 cout << "_";
1285 if (input[j])
1286 cout << "1";
1287 else
1288 cout << "0";
1289 }
1290 cout << endl;
1291 cout << "Input : wire hit timing" << endl;
1292 unsigned o = 48;
1293 for (unsigned i = 0; i < 48; i++) {
1294 TRGState s = input.subset(o + i * 5, 5);
1295 if ((i % 4) == 0)
1296 cout << " ";
1297 cout << i << ": " << s << " ";
1298 if ((i % 4) == 3)
1299 cout << endl;
1300 }
1301
1302 cout << "Output bit size=" << output.size() << endl;
1303
1304 cout << "Output : wire hit pattern" << endl;
1305 cout << " ";
1306 for (unsigned i = 0; i < 32; i++) {
1307 const unsigned j = 32 - i - 1;
1308 if (i && ((i % 8) == 0))
1309 cout << "_";
1310 if (output[j])
1311 cout << "1";
1312 else
1313 cout << "0";
1314 }
1315 cout << endl;
1316
1317 cout << "Output : priority cell timing" << endl;
1318 o = 32;
1319 for (unsigned i = 0; i < 16; i++) {
1320 TRGState s = output.subset(o + i * 5, 5);
1321 if ((i % 4) == 0)
1322 cout << " ";
1323 cout << i << ": " << s << " ";
1324 if ((i % 4) == 3)
1325 cout << endl;
1326 }
1327
1328 cout << "Output : second priority cell position" << endl;
1329 cout << " ";
1330 o = 112;
1331 for (unsigned i = 0; i < 16; i++) {
1332 TRGState s = output.subset(o + i, 1);
1333 if (i && ((i % 8) == 0))
1334 cout << "_";
1335 if (s.active())
1336 cout << "1";
1337 else
1338 cout << "0";
1339 }
1340 cout << endl;
1341
1342 cout << "Output : fastest timing" << endl;
1343 o = 128;
1344 for (unsigned i = 0; i < 16; i++) {
1345 TRGState s = output.subset(o + i * 5, 5);
1346 if ((i % 4) == 0)
1347 cout << " ";
1348 cout << i << ": " << s << " ";
1349 if ((i % 4) == 3)
1350 cout << endl;
1351 }
1352
1353 cout << "Output : timing of missing wires" << endl;
1354 o = 208;
1355 for (unsigned i = 0; i < 1; i++) {
1356 TRGState s = output.subset(o + i * 5, 5);
1357 if ((i % 4) == 0)
1358 cout << " ";
1359 cout << i << ": " << s << " ";
1360 if ((i % 4) == 3)
1361 cout << endl;
1362 }
1363
1364 cout << endl;
1365 }
1366
1367 void
1369 const TRGState& output)
1370 {
1371
1372 cout << "Input bit size=" << input.size() << endl;
1373
1374 cout << "Input : wire hit pattern" << endl;
1375 cout << " ";
1376 for (unsigned i = 0; i < 48; i++) {
1377 const unsigned j = 48 - i - 1;
1378 if (i && ((i % 8) == 0))
1379 cout << "_";
1380 if (input[j])
1381 cout << "1";
1382 else
1383 cout << "0";
1384 }
1385 cout << endl;
1386 cout << "Input : wire hit timing" << endl;
1387 unsigned o = 48;
1388 for (unsigned i = 0; i < 48; i++) {
1389 TRGState s = input.subset(o + i * 5, 5);
1390 if ((i % 4) == 0)
1391 cout << " ";
1392 cout << i << ": " << s << " ";
1393 if ((i % 4) == 3)
1394 cout << endl;
1395 }
1396
1397 cout << "Output bit size=" << output.size() << endl;
1398
1399 cout << "Output : wire hit pattern" << endl;
1400 cout << " ";
1401 for (unsigned i = 0; i < 48; i++) {
1402 const unsigned j = 48 - i - 1;
1403 if (i && ((i % 8) == 0))
1404 cout << "_";
1405 if (output[j])
1406 cout << "1";
1407 else
1408 cout << "0";
1409 }
1410 cout << endl;
1411
1412 cout << "Output : fastest timing" << endl;
1413 o = 48;
1414 for (unsigned i = 0; i < 16; i++) {
1415 TRGState s = output.subset(o + i * 5, 5);
1416 if ((i % 4) == 0)
1417 cout << " ";
1418 cout << i << ": " << s << " ";
1419 if ((i % 4) == 3)
1420 cout << endl;
1421 }
1422
1423 cout << "Output : timing of missing wires" << endl;
1424 o = 128;
1425 for (unsigned i = 0; i < 4; i++) {
1426 TRGState s = output.subset(o + i * 5, 5);
1427 if ((i % 4) == 0)
1428 cout << " ";
1429 cout << i << ": " << s << " ";
1430 if ((i % 4) == 3)
1431 cout << endl;
1432 }
1433
1434 cout << endl;
1435 }
1436
1437 void
1439 const TRGState& output)
1440 {
1441
1442 cout << "Input bit size=" << input.size() << endl;
1443
1444 cout << "Input : wire hit pattern" << endl;
1445 cout << " ";
1446 for (unsigned i = 0; i < 48; i++) {
1447 const unsigned j = 48 - i - 1;
1448 if (i && ((i % 8) == 0))
1449 cout << "_";
1450 if (input[j])
1451 cout << "1";
1452 else
1453 cout << "0";
1454 }
1455 cout << endl;
1456 cout << "Input : wire hit timing" << endl;
1457 unsigned o = 48;
1458 for (unsigned i = 0; i < 48; i++) {
1459 TRGState s = input.subset(o + i * 5, 5);
1460 if ((i % 4) == 0)
1461 cout << " ";
1462 cout << i << ": " << s << " ";
1463 if ((i % 4) == 3)
1464 cout << endl;
1465 }
1466
1467 cout << "Output bit size=" << output.size() << endl;
1468
1469 cout << "Output : wire hit pattern" << endl;
1470 cout << " ";
1471 for (unsigned i = 0; i < 48; i++) {
1472 const unsigned j = 48 - i - 1;
1473 if (i && ((i % 8) == 0))
1474 cout << "_";
1475 if (output[j])
1476 cout << "1";
1477 else
1478 cout << "0";
1479 }
1480 cout << endl;
1481
1482 cout << "Output : priority cell timing" << endl;
1483 o = 48;
1484 for (unsigned i = 0; i < 16; i++) {
1485 TRGState s = output.subset(o + i * 5, 5);
1486 if ((i % 4) == 0)
1487 cout << " ";
1488 cout << i << ": " << s << " ";
1489 if ((i % 4) == 3)
1490 cout << endl;
1491 }
1492
1493 cout << "Output : fastest timing" << endl;
1494 o = 128;
1495 for (unsigned i = 0; i < 16; i++) {
1496 TRGState s = output.subset(o + i * 5, 5);
1497 if ((i % 4) == 0)
1498 cout << " ";
1499 cout << i << ": " << s << " ";
1500 if ((i % 4) == 3)
1501 cout << endl;
1502 }
1503
1504 cout << "Output : timing of missing wires" << endl;
1505 o = 208;
1506 for (unsigned i = 0; i < 2; i++) {
1507 TRGState s = output.subset(o + i * 5, 5);
1508 if ((i % 4) == 0)
1509 cout << " ";
1510 cout << i << ": " << s << " ";
1511 if ((i % 4) == 3)
1512 cout << endl;
1513 }
1514
1515 cout << endl;
1516 }
1517
1518 void
1520 const TRGState& output)
1521 {
1522
1523 cout << "Input bit size=" << input.size() << endl;
1524
1525 cout << "Input : wire hit pattern" << endl;
1526 cout << " ";
1527 for (unsigned i = 0; i < 48; i++) {
1528 const unsigned j = 48 - i - 1;
1529 if (i && ((i % 8) == 0))
1530 cout << "_";
1531 if (input[j])
1532 cout << "1";
1533 else
1534 cout << "0";
1535 }
1536 cout << endl;
1537 cout << "Input : wire hit timing" << endl;
1538 unsigned o = 48;
1539 for (unsigned i = 0; i < 48; i++) {
1540 TRGState s = input.subset(o + i * 5, 5);
1541 if ((i % 4) == 0)
1542 cout << " ";
1543 cout << i << ": " << s << " ";
1544 if ((i % 4) == 3)
1545 cout << endl;
1546 }
1547
1548 cout << "Output bit size=" << output.size() << endl;
1549
1550 cout << "Output : wire hit pattern" << endl;
1551 cout << " ";
1552 for (unsigned i = 0; i < 48; i++) {
1553 const unsigned j = 48 - i - 1;
1554 if (i && ((i % 8) == 0))
1555 cout << "_";
1556 if (output[j])
1557 cout << "1";
1558 else
1559 cout << "0";
1560 }
1561 cout << endl;
1562
1563 cout << "Output : Second priority cell timing" << endl;
1564 o = 48;
1565 for (unsigned i = 0; i < 16; i++) {
1566 TRGState s = output.subset(o + i * 5, 5);
1567 if ((i % 4) == 0)
1568 cout << " ";
1569 cout << i << ": " << s << " ";
1570 if ((i % 4) == 3)
1571 cout << endl;
1572 }
1573
1574 cout << "Output : fastest timing" << endl;
1575 o = 128;
1576 for (unsigned i = 0; i < 16; i++) {
1577 TRGState s = output.subset(o + i * 5, 5);
1578 if ((i % 4) == 0)
1579 cout << " ";
1580 cout << i << ": " << s << " ";
1581 if ((i % 4) == 3)
1582 cout << endl;
1583 }
1584
1585 cout << "Output : timing of missing wires" << endl;
1586 o = 208;
1587 for (unsigned i = 0; i < 2; i++) {
1588 TRGState s = output.subset(o + i * 5, 5);
1589 if ((i % 4) == 0)
1590 cout << " ";
1591 cout << i << ": " << s << " ";
1592 if ((i % 4) == 3)
1593 cout << endl;
1594 }
1595 cout << endl;
1596 }
1597
1598
1599 void //Dump all the details of _mosb into a .log file, do it in the end of simulate()
1601 {
1602
1603 if (type() == innerInside) dump_log_innerInside();
1604 else if (type() == innerOutside) dump_log_innerOutside();
1605 else if (type() == outerInside) dump_log_outerInside();
1606 else if (type() == outerOutside) dump_log_outerOutside();
1607
1608 }
1609
1610 void
1612 {
1613
1614 const TRGClock& dClock = TRGCDC::getTRGCDC()->dataClock();
1615 ofstream output((name() + ".log").c_str());
1616
1617 output << "InnerInside FrontEnd output dump" << endl << endl;
1618
1619 const std::vector<int> changetime = _osb->stateChanges();
1620 std::vector<vector<int>> boolvector(changetime.size());
1621 for (unsigned ch_t = 0; ch_t < changetime.size(); ch_t++) {
1622
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);
1625 }
1626
1627 output << "# of clk: " << changetime[ch_t] << " (" << dClock.absoluteTime(changetime[ch_t]) << " ns), signal vector: " << endl;
1628
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 << " ";
1633 }
1634 output << endl;
1635
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
1638 * b + 2 ]
1639 << boolvector[ch_t][ 32 + 5 * b + 1 ] << boolvector[ch_t][ 32 + 5 * b] << endl;
1640 }
1641 output << endl;
1642
1643 output << "Secondary: ";
1644 for (int b = 0; b < 16; b++) {
1645 output << boolvector[ch_t][ 127 - b ] ;
1646 }
1647 output << endl;
1648
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
1651 + 5 * b + 2 ]
1652 << boolvector[ch_t][ 128 + 5 * b + 1 ] << boolvector[ch_t][ 128 + 5 * b] << endl;
1653 }
1654
1655 output << 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;
1658
1659 output << endl;
1660 }
1661
1662 output.close();
1663
1664 }
1665
1666
1667 void
1669 {
1670
1671 const TRGClock& dClock = TRGCDC::getTRGCDC()->dataClock();
1672 ofstream output((name() + ".log").c_str());
1673
1674 output << "InnerOutside FrontEnd output dump" << endl << endl;
1675
1676 const std::vector<int> changetime = _osb->stateChanges();
1677 std::vector<vector<int>> boolvector(changetime.size());
1678 for (unsigned ch_t = 0; ch_t < changetime.size(); ch_t++) {
1679
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);
1682 }
1683
1684 output << "# of clk: " << changetime[ch_t] << " (" << dClock.absoluteTime(changetime[ch_t]) << " ns), signal vector: " << endl;
1685
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 << " ";
1691 }
1692 output << endl;
1693
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
1696 * b + 2 ]
1697 << boolvector[ch_t][ 48 + 5 * b + 1 ] << boolvector[ch_t][ 48 + 5 * b] << endl;
1698 }
1699
1700 output << 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;
1709
1710 output << endl;
1711 }
1712
1713 output.close();
1714 }
1715
1716
1717 void
1719 {
1720
1721 const TRGClock& dClock = TRGCDC::getTRGCDC()->dataClock();
1722 ofstream output((name() + ".log").c_str());
1723
1724 output << "OuterInside FrontEnd output dump" << endl << endl;
1725
1726 const std::vector<int> changetime = _osb->stateChanges();
1727 std::vector<vector<int>> boolvector(changetime.size());
1728 for (unsigned ch_t = 0; ch_t < changetime.size(); ch_t++) {
1729
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);
1732 }
1733
1734 output << "# of clk: " << changetime[ch_t] << " (" << dClock.absoluteTime(changetime[ch_t]) << " ns), signal vector: " << endl;
1735
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 << " ";
1741 }
1742 output << endl;
1743
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
1746 * b + 2 ]
1747 << boolvector[ch_t][ 48 + 5 * b + 1 ] << boolvector[ch_t][ 48 + 5 * b] << endl;
1748 }
1749 output << endl;
1750
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
1753 + 5 * b + 2 ]
1754 << boolvector[ch_t][ 128 + 5 * b + 1 ] << boolvector[ch_t][ 128 + 5 * b] << endl;
1755 }
1756
1757 output << 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;
1762
1763 output << endl;
1764 }
1765
1766 output.close();
1767
1768 }
1769
1770 void
1772 {
1773
1774 const TRGClock& dClock = TRGCDC::getTRGCDC()->dataClock();
1775 ofstream output((name() + ".log").c_str());
1776
1777 output << "OuterOutside FrontEnd output dump" << endl << endl;
1778 const std::vector<int> changetime = _osb->stateChanges();
1779 std::vector<vector<int>> boolvector(changetime.size());
1780 for (unsigned ch_t = 0; ch_t < changetime.size(); ch_t++) {
1781
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);
1784 }
1785
1786 output << "# of clk: " << changetime[ch_t] << " (" << dClock.absoluteTime(changetime[ch_t]) << " ns), signal vector: " << endl;
1787
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 ;
1793 }
1794 output << endl;
1795
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
1798 * b + 2 ]
1799 << boolvector[ch_t][ 48 + 5 * b + 1 ] << boolvector[ch_t][ 48 + 5 * b] << endl;
1800 }
1801 output << endl;
1802
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
1805 + 5 * b + 2 ]
1806 << boolvector[ch_t][ 128 + 5 * b + 1 ] << boolvector[ch_t][ 128 + 5 * b] << endl;
1807 }
1808
1809 output << 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;
1814
1815
1816 output << endl;
1817 }
1818
1819
1820 output.close();
1821 }
1822
1823
1824
1826} // namespace Belle2
A class to represent a trigger board.
Definition: Board.h:25
TRGSignalBundle * _isb
Input signal bundle.
Definition: FrontEnd.h:148
boardType _type
Board type.
Definition: FrontEnd.h:145
TRGSignalBundle * _osb
Output signal bundle.
Definition: FrontEnd.h:151
boardType
enum boardType
Definition: FrontEnd.h:41
A class to represent a wire in CDC.
Definition: Wire.h:56
A class to represent a digitized signal. Unit is nano second.
Definition: Clock.h:38
A class to represent a bundle of SignalVectors.
Definition: SignalBundle.h:26
A class to represent a bundle of digitized signals.
Definition: SignalVector.h:26
A class to represent a digitized signal. Unit is nano second.
Definition: Signal.h:23
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.
Definition: State.h:24
static std::string tab(void)
returns tab spaces.
Definition: Debug.cc:47
static TRGCDC * getTRGCDC(void)
returns TRGCDC object.
Definition: TRGCDC.cc:192
static unsigned toUnsigned(unsigned n, const bool *array)
Coverts from bool array to unsigned.
Definition: State.h:334
TRGCDCFrontEnd(const std::string &name, boardType type, const TRGClock &systemClock, const TRGClock &dataClock, const TRGClock &userClock)
Constructor.
Definition: FrontEnd.cc:31
void dump_log_innerOutside(void) const
Dump all the details of _mosb into a .log file, for innerOutside FE.
Definition: FrontEnd.cc:1668
double absoluteTime(int clockPosition) const
returns absolute time of clock position
Definition: Clock.cc:128
static TRGState packerOuterInside(const TRGState &input)
Makes bit pattern using input bit pattern for the inner FE.
Definition: FrontEnd.cc:923
TRGState subset(unsigned i, unsigned n) const
returns subset from i with n bits.
Definition: State.cc:356
const TRGClock & clockData(void) const
returns data clock.
Definition: Board.h:123
static int implementationPort(const boardType &type, std::ofstream &)
writes a port map.
Definition: FrontEnd.cc:102
double phase(double timing) const
returns phase of given timing in degree (0 to 360).
Definition: Clock.cc:154
static TRGState packerInnerInside(const TRGState &input)
Makes bit pattern using input bit pattern for the inner FE.
Definition: FrontEnd.cc:341
const std::string & name(void) const
returns name.
Definition: Board.h:109
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.
Definition: FrontEnd.cc:1519
static std::string itostring(int i)
converts int to string. (Use boost::lexical_cast)
Definition: Utilities.cc:50
void dump_log(void) const
Dump all the details of _mosb into a .log file, do it in the end of simulate()
Definition: FrontEnd.cc:1600
static void unpackerInnerOutside(const TRGState &input, const TRGState &output)
Unpacks TRGState.
Definition: FrontEnd.cc:1368
const TRGState & set(unsigned position, bool state=true)
sets state at bit i.
Definition: State.h:305
const TRGClock & dataClock(void) const
returns the data clock.
Definition: TRGCDC.h:982
static TRGState packerInnerOutside(const TRGState &input)
Makes bit pattern using input bit pattern for the outer FE.
Definition: FrontEnd.cc:571
static void unpackerOuterInside(const TRGState &input, const TRGState &output)
Unpacks TRGState.
Definition: FrontEnd.cc:1438
void dump_log_outerInside(void) const
Dump all the details of _mosb into a .log file, for outerInside FE.
Definition: FrontEnd.cc:1718
boardType type(void) const
returns type.
Definition: FrontEnd.cc:59
static int level(void)
returns the debug level.
Definition: Debug.cc:67
static int implementation(const boardType &type, std::ofstream &)
make a VHDL component file.
Definition: FrontEnd.cc:65
bool active(void) const
returns true if there is a signal.
int position(double timing) const
returns clock position.
Definition: Clock.cc:114
static TRGState packerOuterOutside(const TRGState &input)
Makes bit pattern using input bit pattern for the outer FE.
Definition: FrontEnd.cc:1104
static std::string version(void)
returns version.
Definition: FrontEnd.cc:53
void simulate(void)
simulates firmware.
Definition: FrontEnd.cc:152
virtual ~TRGCDCFrontEnd()
Destructor.
Definition: FrontEnd.cc:48
void dump_log_innerInside(void) const
Dump all the details of _mosb into a .log file, for innerInside FE.
Definition: FrontEnd.cc:1611
void dump_log_outerOutside(void) const
Dump all the details of _mosb into a .log file, for outerOutside FE.
Definition: FrontEnd.cc:1771
static void unpackerInnerInside(const TRGState &input, const TRGState &output)
Unpacks TRGState.
Definition: FrontEnd.cc:1273
void push_back(const TRGCDCWire *)
push back TRGCDCWire for this Front-end
Definition: FrontEnd.cc:140
void dump(const std::string &message="", const std::string &pre="") const
dumps contents.
Definition: FrontEnd.cc:146
Abstract base class for different kinds of events.
STL namespace.