Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 1524)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 1525)
@@ -1,3 +1,69 @@
                                                                   -*-*- END -*-*-
+
+ 2002/09/16: Thomas Bretz
+
+   * macros/rootlogon.C:
+     - added SetMakeSharedLib to make it work correctly on linux
+
+   * manalysis/AnalysisLinkDef.h, manalysis/Makefile:
+     - added MEnergyEstParam
+     - added MMatrixLoop
+
+   * manalysis/MEnergyEstParam.[h,cc], manalysis/MMatrixLoop.[h,cc]:
+     - added
+
+   * manalysis/MEnergyEst.h:
+     - added fImpact provisionally
+     - changed to 'no-storage'
+
+   * manalysis/MHillas.[h,cc], manalysis/MHillasExt.[h,cc],
+     manalysis/MHillasSrc.[h,cc]:
+     - added set function to support Thomas Schweitzers Image files
+
+   * mbase/MFilter.cc:
+     - small changes to output
+
+   * mbase/MLog.[h,cc]:
+     - added IsNull to switch off output completely
+
+   * mbase/MParList.[h,cc]:
+     - added Remove function
+     - added IsOwner function
+     - changes to SavePrimitive
+     - kDoNotReset-support
+
+   * mbase/MTaskList.cc:
+     - make sure, that in sub-tasklist the parameterlist isn't reset
+
+   * mdata/MDataLinkDef.h, mdata/Makefile:
+     - added MDataElement
+     - added mhist-path
+
+   * mdata/MDataChain.[h,cc]:
+     - added support for MDataElement
+
+   * mhist/MH3.[h,cc]:
+     - added enums for log-scale
+     - set logscale automatic when drawing
+     - added 'only' option to draw functions
+     - set colors when 'col' option is given
+
+   * mhist/MHHillas.cc:
+     - better hist range for fCenter
+
+   * mhist/MHMatrix.[h,cc]:
+     - made default name and title a static class member
+     - changed AddColumn now returning the new comlumn index
+     - added Fill to fill Matrix from file
+     - added locking
+     - added IsValid
+     - added GetNumRows
+     - added SetNumRow
+     - added []-operator
+     - added GetNumRow
+
+   * mhist/MHStarMap.cc:
+     - fixed some comments
+
 
  2002/09/02: Thomas Bretz
Index: /trunk/MagicSoft/Mars/manalysis/MEnergyEst.cc
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MEnergyEst.cc	(revision 1524)
+++ /trunk/MagicSoft/Mars/manalysis/MEnergyEst.cc	(revision 1525)
@@ -34,4 +34,7 @@
 #include "MEnergyEst.h"
 
+#include "MLog.h"
+#include "MLogManip.h"
+
 ClassImp(MEnergyEst);
 
@@ -46,3 +49,7 @@
 }
 
+void MEnergyEst::Print(Option_t *o) const
+{
+    *fLog << all << GetDescriptor() << ": Eest = " << (int)fEnergy << "GeV \t Ir = " << (int)(fImpact/100) << "m" << endl;
+}
 
Index: /trunk/MagicSoft/Mars/manalysis/MEnergyEstParam.cc
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MEnergyEstParam.cc	(revision 1525)
+++ /trunk/MagicSoft/Mars/manalysis/MEnergyEstParam.cc	(revision 1525)
@@ -0,0 +1,284 @@
+/* ======================================================================== *\
+!
+! *
+! * This file is part of MARS, the MAGIC Analysis and Reconstruction
+! * Software. It is distributed to you in the hope that it can be a useful
+! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
+! * It is distributed WITHOUT ANY WARRANTY.
+! *
+! * Permission to use, copy, modify and distribute this software and its
+! * documentation for any purpose is hereby granted without fee,
+! * provided that the above copyright notice appear in all copies and
+! * that both that copyright notice and this permission notice appear
+! * in supporting documentation. It is provided "as is" without express
+! * or implied warranty.
+! *
+!
+!
+!   Author(s): Thomas Bretz  9/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2002
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//                                                                         //
+// MEnergyEstParam                                                         //
+//                                                                         //
+// Task to estimate the energy using a parametrization.                    //
+// Make sure, that all source dependant containers are based on the same   //
+// set of basic hillas parameters                                          //
+//                                                                         //
+/////////////////////////////////////////////////////////////////////////////
+#include "MEnergyEstParam.h"
+
+#include "MParList.h"
+
+#include "MMcEvt.hxx"
+#include "MHMatrix.h"
+#include "MHillasSrc.h"
+#include "MEnergyEst.h"
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+ClassImp(MEnergyEstParam);
+
+// --------------------------------------------------------------------------
+//
+// Initialize the coefficients with (nonsense) values
+//
+void MEnergyEstParam::InitCoefficients()
+{
+    fA[0] =   39.667402; // [cm]
+    fA[1] =  143.081912; // [cm]
+    fA[2] = -395.501677; // [cm]
+    fA[3] =    0.006193;
+
+    fB[0] =   45.037867; // [GeV]
+    fB[1] =    0.087222; // [GeV]
+    fB[2] =   -0.208065; // [GeV/cm]
+    fB[3] =   78.164942; // [GeV]
+    fB[4] = -159.361283; // [GeV]
+    fB[5] =   -0.130455; // [GeV/cm]
+    fB[6] =    0.051139;
+}
+
+// --------------------------------------------------------------------------
+//
+// Default constructor. Give the name of the parameter container (MHillas)
+// storing wisth, length and size (Default="MHillas").
+// For the Zenith Angle MMcEvt.fTheta is used.
+//
+MEnergyEstParam::MEnergyEstParam(const char *hillas, const char *name, const char *title)
+   : fMatrix(NULL), fA(4), fB(7)
+{
+    fName  = name  ? name  : "MEnergyEstParam";
+    fTitle = title ? title : "Task to estimate the energy";
+
+    fHillasName = hillas;
+
+    fPairs     = new TList;
+    fEnergy    = new TList;
+    fHillasSrc = new TList;
+
+    fPairs->SetOwner();
+
+    InitCoefficients();
+
+    AddToBranchList("MMcEvt.fTheta");
+    AddToBranchList(fHillasName+"fSize");
+    AddToBranchList(fHillasName+"fWidth");
+    AddToBranchList(fHillasName+"fLength");
+}
+
+
+// --------------------------------------------------------------------------
+//
+// Destructor.
+//
+MEnergyEstParam::~MEnergyEstParam()
+{
+    delete fPairs;
+    delete fEnergy;
+    delete fHillasSrc;
+}
+
+// --------------------------------------------------------------------------
+//
+// Check for all necessary parameter containers.
+//
+Bool_t MEnergyEstParam::PreProcess(MParList *plist)
+{
+    if (!fMatrix)
+    {
+        fHillas = (MHillas*)plist->FindObject(fHillasName, "MHillas");
+        if (!fHillas)
+        {
+            *fLog << err << dbginf << fHillasName << " [MHillas] not found... aborting." << endl;
+            return kFALSE;
+        }
+
+        fMc = (MMcEvt*)plist->FindObject("MMcEvt");
+        if (!fMc)
+        {
+            *fLog << err << dbginf << "MMcEvt not found... aborting." << endl;
+            return kFALSE;
+        }
+    }
+
+    TObject *obj = NULL;
+    TIter Next(fPairs);
+
+    while ((obj=Next()))
+    {
+        TObject *o = plist->FindCreateObj(obj->GetTitle(), "MEnergyEst");
+        if (!o)
+            return kFALSE;
+
+        if (!fEnergy->FindObject(obj->GetTitle()))
+            fEnergy->Add(o);
+
+        if (fMatrix)
+            continue;
+
+        o = plist->FindObject(obj->GetName(), "MHillasSrc");
+        if (!o)
+        {
+            *fLog << err << dbginf << obj->GetName() << " not found... aborting." << endl;
+            return kFALSE;
+        }
+        fHillasSrc->Add(o);
+    }
+
+   return kTRUE;    
+}
+
+// --------------------------------------------------------------------------
+//
+// Set the four coefficients for the estimation of the impact parameter.
+// Argument must ba a TArrayD of size 4.
+//
+void MEnergyEstParam::SetCoeffA(TArrayD arr)
+{
+    if (arr.GetSize() != fA.GetSize())
+    {
+        *fLog << err << dbginf << "Error - Wrong number of coefficients!" << endl;
+        return;
+    }
+
+    fA = arr;
+}
+
+// --------------------------------------------------------------------------
+//
+// Set the four coefficients for the estimation of the energy.
+// Argument must ba a TArrayD of size 7.
+//
+void MEnergyEstParam::SetCoeffB(TArrayD arr)
+{
+    if (arr.GetSize() != fB.GetSize())
+    {
+        *fLog << err << dbginf << "Error - Wrong number of coefficients!" << endl;
+        return;
+    }
+
+    fB = arr;
+}
+
+// --------------------------------------------------------------------------
+//
+// Returns the mapped value from the Matrix
+//
+Double_t MEnergyEstParam::GetVal(Int_t i) const
+{
+    return (*fMatrix)[fMap[i]];
+}
+
+// --------------------------------------------------------------------------
+//
+// You can use this function if you want to use a MHMatrix instead of the
+// given containers. This function adds all necessary columns to the
+// given matrix. Afterward you should fill the matrix with the corresponding
+// data (eg from a file by using MHMatrix::Fill). If you now loop
+// through the matrix (eg using MMatrixLoop) MEnergyEstParam::Process
+// will take the values from the matrix instead of the containers.
+//
+void MEnergyEstParam::InitMapping(MHMatrix *mat)
+{
+    if (fMatrix)
+        return;
+
+    fMatrix = mat;
+
+    fMap[0] = fMatrix->AddColumn("MMcEvt.fTheta");
+    fMap[1] = fMatrix->AddColumn(fHillasName+".fWidth");
+    fMap[2] = fMatrix->AddColumn(fHillasName+".fLength");
+    fMap[3] = fMatrix->AddColumn(fHillasName+".fSize");
+
+    Int_t col = 4;
+    TIter Next(fPairs);
+    TObject *o = NULL;
+    while ((o=Next()))
+        fMap[col++] = fMatrix->AddColumn(TString(o->GetName())+".fDist");
+}
+
+// --------------------------------------------------------------------------
+//
+// Add a pair of input/output containers.
+//   eg. Add("MHillasSrc", "MEnergyEst");
+// Usefull if you want to estimate the stuff for the source and antisource
+//
+void MEnergyEstParam::Add(const TString hillas, const TString energy)
+{
+    fPairs->Add(new TNamed(hillas, energy));
+
+    AddToBranchList(hillas+".fDist");
+}
+
+// --------------------------------------------------------------------------
+//
+//  Estimates the impact parameter and energy using a parameterization
+//  (see code)
+//
+Bool_t MEnergyEstParam::Process()
+{
+    const Double_t theta  = fMatrix ? GetVal(0) : fMc->GetTheta();
+    const Double_t width  = fMatrix ? GetVal(1) : fHillas->GetWidth();
+    const Double_t length = fMatrix ? GetVal(2) : fHillas->GetLength();
+    const Double_t size   = fMatrix ? GetVal(3) : fHillas->GetSize();
+
+    const Double_t k   = 1/cos(theta);
+    const Double_t k2  = k*k;
+
+    const Double_t i0 = k * (1+fA[3]*k)/(1+fA[3]);
+    const Double_t i1 = fA[0] + fA[2]*width;
+
+    const Double_t e0 = k2 * (1+fB[6]*k2)/(1+fB[6]);
+    const Double_t e1 = fB[0] + fB[1]*size + fB[3]*length + fB[4]*size*length;
+    const Double_t e2 = fB[2] + fB[5]*length;
+
+    TIter NextH(fHillasSrc);
+    TIter NextE(fEnergy);
+
+    Int_t col = 4;
+
+    while (1)
+    {
+        MEnergyEst *est = (MEnergyEst*)NextE();
+        if (!est)
+            break;
+
+        const Double_t dist = fMatrix ? GetVal(col++) : ((MHillasSrc*)NextH())->GetDist();
+
+        const Double_t ir =  i0 * (i1 + fA[1]*dist); // [cm]
+        const Double_t er = -e0 * (e1 + e2*ir);      // [GeV]
+
+        est->SetEnergy(er);
+        est->SetImpact(ir);
+    }
+
+    return kTRUE;
+}
+
Index: /trunk/MagicSoft/Mars/manalysis/MEnergyEstParam.h
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MEnergyEstParam.h	(revision 1525)
+++ /trunk/MagicSoft/Mars/manalysis/MEnergyEstParam.h	(revision 1525)
@@ -0,0 +1,59 @@
+#ifndef MARS_MEnergyEstParam
+#define MARS_MEnergyEstParam
+
+#ifndef MARS_MTask
+#include "MTask.h"
+#endif
+
+#ifndef ROOT_TArrayD
+#include <TArrayD.h>
+#endif
+
+class MHillasSrc;
+class MEnergyEst;
+class MHillas;
+class MMcEvt;
+class MHMatrix;
+
+class MEnergyEstParam : public MTask
+{
+private:
+    Int_t     fMap[100];
+
+    MHMatrix *fMatrix;
+
+    TList    *fPairs;
+
+    TList    *fHillasSrc;
+    TList    *fEnergy;
+
+    MHillas  *fHillas;
+    TString   fHillasName;
+
+    TArrayD   fA;
+    TArrayD   fB;
+
+    MMcEvt   *fMc;
+
+    void InitCoefficients();
+
+    Double_t GetVal(Int_t i) const;
+
+public:
+    MEnergyEstParam(const char *hil="MHillas", const char *name=NULL, const char *title=NULL);
+    ~MEnergyEstParam();
+
+    Bool_t PreProcess(MParList *plist);
+    Bool_t Process();
+
+    void Add(const TString hillas, const TString energy);
+
+    void InitMapping(MHMatrix *mat);
+
+    void SetCoeffA(TArrayD arr);
+    void SetCoeffB(TArrayD arr);
+
+    ClassDef(MEnergyEstParam, 0) // Task to estimate the energy
+};
+
+#endif
Index: /trunk/MagicSoft/Mars/manalysis/MMatrixLoop.cc
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MMatrixLoop.cc	(revision 1525)
+++ /trunk/MagicSoft/Mars/manalysis/MMatrixLoop.cc	(revision 1525)
@@ -0,0 +1,62 @@
+/* ======================================================================== *\
+!
+! *
+! * This file is part of MARS, the MAGIC Analysis and Reconstruction
+! * Software. It is distributed to you in the hope that it can be a useful
+! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
+! * It is distributed WITHOUT ANY WARRANTY.
+! *
+! * Permission to use, copy, modify and distribute this software and its
+! * documentation for any purpose is hereby granted without fee,
+! * provided that the above copyright notice appear in all copies and
+! * that both that copyright notice and this permission notice appear
+! * in supporting documentation. It is provided "as is" without express
+! * or implied warranty.
+! *
+!
+!
+!   Author(s): Thomas Bretz  9/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2002
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// MMatrixLoop
+//
+// Use this task instead of reading from a file. It loops through the rows
+// of a given MHMatrix. PreProcessing the task again starts from scratch.
+//
+/////////////////////////////////////////////////////////////////////////////
+#include "MMatrixLoop.h"
+
+#include "MHMatrix.h"
+
+ClassImp(MMatrixLoop);
+
+const TString MMatrixLoop::gsDefName  = "MMatrixLoop";
+const TString MMatrixLoop::gsDefTitle = "Loop through a MHMatrix (instead of reading from a file)";
+
+// --------------------------------------------------------------------------
+//
+//  Default Constructor. Specify the MHMatrix object you want to loop
+//  through.
+//
+MMatrixLoop::MMatrixLoop(MHMatrix *mat, const char *name, const char *title) : fMatrix(mat)
+{
+    fName  = name  ? name  : gsDefName.Data();
+    fTitle = title ? title : gsDefTitle.Data();
+}
+
+// --------------------------------------------------------------------------
+//
+// Set the present row of the Matrix, stops the loop when all rows have
+// been accessed.
+//
+Bool_t MMatrixLoop::Process()
+{
+    return fMatrix->SetNumRow(fNumRow++);
+}
+
Index: /trunk/MagicSoft/Mars/manalysis/MMatrixLoop.h
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MMatrixLoop.h	(revision 1525)
+++ /trunk/MagicSoft/Mars/manalysis/MMatrixLoop.h	(revision 1525)
@@ -0,0 +1,35 @@
+#ifndef MARS_MMatrixLoop
+#define MARS_MMatrixLoop
+
+#ifndef MARS_MTask
+#include "MTask.h"
+#endif
+
+class MHMatrix;
+
+class MMatrixLoop : public MTask
+{
+private:
+    static const TString gsDefName;
+    static const TString gsDefTitle;
+
+protected:
+    MHMatrix *fMatrix;
+    Int_t     fNumRow;    //! Number of dimensions of histogram
+
+public:
+    MMatrixLoop(MHMatrix *mat, const char *name=NULL, const char *title=NULL);
+
+    Bool_t PreProcess(MParList *plist)
+    {
+        fNumRow = 0;
+
+        return fMatrix ? kTRUE : kFALSE;
+    }
+
+    Bool_t Process();
+
+    ClassDef(MMatrixLoop, 0)
+};
+
+#endif
Index: /trunk/MagicSoft/Mars/mbase/MEvtLoop.cc
===================================================================
--- /trunk/MagicSoft/Mars/mbase/MEvtLoop.cc	(revision 1524)
+++ /trunk/MagicSoft/Mars/mbase/MEvtLoop.cc	(revision 1525)
@@ -101,4 +101,5 @@
 MEvtLoop::MEvtLoop() : fParList(NULL), fProgress(NULL)
 {
+    fName = "Evtloop";
 }
 
@@ -300,50 +301,95 @@
 //  eventloop setup as a macro. The default name is "evtloop.C". The default
 //  extension is .C If the extension is not given, .C is added.
+//  I the last character in the argument is a '+' the file is not closed.
+//  This is usefull if you have an eventloop which runs three times and
+//  you want to write one macro. If the first character is a '+' no
+//  opening is written, eg:
+//
+//     MEvtLoop evtloop;
+//     // some setup
+//     evtloop.MakeMacro("mymacro+");
+//     // replace the tasklist the first time
+//     evtloop.MakeMacro("+mymacro+");
+//     // replace the tasklist the second time
+//     evtloop.MakeMacro("+mymacro");
 //
 void MEvtLoop::MakeMacro(const char *filename)
 {
     TString name(filename);
+
+    name = name.Strip(TString::kBoth);
+
+    Bool_t open  = kTRUE;
+    Bool_t close = kTRUE;
+    if (name[0]=='+')
+    {
+        open = kFALSE;
+        name.Remove(0, 1);
+        name = name.Strip(TString::kBoth);
+    }
+
+    if (name[name.Length()-1]=='+')
+    {
+        close = kFALSE;
+        name.Remove(name.Length()-1, 1);
+        name = name.Strip(TString::kBoth);
+    }
 
     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);
+    ofstream fout;
+
+    if (!open)
+    {
+        fout.open(name, ios::app);
+        fout << endl;
+        fout << "   // ----------------------------------------------------------------------" << endl;
+        fout << endl;
+    }
+    else
+    {
+        fout.open(name);
+
+        time_t t = time(NULL);
+        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, (TString)"" + (open?"open":"") + (close?"close":""));
+
+    if (!close)
+        return;
 
     fout << "}" << endl;
@@ -358,6 +404,15 @@
 // gui elements to a macro-file.
 //
-void MEvtLoop::SavePrimitive(ofstream &out, Option_t *)
-{
+
+void MEvtLoop::StreamPrimitive(ofstream &out) const
+{
+    out << "   MEvtLoop " << GetUniqueName() << ";" << endl;
+}
+
+void MEvtLoop::SavePrimitive(ofstream &out, Option_t *opt)
+{
+    TString options = opt;
+    options.ToLower();
+
     if (HasDuplicateNames("MEvtLoop::SavePrimitive"))
     {
@@ -370,22 +425,33 @@
     }
 
-    gListOfPrimitives = new TList;
+    if (!options.Contains("open"))
+    {
+        if (gListOfPrimitives)
+        {
+            *fLog << err << "MEvtLoop::SavePrimitive - Error: old file not closed." << endl;
+            gListOfPrimitives->ForEach(TObject, ResetBit)(BIT(15));
+            delete gListOfPrimitives;
+        }
+        gListOfPrimitives = new TList;
+    }
 
     if (fParList)
         fParList->SavePrimitive(out);
 
-    out << "   MEvtLoop evtloop;" << endl;
+    MParContainer::SavePrimitive(out);
+
     if (fParList)
-        out << "   evtloop.SetParList(&" << fParList->GetUniqueName() << ");" << endl;
+        out << "   " << GetUniqueName() << ".SetParList(&" << fParList->GetUniqueName() << ");" << endl;
     else
         out << "   // fParList empty..." << endl;
-    out << "   if (!evtloop.Eventloop())" << endl;
+    out << "   if (!" << GetUniqueName() << ".Eventloop())" << endl;
     out << "      return;" << endl;
+
+    if (!options.Contains("close"))
+        return;
 
     gListOfPrimitives->ForEach(TObject, ResetBit)(BIT(15));
     delete gListOfPrimitives;
     gListOfPrimitives = 0;
-
-    // remove all objects with BIT(15) set from gObjectTable
 }
 
Index: /trunk/MagicSoft/Mars/mbase/MParContainer.h
===================================================================
--- /trunk/MagicSoft/Mars/mbase/MParContainer.h	(revision 1524)
+++ /trunk/MagicSoft/Mars/mbase/MParContainer.h	(revision 1525)
@@ -34,12 +34,12 @@
     MLog   *fLog;         // The general log facility for this object, initialized with the global object
 
-    virtual void StreamPrimitive(ofstream &out) const;
-
 private:
-    Bool_t  fReadyToSave; // should be set to true if the contents of the container is changed somehow
-
     enum {
         kIsSavedAsPrimitive = BIT(15)
     };
+
+    Bool_t  fReadyToSave; // should be set to true if the contents of the container is changed somehow
+
+    virtual void StreamPrimitive(ofstream &out) const;
 
 public:
