Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

bogus_dcs.c File Reference

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.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

int send_bogus_stuff (long *buffer, int bsize, int mxrec)
int parse_detector (const char *detname)
int config_autosave (const char *config)
int config_compress (const char *config)
int config_basketsize (const char *config)
long build_dcs_blockid (int detector, int major, int version)
long * append_dcs_header_block (long *buffer, long *toofar)
long * append_dcs_monitor_block (long *buffer, long *toofar)
long * append_dcs_alarm_block (long *buffer, long *toofar)
int main (int argc, char **argv)

Variables

int gDetector = kMdBlockSourceFarDetector


Define Documentation

#define MAXBUFFER   8388608
 

Definition at line 34 of file bogus_dcs.c.


Function Documentation

long * append_dcs_alarm_block long *  buffer,
long *  toofar
 

Definition at line 626 of file bogus_dcs.c.

References build_dcs_blockid(), gDetector, kMdBlockDcsAlarm, logError(), and rdxsum_calc().

00627 {
00628   /*
00629    * 0 DcsAlarmBlock  size
00630    * 1                checksum
00631    * 2                blockid
00632    * ...              <stuff>
00633    */
00634 
00635   int  version = 0;
00636   long blksize, payload, j;
00637 
00638   /* 
00639    * determine whether this block is to go out on this record
00640    */
00641 
00642   /* for this case pick a random frequency (see Linux "man -s 3 rand")*/
00643   /* here pick 10% chance of adding one */
00644   if ( rand()/(RAND_MAX+1.0) > 0.10 ) return buffer;
00645 
00646   /* 
00647    * determine how big this block is going to be when done
00648    */
00649 
00650   /* for this case pick a random size (1 to 30 words) for the data payload */
00651   payload = 1 + (int)(30.*rand()/(RAND_MAX+1.0));
00652   blksize = 3 + payload;
00653 
00654   /* check that adding this won't overflow buffer */
00655   if (buffer+blksize > toofar) { 
00656     logError("append_dcs_alarm_block: need %ld have %d",
00657              blksize,toofar-buffer);
00658     return buffer;
00659   }
00660 
00661   /* fill in the data */
00662 
00663   buffer[0] = blksize;
00664   /* skip checksum */
00665   buffer[2] = build_dcs_blockid(gDetector,kMdBlockDcsAlarm,version);
00666 
00667   /* payload of random numbers */
00668   for (j=0; j<payload; ++j) buffer[j+3] = rand();
00669 
00670   /* now fill in checksum */
00671   buffer[1] = rdxsum_calc(buffer+0,1);
00672 
00673   return buffer + buffer[0];
00674 }

long * append_dcs_header_block long *  buffer,
long *  toofar
 

Definition at line 573 of file bogus_dcs.c.

References build_dcs_blockid(), gDetector, kMdBlockDcsHeader, logError(), and rdxsum_calc().

00574 {
00575   /*
00576    * 0 DcsHeaderBlock size
00577    * 1                checksum
00578    * 2                blockid
00579    * 3                sec
00580    * 4                ns
00581    */
00582 
00583   int  version = 0;
00584   long blksize = 5;
00585   struct timeval now;
00586 
00587   /* check that adding this won't overflow buffer */
00588   if (buffer+blksize > toofar) {
00589     logError("append_dcs_header_block: need %ld have %d",
00590              blksize,toofar-buffer);
00591     return buffer;
00592   }
00593 
00594   /* fill in the data */
00595 
00596   buffer[0] = blksize;
00597   /* skip checksum */
00598   buffer[2] = build_dcs_blockid(gDetector,kMdBlockDcsHeader,version);
00599 
00600   /* for now tag record with the current system time */
00601   gettimeofday(&now,0);
00602   buffer[3] = now.tv_sec;
00603   buffer[4] = now.tv_usec*1000;
00604 
00605   /* now fill in checksum */
00606   buffer[1] = rdxsum_calc(buffer+0,1);
00607 
00608   return buffer + buffer[0];
00609 }

long * append_dcs_monitor_block long *  buffer,
long *  toofar
 

Definition at line 691 of file bogus_dcs.c.

References build_dcs_blockid(), gDetector, kMdBlockDcsMonitor, logError(), and rdxsum_calc().

00692 {
00693   /*
00694    * 0 DcsMonitorBlock  size
00695    * 1                checksum
00696    * 2                blockid
00697    * ...              <stuff>
00698    */
00699 
00700   int  version = 0;
00701   long blksize, payload, j;
00702 
00703   /* 
00704    * determine whether this block is to go out on this record
00705    */
00706 
00707   /* for this case pick a random frequency (see Linux "man -s 3 rand")*/
00708   /* here pick 90% chance of adding one */
00709   if ( rand()/(RAND_MAX+1.0) > 0.90 ) return buffer;
00710 
00711   /* 
00712    * determine how big this block is going to be when done
00713    */
00714 
00715   /* for this case pick a random size (30 to 300 words) for the data payload */
00716   payload = 30 + (int)(300.*rand()/(RAND_MAX+1.0));
00717   blksize = 3 + payload;
00718 
00719   /* check that adding this won't overflow buffer */
00720   if (buffer+blksize > toofar) { 
00721     logError("append_dcs_monitor_block: need %ld have %d",
00722              blksize,toofar-buffer);
00723     return buffer;
00724   }
00725 
00726   /* fill in the data */
00727 
00728   buffer[0] = blksize;
00729   /* skip checksum */
00730   buffer[2] = build_dcs_blockid(gDetector,kMdBlockDcsMonitor,version);
00731 
00732   /* payload of random numbers */
00733   for (j=0; j<payload; ++j) buffer[j+3] = rand();
00734 
00735   /* now fill in checksum */
00736   buffer[1] = rdxsum_calc(buffer+0,1);
00737 
00738   return buffer + buffer[0];
00739 }

long build_dcs_blockid int  detector,
int  major,
int  version
 

Definition at line 533 of file bogus_dcs.c.

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

Referenced by append_dcs_alarm_block(), append_dcs_header_block(), and append_dcs_monitor_block().

00534 {
00535    const long  shiftRawBlkIdMinor    =  0;
00536    const long  shiftRawBlkIdMajor    =  8;
00537    const long  shiftRawBlkIdDetector = 25;
00538    const long  shiftRawBlkIdCSimFlag = 28;
00539    
00540    const long  maskRawBlkIdMinor     = 0x000000ff;
00541    const long  maskRawBlkIdMajor     = 0x00ffff00;
00542    const long  maskRawBlkIdIsDCS     = 0x01000000;
00543    const long  maskRawBlkIdDetector  = 0x0e000000;
00544    const long  maskRawBlkIdCSimFlag  = 0x30000000;
00545 
00546    int cmptSimFlag = 0;  /* compact simflag for real Data */
00547    int isDCS = 1;
00548 
00549    return
00550       ((cmptSimFlag << shiftRawBlkIdCSimFlag) & maskRawBlkIdCSimFlag) |
00551       ((   detector << shiftRawBlkIdDetector) & maskRawBlkIdDetector) |
00552       ((isDCS) ? maskRawBlkIdIsDCS : 0)                               |
00553       ((         major   << shiftRawBlkIdMajor) & maskRawBlkIdMajor)  |
00554       ((         version << shiftRawBlkIdMinor) & maskRawBlkIdMinor);
00555 
00556 }

int config_autosave const char *  config  ) 
 

int config_basketsize const char *  config  ) 
 

int config_compress const char *  config  ) 
 

int main int  argc,
char **  argv
 

COMMAND LINE

CALIB CONSTANTS

BEAM RUN KEY

Cerenkov ADC cuts:

ATTENUATION PARAMS

FILE + TREE

Definition at line 69 of file bogus_dcs.c.

References config_autosave(), config_basketsize(), config_compress(), gDetector, logDebugLevelSet(), logNotice(), msgLogCleanup(), msgLogInit(), msgLogLocalEchoSet(), msgLogNodeIdSet(), parse_detector(), port, producer(), roto_close_connection(), roto_open_connection(), roto_open_DCS_connection(), roto_set_connection_nodelay(), roto_verbose, and send_bogus_stuff().

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

int parse_detector const char *  detname  ) 
 

Definition at line 299 of file bogus_dcs.c.

References gDetector, and logWarn().

Referenced by main().

00300 {
00301 
00302   switch (detname[0]) {
00303   case 'n':
00304   case 'N':
00305   case '1':
00306     return kMdBlockSourceNearDetector;
00307     break;
00308   case 'f':
00309   case 'F':
00310   case '2':
00311     return kMdBlockSourceFarDetector;
00312     break;
00313   case 'c':
00314   case 'C':
00315   case '4':
00316     return kMdBlockSourceCalDetector;
00317     break;
00318   default:
00319     logWarn("parse_detector: could not decipher '%s', using value %d",
00320             detname,gDetector);
00321     return gDetector;
00322   }
00323 }

int send_bogus_stuff long *  buffer,
int  bsize,
int  mxrec
 

Referenced by main().


Variable Documentation

int gDetector = kMdBlockSourceFarDetector
 

Definition at line 37 of file bogus_dcs.c.


Generated on Mon Feb 15 11:07:54 2010 for loon by  doxygen 1.3.9.1