Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 8064)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 8065)
@@ -18,4 +18,47 @@
 
                                                  -*-*- END OF LINE -*-*-
+
+ 2006/10/14 Thomas Bretz
+
+   * datacenter/macros/buildsequenceentries.C:
+     - fixed that in case of wobble sources always the project
+       and/or source name of the first run was assigned instead of
+       the new generaliyed wobble-source/-project name
+
+   * datacenter/scripts/dbchk:
+     - added some more checks
+
+   * datacenter/scripts/sourcefile:
+     - fixed the intgrep (didn't work with the colors in filldotraw)
+
+   * mastro/AstroIncl.h:
+     - added TArrayD
+
+   * mastro/MAstro.[h,cc]:
+     - added some functions around the sun and the moon
+
+   * mastro/MAstroCatalog.[h,cc]:
+     - check the epoch in Xephem catalog as numbe rnot as string
+     - added GetVisibilityCurve member function
+     - overwrote FindObject
+     - added MarkObject
+
+   * mastro/MObservatory.[h,cc]:
+     - added Tuorla observatory
+     - added member function to calculate sunrise and -set
+
+   * mbase/MTime.h:
+     - added a function to return Julian Date
+
+   * mhflux/MHCollectionArea.cc:
+     - some update in comments
+
+   * mhist/MHCamera.h:
+     - fixed a warning with root 5.13/04
+
+   * mmc/MMcRunHeader.cxx:
+     - initalize fImpactMax to -1
+
+
 
  2006/10/13 Daniela Dorner
Index: /trunk/MagicSoft/Mars/datacenter/macros/buildsequenceentries.C
===================================================================
--- /trunk/MagicSoft/Mars/datacenter/macros/buildsequenceentries.C	(revision 8064)
+++ /trunk/MagicSoft/Mars/datacenter/macros/buildsequenceentries.C	(revision 8065)
@@ -259,11 +259,4 @@
     TList fListRegexp;
 
-    /*
-    TString GetKeyName(TString col, TString key)
-    {
-        col(TRegexp("^Elt")) = "";
-        return QueryNameOfKey(col, key, kFALSE);
-    }*/
-
     Int_t CheckTransition(TSQLResult &res, const TString *keys, TSQLRow &row, Int_t i)
     {
@@ -330,11 +323,23 @@
         delete res;
 
+        const TString elts = GetELTSource(where);
+        if (elts.IsNull())
+            return kFALSE;
+
+        const TString eltp = GetELTProject(where);
+        if (eltp.IsNull())
+            return kFALSE;
+
         // ========== Request data of sequence ==========
-        query = Form("SELECT fSourceKEY, fProjectKEY, "
-                     " fL1TriggerTableKEY, fL2TriggerTableKEY,"
-                     " fHvSettingsKEY, fDiscriminatorThresholdTableKEY,"
-                     " fTriggerDelayTableKEY, fObservationModeKEY "
-                     " FROM RunData WHERE fRunTypeKEY=2 AND %s"
-                     " LIMIT 1", where.Data());
+        query  = "SELECT ";
+        query += elts;
+        query += ", ";
+        query += eltp;
+        query += ", fL1TriggerTableKEY, fL2TriggerTableKEY,"
+            " fHvSettingsKEY, fDiscriminatorThresholdTableKEY,"
+            " fTriggerDelayTableKEY, fObservationModeKEY "
+            " FROM RunData WHERE fRunTypeKEY=2 AND ";
+        query += where;
+        query += " LIMIT 1";
 
         res = Query(query);
@@ -692,4 +697,53 @@
     }
 
+    TString GetELTQuery(const char *col, const char *cond) const
+    {
+        return Form("SELECT RunData.f%sKEY, f%sName FROM RunData "
+                    "LEFT JOIN %s ON RunData.f%sKEY=%s.f%sKEY "
+                    "WHERE %s GROUP BY f%sName",
+                    col, col, col, col, col, col, cond, col);
+    }
+
+    TString GetELTSource(const char *cond)
+    {
+        //query all sources observed in this night
+        TSQLResult *resx = Query(GetELTQuery("Source", cond));
+        if (!resx)
+            return "";
+
+        // In the case there is only a single source
+        // do not replace the source key by the ELT
+        if (resx->GetRowCount()==1)
+            return "fSourceKEY";
+
+        TString elts = GetELT("Source", resx, "\\-?W[1-9][ abc]?$");
+        delete resx;
+
+        return elts;
+    }
+
+    TString GetELTProject(const char *cond)
+    {
+        //query all project names observed in this night
+        TSQLResult *resx = Query(GetELTQuery("Project", cond));
+        if (!resx)
+            return "";
+
+        // In the case there is only a single project
+        // do not replace the project key by the ELT
+        if (resx->GetRowCount()==1)
+            return "fProjectKEY";
+
+        TList regexp;
+        regexp.Add(new TObjString("\\-?W[1-9][abc]?$"));
+        regexp.Add(new TObjString("\\-W[0-9]\\.[0-9][0-9]\\+[0-9][0-9][0-9]$"));
+
+        TString eltp2 = GetELT("Project", resx, regexp);
+        delete resx;
+        regexp.Delete();
+
+        return eltp2;
+    }
+
     Bool_t HasAtLeastOne(TString src, TString chk) const
     {
@@ -1042,10 +1096,5 @@
         fMap.DeleteAll();
     }
-    /*
-     SequenceBuild(SequenceBuild &sb) : MSQLServer(sb)
-     {
-        fPathRawData = sb.fPathRawData;
-        fPathSequences = sb.fPathSequences;
-    }*/
+
     void SetPathRawData(const char *path) { fPathRawData=path; }
     void SetPathSequences(const char *path) { fPathSequences=path; }
@@ -1059,34 +1108,16 @@
         const TString cond =
             Form("(fRunStart>ADDDATE(\"%s\", INTERVAL -1 DAY) AND fRunStart<\"%s\") "
-                 "AND fExcludedFDAKEY=1 AND fRunTypeKEY BETWEEN 2 AND 4 "
-                 "ORDER BY fRunNumber",
+                 "AND fExcludedFDAKEY=1 AND fRunTypeKEY BETWEEN 2 AND 4 ",
                  day.Data(), day.Data());
 
-
-
         //query all sources observed in this night
-        TString querys(Form("SELECT RunData.fSourceKEY, fSourceName FROM RunData "
-                            "LEFT JOIN Source ON RunData.fSourceKEY=Source.fSourceKEY "
-                            "WHERE %s", cond.Data()));
-        TSQLResult *resx = Query(querys);
-        if (!resx)
-            return 2;
-        TString elts = GetELT("Source", resx, "\\-?W[1-9][ abc]?$");
-        delete resx;
+        const TString elts = GetELTSource(cond);
+        if (elts.IsNull())
+            return 2;
 
         //query all project names observed in this night
-        TString queryp(Form("SELECT RunData.fProjectKEY, fProjectName FROM RunData "
-                            "LEFT JOIN Project ON RunData.fProjectKEY=Project.fProjectKEY "
-                            "WHERE %s", cond.Data()));
-        resx = Query(queryp);
-        if (!resx)
-            return 2;
-
-        TList regexp;
-        regexp.Add(new TObjString("\\-?W[1-9][abc]?$"));
-        regexp.Add(new TObjString("\\-W[0-9]\\.[0-9][0-9]\\+[0-9][0-9][0-9]$"));
-        TString eltp2 = GetELT("Project", resx, regexp);
-        delete resx;
-        regexp.Delete();
+        const TString eltp2 = GetELTProject(cond);
+        if (elts.IsNull())
+            return 2;
 
         // Setup query to get all values from the database,
@@ -1106,5 +1137,5 @@
                 query += mapkey->GetName();
             }
-        query += Form(" FROM RunData WHERE %s", cond.Data());
+        query += Form(" FROM RunData WHERE %s ORDER BY fRunNumber", cond.Data());
 
         TSQLResult *res = Query(query);
Index: /trunk/MagicSoft/Mars/datacenter/scripts/dbchk
===================================================================
--- /trunk/MagicSoft/Mars/datacenter/scripts/dbchk	(revision 8064)
+++ /trunk/MagicSoft/Mars/datacenter/scripts/dbchk	(revision 8065)
@@ -6,4 +6,6 @@
 # directory where the sequence files are stored
 sequencedir=/magic/sequences
+callistodir=/magic/data/callisto
+stardir=/magic/data/star
 # access to the sql database
 alias mymysql='mysql -s -u MAGIC -h hercules --password=d99swMT!'
@@ -17,8 +19,10 @@
 # Cross check sequences in Sequence and other databases
 # added switch which allows to correct for the problems immediatly
+# unify the checks (especially 1b and 1c)
+# for the sequences better use 0* instead of 0+ ?
 
 
 # CHECK 1
-echo Checking if all sequences in Sequences have a corresponding sequence files
+echo Checking if all sequence files have a corresponding entry in Sequences
 files=`find $sequencedir -type f`
 for file in $files
@@ -27,5 +31,5 @@
    if [ "$sequence" = "" ]
    then
-      echo No sequence file: $sequence
+      echo No sequence file: $file
       continue
    fi
@@ -34,5 +38,45 @@
    if ! [ "$sequence" = "$var" ]
    then
-      echo Sequence-File $sequence exist but it is not in the db.
+      echo Sequence-File $sequence exist but it is not in Sequences.
+      continue
+   fi
+done
+
+# CHECK 1b (callisto)
+echo Checking if all sequences in $callistodir have a corresponding sequence in Sequence
+dirs=`find $callistodir -type d`
+for dir in $dirs
+do
+   sequence=`echo $file | sed -e "s/^.*\/0\+\([0-9]\+\)$/\1/"`
+   if [ "$sequence" = "" ]
+   then
+      echo Invalid directory: $dir
+      continue
+   fi
+
+   var=`echo SELECT fSequenceFirst FROM $db.Sequences WHERE fSequenceFirst=$sequence | mymysql`
+   if ! [ "$sequence" = "$var" ]
+   then
+      echo $dir exists but no corresponding sequence in Sequences.
+      continue
+   fi
+done
+
+# CHECK 1c (star)
+echo Checking if all sequences in $stardir have a corresponding sequence in Sequence
+dirs=`find $stardir -type d`
+for dir in $dirs
+do
+   sequence=`echo $file | sed -e "s/^.*\/0\+\([0-9]\+\)$/\1/"`
+   if [ "$sequence" = "" ]
+   then
+      echo Invalid directory: $dir
+      continue
+   fi
+
+   var=`echo SELECT fSequenceFirst FROM $db.Sequences WHERE fSequenceFirst=$sequence | mymysql`
+   if ! [ "$sequence" = "$var" ]
+   then
+      echo $dir exists but no corresponding sequence in Sequences.
       continue
    fi
@@ -40,9 +84,9 @@
 
 # CHECK 2
-echo Checking if all sequence files have a corresponding entry in Sequences
+echo Checking if all sequences in Sequences have a corresponding sequence files
 sequences=`echo SELECT fSequenceFirst FROM $db.Sequences | mymysql`
 for sequence in $sequences
 do
-   var=`find $sequencedir -regex .*/sequence0+${sequence}\.txt$`
+   var=`find $sequencedir -type f -regex .*/sequence0+${sequence}\.txt$`
    if [ "$var" = "" ]
    then
Index: /trunk/MagicSoft/Mars/datacenter/scripts/sourcefile
===================================================================
--- /trunk/MagicSoft/Mars/datacenter/scripts/sourcefile	(revision 8064)
+++ /trunk/MagicSoft/Mars/datacenter/scripts/sourcefile	(revision 8065)
@@ -114,6 +114,7 @@
 
 
-# alias
-alias 'intgrep'='grep -E ^\\\(int\\\)[0-9]+$ | sed -e s\/\(int\)\/\/'
+# alias (we cannot check the beginning of the line due to
+# color codes in filldotraw.C)
+alias 'intgrep'='grep -E -o \\\(int\\\)[0-9]+$'
 
 # in the following the functions, which are needed by several scripts, are 
