Index: trunk/MagicSoft/Mars/datacenter/macros/fillstar.C
===================================================================
--- trunk/MagicSoft/Mars/datacenter/macros/fillstar.C	(revision 8996)
+++ trunk/MagicSoft/Mars/datacenter/macros/fillstar.C	(revision 9062)
@@ -59,13 +59,8 @@
 #include <iomanip>
 
-#include <TRegexp.h>
-
+#include <TFile.h>
 #include <TH1.h>
 #include <TH2.h>
 #include <TGraph.h>
-#include <TProfile.h>
-#include <TFile.h>
-#include <TSQLResult.h>
-#include <TSQLRow.h>
 
 #include "MSQLMagic.h"
@@ -73,7 +68,8 @@
 #include "MHCamera.h"
 #include "MHMuonPar.h"
+#include "MSequence.h"
 #include "MStatusArray.h"
-#include "MGeomCamMagic.h"
 #include "MBadPixelsCam.h"
+#include "MHEffectiveOnTime.h"
 
 using namespace std;
@@ -104,5 +100,5 @@
     if (!hsparks)
     {
-        cout << "WARNING - Reading of Sparks failed." << endl;
+        cout << "ERROR - Reading of Sparks failed." << endl;
         return 2;
     }
@@ -111,5 +107,5 @@
     if (!hcog)
     {
-        cout << "WARNING - Reading of MHHillas failed." << endl;
+        cout << "ERROR - Reading of MHHillas failed." << endl;
         return 2;
     }
@@ -118,5 +114,5 @@
     if (!hmuon)
     {
-        cout << "WARNING - Reading of MHMuon failed." << endl;
+        cout << "ERROR - Reading of MHMuon failed." << endl;
         return 2;
     }
@@ -132,11 +128,10 @@
         }
 
-    Double_t inhom = TMath::RMS(6, val)*6/hcog->GetEntries()*100;
-    inhom = TMath::Nint(inhom*10)/10.;
+    Float_t inhom = TMath::RMS(6, val)*6/hcog->GetEntries()*100;
     TString inhomogen = Form("%5.1f", inhom);
 
-    Float_t mw    = hmuon->GetMeanWidth();
-    Float_t psf   = 70.205*mw - 28.055;
-    TString PSF = Form("%5.1f", psf<0?0:psf);
+    Float_t mw  = hmuon->GetMeanWidth();
+    Float_t psf = 70.205*mw - 28.055;
+    TString PSF = Form("%5.1f", (psf<0?0:psf));
     Int_t   num = (int)hmuon->GetEntries();
 
@@ -147,5 +142,5 @@
     if (!h)
     {
-        cout << "WARNING - Reading of Islands failed." << endl;
+        cout << "ERROR - Reading of Islands failed." << endl;
         return 2;
     }
@@ -154,25 +149,24 @@
 
     h = (TH1*)arr.FindObjectInCanvas("EffOnTheta", "TH1D", "EffOnTime");
+
+    Float_t effon = h ? h->Integral() : -1;
+
+    h = (TH1*)arr.FindObjectInCanvas("Cleaned;avg", "TH1D", "Cleaned");
     if (!h)
     {
-        cout << "WARNING - Reading of EffOnTheta failed." << endl;
-        return 2;
-    }
-
-    Float_t effon = h->Integral();
+        cout << "ERROR - Reading of Cleaned;avg failed." << endl;
+        return 2;
+    }
+
+    if (effon<0)
+        effon = h->GetEntries()/100;
+
     Float_t mrate  = num/effon;
     TString muonrate = Form("%6.2f", mrate<0?0:mrate);
-    Int_t effontime = TMath::Nint(effon);
-
-    h = (TH1*)arr.FindObjectInCanvas("ProjDeltaT", "TH1D", "EffOnTime");
-    if (!h)
-    {
-        cout << "WARNING - Reading of ProjDeltaT failed." << endl;
-        return 2;
-    }
+    TString effontime = Form("%.1f", effon);
 
     Int_t numsparks = (int)hsparks->GetEntries();
     Int_t numevents = (int)h->GetEntries() - numsparks;
-    Int_t datarate  = (int)(numevents/effon);
+    Int_t datarate  = TMath::Nint(numevents/effon);
 
     TString sparkrate = Form("%5.2f", numsparks/effon);
@@ -181,73 +175,64 @@
         sparkrate="0.00";
 
+    MHEffectiveOnTime *ontm = (MHEffectiveOnTime*)arr.FindObjectInCanvas("MHEffectiveOnTime", "MHEffectiveOnTime", "EffOnTime");
+    TString totontime = ontm ? Form("%d", TMath::Nint(ontm->GetTotalTime())) : "NULL";
+    TString relontime = ontm ? Form("%.2f", effon/ontm->GetTotalTime()*100) : "NULL";
+
     TGraph *g = (TGraph*)arr.FindObjectInCanvas("Humidity", "TGraph", "MHWeather");
-    if (!g)
-    {
-        cout << "WARNING - Reading of Humidity failed." << endl;
-        return 2;
-    }
+
     TString maxhum = CheckGraph(g) ? Form("%5.1f", TMath::MaxElement(g->GetN(), g->GetY())) : "NULL";
     TString avghum = CheckGraph(g) ? Form("%5.1f", g->GetMean(2)) : "NULL";
 
     g = (TGraph*)arr.FindObjectInCanvas("Temperature", "TGraph", "MHWeather");
-    if (!g)
-    {
-        cout << "WARNING - Reading of Temperature failed." << endl;
-        return 2;
-    }
+
     TString avgtemp = CheckGraph(g) ? Form("%5.1f", g->GetMean(2)) : "NULL";
 
     g = (TGraph*)arr.FindObjectInCanvas("WindSpeed", "TGraph", "MHWeather");
-    if (!g)
-    {
-        cout << "WARNING - Reading of WindSpeed failed." << endl;
-        return 2;
-    }
+
     TString avgwind = CheckGraph(g) ? Form("%5.1f", g->GetMean(2)) : "NULL";
 
     g = (TGraph*)arr.FindObjectInCanvas("Cloudiness", "TGraph", "MHWeather");
-    if (!g)
-        cout << "WARNING - Reading of Cloudiness failed." << endl;
-
+    //if (!g)
+    //    cout << "WARNING - Reading of Cloudiness failed." << endl;
     TString avgclouds = CheckGraph(g) ? Form("%5.1f", g->GetMean(2)) : "NULL";
     TString rmsclouds = CheckGraph(g) ? Form("%5.1f", g->GetRMS(2))  : "NULL";
 
     g = (TGraph*)arr.FindObjectInCanvas("TempSky", "TGraph", "MHWeather");
-    if (!g)
-        cout << "WARNING - Reading of TempSky failed." << endl;
+    //if (!g)
+    //    cout << "WARNING - Reading of TempSky failed." << endl;
     TString avgsky = CheckGraph(g) ? Form("%5.1f", g->GetMean(2)+200) : "NULL";
 
 
     g = (TGraph*)arr.FindObjectInCanvas("NumStars", "TGraph", "MHPointing");
-    if (!g)
-        cout << "WARNING - Reading of NumStars failed." << endl;
-
+    //if (!g)
+    //    cout << "WARNING - Reading of NumStars failed." << endl;
     TString numstarsmed = CheckGraph(g) ? Form("%5.1f", TMath::Median(g->GetN(), g->GetY())) : "NULL";
     TString numstarsrms = CheckGraph(g) ? Form("%5.1f", g->GetRMS(2)) : "NULL";
 
     g = (TGraph*)arr.FindObjectInCanvas("NumStarsCor", "TGraph", "MHPointing");
-    if (!g)
-        cout << "WARNING - Reading of NumStarsCor failed." << endl;
-
+    //if (!g)
+    //    cout << "WARNING - Reading of NumStarsCor failed." << endl;
     TString numcorsmed = CheckGraph(g) ? Form("%5.1f", TMath::Median(g->GetN(), g->GetY())) : "NULL";
     TString numcorsrms = CheckGraph(g) ? Form("%5.1f", g->GetRMS(2)) : "NULL";
 
     g = (TGraph*)arr.FindObjectInCanvas("Brightness", "TGraph", "MHPointing");
-    if (!g)
-        cout << "WARNING - Reading of SkyBrightness failed." << endl;
-
+    //if (!g)
+    //    cout << "WARNING - Reading of SkyBrightness failed." << endl;
     TString skybrightnessmed = CheckGraph(g) ? Form("%5.1f", TMath::Median(g->GetN(), g->GetY())) : "NULL";
     TString skybrightnessrms = CheckGraph(g) ? Form("%5.1f", g->GetRMS(2)) : "NULL";
 
-    TString sequence = fname(TRegexp("star[0-9]+[.]root$"));
-    if (sequence.IsNull())
-    {
-        cout << "WARNING - Could not determine sequence# from filename: " << fname << endl;
-        return 2;
-    }
-
-    Int_t seq = atoi(sequence.Data()+5);
-
-    cout << "Sequence #" << seq << endl;
+    MSequence seq;
+    if (seq.Read("sequence[0-9]{8}|MSequence")<=0)
+    {
+        cout << "ERROR - Could not find sequence in file: " << fname << endl;
+        return 2;
+    }
+    if (!seq.IsValid())
+    {
+        cout << "ERROR - Sequence read from file inavlid: " << fname << endl;
+        return 2;
+    }
+
+    cout << "Sequence M" << seq.GetTelescope() << ":" << seq.GetSequence() << endl;
     cout << "  Inhomogeneity            " << inhomogen << endl;
     cout << "  PSF [mm]                 " << PSF       << endl;
@@ -255,5 +240,7 @@
     cout << "  Ratio [%]                " << ratio     << endl;
     cout << "  Muon Number              " << num       << endl;
-    cout << "  EffOnTime [s]            " << effontime << endl;
+    cout << "  Eff. OnTime [s]          " << effontime << endl;
+    cout << "  Tot. OnTime [s]          " << totontime << endl;
+    cout << "  Rel. OnTime [%]          " << relontime << endl;
     cout << "  Muon Rate [Hz]           " << muonrate  << endl;
     cout << "  # of Events (w/o sparks) " << numevents << endl;
@@ -271,8 +258,11 @@
     cout << "  Skybrightness            " << skybrightnessmed << " +/- " << skybrightnessrms << endl;
 
-    TString vars = Form(" fMeanNumberIslands=%s,"
+    TString vars = Form(" fSequenceFirst=%d, "
+                        " fTelescopeNumber=%d, "
+                        " fMeanNumberIslands=%s,"
                         " fRatio=%s,"
                         " fMuonNumber=%d,"
-                        " fEffOnTime=%d,"
+                        " fEffOnTime=%s,"
+                        " fTotOnTime=%s,"
                         " fMuonRate=%s,"
                         " fPSF=%s,"
@@ -293,6 +283,7 @@
                         " fBrightnessRMS=%s,"
                         " fInhomogeneity=%s ",
+                        seq.GetSequence(), seq.GetTelescope(),
                         islands.Data(), ratio.Data(),
-                        num, effontime,
+                        num, effontime.Data(), totontime.Data(),
                         muonrate.Data(), PSF.Data(),
                         datarate, sparkrate.Data(), maxhum.Data(),
@@ -304,5 +295,8 @@
                         inhomogen.Data());
 
-    return serv.InsertUpdate("Star", "fSequenceFirst", Form("%d", seq), vars);
+    TString where = Form("fSequenceFirst=%d AND fTelescopeNumber=%d",
+                         seq.GetSequence(), seq.GetTelescope());
+
+    return serv.InsertUpdate("Star", vars, where) ? 1 : 2;
 }
 
