Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 7274)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 7275)
@@ -18,4 +18,14 @@
 
                                                  -*-*- END OF LINE -*-*-
+ 2005/08/08 Daniela Dorner
+
+   * datacenter/macros/buildsequenceentries.C:
+     - fixed some bugs
+     - added deleting of sequences
+
+   * datacenter/macros/resetallruns.C:
+     - fixed small bug
+
+
 
  2005/08/05
Index: /trunk/MagicSoft/Mars/datacenter/macros/buildsequenceentries.C
===================================================================
--- /trunk/MagicSoft/Mars/datacenter/macros/buildsequenceentries.C	(revision 7274)
+++ /trunk/MagicSoft/Mars/datacenter/macros/buildsequenceentries.C	(revision 7275)
@@ -52,4 +52,5 @@
 #include <TRegexp.h>
 #include <TSystem.h>
+#include <TObjString.h>
 
 #include <MTime.h>
@@ -175,5 +176,5 @@
 }
 
-Bool_t CheckSequence(MSQLServer &serv, TString datapath, TString sequpath, Int_t from, Int_t to, Bool_t dummy)
+Int_t CheckSequence(MSQLServer &serv, TString datapath, TString sequpath, Int_t from, Int_t to, Bool_t dummy)
 {
     Int_t rc=0;
@@ -216,5 +217,5 @@
 
         //calibration table
-        query(Form("SELECT fSequenceFirst FROM Calibration WHERE fSequenceFirst BETWEEN %d and %d", from, to));
+        query=Form("SELECT fSequenceFirst FROM Calibration WHERE fSequenceFirst BETWEEN %d and %d", from, to);
         res = serv.Query(query);
         if (!res)
@@ -225,11 +226,10 @@
             if (!DeleteSequence(serv, datapath, sequpath, atoi((*row)[0]), dummy))
                 return -1;
-            else
-                rc=1;
+            rc=1;
         }
         delete res;
 
         //Star table
-        query(Form("SELECT fSequenceFirst FROM Star WHERE fSequenceFirst BETWEEN %d and %d", from, to));
+        query=Form("SELECT fSequenceFirst FROM Star WHERE fSequenceFirst BETWEEN %d and %d", from, to);
         res = serv.Query(query);
         if (!res)
@@ -240,11 +240,10 @@
             if (!DeleteSequence(serv, datapath, sequpath, atoi((*row)[0]), dummy))
                 return -1;
-            else
-                rc=1;
+            rc=1;
         }
         delete res;
 
         //SequenceProcessStatus table
-        query(Form("SELECT fSequenceFirst FROM SequenceProcessStatus WHERE fSequenceFirst BETWEEN %d and %d", from, to));
+        query=Form("SELECT fSequenceFirst FROM SequenceProcessStatus WHERE fSequenceFirst BETWEEN %d and %d", from, to);
         res = serv.Query(query);
         if (!res)
@@ -255,6 +254,5 @@
             if (!DeleteSequence(serv, datapath, sequpath, atoi((*row)[0]), dummy))
                 return -1;
-            else
-                rc=1;
+            rc=1;
         }
         delete res;
@@ -267,6 +265,5 @@
             if (!DeleteSequence(serv, datapath, sequpath, sequences.At(0), dummy))
                 return -1;
-            else
-                rc=1;
+            rc=1;
         }
         else
@@ -275,5 +272,5 @@
 
             //getting olf runs
-            query(Form("SELECT fRunNumber FROM RunData WHERE fSequenceFirst=%d ", from));
+            query=Form("SELECT fRunNumber FROM RunData WHERE fSequenceFirst=%d ", from);
             res = serv.Query(query);
             if (!res)
@@ -292,5 +289,5 @@
 
             //getting new runs
-            query(Form("SELECT fRunNumber FROM RunData WHERE fRunNumber BETWEEN %d and %d AND fExcludedFDAKEY=1", from, to));
+            query=Form("SELECT fRunNumber FROM RunData WHERE fRunNumber BETWEEN %d and %d AND fExcludedFDAKEY=1", from, to);
             res = serv.Query(query);
             if (!res)
@@ -302,6 +299,6 @@
             {
                 count++;
-                oldruns.Set(count);
-                oldruns.AddAt(atoi((*row)[0]), count-1);
+                newruns.Set(count);
+                newruns.AddAt(atoi((*row)[0]), count-1);
             }
             delete res;
@@ -310,9 +307,9 @@
             if (oldruns.GetSize()!=newruns.GetSize())
             {
-                cout << " number of runs is not the same -> deleting sequence " << sequences.At(0) << endl;
+//                cout << " number of runs (" << oldruns.GetSize() << " - " << newruns.GetSize()
+//                    << ") is not the same -> deleting sequence " << sequences.At(0) << endl;
                 if (!DeleteSequence(serv, datapath, sequpath, sequences.At(0), dummy))
                     return -1;
-                else
-                    rc=1;
+                rc=1;
             }
             else
@@ -322,4 +319,5 @@
                 for (Int_t i=0;i<newruns.GetSize();i++)
                 {
+//                    cout << "i: " << i << " - new: " << newruns.At(i) << " - old: " << oldruns.At(i) << endl;
                     if (newruns.At(i)==oldruns.At(i))
                         continue;
@@ -329,6 +327,5 @@
                     if (!DeleteSequence(serv, datapath, sequpath, sequences.At(0), dummy))
                         return -1;
-                    else
-                        rc=1;
+                    rc=1;
                     break;
                 }
@@ -346,6 +343,5 @@
                 if (!DeleteSequence(serv, datapath, sequpath, sequences.At(i), dummy))
                     return -1;
-                else
-                    rc=1;
+                rc=1;
         }
     }
@@ -489,5 +485,5 @@
 }
 
-Bool_t NewSequence(MSQLServer &serv, TString datapath, TString sequpath, Int_t from, Int_t to, Bool_t dummy)
+Bool_t NewSequence(MSQLServer &serv, TString datapath, TString sequpath, Int_t from, Int_t to, TList &sequlist, Bool_t dummy)
 {
     cout << "Found Sequence (" << from << ", " << to << ") ... checking runs..." << flush;
@@ -513,4 +509,5 @@
     cout << "checking Sequence..." << endl;
 
+    TObject *sequ;
     Bool_t rc=kFALSE;
     switch (CheckSequence(serv, datapath, sequpath, from, to, dummy))
@@ -524,4 +521,6 @@
         }
         cout << endl;
+        if ((sequ=sequlist.Remove(sequlist.FindObject(Form("%d", from)))))
+            delete sequ;
         return InsertSequence(serv, from, to);
 
@@ -534,8 +533,12 @@
         }
         cout << endl;
+        if ((sequ=sequlist.Remove(sequlist.FindObject(Form("%d", from)))))
+            delete sequ;
         return InsertSequence(serv, from, to);
 
     case 2:
-        cout << " sequence is already existing -> inserting not necessary" << endl;
+        cout << " sequence " << from << " is already existing -> inserting not necessary" << endl;
+        if ((sequ=sequlist.Remove(sequlist.FindObject(Form("%d", from)))))
+            delete sequ;
         return kTRUE;
 
@@ -549,5 +552,5 @@
 }
 
-Bool_t Process(MSQLServer &serv, TString datapath, TString sequpath, Int_t from, Int_t to, Bool_t dummy)
+Bool_t Process(MSQLServer &serv, TString datapath, TString sequpath, Int_t from, Int_t to,  TList &sequlist, Bool_t dummy)
 {
 
@@ -692,5 +695,5 @@
             if (n!=-1)
             {
-                if (!NewSequence(serv, datapath, sequpath, start, last, dummy))
+                if (!NewSequence(serv, datapath, sequpath, start, last, sequlist, dummy))
                 {
                     rc = kFALSE;
@@ -708,5 +711,5 @@
     if (n!=-1 && start!=last)
     {
-        if (!NewSequence(serv, datapath, sequpath, start, last, dummy))
+        if (!NewSequence(serv, datapath, sequpath, start, last, sequlist, dummy))
             rc = kFALSE;
     }
@@ -797,4 +800,23 @@
 
 
+    TList sequlist;
+    query=Form("SELECT fSequenceFirst FROM Sequences WHERE %s order by fSequenceFirst",
+               cond.Data());
+
+//    cout << "Q: " << query << endl;
+
+    res = serv.Query(query);
+    if (!res)
+        return 0;
+
+    cout << "old sequences: " << flush;
+    while ((row=res->Next()))
+    {
+        const char *str =  (*row)[0];
+        cout << str << " " << flush;
+        sequlist.Add(new TObjString(str));
+    }
+    cout << endl;
+
     Bool_t rc = kTRUE;
 
@@ -807,8 +829,18 @@
         cout << endl << "datablock from " << runstart2 << " to " << runstop2 << endl;
 
-        if (!Process(serv, datapath, sequpath, runstart2, runstop2, dummy))
+        if (!Process(serv, datapath, sequpath, runstart2, runstop2, sequlist, dummy))
             rc = kFALSE;
 
     }
+
+    TIter Next(&sequlist);
+    TObject *obj = 0;
+    while ((obj=Next()))
+    {
+        cout << "sequ: " << obj->GetName() << " deleting... " << endl;
+        if (!DeleteSequence(serv, datapath, sequpath, atoi(obj->GetName()), dummy))
+            return 0;
+    }
+
     return rc ? 1 : 0;
 }
@@ -832,9 +864,11 @@
         return 0;
 
+    TString date;
     TSQLRow *row=0;
     while ((row=res->Next()))
     {
-        cout << "date: " << (*row)[0] << endl;
-        buildsequenceentries((*row)[0], dummy);
+        date=(*row)[0];
+        cout << "date: " << date << endl;
+        buildsequenceentries(date, datapath, sequpath, dummy);
     }
 
