Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 7982)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 7983)
@@ -43,4 +43,12 @@
    * ganymed_onoff.rc, ganymed_wobble.rc:
      - updated with comments how to use random forest
+
+   * datacenter/macros/buildsequenceentries.C:
+     - updated with a completely redesigned algorithm and completly
+       redisigned code
+
+   * datacenter/macros/writesequencefile.C:
+     - the new simplified version doesn't take the number of pedestal 
+       events anymore into account.
 
 
Index: /trunk/MagicSoft/Mars/NEWS
===================================================================
--- /trunk/MagicSoft/Mars/NEWS	(revision 7982)
+++ /trunk/MagicSoft/Mars/NEWS	(revision 7983)
@@ -2,4 +2,14 @@
 
  *** Version  <cvs>
+
+   - general: The algorithm to build seqeunces has been redesigned
+     completly. It is now more flexible in terms of a resource file
+     resources/sequences.rc which can be used to partly overwrite
+     the default algorithm and defined the important part of the
+     algorithm. It also takes correctly into account several ways
+     of taking wobble-data. Currently the new algorithm doesn't take
+     the number of pedestal events anymore into account (so a sequence
+     could have much less than 1000 pedestal events and data runs are
+     no-more used instead)
 
    - general: a lot of small changes to make the code compatible with
Index: /trunk/MagicSoft/Mars/datacenter/macros/writesequencefile.C
===================================================================
--- /trunk/MagicSoft/Mars/datacenter/macros/writesequencefile.C	(revision 7982)
+++ /trunk/MagicSoft/Mars/datacenter/macros/writesequencefile.C	(revision 7983)
@@ -46,5 +46,4 @@
 #include <fstream>
 
-#include <MSQLServer.h>
 #include <TSQLRow.h>
 #include <TSQLResult.h>
@@ -54,11 +53,13 @@
 #include <TRegexp.h>
 
-#include <MAstro.h>
-#include <MTime.h>
-#include <MDirIter.h>
+#include "MAstro.h"
+#include "MTime.h"
+#include "MDirIter.h"
+
+#include "MSQLServer.h"
 
 using namespace std;
 
-Bool_t GetAllRuns(MSQLServer &serv, ofstream &fout, TString query)
+Bool_t GetRuns(MSQLServer &serv, ofstream &fout, TString query, TString name)
 {
     TSQLResult *res = serv.Query(query);
@@ -66,9 +67,8 @@
         return kFALSE;
 
+    Int_t cnt=0;
+
+    fout << name << ":";
     TSQLRow *row=0;
-
-    Int_t cnt = 0;
-
-    fout << "Runs:";
     while ((row = res->Next()))
     {
@@ -82,142 +82,5 @@
     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;
+        cout << "ERROR - No " << name << " belonging to this sequence found." << endl;
         return kFALSE;
     }
@@ -297,19 +160,24 @@
     TString query(Form("SELECT fRunNumber, fRunTypeKEY, fRunStart, fRunStop, fNumEvents"
                        " FROM RunData WHERE fSequenceFirst=%s AND fExcludedFDAKEY=1"
-                       " ORDER BY fRunNumber",
+                       " AND fRunTypeKEY %%s ORDER BY fRunNumber",
                        data[0]));
 
+
+    TString queryA(Form(query.Data(), "BETWEEN 2 AND 4"));
+    TString queryC(Form(query.Data(), "BETWEEN 4 AND 4"));
+    TString queryD(Form(query.Data(), "BETWEEN 2 AND 2"));
+    TString queryP(Form(query.Data(), "BETWEEN 3 AND 3"));
+
     //write runs into sequence file
-    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))
+    if (!GetRuns(serv, fout, queryA, "Runs"))
+        return kFALSE;
+
+    fout << endl;
+
+    if (!GetRuns(serv, fout, queryC, "CalRuns"))
+        return kFALSE;
+    if (!GetRuns(serv, fout, queryP, "PedRuns"))
+        return kFALSE;
+    if (!GetRuns(serv, fout, queryD, "DatRuns"))
         return kFALSE;
 
