Index: trunk/MagicSoft/Mars/mhbase/MBinning.cc
===================================================================
--- trunk/MagicSoft/Mars/mhbase/MBinning.cc	(revision 5956)
+++ trunk/MagicSoft/Mars/mhbase/MBinning.cc	(revision 5971)
@@ -151,4 +151,8 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// Removes the first edge
+//
 void MBinning::RemoveFirstEdge()
 {
@@ -159,4 +163,8 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// Removes the last edge
+//
 void MBinning::RemoveLastEdge()
 {
@@ -205,4 +213,122 @@
 // --------------------------------------------------------------------------
 //
+// Set edged from text. With the following structure:
+//
+//     n lo hi [type [title]]
+//
+//  n:  number of bins
+//  lo: lowest edge
+//  hi: highest edge
+//  type: "lin" <default>, "log", "cos" (without quotationmarks)
+//  title: Whatever the title might be
+//
+// For example:
+//   SetEdgesRaw("12 0 1 lin This is the title");
+//
+Bool_t MBinning::SetEdgesRaw(const char *txt)
+{
+    Int_t   nbins  = 0;
+    Float_t loedge = 0;
+    Float_t upedge = 0;
+    Int_t   len    = 0;
+    if (3!=sscanf(txt, " %d %f %f %n", &nbins, &loedge, &upedge, &len))
+    {
+        *fLog << warn << GetDescriptor() << "::SetEdges: Not enough arguments... ignored." << endl;
+        return kFALSE;
+    }
+
+    if (loedge>=upedge)
+    {
+        *fLog << warn << GetDescriptor() << "::SetEdges: Lowest edge >= highest edge... ignored." << endl;
+        return kFALSE;
+    }
+
+    TString str(txt);
+    str.Remove(0, len);
+    str = str.Strip(TString::kBoth);
+
+    TString typ;
+    Ssiz_t pos = str.First(' ');
+    if (pos>=0)
+    {
+        typ = str(0, pos);
+        if (typ!=(TString)"lin" && typ!=(TString)"log" && typ!=(TString)"cos")
+        {
+            *fLog << warn << GetDescriptor() << "::SetEdges: Type " << typ << " unknown... ignored." << endl;
+            return kFALSE;
+        }
+    }
+
+    SetEdges(nbins, loedge, upedge, typ.Data());
+
+    str = str.Strip(TString::kBoth);
+
+    if (!str.IsNull())
+        fTitle = str;
+
+    return kTRUE;
+}
+/*
+// --------------------------------------------------------------------------
+//
+// Set edged from text. With the following structure:
+//
+//     n= lo= hi= type= title="my title"
+//
+//  n:  number of bins
+//  lo: lowest edge
+//  hi: highest edge
+//  type: "lin" <default>, "log", "cos" (without quotationmarks)
+//  title: Whatever the title might be
+//
+// For example:
+//   SetEdgesRaw("12 0 1 lin This is the title");
+//
+Bool_t MBinning::SetEdgesRaw(const char *txt)
+{
+    Int_t   nbins  = 0;
+    Float_t loedge = 0;
+    Float_t upedge = 0;
+    Int_t   len    = 0;
+    if (3!=sscanf(txt, " %d %f %f %n", &nbins, &loedge, &upedge, &len))
+    {
+        *fLog << warn << GetDescriptor() << "::SetEdges: Not enough arguments... ignored." << endl;
+        return kFALSE;
+    }
+
+    if (loedge>=upedge)
+    {
+        *fLog << warn << GetDescriptor() << "::SetEdges: Lowest edge >= highest edge... ignored." << endl;
+        return kFALSE;
+    }
+
+    TString str(txt);
+    str.Remove(0, len);
+    str = str.Strip(TString::kBoth);
+
+    TString typ;
+    Ssiz_t pos = str.First(' ');
+    if (pos>=0)
+    {
+        typ = str(0, pos);
+        if (typ!=(TString)"lin" && typ!=(TString)"log" && typ!=(TString)"cos")
+        {
+            *fLog << warn << GetDescriptor() << "::SetEdges: Type " << typ << " unknown... ignored." << endl;
+            return kFALSE;
+        }
+    }
+
+    SetEdges(nbins, loedge, upedge, typ.Data());
+
+    str = str.Strip(TString::kBoth);
+
+    if (!str.IsNull())
+        fTitle = str;
+
+    return kTRUE;
+}
+*/
+// --------------------------------------------------------------------------
+//
 // Calls SetEdgesLog if opt contains "log"
 // Calls SetEdgesCos if opt contains "cos"
@@ -276,4 +402,29 @@
 
     MH::SetBinning(&h, this);
+}
+
+// --------------------------------------------------------------------------
+//
+// Print binning.
+//
+void MBinning::Print(Option_t *o) const
+{
+    *fLog << all;
+    *fLog << GetDescriptor() << ": nbins=" << GetNumBins() << " [";
+    *fLog << GetEdgeLo() << ", " << GetEdgeHi() << "] ";
+    switch (fType)
+    {
+    case kIsDefault:     *fLog << "deafult"; break;
+    case kIsLinear:      *fLog << "linear"; break;
+    case kIsLogarithmic: *fLog << "logarithmic"; break;
+    case kIsCosinic:     *fLog << "consinic"; break;
+    case kIsUserArray:   *fLog << "user-array"; break;
+    }
+    *fLog << ">";
+
+    if (fTitle!=gsDefTitle)
+        *fLog << " title=" << fTitle;
+
+    *fLog << endl;
 }
 
@@ -317,2 +468,86 @@
     out << "   }" << endl;
 }
+
+// --------------------------------------------------------------------------
+//
+// Allows reading a binning from resource files. The structure is as follows
+//
+Int_t MBinning::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
+{
+    Bool_t rc = kFALSE;
+
+    UInt_t  nbins  = GetNumBins();
+    Float_t edgelo = GetEdgeLo();
+    Float_t edgehi = GetEdgeHi();
+    TString type;
+    if (IsEnvDefined(env, prefix, "NumBins", print))
+    {
+        nbins = GetEnvValue(env, prefix, "NumBins", GetNumBins());
+        rc = kTRUE;
+    }
+    if (IsEnvDefined(env, prefix, "EdgeLo", print))
+    {
+        edgelo = GetEnvValue(env, prefix, "EdgeLo", GetEdgeLo());
+        rc = kTRUE;
+    }
+    if (IsEnvDefined(env, prefix, "EdgeHi", print))
+    {
+        edgehi = GetEnvValue(env, prefix, "EdgeHi", GetEdgeHi());
+        rc = kTRUE;
+    }
+    if (rc==kTRUE && (type==kIsUserArray || type==kIsDefault))
+        type = kIsLinear;
+
+    if (IsEnvDefined(env, prefix, "Type", print))
+    {
+        type = GetEnvValue(env, prefix, "Type", "lin");
+        if (type!=(TString)"lin" && type!=(TString)"log" && type!=(TString)"cos")
+        {
+            *fLog << warn << GetDescriptor() << "::ReadEnv - WARNING: Type is not lin, log nor cos... assuming lin." << endl;
+            type = "lin";
+        }
+        rc = kTRUE;
+    }
+    if (IsEnvDefined(env, prefix, "Edges", print))
+    {
+        if (rc==kTRUE)
+            *fLog << warn << GetDescriptor() << "::ReadEnv - WARNING: 'Edges' found... ignoring any 'NumBins', 'EdgeLo' and 'EdgeHi'" << endl;
+
+        const TString type = GetEnvValue(env, prefix, "Edges", "");
+        //type = kIsUserArray;
+        /* MISSING */
+        rc = kTRUE;
+        *fLog << err << " SORRY USER ARRAY NOT YET IMPLEMENTED" << endl;
+        return kERROR;
+    }
+
+    const Bool_t raw = IsEnvDefined(env, prefix, "Raw", print);
+    //const Bool_t fullbins    = IsEnvDefined(env, prefix, "Binning", print);
+    if (!raw && /*!fullbins &&*/ rc==kTRUE)
+        SetEdges(nbins, edgelo, edgehi, type.Data());
+
+    if (rc==kTRUE)
+        *fLog << warn << GetDescriptor() << "::ReadEnv - WARNING: 'Binning' found... ignoring any 'NumBins', 'EdgeLo', 'EdgeHi' and 'Edges'" << endl;
+
+    if (IsEnvDefined(env, prefix, "Title", print))
+    {
+        fTitle = GetEnvValue(env, prefix, "Title", gsDefTitle.Data());
+        rc = kTRUE;
+    }
+
+    if (raw)
+    {
+        const TString txt = GetEnvValue(env, prefix, "Raw", "");
+        if (!SetEdgesRaw(txt.Data()))
+            return kERROR;
+    }
+/*
+    if (fullbins)
+    {
+        TString txt = GetEnvValue(env, prefix, "Binning", "");
+        SetEdgesRaw(txt.Data());
+    }
+   */
+
+    return rc;
+}
Index: trunk/MagicSoft/Mars/mhbase/MBinning.h
===================================================================
--- trunk/MagicSoft/Mars/mhbase/MBinning.h	(revision 5956)
+++ trunk/MagicSoft/Mars/mhbase/MBinning.h	(revision 5971)
@@ -55,4 +55,6 @@
 
     Bool_t SetEdges(const MParList &list, const char *name=0);
+    Bool_t SetEdgesRaw(const char *txt);
+    //Bool_t SetEdges(const char *txt);
     void SetEdges(const TAxis &axe);
     void SetEdges(const MBinning &bins) { SetEdges(bins.fEdges); fType = bins.fType; fTitle = bins.fTitle; }
@@ -104,4 +106,8 @@
     void Apply(TH1 &) const;
 
+    void Print(Option_t *o="") const;
+
+    Int_t ReadEnv(const TEnv &env, TString prefix, Bool_t print=kFALSE);
+
     ClassDef(MBinning, 1) //Container to store the binning of a histogram
 };
