Index: trunk/MagicSoft/Mars/datacenter/macros/buildsequenceentries.C
===================================================================
--- trunk/MagicSoft/Mars/datacenter/macros/buildsequenceentries.C	(revision 9015)
+++ trunk/MagicSoft/Mars/datacenter/macros/buildsequenceentries.C	(revision 9017)
@@ -446,9 +446,13 @@
         if (IsDummy())
         {
-            cout << "       + unlink " << fname << endl;
-            cout << "       + " << cmd1 << endl;
-            cout << "       + " << cmd2 << endl;
+            cout << "       + would unlink " << fname << endl;
+            cout << "       + would remove " << cmd1 << endl;
+            cout << "       + would remove " << cmd2 << endl;
             return kTRUE;
         }
+
+        cout << "       + will unlink " << fname << endl;
+        cout << "       + will remove " << cmd1 << endl;
+        cout << "       + will remove " << cmd2 << endl;
 
         gSystem->Unlink(fname);
Index: trunk/MagicSoft/Mars/datacenter/macros/plotdb.C
===================================================================
--- trunk/MagicSoft/Mars/datacenter/macros/plotdb.C	(revision 9015)
+++ trunk/MagicSoft/Mars/datacenter/macros/plotdb.C	(revision 9017)
@@ -1,4 +1,4 @@
 /* ======================================================================== *\
-! $Name: not supported by cvs2svn $:$Id: plotdb.C,v 1.48 2008-06-30 09:36:34 tbretz Exp $
+! $Name: not supported by cvs2svn $:$Id: plotdb.C,v 1.49 2008-07-20 14:21:40 tbretz Exp $
 ! --------------------------------------------------------------------------
 !
@@ -63,5 +63,4 @@
 
 #include <TH1.h>
-#include <TEnv.h>
 #include <TPad.h>
 #include <TLine.h>
@@ -90,4 +89,5 @@
         kGroupByPrimary,
         kGroupByHour,
+        kGroupByDay,
         kGroupByNight,
         kGroupByWeek,
@@ -159,10 +159,12 @@
         while ((row=res.Next()))
         {
+            Int_t pos=0;
             // Get all fields of this row
-            const char *date = (*row)[0];
-            const char *zd   = (*row)[1];
-            const char *val  = (*row)[2];
-            const char *snum = res.GetFieldCount()>3 ? (*row)[3] : 0;
-            const char *verr = res.GetFieldCount()>4 ? (*row)[5] : 0;
+            const char *date  = (*row)[pos++];
+            const char *zd    = (*row)[pos++];
+            const char *val   = (*row)[pos++];
+            const char *zderr = fGroupBy!=kNone ? (*row)[pos++] : 0;
+            const char *verr  = fGroupBy!=kNone ? (*row)[pos++] : 0;
+            const char *snum  = fDataSet        ? (*row)[pos++] : 0;
 
             delete row;
@@ -383,6 +385,12 @@
             fDataSet = NULL;
         }
-        if (!filename.IsNull())
-            fDataSet = new MDataSet(filename);
+
+        fPrimaryNumber="";
+
+        if (filename.IsNull())
+            return;
+
+        fDataSet = new MDataSet(filename);
+        fPrimaryNumber="Sequences.fSequenceFirst";
     }
     void SetPlotRange(Float_t min, Float_t max/*, Int_t n=5*/) { fPlotMin = min; fPlotMax = max; }
@@ -395,8 +403,9 @@
     void SetGroupBy(GroupBy_t b=kGroupByWeek) { fGroupBy=b; }
     void SetPrimaryDate(const char *ts) { fPrimaryDate=ts; }
-    void SetPrimaryNumber(const char *ts) { fPrimaryNumber=ts; }
+    void SetPrimaryNumber(const char *ts) { }
     void SetSecondary(const char *ts) { fSecondary=ts; }
 
     MStatusDisplay *GetDisplay() { return fDisplay; }
+    MSQLMagic &GetServer() { return fServer; }
 
     Bool_t Plot(const char *value, Float_t min=0, Float_t max=-1, Float_t resolution=0)
@@ -424,4 +433,7 @@
         case kGroupByNight:
             query += Form("DATE_FORMAT(ADDDATE(%s,Interval 12 hour), '%%Y-%%m-%%d 00:00:00') AS %s ", fPrimaryDate.Data(), valued.Data()+1);
+            break;
+        case kGroupByDay:
+            query += Form("DATE_FORMAT(%s, '%%Y-%%m-%%d 00:00:00') AS %s ", fPrimaryDate.Data(), valued.Data()+1);
             break;
         case kGroupByWeek:
@@ -445,36 +457,37 @@
             query += ", ";
             query += value;
+        }
+        else
+        {
+            TString v(value);
+
+            TString as = v(TPRegexp(" +[aA][sS] +[a-zA-Z0-9]+ *$"));
+            Ssiz_t  p  = v.Index(as);
+
+            v.Prepend("(");
+            v.Insert(p<=0?v.Length():p+1, ")");
+
+            query += ", AVG";
+            query += v;
+            query += ", AVG(";
+            query += fSecondary;
+            query += "), STD";
+            query += v;
+            query += ", STD(";
+            query += fSecondary;
+            query += ")";
+        }
+
+        if (fDataSet)
+        {
             query += ", ";
             query += fPrimaryNumber;
-            query += " ";
-        }
-        else
-        {
-            query += ", AVG(";
-            query += fSecondary;
-            query += "), AVG(";
-            query += value;
-            query += "), ";
-            query += fPrimaryNumber;
-            query += ", STD(";
-            query += fSecondary;
-            query += "), STD(";
-            query += value;
-            query += ") ";
-        }
-
-        query += Form("FROM %s ", tabled.Data());
+        }
+
+        query += Form(" FROM %s ", tabled.Data());
 
         const Bool_t interval = !fRequestFrom.IsNull() && !fRequestTo.IsNull();
 
         TString where(fCondition);
-        /*
-        if (!fDataSet && !interval && tablev=="Star")
-        {
-            if (!where.IsNull())
-                where += " AND ";
-            where += "Star.fMuonNumber>300 ";
-        }
-        */
         if (interval)
         {
@@ -521,12 +534,15 @@
         return kTRUE;
     }
+//    ClassDef(MPlot, 0)
 };
+
+//ClassImp(MPlot);
 
 void plotalldb(MPlot &plot)
 {
     //plot.SetGroupBy(MPlot::kGroupByNight);
+    //plot.SetDataSet("dataset.txt");
 
     plot.SetPrimaryDate("Sequences.fRunStart");
-    plot.SetPrimaryNumber("Sequences.fSequenceFirst");
     plot.SetSecondary("(Sequences.fZenithDistanceMin+Sequences.fZenithDistanceMax)/2 as '<Zd>'");
 
@@ -668,7 +684,5 @@
 int plotdb(TString from, TString to, const char *dataset=0)
 {
-    TEnv env("sql.rc");
-
-    MSQLMagic serv(env);
+    MSQLMagic serv("sql.rc");
     if (!serv.IsConnected())
     {
@@ -700,7 +714,5 @@
 int plotdb(const char *ds)
 {
-    TEnv env("sql.rc");
-
-    MSQLMagic serv(env);
+    MSQLMagic serv("sql.rc");
     if (!serv.IsConnected())
     {
@@ -732,7 +744,5 @@
 int plotdb(Int_t period, const char *dataset="")
 {
-    TEnv env("sql.rc");
-
-    MSQLMagic serv(env);
+    MSQLMagic serv("sql.rc");
     if (!serv.IsConnected())
     {
Index: trunk/MagicSoft/Mars/datacenter/macros/plotrundb.C
===================================================================
--- trunk/MagicSoft/Mars/datacenter/macros/plotrundb.C	(revision 9015)
+++ trunk/MagicSoft/Mars/datacenter/macros/plotrundb.C	(revision 9017)
@@ -1,4 +1,4 @@
 /* ======================================================================== *\
-! $Name: not supported by cvs2svn $:$Id: plotrundb.C,v 1.6 2008-07-05 19:01:42 tbretz Exp $
+! $Name: not supported by cvs2svn $:$Id: plotrundb.C,v 1.7 2008-07-20 14:21:40 tbretz Exp $
 ! --------------------------------------------------------------------------
 !
@@ -61,5 +61,5 @@
 #include "plotdb.C"
 
-void plotall(MPlot &plot)
+void plotall(MPlot &plot, Int_t tel=0)
 {
     plot.SetGroupBy(MPlot::kGroupByNight);
@@ -73,4 +73,9 @@
     cond += t.GetSqlDateTime();
     cond += "'";
+    if (tel>0)
+    {
+        query[0] += " AND fTelescopeNumber=";
+        query[0] += tel;
+    }
     plot.SetCondition(cond);
 
Index: trunk/MagicSoft/Mars/datacenter/scripts/checkfilesforsequenceavail
===================================================================
--- trunk/MagicSoft/Mars/datacenter/scripts/checkfilesforsequenceavail	(revision 9015)
+++ trunk/MagicSoft/Mars/datacenter/scripts/checkfilesforsequenceavail	(revision 9017)
@@ -73,5 +73,5 @@
    makedir $checkfileavailpath  >> $scriptlog 2>&1 
    checkfileavaillog=$checkfileavailpath/$program-$sequence.log
-   
+
    sequencefile=$sequpath/$no/sequence$no2.txt
 
@@ -79,5 +79,5 @@
    setstatus "start" >> $scriptlog 2>&1
 
-   check1=`root -q -b $macrospath/checkfileavail.C+\(\""$sequencefile\""\) | tee $checkfileavaillog | intgrep`
+   check1=`root -q -b $macrospath/checkfileavail.C+\(\""$sequencefile\",1"\) | tee $checkfileavaillog | intgrep`
 
    case $check1 in
