StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
l1_fp201_2012_b.cc
1 //
2 // Pibero Djawotho <pibero@tamu.edu>
3 // Texas A&M University
4 // 13 Feb 2012
5 //
6 
7 #include "bits.hh"
8 #include "l1_fp201_2012_b.hh"
9 #include <stdio.h>
10 
11 void l1_fp201_2012_b(Board& fp201, int t){
12  int* channels = (int*)fp201.channels[t];
13 
14  const int R0 = fp201.registers[0]; // FMS-JP0
15  const int R1 = fp201.registers[1]; // FMS-JP1
16  const int R2 = fp201.registers[2]; // FMS-JP2
17  const int R3 = fp201.registers[3]; // FMS-layer2-mode: 0=data taking, 1=debug
18  const int R4 = fp201.registers[4]; // FMS-combo1-enable
19  const int R5 = fp201.registers[5]; // FMS-combo2-enable
20 
21  int fm101out = channels[0]; // small cells
22  int fm102out = channels[1]; // large cells south
23  int fm103out = channels[2]; // large cells north
24  int fe101out = channels[7]; // FE101, FPE
25 
26  // Combine (OR) the two FPE bits
27  int fpe0 = btest(fe101out,0);
28  int fpe1 = btest(fe101out,1);
29  int fpe = fpe0|fpe1;
30 
31  // If the algorithm is in debug mode (R3=1) then delay the HT bits from the small
32  // cell array to the 3rd step. Otherwise (R3=0), just zero them out.
33  int HT0 = btest(fm102out,27) | btest(fm103out,27);
34  int HT1 = btest(fm102out,28) | btest(fm103out,28);
35 
36  if (R3 == 1) {
37  HT0 |= btest(fm101out,20);
38  HT1 |= btest(fm101out,21);
39  }
40 
41  // Pass the small cell BSum0 and BSum1 bits to the TCU (3 bits:
42  // SBsum0 and SBsum1)
43  int SBS0 = btest(fm101out,30);
44  int SBS1 = btest(fm101out,31);
45 
46  // OR the large cell BSum0 bits from the two large-cell Layer-1 DSM
47  // boards together, and likewise for the BSum1 and BSum2 bits. Output
48  // the results to the TCU (3 bits: LBsum0, LBsum1, LBsum2)
49  int LBS0 = btest(fm102out,24) | btest(fm103out,24);
50  int LBS1 = btest(fm102out,25) | btest(fm103out,25);
51  int LBS2 = btest(fm102out,26) | btest(fm103out,26);
52 
53  // Make the six overlapping jet patches by adding together the small
54  // and large cell sums for each quadrant
55  int SumST, SumSB, SumNT, SumNB, SumS, SumN;
56  computeJetPatchSums(fp201,SumST,SumSB,SumNT,SumNB,SumS,SumN);
57 
58  // OR the JP0 bits from the four quadrants together, and likewise
59  // for the JP1 and JP2 bits. Output the results to the TCU (3 bits:
60  // JP0, JP1, JP2)
61  int JP0 = SumST > R0 || SumSB > R0 || SumNT > R0 || SumNB > R0 || SumS > R0;
62  int JP1 = SumST > R1 || SumSB > R1 || SumNT > R1 || SumNB > R1 || SumS > R1;
63  int JP2 = SumST > R2 || SumSB > R2 || SumNT > R2 || SumNB > R2 || SumS > R2;
64 
65  if (R3 == 0) {
66  JP0 |= SumN > R0;
67  JP1 |= SumN > R1;
68  JP2 |= SumN > R2;
69  }
70 
71  // If two or more quadrants satisfy the JP0 threshold, set the
72  // "di-jet" bit. Output it to the TCU (1 bit: Di-jet)
73  int dijet = (((SumST > R0) && ((SumSB > R0) || (SumNT > R0) || (SumNB > R0))) ||
74  ((SumSB > R0) && ((SumNT > R0) || (SumNB > R0))) ||
75  ((SumNT > R0) && (SumNB > R0)) ||
76  ((SumN > R0) && (SumST > R0)) ||
77  ((SumN > R0) && (SumS > R0)) ||
78  ((SumN > R0) && (SumSB > R0)) ||
79  ((SumS > R0) && (SumNT > R0)) ||
80  ((SumS > R0) && (SumNB > R0)));
81 
82  int combo1 = ((SBS0 && btest(R4,0)) ||
83  (SBS1 && btest(R4,1)) ||
84  (LBS0 && btest(R4,2)) ||
85  (LBS1 && btest(R4,3)) ||
86  (LBS2 && btest(R4,4)) ||
87  (JP0 && btest(R4,5)) ||
88  (JP1 && btest(R4,6)) ||
89  (JP2 && btest(R4,7)) ||
90  (dijet && btest(R4,8)) ||
91  (fpe && btest(R4,9)));
92 
93  int combo2 = ((SBS0 && btest(R5,0)) ||
94  (SBS1 && btest(R5,1)) ||
95  (LBS0 && btest(R5,2)) ||
96  (LBS1 && btest(R5,3)) ||
97  (LBS2 && btest(R5,4)) ||
98  (JP0 && btest(R5,5)) ||
99  (JP1 && btest(R5,6)) ||
100  (JP2 && btest(R5,7)) ||
101  (dijet && btest(R5,8)) ||
102  (fpe && btest(R5,9)));
103 
104  fp201.output[t] = 0;
105 
106  fp201.output[t] |= HT0 << 0;
107  fp201.output[t] |= HT1 << 1;
108  fp201.output[t] |= SBS0 << 2;
109  fp201.output[t] |= SBS1 << 3;
110  fp201.output[t] |= LBS0 << 5;
111  fp201.output[t] |= LBS1 << 6;
112  fp201.output[t] |= LBS2 << 7;
113  fp201.output[t] |= JP0 << 8;
114  fp201.output[t] |= JP1 << 9;
115  fp201.output[t] |= JP2 << 10;
116  fp201.output[t] |= dijet << 11;
117  fp201.output[t] |= combo1 << 12;
118  fp201.output[t] |= combo2 << 13;
119  fp201.output[t] |= fpe << 14;
120 }
121 
122 void computeJetPatchSums(const Board& fp201, int& SumST, int& SumSB, int& SumNT, int& SumNB, int& SumS, int& SumN, int t)
123 {
124  int* channels = (int*)fp201.channels[t];
125 
126  int fm101out = channels[0]; // small cells
127  int fm102out = channels[1]; // large cells south
128  int fm103out = channels[2]; // large cells north
129 
130  // small cells
131  int SumSmST = getbits(fm101out,0 ,5); // south-top
132  int SumSmS = getbits(fm101out,5 ,5); // south
133  int SumSmSB = getbits(fm101out,10,5); // south-bottom
134  int SumSmNT = getbits(fm101out,15,5); // north-top
135  int SumSmN = getbits(fm101out,20,5); // north
136  int SumSmNB = getbits(fm101out,25,5); // north-bottom
137 
138  // large cells
139  int SumLgST = getbits(fm102out,0 ,5); // south-top
140  int SumLgS = getbits(fm102out,5 ,5); // south
141  int SumLgSB = getbits(fm102out,10,5); // south-bottom
142  int SumLgNT = getbits(fm103out,0 ,5); // north-top
143  int SumLgN = getbits(fm103out,5 ,5); // north
144  int SumLgNB = getbits(fm103out,10,5); // north-bottom
145 
146  // jet patch sums
147  SumST = SumSmST + SumLgST; // south-top
148  SumSB = SumSmSB + SumLgSB; // south-bottom
149  SumNT = SumSmNT + SumLgNT; // north-top
150  SumNB = SumSmNB + SumLgNB; // north-bottom
151  SumS = SumSmS+SumLgS; // south
152  SumN = SumSmN+SumLgN; // north
153 }
Definition: Board.hh:14