00001 #define PP printf(
00002 #include <stdio.h>
00003 #include <unistd.h>
00004 #include <assert.h>
00005 #include <string.h>
00006 #include <arpa/inet.h>
00007
00008 #include "daqFormats.h"
00009 #include "rtsSystems.h"
00010
00011 #include "evpSupport.h"
00012 #include "scReader.h"
00013 #define SWAP32(bk,x) ((bk->bh.byte_order==0x4030201)?(bk->x):swap32(bk->x))
00014
00015 using namespace OLDEVP;
00016 namespace OLDEVP {
00017 struct sc_t sc;
00018 };
00019
00020
00021 int OLDEVP::scReader(char *m)
00022 {
00023 int len ;
00024 u_int off ;
00025 struct SCD *scd ;
00026 struct DATAP *datap ;
00027 struct DATAPX *datapx ;
00028
00029
00030 if(m == NULL) return EVP_DATA_ERR ;
00031
00032 datap = (struct DATAP *)m ;
00033
00034
00035 len = SWAP32(datap,det[EXT_ID].len) ;
00036 if(len == 0) return EVP_NO_DET;
00037 assert(len>0&&len<99999);
00038
00039 off = SWAP32(datap,det[EXT_ID].off);
00040 if(off == 0) return EVP_NO_DET;
00041
00042 datapx = (struct DATAPX *)((u_int *)m+off);
00043
00044
00045 assert(checkBank(datapx->bh.bank_type,CHAR_DATAPX) == 0);
00046
00047 len = SWAP32(datapx,det[SC_ID-10].len);
00048 if(len == 0) return EVP_NO_DET ;
00049
00050 off = SWAP32(datapx,det[SC_ID-10].off);
00051 if(off == 0) return EVP_NO_DET;
00052
00053
00054
00055 scd = (struct SCD *)(((u_int *)datapx)+off) ;
00056 if(checkBank((char *)scd,"SCD") < 0) assert(0);
00057
00058 if(scd->bh.token == 0) {
00059
00060 return EVP_NO_DET ;
00061 }
00062 int sz = SWAP32(scd,bh.length);
00063
00064 if((len != sz) ||
00065 ((u_int)len > sizeof(SCD))) {
00066
00067
00068
00069 return EVP_DATA_ERR;
00070 }
00071
00072
00073
00074 sc.time = SWAP32(scd,time);
00075 int mag = SWAP32(scd,mag_field);
00076 sc.mag_field= *((float*)&mag);
00077 for(int i=0;i<16;i++) {
00078 sc.rich_scalers[i] = SWAP32(scd,rich_scalers[i]);
00079 }
00080
00081 sc.timelag = SWAP32(datap,time) - sc.time;
00082
00083 int alag = sc.timelag > 0 ? sc.timelag : -sc.timelag;
00084
00085 if(alag > 5) sc.valid = 0;
00086 else sc.valid = 1;
00087
00088 return len;
00089 }
00090