]> jspc29.x-matter.uni-frankfurt.de Git - daqdata.git/commitdiff
Make ANSI C happy again -- mm
authorhadaq <hadaq>
Wed, 9 Oct 2002 15:38:46 +0000 (15:38 +0000)
committerhadaq <hadaq>
Wed, 9 Oct 2002 15:38:46 +0000 (15:38 +0000)
hadaq/hwrich.c

index 25f3c45cff294eb4c655740d818b0b2715893fa1..67ee53b3e7933551c95b2430bb9ee434833a4286 100644 (file)
@@ -1,4 +1,4 @@
-static char *rcsId = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hadaq/Attic/hwrich.c,v 6.24 2002-10-09 12:42:17 hadaq Exp $";
+static char *rcsId = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hadaq/Attic/hwrich.c,v 6.25 2002-10-09 15:38:46 hadaq Exp $";
 
 #define _POSIX_C_SOURCE 199309L
 #include <unistd.h>
@@ -15,13 +15,11 @@ static char *rcsId = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hada
 #include "subevt.h"
 #include "hwrace.h"
 
-/* Set number of RCs here */
-#define NRACES 4
-
 struct HardwareS {
        size_t maxSubEvtSize;
-       HwRace *race[NRACES];
-       LInt *lInt[NRACES];
+       int nRaces;
+       HwRace **race;
+       LInt **lInt;
 };
 
 #include "hardware.h"
@@ -36,31 +34,107 @@ int Hardware_inSpill(const Hardware *my)
        return 0;
 }
 
-Hardware *newHardware(void)
+static int getCards(Param *param, const char *subsystem, const char *cardtype, int *nCards, char **cards) {
+       int getCardsR;
+       int i;
+       char unitsS[PARAM_MAX_ARRAY_LEN][PARAM_MAX_VALUE_LEN];
+       char *units[PARAM_MAX_ARRAY_LEN];
+       int r;
+
+       for (i = 0; i < PARAM_MAX_ARRAY_LEN; i++) {
+               units[i] = unitsS[i];
+       }
+
+       if (0 > Param_getStringArray(param, subsystem, "unit", PARAM_MAX_ARRAY_LEN, &r, units) || r == 0) {
+               getCardsR = -1;
+               syslog(LOG_ERR, "Parameter %s(unit) not found, unknown list of VME modules", subsystem);
+       } else {
+               int unit;
+               int card;
+
+               getCardsR = 0;
+               card = 0;
+               for (unit = 0; unit < r; unit++) {
+                       char ct[PARAM_MAX_VALUE_LEN];
+                       int r;
+               
+                       if (Param_getString(param, units[unit], "cardtype", &r, ct) || r == 0) {
+                               syslog(LOG_ERR, "Parameter %s(cardtype) not found", units[unit]);
+                               getCardsR = -1;
+                       } else {
+                               if (strcmp(cardtype, ct) == 0) {
+                                       strcpy(cards[card++], units[unit]);
+                               }
+                       }
+               }
+               *nCards = card;
+       }
+
+       if (0 == getCardsR) {
+               int card;
+
+               syslog(LOG_DEBUG, "List of matching cards for subsystem %s, cardtype %s", subsystem, cardtype);
+               for (card = 0; card < *nCards; card++) {
+                       syslog(LOG_DEBUG, "%s", cards[card]);
+               }
+       }
+       return getCardsR;
+}
+
+Hardware *newHardware(const char *subsystem)
 {
        Hardware *my;
        Param paramS, *param = &paramS;
        int i;
+       const char *ss;
+       char cardsS[PARAM_MAX_ARRAY_LEN][PARAM_MAX_VALUE_LEN];
+       char *cards[PARAM_MAX_ARRAY_LEN];
+       int nCards;
+
+       for (i = 0; i < PARAM_MAX_ARRAY_LEN; i++) {
+               cards[i] = cardsS[i];
+       }
 
+       if (strcmp(subsystem, "unknown") == 0) {
+               syslog(LOG_NOTICE, "Subsystem not set, defaulting to rich0");
+               ss = "rich0";
+       } else {
+               ss = subsystem;
+       }
+               
        if (0 > conParam(param)) {
                syslog(LOG_ERR, "%s:%d:%s", __FILE__, __LINE__, strerror(errno));
                return NULL;
        }
-       my = malloc(sizeof(Hardware));
 
-       my->maxSubEvtSize = SubEvt_hdrSize() + (NRACES * 2500 * sizeof(uint32_t));
+       if (0 > getCards(param, ss, "race", &nCards, cards)) {
+               syslog(LOG_ERR, "Retrieval of card list failed");
+               return NULL;
+       }
+
+       my = malloc(sizeof(Hardware));
+       my->race = malloc(nCards * sizeof(HwRace));
+       my->lInt = malloc(nCards * sizeof(LInt));
 
-       for (i = 0; i < NRACES; i++) {
-               char buf[16];
+       my->maxSubEvtSize = SubEvt_hdrSize() + (nCards * 2500 * sizeof(uint32_t));
+       my->nRaces = nCards;
 
+       for (i = 0; i < my->nRaces; i++) {
+               unsigned long statusId;
+               int paramWasFound;
+               
                my->race[i] = malloc(sizeof(HwRace));
-               sprintf(buf, "race%d", i);
-               if (0 > conHwRace(my->race[i], buf, param)) {
+               if (0 > conHwRace(my->race[i], cards[i], param)) {
                        syslog(LOG_ERR, "%s:%d:%s", __FILE__, __LINE__, strerror(errno));
                        return NULL;
                }
                my->lInt[i] = malloc(sizeof(LInt));
-               conLInt(my->lInt[i], 100 + i);
+               Param_getInt(param, my->race[i]->name, "status_id", &paramWasFound, &statusId);
+               if (!paramWasFound) {
+                       syslog(LOG_ERR, "Parameter %s(status_id) not found", my->race[i]->name);
+                       return NULL;
+               }
+               conLInt(my->lInt[i], statusId);
        }
 
        desParam(param);
@@ -71,12 +145,14 @@ void deleteHardware(Hardware *my)
 {
        int i;
 
-       for (i = 0; i < NRACES; i++) {
+       for (i = 0; i < my->nRaces; i++) {
                desLInt(my->lInt[i]);
                free(my->lInt[i]);
                desHwRace(my->race[i]);
                free(my->race[i]);
        }
+       free(my->lInt);
+       free(my->race);
        free(my);
 }
 
@@ -84,7 +160,7 @@ void Hardware_waitForTrigger(Hardware *my, void *subEvt)
 {
        int i;
 
-       for (i = 0; i < NRACES; i++) {
+       for (i = 0; i < my->nRaces; i++) {
                if (HwRace_isEmpty(my->race[i])) {
                        HwRace_requestBuffer(my->race[i]);
 #ifndef NDEBUG
@@ -93,7 +169,7 @@ void Hardware_waitForTrigger(Hardware *my, void *subEvt)
                }
        }
 
-       for (i = 0; i < NRACES; i++) {
+       for (i = 0; i < my->nRaces; i++) {
                if(HwRace_isBufRequested(my->race[i])) {
                        LInt_wait(my->lInt[i]);
                        HwRace_getEndOfData(my->race[i]);
@@ -119,7 +195,7 @@ void Hardware_readout(Hardware *my, void *partEvt)
 
        /* read all races, check for common trigger tag */
        firstRace = -1;
-       for (i = 0; i < NRACES; i++) {
+       for (i = 0; i < my->nRaces; i++) {
                if((size=HwRace_readSubEvt(my->race[i], subEvt)) > 0) {
                  if (firstRace < 0) {
                        trigTag = SubEvt_trigNr(subEvt) & 0xff;
@@ -132,8 +208,7 @@ void Hardware_readout(Hardware *my, void *partEvt)
                                        my->race[i]->name,trigTag,firstRace,SubEvt_trigNr(subEvt));
                        }
                  }
-                 /* this does 64 bit alignment, should be replaced by a function */
-                 (char *)subEvt += (size+4) & 0xffffff8;
+               subEvt = SubEvt_next(partEvt, subEvt);
                }
        }