13 #include "L2BinEvent.h"
17 L2BinEvent::L2BinEvent() {
24 L2BinEvent::read(
struct BinEveContainer* eve,FILE *fd,
int dbg){
29 memset(eve->lenA,0,
sizeof(eve->lenA));
30 memset(eve->mHEAD,
':',
sizeof(eve->mHEAD));
31 memset(eve->mBTOW_BANK,0,
sizeof(eve->mBTOW_BANK));
32 memset(eve->mETOW_BANK,0,
sizeof(eve->mETOW_BANK));
33 memset(eve->mTrigData ,0,
sizeof(eve->mTrigData));
34 eve->mBTOW_in=eve->mETOW_in=0;
40 for(i=0;i<
sizeof(eve->lenA);i++) c[i]=fgetc(fd);
41 if(dbg)
for(i=0;i<4;i++) printf(
"lenA[%d]=%d\n",i,eve->lenA[i]);
44 if(eve->lenA[0]>
sizeof(eve->mHEAD))
return -10;
45 if(eve->lenA[1]>
sizeof(eve-> mTrigData))
return -11;
46 if(eve->lenA[2]>
sizeof(eve->mBTOW_BANK))
return -12;
47 if(eve->lenA[3]>
sizeof(eve->mETOW_BANK))
return -13;
51 for(i=0;i<eve->lenA[0];i++) c[i]=fgetc(fd);
53 c=(
char *)eve->mTrigData;
54 for(i=0;i<eve->lenA[1];i++) c[i]=fgetc(fd);
56 c=(
char *)eve->mBTOW_BANK;
57 for(i=0;i<eve->lenA[2];i++) c[i]=fgetc(fd);
59 c=(
char *)eve->mETOW_BANK;
60 for(i=0;i<eve->lenA[3];i++) c[i]=fgetc(fd);
64 for(i=0;i<4;i++) EOE[i]=fgetc(fd);
66 if(!strstr(EOE,
"EofE"))
return -1;
67 assert(strstr(EOE,
"EofE"));
69 eve->mBTOW_in=eve->lenA[2]>0;
70 eve->mETOW_in=eve->lenA[3]>0;
72 if(dbg) printf(
"head='%s'\nBTOW_in=%d, ETOW_in=%d \n",eve->mHEAD,eve->mBTOW_in,eve->mETOW_in);
80 L2BinEvent::write(
char* headText,
int trgLen,
void * trgData,
81 int bemcLen,
unsigned short *bemcData,
82 int eemcLen,
unsigned short *eemcData,
90 eve.lenA[0]=
sizeof(eve.mHEAD);
98 const char *c=(
char*)eve.lenA;
99 for(i=0;i<
sizeof(eve.lenA);i++) fputc(c[i],binFd);
102 for(i=0;i<eve.lenA[0];i++) fputc(c[i],binFd);
105 for(i=0;i<eve.lenA[1];i++) fputc(c[i],binFd);
108 for(i=0;i< eve.lenA[2];i++) fputc(c[i],binFd);
111 for(i=0;i<eve.lenA[3];i++) fputc(c[i],binFd);
114 for(i=0;i<4;i++) fputc(c[i],binFd);