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:
