Index: trunk/FACT++/src/EventBuilder.c
===================================================================
--- trunk/FACT++/src/EventBuilder.c	(revision 11343)
+++ trunk/FACT++/src/EventBuilder.c	(revision 11443)
@@ -41,4 +41,6 @@
 extern int  runClose(FileHandle_t fileHd ,  RUN_TAIL *runth, size_t len ) ;
 extern void factOut(int severity, int err, char* message ) ;
+extern void gotNewRun( int runnr, PEVNT_HEADER *headers ); 
+
 
 extern void factStat(GUI_STAT gj) ;
@@ -58,4 +60,5 @@
 
 uint g_actTime   ;
+uint g_actUsec   ;
 int  g_runStat   ;
 int  g_reset     ;
@@ -77,6 +80,6 @@
  int gi_memStat = +1 ;
 
- uint32_t gi_myRun ;
-
+ uint32_t gi_myRun = 9876789 ;
+ uint32_t actrun ;
 
 
@@ -118,8 +121,8 @@
 
 typedef union {
-  int8_t  B[MAX_LEN/8];
-  int16_t S[MAX_LEN/4];
-  int32_t I[MAX_LEN/2];
-  int64_t L[MAX_LEN  ];
+  int8_t  B[MAX_LEN  ];
+  int16_t S[MAX_LEN/2];
+  int32_t I[MAX_LEN/4];
+  int64_t L[MAX_LEN/8];
 } CNV_FACT ;
 
@@ -137,10 +140,12 @@
   int  runID  ;          // run       "
   int  ftmID  ;          // event ID from FTM
-  uint  fadLen ;         // FADlength of event currently read
+  uint fadLen ;         // FADlength of event currently read
   int  fadVers ;         // Version of FAD
   int  board ;           // boardID (softwareID: 0..40 )
   int  Port ;
 
+  CNV_FACT *xBuf ;      //a copy of rBuf (temporary for debuging) 
   CNV_FACT *rBuf ;
+
 
 } READ_STRUCT ;
@@ -199,4 +204,5 @@
   if (flag < 0) {
      free(rd->rBuf) ;   //and never open again
+     free(rd->xBuf) ;   //and never open again
      rd->rBuf = NULL ;     
      rd->sockStat = 99 ;  
@@ -211,4 +217,5 @@
      rd->SockAddr.sin_addr = sockAddr->sin_addr ;
 
+     rd->xBuf = malloc(sizeof(CNV_FACT) ) ;
      rd->rBuf = malloc(sizeof(CNV_FACT) ) ;
      if ( rd->rBuf == NULL ) {
@@ -270,5 +277,5 @@
 
 
-int mBufEvt( int evID, uint runID, int nRoi) {
+int mBufEvt( int evID, uint runID, int nRoi, int sk, int fadlen) {
 // generate a new Event into mBuffer:   
 // make sure only complete Event are possible, so 'free' will always work
@@ -316,6 +323,9 @@
         if (gi_memStat>0 ) {
            gi_memStat = -99 ;
-           snprintf(str,MXSTR,"no memory left to keep event %d",evID) ;
+           snprintf(str,MXSTR,"no memory left to keep event %6d sock %3d",evID,sk) ;
            factOut(kError,882, str ) ;
+        } else {
+           snprintf(str,MXSTR,"no memory left to keep event %6d sock %3d",evID,sk) ;
+           factOut(kDebug,882, str ) ;
         }
         return -11 ;
@@ -354,4 +364,6 @@
    }
 
+   mBuffer[i].fEvent->PCTime[0] = g_actTime ;
+   mBuffer[i].fEvent->PCTime[1] = g_actUsec ;
    mBuffer[i].pcTime  = g_actTime ;
    mBuffer[i].nRoi    = nRoi ;
@@ -373,6 +385,7 @@
 
 
-snprintf(str,MXSTR,"%5d start new evt  %8d %8d %2d",evID,i,evtCtrl.lastPtr,0);
-factOut(kDebug,-11, str ) ;
+   snprintf(str,MXSTR,"%5d start new evt  %8d %8d sock %3d len %5d t %10d",
+      evID,i,evtCtrl.lastPtr,sk,fadlen,mBuffer[i].pcTime);
+   factOut(kDebug,-11, str ) ;
    evtCtrl.lastPtr++ ;
    if (evtCtrl.lastPtr == MAX_EVT*MAX_RUN ) evtCtrl.lastPtr = 0;
@@ -393,4 +406,5 @@
       runCtrl[evFree].runId = runID ;
       runCtrl[evFree].fileId = -2 ;
+      runCtrl[evFree].lastEvt= -1 ;
       runCtrl[evFree].nextEvt= 0;
       runCtrl[evFree].actEvt = 0;
@@ -419,6 +433,8 @@
 
    int headmem=0 ;
+   int evid ;
    size_t freemem = 0 ;
 
+   evid    = mBuffer[i].evNum  ;
    freemem = mBuffer[i].evtLen ; 
 
@@ -488,5 +504,5 @@
 void *readFAD( void *ptr ) {
 /* *** main loop reading FAD data and sorting them to complete events */
-  int head_len,frst_len,numok,numok2,dest,evID,i,k ;
+  int head_len,frst_len,numok,numok2,numokx,dest,evID,i,k ;
   int actBoards = 0, minLen ;
   int32_t jrd ;
@@ -498,5 +514,5 @@
 
   int sockDef[NBOARDS];    //internal state of sockets
-
+  int jrdx ;
 
 
@@ -509,4 +525,5 @@
 
 
+  gi_myRun   = g_actTime ;
   snprintf(str,MXSTR,"start initializing");
   factOut(kInfo,-1, str ) ;
@@ -546,5 +563,4 @@
   evtCtrl.lastPtr = 0 ;
 
-  gi_myRun   = g_actTime ;
   gi_SecTime = g_actTime ;
   gi_runStat = g_runStat ;
@@ -602,7 +618,7 @@
           gi.numConn[ b ] = 0; 
           gj.numConn[ b ] = 0; 
-          if (            sockDef[b] == 0) s0= 0 ;  //sockets to be defined and opened   
-          else if (g_port[b].sockDef == 0) s0=-1 ;  //sockets to be destroyed
-          else                             s0=+1 ;  //sockets to be closed and reopened
+          if (            sockDef[b] == 0) s0=  0 ;  //sockets to be defined and opened   
+          else if (g_port[b].sockDef == 0) s0= -1 ;  //sockets to be destroyed
+          else                             s0= +1 ;  //sockets to be closed and reopened
 
           if (s0 == 0) p0=ntohs(g_port[b].sockAddr.sin_port);
@@ -625,16 +641,16 @@
 
 
-
-
+    jrdx  = 0;
+    numokx= 0;
     numok = 0 ;                       //count number of succesfull actions
 
     for (i=0; i<MAX_SOCK; i++) {         //check all sockets if something to read
       b = i / 7 ;
-      if (sockDef[b] > 0) s0=+1 ;
-      else                s0=-1 ;
+      if (sockDef[b] > 0) s0= +1 ;
+      else                s0= -1 ;
 
       gettimeofday( tv, NULL);
       g_actTime = tsec = atv.tv_sec ;
-      tusec= atv.tv_usec ; 
+      g_actUsec = tusec= atv.tv_usec ;
 
       if (rd[i].sockStat <0 ) {         //try to connect if not yet done
@@ -647,5 +663,5 @@
           } else { 
              rd[i].bufTyp = -1 ;           //  full data to be skipped
-             rd[i].bufLen = sizeof(CNV_FACT) ; //huge for skipping
+             rd[i].bufLen = MAX_LEN ;      //huge for skipping
           }
           rd[i].bufPos = 0 ;            //  no byte read so far
@@ -666,4 +682,7 @@
           if (jrd >0 ) {
              debugStream(i,&rd[i].rBuf->B[ rd[i].bufPos],jrd) ;
+             memcpy(&rd[i].xBuf->B[ rd[i].bufPos], &rd[i].rBuf->B[ rd[i].bufPos], jrd) ;
+ snprintf(str,MXSTR,"read sock %3d bytes %5d , %5d",i,jrd,rd[i].bufLen);
+ factOut(kDebug,301, str ) ;
           }
 
@@ -685,8 +704,15 @@
              jrd = 0 ;
           }
-        } else jrd = 0 ;                //did read nothing as requested
+        } else {
+          jrd = 0 ;                //did read nothing as requested
+          snprintf(str,MXSTR,"do not read from socket %d  %d",i,rd[i].bufLen ) ;
+          factOut(kDebug,301, str ) ;
+        }
 
         gi.gotByte[ b ] += jrd ;
         gj.rateBytes[b] += jrd ;
+
+        if (jrd>0) {numokx++ ; jrdx+= jrd; }
+
 
         if ( rd[i].bufTyp <0 ) { // we are skipping this board ...
@@ -702,20 +728,34 @@
              rd[i].bufPos  = rd[i].fadLen ;
              if ( rd[i].rBuf->B[ rd[i].bufPos-1] != stop.B[0]
-               && rd[i].rBuf->B[ rd[i].bufPos  ] != stop.B[1]) {
+               || rd[i].rBuf->B[ rd[i].bufPos-2] != stop.B[1]) {
                 gi.evtErr++ ;
-                snprintf(str,MXSTR,"wrong end of buffer found %d",rd[i].bufPos);
+                snprintf(str,MXSTR,"wrong end of buffer found sock %3d ev %4d len %5d %3d %3d - %3d %3d ",
+                   i,rd[i].fadLen, rd[i].evtID, rd[i].rBuf->B[0], rd[i].rBuf->B[1], rd[i].rBuf->B[ rd[i].bufPos-2], 
+                   rd[i].rBuf->B[ rd[i].bufPos-1]);
                 factOut(kError,301, str ) ;
                 goto EndBuf ;
 
-             } 
-             debugRead(i,jrd,rd[i].evtID,rd[i].ftmID,rd[i].runID, 1,tsec,tusec) ; // i=socket; jrd=#bytes; ievt=eventid; 1=finished event
+//           } else {
+//              snprintf(str,MXSTR,"good  end of buffer found sock %3d len %5d %d %d : %d %d - %d %d : %d %d",
+//                 i,rd[i].fadLen, 
+//                 rd[i].rBuf->B[ 0 ],             rd[i].rBuf->B[ 1 ],           start.B[1],start.B[0],
+//                 rd[i].rBuf->B[ rd[i].bufPos-2], rd[i].rBuf->B[ rd[i].bufPos-1], stop.B[1], stop.B[0]);
+//              factOut(kDebug,301, str ) ;
+             }
+
+             if (jrd>0) debugRead(i,jrd,rd[i].evtID,rd[i].ftmID,rd[i].runID, 1,tsec,tusec) ; // i=socket; jrd=#bytes; ievt=eventid; 1=finished event
 
              //we have a complete buffer, copy to WORK area
              roi = ntohs(rd[i].rBuf->S[ head_len/2 + 2 ]) ; 
              //get index into mBuffer for this event (create if needed)
-             evID = mBufEvt( rd[i].evtID, rd[i].runID, roi ) ;
+             evID = mBufEvt( rd[i].evtID, rd[i].runID, roi, i, rd[i].fadLen ) ;
 
              if (evID <-9000) goto EndBuf ;  //illegal event, skip it ...
              if (evID < 0) {
+
+     if ( rd[i].bufLen != 0) { 
+        snprintf(str,MXSTR,"something screwed up");
+        factOut(kFatal, 1, str ) ;
+     }
                 xwait.tv_sec = 0;
                 xwait.tv_nsec= 10000000 ;  // sleep for ~10 msec
@@ -726,4 +766,19 @@
 
              //we have a valid entry in mBuffer[]; fill it
+
+int xchk = memcmp(&rd[i].xBuf->B[0], &rd[i].rBuf->B[0], rd[i].fadLen   ) ;
+if (xchk != 0) {
+   snprintf(str,MXSTR,"ERROR OVERWRITE %d %d on port %d",xchk,rd[i].fadLen,i) ;
+   factOut(kFatal, 1, str ) ;
+
+   uint iq;
+   for (iq=0; iq < rd[i].fadLen  ; iq++) {
+      if (rd[i].rBuf->B[iq] != rd[i].xBuf->B[iq] ) {
+         snprintf(str,MXSTR,"ERROR %4d %4d %x %x",i,iq,rd[i].rBuf->B[iq], rd[i].xBuf->B[iq]);
+         factOut(kFatal, 1, str ) ;
+      }
+   }
+}
+
 
              boardId = b ;
@@ -735,5 +790,7 @@
              }
              if ( mBuffer[evID].board[ boardId ] != -1) {   
-                snprintf(str,MXSTR,"double board %d for event %d",boardId,evID) ;
+                snprintf(str,MXSTR,"double board: ev %5d, b %3d, %3d;  len %5d %3d %3d - %3d %3d ",
+                   evID,boardId,i,rd[i].fadLen, rd[i].rBuf->B[0], 
+                   rd[i].rBuf->B[1], rd[i].rBuf->B[ rd[i].bufPos-2], rd[i].rBuf->B[ rd[i].bufPos-1]);
                 factOut(kWarn,501, str ) ;
                 goto EndBuf ; //--> skip Board
@@ -749,6 +806,6 @@
              tmS  = boardId*4  -1 ;   //
              src  = head_len/2 ;
+                for ( px=0; px<9; px++ ) {            //different sort in FAD board.....
              for ( drs=0; drs<4; drs++ ) {
-                for ( px=0; px<9; px++ ) {
                    pixH= ntohs(rd[i].rBuf->S[src++]) ;
                    pixC= ntohs(rd[i].rBuf->S[src++]) ;
@@ -796,4 +853,21 @@
                 snprintf(str,MXSTR,"%5d complete event %8d %8d %2d",mBuffer[evID].evNum,evtCtrl.evtBuf[iDx],iDx,evtCtrl.evtStat[ iDx ]);
                 factOut(kDebug,-1, str ) ;
+
+                if (mBuffer[evID].runNum != actrun ) {        // have we already reported first event of this run ???
+                   actrun = mBuffer[i].runNum ;
+                   int ir ;
+                   for ( ir=0; ir<MAX_RUN; ir++) {
+                      if ( runCtrl[ir].runId == actrun) {
+                         if ( runCtrl[ir].lastEvt <0 ) {
+                            runCtrl[ir].lastEvt = +1 ;
+                            gotNewRun( actrun, mBuffer[evID].FADhead ); 
+                snprintf(str,MXSTR,"gotNewRun %d (ev %d)",mBuffer[evID].runNum,mBuffer[evID].evNum);
+                factOut(kInfo,1, str ) ;
+                            break ;
+                         }
+                      }
+                   }
+                }
+
                 //complete event read ---> flag for next processing
                 evtCtrl.evtStat[ iDx ] = 99;
@@ -821,7 +895,4 @@
 
               if (k >= rd[i].bufPos-1 ) {   //no start of header found
-//                 snprintf(str,MXSTR,"no start of header on port%d", i ) ;
-//                 factOut(kWarn,666, str ) ;
-
                  rd[i].bufPos = 0 ;
                  rd[i].bufLen = head_len ;
@@ -830,4 +901,5 @@
                  rd[i].bufLen += k ;
                  memcpy(&rd[i].rBuf->B[0], &rd[i].rBuf->B[k], rd[i].bufPos ) ;
+                 memcpy(&rd[i].xBuf->B[0], &rd[i].xBuf->B[k], rd[i].bufPos ) ;
               }
               if ( rd[i].bufPos >= minLen ) {
@@ -843,8 +915,20 @@
                  rd[i].ftmID  = ntohl(rd[i].rBuf->I[5]) ; //(FTMevt)
                  rd[i].runID  = ntohl(rd[i].rBuf->I[11]) ;
-                 if (rd[i].runID ==0 ) rd[i].runID = gi_myRun ;
                  rd[i].bufTyp = 1 ;       //ready to read full record
                  rd[i].bufLen = rd[i].fadLen - rd[i].bufPos ;
-                 if (rd[i].bufLen <=0 ) rd[i].bufLen = 100000 ;    //?
+
+                 int fadboard = ntohs(rd[i].rBuf->S[12] ) ;
+                 int fadcrate = fadboard/256 ;
+                     fadboard = (fadcrate*10 + fadboard%256) ; 
+snprintf(str,MXSTR,"sk %3d head: %5d %5d %5d %10d %4d %6d",i,rd[i].fadLen,rd[i].evtID,rd[i].ftmID,rd[i].runID,fadboard,jrd) ;
+factOut(kDebug,1, str ) ;
+
+                 if (rd[i].runID ==0 ) rd[i].runID = gi_myRun ;
+
+                 if (rd[i].bufLen <=head_len || rd[i].bufLen > MAX_LEN ) {
+                    snprintf(str,MXSTR,"illegal event-length on port %d",i) ;
+                    factOut(kFatal,881, str ) ;
+                    rd[i].bufLen = 100000 ;    //?
+                 }
                  int fadBoard = ntohs(rd[i].rBuf->S[12] ) ;
                  debugHead(i,fadBoard,rd[i].rBuf); 
@@ -861,4 +945,6 @@
     } //finished trying to read all sockets
 
+snprintf(str,MXSTR,"Loop ---- %3d --- %8d",numokx,jrdx);
+factOut(kDebug,-1, str ) ;
     gi.numRead[ numok ] ++ ;
 
@@ -897,5 +983,5 @@
 
              int id =evtCtrl.evtBuf[k0] ;
-             snprintf(str,MXSTR,"%5d free event buffer (written) %3d", mBuffer[id].evNum, mBuffer[id].nBoard ) ;
+             snprintf(str,MXSTR,"%5d free event buffer, nb=%3d", mBuffer[id].evNum, mBuffer[id].nBoard ) ;
              factOut(kDebug,-1, str ) ;
              mBufFree(id) ;               //event written--> free memory
@@ -954,5 +1040,5 @@
  } else {
    gi_reset  = 0;
-   if ( g_runStat==-1 ) gi_resetR = 1 ;
+   if ( g_runStat== -1 ) gi_resetR = 1 ;
    else                 gi_resetR = 7 ;
    gi_resetS = 7 ; //close all sockets
@@ -971,8 +1057,12 @@
     for (i=0; i<MAX_SOCK; i++) {  
        if (rd[i].sockStat ==0 ) {
-          GenSock(-1, i, 0, NULL, &rd[i]) ; //close and destroy socket   
-          gi_NumConnect[ i/7 ]-- ;
-          gi.numConn[ i/7 ]-- ;
-          gj.numConn[ i/7 ]-- ;
+          GenSock(-1, i, 0, NULL, &rd[i]) ; //close and destroy open socket   
+          if ( i%7 == 0 ) {
+             gi_NumConnect[ i/7 ]-- ;
+             gi.numConn[ i/7 ]-- ;
+             gj.numConn[ i/7 ]-- ;
+             sockDef[i/7] = 0 ;       //flag ro recreate the sockets ...
+             rd[i/7].sockStat = -1;    //and try to open asap
+          }
        }
     }
@@ -1022,4 +1112,6 @@
           if (evtCtrl.evtStat[k0] > minclear ) {
             int id =evtCtrl.evtBuf[k0] ;
+             snprintf(str,MXSTR,"ev %5d free event buffer, nb=%3d", mBuffer[id].evNum, mBuffer[id].nBoard ) ;
+             factOut(kDebug,-1, str ) ;
              mBufFree(id) ;               //event written--> free memory
              evtCtrl.evtStat[k0] = -1; 
@@ -1309,5 +1401,5 @@
               actRun.NTm     = NTMARK ;
               actRun.Nroi    = mBuffer[id].nRoi ;
-//            actRun.FADhead = mBuffer[id].FADhead ;  //to be corrected
+              memcpy(actRun.FADhead, mBuffer[id].FADhead, NBOARDS* sizeof(PEVNT_HEADER) ) ; 
 
               runCtrl[j].fileHd = runOpen(irun,  &actRun, sizeof(actRun) ) ;
@@ -1315,5 +1407,5 @@
                  snprintf(str,MXSTR,"W could not open a file for run %d",irun);
                  factOut(kError,502, str ) ;
-                 runCtrl[j].fileId = 99 ;
+                 runCtrl[j].fileId = 91 ;
               } else {
                  snprintf(str,MXSTR,"W opened new run_file %d",irun) ;
@@ -1325,6 +1417,15 @@
 
            if (runCtrl[j].fileId != 0 ) {
-              snprintf(str,MXSTR,"W no open file for this run %d",irun) ;
-              factOut(kWarn,123,str) ;
+              if (runCtrl[j].fileId < 0 ) {
+                 snprintf(str,MXSTR,"W never opened file for this run %d",irun) ;
+                 factOut(kError,123,str) ;
+              } else if (runCtrl[j].fileId < 100 ) {
+                 snprintf(str,MXSTR,"W.file for this run is closed %d",irun) ;
+                 factOut(kWarn,123,str) ;
+                 runCtrl[j].fileId += 100 ;
+              } else {
+                 snprintf(str,MXSTR,"W:file for this run is closed %d",irun) ;
+                 factOut(kDebug,123,str) ;
+              }
               evtCtrl.evtStat[k0] = 903 ;
               gi.wrtErr++ ;
@@ -1363,9 +1464,9 @@
                     snprintf(str,MXSTR,"error closing run %d %d AAA",runCtrl[j].runId,i) ;
                     factOut(kError,503, str ) ;
-                    runCtrl[j].fileId = 9001 ;
+                    runCtrl[j].fileId = 92   ;
                  } else {
                     snprintf(str,MXSTR,"W closed run %d AAA %d",irun,ii) ;
                     factOut(kInfo,503, str ) ;
-                    runCtrl[j].fileId = 901 ;
+                    runCtrl[j].fileId = 93  ;
                  }
               }
@@ -1393,9 +1494,9 @@
               snprintf(str,MXSTR,"error closing run %d %d BBB",runCtrl[j].runId,i) ;
               factOut(kError,506, str ) ;
-              runCtrl[j].fileId = 9011 ;
+              runCtrl[j].fileId = 94   ;
            } else {
               snprintf(str,MXSTR,"W closed run %d BBB %d",runCtrl[j].runId,ii) ;
               factOut(kInfo,507, str ) ;
-              runCtrl[j].fileId = 911 ;
+              runCtrl[j].fileId = 95  ;
            }
         }
@@ -1439,9 +1540,9 @@
            snprintf(str,MXSTR,"error closing run %d %d CCC",runCtrl[j].runId,i) ;
            factOut(kError,506, str ) ;
-           runCtrl[j].fileId = 9021 ;
+           runCtrl[j].fileId = 96   ;
         } else {
            snprintf(str,MXSTR,"W closed run %d CCC %d",runCtrl[j].runId,ii) ;
            factOut(kInfo,507, str ) ;
-           runCtrl[j].fileId = 921 ;
+           runCtrl[j].fileId = 97  ;
         }
      }
@@ -1470,8 +1571,8 @@
   gj.readStat= gj.procStat= gj.writStat= 0 ;
 
-  snprintf(str,MXSTR,"Starting EventBuilder");
+  snprintf(str,MXSTR,"Starting EventBuilder V15.07 A");
   factOut(kInfo,-1, str ) ;
 
-/* initialize run control logics */
+//initialize run control logics 
   for (i=0; i<MAX_RUN; i++) {
      runCtrl[i].runId = 0 ;
@@ -1479,5 +1580,5 @@
   }
 
-/* partially initialize event control logics */
+//partially initialize event control logics
   evtCtrl.frstPtr = 0 ;
   evtCtrl.lastPtr = 0 ;
@@ -1501,5 +1602,5 @@
 
 #ifdef BILAND
-         xwait.tv_sec = 20;;
+         xwait.tv_sec = 30;;
          xwait.tv_nsec= 0 ;  // sleep for ~20sec
          nanosleep( &xwait , NULL ) ;
@@ -1509,5 +1610,5 @@
          CloseRunFile( 0, time(NULL)+2, 0) ;
 
-         xwait.tv_sec = 5;;
+         xwait.tv_sec = 1;;
          xwait.tv_nsec= 0 ;  // sleep for ~20sec
          nanosleep( &xwait , NULL ) ;
@@ -1563,5 +1664,8 @@
 
 int  runWrite(FileHandle_t fileHd ,  EVENT    *event, size_t len ) 
-{ return 1; } ;
+{ return 1; usleep(10000); return 1; }
+
+
+//{ return 1; } ;
 
 int  runClose(FileHandle_t fileHd ,  RUN_TAIL *runth, size_t len ) 
@@ -1574,8 +1678,8 @@
    int i=0;
 
-   printf("------------%d\n",ntohl(fadhd[7].fad_evt_counter) );
-   for (i=0; i<NBOARDS; i++) {
-      printf("b=%2d,=%5d\n",i,fadhd[i].board_id);
-   }
+// printf("------------%d\n",ntohl(fadhd[7].fad_evt_counter) );
+// for (i=0; i<NBOARDS; i++) {
+//    printf("b=%2d,=%5d\n",i,fadhd[i].board_id);
+// }
    return 0;
 }
@@ -1585,10 +1689,12 @@
   int i ;
 
-  for (i=0;i<MAX_SOCK;i++) {
-     printf("%4d",gi.numRead[i]);
-     if (i%20 == 0 ) printf("\n");
-  }
+//for (i=0;i<MAX_SOCK;i++) {
+//   printf("%4d",gi.numRead[i]);
+//   if (i%20 == 0 ) printf("\n");
+//}
 }
 
+void gotNewRun( int runnr, PEVNT_HEADER *headers ) 
+{ printf("got new run %d\n",runnr); return; }
 
 void factStat(GUI_STAT gj) {
@@ -1635,5 +1741,6 @@
 
   g_maxMem = 1024*1024    ;        //MBytes
-  g_maxMem = g_maxMem * 1024 *10 ; //10GBytes
+//g_maxMem = g_maxMem * 1024 *10 ; //10GBytes
+  g_maxMem = g_maxMem *  200;      //100MBytes
 
 
@@ -1661,5 +1768,7 @@
      for (b=0; b<10; b++) {
         sprintf(ipStr,"10.0.%d.11",128+c) ;
-        if (c==0) sprintf(ipStr,"10.0.100.11") ;
+      if (c<2) sprintf(ipStr,"10.0.%d.11",128) ;
+      else     sprintf(ipStr,"10.0.%d.11",131) ;
+//      if (c==0) sprintf(ipStr,"10.0.100.11") ;
 
         inet_pton(PF_INET, ipStr, &IPaddr) ;
