StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
fms_fm005_2015_a.cc
1 #include "bits.hh"
2 #include "qt32b_fms_2015_a.hh"
3 #include "fms_fm005_2015_a.hh"
4 #include <stdio.h>
5 
6 //#include "registerHack.hh"
7 
8 void fms_fm005_2015_a(Board& fm005, int t, int simdat){
9  int BSThr1 = fm005.registers[0];
10  int BSThr2 = fm005.registers[1];
11  int BSThr3 = fm005.registers[2];
12  int BitSelect= fm005.registers[3];
13  //Hack until we know details of registers
14  //int BSThr1=Lg_BSThr1;
15  //int BSThr2=Lg_BSThr2;
16  //int BSThr3=Lg_BSThr3;
17  //int BitSelect=Lg_BitSelect;
18 
19  //input
20  int* in;
21  if(simdat==0) {in=(int*)fm005.channels[t];}
22  else {in=(int*)fm005.dsmdata[t];}
23  int G=in[3];
24  int H=in[2];
25  int I=in[1];
26  int J=in[0];
27 
28  //2x8 sums from QT
29  int G01 = getQT01Sum(G);
30  int G23 = getQT23Sum(G);
31  int H01 = getQT01Sum(H);
32  int H23 = getQT23Sum(H);
33  int I01 = getQT01Sum(I);
34  int I23 = getQT23Sum(I);
35  int J01 = getQT01Sum(J);
36  int J23 = getQT23Sum(J);
37  //printf("G01-J23=%x %x %x %x %x %x %x %x\n",G01,G23,H01,H23,I01,I23,J01,J23);
38 
39  // Form 2x4 board sums
40  const int MAX=7;
41  int bs[MAX];
42  bs[0] = G01 + G23; //G
43  bs[1] = G23 + H01; //GH
44  bs[2] = H01 + H23; //H
45  bs[3] = H23 + I01; //HI
46  bs[4] = I01 + I23; //I
47  bs[5] = I23 + J01; //IJ
48  bs[6] = J01 + J23; //J
49  fm005.userdata[t][0]=bs[0];
50  fm005.userdata[t][1]=bs[1];
51  fm005.userdata[t][2]=bs[2];
52  fm005.userdata[t][3]=bs[3];
53  fm005.userdata[t][4]=bs[4];
54  fm005.userdata[t][5]=bs[5];
55  fm005.userdata[t][6]=bs[6];
56 
57  //Compare BS to thresholds
58  int BS3=0, BS2=0;
59  fm005.userdata[t][7]=0;
60  fm005.userdata[t][8]=0;
61  fm005.userdata[t][9]=0;
62  for(int i=0; i<MAX; i++){
63  if(bs[i]>BSThr3) {BS3=1; fm005.userdata[t][7]+=(1<<i); }
64  if(bs[i]>BSThr2) {BS2=1; fm005.userdata[t][8]+=(1<<i); }
65  if(bs[i]>BSThr1) { fm005.userdata[t][9]+=(1<<i); }
66  }
67  int BS1GHIJ= (bs[0]>BSThr1) | (bs[1]>BSThr1) | (bs[2]>BSThr1) | (bs[3]>BSThr1)
68  | (bs[4]>BSThr1) | (bs[5]>BSThr1) | (bs[6]>BSThr1);
69 
70  //Jp Sum
71  int JpGH = (bs[0] + bs[2])>>BitSelect; //G+H
72  int JpIJ = (bs[4] + bs[6])>>BitSelect; //I+J
73  if(JpGH >0xFF) JpGH=0xFF;
74  if(JpIJ >0xFF) JpIJ=0xFF;
75 
76  // Output the resulting 6 5-bit sums to the Layer-1 DSM (30 bits)
77  fm005.output[t]
78  = BS3 | BS2 << 1
79  | BS1GHIJ << 2
80  | J23 << 4
81  | JpGH << 16 | JpIJ << 24;
82 
83  if(PRINT){
84  printf("%s input G=%08x H=%08x I=%08x J=%08x\n",fm005.name,G,H,I,J);
85  printf("%s out=%08x BS3=%1d BS2=%1d BS1GHIJ=%1d sum=%4d %4d %4d %4d %4d %4d %4d JpGH/IJ=%3d %3d\n",
86  fm005.name,fm005.output[t],BS3,BS2,BS1GHIJ,
87  bs[0],bs[1],bs[2],bs[3],bs[4],bs[5],bs[6],JpGH,JpIJ);
88  }
89 }
90 
91 int getFM005_BS3(int out) {return getbits(out, 0, 1);}
92 int getFM005_BS2(int out) {return getbits(out, 1, 1);}
93 int getFM005_BS1GHIJ(int out){return getbits(out, 2, 1);}
94 int getFM005_J23(int out) {return getbits(out, 4,12);}
95 int getFM005_JpGH(int out) {return getbits(out,16, 8);}
96 int getFM005_JpIJ(int out) {return getbits(out,24, 8);}
Definition: Board.hh:14