bogus_beammon.c File Reference

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

Go to the source code of this file.

Defines

#define MAXBUFFER   8388608

Functions

int32_t send_bogus_stuff (int32_t *buffer, int32_t bsize, int32_t mxrec)
int32_t config_autosave (const char *config)
int32_t config_compress (const char *config)
int32_t config_basketsize (const char *config)
int32_t build_beammon_blockid (int32_t major)
int main (int argc, char **argv)

Define Documentation

#define MAXBUFFER   8388608

Definition at line 32 of file bogus_beammon.c.


Function Documentation

int32_t build_beammon_blockid ( int32_t  major  ) 

Definition at line 480 of file bogus_beammon.c.

References maskRawBlkIdCSimFlag, maskRawBlkIdDetector, maskRawBlkIdIsDCS, maskRawBlkIdMajor, maskRawBlkIdMinor, shiftRawBlkIdCSimFlag, shiftRawBlkIdDetector, shiftRawBlkIdMajor, and shiftRawBlkIdMinor.

Referenced by send_bogus_stuff().

00481 {
00482    const int32_t  shiftRawBlkIdMinor    =  0;
00483    const int32_t  shiftRawBlkIdMajor    =  8;
00484    const int32_t  shiftRawBlkIdDetector = 25;
00485    const int32_t  shiftRawBlkIdCSimFlag = 28;
00486    
00487    const int32_t  maskRawBlkIdMinor     = 0x000000ff;
00488    const int32_t  maskRawBlkIdMajor     = 0x00ffff00;
00489    const int32_t  maskRawBlkIdIsDCS     = 0x01000000;
00490    const int32_t  maskRawBlkIdDetector  = 0x0e000000;
00491    const int32_t  maskRawBlkIdCSimFlag  = 0x30000000;
00492 
00493    int32_t cmptSimFlag = 1;  /* compact simflag for DaqFakeData */
00494    int32_t isDCS = 1;
00495    int32_t minor = 0;
00496    int32_t detector = 0;
00497 
00498    return
00499       ((cmptSimFlag << shiftRawBlkIdCSimFlag) & maskRawBlkIdCSimFlag) |
00500       ((   detector << shiftRawBlkIdDetector) & maskRawBlkIdDetector) |
00501       ((isDCS) ? maskRawBlkIdIsDCS : 0)                               |
00502       ((         major << shiftRawBlkIdMajor) & maskRawBlkIdMajor)    |
00503       ((         minor << shiftRawBlkIdMinor) & maskRawBlkIdMinor);
00504 
00505 }

int32_t config_autosave ( const char *  config  ) 

Definition at line 308 of file bogus_beammon.c.

References len, logInfo(), roto_send_autosave_config(), and rototalk_err_badconfig.

00309 {
00310    int32_t nerr = 0;
00311    int32_t len = strlen(config);
00312    char *wcopy = (char*)malloc(len+1);  /* a writable copy of config string */
00313    char stream[1024];
00314    const char *p1;
00315    char *p2;
00316    char achar;
00317    int32_t nrec,nsec, nitems;
00318 
00319    /* make a copy, replacing all the commas with blanks*/
00320    p1 = config; p2 = wcopy;
00321    while (p2 < wcopy+len) {
00322       achar = *p1;
00323       if (achar != ',') *p2 = achar;
00324       else              *p2 = ' ';
00325       p1++; p2++;
00326    }
00327 
00328    p2 = wcopy;
00329    while (p2  < wcopy+len) {
00330       nitems = sscanf(p2,"%s %d %d",stream,&nrec,&nsec);
00331       if (nitems != 3) {
00332          logInfo("config_autosave: only %d items from \"%s\"\n",nitems,p2);
00333          nerr += rototalk_err_badconfig;
00334       }
00335       else 
00336          nerr += roto_send_autosave_config(stream,nrec,nsec);
00337 
00338       p2 = strchr(p2,';'); /* move to the semicolon         */
00339       if (!p2) break;      /* in case of no final semicolon */
00340       p2++;                /* start just beyond semicolon   */
00341    }
00342 
00343 
00344    free(wcopy);  /* return the allocated space */
00345    wcopy = 0;
00346 
00347    return nerr;
00348 }

int32_t config_basketsize ( const char *  config  ) 

Definition at line 424 of file bogus_beammon.c.

References len, logInfo(), roto_send_basketsize_config(), and rototalk_err_badconfig.

00425 {
00426    int32_t nerr = 0;
00427    int32_t len = strlen(config);
00428    char *wcopy = (char*)malloc(len+1);  /* a writable copy of config string */
00429    char stream[1024];
00430    const char *p1;
00431    char *p2;
00432    char achar;
00433    int32_t bsize, nitems;
00434 
00435    /* make a copy, replacing all the commas with blanks*/
00436    p1 = config; p2 = wcopy;
00437    while (p2 < wcopy+len) {
00438       achar = *p1;
00439       if (achar != ',') *p2 = achar;
00440       else              *p2 = ' ';
00441       p1++; p2++;
00442    }
00443 
00444    p2 = wcopy;
00445    while (p2  < wcopy+len) {
00446       nitems = sscanf(p2,"%s %d",stream,&bsize);
00447       if (nitems != 2) {
00448          logInfo("config_basketsize: only %d items from \"%s\"\n",nitems,p2);
00449          nerr += rototalk_err_badconfig;
00450       }
00451       else 
00452          nerr += roto_send_basketsize_config(stream,bsize);
00453 
00454       p2 = strchr(p2,';'); /* move to the semicolon         */
00455       if (!p2) break;      /* in case of no final semicolon */
00456       p2++;                /* start just beyond semicolon   */
00457    }
00458 
00459 
00460    free(wcopy);  /* return the allocated space */
00461    wcopy = 0;
00462 
00463    return nerr;
00464 }

int32_t config_compress ( const char *  config  ) 

Definition at line 366 of file bogus_beammon.c.

References len, logInfo(), roto_send_compress_config(), and rototalk_err_badconfig.

00367 {
00368    int32_t nerr = 0;
00369    int32_t len = strlen(config);
00370    char *wcopy = (char*)malloc(len+1);  /* a writable copy of config string */
00371    char stream[1024];
00372    const char *p1;
00373    char *p2;
00374    char achar;
00375    int32_t level, nitems;
00376 
00377    /* make a copy, replacing all the commas with blanks*/
00378    p1 = config; p2 = wcopy;
00379    while (p2 < wcopy+len) {
00380       achar = *p1;
00381       if (achar != ',') *p2 = achar;
00382       else              *p2 = ' ';
00383       p1++; p2++;
00384    }
00385 
00386    p2 = wcopy;
00387    while (p2  < wcopy+len) {
00388       nitems = sscanf(p2,"%s %d",stream,&level);
00389       if (nitems != 2) {
00390          logInfo("config_compress: only %d items from \"%s\"\n",nitems,p2);
00391          nerr += rototalk_err_badconfig;
00392       }
00393       else 
00394          nerr += roto_send_compress_config(stream,level);
00395 
00396       p2 = strchr(p2,';'); /* move to the semicolon         */
00397       if (!p2) break;      /* in case of no final semicolon */
00398       p2++;                /* start just beyond semicolon   */
00399    }
00400 
00401 
00402    free(wcopy);  /* return the allocated space */
00403    wcopy = 0;
00404 
00405    return nerr;
00406 }

int main ( int  argc,
char **  argv 
)

Definition at line 63 of file bogus_beammon.c.

References config_autosave(), config_basketsize(), config_compress(), exit(), logNotice(), MAXBUFFER, MINOS_ROOTER_BEAMMON, MINOS_ROOTER_DCP, MINOS_ROOTER_DCS, MINOS_ROOTER_UNIDENTIFIED_CLIENT, msgLogCleanup(), msgLogInit(), msgLogLocalEchoSet(), msgLogNodeIdSet(), port, producer(), roto_close_connection(), roto_open_BeamMon_connection(), roto_open_connection(), roto_set_connection_nodelay(), roto_verbose, and send_bogus_stuff().

00064 {
00065 
00066    /* this is C ... all declarations must come first */
00067    const char* iphost = "localhost";
00068    const char* default_producer = "BeamMon";   /* default producer */
00069    const int32_t default_port     = 9013;        /* default BeamMon port */
00070    const char* producer = default_producer;
00071    const char* autosave_config = 0;
00072    const char* compress_config = 0;
00073    const char* basketsize_config = 0;
00074    int32_t port = default_port;
00075    int32_t whoami = MINOS_ROOTER_BEAMMON;
00076    int32_t bsize = MAXBUFFER;
00077    int32_t* buffer = 0;
00078    int32_t nerr = 0;
00079    int32_t mxrec = 1000;  /* no input file, so limit how much stuff to send */
00080    int32_t nodelay_flag = 1;  /* on by default */
00081    int32_t echoMsgLog = 0;
00082    int32_t copt;
00083 
00084    /*
00085     * parse the options and filenames
00086     * -i and -p take args
00087     */
00088    while ((copt = getopt(argc, argv, "i:b:c:C:B:w:p:ev:n:D:h")) != EOF) {
00089       switch (copt) {
00090       case 'i':  /* internet host */
00091          iphost = optarg;
00092          break;
00093       case 'b':  /* buffer size */
00094          bsize = atoi(optarg);
00095          break;
00096       case 'c':  /* autosave config string */
00097          autosave_config = optarg;
00098          break;
00099       case 'C':  /* compression config string */
00100          compress_config = optarg;
00101          break;
00102       case 'B':  /* basketsize config string */
00103          basketsize_config = optarg;
00104          break;
00105       case 'w':  /* whoami:  DCP, DCS, other */
00106          producer = optarg;
00107          break;
00108       case 'p':  /* port # */
00109          port = atoi(optarg);
00110          break;
00111       case 'e':  /* msgLog messages to stdout as well */
00112          echoMsgLog = 1;
00113          break;
00114       case 'v':  /* verbosity */
00115          roto_verbose = atoi(optarg);
00116          break;
00117       case 'n':  /* maximum number of records */
00118          mxrec = atoi(optarg);
00119          break;
00120       case 'D':  /* set nodelay_flag? */
00121          nodelay_flag = atoi(optarg);
00122          break;
00123       case 'h':  /* help */
00124          printf(" usage: %s -i<hostname> -b<buffer size> -w<whoami> -p<port #> <filenames..>\n", argv[0]);
00125          printf("   -i: hostname where rotorooter is running\n");
00126          printf("   -b: buffer size to use\n");
00127          printf("   -w: DCP, DCS or BeamMon\n");
00128          printf("   -p: port number rotorooter is listening on\n");
00129          printf("   -v: how verbose to be\n");
00130          printf("   -c: autosave config \"streamName,nrec,nsec[;streamName,nrec,nsec]\"\n");
00131          printf("   -C: compression config \"streamName,level[;streamName,level]\"\n");
00132          printf("   -B: basketsize config \"streamName,size[;streamName,size]\"\n");
00133 
00134          printf("   -n: maximum number of records from each file\n");
00135 
00136          printf("   -h: print this message\n");
00137          exit(1);
00138       default:
00139          printf(" unrecognized option '%c' ignored\n",(char)optopt);
00140          break;
00141       }
00142    }
00143 
00144    msgLogInit(argv[0]);
00145    msgLogNodeIdSet(whoami);
00146    msgLogLocalEchoSet(echoMsgLog);
00147    logNotice("starting %s",argv[0]);
00148 
00149    /* allocate a buffer to use */
00150    buffer = (int32_t*) malloc(bsize);
00151    if (!buffer) {
00152       printf("failed to allocate buffer of size %d\n",bsize);
00153       exit(1);
00154    }
00155    if (roto_verbose>1) printf("allocated buffer of size %d\n",bsize);
00156 
00157    /* open a connection to the Rotorooter */
00158    if (0 == strcmp(producer,default_producer) && 
00159        port == default_port) {
00160       /* standard connection */
00161       if (roto_verbose>1) 
00162          printf("connect via roto_open_BeamMon_connection\n");
00163       nerr += roto_open_BeamMon_connection(iphost);
00164    } else {
00165       /* non-standard connection requested (either producer or port) */
00166       if (0 == strcmp(producer,"DCP")) {
00167          whoami  = MINOS_ROOTER_DCP;
00168       }
00169       else if (0 == strcmp(producer,"DCS")) {
00170          whoami = MINOS_ROOTER_DCS;
00171       }
00172       else if (0 == strcmp(producer,"BeamMon")) {
00173          whoami = MINOS_ROOTER_BEAMMON;
00174       }
00175       else 
00176          whoami = MINOS_ROOTER_UNIDENTIFIED_CLIENT;
00177 
00178       if (roto_verbose>1) 
00179          printf("connect via roto_open_connection: port %d, whoami %s (0x%2.2x)\n",port,producer,whoami);
00180       nerr += roto_open_connection(iphost,port,whoami);
00181    }
00182    if (nerr) exit(nerr);
00183    
00184    nerr += roto_set_connection_nodelay(nodelay_flag);
00185 
00186    if (autosave_config) nerr += config_autosave(autosave_config);
00187    if (compress_config) nerr += config_compress(compress_config);
00188    if (basketsize_config) nerr += config_basketsize(basketsize_config);
00189 
00190    nerr += send_bogus_stuff(buffer,bsize,mxrec);
00191 
00192    /* close the connection */
00193    nerr += roto_close_connection();
00194 
00195    /* set my buffer free */
00196    free(buffer);
00197 
00198    logNotice("stopping %s",argv[0]);
00199    msgLogCleanup();
00200 
00201    exit(nerr);
00202 }

int32_t send_bogus_stuff ( int32_t *  buffer,
int32_t  bsize,
int32_t  mxrec 
)

Definition at line 220 of file bogus_beammon.c.

References build_beammon_blockid(), kMdBlockBeamMonHeader, kMdBlockBeamMonPayload, rdxsum_calc(), roto_close_beammonfile(), roto_open_beammonfile(), and roto_send_record().

Referenced by main().

00221 {
00222 
00223    int32_t   nRecords=0;
00224    int32_t   nbytes;
00225    int32_t   nextra, j;
00226    const float nextra_max = 100.0;
00227    int32_t   blktype;
00228    uint32_t  spillcnt = 0;
00229 
00230    int32_t nerr = 0;
00231 
00232    struct timeval now;
00233    gettimeofday(&now,0);
00234 
00235    nerr += roto_open_beammonfile(now.tv_sec,now.tv_usec*1000);
00236    if (nerr) {
00237       printf("Rotorooter failed to open output file\n");
00238       return 1;
00239    }
00240 
00241    while (1) {
00242       if (mxrec>0 && nRecords==mxrec) break;
00243       nRecords++;
00244       /* fill a BeamMon record */
00245       /*
00246        * 0 BeamMonHeaderBlock size
00247        * 1                checksum
00248        * 2                blockid
00249        * 3                sec
00250        * 4                ns
00251        * 5                spillcnt
00252        * 6 {In|OutOf}SpillBeamMonBlock size
00253        * 7                         checksum
00254        * 8                         blockid
00255        * 9..                       <stuff>
00256        */
00257       /* see Linux "man -s 3 rand" on why whe do this */
00258       nextra = 1+(int32_t) (nextra_max*rand()/(RAND_MAX+1.0));
00259       nbytes = (9+nextra)*sizeof(int32_t);
00260       if (nbytes>bsize) {
00261         nbytes = bsize;
00262         nextra = nbytes/sizeof(int32_t) - 9;
00263       }
00264       blktype = kMdBlockBeamMonPayload;
00265 
00266       buffer[0] = 6; /* BeamMonHeaderBlock size */
00267       /* skip checksum */
00268       buffer[2] = build_beammon_blockid(kMdBlockBeamMonHeader);
00269       gettimeofday(&now,0);
00270       buffer[3] = now.tv_sec;
00271       buffer[4] = now.tv_usec*1000;
00272       buffer[5] = ++spillcnt;
00273       /* now fill in checksum */
00274       buffer[1] = rdxsum_calc(buffer+0,1);
00275 
00276       buffer[6] = 3 + nextra; /* {In|OutOf}SpillBeamMonBlock size */
00277       /* skip checksum */
00278       buffer[8] = build_beammon_blockid(blktype);
00279       /* fill in some arbitrary stuff */
00280       for (j=0; j<nextra; ++j) buffer[j+9] = rand();
00281       /* now fill in checksum */
00282       buffer[7] = rdxsum_calc(buffer+6,1);
00283                                  
00284       /* send the record */
00285       nerr += roto_send_record(buffer,nbytes);
00286    }
00287 
00288    nerr += roto_close_beammonfile();
00289    return nerr;
00290 }


Generated on 22 Jul 2018 for loon by  doxygen 1.6.1