]> jspc29.x-matter.uni-frankfurt.de Git - daqdata.git/commitdiff
Trigger type to event header is done. Sergey.
authorhadaq <hadaq>
Fri, 18 Jun 2010 11:19:30 +0000 (11:19 +0000)
committerhadaq <hadaq>
Fri, 18 Jun 2010 11:19:30 +0000 (11:19 +0000)
hadaq/evtbuild.c

index ffb0e1d49bc519cbc0a7ad3f7165c008fc7cdf93..baad418d6833c664984516ca5b0c5cf1f32932b3 100644 (file)
@@ -1,4 +1,4 @@
-static char *rcsId = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hadaq/evtbuild.c,v 6.114 2010-06-17 15:56:15 hadaq Exp $";
+static char *rcsId = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hadaq/evtbuild.c,v 6.115 2010-06-18 11:19:30 hadaq Exp $";
 
 #define _POSIX_C_SOURCE 199309L
 #define SYSLOG_NAMES
@@ -94,7 +94,14 @@ typedef struct TheArgsS {
        unsigned long queueSize[MAXINPATH];
        int queueSizeCnt;
        char verbosity[PARAM_MAX_VALUE_LEN];
+
        unsigned long evtId;
+       char trigType[PARAM_MAX_VALUE_LEN];
+       unsigned long subsysId;
+       unsigned long wordNr;
+       unsigned long bitMask;
+       unsigned long bitShift;
+
        unsigned long maxFileSz;
        unsigned short online;
        unsigned int resdownscale;
@@ -114,6 +121,7 @@ typedef struct TheArgsS {
        char rfioRemotePath[PARAM_MAX_VALUE_LEN];
        char rfioLustrePath[PARAM_MAX_VALUE_LEN];
        char rfio_pcOption[PARAM_MAX_VALUE_LEN];
+
        unsigned short rfio_iCopyMode;
        unsigned short rfio_iCopyFrac;
        unsigned short rfio_iMaxFile;
@@ -224,7 +232,10 @@ static void usage(const char *progName)
        syslog(LOG_ERR, "       [-r runNumber]");
        syslog(LOG_ERR, "       [--shmname shmem_name]       Extension of shared memory segment name.");
        syslog(LOG_ERR, "       [-a (agent)] [-p priority]");
-       syslog(LOG_ERR, "       [-I evtId]                   Event Id can be set by Event Builder.");
+       syslog(LOG_ERR, "       [-I trigType]                Trigger type can be set by Event Builder.");
+       syslog(LOG_ERR, "       [-T evtId:wordNr:bitMask]    EB will read trigger type from the first data stream");
+       syslog(LOG_ERR, "                                    (evtId is not used now) from wordNr according to bitMask,");
+       syslog(LOG_ERR, "                                    default:  1:2:f00000");
        syslog(LOG_ERR, "       [--online]                   Switch on online service (default off).");
        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.");
@@ -268,6 +279,43 @@ static void usage(const char *progName)
        syslog(LOG_ERR, "       [--ebnum num]                Number of the event builder.");
 }
 
+static int makeTrigType(TheArgs *my)
+{
+       int retVal = 0;
+
+       if (0 == (sscanf(my->trigType, "%x:%x:%x", &my->subsysId, &my->wordNr, &my->bitMask))) {
+               syslog(LOG_ERR, "evtbuild.c: makeTrigType: %s", "trigtype option is wrong.");
+               retVal = -1;
+       }
+       printf("TrigType: 0x%x 0x%x 0x%x\n", my->subsysId, my->wordNr, my->bitMask);
+
+       /* 
+        * Count trailing zeros in the bit mask
+        *
+        * v = input to count trailing zero bits
+        * c = output: c will count v's trailing zero bits,
+        * so if v is 1101000 (base 2), then c will be 3
+        */
+
+       unsigned int v;
+       unsigned int c;
+
+       v = my->bitMask;
+
+       if (v) {
+               v = (v ^ (v - 1)) >> 1; /* Set v's trailing 0s to 1s and zero rest */
+               for (c = 0; v; c++) {
+                       v >>= 1;
+               }
+       } else {
+               c = CHAR_BIT * sizeof(v);
+       }
+
+       my->bitShift = c;
+
+       return retVal;
+}
+
 static int makeQueues(TheArgs *my)
 {
        int retVal = 0;
@@ -386,7 +434,13 @@ static void argsDefault(TheArgs *my)
        my->isStandalone = 1;
        my->queueSize[0] = 64 * 1024 * 1024UL;
        strcpy(my->verbosity, "info");
+
        my->evtId = 0;
+       my->subsysId = 1;
+       my->wordNr = 2;
+       my->bitMask = 0xf000000;
+       my->bitShift = 24;
+
        my->maxFileSz = (1.5 * 1024 * 1024 * 1024UL - 1);
        my->online = 0;                         /* 0=off, 1=on */
        my->write_data = 0;
@@ -462,9 +516,10 @@ static int argsFromCL(TheArgs *my, int argc, char *argv[])
                        {"orapath", 1, 0, 'O'},
                        {"ignore", 0, 0, 'i'},
                        {"debug", 1, 0, 'D'},
+                       {"trigtype", 1, 0, 'T'},
                        {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:D:", 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:T:", long_options,
                                                &option_index);
                if (i == -1)
                        break;
@@ -499,6 +554,11 @@ static int argsFromCL(TheArgs *my, int argc, char *argv[])
                case 'Q':
                        strcpy(my->queueVarSize[my->queueVarSizeCnt++], optarg);
                        break;
+               case 'T':
+                       strcpy(my->trigType, optarg);
+                       if (makeTrigType(my) == -1)
+                               return -1;
+                       break;
                case 'v':
                        strcpy(my->verbosity, optarg);
                        break;
@@ -573,11 +633,9 @@ static int argsFromCL(TheArgs *my, int argc, char *argv[])
                        sprintf(my->runinfo2ora, "%s_runinfo2ora.txt", getenv("DAQ_SETUP"));
                        break;
                case 'H':
-                       usage(argv[0]);
                        return -1;
                        break;
                default:
-                       usage(argv[0]);
                        return -1;
                        break;
                }
@@ -1941,6 +1999,7 @@ int main(int argc, char *argv[])
        rfio_openConnection(theArgs);
 #endif
 
+       uint32_t trigType;
        uint32_t lastCurrTrigNr = 0;
        int brokenEvtCnt = 0;
 
@@ -2044,7 +2103,9 @@ int main(int argc, char *argv[])
 
                                if (theArgs->evtId != 0)
                                        currId = theArgs->evtId;
-                               else
+                               else if (theArgs->subsysId != 0) {
+                                       currId = SubEvt_trigType(subEvt, theArgs->wordNr, theArgs->bitMask, theArgs->bitShift);
+                               } else
                                        currId = SubEvt_pureId(subEvt);
 
                                syslog(LOG_DEBUG, "currTrigNr: 0x%06x, currTrigTag 0x%02x, currId 0x%08x", currTrigNr, currTrigTag, currId);