Index: trunk/MagicSoft/Mars/mbase/MParList.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MParList.cc	(revision 1022)
+++ trunk/MagicSoft/Mars/mbase/MParList.cc	(revision 1023)
@@ -66,6 +66,4 @@
     fContainer  = new TOrdCollection;
     fAutodelete = new TOrdCollection;
-
-    fAutodelete->SetOwner();
 }
 
@@ -89,6 +87,21 @@
 MParList::~MParList()
 {
-    if (TestBit(kIsOwner))
-        fContainer->SetOwner();
+    const Bool_t isowner = TestBit(kIsOwner);
+
+    //
+    // Case:
+    //  1) MParList is owner of the containers:
+    //     All container are stored in fContainer, and become deleted by
+    //     'delete fContainer'. Some of these containers, which were
+    //     created automatically are stored in fAutodelete, too. To prevent
+    //     double deletion this containers are not deleted by the destructor
+    //     of fAutodelete.
+    //  2) MParList is not owner of the containers:
+    //     The containers which were Added by AddToList are not touched.
+    //     Only the containers which were created automatically are also
+    //     automatically deleted.
+    //
+    fContainer->SetOwner(isowner);
+    fAutodelete->SetOwner(!isowner);
 
     delete fContainer;
@@ -113,14 +126,5 @@
 void MParList::SetLogStream(MLog *log)
 {
-    TIter Next(fContainer);
-
-    MParContainer *cont=NULL;
-
-    //
-    // loop over all tasks for preproccesing
-    //
-    while ( (cont=(MParContainer*)Next()) )
-        cont->SetLogStream(log);
-
+    fContainer->ForEach(MParContainer, SetLogStream)(log);
     MParContainer::SetLogStream(log);
 }
@@ -209,43 +213,5 @@
     MParContainer *cont = NULL;
     while ((cont=(MParContainer*)Next()))
-    {
         AddToList(cont);
-/*        //
-        // 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;*/
-    }
 }
 
@@ -426,14 +392,5 @@
 void MParList::SetReadyToSave(Bool_t flag)
 {
-    TIter Next(fContainer);
-
-    MParContainer *cont=NULL;
-
-    //
-    // loop over all tasks for preproccesing
-    //
-    while ( (cont=(MParContainer*)Next()) )
-        cont->SetReadyToSave(flag);
-
+    fContainer->ForEach(MParContainer, SetReadyToSave)(flag);
     MParContainer::SetReadyToSave(flag);
 }
@@ -445,13 +402,5 @@
 void MParList::Reset()
 {
-    TIter Next(fContainer);
-
-    MParContainer *cont=NULL;
-
-    //
-    // loop over all tasks for preproccesing
-    //
-    while ((cont=(MParContainer*)Next()))
-        cont->Reset();
+    fContainer->ForEach(MParContainer, Reset)();
 }
 
Index: trunk/MagicSoft/Mars/mbase/MTaskList.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MTaskList.cc	(revision 1022)
+++ trunk/MagicSoft/Mars/mbase/MTaskList.cc	(revision 1023)
@@ -113,17 +113,5 @@
 void MTaskList::SetLogStream(MLog *log)
 {
-    //
-    // create the Iterator over the tasklist
-    //
-    TIter Next(fTasks);
-
-    MTask *task=NULL;
-
-    //
-    // loop over all tasks for preproccesing
-    //
-    while ((task=(MTask*)Next()))
-        task->SetLogStream(log);
-
+    fTasks->ForEach(MTask, SetLogStream)(log);
     MParContainer::SetLogStream(log);
 }
@@ -383,13 +371,5 @@
     //  create the Iterator for the TaskList
     //
-    TIter Next(fTasks);
-
-    MTask *task=NULL;
-    //
-    //  loop over all tasks for postprocessing
-    //  only tasks which have successfully been preprocessed are postprocessed.
-    //
-    while ( (task=(MTask*)Next()) )
-        task->PrintStatistics(lvl+1);
+    fTasks->ForEach(MTask, PrintStatistics)(lvl+1);
 
     if (lvl==0)
