Index: trunk/MagicSoft/Mars/mbase/BaseLinkDef.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/BaseLinkDef.h	(revision 1032)
+++ trunk/MagicSoft/Mars/mbase/BaseLinkDef.h	(revision 1035)
@@ -35,4 +35,5 @@
 
 #pragma link C++ class MReadTree+;
+#pragma link C++ class MReadMarsFile+;
 
 #pragma link C++ class MRootFileBranch+;
Index: trunk/MagicSoft/Mars/mbase/MReadMarsFile.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MReadMarsFile.cc	(revision 1035)
+++ trunk/MagicSoft/Mars/mbase/MReadMarsFile.cc	(revision 1035)
@@ -0,0 +1,148 @@
+/* ======================================================================== *\
+!
+! *
+! * 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  12/2000 (tbretz@uni-sw.gwdg.de)
+!
+!   Copyright: MAGIC Software Development, 2000-2001
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//                                                                         //
+// MReadMarsFile                                                           //
+//                                                                         //
+// This tasks opens all branches in a specified tree and creates the       //
+// corresponding parameter containers if not already existing in the       //
+// parameter list.                                                         //
+//                                                                         //
+// The Process function reads one events from the tree. To go through the  //
+// events of one tree make sure that the event number is increased from    //
+// outside. It makes also possible to go back by decreasing the number.    //
+//                                                                         //
+// If you don't want to start reading the first event you have to call     //
+// MReadMarsFile::SetEventNum after instantiating your                     //
+// MReadMarsFile-object.                                                   //
+//                                                                         //
+// To make reading much faster (up to a factor of 10 to 20) you can        //
+// ensure that only the data you are really processing is enabled by       //
+// calling MReadMarsFile::UseLeaf.                                         //
+//                                                                         //
+// FIXME: An automatic enabeling scheme would be nice.                     //
+//        Can we use TBranch::SetAutoDelete?                               //
+//                                                                         //
+// Later we'll use TChain::SetNotify to notify MReadMarsFile if the TChain //
+// starts to read a new file.                                              //
+//                                                                         //
+/////////////////////////////////////////////////////////////////////////////
+
+#include "MReadMarsFile.h"
+
+#include "MLog.h"
+
+ClassImp(MReadMarsFile);
+
+// --------------------------------------------------------------------------
+//
+//  Default constructor. It creates an TChain instance which represents the
+//  the Tree you want to read and adds the given file (if you gave one).
+//  More files can be added using MReadMarsFile::AddFile.
+//  Also an empty veto list is created. This list is used if you want to
+//  veto (disable or "don't enable") a branch in the tree.
+//
+MReadMarsFile::MReadMarsFile(const char *tname, const char *fname,
+                             const char *name, const char *title)
+    : MReadTree(tname, fname)
+{
+    fName  = name  ? name  : "MReadMarsFile";
+    fTitle = title ? title : "Task to loop over all events in a tree of a Mars file.";
+
+    //
+    // open the input stream
+    //
+    fRun = new MReadTree("RunHeaders", fname);
+    fRun->DisableAutoScheme();
+}
+
+// --------------------------------------------------------------------------
+//
+// Destructor. It deletes the TChain and veto list object
+//
+MReadMarsFile::~MReadMarsFile()
+{
+    delete fRun;
+}
+
+// --------------------------------------------------------------------------
+//
+//  If you want to read the given tree over several files you must add
+//  the files here before PreProcess is called. Be careful: If the tree
+//  doesn't have the same contents (branches) it may confuse your
+//  program (trees which are are not existing in later files are not read
+//  anymore, tree wich are not existing in the first file are never read)
+//
+//  Name may use the wildcarding notation, eg "xxx*.root" means all files
+//  starting with xxx in the current file system directory.
+//
+Int_t MReadMarsFile::AddFile(const char *fname)
+{
+    //
+    // FIXME! A check is missing whether the file already exists or not.
+    //
+    //
+    // returns the number of file which were added
+    //
+    Int_t n1 = fRun->AddFile(fname);
+    Int_t n2 = MReadTree::AddFile(fname);
+
+    return n1 != n2 ? -1 : n1;
+}
+
+Bool_t MReadMarsFile::Notify()
+{
+    if (GetEventNum() == 0)
+        return kTRUE;
+
+    *fLog << "MReadMarsFile: Switching to next file '" << GetFileName() << "' ";
+    *fLog << "(before Event #" << GetEventNum()-1 << ")" << endl;
+    fRun->Process();
+
+    MReadTree::Notify();
+
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+//  The PreProcess loops (till now) over the branches in the given tree.
+//  It checks if the corresponding containers (containers with the same
+//  name than the branch name) are existing in the Parameter Container List.
+//  If not, a container of objec type 'branch-name' is created (everything
+//  after the last semicolon in the branch name is stripped). Only
+//  branches which don't have a veto (see VetoBranch) are enabled If the
+//  object isn't found in the root dictionary (a list of classes known by the
+//  root environment) the branch is skipped and an error message is printed
+//  out.
+//
+Bool_t MReadMarsFile::PreProcess(MParList *pList)
+{
+    if (!fRun->PreProcess(pList))
+        return kFALSE;
+
+    return MReadTree::PreProcess(pList);
+}
+
Index: trunk/MagicSoft/Mars/mbase/MReadMarsFile.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MReadMarsFile.h	(revision 1035)
+++ trunk/MagicSoft/Mars/mbase/MReadMarsFile.h	(revision 1035)
@@ -0,0 +1,26 @@
+#ifndef MARS_MReadMarsFile
+#define MARS_MReadMarsFile
+
+#ifndef MARS_MReadTree
+#include "MReadTree.h"
+#endif
+
+class MReadMarsFile : public MReadTree
+{
+private:
+    MReadTree *fRun;
+
+    Bool_t Notify();
+
+    Bool_t PreProcess(MParList *pList);
+  
+public:
+    MReadMarsFile(const char *treename, const char *filename=NULL, const char *name=NULL, const char *title=NULL);
+    ~MReadMarsFile();
+
+    Int_t AddFile(const char *fname);
+
+    ClassDef(MReadMarsFile, 0)	// Reads a tree from file(s)
+};
+
+#endif
Index: trunk/MagicSoft/Mars/mbase/MReadTree.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MReadTree.cc	(revision 1032)
+++ trunk/MagicSoft/Mars/mbase/MReadTree.cc	(revision 1035)
@@ -54,4 +54,5 @@
 #include <fstream.h>
 
+#include <TFile.h>           // TFile::GetName
 #include <TChain.h>
 #include <TGProgressBar.h>
@@ -86,8 +87,11 @@
     fVetoList->SetOwner();
 
+    fNotify = new TOrdCollection;
+
     //
     // open the input stream
     //
     fChain = new TChain(tname);
+    fChain->SetNotify(this);
 
     if (fname)
@@ -115,5 +119,17 @@
     //
     delete fChain;
+    delete fNotify;
     delete fVetoList;
+}
+
+void MReadTree::SetOwner(Bool_t flag)
+{
+    flag ? fNotify->SetBit(kIsOwner) : fNotify->ResetBit(kIsOwner);
+}
+
+Bool_t MReadTree::Notify()
+{
+    fNotify->ForEach(TObject, Notify)();
+    return kTRUE;
 }
 
@@ -464,2 +480,12 @@
     fVetoList->Add(branch);
 }
+
+const char *MReadTree::GetFileName() const
+{
+    return fChain->GetFile()->GetName();
+}
+
+void MReadTree::AddNotify(TObject *obj)
+{
+    fNotify->Add(obj);
+}
Index: trunk/MagicSoft/Mars/mbase/MReadTree.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MReadTree.h	(revision 1032)
+++ trunk/MagicSoft/Mars/mbase/MReadTree.h	(revision 1035)
@@ -22,4 +22,5 @@
 
     TOrdCollection *fVetoList; // List of Branches which are not allowed to get enabled
+    TOrdCollection *fNotify;   // List of TObjects to notify when switching files
 
     TGProgressBar  *fProgress; // Possible display of status
@@ -32,12 +33,10 @@
     void EnableBranchChoosing();
 
-    Bool_t PreProcess(MParList *pList);
-    Bool_t Process();
-  
+    enum { kIsOwner = BIT(14) };
+
 public:
     MReadTree(const char *treename, const char *filename=NULL, const char *name=NULL, const char *title=NULL);
     ~MReadTree();
 
-    Int_t  AddFile(const char *fname);
     void   DisableAutoScheme() { fAutoEnable = kFALSE; }
     void   EnableBranch(const char *name);
@@ -55,4 +54,16 @@
     UInt_t GetEntries() const  { return fNumEntries; }
 
+    const char *GetFileName() const;
+
+    virtual void   AddNotify(TObject *obj);
+    virtual void   SetOwner(Bool_t flag=kTRUE);
+
+    virtual Int_t  AddFile(const char *fname);
+
+    virtual Bool_t PreProcess(MParList *pList);
+    virtual Bool_t Process();
+
+    virtual Bool_t Notify();
+
     ClassDef(MReadTree, 0)	// Reads a tree from file(s)
 };
Index: trunk/MagicSoft/Mars/mbase/Makefile
===================================================================
--- trunk/MagicSoft/Mars/mbase/Makefile	(revision 1032)
+++ trunk/MagicSoft/Mars/mbase/Makefile	(revision 1035)
@@ -40,4 +40,5 @@
            MEvtLoop.cc \
            MReadTree.cc \
+           MReadMarsFile.cc \
            MWriteFile.cc \
            MWriteAsciiFile.cc \
