Index: trunk/MagicSoft/Mars/mbase/MParList.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MParList.cc	(revision 887)
+++ trunk/MagicSoft/Mars/mbase/MParList.cc	(revision 890)
@@ -43,4 +43,5 @@
 #include <TNamed.h>
 #include <TClass.h>
+#include <TObjArray.h>
 
 #include "MLog.h"
@@ -163,4 +164,60 @@
 // --------------------------------------------------------------------------
 //
+//  Add all entries of the TObjArray to the list.
+//
+void MParList::AddToList(TObjArray *list)
+{
+    //
+    //  check if the object (you want to add) exists
+    //
+    if (!list)
+        return;
+
+    TObjArrayIter Next(list);
+
+    MParContainer *cont = NULL;
+    while ((cont=(MParContainer*)Next()))
+    {
+        //
+        // Get Name of new container
+        //
+        const char *name = cont->GetName();
+
+        //
+        // Check if the new container is already existing in the list
+        //
+        const TObject *objn = fContainer.FindObject(name);
+        const TObject *objt = fContainer.FindObject(cont);
+
+        if (objn || objt)
+        {
+            //
+            // If the container is already in the list ignore it.
+            //
+            if (objt || objn==cont)
+            {
+                *fLog << dbginf << "Warning: Container '" << cont->GetName() << ", 0x" << (void*)cont;
+                *fLog << "' already existing in '" << GetName() << "'... ignoring." << endl;
+                continue;
+            }
+
+            //
+            // Otherwise add it to the list, but print a warning message
+            //
+            *fLog << dbginf << "Warning: Container with the same name '" << cont->GetName();
+            *fLog << "' already existing in '" << GetName() << "'." << endl;
+            *fLog << "You may not be able to get a pointer to container task by name." << endl;
+        }
+
+        *fLog << "Adding " << name << " to " << GetName() << "... " << flush;
+
+        fContainer.Add(cont);
+
+        *fLog << "Done." << endl;
+    }
+}
+
+// --------------------------------------------------------------------------
+//
 //  Find an object in the list.
 //  'name' is the name of the object you are searching for.
@@ -178,4 +235,46 @@
 {
     return fContainer.FindObject(obj);
+}
+
+// --------------------------------------------------------------------------
+//
+//  returns the ClassName without anything which is behind that last ';' in
+//  string.
+//
+TString MParList::GetClassName(const char *classname)
+{
+    TString cname(classname);
+    const char *semicolon = strrchr(cname, ';');
+
+    if (semicolon)
+        cname.Remove(semicolon-cname);
+
+    return cname;
+}
+
+// --------------------------------------------------------------------------
+//
+//  returns the ObjectName. It is created from a class and object name.
+//  If no object name is given the objectname is the same than the
+//  class name. Leading dots are removed from the object name
+//
+TString MParList::GetObjectName(const char *classname, const char *objname)
+{
+    TString cname(classname);
+    const char *semicolon = strrchr(cname, ';');
+
+    TString oname(objname ? objname : classname);
+
+    if (semicolon)
+    {
+        //
+        // Remove leading dots from objectname (eg. "MMcTrig;5.")
+        //
+        Int_t sz = oname.Sizeof()-2;
+
+        while (sz>=0 && oname[sz]=='.')
+            oname.Remove(sz--);
+    }
+    return oname;
 }
 
@@ -208,6 +307,4 @@
     // List) is given use it's classname as the objectname
     //
-    if (!objname)
-        objname = classname;
 
     //
@@ -221,21 +318,6 @@
     // the new object deleted automatically
     //
-    TString cname(classname);
-    const char *semicolon = strrchr(cname, ';');
-
-    TString oname(objname);
-
-    if (semicolon)
-    {
-        cname.Remove(semicolon-cname);
-
-        //
-        // Remove leading dots from objectname (eg. "MMcTrig;5.")
-        //
-        Int_t sz = oname.Sizeof()-2;
-
-        while (sz>=0 && oname[sz]=='.')
-            oname.Remove(sz--);
-    }
+    TString cname = GetClassName(classname);
+    TString oname = GetObjectName(classname, objname);
 
     //
@@ -273,6 +355,5 @@
 
     //
-    // If a name different to the classname was given,
-    // set the new object name of the object
+    // Set the name of the container
     //
     pcont->SetName(oname);
@@ -326,4 +407,8 @@
 }
 
+// --------------------------------------------------------------------------
+//
+//   Reset all containers in the list
+//
 void MParList::Reset()
 {
@@ -338,2 +423,167 @@
         cont->Reset();
 }
+
+// --------------------------------------------------------------------------
+//
+//  This finds numbered objects. The objects are returned in a copy of a
+//  TObjArray.
+//
+//  If from only is given (or to=0) object are assumed numbered
+//  from 1 to from.
+//
+TObjArray MParList::FindObjectList(const char *name, const UInt_t from, const UInt_t to) const
+{
+    TObjArray list;
+
+    if (to>0 && to<=from)
+    {
+        *fLog << dbginf << "Cannot create entries backwards (to<from)...skipped." << endl;
+        return list;
+    }
+
+    const UInt_t len = strlen(name);
+
+    char *auxname = new char[len+7];
+    strcpy(auxname, name);
+
+    //
+    // If only 'from' is specified the number of entries are ment
+    //
+    const Bool_t exc = from>0 && to==0;
+
+    const UInt_t first = exc ?    0 : from;
+    const UInt_t last  = exc ? from : to;
+
+    for (UInt_t num=first; num<last; num++)
+    {
+        if (from!=0 || to!=0)
+            sprintf(auxname+len, ";%d", num+1);
+
+        TObject *obj = FindObject(auxname);
+        if (!obj)
+            continue;
+
+        list.AddLast(obj);
+    }
+    delete auxname;
+
+    return list;
+}
+
+// --------------------------------------------------------------------------
+//
+//  This finds numbered objects. The objects are returned in a copy of a
+//  TObjArray. If one of the objects doesn't exist it is created from the
+//  meaning of cname and oname (s. FindCreateObj)
+//
+//  If from only is given (or to=0) object are assumed numbered
+//  from 1 to from.
+//
+TObjArray MParList::FindCreateObjList(const char *cname, const UInt_t from, const UInt_t to, const char *oname)
+{
+    TObjArray list;
+
+    if (to>0 && to<=from)
+    {
+        *fLog << dbginf << "Cannot create entries backwards (to<from)...skipped." << endl;
+        return list;
+    }
+
+    const UInt_t len = strlen(cname);
+
+    char *auxname = new char[len+7];
+    strcpy(auxname, cname);
+
+    //
+    // If only 'from' is specified the number of entries are ment
+    //
+    const Bool_t exc = from>0 && to==0;
+
+    const UInt_t first = exc ?    0 : from;
+    const UInt_t last  = exc ? from : to;
+
+    for (UInt_t num=first; num<last; num++)
+    {
+        if (from!=0 || to!=0)
+            sprintf(auxname+len, ";%d", num+1);
+
+        TObject *obj = FindCreateObj(auxname, oname);
+        if (!obj)
+            break;
+
+        list.AddLast(obj);
+    }
+    delete auxname;
+
+    return list;
+}
+
+// --------------------------------------------------------------------------
+//
+//  This finds numbered objects. The objects are returned in a copy of a
+//  TObjArray. If one of the objects doesn't exist it is created from the
+//  meaning of cname and oname (s. FindCreateObj)
+//
+//  If from only is given (or to=0) object are assumed numbered
+//  from 1 to from.
+//
+//  Remark: Because it is static the object are only created and not added to
+//  the parameter list. You must also take care of deleting these objects!
+//  This function is mainly made for use in root macros. Don't use it in
+//  compiled programs if you are not 100% sure what you are doing.
+//
+TObjArray MParList::CreateObjList(const char *cname, const UInt_t from, const UInt_t to=0, const char *oname=NULL)
+{
+    TObjArray list;
+
+    //
+    // try to get class from root environment
+    //
+    TClass *cls = gROOT->GetClass(cname);
+
+    if (!cls)
+    {
+        //
+        // if class is not existing in the root environment
+        //
+        gLog << dbginf << "Class '" << cname << "' not existing in dictionary." << endl;
+        return list;
+    }
+
+    const UInt_t len = strlen(cname);
+
+    char *auxname = new char[len+7];
+    strcpy(auxname, cname);
+
+    //
+    // If only 'from' is specified the number of entries are ment
+    //
+    const Bool_t exc = from>0 && to==0;
+
+    const UInt_t first = exc ?    0 : from;
+    const UInt_t last  = exc ? from : to;
+
+    for (UInt_t num=first; num<last; num++)
+    {
+        if (from!=0 || to!=0)
+            sprintf(auxname+len, ";%d", num+1);
+
+        //
+        // create the parameter container of the the given class type
+        //
+        MParContainer *pcont = (MParContainer*)cls->New();
+
+        //
+        // Set the name of the container
+        //
+        pcont->SetName(auxname);
+
+        //
+        // Add new object to the return list
+        //
+        list.AddLast(pcont);
+    }
+    delete auxname;
+
+    return list;
+}
