Index: trunk/MagicSoft/Mars/mbase/BaseLinkDef.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/BaseLinkDef.h	(revision 9267)
+++ trunk/MagicSoft/Mars/mbase/BaseLinkDef.h	(revision 9268)
@@ -89,4 +89,6 @@
 #pragma link C++ class MParameterD+;
 #pragma link C++ class MParameterDerr+;
+
+#pragma link C++ class MParEnv+;
 #pragma link C++ class MParEmulated+;
 
Index: trunk/MagicSoft/Mars/mbase/MParContainer.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MParContainer.cc	(revision 9267)
+++ trunk/MagicSoft/Mars/mbase/MParContainer.cc	(revision 9268)
@@ -920,5 +920,5 @@
     // Check For: Job4.MClassName.Varname
     if (print)
-        *fLog << all << "Testing Prefix+ClasName: " << prefix+ClassName() << endl;
+        *fLog << all << "Testing Prefix+ClassName: " << prefix+ClassName() << endl;
     rc = ReadEnv(env, prefix+ClassName(), print);
     if (rc==kERROR || rc==kTRUE)
Index: trunk/MagicSoft/Mars/mbase/MParEnv.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MParEnv.cc	(revision 9268)
+++ trunk/MagicSoft/Mars/mbase/MParEnv.cc	(revision 9268)
@@ -0,0 +1,192 @@
+/* ======================================================================== *\
+!
+! *
+! * 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 1/2009 <mailto:tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2009
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// MParEnv
+//
+// A wrapper container which allows to set a new container from the
+// resource file. Via SetClassName you can define which type of class
+// you want to allow (the given object must inherit from it).
+//
+// For further details see MParEnv::ReadEnv
+//
+/////////////////////////////////////////////////////////////////////////////
+#include "MParEnv.h"
+
+#include <TInterpreter.h>
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+ClassImp(MParEnv);
+
+using namespace std;
+
+// --------------------------------------------------------------------------
+//
+// Default constructor.
+//
+MParEnv::MParEnv(const char *name, const char *title) : fCont(0), fClassName("MParContainer"), fIsOwner(kFALSE)
+{
+    fName  = name  ? name  : "MParEnv";
+    fTitle = title ? title : "A wrapper container which allows to set a new container from the resource file";
+}
+
+// --------------------------------------------------------------------------
+//
+// Delete fOwner if we own the instance.
+//
+MParEnv::~MParEnv()
+{
+    if (fIsOwner)
+        delete fCont;
+}
+
+// --------------------------------------------------------------------------
+//
+// Print the descriptor of this instance.
+// Calls Print() of fCont if fCont is set.
+//
+void MParEnv::Print(Option_t *o) const
+{
+    *fLog << all << GetDescriptor() << endl;
+    if (fCont)
+        fCont->Print();
+    *fLog << endl;
+}
+
+// --------------------------------------------------------------------------
+//
+// Set the class name fCont must inherit from. Check if the class name
+// inherits from MParContainer.
+// In case of success returns kTRUE, kFALSE otherwise.
+//
+Bool_t MParEnv::SetClassName(const char *name)
+{
+    TClass *cls = GetClass(name, fLog);
+    if (!cls)
+        return kFALSE;
+
+    if (!cls->InheritsFrom(MParContainer::Class()))
+    {
+        *fLog << err << "ERROR - " << name << " must inherit from MParContainer." << endl;
+        return kFALSE;
+    }
+
+    fClassName = name;
+
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+// Deletes fCont if we are owner.
+// Sets fCont to 0.
+// Checks if c inherits from fClassName.
+// Sets fIsOwner to kFALSE.
+// Sets fCont to c.
+// Sets name of c to fName.
+//
+void MParEnv::SetCont(MParContainer *c)
+{
+    if (fIsOwner && fCont)
+        delete fCont;
+    fCont=0;
+
+    if (!c)
+        return;
+
+    TClass *cls = GetClass(fClassName, fLog);
+    if (!c->InheritsFrom(cls))
+    {
+        *fLog << err << "ERROR - MParEnv::SetCont: " << c->ClassName() << "  doesn't inherit from " << fClassName << endl;
+        return;
+    }
+
+    fIsOwner = kFALSE;
+
+    fCont = c;
+    fCont->SetName(fName);
+}
+
+// --------------------------------------------------------------------------
+//
+// Checks for Class and Constructor.
+//
+// First we check for
+//
+//   MParEnv.Class: MMyContainer
+//
+// which would create a new instance of MMyContainer which must inherit from
+// fClassName. The instance is created via TObject::New()
+//
+// If this was not found we check for
+//
+//   MParEnv.Constructor: MMyContainer(14, "Hallo", "Test");
+//
+// which calls the given constructor via gInterpreter->ProcessLine. Also here
+// the result must inherit from fClassName.
+//
+// WARNING: Especially in the second case oyu can do weird thing which
+//          in principle can result in crashes. Please be extra-carefull.
+//
+Int_t MParEnv::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
+{
+    MParContainer *cont = 0;
+    Bool_t rc = kFALSE;
+    if (IsEnvDefined(env, prefix, "Class", print))
+    {
+        rc = kTRUE;
+        TString cls = GetEnvValue(env, prefix, "Class", "");
+        cont = GetNewObject(fName, cls);
+    }
+
+    if (!cont && IsEnvDefined(env, prefix, "Constructor", print))
+    {
+        rc = kTRUE;
+        if (!gInterpreter)
+        {
+            *fLog << err << "ERROR - gInterpreter==NULL." << endl;
+            return kERROR;
+        }
+
+        TString line = GetEnvValue(env, prefix, "Constructor", "");
+
+        cont = (MParContainer*)gInterpreter->ProcessLine(TString("new ")+line);
+    }
+
+    if (!rc)
+        return kFALSE;
+
+    SetCont(cont);
+    if (!fCont)
+    {
+        if (cont)
+            delete cont;
+        return kERROR;
+    }
+    fIsOwner = kTRUE;
+    return kTRUE;
+}
Index: trunk/MagicSoft/Mars/mbase/MParEnv.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MParEnv.h	(revision 9268)
+++ trunk/MagicSoft/Mars/mbase/MParEnv.h	(revision 9268)
@@ -0,0 +1,32 @@
+#ifndef MARS_MParEnv
+#define MARS_MParEnv
+
+#ifndef MARS_MParContainer
+#include "MParContainer.h"
+#endif
+
+class MParEnv : public MParContainer
+{
+private:
+    MParContainer *fCont;  // Pointer to the paremetr container
+
+    TString fClassName;    // Name of the Class fCont must inherit from
+    Bool_t  fIsOwner;      // Flag whether MParEnv owns fCont
+
+    Int_t ReadEnv(const TEnv &env, TString prefix, Bool_t print);
+
+public:
+    MParEnv(const char *name=NULL, const char *title=NULL);
+    ~MParEnv();
+
+    void SetCont(MParContainer *c=0);
+    MParContainer *GetCont() const { return fCont; }
+
+    Bool_t SetClassName(const char *cls="MParContainer");
+
+    void Print(Option_t *o="") const;
+
+    ClassDef(MParEnv, 1) // A wrapper container which allows to set a new container from the resource file
+};
+
+#endif
Index: trunk/MagicSoft/Mars/mbase/MParList.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MParList.cc	(revision 9267)
+++ trunk/MagicSoft/Mars/mbase/MParList.cc	(revision 9268)
@@ -51,4 +51,5 @@
 
 #include "MIter.h"
+#include "MParEnv.h"
 #include "MTaskList.h"
 
@@ -349,5 +350,7 @@
 TObject *MParList::FindObject(const char *name) const
 {
-    return fContainer->FindObject(name);
+    TObject *obj = fContainer->FindObject(name);
+    const MParEnv *env = dynamic_cast<const MParEnv*>(obj);
+    return env ? env->GetCont() : obj;
 }
 
@@ -358,5 +361,7 @@
 TObject *MParList::FindObject(const TObject *obj) const
 {
-    return fContainer->FindObject(obj);
+    TObject *ret = fContainer->FindObject(obj);
+    const MParEnv *env = dynamic_cast<const MParEnv*>(ret);
+    return env ? env->GetCont() : ret;
 }
 
@@ -370,5 +375,5 @@
 TObject *MParList::FindObject(const char *name, const char *classname) const
 {
-    TObject *obj = fContainer->FindObject(name);
+    TObject *obj = FindObject(name);
 
     if (!obj)
@@ -391,5 +396,5 @@
 TObject *MParList::FindObject(const TObject *obj, const char *classname) const
 {
-    TObject *nobj = fContainer->FindObject(obj);
+    TObject *nobj = FindObject(obj);
 
     if (!nobj)
Index: trunk/MagicSoft/Mars/mbase/MParameters.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MParameters.cc	(revision 9267)
+++ trunk/MagicSoft/Mars/mbase/MParameters.cc	(revision 9268)
@@ -81,4 +81,8 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// Print value of container.
+//
 void MParameterD::Print(Option_t *) const
 {
@@ -86,4 +90,8 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// Print value and error of container.
+//
 void MParameterDerr::Print(Option_t *) const
 {
@@ -91,6 +99,59 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// Print value of container.
+//
 void MParameterI::Print(Option_t *) const
 {
     *fLog << all << GetDescriptor() << ":  Val=" << fVal << endl;
 }
+
+// --------------------------------------------------------------------------
+//
+// MParameterD.Val: 55.7
+//
+Int_t MParameterD::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
+{
+    Bool_t rc = kFALSE;
+    if (IsEnvDefined(env, prefix, "Val", print))
+    {
+        rc = kTRUE;
+        fVal = GetEnvValue(env, prefix, "Val", fVal);
+    }
+    return rc;
+}
+
+// --------------------------------------------------------------------------
+//
+// MParameterD.Val: 55.7
+// MParameterD.Err: 12.3
+//
+Int_t MParameterDerr::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
+{
+    Int_t rc = MParameterD::ReadEnv(env, prefix, print);
+    if (rc==kERROR)
+        return kERROR;
+
+    if (IsEnvDefined(env, prefix, "Err", print))
+    {
+        rc = kTRUE;
+        fErr = GetEnvValue(env, prefix, "Err", fErr);
+    }
+    return rc;
+}
+
+// --------------------------------------------------------------------------
+//
+// MParameterD.Val: 42
+//
+Int_t MParameterI::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
+{
+    Bool_t rc = kFALSE;
+    if (IsEnvDefined(env, prefix, "Val", print))
+    {
+        rc = kTRUE;
+        fVal = GetEnvValue(env, prefix, "Val", fVal);
+    }
+    return rc;
+}
Index: trunk/MagicSoft/Mars/mbase/MParameters.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MParameters.h	(revision 9267)
+++ trunk/MagicSoft/Mars/mbase/MParameters.h	(revision 9268)
@@ -10,4 +10,7 @@
 private:
     Double_t fVal;
+
+protected:
+    Int_t ReadEnv(const TEnv &env, TString prefix, Bool_t print);
 
 public:
@@ -29,4 +32,6 @@
     Double_t fErr;
 
+    Int_t ReadEnv(const TEnv &env, TString prefix, Bool_t print);
+
 public:
     MParameterDerr(const char *name=NULL, const char *title=NULL);
@@ -45,4 +50,6 @@
 private:
     Int_t fVal;
+
+    Int_t ReadEnv(const TEnv &env, TString prefix, Bool_t print);
 
 public:
Index: trunk/MagicSoft/Mars/mbase/Makefile
===================================================================
--- trunk/MagicSoft/Mars/mbase/Makefile	(revision 9267)
+++ trunk/MagicSoft/Mars/mbase/Makefile	(revision 9268)
@@ -34,4 +34,5 @@
            MParContainer.cc \
 	   MParEmulated.cc \
+	   MParEnv.cc \
            MParameters.cc \
 	   MInputStreamID.cc \
