StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
fms_fm101_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_fm101_2012_a.hh"
9 
10 void fms_fm101_2012_a(Board& fm101, int t){
11  int* channels = (int*)fm101.channels[t];
12 
13  const int R0 = fm101.registers[0]; // FMSsmall-cluster-th0
14  const int R1 = fm101.registers[1]; // FMSsmall-cluster-th1
15  const int R2 = fm101.registers[2]; // FMSsmall-layer1-mode: 0=data taking, 1=debug
16 
17  // High tower bits
18  int HT0 = 0;
19  int HT1 = 0;
20 
21  // Board sum bits
22  int BS0 = 0;
23  int BS1 = 0;
24 
25  // Quadrant sums
26  int Sum[4];
27  int PairSum[4];
28 
29  for (int i = 0; i < 4; ++i) {
30  int fm001out = channels[i];
31 
32  // Combine (OR) the HT threshold bits from all 4 quadrants
33  HT0 |= btest(fm001out,30);
34  HT1 |= btest(fm001out,31);
35 
36  // Compare the 24 5-bit Sum values to three thresholds (BSum0,
37  // BSum1, BSum2). OR the results together, and output them to the
38  // Layer-2 DSM (3 bits, not muxed)
39  int SumD = getbits(fm001out,0 ,5);
40  int SumC = getbits(fm001out,5 ,5);
41  int SumBC = getbits(fm001out,10,5);
42  int SumB = getbits(fm001out,15,5);
43  int SumCD = getbits(fm001out,20,5);
44  int SumA = getbits(fm001out,25,5);
45 
46  BS0 |= SumA > R0 || SumCD > R0 || SumB > R0 || SumBC > R0 || SumC > R0 || SumD > R0;
47  BS1 |= SumA > R1 || SumCD > R1 || SumB > R1 || SumBC > R1 || SumC > R1 || SumD > R1;
48 
49  // Compute the 5-bit total SumA+SumB+SumC+SumD for each of the four quadrants
50  Sum[i] = SumA+SumB+SumC+SumD;
51  PairSum[i] = SumC+SumD;
52  }
53 
54  // Extract the 5 least significant bits from each quadrant sum.
55  // Set the result to 31 (i.e. binary 11111) if the most significant bit
56  // is set.
57 
58  int SumST = Sum[0];
59  int SumSB = Sum[1];
60  int SumNT = Sum[2];
61  int SumNB = Sum[3];
62 
63  int SumS = PairSum[0]+PairSum[1];
64  int SumN = PairSum[2]+PairSum[3];
65 
66  if (SumST > 31) SumST = 31;
67  if (SumSB > 31) SumSB = 31;
68  if (SumNT > 31) SumNT = 31;
69  if (SumNB > 31) SumNB = 31;
70 
71  if (SumS > 31) SumS = 31;
72  if (SumN > 31) SumN = 31;
73 
74  fm101.output[t] = 0;
75 
76  switch (R2) {
77  case 0: // data taking mode
78  fm101.output[t] |= SumST << 0;
79  fm101.output[t] |= SumS << 5;
80  fm101.output[t] |= SumSB << 10;
81  fm101.output[t] |= SumNT << 15;
82  fm101.output[t] |= SumN << 20;
83  fm101.output[t] |= SumNB << 25;
84  fm101.output[t] |= BS0 << 30;
85  fm101.output[t] |= BS1 << 31;
86  break;
87  case 1: // debug mode
88  fm101.output[t] |= SumST << 0;
89  fm101.output[t] |= SumS << 5;
90  fm101.output[t] |= SumSB << 10;
91  fm101.output[t] |= SumNT << 15;
92  fm101.output[t] |= HT0 << 20;
93  fm101.output[t] |= HT1 << 21;
94  fm101.output[t] |= SumNB << 25;
95  fm101.output[t] |= BS0 << 30;
96  fm101.output[t] |= BS1 << 31;
97  break;
98  }
99 }
Definition: Board.hh:14