StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
fms_fm001_2017_a.cc
1 #include "bits.hh"
2 #include "qt32b_fms_2015_a.hh"
3 #include "fms_fm001_2017_a.hh"
4 #include <stdio.h>
5 
6 //#include "registerHack.hh"
7 
8 void fms_fm001_2017_a(Board& fm001, int t, int simdat){
9  // thresholds
10  const int BSThr1 = fm001.registers[0];
11  const int BSThr2 = fm001.registers[1];
12  const int BSThr3 = fm001.registers[2];
13  const int BitSelect = fm001.registers[3];
14  //Hack until we know details of registers
15  //int BSThr1=Sm_BSThr1;
16  //int BSThr2=Sm_BSThr2;
17  //int BSThr3=Sm_BSThr3;
18  //int BitSelect=Sm_BitSelect;
19 
20  //input
21  int* in;
22  if(simdat==0) {in=(int*)fm001.channels[t];}
23  else {in=(int*)fm001.dsmdata[t];}
24  int A=in[3];
25  int B=in[2];
26  int C=in[1];
27  int D=in[0];
28 
29  //2x8 sums from QT
30  int A01 = getQT01Sum(A);
31  int A23 = getQT23Sum(A);
32  int B01 = getQT01Sum(B);
33  int B23 = getQT23Sum(B);
34  int C01 = getQT01Sum(C);
35  int C23 = getQT23Sum(C);
36  int D01 = getQT01Sum(D);
37  int D23 = getQT23Sum(D);
38 
39  // Form 2x4 board sums
40  const int MAX=6;
41  int bs[MAX];
42  bs[0] = A01 + A23; //A
43  bs[1] = B01 + B23; //B
44  bs[2] = B23 + C01; //BC
45  bs[3] = C01 + C23; //C
46  bs[4] = C23 + D01; //CD
47  bs[5] = D01 + D23; //D
48  fm001.userdata[t][0]=bs[0];
49  fm001.userdata[t][1]=bs[1];
50  fm001.userdata[t][2]=bs[2];
51  fm001.userdata[t][3]=bs[3];
52  fm001.userdata[t][4]=bs[4];
53  fm001.userdata[t][5]=bs[5];
54 
55  //Compare BS to thresholds
56  int BS3=0, BS2=0;
57  fm001.userdata[t][7]=0;
58  fm001.userdata[t][8]=0;
59  fm001.userdata[t][9]=0;
60  for(int i=0; i<MAX; i++){
61  if(bs[i]>BSThr3) {BS3=1; fm001.userdata[t][7]+=(1<<i); }
62  if(bs[i]>BSThr2) {BS2=1; fm001.userdata[t][8]+=(1<<i); }
63  if(bs[i]>BSThr1) { fm001.userdata[t][9]+=(1<<i); }
64  }
65  int BS1ABC=(bs[0]>BSThr1) | (bs[1]>BSThr1) | (bs[2]>BSThr1) | (bs[3]>BSThr1);
66  int BS1CD=(bs[4]>BSThr1) | (bs[5]>BSThr1);
67 
68  //Jp Sum
69  int JpAB = (bs[0] + bs[1])>>BitSelect; //A+B
70  int JpCD = (bs[3] + bs[5])>>BitSelect; //C+D
71  if(JpAB>0xFF) JpAB=0xFF;
72  if(JpCD>0xFF) JpCD=0xFF;
73 
74  // Output
75  fm001.output[t]
76  = BS3 | BS2 << 1
77  | BS1CD << 2 | BS1ABC << 3
78  | D23 << 4
79  | JpAB << 16 | JpCD << 24;
80 
81 
82  if(PRINT){
83  printf("%s input A=%08x B=%08x C=%08x D=%08x\n",fm001.name,A,B,C,D);
84  printf("%s out=%08x BS3=%1d BS2=%1d BS1ABC/CD=%1d %1d sum=%4d %4d %4d %4d %4d %4d Jp=%3d %3d\n",
85  fm001.name,fm001.output[t],BS3,BS2,BS1ABC,BS1CD,
86  bs[0],bs[1],bs[2],bs[3],bs[4],bs[5],JpAB,JpCD);
87  }
88 }
89 
90 int getFM001_2017a_BS3(int out) {return getbits(out, 0, 1);}
91 int getFM001_2017a_BS2(int out) {return getbits(out, 1, 1);}
92 int getFM001_2017a_BS1CD(int out) {return getbits(out, 2, 1);}
93 int getFM001_2017a_BS1ABC(int out) {return getbits(out, 3, 1);}
94 int getFM001_2017a_D23(int out) {return getbits(out, 4,12);}
95 int getFM001_2017a_JpAB(int out) {return getbits(out,16, 8);}
96 int getFM001_2017a_JpCD(int out) {return getbits(out,24, 8);}
Definition: Board.hh:14