StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ric_reader.cxx
1 #include <stdio.h>
2 #include <string.h>
3 #include <arpa/inet.h>
4 
5 #include <rtsLog.h>
6 #include <rtsSystems.h>
7 #include <daqFormats.h>
8 #include <rts.h>
9 
10 #include "daq_ric.h"
11 
12 
13 int ric_reader(char *m, struct ric_t *ric, u_int driver)
14 {
15  struct DATAP *datap = (struct DATAP *)m ;
16  struct RICP *ricp ;
17  struct RICCRAMP *riccramp ;
18  struct RICDATAD *ricdatad ;
19 
20  int len, off ;
21 
22  ric->mode = 1 ;
23  ric->max_channels = 16*960 ;
24  ric->channels = 0 ;
25 
26  if(datap == NULL) return 0 ;
27 
28  len = ntohl(datap->det[RIC_ID].len) * 4 ;
29  if(len == 0) return 0 ;
30 
31  off = ntohl(datap->det[RIC_ID].off) ;
32  if(off == 0) return 0 ;
33 
34 
35  LOG(DBG,"RIC len %d, off %d",len,off,0,0,0) ;
36 
37  ricp = (struct RICP *)((u_int *)m + off) ;
38 
39  if(checkBank(ricp->bh.bank_type,CHAR_RICP) < 0) {
40  return -1 ;
41  }
42 
43 #define RUN_ME
44 #ifdef RUN_ME
45 
46  memset(ric->adc,0,sizeof(ric->adc)) ;
47 
48 
49  int cram ;
50 
51  for(cram=0;cram<16;cram++) {
52  int banks ;
53 
54  if(ricp->crams[cram].len <= 0) continue ;
55 
56  riccramp = (struct RICCRAMP *)((u_int *)ricp + b2h32(ricp->crams[cram].off)) ;
57 
58  if(checkBank(riccramp->bh.bank_type,CHAR_RICCRAMP) < 0) {
59  return -1 ;
60  }
61 
62  for(banks=0;banks<8;banks++) {
63  u_int cou ;
64  u_int i ;
65 
66  if(riccramp->banks[banks].len <= 0) continue ;
67 
68  if(banks != RIC_BANK_DATAD) {
69  LOG(DBG,"Found non-DATAD bank %d - skipping...",banks,0,0,0,0) ;
70  continue ;
71  }
72 
73 
74 
75  ricdatad = (struct RICDATAD *)((u_int *)riccramp + b2h32(riccramp->banks[banks].off)) ;
76 
77 
78  LOG(DBG,"Bank id is %d...",banks,0,0,0,0) ;
79 
80  if(checkBank(ricdatad->bh.bank_type,CHAR_RICDATAD) < 0) {
81  return -1 ;
82  }
83 
84 
85  cou = b2h32(ricdatad->bh.length) - sizeof(struct bankHeader)/4 ;
86 
87  LOG(DBG,"RICH bank %d, CRAM %d has %d entries...",banks,cram,cou,0,0) ;
88 
89  if(cou == 0) continue ;
90 
91 
92  for(i=0;i<cou*2;i+=2) {
93  u_short adc, ch ;
94 
95  ch = b2h16(ricdatad->data[i]) ;
96  adc = b2h16(ricdatad->data[i+1]) ;
97 
98  if(adc > 1023) adc = 1023 ;
99 
100  if(adc == 0) continue ;
101 
102  // sanity
103  if(ch >= 960) {
104  LOG(ERR,"RICH channel %d >= 960!",ch,0,0,0,0) ;
105  return -1 ;
106  }
107 
108  ric->adc[cram][ch] = adc ;
109 
110  ric->channels++ ;
111  }
112 
113  }
114 
115  }
116 
117 
118 #endif
119  return len ;
120 
121 }
122 
Definition: daq_ric.h:8