From 878dd0bdc0522380d9ebbc75ba8c53ca49878603 Mon Sep 17 00:00:00 2001 From: hadaq Date: Tue, 3 Apr 2012 09:29:08 +0000 Subject: [PATCH] JAM: avoid duplilcate filenames in case of old runid (epics). to be tested. bugfix: do not discard res events for all new files, only on process startup. --- hadaq/evtbuild.c | 46 +++++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/hadaq/evtbuild.c b/hadaq/evtbuild.c index 02ae878..c8f05e2 100644 --- a/hadaq/evtbuild.c +++ b/hadaq/evtbuild.c @@ -1,4 +1,4 @@ -static char *rcsId = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hadaq/evtbuild.c,v 6.163 2012-04-02 10:34:08 hadaq Exp $"; +static char *rcsId = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hadaq/evtbuild.c,v 6.164 2012-04-03 09:29:08 hadaq Exp $"; #define _POSIX_C_SOURCE 199309L #define SYSLOG_NAMES @@ -502,8 +502,8 @@ static int openFile(TheArgs *theArgs, TheStats *theStats) static char outLustrePath[_POSIX_PATH_MAX]; static char sec_path[_POSIX_PATH_MAX]; static once = 1; - /*static unsigned long old_runNr=0; - static unsigned open_count=0; */ + static unsigned long old_runNr = 0; + static unsigned open_count = 0; seqNr = 0; @@ -537,19 +537,17 @@ static int openFile(TheArgs *theArgs, TheStats *theStats) /* JAM: check here if new run id from epics is our old run id * this means we closed our file because of reaching file size limit * before master ioc assigned new run id. In this case, we need to modify file name! - * Still disabled to ensure old naming convention for analysis scripts... * */ - /*if(old_runNr!=0 && (theArgs->runNr > old_runNr)) - { - open_count=0; we have a real new run nr, reset file count for this run nr - } - else if(old_runNr!=0 && (theArgs->runNr ==old_runNr)) - { - sprintf(msglog, " openFile: begin next file %d for run id: %s", open_count,fileName); - storeLogInfo(theArgs, msglog); - } - sprintf(fileName, "%s_%02d_", fileName, open_count++); file name is always run id + file count - */ + + if ((theArgs->runNr == old_runNr)) { + open_count++; + sprintf(msglog, " openFile: duplicate runid: Open additional file version %d for run id: %s", open_count, fileName); + storeLogInfo(theArgs, msglog); + } else { + open_count = 0; /*we have a real new run nr, reset file count for this run nr */ + } + old_runNr = theArgs->runNr; + /* if ebnum == 0 then we assume that there is only 1 EB, @@ -561,6 +559,14 @@ static int openFile(TheArgs *theArgs, TheStats *theStats) else sprintf(fileName, "%s.hld", fileName); + + if (open_count) { + sprintf(fileName, "%s-%02d", fileName, open_count); /* add cycle number to file */ + sprintf(msglog, " openFile: Using filename %s", fileName); + storeLogInfo(theArgs, msglog); + } + + /* Copy file name to theArgs */ /* if( strcmp(theArgs->outDev, "file") == 0 || */ /* #ifdef RFIO */ @@ -899,6 +905,7 @@ int main(int argc, char *argv[]) uint32_t currId; uint32_t lastTrigNr = 0; + int firstFile = 1; @@ -1490,16 +1497,16 @@ int main(int argc, char *argv[]) if (theArgs->resdownscale) { /* my->resstartevent */ - if (*theStats->evtsComplete < theArgs->resfirstevent) { + if ((firstFile != 0) && (*theStats->evtsComplete < theArgs->resfirstevent)) { /*JAM skip first n events workaround to avoid QA crashes */ } else { - if (*theStats->evtsComplete == theArgs->resfirstevent) { + if ((firstFile != 0) && (*theStats->evtsComplete == theArgs->resfirstevent)) { /* give some debug statement that we started writing */ sprintf(msglog, " Started writing resfile after %d skipped initial events", *theStats->evtsComplete); storeLogInfo(theArgs, msglog); + firstFile = 0; } - /* * If the setting are as follows: * EVENT_NUM_OFFSET == 100 @@ -1508,7 +1515,8 @@ int main(int argc, char *argv[]) * then from each 100 events only * first 5 events are written to refFile. */ - if (((*theStats->evtsComplete) % EVENT_NUM_OFFSET) < theArgs->resdown_offset) { + if (((*theStats->evtsComplete) % EVENT_NUM_OFFSET) + < theArgs->resdown_offset) { (*theStats->evtsRes)++; Res_writeFile(evt, runNr, seqNr); } -- 2.43.0