Index: /trunk/FACT++/src/EventBuilder.c
===================================================================
--- /trunk/FACT++/src/EventBuilder.c	(revision 15343)
+++ /trunk/FACT++/src/EventBuilder.c	(revision 15344)
@@ -2327,5 +2327,5 @@
 }
 
-void checkAndCloseRun(int j, int irun, int cond, char *where)
+void checkAndCloseRun(int j, int irun, int cond, int where)
 {
     if (!cond &&
@@ -2360,13 +2360,13 @@
     if (rc<0)
     {
-        factPrintf(kError, 503, "writeEvt-%s: Error closing run %d (runClose[1],rc=%d)",
+        factPrintf(kError, 503, "writeEvt-%d: Error closing run %d (runClose,rc=%d)",
                    where, runCtrl[j].runId, rc);
-        runCtrl[j].fileId = 92;
+        runCtrl[j].fileId = 92+where*2;
     }
     else
     {
-        factPrintf(kInfo, 503, "writeEvt-%s: Closed run %d (ii=%d)",
+        factPrintf(kInfo, 503, "writeEvt-%d: Closed run %d (reason=%d)",
                    where, irun, ii);
-        runCtrl[j].fileId = 93;
+        runCtrl[j].fileId = 93+where*2;
     }
 }
@@ -2500,5 +2500,5 @@
                   }
 
-                  checkAndCloseRun(j, irun, rc<0, "1");
+                  checkAndCloseRun(j, irun, rc<0, 1);
                }
             }
@@ -2553,5 +2553,5 @@
               //ETIENNE added the condition at this line. dunno what to do with run 0: skipping it
               const int cond = runCtrl[j].lastTime < lastStartedTime && runCtrl[j].runId != 0;
-              checkAndCloseRun(j, runCtrl[j].runId, cond, "2");
+              checkAndCloseRun(j, runCtrl[j].runId, cond, 2);
           }
       }
@@ -2581,30 +2581,8 @@
    factPrintf(kInfo, -1, "Close all open files ...");
    for (j = 0; j < MAX_RUN; j++)
-      if (runCtrl[j].fileId == 0) {
-         if (runCtrl[j].runId == gi_myRun)
-            gi_myRun = g_actTime;
-
-         if (runCtrl[j].procId == 0) {
-            runFinish1 (runCtrl[j].runId);
-            runCtrl[j].procId = 92;
-         }
-
-         runCtrl[j].closeTime = g_actTime - 1;
-         int i = runClose (runCtrl[j].fileHd, &runTail[j], sizeof (runTail[j]));
-         int ii = 0;
-         if (runCtrl[j].closeTime < g_actTime)
-            ii |= 2; // = 2
-         /*else*/ if (runCtrl[j].lastTime < g_actTime - 300)
-            ii |= 4; // = 3
-         /*else*/ if (runCtrl[j].maxEvt <= runCtrl[j].actEvt)
-            ii |= 8; // = 4
-         if (i < 0) {
-             factPrintf(kError, 506, "writeEvt: Error closing run %d (runClose[3],i=%d)", runCtrl[j].runId, i);
-            runCtrl[j].fileId = 96;
-         } else {
-             factPrintf(kInfo, 507, "writeEvt: Closed run %d (ii[3]=%d)", runCtrl[j].runId, ii);
-            runCtrl[j].fileId = 97;
-         }
-      }
+   {
+       if (runCtrl[j].fileId == 0)
+           checkAndCloseRun(j, runCtrl[j].runId, 1, 3);
+   }
 
    gw_runStat = -99;
