Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 1567)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 1568)
@@ -1,3 +1,20 @@
                                                                   -*-*- END -*-*-
+ 2002/10/30: Thomas Bretz
+
+   * mhist/MHMatrix.cc:
+     - changed the return value for the kernel method from log to -log
+     - fixed a typo in an error message
+     - fixed a crash in case the matrix is singular
+
+   * mhist/MMultiDimDistCalc.cc:
+     - check whether calculation of the distance succeeded
+
+   * mfileio/MReadTree.[h,cc]:
+     - implementation which makes sure, that the number of events returned 
+       by GetEntries always is the correct value.
+     - mainly use GetEntries now instead of fNumEntries
+
+
+
  2002/10/29: Thomas Bretz
 
Index: /trunk/MagicSoft/Mars/manalysis/MCameraSmooth.cc
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MCameraSmooth.cc	(revision 1567)
+++ /trunk/MagicSoft/Mars/manalysis/MCameraSmooth.cc	(revision 1568)
@@ -44,6 +44,4 @@
 #include "MCerPhotEvt.h"
 #include "MBlindPixels.h"
-
-#include "MMcRunHeader.hxx"
 
 ClassImp(MCameraSmooth);
Index: /trunk/MagicSoft/Mars/mfileio/MReadTree.cc
===================================================================
--- /trunk/MagicSoft/Mars/mfileio/MReadTree.cc	(revision 1567)
+++ /trunk/MagicSoft/Mars/mfileio/MReadTree.cc	(revision 1568)
@@ -98,5 +98,5 @@
 MReadTree::MReadTree(const char *tname, const char *fname,
                      const char *name, const char *title)
-    : fNumEntry(0), fBranchChoosing(kFALSE), fAutoEnable(kTRUE), fProgress(NULL)
+    : fNumEntry(0), fNumEntries(0), fBranchChoosing(kFALSE), fAutoEnable(kTRUE), fProgress(NULL)
 {
     fName  = name  ? name  : "MReadTree";
@@ -119,5 +119,6 @@
 
     if (fname)
-        fChain->Add(fname);
+        if (fChain->Add(fname)>0)
+            SetBit(kChainWasChanged);
 }
 
@@ -198,5 +199,11 @@
     // returns the number of file which were added
     //
-    return fChain->Add(fname);
+
+    const Int_t numfiles = fChain->Add(fname);
+
+    if (numfiles>0)
+        SetBit(kChainWasChanged);
+
+    return numfiles;
 }
 
@@ -215,4 +222,7 @@
     while ((obj=Next()))
         rc += AddFile(obj->GetTitle());
+
+    if (rc>0)
+        SetBit(kChainWasChanged);
 
     return rc;
@@ -391,4 +401,21 @@
     }
 */
+}
+
+// --------------------------------------------------------------------------
+//
+//  If the chain has been changed (by calling AddFile or using a file
+//  in the constructors argument) the number of entries is newly
+//  calculated from the files in the chain - this may take a while.
+//  The number of entries is returned.
+//
+UInt_t MReadTree::GetEntries()
+{
+    if (TestBit(kChainWasChanged))
+    {
+        fNumEntries = (UInt_t)fChain->GetEntries();
+        ResetBit(kChainWasChanged);
+    }
+    return fNumEntries;
 }
 
@@ -433,7 +460,5 @@
     // get number of events in this tree
     //
-    fNumEntries = (UInt_t)fChain->GetEntries();
-
-    if (!fNumEntries)
+    if (!GetEntries())
     {
         *fLog << warn << dbginf << "No entries found in file(s)" << endl;
@@ -616,5 +641,5 @@
     //
 #if ROOT_VERSION_CODE < ROOT_VERSION(3,03,01)
-    if (fNumEntry >= fNumEntries)
+    if (fNumEntry >= GetEntries())
         return kFALSE;
 #endif
@@ -666,5 +691,5 @@
 Bool_t MReadTree::DecEventNum(UInt_t dec)
 {
-    if (fNumEntry-dec >= fNumEntries)
+    if (fNumEntry-dec >= GetEntries())
     {
         *fLog << warn << GetDescriptor() << ": DecEventNum, WARNING - Event " << fNumEntry << "-";
@@ -684,5 +709,5 @@
 Bool_t MReadTree::IncEventNum(UInt_t inc)
 {
-    if (fNumEntry+inc >= fNumEntries)
+    if (fNumEntry+inc >= GetEntries())
     {
         *fLog << warn << GetDescriptor() << ": IncEventNum, WARNING - Event " << fNumEntry << "+";
@@ -704,5 +729,5 @@
 Bool_t MReadTree::SetEventNum(UInt_t nr)
 {
-    if (nr >= fNumEntries)
+    if (nr >= GetEntries())
     {
         *fLog << warn << GetDescriptor() << ": SetEventNum, WARNING - " << nr << " out of Range." << endl;
Index: /trunk/MagicSoft/Mars/mfileio/MReadTree.h
===================================================================
--- /trunk/MagicSoft/Mars/mfileio/MReadTree.h	(revision 1567)
+++ /trunk/MagicSoft/Mars/mfileio/MReadTree.h	(revision 1568)
@@ -23,4 +23,6 @@
     TList  *fVetoList;         // List of Branches which are not allowed to get enabled
     TList  *fNotify;           // List of TObjects to notify when switching files
+
+    enum { kChainWasChanged = BIT(14) };
 
 private:
@@ -58,5 +60,5 @@
 
     UInt_t GetEventNum() const { return fNumEntry;   }
-    UInt_t GetEntries() const  { return fNumEntries; }
+    UInt_t GetEntries();
 
     TString    GetFileName() const;
