]> jspc29.x-matter.uni-frankfurt.de Git - daqdata.git/commitdiff
avoid copies for realloc, event size has MAX now !!!
authorhades <hades>
Thu, 9 Sep 1999 14:54:44 +0000 (14:54 +0000)
committerhades <hades>
Thu, 9 Sep 1999 14:54:44 +0000 (14:54 +0000)
hadaq/evt.c
hadaq/evt.h
hadaq/evtbuild.c

index b46ed60ff8501224b15ef1a7a194f3ea7727f827..1a74f093a9187184b1f42e06c96966543ea83f11 100644 (file)
@@ -1,4 +1,4 @@
-static char rcsId[] = "$Id: evt.c,v 6.1 1999-08-31 10:37:23 muench Exp $";
+static char rcsId[] = "$Id: evt.c,v 6.2 1999-09-09 14:54:44 hades Exp $";
 
 #define _ANSI_C_SOURCE
 #include <stddef.h>
@@ -143,24 +143,19 @@ char *Evt_2charP(const void *my)
 void *newEvt(UInt4 decoding, UInt4 id, UInt4 runNr)
 {
        void *my;
+       static UInt4 seqNr = 0;
+       time_t tempo;
+       struct tm *gmTime;
+       UInt4 dummy;
 
-       my = allocMem(Evt_hdrSize());
+
+       my = allocMem(EVT_MAXSIZE);
 
        Evt_setSize(my, Evt_hdrSize());
        Evt_setDecoding(my, decoding);
        Evt_setId(my, id);
        Evt_setRunNr(my, runNr);
 
-       return my;
-}
-
-void *getEvt(void *my)
-{
-       static UInt4 seqNr = 0;
-       time_t tempo;
-       struct tm *gmTime;
-       UInt4 dummy;
-
        Evt_setSeqNr(my, seqNr++);
 
        tempo = time(NULL);
@@ -193,8 +188,6 @@ int Evt_write(void *my, FILE * file)
 
 void *Evt_appendSubEvt(void *my, void *subEvt)
 {
-       /* BUGBUG in principal, aligned memory size must be allocated */
-       my = reallocMem(my, Evt_paddedSize(my) + SubEvt_size(subEvt));
        memcpy(Evt_end(my), subEvt, SubEvt_size(subEvt));
        Evt_setSize(my, Evt_paddedSize(my) + SubEvt_size(subEvt));
 
@@ -203,18 +196,12 @@ void *Evt_appendSubEvt(void *my, void *subEvt)
 
 void *Evt_fget(FILE * file)
 {
-       static void *evt = NULL;
-
-       if (evt != NULL) {
-               freeMem(evt);
-       }
-       evt = allocMem(Evt_hdrSize());
+       static void evt[EVT_MAXSIZE];
 
        if (Evt_hdrSize() != fread(evt, 1, Evt_hdrSize(), file)) {
                msglog(LOG_DEBUG, "%s:%d: %s\n", __FILE__, __LINE__, strerror(errno));
                return NULL;
        }
-       evt = reallocMem(evt, Evt_paddedSize(evt));
 
        /* BUGBUG quickhack for a "Evt_paddedDataSize" */
        if (Evt_paddedSize(evt) - Evt_hdrSize() != fread(Evt_data(evt), 1, Evt_paddedSize(evt) - Evt_hdrSize(), file)) {
index e5d9f922690ddeff8491270985f1b9632d471439..f644df82c66ae0cf60079e4c8cb166a32fa4bce2 100644 (file)
@@ -8,6 +8,8 @@
 #include "hadtu.h"
 #include "subevt.h"
 
+#define EVT_MAXSIZE (100 * 1024)
+
 static const int evtBlockSize = 8 * 1024;
 
 enum EvtId {
@@ -55,7 +57,6 @@ UInt4 Evt_runNr(const void *my);
 void Evt_setRunNr(void *my, UInt4 runNr);
 
 void *newEvt(UInt4 decoding, UInt4 id, UInt4 runNr);
-void *getEvt(void *my);
 void deleteEvt(void *my);
 int Evt_write(void *my, FILE * file);
 void *Evt_fget(FILE * file);
index 29b97498e16b69c2e3e590b0a0dd6dd2729eb037..d982d1924543a3b32b28c95ad8d83f701fa42cf4 100644 (file)
@@ -1,4 +1,4 @@
-static char rcsId[] = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hadaq/evtbuild.c,v 6.4 1999-09-06 07:33:14 hades Exp $";
+static char rcsId[] = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hadaq/evtbuild.c,v 6.5 1999-09-09 14:54:44 hades Exp $";
 
 #define _XOPEN_SOURCE
 #include <unistd.h>
@@ -280,7 +280,7 @@ int main(int argc, char *argv[])
                evt = appendFile(evt, slowCtrlFiles[i]);
        }
        if (outFile != NULL) {
-               Evt_write(getEvt(evt), outFile);
+               Evt_write(evt, outFile);
        }
        deleteEvt(evt);
 
@@ -337,8 +337,6 @@ int main(int argc, char *argv[])
                        }
                }
                if (currNrOfSubEvts == nrOfSubEvts) {
-                       evt = getEvt(evt);      /* BUGBUG differnce newEvt <> getEvt not
-                                   necessary  any more */
                        if (outFile != NULL) {
                                Evt_write(evt, outFile);
                        }
@@ -356,7 +354,7 @@ int main(int argc, char *argv[])
                evt = appendFile(evt, slowCtrlFiles[i]);
        }
        if (outFile != NULL) {
-               Evt_write(getEvt(evt), outFile);
+               Evt_write(evt, outFile);
        }
        deleteEvt(evt);