StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
bsmd_reader.cxx
1 #include <sys/types.h>
2 
3 #include <rtsLog.h>
4 #include <rtsSystems.h>
5 #include <daqFormats.h>
6 #include <rts.h>
7 
8 #include <DAQ_READER/daq_det.h>
9 
10 #include "daq_bsmd.h"
11 
12 const char *hdrs[3] = {
13  CHAR_EMCADCR,
14  CHAR_EMCADCD,
15  CHAR_EMCPEDR
16 } ;
17 
18 char *bsmd_reader(char *e, struct bsmd_desc *bsmd_d)
19 {
20  struct EMCP *emcp = (struct EMCP *)e ;
21  u_int off, len ;
22  int found_some ;
23 
24  found_some = 0 ; // assume we haven't found anything
25  memset(bsmd_d,0,sizeof(struct bsmd_desc)) ;
26 
27  LOG(DBG,"BSMD: %p",emcp) ;
28 
29  if(!emcp) return 0 ;
30 
31 
32  if(checkBank(emcp->bh.bank_type, CHAR_EMCP)<0) return 0 ;
33 
34  off = b2h32(emcp->sec[1].off) ; // BSMD is at 1
35  len = b2h32(emcp->sec[1].len) ;
36  LOG(DBG,"BSMD: sector 1: %d %d",off,len) ;
37 
38  if((len==0) || (off==0)) return 0 ;
39 
40  struct EMCSECP *emcsecp = (struct EMCSECP *)((u_int *)emcp + off) ;
41 
42  if(checkBank(emcsecp->bh.bank_type, CHAR_EMCSECP)<0) return 0 ;
43 
44  int fibers = (b2h32(emcsecp->bh.length)-10) / 2 ;
45 
46  LOG(DBG,"BSMD: %d fibers",fibers) ;
47 
48  for(int f=0;f<fibers;f++) { // 12 fibers!
49 
50  len = b2h32(emcsecp->fiber[f].len) ;
51  off = b2h32(emcsecp->fiber[f].off) ;
52 
53  if((len==0) || (off==0)) continue ;
54 
55  struct EMCRBP *emcrbp = (struct EMCRBP *)((u_int *)emcsecp + off) ;
56 
57  if(checkBank(emcrbp->bh.bank_type, CHAR_EMCRBP)< 0) return 0 ;
58 
59  int banks = (b2h32(emcrbp->bh.length) - 10)/2 ;
60 
61  LOG(DBG,"BSMD: fiber %d: %d banks",f,banks) ;
62 
63  for(int b=0;b<banks;b++) {
64 
65  len = b2h32(emcrbp->banks[b].len) ;
66  off = b2h32(emcrbp->banks[b].off) ;
67 
68  if((len==0) || (off==0)) continue ;
69 
70  struct DUMMYDATA *emcadc = (DUMMYDATA *) ((u_int *)emcrbp + off) ;
71 
72  if(checkBank(emcadc->bh.bank_type, (char *)hdrs[b])<0) return 0 ;
73 
74  // mark the fact that we found at least one good bank
75  found_some = 1 ;
76 
77  if(b!=0) { // big endian for pedrms and ZS data!
78  bsmd_d->bytes[f][b] = b2h32(emcadc->bh.length)*4 - 40 ; // length is in words but includes the bankHeader
79  bsmd_d->endian[f][b] = 1 ; // big!
80  }
81  else {
82  bsmd_d->bytes[f][b] = l2h32(emcadc->bh.length)*4 - 40 ; // length is in words but includes the bankHeader
83  bsmd_d->endian[f][b] = 0 ; // little!
84  }
85 
86  bsmd_d->dta[f][b] = ((char *)emcadc + 40) ; // skip the 40 bytes bankHeader
87 
88  LOG(DBG,"BSMD: fiber %d: bank %d: bytes %d",f,b,bsmd_d->bytes[f][b]) ;
89  }
90  }
91 
92  LOG(DBG,"bsmd_reader: found some %d",found_some) ;
93 
94  if(found_some) return (char *)bsmd_d ;
95  else return 0 ;
96 }
97 
98 
99