StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
fpd_reader.cxx
1 #include <stdio.h>
2 #include <string.h>
3 #include <arpa/inet.h>
4 
5 #include <rtsLog.h>
6 #include <rts.h>
7 #include <rtsSystems.h>
8 #include <daqFormats.h>
9 
10 #include "daq_fpd.h"
11 
12 int fpd_reader(char *m, struct fpd_t *fpd, u_int driver)
13 {
14  struct DATAP *datap = (struct DATAP *)m ;
15  struct FPDP *fpdp ;
16  struct FPDADCD *adcd ;
17  struct FPDTDCD *tdcd ;
18  struct FPDREGD *regd ;
19  struct FPDPEDR *pedr ;
20  struct FPDSCL *scl ;
21  struct BBCDAT *bbcdat ;
22  struct BBCPED *bbcped ;
23  struct BBCSCL *bbcscl ;
24 
25  int len, off ;
26  int i, banks, type ;
27  int ch ;
28 
29  fpd->mode = 1 ;
30  fpd->max_channels = 1 ;
31  fpd->channels = 0 ;
32 
33  if(datap == NULL) return 0 ;
34 
35  len = ntohl(datap->det[FPD_ID].len) * 4 ;
36  if(len == 0) return 0 ;
37 
38  off = ntohl(datap->det[FPD_ID].off) ;
39  if(off == 0) return 0 ;
40 
41 
42  fpdp = (struct FPDP *)((u_int *)m + off) ;
43 
44  if(checkBank(fpdp->bh.bank_type,"FPDP") < 0) {
45  return -1 ;
46  }
47 
48  memset(&fpd,0,sizeof(fpd)) ;
49  fpd->mode = 1 ;
50  fpd->max_channels = 256 ;
51  fpd->channels = 0 ;
52 
53 
54  banks = (l2h32(fpdp->bh.length) - 10)/2 ; // number of pointers present
55 
56  for(type=0;type<banks;type++) {
57  if(fpdp->type[type].len == 0) {
58  LOG(DBG,"FPD bank %d not present (len==0)",type,0,0,0,0) ;
59  continue ;
60  }
61  else {
62  LOG(DBG,"FPD bank %d found: len %d qw, off %d qw (%d %d)",type,
63  l2h32(fpdp->type[type].len),l2h32(fpdp->type[type].off),fpdp->type[type].len,fpdp->type[type].off) ;
64  }
65 
66  switch(type) {
67  case FPDP_ADCD :
68 
69  adcd = (struct FPDADCD *)((u_int *)fpdp + l2h32(fpdp->type[type].off)) ;
70 // adcd = (struct FPDADCD *)((u_int *)fpdp + (fpdp->type[type].off)) ;
71  if(checkBank(adcd->bh.bank_type,CHAR_FPDADCD) < 0) {
72  return -1 ;
73  }
74 
75  // could be variable size
76  ch = (l2h32(adcd->bh.length) - 10)*2 ; // size in shorts!
77  fpd->channels = ch ;
78 
79  if(ch > (int)(sizeof(fpd->adc)/sizeof(fpd->adc[0]))) {
80  LOG(ERR,"Counter overflow in FPDADCD! ch == %d",ch,0,0,0,0) ;
81  return -1 ;
82  }
83 
84  for(i=0;i<ch;i++) {
85  fpd->adc[i] = l2h16(adcd->data[i]) ;
86  }
87 
88  break ;
89  case FPDP_TDCD :
90 
91  tdcd = (struct FPDTDCD *)((u_int *)fpdp + l2h32(fpdp->type[type].off)) ;
92  if(checkBank(tdcd->bh.bank_type,CHAR_FPDTDCD) < 0) {
93  return -1 ;
94  }
95 
96  // fixed size 8
97  for(i=0;i<8;i++) {
98  fpd->tdc[i] = l2h16(tdcd->data[i]) ;
99  }
100 
101  break ;
102 
103  case FPDP_REGD :
104  regd = (struct FPDREGD *)((u_int *)fpdp + l2h32(fpdp->type[type].off)) ;
105  if(checkBank(regd->bh.bank_type,CHAR_FPDREGD) < 0) {
106  return -1 ;
107  }
108 
109  // fixed size 3
110  for(i=0;i<3;i++) {
111  fpd->reg[i] = l2h16(regd->data[i]) ;
112  }
113 
114  break ;
115 
116  case FPDP_PEDR :
117  pedr = (struct FPDPEDR *)((u_int *)fpdp + l2h32(fpdp->type[type].off)) ;
118  if(checkBank(pedr->bh.bank_type,CHAR_FPDPEDR) < 0) {
119  return -1 ;
120  }
121 
122  // fixed sizes...
123  for(i=0;i<256;i++) {
124  fpd->ped[i] = l2h16(pedr->ped[i]) ;
125  }
126  for(i=0;i<256;i++) {
127  fpd->rms[i] = l2h16(pedr->rms[i]) ;
128  }
129 
130  break ;
131  case FPDP_SCL :
132  scl = (struct FPDSCL *)((u_int *)fpdp + l2h32(fpdp->type[type].off)) ;
133  if(checkBank(scl->bh.bank_type,CHAR_FPDSCL) < 0) {
134  return -1 ;
135  }
136 
137  break ;
138  case FPDP_BBCDAT :
139  bbcdat = (struct BBCDAT *)((u_int *)fpdp + l2h32(fpdp->type[type].off)) ;
140  if(checkBank(bbcdat->bh.bank_type,CHAR_BBCDAT) < 0) {
141  return -1 ;
142  }
143 
144  // fixed sizes...
145  for(i=0;i<32;i++) {
146  fpd->bbc.pulse[i] = l2h16(bbcdat->pulse[i]) ;
147  }
148  for(i=0;i<32;i++) {
149  fpd->bbc.time[i] = l2h16(bbcdat->time[i]) ;
150  }
151  for(i=0;i<2;i++) {
152  fpd->bbc.proof[i] = l2h16(bbcdat->proof[i]) ;
153  }
154  for(i=0;i<6;i++) {
155  fpd->bbc.spare[i] = l2h16(bbcdat->spare[i]) ;
156  }
157 
158 
159  break ;
160  case FPDP_BBCPED :
161  bbcped = (struct BBCPED *)((u_int *)fpdp + l2h32(fpdp->type[type].off)) ;
162  if(checkBank(bbcped->bh.bank_type,CHAR_BBCPED) < 0) {
163  return -1 ;
164  }
165 
166  for(i=0;i<32;i++) {
167  fpd->bbc.ped[i] = l2h16(bbcped->ped[i]) ;
168  }
169  for(i=0;i<32;i++) {
170  fpd->bbc.rms[i] = l2h16(bbcped->rms[i]) ;
171  }
172  for(i=0;i<64;i++) {
173  fpd->bbc.peaks[i] = l2h16(bbcped->peaks[i]) ;
174  }
175 
176  break ;
177  case FPDP_BBCSCL :
178  bbcscl = (struct BBCSCL *)((u_int *)fpdp + l2h32(fpdp->type[type].off)) ;
179  if(checkBank(bbcscl->bh.bank_type,CHAR_BBCSCL) < 0) {
180  return -1 ;
181  }
182 
183  for(i=0;i<32;i++) {
184  fpd->bbc.scl[i] = l2h16(bbcscl->scl[i]) ;
185  }
186 
187  break ;
188 
189 
190  default :
191  LOG(ERR,"Unknown bank id %d in FPDP?",type,0,0,0,0) ;
192  break ;
193  }
194 
195  }
196 
197  return len ;
198 
199 }
200 
Definition: daq_fpd.h:20