Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 1482)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 1483)
@@ -39,4 +39,19 @@
    * mhist/MH3.[h,cc]:
      - added the missing const-qualifier of StreamPrimitive
+
+   * mbase/MParContainer.[h,cc]:
+     - implemented setting a unique id in SavePrimitive
+     - imnplemented GetUniqueID 
+     
+   * manalysis/MHillasSrcCalc.cc, manalysis/MImgCleanStd.cc,
+     manalysis/MSrcPosCam.cc, mbase/MEvtLoop.cc, mbase/MParList.cc,
+     mbase/MTaskList.cc, mfileio/MReadTree.cc, mfileio/MWriteRootFile.cc,
+     mhist/MF.cc, mfilter/MFAlpha.cc, mfilter/MFDataMember.cc,
+     mfilter/MFParticleId.cc, mfilter/MFTriggerLvl1.cc, mhist/MBinning.cc,
+     mhist/MFillH.cc, mhist/MH3.cc:
+     - changed the 'instance' name to the UniqueName
+     - in some files: implemented a static constant name and title, which
+       is used to descide whether the name and/or title should be stream
+       in the constructor-call in StreamPrimitive
 
 
Index: /trunk/MagicSoft/Mars/manalysis/MHillasSrcCalc.cc
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MHillasSrcCalc.cc	(revision 1482)
+++ /trunk/MagicSoft/Mars/manalysis/MHillasSrcCalc.cc	(revision 1483)
@@ -115,13 +115,13 @@
         fHillasSrc->SavePrimitive(out);
 
-    out << "   MHillasSrcCalc " << ToLower(fName) << "(";
+    out << "   MHillasSrcCalc " << GetUniqueName() << "(";
 
     if (fSrcPos)
-        out << "&" << ToLower(fSrcPos->GetName());
+        out << "&" << fSrcPos->GetUniqueName();
     else
         out << "\"" << fSrcName << "\"";
 
     if (fHillasSrc)
-        out << "&" << ToLower(fHillasSrc->GetName());
+        out << "&" << fHillasSrc->GetUniqueName();
     else
         out << "\"" << fHillasName << "\"";
Index: /trunk/MagicSoft/Mars/manalysis/MImgCleanStd.cc
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MImgCleanStd.cc	(revision 1482)
+++ /trunk/MagicSoft/Mars/manalysis/MImgCleanStd.cc	(revision 1483)
@@ -416,5 +416,5 @@
 void MImgCleanStd::StreamPrimitive(ofstream &out) const
 {
-    out << "   MImgCleanStd " << ToLower(fName) << "(";
+    out << "   MImgCleanStd " << GetUniqueName() << "(";
     out << fCleanLvl1 << ", " << fCleanLvl2 << ", \"";
     out << fName << "\", \"" << fTitle << "\");" << endl;
Index: /trunk/MagicSoft/Mars/manalysis/MSrcPosCam.cc
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MSrcPosCam.cc	(revision 1482)
+++ /trunk/MagicSoft/Mars/manalysis/MSrcPosCam.cc	(revision 1483)
@@ -90,6 +90,6 @@
 void MSrcPosCam::StreamPrimitive(ofstream &out) const
 {
-    out << "   MSrcPosCam " << ToLower(fName) << "(\"";
+    out << "   MSrcPosCam " << GetUniqueName() << "(\"";
     out << fName << "\", \"" << fTitle << "\");" << endl;
 
-    out << "   " << ToLower(fName) << ".SetXY(" << fX << ", " << fY << ");" << endl;}
+    out << "   " << GetUniqueName() << ".SetXY(" << fX << ", " << fY << ");" << endl;}
Index: /trunk/MagicSoft/Mars/mbase/MEvtLoop.cc
===================================================================
--- /trunk/MagicSoft/Mars/mbase/MEvtLoop.cc	(revision 1482)
+++ /trunk/MagicSoft/Mars/mbase/MEvtLoop.cc	(revision 1483)
@@ -371,5 +371,5 @@
     out << "   MEvtLoop evtloop;" << endl;
     if (fParList)
-        out << "   evtloop.SetParList(&" << ToLower(fParList->GetName()) << ");" << endl;
+        out << "   evtloop.SetParList(&" << fParList->GetUniqueName() << ");" << endl;
     else
         out << "   // fParList empty..." << endl;
Index: /trunk/MagicSoft/Mars/mbase/MParContainer.cc
===================================================================
--- /trunk/MagicSoft/Mars/mbase/MParContainer.cc	(revision 1482)
+++ /trunk/MagicSoft/Mars/mbase/MParContainer.cc	(revision 1483)
@@ -37,4 +37,5 @@
 #include "MParContainer.h"
 
+#include <ctype.h>       // isdigit
 #include <fstream.h>     // ofstream, AsciiWrite
 
@@ -139,4 +140,22 @@
 // --------------------------------------------------------------------------
 //
+//  Return a unique name for this container. It is created from
+//  the container name and the unique Id. (This is mostly used
+//  in the StreamPrimitive member functions)
+//
+const TString MParContainer::GetUniqueName() const
+{
+    TString ret = ToLower(fName);
+
+    if (isdigit(ret[ret.Length()-1]))
+        ret+="_";
+
+    ret+=GetUniqueID();
+
+    return ret;
+}
+
+// --------------------------------------------------------------------------
+//
 //  List MParContainer name and title.
 //
@@ -359,7 +378,10 @@
 void MParContainer::SavePrimitive(ofstream &out, Option_t *o)
 {
+    static UInt_t uid = 0;
+
     if (IsSavedAsPrimitive())
         return;
 
+    SetUniqueID(uid++/*gRandom->Uniform(kMaxInt)*/);
     StreamPrimitive(out);
     SetBit(kIsSavedAsPrimitive);
@@ -373,5 +395,5 @@
 {
     out << "   // Using MParContainer::StreamPrimitive" << endl;
-    out << "   " << ClassName() << " " << ToLower(fName) << "(\"";
+    out << "   " << ClassName() << " " << GetUniqueName() << "(\"";
     out << fName << "\", \"" << fTitle << "\");" << endl;
 }
Index: /trunk/MagicSoft/Mars/mbase/MParContainer.h
===================================================================
--- /trunk/MagicSoft/Mars/mbase/MParContainer.h	(revision 1482)
+++ /trunk/MagicSoft/Mars/mbase/MParContainer.h	(revision 1483)
@@ -55,9 +55,10 @@
     virtual void        FillBuffer(char *&buffer);
 
-    virtual const char *GetDescriptor() const { return Form("%s [%s]", fName.Data(), ClassName()); }
-    virtual const char *GetName() const       { return fName.Data(); }
-    virtual const char *GetTitle() const      { return fTitle.Data(); }
-    virtual ULong_t     Hash() const          { return fName.Hash(); }
-    virtual Bool_t      IsSortable() const    { return kTRUE; }
+    virtual const char   *GetDescriptor() const { return Form("%s [%s]", fName.Data(), ClassName()); }
+    virtual const TString GetUniqueName() const;
+    virtual const char   *GetName() const       { return fName.Data(); }
+    virtual const char   *GetTitle() const      { return fTitle.Data(); }
+    virtual ULong_t       Hash() const          { return fName.Hash(); }
+    virtual Bool_t        IsSortable() const    { return kTRUE; }
 
     virtual void        SetName(const char *name); // *MENU*
Index: /trunk/MagicSoft/Mars/mbase/MParList.cc
===================================================================
--- /trunk/MagicSoft/Mars/mbase/MParList.cc	(revision 1482)
+++ /trunk/MagicSoft/Mars/mbase/MParList.cc	(revision 1483)
@@ -52,4 +52,7 @@
 ClassImp(MParList);
 
+static const TString gsDefName  = "MParList";
+static const TString gsDefTitle = "A list of Parameter Containers";
+
 // --------------------------------------------------------------------------
 //
@@ -59,6 +62,6 @@
 MParList::MParList(const char *name, const char *title)
 {
-    fName  = name  ? name  : "MParList";
-    fTitle = title ? title : "A list of Parameter Containers";
+    fName  = name  ? name  : gsDefName.Data();
+    fTitle = title ? title : gsDefTitle.Data();
 
     //
@@ -668,19 +671,31 @@
 void MParList::StreamPrimitive(ofstream &out) const
 {
-    out << "   MParList " << ToLower(fName) << "(\"";
-    out << fName << "\", \"" << fTitle << "\");" << endl << endl;
+    out << "   MParList " << GetUniqueName();
+    if (fName!=gsDefName)
+    {
+        out << "(\"" << fName << "\"";
+        if (fTitle!=gsDefTitle)
+            out << ", \"" << fTitle << "\"";
+        out <<")";
+    }
+    out << ";" << endl << endl;
 
     TIter Next(fContainer);
 
-    TObject *cont = NULL;
-    while ((cont=Next()))
+    MParContainer *cont = NULL;
+    while ((cont=(MParContainer*)Next()))
     {
         cont->SavePrimitive(out, "");
 
-        out << "   " << ToLower(fName) << ".AddToList(&";
-        out << ToLower(cont->GetName()) << ");" << endl << endl;
-    }
-}
-
+        out << "   " << GetUniqueName() << ".AddToList(&";
+        out << cont->GetUniqueName() << ");" << endl << endl;
+    }
+}
+
+// --------------------------------------------------------------------------
+//
+// Adds one TNamed object per object in the list. The TNamed object must
+// be deleted by the user.
+//
 void MParList::GetNames(TObjArray &arr) const
 {
@@ -689,4 +704,9 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// Sets name and title of each object in the list from the objects in
+// the array.
+//
 void MParList::SetNames(TObjArray &arr)
 {
Index: /trunk/MagicSoft/Mars/mbase/MTaskList.cc
===================================================================
--- /trunk/MagicSoft/Mars/mbase/MTaskList.cc	(revision 1482)
+++ /trunk/MagicSoft/Mars/mbase/MTaskList.cc	(revision 1483)
@@ -71,4 +71,6 @@
 ClassImp(MTaskList);
 
+static const TString gsDefName  = "MTaskList";
+static const TString gsDefTitle = "A list for tasks to be executed";
 // --------------------------------------------------------------------------
 //
@@ -79,6 +81,6 @@
 MTaskList::MTaskList(const char *name, const char *title)
 {
-    fName  = name  ? name  : "MTaskList";
-    fTitle = title ? title : "A list for tasks to be executed";
+    fName  = name  ? name  : gsDefName.Data();
+    fTitle = title ? title : gsDefTitle.Data();
 
     fTasks = new TList;
@@ -522,15 +524,22 @@
 void MTaskList::StreamPrimitive(ofstream &out) const
 {
-    out << "   MTaskList " << ToLower(fName) << "(\"";
-    out << fName << "\", \"" << fTitle << "\");" << endl << endl;
+    out << "   MTaskList " << GetUniqueName();
+    if (fName!=gsDefName)
+    {
+        out << "(\"" << fName << "\"";
+        if (fTitle!=gsDefTitle)
+            out << ", \"" << fTitle << "\"";
+        out <<")";
+    }
+    out << ";" << endl << endl;
 
     TIter Next(fTasks);
 
-    TObject *cont = NULL;
-    while ((cont=Next()))
+    MParContainer *cont = NULL;
+    while ((cont=(MParContainer*)Next()))
     {
         cont->SavePrimitive(out, "");
-        out << "   " << ToLower(fName) << ".AddToList(&";
-        out << ToLower(cont->GetName()) << ");" << endl << endl;
+        out << "   " << GetUniqueName() << ".AddToList(&";
+        out << cont->GetUniqueName() << ");" << endl << endl;
     }
 }
Index: /trunk/MagicSoft/Mars/mfileio/MReadTree.cc
===================================================================
--- /trunk/MagicSoft/Mars/mfileio/MReadTree.cc	(revision 1482)
+++ /trunk/MagicSoft/Mars/mfileio/MReadTree.cc	(revision 1483)
@@ -785,7 +785,5 @@
 void MReadTree::StreamPrimitive(ofstream &out) const
 {
-    TString name = ToLower(fName);
-
-    out << "   " << ClassName() << " " << name << "(\"";
+    out << "   " << ClassName() << " " << GetUniqueName() << "(\"";
     out << fChain->GetName() << "\", \"" << fName << "\", \"" << fTitle << "\");" << endl;
 
@@ -793,12 +791,12 @@
     TObject *obj = NULL;
     while ((obj=Next()))
-        out << "   " << name << ".AddFile(\"" << obj->GetTitle() << "\");" << endl;
+        out << "   " << GetUniqueName() << ".AddFile(\"" << obj->GetTitle() << "\");" << endl;
 
     if (!fAutoEnable)
-        out << "   " << name << ".DisableAutoScheme();" << endl;
+        out << "   " << GetUniqueName() << ".DisableAutoScheme();" << endl;
 
     if (fNumEntry!=0)
-       out << "   " << name << ".SetEventNum(" << fNumEntry << ");" << endl;
-
-
-}
+       out << "   " << GetUniqueName() << ".SetEventNum(" << fNumEntry << ");" << endl;
+
+
+}
Index: /trunk/MagicSoft/Mars/mfileio/MWriteRootFile.cc
===================================================================
--- /trunk/MagicSoft/Mars/mfileio/MWriteRootFile.cc	(revision 1482)
+++ /trunk/MagicSoft/Mars/mfileio/MWriteRootFile.cc	(revision 1483)
@@ -405,5 +405,5 @@
 void MWriteRootFile::StreamPrimitive(ofstream &out) const
 {
-    out << "   MWriteRootFile " << ToLower(fName) << "(\"";
+    out << "   MWriteRootFile " << GetUniqueName() << "(\"";
     out << fOut->GetName() << "\", \"";
     out << fOut->GetOption() << "\", \"";
@@ -419,5 +419,5 @@
         {
             entry->GetContainer()->SavePrimitive(out);
-            out << "&" << ToLower(entry->GetContainer()->GetName());
+            out << "&" << entry->GetContainer()->GetUniqueName();
         }
         else
Index: /trunk/MagicSoft/Mars/mfilter/MF.cc
===================================================================
--- /trunk/MagicSoft/Mars/mfilter/MF.cc	(revision 1482)
+++ /trunk/MagicSoft/Mars/mfilter/MF.cc	(revision 1483)
@@ -372,5 +372,5 @@
 void MF::StreamPrimitive(ofstream &out) const
 {
-    out << "   MF " << ToLower(fName) << "";
-}
-
+    out << "   MF " << GetUniqueName() << "";
+}
+
Index: /trunk/MagicSoft/Mars/mfilter/MFAlpha.cc
===================================================================
--- /trunk/MagicSoft/Mars/mfilter/MFAlpha.cc	(revision 1482)
+++ /trunk/MagicSoft/Mars/mfilter/MFAlpha.cc	(revision 1483)
@@ -117,8 +117,8 @@
         fHillas->SavePrimitive(out);
 
-    out << "   MFParticleId " << ToLower(fName) << "(";
+    out << "   MFParticleId " << GetUniqueName() << "(";
 
     if (fHillas)
-        out << "&" << ToLower(fHillas->GetName());
+        out << "&" << fHillas->GetUniqueName();
     else
         out << "\"" << fContName << "\"";
Index: /trunk/MagicSoft/Mars/mfilter/MFDataMember.cc
===================================================================
--- /trunk/MagicSoft/Mars/mfilter/MFDataMember.cc	(revision 1482)
+++ /trunk/MagicSoft/Mars/mfilter/MFDataMember.cc	(revision 1483)
@@ -103,5 +103,5 @@
 void MFDataMember::StreamPrimitive(ofstream &out) const
 {
-    out << "   MFDataMember " << ToLower(fName) << "(\"";
+    out << "   MFDataMember " << GetUniqueName() << "(\"";
     out << fData.GetRule() << "\", '";
     out << (fFilterType==kELowerThan?"<":">");
Index: /trunk/MagicSoft/Mars/mfilter/MFParticleId.cc
===================================================================
--- /trunk/MagicSoft/Mars/mfilter/MFParticleId.cc	(revision 1482)
+++ /trunk/MagicSoft/Mars/mfilter/MFParticleId.cc	(revision 1483)
@@ -128,8 +128,8 @@
         fMcEvt->SavePrimitive(out);
 
-    out << "   MFParticleId " << ToLower(fName) << "(";
+    out << "   MFParticleId " << GetUniqueName() << "(";
 
     if (fMcEvt)
-        out << "&" << ToLower(fMcEvt->GetName());
+        out << "&" << fMcEvt->GetUniqueName();
     else
         out << "\"" << fContName << "\"";
Index: /trunk/MagicSoft/Mars/mfilter/MFTriggerLvl1.cc
===================================================================
--- /trunk/MagicSoft/Mars/mfilter/MFTriggerLvl1.cc	(revision 1482)
+++ /trunk/MagicSoft/Mars/mfilter/MFTriggerLvl1.cc	(revision 1483)
@@ -123,8 +123,8 @@
         fMcTrig->SavePrimitive(out);
 
-    out << "   MFTriggerLvl1 " << ToLower(fName) << "(";
+    out << "   MFTriggerLvl1 " << GetUniqueName() << "(";
 
     if (fMcTrig)
-        out << "&" << ToLower(fMcTrig->GetName());
+        out << "&" << fMcTrig->GetUniqueName();
     else
         out << "\"" << fContName << "\"";
Index: /trunk/MagicSoft/Mars/mhist/MBinning.cc
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MBinning.cc	(revision 1482)
+++ /trunk/MagicSoft/Mars/mhist/MBinning.cc	(revision 1483)
@@ -36,4 +36,7 @@
 ClassImp(MBinning);
 
+static const TString gsDefName  = "MBinning";
+static const TString gsDefTitle = "Container describing the binning of an axis";
+
 // --------------------------------------------------------------------------
 //
@@ -46,6 +49,6 @@
     //   set the name and title of this object
     //
-    fName  = name  ? name  : "MBinning";
-    fTitle = title ? title : "Container describing the binning of an axis";
+    fName  = name  ? name  : gsDefName.Data();
+    fTitle = title ? title : gsDefTitle.Data();
 
     SetEdges(10, 0, 1);
@@ -105,6 +108,13 @@
 void MBinning::StreamPrimitive(ofstream &out) const
 {
-    out << "   MBinning " << ToLower(fName) << "(\"";
-    out << fName << "\", \"" << fTitle << "\");" << endl;
+    out << "   MBinning " << GetUniqueName();
+    if (fName!=gsDefName)
+    {
+        out << "(\"" << fName << "\"";
+        if (fTitle!=gsDefTitle)
+            out << ", \"" << fTitle << "\"";
+        out <<")";
+    }
+    out << ";" << endl;
 
     if (IsDefault())
@@ -113,5 +123,5 @@
     if (IsLinear() || IsLogarithmic())
     {
-        out << "   " << ToLower(fName) << ".SetEdges";
+        out << "   " << GetUniqueName() << ".SetEdges";
         if (IsLogarithmic())
             out << "Log";
@@ -124,5 +134,5 @@
     for (int i=0; i<GetNumEdges(); i++)
         out << "      dummy[" << i << "]=" << GetEdges()[i] << ";" << endl;
-    out << "      " << ToLower(fName) << ".SetEdges(dummy);" << endl;
+    out << "      " << GetUniqueName() << ".SetEdges(dummy);" << endl;
     out << "   }" << endl;
 }
Index: /trunk/MagicSoft/Mars/mhist/MFillH.cc
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MFillH.cc	(revision 1482)
+++ /trunk/MagicSoft/Mars/mhist/MFillH.cc	(revision 1483)
@@ -358,13 +358,13 @@
         fParContainer->SavePrimitive(out);
 
-    out << "   MFillH " << ToLower(fName) << "(";
+    out << "   MFillH " << GetUniqueName() << "(";
 
     if (fH)
-        out << "&" << ToLower(fH->GetName());
+        out << "&" << fH->GetUniqueName();
     else
         out << "\"" << fHName << "\"";
 
     if (fParContainer)
-        out << ", &" << ToLower(fParContainer->GetName());
+        out << ", &" << fParContainer->GetUniqueName();
     else
         if (!fParContainerName.IsNull())
Index: /trunk/MagicSoft/Mars/mhist/MH3.cc
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MH3.cc	(revision 1482)
+++ /trunk/MagicSoft/Mars/mhist/MH3.cc	(revision 1483)
@@ -78,8 +78,11 @@
 ClassImp(MH3);
 
+static const TString gsDefName  = "MH3";
+static const TString gsDefTitle = "Container for a %dD Mars Histogram";
+
 MH3::MH3() : fDimension(0), fHist(NULL)
 {
-    fName  = "MH3";
-    fTitle = "Container for a 1D Mars Histogram";
+    fName  = gsDefName;
+    fTitle = Form(gsDefTitle.Data(), 0);
 
     fData[0]  = fData[1]  = fData[2]  = NULL;
@@ -101,6 +104,6 @@
     fData[2] = NULL;
 
-    fName  = "MH3";
-    fTitle = "Container for a 1D Mars Histogram";
+    fName  = gsDefName;
+    fTitle = Form(gsDefTitle.Data(), 1);
 
     fHist->SetDirectory(NULL);
@@ -127,6 +130,6 @@
     fData[2] = NULL;
 
-    fName  = "MH3";
-    fTitle = "Container for a 2D Mars Histogram";
+    fName  = gsDefName;
+    fTitle = Form(gsDefTitle.Data(), 2);
 
     fHist->SetDirectory(NULL);
@@ -153,6 +156,6 @@
     fData[2] = new MDataChain(memberz);
 
-    fName  = "MH3";
-    fTitle = "Container for a 3D Mars Histogram";
+    fName  = gsDefName;
+    fTitle = Form(gsDefTitle.Data(), 3);
 
     fHist->SetDirectory(NULL);
@@ -386,5 +389,5 @@
 void MH3::StreamPrimitive(ofstream &out) const
 {
-    TString name = ToLower(fName);
+    TString name = GetUniqueName();
 
     out << "   MH3 " << name << "(\"";
@@ -397,6 +400,9 @@
     out << ");" << endl;
 
-    out << "   " << name << ".SetName(\"" << fName << "\");" << endl;
-    out << "   " << name << ".SetTitle(\"" << fTitle << "\");" << endl;
+    if (fName!=gsDefName)
+        out << "   " << name << ".SetName(\"" << fName << "\");" << endl;
+
+    if (fTitle!=Form(gsDefTitle.Data(), fDimension))
+        out << "   " << name << ".SetTitle(\"" << fTitle << "\");" << endl;
 
     switch (fDimension)
