Index: /trunk/FACT++/src/evtserver.cc
===================================================================
--- /trunk/FACT++/src/evtserver.cc	(revision 17850)
+++ /trunk/FACT++/src/evtserver.cc	(revision 17851)
@@ -78,4 +78,5 @@
             (rst.rise>rst.set && (now.JD()<rst.set  || now.JD()>rst.rise));
 
+        // FIXME: What about errors?
         if (!isUp)
             return EventServer::State::kStandby;
@@ -86,27 +87,40 @@
         if (fNight!=night)
         {
+            fNight = night;
+
             delete fIn;
 
             const string name = fAuxPath + Tools::Form("/%04d/%02d/%02d/%08d.FAD_CONTROL_EVENT_DATA.fits", night/10000, (night/100)%100, night%100, night);
 
-            Info("Opening file "+name);
-
             fIn = new fits(name);
-
             if (!fIn->is_open())
             {
-                Error(string("Opening file failed: ")+strerror(errno));
+                Error(string("Failed to open "+name+": ")+strerror(errno));
                 return StateMachineImp::kSM_Error;
             }
 
-            fIn->SetRefAddress("QoS",  fQoS);
-            fIn->SetRefAddress("Time", fTime);
-            fIn->SetVecAddress("max",  fMax);
-            //fIn->SetVecAddress(fRms);
-            //fIn->SetVecAddress(fMax);
-            //fIn->SetVecAddress(fPos);
-        }
-
-        fNight = night;
+            try
+            {
+                fIn->SetRefAddress("QoS",  fQoS);
+                fIn->SetRefAddress("Time", fTime);
+                fIn->SetVecAddress("max",  fMax);
+                //fIn->SetVecAddress(fRms);
+                //fIn->SetVecAddress(fMax);
+                //fIn->SetVecAddress(fPos);
+            }
+            catch (const runtime_error &e)
+            {
+                delete fIn;
+                fIn = 0;
+
+                Error("Failed to open "+name+": "+e.what());
+                return StateMachineImp::kSM_Error;
+            }
+
+            Info("File "+name+" open.");
+        }
+
+        if (GetCurrentState()==StateMachineImp::kSM_Error)
+            return  StateMachineImp::kSM_Error;
 
         // Get next data event
@@ -143,5 +157,9 @@
             const double deviation = dev[uint32_t(0.682689477208650697*1440)];
 
-            if (sorted[1439]>med+deviation*6)
+            // In a typical shower or muon ring, the first
+            // few pixels will have comparable brightness,
+            // in a NSB event not. Therefore, the 4th brightest
+            // pixel is a good reference.
+            if (sorted[1439-3]>med+deviation*5)
                 break;
         }
@@ -221,9 +239,9 @@
 
 
-        AddEvent("START", EventServer::State::kIdle, StateMachineImp::kSM_Error)
+        AddEvent("START", EventServer::State::kIdle, EventServer::State::kRunning, StateMachineImp::kSM_Error)
             (bind(&StateMachineEventServer::StartServer, this))
             ("Start serving the smartfact camera file");
 
-        AddEvent("START_DATE", "I:1", EventServer::State::kIdle, StateMachineImp::kSM_Error)
+        AddEvent("START_DATE", "I:1", EventServer::State::kIdle, EventServer::State::kRunning, StateMachineImp::kSM_Error)
             (bind(&StateMachineEventServer::StartDate, this, placeholders::_1))
             ("Start serving the smartfact camera file with the events from the given date"
