StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
l1_fp201_2017_a.cc
1 #include "bits.hh"
2 #include "l1_fp201_2017_a.hh"
3 #include "fms_fm101_2017_a.hh"
4 #include "fms_fm101_2017_a.hh"
5 #include "fms_fm103_2017_a.hh"
6 #include <stdio.h>
7 
8 //#include "registerHack.hh"
9 
10 static const int NBITBS=12;
11 static const int tableBS[NBITBS][NBITBS]={
12  {0,0,0,0,0,0,0,0,0,0,0,0}, //SmST
13  {0,0,0,0,0,0,0,0,0,0,0,0}, //SmSM
14  {1,0,0,0,0,0,0,0,0,0,0,0}, //SmSB
15  {1,1,0,0,0,0,0,0,0,0,0,0}, //SmNB
16  {1,1,1,0,0,0,0,0,0,0,0,0}, //SmNM
17  {0,1,1,1,0,0,0,0,0,0,0,0}, //SmNT
18  {0,0,1,1,1,0,0,0,0,0,0,0}, //LgST
19  {0,0,0,1,1,1,0,0,0,0,0,0}, //LgSM
20  {1,0,0,0,1,1,1,0,0,0,0,0}, //LgSB
21  {1,1,0,0,0,1,1,1,0,0,0,0}, //LgNB
22  {1,1,1,0,0,0,1,1,1,0,0,0}, //LgNM
23  {0,1,1,1,0,0,0,1,1,1,0,0}};//LgNT
24 // Small Large
25 // South North South North
26 // T M B B M T T M B B M T
27 
28 static const int NBITJp=6;
29 static const int tableJp[NBITJp][NBITJp]={
30  {0,0,0,1,1,0}, //ST
31  {0,0,0,1,1,1}, //SM
32  {0,0,0,0,1,1}, //SB
33  {1,1,0,0,0,0}, //NB
34  {1,1,1,0,0,0}, //NM
35  {0,1,1,0,0,0}};//NT
36 // South North
37 // T M B B M T
38 
39 void l1_fp201_2017_a(Board& fp201, int t, int simdat){
40  const int JpThr0=fp201.registers[0];
41  const int JpThr1=fp201.registers[1];
42  const int JpThr2=fp201.registers[2];
43  //Hack until we know details of registers
44  //int JpThr0=JPthr0;
45  //int JpThr1=JPthr1;
46  //int JpThr2=JPthr2;
47 
48  //input
49  int* in;
50  if(simdat==0) {in=(int*)fp201.channels[t];}
51  else {in=(int*)fp201.dsmdata[t];}
52  int fm101 = in[3]; // small cells south
53  int fm102 = in[0]; // small cells north
54  int fm103 = in[1]; // large cells south
55  int fm104 = in[2]; // large cells north
56 
57  //BS
58  int smBS3 = getFM101_2017a_BS3(fm101) | getFM101_2017a_BS3(fm102);
59  int lgBS3 = getFM103_2017a_BS3(fm103) | getFM103_2017a_BS3(fm104);
60  int smBS2 = getFM101_2017a_BS2(fm101) | getFM101_2017a_BS2(fm102);
61  int lgBS2 = getFM103_2017a_BS2(fm103) | getFM103_2017a_BS2(fm104);
62  int smBS1 = getFM101_2017a_BS1T(fm101) | getFM101_2017a_BS1M(fm101) | getFM101_2017a_BS1B(fm101)
63  | getFM101_2017a_BS1T(fm102) | getFM101_2017a_BS1M(fm102) | getFM101_2017a_BS1B(fm102);
64  int lgBS1 = getFM103_2017a_BS1T(fm103) | getFM103_2017a_BS1M(fm103) | getFM103_2017a_BS1B(fm103)
65  | getFM103_2017a_BS1T(fm104) | getFM103_2017a_BS1M(fm104) | getFM103_2017a_BS1B(fm104);
66 
67  //DiBS
68  int DiBS=0;
69  union u_t{
70  int INT[36];
71  char DBS[NBITBS][NBITBS];
72  } u;
73  memset(u.INT,0,sizeof(u.INT));
74  int bs1
75  = (getFM101_2017a_BS1T(fm101)<<0) | (getFM101_2017a_BS1M(fm101)<<1) | (getFM101_2017a_BS1B(fm101)<<2)
76  | (getFM101_2017a_BS1B(fm102)<<3) | (getFM101_2017a_BS1M(fm102)<<4) | (getFM101_2017a_BS1T(fm102)<<5)
77  | (getFM103_2017a_BS1T(fm103)<<6) | (getFM103_2017a_BS1M(fm103)<<7) | (getFM103_2017a_BS1B(fm103)<<8)
78  | (getFM103_2017a_BS1B(fm104)<<9) | (getFM103_2017a_BS1M(fm104)<<10)| (getFM103_2017a_BS1T(fm104)<<11);
79  for(int i=0; i<NBITBS; i++){
80  if(btest(bs1,i)){
81  for(int j=i+1; j<NBITBS; j++){
82  if(tableBS[j][i] & btest(bs1,j)) {u.DBS[j][i]=1; DiBS=1;}
83  }
84  }
85  }
86  for(int i=0; i<36; i++) fp201.userdata[t][10+i]=u.INT[i];
87 
88  //Jp
89  int jp[NBITJp];
90  jp[0] = getFM101_2017a_JpT(fm101) + getFM103_2017a_JpT(fm103); //ST
91  jp[1] = getFM101_2017a_JpM(fm101) + getFM103_2017a_JpM(fm103); //SM
92  jp[2] = getFM101_2017a_JpB(fm101) + getFM103_2017a_JpB(fm103); //SB
93  jp[3] = getFM101_2017a_JpB(fm102) + getFM103_2017a_JpB(fm104); //NB
94  jp[4] = getFM101_2017a_JpM(fm102) + getFM103_2017a_JpM(fm104); //NM
95  jp[5] = getFM101_2017a_JpT(fm102) + getFM103_2017a_JpT(fm104); //NT
96  fp201.userdata[t][0]=jp[0];
97  fp201.userdata[t][1]=jp[1];
98  fp201.userdata[t][2]=jp[2];
99  fp201.userdata[t][3]=jp[3];
100  fp201.userdata[t][4]=jp[4];
101  fp201.userdata[t][5]=jp[5];
102 
103  int JP2=0, JP1=0, JP0=0, jp0=0;
104  fp201.userdata[t][7]=0;
105  fp201.userdata[t][8]=0;
106  fp201.userdata[t][9]=0;
107  for(int i=0; i<NBITJp; i++){
108  if(jp[i]>JpThr2) {JP2=1; fp201.userdata[t][7]+=(1<<i); }
109  if(jp[i]>JpThr1) {JP1=1; fp201.userdata[t][8]+=(1<<i); }
110  if(jp[i]>JpThr0) {JP0=1; fp201.userdata[t][9]+=(1<<i); jp0+=(1<<i);}
111  }
112 
113  //DiJp
114  int DiJp=0;
115  union u2_t{
116  int INT[9];
117  char DJp[NBITJp][NBITJp];
118  } u2;
119  memset(u2.INT,0,sizeof(u2.INT));
120  for(int i=0; i<NBITJp-1; i++){
121  if(btest(jp0,i)){
122  for(int j=i+1; j<NBITJp; j++){
123  if(tableJp[j][i] & btest(jp0,j)) {u2.DJp[j][i]=1; DiJp=1;}
124  }
125  }
126  }
127  for(int i=0; i<9; i++) fp201.userdata[t][50+i]=u2.INT[i];
128 
129  fp201.output[t]
130  = smBS3<<0 | smBS2<<1 | smBS1<<2
131  | lgBS3<<3 | lgBS2<<4 | lgBS1<<5
132  | DiBS<<6
133  | JP2<<7 | JP1<<8 | JP0<<9
134  | DiJp<<10;
135 
136  //if(1){
137  if(PRINT){
138  printf("%s input FM101=%08x FM102=%08x FM103=%08x FM104=%08x\n",fp201.name,fm101,fm102,fm103,fm104);
139  printf("%s out=%08x smBS3/2/1=%1d %1d %1d lgBS3/2/1=%1d %1d %1d DiBS=%1d JP=%1d %1d %1d DiJp=%1d\n",
140  fp201.name,fp201.output[t],
141  smBS3,smBS2,smBS1,
142  lgBS3,lgBS2,lgBS1,
143  DiBS,
144  JP2,JP1,JP0,
145  DiJp);
146  }
147 
148  if(PRINT){
149  //if(DiBS){
150  printf("%s DiBS bs1=0x%03x=",fp201.name,bs1);
151  for(int i=NBITBS-1; i>=0; i--) printf("%1x",btest(bs1,i));
152  printf("\n");
153  for(int j=0; j<NBITBS; j++){
154  printf("DiBS %2d : ",j);
155  for(int i=0; i<=j; i++){
156  printf(" %1s", u.DBS[j][i]?"1":"0");
157  }
158  printf("\n");
159  }
160  }
161 
162  if(PRINT){
163  //if(1){
164  printf("%s DiJp jp1=0x%02x=",fp201.name,jp0);
165  for(int i=NBITJp-1; i>=0; i--) printf("%1x",btest(jp0,i));
166  printf("\n");
167  for(int j=0; j<NBITJp; j++){
168  printf("DiJp ");
169  for(int i=0; i<NBITJp; i++){
170  printf(" %1s", u2.DJp[j][i]?"1":"0");
171  }
172  printf("\n");
173  }
174  }
175 }
176 
177 
Definition: Board.hh:14