Index: /trunk/FACT++/gui/Q3DCameraWidget.cc
===================================================================
--- /trunk/FACT++/gui/Q3DCameraWidget.cc	(revision 14790)
+++ /trunk/FACT++/gui/Q3DCameraWidget.cc	(revision 14791)
@@ -163,5 +163,8 @@
     void Q3DCameraWidget::setData(float* ddata)
     {
-        for (int i=0;i<1440;i++)
+        cout << "Info : 3D plotter disabled. requires more work so that less than 300 slices per pixel can be loaded" << endl;
+        cout << "Contact Etienne (etienne.lyard@unige.ch) for more information." << endl;
+        //disabled for now as I am working with 150 slices only
+/*        for (int i=0;i<1440;i++)
             for (int j=0;j<300;j++)
             _data[i*300+j] = (short)(ddata[i*300 + j]);
@@ -169,9 +172,11 @@
         if (isVisible())
             updateGL();
-
+*/
     }
     void Q3DCameraWidget::setData(short* ddata)
     {
-        for (int i=0;i<1440;i++)
+        cout << "Info : 3D plotter disabled. requires more work so that less than 300 slices per pixel can be loaded" << endl;
+        cout << "Contact Etienne (etienne.lyard@unige.ch) for more information." << endl;
+/*        for (int i=0;i<1440;i++)
             for (int j=0;j<300;j++)
                 _data[i*300+j] = ddata[i* 300 + j];
@@ -179,5 +184,5 @@
         if (isVisible())
             updateGL();
-
+*/
     }
     void Q3DCameraWidget::drawCameraBody()
Index: /trunk/FACT++/gui/RawEventsViewer/RawEventsViewer.cc
===================================================================
--- /trunk/FACT++/gui/RawEventsViewer/RawEventsViewer.cc	(revision 14790)
+++ /trunk/FACT++/gui/RawEventsViewer/RawEventsViewer.cc	(revision 14791)
@@ -189,5 +189,8 @@
         else
 
-        color = float(eventData[nRoi*hardwareMapping[i] + whichSlice]+(VALUES_SPAN/2))/(float)(VALUES_SPAN-1);
+//        if (_softwareOrdering)
+//            color = float(eventData[nRoi*i + whichSlice] + (VALUES_SPAN/2))/(float)(VALUES_SPAN-1);
+//        else
+            color = float(eventData[nRoi*hardwareMapping[i] + whichSlice]+(VALUES_SPAN/2))/(float)(VALUES_SPAN-1);
         if (logScale)
         {
@@ -291,5 +294,7 @@
         }*/
 
-    const int hw = hardwareMapping[selectedPixel];
+//    int mapping = _softwareOrdering ? selectedPixel : hardwareMapping[selectedPixel];
+    int mapping = hardwareMapping[selectedPixel];
+    const int hw = mapping;
     const PixelMapEntry& mapEntry = fPixelMap.index(selectedPixel);
     const int pixelIdInPatch = mapEntry.pixel();
@@ -385,4 +390,7 @@
             patchesColor[i][j] = color[j];
     }
+    fZeroArray = NULL;
+
+    _softwareOrdering = false;
 
 }
@@ -402,6 +410,14 @@
         delete[] waveLetArray;
     }
-}
-
+    if (fZeroArray != NULL)
+        delete[] fZeroArray;
+}
+void RawDataViewer::allocateZeroArray()
+{
+    if (fZeroArray == NULL)
+    {
+        fZeroArray = new char[8192];
+    }
+}
 /************************************************************
  * PAINT GL. main drawing function.
@@ -572,4 +588,5 @@
         }
     }
+
     nRows =          inputFile->HasKey("NAXIS2") ? inputFile->GetInt("NAXIS2") : 0;
     nRoi =           inputFile->HasKey("NROI") ?  inputFile->GetInt("NROI") : 0;
@@ -584,10 +601,40 @@
     nBoards =        inputFile->HasKey("NBOARD") ? inputFile->GetInt("NBOARD") : 0;
     nPixels =        inputFile->HasKey("NPIX") ?  inputFile->GetInt("NPIX") : 0;
-    timeSystem =     inputFile->HasKey("TIMESYS") ? inputFile->GetStr("TIMESYS") : 0;
-    creationDate =   inputFile->HasKey("DATE") ? inputFile->GetStr("DATE") : 0;
+    timeSystem =     inputFile->HasKey("TIMESYS") ? inputFile->GetStr("TIMESYS") : "";
+    creationDate =   inputFile->HasKey("DATE") ? inputFile->GetStr("DATE") : "";
     nightInt =       inputFile->HasKey("NIGHT") ? inputFile->GetInt("NIGHT") : 0;
-    camera =         inputFile->HasKey("CAMERA") ? inputFile->GetStr("CAMERA") : 0;
-    daq =            inputFile->HasKey("DAQ") ? inputFile->GetStr("DAQ") : 0;
+    camera =         inputFile->HasKey("CAMERA") ? inputFile->GetStr("CAMERA") : "";
+    daq =            inputFile->HasKey("DAQ") ? inputFile->GetStr("DAQ") : "";
     adcCount =       inputFile->HasKey("ADCRANGE") ? inputFile->GetFloat("ADCRANGE") : 2000;
+    if (nPixels == 0)
+    {
+        cout << "could not read num pixels from fits header. Assuming 1440 (FACT)." << endl;
+        nPixels = 1440;
+    }
+    if (nRoi == 0 && !inputFile->HasKey("NROI"))
+    {//let's try to figure out the roi from the column's format
+        const fits::Table::Columns& cols = inputFile->GetColumns();
+        if (cols.find("Data") == cols.end())
+        {
+            cout << "ERROR: Column \"Data\" could not be found. abortin load." << endl;
+            return;
+        }
+        const fits::Table::Columns::const_iterator col = cols.find("Data");
+        if (col->second.type != 'I')
+        {
+            cout << "ERROR: Data Column has type " << col->second.type << " while viewer expects I" << endl;
+            return;
+        }
+        if (col->second.num % nPixels != 0)
+        {
+            cout << "ERROR: Num pixels (" << nPixels << ") does not match Data length (" << col->second.num << "). Aborting" << endl;
+            return;
+        }
+        nRoi = col->second.num/nPixels;
+        cout << "Estimate num samples per pixels to be " << nRoi;
+        _softwareOrdering = true;
+    }
+    else
+        _softwareOrdering = false;
 
     if (inputFile->HasKey("OFFSET"))
@@ -598,5 +645,5 @@
     nbBad = 0;//inputFile->GetInt("NBEVTBAD");
 
-    eventNum = 0;
+    eventNum = 1;
 
     if (eventData != NULL) {
@@ -612,11 +659,32 @@
     {
         inputFile->SetPtrAddress("Data", rawEventData);
-        inputFile->SetPtrAddress("EventNum", &eventNum);
-        inputFile->SetPtrAddress("TriggerType", &triggerType);
-        inputFile->SetPtrAddress("SoftTrig", &softTrig);
-        inputFile->SetPtrAddress("BoardTime", boardTime);
-        inputFile->SetPtrAddress("StartCellData", startPix);
-        inputFile->SetPtrAddress("StartCellTimeMarker", startTM);
-        inputFile->SetPtrAddress("TimeMarker", &rawEventData[1440*nRoi]);
+        if (inputFile->HasColumn("EventNum"))
+            inputFile->SetPtrAddress("EventNum", &eventNum);
+        else
+            cout << "Warning: could not find column \"EventNum\"" << endl;
+        if (inputFile->HasColumn("TriggerType"))
+            inputFile->SetPtrAddress("TriggerType", &triggerType);
+        else
+            cout << "Warning: could not find column \"TriggerType\"" << endl;
+        if (inputFile->HasColumn("SoftTrig"))
+            inputFile->SetPtrAddress("SoftTrig", &softTrig);
+        else
+            cout << "Warning: could not find column \"SoftTrig\"" << endl;
+        if (inputFile->HasColumn("BoardTime"))
+            inputFile->SetPtrAddress("BoardTime", boardTime);
+        else
+            cout << "Warning: could not find column \"BoardTime\"" << endl;
+        if (inputFile->HasColumn("StartCellData"))
+            inputFile->SetPtrAddress("StartCellData", startPix);
+        else
+            cout << "Warning: could not find column \"StartCellData\"" << endl;
+        if (inputFile->HasColumn("StartCellTimeMarker"))
+            inputFile->SetPtrAddress("StartCellTimeMarker", startTM);
+        else
+            cout << "Warning: could not find column \"StartCellTimeMarker\"" << endl;
+        if (inputFile->HasColumn("TimeMarker"))
+            inputFile->SetPtrAddress("TimeMarker", &rawEventData[1440*nRoi]);
+        else
+            cout << "Warning: could not find column \"TimeMarker\"" << endl;
     }
     catch (const runtime_error &e)
@@ -633,5 +701,6 @@
     {
         pcTime[0] = pcTime[1] = 0;
-        inputFile->SetPtrAddress("UnixTimeUTC", pcTime);
+        if (inputFile->HasColumn("UnixTimeUTC"))
+            inputFile->SetPtrAddress("UnixTimeUTC", pcTime);
     }
     catch (const runtime_error&)
@@ -639,5 +708,9 @@
             try
         {
-            inputFile->SetPtrAddress("PCTime", pcTime);
+            if (inputFile->HasColumn("PCTime"))
+                inputFile->SetPtrAddress("PCTime", pcTime);
+            else
+                cout << "Warning: could not find column \"UnixTimeUTC\" nor \"PCTime\"" << endl;
+
         }
         catch (const runtime_error&)
@@ -824,4 +897,19 @@
         return;
     inputFile->GetRow(rowNum);
+    if (_softwareOrdering)
+    {//remap pixels data according to hardware id
+        if (nRoiTM != 0)
+            cout << "Warning: did not expect Time Markers data from Monte-Carlo simulations. These will not be mapped properly." << endl;
+        //first copy the data
+        int16_t* tempData = new int16_t[1440*nRoi];
+        for (int i=0;i<1440*nRoi;i++)
+            tempData[i] = rawEventData[i];
+        //copy back the data and re-map it on the fly
+        for (int i=0;i<1440;i++)
+            for (int j=0;j<nRoi;j++)
+                rawEventData[i*nRoi + j] = tempData[softwareMapping[i]*nRoi + j];
+
+        delete[] tempData;
+    }
 //    cout << "Getting row " << rowNum << endl;
 
@@ -1273,7 +1361,7 @@
         return;
     }
-    const int idx =
-        GLWindow->nRoi*GLWindow->hardwareMapping[GLWindow->selectedPixel]
-        + GLWindow->whichSlice;
+//    int mapping = GLWindow->_softwareOrdering ? GLWindow->selectedPixel : GLWindow->hardwareMapping[GLWindow->selectedPixel];
+    int mapping = GLWindow->hardwareMapping[GLWindow->selectedPixel];
+    const int idx = GLWindow->nRoi*mapping + GLWindow->whichSlice;
 
     ostringstream str;
@@ -1874,5 +1962,6 @@
         return;
     int softwarePix = pixel;
-    pixel = GLWindow->hardwareMapping[pixel];
+//    if (!GLWindow->_softwareOrdering)
+        pixel = GLWindow->hardwareMapping[pixel];
 
     HwIDBox->setValue(pixel);
@@ -1997,5 +2086,8 @@
         return;
 
-    HwIDBox->setValue(GLWindow->hardwareMapping[swid]);
+//    if (GLWindow->_softwareOrdering)
+//        HwIDBox->setValue(swid);
+//    else
+        HwIDBox->setValue(GLWindow->hardwareMapping[swid]);
 }
 
Index: /trunk/FACT++/gui/RawEventsViewer/RawEventsViewer.h
===================================================================
--- /trunk/FACT++/gui/RawEventsViewer/RawEventsViewer.h	(revision 14790)
+++ /trunk/FACT++/gui/RawEventsViewer/RawEventsViewer.h	(revision 14791)
@@ -120,4 +120,11 @@
     valarray<double> Maxvalues;
     valarray<double> PosOfMaxvalues;
+
+    ///Used to load zero data in case of missing fits columns
+    void allocateZeroArray();
+    char* fZeroArray;
+    //bool telling whether the data is natively ordered in software or hardware id
+    //used to correctly display monte-carlo data.
+    bool _softwareOrdering;
 
 private:
@@ -177,4 +184,5 @@
 
 
+
 //    int hardwareMapping[1440];
 //    int softwareMapping[1440];
