]> jspc29.x-matter.uni-frankfurt.de Git - daqdata.git/commitdiff
EB exit condition if large trigger missmatch. Sergey.
authorhadaq <hadaq>
Fri, 30 Jul 2010 09:18:59 +0000 (09:18 +0000)
committerhadaq <hadaq>
Fri, 30 Jul 2010 09:18:59 +0000 (09:18 +0000)
hadaq/evtbuild.c

index 9a59044941f6f3a0f8f07930a4bdcc07d7e3b403..f1ee7438803914f375af25097eb3d4c299381790 100644 (file)
@@ -1,4 +1,4 @@
-static char *rcsId = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hadaq/evtbuild.c,v 6.123 2010-07-23 13:45:02 hadaq Exp $";
+static char *rcsId = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hadaq/evtbuild.c,v 6.124 2010-07-30 09:18:59 hadaq Exp $";
 
 #define _POSIX_C_SOURCE 199309L
 #define SYSLOG_NAMES
@@ -138,6 +138,8 @@ typedef struct TheArgsS {
 
        char fileName[PARAM_MAX_VALUE_LEN];
        unsigned short multiDisks;      /*  Write files to diferent disks */
+
+       unsigned long maxTrigMissmatch;
 } TheArgs;
 
 typedef struct TheStatsS {
@@ -246,6 +248,7 @@ static void usage(const char *progName)
        syslog(LOG_ERR, "       [--lustre path_to_lustre]    Output path for writing data on the Lustre cluster (if mounted).");
        syslog(LOG_ERR, "       [--orapath path]             Path to eb_runinfo2ora.txt for writing data to Oracle.");
        syslog(LOG_ERR, "       [--ignore]                   Ignore trigger mismatch conditions.");
+       syslog(LOG_ERR, "       [--maxtrigmissmatch number]  Maximum number of triggers allowed for missmatch.");
        syslog(LOG_ERR, "       [--multidisk]                Write data to a disk number provided by daq_disks via shared memory.");
        syslog(LOG_ERR, "");
        syslog(LOG_ERR, "Options for debugging:");
@@ -490,6 +493,8 @@ static void argsDefault(TheArgs *my)
                my->debugOpts[i] = my->debugOptsS[i];
        }
        my->debugOptsCnt = 0;
+
+       my->maxTrigMissmatch = 100000;
 }
 
 static int argsFromCL(TheArgs *my, int argc, char *argv[])
@@ -526,9 +531,10 @@ static int argsFromCL(TheArgs *my, int argc, char *argv[])
                        {"debug", 1, 0, 'D'},
                        {"trigtype", 1, 0, 'T'},
                        {"multidisks", 0, 0, 'k'},
+                       {"maxtrigmissmatch", 1, 0, 'g'},
                        {0, 0, 0, 0}
                };
-               i = getopt_long(argc, argv, "am:f:r:o:d:q:Q:p:v:x:I:tz:e:n:h:w:Hs:l:R:A:bEL:S:B:O:iW:M:F:X:C:D:T:k", long_options,
+               i = getopt_long(argc, argv, "am:f:r:o:d:q:Q:p:v:x:I:tz:e:n:h:w:Hs:l:R:A:bEL:S:B:O:iW:M:F:X:C:D:T:kg:", long_options,
                                                &option_index);
                if (i == -1)
                        break;
@@ -644,6 +650,9 @@ static int argsFromCL(TheArgs *my, int argc, char *argv[])
                case 'O':
                        sprintf(my->runinfo2ora, "%s_runinfo2ora.txt", getenv("DAQ_SETUP"));
                        break;
+               case 'g':
+                       my->maxTrigMissmatch = strtoul(optarg, NULL, 0);
+                       break;
                case 'H':
                        return -1;
                        break;
@@ -974,6 +983,100 @@ static void printDebug(TheArgs *theArgs, TheStats *theStats, TheDebug * theDebug
        }
 }
 
+static void printPopTrigMissmatch(TheArgs *theArgs, TheStats *theStats, TheDebug * theDebug, int qi)
+{
+       int i;
+
+       printf("\n\n");
+       fprintf(stderr, "<E> daq_evtbuild: trigger missmatch is above %d.\n", theArgs->maxTrigMissmatch);
+
+       printf("\n");
+       fputs
+               ("---------------------------- error: discarded triggers ----------------------------------------------------------------\n",
+                stderr);
+       printf("%7s", "Queue");
+       for (i = 0; i < theArgs->nrOfMsgs; i++) {
+               printf("%9d", i);
+       }
+       printf("\n");
+
+       if (theArgs->debugOptsCnt) {
+               int j;
+
+               /* First print last succesfuly built event */
+               if (theArgs->debug_trignr) {
+                       printf("%7s", "trigNr");
+                       for (i = 0; i < theArgs->nrOfMsgs; i++) {
+                               printf(" %08x", theDebug->evtsLastBuilt[i]);
+                       }
+                       printf("\n");
+               }
+
+               int maxEvts = 0;
+               for (i = 0; i < theArgs->nrOfMsgs; i++) {
+                       if (maxEvts < theDebug->evtsBrokenCnt[i])
+                               maxEvts = theDebug->evtsBrokenCnt[i];
+               }
+
+               for (j = 0; j < maxEvts; j++) {
+
+                       /* Print trigger numbers */
+                       if (theArgs->debug_trignr) {
+                               printf("%7s", "trigNr");
+                               for (i = 0; i < theArgs->nrOfMsgs; i++) {
+                                       if (j < theDebug->evtsBrokenCnt[i]) {
+                                               printf(" %08x", theDebug->evtsBroken[i][j]);
+                                       } else {
+                                               printf("%9s", "-");
+                                       }
+                               }
+                               printf("\n");
+                       }
+               }
+       }
+
+       printf("%7s", "lastNr");
+       for (i = 0; i < theArgs->nrOfMsgs; i++) {
+               if (i <= qi) {
+                       printf(" %08x", (*theStats->trigNr[i]));
+               } else {
+                       printf("%9s", "-");
+               }
+       }
+
+       printf("\n\n");
+       fprintf(stderr, "<E> Exit.\n", theArgs->maxTrigMissmatch);
+       printf("\n");
+}
+
+static void printBrokenTrigMissmatch(TheArgs *theArgs, TheStats *theStats)
+{
+       int i;
+
+       printf("\n\n");
+       fprintf(stderr, "<E> daq_evtbuild: trigger missmatch is above %d.\n", theArgs->maxTrigMissmatch);
+       printf("\n");
+
+       fputs
+               ("---------------------------- error: discarded triggers ----------------------------------------------------------------\n",
+                stderr);
+       printf("%7s", "Queue");
+       for (i = 0; i < theArgs->nrOfMsgs; i++) {
+               printf("%9d", i);
+       }
+       printf("\n");
+
+       printf("%7s", "lastNr");
+       for (i = 0; i < theArgs->nrOfMsgs; i++) {
+               printf(" %08x", (*theStats->trigNr[i]));
+       }
+
+       printf("\n\n");
+       fprintf(stderr, "<E> Exit.\n", theArgs->maxTrigMissmatch);
+       printf("\n");
+
+}
+
 static void add2Stat(TheArgs *theArgs, TheStats *my, float interval, ShmTrans **shmtr)
 {
        /* Add statistic for fill levels of buffers in percentage. */
@@ -1447,7 +1550,7 @@ char *strReplace(char const *const original, char const *const pattern, char con
        return returned;
 }
 
-static void changeData(int once, TheArgs *theArgs, TheStats *theStats)
+static void changeDisk(int once, TheArgs *theArgs, TheStats *theStats)
 {
        if (theArgs->multiDisks) {
 
@@ -1536,7 +1639,7 @@ static int openFile(TheArgs *theArgs, TheStats *theStats)
        theArgs->runNr = runNr;
 
        if (once) {
-               changeData(once, theArgs, theStats);
+               changeDisk(once, theArgs, theStats);
                file_size = theArgs->maxFileSz;
                strcpy(sec_path, theArgs->sec_path);
                strcpy(outPath, theArgs->outPath);
@@ -1546,7 +1649,7 @@ static int openFile(TheArgs *theArgs, TheStats *theStats)
                strcpy(theArgs->outPath, outPath);
                strcpy(theArgs->lustrePath, outLustrePath);
                strcpy(theArgs->sec_path, sec_path);
-               changeData(once, theArgs, theStats);
+               changeDisk(once, theArgs, theStats);
        }
 
        /* construct a default filename */
@@ -2148,11 +2251,11 @@ int main(int argc, char *argv[])
        rfio_openConnection(theArgs, theStats);
 #endif
 
-       uint32_t trigType;
-       uint32_t lastCurrTrigNr = 0;
        int brokenEvtCnt = 0;
+       unsigned long popCnt = 0;
 
        currId = 0;
+
        while (setjmp(terminateJmp) == 0) {
                void *evt;
                void *subEvt;
@@ -2221,8 +2324,8 @@ int main(int argc, char *argv[])
                        }
                }
 
-
                evt = newEvt(EvtDecoding_64bitAligned, EvtId_data);
+               popCnt = 0;                             /* Counter of popped up subevents */
 
                for (i = 0; i < theArgs->nrOfMsgs && !evtIsBroken; i += step) {
                        uint32_t trigNr;
@@ -2278,6 +2381,7 @@ int main(int argc, char *argv[])
 
                                        evt = Evt_appendSubEvt(evt, subEvt);
                                }
+
                                HadTuQueue_pop(hadTuQueue[i]);
                                step = 1;
                        } else if (trigNr < currTrigNr) {
@@ -2287,6 +2391,13 @@ int main(int argc, char *argv[])
                                /* BUGBUG subevt discarded, not in statistic */
                                HadTuQueue_pop(hadTuQueue[i]);
                                step = 0;
+
+                               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;
+                               }
                        } else {
                                if (theArgs->debugOptsCnt)
                                        brokenEvtCnt = fillDebug(theArgs, theStats, theDebug, i, "broken");
@@ -2347,6 +2458,12 @@ int main(int argc, char *argv[])
                                Evt_online(evt);
                } else {
                        (*theStats->evtsDiscarded)++;
+
+                       /* Check if triggger missmatch is large enough to exit */
+                       if ((*theStats->evtsDiscarded) > theArgs->maxTrigMissmatch) {
+                               printBrokenTrigMissmatch(theArgs, theStats);
+                               goto bailOut1;
+                       }
 #if CHECK_MISMATCH
                        is_mismatch_enough_to_stop(theArgs, theStats);
 #endif
@@ -2423,6 +2540,8 @@ int main(int argc, char *argv[])
                }
        }
 
+  bailOut1:
+
        ourTime = time(NULL);
        closeFile();