Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 9016)
+++ trunk/MagicSoft/Mars/Changelog	(revision 9017)
@@ -18,4 +18,31 @@
 
                                                  -*-*- END OF LINE -*-*-
+
+ 2008/07/20 Thomas Bretz
+
+   * callisto.cc, star.cc, mjobs/MDataSet.cc, mjobs/MJCalibrateSignal.cc,
+     mjobs/MJCalibration.cc, mjobs/MJPedestal.cc, mjoptim/MJOptimize.cc,
+     mmain/MEventDisplay.cc:
+     - replaced Setup*Runs by GetRuns
+
+   * datacenter/macros/buildsequenceentries.C:
+     - output if something is deleted
+
+   * datacenter/macros/plotdb.C:
+     - added kGroupByDay option
+     - some small changes
+     - made group by work with "as"
+     - made use of TEnv obsolete
+
+   * datacenter/macros/plotrundb.C:
+     - added telescope number as otpion
+
+   * datacenter/scripts/checkfilesforsequenceavail:
+     - added telescope number 1 to call of checkfileavail.C
+
+   * mbase/MTime.cc:
+     - made SetSqlDateTime more flexible
+
+
 
  2008/07/19 Thomas Bretz
Index: trunk/MagicSoft/Mars/callisto.cc
===================================================================
--- trunk/MagicSoft/Mars/callisto.cc	(revision 9016)
+++ trunk/MagicSoft/Mars/callisto.cc	(revision 9017)
@@ -122,12 +122,12 @@
 }
 
-static void PrintFiles(const MSequence &seq, const TString &kInpathD, Bool_t raw, Bool_t showall)
+static void PrintFiles(const MSequence &seq, const TString &kInpathD, Bool_t showall)
 {
     const char *prep = showall ? "Found" : "Scheduled";
 
     MDirIter Next1, Next2, Next3;
-    seq.SetupPedRuns(Next1, kInpathD, raw);
-    seq.SetupCalRuns(Next2, kInpathD, raw);
-    seq.SetupDatRuns(Next3, kInpathD, raw);
+    seq.GetRuns(Next1, MSequence::kRawPed, kInpathD);
+    seq.GetRuns(Next2, MSequence::kRawCal, kInpathD);
+    seq.GetRuns(Next3, MSequence::kRawDat, kInpathD);
 
     gLog << all;
@@ -310,7 +310,7 @@
     //
     if (kPrintFiles)
-        PrintFiles(seq, kInpathD, !seq.IsMonteCarlo(), kFALSE);
+        PrintFiles(seq, kInpathD, kFALSE);
     if (kPrintFound)
-        PrintFiles(seq, kInpathD, !seq.IsMonteCarlo(), kTRUE);
+        PrintFiles(seq, kInpathD, kTRUE);
 
 //    if (seq.HasMoon())
Index: trunk/MagicSoft/Mars/datacenter/macros/buildsequenceentries.C
===================================================================
--- trunk/MagicSoft/Mars/datacenter/macros/buildsequenceentries.C	(revision 9016)
+++ 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 9016)
+++ 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 9016)
+++ 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 9016)
+++ 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
Index: trunk/MagicSoft/Mars/mbase/MTime.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MTime.cc	(revision 9016)
+++ trunk/MagicSoft/Mars/mbase/MTime.cc	(revision 9017)
@@ -403,7 +403,17 @@
         return kFALSE;
 
-    UInt_t  y, mon, d, h, m, s;
+    UInt_t  y, mon, d, h, m, s, ms;
+
+    if (7==sscanf(str, "%04u-%02u-%02u %02u:%02u:%02u.%u", &y, &mon, &d, &h, &m, &s, &ms))
+        return Set(y, mon, d, h, m, s, ms);
+
     if (6==sscanf(str, "%04u-%02u-%02u %02u:%02u:%02u", &y, &mon, &d, &h, &m, &s))
         return Set(y, mon, d, h, m, s);
+
+    if (5==sscanf(str, "%04u-%02u-%02u %02u:%02u", &y, &mon, &d, &h, &m))
+        return Set(y, mon, d, h, m);
+
+    if (4==sscanf(str, "%04u-%02u-%02u %02u", &y, &mon, &d, &h))
+        return Set(y, mon, d, h);
 
     if (3==sscanf(str, "%04u-%02u-%02u", &y, &mon, &d))
Index: trunk/MagicSoft/Mars/mjobs/MDataSet.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MDataSet.cc	(revision 9016)
+++ trunk/MagicSoft/Mars/mjobs/MDataSet.cc	(revision 9017)
@@ -633,5 +633,5 @@
         }
 
-        if (seq->SetupDatRuns(files, MSequence::kImages)<=0)
+        if (seq->GetRuns(files, MSequence::kImages)<=0)
             return kFALSE;
     }
Index: trunk/MagicSoft/Mars/mjobs/MJCalibrateSignal.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJCalibrateSignal.cc	(revision 9016)
+++ trunk/MagicSoft/Mars/mjobs/MJCalibrateSignal.cc	(revision 9017)
@@ -260,5 +260,5 @@
     if (fSequence.IsValid())
     {
-        if (fSequence.SetupDatRuns(iter, 0, !fSequence.IsMonteCarlo())<=0)
+        if (fSequence.GetRuns(iter, MSequence::kRawDat)<=0)
             return kFALSE;
     }
Index: trunk/MagicSoft/Mars/mjobs/MJCalibration.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJCalibration.cc	(revision 9016)
+++ trunk/MagicSoft/Mars/mjobs/MJCalibration.cc	(revision 9017)
@@ -1483,5 +1483,5 @@
 
     MDirIter iter;
-    if (fSequence.SetupCalRuns(iter, 0, !fSequence.IsMonteCarlo())<=0)
+    if (fSequence.GetRuns(iter, MSequence::kRawCal)<=0)
         return kFALSE;
 
Index: trunk/MagicSoft/Mars/mjobs/MJPedestal.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJPedestal.cc	(revision 9016)
+++ trunk/MagicSoft/Mars/mjobs/MJPedestal.cc	(revision 9017)
@@ -949,6 +949,6 @@
     {
         const Int_t n0 = IsUseData()
-            ? fSequence.SetupDatRuns(iter, 0, !fSequence.IsMonteCarlo())
-            : fSequence.SetupPedRuns(iter, 0, !fSequence.IsMonteCarlo());
+            ? fSequence.GetRuns(iter, MSequence::kRawDat)
+            : fSequence.GetRuns(iter, MSequence::kRawPed);
 
         if (n0<=0)
Index: trunk/MagicSoft/Mars/mjoptim/MJOptimize.cc
===================================================================
--- trunk/MagicSoft/Mars/mjoptim/MJOptimize.cc	(revision 9016)
+++ trunk/MagicSoft/Mars/mjoptim/MJOptimize.cc	(revision 9017)
@@ -250,5 +250,5 @@
         if (!seq->IsValid())
             return kFALSE;
-        if (seq->SetupDatRuns(files)<=0)
+        if (seq->GetRuns(files, MSequence::kRootDat)<=0)
             return kFALSE;
     }
Index: trunk/MagicSoft/Mars/mmain/MEventDisplay.cc
===================================================================
--- trunk/MagicSoft/Mars/mmain/MEventDisplay.cc	(revision 9016)
+++ trunk/MagicSoft/Mars/mmain/MEventDisplay.cc	(revision 9017)
@@ -1,4 +1,4 @@
 /* ======================================================================== *\
-! $Name: not supported by cvs2svn $:$Id: MEventDisplay.cc,v 1.64 2008-07-14 19:59:11 tbretz Exp $
+! $Name: not supported by cvs2svn $:$Id: MEventDisplay.cc,v 1.65 2008-07-20 14:21:39 tbretz Exp $
 ! --------------------------------------------------------------------------
 !
@@ -227,5 +227,5 @@
     {
         MDirIter iter;
-        if (seq->SetupDatRuns(iter, MSequence::kCalibrated)<=0)
+        if (seq->GetRuns(iter, MSequence::kCalibrated)<=0)
             return;
         read->AddFiles(iter);
Index: trunk/MagicSoft/Mars/star.cc
===================================================================
--- trunk/MagicSoft/Mars/star.cc	(revision 9016)
+++ trunk/MagicSoft/Mars/star.cc	(revision 9017)
@@ -84,5 +84,5 @@
 
     MDirIter Next;
-    seq.SetupDatRuns(Next, MSequence::kCalibrated, kInpathD);
+    seq.GetRuns(Next, MSequence::kCalibrated, kInpathD);
 
     gLog << all;
