StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
fms_fm006_2017_a.cc
1 #include "bits.hh"
2 #include "qt32b_fms_2015_a.hh"
3 #include "fms_fm006_2017_a.hh"
4 #include <stdio.h>
5 
6 #include "registerHack.hh"
7 
8 void fms_fm006_2017_a(Board& fm006, int t, int simdat){
9  // thresholds
10  int BSThr1 = fm006.registers[0];
11  int BSThr2 = fm006.registers[1];
12  int BSThr3 = fm006.registers[2];
13  int BitSelect= fm006.registers[3];
14  //Hack until we know details of registers
15  //int BSThr1=Lg_BSThr1;
16  //int BSThr2=Lg_BSThr2;
17  //int BSThr3=Lg_BSThr3;
18  //int BitSelect=Lg_BitSelect;
19 
20  //input
21  int* in;
22  if(simdat==0) {in=(int*)fm006.channels[t];}
23  else {in=(int*)fm006.dsmdata[t];}
24  int E=in[1];
25  int F=in[0];
26 
27  //2x8 sums from QT
28  int E01 = getQT01Sum(E);
29  int E23 = getQT23Sum(E);
30  int F01 = getQT01Sum(F);
31  int F23 = getQT23Sum(F);
32 
33  // Form 2x4 board sums
34  const int MAX=3;
35  int bs[MAX];
36  bs[0] = E01 + E23; //E
37  bs[1] = E23 + F01; //EF
38  bs[2] = F01 + F23; //F
39  fm006.userdata[t][0]=bs[0];
40  fm006.userdata[t][1]=bs[1];
41  fm006.userdata[t][2]=bs[2];
42 
43  //Compare BS to thresholds
44  int BS3=0, BS2=0;
45  fm006.userdata[t][7]=0;
46  fm006.userdata[t][8]=0;
47  fm006.userdata[t][9]=0;
48  for(int i=0; i<MAX; i++){
49  if(bs[i]>BSThr3) {BS3=1; fm006.userdata[t][7]+=(1<<i); }
50  if(bs[i]>BSThr2) {BS2=1; fm006.userdata[t][8]+=(1<<i); }
51  if(bs[i]>BSThr1) { fm006.userdata[t][9]+=(1<<i); }
52  }
53  int BS1EF =(bs[0]>BSThr1) | (bs[1]>BSThr1) | (bs[2]>BSThr1);
54 
55  //Jp Sum
56  int JpEF = (bs[0] + bs[2])>>BitSelect; //E+F
57  if(JpEF>0xFF) JpEF =0xFF;
58 
59  // Output the resulting 6 5-bit sums to the Layer-1 DSM (30 bits)
60  fm006.output[t]
61  = BS3 | BS2 << 1
62  | BS1EF << 2
63  | JpEF << 16;
64 
65 
66  if(PRINT){
67  printf("%s input E=%08x F=%08x\n",fm006.name,E,F);
68  printf("%s out=%08x BS3=%1d BS2=%1d BS1EF=%1d sum=%4d %4d %4d JpEF=%3d\n",
69  fm006.name,fm006.output[t],BS3,BS2,BS1EF,bs[0],bs[1],bs[2],JpEF);
70  }
71 }
72 
73 int getFM006_2017a_BS3(int out) {return getbits(out, 0, 1);}
74 int getFM006_2017a_BS2(int out) {return getbits(out, 1, 1);}
75 int getFM006_2017a_BS1EF(int out) {return getbits(out, 2, 1);}
76 int getFM006_2017a_JpEF(int out) {return getbits(out,16, 8);}
Definition: Board.hh:14