Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 1473)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 1474)
@@ -1,3 +1,35 @@
                                                                   -*-*- END -*-*-
+
+ 2002/08/02: Thomas Bretz
+
+   * manalysis/MHillasSrcCalc.[h,cc], manalysis/MImgCleanStd.cc,
+     manalysis/MSrcPosCam.cc, mbase/MParContainer.[h,cc],
+     mfileio/MReadTree.cc, mfileio/MWriteRootFile.cc, mhist/MBinning.cc:
+     - added comments
+
+   * manalysis/MSrcPosCam.cc, mfileio/MWriteRootFile.cc, mhist/MFillH.cc:
+     - fixed a missing " in SavePrimitive
+
+   * mbase/MTask.[h,cc], mhist/MBinning.[h,cc], mhist/MH3.[h,cc]:
+     - implemented SavePrimitive
+
+   * mbase/MEvtLoop.[h,cc]:
+     - added MakeMacro
+     - added Read and Write
+
+   * mbase/MParContainer.[h,cc], mbase/MParList.[h,cc], 
+     mbase/MTaskList.[h,cc]:
+     - added GetNames, SetNames virtual functions
+
+   * mdata/MData.[h,cc], mdata/MDataChain.[h,cc], mdata/MDataList.[h,cc],
+     mdata/MDataValue.[h,cc], mdata/MDataMember.[h,cc]:
+     - implemented GetRule
+     - move Code from Print to GetRule
+     - removed Print
+
+   * mhist/MH3.[h,cc]:
+     - implemented default constructor
+
+
 
  2002/08/01: Thomas Bretz
Index: /trunk/MagicSoft/Mars/manalysis/MHillasSrcCalc.cc
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MHillasSrcCalc.cc	(revision 1473)
+++ /trunk/MagicSoft/Mars/manalysis/MHillasSrcCalc.cc	(revision 1474)
@@ -97,4 +97,10 @@
 
 
+// --------------------------------------------------------------------------
+//
+// Implementation of SavePrimitive. Used to write the call to a constructor
+// to a macro. In the original root implementation it is used to write
+// gui elements to a macro-file.
+//
 void MHillasSrcCalc::SavePrimitive(ofstream &out, Option_t *o="")
 {
Index: /trunk/MagicSoft/Mars/manalysis/MHillasSrcCalc.h
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MHillasSrcCalc.h	(revision 1473)
+++ /trunk/MagicSoft/Mars/manalysis/MHillasSrcCalc.h	(revision 1474)
@@ -13,7 +13,7 @@
 {
 private:
-    MHillas    *fHillas;
-    MSrcPosCam *fSrcPos;
-    MHillasSrc *fHillasSrc;
+    MHillas    *fHillas;     //! Pointer to the source independant hillas parameters
+    MSrcPosCam *fSrcPos;     //! Pointer to the source position
+    MHillasSrc *fHillasSrc;  //! Pointer to the output container for the source dependant parameters
 
     TString     fSrcName;
@@ -29,5 +29,5 @@
     void SavePrimitive(ofstream &out, Option_t *o="");
 
-    ClassDef(MHillasSrcCalc, 0) // task to calculate the source position depandant hillas parameters
+    ClassDef(MHillasSrcCalc, 1) // task to calculate the source position depandant hillas parameters
 };
 
Index: /trunk/MagicSoft/Mars/manalysis/MImgCleanStd.cc
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MImgCleanStd.cc	(revision 1473)
+++ /trunk/MagicSoft/Mars/manalysis/MImgCleanStd.cc	(revision 1474)
@@ -408,4 +408,10 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// Implementation of SavePrimitive. Used to write the call to a constructor
+// to a macro. In the original root implementation it is used to write
+// gui elements to a macro-file.
+//
 void MImgCleanStd::SavePrimitive(ofstream &out, Option_t *o="")
 {
Index: /trunk/MagicSoft/Mars/manalysis/MSrcPosCam.cc
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MSrcPosCam.cc	(revision 1473)
+++ /trunk/MagicSoft/Mars/manalysis/MSrcPosCam.cc	(revision 1474)
@@ -82,8 +82,14 @@
 */
 
+// --------------------------------------------------------------------------
+//
+// Implementation of SavePrimitive. Used to write the call to a constructor
+// to a macro. In the original root implementation it is used to write
+// gui elements to a macro-file.
+//
 void MSrcPosCam::SavePrimitive(ofstream &out, Option_t *o="")
 {
     out << "   MSrcPosCam " << ToLower(fName) << "(\"";
-    out << fName << "\", " << fTitle << "\");" << endl;
+    out << fName << "\", \"" << fTitle << "\");" << endl;
 
     out << "   " << ToLower(fName) << ".SetXY(" << fX << ", " << fY << ");" << endl;}
Index: /trunk/MagicSoft/Mars/mbase/MEvtLoop.cc
===================================================================
--- /trunk/MagicSoft/Mars/mbase/MEvtLoop.cc	(revision 1473)
+++ /trunk/MagicSoft/Mars/mbase/MEvtLoop.cc	(revision 1474)
@@ -52,6 +52,5 @@
 //                                                                          //
 // You can create a macro from a completely setup eventloop by:             //
-//   ofstream fout("mymacro.C");                                            //
-//   evtloop.SavePrimitive(fout);                                           //
+//   evtloop.MakeMacro("mymacro.C");                                        //
 //                                                                          //
 // You will always need to check the macro, it will not run, but it         //
@@ -66,9 +65,10 @@
 //   evtloop.Read("MyEvtloopKey");                                          //
 //                                                                          //
-// To lookup the information write it to a file using SavePrimite           //
+// To lookup the information write it to a file using MakeMacro             //
 //                                                                          //
 //////////////////////////////////////////////////////////////////////////////
 #include "MEvtLoop.h"
 
+#include <time.h>
 #include <fstream.h>     // ofstream, SavePrimitive
 #include <iostream.h>
@@ -292,4 +292,60 @@
 }
 
+void MEvtLoop::MakeMacro(const char *filename="evtloop.C")
+{
+    TString name(filename);
+
+    if (!name.EndsWith(".C"))
+        name += ".C";
+
+    time_t t = time(NULL);
+
+    ofstream fout(name);
+    fout <<
+        "/* ======================================================================== *\\" << endl <<
+        "!" << endl <<
+        "! *" << endl <<
+        "! * This file is part of MARS, the MAGIC Analysis and Reconstruction" << endl <<
+        "! * Software. It is distributed to you in the hope that it can be a useful" << endl <<
+        "! * and timesaving tool in analysing Data of imaging Cerenkov telescopes." << endl <<
+        "! * It is distributed WITHOUT ANY WARRANTY." << endl <<
+        "! *" << endl <<
+        "! * Permission to use, copy, modify and distribute this software and its" << endl <<
+        "! * documentation for any purpose is hereby granted without fee," << endl <<
+        "! * provided that the above copyright notice appear in all copies and" << endl <<
+        "! * that both that copyright notice and this permission notice appear" << endl <<
+        "! * in supporting documentation. It is provided \"as is\" without express" << endl <<
+        "! * or implied warranty." << endl <<
+        "! *" << endl <<
+        "!" << endl <<
+        "!" << endl <<
+        "!   Author(s): Thomas Bretz et al. <mailto:tbretz@astro.uni-wuerzburg.de>" << endl <<
+        "!" << endl <<
+        "!   Copyright: MAGIC Software Development, 2000-2002" << endl <<
+        "!" << endl <<
+        "!" << endl <<
+        "\\* ======================================================================== */" << endl << endl <<
+        "// ------------------------------------------------------------------------" << endl <<
+        "//" << endl <<
+        "//     This macro was automatically created on" << endl<<
+        "//             " << ctime(&t) <<
+        "//        with the MEvtLoop::MakeMacro tool." << endl <<
+        "//" << endl <<
+        "// ------------------------------------------------------------------------" << endl << endl <<
+        "void " << name(0, name.Length()-2) << "()" << endl <<
+        "{" << endl;
+
+    SavePrimitive(fout);
+
+    fout << "}" << endl;
+}
+
+// --------------------------------------------------------------------------
+//
+// Implementation of SavePrimitive. Used to write the call to a constructor
+// to a macro. In the original root implementation it is used to write
+// gui elements to a macro-file.
+
+//
 void MEvtLoop::SavePrimitive(ofstream &out, Option_t *)
 {
@@ -297,6 +353,34 @@
 
     out << "   MEvtLoop evtloop;" << endl;
-    out << "   evtloop.SetParList(&" << ToLower(fParList->GetName()) << ")" << endl;
+    out << "   evtloop.SetParList(&" << ToLower(fParList->GetName()) << ");" << endl;
     out << "   if (!evtloop.Eventloop())" << endl;
     out << "      return;" << endl;
 }
+
+Int_t MEvtLoop::Read(const char *name)
+{
+    Int_t n = 0;
+    TObjArray list;
+
+    n += TObject::Read(name);
+    n += list.Read((TString)name+"_names");
+
+    fParList->SetNames(list);
+
+    return n;
+}
+
+Int_t MEvtLoop::Write(const char *name, Int_t option, Int_t bufsize)
+{
+    Int_t n = 0;
+
+    TObjArray list;
+    list.SetOwner();
+
+    fParList->GetNames(list);
+
+    n += list.Write((TString)name+"_names", kSingleKey);
+    n += TObject::Write(name, option, bufsize);
+
+    return n;
+}
Index: /trunk/MagicSoft/Mars/mbase/MEvtLoop.h
===================================================================
--- /trunk/MagicSoft/Mars/mbase/MEvtLoop.h	(revision 1473)
+++ /trunk/MagicSoft/Mars/mbase/MEvtLoop.h	(revision 1474)
@@ -46,5 +46,10 @@
     Bool_t Eventloop(Int_t maxcnt=-1, const char *tlist="MTaskList");
 
+    void MakeMacro(const char *filename="evtloop.C");
+
     void SavePrimitive(ofstream &out, Option_t *o="");
+
+    Int_t Read(const char *name);
+    Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0);
 
     ClassDef(MEvtLoop, 1) // Class to execute the tasks in a tasklist
Index: /trunk/MagicSoft/Mars/mbase/MParContainer.cc
===================================================================
--- /trunk/MagicSoft/Mars/mbase/MParContainer.cc	(revision 1473)
+++ /trunk/MagicSoft/Mars/mbase/MParContainer.cc	(revision 1474)
@@ -39,7 +39,8 @@
 #include <fstream.h>     // ofstream, AsciiWrite
 
+#include <TROOT.h>       // TROOT::Identlevel
 #include <TClass.h>      // IsA
+#include <TObjArray.h>   // TObjArray
 #include <TBaseClass.h>  // GetClassPointer
-#include <TROOT.h>       // TROOT::Identlevel
 #include <TMethodCall.h> // TMethodCall, AsciiWrite
 #include <TDataMember.h> // TDataMember, AsciiWrite
@@ -347,4 +348,10 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// Implementation of SavePrimitive. Used to write the call to a constructor
+// to a macro. In the original root implementation it is used to write
+// gui elements to a macro-file.
+//
 void MParContainer::SavePrimitive(ofstream &out, Option_t *o="")
 {
@@ -354,2 +361,17 @@
 }
 
+void MParContainer::GetNames(TObjArray &arr) const
+{
+    arr.AddLast(new TNamed(fName, fTitle));
+}
+
+void MParContainer::SetNames(TObjArray &arr)
+{
+    TNamed *name = (TNamed*)arr.First();
+
+    fName  = name->GetName();
+    fTitle = name->GetTitle();
+
+    delete arr.Remove(name);
+    arr.Compress();
+}
Index: /trunk/MagicSoft/Mars/mbase/MParContainer.h
===================================================================
--- /trunk/MagicSoft/Mars/mbase/MParContainer.h	(revision 1473)
+++ /trunk/MagicSoft/Mars/mbase/MParContainer.h	(revision 1474)
@@ -77,4 +77,7 @@
     virtual Bool_t AsciiWrite(ostream &out) const;
 
+    virtual void GetNames(TObjArray &arr) const;
+    virtual void SetNames(TObjArray &arr);
+
     ClassDef(MParContainer, 0)  //The basis for all parameter containers
 };
Index: /trunk/MagicSoft/Mars/mbase/MParList.cc
===================================================================
--- /trunk/MagicSoft/Mars/mbase/MParList.cc	(revision 1473)
+++ /trunk/MagicSoft/Mars/mbase/MParList.cc	(revision 1474)
@@ -660,7 +660,14 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// Implementation of SavePrimitive. Used to write the call to a constructor
+// to a macro. In the original root implementation it is used to write
+// gui elements to a macro-file.
+//
 void MParList::SavePrimitive(ofstream &out, Option_t *o="")
 {
-    out << "   MParList " << ToLower(fName) << ";" << endl << endl;
+    out << "   MParList " << ToLower(fName) << "(\"";
+    out << fName << "\", \"" << fTitle << "\");" << endl << endl;
 
     TIter Next(fContainer);
@@ -674,2 +681,25 @@
     }
 }
+
+void MParList::GetNames(TObjArray &arr) const
+{
+    MParContainer::GetNames(arr);
+    fContainer->ForEach(MParContainer, GetNames)(arr);
+}
+
+void MParList::SetNames(TObjArray &arr)
+{
+    MParContainer::SetNames(arr);
+    cout << fContainer << endl;
+    //    fContainer->ForEach(MParContainer, SetNames)(arr);
+    TIter Next(fContainer);
+
+    MParContainer *cont = NULL;
+    while ((cont=(MParContainer*)Next()))
+    {
+        cout << cont << " " << cont->GetName() << endl;
+        cont->SetNames(arr);
+    }
+
+}
+
Index: /trunk/MagicSoft/Mars/mbase/MParList.h
===================================================================
--- /trunk/MagicSoft/Mars/mbase/MParList.h	(revision 1473)
+++ /trunk/MagicSoft/Mars/mbase/MParList.h	(revision 1474)
@@ -80,4 +80,7 @@
     void SavePrimitive(ofstream &out, Option_t *o="");
 
+    void GetNames(TObjArray &arr) const;
+    void SetNames(TObjArray &arr);
+
     ClassDef(MParList, 1) // list of parameter containers (MParContainer)
 };
Index: /trunk/MagicSoft/Mars/mbase/MTask.cc
===================================================================
--- /trunk/MagicSoft/Mars/mbase/MTask.cc	(revision 1473)
+++ /trunk/MagicSoft/Mars/mbase/MTask.cc	(revision 1474)
@@ -60,10 +60,11 @@
 //   - PostProcess():  executed after the eventloop. Here you can close    //
 //                     output files, start display of the run parameter,   //
-//                     etc. PostProcess should be executed only if         //
+//                     etc. PostProcess is only executed in case of        //
 //                     PreProcess was successfull (returned kTRUE)         //
 //                                                                         //
 /////////////////////////////////////////////////////////////////////////////
-
 #include "MTask.h"
+
+#include <fstream.h>
 
 #include "MLog.h"
@@ -262,2 +263,14 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// Implementation of SavePrimitive. Used to write the call to a constructor
+// to a macro. In the original root implementation it is used to write
+// gui elements to a macro-file.
+//
+void MTask::SavePrimitive(ofstream &out, Option_t *o="")
+{
+    MParContainer::SavePrimitive(out);
+    if (fFilter)
+        out << "   " << ToLower(fName) << ".SetFilter(&" << ToLower(fFilter->GetName()) <<");" << endl;
+}
Index: /trunk/MagicSoft/Mars/mbase/MTask.h
===================================================================
--- /trunk/MagicSoft/Mars/mbase/MTask.h	(revision 1473)
+++ /trunk/MagicSoft/Mars/mbase/MTask.h	(revision 1474)
@@ -71,4 +71,5 @@
     const MFilter *GetFilter() const      { return fFilter; }
     virtual void PrintStatistics(const Int_t lvl=0) const;
+    virtual void SavePrimitive(ofstream &out, Option_t *o="");
 
     UInt_t GetNumExecutions() { return fNumExecutions; }
Index: /trunk/MagicSoft/Mars/mbase/MTaskList.cc
===================================================================
--- /trunk/MagicSoft/Mars/mbase/MTaskList.cc	(revision 1473)
+++ /trunk/MagicSoft/Mars/mbase/MTaskList.cc	(revision 1474)
@@ -514,8 +514,14 @@
 }
 
-
+// --------------------------------------------------------------------------
+//
+// Implementation of SavePrimitive. Used to write the call to a constructor
+// to a macro. In the original root implementation it is used to write
+// gui elements to a macro-file.
+//
 void MTaskList::SavePrimitive(ofstream &out, Option_t *o="")
 {
-    out << "   MTaskList " << ToLower(fName) << ";" << endl << endl;
+    out << "   MTaskList " << ToLower(fName) << "(\"";
+    out << fName << "\", \"" << fTitle << "\");" << endl << endl;
 
     TIter Next(fTasks);
@@ -529,2 +535,15 @@
     }
 }
+
+void MTaskList::GetNames(TObjArray &arr) const
+{
+    MParContainer::GetNames(arr);
+    fTasks->ForEach(MParContainer, GetNames)(arr);
+}
+
+void MTaskList::SetNames(TObjArray &arr)
+{
+    MParContainer::SetNames(arr);
+    fTasks->ForEach(MParContainer, SetNames)(arr);
+}
+
Index: /trunk/MagicSoft/Mars/mbase/MTaskList.h
===================================================================
--- /trunk/MagicSoft/Mars/mbase/MTaskList.h	(revision 1473)
+++ /trunk/MagicSoft/Mars/mbase/MTaskList.h	(revision 1474)
@@ -60,4 +60,7 @@
     const TList *GetList() const { return fTasks; }
 
+    void GetNames(TObjArray &arr) const;
+    void SetNames(TObjArray &arr);
+
     ClassDef(MTaskList, 1) //collection of tasks to be performed in the eventloop
 };
Index: /trunk/MagicSoft/Mars/mdata/MData.cc
===================================================================
--- /trunk/MagicSoft/Mars/mdata/MData.cc	(revision 1473)
+++ /trunk/MagicSoft/Mars/mdata/MData.cc	(revision 1474)
@@ -50,4 +50,6 @@
 #include <fstream.h>
 
+#include "MLog.h"
+
 ClassImp(MData);
 
@@ -58,2 +60,6 @@
 }
 
+void MData::Print(Option_t *opt = "") const
+{
+    *fLog << GetRule() << flush;
+}
Index: /trunk/MagicSoft/Mars/mdata/MData.h
===================================================================
--- /trunk/MagicSoft/Mars/mdata/MData.h	(revision 1473)
+++ /trunk/MagicSoft/Mars/mdata/MData.h	(revision 1474)
@@ -18,9 +18,11 @@
 public:
     virtual Double_t GetValue() const = 0;
-    virtual Bool_t IsValid() const = 0;
-    virtual Bool_t PreProcess(const MParList *plist) = 0;
+    virtual Bool_t   IsValid() const = 0;
+    virtual Bool_t   PreProcess(const MParList *plist) = 0;
+    virtual TString  GetRule() const = 0;
 
     Double_t operator()() { return GetValue(); }
 
+    void Print(Option_t *opt = "") const;
     Bool_t AsciiWrite(ostream &out) const;
 
Index: /trunk/MagicSoft/Mars/mdata/MDataChain.cc
===================================================================
--- /trunk/MagicSoft/Mars/mdata/MDataChain.cc	(revision 1473)
+++ /trunk/MagicSoft/Mars/mdata/MDataChain.cc	(revision 1474)
@@ -448,6 +448,8 @@
 }
 
+    /*
 void MDataChain::Print(Option_t *opt) const
 {
+    *fLog << GetRule() << flush;
     Bool_t bracket = fOperatorType!=kENoop && !fMember->InheritsFrom(MDataList::Class());
 
@@ -483,3 +485,45 @@
     if (bracket)
         *fLog << ")" << flush;
-}
+        }
+        */
+
+TString MDataChain::GetRule() const
+{
+    TString str;
+
+    Bool_t bracket = fOperatorType!=kENoop && !fMember->InheritsFrom(MDataList::Class());
+
+    switch (fOperatorType)
+    {
+    case kEAbs:      str += "abs"   ; break;
+    case kELog:      str += "log"   ; break;
+    case kELog10:    str += "log10" ; break;
+    case kESin:      str += "sin"   ; break;
+    case kECos:      str += "cos"   ; break;
+    case kETan:      str += "tan"   ; break;
+    case kESinH:     str += "sinh"  ; break;
+    case kECosH:     str += "cosh"  ; break;
+    case kETanH:     str += "tanh"  ; break;
+    case kEASin:     str += "asin"  ; break;
+    case kEACos:     str += "acos"  ; break;
+    case kEATan:     str += "atan"  ; break;
+    case kESqrt:     str += "sqrt"  ; break;
+    case kEExp:      str += "exp"   ; break;
+    case kEPow10:    str += "pow10" ; break;
+    case kESgn:      str += "sgn"   ; break;
+    case kENegative: str += "-"     ; break;
+    case kEPositive: str += "+"     ; break;
+    case kENoop:
+        break;
+    }
+
+    if (bracket)
+        str += "(";
+
+    str += fMember->GetRule();
+
+    if (bracket)
+        str += ")";
+
+    return str;
+}
Index: /trunk/MagicSoft/Mars/mdata/MDataChain.h
===================================================================
--- /trunk/MagicSoft/Mars/mdata/MDataChain.h	(revision 1473)
+++ /trunk/MagicSoft/Mars/mdata/MDataChain.h	(revision 1474)
@@ -63,5 +63,7 @@
     Bool_t IsReadyToSave() const;
 
-    void Print(Option_t *opt = "") const;
+//    void Print(Option_t *opt = "") const;
+
+    TString GetRule() const;
 
     ClassDef(MDataChain, 0) // A chain/concatenation of MData objects
Index: /trunk/MagicSoft/Mars/mdata/MDataList.cc
===================================================================
--- /trunk/MagicSoft/Mars/mdata/MDataList.cc	(revision 1473)
+++ /trunk/MagicSoft/Mars/mdata/MDataList.cc	(revision 1474)
@@ -204,4 +204,5 @@
 // one the option string must conatin a "v"
 //
+/*
 void MDataList::Print(Option_t *opt) const
 {
@@ -251,4 +252,52 @@
 
     *fLog << ")" << flush;
-}
-
+    }
+    */
+
+TString MDataList::GetRule() const
+{
+    TIter Next(&fMembers);
+
+    MData *member=(MData*)Next();
+
+    //
+    // loop over all members
+    //
+    if (!member)
+        return "(<empty>)";
+
+    TString str = "(";
+
+    str += member->GetRule();
+
+    while ((member=(MData*)Next()))
+    {
+        switch (fSign)
+        {
+        case kENone:
+            break;
+
+        case kEPlus:
+            str += "+";
+            break;
+
+        case kEMinus:
+            str += "-";
+            break;
+
+        case kEMult:
+            str += "*";
+            break;
+
+        case kEDiv:
+            str += "/";
+            break;
+        }
+
+        str += member->GetRule();
+    }
+
+    str += ")";
+
+    return str;
+}
Index: /trunk/MagicSoft/Mars/mdata/MDataList.h
===================================================================
--- /trunk/MagicSoft/Mars/mdata/MDataList.h	(revision 1473)
+++ /trunk/MagicSoft/Mars/mdata/MDataList.h	(revision 1474)
@@ -46,5 +46,6 @@
     Bool_t PreProcess(const MParList *plist);
 
-    void Print(Option_t *opt = "") const;
+//    void Print(Option_t *opt = "") const;
+    TString GetRule() const;
 
     ClassDef(MDataList, 0) // A concatenation of MData objects by one operator
Index: /trunk/MagicSoft/Mars/mdata/MDataMember.cc
===================================================================
--- /trunk/MagicSoft/Mars/mdata/MDataMember.cc	(revision 1473)
+++ /trunk/MagicSoft/Mars/mdata/MDataMember.cc	(revision 1474)
@@ -158,7 +158,13 @@
 // Print the name of the data member without an CR.
 //
+/*
 void MDataMember::Print(Option_t *opt) const
 {
     *fLog << fName << flush;
 }
+*/
 
+TString MDataMember::GetRule() const
+{
+    return fName;
+}
Index: /trunk/MagicSoft/Mars/mdata/MDataMember.h
===================================================================
--- /trunk/MagicSoft/Mars/mdata/MDataMember.h	(revision 1473)
+++ /trunk/MagicSoft/Mars/mdata/MDataMember.h	(revision 1474)
@@ -32,5 +32,6 @@
     Bool_t IsReadyToSave() const;
 
-    void Print(Option_t *opt = "") const;
+    //void Print(Option_t *opt = "") const;
+    TString GetRule() const;
 
     ClassDef(MDataMember, 0) // MData object corresponding to a single data member of a Mars container
Index: /trunk/MagicSoft/Mars/mdata/MDataValue.cc
===================================================================
--- /trunk/MagicSoft/Mars/mdata/MDataValue.cc	(revision 1473)
+++ /trunk/MagicSoft/Mars/mdata/MDataValue.cc	(revision 1474)
@@ -16,5 +16,5 @@
 !
 !
-!   Author(s): Thomas Bretz  04/2002 <mailto:tbretz@uni-sw.gwdg.de>
+!   Author(s): Thomas Bretz  04/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
 !
 !   Copyright: MAGIC Software Development, 2000-2002
@@ -40,9 +40,11 @@
 // --------------------------------------------------------------------------
 //
-// Print the value
+// Return the value as a string
 //
-void MDataValue::Print(Option_t *opt) const
+TString MDataValue::GetRule() const
 {
-    *fLog << fValue << flush;
+    TString str;
+    str += fValue;
+    return str.Strip(TString::kBoth);
 }
 
Index: /trunk/MagicSoft/Mars/mdata/MDataValue.h
===================================================================
--- /trunk/MagicSoft/Mars/mdata/MDataValue.h	(revision 1473)
+++ /trunk/MagicSoft/Mars/mdata/MDataValue.h	(revision 1474)
@@ -28,5 +28,6 @@
     Bool_t IsReadyToSave() const { return kFALSE; }
 
-    void Print(Option_t *opt = "") const;
+    //void Print(Option_t *opt = "") const;
+    TString GetRule() const;
 
     ClassDef(MDataValue, 0) // MData object corresponding to a single value
Index: /trunk/MagicSoft/Mars/mfileio/MReadTree.cc
===================================================================
--- /trunk/MagicSoft/Mars/mfileio/MReadTree.cc	(revision 1473)
+++ /trunk/MagicSoft/Mars/mfileio/MReadTree.cc	(revision 1474)
@@ -777,4 +777,10 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// Implementation of SavePrimitive. Used to write the call to a constructor
+// to a macro. In the original root implementation it is used to write
+// gui elements to a macro-file.
+//
 void MReadTree::SavePrimitive(ofstream &out, Option_t *o="")
 {
Index: /trunk/MagicSoft/Mars/mfileio/MWriteRootFile.cc
===================================================================
--- /trunk/MagicSoft/Mars/mfileio/MWriteRootFile.cc	(revision 1473)
+++ /trunk/MagicSoft/Mars/mfileio/MWriteRootFile.cc	(revision 1474)
@@ -397,4 +397,10 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// Implementation of SavePrimitive. Used to write the call to a constructor
+// to a macro. In the original root implementation it is used to write
+// gui elements to a macro-file.
+//
 void MWriteRootFile::SavePrimitive(ofstream &out, Option_t *o="")
 {
@@ -413,5 +419,5 @@
         out << entry->GetContName() << "\", \"";
         out << entry->GetName() << "\", \"";
-        out << entry->GetTitle() << "\")" << endl;
+        out << entry->GetTitle() << "\");" << endl;
     }
 }
Index: /trunk/MagicSoft/Mars/mhist/MBinning.cc
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MBinning.cc	(revision 1473)
+++ /trunk/MagicSoft/Mars/mhist/MBinning.cc	(revision 1474)
@@ -28,6 +28,7 @@
 //                                                                          //
 //////////////////////////////////////////////////////////////////////////////
+#include "MBinning.h"
 
-#include "MBinning.h"
+#include <fstream.h>
 
 #include "MH.h"
@@ -52,6 +53,28 @@
 
 
+// --------------------------------------------------------------------------
+//
+// Apply this binning to the given histogram.
+// (By definition this works only for 1D-histograms. For 2D- and 3D-
+//  histograms use MH::SetBinning directly)
+//
 void MBinning::Apply(TH1 &h)
 {
     MH::SetBinning(&h, this);
 }
+
+// --------------------------------------------------------------------------
+//
+// Implementation of SavePrimitive. Used to write the call to a constructor
+// to a macro. In the original root implementation it is used to write
+// gui elements to a macro-file.
+//
+void MBinning::SavePrimitive(ofstream &out, Option_t *o="")
+{
+    out << "   TArrayD dummy;" << endl;
+    for (int i=0; i<fEdges.GetSize(); i++)
+        out << "   dummy[" << i << "]=" << fEdges[i] << ";" << endl;
+    out << "   MBinning " << ToLower(fName) << "(\"";
+    out << fName << "\", \"" << fTitle << "\");" << endl;
+    out << "   " << ToLower(fName) << ".SetEdges(dummy);" << endl;
+}
Index: /trunk/MagicSoft/Mars/mhist/MBinning.h
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MBinning.h	(revision 1473)
+++ /trunk/MagicSoft/Mars/mhist/MBinning.h	(revision 1474)
@@ -54,4 +54,6 @@
     void Apply(TH1 &);
 
+    void SavePrimitive(ofstream &out, Option_t *o="");
+
     ClassDef(MBinning, 1) //Container to store the binning of a histogram
 };
Index: /trunk/MagicSoft/Mars/mhist/MFillH.cc
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MFillH.cc	(revision 1473)
+++ /trunk/MagicSoft/Mars/mhist/MFillH.cc	(revision 1474)
@@ -344,7 +344,13 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// Implementation of SavePrimitive. Used to write the call to a constructor
+// to a macro. In the original root implementation it is used to write
+// gui elements to a macro-file.
+//
 void MFillH::SavePrimitive(ofstream &out, Option_t *o="")
 {
     out << "   MFillH " << ToLower(fName) << "(\"";
-    out << fHName << "\", \"" << fParContainerName << "\")" << endl;
-}
+    out << fHName << "\", \"" << fParContainerName << "\");" << endl;
+}
Index: /trunk/MagicSoft/Mars/mhist/MH3.cc
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MH3.cc	(revision 1473)
+++ /trunk/MagicSoft/Mars/mhist/MH3.cc	(revision 1474)
@@ -58,6 +58,7 @@
 //
 /////////////////////////////////////////////////////////////////////////////
-
 #include "MH3.h"
+
+#include <fstream.h>
 
 #include <TH2.h>
@@ -77,4 +78,13 @@
 ClassImp(MH3);
 
+MH3::MH3() : fDimension(0), fHist(NULL)
+{
+    fName  = "MH3";
+    fTitle = "Container for a 1D Mars Histogram";
+
+    fData[0]  = fData[1]  = fData[2]  = NULL;
+    fScale[0] = fScale[1] = fScale[2] = 1;
+}
+
 // --------------------------------------------------------------------------
 //
@@ -367,2 +377,38 @@
     gPad->Update();
 }
+
+// --------------------------------------------------------------------------
+//
+// Implementation of SavePrimitive. Used to write the call to a constructor
+// to a macro. In the original root implementation it is used to write
+// gui elements to a macro-file.
+//
+void MH3::SavePrimitive(ofstream &out, Option_t *o="")
+{
+    TString name = ToLower(fName);
+
+    out << "   MH3 " << name << "(\"";
+    out << fData[0]->GetRule() << "\"";
+    if (fDimension>1)
+        out << ", \"" << fData[1]->GetRule() << "\"";
+    if (fDimension>2)
+        out << ", \"" << fData[2]->GetRule() << "\"";
+
+    out << ");" << endl;
+
+    out << "   " << name << ".SetName(\"" << fName << "\");" << endl;
+    out << "   " << name << ".SetTitle(\"" << fTitle << "\");" << endl;
+
+    switch (fDimension)
+    {
+    case 3:
+        if (fScale[2]!=1)
+            out << "   " << name << ".SetScaleZ(" << fScale[2] << ");" << endl;
+    case 2:
+        if (fScale[1]!=1)
+            out << "   " << name << ".SetScaleY(" << fScale[1] << ");" << endl;
+    case 1:
+        if (fScale[0]!=1)
+            out << "   " << name << ".SetScaleX(" << fScale[0] << ");" << endl;
+    }
+}
Index: /trunk/MagicSoft/Mars/mhist/MH3.h
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MH3.h	(revision 1473)
+++ /trunk/MagicSoft/Mars/mhist/MH3.h	(revision 1474)
@@ -25,4 +25,5 @@
 
 public:
+    MH3();
     MH3(const char *memberx);
     MH3(const char *memberx, const char *membery);
@@ -48,4 +49,6 @@
     TObject *DrawClone(Option_t *opt=NULL) const;
 
+    void SavePrimitive(ofstream &out, Option_t *o="");
+
     ClassDef(MH3, 1) // Generalized 1/2/3D-histogram for Mars variables
 };
