Index: trunk/FACT++/src/EventBuilder.c
===================================================================
--- trunk/FACT++/src/EventBuilder.c	(revision 11443)
+++ trunk/FACT++/src/EventBuilder.c	(revision 11511)
@@ -1,6 +1,4 @@
 
 
-#define PX8   99  //simulator does not create double-length roi for pixel 8  
-                  //for real data, set PX8 = 8 ==> ask for double roi=TM
 
 
@@ -80,6 +78,6 @@
  int gi_memStat = +1 ;
 
- uint32_t gi_myRun = 9876789 ;
- uint32_t actrun ;
+ uint32_t gi_myRun = 0 ;
+ uint32_t actrun   =       0 ;
 
 
@@ -364,6 +362,6 @@
    }
 
-   mBuffer[i].fEvent->PCTime[0] = g_actTime ;
-   mBuffer[i].fEvent->PCTime[1] = g_actUsec ;
+   mBuffer[i].fEvent->PCUsec = g_actUsec ;
+   mBuffer[i].fEvent->PCTime = 
    mBuffer[i].pcTime  = g_actTime ;
    mBuffer[i].nRoi    = nRoi ;
@@ -410,4 +408,6 @@
       runCtrl[evFree].actEvt = 0;
       runCtrl[evFree].maxEvt = 999999999 ; //max number events allowed
+      runCtrl[evFree].firstUsec=g_actUsec ;
+      runCtrl[evFree].firstTime=
       runCtrl[evFree].lastTime=g_actTime ;
       runCtrl[evFree].closeTime=g_actTime + 3600*24 ; //max time allowed
@@ -652,5 +652,5 @@
       gettimeofday( tv, NULL);
       g_actTime = tsec = atv.tv_sec ;
-      g_actUsec = tusec= atv.tv_usec ;
+      g_actUsec = tusec= atv.tv_usec ; 
 
       if (rd[i].sockStat <0 ) {         //try to connect if not yet done
@@ -683,5 +683,7 @@
              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);
+ snprintf(str,MXSTR,"read sock %3d bytes %5d len %5d first %d %d",i,jrd,rd[i].bufLen,
+ rd[i].rBuf->B[ rd[i].bufPos  ],
+ rd[i].rBuf->B[ rd[i].bufPos  +1] );
  factOut(kDebug,301, str ) ;
           }
@@ -803,19 +805,18 @@
              roi  = mBuffer[evID].nRoi ;
 
-             pixS = boardId*36 -1 ;   //
-             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++ ) {
-                   pixH= ntohs(rd[i].rBuf->S[src++]) ;
-                   pixC= ntohs(rd[i].rBuf->S[src++]) ;
-                   pixR= ntohs(rd[i].rBuf->S[src++]) ;
-
+             for ( px=0; px<9; px++ ) {            //different sort in FAD board.....
+                for ( drs=0; drs<4; drs++ ) {
+                   pixH= ntohs(rd[i].rBuf->S[src++]) ;   // ID
+                   pixC= ntohs(rd[i].rBuf->S[src++]) ;   // start-cell
+                   pixR= ntohs(rd[i].rBuf->S[src++]) ;   // roi
+//here we should check if pixH is correct ....
+
+                   pixS = boardId*36 + drs*9 + px ;
                    src++  ;
-                   pixS++ ; //pixS = pixH2S[pixH] ;
-                   if ( ( px < PX8 && pixR == roi )
-                     || ( px ==PX8 && pixR == 2*roi )
-                     || ( px ==PX8 && pixR == roi && roi > 512 ) ) {
-                       // correct roi
+
+                   if ( ( px != 8 && pixR == roi )
+                     || ( px == 8 && pixR >= roi ) ) {   //we have a reasonable roi
+                      
                       mBuffer[evID].fEvent->StartPix[pixS] =pixC;
                       dest= pixS * roi ;
@@ -823,16 +824,17 @@
                            &mBuffer[evID].fEvent->Adc_Data[dest],
                            &rd[i].rBuf->S[src],  roi * 2) ;
-                      src+= roi ;
-                      if ( px==PX8 ) {
-                         tmS++; // tmS = tmH2S[pixH]
-                         dest= tmS * roi + NPIX* roi ;
-                         if ( roi <=512 ) {
-                            mBuffer[evID].fEvent->StartTM[tmS] =(pixC+roi)%1024 ;
+                      src+= pixR ;
+
+                      if ( px==8 ) {
+                         if ( pixR > roi) {          //and we have additional TM info
+                            tmS =boardId*4 + drs ;
+                            dest= tmS * roi + NPIX* roi ;
+                            int srcT= src - roi ;
+                            mBuffer[evID].fEvent->StartTM[tmS] = (pixC+pixR-roi)%1024 ;
                             memcpy(
                               &mBuffer[evID].fEvent->Adc_Data[dest],
-                              &rd[i].rBuf->S[src],  roi * 2) ;
-                            src+=roi ;
+                              &rd[i].rBuf->S[srcT],  roi * 2) ;
                          } else {
-                             mBuffer[evID].fEvent->StartTM[tmS] = -1 ;
+                            mBuffer[evID].fEvent->StartTM[tmS] = -1 ;
                          }
                       }
@@ -1397,4 +1399,7 @@
               actRun.Version =  1 ;
               actRun.RunType = -1 ;
+
+              actRun.RunTime = runCtrl[j].firstTime ;
+              actRun.RunUsec = runCtrl[j].firstTime ;
               actRun.NBoard  = NBOARDS ;
               actRun.NPix    = NPIX ;
