/****** * * Example code to read raw data on little endian system * Note: You must supply a routine to byte swap integers * and shorts. (swapI and swapS in this example. These * are defined in a local (to trigger) trgUtil.h header. * Ask if you want a copy * * J.M. Nelson January 2009 * ************************************************************/ #include #include #include #include #include #include "trgDataDefs.h" #include "trgConfNum.h" #include "trgUtil.h" TriggerDataBlk *trgData; EvtDescData *evtDesc; L1_DSM_Data *L1_Data; TrgSumData *trgSum; FMSBlock *fms; QTBlock *qt; BELayerBlock *bc1; BEastBlock *bce; BWestBlock *bcw; int ix; int fd; int len; int err; int qtS=1580; int buff; TrgOfflen *tptr; int npre,npost; int bytecount; int formatversion_bytecount[2]; char cname[5]; int readEvent() { err = read(fd,formatversion_bytecount,8); /* First 2 words are format version and bytecount */ if (err <= 0 ) return -1; bytecount = swapI(formatversion_bytecount[1]); printf("Byte count: %d\n", bytecount); trgData = (TriggerDataBlk *) malloc(bytecount); /* Make some space */ trgData->FormatVersion = swapI(formatversion_bytecount[0]); /* Fill in format version and bytecount in first 2 words */ trgData->totalTriggerLength = bytecount; buff = (int) trgData; err = read(fd,&trgData->eventNumber,bytecount-8); /* Get the rest of the data */ printf("Bytes read: %d, version: 0x%x\n",err,trgData->FormatVersion); printf("Event number: %d\n",swapI(trgData->eventNumber)); evtDesc = (EvtDescData *) (buff + swapI(trgData->EventDesc_ofl.offset)); /* Point to the Event descriptor */ strncpy(cname,evtDesc->name,4); cname[4]=0; printf("Length of %s block is %d byte\n",cname,swapI(evtDesc->length)); printf("Token: %d, nPre: %d, nPost: %d\n",swapS(evtDesc->TrgToken),npre=swapS(evtDesc->npre),npost=swapS(evtDesc->npost)); /* Get the token */ L1_Data = (L1_DSM_Data *) (buff + swapI(trgData->L1_DSM_ofl.offset)); /* Point to L1 DSM data */ strncpy(cname,L1_Data->name,4); cname[4]=0; printf("Length of %s block is %d byte\n",cname,swapI(L1_Data->length)); printf("L1 Data: lastDSM array\n"); /* Print a few items */ for (ix=0; ix<8; ix++) { printf("%d ",swapS(L1_Data->lastDSM[ix])); } printf("\n"); trgSum = (TrgSumData *) (buff + swapI(trgData->Summary_ofl.offset)); /* Point to the trigger summary */ strncpy(cname,trgSum->name,4); cname[4]=0; printf("Length of %s block is %d byte\n",cname,swapI(trgSum->length)); printf("Summary: L1Sum and L2Sum\n"); for (ix=0; ix<4; ix++) { printf("%d ",swapI(trgSum->L1Sum[ix])); } printf("\n"); fms = (FMSBlock *) (buff + swapI(trgData->MainX[FMS_CONF_NUM].offset)); /* Now point to a data block, FMS */ if (swapI(trgData->MainX[FMS_CONF_NUM].length)) { strncpy(cname,fms->name,4); cname[4]=0; printf("Length of %s block is %d byte\n",cname,swapI(fms->length)); for (ix=0; ix<10; ix++) { printf("%d ",fms->FMS[ix]); } printf("\n"); } bc1 = (BELayerBlock *) (buff + swapI(trgData->MainX[BC1_CONF_NUM].offset)); /* Now point to a data block, BC1 */ if (swapI(trgData->MainX[BC1_CONF_NUM].length)) { strncpy(cname,bc1->name,4); cname[4]=0; printf("Length of %s block is %d byte\n",cname,swapI(bc1->length)); for (ix=0; ix<10; ix++) { printf("%d ",swapS(bc1->BEMClayer1[ix])); } printf("\n"); } bce = (BEastBlock *) (buff + swapI(trgData->MainX[BCE_CONF_NUM].offset)); /* Now point to a data block, BCE */ if (swapI(trgData->MainX[BCE_CONF_NUM].length)) { strncpy(cname,bce->name,4); cname[4]=0; printf("Length of %s block is %d byte\n",cname,swapI(bce->length)); for (ix=0; ix<10; ix++) { printf("%d ",bce->BEMCEast[ix]); } printf("\n"); } bcw = (BWestBlock *) (buff + swapI(trgData->MainX[BCW_CONF_NUM].offset)); /* Now point to a data block, BCW */ if (swapI(trgData->MainX[BCW_CONF_NUM].length)) { strncpy(cname,bcw->name,4); cname[4]=0; printf("Length of %s block is %d byte\n",cname,swapI(bcw->length)); for (ix=0; ix<10; ix++) { printf("%d ",bcw->BEMCWest[ix]); } printf("\n"); } qt = (QTBlock *) (buff + swapI(trgData->MainX[QT2_CONF_NUM].offset)); /* Or QT2 */ if ((len=swapI(trgData->MainX[QT2_CONF_NUM].length))) { strncpy(cname,qt->name,4); cname[4]=0; printf("Length of %s block is %d bytes and loss %d \n",cname,swapI(qt->length),swapI(qt->dataLoss)); for (ix=qtS/4; ixlength)/4; ) { printf("0x%8.8x ",swapI(qt->data[ix])); if (!(++ix % 8)) printf("\n"); } printf("\n"); } if (!npre && !npost) { /* No pre/post data */ free(trgData); return 0; } for (ix=0; ixPrePostList[ix]) { trgData->PrePostList[ix] = swapI(trgData->PrePostList[ix]) + buff; } } printf("Check names of pre/post FMS data: "); /* Now check that we reach the right blocks */ for (ix=0; ixPrePostList[ix]; if (!swapI(tptr[FMS_CONF_NUM].offset)) break; fms = (FMSBlock *) (buff + swapI(tptr[FMS_CONF_NUM].offset)); strncpy(cname,fms->name,4); cname[4] = 0; printf(" %s %d %d",cname,swapI(fms->length),fms->FMS[0]); } printf("\n"); printf("Check names of pre/post BC1 data: "); for (ix=0; ixPrePostList[ix]; if (!swapI(tptr[BC1_CONF_NUM].offset)) break; bc1 = (BELayerBlock *) (buff + swapI(tptr[BC1_CONF_NUM].offset)); strncpy(cname,bc1->name,4); cname[4] = 0; printf(" %s %d %d",cname,swapI(bc1->length),swapS(bc1->BEMClayer1[0])); } printf("\n"); free(trgData); return 0; } int main(int argc, char **argv) { int err; fd = open(argv[1],O_RDONLY); if (fd < 0) { printf("Could not open file %s\n",argv[1]); return 1; } if (argc == 3) { sscanf(argv[2],"%d",&qtS); } for (;;) { err = readEvent(); if (!err) { printf("\n\n"); continue; } break; } close(fd); return 0; }