Index: trunk/MagicSoft/Mars/datacenter/macros/checkstardone.C
===================================================================
--- trunk/MagicSoft/Mars/datacenter/macros/checkstardone.C	(revision 9055)
+++ trunk/MagicSoft/Mars/datacenter/macros/checkstardone.C	(revision 9062)
@@ -72,5 +72,5 @@
     // -------------------------------------------
 
-    TString query = "NOT ISNULL(fStar) FROM SequenceProcessStatus "
+    TString query = "SELECT MIN(NOT ISNULL(fStar)) FROM SequenceProcessStatus "
         "LEFT JOIN DataSetSequenceMapping USING (fTelescopeNumber,fSequenceFirst) ";
     query += Form("WHERE fDataSetNumber=%d", num);
@@ -87,5 +87,5 @@
     }
 
-    TSQlRow *row = res->Next();
+    TSQLRow *row = res->Next();
 
     if (!row || !(*row)[0])
Index: trunk/MagicSoft/Mars/datacenter/macros/fillcalib.C
===================================================================
--- trunk/MagicSoft/Mars/datacenter/macros/fillcalib.C	(revision 9055)
+++ trunk/MagicSoft/Mars/datacenter/macros/fillcalib.C	(revision 9062)
@@ -61,7 +61,4 @@
 #include <iostream>
 
-#include <TEnv.h>
-#include <TRegexp.h>
-
 #include <TH1.h>
 
@@ -74,4 +71,5 @@
 #include "MStatusArray.h"
 #include "MHCamera.h"
+#include "MSequence.h"
 #include "MGeomCamMagic.h"
 #include "MBadPixelsCam.h"
@@ -145,5 +143,5 @@
     if (!h)
     {
-        cout << "WARNING - Could not find histogram HRelTimeHiGainArea0." << endl;
+        cout << "ERROR - Could not find histogram HRelTimeHiGainArea0 in Time." << endl;
         return 2;
     }
@@ -156,5 +154,5 @@
     if (!h)
     {
-        cout << "WARNING - Could not find histogram HRelTimeHiGainArea1." << endl;
+        cout << "ERROR - Could not find histogram HRelTimeHiGainArea1 in Time." << endl;
         return 2;
     }
@@ -167,5 +165,5 @@
     if (!c)
     {
-        cout << "WARNING - Could not find MHCamera TotalConv." << endl;
+        cout << "ERROR - Could not find MHCamera TotalConv in Conversion." << endl;
         return 2;
     }
@@ -182,13 +180,41 @@
     TString meanconvouter=Form("%6.3f", meanconvo);
 
-    //Getting sequ# from filename
-    TString sequence = fname(TRegexp("calib[0-9]+[.]root$"));
-    if (sequence.IsNull())
-    {
-        cout << "WARNING - Could get sequence# from filename: " << fname << endl;
-        return 2;
-    }
-
-    Int_t seq = atoi(sequence.Data()+5);
+    //Getting relative charge rms
+    c = (MHCamera*)arr.FindObjectInCanvas("RMSperMean", "MHCamera", "FitCharge");
+    if (!c)
+    {
+        cout << "ERROR - Could not find MHCamera RMSperMean in FitCharge." << endl;
+        return 2;
+    }
+
+    Stat_t relrmsi = c->GetMedianSectors(TArrayI(6, s0), inner);
+    Stat_t relrmso = c->GetMedianSectors(TArrayI(6, s0), outer);
+    TString relrmsinner=Form("%6.3f", relrmsi);
+    TString relrmsouter=Form("%6.3f", relrmso);
+
+    //Getting relative charge rms
+    c = (MHCamera*)arr.FindObjectInCanvas("NumPhes", "MHCamera", "FitCharge");
+    if (!c)
+    {
+        cout << "ERROR - Could not find MHCamera NumPhes in FitCharge." << endl;
+        return 2;
+    }
+
+    Stat_t numphei = c->GetMedianSectors(TArrayI(6, s0), inner);
+    Stat_t numpheo = c->GetMedianSectors(TArrayI(6, s0), outer);
+    TString numpheinner=Form("%5.1f", numphei);
+    TString numpheouter=Form("%5.1f", numpheo);
+
+    MSequence seq;
+    if (seq.Read("sequence[0-9]{8}[.]txt|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;
+    }
 
     //getting the ratio of calibration events used
@@ -196,15 +222,16 @@
     if (!h)
     {
-        cout << "WARNING - Could not find histogram ArrTime;avg." << endl;
-        return 2;
-    }
-
-    UInt_t nevts = h->GetEntries();
+        cout << "ERROR - Could not find histogram ArrTime;avg." << endl;
+        return 2;
+    }
+
+    UInt_t nevts = TMath::Nint(h->GetEntries());
 
     TString query;
     query = Form("SELECT SUM(fNumEvents) FROM RunData "
-                 "LEFT JOIN RunType ON RunType.fRunTypeKEY=RunData.fRunTypeKEY "
-                 "WHERE fSequenceFirst=%d AND RunType.fRunTypeName='Calibration'",
-                 seq);
+                 "LEFT JOIN RunType USING (fRunTypeKEY) "
+                 "WHERE fSequenceFirst=%d AND fTelescopeNumber=%d AND "
+                 "RunType.fRunTypeName='Calibration'",
+                 seq.GetSequence(), seq.GetTelescope());
 
     TSQLResult *res = serv.Query(query);
@@ -228,18 +255,26 @@
     delete res;
 
-    cout << "Sequence #" << seq << endl;
-    cout << "  Unsuitable: (i/o) " << Form("%3d %3d", (int)unsin, (int)unsout) << endl; // Unbrauchbar
-    cout << "  Unreliable: (i/o) " << Form("%3d %3d", (int)unrin, (int)unrout) << endl; // Unzuverlaessig
-    cout << "  Isolated:   (i/o) " << Form("%3d %3d", (int)isoin, (int)isoout) << endl; // Isolated (unbrauchbar)
-    cout << "  Max.Cluster:      " << Form("%3d", (int)clumax)                 << endl; // Max Cluster
-    cout << "  Arr Time inner:    " << meaninner << " +- " << rmsinner  << endl;
-    cout << "  Arr Time outer:    " << meanouter << " +- " << rmsouter  << endl;
-    cout << "  Mean Conv inner:   " << meanconvinner << endl;
-    cout << "  Mean Conv outer:   " << meanconvouter << endl;
-    cout << "  Ratio Calib Evts:  " << ratiocal << endl;
+    cout << "Sequence M" << seq.GetTelescope() << ":" << seq.GetSequence() << endl;
+    cout << "  Unsuitable: (i/o)  " << Form("%3d %3d", (int)unsin, (int)unsout) << endl; // Unbrauchbar
+    cout << "  Unreliable: (i/o)  " << Form("%3d %3d", (int)unrin, (int)unrout) << endl; // Unzuverlaessig
+    cout << "  Isolated:   (i/o)  " << Form("%3d %3d", (int)isoin, (int)isoout) << endl; // Isolated (unbrauchbar)
+    cout << "  Max.Cluster:       " << Form("%3d", (int)clumax)                 << endl; // Max Cluster
+    cout << "  Arr Time inner:     " << meaninner << " +- " << rmsinner  << endl;
+    cout << "  Arr Time outer:     " << meanouter << " +- " << rmsouter  << endl;
+    cout << "  Mean Conv inner:     " << meanconvinner << endl;
+    cout << "  Mean Conv outer:     " << meanconvouter << endl;
+    cout << "  Rel.charge rms in:   " << relrmsinner << endl;
+    cout << "  Rel.charge rms out:  " << relrmsouter << endl;
+    cout << "  Med. num phe inner: " << numpheinner << endl;
+    cout << "  Med. num phe outer: " << numpheouter << endl;
+    cout << "  Ratio Calib Evts:   " << ratiocal << endl;
+
+    // FIXME: Fill calibration charge
 
     //inserting or updating the information in the database
     TString vars =
-        Form(" fUnsuitableInner=%d, "
+        Form(" fSequenceFirst=%d, "
+             " fTelescopeNumber=%d, "
+             " fUnsuitableInner=%d, "
              " fUnsuitableOuter=%d, "
              " fUnreliableInner=%d, "
@@ -254,5 +289,10 @@
              " fConvFactorInner=%s, "
              " fConvFactorOuter=%s, "
-             " fRatioCalEvents=%s ",
+             " fRatioCalEvents=%s, "
+             " fRelChargeRmsInner=%s, "
+             " fRelChargeRmsOuter=%s, "
+             " fMedNumPheInner=%s, "
+             " fMedNumPheOuter=%s ",
+             seq.GetSequence(), seq.GetTelescope(),
              (int)unsin, (int)unsout, (int)unrin,
              (int)unrout, (int)isoin, (int)isoout, (int)clumax,
@@ -260,15 +300,18 @@
              meanouter.Data(), rmsouter.Data(),
              meanconvinner.Data(), meanconvouter.Data(),
-             ratiocal.Data());
-
-    return serv.InsertUpdate("Calibration", "fSequenceFirst",
-                             Form("%d", seq), vars.Data()) ? 1 : 2;
+             ratiocal.Data(),
+             relrmsinner.Data(), relrmsouter.Data(),
+             numpheinner.Data(), numpheouter.Data()
+            );
+
+    TString where = Form("fSequenceFirst=%d AND fTelescopeNumber=%d",
+                         seq.GetSequence(), seq.GetTelescope());
+
+    return serv.InsertUpdate("Calibration", vars, where) ? 1 : 2;
 }
 
 int fillcalib(TString fname, Bool_t dummy=kTRUE)
 {
-    TEnv env("sql.rc");
-
-    MSQLMagic serv(env);
+    MSQLMagic serv("sql.rc");
     if (!serv.IsConnected())
     {
Index: trunk/MagicSoft/Mars/datacenter/macros/fillsignal.C
===================================================================
--- trunk/MagicSoft/Mars/datacenter/macros/fillsignal.C	(revision 9055)
+++ trunk/MagicSoft/Mars/datacenter/macros/fillsignal.C	(revision 9062)
@@ -69,4 +69,5 @@
 
 #include "MStatusArray.h"
+#include "MSequence.h"
 #include "MHCamera.h"
 #include "MHVsTime.h"
@@ -140,14 +141,15 @@
 */
 
-    //get sequence number from the filename
-    TString sequence = fname(TRegexp("signal[0-9]+[.]root$"));
-    if (sequence.IsNull())
-    {
-        cout << "ERROR - Sequ# empty" << endl;
-        cout << "Sequ# " << sequence << endl;
-        return 2;
-    }
-
-    Int_t seq = atoi(sequence.Data()+6);
+    MSequence seq;
+    if (seq.Read("sequence[0-9]{8}[.]txt|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;
+    }
 
     TString medpuloff("NULL");
@@ -156,5 +158,5 @@
     TString devhilocal("NULL");
 
-    if (seq < 200000)
+    if (seq.GetSequence()<200000 && seq.GetTelescope()==1)
     {
         MHCamera *hilooff = (MHCamera*)arr.FindObjectInCanvas("HiLoOff;avg", "MHCamera", "HiLoOff");
@@ -313,5 +315,5 @@
     // *****************************************************
 
-    cout << "Sequence #" << seq << endl;
+    cout << "Sequence M" << seq.GetTelescope() << "/" << seq.GetSequence() << endl;
     cout << "  Mean Ped RMS inner [phe] " << meanrmsinner  << endl;
     cout << "  Mean Ped RMS outer [phe] " << meanrmsouter  << endl;
@@ -374,6 +376,7 @@
                        );
 
-
-    return serv.Update("Calibration", vars, Form("fSequenceFirst=%d", seq)) ? 1 : 2;
+    TString where = Form("fSequenceFirst=%d AND fTelescopeNumber=%d",
+                         seq.GetSequence(), seq.GetTelescope());
+    return serv.Update("Calibration", vars, where) ? 1 : 2;
 }
 
Index: trunk/MagicSoft/Mars/datacenter/macros/fillstar.C
===================================================================
--- trunk/MagicSoft/Mars/datacenter/macros/fillstar.C	(revision 9055)
+++ 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;
 }
 
