StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
emc_single_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 const struct hdrs {
11  const char *emcp ;
12  const char *secp ;
13  const char *rbp ;
14  const char *adc ;
15 } hdrs[2] = {
16  { CHAR_EMCP, CHAR_EMCSECP, CHAR_EMCRBP, CHAR_EMCADCR },
17  { CHAR_EECP, CHAR_EECSECP, CHAR_EECRBP, CHAR_EECADCR }
18 } ;
19 
20 /*
21  Returns the pointer to the raw data start.
22  This will include the aux 4 bytes of VME RB stuff.
23 
24 */
25 char *emc_single_reader(char *e, int *bytes, int rts_id)
26 {
27  struct EMCP *emcp = (struct EMCP *)e ;
28  u_int off, len ;
29  int hdr_ix, sec_ix ;
30 
31  *bytes = 0 ;
32 
33  if(!emcp) return 0 ;
34 
35  switch(rts_id) {
36  case BTOW_ID :
37  hdr_ix = 0 ;
38  sec_ix = 0 ;
39  break ;
40  case ETOW_ID :
41  hdr_ix = 1 ;
42  sec_ix = 0 ;
43  break ;
44  case ESMD_ID :
45  hdr_ix = 1 ;
46  sec_ix = 1 ;
47  break ;
48  default :
49  return 0 ;
50  }
51 
52  if(checkBank(emcp->bh.bank_type, hdrs[hdr_ix].emcp)<0) return 0 ;
53 
54  off = b2h32(emcp->sec[sec_ix].off) ;
55  len = b2h32(emcp->sec[sec_ix].len) ;
56 
57  if((len==0) || (off==0)) return 0 ;
58 
59  struct EMCSECP *emcsecp = (struct EMCSECP *)((u_int *)emcp + off) ;
60 
61  if(checkBank(emcsecp->bh.bank_type, hdrs[hdr_ix].secp)<0) return 0 ;
62 
63  // only 1 fiber
64  len = b2h32(emcsecp->fiber[0].len) ;
65  off = b2h32(emcsecp->fiber[0].off) ;
66 
67  if((len==0) || (off==0)) return 0 ;
68 
69  struct EMCRBP *emcrbp = (struct EMCRBP *)((u_int *)emcsecp + off) ;
70 
71  if(checkBank(emcrbp->bh.bank_type, hdrs[hdr_ix].rbp)< 0) return 0 ;
72 
73  // raw data is in bank 0
74  len = b2h32(emcrbp->banks[0].len) ;
75  off = b2h32(emcrbp->banks[0].off) ;
76 
77  if((len==0) || (off==0)) return 0 ;
78 
79  struct DUMMYDATA *emcadc = (DUMMYDATA *) ((u_int *)emcrbp + off) ;
80 
81  if(checkBank(emcadc->bh.bank_type, hdrs[hdr_ix].adc)<0) return 0 ;
82 
83 
84  *bytes = l2h32(emcadc->bh.length)*4 - 40 ; // length is in words but includes the bankHeader of 40 bytes
85  return ((char *)emcadc + 40) ; // skip the 40 bytes bankHeader
86 }
87 
88 
89