-static char *rcsId = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hadaq/evtbuild.c,v 6.124 2010-07-30 09:18:59 hadaq Exp $";
+static char *rcsId = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hadaq/evtbuild.c,v 6.125 2010-08-04 09:16:09 hadaq Exp $";
#define _POSIX_C_SOURCE 199309L
#define SYSLOG_NAMES
#include <sys/stat.h>
#include <sys/vfs.h>
#include <sys/time.h>
+#include <sys/utsname.h>
#include <time.h>
#include <dirent.h>
#define MAXINPATH 100
#define DAQVERSION 2 /* needed by Hydra unpackers */
+
#define NEVTIDS 64UL /* must be 2^n */
#define NEVTIDS_IN_FILE 0UL /* must be 2^n */
#define EVENT_NUM_OFFSET 100
static int evtBrokenFlag = 0;
+static char msglog[300];
+
typedef struct TheArgsS {
unsigned long nrOfMsgs;
char outPath[PARAM_MAX_VALUE_LEN];
char shmname[PARAM_MAX_VALUE_LEN];
unsigned int ebnum;
char runinfo2ora[PARAM_MAX_VALUE_LEN];
- char evtstat[PARAM_MAX_VALUE_LEN]; /* file name for statistics of discarded event */
+ char logname[PARAM_MAX_VALUE_LEN]; /* file name for statistics of discarded event */
char fileName[PARAM_MAX_VALUE_LEN];
unsigned short multiDisks; /* Write files to diferent disks */
unsigned long maxTrigMissmatch;
+ char hostname[PARAM_MAX_VALUE_LEN];
} TheArgs;
typedef struct TheStatsS {
syslog(LOG_ERR, " [--ebnum num] Number of the event builder.");
}
+static void storeLogInfo(TheArgs *theArgs, const char *msg)
+{
+
+ FILE *fp;
+ char ltime[20]; /* local time */
+ time_t t = time(NULL);
+ strftime(ltime, 20, "%b %02d %02H:%02M:%02S", localtime(&t));
+
+ fp = fopen(theArgs->logname, "a+");
+ fprintf(fp, "%s %10s %s %2s %13s %s\n", ltime, theArgs->hostname, "EB", theArgs->shmname, "daq_evtbuild:", msg);
+ fclose(fp);
+}
+
static int makeTrigType(TheArgs *my)
{
int retVal = 0;
for (i = 0; i < my->queueVarSizeCnt; i++) {
if (0 == (sscanf(my->queueVarSize[i], "%d:%s", &queueNum, newQueueSize))) {
+ storeLogInfo(my, "<E> makeQueues: queueVarSize option is wrong.");
syslog(LOG_ERR, "evtbuild.c: makeQueues: %s", "queueVarSize option is wrong.");
retVal = -1;
break;
} else {
if (queueNum >= my->nrOfMsgs) {
+ storeLogInfo(my, "<E> makeQueues: queue number in queueVarSize option exceeds maximum number of data sources.");
syslog(LOG_ERR, "evtbuild.c: makeQueues: %s",
"queue number in queueVarSize option exceeds maximum number of data sources.");
retVal = -1;
/* read path from DAQ_SETUP and define full file name */
sprintf(my->runinfo2ora, "%s_runinfo2ora.txt", getenv("DAQ_SETUP"));
- sprintf(my->evtstat, "%s_evtstat.txt", getenv("DAQ_SETUP"));
+ sprintf(my->logname, "%s%s_log.txt", getenv("DAQ_SETUP"), my->shmname);
my->multiDisks = 0; /* Write files only on one disk */
my->debugOptsCnt = 0;
my->maxTrigMissmatch = 100000;
+
+ /* Get host name */
+ gethostname(my->hostname, 30);
}
static int argsFromCL(TheArgs *my, int argc, char *argv[])
break;
}
}
+
if (optind < argc) {
printf("non-option ARGV-elements: ");
while (optind < argc)
printf("\n");
}
+ sprintf(my->logname, "%s%s_log.txt", getenv("DAQ_SETUP"), my->shmname);
+
return 0;
}
/* check my->maxFileSz */
if ((strcmp(my->outDev, "null") != 0) && (my->maxFileSz <= 0 || my->maxFileSz >= 2 * 1024 * 1024 * 1024UL)) {
- fprintf(stderr, "<E> evtbuild.c, argsCheck(): --filesize must be >0MB and <2000MB\n");
+ storeLogInfo(my, "<E> argsCheck: --filesize must be >0MB and <2000MB.");
+ fprintf(stderr, "<E> evtbuild.c, argsCheck: --filesize must be >0MB and <2000MB\n");
return 1;
}
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,
- "<E> evtbuild.c, argsCheck(): options --resdownscale --resnumevents --respath must be specified together\n");
+ storeLogInfo(my, "<E> argsCheck: options --resdownscale --resnumevents --respath must be specified together.");
+ fprintf(stderr, "<E> 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, "<E> evtbuild.c, argsCheck(): --resdownscale must be >0 and <100001\n");
+ if ((strcmp(my->respath, "") != 0) && (my->resdownscale <= 0 || my->resdownscale > 100000)) {
+ storeLogInfo(my, "<E> argsCheck: --resdownscale must be >0 and <=100000.");
+ fprintf(stderr, "<E> evtbuild.c, argsCheck: --resdownscale must be >0 and <=100000\n");
return 1;
}
/* check my->resnumevents */
- if ((strcmp(my->respath, "") != 0) && (my->resnumevents <= 99 || my->resnumevents >= 1000000001)) {
- fprintf(stderr, "<E> evtbuild.c, argsCheck(): --resnumevents must be >99 and <1000000001\n");
+ if ((strcmp(my->respath, "") != 0) && (my->resnumevents <= 99 || my->resnumevents > 1000000000)) {
+ storeLogInfo(my, "<E> argsCheck: --resnumevents must be >99 and <=1000000000.");
+ fprintf(stderr, "<E> evtbuild.c, argsCheck: --resnumevents must be >99 and <=1000000000\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, "<E> evtbuild.c, argsCheck(): --secsizelimit must be >10 and <100000 MB\n");
+ (my->secsizelimit <= -0.0001 || my->secsizelimit >= 0.0001) && (my->secsizelimit <= 10 || my->secsizelimit > 100000)) {
+ storeLogInfo(my, "<E> argsCheck: --secsizelimit must be >10 and <=100000 MB.");
+ fprintf(stderr, "<E> 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, "<E> evtbuild.c, argsCheck(): --ressizelimit must be >5 and <1000\n");
+ storeLogInfo(my, "<E> argsCheck: --ressizelimit must be >5 and <1000.");
+ fprintf(stderr, "<E> evtbuild.c, argsCheck: --ressizelimit must be >5 and <1000\n");
return 1;
}
if (((my->maxFileSz) < (my->queueSize[0]))) {
+ storeLogInfo(my, "<E> argsCheck: --filesize must be larger than queuesize(-q).");
+ storeLogInfo(my, "<W> argsCheck: the queue size must be given in MBytes.");
fprintf(stderr, "<E> evtbuild.c, argsCheck(): --filesize must be larger than queuesize(-q)\n");
fprintf(stderr, "<W> evtbuild.c, argsCheck(): the queue size must be given in MBytes\n");
return 1;
/* the condition ressizelimit has to be together with respath */
if ((my->ressizelimit) != 0 && (strcmp(my->respath, "") == 0)) {
+ storeLogInfo(my, "<E> argsCheck: --respath is not given.");
fprintf(stderr, "<E> evtbuild.c, argsCheck(): --respath is not given\n");
return 1;
}
/* Check queue sizes */
if (1 * 1024 * 1024 * 1024UL < (my->queueSize[0])) {
+ storeLogInfo(my, "<W> argsCheck: the queue size must be given in MBytes.");
fprintf(stderr, "<W> evtbuild.c, argsCheck(): the queue size must be given in MBytes\n");
return 1;
}
} else if (strcmp(my->debugOpts[i], "size") == 0) {
my->debug_size = 1;
} else {
+ storeLogInfo(my, "<E> wrong argument is given in the option -D|--debug.");
printf("Error: wrong argument is given in the option -D|--debug.\n");
return 1;
}
}
} else {
printf("fillDebug: Event has unknown status!\n");
+ storeLogInfo(theArgs, "<E> fillDebug: Event has unknown status!");
}
evtBrokenFlag = 1;
{
int i;
+ storeLogInfo(theArgs, "<E> trigger missmatch is too large. Exit.");
+
printf("\n\n");
fprintf(stderr, "<E> daq_evtbuild: trigger missmatch is above %d.\n", theArgs->maxTrigMissmatch);
{
int i;
+ storeLogInfo(theArgs, "<E> trigger missmatch is too large. Exit.");
+
printf("\n\n");
fprintf(stderr, "<E> daq_evtbuild: trigger missmatch is above %d.\n", theArgs->maxTrigMissmatch);
printf("\n");
if (Worker_getStatistic(buf, "runId", &myRunId) == -1) {
fprintf(stderr, "<E> evtbuild.c: getRunId: Worker_getStatistic: cannot get runId!\n");
+ storeLogInfo(my, "<N> getRunId: Worker_getStatistic: cannot get runId yet!");
sleep(1);
} else {
t = time(NULL);
dT = t - t0;
if (dT > 2) {
+ storeLogInfo(my, "<I> getRunId: Still waiting for runId from EPICS IOC...");
printf("Still waiting for runId from EPICS IOC...\n");
t0 = t;
}
return myRunId;
}
-static void storeEvtStat(TheArgs *myArgs, unsigned long evtstat)
-{
-
- FILE *fp;
- char ltime[20]; /* local time */
- time_t t = time(NULL);
- strftime(ltime, 20, "%Y-%m-%d %H:%M:%S", localtime(&t));
-
- fp = fopen(myArgs->evtstat, "a+");
- fprintf(fp, "%s %d %s %d %d %d\n", "daq_evtbuild:", (int) getpid(), ltime, myArgs->runNr, myArgs->ebnum, evtstat);
- fclose(fp);
-}
-
static void statsDump(TheArgs *theArgs, TheStats *my, int interval)
{
+
static unsigned long lastEC = 0;
static unsigned long lastEE = 0;
static unsigned long lastTE = 0;
fputc('\n', stderr);
}
- if (*my->evtsDiscarded - lastED > 0)
- storeEvtStat(theArgs, *my->evtsDiscarded - lastED);
+ if (*my->evtsDiscarded - lastED > 0) {
+ sprintf(msglog, "<W> discarded events: %d", *my->evtsDiscarded - lastED);
+ storeLogInfo(theArgs, msglog);
+ }
lastEC = *my->evtsComplete;
lastEE = *my->evtsDataError;
if (Worker_getStatistic(buf, "diskNum", &diskNr) == -1) {
diskNr = 0;
+ storeLogInfo(theArgs, "<E> ChangeDisk: Worker_getStatistic failed for diskNum!");
syslog(LOG_ERR, "Worker_getStatistic failed for diskNum!");
}
static int openFile(TheArgs *theArgs, TheStats *theStats)
{
-
char fileName[_POSIX_PATH_MAX];
static char outPath[_POSIX_PATH_MAX];
static char outLustrePath[_POSIX_PATH_MAX];
}
if (NULL == (outFile = fopen(theArgs->outPath, "wb"))) {
+ sprintf(msglog, "<E> %s, %d: fopen: failed to open file %s: %s", __FILE__, __LINE__, theArgs->outPath, strerror(errno));
+ storeLogInfo(theArgs, msglog);
syslog(LOG_ERR, "opening file %s: %s", theArgs->outPath, strerror(errno));
outFile = NULL;
return -1;
errno = ENOSPC;
outFile = NULL;
unlink(theArgs->outPath);
+
+ sprintf(msglog, "<E> %s, %d: no space left to open new file %s: %s", __FILE__, __LINE__, theArgs->outPath,
+ strerror(errno));
+ storeLogInfo(theArgs, msglog);
syslog(LOG_ERR, "opening file %s: %s", theArgs->outPath, strerror(errno));
return -1;
}
return -1;
}
} else {
+ sprintf(msglog, "<E> %s, %d: unknown outputDev %s", __FILE__, __LINE__, theArgs->outDev);
+ storeLogInfo(theArgs, msglog);
syslog(LOG_ERR, "unknown outputDev \"%s\"", theArgs->outDev);
return -1;
}
fprintf(stderr, "<D> evtbuild.c, rfio_fnewfile(): trying to open remote file %s\n", rfioPath);
if (0 != rfio_fnewfile(fRemote, rfioPath)) {
- syslog(LOG_ERR, "%s, %d: cannot open remote file %s: %s", __FILE__, __LINE__, rfioPath, strerror(errno));
+ sprintf(msglog, "<E> %s, %d: rfio_fnewfile: failed to open file %s: %s", __FILE__, __LINE__, rfioPath, strerror(errno));
+ storeLogInfo(theArgs, msglog);
+ syslog(LOG_ERR, "%s, %d: rfio_fnewfile: failed to open remote file %s: %s", __FILE__, __LINE__, rfioPath,
+ strerror(errno));
exit(EXIT_FAILURE);
}
}
outRESFile = NULL;
if (NULL == (outRESFile = fopen(theArgs->respath, "wb"))) {
- syslog(LOG_ERR, "%s, %d: opening file %s: %s", __FILE__, __LINE__, theArgs->respath, strerror(errno));
+ sprintf(msglog, "<E> %s, %d: openRESFile: failed to open file %s: %s", __FILE__, __LINE__, theArgs->respath,
+ strerror(errno));
+ storeLogInfo(theArgs, msglog);
+ syslog(LOG_ERR, "%s, %d: failed to open file %s: %s", __FILE__, __LINE__, theArgs->respath, strerror(errno));
outRESFile = NULL;
return -1;
} else {
if ((theArgs->maxFileSz) / buf->f_bsize > buf->f_bavail) {
errno = ENOSPC;
if (0 != fclose(outRESFile)) {
- syslog(LOG_ERR, "%s, %d: trying fclose 'outRESFile': %s", __FILE__, __LINE__, strerror(errno));
+ sprintf(msglog, "<E> %s, %d: openRESFile: failed to close file: %s", __FILE__, __LINE__, strerror(errno));
+ storeLogInfo(theArgs, msglog);
+ syslog(LOG_ERR, "%s, %d: failed to fclose 'outRESFile': %s", __FILE__, __LINE__, strerror(errno));
}
outRESFile = NULL;
unlink(theArgs->respath);
- syslog(LOG_ERR, "%s, %d: opening file %s: %s", __FILE__, __LINE__, theArgs->respath, strerror(errno));
+ sprintf(msglog, "<E> %s, %d: openRESFile: failed to open file: %s", __FILE__, __LINE__, strerror(errno));
+ storeLogInfo(theArgs, msglog);
+ syslog(LOG_ERR, "%s, %d: failed to open file %s: %s", __FILE__, __LINE__, theArgs->respath, strerror(errno));
return -1;
}
}
return 0;
}
-static int writeFile(void *evt)
+static int writeFile(TheArgs *theArgs, void *evt)
{
-
int writeFileR;
Evt_setSeqNr(evt, seqNr++);
#ifdef RFIO
/* write to Data Mover via RFIO */
if (fRemote != NULL) {
- if (0 >= rfio_fwrite(evt, 1, Evt_paddedSize(evt), fRemote))
- syslog(LOG_ERR, "%s, %d: writing file via RFIO: %s", __FILE__, __LINE__, strerror(errno));
+ if (0 >= rfio_fwrite(evt, 1, Evt_paddedSize(evt), fRemote)) {
+ sprintf(msglog, "<E> %s, %d: rfio_fwrite: failed to write: %s", __FILE__, __LINE__, strerror(errno));
+ storeLogInfo(theArgs, msglog);
+ syslog(LOG_ERR, "%s, %d: failed to write file via RFIO: %s", __FILE__, __LINE__, strerror(errno));
+ }
}
#endif
return writeFileR;
}
-static int closeFile()
+static int closeFile(TheArgs *theArgs)
{
int closeFileR;
int closeLustreFileR;
if (outFile != NULL) {
closeFileR = fclose(outFile);
if (0 != closeFileR) {
- syslog(LOG_ERR, "%s, %d: trying fclose 'outFile': %s", __FILE__, __LINE__, strerror(errno));
+ sprintf(msglog, "<E> %s, %d: closeFile: failed to close file: %s", __FILE__, __LINE__, strerror(errno));
+ storeLogInfo(theArgs, msglog);
+ syslog(LOG_ERR, "%s, %d: failed to fclose 'outFile': %s", __FILE__, __LINE__, strerror(errno));
}
} else if (outTape != NULL) {
closeFileR = closeAnsiTape(outTape);
/* close file on Data Mover */
if (fRemote != NULL) {
if (0 != rfio_fendfile(fRemote)) {
+ sprintf(msglog, "<E> %s, %d: rfio_fendfile: failed to close file: %s", __FILE__, __LINE__, strerror(errno));
+ storeLogInfo(theArgs, msglog);
syslog(LOG_ERR, "%s, %d: trying rfio_fendfile: %s", __FILE__, __LINE__, strerror(errno));
exit(EXIT_FAILURE);
}
res_dirSize += res_file_size;
closeFileR = fclose(outRESFile);
if (0 != closeFileR) {
+ sprintf(msglog, "<E> %s, %d: closeRESFile: failed to close file: %s", __FILE__, __LINE__, strerror(errno));
+ storeLogInfo(theArgs, msglog);
syslog(LOG_ERR, "%s, %d: trying fclose 'outRESFile': %s", __FILE__, __LINE__, strerror(errno));
}
} else {
+ sprintf(msglog, "<E> %s, %d: closeRESFile: outRESFile is NULL: %s", __FILE__, __LINE__, theArgs->respath, strerror(errno));
+ storeLogInfo(theArgs, msglog);
syslog(LOG_ERR, "%s, %d: closeRESFile failed: outRESFile is NULL", __FILE__, __LINE__);
}
strncpy(pcc, "\0", 1); /* terminates after node name */
fprintf(stderr, "<I> evtbuild.c, rfio_fopen(): trying to open connection to Data Mover: %s\n", rfioBase);
+ sprintf(msglog, "<I> rfio_fopen: opening connection to Data Mover: %s", rfioBase);
+ storeLogInfo(theArgs, msglog);
/* fRemote = rfio_fopen( rfioBase, "wb" ); */
char pcDataMover[16]; /* name of the Data Mover */
theArgs->rfio_iCopyFrac, theArgs->rfio_iMaxFile, theArgs->rfio_iPathConv);
if (fRemote == NULL) {
- syslog(LOG_ERR, "%s, %d: trying to open connection to Data Mover %s: %s",
+ sprintf(msglog, "<E> %s, %d: rfio_fopen_gsidaq_dm: failed to open connection to Data Mover %s: %s", __FILE__, __LINE__,
+ rfioBase, strerror(errno));
+ storeLogInfo(theArgs, msglog);
+ syslog(LOG_ERR, "%s, %d: rfio_fopen_gsidaq_dm: failed to open connection to Data Mover %s: %s",
__FILE__, __LINE__, rfioBase, strerror(errno));
exit(EXIT_FAILURE);
}
if ((strcmp(theArgs->rfioRemotePath, "") != 0) && fRemote != NULL) {
if (0 != rfio_fclose(fRemote)) {
- syslog(LOG_ERR, "%s, %d: trying to close connection to Data Mover: %s", __FILE__, __LINE__, strerror(errno));
+ sprintf(msglog, "<E> %s, %d: rfio_fclose: failed to close connection to Data Mover: %s", __FILE__, __LINE__,
+ strerror(errno));
+ storeLogInfo(theArgs, msglog);
+ syslog(LOG_ERR, "%s, %d: rfio_fclose: failed to close connection to Data Mover: %s", __FILE__, __LINE__,
+ strerror(errno));
exit(EXIT_FAILURE);
}
}
exit(EXIT_FAILURE);
}
+ storeLogInfo(theArgs, "<I> started.");
+
if (0 > makeQueues(theArgs)) {
usage(argv[0]);
exit(EXIT_FAILURE);
sprintf(buf, "%s%s", argv[0], theArgs->shmname);
if (NULL == (worker = Worker_initBegin(buf, sigHandler, theArgs->priority, theArgs->isStandalone))) {
+ sprintf(msglog, "<E> %s, %d: Worker_initBegin: failed to init: %s", __FILE__, __LINE__, strerror(errno));
+ storeLogInfo(theArgs, msglog);
syslog(LOG_ERR, "%s, %d: %s", __FILE__, __LINE__, strerror(errno));
exit(EXIT_FAILURE);
}
if (theArgs->online == 0)
syslog(LOG_WARNING, "DISABLE of online service");
- else if (-1 == initOnline())
+ else if (-1 == initOnline()) {
syslog(LOG_WARNING, "unable to initialize online service");
+ sprintf(msglog, "<E> %s, %d: initOnline: failed to init online service: %s", __FILE__, __LINE__, strerror(errno));
+ storeLogInfo(theArgs, msglog);
+ }
if (theArgs->nrOfMsgs == 0) {
/*
shmTrans[i] = ShmTrans_create(buf, 2 * theArgs->queueSize[i]);
if (shmTrans[i] == NULL) {
- fprintf(stderr, "<E> ShmTrans_create: could not create buffer /dev/shm/%s.shm\n", buf);
+ sprintf(msglog, "<E> %s, %d: ShmTrans_create: failed to create buffer /dev/shm/%s.shm: %s", __FILE__, __LINE__, buf,
+ strerror(errno));
+ storeLogInfo(theArgs, msglog);
+ fprintf(stderr, "<E> ShmTrans_create: failed to create buffer /dev/shm/%s.shm\n", buf);
}
hadTuQueue[i] = NULL;
}
(*theStats->bytesWritten) += Evt_size(evt);
- writeFile(evt);
+ writeFile(theArgs, evt);
deleteEvt(evt);
}
popCnt++;
if (popCnt > theArgs->maxTrigMissmatch) {
- fprintf(stderr, "<E> daq_evtbuild: trigger missmatch is above %d. Exit.\n", theArgs->maxTrigMissmatch);
printPopTrigMissmatch(theArgs, theStats, theDebug, i);
goto bailOut1;
}
#endif
}
(*theStats->bytesWritten) += Evt_size(evt);
- writeFile(evt);
+ writeFile(theArgs, evt);
if (theArgs->resdownscale) {
evt = appendFile(evt, theArgs->slowCtrlFiles[i]);
(*theStats->bytesWritten) += Evt_size(evt);
- writeFile(evt);
+ writeFile(theArgs, evt);
deleteEvt(evt);
/* if( theArgs->epicsCtrl ) */
/* else */
ourTime = time(NULL);
- closeFile();
+ closeFile(theArgs);
storeInfoStop(argv[0], ourTime, worker, theArgs);
bailOut1:
+ storeLogInfo(theArgs, "<I> exited.");
+
ourTime = time(NULL);
- closeFile();
+ closeFile(theArgs);
#ifdef RFIO
rfio_closeConnection(theArgs);