Index: trunk/MagicSoft/Mars/automatic-exclusions.rc
===================================================================
--- trunk/MagicSoft/Mars/automatic-exclusions.rc	(revision 6933)
+++ trunk/MagicSoft/Mars/automatic-exclusions.rc	(revision 6933)
@@ -0,0 +1,95 @@
+#SpecialRunCond means, that the exclusion has to be done up to that
+#run# but not after that run#
+
+#NumEventsSmaller10:
+key15.Column: fNumEvents
+#key15.Join1: 
+#key15.Join2: 
+key15.Cond: fNumEvents between 2 and 9 
+#key15.SpecialRunCond: 
+
+#NumEventsSmaller2:
+key18.Column: fNumEvents
+#key18.Join1: 
+#key18.Join2: 
+key18.Cond: fNumEvents < 2 
+#key18.SpecialRunCond: 
+
+#ProjectLikeTest:
+key17.Join1: Project
+#key17.Join2: 
+key17.Cond: fProjectName like '%test%'
+#key17.SpecialRunCond: 
+
+#ProjectLikeClose:
+key4.Join1: Project
+#key4.Join2: 
+key4.Cond: fProjectName like '%close%' 
+#key4.SpecialRunCond: 
+
+#SourceLikePark:
+key12.Join1: Source
+#key12.Join2: 
+key12.Cond: fSourceName like '%park%'
+#key12.SpecialRunCond: 
+
+#SourceLikeDummy:
+key14.Join1: Source
+#key14.Join2: 
+key14.Cond: fSourceName like '%dummy%'
+#key14.SpecialRunCond: 
+
+#ProjectLikeDummy:
+key16.Join1: Project
+#key16.Join2: 
+key16.Cond: fProjectName like '%dummy%'
+#key16.SpecialRunCond: 
+
+#ProjectLikeCL:
+key3.Join1: Project
+key3.Join2: CalibrationScript
+key3.Cond: fProjectName like binary '%CL%' or fCalibrationScriptName='100_ContinuosLight' 
+#key3.SpecialRunCond: 
+
+#ProjectLikeFFweak:
+key23.Join1: Project
+key23.Join2: CalibrationScript
+key23.Cond: fProjectName like binary '%FFweak%' or fCalibrationScriptName='Flatfielding_weak' 
+#key23.SpecialRunCond: 
+
+#ProjectLikeMovetel:
+key20.Join1: Project
+#key20.Join2: 
+key20.Cond: fProjectName like binary 'movetel%' 
+#key20.SpecialRunCond: 
+
+#ProjectLikeCurtain:
+key10.Join1: Project
+#key10.Join2: 
+key10.Cond: fProjectName like '%curtain%' 
+#key10.SpecialRunCond: 
+
+#PedRunWithNoPedTT:
+key11.Join1: RunType
+key11.Join2: L2TriggerTable
+key11.Cond: fRunTypeName='pedestal' and not (fL2TriggerTableName='PED') 
+key11.SpecialRunCond: 35659
+
+#TriggerTableNA:
+key6.Join1: L2TriggerTable
+key6.Join2: L1TriggerTable
+key6.Cond: fL2TriggerTableName='n/a' and fL1TriggerTableName='n/a'
+#key6.SpecialRunCond: 
+
+#DataRunWithTTPed:
+key2.Join1: RunType
+key2.Join2: L2TriggerTable
+key2.Cond: fRunType='data' and fL2TriggerTableName='PED' 
+#key2.SpecialRunCond: 
+
+#DTTableAsTriggerDelay:
+key21.Join1: TriggerDelayTable
+#key21.Join2: DiscriminatorThresholdTable
+key21.Cond: fTriggerDelayTableName like 'thresh%' 
+#key21.SpecialRunCond: 
+
Index: trunk/MagicSoft/Mars/datacenter/macros/buildsequenceentries.C
===================================================================
--- trunk/MagicSoft/Mars/datacenter/macros/buildsequenceentries.C	(revision 6933)
+++ trunk/MagicSoft/Mars/datacenter/macros/buildsequenceentries.C	(revision 6933)
@@ -0,0 +1,590 @@
+/* ======================================================================== *\
+!
+! *
+! * 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, 08/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
+!   Author(s): Daniela Dorner, 08/2004 <mailto:dorner@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2004
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// buildsequenceentries.C
+// ======================
+//
+// to group the runs of one night into sequences, this marco:
+// - reads the runinformation of one night from the database
+// - sorts the runs by source
+// - groups the runs to sequences such that each run belongs
+//   to the nearest (in time) calibration run
+//
+// apart from that the runs in one sequence must have the same
+// hv-settings, trigger tables, light conditions, DT tables,
+// trigger delay tables and testflag
+//
+/////////////////////////////////////////////////////////////////////////////
+#include <iostream>
+#include <iomanip>
+#include <fstream>
+
+#include <MSQLServer.h>
+#include <TSQLRow.h>
+#include <TSQLResult.h>
+
+#include <TEnv.h>
+#include <TMath.h>
+#include <TExMap.h>
+#include <TArrayI.h>
+#include <TRegexp.h>
+#include <TSystem.h>
+
+#include <MTime.h>
+#include <MDirIter.h>
+
+using namespace std;
+
+int debug = 0;
+
+Bool_t DeleteSequences(MSQLServer &serv, TString cond)
+{
+    TString query(Form("SELECT fSequenceFirst FROM MyMagic.Sequences"
+                       " WHERE %s AND fManuallyChangedKEY=1", cond.Data()));
+
+    TSQLResult *res = serv.Query(query);
+    if (!res)
+        return kFALSE;
+
+    TSQLRow *row=0;
+    while ((row=res->Next()))
+    {
+        query = Form("DELETE FROM MyMagic.Calibration WHERE fSequenceFirst=%s", (*row)[0]);
+
+        TSQLResult *res = serv.Query(query);
+        if (!res)
+            return kFALSE;
+        delete res;
+
+        query = Form("DELETE FROM MyMagic.SequenceProcessStatus WHERE fSequenceFirst=%s", (*row)[0]);
+
+        res = serv.Query(query);
+        if (!res)
+            return kFALSE;
+        delete res;
+
+        Int_t sequno=atoi((*row)[0]);
+        TString fname(Form("/mnt/stk01/sequences/%04d/sequence%08d.txt", sequno/10000, sequno));
+        gSystem->Unlink(fname);
+
+        query = Form("UPDATE MyMagic.RunData SET fSequenceFirst=0 WHERE fSequenceFirst=%s", (*row)[0]);
+
+        res = serv.Query(query);
+        if (!res)
+            return kFALSE;
+        delete res;
+
+    }
+    delete res;
+
+    query = Form("DELETE FROM MyMagic.Sequences WHERE %s AND fManuallyChangedKEY=1", cond.Data());
+    res = serv.Query(query);
+    if (!res)
+        return kFALSE;
+
+    delete res;
+
+    return kTRUE;
+}
+
+Int_t CheckOverlap(MSQLServer &serv, Int_t from, Int_t to)
+{
+    TString query(Form("SELECT fSequenceFirst FROM MyMagic.Sequences WHERE"
+                       " (%d BETWEEN fSequenceFirst AND fSequenceLast) OR "
+                       " (%d BETWEEN fSequenceFirst AND fSequenceLast)", from, to));
+
+    TSQLResult *res = serv.Query(query);
+    if (!res)
+        return -1;
+
+    TSQLRow *row = res->Next();
+
+    Int_t rc = row ? kFALSE : kTRUE;
+    if (rc==kFALSE)
+        cout << "Sorry - the sequence from " << from << " to " << to << " overlaps with sequence #" << (*row)[0] << endl;
+
+    delete res;
+
+    return rc;
+}
+
+Int_t DoCheck(TSQLResult &res, Int_t from, Int_t to)
+{
+    TSQLRow *row=0;
+
+    TArrayI data(9);
+
+    Int_t n = 0;
+
+    while ((row=res.Next()))
+    {
+        n++;
+
+        if (data[0]==0)
+        {
+            for (int i=0; i<data.GetSize(); i++)
+                data[i] = atoi((*row)[i]);
+            continue;
+        }
+
+        for (int i=1; i<data.GetSize(); i++)
+        {
+            if (data[i] != atoi((*row)[i]))
+                return i+1;
+        }
+    }
+    return n==0 ? 0 : -1;
+}
+
+Bool_t CheckSequence(MSQLServer &serv, Int_t from, Int_t to, Int_t src, Int_t type)
+{
+    TString query("SELECT fRunNumber, fL1TriggerTableKEY, fL2TriggerTableKEY,"
+                  " fProjectKEY, fHvSettingsKEY, fDiscriminatorThresholdTableKEY,"
+                  " fTriggerDelayTableKEY, fLightConditionsKEY, fTestFlagKEY"
+                  " FROM MyMagic.RunData");
+    query += Form(" WHERE fRunTypeKEY=%d AND fSourceKEY=%d AND fExcludedFDAKEY=1 AND (fRunNumber BETWEEN %d AND %d)"
+                  " ORDER BY fRunNumber", type, src, from, to);
+
+    TSQLResult *res = serv.Query(query);
+    if (!res)
+        return kFALSE;
+
+    Int_t rc = DoCheck(*res, from, to);
+    delete res;
+
+    switch (rc)
+    {
+    case 0: cout << "ERROR - No runs found for check!"                        << endl; break;
+    case 1: cout << "ERROR - fRunNumber doesn't match!"                       << endl; break;
+    case 2: cout << "ERROR - fL1TriggerTableKEY doesn't match!"                 << endl; break;
+    case 3: cout << "ERROR - fL2TriggerTableKEY doesn't match!"                 << endl; break;
+    case 4: cout << "ERROR - fProjectKEY doesn't match!"                      << endl; break;
+    case 5: cout << "ERROR - fHvSettingsKEY doesn't match!"                   << endl; break;
+    case 6: cout << "ERROR - fDiscriminatorThresholdTableKEY doesn't match!"  << endl; break;
+    case 7: cout << "ERROR - fTriggerDelayTableKEY doesn't match!"            << endl; break;
+    case 8: cout << "ERROR - fLightConditionsKEY doesn't match!"              << endl; break;
+    case 9: cout << "ERROR - fTestFlagKEY doesn't match!"                     << endl; break;
+    }
+
+    return rc<0;
+}
+
+Bool_t InsertSequence(MSQLServer &serv, Int_t from, Int_t to, Int_t src, Bool_t dummy)
+{
+    Int_t rc = dummy ? kTRUE : CheckOverlap(serv, from, to);
+    if (rc<=0)
+        return kFALSE;
+
+    // ========== Request number of events ==========
+    TString query("SELECT SUM(fNumEvents), "
+                  " SUM(if(TIME_TO_SEC(fRunStop)-TIME_TO_SEC(fRunStart)<0,"
+                  "  TIME_TO_SEC(fRunStop)-TIME_TO_SEC(fRunStart)+24*60*60,"
+                  "  TIME_TO_SEC(fRunStop)-TIME_TO_SEC(fRunStart))), ");
+    query +=      " MIN(fZenithDistance), MAX(fZenithDistance), ";
+    query +=      " MIN(fAzimuth), MAX(fAzimuth) ";
+    query += Form(" FROM MyMagic.RunData"
+                  " WHERE fRunTypeKEY=2 AND fSourceKEY=%d AND (fRunNumber BETWEEN %d AND %d) AND fExcludedFDAKEY=1",
+                  src, from, to);
+
+    TSQLResult *res = serv.Query(query);
+    if (!res)
+        return kFALSE;
+
+    TSQLRow *row = res->Next();
+    if (!row || !(*row)[0])
+    {
+        cout << "ERROR - No result from query: " << query << endl;
+        return kFALSE;
+    }
+
+    TString nevts = (*row)[0];
+    TString secs  = (*row)[1];
+    TString zdmin = (*row)[2];
+    TString zdmax = (*row)[3];
+    TString azmin = (*row)[4];
+    TString azmax = (*row)[5];
+
+    delete res;
+
+    // ========== Request start time of sequence ==========
+    query = Form("SELECT fRunStart FROM MyMagic.RunData WHERE fRunNumber=%d AND fSourceKEY=%d AND fExcludedFDAKEY=1", from, src);
+
+    res = serv.Query(query);
+    if (!res)
+        return kFALSE;
+
+    row = res->Next();
+    if (!row || !(*row)[0])
+    {
+        cout << "ERROR - No result from query: " << query << endl;
+        return kFALSE;
+    }
+
+    TString start((*row)[0]);
+
+    delete res;
+
+    // ========== Request data of sequence ==========
+    query = Form("SELECT fProjectKEY, fL1TriggerTableKEY, fL1TriggerTableKEY,"
+                 " fHvSettingsKEY, fDiscriminatorThresholdTableKEY,"
+                 " fTriggerDelayTableKEY, fLightConditionsKEY, fTestFlagKEY"
+                 " FROM MyMagic.RunData"
+                 " WHERE fRunTypeKEY=2 AND fSourceKEY=%d AND fExcludedFDAKEY=1 AND (fRunNumber BETWEEN %d AND %d)"
+                 " LIMIT 1", src, from, to);
+
+    res = serv.Query(query);
+    if (!res)
+        return kFALSE;
+
+    row = res->Next();
+    if (!row)
+    {
+        cout << "ERROR - No result from query: " << query << endl;
+        return kFALSE;
+    }
+
+    TString query1 = Form("INSERT MyMagic.Sequences SET"
+                          " fSequenceFirst=%d,"
+                          " fSequenceLast=%d,"
+                          " fProjectKEY=%s,"
+                          " fSourceKEY=%d,"
+                          " fNumEvents=%s,"
+                          " fRunTime=%s,"
+                          " fRunStart=\"%s\","
+                          " fZenithDistanceMin=%s,"
+                          " fZenithDistanceMax=%s,"
+                          " fAzimuthMin=%s,"
+                          " fAzimuthMax=%s,"
+                          " fL1TriggerTableKEY=%s,"
+                          " fL2TriggerTableKEY=%s,"
+                          " fHvSettingsKEY=%s,"
+                          " fDiscriminatorThresholdTableKEY=%s,"
+                          " fTriggerDelayTableKEY=%s,"
+                          " fLightConditionsKEY=%s,"
+                          " fTestFlagKEY=%s,"
+                          " fManuallyChangedKEY=1",
+                          from, to, (*row)[0], src, nevts.Data(),
+                          secs.Data(), start.Data(), zdmin.Data(),
+                          zdmax.Data(), azmin.Data(), azmax.Data(),
+                          (*row)[1], (*row)[2], (*row)[3],
+                          (*row)[4], (*row)[5], (*row)[6],
+                          (*row)[7]);
+
+    TString query2 = Form("UPDATE MyMagic.RunData SET fSequenceFirst=%d WHERE"
+                          "  (fRunNumber  BETWEEN %d AND %d) AND"
+                          "  (fRunTypeKEY BETWEEN  2 AND  4) AND"
+                          "  fSourceKEY=%d AND fHvSettingsKEY=%s AND fExcludedFDAKEY=1",
+                          from, from, to, src, (*row)[3]);
+
+    TString query3 = Form("INSERT MyMagic.SequenceProcessStatus SET fSequenceFirst=%d ",
+                          from);
+    delete res;
+
+    if (dummy)
+        return kTRUE;
+
+    res = serv.Query(query1);
+    if (!res)
+        return kFALSE;
+    delete res;
+
+    res = serv.Query(query2);
+    if (!res)
+        return kFALSE;
+    delete res;
+
+    res = serv.Query(query3);
+    if (!res)
+        return kFALSE;
+    delete res;
+
+    return kTRUE;
+}
+
+Bool_t NewSequence(MSQLServer &serv, Int_t from, Int_t to, Int_t src, Bool_t dummy)
+{
+    cout << "Found Sequence (" << from << ", " << to << ") ... checking..." << flush;
+
+    if (!CheckSequence(serv, from, to, src, 2))
+    {
+        cout << "Warning - Found inconsistency in data-runs (" << from << ", " << to << ")" << endl;
+        //sequence is not built, but kTRUE is returned, to allow
+        //the automatic processing of the other sequences of this day
+        return kTRUE;
+    }
+    if (!CheckSequence(serv, from, to, src, 3))
+    {
+        cout << "Warning - Found inconsistency in ped-runs (" << from << ", " << to << ")" << endl;
+        //sequence is not built, but kTRUE is returned, to allow
+        //the automatic processing of the other sequences of this day
+        return kTRUE;
+    }
+
+    cout << "ok." << endl;
+
+    Bool_t rc = InsertSequence(serv, from, to, src, dummy);
+    if (!rc)
+        cout << "InsertSequence failed!" << endl;
+
+    return rc;
+}
+
+Bool_t GetSources(MSQLServer &serv, TString cond, TArrayI &srcs)
+{
+    TString query(Form("SELECT fSourceKEY"
+                       " FROM MyMagic.RunData"
+                       " WHERE %s AND fExcludedFDAKEY=1 AND (fRunTypeKEY BETWEEN 2 AND 4) GROUP BY fSourceKEY",
+                       cond.Data())
+                 ); //DATE(fStartTime)=\"2004-05-19\"");
+
+    TSQLResult *res = serv.Query(query);
+    if (!res)
+        return kFALSE;
+
+    srcs.Set(res->GetRowCount());
+
+    cout << "Found " << srcs.GetSize() << " sources." << endl << endl;
+
+    TSQLRow *row=0;
+    Int_t i=0;
+    while ((row=res->Next()))
+        srcs[i++] = atoi((*row)[0]);
+
+    delete res;
+    return kTRUE;
+}
+
+Bool_t Process(MSQLServer &serv, TString cond, Int_t src, Bool_t dummy)
+{
+    if (debug)
+        cout << "Processing Source: " << src << endl;
+
+    TString query(Form("SELECT fRunNumber, fRunTypeKEY, fRunStart, fRunStop"
+                       " FROM MyMagic.RunData"
+                       " WHERE %s AND fSourceKEY=%d AND fExcludedFDAKEY=1 AND"
+                       " (fRunTypeKEY BETWEEN 2 AND 4)"
+                       " ORDER BY fRunNumber", cond.Data(), src)
+                 ); //DATE(fStartTime)=\"2004-05-19\"");
+
+    TSQLResult *res = serv.Query(query);
+    if (!res)
+        return kFALSE;
+
+    TExMap map;
+
+    Int_t start=0;
+    Int_t stop=0;
+    Int_t last=0;
+    Int_t first=0;
+
+    MTime lasttime;
+
+    TSQLRow *row=0;
+
+    enum { UNKNOWN, PED=3, CAL=4, DATA=2 };
+    Char_t status = UNKNOWN;
+
+    Int_t nblocks = 0;
+
+    while ((row=res->Next()))
+    {
+        if (!(*row)[1])
+            continue;
+
+        if (start==0)
+        {
+            first = atoi((*row)[0]);
+            if (debug)
+                cout << "First Run: " << first << endl;
+        }
+
+        switch (atoi((*row)[1]))
+        {
+        case CAL: // ---------- CALIBRATION ----------
+            if (status!=CAL)
+            {
+                start = stop = atoi((*row)[0]);
+                if (!(*row)[2])
+                    cout << "No time available... skipped." << endl;
+                else
+                {
+                    MTime *tm = new MTime;
+                    tm->SetSqlDateTime((*row)[2]);
+                    map.Add((ULong_t)map.GetSize(), (Long_t)nblocks, (Long_t)tm);
+                }
+            }
+            status = CAL;
+            break;
+        default:
+            if (status==CAL)
+            {
+                MTime *tm = new MTime(lasttime);
+                map.Add((ULong_t)map.GetSize(), (Long_t)nblocks, (Long_t)tm);
+
+                stop = last;
+                nblocks++;
+                if (debug)
+                    cout << "Cal Block #" << nblocks << " from " << start << " to " << last << endl;
+            }
+            status = UNKNOWN;
+            break;
+        }
+        last = atoi((*row)[0]);
+        lasttime.SetSqlDateTime((*row)[3]);
+    }
+    if (status==CAL)
+    {
+        stop = last;
+        nblocks++;
+        if (debug)
+            cout << "Cal Block #" << nblocks << " from " << start << " to " << stop << endl;
+    }
+
+    if (debug)
+        cout << "Last Run: " << last << endl;
+    delete res;
+
+    if (debug)
+        cout << "Found " << nblocks << " calibration blocks" << endl;
+
+    res = serv.Query(query);
+    if (!res)
+        return kFALSE;
+
+    Int_t n = -1;
+
+    Bool_t rc = kTRUE;
+
+    start = first;
+    while ((row=res->Next()))
+    {
+        if (!(*row)[1])
+            continue;
+
+        MTime tstart, tstop;
+        tstart.SetSqlDateTime((*row)[2]);
+        tstop.SetSqlDateTime((*row)[3]);
+
+        MTime    min;
+        Int_t    nmin = -1;
+        Double_t dmin = 1e35;
+
+        Long_t key, val;
+        TExMapIter nmap(&map);
+        while (nmap.Next(key, val))
+        {
+            MTime *t = (MTime*)val;
+
+            if (nmin==-1)
+            {
+                nmin = key;
+                min  = *(MTime*)val;
+                dmin = fabs((Double_t)*t-(Double_t)tstart);
+            }
+
+            if (fabs((Double_t)*t-(Double_t)tstart) < dmin)
+            {
+                nmin = key;
+                dmin = fabs((Double_t)*t-(Double_t)tstart);
+                min = *t;
+            }
+            if (fabs((Double_t)*t-(Double_t)tstop) < dmin)
+            {
+                nmin = key;
+                dmin = fabs((Double_t)*t-(Double_t)tstop);
+                min = *t;
+            }
+        }
+
+        if (n!=nmin)
+        {
+            if (n!=-1)
+            {
+                if (!NewSequence(serv, start, last, src, dummy))
+                {
+                    rc = kFALSE;
+                    //continue;
+                }
+            }
+            n = nmin;
+            start = atoi((*row)[0]);
+        }
+        last = atoi((*row)[0]);
+    }
+
+    delete res;
+
+    if (n!=-1 && start!=last)
+    {
+        if (!NewSequence(serv, start, last, src, dummy))
+            rc = kFALSE;
+    }
+
+    if (debug)
+        cout << endl;
+
+    return rc; 
+}
+
+// This tool will work from Period017 (2004_05_17) on...
+int buildsequenceentries(TString day, Bool_t dummy=kTRUE)
+{
+    TEnv env("sql.rc");
+
+    MSQLServer serv(env);
+    if (!serv.IsConnected())
+    {
+        cout << "ERROR - Connection to database failed." << endl;
+        return 0;
+    }
+
+    cout << "buildsequences" << endl;
+    cout << "--------------" << endl;
+    cout << endl;
+    cout << "Connected to " << serv.GetName() << endl;
+    cout << "Night of sunrise at: " << day << endl;
+    cout << endl;
+
+    day += " 13:00:00";
+    const TString cond(Form("(fRunStart>ADDDATE(\"%s\", INTERVAL -1 DAY) AND fRunStart<\"%s\")",
+                            day.Data(), day.Data()));
+
+    if (!dummy && !DeleteSequences(serv, cond))
+        return 0;
+
+    Bool_t rc = kTRUE;
+
+    // get all sources for this day
+    TArrayI src;
+    GetSources(serv, cond, src);
+    // find and build the sequences for the day for each source
+    for (int i=0; i<src.GetSize(); i++)
+        if (!Process(serv, cond, src[i], dummy))
+            rc = kFALSE;
+
+    return rc ? 1 : 0;
+}
Index: trunk/MagicSoft/Mars/datacenter/macros/checkfileavail.C
===================================================================
--- trunk/MagicSoft/Mars/datacenter/macros/checkfileavail.C	(revision 6933)
+++ trunk/MagicSoft/Mars/datacenter/macros/checkfileavail.C	(revision 6933)
@@ -0,0 +1,115 @@
+/* ======================================================================== *\
+!
+! *
+! * 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): Daniela Dorner, 01/2005 <mailto:dorner@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2005
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// checkfileavail.C
+// ================
+//
+/////////////////////////////////////////////////////////////////////////////
+
+#include <iostream>
+#include <iomanip>
+#include <fstream>
+
+#include <TEnv.h>
+
+#include <MSQLServer.h>
+#include <TSQLRow.h>
+#include <TSQLResult.h>
+
+using namespace std;
+
+
+TString GetStatus(MSQLServer &serv, TEnv &rc, TString primary, TString table, TString column)
+{
+    TString query(Form("SELECT %s FROM MyMagic.%s WHERE %s=%s",
+                       column.Data(), table.Data(),
+                       rc.GetValue(table+".Primary", ""),
+                       primary.Data()));
+
+    cout << "Query: " << query << endl;
+
+    TSQLResult *res = serv.Query(query);
+    if (!res)
+    {
+        cout << "Error - no run to check" << endl;
+        return "";
+    }
+
+    TSQLRow *row=0;
+    while ((row = res->Next()))
+    {
+//        TString entry=(*row)[0];
+//        if (entry=="1970-01-01 00:00:00")
+//            return "";
+        return (*row)[0];
+    }
+
+    return "";
+}
+
+int checkfileavail(TString sequenceno)
+{
+    TEnv env("sql.rc");
+
+    MSQLServer serv(env);
+    if (!serv.IsConnected())
+    {
+        cout << "ERROR - Connection to database failed." << endl;
+        return 0;
+    }
+    cout << "checkfileavail" << endl;
+    cout << "--------------" << endl;
+    cout << endl;
+    cout << "Connected to " << serv.GetName() << endl;
+    cout << endl;
+
+    TEnv rc("steps.rc");
+
+    cout << "sequ: " << sequenceno.Data() << endl;
+    TString query(Form("SELECT fRunNumber FROM MyMagic.RunData WHERE fSequenceFirst=%s",
+                       sequenceno.Data()));
+
+    TSQLResult *res = serv.Query(query);
+    if (!res)
+        cout << "Error - no run to check" << endl;
+
+    TSQLRow *row=0;
+    while ((row = res->Next()))
+    {
+        TString runno=(*row)[0];
+        cout << "run#: " << runno << endl;
+        if (GetStatus(serv, rc, runno, "RunProcessStatus", "fCCFileAvail")==""
+            || GetStatus(serv, rc, runno, "RunProcessStatus", "fCaCoFileAvail")==""
+            || GetStatus(serv, rc, runno, "RunProcessStatus", "fCaCoFileFound")==""
+            || GetStatus(serv, rc, runno, "RunProcessStatus", "fTimingCorrection")==""
+//            || GetStatus(serv, rc, runno, "RunProcessStatus", "fTimingCorrection")=="1970-01-01 00:00:00"
+            || GetStatus(serv, rc, runno, "RunProcessStatus", "fRawFileAvail")=="")
+            return 0;
+    }
+    return 1;
+
+}
+
Index: trunk/MagicSoft/Mars/datacenter/macros/doexclusions.C
===================================================================
--- trunk/MagicSoft/Mars/datacenter/macros/doexclusions.C	(revision 6933)
+++ trunk/MagicSoft/Mars/datacenter/macros/doexclusions.C	(revision 6933)
@@ -0,0 +1,202 @@
+/* ======================================================================== *\
+!
+! *
+! * 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, 08/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
+!   Author(s): Daniela Dorner, 08/2004 <mailto:dorner@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2004
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// doexclusions.C
+// ==============
+//
+/////////////////////////////////////////////////////////////////////////////
+#include <iostream>
+#include <iomanip>
+#include <fstream>
+
+#include <MSQLServer.h>
+#include <TSQLRow.h>
+#include <TSQLResult.h>
+
+#include <TEnv.h>
+#include <TSystem.h>
+
+using namespace std;
+
+int GetRunNumber(MSQLServer &serv, TString date, TString value)
+{
+    TString query(Form("SELECT %s(fRunNumber) FROM MyMagic.RunData ", value.Data()));
+
+    if (date!="NULL")
+    {
+        TString day=date+" 13:00:00";
+        query+=Form(" WHERE (fRunStart>ADDDATE(\"%s\", INTERVAL -1 DAY) AND fRunStart<\"%s\")",
+                    day.Data(), day.Data());
+    }
+
+    cout << "query: " << query << endl;
+
+    TSQLResult *res = serv.Query(query);
+    if (!res)
+    {
+        cout << "Error - could not get run#" << endl;
+        return -1;
+    }
+
+    TSQLRow *row =res->Next();
+    cout << (void*)row << endl;
+    if (TString((*row)[0]).IsNull())
+    {
+        cout << "No run available for this date" << endl;
+        delete res;
+        return 0;
+    }
+    delete res;
+    return atoi((*row)[0]);
+}
+
+TString GetJoin(TString table)
+{
+    TString query(Form("left join MyMagic.%s ON RunData.f%sKEY=%s.f%sKEY ",
+                       table.Data(), table.Data(), table.Data(), table.Data()));
+    return query;
+}
+
+int doexclusions(Int_t startrun, Int_t stoprun, TString date="NULL")
+{
+    TEnv env("sql.rc");
+    TEnv rc("automatic-exclusions.rc");
+
+    MSQLServer serv(env);
+    if (!serv.IsConnected())
+    {
+        cout << "ERROR - Connection to database failed." << endl;
+        return 0;
+    }
+
+    cout << "doexclusions" << endl;
+    cout << "------------" << endl;
+    cout << endl;
+    cout << "Connected to " << serv.GetName() << endl;
+
+    if (startrun==0 && stoprun==0)
+    {
+        startrun=GetRunNumber(serv, date, "min");
+        stoprun=GetRunNumber(serv, date, "max");
+    }
+    if (startrun<0 || stoprun<0)
+    {
+        cout << "wrong format of date" << endl;
+        return 0;
+    }
+    if (startrun==0 || stoprun==0)
+        return 1;
+
+    TString runcond(Form("AND fRunNumber BETWEEN %d AND %d ", startrun, stoprun));
+
+    TString query="SELECT fExcludedFDAKEY from MyMagic.ExcludedFDA where fExcludedFDAAutomatic='yes'";
+    TSQLResult *res = serv.Query(query);
+    if (!res)
+    {
+        cout << "Error - could not do any automatic excludes" << endl;
+        return 0;
+    }
+
+    TSQLRow *row=0;
+    while ((row = res->Next()))
+    {
+        TString key=(*row)[0];
+        TString column=rc.GetValue("key"+key+".Column", "");
+        TString join1=rc.GetValue("key"+key+".Join1", "");
+        TString join2=rc.GetValue("key"+key+".Join2", "");
+        TString border=rc.GetValue("key"+key+".SpecialRunCond", "");
+
+        TString query(Form("SELECT fExcludedFDAImportance from MyMagic.ExcludedFDA where fExcludedFDAKEY=%s ", key.Data()));
+        TSQLResult *res = serv.Query(query);
+        if (!res)
+        {
+            cout << "Error" << endl;
+            return 0;
+        }
+
+        TSQLRow *row2=res->Next();
+        Int_t newimp=atoi((*row2)[0]);
+        delete res;
+
+        query="SELECT fRunNumber, fExcludedFDAImportance ";
+        if (!column.IsNull())
+            query+=Form(", %s", column.Data());
+        if (!join1.IsNull())
+            query+=Form(", f%sName", join1.Data());
+        if (!join2.IsNull())
+            query+=Form(", f%sName", join2.Data());
+        query +=" FROM MyMagic.RunData ";
+        query +=GetJoin("ExcludedFDA");
+        if (!join1.IsNull())
+            query+=GetJoin(join1.Data());
+        if (!join2.IsNull())
+            query+=GetJoin(join2.Data());
+        query +=Form("WHERE %s ", rc.GetValue("key"+key+".Cond", ""));
+        if (!border.IsNull())
+            query+=Form(" AND fRunNumber BETWEEN IF(%s>%d, %d, %s) AND IF (%s<%d, %s, %d) ",
+                        border.Data(), startrun, startrun, border.Data(),
+                        border.Data(), stoprun, border.Data(), stoprun);
+        else
+            query +=runcond;
+
+        cout << query << endl;
+
+        res = serv.Query(query);
+        if (!res)
+        {
+            cout << "Error - no runs to exclude" << endl;
+            return 0;
+        }
+
+        while ((row2 = res->Next()))
+        {
+            if (TString((*row2)[1]).IsNull() || atoi((*row2)[1])>newimp)
+            {
+                TString query(Form("UPDATE MyMagic.RunData SET fExcludedFDAKEY=%s WHERE fRunNumber=%s",
+                                   key.Data(), (*row2)[0]));
+                cout << "QU: " << query << endl;
+                TSQLResult *res = serv.Query(query);
+                if (!res)
+                {
+                    cout << "Error - could not insert exclusion" << endl;
+                    return 0;
+                }
+                delete res;
+                continue;
+            }
+            cout << "run#: " << (*row2)[0] << " reason for exclusion is still the same" << endl;
+        }
+        delete res;
+    }
+    delete res;
+    return 1;
+}
+
+int doexclusions(TString date="NULL")
+{
+    return doexclusions(0, 0, date);
+}
Index: trunk/MagicSoft/Mars/datacenter/macros/fillcalib.C
===================================================================
--- trunk/MagicSoft/Mars/datacenter/macros/fillcalib.C	(revision 6933)
+++ trunk/MagicSoft/Mars/datacenter/macros/fillcalib.C	(revision 6933)
@@ -0,0 +1,172 @@
+/* ======================================================================== *\
+!
+! *
+! * 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, 08/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
+!   Author(s): Daniela Dorner, 08/2004 <mailto:dorner@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2004
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// fillcalib.C
+// ===========
+//
+// This macro is used to read the calibartion-/callisto-output files.
+// These files are automatically called calib00000.root.
+//
+// From this file the MBadPixelsCam and the MGeomCam is extracted. If
+// the geometry isn't found MGeomCamMagic is used as a default.
+//
+// Usage:
+//   .x fillcalib.C("/data/MAGIC/Period014/calib00000.root", 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.
+//
+// The corresponding sequence number is extracted from the filename...
+// FIXME: MSeqeuence should be stored in the calib-file?
+//
+// The macro can also be run without ACLiC but this is a lot slower...
+//
+// Remark: Running it from the commandline looks like this:
+//   root -q -l -b fillcalib.C+\(\"filename\"\,kFALSE\) 2>&1 | tee fillcalib.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 "MSQLServer.h"
+
+#include "MGeomCamMagic.h"
+#include "MBadPixelsCam.h"
+
+using namespace std;
+
+int Process(MSQLServer &serv, TString fname, Bool_t dummy)
+{
+    MBadPixelsCam badpix;
+
+    TFile file(fname, "READ");
+    if (badpix.Read("MBadPixelsCam")<=0)
+    {
+        cout << "ERROR - Reading of MBadPixelsCam failed." << endl;
+        return 0;
+    }
+
+    MGeomCamMagic def;
+
+    MGeomCam *geom = (MGeomCam*)file.Get("MGeomCam");
+    if (!geom)
+    {
+        cout << "WARNING - Reading of MGeomCam failed... using default <MGeomCamMagic>" << endl;
+        geom = &def;
+    }
+
+    cout << "Camera Geometry: " << geom->ClassName() << endl;
+
+    const Short_t unsin  = badpix.GetNumUnsuitable(MBadPixelsPix::kUnsuitableRun, geom, 0);
+    const Short_t unsout = badpix.GetNumUnsuitable(MBadPixelsPix::kUnsuitableRun, geom, 1);
+
+    const Short_t unrin  = badpix.GetNumUnsuitable(MBadPixelsPix::kUnreliableRun, geom, 0);
+    const Short_t unrout = badpix.GetNumUnsuitable(MBadPixelsPix::kUnreliableRun, geom, 1);
+
+    const Short_t isoin  = badpix.GetNumIsolated(*geom, 0);
+    const Short_t isoout = badpix.GetNumIsolated(*geom, 1);
+
+    const Short_t clumax = badpix.GetNumMaxCluster(*geom);
+
+    if (unsin<0 || unsout<0 || unrin<0 || unrout<0 || isoin<0 || isoout<0 || clumax<0)
+        return 0;
+
+    //     MHCamera hist(geom);
+    //     hist.SetCamContent(badpix, 1);
+    //     hist.DrawCopy();
+    //     hist.SetCamContent(badpix, 3);
+    //     hist.DrawCopy();
+
+    TString sequence = fname(TRegexp("calib[0-9]+[.]root$"));
+    if (sequence.IsNull())
+        return 0;
+
+    Int_t seq = atoi(sequence.Data()+5);
+
+    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: (i/o)  " << Form("%3d", (int)clumax) << endl;                 // Max Cluster
+
+    if (dummy)
+        return 0;
+
+    TString query = Form("INSERT MyMagic.Calibration SET"
+                         " fSequenceFirst=%d,"
+                         " fUnsuitableInner=%d, "
+                         " fUnsuitableOuter=%d, "
+                         " fUnreliableInner=%d, "
+                         " fUnreliableOuter=%d, "
+                         " fIsolatedInner=%d, "
+                         " fIsolatedOuter=%d, "
+                         " fIsolatedMaxCluster=%d",
+                         seq, (int)unsin, (int)unsout, (int)unrin,
+                         (int)unrout, (int)isoin, (int)isoout, (int)clumax);
+
+
+    TSQLResult *res = serv.Query(query);
+    if (!res)
+    {
+        cout << "ERROR - Query failed: " << query << endl;
+        return 0;
+    }
+
+    return 1;
+}
+
+int fillcalib(TString fname, Bool_t dummy=kTRUE)
+{
+    TEnv env("sql.rc");
+
+    MSQLServer serv(env);
+    if (!serv.IsConnected())
+    {
+        cout << "ERROR - Connection to database failed." << endl;
+        return 0;
+    }
+
+    cout << "fillcalib" << endl;
+    cout << "---------" << endl;
+    cout << endl;
+    cout << "Connected to " << serv.GetName() << endl;
+    cout << "File: " << fname << endl;
+    cout << endl;
+
+    return Process(serv, fname, dummy);
+}
Index: trunk/MagicSoft/Mars/datacenter/macros/filldotrbk.C
===================================================================
--- trunk/MagicSoft/Mars/datacenter/macros/filldotrbk.C	(revision 6933)
+++ trunk/MagicSoft/Mars/datacenter/macros/filldotrbk.C	(revision 6933)
@@ -0,0 +1,237 @@
+/* ======================================================================== *\
+!
+! *
+! * 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, 08/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2004
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// filldotrbk.C
+// ============
+//
+// This macro is used to read the central control runbook files from
+// the data center and store their contents in the runbook-database.
+//
+// Usage:
+//   .x filldotrbk.C("/data/MAGIC/Period014", kTRUE)
+//
+// While the first argument is the directory in which all subdirectories where
+// searches for CC_*.rbk files. All these files were analysed and the runbook
+// entries will be put into the DB, eg:
+//   "/data/MAGIC"                              would do it for all data
+//   "/data/MAGIC/Period019/ccdata"             would do it for one Period
+//   "/data/MAGIC/Period019/ccdata/2004_05_17"  would do it for a single day
+//   "/data/MAGIC/Period019/ccdata/file.rbk"    would do it for a single file
+//
+// 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.
+//
+// Before an antry is added its existance is checked... if it is added already
+// it is ignored.
+//
+// The macro can also be run without ACLiC but this is a lot slower...
+//
+// Remark: Running it from the commandline looks like this:
+//   root -q -l -b filldotrbk.C+\(\"path\"\,kFALSE\) 2>&1 | tee filldotrbk.log
+//
+// Make sure, that database and password are corretly set in the macro.
+//
+// Returns 0 in case of failure and 1 in case of success.
+//
+///////////////////////////////////////////////////////////////////////////
+#include <iostream>
+#include <iomanip>
+#include <fstream>
+
+#include <TEnv.h>
+#include <TRegexp.h>
+
+#include <TSQLRow.h>
+#include <TSQLResult.h>
+
+#include "MDirIter.h"
+#include "MSQLServer.h"
+
+using namespace std;
+
+// --------------------------------------------------------------------------
+//
+// Checks whether an entry for this date is already existing
+//
+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)
+        return kFALSE;
+
+    TSQLRow *row;
+
+    Bool_t rc = kFALSE;
+    while ((row=res->Next()))
+    {
+        if ((*row)[0])
+        {
+            rc = kTRUE;
+            break;
+        }
+    }
+
+    delete res;
+
+    return rc;
+}
+
+int insert(MSQLServer &serv, Bool_t dummy, TString entry, TString date)
+{
+
+    if (ExistStr(serv, "fRunBookDate", "MyMagic.RunBook", date))
+        return 0;
+
+    entry.ReplaceAll("'", "\\'");
+    entry.ReplaceAll("\"", "\\\"");
+
+    // This is a sanity check for \0-bytes in .rbk-files
+    for (int i=0; i<entry.Length(); i++)
+        if ((int)entry[i]==0)
+            entry.Remove(i--);
+
+    TString query("INSERT MyMagic.RunBook (fRunBookDate, fRunBookText) VALUES (\"");
+    query += date;
+    query += "\", \"";
+    query += entry;
+    query += "\");";
+
+    if (dummy)
+        return 1;
+
+    TSQLResult *res = serv.Query(query);
+    if (!res)
+        return 0;
+
+    delete res;
+
+    return 1;
+}
+
+// --------------------------------------------------------------------------
+//
+// insert the entries from this runbook file into the database
+//
+int process(MSQLServer &serv, Bool_t dummy, TString fname)
+{
+    ifstream fin(fname);
+    if (!fin)
+    {
+        cout << "Could not open file " << fname << endl;
+        return 0;
+    }
+
+    TRegexp regexp("^.20[0-9][0-9]-[0-1][0-9]-[0-3][0-9] [0-2][0-9]:[0-5][0-9]:[0-5][0-9].$", kFALSE);
+
+    Int_t num=0;
+
+    TString entry="";
+    TString date="";
+    while (1)
+    {
+        TString line;
+        line.ReadLine(fin);
+        if (!fin)
+        {
+            num += insert(serv, dummy, entry, date);
+            break;
+        }
+
+        TString l0 = line(regexp);
+
+        if (l0.IsNull() || entry.IsNull())
+        {
+            entry += line;
+            entry += "\n";
+            continue;
+        }
+/*
+        if (entry.Contains("Operator names: "))
+        {
+            cout << "OPERATORS: " << entry << flush;
+            entry="";
+        }
+*/
+        if (entry.Contains("MAGIC ELECTRONIC RUNBOOK")   ||
+            entry.Contains("DATA RUN STATISTICS")        ||
+            entry.Contains("CALIBRATION RUN STATISTICS") ||
+            entry.Contains("PEDESTAL RUN STATISTICS"))
+            entry ="";
+
+        if (!entry.IsNull() && !date.IsNull())
+            num += insert(serv, dummy, entry, date);
+
+        date=l0(1, l0.Length()-2);
+        entry="";
+    }
+
+    cout << fname(TRegexp("CC_.*.rbk", kFALSE)) << " <" << num << ">";
+    cout << (dummy?" DUMMY":"") << endl;
+
+    return 1;
+}
+
+// --------------------------------------------------------------------------
+//
+// loop over all files in this path
+//
+int filldotrbk(TString path="/data/MAGIC/Period017/ccdata", Bool_t dummy=kTRUE)
+{
+    TEnv env("sql.rc");
+
+    MSQLServer serv(env);
+    if (!serv.IsConnected())
+    {
+        cout << "ERROR - Connection to database failed." << endl;
+        return 0;
+    }
+
+    cout << endl;
+    cout << "filldotrbk" << endl;
+    cout << "----------" << endl;
+    cout << endl;
+    cout << "Connected to " << serv.GetName() << endl;
+    cout << "Search Path: " << path << endl;
+    cout << endl;
+
+    if (path.EndsWith(".rbk"))
+        return process(serv, dummy, path);
+
+    MDirIter Next(path, "CC_*.rbk", -1);
+    while (1)
+    {
+        TString name = Next();
+        if (name.IsNull())
+            break;
+
+        if (!process(serv, dummy, name))
+            return 0;
+    }
+
+    return 1;
+}
Index: trunk/MagicSoft/Mars/datacenter/macros/filldotrun.C
===================================================================
--- trunk/MagicSoft/Mars/datacenter/macros/filldotrun.C	(revision 6933)
+++ trunk/MagicSoft/Mars/datacenter/macros/filldotrun.C	(revision 6933)
@@ -0,0 +1,627 @@
+/* ======================================================================== *\
+!
+! *
+! * 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): Daniela Dorner, 08/2004 <mailto:dorner@astro.uni-wuerzburg.de>
+!   Author(s): Thomas Bretz, 08/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2004
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// filldotrun.C
+// ============
+//
+// This macro is used in the datacenter to automatically fill the run-database
+// with the information stored in the .run-files written by the central
+// control.
+//
+// To following Arehucas versions are Currently supported:
+//   040505-0, 040514-0,
+//   040518-0, 040727-0,
+//   041113-0, 041209-0, 041221-0
+//
+// Usage:
+//    .x filldotrun.C+("/data/MAGIC/Period019/ccdata", kTRUE)
+//
+// While the first argument is the directory in which all subdirectories where
+// searches for CC_*.run files. All these files were analysed and the run
+// info will be put into the DB, eg:
+//   "/data/MAGIC"                              would do it for all data
+//   "/data/MAGIC/Period019/ccdata"             would do it for one Period
+//   "/data/MAGIC/Period019/ccdata/2004_05_17"  would do it for a single day
+//   "/data/MAGIC/Period019/ccdata/file.run"    would do it for a single file
+//
+// The second argument is the 'dummy-mode'. If it is kTRUE dummy-mode is
+// switched on and nothing will be written into the database. Instead
+// informations about the subtables are displayed. This is usefull for tests
+// when adding a new arehucas version support. If it is kFALSE the information
+// are written into the subtables and the runs info is written into the
+// rundatabase.
+//
+// In the automatic case it makes sense to check the logfiles to make sure
+// that everything is fine...
+//
+// Make sure, that database and password are corretly set in a resource
+// file called sql.rc and the resource file is found.
+//
+// Remark: Running it from the commandline looks like this:
+//   root -q -l -b filldotrun.C+\(\"path\"\,kFALSE\) 2>&1 | tee filldotrun.log
+//
+// Returns 0 in case of failure and 1 in case of success.
+//
+/////////////////////////////////////////////////////////////////////////////
+#include <iostream>
+#include <iomanip>
+#include <fstream>
+
+#include <TEnv.h>
+#include <TMath.h>
+#include <TRegexp.h>
+
+#include <TSQLRow.h>
+#include <TSQLResult.h>
+
+#include "MTime.h"
+#include "MDirIter.h"
+#include "MSQLServer.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)
+        return kFALSE;
+
+    Bool_t rc = kFALSE;
+
+    TSQLRow *row=res->Next();
+    if (row && (*row)[0])
+        rc=kTRUE;
+
+    delete res;
+    return rc;
+}
+
+Int_t QueryNameKEY(MSQLServer &serv, Bool_t dummy, const char *col, const char *name, Bool_t insert=kTRUE)
+{
+    TString query;
+
+    query = Form("SELECT f%sKEY FROM MyMagic.%s WHERE f%sName='%s'", col, col, col, name);
+    TSQLResult *res = serv.Query(query);
+    if (!res)
+        return -1;
+
+    TSQLRow *row=res->Next();
+
+    Int_t rc = row && (*row)[0] ? atoi((*row)[0]) : -1;
+
+    delete res;
+
+    if (rc>=0)
+        return rc;
+
+    if (!insert)
+        return -1;
+
+    query = Form("INSERT MyMagic.%s (f%sName) VALUES (\"%s\");", col, col, name);
+
+    if (dummy)
+    {
+        cout << query << endl;
+        return 0;
+    }
+
+    res=serv.Query(query);
+    if (!res)
+        return -1;
+
+    delete res;
+
+    Int_t key = QueryNameKEY(serv, dummy, col, name, kFALSE);
+    if (key>0)
+    {
+        cout << "New " << col << ": " << name << endl;
+        return key;
+    }
+
+    cout << "ERROR: " << query << endl;
+    return kFALSE;
+}
+
+
+Int_t insert(MSQLServer &serv, Bool_t dummy, TString filename)
+{
+    ifstream fin(filename);
+    if (!fin)
+    {
+        cout << "Could not open file " << filename << endl;
+        return -1;
+    }
+
+    TString strng;
+    strng.ReadLine(fin);
+    if (strng!=TString("[CC Plain Run Summary File]"))
+    {
+        cout << filename << ": No Plain Run Summary File" << endl;
+        cout << "First Line: " << strng << endl;
+        cout << endl;
+        return -1;
+    }
+
+    strng.ReadLine(fin);
+    TRegexp reg("[0-9][0-9][0-9][0-9][0-9][0-9]-[0-9]");
+    TString arehucas = strng(reg);
+    arehucas.Prepend("20");
+    arehucas.ReplaceAll("-", "");
+
+    Int_t version = atoi(arehucas.Data());
+    if (version!=200405050 && version!=200405140 && version!=200405180
+        && version!=200407270 && version!=200411130 &&
+        version!=200412090 && version!=200412210 &&
+        version!=200503220 && version!=200504010)
+    {
+        cout << filename << ": File Version unknown - please update the macro!" << endl;
+        cout << "Second Line: " << strng << endl;
+        cout << endl;
+        return -1;
+    }
+
+    cout << "  V" << version << " " << flush;
+
+    Int_t cnt=0;
+    while (1)
+    {
+        // ========== Col 1: Run Number =========
+        //Reading the line
+        //and converting some strings to ints/floats
+        strng.ReadToDelim(fin, ' ');
+        if (!fin)
+            break;
+
+        Int_t runnumber = atoi(strng.Data());
+
+        //runnumber=0 means no valid dataset
+        //-> continue
+        if (runnumber == 0)
+        {
+            strng.ReadLine(fin);
+            cout << "Runnumber == 0" << endl;
+            continue;
+        }
+
+        //cout << "RunNo: " << runnumber << " ";
+
+        if (ExistStr(serv, "fRunNumber", "MyMagic.RunData", strng.Data()))
+        {
+            // FIXME: Maybe we can implement an switch to update mode?
+            cout << "Run #" << runnumber << " already existing... skipped." << endl;
+            strng.ReadLine(fin);
+            continue;
+        }
+
+        // ========== Col 2: Run Type =========
+        strng.ReadToDelim(fin, ' ');
+        if (strng.Contains("???"))
+            strng="n/a";
+
+        Int_t runtype = QueryNameKEY(serv, dummy, "RunType", strng.Data(), kFALSE);
+        if (runtype<0)
+        {
+            cout << "ERROR - RunType " << strng << " not available." << endl;
+            strng.ReadLine(fin);
+            continue;
+        }
+
+        //cout << runtype << " ";
+
+        // ========== Col 3,4: Start Time =========
+        TString startdate, starttime;
+        startdate.ReadToDelim(fin, ' ');
+        starttime.ReadToDelim(fin, ' ');
+        //cout << startdate << " " << starttime << " ";
+
+        // ========== Col 5,6: Stop Time =========
+        TString stopdate, stoptime;
+        stopdate.ReadToDelim(fin, ' ');
+        stoptime.ReadToDelim(fin, ' ');
+        //cout << stopdate << " " << stoptime << " ";
+
+        if (startdate.Contains("???"))
+            startdate="0000-00-00";
+        if (starttime.Contains("???"))
+            starttime="00:00:00";
+        if (stopdate.Contains("???"))
+            stopdate="0000-00-00";
+        if (stoptime.Contains("???"))
+            stoptime="00:00:00";
+
+        // ========== Col 7: Source Name =========
+        strng.ReadToDelim(fin, ' ');
+        if (strng.Contains("???"))
+            strng="Unavailable";
+
+        Int_t sourcekey = QueryNameKEY(serv, dummy, "Source", strng.Data());
+        if (sourcekey<0)
+        {
+            strng.ReadLine(fin);
+            continue;
+        }
+        //cout << sourcekey << " ";
+
+        // ========== Col 8,9: Local source position =========
+        strng.ReadToDelim(fin, ' ');
+        Float_t zd = atof(strng.Data());
+
+        strng.ReadToDelim(fin, ' ');
+        Float_t az = atof(strng.Data());
+
+        //cout << zd << " " << az << " ";
+
+        // ========== Col 10: Number of Events =========
+        strng.ReadToDelim(fin, ' ');
+        Int_t evtno = atoi(strng.Data());
+
+        //cout << evtno << " ";
+
+        // ========== Col 11: Project Name =========
+        strng.ReadToDelim(fin, ' ');
+        if (strng.Contains("???"))
+            strng="Unavailable";
+
+        Int_t projkey = QueryNameKEY(serv, dummy, "Project", strng.Data());
+        if (projkey<0)
+        {
+            strng.ReadLine(fin);
+            continue;
+        }
+        //cout << projkey << " ";
+
+        // ========== Col 12: Trigger Table Name =========
+        // starting from version 200411130: Col 12,13: Trigger Table Name =========
+        strng.ReadToDelim(fin, ' ');
+        if (strng.Contains("???"))
+            strng="n/a";
+
+        Int_t l1triggerkey=1;
+        Int_t l2triggerkey=1;
+        if (version >=200411130)
+        {
+            l1triggerkey = QueryNameKEY(serv, dummy, "L1TriggerTable", strng.Data());
+            if (l1triggerkey<0)
+            {
+                strng.ReadLine(fin);
+                continue;
+            }
+
+            strng.ReadToDelim(fin, ' ');
+            if (strng.Contains("???"))
+                strng="n/a";
+
+            l2triggerkey = QueryNameKEY(serv, dummy, "L2TriggerTable", strng.Data());
+            if (l2triggerkey<0)
+            {
+                strng.ReadLine(fin);
+                continue;
+            }
+        }
+        else
+        {
+            Int_t c=0;
+
+            if (strng.Contains(":"))
+                c=1;
+
+            if (strng.Contains("L1_") && !(strng.Contains(":")))
+                c=2;
+
+            if (strng.Contains("n/a"))
+                c=3;
+
+            switch (c)
+            {
+            case 0:
+                {
+                    l2triggerkey = QueryNameKEY(serv, dummy, "L2TriggerTable", strng.Data());
+                    if (l2triggerkey<0)
+                    {
+                        strng.ReadLine(fin);
+                        continue;
+                    }
+
+                    strng="n/a";
+                    l1triggerkey = 1;
+
+                    break;
+                }
+            case 1:
+                {
+                    TString L1TT, L2TT;
+                    L2TT=strng(7,12);
+                    L1TT=strng(0,6);
+
+                    l1triggerkey = QueryNameKEY(serv, dummy, "L1TriggerTable", L1TT.Data());
+                    if (l1triggerkey<0)
+                    {
+                        strng.ReadLine(fin);
+                        continue;
+                    }
+
+                    l2triggerkey = QueryNameKEY(serv, dummy, "L2TriggerTable", L2TT.Data());
+                    if (l2triggerkey<0)
+                    {
+                        strng.ReadLine(fin);
+                        continue;
+                    }
+
+                    break;
+                }
+            case 2:
+                {
+                    l1triggerkey = QueryNameKEY(serv, dummy, "L1TriggerTable", strng.Data());
+                    if (l1triggerkey<0)
+                    {
+                        strng.ReadLine(fin);
+                        continue;
+                    }
+
+                    strng="n/a";
+                    l2triggerkey = 1;
+
+                    break;
+                }
+            case 3:
+                {
+                    l1triggerkey = 1;
+                    l2triggerkey = 1;
+                    break;
+                }
+            default:
+                {
+                    cout << "WARNING: neiter L1 nor L2 Trigger table - please check what is happening." << strng << endl;
+                    break;
+                }
+            }
+        }
+
+        // ========== Col 13-15: TrigRate, L2 UnPresc Rate, L2 Presc Rate ==========
+        strng.ReadToDelim(fin, ' ');
+        Float_t trigrate = atof(strng.Data());
+
+        strng.ReadToDelim(fin, ' ');
+        Float_t l2uprate = atof(strng.Data());
+
+        strng.ReadToDelim(fin, ' ');
+        Float_t l2prrate = atof(strng.Data());
+
+        // ========== Col 16,17: DaqRate, Storage Rate ==========
+        strng.ReadToDelim(fin, ' ');
+        Float_t daqrate = atof(strng.Data());
+
+        strng.ReadToDelim(fin, ' ');
+        Float_t storerate = atof(strng.Data());
+
+        // ========== Col 18: HV table =========
+        if (version==200405050 || version==200405140)
+            strng.ReadToDelim(fin, '\n');
+        else
+            strng.ReadToDelim(fin, ' ');
+        if (strng.Contains("???"))
+            strng="n/a";
+
+        Int_t hvkey = QueryNameKEY(serv, dummy, "HvSettings", strng.Data());
+        if (hvkey<0)
+        {
+            //strng.ReadLine(fin);
+            continue;
+        }
+
+        if (version==200405180 || version==200407270)
+            strng.ReadLine(fin);
+
+        Int_t testflagkey=1;
+        Int_t lightcondkey=1;
+        Int_t dttablekey=1;
+        Int_t triggerdelaytablekey=1;
+        Int_t calibrationscriptkey=1;
+        if (version==200411130 || version==200412090 || version==200412210
+            || version==200503220 || version==200504010)
+        {
+            // ========== Col 19-35: DC and HV-values, mjd =========
+            for (int i=0 ; i<17 ; i++)
+            {
+                strng.ReadToDelim(fin, ' ');
+            }
+
+            // ========== Col 36: test-flag =========
+            strng.ReadToDelim(fin, ' ');
+            if (strng.Contains("???"))
+                strng="n/a";
+
+            testflagkey = QueryNameKEY(serv, dummy, "TestFlag", strng.Data());
+            if (testflagkey<0)
+            {
+                strng.ReadLine(fin);
+                continue;
+            }
+
+            // ========== Col 37: light conditions =========
+            strng.ReadToDelim(fin, ' ');
+            if (strng.Contains("???"))
+                strng="n/a";
+
+            lightcondkey = QueryNameKEY(serv, dummy, "LightConditions", strng.Data());
+            if (lightcondkey<0)
+            {
+                strng.ReadLine(fin);
+                continue;
+            }
+
+            // ========== Col 38: discriminator threshold table =========
+            strng.ReadToDelim(fin, ' ');
+            if (strng.Contains("???"))
+                strng="n/a";
+
+            dttablekey = QueryNameKEY(serv, dummy, "DiscriminatorThresholdTable", strng.Data());
+            if (dttablekey<0)
+            {
+                strng.ReadLine(fin);
+                continue;
+            }
+
+            // ========== Col 39: trigger delay table =========
+            strng.ReadToDelim(fin, ' ');
+            if (strng.Contains("???"))
+                strng="n/a";
+
+            triggerdelaytablekey = QueryNameKEY(serv, dummy, "TriggerDelayTable", strng.Data());
+            if (triggerdelaytablekey<0)
+            {
+                strng.ReadLine(fin);
+                continue;
+            }
+
+            // ========== Col 40,41: RA and Dec sent to drive =========
+            strng.ReadToDelim(fin, ' ');
+            strng.ReadToDelim(fin, ' ');
+
+            // ========== Col 42: Calibration Script =========
+            strng.ReadToDelim(fin, '\n');
+            if (strng.Contains("???"))
+                strng="n/a";
+
+            calibrationscriptkey = QueryNameKEY(serv, dummy, "CalibrationScript", strng.Data());
+            if (calibrationscriptkey<0)
+            {
+                strng.ReadLine(fin);
+                continue;
+            }
+
+        }
+
+
+        // ================================================================
+        // ========== Data read from file now access the database =========
+        // ================================================================
+
+        //assemlbe the query that is needed to insert the values of this run
+        TString query;
+        query += "INSERT MyMagic.RunData SET ";
+
+        query += Form("fRunNumber=%d, ",  runnumber);
+        query += Form("fRunTypeKEY=%d, ", runtype);
+        query += Form("fProjectKEY=%d, ", projkey);
+        query += Form("fSourceKEY=%d, ",  sourcekey);
+        query += Form("fNumEvents=%d, ",  evtno);
+        query += Form("fRunStart=\"%s %s\", ", startdate.Data(), starttime.Data());
+        query += Form("fRunStop=\"%s %s\", ", stopdate.Data(), stoptime.Data());
+        query += Form("fL1TriggerTableKEY=%d, ", l1triggerkey);
+        query += Form("fL2TriggerTableKEY=%d, ", l2triggerkey);
+        query += Form("fTestFlagKEY=%d, ", testflagkey);
+        query += Form("fCalibrationScriptKEY=%d, ", calibrationscriptkey);
+        query += Form("fTriggerDelayTableKEY=%d, ", triggerdelaytablekey);
+        query += Form("fDiscriminatorThresholdTableKEY=%d, ", dttablekey);
+        query += Form("fLightConditionsKEY=%d, ", lightcondkey);
+        query += Form("fHvSettingsKEY=%d, ", hvkey);
+        if (!TMath::IsNaN(zd) && TMath::Finite(zd))
+            query += Form("fZenithDistance=%d, ", TMath::Nint(zd));
+        if (!TMath::IsNaN(az) && TMath::Finite(az))
+            query += Form("fAzimuth=%d, ", TMath::Nint(az));
+        if (!TMath::IsNaN(storerate) && TMath::Finite(storerate))
+            query += Form("fDaqStoreRate=%d, ", TMath::Nint(storerate));
+        if (!TMath::IsNaN(daqrate) && TMath::Finite(daqrate))
+            query += Form("fDaqTriggerRate=%d, ", TMath::Nint(daqrate));
+        if (!TMath::IsNaN(trigrate) && TMath::Finite(trigrate))
+            query += Form("fMeanTriggerRate=%d, ", TMath::Nint(trigrate));
+        if (!TMath::IsNaN(l2prrate) && TMath::Finite(l2prrate))
+            query += Form("fL2RatePresc=%d, ", TMath::Nint(l2prrate));
+        if (!TMath::IsNaN(l2uprate) && TMath::Finite(l2uprate))
+            query += Form("fL2RateUnpresc=%d, ", TMath::Nint(l2uprate));
+        query += "fMagicNumberKEY=1, fExcludedFDAKEY=1";
+
+        cnt++;
+
+        if (dummy)
+            continue;
+
+        //send query, add dataset to DB
+        TSQLResult *res = serv.Query(query);
+        if (!res)
+            return -1;
+        delete res;
+
+        //create entry in table RunProcessStatus for this runnumber
+        TString query2=Form("INSERT MyMagic.RunProcessStatus SET fRunNumber=%d, fTimingCorrection='1970-01-01 00:00:00'",
+                    runnumber);
+        res = serv.Query(query2);
+        if (!res)
+            return -1;
+        delete res;
+    }
+
+    return cnt;
+
+}
+
+// This tool will work from Period017 (2004_05_17) on...
+int filldotrun(const TString path="/data/MAGIC/Period018/ccdata", Bool_t dummy=kTRUE)
+{
+    TEnv env("sql.rc");
+
+    MSQLServer serv(env);
+    if (!serv.IsConnected())
+    {
+        cout << "ERROR - Connection to database failed." << endl;
+        return 0;
+    }
+    cout << "filldotrun" << endl;
+    cout << "----------" << endl;
+    cout << endl;
+    cout << "Connected to " << serv.GetName() << endl;
+    cout << "Search Path: " << path << endl;
+    cout << endl;
+
+    if (path.EndsWith(".run"))
+    {
+        cout << path(TRegexp("CC_.*.run", kFALSE)) << flush;
+        Int_t n = insert(serv, dummy, path);
+        cout << " <" << n << "> " << (dummy?"DUMMY":"") << endl;
+
+        return n<0 ? 0 : 1;
+    }
+
+    MDirIter Next(path, "CC_*.run", -1);
+    while (1)
+    {
+        TString name = Next();
+        if (name.IsNull())
+            break;
+
+        cout << name(TRegexp("CC_.*.run", kFALSE)) << flush;
+        Int_t n = insert(serv, dummy, name);
+        cout << " <" << n << "> " << (dummy?"DUMMY":"") << endl;
+
+        if (n<0)
+            return 0;
+    }
+
+    return 1;
+}
Index: trunk/MagicSoft/Mars/datacenter/macros/fillsignal.C
===================================================================
--- trunk/MagicSoft/Mars/datacenter/macros/fillsignal.C	(revision 6933)
+++ trunk/MagicSoft/Mars/datacenter/macros/fillsignal.C	(revision 6933)
@@ -0,0 +1,160 @@
+/* ======================================================================== *\
+!
+! *
+! * 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
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// fillsignal.C
+// ============
+//
+// This macro is used to read the calibration-/callisto-output files
+// signal00000.root.
+//
+// From this file the Mean PedRms for the inner and outer camera is extracted.
+//
+// Usage:
+//   .x fillsignal.C("/data/MAGIC/Period014/signal00000.root", 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.
+//
+// The macro can also be run without ACLiC but this is a lot slower...
+//
+// Remark: Running it from the commandline looks like this:
+//   root -q -l -b fillsignal.C+\(\"filename\"\,kFALSE\) 2>&1 | tee fillsignal.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 "MSQLServer.h"
+
+#include "MStatusArray.h"
+#include "MHCamera.h"
+
+using namespace std;
+
+int Process(MSQLServer &serv, TString fname, Bool_t dummy)
+{
+    TFile file(fname, "READ");
+    MStatusArray *arr = (MStatusArray*)file.Get("MStatusDisplay");
+    if (!arr)
+    {
+        cout << "ERROR - Reading of MStatusDisplay failed." << endl;
+        return 0;
+    }
+
+    MHCamera *cam = (MHCamera*)arr->FindObjectInCanvas("PedRMS;avg", "MHCamera", "PedRMS");
+    if (!cam)
+    {
+        cout << "WARNING - Reading of PedRMS;avg failed." << endl;
+        return 0;
+    }
+
+    TArrayI inner(1);
+    inner[0] = 0;
+
+    TArrayI outer(1);
+    outer[0] = 1;
+
+    Int_t s0[] = { 1, 2, 3, 4, 5, 6 };
+
+    Stat_t meani = cam->GetMeanSectors(TArrayI(6, s0), inner);
+    Stat_t meano = cam->GetMeanSectors(TArrayI(6, s0), outer);
+
+    if (meani<0 || meano<0)
+    {
+        cout << "WARNING - MeanPedRMS inner or outer < 0 " << endl;
+        cout << "MeanPedRMS inner " << meani << endl;
+        cout << "MeanPedRMS outer " << meano << endl;
+        return 0;
+    }
+
+    meani = TMath::Nint(meani*10)/10.;
+    meano = TMath::Nint(meano*10)/10.;
+
+    TString sequence = fname(TRegexp("signal[0-9]+[.]root$"));
+    if (sequence.IsNull())
+    {
+        cout << "WARNING - Sequ# empty" << endl;
+        cout << "Sequ# " << sequence << endl;
+        return 0;
+    }
+
+    Int_t seq = atoi(sequence.Data()+6);
+    TString meaninner=Form("%4.1f", meani);
+    TString meanouter=Form("%4.1f", meano);
+
+    cout << "Sequence #" << seq << endl;
+    cout << "  Mean Ped RMS inner [phe] " << Form("%4.1f", meani) << endl; // Unbrauchbar
+    cout << "  Mean Ped RMS outer [phe] " << Form("%4.1f", meano) << endl; // Unbrauchbar
+
+    TString query = Form("UPDATE MyMagic.Calibration SET fMeanPedRmsInner=%s, "
+                         " fMeanPedRmsOuter=%s WHERE fSequenceFirst='%d' ",
+                         meaninner.Data(), meanouter.Data(), seq);
+
+    if (dummy)
+        return 0;
+
+    TSQLResult *res = serv.Query(query);
+    if (!res)
+    {
+        cout << "ERROR - Query failed: " << query << endl;
+        return 0;
+    }
+
+    return 1;
+}
+
+int fillsignal(TString fname, 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 << "File: " << fname << endl;
+    cout << endl;
+
+    return Process(serv, fname, dummy);
+}
Index: trunk/MagicSoft/Mars/datacenter/macros/findcacofiles.C
===================================================================
--- trunk/MagicSoft/Mars/datacenter/macros/findcacofiles.C	(revision 6933)
+++ trunk/MagicSoft/Mars/datacenter/macros/findcacofiles.C	(revision 6933)
@@ -0,0 +1,91 @@
+/* ======================================================================== *\
+!
+! *
+! * 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): Daniela Dorner, 01/2005 <mailto:dorner@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2005
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// FindCaCoFiles.C
+// ===============
+//
+/////////////////////////////////////////////////////////////////////////////
+
+#include <iostream>
+#include <iomanip>
+#include <fstream>
+
+#include <TEnv.h>
+#include <TSystem.h>
+
+#include <MSQLServer.h>
+#include <TSQLRow.h>
+#include <TSQLResult.h>
+
+using namespace std;
+
+
+int findcacofiles(TString date)
+{
+    TEnv env("sql.rc");
+
+    MSQLServer serv(env);
+    if (!serv.IsConnected())
+    {
+        cout << "ERROR - Connection to database failed." << endl;
+        return 0;
+    }
+    cout << "findcacofiles" << endl;
+    cout << "-------------" << endl;
+    cout << endl;
+    cout << "Connected to " << serv.GetName() << endl;
+    cout << endl;
+
+    TString query="SELECT fRunNumber FROM MyMagic.RunProcessStatus WHERE IsNull(fCaCoFileFound) ";
+    query+=" and fRunNumber > 10000 and not IsNull(fCCFileAvail)";
+
+    TSQLResult *res = serv.Query(query);
+    if (!res)
+    {
+        cout << "Error." << endl;
+        return 0;
+    }
+
+    Int_t idx = date.First('-');
+    TString year = date(0, idx);
+    cout << "year: " << year << endl;
+
+    ofstream fout("/magic/datacenter/autologs/filesondisk/"+year+"/findcacofiles-"+date+".txt");
+    if (!fout)
+    {
+        cout << "ERROR - Cannot open file." << endl;
+        return kFALSE;
+    }
+    TString runnumber=0;
+    TSQLRow *row=0;
+    while ((row = res->Next()))
+        fout << (*row)[0] << endl;
+
+    delete res;
+    return 1;
+}
+
+
Index: trunk/MagicSoft/Mars/datacenter/macros/getdolist.C
===================================================================
--- trunk/MagicSoft/Mars/datacenter/macros/getdolist.C	(revision 6933)
+++ trunk/MagicSoft/Mars/datacenter/macros/getdolist.C	(revision 6933)
@@ -0,0 +1,130 @@
+/* ======================================================================== *\
+!
+! *
+! * 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): Daniela Dorner, 01/2005 <mailto:dorner@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2005
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// GetDoList.C
+// ===========
+//
+/////////////////////////////////////////////////////////////////////////////
+
+#include <iostream>
+#include <iomanip>
+#include <fstream>
+
+#include <TEnv.h>
+#include <TObjString.h>
+#include <TList.h>
+
+#include <MSQLServer.h>
+#include <TSQLRow.h>
+#include <TSQLResult.h>
+
+using namespace std;
+
+
+int getdolist(TString table, TString column, TString date)
+{
+    TEnv env("sql.rc");
+
+    MSQLServer serv(env);
+    if (!serv.IsConnected())
+    {
+        cout << "ERROR - Connection to database failed." << endl;
+        return 0;
+    }
+    cout << "getstatus" << endl;
+    cout << "---------" << endl;
+    cout << endl;
+    cout << "Connected to " << serv.GetName() << endl;
+    cout << endl;
+
+    TEnv rc("steps.rc");
+
+    TString needs  = rc.GetValue(table+"."+column+".Needs", "");
+    cout << "Needs: " << needs  << endl;
+
+    TList l;
+
+    while (!needs.IsNull())
+    {
+        needs = needs.Strip(TString::kBoth);
+
+        Int_t idx = needs.First(' ');
+        if (idx<0)
+            idx = needs.Length();
+
+        TString need = needs(0, idx);
+        needs.Remove(0, idx);
+        l.Add(new TObjString(need));
+    }
+
+    TString query(Form("SELECT %s.%s FROM MyMagic.%s",
+                       table.Data(), rc.GetValue(table+".Primary", ""),
+                       table.Data()));
+
+    if (date!="NULL" && rc.GetValue(table+".TimerTable", "")!="")
+        query+=Form(" left join MyMagic.%s on %s.%s=%s.%s ",
+                    rc.GetValue(table+".TimerTable", ""), table.Data(),
+                    rc.GetValue(table+".Primary", ""),
+                    rc.GetValue(table+".TimerTable", ""),
+                    rc.GetValue(table+".Primary", ""));
+    query+=Form(" WHERE ISNULL(%s)", column.Data());
+
+    TIter Next(&l);
+    TObject *o=0;
+    while ((o=Next()))
+        query+=Form(" AND NOT ISNULL(%s)", o->GetName());
+
+    if (date!="NULL")
+    {
+        if (rc.GetValue(table+".TimerTable", "")!="")
+        {
+            TString day=date+" 13:00:00";
+            query+=Form(" AND (fRunStart>ADDDATE(\"%s\", INTERVAL -1 DAY) AND fRunStart<\"%s\")",
+                        day.Data(), day.Data());
+        }
+        else
+            query+=Form(" AND %s=%s ", rc.GetValue(table+".Primary", ""), date.Data());
+    }
+
+    cout << "query: " << query << endl;
+
+    TSQLResult *res = serv.Query(query);
+    if (!res)
+        return 0;
+
+    ofstream fout("/magic/datacenter/lists/ToDo-"+table+"-"+column+".txt", ios::app);
+//    ofstream fout("/data/MAGIC/datacenter/"+table+"-"+column+".txt", ios::app);
+
+    TSQLRow *row=0;
+    while ((row = res->Next()))
+        fout << (*row)[0] << endl;
+
+    delete res;
+
+    return 1;
+}
+
+
Index: trunk/MagicSoft/Mars/datacenter/macros/insertcacofile.C
===================================================================
--- trunk/MagicSoft/Mars/datacenter/macros/insertcacofile.C	(revision 6933)
+++ trunk/MagicSoft/Mars/datacenter/macros/insertcacofile.C	(revision 6933)
@@ -0,0 +1,78 @@
+/* ======================================================================== *\
+!
+! *
+! * 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): Daniela Dorner, 01/2005 <mailto:dorner@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2005
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// InsertCaCoFiles.C
+// =================
+//
+/////////////////////////////////////////////////////////////////////////////
+
+#include <iostream>
+#include <iomanip>
+#include <fstream>
+
+#include <TEnv.h>
+#include <TSystem.h>
+
+#include <MSQLServer.h>
+#include <TSQLRow.h>
+#include <TSQLResult.h>
+
+using namespace std;
+
+
+int insertcacofile(TString runnumber, TString newrunnumber)
+{
+    TEnv env("sql.rc");
+
+    MSQLServer serv(env);
+    if (!serv.IsConnected())
+    {
+        cout << "ERROR - Connection to database failed." << endl;
+        return 0;
+    }
+    cout << "insertcacofile" << endl;
+    cout << "--------------" << endl;
+    cout << endl;
+    cout << "Connected to " << serv.GetName() << endl;
+    cout << endl;
+
+    Int_t newrunno=atoi(newrunnumber.Data());
+    TString query(Form("UPDATE MyMagic.RunProcessStatus SET fCaCoFileAvail=Now(), fCaCoFileFound=%d WHERE fRunNumber=%s ",
+                       newrunno, runnumber.Data()));
+    cout << "qu: " << query << endl;
+
+    TSQLResult *res = serv.Query(query);
+    if (!res)
+    {
+        cout << "Error - update didn't work." << endl;
+        return 0;
+    }
+
+    delete res;
+    return 1;
+}
+
+
Index: trunk/MagicSoft/Mars/datacenter/macros/insertdate.C
===================================================================
--- trunk/MagicSoft/Mars/datacenter/macros/insertdate.C	(revision 6933)
+++ trunk/MagicSoft/Mars/datacenter/macros/insertdate.C	(revision 6933)
@@ -0,0 +1,113 @@
+/* ======================================================================== *\
+!
+! *
+! * 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): Daniela Dorner, 01/2005 <mailto:dorner@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2005
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// InsertDate.C
+// ============
+//
+/////////////////////////////////////////////////////////////////////////////
+
+#include <iostream>
+#include <iomanip>
+#include <fstream>
+
+#include <TEnv.h>
+
+#include <MSQLServer.h>
+#include <TSQLRow.h>
+#include <TSQLResult.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));
+
+    cout << "query: " << query << endl;
+
+    TSQLResult *res = serv.Query(query);
+    if (!res)
+        return kFALSE;
+
+    Bool_t rc = kFALSE;
+
+    TSQLRow *row=res->Next();
+    if (row && (*row)[0])
+        rc=kTRUE;
+
+    delete res;
+    return rc;
+}
+
+
+int insertdate(TString date)
+{
+    TEnv env("sql.rc");
+
+    MSQLServer serv(env);
+    if (!serv.IsConnected())
+    {
+        cout << "ERROR - Connection to database failed." << endl;
+        return 0;
+    }
+    cout << "insertdate" << endl;
+    cout << "----------" << endl;
+    cout << endl;
+    cout << "Connected to " << serv.GetName() << endl;
+    cout << endl;
+
+    if (!ExistStr(serv, "fDate", "MyMagic.SequenceBuildStatus", date))
+    {
+        TString query(Form("INSERT MyMagic.SequenceBuildStatus SET fDate='%s', fCCFilled=Now() ",
+                           date.Data()));
+
+        TSQLResult *res = serv.Query(query);
+        if (!res)
+        {
+            cout << "Error - could not insert entry" << endl;
+            return 0;
+        }
+        delete res;
+    }
+    else
+    {
+        cout << date << " already exists... do update. " << endl;
+
+        TString query="UPDATE MyMagic.SequenceBuildStatus SET fCCFilled=Now(), fExclusionsDone=NULL, ";
+        query +=Form("fSequenceEntriesBuilt=NULL WHERE fDate='%s' ", date.Data());
+
+        TSQLResult *res = serv.Query(query);
+        if (!res)
+        {
+            cout << "Error - could not update entry" << endl;
+            return 0;
+        }
+        delete res;
+    }
+
+    return 1;
+}
+
+
Index: trunk/MagicSoft/Mars/datacenter/macros/resetallruns.C
===================================================================
--- trunk/MagicSoft/Mars/datacenter/macros/resetallruns.C	(revision 6933)
+++ trunk/MagicSoft/Mars/datacenter/macros/resetallruns.C	(revision 6933)
@@ -0,0 +1,113 @@
+/* ======================================================================== *\
+!
+! *
+! * 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): Daniela Dorner, 01/2005 <mailto:dorner@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2005
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// ResetAllRuns.C
+// ==============
+//
+/////////////////////////////////////////////////////////////////////////////
+
+#include <iostream>
+#include <iomanip>
+#include <fstream>
+
+#include <TEnv.h>
+
+#include <MSQLServer.h>
+#include <TSQLRow.h>
+#include <TSQLResult.h>
+
+using namespace std;
+
+
+int resetallruns(TString filename, TString column)
+{
+    TEnv env("sql.rc");
+
+    MSQLServer serv(env);
+    if (!serv.IsConnected())
+    {
+        cout << "ERROR - Connection to database failed." << endl;
+        return 0;
+    }
+    cout << "resetallruns" << endl;
+    cout << "------------" << endl;
+    cout << endl;
+    cout << "Connected to " << serv.GetName() << endl;
+    cout << endl;
+
+    TString query(Form("UPDATE MyMagic.RunProcessStatus SET %s=NULL",
+                       column.Data()));
+    if (column.Contains("CaCo"))
+        query+=", fCaCoFileFound=NULL";
+
+
+    cout << "q: " << query << endl;
+
+    TSQLResult *res = serv.Query(query);
+    if (!res)
+    {
+        cout << "updating (setting " << column.Data() << "= NULL) didn't work " << endl;
+        return 0;
+    }
+    delete res;
+
+
+    ifstream fin(filename);
+    if (!fin)
+    {
+        cout << "file: " << filename << " missing!" << endl;
+        return 0;
+    }
+
+    while (1)
+    {
+        TString runnumber;
+        runnumber.ReadLine(fin);
+        if (!fin)
+            break;
+
+        TString query(Form("UPDATE MyMagic.RunProcessStatus SET %s=Now()", column.Data()));
+
+        if (column.Contains("CaCo"))
+            query+=Form(", fCaCoFileFound=%d", atoi(runnumber));
+
+        query+=Form(" WHERE fRunNumber=%d ", atoi(runnumber));
+
+        cout << "q2: " << query << endl;
+
+        res = serv.Query(query);
+        if (!res)
+        {
+            cout << "updating (setting " << column.Data() << " = Now()) for run# " << atoi(runnumber) << ") didn't work " << endl;
+            return 0;
+        }
+        delete res;
+    }
+
+    return 1;
+}
+
+
Index: trunk/MagicSoft/Mars/datacenter/macros/setstatus.C
===================================================================
--- trunk/MagicSoft/Mars/datacenter/macros/setstatus.C	(revision 6933)
+++ trunk/MagicSoft/Mars/datacenter/macros/setstatus.C	(revision 6933)
@@ -0,0 +1,158 @@
+/* ======================================================================== *\
+!
+! *
+! * 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): Daniela Dorner, 01/2005 <mailto:dorner@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2005
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// SetStatus.C
+// ===========
+//
+/////////////////////////////////////////////////////////////////////////////
+
+#include <iostream>
+#include <iomanip>
+#include <fstream>
+
+#include <TEnv.h>
+
+#include <MTime.h>
+
+#include <MSQLServer.h>
+#include <TSQLRow.h>
+#include <TSQLResult.h>
+
+using namespace std;
+
+
+Bool_t CheckReset(TEnv &rc, TString table, TString column, TString value)
+{
+    if (value!="NULL")
+    {
+        cout << "everything ok - no reset needed" << endl;
+        return kTRUE;
+    }
+
+    TString reset=rc.GetValue(table+"."+column+".Reset", "no");
+    if (reset.Contains("no"))
+    {
+        cout << "you can't reset " << column << "." << endl;
+        return kFALSE;
+    }
+
+    cout << "reset is possible" << endl;
+    return kTRUE;
+}
+
+TString CheckDefault(MSQLServer &serv, TEnv &rc, TString primary, TString table, TString influence)
+{
+    TString query(Form("SELECT %s FROM MyMagic.%s WHERE %s=%s",
+                       influence.Data(), table.Data(),
+                       rc.GetValue(table+".Primary", ""), primary.Data()));
+
+    TSQLResult *res = serv.Query(query);
+    if (!res)
+        cout << "Error - no run to check" << endl;
+
+    MTime t, t0;
+    //set time t to 'no-version-value',
+    //which is in this case equivalent to NULL
+    t.Set(1970,1,1,0,0,0); 
+    t0.Set(1970,1,1,0,0,0);
+
+    TSQLRow *row=0;
+    while ((row = res->Next()))
+    {
+        if (row && (*row)[0])
+            t.SetSqlDateTime((*row)[0]);
+
+        cout << "t : " << t  << endl;
+        cout << "t0: " << t0 << endl;
+
+        return t()-t0()>0 ? "no" : "yes";
+    }
+}
+
+Int_t SetInfluences(MSQLServer &serv, TEnv &rc, TString primary, TString table, TString column, TString value, Bool_t resetall)
+{
+    cout << "set influenes for " << table << "." << column << endl;
+
+    TString influences  = rc.GetValue(table+"."+column+".Influences", "");
+
+    TString query(Form("UPDATE MyMagic.%s SET %s=%s",
+                       table.Data(), column.Data(), value.Data()));
+
+    while (!influences.IsNull() && resetall)
+    {
+        influences = influences.Strip(TString::kBoth);
+
+        Int_t idx = influences.First(' ');
+        if (idx<0)
+            idx = influences.Length();
+
+        TString influence = influences(0, idx);
+        influences.Remove(0, idx);
+
+        TString deflt  = rc.GetValue(influence+".Default", "");
+
+        if (deflt=="check")
+            deflt=CheckDefault(serv, rc, primary, table, influence);
+
+        if (deflt=="yes")
+            continue;
+
+        query+=Form(", %s=NULL", influence.Data());
+    }
+
+    query+=Form(" WHERE %s='%s'", rc.GetValue(table+".Primary", ""), primary.Data());
+
+//    cout << "query: " << query << endl;
+
+    TSQLResult *res = serv.Query(query);
+    if (!res)
+        return 0;
+
+    return 1;
+}
+
+int setstatus(TString primary, TString table, TString column, TString value, Bool_t resetall=kTRUE)
+{
+    TEnv env("sql.rc");
+
+    MSQLServer serv(env);
+    if (!serv.IsConnected())
+    {
+        cout << "ERROR - Connection to database failed." << endl;
+        return 0;
+    }
+    cout << "setstatus" << endl;
+    cout << "---------" << endl;
+    cout << endl;
+    cout << "Connected to " << serv.GetName() << endl;
+    cout << endl;
+
+    TEnv rc("steps.rc");
+
+    return !CheckReset(rc, table, column, value) ? 0 : SetInfluences(serv, rc, primary, table, column, value, resetall);
+
+}
+
Index: trunk/MagicSoft/Mars/datacenter/macros/setupdb.C
===================================================================
--- trunk/MagicSoft/Mars/datacenter/macros/setupdb.C	(revision 6933)
+++ trunk/MagicSoft/Mars/datacenter/macros/setupdb.C	(revision 6933)
@@ -0,0 +1,806 @@
+#include <iomanip.h>
+/*
+Statements
+
+SELECT [ DISTINCT ] * | LIST OF COLUMNS, FUNCTIONS, CONSTANTS
+   FROM LIST OF TABLES OR VIEWS
+   [ WHERE CONDITION(S) ]
+   [ ORDER BY ORDERING COLUMN(S) [ ASC | DESC ] ]
+   [ GROUP BY GROUPING COLUMN(S) ]
+   [ HAVING CONDITION(S) ]
+
+DELETE FROM TABLE NAME
+   [ WHERE CONDITION(S) ]
+
+INSERT INTO TABLE NAME
+   [ (COLUMN LIST) ]
+   VALUES (VALUE LIST)
+
+UPDATE TABLE NAME
+   SET COLUMN NAME = VALUE
+   [ WHERE CONDITION ]
+
+Functions
+
+Function 	Purpose
+SUM 	Total of the values in a field.
+AVG 	Average of the values in a field.
+MIN 	Lowest value in a field.
+MAX 	Highest value in a field.
+COUNT 	Number of values in a field, not counting Null (blank) values.
+
+Predicates
+
+Predicate 	Description
+BETWEEN ... AND 	Compares a value to a range formed by two values.
+IN 	Determines whether a value exists in a list of values or a table.
+LIKE 	Compares, in part or in whole, one value with another.
+JOIN 	Joins two tables.
+
+Data Definition
+
+CREATE TABLE TABLE_NAME
+   ( COLUMN_NAME DATA_TYPE [(SIZE)] COLUMN_CONSTRAINT,
+   [, other column definitions,...]
+   [, primary key constraint]
+   )
+
+ALTER TABLE TABLE_NAME ADD | DROP | MODIFY
+   ( COLUMN_NAME DATA_TYPE [(SIZE)] COLUMN_CONSTRAINT,
+   [, other column definitions,...]
+   )
+
+DROP TABLE TABLE_NAME
+
+CREATE [UNIQUE] [ASC | DESC] INDEX INDEX_NAME
+   ON TABLE_NAME ( COLUMN_LIST )
+
+DROP INDEX INDEX_NAME ON TABLE_NAME
+
+CREATE VIEW VIEW_NAME AS QUERY_NAME
+
+CONSTRAINT CONSTRAINT_NAME
+    {PRIMARY KEY | UNIQUE | NOT NULL |
+    REFERENCES FOREIGN_TABLE [(FIELD_LIST)]}
+
+    */
+
+void Line(const TArrayI &max)
+{
+    cout << "+" << setfill('-');
+    for (int i=0; i<max.GetSize(); i++)
+        cout << setw(max[i]+1) << "-" << "-+";
+    cout << endl;
+}
+
+void Print(TSQLResult *res)
+{
+    Int_t n = res->GetFieldCount();
+
+    TArrayI max(n);
+
+    for (int i=0; i<n; i++)
+        max[i] = strlen(res->GetFieldName(i));
+
+    TSQLRow *row;
+
+    TList rows;
+    while (row=res->Next())
+    {
+        for (int i=0; i<n; i++)
+            max[i] = TMath::Max(max[i], row->GetFieldLength(i));
+        rows.Add(row);
+    }
+
+    Line(max);
+
+    cout << "|" << setfill(' ');
+    for (int i=0; i<n; i++)
+        cout << setw(max[i]+1) << res->GetFieldName(i) << " |";
+    cout << endl;
+
+    Line(max);
+
+    cout << setfill(' ');
+    TIter Next(&rows);
+    while (row=(TSQLRow*)Next())
+    {
+        cout << "|";
+        for (int i=0; i<n; i++)
+        {
+            char *c = (*row)[i];
+            cout << setw(max[i]+1) << (c?c:"") << " |";
+        }
+        cout << endl;
+    }
+
+    Line(max);
+}
+
+TString GetFields(TSQLServer *serv, const char *db, const char *table)
+{
+    res = serv->GetColumns(db, table);
+    if (!res)
+        return "";
+
+    TString fields;
+
+    TList rows;
+    while (row=res->Next())
+        rows.Add(row);
+
+    TIter Next(&rows);
+    while (row=(TSQLRow*)Next())
+    {
+        fields += (*row)[0];
+        if (row!=rows.Last())
+            fields += ", ";
+    }
+
+    return fields;
+}
+
+void PrintContents(TSQLServer *serv, const char *db, const char *table)
+{
+    TString fields=GetFields(serv, db, table);
+
+    TSQLResult *res = serv->Query(Form("SELECT %s FROM %s", fields.Data(), table));
+    if (res)
+    {
+        Print(res);
+        delete res;
+    }
+}
+
+/*
+ GetTables(db):
+    \u "db"
+    SHOW TABLES;
+
+ GetDataBases();
+    SHOW DATABASES;
+
+ GetColumns(db, table);
+    EXPLAIN table;
+    DESCRIBE table;
+
+ SHOW VARIABLES;
+
+ PRIMARY_KEY impliziert NOT NULL
+
+    */
+
+void CreatePrimaryEntries()
+{
+    TList list;
+    list.SetOwner();
+
+    // Trigger  tables
+    list.Add(new TObjString(
+        "INSERT MyMagic.L1TriggerTable (fL1TriggerTableKEY, fL1TriggerTableName, fL1TriggerTable) VALUES "
+        "  (1, 'n/a', 'Not available')"));
+
+    list.Add(new TObjString(
+        "INSERT MyMagic.L2TriggerTable (fL2TriggerTableKEY, fL2TriggerTableName, fL2TriggerTable) VALUES "
+        "  (1, 'n/a', 'Not available')"));
+
+    // File path
+    list.Add(new TObjString(
+        "INSERT MyMagic.FilePath (fFilePathName, fFilePath) VALUES "
+        "  ('n/a', 'Not available in the Data Center')"));
+
+    // Magic number
+    list.Add(new TObjString(
+        "INSERT MyMagic.MagicNumber (fMagicNumber, fMagicNumberName) VALUES "
+        "  (0x0000, 'Not available'),"
+        "  (0xc0c0, 'Ok'),"
+        "  (0xc0c1, 'Not closed'),"
+        "  (0xffff, 'Wrong')"));
+
+    // Run type
+    list.Add(new TObjString(
+        "INSERT MyMagic.RunType (fRunType, fRunTypeName) VALUES "
+        "  (0xffff, 'Not available'),"
+        "  (0x0000, 'Data'),"
+        "  (0x0001, 'Pedestal'),"
+        "  (0x0002, 'Calibration'),"
+        "  (0x0007, 'Point Run'),"
+        "  (0x0100, 'Monte Carlo')"));
+
+    // HvSettings
+    list.Add(new TObjString(
+        "INSERT MyMagic.HvSettings (fHvSettingsKEY, fHvSettingsName, fHvSettings) VALUES "
+        "  (1, 'n/a', 'Not available')"));
+
+    //Excluded From DataAnalysis
+    list.Add(new TObjString(
+        "INSERT MyMagic.ExcludedFDA (fExcludedFDAKEY, fExcludedFDAName, fExcludedFDA) VALUES "
+        "  (1, \"Not excluded\", \"Not excluded from Data Analysis\")"));
+
+    //Manually Changed
+    list.Add(new TObjString(
+        "INSERT MyMagic.ManuallyChanged (fManuallyChangedKEY, fManuallyChangedName, fManuallyChanged) VALUES "
+        "  (1, \"Automatic\", \"This entry was created automatically without user intervention\")");
+
+    // Source type
+    list.Add(new TObjString(
+        "INSERT MyMagic.SourceType (fSourceTypeName) VALUES ('Unknown')"));
+
+    // LightConditions
+    list.Add(new TObjString(
+        "INSERT MyMagic.LightConditions (fLightConditionsKEY, fLightConditionsName, fLightConditions) VALUES "
+        "  (1, 'n/a', 'Light conditions are not available')"));
+
+    // Testflag
+    list.Add(new TObjString(
+        "INSERT MyMagic.TestFlag (fTestFlagKEY, fTestFlagName, fTestFlag) VALUES "
+        "  (1, 'n/a', 'Testflag is not available')"));
+
+    // Trigger delay table
+    list.Add(new TObjString(
+        "INSERT MyMagic.TriggerDelayTable (fTriggerDelayTableKEY, fTriggerDelayTableName, fTriggerDelayTable) VALUES "
+        "  (1, 'n/a', 'Trigger delay table is not available')"));
+
+    // Calibration script
+    list.Add(new TObjString(
+        "INSERT MyMagic.CalibrationScript (fCalibrationScriptKEY, fCalibrationScriptName, fCalibrationScript) VALUES "
+        "  (1, 'n/a', 'Calibration script is not available')"));
+
+    // discriminator threshold table
+    list.Add(new TObjString(
+        "INSERT MyMagic.DiscriminatorThresholdTable (fDiscriminatorThresholdTableKEY, fDiscriminatorThresholdTableName, fDiscriminatorThresholdTable) VALUES "
+        "  (1, 'n/a', 'Discriminator threshold table is not available')"));
+
+
+    TSQLServer *serv = TSQLServer::Connect("mysql://localhost:3306", "hercules", "d99swMT!");
+    if (!serv)
+        return;
+
+    TIter Next(&list);
+    TObjString *str;
+
+    cout << "Filling tables..." << endl;
+
+    while ((str=(TObjString*)Next()))
+    {
+        TString q(str->GetString());
+
+        Int_t f = q.First('(');
+        TString out = q(0, f);
+        cout << " - " << out << "... " << flush;
+        TSQLResult *res = serv->Query(q);
+        cout << (res==0 ? "ERROR!" : "Ok.") << endl;
+        if (res)
+            delete res;
+    }
+
+    serv->Close();
+    delete serv;
+}
+
+TObjString *CreateKeyTable(TString name)
+{
+    return new TObjString(Form(
+      "CREATE TABLE MyMagic.%s ("
+      "  f%sKEY    SMALLINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,"
+      "  f%sName   VARCHAR(255)         NOT NULL UNIQUE,"
+      "  f%s       VARCHAR(255)             NULL"
+      ") MAX_ROWS=65536", name.Data(), name.Data(), name.Data(), name.Data()));
+}
+
+void CreateMagicDataBase()
+{
+    TList list;
+    list.SetOwner();
+
+    TString query =
+        "CREATE TABLE MyMagic.RunData"
+        "("
+        "  fRunDataKEY                      INT       UNSIGNED   PRIMARY KEY AUTO_INCREMENT,"// COMMENT('The unique key for each run-file'),";
+        "  fRunNumber                       INT       UNSIGNED   NOT NULL UNIQUE,"  // PACK_KEYS=1,";// COMMENT('Run number'),";
+        "  fMagicNumberKEY                  TINYINT   UNSIGNED   NOT NULL,"         // PACK_KEYS=1,";// COMMENT('The MAGIC Key (first two bytes of a raw data file)'),";
+        "  fFormatVersion                   SMALLINT  UNSIGNED   NOT NULL,"         // PACK_KEYS=1,";// COMMENT('File format version of the raw data file)'),";
+        "  fRunTypeKEY                      TINYINT   UNSIGNED   NOT NULL,"         // PACK_KEYS=1,";// COMMENT('Run type'),";
+        "  fProjectKEY                      SMALLINT  UNSIGNED   NOT NULL,"         // PACK_KEYS=1,";// COMMENT('Name of the project (assigned by the physics comittee)'),";
+        "  fSourceKEY                       SMALLINT  UNSIGNED   NOT NULL,"         // PACK_KEYS=1,";// COMMENT('Name of the source observed'),";
+        "  fNumEvents                       MEDIUMINT UNSIGNED   NOT NULL,"         // COMMENT('Number of events in this run-file'),";
+        "  fRunStart                        DATETIME             NOT NULL,"         // COMMENT('Time when the run was started'),";
+        "  fRunStop                         DATETIME                 NULL,";        // COMMENT('Time when the run has stopped')";
+    query +=
+        "  fZenithDistance                  TINYINT                  NULL,"         // COMMENT('Time of last change'),";
+        "  fAzimuth                         SMALLINT                 NULL,"         // COMMENT('Time of last change'),";
+        "  fL1TriggerTableKEY               SMALLINT  UNSIGNED   NOT NULL,"         // COMMENT('Time of last change'),";
+        "  fL2TriggerTableKEY               SMALLINT  UNSIGNED   NOT NULL,"         // COMMENT('Time of last change'),";
+        "  fHvSettingsKEY                   SMALLINT  UNSIGNED   NOT NULL,"         // COMMENT('Time of last change'),";
+        "  fDaqStoreRate                    SMALLINT  UNSIGNED       NULL,"         // COMMENT('Time of last change'),";
+        "  fDaqTriggerRate                  SMALLINT  UNSIGNED       NULL,"         // COMMENT('Time of last change'),";
+        "  fMeanTriggerRate                 SMALLINT  UNSIGNED       NULL,"         // COMMENT('Time of last change'),";
+        "  fL2RatePresc                     SMALLINT  UNSIGNED       NULL,"         // COMMENT('Time of last change'),";
+        "  fL2RateUnpresc                   SMALLINT  UNSIGNED       NULL,"         // COMMENT('Time of last change'),";
+        "  fExcludedFDAKEY                  SMALLINT  UNSIGNED   NOT NULL,"
+        "  fSequenceFirst                        INT  UNSIGNED   NOT NULL,";
+    query +=
+        "  fLastUpdate                      TIMESTAMP"                              // COMMENT('Time of last change'),";
+        "  fTestFlagKEY                     SMALLINT  UNSIGNED   NOT NULL,"
+        "  fLightConditionsKEY              SMALLINT  UNSIGNED   NOT NULL,"
+        "  fCalibrationScriptKEY            SMALLINT  UNSIGNED   NOT NULL,"
+        "  fDiscriminatorThresholdTableKEY  SMALLINT  UNSIGNED   NOT NULL,"
+        "  fTriggerDelayTableKEY            SMALLINT  UNSIGNED   NOT NULL,"
+        ")";
+
+    list.Add(new TObjString(query));
+
+    list.Add(new TObjString(
+        "CREATE TABLE MyMagic.RunType ("
+        "  fRunTypeKEY        TINYINT  UNSIGNED AUTO_INCREMENT PRIMARY KEY,"
+        "  fRunType           SMALLINT UNSIGNED    NOT NULL UNIQUE,"
+        "  fRunTypeName       VARCHAR(255)         NOT NULL UNIQUE,"
+        ") MAX_ROWS=256"));
+
+    list.Add(new TObjString(
+        "CREATE TABLE MyMagic.MagicNumber ("
+        "  fMagicNumberKEY    TINYINT  UNSIGNED AUTO_INCREMENT PRIMARY KEY,"
+        "  fMagicNumber       SMALLINT UNSIGNED    NOT NULL UNIQUE,"
+        "  fMagicNumberName   VARCHAR(255)         NOT NULL UNIQUE"
+        ") MAX_ROWS=256"));
+
+    list.Add(new TObjString(
+        "CREATE TABLE MyMagic.Project ("
+        "  fProjectKEY        SMALLINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,"
+        "  fProjectName       CHAR(22)             NOT NULL UNIQUE,"
+        "  fProject           VARCHAR(255)         NOT NULL"
+        ") MAX_ROWS=65536"));
+
+    list.Add(new TObjString(
+        "CREATE TABLE MyMagic.Source ("
+        "  fSourceKEY         SMALLINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,"
+        "  fSourceName        CHAR(12)             NOT NULL UNIQUE,"
+        "  fSourceTypeKEY     SMALLINT UNSIGNED        NULL,"
+        "  fRightAscension    DOUBLE                   NULL,"
+        "  fDeclination       DOUBLE                   NULL,"
+        "  fEpochChar         CHAR                     NULL,"// DEFAULT='J'
+        "  fEpochDate         SMALLINT(4) UNSIGNED     NULL,"// DEFAULT=2000
+        "  fMagnitude         SMALLINT                 NULL" // 82=8.2
+        ") MAX_ROWS=65536"));
+
+    list.Add(new TObjString(
+        "CREATE TABLE MyMagic.SourceType ("
+        "  fSourceTypeKEY     SMALLINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,"
+        "  fSourceTypeName    VARCHAR(255)         NOT NULL UNIQUE"
+        ") MAX_ROWS=65536"));
+
+    list.Add(new TObjString(
+        "CREATE TABLE MyMagic.Files ("
+        "  fRawFileKEY        INT UNSIGNED         NOT NULL PRIMARY KEY,"
+        "  fRepFileKEY        INT UNSIGNED             NULL UNIQUE,"
+        "  fDccFileKEY        INT UNSIGNED             NULL UNIQUE"
+        ")"));
+
+    list.Add(new TObjString(
+        "CREATE TABLE MyMagic.RawFile ("
+        "  fRawFileKEY        INT UNSIGNED PRIMARY KEY,"
+        "  fRawFileName       VARCHAR(64)           NOT NULL UNIQUE," // NULL means - Not in Wuerzburg!
+        "  fFilePathKEY       SMALLINT UNSIGNED     NOT NULL"
+        ")"));
+
+    list.Add(new TObjString(
+         "CREATE TABLE MyMagic.RepFile ("
+         "  fRepFileKEY        INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,"
+         "  fRepFileName       VARCHAR(64)          NOT NULL UNIQUE,"           // NULL means - Not in Wuerzburg!
+         "  fFilePathKEY       SMALLINT UNSIGNED    NOT NULL"
+         ")"));
+
+    list.Add(new TObjString(
+         "CREATE TABLE MyMagic.DccFile ("
+         "  fDccFileKEY        INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,"
+         "  fDccFileName       VARCHAR(64)          NOT NULL UNIQUE,"           // NULL means - Not in Wuerzburg!
+         "  fFilePathKEY       SMALLINT UNSIGNED    NOT NULL"
+         ")"));
+
+    list.Add(new TObjString(
+         "CREATE TABLE MyMagic.FilePath ("
+         "  fFilePathKEY       SMALLINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,"
+         "  fFilePathName      VARCHAR(255)         NOT NULL UNIQUE,"
+         "  fFilePath          VARCHAR(255)         NOT NULL UNIQUE"
+         ") MAX_ROWS=65536"));
+
+    list.Add(CreateKeyTable("L1TriggerTable"));
+    list.Add(CreateKeyTable("L2TriggerTable"));
+    list.Add(CreateKeyTable("HvSettings"));
+//    list.Add(CreateKeyTable("ExcludedFDA"));
+    list.Add(CreateKeyTable("ManuallyChanged"));
+    list.Add(CreateKeyTable("TestFlag"));
+    list.Add(CreateKeyTable("LightConditions"));
+    list.Add(CreateKeyTable("CalibrationScript"));
+    list.Add(CreateKeyTable("DiscriminatorThresholdTable"));
+    list.Add(CreateKeyTable("TriggerDelayTable"));
+
+    list.Add(new TObjString(
+         "CREATE TABLE MyMagic.%s ("
+         "  fExcludedFDAKEY        SMALLINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,"
+         "  fExcludedFDAImportance SMALLINT UNSIGNED        NULL,"
+         "  fExcludedFDAAutomatic  ENUM("yes","no")         NULL,"
+         "  fExcludedFDAName       VARCHAR(255)         NOT NULL UNIQUE,"
+         "  fExcludedFDA           VARCHAR(255)             NULL"
+         ") MAX_ROWS=65536"));
+
+
+/*
+    list.Add(new TObjString(
+         "CREATE TABLE MyMagic.TriggerTable ("
+         "  fTriggerTableKEY   SMALLINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,"
+         "  fTriggerTableName  VARCHAR(255)         NOT NULL UNIQUE,"
+         "  fTriggerTable      VARCHAR(255)             NULL"
+         ") MAX_ROWS=65536"));
+
+    list.Add(new TObjString(
+         "CREATE TABLE MyMagic.HvSettings ("
+         "  fHvSettingsKEY     SMALLINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,"
+         "  fHvSettingsName    VARCHAR(255)         NOT NULL UNIQUE,"
+         "  fHvSettings        VARCHAR(255)             NULL"
+         ") MAX_ROWS=65536"));
+
+    list.Add(new TObjString(
+         "CREATE TABLE MyMagic.ExcludedFDA ("
+         "  fExcludedFDAKEY    SMALLINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,"
+         "  fExcludedFDAName   VARCHAR(255)         NOT NULL UNIQUE,"
+         "  fExcludedFDA       VARCHAR(255)             NULL"
+         ") MAX_ROWS=65536"));
+ 
+    list.Add(new TObjString(
+         "CREATE TABLE MyMagic.ManuallyChanged ("
+         "  fManuallyChangedKEY    SMALLINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,"
+         "  fManuallyChangedName   VARCHAR(255)         NOT NULL UNIQUE,"
+         "  fManuallyChanged       VARCHAR(255)             NULL"
+         ") MAX_ROWS=65536"));
+ */
+    list.Add(new TObjString(
+         "CREATE TABLE MyMagic.Changes ("
+         "  fChangesKEY        INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,"
+         "  fTimeStamp         TIMESTAMP,"
+         "  fTableName         VARCHAR(64)          NOT NULL,"
+         "  fRowKEY            INT UNSIGNED         NOT NULL,"
+         "  fColumnName        VARCHAR(64)          NOT NULL,"
+         "  fDescription       VARCHAR(255)         NOT NULL"
+         ")"));
+
+    list.Add(new TObjString(
+         "CREATE TABLE MyMagic.Comments ("
+         "  fCommentsKEY        INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,"
+         "  fCommentsName       VARCHAR(255)         NOT NULL,",
+         "  fRunDataKEY         INT UNSIGNED         NOT NULL"
+         ")"));
+
+    list.Add(new TObjString(
+         "CREATE TABLE MyMagic.RunBook ("
+         "  fRunBookKEY        INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,"
+         "  fRunBookDate       DATETIME              NOT NULL,",
+         "  fRunBookText       TEXT                  NOT NULL"
+         ")"));
+
+    list.Add(new TObjString(
+         "CREATE TABLE MyMagic.Sequences ("
+         "  fSequenceFirst     INT       UNSIGNED   PRIMARY KEY, "
+         "  fSequenceLast      INT       UNSIGNED   NOT NULL UNIQUE, "
+         "  fProjectKEY        SMALLINT  UNSIGNED   NOT NULL,"
+         "  fSourceKEY         SMALLINT  UNSIGNED   NOT NULL,"
+         "  fNumEvents         MEDIUMINT UNSIGNED   NOT NULL,"
+         "  fRunTime           SMALLINT  UNSIGNED   NOT NULL,"
+         "  fRunStart          DATETIME             NOT NULL,"
+         "  fZenithDistanceMin TINYINT                  NULL,"
+         "  fZenithDistanceMax TINYINT                  NULL,"
+         "  fAzimuthMin        SMALLINT                 NULL,"
+         "  fAzimuthMax        SMALLINT                 NULL,"
+         "  fL1TriggerTableKEY SMALLINT  UNSIGNED   NOT NULL,";
+    query +=
+         "  fL2TriggerTableKEY SMALLINT  UNSIGNED   NOT NULL,"
+         "  fHvSettingsKEY     SMALLINT  UNSIGNED   NOT NULL,"
+         "  fManuallyChanged   SMALLINT  UNSIGNED   NOT NULL,"
+         "  fLastUpdate                      TIMESTAMP"                              // COMMENT('Time of last change'),";
+         "  fTestFlagKEY                     SMALLINT  UNSIGNED   NOT NULL,"
+         "  fLightConditionsKEY              SMALLINT  UNSIGNED   NOT NULL,"
+         "  fDiscriminatorThresholdTableKEY  SMALLINT  UNSIGNED   NOT NULL,"
+         "  fTriggerDelayTableKEY            SMALLINT  UNSIGNED   NOT NULL,"
+         ")";
+
+    list.Add(new TObjString(
+         "CREATE TABLE MyMagic.Calibration ("
+         "  fSequenceFirst      INT        UNSIGNED   PRIMARY KEY, "
+         "  fUnsuitableInner    SMALLINT   UNSIGNED   NOT NULL, "
+         "  fUnsuitableOuter    SMALLINT   UNSIGNED   NOT NULL, "
+         "  fUnreliableInner    SMALLINT   UNSIGNED   NOT NULL,"
+         "  fUnreliableOuter    SMALLINT   UNSIGNED   NOT NULL,"
+         "  fIsolatedInner      SMALLINT   UNSIGNED   NOT NULL,"
+         "  fIsolatedOuter      SMALLINT   UNSIGNED   NOT NULL,"
+         "  fIsolatedMaxCluster SMALLINT   UNSIGNED   NOT NULL,"
+         "  fMeanPedRmsInner    FLOAT(5,1)            NOT NULL,"
+         "  fMeanPedRmsOuter    FLOAT(5,1)            NOT NULL,"
+         "  fLastUpdate         TIMESTAMP"
+         ")"));
+
+    list.Add(new TObjString(
+         "CREATE TABLE MyMagic.SequenceBuildStatus ("
+         "  fDate                  DATE                 PRIMARY KEY, "
+         "  fCCFilled              DATETIME             NULL,"
+         "  fExclusionsDone        DATETIME             NULL,"
+         "  fSequenceEntriesBuilt  DATETIME             NULL,"
+         ")";
+
+    list.Add(new TObjString(
+         "CREATE TABLE MyMagic.RunProcessStatus ("
+         "  fRunNumber             INT       UNSIGNED   PRIMARY KEY, "
+         "  fCCFileAvail           DATETIME             NULL,"
+         "  fCaCoFileAvail         DATETIME             NULL,"
+         "  fCaCoFileFound         INT       UNSIGNED   NULL,"
+         "  fRawFileAvail          DATETIME             NULL,"
+         "  fFillDotRaw            DATETIME             NULL,"
+         "  fTimingCorrection      DATETIME             NULL,"
+         "  fMerpp                 DATETIME             NULL,"
+         "  fMerppCCUpdate         DATETIME             NULL,"
+         "  fMerppCaCoUpdate       DATETIME             NULL"
+         ")";
+
+    list.Add(new TObjString(
+         "CREATE TABLE MyMagic.SequenceProcessStatus ("
+         "  fSequenceFirst         INT       UNSIGNED   PRIMARY KEY, "
+         "  fSequenceFileWritten   DATETIME             NULL,"
+         "  fFilesAvail            DATETIME             NULL,"
+         "  fCallisto              DATETIME             NULL,"
+         "  fFillCallisto          DATETIME             NULL,"
+         "  fStar                  DATETIME             NULL,"
+         "  fFillStar              DATETIME             NULL"
+         ")";
+
+    TSQLResult *res;
+
+    TSQLServer *serv = TSQLServer::Connect("mysql://localhost:3306", "hercules", "d99swMT!");
+    if (!serv)
+        return;
+
+    res = serv->DropDataBase("MyMagic");
+    res = serv->CreateDataBase("MyMagic");
+    if (res)
+    {
+        cout << "Error creating Data Base!" << endl;
+        return;
+    }
+
+    TIter Next(&list);
+    TObjString *str;
+
+    cout << "Creating tables..." << endl;
+
+    while ((str=(TObjString*)Next()))
+    {
+        TString q(str->GetString());
+
+        Int_t f = q.First('(');
+        TString out = q(0, f);
+        cout << " - " << out << "... " << flush;
+        res = serv->Query(q);
+        cout << (res==0 ? "ERROR!" : "Ok.") << endl;
+        if (res)
+            delete res;
+    }
+
+    serv->Close();
+    delete serv;
+}
+
+void DisplayMagicDataBase()
+{
+    TSQLServer *serv = TSQLServer::Connect("mysql://localhost:3306", "hercules", "d99swMT!");
+    if (!serv)
+        return;
+
+    res = serv->GetColumns("MyMagic", "RunData");
+    if (res)
+        Print(res);
+    res = serv->GetColumns("MyMagic", "RunType");
+    if (res)
+        Print(res);
+    res = serv->GetColumns("MyMagic", "MagicNumber");
+    if (res)
+        Print(res);
+    res = serv->GetColumns("MyMagic", "Project");
+    if (res)
+        Print(res);
+    res = serv->GetColumns("MyMagic", "Source");
+    if (res)
+        Print(res);
+    res = serv->GetColumns("MyMagic", "TriggerTable");
+    if (res)
+        Print(res);
+    res = serv->GetColumns("MyMagic", "HvSettings");
+    if (res)
+        Print(res);
+
+    serv->Close();
+}
+
+Bool_t ExistStr(TSQLServer *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)
+        return kFALSE;
+    delete res;
+
+    TSQLRow *row;
+
+    while (row=res->Next())
+    {
+        if ((*row)[0])
+            return kTRUE;
+    }
+
+    return kFALSE;
+}
+/*
+void LoadSourceNames(const char *fname)
+{
+    TSQLServer *serv = TSQLServer::Connect("mysql://localhost:3306", "hercules", "d99swMT!");
+    if (!serv)
+        return;
+
+    ifstream fin(fname);
+    if (!fin)
+    {
+        cout << "Cannot open " << fname << endl;
+        return;
+    }
+
+    while (1)
+    {
+        TString query, name;
+
+        name.ReadLine(fin);
+        if (!fin)
+            break;
+
+        if (ExistStr(serv, "fSourceName", "MyMagic.Source", name))
+        {
+            cout << "Entry " << name << " exists." << endl;
+            continue;
+        }
+
+        query  = "INSERT MyMagic.Source SET ";
+        query += "  fSourceName='";
+        query += name;
+        query += "', fSourceTypeKEY=1";
+        if (!serv->Query(query))
+        {
+            cout << query << " - FAILED!" << endl;
+            return;
+        }
+    }
+
+    serv->Close();
+}
+
+void LoadProjectNames(const char *fname)
+{
+    TSQLServer *serv = TSQLServer::Connect("mysql://localhost:3306", "hercules", "d99swMT!");
+    if (!serv)
+        return;
+
+    ifstream fin(fname);
+    if (!fin)
+    {
+        cout << "Cannot open " << fname << endl;
+        return;
+    }
+
+    while (1)
+    {
+        TString query, name;
+
+        name.ReadLine(fin);
+        if (!fin)
+            break;
+
+        if (ExistStr(serv, "fProjectName", "MyMagic.Project", name))
+        {
+            cout << "Entry " << name << " exists." << endl;
+            continue;
+        }
+
+        query  = "INSERT MyMagic.Project SET ";
+        query += "  fProjectName='";
+        query += name;
+        query += "', fProject='AUTO: ";
+        query += name;
+        query += "'";
+        if (!serv->Query(query))
+        {
+            cout << query << " - FAILED!" << endl;
+            return;
+        }
+    }
+
+    serv->Close();
+}
+
+void LoadTriggerTableNames(const char *fname)
+{
+    TSQLServer *serv = TSQLServer::Connect("mysql://localhost:3306", "hercules", "d99swMT!");
+    if (!serv)
+        return;
+
+    ifstream fin(fname);
+    if (!fin)
+    {
+        cout << "Cannot open " << fname << endl;
+        return;
+    }
+
+    while (1)
+    {
+        TString query, name;
+
+        name.ReadLine(fin);
+        if (!fin)
+            break;
+
+        if (ExistStr(serv, "fTriggerTableName", "MyMagic.TriggerTable", name))
+        {
+            cout << "Entry " << name << " exists." << endl;
+            continue;
+        }
+
+        query  = "INSERT MyMagic.TriggerTable SET ";
+        query += "  fTriggerTableName='";
+        query += name;
+        query += "'";
+        if (!serv->Query(query))
+        {
+            cout << query << " - FAILED!" << endl;
+            return;
+        }
+    }
+
+    serv->Close();
+}
+*/
+void setupdb()
+{
+    CreateMagicDataBase();
+    CreatePrimaryEntries();
+    //LoadSourceNames("sourcenames.txt");
+    //LoadProjectNames("projectnames.txt");
+    //LoadTriggerTableNames("triggertablenames.txt");
+
+
+    return;
+
+    //TSQLServer *serv = TSQLServer::Connect("mysql://magic:3306", "root", "marWin");
+    //TSQLServer *serv = TSQLServer::Connect("mysql://localhost:3306", "database", "ImM9G1CD8");
+    TSQLServer *serv = TSQLServer::Connect("mysql://localhost:3306", "hercules", "d99swMT!");
+    if (!serv)
+        return;
+
+    cout << "ServerInfo: " << serv->ServerInfo() << endl;
+    cout << "DBMS:       " << serv->GetDBMS() << endl;
+    cout << "Host:       " << serv->GetHost() << endl;
+    cout << "Port:       " << serv->GetPort() << endl;
+
+    TSQLResult *res;
+
+    cout << endl;
+
+    res = serv->GetDataBases();
+    if (res)
+        Print(res);
+
+    serv->Close();
+    /*
+        TList list;
+    if (!list.FindObject(triggertablename))
+    {
+        TNamed *name = new TNamed(triggertablename, "");
+        list.Add(name);
+    }
+
+    list.Print();
+    */
+}
Index: trunk/MagicSoft/Mars/datacenter/macros/writesequencefile.C
===================================================================
--- trunk/MagicSoft/Mars/datacenter/macros/writesequencefile.C	(revision 6933)
+++ trunk/MagicSoft/Mars/datacenter/macros/writesequencefile.C	(revision 6933)
@@ -0,0 +1,343 @@
+/* ======================================================================== *\
+!
+! *
+! * 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, 08/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
+!   Author(s): Daniela Dorner, 08/2004 <mailto:dorner@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2004
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// writesequencefile.C
+// ===================
+//
+// reads the sequence information from the database
+// and writes it into a txt file
+//
+/////////////////////////////////////////////////////////////////////////////
+#include <iostream>
+#include <iomanip>
+#include <fstream>
+
+#include <MSQLServer.h>
+#include <TSQLRow.h>
+#include <TSQLResult.h>
+
+#include <TEnv.h>
+#include <TMath.h>
+#include <TRegexp.h>
+
+#include <MAstro.h>
+#include <MTime.h>
+#include <MDirIter.h>
+
+using namespace std;
+
+Bool_t GetAllRuns(MSQLServer &serv, ofstream &fout, TString query)
+{
+    TSQLResult *res = serv.Query(query);
+    if (!res)
+        return kFALSE;
+
+    TSQLRow *row=0;
+
+    Int_t cnt = 0;
+
+    fout << "Runs:";
+    while ((row = res->Next()))
+    {
+        fout << " " << (*row)[0];
+        cnt++;
+    }
+    fout << endl;
+
+    delete res;
+
+    if (cnt==0)
+    {
+        cout << "ERROR - No runs belonging to this sequence found." << endl;
+        return kFALSE;
+    }
+
+    return kTRUE;
+}
+
+Bool_t GetCalRuns(MSQLServer &serv, ofstream &fout, TString query, MTime *t)
+{
+    TSQLResult *res = serv.Query(query);
+    if (!res)
+        return kFALSE;
+
+    Int_t first = 0;
+    Int_t cnt   = 0;
+
+    fout << "CalRuns:";
+    TSQLRow *row=0;
+    while ((row = res->Next()))
+        if ((*row)[1][0]=='4')
+        {
+            fout << " " << (*row)[0];
+            cnt++;
+
+            if (!first)
+            {
+                t[0].SetSqlDateTime((*row)[2]);
+                first = 1;
+            }
+            t[1].SetSqlDateTime((*row)[3]);
+        }
+    fout << endl;
+
+    delete res;
+
+    if (cnt==0)
+    {
+        cout << "ERROR - No calibration runs belonging to this sequence found." << endl;
+        return kFALSE;
+    }
+
+    return kTRUE;
+}
+
+Bool_t GetPedRuns(MSQLServer &serv, ofstream &fout, TString query, MTime *t)
+{
+    Int_t cnt = 0;
+
+    fout << "PedRuns:";
+
+    Int_t tot = 0;
+
+    while (tot<1000)
+    {
+        TSQLResult *res = serv.Query(query);
+        if (!res)
+            return kFALSE;
+
+        Int_t idx = 0;
+        Int_t n = 0;
+        Double_t diff = 1e35;
+        MTime start, stop;
+
+        TSQLRow *row=0;
+        while ((row=res->Next()))
+        {
+            if ((*row)[1][0]=='3' || (cnt>1 && idx==0 && (*row)[1][0]=='2'))
+            {
+                MTime t0, t1;
+                t0.SetSqlDateTime((*row)[2]);
+                t1.SetSqlDateTime((*row)[3]);
+
+                if ((Double_t)t[0]-(Double_t)t1<diff && t[0]>t1)
+                {
+                    diff = (Double_t)t[0]-(Double_t)t1;
+                    idx = atoi((*row)[0]);
+                    n = atoi((*row)[4]);
+                    start = t0;
+                    stop = t1;
+                }
+                if ((Double_t)t0-(Double_t)t[1]<diff && t0>t[1])
+                {
+                    diff = (Double_t)t0-(Double_t)t[1];
+                    idx = atoi((*row)[0]);
+                    n = atoi((*row)[4]);
+                    start = t0;
+                    stop = t1;
+                }
+            }
+        }
+
+        tot += n;
+        if (idx!=0)
+            fout << " " << idx;
+        cnt ++;
+
+        delete res;
+
+        if (start<t[0])
+            t[0] = start;
+        if (stop>t[1])
+            t[1] = stop;
+    }
+
+    fout << endl;
+
+    if (cnt==0)
+    {
+        cout << "ERROR - No pedestal (data) runs belonging to this sequence found." << endl;
+        return kFALSE;
+    }
+
+    return kTRUE;
+}
+
+Bool_t GetDatRuns(MSQLServer &serv, ofstream &fout, TString query)
+{
+    TSQLResult *res = serv.Query(query);
+    if (!res)
+        return kFALSE;
+
+    Int_t cnt=0;
+
+    fout << "DatRuns:";
+    TSQLRow *row=0;
+    while ((row = res->Next()))
+        if ((*row)[1][0]=='2')
+        {
+            fout << " " << (*row)[0];
+            cnt++;
+        }
+    fout << endl;
+
+    delete res;
+
+    if (cnt==0)
+    {
+        cout << "ERROR - No data runs belonging to this sequence found." << endl;
+        return kFALSE;
+    }
+
+    return kTRUE;
+}
+
+TString GetName(MSQLServer &serv, const char *col, const char *n)
+{
+    TString query(Form("SELECT f%sName FROM MyMagic.%s WHERE f%sKEY=%s",
+                       col, col, col, n));
+    
+    TSQLResult *res = serv.Query(query);
+    if (!res)
+    {
+        cout << "ERROR - Resolving " << col << " failed! " << endl;
+        return "";
+    }
+
+    TSQLRow *row = res->Next();
+    return (*row)[0];
+}
+
+Bool_t GetSequence(MSQLServer &serv, TSQLRow &data)
+{
+    UShort_t y;
+    Byte_t m, d;
+
+    MTime time;
+    time.SetSqlDateTime(data[8]);
+    time.GetDateOfSunrise(y, m, d);
+
+    TString date = Form("%04d-%02d-%02d", y, (int)m, (int)d);
+
+    Int_t period = MAstro::GetMagicPeriod(time.GetMjd());
+
+    TString str[6];
+    str[0] = GetName(serv, "Project",         data[2]);
+    str[1] = GetName(serv, "Source",          data[3]);
+    str[2] = GetName(serv, "L1TriggerTable",  data[4]);
+    str[3] = GetName(serv, "L2TriggerTable",  data[5]);
+    str[4] = GetName(serv, "HvSettings",      data[6]);
+    str[5] = GetName(serv, "LightConditions", data[7]);
+
+    if (str[0].IsNull() || str[1].IsNull() || str[2].IsNull() || str[3].IsNull() || str[4].IsNull() || str[5].IsNull())
+        return kFALSE;
+
+    TString fname(Form("/mnt/stk01/sequences/%04d/sequence%08d.txt", atoi(data[0])/10000, atoi(data[0])));
+    cout << "Creating " << fname << "..." << flush;
+
+    ofstream fout(fname);
+    if (!fout)
+    {
+        cout << "ERROR - Cannot open file." << endl;
+        return kFALSE;
+    }
+
+    fout << "Sequence:        " << data[0] << endl;
+    fout << "Period:          " << period  << endl;
+    fout << "Night:           " << date    << endl;
+    fout << "LightConditions: " << str[5] << endl;
+    fout << endl;
+    fout << "Start:           " << data[8] << endl;
+    fout << "LastRun:         " << data[1] << endl;
+    fout << "Project:         " << str[0]  << endl;
+    fout << "Source:          " << str[1]  << endl;
+    fout << "L1TriggerTable:  " << str[2]  << endl;
+    fout << "L2TriggerTable:  " << str[3]  << endl;
+    fout << "HvSettings:      " << str[4]  << endl;
+    fout << "NumEvents:       " << data[9] << endl;
+    fout << endl;
+
+    TString query(Form("SELECT fRunNumber, fRunTypeKEY, fRunStart, fRunStop, fNumEvents"
+                       " FROM MyMagic.RunData WHERE fSequenceFirst=%s AND fExcludedFDAKEY=1"
+                       " ORDER BY fRunNumber",
+                       data[0]));
+
+    if (!GetAllRuns(serv, fout, query))
+        return kFALSE;
+
+    fout << endl;
+
+    MTime t[2];
+    if (!GetCalRuns(serv, fout, query, t))
+        return kFALSE;
+    if (!GetPedRuns(serv, fout, query, t))
+        return kFALSE;
+    if (!GetDatRuns(serv, fout, query))
+        return kFALSE;
+
+    fout << endl;
+
+    cout << " done <Nevts=" << data[8] << ">" << endl;
+
+    return kTRUE;
+}
+
+// This tool will work from Period017 (2004_05_17) on...
+int writesequencefile(Int_t sequno)
+{
+    TEnv env("sql.rc");
+
+    MSQLServer serv(env);
+    if (!serv.IsConnected())
+    {
+        cout << "ERROR - Connection to database failed." << endl;
+        return 0;
+    }
+
+    cout << "writesequencefile" << endl;
+    cout << "-----------------" << endl;
+    cout << endl;
+    cout << "Connected to " << serv.GetName() << endl;
+    cout << endl;
+
+    TString query(Form("SELECT fSequenceFirst, fSequenceLast, fProjectKEY, fSourceKEY,"
+                       " fL1TriggerTableKEY, fL2TriggerTableKEY, fHvSettingsKEY, "
+                       " fLightConditionsKEY, fRunStart, fNumEvents"
+                       " FROM MyMagic.Sequences WHERE fSequenceFirst=%d", sequno));
+    TSQLResult *res = serv.Query(query);
+
+    TSQLRow *row = 0;
+    while ((row = res->Next()))
+        if (!GetSequence(serv, *row))
+            return 0;
+
+    delete res;
+
+    cout << endl;
+
+    return 1;
+}
Index: trunk/MagicSoft/Mars/steps.rc
===================================================================
--- trunk/MagicSoft/Mars/steps.rc	(revision 6933)
+++ trunk/MagicSoft/Mars/steps.rc	(revision 6933)
@@ -0,0 +1,165 @@
+#primaries:
+SequenceBuildStatus.Primary: fDate
+#SequenceBuildStatus.TimerTable: -
+RunProcessStatus.Primary: fRunNumber
+RunProcessStatus.TimerTable: RunData
+SequenceProcessStatus.Primary: fSequenceFirst
+SequenceProcessStatus.TimerTable: Sequences
+
+
+#--------------------------------------------------------------------
+
+
+#SequenceBuildStatus.fDate: 
+SequenceBuildStatus.fDate.Default: yes
+#SequenceBuildStatus.fDate.Needs: -
+SequenceBuildStatus.fDate.Influences: SequenceBuildStatus.fExclusionsDone SequenceBuildStatus.fSequenceEntriesBuilt 
+SequenceBuildStatus.fDate.Reset: yes
+
+
+#SequenceBuildStatus.fCCFilled:
+SequenceBuildStatus.fCCFilled.Default: no
+SequenceBuildStatus.fCCFilled.Needs: SequenceBuildStatus.fDate
+SequenceBuildStatus.fCCFilled.Influences: SequenceBuildStatus.fExclusionsDone SequenceBuildStatus.fSequenceEntriesBuilt 
+SequenceBuildStatus.fCCFilled.Reset: yes
+
+
+#SequenceBuildStatus.fExclusionsDone.: 
+SequenceBuildStatus.fExclusionsDone.Default: no
+SequenceBuildStatus.fExclusionsDone.Needs: SequenceBuildStatus.fCCFilled 
+SequenceBuildStatus.fExclusionsDone.Influences: SequenceBuildStatus.fSequenceEntriesBuilt 
+SequenceBuildStatus.fExclusionsDone.Reset: yes
+
+
+#SequenceBuildStatus.fSequenceEntriesBuilt.: 
+SequenceBuildStatus.fSequenceEntriesBuilt.Default: no
+SequenceBuildStatus.fSequenceEntriesBuilt.Needs: SequenceBuildStatus.fCCFilled SequenceBuildStatus.fExclusionsDone 
+#SequenceBuildStatus.fSequenceEntriesBuilt.Influences: 
+SequenceBuildStatus.fSequenceEntriesBuilt.Reset: yes
+
+
+#--------------------------------------------------------------------
+
+
+#RunProcessStatus.fRunNumber.: 
+RunProcessStatus.fRunNumber.Default: yes
+#RunProcessStatus.fRunNumber.Needs: - 
+RunProcessStatus.fRunNumber.Influences: RunProcessStatus.fCCFileAvail RunProcessStatus.fCaCoFileAvail RunProcessStatus.fCaCoFileFound RunProcessStatus.fRawFileAvail RunProcessStatus.fMerpp RunProcessStatus.fMerppCCUpdate RunProcessStatus.fMerppCaCoUpdate
+RunProcessStatus.fRunNumber.Reset: yes 
+
+
+#RunProcessStatus.fRawFileAvail: 
+RunProcessStatus.fRawFileAvail.Default: no
+#RunProcessStatus.fRawFileAvail.Needs: - 
+#RunProcessStatus.fRawFileAvail.Influences: RunProcessStatus.fTimingCorrection RunProcessStatus.fMerpp RunProcessStatus.fMerppCCUpdate RunProcessStatus.fMerppCaCoUpdate
+RunProcessStatus.fRawFileAvail.Reset: yes 
+
+
+#RunProcessStatus.fCCFileAvail.: 
+RunProcessStatus.fCCFileAvail.Default: no
+#RunProcessStatus.fCCFileAvail.Needs: - 
+#RunProcessStatus.fCCFileAvail.Influences: RunProcessStatus.fMerppCCUpdate RunProcessStatus.fMerppCaCoUpdate
+RunProcessStatus.fCCFileAvail.Reset: yes 
+
+
+#RunProcessStatus.fCaCoFileAvail.: 
+RunProcessStatus.fCaCoFileAvail.Default: no
+#RunProcessStatus.fCaCoFileAvail.Needs: - 
+#RunProcessStatus.fCaCoFileAvail.Influences: RunProcessStatus.fMerppCaCoUpdate
+RunProcessStatus.fCaCoFileAvail.Reset: yes 
+
+
+#RunProcessStatus.fCaCoFileFound.: 
+RunProcessStatus.fCaCoFileFound.Default: no
+#RunProcessStatus.fCaCoFileFound.Needs: - 
+#RunProcessStatus.fCaCoFileFound.Influences: RunProcessStatus.fMerppCaCoUpdate
+RunProcessStatus.fCaCoFileFound.Reset: yes 
+
+
+#RunProcessStatus.fFillDotRaw.: 
+RunProcessStatus.fFillDotRaw.Default: no
+RunProcessStatus.fFillDotRaw.Needs: RunProcessStatus.fRawFileAvail
+#RunProcessStatus.fFillDotRaw.Influences: -
+RunProcessStatus.fFillDotRaw.Reset: yes 
+
+
+#RunProcessStatus.fTimingCorrection.: 
+RunProcessStatus.fTimingCorrection.Default: check
+RunProcessStatus.fTimingCorrection.Needs: RunProcessStatus.fRawFileAvail
+RunProcessStatus.fTimingCorrection.Influences: RunProcessStatus.fMerpp RunProcessStatus.fMerppCCUpdate RunProcessStatus.fMerppCaCoUpdate
+RunProcessStatus.fTimingCorrection.Reset: yes 
+
+
+#RunProcessStatus.fMerpp.: 
+RunProcessStatus.fMerpp.Default: no
+RunProcessStatus.fMerpp.Needs: RunProcessStatus.fRawFileAvail RunProcessStatus.fTimingCorrection
+RunProcessStatus.fMerpp.Influences: RunProcessStatus.fMerppCCUpdate RunProcessStatus.fMerppCaCoUpdate
+RunProcessStatus.fMerpp.Reset: yes 
+
+
+#RunProcessStatus.fMerppCCUpdate.: 
+RunProcessStatus.fMerppCCUpdate.Default: no
+RunProcessStatus.fMerppCCUpdate.Needs: RunProcessStatus.fRawFileAvail RunProcessStatus.fMerpp RunProcessStatus.fTimingCorrection RunProcessStatus.fCCFileAvail
+RunProcessStatus.fMerppCCUpdate.Influences: RunProcessStatus.fMerppCaCoUpdate
+RunProcessStatus.fMerppCCUpdate.Reset: no
+
+
+#RunProcessStatus.fMerppCaCoUpdate.: 
+RunProcessStatus.fMerppCaCoUpdate.Default: no 
+RunProcessStatus.fMerppCaCoUpdate.Needs: RunProcessStatus.fRawFileAvail RunProcessStatus.fMerpp RunProcessStatus.fTimingCorrection RunProcessStatus.fCCFileAvail RunProcessStatus.fMerppCCUpdate RunProcessStatus.fCaCoFileFound
+#RunProcessStatus.fMerppCaCoUpdate.Influences: - 
+RunProcessStatus.fMerppCaCoUpdate.Reset: no
+
+
+#--------------------------------------------------------------------
+
+
+#SequenceProcessStatus.fSequenceFirst.: 
+SequenceProcessStatus.fSequenceFirst.Default: yes
+#SequenceProcessStatus.fSequenceFirst.Needs: -
+SequenceProcessStatus.fSequenceFirst.Influences: SequenceProcessStatus.fSequenceFileWritten SequenceProcessStatus.fAllFilesAvail SequenceProcessStatus.fCallisto SequenceProcessStatus.fFillCallisto SequenceProcessStatus.fStar SequenceProcessStatus.fFillStar
+SequenceProcessStatus.fSequenceFirst.Reset: yes
+
+
+#SequenceProcessStatus.fSequenceFileWritten.: 
+SequenceProcessStatus.fSequenceFileWritten.Default: no
+SequenceProcessStatus.fSequenceFileWritten.Needs: SequenceProcessStatus.fSequenceFirst
+SequenceProcessStatus.fSequenceFileWritten.Influences: SequenceProcessStatus.fCallisto SequenceProcessStatus.fFillCallisto SequenceProcessStatus.fStar SequenceProcessStatus.fFillStar
+SequenceProcessStatus.fSequenceFileWritten.Reset: yes 
+
+
+#SequenceProcessStatus.fAllFilesAvail.: 
+SequenceProcessStatus.fAllFilesAvail.Default: no
+SequenceProcessStatus.fAllFilesAvail.Needs: SequenceProcessStatus.fSequenceFileWritten
+SequenceProcessStatus.fAllFilesAvail.Influences: SequenceProcessStatus.fCallisto SequenceProcessStatus.fFillCallisto SequenceProcessStatus.fStar SequenceProcessStatus.fFillStar
+SequenceProcessStatus.fAllFilesAvail.Reset: yes
+
+
+#SequenceProcessStatus.fCallisto.: 
+SequenceProcessStatus.fCallisto.Default: no
+SequenceProcessStatus.fCallisto.Needs: SequenceProcessStatus.fSequenceFileWritten SequenceProcessStatus.fAllFilesAvail
+SequenceProcessStatus.fCallisto.Influences: SequenceProcessStatus.fFillCallisto SequenceProcessStatus.fStar SequenceProcessStatus.fFillStar
+SequenceProcessStatus.fCallisto.Reset: yes
+
+
+#SequenceProcessStatus.fFillCallisto.: 
+SequenceProcessStatus.fFillCallisto.Default: no
+SequenceProcessStatus.fFillCallisto.Needs: SequenceProcessStatus.fSequenceFileWritten SequenceProcessStatus.fAllFilesAvail SequenceProcessStatus.fCallisto
+#SequenceProcessStatus.fFillCallisto.Influences: -
+SequenceProcessStatus.fFillCallisto.Reset: yes
+
+
+#SequenceProcessStatus.fStar.: 
+SequenceProcessStatus.fStar.Default: no
+SequenceProcessStatus.fStar.Needs: SequenceProcessStatus.fSequenceFileWritten SequenceProcessStatus.fAllFilesAvail SequenceProcessStatus.fCallisto
+SequenceProcessStatus.fStar.Influences: SequenceProcessStatus.fFillStar
+SequenceProcessStatus.fStar.Reset: yes
+
+
+#SequenceProcessStatus.fFillStar.: 
+SequenceProcessStatus.fFillStar.Default: no
+SequenceProcessStatus.fFillStar.Needs: SequenceProcessStatus.fSequenceFileWritten SequenceProcessStatus.fAllFilesAvail SequenceProcessStatus.fCallisto SequenceProcessStatus.fStar
+#SequenceProcessStatus.fFillStar.Influences: -
+SequenceProcessStatus.fFillStar.Reset: yes
+
+
