Index: /trunk/MagicSoft/Mars/datacenter/macros/plotdb.C
===================================================================
--- /trunk/MagicSoft/Mars/datacenter/macros/plotdb.C	(revision 7491)
+++ /trunk/MagicSoft/Mars/datacenter/macros/plotdb.C	(revision 7492)
@@ -68,6 +68,13 @@
 #include "MTime.h"
 #include "MAstro.h"
+#include "MDataSet.h"
 #include "MSQLServer.h"
 #include "MStatusDisplay.h"
+
+// Replace this line
+MDataSet ds;
+//  by
+// MDataSet ds("/magic/datasets/00000/dataset00000003.txt");
+//  to mark the sequences of your favourite dataset.
 
 class MPlot : public MParContainer
@@ -95,18 +102,30 @@
         TSQLRow *row;
 
-        TGraph g;
-        g.SetNameTitle(name, Form("%s vs Time", name.Data()));
-        g.SetMarkerStyle(kFullDotMedium);
-
-        TGraph g2;
-        g2.SetNameTitle(name, Form("%s vs <Zd>", name.Data()));
-        g2.SetMarkerStyle(kFullDotMedium);
+        TGraph gt;
+        gt.SetNameTitle(name, Form("%s vs Time", name.Data()));
+        gt.SetMarkerStyle(kFullDotMedium);
+
+        TGraph gz;
+        gz.SetNameTitle(name, Form("%s vs <Zd>", name.Data()));
+        gz.SetMarkerStyle(kFullDotMedium);
+
+        TGraph gt0, gt1;
+        gt0.SetMarkerColor(kRed);
+        gt1.SetMarkerColor(kBlue);
+        gt0.SetMarkerStyle(kFullDotLarge);
+        gt1.SetMarkerStyle(kFullDotLarge);
+
+        TGraph gz0, gz1;
+        gz0.SetMarkerColor(kRed);
+        gz1.SetMarkerColor(kBlue);
+        gz0.SetMarkerStyle(kFullDotLarge);
+        gz1.SetMarkerStyle(kFullDotLarge);
 
         if (fmax>fmin)
         {
-            g.SetMinimum(fmin);
-            g.SetMaximum(fmax);
-            g2.SetMinimum(fmin);
-            g2.SetMaximum(fmax);
+            gt.SetMinimum(fmin);
+            gt.SetMaximum(fmax);
+            gz.SetMinimum(fmin);
+            gz.SetMaximum(fmax);
         }
 
@@ -119,5 +138,6 @@
             const char *zd   = (*row)[1];
             const char *val  = (*row)[2];
-            if (!date || !val || !zd)
+            const char *snum = (*row)[3];
+            if (!date || !val || !zd || !snum)
                 continue;
 
@@ -133,8 +153,23 @@
             last = TMath::Nint(TMath::Ceil(t.GetMjd()));
 
+            UInt_t seq = atoi(snum);
+    
             Float_t value = atof(val);
             Float_t zenith = atof(zd);
-            g.SetPoint(g.GetN(), t.GetAxisTime(), value);
-            g2.SetPoint(g2.GetN(), zenith, value);
+
+            if (ds.HasOnSequence(seq))
+            {
+                gt1.SetPoint(gt1.GetN(), t.GetAxisTime(), value);
+                gz1.SetPoint(gz1.GetN(), zenith, value);
+            }
+
+            if (ds.HasOffSequence(seq))
+            {
+                gt0.SetPoint(gt0.GetN(), t.GetAxisTime(), value);
+                gz0.SetPoint(gz0.GetN(), zenith, value);
+            }
+
+            gt.SetPoint(gt.GetN(), t.GetAxisTime(), value);
+            gz.SetPoint(gz.GetN(), zenith, value);
         }
 
@@ -147,4 +182,11 @@
         c.Divide(1,2);
 
+        if (gt0.GetN()>0 && gt1.GetN()>0)
+        {
+            cerr << setw(10) << title << ":   ";
+            cerr << setw(9) << gt0.GetMean(2) << "+-" << setw(9) << gt0.GetRMS(2) << "   ";
+            cerr << setw(9) << gt1.GetMean(2) << "+-" << setw(9) << gt1.GetRMS(2) << endl;
+        }
+
         TVirtualPad *pad = gPad;
         pad->cd(2);
@@ -157,5 +199,5 @@
         gPad->SetBottomMargin(0.08);
 
-        TH1 *h = g.GetHistogram();
+        TH1 *h = gt.GetHistogram();
 
         h->SetXTitle("Time");
@@ -166,5 +208,9 @@
         h->GetXaxis()->SetLabelOffset(0.01);
 
-        g.DrawClone("AP");
+        gt.DrawClone("AP");
+        if (gt0.GetN()>0)
+            gt0.DrawClone("P");
+        if (gt1.GetN()>0)
+            gt1.DrawClone("P");
 
         TLine l;
@@ -195,4 +241,7 @@
         const Double_t max = fHistMin>fHistMax ? h->GetMaximum()+resolution/2 : fHistMax;
 
+        // Use this to save the pad with the time development to a file
+        //gPad->SaveAs(Form("plotdb-%s.eps", title.Data()));
+
         pad->cd(1);
         gPad->SetBorderMode(0);
@@ -212,6 +261,6 @@
         hist.SetDirectory(0);
 
-        for (int i=0; i<g.GetN(); i++)
-            hist.Fill(g.GetY()[i]);
+        for (int i=0; i<gt.GetN(); i++)
+            hist.Fill(gt.GetY()[i]);
 
         if (fDescription.IsNull())
@@ -226,10 +275,14 @@
         gPad->SetGridy();
 
-        TH1 *h2 = g2.GetHistogram();
+        TH1 *h2 = gz.GetHistogram();
 
         h2->SetXTitle("Zd");
         h2->SetYTitle(name);
 
-        g2.DrawClone("AP");
+        gz.DrawClone("AP");
+        if (gz0.GetN()>0)
+            gz0.DrawClone("P");
+        if (gz1.GetN()>0)
+            gz1.DrawClone("P");
     }
 
@@ -263,5 +316,5 @@
 
         TString query;
-        query  = Form("select %s, %s, %s ",    valued.Data(), named2.Data(), valuev.Data());
+        query  = Form("select %s, %s, %s, Sequences.fSequenceFirst ",    valued.Data(), named2.Data(), valuev.Data());
         query += Form("from %s left join %s ", tabled.Data(), tablev.Data());
         query += Form("on %s.%s=%s.%s ",       tabled.Data(), join.Data(), tablev.Data(), join.Data());
Index: /trunk/MagicSoft/Mars/mjobs/MDataSet.h
===================================================================
--- /trunk/MagicSoft/Mars/mjobs/MDataSet.h	(revision 7491)
+++ /trunk/MagicSoft/Mars/mjobs/MDataSet.h	(revision 7492)
@@ -53,4 +53,12 @@
     }
 
+    Bool_t HasSequence(UInt_t num, const TArrayI &seq) const
+    {
+        for (int i=0; i<seq.GetSize(); i++)
+            if ((UInt_t)seq[i]==num)
+                return kTRUE;
+        return kFALSE;
+    }
+
 public:
     MDataSet(Int_t num=(UInt_t)-1) : fNumAnalysis(num) { }
@@ -89,4 +97,8 @@
 
     Bool_t HasOffSequences() const { return GetNumSequencesOff()>0; }
+
+    Bool_t HasOffSequence(UInt_t num) const { return HasSequence(num, fNumSequencesOff); }
+    Bool_t HasOnSequence(UInt_t num) const  { return HasSequence(num, fNumSequencesOn); }
+    Bool_t HasSequence(UInt_t num) const    { return HasOnSequence(num) || HasOffSequence(num); }
 
     UInt_t GetNumAnalysis() const { return fNumAnalysis; }
