StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
fms_fm102_2012_a.cc
1 //
2 // Pibero Djawotho <pibero@tamu.edu>
3 // Texas A&M University
4 // 9 Feb 2012
5 //
6 
7 #include "bits.hh"
8 #include "fms_fm102_2012_a.hh"
9 
10 void fms_fm102_2012_a(Board& fm102, int t){
11  int* channels = (int*)fm102.channels[t];
12 
13  // Board sum thresholds
14  const int R0 = fm102.registers[0]; // FMSlarge-cluster-th0
15  const int R1 = fm102.registers[1]; // FMSlarge-cluster-th1
16  const int R2 = fm102.registers[2]; // FMSlarge-cluster-th2
17 
18  // High tower bits
19  int HT0 = 0;
20  int HT1 = 0;
21 
22  // Board sum bits
23  int BS0 = 0;
24  int BS1 = 0;
25  int BS2 = 0;
26 
27  // Quadrant sums
28  int Sum[4];
29 
30  for (int i = 0; i < 4; i += 2) {
31  int fm005out = channels[i];
32  int fm006out = channels[i+1];
33 
34  // OR the HT0 bits from the four Layer-0 DSM boards together, and
35  // likewise for the HT1 bits. Output the results to the Layer-2 DSM (2 bits)
36  HT0 |= btest(fm005out,30);
37  HT0 |= btest(fm006out,30);
38 
39  HT1 |= btest(fm005out,31);
40  HT1 |= btest(fm006out,31);
41 
42  // Compare the 18 5-bit Sum values to three thresholds (BSum0,
43  // BSum1, BSum2). OR the results together, and output them to the
44  // Layer-2 DSM (3 bits, not muxed)
45  int SumH = getbits(fm005out,0 ,5);
46  int SumGH = getbits(fm005out,5 ,5);
47  int SumG = getbits(fm005out,10,5);
48  int SumF = getbits(fm005out,15,5);
49  int SumEF = getbits(fm005out,20,5);
50  int SumE = getbits(fm005out,25,5);
51 
52  int SumJ = getbits(fm006out,15,5);
53  int SumIJ = getbits(fm006out,20,5);
54  int SumI = getbits(fm006out,25,5);
55 
56  BS0 |= SumE > R0 || SumEF > R0 || SumF > R0 || SumG > R0 || SumGH > R0 || SumH > R0;
57  BS1 |= SumE > R1 || SumEF > R1 || SumF > R1 || SumG > R1 || SumGH > R1 || SumH > R1;
58  BS2 |= SumE > R2 || SumEF > R2 || SumF > R2 || SumG > R2 || SumGH > R2 || SumH > R2;
59  BS0 |= SumI > R0 || SumIJ > R0 || SumJ > R0;
60  BS1 |= SumI > R1 || SumIJ > R1 || SumJ > R1;
61  BS2 |= SumI > R2 || SumIJ > R2 || SumJ > R2;
62 
63  // Compute the 8-bit total SumE+SumF+SumG+SumH+SumI+SumJ for each of
64  // the two quadrants
65  Sum[i ] = SumE+SumF+SumG+SumH+SumI+SumJ;
66  Sum[i+1] = SumH+SumI+SumJ;
67  }
68 
69  // Extract the 5 least significant bits from each quadrant sum. Set the result to 31
70  // (i.e. binary 11111) if the most significant bit is set.
71  int SumT = Sum[0];
72  int SumB = Sum[2];
73  int SumS = Sum[1]+Sum[3];
74 
75  if (SumT > 31) SumT = 31;
76  if (SumB > 31) SumB = 31;
77  if (SumS > 31) SumS = 31;
78 
79  fm102.output[t] = 0;
80 
81  fm102.output[t] |= SumT << 0;
82  fm102.output[t] |= SumS << 5;
83  fm102.output[t] |= SumB << 10;
84  fm102.output[t] |= BS0 << 24;
85  fm102.output[t] |= BS1 << 25;
86  fm102.output[t] |= BS2 << 26;
87  fm102.output[t] |= HT0 << 27;
88  fm102.output[t] |= HT1 << 28;
89 }
Definition: Board.hh:14