Index: trunk/MagicSoft/Mars/mbase/MAGIC.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MAGIC.h	(revision 1333)
+++ trunk/MagicSoft/Mars/mbase/MAGIC.h	(revision 1337)
@@ -22,5 +22,5 @@
 //     ParticleId for Monte Carlo simulation
 //
-const Int_t kGAMMA  =    0;
+const Int_t kGAMMA  =    1;
 const Int_t kPROTON =   14;
 const Int_t kHELIUM =  402;
Index: trunk/MagicSoft/Mars/mbase/MLogo.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MLogo.cc	(revision 1337)
+++ trunk/MagicSoft/Mars/mbase/MLogo.cc	(revision 1337)
@@ -0,0 +1,207 @@
+/* ======================================================================== *\
+!
+! *
+! * 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  05/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2002
+!
+!
+\* ======================================================================== */
+
+//////////////////////////////////////////////////////////////////////////////
+//                                                                          //
+// MLogo                                                                    //
+//                                                                          //
+// X based logo displayer. Displays a given logo after a call to Popup()    //
+// until Popdown() or the destructor is called, but for a minimum of a      //
+// given number of milliseconds.                                            //
+//                                                                          //
+//////////////////////////////////////////////////////////////////////////////
+#include "MLogo.h"
+
+#include <unistd.h>    // usleep
+#include <iostream.h>  // cout
+#include <sys/time.h>  // gettimeofday
+
+#ifndef XpmSuccess
+#define XpmSuccess       0
+#endif
+#ifndef XpmColorError
+#define XpmColorError    1
+#endif
+
+MLogo::MLogo(int millisec)
+   : fDisplay(0), fLogoWindow(0), fLogoPixmap(0), fMilliSec(millisec)
+{
+    // millisec: time of minimum stayup
+}
+
+void MLogo::Wait() const
+{
+    struct timeval tv;
+
+    gettimeofday(&tv, 0);
+
+    tv.tv_sec  -= fPopupTime.tv_sec;
+    tv.tv_usec -= fPopupTime.tv_usec;
+
+    while (tv.tv_usec < 0)
+    {
+        tv.tv_usec += 1000000;
+        tv.tv_sec--;
+    }
+
+    while (tv.tv_sec > 0)
+        tv.tv_usec += 1000000;
+
+    long sleep = fMilliSec*1000-tv.tv_usec;
+
+    if (sleep <= 0)
+        return;
+
+    usleep(sleep);
+}
+
+Pixmap MLogo::GetLogo() const
+{
+#ifdef XpmVersion
+    int depth = PlanesOfScreen(XDefaultScreenOfDisplay(fDisplay));
+
+    if (depth <= 1)
+        return 0;
+
+    XWindowAttributes win_attr;
+    XGetWindowAttributes(fDisplay, fLogoWindow, &win_attr);
+
+    XpmAttributes attr;
+    attr.valuemask = XpmVisual | XpmColormap | XpmDepth;
+    attr.visual    = win_attr.visual;
+    attr.colormap  = win_attr.colormap;
+    attr.depth     = win_attr.depth;
+
+#ifdef XpmColorKey              // Not available in XPM 3.2 and earlier
+
+    switch (depth)
+    {
+    case 0:
+        attr.valuemask &= ~XpmColorKey;
+        break;
+    case 1:
+        attr.color_key = XPM_MONO;
+        break;
+    case 2:
+        attr.color_key = XPM_GRAY;
+        break;
+    case 3:
+    case 4:
+        attr.color_key = XPM_GRAY4;
+        break;
+    default:
+        attr.color_key = XPM_COLOR;
+    }
+#endif // defined(XpmColorKey)
+
+
+    Pixmap logo;
+#ifdef USE_MAGICLOGO
+#include "../magiclogo.xpm"
+    int ret = XpmCreatePixmapFromData(fDisplay, fLogoWindow,
+                                      mag1, &logo, 0, &attr);
+#else
+#include "../marslogo_neu.xpm"
+    int ret = XpmCreatePixmapFromData(fDisplay, fLogoWindow,
+                                      marslogo_neu_xpm, &logo, 0, &attr);
+#endif
+    XpmFreeAttributes(&attr);
+
+    if (ret == XpmSuccess || ret == XpmColorError)
+        return logo;
+
+    if (logo)
+        XFreePixmap(fDisplay, logo);
+#endif
+    return 0;
+}
+
+void MLogo::Popup()
+{
+#ifdef XpmVersion
+    if (fLogoWindow || fLogoPixmap || fDisplay)
+#endif
+        return;
+
+    fDisplay = XOpenDisplay("");
+    if (!fDisplay)
+        return;
+
+    int screen = DefaultScreen(fDisplay);
+
+    fLogoWindow = XCreateSimpleWindow(fDisplay, DefaultRootWindow(fDisplay),
+                                      -100, -100, 50, 50, 0,
+                                      BlackPixel(fDisplay, screen),
+                                      WhitePixel(fDisplay, screen));
+    fLogoPixmap = GetLogo();
+
+    Window root;
+    int x, y;
+    unsigned int w, h, bw, depth;
+    XGetGeometry(fDisplay, fLogoPixmap,
+                 &root, &x, &y, &w, &h, &bw, &depth);
+
+    Screen *xscreen = XDefaultScreenOfDisplay(fDisplay);
+    x = (WidthOfScreen(xscreen) - w) / 2;
+    y = (HeightOfScreen(xscreen) - h) / 2;
+
+    XMoveResizeWindow(fDisplay, fLogoWindow, x, y, w, h);
+    XSync(fDisplay, False);   // make sure move & resize is done before mapping
+
+    unsigned long valmask  = CWBackPixmap | CWOverrideRedirect;
+
+    XSetWindowAttributes xswa;
+    xswa.background_pixmap = fLogoPixmap;
+    xswa.override_redirect = True;
+    XChangeWindowAttributes(fDisplay, fLogoWindow, valmask, &xswa);
+
+    XMapRaised(fDisplay, fLogoWindow);
+    XSync(fDisplay, False);
+
+    gettimeofday(&fPopupTime, 0);
+}
+
+void MLogo::Popdown()
+{
+    if (fLogoWindow && fLogoPixmap && fDisplay)
+        Wait();
+
+    if (fLogoWindow)
+    {
+        XUnmapWindow(fDisplay, fLogoWindow);
+        XDestroyWindow(fDisplay, fLogoWindow);
+        fLogoWindow = 0;
+    }
+    if (fLogoPixmap)
+    {
+        XFreePixmap(fDisplay, fLogoPixmap);
+        fLogoPixmap = 0;
+    }
+    if (fDisplay)
+    {
+        XSync(fDisplay, False);
+        XCloseDisplay(fDisplay);
+        fDisplay = 0;
+    }
+}
Index: trunk/MagicSoft/Mars/mbase/MLogo.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MLogo.h	(revision 1337)
+++ trunk/MagicSoft/Mars/mbase/MLogo.h	(revision 1337)
@@ -0,0 +1,35 @@
+#ifndef MARS_MLogo
+#define MARS_MLogo
+
+#ifndef __CINT__
+
+#include <X11/Xlib.h>
+
+#include "Xpm.h"
+
+class MLogo
+{
+    Display *fDisplay;         // display handle
+    Window   fLogoWindow;      // window handle
+    Pixmap   fLogoPixmap;      // pixmap handle
+    long     fMilliSec;        // stayup time
+
+    struct timeval fPopupTime; // time of popup
+
+    void   Wait() const;
+    Pixmap GetLogo() const;
+
+public:
+    MLogo(int millisec=777);
+    ~MLogo()
+    {
+        Popdown();
+    }
+
+    void Popup();
+    void Popdown();
+};
+
+#endif
+
+#endif
Index: trunk/MagicSoft/Mars/mbase/MParList.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MParList.cc	(revision 1333)
+++ trunk/MagicSoft/Mars/mbase/MParList.cc	(revision 1337)
@@ -215,4 +215,36 @@
 // --------------------------------------------------------------------------
 //
+//  Find an object with the same name in the list and replace it with
+//  the new one. If the kIsOwner flag is set and the object was not
+//  created automatically, the object is deleted.
+//
+Bool_t MParList::Replace(MParContainer *cont)
+{
+    //
+    //  check if the object (you want to add) exists
+    //
+    if (!cont)
+        return kFALSE;
+
+    TObject *obj = FindObject(cont->GetName());
+    if (!obj)
+    {
+        *fLog << warn << "No object with the same name '";
+        *fLog << cont->GetName() << "' in list... ignored." << endl;
+        return kFALSE;
+    }
+
+    fContainer->Remove(obj);
+
+    if (TestBit(kIsOwner) && !fAutodelete->FindObject(obj))
+        delete obj;
+
+    *fLog << inf << "MParContainer '" << obj->GetName() << "' found and replaced..." << endl;
+
+    return AddToList(cont);
+}
+
+// --------------------------------------------------------------------------
+//
 //  Find an object in the list.
 //  'name' is the name of the object you are searching for.
Index: trunk/MagicSoft/Mars/mbase/MParList.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MParList.h	(revision 1333)
+++ trunk/MagicSoft/Mars/mbase/MParList.h	(revision 1337)
@@ -42,4 +42,6 @@
     void   AddToList(TObjArray *list);
 
+    Bool_t Replace(MParContainer *obj);
+
     void SetLogStream(MLog *log);
 
Index: trunk/MagicSoft/Mars/mbase/MReadMarsFile.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MReadMarsFile.cc	(revision 1333)
+++ trunk/MagicSoft/Mars/mbase/MReadMarsFile.cc	(revision 1337)
@@ -108,13 +108,26 @@
 Bool_t MReadMarsFile::Notify()
 {
+    Int_t runtype = -1;
+/*
+    const MRawRunHeader *runheader = (MRawRunHeader*)fParList->FindObject("MRawRunHeader");
+    if (runheader)
+        runtype = runheader->GetRunType();
+*/
     //
     // Try to read the new run headers. If reading the new run header
     // was successfull call the ReInits
     //
+    const Int_t idx = GetFileIndex();
+    fRun->SetEventNum(idx<0?0:idx); // Assumption: One Entry per File!
     if (fRun->Process())
     {
-        *fLog << inf << "MReadMarsFile: Switching to '" << GetFileName() << "' ";
-        *fLog << "(before event #" << GetEventNum()-1 << ")" << endl;
-
+        *fLog << inf << "MReadMarsFile: Switching to #" << GetFileIndex();
+        *fLog << " '" << GetFileName() << "' (before event #";
+        *fLog << GetEventNum()-1 << ")" << endl;
+/*
+        if (runheader)
+            if (runtype != runheader->GetRunType())
+                *fLog << warn << "Warning - You are mixing files with different run types!" << endl;
+*/
         if (fTaskList->ReInit())
             return kTRUE;
@@ -137,13 +150,20 @@
 Bool_t MReadMarsFile::PreProcess(MParList *pList)
 {
+    fParList  = pList;
     fTaskList = (MTaskList*)pList->FindObject("MTaskList");
 
     if (!fRun->PreProcess(pList))
+    {
+        *fLog << err << "Error - PreProcessing MReadMarsFile::fRun... aborting." << endl;
         return kFALSE;
+    }
 
+    const Int_t idx = GetFileIndex();
+    fRun->SetEventNum(idx<0?0:idx); // Assumption: One Entry per File!
     if (!fRun->Process())
+    {
+        *fLog << err << "Error - Processing MReadMarsFile::fRun... aborting." << endl;
         return kFALSE;
-
-    fRun->SetEventNum(0);
+    }
 
     return MReadTree::PreProcess(pList);
Index: trunk/MagicSoft/Mars/mbase/MReadMarsFile.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MReadMarsFile.h	(revision 1333)
+++ trunk/MagicSoft/Mars/mbase/MReadMarsFile.h	(revision 1337)
@@ -6,4 +6,5 @@
 #endif
 
+class MParList;
 class MTaskList;
 
@@ -12,4 +13,5 @@
 private:
     MReadTree *fRun;
+    MParList  *fParList;  //! Parlist for reinitialization
     MTaskList *fTaskList; //! Tasklist for reinitialization
 
Index: trunk/MagicSoft/Mars/mbase/MReadTree.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MReadTree.cc	(revision 1333)
+++ trunk/MagicSoft/Mars/mbase/MReadTree.cc	(revision 1337)
@@ -55,4 +55,5 @@
 #include <TFile.h>           // TFile::GetName
 #include <TChain.h>
+#include <TSystem.h>         // gSystem->ExpandPath
 #include <TGProgressBar.h>
 #include <TChainElement.h>
@@ -746,4 +747,28 @@
 // --------------------------------------------------------------------------
 //
+//  Return the number of the file in the chain, -1 in case of an error
+//
+Int_t MReadTree::GetFileIndex() const
+{
+    return fChain->GetTreeNumber();
+    /*
+    const TString filename = fChain->GetFile()->GetName();
+
+    int i=0;
+    TObject *file = NULL;
+
+    TIter Next(fChain->GetListOfFiles());
+    while ((file=Next()))
+    {
+        if (filename==gSystem->ExpandPathName(file->GetTitle()))
+            return i;
+        i++;
+    }
+    return -1;
+    */
+}
+
+// --------------------------------------------------------------------------
+//
 //  This schedules a TObject which Notify(9 function is called in case
 //  of MReadTree (TChain) switches from one file in the chain to another
@@ -759,5 +784,5 @@
     *fLog << all << GetDescriptor() << dec << endl;
     *fLog << setfill('-') << setw(strlen(GetDescriptor())) << "" << endl;
-    *fLog << " Files:" << endl;
+    *fLog << " Files [Tree]:" << endl;
 
     int i = 0;
@@ -765,7 +790,7 @@
     TObject *obj = NULL;
     while ((obj=Next()))
-        *fLog << " " << i++ << ") " << obj->GetName() << endl;
-
-    *fLog << " Entries: " << fNumEntries << endl;
-    *fLog << " Next Entry: " << fNumEntry << endl;
-}
+        *fLog << " " << i++ << ") " << obj->GetTitle() << " [" << obj->GetName() << "]" << endl;
+
+    *fLog << " Total Number of Entries: " << fNumEntries << endl;
+    *fLog << " Next Entry to read: " << fNumEntry << endl;
+}
Index: trunk/MagicSoft/Mars/mbase/MReadTree.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MReadTree.h	(revision 1333)
+++ trunk/MagicSoft/Mars/mbase/MReadTree.h	(revision 1337)
@@ -59,4 +59,5 @@
 
     TString GetFileName() const;
+    Int_t   GetFileIndex() const;
 
     virtual void   AddNotify(TObject *obj);
Index: trunk/MagicSoft/Mars/mbase/MTaskList.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MTaskList.cc	(revision 1333)
+++ trunk/MagicSoft/Mars/mbase/MTaskList.cc	(revision 1337)
@@ -303,5 +303,5 @@
     fParList = pList;
 
-    fTasksProcess.Delete();
+    fTasksProcess.Clear();
 
     //
@@ -317,4 +317,6 @@
     while ((task=(MTask*)Next()))
     {
+        *fLog << all << task->GetName() << "... " << flush;
+
         if (CheckClassForProcess(task->IsA()))
             fTasksProcess.Add(task);
@@ -457,8 +459,8 @@
     while ( (task=(MTask*)Next()) )
     {
+        *fLog << all << task->GetName() << "... " << flush;
+
         if (!task->CallPostProcess())
             return kFALSE;
-
-        *fLog << all << task->GetName() << "... " << flush;
     }
 
Index: trunk/MagicSoft/Mars/mbase/MWriteAsciiFile.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MWriteAsciiFile.cc	(revision 1333)
+++ trunk/MagicSoft/Mars/mbase/MWriteAsciiFile.cc	(revision 1337)
@@ -263,2 +263,21 @@
 }
 
+/*
+Bool_t MWriteAsciiFile::PreProcess(MParList *plist)
+{
+    MDataChain *chain=NULL;
+
+    TIter Next(&fList);
+    while (((MDataChain*)chain=Next()))
+        if (!chain->PreProcess(plist))
+            return kFALSE;
+
+    return MWriteFile::PreProcess(plist);
+}
+
+void MWriteAsciiFile::Add(const char *rule)
+{
+    MDataChain *chain = new MDataChain(rule);
+    fList.Add(chain);
+}
+*/
Index: trunk/MagicSoft/Mars/mbase/MWriteAsciiFile.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MWriteAsciiFile.h	(revision 1333)
+++ trunk/MagicSoft/Mars/mbase/MWriteAsciiFile.h	(revision 1337)
@@ -29,5 +29,7 @@
 
     TString fNameFile;
-
+/*
+    TList fList;
+*/
     virtual void   CheckAndWrite() const;
     virtual Bool_t IsFileOpen() const;
@@ -47,4 +49,9 @@
     void AddContainer(MParContainer *cont, const char *member="", Double_t scale=1);
 
+    /*
+     Bool_t PreProcess(MParList *plist);
+     void Add(const char *rule);
+     */
+
     ClassDef(MWriteAsciiFile, 0) // Class to write one container to an ascii file
 };
