/****** * * Example code to read raw data * * J.M. Nelson November 2008 * **************************************/ #include #include #include #include #include #include "trgDataDefs.h" #include "trgConfNum.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 = formatversion_bytecount[1]; printf("Byte count: %d\n", bytecount); trgData = (TriggerDataBlk *) malloc(bytecount); /* Make some space */ trgData->FormatVersion = 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",trgData->eventNumber); evtDesc = (EvtDescData *) (buff + 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,evtDesc->length); printf("Token: %d, nPre: %d, nPost: %d\n",evtDesc->TrgToken,npre=evtDesc->npre,npost=evtDesc->npost); /* Get the token */ L1_Data = (L1_DSM_Data *) (buff + 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,L1_Data->length); printf("L1 Data: lastDSM array\n"); /* Print a few items */ for (ix=0; ix<8; ix++) { printf("%d ",L1_Data->lastDSM[ix]); } printf("\n"); trgSum = (TrgSumData *) (buff + 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,trgSum->length); printf("Summary: L1Sum and L2Sum\n"); for (ix=0; ix<4; ix++) { printf("%d ",trgSum->L1Sum[ix]); } printf("\n"); fms = (FMSBlock *) (buff + trgData->MainX[FMS_CONF_NUM].offset); /* Now point to a data block, FMS */ if (trgData->MainX[FMS_CONF_NUM].length) { strncpy(cname,fms->name,4); cname[4]=0; printf("Length of %s block is %d byte\n",cname,fms->length); for (ix=0; ix<10; ix++) { printf("%d ",fms->FMS[ix]); } printf("\n"); } bc1 = (BELayerBlock *) (buff + trgData->MainX[BC1_CONF_NUM].offset); /* Now point to a data block, BC1 */ if (trgData->MainX[BC1_CONF_NUM].length) { strncpy(cname,bc1->name,4); cname[4]=0; printf("Length of %s block is %d byte\n",cname,bc1->length); for (ix=0; ix<10; ix++) { printf("%d ",bc1->BEMClayer1[ix]); } printf("\n"); } bce = (BEastBlock *) (buff + trgData->MainX[BCE_CONF_NUM].offset); /* Now point to a data block, BCE */ if (trgData->MainX[BCE_CONF_NUM].length) { strncpy(cname,bce->name,4); cname[4]=0; printf("Length of %s block is %d byte\n",cname,bce->length); for (ix=0; ix<10; ix++) { printf("%d ",bce->BEMCEast[ix]); } printf("\n"); } bcw = (BWestBlock *) (buff + trgData->MainX[BCW_CONF_NUM].offset); /* Now point to a data block, BCW */ if (trgData->MainX[BCW_CONF_NUM].length) { strncpy(cname,bcw->name,4); cname[4]=0; printf("Length of %s block is %d byte\n",cname,bcw->length); for (ix=0; ix<10; ix++) { printf("%d ",bcw->BEMCWest[ix]); } printf("\n"); } qt = (QTBlock *) (buff + trgData->MainX[QT2_CONF_NUM].offset); /* Or QT2 */ if ((len=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,qt->length,qt->dataLoss); for (ix=qtS/4; ixlength/4; ) { printf("0x%8.8x ",qt->data[ix]); if (!(++ix % 8)) printf("\n"); } printf("\n"); } qt = (QTBlock *) (buff + trgData->MainX[QT3_CONF_NUM].offset); /* Or QT3 */ if (trgData->MainX[QT3_CONF_NUM].length) { strncpy(cname,qt->name,4); cname[4]=0; printf("Length of %s block is %d bytes and loss %d \n",cname,qt->length,qt->dataLoss); for (ix=qtS/4; ixlength/4; ) { printf("0x%8.8x ",qt->data[ix]); if (!(++ix % 8)) printf("\n"); } printf("\n"); } qt = (QTBlock *) (buff + trgData->MainX[QT4_CONF_NUM].offset); /* Or QT4 */ if (trgData->MainX[QT4_CONF_NUM].length) { strncpy(cname,qt->name,4); cname[4]=0; printf("Length of %s block is %d bytes and loss %d \n",cname,qt->length,qt->dataLoss); for (ix=qtS/4; ixlength/4; ) { printf("0x%8.8x ",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] = (int) 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 (!tptr[FMS_CONF_NUM].offset) break; fms = (FMSBlock *) (buff + tptr[FMS_CONF_NUM].offset); strncpy(cname,fms->name,4); cname[4] = 0; printf(" %s %d %d",cname,fms->length,fms->FMS[0]); } printf("\n"); printf("Check names of pre/post BC1 data: "); for (ix=0; ixPrePostList[ix]; if (!tptr[BC1_CONF_NUM].offset) break; bc1 = (BELayerBlock *) (buff + tptr[BC1_CONF_NUM].offset); strncpy(cname,bc1->name,4); cname[4] = 0; printf(" %s %d %d",cname,bc1->length,bc1->BEMClayer1[0]); } printf("\n"); printf("Check names of pre/post BCE data: "); for (ix=0; ixPrePostList[ix]; if (!tptr[BCE_CONF_NUM].offset) break; bce = (BEastBlock *) (buff + tptr[BCE_CONF_NUM].offset); strncpy(cname,bce->name,4); cname[4] = 0; printf(" %s %d %d",cname,bce->length,bce->BEMCEast[0]); } printf("\n"); printf("Check names of pre/post BCW data: "); for (ix=0; ixPrePostList[ix]; if (!tptr[BCW_CONF_NUM].offset) break; bcw = (BWestBlock *) (buff + tptr[BCW_CONF_NUM].offset); strncpy(cname,bcw->name,4); cname[4] = 0; printf(" %s %d %d",cname,bcw->length,bcw->BEMCWest[0]); } printf("\n"); printf("Check names of pre/post QT2 data: "); for (ix=0; ixPrePostList[ix]; if (!tptr[QT2_CONF_NUM].offset) break; qt = (QTBlock *) (buff + tptr[QT2_CONF_NUM].offset); strncpy(cname,qt->name,4); cname[4] = 0; printf("%s\n",cname); for (ix=qtS/4; ixlength/4; ) { printf("0x%8.8x ",qt->data[ix]); if (!(++ix % 8)) printf("\n"); } } printf("\n"); printf("Check names of pre/post QT3 data: "); for (ix=0; ixPrePostList[ix]; if (!tptr[QT3_CONF_NUM].offset) break; qt = (QTBlock *) (buff + tptr[QT3_CONF_NUM].offset); strncpy(cname,qt->name,4); cname[4] = 0; printf("%s\n",cname); for (ix=qtS/4; ixlength/4; ) { printf("0x%8.8x ",qt->data[ix]); if (!(++ix % 8)) printf("\n"); } } printf("\n"); printf("Check names of pre/post QT4 data: "); for (ix=0; ixPrePostList[ix]; if (!tptr[QT3_CONF_NUM].offset) break; qt = (QTBlock *) (buff + tptr[QT4_CONF_NUM].offset); strncpy(cname,qt->name,4); cname[4] = 0; printf("%s\n",cname); for (ix=qtS/4; ixlength/4; ) { printf("0x%8.8x ",qt->data[ix]); if (!(++ix % 8)) printf("\n"); } } 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; }