From: hadaq Date: Thu, 10 Dec 2009 11:45:11 +0000 (+0000) Subject: rfio to lustre feature added. Sergey. X-Git-Url: https://jspc29.x-matter.uni-frankfurt.de/git/?a=commitdiff_plain;h=d8ac8d0b04cad597cca19669a3910566e801c137;p=daqdata.git rfio to lustre feature added. Sergey. --- diff --git a/hadaq/evtbuild.c b/hadaq/evtbuild.c index 5f29ea0..ac2f41a 100644 --- a/hadaq/evtbuild.c +++ b/hadaq/evtbuild.c @@ -1,10 +1,8 @@ -static char *rcsId = - "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hadaq/evtbuild.c,v 6.94 2008-10-06 12:50:14 hadaq Exp $"; - +static char *rcsId = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hadaq/evtbuild.c,v 6.95 2009-12-10 11:45:11 hadaq Exp $"; #define _POSIX_C_SOURCE 199309L #define SYSLOG_NAMES -/* #define RFIO */ +#define RFIO 1 #include #include @@ -38,19 +36,19 @@ static char *rcsId = #include "genid32.h" #ifdef RFIO -#include "rawapin.h" /* for rfio */ +#include "rawapin.h" /* for rfio */ static RFILE *fRemote = NULL; #endif #define MAXINPATH 100 -#define NEVTIDS 64UL /* must be 2^n */ -#define NEVTIDS_IN_FILE 0UL /* must be 2^n */ +#define NEVTIDS 64UL /* must be 2^n */ +#define NEVTIDS_IN_FILE 0UL /* must be 2^n */ #define EVENT_NUM_OFFSET 100 #define DEBUG2 0 -#define CHECK_MISMATCH 1 +#define CHECK_MISMATCH 0 #define BEAM 1 -#define TIMEOFFSET 1200000000 /* needed to reconstruct time from runId */ +#define TIMEOFFSET 1200000000 /* needed to reconstruct time from runId */ static FILE *outFile; static FILE *outLustreFile; static FILE *outSecondFile; @@ -59,7 +57,7 @@ static AnsiTape *outTape; static uint32_t seqNr; static uint32_t res_seqNr; static uint32_t runNr; -static uint32_t newRunId; /* needed to get new RUN id from epics ctrl */ +static uint32_t newRunId; /* needed to get new RUN id from epics ctrl */ static time_t ourTime; static long file_size; static long res_file_size; @@ -70,1936 +68,1817 @@ static time_t res_time; static int diff_time; static int trig_mismatch; -typedef struct TheArgsS -{ - unsigned long nrOfMsgs; - char outPath[PARAM_MAX_VALUE_LEN]; - char outDev[PARAM_MAX_VALUE_LEN]; - unsigned long runNr; - char expId[PARAM_MAX_VALUE_LEN]; - char *slowCtrlFiles[PARAM_MAX_ARRAY_LEN]; - char slowCtrlFilesS[PARAM_MAX_ARRAY_LEN][PARAM_MAX_NAME_LEN]; - int slowCtrlFileCnt; - unsigned long isStandalone; - unsigned long priority; - unsigned long queueSize; - char verbosity[PARAM_MAX_VALUE_LEN]; - unsigned long evtId; - unsigned long maxFileSz; - unsigned short no_rpc; - unsigned int resdownscale; - unsigned int resnumevents; - char respath[PARAM_MAX_VALUE_LEN]; - unsigned short write_data; - char sec_path[PARAM_MAX_VALUE_LEN]; - unsigned int ressizelimit; - double secsizelimit; - double resdown_offset; - - /* the following arguments are for the variable queue size. S.Y. */ - unsigned long varQSize[MAXINPATH]; - int varQSizeCnt; - - char rfioRemotePath[PARAM_MAX_VALUE_LEN]; - char lustrePath[PARAM_MAX_VALUE_LEN]; - unsigned short buffStat; - unsigned short epicsCtrl; - unsigned short ignore; /* ignore all trigger mismatch conditions */ - char shmname[PARAM_MAX_VALUE_LEN]; - unsigned int ebnum; - char runinfo2ora[PARAM_MAX_VALUE_LEN]; +typedef struct TheArgsS { + unsigned long nrOfMsgs; + char outPath[PARAM_MAX_VALUE_LEN]; + char outDev[PARAM_MAX_VALUE_LEN]; + unsigned long runNr; + char expId[PARAM_MAX_VALUE_LEN]; + char *slowCtrlFiles[PARAM_MAX_ARRAY_LEN]; + char slowCtrlFilesS[PARAM_MAX_ARRAY_LEN][PARAM_MAX_NAME_LEN]; + int slowCtrlFileCnt; + unsigned long isStandalone; + unsigned long priority; + unsigned long queueSize; + char verbosity[PARAM_MAX_VALUE_LEN]; + unsigned long evtId; + unsigned long maxFileSz; + unsigned short no_rpc; + unsigned int resdownscale; + unsigned int resnumevents; + char respath[PARAM_MAX_VALUE_LEN]; + unsigned short write_data; + char sec_path[PARAM_MAX_VALUE_LEN]; + unsigned int ressizelimit; + double secsizelimit; + double resdown_offset; + + /* the following arguments are for the variable queue size. S.Y. */ + unsigned long varQSize[MAXINPATH]; + int varQSizeCnt; + + char rfioRemotePath[PARAM_MAX_VALUE_LEN]; + char rfioLustrePath[PARAM_MAX_VALUE_LEN]; + char lustrePath[PARAM_MAX_VALUE_LEN]; + unsigned short buffStat; + unsigned short epicsCtrl; + unsigned short ignore; /* ignore all trigger mismatch conditions */ + char shmname[PARAM_MAX_VALUE_LEN]; + unsigned int ebnum; + char runinfo2ora[PARAM_MAX_VALUE_LEN]; } TheArgs; -typedef struct TheStatsS -{ - unsigned long *evtsDiscarded; - unsigned long *evtsComplete; - unsigned long *evtsDataError; - unsigned long *evtsTagError; - unsigned long *bytesWritten; - unsigned long *evtId[NEVTIDS]; - unsigned long *trigNr[MAXINPATH]; - unsigned long *evtsRes; - unsigned long *evtbuildBuff[MAXINPATH]; - unsigned long *nrOfMsgs; - unsigned long *runId; +typedef struct TheStatsS { + unsigned long *evtsDiscarded; + unsigned long *evtsComplete; + unsigned long *evtsDataError; + unsigned long *evtsTagError; + unsigned long *bytesWritten; + unsigned long *evtId[NEVTIDS]; + unsigned long *trigNr[MAXINPATH]; + unsigned long *evtsRes; + unsigned long *evtbuildBuff[MAXINPATH]; + unsigned long *nrOfMsgs; + unsigned long *runId; } TheStats; static jmp_buf terminateJmp; -void sigHandler (int sig) +void sigHandler(int sig) { - longjmp (terminateJmp, sig); + longjmp(terminateJmp, sig); } -static void *appendFile (void *my, const char *path) +static void *appendFile(void *my, const char *path) { - void *subEvt; - char *dataBuf; - FILE *file; - size_t fileSize; - - if (NULL == (file = fopen (path, "r"))) - { - syslog (LOG_ERR, "%s, %d: %s", __FILE__, __LINE__, strerror (errno)); - return my; - } - subEvt = newSubEvt (SubEvtDecoding_text, SubEvtId_slowTest, 0); - - if (NULL == (dataBuf = malloc (strlen (path + 2)))) - { - syslog (LOG_ERR, "%s, %d: %s", __FILE__, __LINE__, strerror (errno)); - return my; - } - sprintf (dataBuf, "#%s\n", path); - subEvt = SubEvt_appendData (subEvt, dataBuf, strlen (dataBuf)); - free (dataBuf); - - fseek (file, 0, SEEK_END); - fileSize = ftell (file); - fseek (file, 0, SEEK_SET); - if (NULL == (dataBuf = malloc (fileSize))) - { - syslog (LOG_ERR, "%s, %d: %s", __FILE__, __LINE__, strerror (errno)); - return my; - } - fread (dataBuf, 1, fileSize, file); - - subEvt = SubEvt_appendData (subEvt, dataBuf, fileSize); - my = Evt_appendSubEvt (my, subEvt); - - deleteSubEvt (subEvt); - free (dataBuf); - fclose (file); - - return my; + void *subEvt; + char *dataBuf; + FILE *file; + size_t fileSize; + + if (NULL == (file = fopen(path, "r"))) { + syslog(LOG_ERR, "%s, %d: %s", __FILE__, __LINE__, strerror(errno)); + return my; + } + subEvt = newSubEvt(SubEvtDecoding_text, SubEvtId_slowTest, 0); + + if (NULL == (dataBuf = malloc(strlen(path + 2)))) { + syslog(LOG_ERR, "%s, %d: %s", __FILE__, __LINE__, strerror(errno)); + return my; + } + sprintf(dataBuf, "#%s\n", path); + subEvt = SubEvt_appendData(subEvt, dataBuf, strlen(dataBuf)); + free(dataBuf); + + fseek(file, 0, SEEK_END); + fileSize = ftell(file); + fseek(file, 0, SEEK_SET); + if (NULL == (dataBuf = malloc(fileSize))) { + syslog(LOG_ERR, "%s, %d: %s", __FILE__, __LINE__, strerror(errno)); + return my; + } + fread(dataBuf, 1, fileSize, file); + + subEvt = SubEvt_appendData(subEvt, dataBuf, fileSize); + my = Evt_appendSubEvt(my, subEvt); + + deleteSubEvt(subEvt); + free(dataBuf); + fclose(file); + + return my; } -static void usage (const char *progName) +static void usage(const char *progName) { - syslog (LOG_ERR, "Usage: %s [-x expId]", progName); - syslog (LOG_ERR, "Usage: [-m nrOfMsgs] [-f slowCtrlFile ...]"); - syslog (LOG_ERR, "Usage: [-o outPath] [-d null|tape|file|stdout]"); - syslog (LOG_ERR, "Usage: [-q queueSize] [-r runNumber]"); - syslog (LOG_ERR, "Usage: [--shmname shmem_name] extension of shared memory name to be opened"); - syslog (LOG_ERR, "Usage: [-a (agent)] [-p priority] [-I evtId]"); - syslog (LOG_ERR, "Usage: [-v debug|info|notice|warning|err|alert|crit|emerg]"); - syslog (LOG_ERR, "Usage: [--norpc]"); - syslog (LOG_ERR, "Usage: [--filesize max_size] maximum size of output file in MB"); - syslog (LOG_ERR, "Usage: [--resdownscale downscale_factor] downscale factor for the res events"); - syslog (LOG_ERR, "Usage: [--resnumevents evt_num] maximum number of events in a resfile"); - syslog (LOG_ERR, "Usage: [--respath path] path for the res directory"); - syslog (LOG_ERR, "Usage: [--secsizelimit max_size] maximum size of second directory with the mirrored data [in MB]"); - syslog (LOG_ERR, "Usage: [--ressizelimit max_file_num] maximum number of files in res dir"); - syslog (LOG_ERR, "Usage: [--write_data path] path to the directory with mirrored data"); + syslog(LOG_ERR, "Usage: %s [-x expId]", progName); + syslog(LOG_ERR, "Usage: [-m nrOfMsgs] [-f slowCtrlFile ...]"); + syslog(LOG_ERR, "Usage: [-o outPath] [-d null|tape|file|stdout]"); + syslog(LOG_ERR, "Usage: [-q queueSize] [-r runNumber]"); + syslog(LOG_ERR, "Usage: [--shmname shmem_name] extension of shared memory name to be opened"); + syslog(LOG_ERR, "Usage: [-a (agent)] [-p priority] [-I evtId]"); + syslog(LOG_ERR, "Usage: [-v debug|info|notice|warning|err|alert|crit|emerg]"); + syslog(LOG_ERR, "Usage: [--norpc]"); + syslog(LOG_ERR, "Usage: [--filesize max_size] maximum size of output file in MB"); + syslog(LOG_ERR, "Usage: [--resdownscale downscale_factor] downscale factor for the res events"); + syslog(LOG_ERR, "Usage: [--resnumevents evt_num] maximum number of events in a resfile"); + syslog(LOG_ERR, "Usage: [--respath path] path for the res directory"); + syslog(LOG_ERR, "Usage: [--secsizelimit max_size] maximum size of second directory with the mirrored data [in MB]"); + syslog(LOG_ERR, "Usage: [--ressizelimit max_file_num] maximum number of files in res dir"); + syslog(LOG_ERR, "Usage: [--write_data path] path to the directory with mirrored data"); #ifdef RFIO - syslog (LOG_ERR, "Usage: [--rfio path_to_tape_archive] example: --rfio rfiodaq:gstore:/hadaqtest/test002"); + syslog(LOG_ERR, "Usage: [--rfio path_to_tape_archive] example: --rfio rfiodaq:gstore:/hadaqtest/test002"); + syslog(LOG_ERR, "Usage: [--rfiolustre path] example: --rfiolustre /lustre/hades/daq"); #endif - syslog (LOG_ERR, "Usage: [--buffstat] show fill levels of buffers"); - syslog (LOG_ERR, "Usage: [--epicsctrl] enable synch and distribution of RUN Id by Epics for parallel event builders"); - syslog (LOG_ERR, "Usage: [--lustre path_to_lustre] path to the file on the Lustre cluster"); - syslog (LOG_ERR, "Usage: [--ebnum] number of the event builder"); - syslog (LOG_ERR, "Usage: [--orapath path] path to eb_runinfo2ora.txt"); - syslog (LOG_ERR, "Usage: [--ignore] ignore trigger mismatch conditions"); + syslog(LOG_ERR, "Usage: [--buffstat] show fill levels of buffers"); + syslog(LOG_ERR, "Usage: [--epicsctrl] enable synch and distribution of RUN Id by Epics for parallel event builders"); + syslog(LOG_ERR, "Usage: [--lustre path_to_lustre] path to the file on the Lustre cluster"); + syslog(LOG_ERR, "Usage: [--ebnum] number of the event builder"); + syslog(LOG_ERR, "Usage: [--orapath path] path to eb_runinfo2ora.txt"); + syslog(LOG_ERR, "Usage: [--ignore] ignore trigger mismatch conditions"); } -static void argsDump (TheArgs * my) +static void argsDump(TheArgs *my) { - int i; - - syslog (LOG_DEBUG, "nrOfMsgs: %d", my->nrOfMsgs); - for (i = 0; i < my->slowCtrlFileCnt; i++) { - syslog (LOG_DEBUG, "slowCtrlFiles[%d]: %s", i, my->slowCtrlFiles[i]); - } - syslog (LOG_DEBUG, "outPath: %s", my->outPath); - syslog (LOG_DEBUG, "outDev: %s", my->outDev); - syslog (LOG_DEBUG, "runNr: %d", my->runNr); - syslog (LOG_DEBUG, "expId: %s", my->expId); - syslog (LOG_DEBUG, "priority: %d", my->priority); - syslog (LOG_DEBUG, "isStandalone: %d", my->isStandalone); - syslog (LOG_DEBUG, "queueSize: %d", my->queueSize); - syslog (LOG_DEBUG, "verbosity: %s", my->verbosity); - syslog (LOG_DEBUG, "evtId: %ld", my->evtId); - syslog (LOG_DEBUG, "maxFileSz: %ld", my->maxFileSz); - if( strcmp( my->shmname, "" ) != 0 ) { - syslog (LOG_DEBUG, "shmem name: %s", my->shmname); - } - if (my->resdownscale != 0) { - syslog (LOG_DEBUG, "resdownscale: %ld", my->resdownscale); - syslog (LOG_DEBUG, "resnumevents: %ld", my->resnumevents); - syslog (LOG_DEBUG, "respath: %s", my->respath); - syslog (LOG_DEBUG, "secsizelimit: %ld", my->secsizelimit); - syslog (LOG_DEBUG, "ressizelimit: %d", my->ressizelimit); - } - if (my->no_rpc == 1) { - syslog (LOG_DEBUG, "no rpc is set"); - } - if (my->write_data == 1) { - syslog (LOG_DEBUG, "sec_path: %s", my->sec_path); - } - if( strcmp( my->rfioRemotePath, "" ) != 0 ) { - syslog (LOG_DEBUG, "rfio path: %s", my->rfioRemotePath); - } - if( strcmp( my->lustrePath, "" ) != 0 ) { - syslog (LOG_DEBUG, "lustre path: %s", my->lustrePath); - } - syslog (LOG_DEBUG, "EB numder: %d", my->ebnum); + int i; + + syslog(LOG_DEBUG, "nrOfMsgs: %d", my->nrOfMsgs); + for (i = 0; i < my->slowCtrlFileCnt; i++) { + syslog(LOG_DEBUG, "slowCtrlFiles[%d]: %s", i, my->slowCtrlFiles[i]); + } + syslog(LOG_DEBUG, "outPath: %s", my->outPath); + syslog(LOG_DEBUG, "outDev: %s", my->outDev); + syslog(LOG_DEBUG, "runNr: %d", my->runNr); + syslog(LOG_DEBUG, "expId: %s", my->expId); + syslog(LOG_DEBUG, "priority: %d", my->priority); + syslog(LOG_DEBUG, "isStandalone: %d", my->isStandalone); + syslog(LOG_DEBUG, "queueSize: %d", my->queueSize); + syslog(LOG_DEBUG, "verbosity: %s", my->verbosity); + syslog(LOG_DEBUG, "evtId: %ld", my->evtId); + syslog(LOG_DEBUG, "maxFileSz: %ld", my->maxFileSz); + if (strcmp(my->shmname, "") != 0) { + syslog(LOG_DEBUG, "shmem name: %s", my->shmname); + } + if (my->resdownscale != 0) { + syslog(LOG_DEBUG, "resdownscale: %ld", my->resdownscale); + syslog(LOG_DEBUG, "resnumevents: %ld", my->resnumevents); + syslog(LOG_DEBUG, "respath: %s", my->respath); + syslog(LOG_DEBUG, "secsizelimit: %ld", my->secsizelimit); + syslog(LOG_DEBUG, "ressizelimit: %d", my->ressizelimit); + } + if (my->no_rpc == 1) { + syslog(LOG_DEBUG, "no rpc is set"); + } + if (my->write_data == 1) { + syslog(LOG_DEBUG, "sec_path: %s", my->sec_path); + } + if (strcmp(my->rfioRemotePath, "") != 0) { + syslog(LOG_DEBUG, "rfio path: %s", my->rfioRemotePath); + } + if (strcmp(my->rfioLustrePath, "") != 0) { + syslog(LOG_DEBUG, "rfio lustre path: %s", my->rfioLustrePath); + } + if (strcmp(my->lustrePath, "") != 0) { + syslog(LOG_DEBUG, "lustre path: %s", my->lustrePath); + } + syslog(LOG_DEBUG, "EB numder: %d", my->ebnum); } -static void argsDefault (TheArgs * my) +static void argsDefault(TheArgs *my) { - int i; - - my->nrOfMsgs = 0; - for (i = 0; i < PARAM_MAX_ARRAY_LEN; i++) - { - my->slowCtrlFiles[i] = my->slowCtrlFilesS[i]; - } - my->slowCtrlFileCnt = 0; - strcpy (my->outPath, ""); - strcpy (my->outDev, "null"); - strcpy (my->expId, "xx"); - strcpy (my->shmname, ""); - my->priority = 0; - my->isStandalone = 1; - my->queueSize = 4 * 1024 * 1024UL; - strcpy (my->verbosity, "info"); - my->evtId = 0; - my->maxFileSz = (1.5 * 1024 * 1024 * 1024UL - 1); - my->no_rpc = 0; - my->write_data = 0; - my->resdownscale = 0; - my->resdown_offset = 0; - my->resnumevents = -1; - my->secsizelimit = 0.; - my->ressizelimit = 0; - strcpy (my->respath, ""); - - for (i = 0; i < MAXINPATH; i++) { - my->varQSize[i] = 4 * 1024 * 1024UL; - } - - strcpy (my->rfioRemotePath, ""); - strcpy (my->lustrePath, ""); - my->buffStat = 0; - my->epicsCtrl = 0; - my->ebnum = 1; - my->ignore = 0; - - /* read path from DAQ_SETUP and define full file name */ - sprintf(my->runinfo2ora,"%s_runinfo2ora.txt",getenv("DAQ_SETUP")); + int i; + + my->nrOfMsgs = 0; + for (i = 0; i < PARAM_MAX_ARRAY_LEN; i++) { + my->slowCtrlFiles[i] = my->slowCtrlFilesS[i]; + } + my->slowCtrlFileCnt = 0; + strcpy(my->outPath, ""); + strcpy(my->outDev, "null"); + strcpy(my->expId, "xx"); + strcpy(my->shmname, ""); + my->priority = 0; + my->isStandalone = 1; + my->queueSize = 4 * 1024 * 1024UL; + strcpy(my->verbosity, "info"); + my->evtId = 0; + my->maxFileSz = (1.5 * 1024 * 1024 * 1024UL - 1); + my->no_rpc = 0; + my->write_data = 0; + my->resdownscale = 0; + my->resdown_offset = 0; + my->resnumevents = -1; + my->secsizelimit = 0.; + my->ressizelimit = 0; + strcpy(my->respath, ""); + + for (i = 0; i < MAXINPATH; i++) { + my->varQSize[i] = 4 * 1024 * 1024UL; + } + + strcpy(my->rfioRemotePath, ""); + strcpy(my->rfioLustrePath, ""); + strcpy(my->lustrePath, ""); + my->buffStat = 0; + my->epicsCtrl = 0; + my->ebnum = 1; + my->ignore = 0; + + /* read path from DAQ_SETUP and define full file name */ + sprintf(my->runinfo2ora, "%s_runinfo2ora.txt", getenv("DAQ_SETUP")); } -static int argsFromCL (TheArgs * my, int argc, char *argv[]) +static int argsFromCL(TheArgs *my, int argc, char *argv[]) { - extern char *optarg; - int i; - while (1) - { - int this_option_optind = optind ? optind : 1; - int option_index = 0; - - static struct option long_options[] = { - {"norpc", 0, 0, 't'}, - {"filesize", 1, 0, 'z'}, - {"resdownscale", 1, 0, 'e'}, - {"resnumevents", 1, 0, 'n'}, - {"respath", 1, 0, 'h'}, - {"secsizelimit", 1, 0, 'l'}, - {"ressizelimit", 1, 0, 's'}, - {"write_data", 1, 0, 'w'}, - {"help", 0, 0, 'H'}, - {"rfio", 1, 0, 'R'}, - {"buffstat", 0, 0, 'b'}, - {"epicsctrl", 0, 0, 'E'}, - {"lustre", 1, 0, 'L'}, - {"shmname", 1, 0, 'S'}, - {"ebnum", 1, 0, 'B'}, - {"orapath", 1, 0, 'O'}, - {"ignore", 0, 0, 'i'}, - {0, 0, 0, 0} - }; - i = getopt_long (argc, argv, - "am:f:r:o:d:q:p:v:x:I:tz:e:n:h:w:tz:e:n:Hs:l:R:bEL:S:B:O:i", - long_options, &option_index); - if (i == -1) - break; - switch (i) - { - case 'm': - my->nrOfMsgs = strtoul (optarg, NULL, 0); - break; - case 'f': - strcpy (my->slowCtrlFiles[my->slowCtrlFileCnt++], optarg); - break; - case 'o': - strcpy (my->outPath, optarg); - break; - case 'd': - strcpy (my->outDev, optarg); - break; - case 'x': - strcpy (my->expId, optarg); - break; - case 'a': - my->isStandalone = 0; - break; - case 'p': - my->priority = strtoul (optarg, NULL, 0); - break; - case 'q': - my->queueSize = strtoul (optarg, NULL, 0); - break; - case 'v': - strcpy (my->verbosity, optarg); - break; - case 'I': - my->evtId = strtoul (optarg, NULL, 0); - break; - case 't': /* norpc - no arg */ - my->no_rpc = 1; - break; - case 'z': /* from MBytes to Bytes */ - my->maxFileSz = (1024 * 1024UL * strtoul( optarg, NULL, 0 )); - break; - case 'e': /* need resnumevents & respath */ - my->resdownscale = strtoul (optarg, NULL, 0); - if(my->resdownscale > 0) - my->resdown_offset = EVENT_NUM_OFFSET / (my->resdownscale); - break; - case 'n': - my->resnumevents = strtoul (optarg, NULL, 0); - break; - case 'l': - my->secsizelimit = (double) strtoul (optarg, NULL,0); - break; - case 's': - my->ressizelimit = strtoul (optarg, NULL, 0); - break; - case 'h': - strcpy (my->respath, optarg); - break; - case 'w': - my->write_data = 1; - strcpy (my->sec_path, optarg); - break; - case 'R': - strcpy( my->rfioRemotePath, optarg ); - break; - case 'L': - strcpy( my->lustrePath, optarg ); - break; - case 'S': - strcpy( my->shmname, optarg ); - break; - case 'b': - my->buffStat = 1; - break; - case 'E': - my->epicsCtrl = 1; - break; - case 'i': - my->ignore = 1; - break; - case 'B': - my->ebnum = strtoul (optarg, NULL, 0); - break; - case 'O': - sprintf(my->runinfo2ora,"%s_runinfo2ora.txt",optarg); - break; - case 'H': - usage (argv[0]); - return -1; - break; - default: - usage (argv[0]); - return -1; - break; - } - } - if (optind < argc) - { - printf ("non-option ARGV-elements: "); - while (optind < argc) - printf ("%s ", argv[optind++]); - printf ("\n"); - } - - return 0; + extern char *optarg; + int i; + while (1) { + int this_option_optind = optind ? optind : 1; + int option_index = 0; + + static struct option long_options[] = { + {"norpc", 0, 0, 't'}, + {"filesize", 1, 0, 'z'}, + {"resdownscale", 1, 0, 'e'}, + {"resnumevents", 1, 0, 'n'}, + {"respath", 1, 0, 'h'}, + {"secsizelimit", 1, 0, 'l'}, + {"ressizelimit", 1, 0, 's'}, + {"write_data", 1, 0, 'w'}, + {"help", 0, 0, 'H'}, + {"rfio", 1, 0, 'R'}, + {"rfiolustre", 1, 0, 'A'}, + {"buffstat", 0, 0, 'b'}, + {"epicsctrl", 0, 0, 'E'}, + {"lustre", 1, 0, 'L'}, + {"shmname", 1, 0, 'S'}, + {"ebnum", 1, 0, 'B'}, + {"orapath", 1, 0, 'O'}, + {"ignore", 0, 0, 'i'}, + {0, 0, 0, 0} + }; + i = getopt_long(argc, argv, "am:f:r:o:d:q:p:v:x:I:tz:e:n:h:w:tz:e:n:Hs:l:R:A:bEL:S:B:O:i", long_options, &option_index); + if (i == -1) + break; + switch (i) { + case 'm': + my->nrOfMsgs = strtoul(optarg, NULL, 0); + break; + case 'f': + strcpy(my->slowCtrlFiles[my->slowCtrlFileCnt++], optarg); + break; + case 'o': + strcpy(my->outPath, optarg); + break; + case 'd': + strcpy(my->outDev, optarg); + break; + case 'x': + strcpy(my->expId, optarg); + break; + case 'a': + my->isStandalone = 0; + break; + case 'p': + my->priority = strtoul(optarg, NULL, 0); + break; + case 'q': + my->queueSize = strtoul(optarg, NULL, 0); + break; + case 'v': + strcpy(my->verbosity, optarg); + break; + case 'I': + my->evtId = strtoul(optarg, NULL, 0); + break; + case 't': /* norpc - no arg */ + my->no_rpc = 1; + break; + case 'z': /* from MBytes to Bytes */ + my->maxFileSz = (1024 * 1024UL * strtoul(optarg, NULL, 0)); + break; + case 'e': /* need resnumevents & respath */ + my->resdownscale = strtoul(optarg, NULL, 0); + if (my->resdownscale > 0) + my->resdown_offset = EVENT_NUM_OFFSET / (my->resdownscale); + break; + case 'n': + my->resnumevents = strtoul(optarg, NULL, 0); + break; + case 'l': + my->secsizelimit = (double) strtoul(optarg, NULL, 0); + break; + case 's': + my->ressizelimit = strtoul(optarg, NULL, 0); + break; + case 'h': + strcpy(my->respath, optarg); + break; + case 'w': + my->write_data = 1; + strcpy(my->sec_path, optarg); + break; + case 'R': + strcpy(my->rfioRemotePath, optarg); + break; + case 'A': + strcpy(my->rfioLustrePath, optarg); + break; + case 'L': + strcpy(my->lustrePath, optarg); + break; + case 'S': + strcpy(my->shmname, optarg); + break; + case 'b': + my->buffStat = 1; + break; + case 'E': + my->epicsCtrl = 1; + break; + case 'i': + my->ignore = 1; + break; + case 'B': + my->ebnum = strtoul(optarg, NULL, 0); + break; + case 'O': + sprintf(my->runinfo2ora, "%s_runinfo2ora.txt", optarg); + break; + case 'H': + usage(argv[0]); + return -1; + break; + default: + usage(argv[0]); + return -1; + break; + } + } + if (optind < argc) { + printf("non-option ARGV-elements: "); + while (optind < argc) + printf("%s ", argv[optind++]); + printf("\n"); + } + + return 0; } -static int argsCheck( TheArgs *my ) +static int argsCheck(TheArgs *my) { - /* - * Check the content of TheArgs. - */ - - /* check my->maxFileSz */ - if( (strcmp(my->outDev, "null") != 0) && (my->maxFileSz <= 0 || my->maxFileSz >= 1024 * 1024UL * 2000) ) { - fprintf( stderr, " evtbuild.c, argsCheck(): --filesize must be >0MB and <2000MB\n"); - return 1; - } - - /* Conditions: if the Remote Event Server is used */ - if ( ( my->resdownscale != 0 && ( my->resnumevents == -1 || - (strcmp(my->respath, "") == 0) ) ) || - ( my->resnumevents != -1 && ( my->resdownscale == 0 || - (strcmp(my->respath, "") == 0) ) ) || - ( (strcmp(my->respath, "") != 0) && ( my->resnumevents == -1 || - my->resdownscale == 0 ) ) ) { - - fprintf( stderr, " evtbuild.c, argsCheck(): options --resdownscale --resnumevents --respath must be specified together\n"); - return 1; - } - - /* check my->resdownscale */ - if( (strcmp(my->respath, "") != 0) && - ( my->resdownscale <= 0 || my->resdownscale >= 100001 ) ) { - fprintf( stderr," evtbuild.c, argsCheck(): --resdownscale must be >0 and <100001\n"); - return 1; - } - - /* check my->resnumevents */ - if( (strcmp(my->respath, "") != 0) && - ( my->resnumevents <= 99 || my->resnumevents >= 1000000001 ) ) { - fprintf( stderr," evtbuild.c, argsCheck(): --resnumevents must be >99 and <1000000001\n"); - return 1; - } - - /* check my->secsizelimit */ - if( (strcmp(my->respath, "") != 0) && - ( my->secsizelimit <= -0.0001 || my->secsizelimit >= 0.0001 ) && - ( my->secsizelimit <= 10 || my->secsizelimit >= 100001 ) ) { - fprintf( stderr," evtbuild.c, argsCheck(): --secsizelimit must be >10 and <100000 MB\n"); - return 1; - } - - /* check my->ressizelimit */ - if( (strcmp(my->respath, "") != 0) && - ( my->ressizelimit <= 5 || my->ressizelimit >= 1000 ) ) { - fprintf( stderr, " evtbuild.c, argsCheck(): --ressizelimit must be >5 and <1000\n"); - return 1; - } - - if (((my->maxFileSz) < (my->queueSize))) { - fprintf( stderr, " evtbuild.c, argsCheck(): --filesize must be larger than queuesize(-q)\n"); - return 1; - } - - /* the condition ressizelimit has to be together with respath */ - if ((my->ressizelimit) != 0 && (strcmp(my->respath, "") == 0) ) { - fprintf( stderr, " evtbuild.c, argsCheck(): --respath is not given\n" ); - return 1; - } - - return 0; + /* + * Check the content of TheArgs. + */ + + /* check my->maxFileSz */ + if ((strcmp(my->outDev, "null") != 0) && (my->maxFileSz <= 0 || my->maxFileSz >= 1024 * 1024UL * 2000)) { + fprintf(stderr, " evtbuild.c, argsCheck(): --filesize must be >0MB and <2000MB\n"); + return 1; + } + + /* Conditions: if the Remote Event Server is used */ + if ((my->resdownscale != 0 && (my->resnumevents == -1 || + (strcmp(my->respath, "") == 0))) || + (my->resnumevents != -1 && (my->resdownscale == 0 || + (strcmp(my->respath, "") == 0))) || + ((strcmp(my->respath, "") != 0) && (my->resnumevents == -1 || my->resdownscale == 0))) { + + fprintf(stderr, + " evtbuild.c, argsCheck(): options --resdownscale --resnumevents --respath must be specified together\n"); + return 1; + } + + /* check my->resdownscale */ + if ((strcmp(my->respath, "") != 0) && (my->resdownscale <= 0 || my->resdownscale >= 100001)) { + fprintf(stderr, " evtbuild.c, argsCheck(): --resdownscale must be >0 and <100001\n"); + return 1; + } + + /* check my->resnumevents */ + if ((strcmp(my->respath, "") != 0) && (my->resnumevents <= 99 || my->resnumevents >= 1000000001)) { + fprintf(stderr, " evtbuild.c, argsCheck(): --resnumevents must be >99 and <1000000001\n"); + return 1; + } + + /* check my->secsizelimit */ + if ((strcmp(my->respath, "") != 0) && + (my->secsizelimit <= -0.0001 || my->secsizelimit >= 0.0001) && (my->secsizelimit <= 10 || my->secsizelimit >= 100001)) { + fprintf(stderr, " evtbuild.c, argsCheck(): --secsizelimit must be >10 and <100000 MB\n"); + return 1; + } + + /* check my->ressizelimit */ + if ((strcmp(my->respath, "") != 0) && (my->ressizelimit <= 5 || my->ressizelimit >= 1000)) { + fprintf(stderr, " evtbuild.c, argsCheck(): --ressizelimit must be >5 and <1000\n"); + return 1; + } + + if (((my->maxFileSz) < (my->queueSize))) { + fprintf(stderr, " evtbuild.c, argsCheck(): --filesize must be larger than queuesize(-q)\n"); + return 1; + } + + /* the condition ressizelimit has to be together with respath */ + if ((my->ressizelimit) != 0 && (strcmp(my->respath, "") == 0)) { + fprintf(stderr, " evtbuild.c, argsCheck(): --respath is not given\n"); + return 1; + } + + return 0; } -static int argsFromParam (TheArgs *my, int argc, char *argv[]) +static int argsFromParam(TheArgs *my, int argc, char *argv[]) { - Param paramS, *param = ¶mS; - int paramWasFound; - char *name; - - conSetupParam (param, getenv ("DAQ_SETUP")); - - name = (char *) basename (argv[0]); - - Param_getInt (param, name, "nrofmsgs", ¶mWasFound, &my->nrOfMsgs); - Param_getStringArray (param, name, "slwctrlfile", PARAM_MAX_ARRAY_LEN, - &my->slowCtrlFileCnt, my->slowCtrlFiles); - Param_getString (param, name, "outpath", ¶mWasFound, my->outPath); - Param_getString (param, name, "outdev", ¶mWasFound, my->outDev); - Param_getString (param, name, "expid", ¶mWasFound, my->expId); - Param_getInt (param, name, "stndln", ¶mWasFound, &my->isStandalone); - Param_getInt (param, name, "prio", ¶mWasFound, &my->priority); - Param_getInt (param, name, "qsize", ¶mWasFound, &my->queueSize); - Param_getString (param, name, "verb", ¶mWasFound, my->verbosity); - Param_getInt (param, name, "evtid", ¶mWasFound, &my->evtId); - Param_getInt (param, name, "maxfilesz", ¶mWasFound, &my->maxFileSz); - - Param_getIntArray(param, name, "varqsize", MAXINPATH, &my->varQSizeCnt, my->varQSize); - desParam (param); + Param paramS, *param = ¶mS; + int paramWasFound; + char *name; + + conSetupParam(param, getenv("DAQ_SETUP")); + + name = (char *) basename(argv[0]); + + Param_getInt(param, name, "nrofmsgs", ¶mWasFound, &my->nrOfMsgs); + Param_getStringArray(param, name, "slwctrlfile", PARAM_MAX_ARRAY_LEN, &my->slowCtrlFileCnt, my->slowCtrlFiles); + Param_getString(param, name, "outpath", ¶mWasFound, my->outPath); + Param_getString(param, name, "outdev", ¶mWasFound, my->outDev); + Param_getString(param, name, "expid", ¶mWasFound, my->expId); + Param_getInt(param, name, "stndln", ¶mWasFound, &my->isStandalone); + Param_getInt(param, name, "prio", ¶mWasFound, &my->priority); + Param_getInt(param, name, "qsize", ¶mWasFound, &my->queueSize); + Param_getString(param, name, "verb", ¶mWasFound, my->verbosity); + Param_getInt(param, name, "evtid", ¶mWasFound, &my->evtId); + Param_getInt(param, name, "maxfilesz", ¶mWasFound, &my->maxFileSz); + + Param_getIntArray(param, name, "varqsize", MAXINPATH, &my->varQSizeCnt, my->varQSize); + desParam(param); } -static char *unit (unsigned long v) +static char *unit(unsigned long v) { - static char retVal[6]; - static char u[] = " kM"; - int i; + static char retVal[6]; + static char u[] = " kM"; + int i; - for (i = 0; v >= 10000 && i < sizeof (u) - 2; v /= 1000, i++) {} - sprintf (retVal, "%4d%c", v, u[i]); + for (i = 0; v >= 10000 && i < sizeof(u) - 2; v /= 1000, i++) { + } + sprintf(retVal, "%4d%c", v, u[i]); - return retVal; + return retVal; } static void printTime() { - struct timeval tv; - struct tm* ptm; - char time_string[40]; - long milliseconds; + struct timeval tv; + struct tm *ptm; + char time_string[40]; + long milliseconds; - gettimeofday( &tv, NULL ); + gettimeofday(&tv, NULL); - /* Obtain the time of day, and convert it to a tm struct. */ - ptm = localtime (&tv.tv_sec); + /* Obtain the time of day, and convert it to a tm struct. */ + ptm = localtime(&tv.tv_sec); - /* Format the date and time, down to a single second. */ - strftime (time_string, sizeof (time_string), "%Y-%m-%d %H:%M:%S", ptm); + /* Format the date and time, down to a single second. */ + strftime(time_string, sizeof(time_string), "%Y-%m-%d %H:%M:%S", ptm); - /* Compute milliseconds from microseconds. */ - milliseconds = tv.tv_usec / 1000; + /* Compute milliseconds from microseconds. */ + milliseconds = tv.tv_usec / 1000; - /* Print the formatted time, in seconds, followed by a decimal point - and the milliseconds. */ - printf ("Time: %s.%03ld\n", time_string, milliseconds); + /* Print the formatted time, in seconds, followed by a decimal point + and the milliseconds. */ + printf("Time: %s.%03ld\n", time_string, milliseconds); } -static void add2Stat( TheArgs * theArgs, TheStats * my, float interval, ShmTrans **shmtr ) +static void add2Stat(TheArgs *theArgs, TheStats *my, float interval, ShmTrans **shmtr) { - /* Add statistic for fill levels of buffers in percentage. */ - - static time_t t_0 = 0; - float buffSize, queueSize; - time_t t, dT; - int i; - unsigned long fillLevel; - - t = time (NULL); - dT = t - t_0; - - if( dT >= interval ) { - for( i=0; inrOfMsgs; i++ ) { - buffSize = 2*theArgs->varQSize[i]; - queueSize = HadTuQueue_size(shmtr[i]->rdQueue); - - /* Add here statistic for fill levels of buffers */ - fillLevel = (unsigned long) (100*queueSize+0.5)/buffSize; - (*my->evtbuildBuff[i]) = fillLevel; - } - } - - t_0 = t; -} + /* Add statistic for fill levels of buffers in percentage. */ -static void statsBufferDump (TheArgs *theArgs, TheStats *my, float interval, - HadTuQueue **htuq, ShmTrans **shmtr, char *progName) -{ - static unsigned long lastEC2; - static unsigned long lastBW2; - - static time_t t0 = 0; - time_t t, dT; - int i, j; - int col = 0; - char emptybuffer[] = "-"; - int outputGraph = 1; - int outputNum = 0; - - if (theArgs->isStandalone && theArgs->buffStat) { - - t = time (NULL); - dT = t - t0; - - if (dT >= interval) { - - if( outputNum == 1) { - fputs("==============================================================================\n\n",stderr); - - for(i=0; inrOfMsgs; i++) { - - fprintf (stderr, "q[%2d]: ", i); - if (!HadTuQueue_empty(shmtr[i]->rdQueue)) - fprintf (stderr, "%8d ", HadTuQueue_size(shmtr[i]->rdQueue)); - else - fprintf (stderr, "%8s ", emptybuffer); - - col++; - if (col == 6) { - fputc ('\n', stderr); - col = 0; - } - } - } - if( outputGraph == 1 ){ - fputs ("------------------ buffer fill levels ----------------------------------------\n", stderr); - + static time_t t_0 = 0; float buffSize, queueSize; - int maxnorm = 10.; - - for( j=0; jnrOfMsgs; i++ ){ - buffSize = 2*theArgs->varQSize[i]; - queueSize = HadTuQueue_size(shmtr[i]->rdQueue); - - if(maxnorm - maxnorm*queueSize/buffSize < j){ - if (!HadTuQueue_empty(shmtr[i]->rdQueue)) - fputc( '|', stderr ); - else - fputc( '-', stderr ); - - } - else{ - fputc( ' ', stderr ); - } - } - fputc( '\n', stderr ); - } - - /* The following is just to print the numbers of buffers*/ - int factor, mod; - - fputs( "q:", stderr ); - factor = 0; - for( i=0; inrOfMsgs; i++ ) { - mod = i%10; - fprintf (stderr, "%1d", mod); - } - fputc( '\n', stderr ); - - fputs( " ", stderr ); - for( i=0; inrOfMsgs; i++ ) { - mod = i%10; - if( mod == 0 ) - fprintf (stderr, "%1d", i/10 ); - else - fputc( ' ', stderr ); - } - fputc( '\n', stderr ); - fputs( "------------------------------------------------------------------------------\n", stderr ); - - /* Print Trigger Numbers for all queues */ - char trigNum[theArgs->nrOfMsgs][10]; - - for( i=0; i < theArgs->nrOfMsgs; i++ ) { - sprintf( trigNum[i], "%08x", *my->trigNr[i] ); - } - - for( j=0; j < 8; j++ ) { - fputc (' ', stderr); - fputc (' ', stderr); - for( i=0; i < theArgs->nrOfMsgs; i++ ) { - fprintf (stderr, "%c", trigNum[i][j]); - } - fputc ('\n', stderr); - } - fputs( "------------------------------------------------------------------------------\n", stderr ); - - fprintf (stderr, "%7s:%6s", "evtComp", - unit (*my->evtsComplete)); - if( dT > 0 ) - fprintf (stderr, "%10s:%6s", " evtComp/s", - unit ((*my->evtsComplete - lastEC2) / dT)); - fprintf (stderr, "%10s:%6s", " bytesWrit", - unit (*my->bytesWritten)); - if( dT > 0 ) - fprintf (stderr, "%12s:%6s", " bytesWrit/s", - unit ((*my->bytesWritten - lastBW2) / dT)); - fputc ('\n', stderr); - fprintf (stderr, "%7s:%6s", "evtDisc", - unit (*my->evtsDiscarded)); - fprintf (stderr, "%10s:%6s", " evtDatErr", - unit (*my->evtsDataError)); - fprintf (stderr, "%10s:%6s", " evtTagErr", - unit (*my->evtsTagError)); - - fputc ('\n', stderr); - - lastEC2 = *my->evtsComplete; - lastBW2 = *my->bytesWritten; - - /* get wall-clock time */ - printTime(); - - unsigned long runId2print; - char buf[_POSIX_PATH_MAX]; - sprintf( buf, "%s%s", progName, theArgs->shmname ); - Worker_getStatistic( buf, "runId", &runId2print); - printf("ioc: RUN Id = %lu RUN Nr = %lu\n", runId2print, runNr); - } - } - - t0 = t; - } + time_t t, dT; + int i; + unsigned long fillLevel; + + t = time(NULL); + dT = t - t_0; + + if (dT >= interval) { + for (i = 0; i < theArgs->nrOfMsgs; i++) { + buffSize = 2 * theArgs->varQSize[i]; + queueSize = HadTuQueue_size(shmtr[i]->rdQueue); + + /* Add here statistic for fill levels of buffers */ + fillLevel = (unsigned long) (100 * queueSize + 0.5) / buffSize; + (*my->evtbuildBuff[i]) = fillLevel; + } + } + + t_0 = t; } -unsigned long getRunId( TheArgs *my ) +static void statsBufferDump(TheArgs *theArgs, TheStats *my, float interval, HadTuQueue **htuq, ShmTrans **shmtr, char *progName) { - unsigned long myRunId = 0; - struct timespec tv = { 0, 1e+8 }; - - while( my->epicsCtrl && myRunId == 0 ) { - if( Worker_getStatistic( "daq_evtbuild", "runId", &myRunId) == -1 ) { - fprintf( stderr, " evtbuild.c: getRunId: Worker_getStatistic: cannot get runId!" ); - sleep(1); - } - else { - - if( myRunId == 0 ) - nanosleep( &tv, NULL ); - } - - } - - return myRunId; + static unsigned long lastEC2; + static unsigned long lastBW2; + + static time_t t0 = 0; + time_t t, dT; + int i, j; + int col = 0; + char emptybuffer[] = "-"; + int outputGraph = 1; + int outputNum = 0; + + if (theArgs->isStandalone && theArgs->buffStat) { + + t = time(NULL); + dT = t - t0; + + if (dT >= interval) { + + if (outputNum == 1) { + fputs("==============================================================================\n\n", stderr); + + for (i = 0; i < theArgs->nrOfMsgs; i++) { + + fprintf(stderr, "q[%2d]: ", i); + if (!HadTuQueue_empty(shmtr[i]->rdQueue)) + fprintf(stderr, "%8d ", HadTuQueue_size(shmtr[i]->rdQueue)); + else + fprintf(stderr, "%8s ", emptybuffer); + + col++; + if (col == 6) { + fputc('\n', stderr); + col = 0; + } + } + } + if (outputGraph == 1) { + fputs("------------------ buffer fill levels ----------------------------------------\n", stderr); + + float buffSize, queueSize; + int maxnorm = 10.; + + for (j = 0; j < maxnorm; j++) { + fprintf(stderr, "%1d ", maxnorm - j - 1); + for (i = 0; i < theArgs->nrOfMsgs; i++) { + buffSize = 2 * theArgs->varQSize[i]; + queueSize = HadTuQueue_size(shmtr[i]->rdQueue); + + if (maxnorm - maxnorm * queueSize / buffSize < j) { + if (!HadTuQueue_empty(shmtr[i]->rdQueue)) + fputc('|', stderr); + else + fputc('-', stderr); + + } else { + fputc(' ', stderr); + } + } + fputc('\n', stderr); + } + + /* The following is just to print the numbers of buffers */ + int factor, mod; + + fputs("q:", stderr); + factor = 0; + for (i = 0; i < theArgs->nrOfMsgs; i++) { + mod = i % 10; + fprintf(stderr, "%1d", mod); + } + fputc('\n', stderr); + + fputs(" ", stderr); + for (i = 0; i < theArgs->nrOfMsgs; i++) { + mod = i % 10; + if (mod == 0) + fprintf(stderr, "%1d", i / 10); + else + fputc(' ', stderr); + } + fputc('\n', stderr); + fputs("------------------------------------------------------------------------------\n", stderr); + + /* Print Trigger Numbers for all queues */ + char trigNum[theArgs->nrOfMsgs][10]; + + for (i = 0; i < theArgs->nrOfMsgs; i++) { + sprintf(trigNum[i], "%08x", *my->trigNr[i]); + } + + for (j = 0; j < 8; j++) { + fputc(' ', stderr); + fputc(' ', stderr); + for (i = 0; i < theArgs->nrOfMsgs; i++) { + fprintf(stderr, "%c", trigNum[i][j]); + } + fputc('\n', stderr); + } + fputs("------------------------------------------------------------------------------\n", stderr); + + fprintf(stderr, "%7s:%6s", "evtComp", unit(*my->evtsComplete)); + if (dT > 0) + fprintf(stderr, "%10s:%6s", " evtComp/s", unit((*my->evtsComplete - lastEC2) / dT)); + fprintf(stderr, "%10s:%6s", " bytesWrit", unit(*my->bytesWritten)); + if (dT > 0) + fprintf(stderr, "%12s:%6s", " bytesWrit/s", unit((*my->bytesWritten - lastBW2) / dT)); + fputc('\n', stderr); + fprintf(stderr, "%7s:%6s", "evtDisc", unit(*my->evtsDiscarded)); + fprintf(stderr, "%10s:%6s", " evtDatErr", unit(*my->evtsDataError)); + fprintf(stderr, "%10s:%6s", " evtTagErr", unit(*my->evtsTagError)); + + fputc('\n', stderr); + + lastEC2 = *my->evtsComplete; + lastBW2 = *my->bytesWritten; + + /* get wall-clock time */ + printTime(); + + unsigned long runId2print; + char buf[_POSIX_PATH_MAX]; + sprintf(buf, "%s%s", progName, theArgs->shmname); + Worker_getStatistic(buf, "runId", &runId2print); + printf("ioc: RUN Id = %lu RUN Nr = %lu\n", runId2print, runNr); + } + } + + t0 = t; + } } -static void statsDump (TheArgs * theArgs, TheStats * my, int interval) +unsigned long getRunId(TheArgs *my) { - static unsigned long lastEC; - static unsigned long lastEE; - static unsigned long lastTE; - static unsigned long lastED; - static unsigned long lastBW; - static time_t t0 = 0; - time_t t, dT; - int i; - - if (theArgs->isStandalone && strcmp (theArgs->verbosity, "info") == 0 && - !(theArgs->buffStat)) - { - t = time (NULL); - dT = t - t0; - if (dT >= interval) - { - int col = 0; - - fputs - ("==============================================================================\n", - stderr); - fprintf (stderr, "%19s:%6s", "evtsComplete ", - unit (*my->evtsComplete)); - fprintf (stderr, "%19s:%6s", "evtsDiscarded ", - unit (*my->evtsDiscarded)); - fprintf (stderr, "%19s:%6s", "bytesWritten ", - unit (*my->bytesWritten)); - fputc ('\n', stderr); - fprintf (stderr, "%19s:%6s", "evtsDataError ", - unit (*my->evtsDataError)); - fprintf (stderr, "%19s:%6s", "evtsTagError ", - unit (*my->evtsTagError)); - fputc ('\n', stderr); - - if ( dT > 0 ){ - fprintf (stderr, "%19s:%6s", "evtsComplete/s", - unit ((*my->evtsComplete - lastEC) / dT)); - fprintf (stderr, "%19s:%6s", "evtsDiscarded/s", - unit ((*my->evtsDiscarded - lastED) / dT)); - fprintf (stderr, "%19s:%6s", "bytesWritten/s", - unit ((*my->bytesWritten - lastBW) / dT)); - fputc ('\n', stderr); - fprintf (stderr, "%19s:%6s", "evtsDataError/s", - unit ((*my->evtsDataError - lastEE) / dT)); - fprintf (stderr, "%19s:%6s", "evtsTagError/s", - unit ((*my->evtsTagError - lastTE) / dT)); - fputc ('\n', stderr); - } - - lastEC = *my->evtsComplete; - lastEE = *my->evtsDataError; - lastTE = *my->evtsTagError; - lastED = *my->evtsDiscarded; - lastBW = *my->bytesWritten; - - fputs - ("------------------------------------------------------------------------------\n", - stderr); - col = 0; - for (i = 0; i < NEVTIDS; i++) - { - if (*my->evtId[i] != 0) - { - fprintf (stderr, "%17s%02x:%6s", "evtId", i, - unit (*my->evtId[i])); - if (++col == 3) - { - fputc ('\n', stderr); - col = 0; - } + unsigned long myRunId = 0; + struct timespec tv = { 0, 1e+8 }; + + while (my->epicsCtrl && myRunId == 0) { + if (Worker_getStatistic("daq_evtbuild", "runId", &myRunId) == -1) { + fprintf(stderr, " evtbuild.c: getRunId: Worker_getStatistic: cannot get runId!"); + sleep(1); + } else { + + if (myRunId == 0) + nanosleep(&tv, NULL); } - } - if (col != 0) - { - fputc ('\n', stderr); - } - col = 0; - - fputs - ("------------------------------------------------------------------------------\n", - stderr); - for (i = 0; i < theArgs->nrOfMsgs; i++) - { - fprintf (stderr, "%12s%02d: 0x%08x", "trigNr", i, - *my->trigNr[i]); - if (++col == 3) - { - fputc ('\n', stderr); - col = 0; + + } + + return myRunId; +} + +static void statsDump(TheArgs *theArgs, TheStats *my, int interval) +{ + static unsigned long lastEC; + static unsigned long lastEE; + static unsigned long lastTE; + static unsigned long lastED; + static unsigned long lastBW; + static time_t t0 = 0; + time_t t, dT; + int i; + + if (theArgs->isStandalone && strcmp(theArgs->verbosity, "info") == 0 && !(theArgs->buffStat)) { + t = time(NULL); + dT = t - t0; + if (dT >= interval) { + int col = 0; + + fputs("==============================================================================\n", stderr); + fprintf(stderr, "%19s:%6s", "evtsComplete ", unit(*my->evtsComplete)); + fprintf(stderr, "%19s:%6s", "evtsDiscarded ", unit(*my->evtsDiscarded)); + fprintf(stderr, "%19s:%6s", "bytesWritten ", unit(*my->bytesWritten)); + fputc('\n', stderr); + fprintf(stderr, "%19s:%6s", "evtsDataError ", unit(*my->evtsDataError)); + fprintf(stderr, "%19s:%6s", "evtsTagError ", unit(*my->evtsTagError)); + fputc('\n', stderr); + + if (dT > 0) { + fprintf(stderr, "%19s:%6s", "evtsComplete/s", unit((*my->evtsComplete - lastEC) / dT)); + fprintf(stderr, "%19s:%6s", "evtsDiscarded/s", unit((*my->evtsDiscarded - lastED) / dT)); + fprintf(stderr, "%19s:%6s", "bytesWritten/s", unit((*my->bytesWritten - lastBW) / dT)); + fputc('\n', stderr); + fprintf(stderr, "%19s:%6s", "evtsDataError/s", unit((*my->evtsDataError - lastEE) / dT)); + fprintf(stderr, "%19s:%6s", "evtsTagError/s", unit((*my->evtsTagError - lastTE) / dT)); + fputc('\n', stderr); + } + + lastEC = *my->evtsComplete; + lastEE = *my->evtsDataError; + lastTE = *my->evtsTagError; + lastED = *my->evtsDiscarded; + lastBW = *my->bytesWritten; + + fputs("------------------------------------------------------------------------------\n", stderr); + col = 0; + for (i = 0; i < NEVTIDS; i++) { + if (*my->evtId[i] != 0) { + fprintf(stderr, "%17s%02x:%6s", "evtId", i, unit(*my->evtId[i])); + if (++col == 3) { + fputc('\n', stderr); + col = 0; + } + } + } + if (col != 0) { + fputc('\n', stderr); + } + col = 0; + + fputs("------------------------------------------------------------------------------\n", stderr); + for (i = 0; i < theArgs->nrOfMsgs; i++) { + fprintf(stderr, "%12s%02d: 0x%08x", "trigNr", i, *my->trigNr[i]); + if (++col == 3) { + fputc('\n', stderr); + col = 0; + } + } + if (col != 0) { + fputc('\n', stderr); + } + t0 = t; } - } - if (col != 0) - { - fputc ('\n', stderr); - } - t0 = t; - } - } + } } static void storeRunInfoStart(time_t t, TheArgs *myArgs) { - /* open ascii file eb_runinfo2ora.txt to store simple information for - the started RUN. The format: start