Index: trunk/MagicSoft/Mars/mranforest/MRanForestCalc.cc
===================================================================
--- trunk/MagicSoft/Mars/mranforest/MRanForestCalc.cc	(revision 4647)
+++ trunk/MagicSoft/Mars/mranforest/MRanForestCalc.cc	(revision 5690)
@@ -72,5 +72,5 @@
 //
 MRanForestCalc::MRanForestCalc(const char *name, const char *title)
-    : fNum(100), fHadronnessName("MHadronness"), fData(NULL)
+    : fNum(100), fHadronnessName("MHadronness"), fData(NULL), fRanForest(0), fRanTree(0)
 {
     //
@@ -87,5 +87,9 @@
 MRanForestCalc::~MRanForestCalc()
 {
-    //    delete fData;
+    if (!IsOwner())
+        return;
+
+    delete fRanForest;
+    delete fRanTree;
 }
 
@@ -103,23 +107,23 @@
 Int_t MRanForestCalc::PreProcess(MParList *plist)
 {
-    fRanForest = (MRanForest*)plist->FindObject("MRanForest");
     if (!fRanForest)
     {
-        *fLog << err << dbginf << "MRanForest not found... aborting." << endl;
-        return kFALSE;
-    }
-
-    fRanTree = (MRanTree*)plist->FindObject("MRanTree");
+        fRanForest = (MRanForest*)plist->FindObject("MRanForest");
+        if (!fRanForest)
+        {
+            *fLog << err << dbginf << "MRanForest not found... aborting." << endl;
+            return kFALSE;
+        }
+    }
+
     if (!fRanTree)
     {
-        *fLog << err << dbginf << "MRanTree not found... aborting." << endl;
-        return kFALSE;
-    }
-
-    /*if(!fRanForest->GetCurTree())
-    {
-        *fLog << err << dbginf << "MRanForest does not contain trees... aborting." << endl;
-        return kFALSE;
-    }*/
+        fRanTree = (MRanTree*)plist->FindObject("MRanTree");
+        if (!fRanTree)
+        {
+            *fLog << err << dbginf << "MRanTree not found... aborting." << endl;
+            return kFALSE;
+        }
+    }
 
     fData = fRanTree->GetRules();
@@ -253,2 +257,59 @@
     return kTRUE;
 }
+
+Int_t MRanForestCalc::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
+{
+    if (!IsEnvDefined(env, prefix, "File",     print))
+        return kFALSE;
+
+    TString fname = GetEnvValue(env, prefix, "File", "RF.root");
+    TString tname = GetEnvValue(env, prefix, "Tree", "Tree");
+    const Int_t   num   = GetEnvValue(env, prefix, "NumTrees", 100);
+    const Bool_t  debug = GetEnvValue(env, prefix, "Debug", kFALSE);
+
+    fname.ReplaceAll("\015", "");
+    tname.ReplaceAll("\015", "");
+
+    *fLog << dbginf << "Reading " << num << " trees " << tname << " from file " << fname << endl;
+
+    gLog.SetNullOutput(!debug);
+    MEvtLoop evtloop;
+    MParList  plist;
+    evtloop.SetParList(&plist);
+    MLog l;
+    l.SetNullOutput(!debug);
+    evtloop.SetLogStream(&l);
+    gLog.SetNullOutput(debug);
+
+    if (IsOwner())
+    {
+        delete fRanForest;
+        delete fRanTree;
+    }
+    fRanForest = new MRanForest;
+    fRanTree   = new MRanTree;
+    SetOwner();
+
+    plist.AddToList(fRanForest);
+    plist.AddToList(fRanTree);
+
+    MTaskList tlist;
+    plist.AddToList(&tlist);
+
+    MReadTree read(tname, fname);
+    read.DisableAutoScheme();
+
+    MRanForestFill rffill;
+    rffill.SetNumTrees(num);
+
+    tlist.AddToList(&read);
+    tlist.AddToList(&rffill);
+
+    if (!evtloop.Eventloop())
+    {
+        *fLog << err << "ERROR - Reading " << tname << " from file " << fname << endl;
+        return kERROR;
+    }
+
+    return kTRUE;
+}
Index: trunk/MagicSoft/Mars/mranforest/MRanForestCalc.h
===================================================================
--- trunk/MagicSoft/Mars/mranforest/MRanForestCalc.h	(revision 4647)
+++ trunk/MagicSoft/Mars/mranforest/MRanForestCalc.h	(revision 5690)
@@ -31,7 +31,14 @@
     Int_t Process();
 
+    enum { kIsOwner = BIT(14) };
+
+    Bool_t IsOwner() const { return TestBit(kIsOwner); }
+    void SetOwner() { SetBit(kIsOwner); }
+
 public:
     MRanForestCalc(const char *name=NULL, const char *title=NULL);
     ~MRanForestCalc();
+
+    Int_t ReadEnv(const TEnv &env, TString prefix, Bool_t print);
 
     void SetHadronnessName(const TString name) { fHadronnessName = name; }
