Index: /trunk/FACT++/src/EventBuilder.c
===================================================================
--- /trunk/FACT++/src/EventBuilder.c	(revision 15467)
+++ /trunk/FACT++/src/EventBuilder.c	(revision 15468)
@@ -141,7 +141,4 @@
 
 
-#define THOMAS_MALLOC
-
-#ifdef THOMAS_MALLOC
 #define MAX_HEAD_MEM (NBOARDS * sizeof(PEVNT_HEADER))
 #define MAX_TOT_MEM (sizeof(EVENT) + (NPIX+NTMARK)*1024*2 + MAX_HEAD_MEM)
@@ -196,127 +193,4 @@
     tgb_inuse -= MAX_TOT_MEM;
 }
-#endif
-
-#ifdef ETIENNE_MALLOC
-//ETIENNE
-#define MAX_SLOTS_PER_CHUNK 100
-
-typedef struct {
-    int32_t eventNumber;
-    int32_t chunk;
-    int32_t slot;
-} CHUNK_MAPPING;
-
-CHUNK_MAPPING mBufferMapping[MAX_EVT * MAX_RUN];
-
-#define MAX_EVT_MEM (sizeof(EVENT) + NPIX*1024*2 + NTMARK*1024*2)
-#define MAX_HEAD_MEM (NBOARDS * sizeof(PEVNT_HEADER))
-#define MAX_SLOT_SIZE (MAX_EVT_MEM + MAX_HEAD_MEM)
-#define MAX_CHUNK_SIZE (MAX_SLOT_SIZE*MAX_SLOTS_PER_CHUNK)
-
-typedef struct {
-    void * pointers[MAX_SLOTS_PER_CHUNK];
-    int32_t events[MAX_SLOTS_PER_CHUNK];
-    int32_t nFreeSlots;
-    int32_t nSlots;
-} ETI_CHUNK;
-
-int32_t numAllocatedChunks = 0;
-
-#define MAX_CHUNKS 8096
-ETI_CHUNK EtiMemoryChunks[MAX_CHUNKS];
-
-void* ETI_Malloc(int evtId, int evtIndex)
-{
-    for (int i=0;i<numAllocatedChunks;i++) {
-        if (EtiMemoryChunks[i].nFreeSlots > 0) {
-            for (int j=0;j<EtiMemoryChunks[i].nSlots;j++)
-            {
-                if (EtiMemoryChunks[i].events[j] == -1)
-                {
-                    EtiMemoryChunks[i].events[j] = evtId;
-                    EtiMemoryChunks[i].nFreeSlots--;
-                    if (EtiMemoryChunks[i].nFreeSlots < 0)
-                    {
-                        factPrintf(kError, 0, "Number of free slot in chunk %d went below zero (%d) slot: %d", i, EtiMemoryChunks[i].nFreeSlots, j);
-                        return NULL;
-                    }
-                    mBufferMapping[evtIndex].eventNumber = evtId;
-                    mBufferMapping[evtIndex].chunk = i;
-                    mBufferMapping[evtIndex].slot = j;
-                    return EtiMemoryChunks[i].pointers[j];
-                }
-            }
-            //If I reach this point then we have a problem because it should have found
-            //a free spot just above.
-            factPrintf(kError, 0, "Could not find a free slot in a chunk that's supposed to have some. chunk=%d", i);
-            return NULL;
-        }
-    }
-    //If we reach this point this means that we should allocate more memory
-    int32_t numNewSlots = MAX_SLOTS_PER_CHUNK;
-    if ((numAllocatedChunks + 1)*MAX_CHUNK_SIZE >= g_maxMem)
-        return NULL;
-
-    EtiMemoryChunks[numAllocatedChunks].pointers[0] = malloc(MAX_SLOT_SIZE*MAX_SLOTS_PER_CHUNK);
-    if (EtiMemoryChunks[numAllocatedChunks].pointers[0] == NULL)
-    {
-        factPrintf(kError, 0, "Allocation of %lu bytes failed. %d chunks are currently allocated (max allowed %lu bytes)", MAX_CHUNK_SIZE, numAllocatedChunks, g_maxMem);
-        return NULL;
-    }
-
-    EtiMemoryChunks[numAllocatedChunks].nSlots = numNewSlots;
-    EtiMemoryChunks[numAllocatedChunks].events[0] = evtId;
-    EtiMemoryChunks[numAllocatedChunks].nFreeSlots = numNewSlots-1;
-    mBufferMapping[evtIndex].eventNumber = evtId;
-    mBufferMapping[evtIndex].chunk = numAllocatedChunks;
-    mBufferMapping[evtIndex].slot = 0;
-
-    for (int i=1;i<numNewSlots;i++)
-    {
-        EtiMemoryChunks[numAllocatedChunks].pointers[i] = (char*)EtiMemoryChunks[numAllocatedChunks].pointers[0] + i*MAX_SLOT_SIZE;// &(((char*)(EtiMemoryChunks[numAllocatedChunks].pointers[i-1]))[MAX_SLOT_SIZE]);
-        EtiMemoryChunks[numAllocatedChunks].events[i] = -1;
-    }
-    numAllocatedChunks++;
-
-    return EtiMemoryChunks[numAllocatedChunks-1].pointers[0];
-}
-
-void ETI_Free(int evtId, int evtIndex)
-{
-    ETI_CHUNK* currentChunk = &EtiMemoryChunks[mBufferMapping[evtIndex].chunk];
-    if (currentChunk->events[mBufferMapping[evtIndex].slot] != evtId)
-    {
-        factPrintf(kError, 0, "Mismatch in chunk mapping table. Expected evtId %d. Got %d. No memory was freed.", evtId, currentChunk->events[mBufferMapping[evtIndex].slot]);
-        return;
-    }
-    currentChunk->events[mBufferMapping[evtIndex].slot] = -1;
-    currentChunk->nFreeSlots++;
-
-    return; /* TEST */
-
-    int chunkIndex = mBufferMapping[evtIndex].chunk;
-    if (chunkIndex != numAllocatedChunks-1)
-        return;
-
-    while (EtiMemoryChunks[chunkIndex].nFreeSlots == EtiMemoryChunks[chunkIndex].nSlots)
-    {//free this chunk
-        if (EtiMemoryChunks[chunkIndex].pointers[0] == NULL)
-        {
-            factPrintf(kError, 0, "Chunk %d not allocated as it ought to be. Skipping memory release.", chunkIndex);
-            return;
-        }
-        free(EtiMemoryChunks[chunkIndex].pointers[0]);
-        EtiMemoryChunks[chunkIndex].pointers[0] = NULL;
-        EtiMemoryChunks[chunkIndex].nSlots = 0;
-        numAllocatedChunks--;
-        chunkIndex--;
-        if (numAllocatedChunks == 0)
-            break;
-    }
-}
-//END ETIENNE
-#endif
-
 
 RUN_CTRL runCtrl[MAX_RUN];
@@ -507,17 +381,5 @@
       //evtCtrl[i].mBuffer_idx = -1;
       evtCtrl[i].evtStat = -1;
-
-#ifdef ETIENNE_MALLOC
-      //ETIENNE
-      mBufferMapping[i].chunk = -1;
-      mBufferMapping[i].eventNumber = -1;
-      mBufferMapping[i].slot = -1;
-      //END ETIENNE
-#endif
-   }
-#ifdef ETIENNE_MALLOC
-   for (int j=0;j<MAX_CHUNKS;j++)
-       EtiMemoryChunks[j].pointers[0] = NULL;
-#endif
+   }
 
    //actRun.FADhead = malloc (NBOARDS * sizeof (PEVNT_HEADER));
@@ -739,50 +601,13 @@
 //(and make sure multiple calls do no harm ....)
 
-//   int headmem = 0;
-//   size_t freemem = 0;
-
-#ifdef ETIENNE_MALLOC
-   int evid;
-   evid = mBuffer[i].evNum;
-   ETI_Free(evid, i);
-#endif
-
-//   freemem = mBuffer[i].evtLen;
-   //ETIENNE
-#ifdef THOMAS_MALLOC
    TGB_free(evtCtrl[i].FADhead);
-#endif
-
-#ifdef STANDARD_MALLOC
-   free (mBuffer[i].FADhead);
-#endif
-
-//   free (mBuffer[i].fEvent);
+
    evtCtrl[i].fEvent = NULL;
-
-//   free (mBuffer[i].FADhead);
    evtCtrl[i].FADhead = NULL;
 
-//   free (mBuffer[i].buffer);
-//   mBuffer[i].buffer = NULL;
-//END ETIENNE
-//   headmem = NBOARDS * sizeof (PEVNT_HEADER);
    evtCtrl[i].evNum = evtCtrl[i].nRoi = -1;
    evtCtrl[i].runNum = 0;
 
-#ifdef ETIENNE_MALLOC
-//ETIENNE
-//   gj.usdMem = gj.usdMem - freemem - headmem - gi_maxSize;
-   gj.usdMem = 0;
-   for (int k=0;k<numAllocatedChunks;k++)
-   {
-       gj.usdMem += EtiMemoryChunks[k].nSlots * MAX_SLOT_SIZE;
-   }
-//END ETIENNE
-#endif
-
-#ifdef THOMAS_MALLOC
    gj.usdMem = tgb_inuse;
-#endif
 
    gj.bufTot--;
@@ -1134,9 +959,5 @@
       gj.bufTot = gj.maxEvt = gj.xxxEvt = 0;
       gj.usdMem = gj.maxMem = gj.xxxMem = 0;
-#ifdef THOMAS_MALLOC
       gj.totMem = tgb_memory;
-#else
-      gj.totMem = g_maxMem;
-#endif
       gj.bufNew = gj.bufEvt = 0;
       //gj.badRoiE = gj.badRoiR = gj.badRoiB = 0;
@@ -1648,9 +1469,5 @@
           gj.totBytes[ib] += gj.rateBytes[ib];
 
-#ifdef THOMAS_MALLOC
       gj.totMem = tgb_memory;
-#else
-      gj.totMem = g_maxMem;
-#endif
 
       if (gj.maxMem > gj.xxxMem)
@@ -1803,7 +1620,5 @@
    factPrintf(kInfo, -1, "Exit read Process...");
 
-#ifdef THOMAS_MALLOC
    factPrintf(kInfo, -1, "%ld Bytes flaged as in-use.", tgb_inuse);
-#endif
 
    gi_runStat = -99;
