7 #define TRG_VERSION 0x32
9 #include <daqFormats.h>
11 #include <rtsSystems.h>
17 extern int trgReader12(
char *trgd,
struct trg_t *trg) ;
18 extern int trgReader20(
char *trgd,
struct trg_t *trg) ;
19 extern int trgReader21(
char *trgd,
struct trg_t *trg) ;
20 extern int trgReader22(
char *trgd,
struct trg_t *trg) ;
21 extern int trgReader30(
char *trgd,
struct trg_t *trg);
22 extern int trgReader32(
char *trgd,
struct trg_t *trg);
23 extern int trgReader10(
char *trgd,
struct trg_t *trg);
27 char *trg_find_raw(
char *m,
int *bytes)
38 datap = (
struct DATAP *) m ;
41 if(datap->bh.byte_order != DAQ_RAW_FORMAT_ORDER) swapit = 1 ;
44 len = qswap32(swapit, datap->det[TRG_ID].len);
45 if(len == 0)
return 0 ;
48 off = qswap32(swapit, datap->det[TRG_ID].off);
49 if(off == 0)
return 0 ;
51 LOG(DBG,
"Trg raw len %d (0x%x), off %d(0x%x)",len,len,off,off,0) ;
53 trgp = (
struct TRGP *)((u_int *) m + off) ;
54 if(checkBank(trgp->bh.bank_type,
"TRGP") < 0) {
59 if(trgp->bh.byte_order != DAQ_RAW_FORMAT_ORDER) swapit = 1 ;
62 if(trgp->trgData.len == 0)
return 0 ;
63 if(trgp->trgData.off == 0)
return 0 ;
65 off = qswap32(swapit, trgp->trgData.off);
67 trgd = (
struct TRGD *) ((u_int *)trgp + off) ;
71 if(trgd->bh.byte_order != DAQ_RAW_FORMAT_ORDER) swapit = 1;
74 if(checkBank(trgd->bh.bank_type,
"TRGD") < 0) {
78 len = qswap32(swapit, trgd->bh.length) ;
84 LOG(DBG,
"Returning pointer to raw trigger data of %d bytes", *bytes) ;
86 return (
char *) &(trgd->desc) ;
91 int trg_reader(
char *m,
struct trg_t *trg, u_int driver, u_int evp_daqbits)
105 memset(trg,0,
sizeof(
trg_t)) ;
108 trg->max_channels = 240 * 128 * 6 ;
113 trg->daqbits = evp_daqbits;
115 if(m == NULL)
return 0 ;
117 datap = (
struct DATAP *) m ;
118 if(datap->bh.byte_order != DAQ_RAW_FORMAT_ORDER)
122 len = qswap32(swapdatap, datap->det[TRG_ID].len);
123 if(len == 0)
return 0 ;
126 off = qswap32(swapdatap, datap->det[TRG_ID].off);
127 if(off == 0)
return 0 ;
129 LOG(DBG,
"Trg raw len %d (0x%x), off %d(0x%x)",len,len,off,off,0) ;
131 trgp = (
struct TRGP *)((u_int *)m+off) ;
132 if(checkBank(trgp->bh.bank_type,
"TRGP") < 0) {
136 if(trgp->bh.byte_order != DAQ_RAW_FORMAT_ORDER)
139 if(trgp->bh.token == 0) {
140 LOG(ERR,
"Token 0 - skipping...",0,0,0,0,0) ;
145 trgp_banks = qswap32(swaptrgp, trgp->bh.length);
147 trgp_banks = (trgp_banks - 10)/2 ;
150 LOG(DBG,
"TRGP bytes %d, TRGD off:len 0x%X:%d (banks %d)",
151 qswap32(swaptrgp, trgp->bh.length)*4,
152 qswap32(swaptrgp, trgp->trgData.off),
153 qswap32(swaptrgp, trgp->trgData.len),
157 if(trgp_banks >= 2) {
158 if(trgp->trgId.len && trgp->trgId.off) {
159 int off = qswap32(swaptrgp, trgp->trgId.off);
160 struct TRGID *trgid = (
struct TRGID *)((
char *)trgp + 4*off) ;
162 if(trgid->bh.byte_order != DAQ_RAW_FORMAT_ORDER) swaptrgid = 1;
164 if(checkBank(trgid->bh.bank_type,CHAR_TRGID) >= 0) {
168 if(evp_daqbits & (1 << i)) {
169 LOG(DBG,
"TRGID %d: bit %2d is 0x%02X [%u dec]",i,i,
170 qswap32(swaptrgid, trgid->triggerId[i]),
171 qswap32(swaptrgid, trgid->triggerId[i]), 0);
172 trg->offline_id[i] = qswap32(swaptrgid, trgid->triggerId[i]);
180 if(trgp->trgData.len == 0)
return 0 ;
181 if(trgp->trgData.off == 0)
return 0 ;
183 off = qswap32(swaptrgp, trgp->trgData.off);
184 trgd = (
struct TRGD *) ((
char *)trgp + 4*off) ;
186 if(trgd->bh.byte_order != DAQ_RAW_FORMAT_ORDER) swaptrgd = 1;
189 if(checkBank(trgd->bh.bank_type,
"TRGD") < 0) {
193 LOG(DBG,
"TRGD len %d",
194 qswap32(swaptrgd, trgd->bh.length),0,0,0) ;
196 if(qswap32(swaptrgd, trgd->bh.length) == 10)
return 0 ;
199 trg->trgc = (u_char *) trgd ;
201 u_char trg_version = trgd->desc.TrgDataFmtVer ;
204 switch(trg_version) {
207 LOG(NOTE,
"TRG: version 0x%02X supported...",trg_version,0,0,0,0) ;
208 trgReader12((
char *)trgd, trg) ;
211 LOG(NOTE,
"TRG: version 0x%02X supported...",trg_version,0,0,0,0) ;
212 trgReader20((
char *)trgd, trg) ;
215 LOG(NOTE,
"TRG: version 0x%02X supported...",trg_version,0,0,0,0) ;
216 trgReader21((
char *)trgd, trg) ;
219 LOG(NOTE,
"TRG: version 0x%02X supported...",trg_version,0,0,0,0) ;
220 trgReader22((
char *)trgd, trg) ;
224 LOG(NOTE,
"TRG: version 0x%02X supported", trg_version,0,0,0,0);
225 trgReader30((
char *)trgd, trg);
229 LOG(NOTE,
"TRG: version 0x%02X supported, ", trg_version, 0,0,0,0);
231 trgReader10((
char *)trgd,trg);
235 LOG(ERR,
"Can't read Trigger Format Version 0x%02X!",trg_version,0,0,0,0) ;