Index: trunk/FACT++/src/EventBuilder.c
===================================================================
--- trunk/FACT++/src/EventBuilder.c	(revision 15469)
+++ trunk/FACT++/src/EventBuilder.c	(revision 15470)
@@ -589,7 +589,13 @@
         evtCtrl[i].fEvent->StartTM[k] = -1;
 
-    evtCtrl[i].fEvent->NumBoards = 0;
-    evtCtrl[i].fEvent->PCTime    = evtCtrl[i].pcTime[0];
-    evtCtrl[i].fEvent->PCUsec    = evtCtrl[i].pcTime[1];
+    evtCtrl[i].fEvent->NumBoards   = 0;
+    evtCtrl[i].fEvent->SoftTrig    = 0;
+    evtCtrl[i].fEvent->PCTime      = evtCtrl[i].pcTime[0];
+    evtCtrl[i].fEvent->PCUsec      = evtCtrl[i].pcTime[1];
+    evtCtrl[i].fEvent->Roi         = evtCtrl[i].nRoi;
+    evtCtrl[i].fEvent->RoiTM       = evtCtrl[i].nRoiTM;
+    evtCtrl[i].fEvent->EventNum    = evtCtrl[i].evNum;
+    evtCtrl[i].fEvent->TriggerNum  = evtCtrl[i].trgNum;
+    evtCtrl[i].fEvent->TriggerType = evtCtrl[i].trgTyp;
 }
 
@@ -1261,27 +1267,27 @@
 
           //get index into mBuffer for this event (create if needed)
-          const int evID = mBufEvt(i);
+          const int idx = mBufEvt(i);
 
           // no free entry in mBuffer, retry later
-          if (evID == -1)
+          if (idx == -1)
               continue;
 
           // We have a valid entry, but no memory has yet been allocated
-          if (evID >= 0 && evtCtrl[evID].FADhead == NULL)
+          if (idx >= 0 && evtCtrl[idx].FADhead == NULL)
           {
               // Try to get memory from the big buffer
-              evtCtrl[evID].FADhead = (PEVNT_HEADER*)TGB_Malloc();
-              if (evtCtrl[evID].FADhead == NULL)
+              evtCtrl[idx].FADhead = (PEVNT_HEADER*)TGB_Malloc();
+              if (evtCtrl[idx].FADhead == NULL)
               {
                   // If this works properly, this is a hack which can be removed, or
                   // replaced by a signal or dim message
                   if (rd[i].bufTyp==2)
-                      factPrintf(kError, 882, "malloc failed for event %d", evID);
+                      factPrintf(kError, 882, "malloc failed for event %d (run=%d)", evtCtrl[idx].evNum, evtCtrl[idx].runNum);
                   rd[i].bufTyp = 2;
                   continue;
               }
 
-              // Initialice mBuffer[evID]->fEvent
-              initEvent(evID);
+              // Initialise contents of mBuffer[evID]->fEvent
+              initEvent(idx);
 
               // Some statistics
@@ -1295,14 +1301,4 @@
               if (gj.bufTot > gj.maxEvt)
                   gj.maxEvt = gj.bufTot;
-
-              //register event in 'active list (reading)'
-              //mBuffer[evID].evtCtrl_idx = evtCtrl_lastPtr;
-
-              //evtCtrl[evtCtrl_lastPtr].mBuffer_idx = evID;
-              //evtCtrl[evtCtrl_lastPtr].evtStat = 0;
-              //evtCtrl[evtCtrl.lastPtr].pcTime  = g_actTime;
-
-              //evtCtrl_lastPtr++;
-              //evtCtrl_lastPtr %= MAX_EVT * MAX_RUN;
           }
 
@@ -1313,5 +1309,5 @@
 
           // Fatal error occured. Event cannot be processed. Skip it. Start reading next header.
-          if (evID < -1000)
+          if (idx < -1000)
               continue;
 
@@ -1326,8 +1322,8 @@
           }
 
-          if (evtCtrl[evID].board[board] != -1)
+          if (evtCtrl[idx].board[board] != -1)
           {
               factPrintf(kWarn, 501, "Got event %5d from board %3d (i=%3d, len=%5d) twice: Starts with %3d %3d - ends with %3d %3d",
-                         evID, board, i, rd[i].fadLen,
+                         evtCtrl[idx].evNum, board, i, rd[i].fadLen,
                          rd[i].rBuf->B[0], rd[i].rBuf->B[1],
                          rd[i].rBuf->B[rd[i].fadLen - 2],
@@ -1337,21 +1333,21 @@
 
           // Copy data from rd[i] to mBuffer[evID]
-          copyData(i, evID, board);
+          copyData(i, idx, board);
 
           // now we have stored a new board contents into Event structure
 
-          evtCtrl[evID].fEvent->NumBoards++;
-          evtCtrl[evID].board[board] = board;
-          evtCtrl[evID].nBoard++;
-          evtCtrl[evID].evtStat  = evtCtrl[evID].nBoard;
+          evtCtrl[idx].fEvent->NumBoards++;
+          evtCtrl[idx].board[board] = board;
+          evtCtrl[idx].nBoard++;
+          evtCtrl[idx].evtStat  = evtCtrl[idx].nBoard;
 
           // have we already reported first (partial) event of this run ???
-          if (evtCtrl[evID].nBoard==1 && evtCtrl[evID].runNum != actrun)
+          if (evtCtrl[idx].nBoard==1 && evtCtrl[idx].runNum != actrun)
           {
               // Signal the fadctrl that a new run has been started
-              gotNewRun(evtCtrl[evID].runNum, NULL);
+              gotNewRun(evtCtrl[idx].runNum, NULL);
 
               factPrintf(kInfo, 1, "gotNewRun called, prev run %d, new run %d, event %d",
-                         actrun, evtCtrl[evID].runNum, evtCtrl[evID].evNum);
+                         actrun, evtCtrl[idx].runNum, evtCtrl[idx].evNum);
 
               for (int j=0; j<MAX_RUN; j++)
@@ -1364,14 +1360,14 @@
                   // We got the first part of this event, so this is
                   // the number of events we expect for this run
-                  if (runCtrl[j].runId==evtCtrl[evID].runNum)
+                  if (runCtrl[j].runId==evtCtrl[idx].runNum)
                       runCtrl[j].lastEvt++;
               }
 
               // Change 'actrun' the the new runnumber
-              actrun = evtCtrl[evID].runNum;
+              actrun = evtCtrl[idx].runNum;
           }
 
           // event not yet complete
-          if (evtCtrl[evID].nBoard < actBoards)
+          if (evtCtrl[idx].nBoard < actBoards)
               continue;
 
@@ -1386,5 +1382,5 @@
 
           // Flag that the event is ready for processing
-          evtCtrl[evID].evtStat = 99;
+          evtCtrl[idx].evtStat = 99;
 
       } // end for loop over all sockets
@@ -1823,15 +1819,8 @@
 
            //and set correct event header ; also check for consistency in event (not yet)
-           evtCtrl[k0].fEvent->Roi         = evtCtrl[k0].nRoi;
-           evtCtrl[k0].fEvent->RoiTM       = evtCtrl[k0].nRoiTM;
-           evtCtrl[k0].fEvent->EventNum    = evtCtrl[k0].evNum;
-           evtCtrl[k0].fEvent->TriggerNum  = evtCtrl[k0].trgNum;
-           evtCtrl[k0].fEvent->TriggerType = evtCtrl[k0].trgTyp;
            evtCtrl[k0].fEvent->Errors[0]   = evtCtrl[k0].Errors[0];
            evtCtrl[k0].fEvent->Errors[1]   = evtCtrl[k0].Errors[1];
            evtCtrl[k0].fEvent->Errors[2]   = evtCtrl[k0].Errors[2];
            evtCtrl[k0].fEvent->Errors[3]   = evtCtrl[k0].Errors[3];
-           evtCtrl[k0].fEvent->SoftTrig    = 0;
-
 
            for (int ib=0; ib<NBOARDS; ib++)
