From e522c7ec6bbfaa9d0b27156d7452db72f96af79a Mon Sep 17 00:00:00 2001 From: hades Date: Tue, 10 Oct 2000 10:33:38 +0000 Subject: [PATCH] join with new-evtbuild-branch Supposed to be downward compatible --- hadaq/evt.c | 40 +++++++++++++-- hadaq/evt.h | 6 ++- hadaq/evtbuild.c | 131 ++++++++++++++++++----------------------------- hadaq/showevt.c | 13 ++--- hadaq/soft.tcl | 2 +- 5 files changed, 97 insertions(+), 95 deletions(-) diff --git a/hadaq/evt.c b/hadaq/evt.c index 60e6713..c9fe668 100644 --- a/hadaq/evt.c +++ b/hadaq/evt.c @@ -1,4 +1,4 @@ -static char rcsId[] = "$Id: evt.c,v 6.7 2000-05-22 08:20:48 hades Exp $"; +static char rcsId[] = "$Id: evt.c,v 6.8 2000-10-10 10:33:38 hades Exp $"; #define _ANSI_C_SOURCE #include @@ -20,7 +20,7 @@ enum EvtIdx { EvtIdx_date, EvtIdx_time, EvtIdx_runNr, - EvtIdx_pad, + EvtIdx_expId, EvtIdx_data }; @@ -94,6 +94,35 @@ void Evt_setRunNr(void *my, UInt4 runNr) Evt_setHdrValue(my, EvtIdx_runNr, runNr); } +UInt4 Evt_expId(const void *my) +{ + return Evt_hdrValue(my, EvtIdx_expId); +} + +void Evt_setExpId(void *my, UInt4 expId) +{ + Evt_setHdrValue(my, EvtIdx_expId, expId); +} + +char *Evt_expId2charP(const void *my) +{ + static char buffer[3]; + UInt4 expId; + + expId = Evt_expId(my); + + buffer[0] = (expId >> 8) & 0xff; + buffer[1] = expId & 0xff; + buffer[2] = '\0'; + + return buffer; +} + +void Evt_setExpIdCharP(void *my, const char *expId) +{ + Evt_setExpId(my, (expId[0] << 8) | expId[1]); +} + char *Evt_date2charP(const void *my) { time_t tempo; @@ -132,15 +161,15 @@ char *Evt_2charP(const void *my) sprintf(buf, "size: %08x\tdecoding: %08x\tid: %08x\tseqNr: %08x\n" - "date: %s\ttime: %s\trunNr: %d", + "date: %s\ttime: %s\trunNr: %d\texpId: %x", Evt_size(my), Evt_decoding(my), Evt_id(my), Evt_seqNr(my), - Evt_date2charP(my), Evt_time2charP(my), Evt_runNr(my) + Evt_date2charP(my), Evt_time2charP(my), Evt_runNr(my), Evt_expId(my) ); return buf; } -void *newEvt(UInt4 decoding, UInt4 id, UInt4 runNr) +void *newEvt(UInt4 decoding, UInt4 id, UInt4 runNr, const char *expId) { void *my; static UInt4 seqNr = 0; @@ -155,6 +184,7 @@ void *newEvt(UInt4 decoding, UInt4 id, UInt4 runNr) Evt_setDecoding(my, decoding); Evt_setId(my, id); Evt_setRunNr(my, runNr); + Evt_setExpIdCharP(my, expId); Evt_setSeqNr(my, seqNr++); diff --git a/hadaq/evt.h b/hadaq/evt.h index f648076..f00b07b 100644 --- a/hadaq/evt.h +++ b/hadaq/evt.h @@ -44,6 +44,8 @@ void *Evt_data(const void *my); char *Evt_date2charP(const void *my); char *Evt_time2charP(const void *my); char *Evt_2charP(const void *my); +char *Evt_expId2charP(const void *my); +void Evt_setExpIdCharP(void *my, const char *expId); UInt4 Evt_id(const void *my); void Evt_setId(void *my, UInt4 id); @@ -54,9 +56,11 @@ void Evt_setDate(void *my, UInt4 date); UInt4 Evt_time(const void *my); void Evt_setTime(void *my, UInt4 time); UInt4 Evt_runNr(const void *my); +UInt4 Evt_expId(const void *my); void Evt_setRunNr(void *my, UInt4 runNr); +void Evt_setExpId(void *my, UInt4 expId); -void *newEvt(UInt4 decoding, UInt4 id, UInt4 runNr); +void *newEvt(UInt4 decoding, UInt4 id, UInt4 runNr, const char *expId); void deleteEvt(void *my); void *Evt_fget(FILE * file); void *Evt_appendSubEvt(void *my, void *subEvt); diff --git a/hadaq/evtbuild.c b/hadaq/evtbuild.c index f5996ce..5d40563 100644 --- a/hadaq/evtbuild.c +++ b/hadaq/evtbuild.c @@ -1,6 +1,7 @@ -static char rcsId[] = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hadaq/evtbuild.c,v 6.17 2000-05-22 16:26:06 hades Exp $"; +static char rcsId[] = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hadaq/evtbuild.c,v 6.18 2000-10-10 10:33:38 hades Exp $"; + +#define _POSIX_C_SOURCE 199309L -#define _XOPEN_SOURCE #include #include @@ -69,64 +70,10 @@ static void *appendFile(void *my, const char *path) return my; } -#if 0 -/* BUGBUG Tape handling needs complete new implementation */ -static FILE *openTape(const char *outPath) -{ - FILE *outFile; - int fd[2]; - char path[_POSIX_PATH_MAX]; - - strcpy(path, "of="); - strcat(path, outPath); - - if (0 > pipe(fd)) { - msglog(LOG_DEBUG, "%s, %d: %s\n", __FILE__, __LINE__, strerror(errno)); - return NULL; - } - switch (fork()) { - case -1: - msglog(LOG_DEBUG, "%s, %d: %s\n", __FILE__, __LINE__, strerror(errno)); - return NULL; - break; - case 0: - if (-1 == close(0)) { - msglog(LOG_ERR, "%s, %d: %s\n", __FILE__, __LINE__, strerror(errno)); - exit(EXIT_FAILURE); - } - if (0 != dup(fd[0])) { - msglog(LOG_ERR, "%s, %d: %s\n", __FILE__, __LINE__, strerror(errno)); - exit(EXIT_FAILURE); - } - if (-1 == close(fd[0])) { - msglog(LOG_ERR, "%s, %d: %s\n", __FILE__, __LINE__, strerror(errno)); - exit(EXIT_FAILURE); - } - if (-1 == close(fd[1])) { - msglog(LOG_ERR, "%s, %d: %s\n", __FILE__, __LINE__, strerror(errno)); - exit(EXIT_FAILURE); - } - if (-1 == execlp("dd", "dd", "ibs=1024k", "obs=8192", path, NULL)) { - msglog(LOG_ERR, "%s, %d: %s\n", __FILE__, __LINE__, strerror(errno)); - exit(EXIT_FAILURE); - } - break; - default: - outFile = fdopen(fd[1], "wb"); - if (-1 == close(fd[0])) { - msglog(LOG_DEBUG, "%s, %d: %s\n", __FILE__, __LINE__, strerror(errno)); - return NULL; - } - break; - } - return outFile; -} -#endif - static void usage(const char *progName) { - msglog(LOG_ERR, "Usage: %s -s nrOfSubEvts [...] [-r runNr]\n", progName); - msglog(LOG_ERR, "Usage: [-m nrOfMsgs]\n"); + msglog(LOG_ERR, "Usage: %s [-x expId]\n", progName); + msglog(LOG_ERR, "Usage: [-m nrOfMsgs] [-r runNr]\n"); msglog(LOG_ERR, "Usage: [-f slowCtrlFile ...] [-o outPath] [-d null|tape|file]\n"); msglog(LOG_ERR, "Usage: [-a (agent)] [-p priority]\n"); msglog_usage(); @@ -142,14 +89,17 @@ int main(int argc, char *argv[]) int isStandalone; int nrOfMsgs; void *evt; - char *outPath; + char outPath[_POSIX_PATH_MAX] = ""; + char fileName[_POSIX_PATH_MAX]; char *outDev; int priority; FILE *outFile; AnsiTape *outTape; void *subEvt; - UInt4 nrOfSubEvts = 0; + UInt4 nrOfSubEvts; + time_t t; UInt4 runNr; + char expId[3] = "xx"; char **slowCtrlFiles; int slowCtrlFileCnt; size_t queueSize; @@ -162,18 +112,19 @@ int main(int argc, char *argv[]) unsigned long *evtsComplete; unsigned long *bytesWritten; + t = time(NULL); + msglog_setlevel(argv[0], "info"); isStandalone = 1; nrOfMsgs = 0; slowCtrlFiles = NULL; slowCtrlFileCnt = 0; - outPath = "-"; outDev = "null"; priority = 0; - runNr = time(NULL); + runNr = t; queueSize = 1 * 1024 * 1024; - while ((i = getopt(argc, argv, "am:f:r:s:o:d:p:v:")) != -1) { + while ((i = getopt(argc, argv, "am:f:s:r:o:d:p:v:x:")) != -1) { switch (i) { case 'a': isStandalone = 0; @@ -190,10 +141,11 @@ int main(int argc, char *argv[]) runNr = atoi(optarg); break; case 's': - nrOfSubEvts = atoi(optarg); + msglog(LOG_WARNING, + "-s option obsolete, will be removed in a future version\n"); break; case 'o': - outPath = optarg; + strcpy(outPath, optarg); break; case 'd': outDev = optarg; @@ -207,6 +159,11 @@ int main(int argc, char *argv[]) exit(EXIT_FAILURE); } break; + case 'x': + expId[0] = tolower(optarg[0]); + expId[1] = tolower(optarg[1]); + expId[2] = '\0'; + break; default: usage(argv[0]); exit(EXIT_FAILURE); @@ -214,28 +171,35 @@ int main(int argc, char *argv[]) } } - if (nrOfSubEvts == 0) { - msglog(LOG_ERR, "missing nrOfSubEvts\n"); - usage(argv[0]); - exit(EXIT_FAILURE); - } - if (nrOfMsgs == 0) { - msglog(LOG_NOTICE, "nrOfMsgs not set, assuming readout is local\n"); + /* construct a default filename */ + strcpy(fileName, expId); + strftime(fileName + strlen(fileName), 18, "%y%j%H%M%S.hld", localtime(&t)); + + /* construct the output path */ + if (strcmp(outPath, "") == 0) { + strcpy(outPath, fileName); + } else { + struct stat bufS, *buf = &bufS; + + stat(outPath, buf); + if (S_ISDIR(buf->st_mode)) { + strcat(outPath, "/"); + strcat(outPath, fileName); + } } + if (NULL == (worker = Worker_initBegin(argv[0], sigHandler, priority, isStandalone))) { msglog(LOG_ERR, "%s, %d: %s\n", __FILE__, __LINE__, strerror(errno)); exit(EXIT_FAILURE); } if (strcmp(outDev, "null") == 0) { outFile = NULL; + } else if (strcmp(outDev, "stdout") == 0) { + outFile = stdout; } else if (strcmp(outDev, "file") == 0) { - if (strcmp(outPath, "-") == 0) { - outFile = stdout; - } else { - if (NULL == (outFile = fopen(outPath, "wb"))) { - msglog(LOG_ERR, "%s, %d: %s\n", __FILE__, __LINE__, strerror(errno)); - exit(EXIT_FAILURE); - } + if (NULL == (outFile = fopen(outPath, "wb"))) { + msglog(LOG_ERR, "%s, %d: %s\n", __FILE__, __LINE__, strerror(errno)); + exit(EXIT_FAILURE); } } else if (strcmp(outDev, "tape") == 0) { if (NULL == (outTape = openAnsiTape(outPath))) { @@ -259,6 +223,8 @@ int main(int argc, char *argv[]) readout task (daq_readout) is running on the same node and communicates directly via shared memory */ + msglog(LOG_NOTICE, "nrOfMsgs not set, assuming readout is local\n"); + shmTrans = allocMem(sizeof(ShmTrans *)); hadTuQueue = allocMem(sizeof(HadTuQueue *)); @@ -283,7 +249,7 @@ int main(int argc, char *argv[]) bytesWritten = Worker_addStatistic(worker, "bytesWritten"); Worker_initEnd(worker); - evt = newEvt(EvtDecoding_64bitAligned, EvtId_runStart, runNr); + evt = newEvt(EvtDecoding_64bitAligned, EvtId_runStart, runNr, expId); for (i = 0; i < slowCtrlFileCnt; i++) { evt = appendFile(evt, slowCtrlFiles[i]); } @@ -296,6 +262,7 @@ int main(int argc, char *argv[]) } deleteEvt(evt); + nrOfSubEvts = nrOfMsgs; currTrigNr = 0xffffffff; while (setjmp(terminateJmp) == 0) { int tryNext; @@ -304,7 +271,7 @@ int main(int argc, char *argv[]) i = 0; tryNext = 0; - evt = newEvt(EvtDecoding_64bitAligned, EvtId_data, runNr); + evt = newEvt(EvtDecoding_64bitAligned, EvtId_data, runNr, expId); currNrOfSubEvts = 0; while (i < nrOfMsgs) { if (hadTuQueue[i] == NULL) { @@ -370,7 +337,7 @@ int main(int argc, char *argv[]) } Worker_dump(worker, 0); - evt = newEvt(EvtDecoding_64bitAligned, EvtId_runStop, runNr); + evt = newEvt(EvtDecoding_64bitAligned, EvtId_runStop, runNr, expId); for (i = 0; i < slowCtrlFileCnt; i++) { evt = appendFile(evt, slowCtrlFiles[i]); } diff --git a/hadaq/showevt.c b/hadaq/showevt.c index 28d4e88..40593dd 100644 --- a/hadaq/showevt.c +++ b/hadaq/showevt.c @@ -1,4 +1,4 @@ -static char rcsId[] = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hadaq/showevt.c,v 6.3 2000-02-03 18:35:27 muench Stab $"; +static char rcsId[] = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hadaq/showevt.c,v 6.4 2000-10-10 10:33:38 hades Exp $"; #define _ANSI_C_SOURCE #include @@ -24,16 +24,17 @@ int analyseEvt(void *evt) /* print the event header */ printf( - "size: 0x%08x decoding: 0x%08x id: 0x%08x seqNr: 0x%08x\n" - "date: %s time: %s runNr: 0x%08x\n", - Evt_size(evt), Evt_decoding(evt), Evt_id(evt), Evt_seqNr(evt), - Evt_date2charP(evt), Evt_time2charP(evt), Evt_runNr(evt) + "size: 0x%08x decoding: 0x%08x id: 0x%08x seqNr: 0x%08x\n" + "date: %s time: %s runNr: 0x%08x expId: %s\n", + Evt_size(evt), Evt_decoding(evt), Evt_id(evt), Evt_seqNr(evt), + Evt_date2charP(evt), Evt_time2charP(evt), Evt_runNr(evt), + Evt_expId2charP(evt) ); i = 0; /* loop over all subevents */ for (subEvt = Evt_data(evt); subEvt < Evt_end(evt); subEvt = Evt_next(evt, subEvt)) { - printf("size: 0x%08x decoding: 0x%08x id: 0x%08x trigNr: 0x%08x\n", + printf("size: 0x%08x decoding: 0x%08x id: 0x%08x trigNr: 0x%08x\n", SubEvt_size(subEvt), SubEvt_decoding(subEvt), SubEvt_id(subEvt), SubEvt_trigNr(subEvt)); if (SubEvt_decoding(subEvt) == SubEvtDecoding_32bitData) { for (i = 0; i < SubEvt_dataSize(subEvt) / sizeof(UInt4); i++) { diff --git a/hadaq/soft.tcl b/hadaq/soft.tcl index 7b4aa82..27b7e5b 100644 --- a/hadaq/soft.tcl +++ b/hadaq/soft.tcl @@ -1,6 +1,6 @@ agent create neptun muench /home/muench/hdev/daq/hadaq agent create acheron muench /home/muench/hdev/daq/hadaq -worker create neptun:evtbuild -a -p -2 -s 1 -m 1 +worker create neptun:evtbuild -a -p -2 -s 1 -m 1 -x xx worker create neptun:netmem -a -p -1 -m 1 -i UDP:0.0.0.0:3000 worker create acheron:memnet -a -p -1 -w 2500 -o UDP:129.187.154.111:3000 worker create acheron:readout -a -p -2 -- 2.43.0