Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 7261)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 7262)
@@ -32,4 +32,23 @@
      - added option --outf to make it possible to give the filename 
        (needed for automation of datacheck)
+     - added output in txt-file in case of no events (needed for the 
+       evaluation of runs with no interlaced events)
+     - small changes in output
+
+   * datacenter/macros/setupdb.C:
+     - added new table (DataCheck)
+
+   * datacenter/macros/fillsinope.C:
+     - added (macro to read in the sinope*.txt files and fill the 
+       information into the DB)
+
+   * datacenter/macros/filldotraw.C:
+     - added (was before in the directory macros/sql/)
+     - made some changes to include it into the automation 
+       added function make it possible to call the macro not only 
+       with the filename but also with the runnumber
+
+   * macros/sql/*:
+     - removed (all macros are now in the datacenter directory)
 
 
Index: /trunk/MagicSoft/Mars/datacenter/macros/fillsinope.C
===================================================================
--- /trunk/MagicSoft/Mars/datacenter/macros/fillsinope.C	(revision 7262)
+++ /trunk/MagicSoft/Mars/datacenter/macros/fillsinope.C	(revision 7262)
@@ -0,0 +1,195 @@
+/* ======================================================================== *\
+!
+! *
+! * This file is part of MARS, the MAGIC Analysis and Reconstruction
+! * Software. It is distributed to you in the hope that it can be a useful
+! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
+! * It is distributed WITHOUT ANY WARRANTY.
+! *
+! * Permission to use, copy, modify and distribute this software and its
+! * documentation for any purpose is hereby granted without fee,
+! * provided that the above copyright notice appear in all copies and
+! * that both that copyright notice and this permission notice appear
+! * in supporting documentation. It is provided "as is" without express
+! * or implied warranty.
+! *
+!
+!
+!   Author(s): Thomas Bretz, 04/2005 <mailto:tbretz@astro.uni-wuerzburg.de>
+!   Author(s): Daniela Dorner, 04/2005 <mailto:dorner@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2004
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// fillsinope.C
+// ============
+//
+// This macro is used to read the sinope output files sinope*.txt
+//
+// Usage:
+//   .x fillsignal.C(runnumber, kTRUE)
+//
+// The second argument is the 'dummy-mode'. If it is kTRUE dummy-mode is
+// switched on and nothing will be written into the database. This is usefull
+// for tests.
+//
+// Remark: Running it from the commandline looks like this:
+//   root -q -l -b fillsinope.C+\(runno\,kFALSE\) 2>&1 | tee fillsinope.log
+//
+// Make sure, that database and password are corretly set in a resource
+// file called sql.rc and the resource file is found.
+//
+// Returns 0 in case of failure and 1 in case of success.
+//
+/////////////////////////////////////////////////////////////////////////////
+#include <iostream>
+
+#include <TEnv.h>
+#include <TRegexp.h>
+
+#include <TFile.h>
+#include <TSQLResult.h>
+#include <TSQLRow.h>
+
+#include "MSQLServer.h"
+
+#include "MStatusArray.h"
+#include "MHCamera.h"
+
+using namespace std;
+
+Bool_t ExistStr(MSQLServer &serv, const char *column, const char *table, const char *test)
+{
+    TString query(Form("SELECT %s FROM %s WHERE %s='%s'", column, table, column, test));
+    TSQLResult *res = serv.Query(query);
+    if (!res)
+    {
+        cout << "ERROR - Query failed: " << query << endl;
+        return kFALSE;
+    }
+
+    Bool_t rc = kFALSE;
+
+    TSQLRow *row=res->Next();
+    if (row && (*row)[0])
+        rc=kTRUE;
+
+    delete res;
+    return rc;
+}
+
+int Process(MSQLServer &serv, TString fname, Int_t runno, Bool_t cal, Bool_t dummy)
+{
+    TEnv env(fname);
+
+    TString query="UPDATE DataCheck SET ";
+
+    TString values[9] = { "Events" , "HasSignal" , "HasPedestal" , "PositionSignal" , "PositionFWHM" , "PositionAsym" , "HeightSignal" , "HeightFWHM" , "HeightAsym" };
+
+    TString str;
+    for (Int_t i=0 ; i<9 ; i++)
+    {
+        cout << "value: " << values[i] << endl;
+        str = env.GetValue(values[i], "");
+        if (str.IsNull())
+            continue;
+
+        if (cal)
+            values[i]+="InterLaced";
+        values[i]+="='";
+        values[i]+=str;
+
+        if (i!=0)
+            query+=", ";
+        query+=" f";
+        query+=values[i];
+        query+="' ";
+
+        cout << "value: " << values[i] << endl;
+
+    }
+
+    query+=Form(" WHERE fRunNumber=%d", runno);
+
+    cout << "Q: " << query << endl;
+    TSQLResult *res = serv.Query(query);
+    if (!res)
+    {
+        cout << "ERROR - Query failed: " << query << endl;
+        return kFALSE;
+    }
+    delete res;
+    return 1;
+}
+
+int fillsinope(Int_t runno, TString datapath, Bool_t dummy=kTRUE)
+{
+    TEnv env("sql.rc");
+
+    MSQLServer serv(env);
+    if (!serv.IsConnected())
+    {
+        cout << "ERROR - Connection to database failed." << endl;
+        return 0;
+    }
+
+    cout << "fillsignal" << endl;
+    cout << "----------" << endl;
+    cout << endl;
+    cout << "Connected to " << serv.GetName() << endl;
+    cout << "Run: " << runno << endl;
+    cout << endl;
+
+    TString query(Form("SELECT DATE_FORMAT(ADDDATE(fRunStart, Interval 13 HOUR), '%%Y/%%m/%%d') FROM RunData WHERE fRunNumber=%d",
+                       runno));
+
+    TSQLResult *res = serv.Query(query);
+    if (!res)
+    {
+        cout << "ERROR - Query failed: " << query << endl;
+        return 0;
+    }
+
+    TSQLRow *row = 0;
+    row = res->Next();
+    TString date=(*row)[0];
+    cout << "date: " << date << endl;
+    delete res;
+
+    if (!ExistStr(serv, "fRunNumber", "DataCheck", Form("%d", runno)))
+    {
+        query=Form("INSERT DataCheck SET fRunNumber=%d", runno);
+
+        cout << "U:" << query << endl;
+        res = serv.Query(query);
+        if (!res)
+        {
+            cout << "ERROR - Query failed: " << query << endl;
+            return 0;
+        }
+    }
+
+    TString fname(Form("%s/sinope/%s/sinope%08d.txt",
+                       datapath.Data(), date.Data(), runno));
+    cout << "file: " << fname << endl;
+    TString fnamecal(Form("%s/sinope/%s/sinope-cal%08d.txt",
+                        datapath.Data(), date.Data(), runno));
+    cout << "file-cal: " << fnamecal << endl;
+
+    fname="/home/bla/Mars.cvs/bla.txt";
+    fnamecal="/home/bla/Mars.cvs/blacal.txt";
+
+    Int_t rc=0;
+    rc=Process(serv, fname, runno, kFALSE, dummy);
+    if (rc==0)
+        return rc;
+
+    rc=Process(serv, fnamecal, runno, kTRUE, dummy);
+
+    return rc;
+
+}
Index: /trunk/MagicSoft/Mars/datacenter/macros/setupdb.C
===================================================================
--- /trunk/MagicSoft/Mars/datacenter/macros/setupdb.C	(revision 7261)
+++ /trunk/MagicSoft/Mars/datacenter/macros/setupdb.C	(revision 7262)
@@ -418,5 +418,5 @@
 
     list.Add(new TObjString(
-         "CREATE TABLE MyMagic.%s ("
+         "CREATE TABLE MyMagic.ExcludedFDA ("
          "  fExcludedFDAKEY        SMALLINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,"
          "  fExcludedFDAImportance SMALLINT UNSIGNED        NULL,"
@@ -425,4 +425,28 @@
          "  fExcludedFDA           VARCHAR(255)             NULL"
          ") MAX_ROWS=65536"));
+
+
+    list.Add(new TObjString(
+         "CREATE TABLE MyMagic.DataCheck ("
+         "  fRunNumber                INT      UNSIGNED PRIMARY KEY,"
+         "  fEvents                   INT      UNSIGNED        NULL,"
+         "  fPositionSignal           TINYINT  UNSIGNED        NULL,"
+         "  fPositionFWHM             TINYINT  UNSIGNED        NULL,"
+         "  fHeightSignal             SMALLINT UNSIGNED        NULL,"
+         "  fHeightFWHM               SMALLINT UNSIGNED        NULL,"
+         "  fHasSignal                ENUM(\"yes\",\"no\")     NULL,"
+         "  fHasPedestal              ENUM(\"yes\",\"no\")     NULL,"
+         "  fPositionAsym             ENUM(\"yes\",\"no\")     NULL,"
+         "  fHeightAsym               ENUM(\"yes\",\"no\")     NULL,"
+         "  fEventsInterlaced         INT      UNSIGNED        NULL,"
+         "  fPositionSignalInterlaced TINYINT  UNSIGNED        NULL,"
+         "  fPositionFWHMInterlaced   TINYINT  UNSIGNED        NULL,"
+         "  fHeightSignalInterlaced   SMALLINT UNSIGNED        NULL,"
+         "  fHeightFWHMInterlaced     SMALLINT UNSIGNED        NULL,"
+         "  fHasSignalInterlaced      ENUM(\"yes\",\"no\")     NULL,"
+         "  fHasPedestalInterlaced    ENUM(\"yes\",\"no\")     NULL,"
+         "  fPositionAsymInterlaced   ENUM(\"yes\",\"no\")     NULL,"
+         "  fHeightAsymInterlaced     ENUM(\"yes\",\"no\")     NULL"
+         ")"));
 
 
Index: /trunk/MagicSoft/Mars/sinope.cc
===================================================================
--- /trunk/MagicSoft/Mars/sinope.cc	(revision 7261)
+++ /trunk/MagicSoft/Mars/sinope.cc	(revision 7262)
@@ -117,5 +117,16 @@
     {
         gLog << warn << "No entries processed..." << endl;
-        return kFALSE;
+
+        ofstream fout(Form("%stxt", kOutpath.Data()));
+        if (!fout)
+        {
+            gLog << err << "Cannot open file: " << strerror(errno) << endl;
+            return kERROR;
+        }
+
+        fout << "Events:         " << events << endl;
+        fout << endl;
+
+        return kTRUE;
     }
 
@@ -164,14 +175,14 @@
 
     fout << "Events:         " << events << endl;
-    fout << "HasSignals:     " << (fwhm1>10?"No":"Yes") << endl;
-    fout << "HasPedestal:    " << (fwhm1<20?"No":"Yes") << endl;
+    fout << "HasSignal:      " << (fwhm1>10?"no":"yes") << endl;
+    fout << "HasPedestal:    " << (fwhm1<20?"no":"yes") << endl;
     fout << endl;
     fout << "PositionSignal: " << h1.GetMaximumBin()-1 << endl;
     fout << "PositionFWHM:   " << fwhm1 << endl;
-    fout << "PositionAsym:   " << (asym1?"Yes":"No") << endl;
+    fout << "PositionAsym:   " << (asym1?"yes":"no") << endl;
     fout << endl;
     fout << "HeightSignal:   " << h2.GetMaximumBin()-1 << endl;
     fout << "HeightFWHM:     " << fwhm2 << endl;
-    fout << "HeightAsym:     " << (asym2?"Yes":"No") << endl;
+    fout << "HeightAsym:     " << (asym2?"yes":"no") << endl;
     fout << endl;
 
