Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 2116)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 2117)
@@ -1,3 +1,59 @@
                                                  -*-*- END OF LINE -*-*-
+
+ 2003/05/16: Thomas Bretz
+
+   * mbase/MContinue.cc:
+     - SetDisplay for filter
+     - Set LogStream for filter
+     
+   * mbase/MEvtLoop.cc:
+     - don't use pointer to fTasklist in PostProcess if not initialized
+     - do not execute Process if fTasklist is not initialized
+     
+   * mbase/MTask.[h,cc]:
+     - overwrite SetDisplay (set also display of attached filter
+     
+   * mbase/MTaskList.cc:
+     - minor changes 
+     
+   * mdata/MDataChain.[h,cc]:
+     - implemented ParseDataMember to support constants
+
+   * mfileio/MCT1ReadPreProc.[h,cc]:
+     - added fNumFile to support Rewind
+     - added Rewind
+     
+   * mfileio/MRead.[h,cc]:
+     - new virtual function Rewind
+     
+   * mfileio/MReadMarsFile.[h,cc]:
+     - added Rewind
+     
+   * mfileio/MReadTree.[h,cc]:
+     - added Rewind
+     - fixed a missing 'else' in AddFile
+     
+   * mhist/MBinning.[h,cc]:
+     - added SetEdges(TAxis&)
+     - added SetEdges(TH1&, char)
+
+   * mhist/MFillH.[h,cc]:
+     - added bit kDoNotDisplay
+     
+   * mhist/MH.h:
+     - added a comment
+     
+   * mhist/MH3.[h,cc]:
+     - implemented GetRule
+     - implemented GetNbins
+     - implemented FindFixBin
+     
+   * mimage/MHHillasSrc.cc:
+     - replaced gPad->cd(4) by savepad
+
+   * mmain/MStatusDisplay.[h,cc]:
+     - fixed locked mode for loop-in-loop cases
+
+
 
  2003/05/15: Wolfgang Wittek
@@ -14,5 +70,6 @@
 
    * mranforest/MRanForestCalc.cc
-     - exchange arguments in 'FindCreateObj("MHadronness", fHadronnessName)'
+     - exchange arguments in 
+       FindCreateObj("MHadronness", fHadronnessName)
 
 
Index: /trunk/MagicSoft/Mars/mbase/MContinue.cc
===================================================================
--- /trunk/MagicSoft/Mars/mbase/MContinue.cc	(revision 2116)
+++ /trunk/MagicSoft/Mars/mbase/MContinue.cc	(revision 2117)
@@ -137,4 +137,7 @@
     }
 
+    GetFilter()->SetDisplay(fDisplay);
+    GetFilter()->SetLogStream(fLog);
+
     SetBit(kFilterIsPrivate);
 
Index: /trunk/MagicSoft/Mars/mbase/MEvtLoop.cc
===================================================================
--- /trunk/MagicSoft/Mars/mbase/MEvtLoop.cc	(revision 2116)
+++ /trunk/MagicSoft/Mars/mbase/MEvtLoop.cc	(revision 2117)
@@ -171,4 +171,6 @@
 Bool_t MEvtLoop::PreProcess(const char *tlist)
 {
+    fTaskList = NULL;
+
     //
     // check if the needed parameter list is set.
@@ -328,4 +330,7 @@
 Bool_t MEvtLoop::Process(Int_t maxcnt)
 {
+    if (!fTaskList)
+        return kFALSE;
+
     //
     //   loop over all events and process all tasks for
@@ -440,5 +445,5 @@
     //  execute the post process of all tasks
     //
-    return fTaskList->PostProcess();
+    return fTaskList ? fTaskList->PostProcess() : kTRUE;
 }
 
Index: /trunk/MagicSoft/Mars/mbase/MTask.cc
===================================================================
--- /trunk/MagicSoft/Mars/mbase/MTask.cc	(revision 2116)
+++ /trunk/MagicSoft/Mars/mbase/MTask.cc	(revision 2117)
@@ -364,2 +364,9 @@
     return kFALSE;
 }
+
+void MTask::SetDisplay(MStatusDisplay *d)
+{
+    if (fFilter)
+        fFilter->SetDisplay(d);
+    MParContainer::SetDisplay(d);
+}
Index: /trunk/MagicSoft/Mars/mbase/MTask.h
===================================================================
--- /trunk/MagicSoft/Mars/mbase/MTask.h	(revision 2116)
+++ /trunk/MagicSoft/Mars/mbase/MTask.h	(revision 2117)
@@ -68,4 +68,5 @@
     const MFilter *GetFilter() const      { return fFilter; }
     MFilter *GetFilter()  { return fFilter; } // for MContinue only
+    void SetDisplay(MStatusDisplay *d);
     virtual void PrintStatistics(const Int_t lvl=0, Bool_t title=kFALSE) const;
 
Index: /trunk/MagicSoft/Mars/mbase/MTaskList.cc
===================================================================
--- /trunk/MagicSoft/Mars/mbase/MTaskList.cc	(revision 2116)
+++ /trunk/MagicSoft/Mars/mbase/MTaskList.cc	(revision 2117)
@@ -134,5 +134,5 @@
 {
     fTasks->ForEach(MTask, SetLogStream)(log);
-    MParContainer::SetLogStream(log);
+    MTask::SetLogStream(log);
 }
 
@@ -140,5 +140,5 @@
 {
     fTasks->ForEach(MTask, SetDisplay)(d);
-    MParContainer::SetDisplay(d);
+    MTask::SetDisplay(d);
 }
 
Index: /trunk/MagicSoft/Mars/mdata/MDataChain.cc
===================================================================
--- /trunk/MagicSoft/Mars/mdata/MDataChain.cc	(revision 2116)
+++ /trunk/MagicSoft/Mars/mdata/MDataChain.cc	(revision 2117)
@@ -82,4 +82,19 @@
 //   randl(x)  returns gRandom->Landau(0, x)
 //
+//
+// Constants are implemented in ParseDataMember, namely:
+//   kPi:      TMath::Pi()
+//   kRad2Deg: 180/kPi
+//   kDeg2Rad: kPi/180
+//
+// You can also defined constants which are defined in TMath by:
+//   kLn10      for   static Double_t TMath::Ln10();
+//   kLogE      for   static Double_t TMath::LogE();
+//   kRadToDeg  for   static Double_t TMath::RadToDeg();
+//   kDegToRad  for   static Double_t TMath::DegToRad();
+// Remark: In older root versions only Pi() and E() are implemented in
+//         TMath.
+//
+//
 // REMARK:
 //         - All the random functions are returning 0 if gRandom==0
@@ -100,4 +115,5 @@
 
 #include <TRandom.h>
+#include <TMethodCall.h>
 
 #include "MLog.h"
@@ -126,21 +142,15 @@
 // --------------------------------------------------------------------------
 //
-//  Default constructor
-//
-MDataChain::MDataChain()
-    : fMember(NULL), fOperatorType(kENoop)
-{
-}
-
-// --------------------------------------------------------------------------
-//
 // Constructor taking a rule as an argument. For more details see
 // class description
 //
 MDataChain::MDataChain(const char *rule, const char *name, const char *title)
-    : fOperatorType(kENoop)
+    : fMember(NULL), fOperatorType(kENoop)
 {
     fName  = name  ? name  : "MDataChain";
     fTitle = title ? title : rule;
+
+    if (TString(rule).IsNull())
+        return;
 
     *fLog << inf << "Trying to resolve rule... " << flush;
@@ -259,4 +269,38 @@
 // --------------------------------------------------------------------------
 //
+// Here the names of data members are interpreted. This can be used to
+// check for constants.
+//
+MData *MDataChain::ParseDataMember(TString txt)
+{
+    //txt.ToLower();
+
+    if (txt=="kRad2Deg") return new MDataValue(kRad2Deg);
+    if (txt=="kDeg2Rad") return new MDataValue(1./kRad2Deg);
+
+    if (!txt.BeginsWith("k"))
+        return new MDataMember(txt.Data());
+
+    const TString name = txt(1, txt.Length());
+    TMethodCall call(TMath::Class(), name, "");
+    switch (call.ReturnType())
+    {
+    case TMethodCall::kLong:
+        Long_t l;
+        call.Execute(l);
+        return new MDataValue(l);
+    case TMethodCall::kDouble:
+        Double_t d;
+        call.Execute(d);
+        return new MDataValue(d);
+    default:
+        break;
+    }
+
+    return new MDataMember(txt.Data());
+}
+
+// --------------------------------------------------------------------------
+//
 // Core of the data chain. Here the chain is constructed out of the rule.
 //
@@ -418,5 +462,5 @@
             if ((txt.IsNull() || txt[0]!='(') && text[0]!='-' && text[0]!='+')
             {
-                newmember = new MDataMember(text.Data());
+                newmember = ParseDataMember(text.Data());
                 break;
             }
@@ -469,5 +513,5 @@
     if (!fMember)
     {
-        *fLog << warn << "MDataChain not valid." << endl;
+        //*fLog << warn << "MDataChain not valid." << endl;
         return 0;
     }
Index: /trunk/MagicSoft/Mars/mdata/MDataChain.h
===================================================================
--- /trunk/MagicSoft/Mars/mdata/MDataChain.h	(revision 2116)
+++ /trunk/MagicSoft/Mars/mdata/MDataChain.h	(revision 2117)
@@ -59,10 +59,10 @@
 
     MData *ParseString(TString txt, Int_t level);
+    MData *ParseDataMember(TString txt);
 
     MDataChain(const char *rule, OperatorType_t op);
 
 public:
-    MDataChain();
-    MDataChain(const char *rule, const char *name=NULL, const char *title=NULL);
+    MDataChain(const char *rule=NULL, const char *name=NULL, const char *title=NULL);
     ~MDataChain();
 
Index: /trunk/MagicSoft/Mars/mfileio/MCT1ReadPreProc.cc
===================================================================
--- /trunk/MagicSoft/Mars/mfileio/MCT1ReadPreProc.cc	(revision 2116)
+++ /trunk/MagicSoft/Mars/mfileio/MCT1ReadPreProc.cc	(revision 2117)
@@ -549,7 +549,12 @@
     // Check for the existence of a next file to read
     //
-    TNamed *file = (TNamed*)fFileNames->First();
-    if (!file)
-        return kFALSE;
+    if (fNumFile >= (UInt_t)fFileNames->GetSize())
+        return kFALSE;
+
+    TNamed *file = (TNamed*)fFileNames->At(fNumFile);
+
+    //TNamed *file = (TNamed*)fFileNames->GetFirst();
+    //if (!file)
+    //    return kFALSE;
 
     //
@@ -565,18 +570,16 @@
     // Remove this file from the list of pending files
     //
-    fFileNames->Remove(file);
+    //fFileNames->Remove(file);
 
     *fLog << inf << "Open file: '" << name << "'" << endl;
 
     if (!CheckHeader(fname))
-    {
-        *fLog << "OpenNextFile : CheckHeader(fname) is FALSE" << endl;
-        return kFALSE;
-    }
+        return kFALSE;
+
+    fNumFile++;
 
     fIn = new ifstream(fname);
 
     *fLog << inf << "-----------------------------------------------------------------------" << endl;
-
 
     switch (ReadRunHeader())
@@ -690,100 +693,111 @@
 }
 
-// --------------------------------------------------------------------------
-//
-// Open the first file in the list. Check for the output containers or create
-// them if they don't exist.
-//
-// Initialize the size of the MPedestalCam container to 127 pixels (CT1 camera)
-//
-Bool_t MCT1ReadPreProc::PreProcess(MParList *pList)
-{
-
-    fParList = pList;
-
-    //
-    //  look for the HourAngle container in the plist
-    //
-    fHourAngle = (MParameterD*)pList->FindCreateObj("MParameterD", "HourAngle");
-    if (!fHourAngle)
-        return kFALSE;
-    fHourAngle->SetTitle("Store the CT1 hour angle [deg]");
-
-    //
-    //  look for the ThetaOrig container in the plist
-    //
-    fThetaOrig = (MParameterD*)pList->FindCreateObj("MParameterD", "ThetaOrig");
-    if (!fThetaOrig)
-        return kFALSE;
-    fThetaOrig->SetTitle("Store the original CT1 zenith angle [rad]");
-
-    //
-    //  look for the MCerPhotEvt class in the plist
-    //
-    fNphot = (MCerPhotEvt*)pList->FindCreateObj("MCerPhotEvt");
-    if (!fNphot)
-        return kFALSE;
-
-    //
-    //  look for the pedestal class in the plist
-    //
-    fPedest = (MPedestalCam*)pList->FindCreateObj("MPedestalCam");
-    if (!fPedest)
-        return kFALSE;
-
-    //
-    //  look for the time class in the plist
-    //
-    fTime = (MTime*)pList->FindCreateObj("MTime");
-    if (!fTime)
-        return kFALSE;
-
-    //
-    //  look for the pedestal class in the plist
-    //
-    fBlinds = (MBlindPixels*)pList->FindCreateObj("MBlindPixels");
-    if (!fBlinds)
-        return kFALSE;
-
-    //
-    //  look for the source position in the camera
-    //
-    fSrcPos = (MSrcPosCam*)pList->FindCreateObj("MSrcPosCam");
-    if (!fSrcPos)
-        return kFALSE;
-
-    //
-    //  look for the camera geometry
-    //
-    fGeom = (MGeomCam*)pList->FindCreateObj("MGeomCamCT1", "MGeomCam");
-    if (!fGeom)
-        return kFALSE;
-
-    //
-    //  look for the mc event class
-    //
-    fMcEvt = (MMcEvt*)pList->FindCreateObj("MMcEvt");
-    if (!fMcEvt)
-        return kFALSE;
-
-    //
-    //  look for the mc trigger class
-    //
-    fMcTrig = (MMcTrig*)pList->FindCreateObj("MMcTrig");
-    if (!fMcTrig)
-        return kFALSE;
-
-    //
-    //  look for the raw run header class
-    //
-    fRawRunHeader = (MRawRunHeader*)pList->FindCreateObj("MRawRunHeader");
-    if (!fRawRunHeader)
-        return kFALSE;
-
-    fBinningT = (MBinning*)pList->FindObject("BinningTheta");
-
+Bool_t MCT1ReadPreProc::Rewind()
+{
     fNumFilterEvts = 0;
     fNumEvents     = 0;
     fNumRuns       = 0;
+    fNumFile       = 0;
+    if (fIn)
+        delete fIn;
+
+    fIn=NULL;
+
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+// Open the first file in the list. Check for the output containers or create
+// them if they don't exist.
+//
+// Initialize the size of the MPedestalCam container to 127 pixels (CT1 camera)
+//
+Bool_t MCT1ReadPreProc::PreProcess(MParList *pList)
+{
+    fParList = pList;
+
+    //
+    //  look for the HourAngle container in the plist
+    //
+    fHourAngle = (MParameterD*)pList->FindCreateObj("MParameterD", "HourAngle");
+    if (!fHourAngle)
+        return kFALSE;
+    fHourAngle->SetTitle("Store the CT1 hour angle [deg]");
+
+    //
+    //  look for the ThetaOrig container in the plist
+    //
+    fThetaOrig = (MParameterD*)pList->FindCreateObj("MParameterD", "ThetaOrig");
+    if (!fThetaOrig)
+        return kFALSE;
+    fThetaOrig->SetTitle("Store the original CT1 zenith angle [rad]");
+
+    //
+    //  look for the MCerPhotEvt class in the plist
+    //
+    fNphot = (MCerPhotEvt*)pList->FindCreateObj("MCerPhotEvt");
+    if (!fNphot)
+        return kFALSE;
+
+    //
+    //  look for the pedestal class in the plist
+    //
+    fPedest = (MPedestalCam*)pList->FindCreateObj("MPedestalCam");
+    if (!fPedest)
+        return kFALSE;
+
+    //
+    //  look for the time class in the plist
+    //
+    fTime = (MTime*)pList->FindCreateObj("MTime");
+    if (!fTime)
+        return kFALSE;
+
+    //
+    //  look for the pedestal class in the plist
+    //
+    fBlinds = (MBlindPixels*)pList->FindCreateObj("MBlindPixels");
+    if (!fBlinds)
+        return kFALSE;
+
+    //
+    //  look for the source position in the camera
+    //
+    fSrcPos = (MSrcPosCam*)pList->FindCreateObj("MSrcPosCam");
+    if (!fSrcPos)
+        return kFALSE;
+
+    //
+    //  look for the camera geometry
+    //
+    fGeom = (MGeomCam*)pList->FindCreateObj("MGeomCamCT1", "MGeomCam");
+    if (!fGeom)
+        return kFALSE;
+
+    //
+    //  look for the mc event class
+    //
+    fMcEvt = (MMcEvt*)pList->FindCreateObj("MMcEvt");
+    if (!fMcEvt)
+        return kFALSE;
+
+    //
+    //  look for the mc trigger class
+    //
+    fMcTrig = (MMcTrig*)pList->FindCreateObj("MMcTrig");
+    if (!fMcTrig)
+        return kFALSE;
+
+    //
+    //  look for the raw run header class
+    //
+    fRawRunHeader = (MRawRunHeader*)pList->FindCreateObj("MRawRunHeader");
+    if (!fRawRunHeader)
+        return kFALSE;
+
+    fBinningT = (MBinning*)pList->FindObject("BinningTheta");
+
+    Rewind();
 
     fPedest->InitSize(iMAXNUMPIX);
@@ -1115,4 +1129,7 @@
     }
 
+    delete fIn;
+    fIn = NULL;
+
     return GetSelector() ? GetSelector()->CallPostProcess() : kTRUE;
 }
Index: /trunk/MagicSoft/Mars/mfileio/MCT1ReadPreProc.h
===================================================================
--- /trunk/MagicSoft/Mars/mfileio/MCT1ReadPreProc.h	(revision 2116)
+++ /trunk/MagicSoft/Mars/mfileio/MCT1ReadPreProc.h	(revision 2117)
@@ -50,4 +50,5 @@
     Bool_t fIsMcFile;       // Flag whether current run is a MC run
 
+    UInt_t fNumFile;
     UInt_t fNumEvents;      // number of events counted in all runs in all files
     UInt_t fNumEventsInRun; // number of events in the counted in th ecurrent run
@@ -76,4 +77,6 @@
     Bool_t PostProcess();
 
+    Bool_t Rewind();
+
 public:
     MCT1ReadPreProc(const char *filename=NULL,
Index: /trunk/MagicSoft/Mars/mfileio/MRead.cc
===================================================================
--- /trunk/MagicSoft/Mars/mfileio/MRead.cc	(revision 2116)
+++ /trunk/MagicSoft/Mars/mfileio/MRead.cc	(revision 2117)
@@ -41,4 +41,10 @@
 
 ClassImp(MRead);
+
+Bool_t MRead::Rewind()
+{
+    *fLog << err << "ERROR - Rewind() not implemented for " << GetDescriptor() << endl;
+    return kFALSE;
+}
 
 // --------------------------------------------------------------------------
Index: /trunk/MagicSoft/Mars/mfileio/MRead.h
===================================================================
--- /trunk/MagicSoft/Mars/mfileio/MRead.h	(revision 2116)
+++ /trunk/MagicSoft/Mars/mfileio/MRead.h	(revision 2117)
@@ -17,4 +17,5 @@
 
     virtual UInt_t GetEntries() = 0;
+    virtual Bool_t Rewind();
 
     void SetSelector(MFilter *f) { fSelector = f; }
Index: /trunk/MagicSoft/Mars/mfileio/MReadMarsFile.h
===================================================================
--- /trunk/MagicSoft/Mars/mfileio/MReadMarsFile.h	(revision 2116)
+++ /trunk/MagicSoft/Mars/mfileio/MReadMarsFile.h	(revision 2117)
@@ -26,4 +26,6 @@
     Int_t AddFile(const char *fname, Int_t entries=-1);
 
+    Bool_t Rewind() { if (fRun) fRun->Rewind(); MReadTree::Rewind(); return kTRUE; }
+
     ClassDef(MReadMarsFile, 1)	// Reads a tree from file(s) and the information from the 'RunHeader'-tree
 };
Index: /trunk/MagicSoft/Mars/mfileio/MReadTree.cc
===================================================================
--- /trunk/MagicSoft/Mars/mfileio/MReadTree.cc	(revision 2116)
+++ /trunk/MagicSoft/Mars/mfileio/MReadTree.cc	(revision 2117)
@@ -131,5 +131,6 @@
     //
     // Delete all the pointers to pointers to the objects where the
-    // branche data gets stored.
+    // branche data gets stored. FIXME: When PreProcessed twice this
+    // creates a memory leak!
     //
     TIter Next(fChain->GetStatus());
@@ -239,6 +240,6 @@
     if (numfiles>0)
         SetBit(kChainWasChanged);
-
-    *fLog << warn << "WARNING: '" << fname << "' not added to " << GetDescriptor() << endl;
+    else
+        *fLog << warn << "WARNING: '" << fname << "' not added to " << GetDescriptor() << endl;
 
     return numfiles;
Index: /trunk/MagicSoft/Mars/mfileio/MReadTree.h
===================================================================
--- /trunk/MagicSoft/Mars/mfileio/MReadTree.h	(revision 2116)
+++ /trunk/MagicSoft/Mars/mfileio/MReadTree.h	(revision 2117)
@@ -57,19 +57,20 @@
     UInt_t GetEntries();
 
-    TString    GetFileName() const;
-    Int_t      GetFileIndex() const;
+    TString GetFileName() const;
+    Int_t   GetFileIndex() const;
 
-    virtual void   AddNotify(TObject *obj);
-    virtual void   SetOwner(Bool_t flag=kTRUE);
-    virtual void   Print(Option_t *opt="") const;
+    virtual void AddNotify(TObject *obj);
+    virtual void SetOwner(Bool_t flag=kTRUE);
 
-    virtual Int_t  AddFile(const char *fname, Int_t entries=-1);
-    virtual Int_t  AddFiles(const MReadTree &read);
+    virtual Int_t AddFile(const char *fname, Int_t entries=-1);
+    virtual Int_t AddFiles(const MReadTree &read);
 
-    virtual Bool_t PreProcess(MParList *pList);
-    virtual Bool_t Process();
-    virtual Bool_t PostProcess();
+    Bool_t PreProcess(MParList *pList);
+    Bool_t Process();
+    Bool_t PostProcess();
 
-    virtual Bool_t Notify();
+    Bool_t Notify();
+    Bool_t Rewind() { SetEventNum(0); return kTRUE; }
+    void   Print(Option_t *opt="") const;
 
     ClassDef(MReadTree, 1)	// Reads a tree from file(s)
Index: /trunk/MagicSoft/Mars/mhist/MBinning.cc
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MBinning.cc	(revision 2116)
+++ /trunk/MagicSoft/Mars/mhist/MBinning.cc	(revision 2117)
@@ -16,7 +16,7 @@
 !
 !
-!   Author(s): Thomas Bretz  01/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
-!
-!   Copyright: MAGIC Software Development, 2000-2002
+!   Author(s): Thomas Bretz, 01/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2003
 !
 !
@@ -30,4 +30,5 @@
 #include "MBinning.h"
 
+#include <ctype.h>      // tolower
 #include <fstream.h>
 
@@ -60,4 +61,36 @@
 
     fType = kIsDefault;
+}
+
+void MBinning::SetEdges(const TAxis &axe)
+{
+    const TArrayD &arr = *((TAxis&)axe).GetXbins();
+    if (arr.GetSize()>0)
+    {
+        SetEdges(arr);
+        return;
+    }
+
+    SetEdges(axe.GetNbins(), axe.GetXmin(), axe.GetXmax());
+}
+
+void MBinning::SetEdges(const TH1 &h, const Char_t axis='x')
+{
+    TH1 &hist = (TH1&)h; // get rid of const qualifier
+    switch (tolower(axis))
+    {
+    case 'x':
+        SetEdges(*hist.GetXaxis());
+        return;
+    case 'y':
+        SetEdges(*hist.GetYaxis());
+        return;
+    case 'z':
+        SetEdges(*hist.GetZaxis());
+        return;
+    default:
+        *fLog << warn << "MBinning::SetEdges: Axis '" << axis << "' unknown... using x." << endl;
+        SetEdges(*hist.GetXaxis());
+    }
 }
 
Index: /trunk/MagicSoft/Mars/mhist/MBinning.h
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MBinning.h	(revision 2116)
+++ /trunk/MagicSoft/Mars/mhist/MBinning.h	(revision 2117)
@@ -7,8 +7,9 @@
 
 #ifndef ROOT_TArrayD
-#include "TArrayD.h"
+#include <TArrayD.h>
 #endif
 
 class TH1;
+class TAxis;
 
 class MBinning : public MParContainer
@@ -38,4 +39,6 @@
     }
 
+    void SetEdges(const TAxis &axe);
+    void SetEdges(const TH1 &h, const Char_t axis='x');
     void SetEdges(const Int_t nbins, const Axis_t lo, Axis_t up);
     void SetEdgesLog(const Int_t nbins, const Axis_t lo, Axis_t up);
Index: /trunk/MagicSoft/Mars/mhist/MFillH.cc
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MFillH.cc	(revision 2116)
+++ /trunk/MagicSoft/Mars/mhist/MFillH.cc	(revision 2117)
@@ -341,4 +341,7 @@
         return kTRUE;
 
+    if (TestBit(kDoNotDisplay))
+        return kTRUE;
+
     fCanvas = &fDisplay->AddTab(fH->GetName());
     fH->Draw();
Index: /trunk/MagicSoft/Mars/mhist/MFillH.h
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MFillH.h	(revision 2116)
+++ /trunk/MagicSoft/Mars/mhist/MFillH.h	(revision 2117)
@@ -16,4 +16,9 @@
 class MFillH : public MTask
 {
+public:
+    enum {
+        kDoNotDisplay = BIT(17)
+    };
+
 private:
     MParContainer *fParContainer; // Pointer to the data container storing
Index: /trunk/MagicSoft/Mars/mhist/MH.h
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MH.h	(revision 2116)
+++ /trunk/MagicSoft/Mars/mhist/MH.h	(revision 2117)
@@ -36,4 +36,6 @@
     static TCanvas *MakeDefCanvas(const TObject *obj,
                                   const UInt_t w=625, const UInt_t h=440);
+
+    // FIXME: * --> & !!!
 
     static void SetBinning(TH1 *h, const MBinning *binsx);
Index: /trunk/MagicSoft/Mars/mhist/MH3.cc
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MH3.cc	(revision 2116)
+++ /trunk/MagicSoft/Mars/mhist/MH3.cc	(revision 2117)
@@ -60,4 +60,5 @@
 #include "MH3.h"
 
+#include <ctype.h>   // tolower
 #include <fstream.h>
 
@@ -636,2 +637,76 @@
     return h;
 }
+
+TString MH3::GetRule(const Char_t axis='x') const
+{
+    switch (tolower(axis))
+    {
+    case 'x':
+        return fData[0] ? fData[0]->GetRule() : TString("");
+    case 'y':
+        return fData[1] ? fData[1]->GetRule() : TString("");
+    case 'z':
+        return fData[2] ? fData[2]->GetRule() : TString("");
+    default:
+        return "<n/a>";
+    }
+}
+
+// --------------------------------------------------------------------------
+//
+// Returns the total number of bins in a histogram (excluding under- and
+// overflow bins)
+//
+Int_t MH3::GetNbins() const
+{
+    Int_t num = 1;
+
+    switch (fDimension)
+    {
+    case 3:
+        num *= fHist->GetNbinsZ()+2;
+    case 2:
+        num *= fHist->GetNbinsY()+2;
+    case 1:
+        num *= fHist->GetNbinsX()+2;
+    }
+
+    return num;
+}
+
+// --------------------------------------------------------------------------
+//
+// Returns the total number of bins in a histogram (excluding under- and
+// overflow bins) Return -1 if bin is underflow or overflow
+//
+Int_t MH3::FindFixBin(Double_t x, Double_t y, Double_t z) const
+{
+    const TAxis &axex = *fHist->GetXaxis();
+    const TAxis &axey = *fHist->GetYaxis();
+    const TAxis &axez = *fHist->GetZaxis();
+
+    Int_t binz = 0;
+    Int_t biny = 0;
+    Int_t binx = 0;
+
+    switch (fDimension)
+    {
+    case 3:
+        binz = axez.FindFixBin(z);
+        if (binz>axez.GetLast() || binz<axez.GetFirst())
+            return -1;
+    case 2:
+        biny = axey.FindFixBin(y);
+        if (biny>axey.GetLast() || biny<axey.GetFirst())
+            return -1;
+    case 1:
+        binx = axex.FindFixBin(x);
+        if (binx<axex.GetFirst() || binx>axex.GetLast())
+            return -1;
+    }
+
+    const Int_t nx = fHist->GetNbinsX()+2;
+    const Int_t ny = fHist->GetNbinsY()+2;
+
+    return binx + nx*(biny +ny*binz);
+}
Index: /trunk/MagicSoft/Mars/mhist/MH3.h
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MH3.h	(revision 2116)
+++ /trunk/MagicSoft/Mars/mhist/MH3.h	(revision 2117)
@@ -17,8 +17,6 @@
 protected:
     // Could be const but root < 3.02/06 doesn't like this...
-    Int_t fDimension;            // Number of dimensions of histogram
-    TH1  *fHist;                 // Histogram to fill
-
-    TString     fDataMember[3];  // Data member which should be filled into the histogram x
+    Int_t       fDimension;      // Number of dimensions of histogram
+    TH1        *fHist;           // Histogram to fill
     MDataChain *fData[3];        // Object from which the data is filled
     Double_t    fScale[3];       // Scale for the three axis (eg unit)
@@ -44,4 +42,6 @@
 
     Int_t GetDimension() const { return fDimension; }
+    Int_t GetNbins() const;
+    Int_t FindFixBin(Double_t x, Double_t y=0, Double_t z=0) const;
 
     void SetName(const char *name);
@@ -52,4 +52,5 @@
 
     TString GetDataMember() const;
+    TString GetRule(const Char_t axis='x') const;
 
     TH1 &GetHist() { return *fHist; }
Index: /trunk/MagicSoft/Mars/mimage/MHHillasSrc.cc
===================================================================
--- /trunk/MagicSoft/Mars/mimage/MHHillasSrc.cc	(revision 2116)
+++ /trunk/MagicSoft/Mars/mimage/MHHillasSrc.cc	(revision 2117)
@@ -230,5 +230,5 @@
 
     TVirtualPad *savepad = gPad;
-    gPad->cd(4);
+    savepad->cd(4);
     gPad->SetLogy();
     gPad = savepad;
Index: /trunk/MagicSoft/Mars/mmain/MStatusDisplay.cc
===================================================================
--- /trunk/MagicSoft/Mars/mmain/MStatusDisplay.cc	(revision 2116)
+++ /trunk/MagicSoft/Mars/mmain/MStatusDisplay.cc	(revision 2117)
@@ -485,5 +485,5 @@
 //
 MStatusDisplay::MStatusDisplay(Long_t t)
-: TGMainFrame(gClient->GetRoot(), 1, 1), fTimer(this, t, kTRUE), fStatus(kLoopNone), fLog(&gLog), fLogIdx(-1), fLogTimer(this, 250, kTRUE), fLogBox(NULL)
+: TGMainFrame(gClient->GetRoot(), 1, 1), fTimer(this, t, kTRUE), fStatus(kLoopNone), fLog(&gLog), fLogIdx(-1), fLogTimer(this, 250, kTRUE), fLogBox(NULL), fIsLocked(0)
 {
     gROOT->GetListOfSpecials()->Add(this);
@@ -758,5 +758,5 @@
     case kLoopStop:
     case kFileExit:
-        if (id==kFileExit && !TestBit(kIsLocked))
+        if (id==kFileExit && !fIsLocked)
             delete this;
         fStatus = (Status_t)id;
@@ -1075,4 +1075,7 @@
 void MStatusDisplay::SetNoContextMenu(Bool_t flag)
 {
+    if (fIsLocked>1)
+        return;
+
     flag ? SetBit(kNoContextMenu) : ResetBit(kNoContextMenu);
     for (int i=1; i<fTab->GetNumberOfTabs(); i++)
@@ -1253,4 +1256,7 @@
 void MStatusDisplay::StartUpdate(Int_t millisec)
 {
+    if (fIsLocked>1)
+        return;
+
     if (fTimer.GetTime()<TTime(0))
         return;
@@ -1264,4 +1270,7 @@
 void MStatusDisplay::StopUpdate()
 {
+    if (fIsLocked>1)
+        return;
+
     fTimer.Stop();
 }
Index: /trunk/MagicSoft/Mars/mmain/MStatusDisplay.h
===================================================================
--- /trunk/MagicSoft/Mars/mmain/MStatusDisplay.h	(revision 2116)
+++ /trunk/MagicSoft/Mars/mmain/MStatusDisplay.h	(revision 2117)
@@ -72,4 +72,6 @@
     FontStruct_t fFont;
 
+    UInt_t fIsLocked;
+
     void AddMenuBar();
     void AddProgressBar();
@@ -100,7 +102,4 @@
     void UpdatePSHeader(const TString &name) const;
 
-    enum {
-        kIsLocked = BIT(14)
-    };
 public:
      MStatusDisplay(Long_t t=1000);
@@ -152,6 +151,6 @@
      void ClearStatus() { fStatus = kLoopNone; }
 
-     void Lock() { SetBit(kIsLocked); }
-     void UnLock() { ResetBit(kIsLocked); }
+     void Lock() { fIsLocked++; }
+     void UnLock() { if (fIsLocked>0) fIsLocked--; }
 
      Bool_t CheckTabForCanvas(int num) const;
