-static char *rcsId = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hadaq/evtbuild.c,v 6.108 2010-06-14 14:37:43 hadaq Exp $";
+static char *rcsId = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hadaq/evtbuild.c,v 6.109 2010-06-16 14:44:15 hadaq Exp $";
#define _POSIX_C_SOURCE 199309L
#define SYSLOG_NAMES
static RFILE *fRemote = NULL;
#endif
+#define MAXDEBUGEVTS 20
+
#define MAXINPATH 100
#define NEVTIDS 64UL /* must be 2^n */
static int diff_time;
static int trig_mismatch;
+static int evtBrokenFlag = 0;
+
typedef struct TheArgsS {
unsigned long nrOfMsgs;
char outPath[PARAM_MAX_VALUE_LEN];
char *slowCtrlFiles[PARAM_MAX_ARRAY_LEN];
char slowCtrlFilesS[PARAM_MAX_ARRAY_LEN][PARAM_MAX_NAME_LEN];
int slowCtrlFileCnt;
+ char *debugOpts[PARAM_MAX_ARRAY_LEN];
+ char debugOptsS[PARAM_MAX_ARRAY_LEN][PARAM_MAX_NAME_LEN];
+ int debugOptsCnt;
+ int debug_trignr;
+ int debug_errbit;
+ int debug_word;
+
unsigned long isStandalone;
unsigned long priority;
unsigned long queueSize[MAXINPATH];
unsigned long *evtId[NEVTIDS];
unsigned long *trigNr[MAXINPATH];
unsigned long *errBit[MAXINPATH];
+ unsigned long *debugWord[MAXINPATH];
unsigned long *evtsRes;
unsigned long *evtbuildBuff[MAXINPATH];
unsigned long *nrOfMsgs;
unsigned long *runId;
} TheStats;
+typedef struct TheDebugS {
+ unsigned long *evtsBroken[MAXINPATH];
+ unsigned long evtsBrokenS[MAXINPATH][MAXDEBUGEVTS];
+ unsigned long evtsBrokenCnt[MAXINPATH];
+ unsigned long *errBits[MAXINPATH];
+ unsigned long errBitsS[MAXINPATH][MAXDEBUGEVTS];
+ unsigned long errBitsCnt[MAXINPATH];
+ unsigned long *debugWords[MAXINPATH];
+ unsigned long debugWordsS[MAXINPATH][MAXDEBUGEVTS];
+ unsigned long debugWordsCnt[MAXINPATH];
+ unsigned long evtsLastBuilt[MAXINPATH];
+} TheDebug;
+
+
static jmp_buf terminateJmp;
void sigHandler(int sig)
syslog(LOG_DEBUG, "EB numder: %d", my->ebnum);
}
+static void initDebug(TheDebug * theDebug)
+{
+
+ int i;
+
+ for (i = 0; i < MAXINPATH; i++) {
+ theDebug->evtsBroken[i] = theDebug->evtsBrokenS[i];
+ theDebug->errBits[i] = theDebug->errBitsS[i];
+ theDebug->debugWords[i] = theDebug->debugWordsS[i];
+ theDebug->evtsBrokenCnt[i] = 0;
+ theDebug->errBitsCnt[i] = 0;
+ theDebug->debugWordsCnt[i] = 0;
+ theDebug->evtsLastBuilt[i] = 0;
+ }
+}
+
static void argsDefault(TheArgs *my)
{
int i;
/* 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"));
+
+ /* Debugging args */
+ my->debug_trignr = 0;
+ my->debug_errbit = 0;
+ my->debug_word = 0;
+
+ for (i = 0; i < PARAM_MAX_ARRAY_LEN; i++) {
+ my->debugOpts[i] = my->debugOptsS[i];
+ }
+ my->debugOptsCnt = 0;
}
static int argsFromCL(TheArgs *my, int argc, char *argv[])
{"ebnum", 1, 0, 'B'},
{"orapath", 1, 0, 'O'},
{"ignore", 0, 0, 'i'},
+ {"debug", 1, 0, 'D'},
{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:tz:e:n:Hs:l:R:A:bEL:S:B:O:iW:M:F:X:C:", long_options,
+ i = getopt_long(argc, argv, "am:f:r:o:d:q:Q:p:v:x:I:tz:e:n:h:w:tz:e:n:Hs:l:R:A:bEL:S:B:O:iW:M:F:X:C:D:", long_options,
&option_index);
if (i == -1)
break;
case 'f':
strcpy(my->slowCtrlFiles[my->slowCtrlFileCnt++], optarg);
break;
+ case 'D':
+ strcpy(my->debugOpts[my->debugOptsCnt++], optarg);
+ break;
case 'o':
strcpy(my->outPath, optarg);
break;
return 1;
}
+ /* Check debug options */
+ int i;
+
+ for (i = 0; i < my->debugOptsCnt; i++) {
+ if (strcmp(my->debugOpts[i], "trignr") == 0) {
+ my->debug_trignr = 1;
+ } else if (strcmp(my->debugOpts[i], "errbit") == 0) {
+ my->debug_errbit = 1;
+ } else if (strcmp(my->debugOpts[i], "debugword") == 0) {
+ my->debug_word = 1;
+ } else {
+ printf("Error: wrong argument is given in the option -D|--debug.\n");
+ return 1;
+ }
+ }
+
return 0;
}
printf("Time: %s.%03ld\n", time_string, milliseconds);
}
+static int fillDebug(TheArgs *theArgs, TheStats *theStats, TheDebug * theDebug, int i, char *evtStatus)
+{
+ int j;
+
+ if (strcmp(evtStatus, "pop") == 0) {
+ if (theDebug->evtsBrokenCnt[i] == MAXDEBUGEVTS ||
+ theDebug->errBitsCnt[i] == MAXDEBUGEVTS || theDebug->debugWordsCnt[i] == MAXDEBUGEVTS)
+ return MAXDEBUGEVTS;
+
+ j = theDebug->evtsBrokenCnt[i];
+
+ theDebug->evtsBroken[i][j] = (*theStats->trigNr[i]);
+ theDebug->errBits[i][j] = (*theStats->errBit[i]);
+ theDebug->debugWords[i][j] = (*theStats->debugWord[i]);
+
+ theDebug->evtsBrokenCnt[i]++;
+ theDebug->errBitsCnt[i]++;
+ theDebug->debugWordsCnt[i]++;
+ } else if (strcmp(evtStatus, "broken") == 0) {
+ int k;
+ for (k = 0; k < i; k++) {
+
+ if (theDebug->evtsBrokenCnt[k] == MAXDEBUGEVTS ||
+ theDebug->errBitsCnt[k] == MAXDEBUGEVTS || theDebug->debugWordsCnt[k] == MAXDEBUGEVTS)
+ return MAXDEBUGEVTS;
+
+ j = theDebug->evtsBrokenCnt[k];
+
+ theDebug->evtsBroken[k][j] = (*theStats->trigNr[k]);
+ theDebug->errBits[k][j] = (*theStats->errBit[k]);
+ theDebug->debugWords[k][j] = (*theStats->debugWord[k]);
+
+ theDebug->evtsBrokenCnt[k]++;
+ theDebug->errBitsCnt[k]++;
+ theDebug->debugWordsCnt[k]++;
+ }
+ } else {
+ printf("fillDebug: Event has unknown status!\n");
+ }
+
+ evtBrokenFlag = 1;
+
+ return j;
+}
+
+static void printDebug(TheArgs *theArgs, TheStats *theStats, TheDebug * theDebug)
+{
+ int i;
+ int j;
+
+ printf("\n");
+ fputs
+ ("---------------------------- debug: discarded triggers ----------------------------------------------------------------\n",
+ stderr);
+ printf("%7s", "Queue");
+ for (i = 0; i < theArgs->nrOfMsgs; i++) {
+ printf("%9d", i);
+ }
+ printf("\n");
+
+ /* First print last succesfuly built event */
+ if (theArgs->debug_trignr) {
+ printf("%7s", "trigNr");
+ for (i = 0; i < theArgs->nrOfMsgs; i++) {
+ printf("%9x", theDebug->evtsLastBuilt[i]);
+ }
+ printf("\n");
+ }
+
+ /* Maximum element */
+ 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");
+ }
+
+ /* Print error bits */
+ if (theArgs->debug_errbit) {
+ printf("%7s", "errBit");
+ for (i = 0; i < theArgs->nrOfMsgs; i++) {
+ if (j < theDebug->errBitsCnt[i]) {
+ printf(" %08x", theDebug->errBits[i][j]);
+ } else {
+ printf("%9s", "-");
+ }
+ }
+ printf("\n");
+ }
+
+ /* Print debugging word */
+ if (theArgs->debug_word) {
+ printf("%7s", "debug");
+ for (i = 0; i < theArgs->nrOfMsgs; i++) {
+ if (j < theDebug->debugWordsCnt[i] && theDebug->debugWords[i][j] != 0) {
+ printf(" %08x", theDebug->debugWords[i][j]);
+ } else {
+ printf("%9s", "-");
+ }
+ }
+ printf("\n");
+ }
+ }
+
+ /* Print the last properly built line */
+ if (theArgs->debug_trignr) {
+ printf("%7s", "trigNr");
+ for (i = 0; i < theArgs->nrOfMsgs; i++) {
+ printf(" %08x", *theStats->trigNr[i]);
+ }
+ printf("\n");
+ }
+
+ evtBrokenFlag = 0;
+
+ /* Set counters of broken subevts to zero */
+ for (i = 0; i < MAXINPATH; i++) {
+ theDebug->evtsBrokenCnt[i] = 0;
+ theDebug->errBitsCnt[i] = 0;
+ theDebug->debugWordsCnt[i] = 0;
+ }
+}
+
static void add2Stat(TheArgs *theArgs, TheStats *my, float interval, ShmTrans **shmtr)
{
/* Add statistic for fill levels of buffers in percentage. */
/* BUGBUG bailOut not proper yet */
int main(int argc, char *argv[])
{
-
int i;
TheArgs theArgsS, *theArgs = &theArgsS;
TheStats theStatsS, *theStats = &theStatsS;
+ TheDebug theDebugS, *theDebug = &theDebugS;
ShmTrans **shmTrans;
HadTuQueue **hadTuQueue;
Worker *worker;
exit(EXIT_FAILURE);
}
+ /* Init debugging structure */
+ if (theArgs->debugOptsCnt)
+ initDebug(theDebug);
+
for (i = 0; prioritynames[i].c_name != NULL && 0 != strcmp(prioritynames[i].c_name, theArgs->verbosity); i++) {
}
sprintf(buf, "trigNr%d", i);
theStats->trigNr[i] = Worker_addStatistic(worker, buf);
}
+
for (i = 0; i < theArgs->nrOfMsgs; i++) {
char buf[WORKER_MAX_NAME_LEN];
sprintf(buf, "errBit%d", i);
theStats->errBit[i] = Worker_addStatistic(worker, buf);
}
+ if (theArgs->debugOptsCnt) {
+ for (i = 0; i < theArgs->nrOfMsgs; i++) {
+ char buf[WORKER_MAX_NAME_LEN];
+
+ sprintf(buf, "debugWord%d", i);
+ theStats->debugWord[i] = Worker_addStatistic(worker, buf);
+ }
+ }
/* Add statistic for fill levels of buffers. */
for (i = 0; i < theArgs->nrOfMsgs; i++) {
#endif
uint32_t lastCurrTrigNr = 0;
- int gap = 0;
+ int brokenEvtCnt = 0;
currId = 0;
while (setjmp(terminateJmp) == 0) {
(*theStats->trigNr[i]) = SubEvt_trigNr(subEvt);
(*theStats->errBit[i]) = SubEvt_errBit(subEvt);
+ if (theArgs->debugOptsCnt)
+ (*theStats->debugWord[i]) = SubEvt_debugWord(subEvt);
if (i == 0) {
currTrigNr = SubEvt_trigNr(subEvt) >> 8;
HadTuQueue_pop(hadTuQueue[i]);
step = 1;
} else if (trigNr < currTrigNr) {
+ if (theArgs->debugOptsCnt)
+ brokenEvtCnt = fillDebug(theArgs, theStats, theDebug, i, "pop");
+
/* BUGBUG subevt discarded, not in statistic */
HadTuQueue_pop(hadTuQueue[i]);
step = 0;
} else {
+ if (theArgs->debugOptsCnt)
+ brokenEvtCnt = fillDebug(theArgs, theStats, theDebug, i, "broken");
+
evtIsBroken = 1;
}
if (HadTuQueue_empty(hadTuQueue[i])) {
}
}
if (!evtIsBroken) {
+ if (theArgs->debugOptsCnt) {
+ if (evtBrokenFlag) {
+ printDebug(theArgs, theStats, theDebug);
+ }
+ int iq;
+ for (iq = 0; iq < theArgs->nrOfMsgs; iq++)
+ theDebug->evtsLastBuilt[iq] = (*theStats->trigNr[iq]);
+ }
+
(*theStats->evtsComplete)++;
(*theStats->evtId[currId & (NEVTIDS - 1)])++;