Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 8087)
+++ trunk/MagicSoft/Mars/Changelog	(revision 8088)
@@ -18,11 +18,37 @@
 
                                                  -*-*- END OF LINE -*-*-
+ 2006/10/17 Thomas Bretz
+
+   * mdata/MDataPhrase.cc:
+     - updated comments
+     - only add the missing functions to TDataPrimitives when not
+       yet done. Everything lse would leak memory
+
+   * mhbase/MH3.[h,cc], mhvstime/MHVsTime.[h,cc]:
+     - exchanged the MDataChain by MDataPhrase
+     - therefore changed the datamember from MDataChain* to MData*
+       (this change is not necessarily backward compatible)
+     - increased class version number by one
+
+   * mraw/MRawRunHeader.h:
+     - added getter for fObservationMode
+
+   * callisto.cc, ganymed.cc, merpp.cc, readdaq.cc, readraw.cc,
+     showplot.cc, sinope.cc, star.cc, rootlogon.C
+     - enabled error redirection
+
+   * mbase/MLog.[h,cc]:
+     - added code to allow redirection of root error handler to 
+       out own error handler
+
+
+
  2006/10/17 Markus Meyer
 
-   * mtools
-     - added a new class called MRolke, which is a modification of 
-       TRolke from root_v5.12.00b. There is now a new function, called
-       LogFactorial() which enables to calculate confidence intervals 
-       even for a large number of events (larger than 170). 
+   * mtools/MRolke.[h,cc]:
+     - added: a modification of TRolke from root_v5.12.00b. There is
+       now a new function, called LogFactorial() which enables to
+       calculate confidence intervals even for a large number of
+       events (larger than 170). 
 
 
@@ -78,5 +104,5 @@
    * mbase/MMath.cc:
      - small update to SolvePol3 which is more accurate in the number 
-       or different solutions
+       of different solutions
 
    * mdata/DataLinkDef.h, mdata/Makefile:
Index: trunk/MagicSoft/Mars/NEWS
===================================================================
--- trunk/MagicSoft/Mars/NEWS	(revision 8087)
+++ trunk/MagicSoft/Mars/NEWS	(revision 8088)
@@ -5,4 +5,7 @@
    - general: The programs now return 0xfe if the requested resource file
      doesn't exist.
+
+   - general: Errors comming from root itself are now not output to
+     stderr anymore but to our default (colored) log-stream.
 
 
Index: trunk/MagicSoft/Mars/callisto.cc
===================================================================
--- trunk/MagicSoft/Mars/callisto.cc	(revision 8087)
+++ trunk/MagicSoft/Mars/callisto.cc	(revision 8088)
@@ -145,4 +145,6 @@
         return 0xff;
 
+    MLog::RedirectErrorHandler(MLog::kColor);
+
     //
     // Evaluate arguments
Index: trunk/MagicSoft/Mars/ganymed.cc
===================================================================
--- trunk/MagicSoft/Mars/ganymed.cc	(revision 8087)
+++ trunk/MagicSoft/Mars/ganymed.cc	(revision 8088)
@@ -94,4 +94,6 @@
         return 0xff;
 
+    MLog::RedirectErrorHandler(MLog::kColor);
+
     //
     // Evaluate arguments
Index: trunk/MagicSoft/Mars/macros/rootlogon.C
===================================================================
--- trunk/MagicSoft/Mars/macros/rootlogon.C	(revision 8087)
+++ trunk/MagicSoft/Mars/macros/rootlogon.C	(revision 8088)
@@ -122,4 +122,6 @@
         return;
 
+    MLog::RedirectErrorHandler(MLog::kColor);
+
     gInterpreter->AddIncludePath(dir+"macros");
     gInterpreter->AddIncludePath(dir+"manalysis");
Index: trunk/MagicSoft/Mars/mbase/MLog.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MLog.cc	(revision 8087)
+++ trunk/MagicSoft/Mars/mbase/MLog.cc	(revision 8088)
@@ -108,4 +108,7 @@
 #include <TGTextView.h>
 
+#include <TEnv.h>       // gEnv (ErrorHandler)
+#include <TError.h>     // TError (SetErrorHandler)
+
 #include "MArgs.h"
 #include "MTime.h"
@@ -113,4 +116,5 @@
 
 #include "MLogHtml.h"
+#include "MLogManip.h"  // inf,warn,err (MLog::ErrorHandler)
 
 ClassImp(MLog);
@@ -153,5 +157,4 @@
 void MLog::Init()
 {
-
     //
     // Creat drawing semaphore
@@ -745,2 +748,155 @@
     return rc;
 }
+
+// --------------------------------------------------------------------------
+//
+// Check whether errors at this level should be ignored.
+//
+bool MLog::ErrorHandlerIgnore(Int_t level)
+{
+    // The default error handler function. It prints the message on stderr and
+    // if abort is set it aborts the application.
+   if (gErrorIgnoreLevel == kUnset) {
+      R__LOCKGUARD2(gErrorMutex);
+
+      gErrorIgnoreLevel = 0;
+      if (gEnv) {
+         TString level = gEnv->GetValue("Root.ErrorIgnoreLevel", "Info");
+         if (!level.CompareTo("Info",TString::kIgnoreCase))
+            gErrorIgnoreLevel = kInfo;
+         else if (!level.CompareTo("Warning",TString::kIgnoreCase))
+            gErrorIgnoreLevel = kWarning;
+         else if (!level.CompareTo("Error",TString::kIgnoreCase))
+            gErrorIgnoreLevel = kError;
+         else if (!level.CompareTo("Break",TString::kIgnoreCase))
+            gErrorIgnoreLevel = kBreak;
+         else if (!level.CompareTo("SysError",TString::kIgnoreCase))
+            gErrorIgnoreLevel = kSysError;
+         else if (!level.CompareTo("Fatal",TString::kIgnoreCase))
+            gErrorIgnoreLevel = kFatal;
+      }
+   }
+
+   return level < gErrorIgnoreLevel;
+}
+
+// --------------------------------------------------------------------------
+//
+// Output the root error message to the log-stream.
+//
+void MLog::ErrorHandlerPrint(Int_t level, const char *location, const char *msg)
+{
+    R__LOCKGUARD2(gErrorMutex);
+
+    if (level >= kError)
+        gLog << "ROOT:Error";
+    else
+        if (level >= kSysError)
+            gLog << "SysError";
+        else
+            if (level >= kBreak)
+                gLog << "\n *** Break ***";
+            else
+                if (level >= kFatal)
+                    gLog << "Fatal";
+                else
+                    if (level >= kWarning)
+                        gLog << "ROOT:Warning";
+                    else
+                        if (level >= kInfo)
+                            gLog << "ROOT:Info";
+
+    if (level >= kBreak && level < kSysError)
+        gLog << " " << msg << std::endl;
+    else
+        if (!location || strlen(location) == 0)
+            gLog << ": " << msg << std::endl;
+        else
+            gLog << " in <" << location << ">: " << msg << std::endl;
+}
+
+// --------------------------------------------------------------------------
+//
+// A new error handler using gLog instead of stderr as output.
+// It is mainly a copy of root's DefaultErrorHandler
+// (see TError.h and TError.cxx)
+//
+void MLog::ErrorHandlerCol(Int_t level, Bool_t abort, const char *location, const char *msg)
+{
+    if (ErrorHandlerIgnore(level))
+        return;
+
+    gLog << std::flush;
+
+    if (level >= kInfo)
+       gLog << inf;
+    if (level >= kWarning)
+        gLog << warn;
+    if (level >= kError)
+        gLog << err;
+
+    ErrorHandlerPrint(level, location, msg);
+
+    gLog << std::flush;
+    if (!abort)
+        return;
+
+    gLog << err << "aborting" << std::endl;
+    if (gSystem) {
+        gSystem->StackTrace();
+        gSystem->Abort();
+    } else
+        ::abort();
+}
+
+// --------------------------------------------------------------------------
+//
+// A new error handler using gLog instead of stderr as output.
+// It is mainly a copy of root's DefaultErrorHandler
+// (see TError.h and TError.cxx)
+//
+void MLog::ErrorHandlerAll(Int_t level, Bool_t abort, const char *location, const char *msg)
+{
+    if (ErrorHandlerIgnore(level))
+        return;
+
+    gLog << std::flush << all;
+
+    ErrorHandlerPrint(level, location, msg);
+
+    gLog << std::flush;
+    if (!abort)
+        return;
+
+    gLog << err << "aborting" << std::endl;
+    if (gSystem) {
+        gSystem->StackTrace();
+        gSystem->Abort();
+    } else
+        ::abort();
+}
+
+// --------------------------------------------------------------------------
+//
+// Redirect the root ErrorHandler (see TError.h) output to gLog.
+//
+// The diffrent types are:
+//  kColor:      Use gLog colors
+//  kBlackWhite: Use all-qualifier (as in gLog << all << endl;)
+//  kDefault:    Set back to root's default error handler
+//               (redirect output to stderr)
+//
+void MLog::RedirectErrorHandler(ELogType typ)
+{
+    switch (typ)
+    {
+    case kColor:
+        SetErrorHandler(MLog::ErrorHandlerCol);
+        break;
+    case kBlackWhite:
+        SetErrorHandler(MLog::ErrorHandlerAll);
+        break;
+    case kDefault:
+        SetErrorHandler(DefaultErrorHandler);
+    }
+}
Index: trunk/MagicSoft/Mars/mbase/MLog.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MLog.h	(revision 8087)
+++ trunk/MagicSoft/Mars/mbase/MLog.h	(revision 8088)
@@ -35,4 +35,10 @@
     enum ELogBits {
         kHasChanged = BIT(14)  // if gui has changed
+    };
+
+    enum ELogType {
+        kDefault,
+        kColor,
+        kBlackWhite
     };
 
@@ -95,5 +101,12 @@
     void AddGuiLine(const TString& line);
 
+    // User defined error handling (see TError.h)
+    static bool ErrorHandlerIgnore(Int_t level);
+    static void ErrorHandlerPrint(Int_t level, const char *location, const char *msg);
+    static void ErrorHandlerCol(Int_t level, Bool_t abort, const char *location, const char *msg);
+    static void ErrorHandlerAll(Int_t level, Bool_t abort, const char *location, const char *msg);
+
 public:
+
     MLog(int i=eStdout);
     MLog(ofstream &out);
@@ -110,4 +123,5 @@
 
     static TString Intro();
+    static void RedirectErrorHandler(ELogType typ=kColor);
 
     bool LockUpdate(const char *msg);
Index: trunk/MagicSoft/Mars/merpp.cc
===================================================================
--- trunk/MagicSoft/Mars/merpp.cc	(revision 8087)
+++ trunk/MagicSoft/Mars/merpp.cc	(revision 8088)
@@ -150,4 +150,6 @@
         return 0xff;
 
+    MLog::RedirectErrorHandler(MLog::kColor);
+
     //
     // Evaluate arguments
Index: trunk/MagicSoft/Mars/readdaq.cc
===================================================================
--- trunk/MagicSoft/Mars/readdaq.cc	(revision 8087)
+++ trunk/MagicSoft/Mars/readdaq.cc	(revision 8088)
@@ -62,4 +62,6 @@
         return 0xff;
 
+    MLog::RedirectErrorHandler(MLog::kColor);
+
     //
     // Evaluate arguments
Index: trunk/MagicSoft/Mars/readraw.cc
===================================================================
--- trunk/MagicSoft/Mars/readraw.cc	(revision 8087)
+++ trunk/MagicSoft/Mars/readraw.cc	(revision 8088)
@@ -72,4 +72,6 @@
     if (!MARS::CheckRootVer())
         return 0xff;
+
+    MLog::RedirectErrorHandler(MLog::kColor);
 
     // Evaluate arguments
Index: trunk/MagicSoft/Mars/showplot.cc
===================================================================
--- trunk/MagicSoft/Mars/showplot.cc	(revision 8087)
+++ trunk/MagicSoft/Mars/showplot.cc	(revision 8088)
@@ -93,4 +93,6 @@
         return 0xff;
 
+    MLog::RedirectErrorHandler(MLog::kColor);
+
     //
     // Evaluate arguments
Index: trunk/MagicSoft/Mars/sinope.cc
===================================================================
--- trunk/MagicSoft/Mars/sinope.cc	(revision 8087)
+++ trunk/MagicSoft/Mars/sinope.cc	(revision 8088)
@@ -269,4 +269,6 @@
         return 0xff;
 
+    MLog::RedirectErrorHandler(MLog::kColor);
+
     //
     // Evaluate arguments
Index: trunk/MagicSoft/Mars/star.cc
===================================================================
--- trunk/MagicSoft/Mars/star.cc	(revision 8087)
+++ trunk/MagicSoft/Mars/star.cc	(revision 8088)
@@ -94,4 +94,6 @@
         return 0xff;
 
+    MLog::RedirectErrorHandler(MLog::kColor);
+
     //
     // Evaluate arguments
