Index: /trunk/FACT++/src/EventBuilderWrapper.h
===================================================================
--- /trunk/FACT++/src/EventBuilderWrapper.h	(revision 11564)
+++ /trunk/FACT++/src/EventBuilderWrapper.h	(revision 11565)
@@ -407,4 +407,6 @@
     }
 
+        int fRoiTM;
+
     // --------------------------------------------------------------------------
     //
@@ -414,5 +416,5 @@
     //
     bool OpenFile(RUN_HEAD* h)
-    {
+        {
         //Form filename, based on runid and run-type
         const string fileName = FormFileName(GetRunId(), "fits");
@@ -451,27 +453,36 @@
         }
 
+        h->NroiTM = 0;
+
         vector<string> colNames;
         vector<string> dataTypes;
-        AddColumnEntry(colNames, dataTypes, 1,            'J', "EventNum");
-        AddColumnEntry(colNames, dataTypes, 1,            'I', "TriggerType");
-        AddColumnEntry(colNames, dataTypes, 1,            'I', "NumBoards");
-        AddColumnEntry(colNames, dataTypes, 1,            'I', "reserved");
-        AddColumnEntry(colNames, dataTypes, 1,            'J', "SoftTrig");
-        AddColumnEntry(colNames, dataTypes, 2,            'J', "PCTime");
-        AddColumnEntry(colNames, dataTypes, NBOARDS,      'J', "BoardTime");
-        AddColumnEntry(colNames, dataTypes, NPIX,         'I', "StartCell");
-        AddColumnEntry(colNames, dataTypes, NTMARK,       'I', "StartTM");
-        AddColumnEntry(colNames, dataTypes, NPIX*h->Nroi, 'I', "Data");
+        AddColumnEntry(colNames, dataTypes, 1,                'J', "EventNum");
+        AddColumnEntry(colNames, dataTypes, 1,                'I', "TriggerType");
+        AddColumnEntry(colNames, dataTypes, 1,                'J', "NumBoards");
+        AddColumnEntry(colNames, dataTypes, 1,                'J', "reserved");
+        AddColumnEntry(colNames, dataTypes, 1,                'J', "SoftTrig");
+        AddColumnEntry(colNames, dataTypes, 2,                'J', "PCTime");
+        AddColumnEntry(colNames, dataTypes, h->NBoard,        'J', "BoardTime");
+        AddColumnEntry(colNames, dataTypes, h->NPix,          'I', "StartCellData");
+        AddColumnEntry(colNames, dataTypes, h->NTm,           'I', "StartCellTimeMarker");
+        AddColumnEntry(colNames, dataTypes, h->NPix*h->Nroi,  'I', "Data");
+        AddColumnEntry(colNames, dataTypes, h->NTm*h->NroiTM, 'I', "TimeMarker");
 
         // Write length of physical pipeline (1024)
 
+        /*
         ostringstream fmt;
-        fmt << "I:1;S:1;I:1;I:1;I:1;I:2";
-        fmt << ";I:" << NBOARDS;
-        fmt << ";S:" << NPIX;
-        fmt << ";S:" << NTMARK;
-        fmt << ";S:" << NPIX*h->Nroi;
-
-        fConv = new Converter(fmt.str());
+        fmt << "I:1";   // uint32_t EventNum
+        fmt << ";S:1";  // uint16_t TriggerType
+        fmt << ";I:5";  // uint32_t NumBoards, reserved, SoftTrig, PCTime, PCUsec
+        fmt << ";I:" << h->NBoard;       // uint32_t BoardTime[NBOARDS]
+        fmt << ";S:" << h->NPix+h->NTm;  // int16_t StartPix[NPIX], StartTM[NTMARK]
+        fmt << ";S:" << h->NPix*h->Nroi + h->NTm*h->NroiTM; // int16_t Adc_Data[]
+        */
+        fRoiTM = h->NroiTM;
+
+        cout << "==> " << Converter::ToFormat(dataTypes) << endl;
+
+        fConv = new Converter(Converter::ToFormat(dataTypes));
 
         //actually create the table
@@ -515,4 +526,5 @@
         WriteKey("NTMARK",   h->NTm,      "Number of Time marks");
         WriteKey("NROI",     h->Nroi,     "Number of slices per pixels");
+        WriteKey("NROITM",   h->NroiTM,   "Number of slices per time-marker");
 
         const Time now;
@@ -526,5 +538,7 @@
         WriteKey("DAQ",      "DRS4", "");
 
-        Fatal("Write sampling frequency...");
+        WriteKey("ADCCOUNT",  2.0f,       "ADC Counts per milliVolt");
+
+        Info("==> TODO: Write sampling frequency...");
 
         // Write a single key for:
@@ -637,5 +651,8 @@
         fNumRows++;
 
-        const vector<char> data = fConv->ToFits(((char*)e)+2, sizeof(EVENT)+NPIX*e->Roi*2-2);
+        // FIXME: Get NPIX and NTMARK from header
+        const size_t sz = sizeof(EVENT) + sizeof(e->StartPix)*e->Roi+sizeof(e->StartTM)*fRoiTM;
+
+        const vector<char> data = fConv->ToFits(reinterpret_cast<char*>(e)+2, sz-2);
 
         // column size pointer
@@ -1160,4 +1177,5 @@
         catch (const exception &e)
         {
+            fMsg.Error("Exception trying to open file: "+string(e.what()));
             return 0;
         }
@@ -1351,7 +1369,6 @@
          */
 
-        /*
         const FAD::EventHeader *beg = reinterpret_cast<FAD::EventHeader*>(fadhd);
-        const FAD::EventHeader *end = reinterpret_cast<FAD::EventHeader*>(fadhd)+41;
+        const FAD::EventHeader *end = reinterpret_cast<FAD::EventHeader*>(fadhd)+40;
 
         for (const FAD::EventHeader *ptr=beg; ptr!=end; ptr++)
@@ -1378,5 +1395,5 @@
             if (ptr->fVersion     != beg->fVersion)
                 return -1;
-        }*/
+        }
 
         // check REFCLK_frequency
