daq_bin2dump.c File Reference

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "OnlineUtil/msgLogLib/msgLog.h"
#include <time.h>
#include <sys/time.h>
#include "OnlineUtil/rototalk.h"
#include "OnlineUtil/rdChecksum.h"

Go to the source code of this file.

Defines

#define MAXBUFFER   8388608

Enumerations

enum  MinosOnlineEntities {
  MINOS_MBRP = 0x01, MINOS_BRP0 = 0x11, MINOS_BRP1, MINOS_BRP2,
  MINOS_BRP3, MINOS_BRP4, MINOS_BRP5, MINOS_ROP0 = 0x20,
  MINOS_ROP1, MINOS_ROP2, MINOS_ROP3, MINOS_ROP4,
  MINOS_ROP5, MINOS_ROP6, MINOS_ROP7, MINOS_ROP8,
  MINOS_ROP9, MINOS_ROPA, MINOS_ROPB, MINOS_ROPC,
  MINOS_ROPD, MINOS_ROPE, MINOS_ROPF, MINOS_ROP10,
  MINOS_ROP11, MINOS_TRP0 = 0x40, MINOS_TRP1, MINOS_TRP2,
  MINOS_TRP3, MINOS_TRP4, MINOS_TRP5, MINOS_TRP6,
  MINOS_TRP7, MINOS_TRP8, MINOS_TRP9, MINOS_TRPA,
  MINOS_TRPB, MINOS_TRPC, MINOS_TRPD, MINOS_TRPE,
  MINOS_TRPF, MINOS_FPC = 0x60, MINOS_TPC, MINOS_DDS,
  MINOS_DCP, MINOS_DCS, MINOS_TRIGGER, MINOS_ROOTER,
  MINOS_SPILLSERVER, MINOS_QUASI_ONLINE = 0x70, MINOS_ONLINE_MONITORING, MINOS_ONLINE_DBU,
  MINOS_ONLINE_EVENT_DISPLAY, MINOS_RC, MINOS_DAQ_GLOBAL, MINOS_RC_MASTER_GUI,
  MINOS_RC_MONITOR_GUI, MINOS_RC_GUIS, MINOS_UNIDENTIFIED_CLIENT, END_OF_MINOS_DAQ_ENTITIES,
  MINOS_DCP = 0x63, MINOS_DCS = 0x64, MINOS_ROOTER = 0x66, MINOS_UNIDENTIFIED_CLIENT = 0x79
}

Functions

int32_t dump_whole_file (const char *fname, int32_t *buffer, int32_t bsize, int32_t mxrec, int32_t nooutrec)
int32_t dump_one_record (const char *fname, int32_t nrecord, int32_t *buffer, int32_t nbytes, char *time_buff)
const char * blockname (int32_t rbid, int32_t *blkisheader)
int main (int argc, char **argv)

Variables

char blkname [1000]

Define Documentation

#define MAXBUFFER   8388608

Definition at line 30 of file daq_bin2dump.c.


Enumeration Type Documentation

Enumerator:
MINOS_MBRP 
MINOS_BRP0 
MINOS_BRP1 
MINOS_BRP2 
MINOS_BRP3 
MINOS_BRP4 
MINOS_BRP5 
MINOS_ROP0 
MINOS_ROP1 
MINOS_ROP2 
MINOS_ROP3 
MINOS_ROP4 
MINOS_ROP5 
MINOS_ROP6 
MINOS_ROP7 
MINOS_ROP8 
MINOS_ROP9 
MINOS_ROPA 
MINOS_ROPB 
MINOS_ROPC 
MINOS_ROPD 
MINOS_ROPE 
MINOS_ROPF 
MINOS_ROP10 
MINOS_ROP11 
MINOS_TRP0 
MINOS_TRP1 
MINOS_TRP2 
MINOS_TRP3 
MINOS_TRP4 
MINOS_TRP5 
MINOS_TRP6 
MINOS_TRP7 
MINOS_TRP8 
MINOS_TRP9 
MINOS_TRPA 
MINOS_TRPB 
MINOS_TRPC 
MINOS_TRPD 
MINOS_TRPE 
MINOS_TRPF 
MINOS_FPC 
MINOS_TPC 
MINOS_DDS 
MINOS_DCP 
MINOS_DCS 
MINOS_TRIGGER 
MINOS_ROOTER 
MINOS_SPILLSERVER 
MINOS_QUASI_ONLINE 
MINOS_ONLINE_MONITORING 
MINOS_ONLINE_DBU 
MINOS_ONLINE_EVENT_DISPLAY 
MINOS_RC 
MINOS_DAQ_GLOBAL 
MINOS_RC_MASTER_GUI 
MINOS_RC_MONITOR_GUI 
MINOS_RC_GUIS 
MINOS_UNIDENTIFIED_CLIENT 
END_OF_MINOS_DAQ_ENTITIES 
MINOS_DCP 
MINOS_DCS 
MINOS_ROOTER 
MINOS_UNIDENTIFIED_CLIENT 

Definition at line 33 of file daq_bin2dump.c.

00033                          {
00034    MINOS_DCP = 0x63,
00035    MINOS_DCS = 0x64,
00036    MINOS_ROOTER = 0x66,
00037    MINOS_UNIDENTIFIED_CLIENT = 0x79
00038 };


Function Documentation

const char * blockname ( int32_t  rbid,
int32_t *  blkisheader 
)

Definition at line 350 of file daq_bin2dump.c.

References blkname, and det.

Referenced by dump_one_record().

00351 {
00352   int minor  =  rbid      & 0xFF;
00353   int major  = (rbid>> 8) & 0xFFFF;
00354   int daqdcs = (rbid>>24) & 1;
00355   int det    = (rbid>>25) & 0x7;
00356   int cmpsim = (rbid>>28) & 0x3;
00357 
00358   const char* majorname = "UnknownBlock";
00359   const char* isdcs     = "DAQ";
00360   const char* detname   = "?Det";
00361   const char* sfname    = "?Data";
00362 
00363   *blkisheader = 0;
00364 
00365   if (!daqdcs) {
00366     isdcs = "DAQ";
00367     switch (major) {
00368     case 0x101: majorname = "SnarlHeader"; *blkisheader = 1; break;
00369     case 0x102: majorname = "CrateReadout"; break;
00370     case 0x103: majorname = "TdcRaw"; break;
00371     case 0x104: majorname = "TofReadout"; break;
00372       
00373     case 0x200: majorname = "MonitorHeader"; *blkisheader = 1; break;
00374     case 0x201: majorname = "PedestalTable"; break;
00375     case 0x202: majorname = "ChargeInjectInfo"; break;
00376     case 0x203: majorname = "VarcErrorInTf"; break;
00377     case 0x204: majorname = "SparsifierTable"; break;
00378     case 0x205: majorname = "CrateMonitor"; break;
00379     case 0x206: majorname = "TrcMonitor"; break;
00380     case 0x207: majorname = "VaTimingMonitor"; break;
00381     case 0x208: majorname = "SpillServerMonitor"; break;
00382       
00383     case 0x301: majorname = "TpSummarySingles"; break;
00384     case 0x302: majorname = "LiSummaryAdc"; break;
00385     case 0x303: majorname = "LiSummaryTiming"; break;
00386     case 0x304: majorname = "DaqDadTime"; break;
00387     case 0x305: majorname = "LiTpmtDigits"; break;
00388       
00389     case 0x401: majorname = "RunStart"; break;
00390     case 0x402: majorname = "RunEnd"; break;
00391     case 0x403: majorname = "RunComment"; break;
00392     case 0x404: majorname = "TriggerStats"; break;
00393     case 0x405: majorname = "ErrorStats"; break;
00394     case 0x406: majorname = "SubRunEnd"; break;
00395       
00396     case 0x501: majorname = "ConfigRunPrepare"; break;
00397     case 0x502: majorname = "ConfigFiles"; break;
00398       
00399     case 0x601: majorname = "QieData"; break;
00400     case 0x602: majorname = "LinearizedData"; break;
00401     case 0x603: majorname = "QieCalibrationData"; break;
00402     case 0x604: majorname = "CurrentInjectData"; break;
00403     case 0x605: majorname = "CalibrationFits"; break;
00404     case 0x606: majorname = "NDErrorBlock"; break;
00405     case 0x607: majorname = "VtmTimeInfo"; break;
00406     case 0x608: majorname = "LookUpTable"; break;
00407       
00408     case 0xf00: majorname = "VaDeadChips"; break;
00409     case 0xf01: majorname = "VaOvershoot"; break;
00410     }
00411   }
00412   else {
00413     isdcs = "DCS";
00414     switch (major) {
00415     case 0x001: majorname = "DcsHeader"; *blkisheader = 1; break;
00416 
00417     case 0x100: majorname = "DcsAlarm"; break;
00418     case 0x200: majorname = "DcsMonitor"; break;
00419 
00420     case 0x201: majorname = "DcsHvMonitor"; break;
00421     case 0x202: majorname = "DcsRpsMonitor"; break;
00422     case 0x203: majorname = "DcsMagnetMonitor"; break;
00423     case 0x204: majorname = "DcsEnvMonitor"; break;
00424     case 0x205: majorname = "DcsChillerMonitor"; break;
00425     case 0x206: majorname = "DcsUpsMonitor"; break;
00426     case 0x207: majorname = "DcsCanMonitor"; break;
00427 
00428     case 0x310: majorname = "BeamMonHeader"; *blkisheader = 1; break;
00429     case 0x311: majorname = "BeamMonPayload"; break;
00430     }
00431   }
00432   
00433   switch (det) {
00434   case 1: detname = "Near"; break;
00435   case 2: detname = "Far"; break;
00436   case 4: detname = "CalDet"; break;
00437   }
00438 
00439   switch (cmpsim) {
00440   case 0: sfname = "Data"; break;
00441   case 1: sfname = "DaqFakeData"; break;
00442   case 2: sfname = "MC"; break;
00443   case 3: sfname = "Reroot"; break;
00444   }
00445 
00446   sprintf(blkname,"%3s:%s;%3.3d(%s+%s)",isdcs,majorname,minor,detname,sfname);
00447 
00448   return blkname;
00449 }

int dump_one_record ( const char *  fname,
int32_t  nrecord,
int32_t *  buffer,
int32_t  nbytes,
char *  time_buff 
)

Definition at line 264 of file daq_bin2dump.c.

References blockname(), rdxsum_calc(), and rdxsum_test().

Referenced by dump_whole_file().

00266 {
00267   int32_t nlong = nbytes/sizeof(int32_t);
00268   int32_t i, inblk, blksiz, nblk;
00269   int32_t blkisheader, subrun, runtype, xsumdiff = 0;
00270 
00271   time_t sec;
00272   struct tm *ptm;
00273   const char* ISO8601Z = "%Y-%m-%d %H:%M:%SZ";
00274   char fmttime[100];
00275   uint32_t xsumcalc = 0;
00276   const int32_t* blkstart = 0;
00277 
00278   printf("Record %d in file %s - data %d bytes (%d long words)\n",
00279          nrecord,fname,nbytes,nlong);
00280 
00281   nblk = blksiz = inblk = i = -1;
00282 
00283   while ( 1 ) {
00284     i++;
00285     if (i == nlong ) break;
00286 
00287     inblk++;
00288     printf("0x%04x: 0x%08x",i,buffer[i]);
00289     
00290     if (inblk == blksiz) inblk = 0;
00291     
00292     if (inblk == 0) {
00293       /* start of new block */
00294       nblk++;
00295       blksiz = buffer[i];
00296       printf(" size %d (start of block %d)",blksiz,nblk);
00297       blkstart = buffer + i;
00298       /* note rdxsum_test returns non-zero if there was a mismatch */
00299       xsumdiff = rdxsum_test(buffer+i);
00300       xsumcalc = rdxsum_calc(blkstart,(blkstart[1]>>30)&0x3);
00301     }
00302     else if (inblk == 1) {
00303       printf(" checksum %s",((xsumdiff)?"failed":"ok"));
00304       if (xsumdiff) printf(", calc 0x%08x",xsumcalc);
00305     }
00306     else if (inblk == 2) {
00307       printf(" blockid %s",blockname(buffer[i],&blkisheader));
00308     }
00309     else if (blkisheader) {
00310       if      (inblk == 3) printf(" run %d",buffer[i]);
00311       else if (inblk == 4) {
00312         subrun  = (buffer[i]>>16) & 0xFFFF;
00313         runtype =  buffer[i]      & 0xFFFF;
00314         printf(" subrun %d runtype %d",subrun,runtype);
00315         
00316       }
00317       else if (inblk == 5) {
00318         sec = buffer[i];
00319         ptm = gmtime(&sec);
00320         strftime(fmttime,sizeof(fmttime),ISO8601Z,ptm);
00321         printf(" %s",fmttime);
00322         sprintf(time_buff," %s 0.%9.9ds",fmttime,buffer[i+1]);
00323       }
00324       else if (inblk == 6) printf(" 0.%9.9ds",buffer[i]);
00325     }
00326 
00327     printf("\n");
00328       
00329   } /* while still within record length */
00330 
00331   return 0;
00332 }

int32_t dump_whole_file ( const char *  fname,
int32_t *  buffer,
int32_t  bsize,
int32_t  mxrec,
int32_t  nooutrec 
)

Definition at line 156 of file daq_bin2dump.c.

References dump_one_record(), and size.

Referenced by main().

00158 {
00159 
00160    FILE* file;
00161    int32_t  size;
00162    int32_t   nRecords=0;
00163    int32_t   nbytes;
00164    char  time_first[100];
00165    char  time_last[100];
00166    char  *time_buff = time_first;
00167 
00168    int32_t nerr = 0;
00169 
00170    nerr = 0;
00171 
00172    file=fopen(fname,"rb");
00173    if (file==NULL) {
00174       printf("Failed to open input file: '%s'\n",fname);
00175       return 1;
00176    }
00177 
00178 /*
00179  * NB These binary files are a temporary measure
00180  *    ROOT files will replace them soon
00181  *
00182  * Format is
00183  * [#bytes in record] [record data]
00184  * [#bytes in record] [record data]
00185  * and so on
00186  *
00187  * The record data contains the 'data' DAQ blocks
00188  * : TP singles summary
00189  * : Snarl header
00190  * : Crate Readout
00191  * - identify them by their block ID. 
00192  *
00193  * You may find others that are of no interest so branch on block ID
00194  *
00195  * See http://hepunx.rl.ac.uk/minos/daq/data-format/blocks/tp-singles.html
00196  * See http://hepunx.rl.ac.uk/minos/daq/data-format/blocks/snarl-header.html
00197  * See http://hepunx.rl.ac.uk/minos/daq/data-format/blocks/crate-readout.html
00198  *
00199  */
00200 
00201    while(!feof(file)){
00202       if (mxrec>0 && nRecords==mxrec) break;
00203       if (fread(&size,sizeof(int32_t),1,file)==1) {
00204          nRecords++;
00205          nbytes = size-sizeof(int32_t);  /* byte count is inclusive */
00206          if (nbytes>bsize) {
00207             printf("Record %d Size %d bytes too large for buffer (%d)\n",
00208                    nRecords,nbytes,bsize);
00209             printf("Skip the rest of '%s'\n",fname);
00210             break;
00211          }
00212 #ifdef OLDDUMPALL
00213          printf("Record %d Size = %d bytes (0x%03x words follow)\n",
00214                 nRecords,size,(size-sizeof(int32_t))/sizeof(int32_t));
00215 #endif
00216          if (fread(buffer,nbytes,1,file)==1) {
00217            if ( nRecords>nooutrec || nRecords==1 ) 
00218              nerr += dump_one_record(fname,nRecords,buffer,nbytes,time_buff);
00219            time_buff = time_last;
00220 #ifdef OLDDUMPALL
00221          /* this is the old "dump" code */
00222             for (i=0;i<(size-4)/sizeof(int32_t);i++) {
00223                printf("0x%03x: 0x%08lx\n",i,buffer[i]);
00224             }
00225 #endif
00226          }
00227          else {
00228            printf("Failed to read record %d size %d bytes\n",
00229                   nRecords,size);
00230            nerr++;
00231          }
00232       }
00233    }
00234 
00235    /* done: */
00236    fclose(file);
00237 
00238    printf("first time seen: %s\n",time_first);
00239    printf("last  time seen: %s (%d records)\n",time_last,nRecords);
00240 
00241    return nerr;
00242 }

int main ( int  argc,
char **  argv 
)

Definition at line 61 of file daq_bin2dump.c.

References dump_whole_file(), exit(), logDebugLevelSet(), MAXBUFFER, msgLogCleanup(), msgLogInit(), msgLogLocalEchoSet(), msgLogNodeIdSet(), and roto_verbose.

00062 {
00063 
00064    /* this is C ... all declarations must come first */
00065    int32_t bsize = MAXBUFFER;
00066    int32_t* buffer = 0;
00067    int32_t nerr = 0;
00068    int32_t mxrec = 0;
00069    int32_t nooutrec = 0;
00070    int32_t whoami = 0xFF;
00071    int32_t echoMsgLog = 0;
00072    int32_t copt;
00073 
00074    /*
00075     * parse the options and filenames
00076     * -i and -p take args
00077     */
00078    while ((copt = getopt(argc, argv, "b:ev:n:N:h")) != EOF) {
00079       switch (copt) {
00080       case 'b':  /* buffer size */
00081          bsize = atoi(optarg);
00082          break;
00083       case 'e':  /* msgLog messages to stdout as well */
00084          echoMsgLog = 1;
00085          break;
00086       case 'v':  /* verbosity */
00087          roto_verbose = atoi(optarg);
00088          break;
00089       case 'n':  /* maximum number of records */
00090          mxrec = atoi(optarg);
00091          break;
00092       case 'N':  /* maximum number of records */
00093          nooutrec = atoi(optarg);
00094          break;
00095       case 'h':  /* help */
00096          printf(" usage: %s -i<hostname> -b<buffer size> -w<whoami> -p<port #> <filenames..>\n", argv[0]);
00097          printf("   -b: buffer size to use\n");
00098          printf("   -v: how verbose to be\n");
00099          printf("   -n: maximum number of records from each file\n");
00100          printf("   -N: don't output first N records\n");
00101          printf("   -h: print this message\n");
00102          exit(1);
00103       default:
00104          printf(" unrecognized option '%c' ignored\n",(char)optopt);
00105          break;
00106       }
00107    }
00108 
00109    msgLogInit(argv[0]);
00110    msgLogNodeIdSet(whoami);
00111    msgLogLocalEchoSet(echoMsgLog);
00112    logDebugLevelSet(3);
00113    /* logNotice("starting %s",argv[0]); */
00114 
00115    /* allocate a buffer to use */
00116    buffer = (int32_t*) malloc(bsize);
00117    if (!buffer) {
00118       printf("failed to allocate buffer of size %d\n",bsize);
00119       exit(1);
00120    }
00121    if (roto_verbose>1) printf("allocated buffer of size %d\n",bsize);
00122 
00123    /* process each file in turn */
00124    while (optind < argc) {
00125       nerr += dump_whole_file(argv[optind++],buffer,bsize,mxrec,nooutrec);
00126    }   
00127 
00128    /* set my buffer free */
00129    free(buffer);
00130 
00131    /* logNotice("stopping %s",argv[0]); */
00132    msgLogCleanup();
00133 
00134    exit(nerr);
00135 }


Variable Documentation

char blkname[1000]

Generated on 21 Jun 2018 for loon by  doxygen 1.6.1