Index: trunk/MagicSoft/Mars/LinkDef.h
===================================================================
--- trunk/MagicSoft/Mars/LinkDef.h	(revision 454)
+++ trunk/MagicSoft/Mars/LinkDef.h	(revision 454)
@@ -0,0 +1,7 @@
+#ifdef __CINT__
+
+#pragma link off all globals;
+#pragma link off all classes;
+#pragma link off all functions;
+
+#endif
Index: trunk/MagicSoft/Mars/Makefile
===================================================================
--- trunk/MagicSoft/Mars/Makefile	(revision 454)
+++ trunk/MagicSoft/Mars/Makefile	(revision 454)
@@ -0,0 +1,105 @@
+##################################################################
+#
+#   makefile
+# 
+#   for the MARS software
+#
+##################################################################
+# @maintitle
+
+# @code
+
+#
+#  please change all system depend values in the 
+#  config.mk.${OSTYPE} file 
+#
+#
+include Makefile.conf.$(OSTYPE)
+include Makefile.conf.general
+
+# @endcode 
+
+# @code 
+
+PROGRAM1 = merpp
+PROGRAM2 = readraw
+SOLIB    = mars.so
+
+#
+#  connect the include files defined in the config.mk file
+#
+INCLUDES = -I. -Imbase -Imraw
+
+#
+#  ----->>>   mars libraries
+#
+
+MARS_LIB = -Llib -lmbase  -lmraw 
+MARS_LIBB = libmbase.a libmraw.a
+
+
+#------------------------------------------------------------------------------
+
+#.SILENT:
+
+.SUFFIXES: .c .cc .cxx .h .hxx .o 
+
+
+SRCFILES = 
+
+SRCS    = $(SRCFILES)
+HEADERS = $(SRCFILES:.cc=.h)
+OBJS    = $(SRCFILES:.cc=.o) 
+OBJS1   = merpp.o 
+OBJS2   = readraw.o
+
+############################################################
+
+all: rmlib $(PROGRAM1) $(PROGRAM2) $(SOLIB)
+
+$(PROGRAM1): $(MARS_LIBB) $(OBJS1) $(OBJS) MCint.o 
+	@echo " Linking $(PROGRAM1) ..." 
+	$(CXX) $(CXXFLAGS) $(OBJS1) $(OBJS) $(MARS_LIB) MCint.o $(ROOTLIBS) $(ROOTGLIBS) -o $@
+ 
+$(PROGRAM2): $(MARS_LIBB) $(OBJS2) $(OBJS) MCint.o 
+	@echo " Linking $(PROGRAM2) ..." 
+	$(CXX) $(CXXFLAGS) $(OBJS2) $(OBJS) $(MARS_LIB) MCint.o $(ROOTLIBS) $(ROOTGLIBS) -o $@
+        
+$(SOLIB): $(MARS_LIBB) $(OBJS) MCint.o
+	@echo " Linking $(SOLIB) ..."
+	$(CXX) $(CXXFLAGS) -shared  $(OBJS2) $(OBJS) $(MARS_LIB) MCint.o $(ROOTLIBS) $(ROOTGLIBS) -o $@
+	mv mars.so lib
+
+libmbase.a:
+	@echo " Creating libmbase.a:"
+	(cd mbase; make; cd ..; mv mbase/libmbase.a lib) 
+
+libmraw.a:
+	@echo " Creating libmraw.a:"
+	(cd mraw; make; cd ..; mv mraw/libmraw.a lib) 
+
+libmocttest.a:
+	@echo " Creating libmocttest.a:"
+	(cd mocttest; make; cd .., mv mocttest/libmocttest.a lib) 
+        
+dox:
+	@echo " Creating html documentation:"
+	root -b -q dohtml.C
+
+
+MCint.cc:	$(HEADERS)
+	       	@echo "Generating dictionary MCint.cc..."
+		@$(ROOTSYS)/bin/rootcint -f MCint.cc \
+                -c $(INCLUDES) $(HEADERS) LinkDef.h 
+
+include Makefile.rules
+
+clean:	rmlib rmcint rmobjs rmcore rmbin
+
+# @endcode
+
+
+
+# DO NOT DELETE
+
+
Index: trunk/MagicSoft/Mars/Makefile.conf.general
===================================================================
--- trunk/MagicSoft/Mars/Makefile.conf.general	(revision 454)
+++ trunk/MagicSoft/Mars/Makefile.conf.general	(revision 454)
@@ -0,0 +1,16 @@
+#
+#  ----->>>   root libraries
+#
+
+ROOTLIBS   =  `root-config --libs`
+ROOTGLIBS  =  `root-config --glibs`
+ROOTCFLAGS =  `root-config --cflags`
+
+#
+#  compiler flags
+#
+
+CXXFLAGS  = $(ROOTCFLAGS) $(INCLUDES) $(OPTIM) $(DEBUG)
+CFLAGS    = $(CXXFLAGS)
+FFLAGS    = $(CXXFLAGS)
+
Index: trunk/MagicSoft/Mars/Makefile.conf.linux-gnu
===================================================================
--- trunk/MagicSoft/Mars/Makefile.conf.linux-gnu	(revision 454)
+++ trunk/MagicSoft/Mars/Makefile.conf.linux-gnu	(revision 454)
@@ -0,0 +1,41 @@
+##################################################################
+#
+# config.mk
+#
+# @file        config.mk
+# 
+##################################################################
+# @maintitle
+
+# @code
+
+#
+#  ----->>>  includes
+#
+
+INCLUDE_ROOT    = ${ROOTSYS}/include
+INCLUDE_CPLUS   = /usr/include/g++
+INCLUDE_MBASE   = ./mbase
+
+
+# compilers
+
+CC            = g++
+CXX           = g++
+F77           = f77
+AR            = ar -rc
+#
+#  ----->>>   settings for compilation
+#
+
+OPTIM    = -O2 -Wall -fno-rtti -fno-exceptions -fPIC
+DEBUG    = -g 
+
+# uncomment this for quiet compilation
+
+.SILENT:
+
+# @endcode
+##EOF
+
+
Index: trunk/MagicSoft/Mars/Makefile.conf.osf1
===================================================================
--- trunk/MagicSoft/Mars/Makefile.conf.osf1	(revision 454)
+++ trunk/MagicSoft/Mars/Makefile.conf.osf1	(revision 454)
@@ -0,0 +1,43 @@
+##################################################################
+#
+# config.mk
+#
+# @file        config.mk
+# 
+##################################################################
+# @maintitle
+
+# @code
+
+#
+#  ----->>>  includes
+#
+
+INCLUDE_ROOT    = ${ROOTSYS}/include
+INCLUDE_CPLUS   = /usr/include/cxx
+INCLUDE_MBASE   = ./mbase
+
+#
+# compilers
+#
+
+CC            = cc
+CXX           = cxx
+F77           = f77
+AR            = ar -c -r
+
+#
+#  ----->>>   settings for compilation
+#
+
+OPTIM    = -O2 -ieee -arch host
+DEBUG    = -g 
+
+# uncomment this for quiet compilation
+
+.SILENT:
+
+# @endcode
+##EOF
+
+
Index: trunk/MagicSoft/Mars/Makefile.depend
===================================================================
--- trunk/MagicSoft/Mars/Makefile.depend	(revision 454)
+++ trunk/MagicSoft/Mars/Makefile.depend	(revision 454)
@@ -0,0 +1,9 @@
+##################################################################
+#
+#   makefile
+# 
+#   for the MARS software
+#
+##################################################################
+
+# DO NOT DELETE
Index: trunk/MagicSoft/Mars/Makefile.rules
===================================================================
--- trunk/MagicSoft/Mars/Makefile.rules	(revision 454)
+++ trunk/MagicSoft/Mars/Makefile.rules	(revision 454)
@@ -0,0 +1,56 @@
+
+depend:
+	@makedepend $(SRCS) $(INCLUDES) -I$(INCLUDE_CPLUS) $(ROOTCFLAGS) \
+        -f Makefile.depend 2> kk.kk ; cat kk.kk
+
+.cxx.o:	
+	@echo "Compiling " $<
+	$(CXX) $(CXXFLAGS) -c $< -o $@
+
+.cc.o:	
+	@echo "Compiling " $<
+	$(CXX) $(CXXFLAGS) -c $< -o $@
+
+.c.o:	
+	@echo "Compiling " $<
+	$(CC) $(CFLAGS) -c $< -o $@
+#
+# The cleaning facility
+#
+
+rmcint:	
+	@echo "Removing cint-stuff..."
+	@rm -f *Cint.*
+
+rmlib:	
+	@echo "Removing libraries..."
+	@rm -f lib/lib*.a
+
+rmobjs:	
+	@echo "Removing object files..."
+	@rm -f *.o
+
+rmcore:	
+	@echo "Removing core files..."
+	@rm -f core*
+
+rmbin:	
+	@echo "Removing binary files..."
+	@rm -f $(PROGRAM1) $(PROGRAM2) lib/$(SOLIB) so_locations
+
+mrproper:	clean
+	@echo "Removing *~ *.bak kk.kk htmldoc/..."
+	@rm -f *~ kk.kk *.bak macros/*~
+	@rm -rf htmldoc
+	@echo "cd mbase"
+	@cd mbase; make mrproper; cd ..
+	@echo "cd .."
+	@echo "cd mraw"
+	@cd mraw; make mrproper; cd ..
+	@echo "cd .."
+#	@echo "cd mocttest"
+#	@cd mocttest; make mrproper; cd ..
+#	@echo "cd .."
+
+
+
Index: trunk/MagicSoft/Mars/macros/dohtml.C
===================================================================
--- trunk/MagicSoft/Mars/macros/dohtml.C	(revision 454)
+++ trunk/MagicSoft/Mars/macros/dohtml.C	(revision 454)
@@ -0,0 +1,21 @@
+void dohtml()
+{
+  //
+  //  don't forget that the shared object must be loaded
+  //
+
+  //
+  //   create the html document class
+  //
+  THtml html;
+
+  html.SetOutputDir("htmldoc");
+  html.SetSourceDir(".:mbase:mraw");
+
+  html.MakeAll(kTRUE);
+
+  html.SetSourceDir("macros");
+  html.Convert("merpp.C", "MARS - Merging and Preprocessing Macro");
+  html.Convert("readraw.C", "MARS - Read a raw file macro");
+  html.Convert("rootlogon.C", "MARS - rootlogon.C");
+}
Index: trunk/MagicSoft/Mars/macros/merpp.C
===================================================================
--- trunk/MagicSoft/Mars/macros/merpp.C	(revision 454)
+++ trunk/MagicSoft/Mars/macros/merpp.C	(revision 454)
@@ -0,0 +1,60 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// This is an easy implementation of the Merging process (as root Macro)
+//
+// at the moment it reads a binary file ("rawtest.bin") which was written
+// in the DAQ raw format.
+//
+// The data are stored in root container objects (classes derived from
+// TObject like MRawRunHeader)
+//
+// This containers are written to a root file ("rawtest.root")
+//
+/////////////////////////////////////////////////////////////////////////////
+
+int merpp()
+{
+    //
+    // create a (empty) list of parameters which can be used by the tasks
+    // and an (empty) list of tasks which should be executed
+    //
+    MParList *plist  = new MParList;
+    MTaskList *tasks = new MTaskList;
+
+    //
+    // create the tasks which should be executed and add them to the list
+    // in the case you don't need parameter containers, all of them can
+    // be created by MRawFileRead::PreProcess
+    //
+    // REMARK: Don't change the order of the two instantiations.
+    //         I don't have an idea why, but here it crashes to
+    //         Interpreter.
+    //         (Using root 2.25/03, with Cint 5.14.50 on OSF1)
+    //
+    MRawFileWrite *writer = new MRawFileWrite("rawtest.root", "RECREATE");
+    MRawFileRead  *reader = new MRawFileRead("rawtest.bin");
+    tasks->AddToList(reader);
+    tasks->AddToList(writer);
+
+    //
+    // create the looping object and thell it about the parameters to use
+    // and the tasks to execute
+    //
+    MEvtLoop magic;
+
+    magic.SetParList(plist);
+    magic.SetTaskList(tasks);
+
+    //
+    // Start the eventloop which reads the raw file (MRawFileRead) and
+    // write all the information into a root file (MRawFileWrite)
+    //
+    // between reading and writing we can do, transformations, checks, etc.
+    // (I'm think of a task like MRawDataCheck)
+    //
+    magic.Eventloop();
+
+    return 0;
+}
+
+
Index: trunk/MagicSoft/Mars/macros/readin.C
===================================================================
--- trunk/MagicSoft/Mars/macros/readin.C	(revision 454)
+++ trunk/MagicSoft/Mars/macros/readin.C	(revision 454)
@@ -0,0 +1,62 @@
+{
+
+    //
+    // open the file
+    //
+    TFile input("test.root", "READ");
+
+    //
+    // open the Run Header tree
+    //
+    TTree *runtree = (TTree*) input.Get("RunHeaders") ;
+    cout << " Entries in Tree RunHeaders: " << runtree->GetEntries() << endl ;
+
+    //
+    // create an instance of MRawRunHeader, enable the branch and
+    // read the header, print it
+    //
+    MRawRunHeader *runheader = new MRawRunHeader();
+    runtree->GetBranch("MRawRunHeader")->SetAddress(&runheader);
+    runtree->GetEvent(0);
+    runheader->Print();
+
+    //
+    // open the Data Tree
+    //
+    TTree *evttree = (TTree*) input.Get("Data") ;
+
+    //
+    // create the instances of the data to read in
+    //
+    MRawEvtHeader  *evtheader = new MRawEvtHeader();
+    MTime          *evttime   = new MTime();
+    MRawEvtData    *evtdata   = new MRawEvtData();
+    MRawCrateArray *evtcrate  = new MRawCrateArray();
+
+    //
+    // enable the corresponding branches
+    //
+    evttree->GetBranch("MRawEvtHeader")->SetAddress(&evtheader);
+    evttree->GetBranch("MTime")->SetAddress(&evttime);
+    evttree->GetBranch("MRawEvtData")->SetAddress(&evtdata);
+    evttree->GetBranch("MRawCrateArray")->SetAddress(&evtcrate);
+
+    //
+    // loop over all events and print the information
+    //
+    Int_t iEnt = evttree->GetEntries();
+    cout << " Entries in Tree Data: " << iEnt << endl;
+
+    for (Int_t i = 0; i<iEnt; i++)
+    {
+      // readin event with the selected branches
+      evttree->GetEvent(i);
+
+      evtheader->Print();
+      evttime->Print();
+      evtcrate->Print();
+      evtdata->Print();
+    } 
+}
+
+
Index: trunk/MagicSoft/Mars/macros/readraw.C
===================================================================
--- trunk/MagicSoft/Mars/macros/readraw.C	(revision 454)
+++ trunk/MagicSoft/Mars/macros/readraw.C	(revision 454)
@@ -0,0 +1,62 @@
+{
+
+    //
+    // open the file
+    //
+    TFile input("test.root", "READ");
+
+    //
+    // open the Run Header tree
+    //
+    TTree *runtree = (TTree*) input.Get("RunHeaders") ;
+    cout << " Entries in Tree RunHeaders: " << runtree->GetEntries() << endl ;
+
+    //
+    // create an instance of MRawRunHeader, enable the branch and
+    // read the header, print it
+    //
+    MRawRunHeader *runheader = new MRawRunHeader();
+    runtree->GetBranch("MRawRunHeader")->SetAddress(&runheader);
+    runtree->GetEvent(0);
+    runheader->Print();
+
+    //
+    // open the Data Tree
+    //
+    TTree *evttree = (TTree*) input.Get("Data") ;
+
+    //
+    // create the instances of the data to read in
+    //
+    MRawEvtHeader  *evtheader = new MRawEvtHeader();
+    MTime          *evttime   = new MTime();
+    MRawEvtData    *evtdata   = new MRawEvtData();
+    MRawCrateArray *evtcrate  = new MRawCrateArray();
+
+    //
+    // enable the corresponding branches
+    //
+    evttree->GetBranch("MRawEvtHeader")->SetAddress(&evtheader);
+    evttree->GetBranch("MTime")->SetAddress(&evttime);
+    evttree->GetBranch("MRawEvtData")->SetAddress(&evtdata);
+    evttree->GetBranch("MRawCrateArray")->SetAddress(&evtcrate);
+
+    //
+    // loop over all events and print the information
+    //
+    Int_t iEnt = evttree->GetEntries();
+    cout << " Entries in Tree Data: " << iEnt << endl;
+
+    for (Int_t i = 0; i<iEnt; i++)
+    {
+      // readin event with the selected branches
+      evttree->GetEvent(i);
+
+      evtheader->Print();
+      evttime->Print();
+      evtcrate->Print();
+      evtdata->Print();
+    } 
+}
+
+
Index: trunk/MagicSoft/Mars/macros/rootlogon.C
===================================================================
--- trunk/MagicSoft/Mars/macros/rootlogon.C	(revision 454)
+++ trunk/MagicSoft/Mars/macros/rootlogon.C	(revision 454)
@@ -0,0 +1,17 @@
+{
+    cout << endl;
+
+    cout << "Loading 'mars.so'... " << flush;
+
+    if (gSystem->Load("mars.so")!=0)
+        cout << "error." << endl;
+    else
+        cout << "done." << endl;
+
+    cout << endl;
+
+    cout << "Welcome to the Mars Root environment." << endl;
+
+    cout << endl;
+}
+
Index: trunk/MagicSoft/Mars/macros/test.C
===================================================================
--- trunk/MagicSoft/Mars/macros/test.C	(revision 454)
+++ trunk/MagicSoft/Mars/macros/test.C	(revision 454)
@@ -0,0 +1,61 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// This is an easy implementation of the Merging process (as root Macro)
+//
+// at the moment it reads a binary file ("rawtest.bin") which was written
+// in the DAQ raw format.
+//
+// The data are stored in root container objects (classes derived from
+// TObject like MRawRunHeader)
+//
+// This containers are written to a root file ("rawtest.root")
+//
+/////////////////////////////////////////////////////////////////////////////
+
+int test()
+{
+    //
+    // create a (empty) list of parameters which can be used by the tasks
+    // and an (empty) list of tasks which should be executed
+    //
+    MParList *plist  = new MParList;
+    MTaskList *tasks = new MTaskList;
+
+    //
+    // create the tasks which should be executed and add them to the list
+    // in the case you don't need parameter containers, all of them can
+    // be created by MRawFileRead::PreProcess
+    //
+    // REMARK: Don't change the order of the two instantiations.
+    //         I don't have an idea why, but here it crashes to
+    //         Interpreter.
+    //         (Using root 2.25/03, with Cint 5.14.50 on OSF1)
+    //
+    MRawFileWrite *writer = new MRawFileWrite("output.root", "RECREATE");
+    MReadTree     *reader = new MReadTree("delme.root", "Data");
+    tasks->AddToList(reader);
+    tasks->AddToList(writer);
+
+    plist->AddToList(tasks);
+
+    //
+    // create the looping object and thell it about the parameters to use
+    // and the tasks to execute
+    //
+    MEvtLoop magic;
+
+    magic.SetParList(plist);
+
+    //
+    // Start the eventloop which reads the raw file (MRawFileRead) and
+    // write all the information into a root file (MRawFileWrite)
+    //
+    // between reading and writing we can do, transformations, checks, etc.
+    // (I'm think of a task like MRawDataCheck)
+    //
+    magic.Eventloop();
+
+    return 0;
+}
+
+
Index: trunk/MagicSoft/Mars/mbase/BaseIncl.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/BaseIncl.h	(revision 454)
+++ trunk/MagicSoft/Mars/mbase/BaseIncl.h	(revision 454)
@@ -0,0 +1,6 @@
+#ifndef __CINT__
+
+#include <TFile.h>
+#include <TTree.h>
+
+#endif // __CINT__
Index: trunk/MagicSoft/Mars/mbase/BaseLinkDef.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/BaseLinkDef.h	(revision 454)
+++ trunk/MagicSoft/Mars/mbase/BaseLinkDef.h	(revision 454)
@@ -0,0 +1,25 @@
+#ifdef __CINT__
+
+#pragma link off all globals;
+#pragma link off all classes;
+#pragma link off all functions;
+
+#pragma link C++ class MTask;
+#pragma link C++ class MTaskList;
+
+#pragma link C++ class MParContainer;
+#pragma link C++ class MParList;
+
+#pragma link C++ class MEvtLoop;
+
+#pragma link C++ class MInputStreamID;
+
+#pragma link C++ class MReadTree;
+
+#pragma link C++ class MArray;
+#pragma link C++ class MArrayB;
+#pragma link C++ class MArrayS;
+
+#pragma link C++ class MTime;
+
+#endif
Index: trunk/MagicSoft/Mars/mbase/MAGIC.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MAGIC.h	(revision 454)
+++ trunk/MagicSoft/Mars/mbase/MAGIC.h	(revision 454)
@@ -0,0 +1,32 @@
+#ifndef MAGIC_H
+#define MAGIC_H
+///////////////////////////////////////////////////////////////////////////////
+//
+//     Magic.h
+//
+//     defines MAGIC base informations
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include <TROOT.h>
+
+//
+// Magic number to detect the magic file type
+//
+// const UShort_t kMagicNumber = 0xc0c0;
+
+//
+// Values for the eventloop control
+//
+const Int_t kCONTINUE = 2;
+
+//
+//     ParticleId for Monte Carlo simulation
+//
+const Int_t kGAMMA  =    0;
+const Int_t kPROTON =   14;
+const Int_t kHELIUM =  402;
+const Int_t kOXIGEN = 1608;
+const Int_t kIRON   = 5626;
+
+#endif
Index: trunk/MagicSoft/Mars/mbase/MArray.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MArray.cc	(revision 454)
+++ trunk/MagicSoft/Mars/mbase/MArray.cc	(revision 454)
@@ -0,0 +1,4 @@
+#include "MArray.h"
+
+ClassImp(MArray)
+
Index: trunk/MagicSoft/Mars/mbase/MArray.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MArray.h	(revision 454)
+++ trunk/MagicSoft/Mars/mbase/MArray.h	(revision 454)
@@ -0,0 +1,31 @@
+#ifndef MARRAY_H
+#define MARRAY_H
+
+#ifndef MAGIC_H
+#include "MAGIC.h"
+#endif
+
+#ifndef ROOT_TObject
+#include <TObject.h>
+#endif
+
+class MArray : public TObject
+{
+protected:
+    Int_t fN; // Number of array elements
+
+public:
+   MArray()                              { fN = 0; }
+   MArray(Int_t n)                       { fN = n; }
+   MArray(const MArray &a)               { fN = a.fN; }
+   virtual ~MArray()                     { fN = 0; }
+
+   MArray &operator=(const MArray &rhs)  { fN = rhs.fN; return *this; }
+
+   Int_t        GetSize() const          { return fN; }
+   virtual void Set(Int_t n) = 0;
+
+   ClassDef(MArray, 1)  //Abstract array base class for TObject derived Arrays
+};
+
+#endif
Index: trunk/MagicSoft/Mars/mbase/MArrayB.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MArrayB.cc	(revision 454)
+++ trunk/MagicSoft/Mars/mbase/MArrayB.cc	(revision 454)
@@ -0,0 +1,4 @@
+#include "MArrayB.h"
+
+ClassImp(MArrayB)
+
Index: trunk/MagicSoft/Mars/mbase/MArrayB.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MArrayB.h	(revision 454)
+++ trunk/MagicSoft/Mars/mbase/MArrayB.h	(revision 454)
@@ -0,0 +1,167 @@
+#ifndef MARRAYB_H
+#define MARRAYB_H
+
+#ifndef MARRAY_H
+#include "MArray.h"
+#endif
+
+#include <string.h>
+
+
+class MArrayB : public MArray
+{
+private:
+    Byte_t *fArray; //[fN] Array of fN chars
+
+public:
+
+    MArrayB()
+    {
+        fN = 0;
+        fArray = NULL;
+    }
+
+    MArrayB(Int_t n)
+    {
+        fN = 0;
+        fArray = NULL;
+        if (n > 0)
+            Set(n);
+    }
+
+    MArrayB(Int_t n, Byte_t *array)
+    {
+        // Create TArrayC object and initialize it with values of array.
+        fN = 0;
+        fArray = NULL;
+        Set(n, array);
+    }
+
+    MArrayB(const MArrayB &array)
+    {
+        // Copy constructor.
+        fArray = NULL;
+        Set(array.fN, array.fArray);
+    }
+
+    Int_t GetSize() const
+    {
+        return fN;
+    }
+
+    MArrayB &operator=(const MArrayB &rhs)
+    {
+        // TArrayC assignment operator.
+        if (this != &rhs)
+            Set(rhs.fN, rhs.fArray);
+        return *this;
+    }
+
+    virtual ~MArrayB()
+    {
+        // Delete TArrayC object.
+        delete [] fArray;
+        fArray = NULL;
+    }
+
+    void Adopt(Int_t n, Byte_t *array)
+    {
+        // Adopt array arr into TArrayC, i.e. don't copy arr but use it directly
+        // in TArrayC. User may not delete arr, TArrayC dtor will do it.
+        if (fArray)
+            delete [] fArray;
+
+        fN     = n;
+        fArray = array;
+    }
+
+    void AddAt(Byte_t c, Int_t i)
+    {
+        // Add char c at position i. Check for out of bounds.
+        fArray[i] = c;
+    }
+
+    void AddAt(Byte_t *array, Int_t i, Int_t n)
+    {
+        // Add char c at position i. Check for out of bounds.
+        memcpy(fArray+i, array, n*sizeof(Byte_t));
+    }
+
+    Byte_t     At(Int_t i)
+    {
+        return fArray[i];
+    }
+
+    Byte_t    *GetArray() const
+    {
+        return fArray;
+    }
+
+    void Reset()
+    {
+        memset(fArray, 0, fN*sizeof(Byte_t));
+    }
+
+    void Set(Int_t n)
+    {
+        // Set size of this array to n chars.
+        // A new array is created, the old contents copied to the new array,
+        // then the old array is deleted.
+
+        if (n < 0 || n==fN)
+            return;
+
+        Byte_t *temp = fArray;
+        if (n != 0)
+        {
+            fArray = new Byte_t[n];
+            if (n < fN)
+                memcpy(fArray,temp, n*sizeof(Byte_t));
+            else
+            {
+                memcpy(fArray,temp,fN*sizeof(Byte_t));
+                memset(&fArray[fN],0,(n-fN)*sizeof(Byte_t));
+            }
+        }
+        else
+        {
+            fArray = 0;
+        }
+
+        if (fN)
+            delete [] temp;
+
+        fN = n;
+    }
+
+    void Set(Int_t n, Byte_t *array)
+    {
+        // Set size of this array to n chars and set the contents.
+        if (n < 0 || array == 0)
+            return;
+
+        if (fArray && fN != n)
+        {
+            delete [] fArray;
+            fArray = 0;
+        }
+        fN = n;
+
+        if (fN == 0)
+            return;
+
+        if (!fArray)
+            fArray = new Byte_t[fN];
+
+        memcpy(fArray,array, n*sizeof(Byte_t));
+    }
+
+    Byte_t &operator[](Int_t i)
+    {
+        return fArray[i];
+    }
+
+    ClassDef(MArrayB, 1)  //Array of Byte_t
+};
+
+#endif
Index: trunk/MagicSoft/Mars/mbase/MArrayS.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MArrayS.cc	(revision 454)
+++ trunk/MagicSoft/Mars/mbase/MArrayS.cc	(revision 454)
@@ -0,0 +1,4 @@
+#include "MArrayS.h"
+
+ClassImp(MArrayS)
+
Index: trunk/MagicSoft/Mars/mbase/MArrayS.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MArrayS.h	(revision 454)
+++ trunk/MagicSoft/Mars/mbase/MArrayS.h	(revision 454)
@@ -0,0 +1,160 @@
+#ifndef MARRAYS_H
+#define MARRAYS_H
+
+#ifndef MARRAY_H
+#include "MArray.h"
+#endif
+
+#include <string.h>
+
+class MArrayS : public MArray
+{
+private:
+    UShort_t *fArray; //[fN] Array of fN chars
+
+public:
+
+    MArrayS()
+    {
+        fN = 0;
+        fArray = NULL;
+    }
+
+    MArrayS(Int_t n)
+    {
+        fN = 0;
+        fArray = NULL;
+        if (n > 0)
+            Set(n);
+    }
+
+    MArrayS(Int_t n, UShort_t *array)
+    {
+        // Create TArrayC object and initialize it with values of array.
+        fN = 0;
+        fArray = NULL;
+        Set(n, array);
+    }
+
+    MArrayS(const MArrayS &array)
+    {
+        // Copy constructor.
+        fArray = NULL;
+        Set(array.fN, array.fArray);
+    }
+
+    Int_t GetSize() const
+    {
+        return fN;
+    }
+
+    MArrayS &operator=(const MArrayS &rhs)
+    {
+        // TArrayC assignment operator.
+        if (this != &rhs)
+            Set(rhs.fN, rhs.fArray);
+        return *this;
+    }
+
+    virtual ~MArrayS()
+    {
+        // Delete TArrayC object.
+        delete [] fArray;
+        fArray = NULL;
+    }
+
+    void Adopt(Int_t n, UShort_t *array)
+    {
+        // Adopt array arr into TArrayC, i.e. don't copy arr but use it directly
+        // in TArrayC. User may not delete arr, TArrayC dtor will do it.
+        if (fArray)
+            delete [] fArray;
+
+        fN     = n;
+        fArray = array;
+    }
+
+    void AddAt(UShort_t c, Int_t i)
+    {
+        // Add char c at position i. Check for out of bounds.
+        fArray[i] = c;
+    }
+
+    UShort_t     At(Int_t i)
+    {
+        return fArray[i];
+    }
+
+    UShort_t    *GetArray() const
+    {
+        return fArray;
+    }
+
+    void Reset()
+    {
+        memset(fArray, 0, fN*sizeof(UShort_t));
+    }
+
+    void Set(Int_t n)
+    {
+        // Set size of this array to n chars.
+        // A new array is created, the old contents copied to the new array,
+        // then the old array is deleted.
+
+        if (n < 0 || n==fN)
+            return;
+
+        UShort_t *temp = fArray;
+        if (n != 0)
+        {
+            fArray = new UShort_t[n];
+            if (n < fN)
+                memcpy(fArray, temp, n*sizeof(UShort_t));
+            else
+            {
+                memcpy(fArray, temp, fN*sizeof(UShort_t));
+                memset(&fArray[fN], 0, (n-fN)*sizeof(UShort_t));
+            }
+        }
+        else
+        {
+            fArray = NULL;
+        }
+
+        if (fN)
+            delete [] temp;
+
+        fN = n;
+    }
+
+    void Set(Int_t n, UShort_t *array)
+    {
+        // Set size of this array to n chars and set the contents.
+        if (n < 0 || array == 0)
+            return;
+
+        if (fArray && fN != n)
+        {
+            delete [] fArray;
+            fArray = 0;
+        }
+        fN = n;
+
+        if (fN == 0)
+            return;
+
+        if (!fArray)
+            fArray = new UShort_t[fN];
+
+        memcpy(fArray, array, n*sizeof(UShort_t));
+    }
+
+    UShort_t &operator[](Int_t i)
+    {
+        return fArray[i];
+    }
+
+    ClassDef(MArrayS, 1)  //Array of UShort_t
+};
+
+#endif
Index: trunk/MagicSoft/Mars/mbase/MEvtLoop.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MEvtLoop.cc	(revision 454)
+++ trunk/MagicSoft/Mars/mbase/MEvtLoop.cc	(revision 454)
@@ -0,0 +1,109 @@
+#include "MEvtLoop.h"
+
+#include <iostream.h>
+
+#include <TStopwatch.h>
+
+#include "MParList.h"
+#include "MTaskList.h"
+
+ClassImp(MEvtLoop)
+
+MEvtLoop::MEvtLoop() : fParlist(NULL)
+{
+}
+
+MEvtLoop::~MEvtLoop()
+{
+}
+
+void MEvtLoop::SetParList(MParList *p)
+{
+    fParlist = p;
+}
+
+void MEvtLoop::Eventloop(Int_t maxcnt, const char *ftasks)
+{
+    //
+    // check if the needed parameter list is set.
+    //
+    if (!fParlist)
+    {
+        cout << "MEvtLoop::Eventloop - Error: Parlist not initialized." << endl;
+        return;
+    }
+
+    //
+    //  check for the existance of the specified task list
+    //  the default name is "MTaskList"
+    //
+    MTaskList *tasks = (MTaskList*)fParlist->FindObject(ftasks);
+    if (!tasks)
+    {
+        cout << "MEvtLoop::Eventloop - Error: Cannot find tasklist '" << ftasks << "' in parameter list." << endl;
+        return;
+    }
+
+    //
+    //  execute the preprocess of all tasks
+    //  connect the different tasks with the right containers in
+    //  the parameter list
+    //
+    if (!tasks->PreProcess(fParlist))
+    {
+        cout << "Error detected while PreProcessing" << endl;
+        return;
+    }
+
+    //
+    //   loop over all events and process all tasks for
+    //   each event
+    //
+    cout << endl << "Eventloop running (";
+
+    if (maxcnt<0)
+        cout << "all";
+    else
+        cout << dec << maxcnt;
+
+    cout << " events)..." << flush;
+
+    Int_t dummy = maxcnt<0 ? 0 : maxcnt;
+
+    //
+    // start a stopwatch
+    //
+    TStopwatch clock;
+    clock.Start();
+
+    //
+    // This is the MAIN EVENTLOOP which processes the data
+    // if maxcnt<0 the number of processed events is counted
+    // else only maxcnt events are processed
+    //
+    if (maxcnt<0)
+        while (tasks->Process() && ++dummy);
+    else
+        while (tasks->Process() && dummy--);
+
+    //
+    // stop stop-watch, print results
+    //
+    clock.Stop();
+
+    cout << "Ready!" << endl << endl;
+
+    clock.Print();
+
+    cout << dec << endl
+        << "Time: " << clock.CpuTime() << "s"
+        << " for " << (maxcnt<0?dummy:maxcnt) << " Events"
+        << " --> " << (maxcnt<0?dummy:maxcnt)/clock.CpuTime() << " Events/s"
+        << endl << endl;
+
+    //
+    //  execute the post process of all tasks
+    //
+    tasks->PostProcess();
+}
+
Index: trunk/MagicSoft/Mars/mbase/MEvtLoop.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MEvtLoop.h	(revision 454)
+++ trunk/MagicSoft/Mars/mbase/MEvtLoop.h	(revision 454)
@@ -0,0 +1,26 @@
+#ifndef MEVTLOOP_H
+#define MEVTLOOP_H
+
+#ifndef MAGIC_H
+#include "MAGIC.h"
+#endif
+
+class MParList;
+
+class MEvtLoop
+{
+private:
+    MParList  *fParlist;
+
+public:
+    MEvtLoop();
+    virtual ~MEvtLoop();
+
+    void SetParList(MParList *p);
+
+    void Eventloop(Int_t maxcnt=-1, const char *tlist="MTaskList");
+
+    ClassDef(MEvtLoop, 1)
+};
+
+#endif
Index: trunk/MagicSoft/Mars/mbase/MInputStreamID.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MInputStreamID.cc	(revision 454)
+++ trunk/MagicSoft/Mars/mbase/MInputStreamID.cc	(revision 454)
@@ -0,0 +1,18 @@
+#include "MInputStreamID.h"
+
+ClassImp(MInputStreamID);
+
+// ---------------------------------------------------------------------
+
+MInputStreamID::MInputStreamID(const char *name, const char *title)
+{
+    //
+    // (default) constructor
+    //
+    *fName = name ? name : ClassName();
+    *fTitle = title;
+
+    fStreamId = new char[4];
+    strcpy(fStreamId, "All");
+}
+
Index: trunk/MagicSoft/Mars/mbase/MInputStreamID.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MInputStreamID.h	(revision 454)
+++ trunk/MagicSoft/Mars/mbase/MInputStreamID.h	(revision 454)
@@ -0,0 +1,42 @@
+#ifndef MINPUTSTREAMID_H
+#define MINPUTSTREAMID_H
+///////////////////////////////////////////////////////////////////////
+//                                                                   //
+// MInpuStreamID                                                     //
+//                                                                   //
+// This is the storage container for general (CaOs, Raw, ...) Event  //
+// Info like the type of the 'actual' event                          //
+//                                                                   //
+///////////////////////////////////////////////////////////////////////
+
+#ifndef MPARCONTAINER_H
+#include "MParContainer.h"
+#endif
+
+// -----------------------------------------------------------------------
+
+class MInputStreamID : public MParContainer
+{
+private:
+    char *fStreamId;		//! which type of task should be processed?
+
+public:
+    MInputStreamID(const char *name=NULL, const char *title=NULL);
+
+    const char *GetStreamId()
+    {
+	return (const char *)fStreamId;
+    }
+    void SetStreamId(const char *t)
+    {
+        delete fStreamId;
+        fStreamId = new char[strlen(t)+1];
+        strcpy(fStreamId, t);
+    }
+
+    ClassDef(MInputStreamID, 1)	// Process control container for the task list
+};
+
+// ---------------------------------------------------------------------
+
+#endif
Index: trunk/MagicSoft/Mars/mbase/MLoopEvt.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MLoopEvt.cc	(revision 454)
+++ trunk/MagicSoft/Mars/mbase/MLoopEvt.cc	(revision 454)
@@ -0,0 +1,118 @@
+#include "MLoopEvt.h"
+
+#include <iostream.h>
+
+#include <TStopwatch.h>
+
+#include "MParList.h"
+#include "MTaskList.h"
+
+ClassImp(MLoopEvt)
+
+MLoopEvt::MLoopEvt() : fTasks(NULL), fParlist(NULL)
+{
+}
+
+MLoopEvt::~MLoopEvt()
+{
+}
+
+void MLoopEvt::SetTaskList(MTaskList *t)
+{
+    fTasks = t;
+}
+
+void MLoopEvt::SetParList(MParList *p)
+{
+    fParlist = p;
+
+    //
+    // check if the task list is already known
+    //
+    if (fTasks)
+    {
+        cout << "MLoopEvt::SetParList - Warning: Task List already set, using this one" << endl;
+        return;
+    }
+
+    //
+    // get the task list from the parameter list
+    //
+    fTasks = (MTaskList*)fParlist->FindObject("MTaskList");
+
+    if (!fTasks)
+        cout << "MLoopEvt::SetParList - Warning: MTaskList not found." << endl;
+}
+
+void MLoopEvt::Eventloop(Int_t maxcnt)
+{
+    //
+    // check if the parameter list is known
+    //
+    if (!fParlist)
+    {
+        cout << "MLoopEvt::Eventloop - Error: ParList not set." << endl;
+        return;
+    }
+
+    //
+    // check if the task list could be retrieved from the parameter list
+    //
+    if (!fTasks)
+    {
+        cout << "MLoopEvt::Eventloop - Error: TaskList not set." << endl;
+        return;
+    }
+
+    //
+    //  execute the preprocess of all tasks
+    //  connect the different tasks with the right containers in
+    //  the parameter list
+
+    if (!fTasks->PreProcess(fParlist))
+    {
+        cout << "Error detected while PreProcessing" << endl;
+        return;
+    }
+
+    //
+    //   loop over all events and process all tasks for
+    //   each event
+    //
+    cout << endl << "Eventloop running (";
+
+    if (maxcnt<0)
+        cout << "all";
+    else
+        cout << dec << maxcnt;
+
+    cout << " events)..." << flush;
+
+    Int_t dummy = maxcnt<0 ? 0 : maxcnt;
+
+    TStopwatch clock;
+    clock.Start();
+
+    if (maxcnt<0)
+        while (fTasks->Process() && ++dummy);
+    else
+        while (fTasks->Process() && dummy--);
+
+    clock.Stop();
+
+    cout << "Ready!" << endl << endl;
+
+    clock.Print();
+
+    cout << dec << endl
+        << "Time: " << clock.CpuTime() << "s"
+        << " for " << (maxcnt<0?dummy:maxcnt) << " Events"
+        << " --> " << (maxcnt<0?dummy:maxcnt)/clock.CpuTime() << " Events/s"
+        << endl << endl;
+
+    //
+    //  execute the post process of all tasks
+    //
+    fTasks->PostProcess();
+}
+
Index: trunk/MagicSoft/Mars/mbase/MLoopEvt.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MLoopEvt.h	(revision 454)
+++ trunk/MagicSoft/Mars/mbase/MLoopEvt.h	(revision 454)
@@ -0,0 +1,29 @@
+#ifndef MLOOP_H
+#define MLOOP_H
+
+#ifndef MAGIC_H
+#include "MAGIC.h"
+#endif
+
+class MTaskList;
+class MParList;
+
+class MLoopEvt
+{
+private:
+    MTaskList *fTasks;
+    MParList  *fParlist;
+
+public:
+    MLoopEvt();
+    ~MLoopEvt();
+
+    void SetTaskList(MTaskList *t);
+    void SetParList(MParList *p);
+
+    void Eventloop(Int_t maxcnt=-1);
+
+    ClassDef(MLoopEvt, 1)
+};
+
+#endif
Index: trunk/MagicSoft/Mars/mbase/MParContainer.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MParContainer.cc	(revision 454)
+++ trunk/MagicSoft/Mars/mbase/MParContainer.cc	(revision 454)
@@ -0,0 +1,138 @@
+//////////////////////////////////////////////////////////////////////////
+//                                                                      //
+// TNamed                                                               //
+//                                                                      //
+// The TNamed class is the base class for all named ROOT classes        //
+// A TNamed contains the essential elements (name, title)               //
+// to identify a derived object in containers, directories and files.   //
+// Most member functions defined in this base class are in general      //
+// overridden by the derived classes.                                   //
+//                                                                      //
+//////////////////////////////////////////////////////////////////////////
+#include "MParContainer.h"
+
+#include <iostream.h>    // cout
+
+#include "TClass.h"      // IsA
+#include "TROOT.h"       // TROOT::Identlevel
+#include "TVirtualPad.h" // gPad
+
+ClassImp(MParContainer)
+
+//______________________________________________________________________________
+MParContainer::MParContainer(const MParContainer &named)
+{
+   // TNamed copy ctor.
+
+   *fName = *(named.fName);
+   *fTitle = *(named.fTitle);
+}
+
+//______________________________________________________________________________
+MParContainer& MParContainer::operator=(const MParContainer& rhs)
+{
+   // TNamed assignment operator.
+
+   if (this != &rhs) {
+      TObject::operator=(rhs);
+      *fName  = *(rhs.fName);
+      *fTitle = *(rhs.fTitle);
+   }
+   return *this;
+}
+
+//______________________________________________________________________________
+Int_t MParContainer::Compare(TObject *obj)
+{
+   // Compare two TNamed objects. Returns 0 when equal, -1 when this is
+   // smaller and +1 when bigger (like strcmp).
+
+   if (this == obj) return 0;
+   return fName->CompareTo(obj->GetName());
+}
+
+//______________________________________________________________________________
+void MParContainer::Copy(TObject &obj)
+{
+   // Copy this to obj.
+
+   TObject::Copy(obj);
+   *(((MParContainer&)obj).fName)  = *fName;
+   *(((MParContainer&)obj).fTitle) = *fTitle;
+}
+
+//______________________________________________________________________________
+void MParContainer::FillBuffer(char *&buffer)
+{
+   // Encode TNamed into output buffer.
+
+   fName->FillBuffer(buffer);
+   fTitle->FillBuffer(buffer);
+}
+
+//______________________________________________________________________________
+void MParContainer::ls(Option_t *)
+{
+   // List TNamed name and title.
+
+   TROOT::IndentLevel();
+   cout <<"OBJ: " << IsA()->GetName() << "\t" << GetName() << "\t" << GetTitle() << " : "
+        << Int_t(TestBit(kCanDelete)) << endl;
+}
+
+//______________________________________________________________________________
+void MParContainer::Print(Option_t *)
+{
+   // Print TNamed name and title.
+
+   cout <<"OBJ: " << IsA()->GetName() << "\t" << GetName() << "\t" << GetTitle() << endl;
+}
+
+//______________________________________________________________________________
+void MParContainer::SetName(const char *name)
+{
+   // Change (i.e. set) the name of the TNamed.
+   // WARNING !!
+   // If the object is a member of a THashTable, THashList container
+   // The HashTable must be Rehashed after SetName
+   // For example the list of objects in the current directory is a THashList
+
+   *fName = name;
+   if (gPad && TestBit(kMustCleanup)) gPad->Modified();
+}
+
+//______________________________________________________________________________
+void MParContainer::SetObject(const char *name, const char *title)
+{
+   // Change (i.e. set) all the TNamed parameters (name and title).
+   // See also WARNING in SetName
+
+   *fName  = name;
+   *fTitle = title;
+   if (gPad && TestBit(kMustCleanup)) gPad->Modified();
+}
+
+//______________________________________________________________________________
+void MParContainer::SetTitle(const char *title)
+{
+   // Change (i.e. set) the title of the TNamed.
+
+   *fTitle = title;
+   if (gPad && TestBit(kMustCleanup)) gPad->Modified();
+}
+
+//______________________________________________________________________________
+Int_t MParContainer::Sizeof() const
+{
+   // Return size of the TNamed part of the TObject.
+
+   Int_t nbytes = fName->Sizeof() + fTitle->Sizeof();
+   return nbytes;
+}
+
+
+
+
+
+
+
Index: trunk/MagicSoft/Mars/mbase/MParContainer.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MParContainer.h	(revision 454)
+++ trunk/MagicSoft/Mars/mbase/MParContainer.h	(revision 454)
@@ -0,0 +1,58 @@
+#ifndef MPARCONTAINER_H
+#define MPARCONTAINER_H
+
+//////////////////////////////////////////////////////////////////////////
+//                                                                      //
+// TNamed                                                               //
+//                                                                      //
+// The basis for a named object (name, title).                          //
+//                                                                      //
+//////////////////////////////////////////////////////////////////////////
+
+#ifndef ROOT_TObject
+#include <TObject.h>
+#endif
+#ifndef ROOT_TString
+#include <TString.h>
+#endif
+
+class MParContainer : public TObject
+{
+ private:
+    void Init(const char *name, const char *title)
+	{
+	    fName = new TString;
+	    (*fName) = name;
+	    fTitle = new TString;
+	    (*fTitle) = title;
+	}
+ protected:
+    TString   *fName;            //! object identifier
+    TString   *fTitle;           //! object title
+    
+ public:
+    MParContainer(const char *name="", const char *title="") { Init(name, title); }
+     MParContainer(const TString &name, const TString &title)  { Init(name, title); }
+     MParContainer(const MParContainer &named);
+     MParContainer& operator=(const MParContainer& rhs);
+     virtual ~MParContainer() { delete fName; delete fTitle; }
+     virtual Int_t    Compare(TObject *obj);
+     virtual void     Copy(TObject &named);
+     virtual void     FillBuffer(char *&buffer);
+     virtual const char  *GetName() const {return fName->Data();}
+     virtual const char  *GetTitle() const {return fTitle->Data();}
+     virtual ULong_t  Hash() { return fName->Hash(); }
+     virtual Bool_t   IsSortable() const { return kTRUE; }
+     virtual void     SetName(const char *name); // *MENU*
+     virtual void     SetObject(const char *name, const char *title);
+     virtual void     SetTitle(const char *title=""); // *MENU*
+     virtual void     ls(Option_t *option="");
+     virtual void     Print(Option_t *option="");
+     virtual Int_t    Sizeof() const;
+     
+     ClassDef(MParContainer, 1)  //The basis for Parameter Containers
+};
+
+#endif
+
+
Index: trunk/MagicSoft/Mars/mbase/MParList.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MParList.cc	(revision 454)
+++ trunk/MagicSoft/Mars/mbase/MParList.cc	(revision 454)
@@ -0,0 +1,100 @@
+///////////////////////////////////////////////////////////////////////
+//
+// MParList
+//
+// This class contains a list of different Parameter and Data
+// Containers. 
+//
+// You can add every parameter Container (Named object) to the
+// instance and access it from somewhere else via its Name.
+//
+///////////////////////////////////////////////////////////////////////
+
+#include "MParList.h"
+
+#include <TNamed.h>
+
+#include "MParContainer.h"
+
+ClassImp(MParList)
+
+MParList::MParList() : fNext(NULL)
+{
+  //
+  //  default constructor 
+  //  creates an empty list 
+  //
+
+}
+
+MParList::MParList(MParList &ts)
+{
+  //
+  // copy constructor 
+  //
+
+  fContainer.AddAll(&ts.fContainer);
+}
+
+
+Bool_t MParList::AddToList(MParContainer *obj, MParContainer *where)
+{
+  // 
+  //  Add an Container to the list.
+  // 
+  //  If 'where' is given, the object will be added after this.
+  //
+  
+  //
+  //  check if the object (you want to add) exists
+  //
+  if (!obj) return kTRUE;
+
+  cout << "Adding " << obj->GetName() << " to " << GetName() << "... " << flush;
+  //
+  //  check if it is in the list yet
+  //
+  if (fContainer.FindObject(obj))
+  {
+      cout << "WARNING: MParList::add: Container already added" << endl;
+      return kTRUE;
+  }
+
+  //
+  //  check if you want to add the new parameter container somewhere 
+  //  special (in that case you specify "where") 
+  //  
+  if (where)
+  {
+      if (!fContainer.FindObject(where))
+      {
+          cout << "ERROR: MParList::add: Cannot find parameter container after which the new one should be added!" << endl;
+          return kFALSE;
+      }
+  }
+
+  fContainer.Add(obj);
+  cout << "Done." << endl;
+
+  return kTRUE;
+}
+
+TObject *MParList::FindObject(const char *name) const
+{
+    //
+    //  Find an object in the list.
+    //  'name' is the name of the object you are searching for.
+    //
+    return (TObject*)fContainer.FindObject(name);
+}
+
+
+void MParList::Print(Option_t *t)
+{
+    //
+    //   print some information about the current status of MParList
+    //
+    cout << "ParList: " << this->GetName() << " <" << this->GetTitle() << ">" << endl;
+    cout << endl;
+}
+
Index: trunk/MagicSoft/Mars/mbase/MParList.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MParList.h	(revision 454)
+++ trunk/MagicSoft/Mars/mbase/MParList.h	(revision 454)
@@ -0,0 +1,51 @@
+#ifndef MPARLIST_H
+#define MPARLIST_H
+
+#ifndef MAGIC_H
+#include "MAGIC.h"
+#endif
+
+#include <iostream.h>
+
+#ifndef ROOT_TOrdCollection
+#include "TOrdCollection.h"
+#endif
+
+class MParContainer;
+
+class MParList : public TObject
+{
+private:
+    TIter *fNext;               //!
+    TOrdCollection fContainer;	// Collection of Parameter and Data Containers
+
+public:
+    MParList();
+    MParList(MParList &ts);
+
+    ~MParList()
+    {
+        if (fNext)
+            delete fNext;
+    }
+
+    Bool_t AddToList(MParContainer *obj, MParContainer *where = NULL);
+
+    TObject *FindObject(const char *name) const;
+
+    void Reset()
+    {
+        fNext = new TIter(&fContainer);
+    }
+
+    MParContainer *Next()
+    {
+        return (MParContainer*)(*fNext)();
+    }
+
+    void Print(Option_t *t = NULL);
+
+    ClassDef(MParList, 1)	// list of Parameter Containers
+};
+
+#endif
Index: trunk/MagicSoft/Mars/mbase/MReadTree.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MReadTree.cc	(revision 454)
+++ trunk/MagicSoft/Mars/mbase/MReadTree.cc	(revision 454)
@@ -0,0 +1,212 @@
+////////////////////////////////////////////////////////////////////////
+//
+//  MRawFile
+//
+//  This tasks reads the raw binary file like specified in the TDAS???
+//  and writes the data in the corresponding containers which are
+//  either retrieved from the parameter list or created and added.
+//
+////////////////////////////////////////////////////////////////////////
+
+#include "MReadTree.h"
+
+#include <iostream.h>
+#include <fstream.h>
+
+#include <TFile.h>
+#include <TTree.h>
+#include <TObjArray.h>
+
+#include "MTime.h"
+#include "MParList.h"
+
+ClassImp(MReadTree)
+
+MReadTree::MReadTree(const char *fname, const char *tname,
+                     const char *name, const char *title)
+{
+    *fName  = name  ? name  : "MReadTree";
+    *fTitle = title ? title : "Task to loop over all events in one single tree";
+
+    //
+    // open the input stream
+    //
+    fFileName = fname;
+    fTreeName = tname;
+}
+
+Bool_t MReadTree::PreProcess (MParList *pList)
+{
+    //
+    // open file
+    //
+    fFile = new TFile(fFileName, "READ");
+
+    if (!fFile->IsOpen())
+    {
+        cout << "MReadTree::PreProcess: ERROR: Cannot open file '";
+        cout << fFileName << "'" << endl;
+        return kFALSE;
+    }
+
+    fTree = (TTree*)fFile->Get(fTreeName);
+
+    if (!fTree)
+    {
+        cout << "MReadTree::PreProcess: ERROR: Cannot open tree '";
+        cout << fTreeName << "'" << endl;
+        return kFALSE;
+    }
+
+    fNumEntries = (UInt_t)fTree->GetEntries();
+    fNumEntry   = 0;
+
+    cout << "File: '" << fFileName << "'  Tree: '" << fTreeName;
+    cout << "' with " << fNumEntries << " Entries opened." << endl;
+
+    //
+    // Get all branches of this tree and
+    // create the Iterator to loop over all branches
+    //
+    TIter Next(fTree->GetListOfBranches());
+    TBranch *branch=NULL;
+    
+    //
+    // loop over all tasks for processing
+    //
+    while ( (branch=(TBranch*)Next()) )
+    {
+        //
+        // Get Name of Branch
+        //
+        const char *name = branch->GetName();
+
+        //
+        // check if object is existing in the list
+        //
+        MParContainer *pcont = (MParContainer*)pList->FindObject(name);
+
+        if (!pcont)
+        {
+            //
+            // if object is not existing in the list try to create one
+            //
+            cout << "MReadTree::PreProcess - WARNING: '" << name << "' not found... creating." << endl;
+
+            //
+            // try to get class from root environment
+            //
+            TClass *cls = gROOT->GetClass(name);
+
+            if (!cls)
+            {
+                //
+                // if class is not existing in the root environment
+                // we cannot proceed reading this branch
+                //
+                cout << "MReadTree::PreProcess - Warning: Class '" << name << "' not existing in dictionary. Branch skipped." << endl;
+                continue;
+            }
+
+            //
+            // create the container and add it to the list
+            //
+            pcont = (MParContainer*)cls->New();
+            cout << pcont << endl;
+            pList->AddToList(pcont);
+        }
+
+        //
+        // here pcont is a pointer the to container in which the data from
+        // the actual branch should be stored - enable branch.
+        //
+        branch->SetAddress(&pcont);
+    }
+
+    return kTRUE;
+}
+
+Bool_t MReadTree::Process()
+{
+    //
+    // check for end of file
+    //
+    if (fNumEntry==fNumEntries)
+        return kFALSE;
+
+    //
+    // get entry
+    //
+    fTree->GetEntry(fNumEntry/*++*/);
+    return kTRUE;
+}
+
+Bool_t MReadTree::PostProcess()
+{
+    //
+    // Close File
+    //
+    fFile->Close();
+
+    return kTRUE;
+}
+
+Bool_t MReadTree::DecEventNum(UInt_t dec)
+{
+    //
+    // Decrease the number of the event which is read by Process() next
+    // by one or more
+    //
+
+    //!
+    //! this function makes Process() read the event one (or more) before
+    //! the actual position (event) in the tree
+    //!
+    if (fNumEntry < dec/*+1*/)
+    {
+        cout << "MReadTree::SetPrevEvent: WARNING: " << fNumEntry/*-1*/ << "-" << dec << " out of Range." << endl;
+        return kFALSE;
+    }
+
+    fNumEntry -= dec/*+1*/;
+    return kTRUE;
+}
+
+Bool_t MReadTree::IncEventNum(UInt_t inc)
+{
+    //
+    // Increase the number of the event which is read by Process() next
+    // by one or more
+    //
+
+    //!
+    //! this function makes Process() read the next (or more) after
+    //! the actual position (event) in the tree
+    //! (Be careful: IncEventNum() or IncEventNum(1) does not chenge anything
+    //!  in the standard behaviour of the task)
+    //!
+    if (fNumEntry+inc/*-1*/ >= fNumEntries)
+    {
+        cout << "MReadTree::SkipEvents: WARNING: " << fNumEntry/*-1*/ << "+" << inc << " out of Range." << endl;
+        return kFALSE;
+    }
+
+    fNumEntry += inc/*-1*/;
+    return kTRUE;
+}
+
+Bool_t MReadTree::SetEventNum(UInt_t nr)
+{
+    //
+    // this function makes Process() read event number nr next
+    //
+    if (nr>=fNumEntries)
+    {
+        cout << "MReadTree::SetEventNum: WARNING: " << nr << " out of Range." << endl;
+        return kFALSE;
+    }
+
+    fNumEntry = nr;
+    return kTRUE;
+}
+
Index: trunk/MagicSoft/Mars/mbase/MReadTree.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MReadTree.h	(revision 454)
+++ trunk/MagicSoft/Mars/mbase/MReadTree.h	(revision 454)
@@ -0,0 +1,39 @@
+#ifndef MREADTREE_H
+#define MREADTREE_H
+
+#ifndef MTASK_H
+#include "MTask.h"
+#endif
+
+class TFile;
+class TTree;
+
+class MReadTree : public MTask
+{
+private:
+    TFile  *fFile;       // Pointer to file
+    TTree  *fTree;       // Pointer to tree
+
+    UInt_t  fNumEntry;   // Namber of actual entry
+    UInt_t  fNumEntries; // Number of Events in Tree
+
+    TString fFileName;   // Name of File
+    TString fTreeName;   // Name of Tree
+
+public:
+    MReadTree(const char *filename, const char *treename, const char *name=NULL, const char *title=NULL);
+
+    Bool_t PreProcess(MParList *pList);
+    Bool_t Process();
+    Bool_t PostProcess();
+
+    Bool_t DecEventNum(UInt_t dec=1); // decrease number of event (position in tree)
+    Bool_t IncEventNum(UInt_t inc=1); // increase number of event (position in tree)
+    Bool_t SetEventNum(UInt_t nr);    // set number of event (position in tree)
+    UInt_t GetEventNum() {return fNumEntry;}
+    UInt_t GetEntries() {return fNumEntries;}
+
+    ClassDef(MReadTree, 1)	// Reads one tree
+};
+
+#endif
Index: trunk/MagicSoft/Mars/mbase/MTask.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MTask.cc	(revision 454)
+++ trunk/MagicSoft/Mars/mbase/MTask.cc	(revision 454)
@@ -0,0 +1,78 @@
+///////////////////////////////////////////////////////////////////////
+//
+//   MTask
+// 
+//   Base class for all tasks which can perfomed in a tasklist
+//   For each event processed in the eventloop all the different
+//   tasks in the tasklist will be processed.
+//  
+//   So all tasks must inherit from this baseclass. 
+//
+//   The data member fEventType is used to indicate the type of events
+//   that are process by this task. There are the following different
+//   event types: 
+//
+//   This is the type of task for which this task should be processed
+//   taskType-bits: 7 6 5 4 3 2 1 0
+//   0 DATA_EVT
+//   1 CALIBRATION_EVT
+//   ? etc. etc. 
+//
+//   Inside this abstract class, there are three fundamental function: 
+//
+//   - PreProcess() :  executed before the eventloop starts. Here you 
+//                     can initiate different things, open files, etc. 
+//
+//   - Process()    :  executed for each event in the eventloop. Do in 
+//                     one task after the other (as the occur in the 
+//                     tasklist) the action of one task. 
+//  
+//   - PostProcess():  executed after the eventloop. Here you can close 
+//                     output files, start display of the run parameter, 
+//                     etc. 
+//  
+//  
+///////////////////////////////////////////////////////////////////////
+
+#include "MTask.h"
+
+#include <string.h>
+#include <iostream.h>
+
+ClassImp(MTask)
+
+Bool_t MTask::PreProcess( MParList *pList )
+{
+  //
+  // This is processed before the eventloop starts
+  // 
+  // It is the job of the PreProcess to connect the tasks
+  // with the right container in the parameter list. 
+  //
+  // the virtual implementation returns kTRUE
+  //
+  return kTRUE; 
+}
+
+
+Bool_t MTask::Process()
+{
+  //
+  // This is processed for every event in the eventloop 
+  //
+  // the virtual implementation returns kTRUE
+  //
+  return kTRUE;
+}
+
+Bool_t MTask::PostProcess()
+{
+  //
+  // This is processed after the eventloop starts
+  //
+  // the virtual implementation returns kTRUE
+  //
+  return kTRUE;
+}
+
+
Index: trunk/MagicSoft/Mars/mbase/MTask.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MTask.h	(revision 454)
+++ trunk/MagicSoft/Mars/mbase/MTask.h	(revision 454)
@@ -0,0 +1,25 @@
+#ifndef MTASK_H
+#define MTASK_H
+
+#ifndef MINPUTSTREAMID_H
+#include "MInputStreamID.h"
+#endif
+
+class MParList;
+
+class MTask : public MInputStreamID
+{
+
+public:
+    ~MTask()
+    {
+    }
+
+    virtual Bool_t PreProcess(MParList *pList);
+    virtual Bool_t Process();
+    virtual Bool_t PostProcess();
+
+    ClassDef(MTask, 1)		// Base (abstract) class for a task
+};
+
+#endif
Index: trunk/MagicSoft/Mars/mbase/MTaskList.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MTaskList.cc	(revision 454)
+++ trunk/MagicSoft/Mars/mbase/MTaskList.cc	(revision 454)
@@ -0,0 +1,202 @@
+///////////////////////////////////////////////////////////////////////
+//                                                                   //
+// MTaskList                                                          //
+//                                                                   //
+// Collection of tasks which should be processed in the eventloop    //
+//                                                                   //
+///////////////////////////////////////////////////////////////////////
+
+#include "MTaskList.h"
+
+#include <iostream.h>
+
+#include "MParList.h"
+#include "MInputStreamID.h"
+
+ClassImp(MTaskList)
+
+MTaskList::MTaskList(const char *title)
+{
+    //
+    // the name for the task list must be the same for all task lists
+    // because the task list (at the moment) is identified by exactly
+    // this name in the parameter list (by MEvtLoop::SetParList)
+    //
+    *fName  = "MTaskList";
+    *fTitle = title ? title : "List for Tasks";
+
+    //
+    //  default constructor: create empty task list
+    //
+}
+
+MTaskList::MTaskList(MTaskList &ts)
+{
+  //
+  //   CopyConstructor 
+  //   creates a new TaskList and put the contents of an existing
+  //   TaskList in the new TaskList. 
+  //
+  fTasks.AddAll(&ts.fTasks);
+}
+
+Bool_t MTaskList::AddToList(MTask *task, const char *type, MTask *where)
+{
+    // schedule task for execution, whether as first task, or after
+    // 'where'. 'tType' is the event type which should be processed
+    if (!task)
+        return kTRUE;
+
+    const char *name = task->GetName();
+
+    // FIXME: We agreed to put the task into list in an ordered way.
+
+    if (fTasks.FindObject(task))
+    {
+        cout << "WARNING: MTaskList::AddToList: Task already existing." << endl;
+        return kTRUE;
+    }
+
+    if (fTasks.FindObject(name))
+    {
+        cout << "WARNING: MTaskList::AddToList: '" << name << "' exists in List already." << endl;
+        return kTRUE;
+    }
+
+    if (where)
+    {
+        if (!fTasks.FindObject(where))
+        {
+            printf("ERROR: MTaskList::AddToList: Cannot find task after which the new task should be scheduled!\n");
+            return kFALSE;
+        }
+    }
+
+    cout << "Adding " << name << " to " << GetName() << " for " << type << "... " << flush;
+
+    task->SetStreamId(type);
+    fTasks.Add(task);
+
+    cout << "Done." << endl;
+
+    return kTRUE;
+}
+
+
+Bool_t MTaskList::PreProcess( MParList *pList )
+{ 
+    //
+    // do pre processing (before eventloop) of all tasks in the task-list
+    //
+    cout << "Preprocessing... " << flush;
+
+    //
+    //  create the Iterator over the tasklist
+    //
+    TIter next(&fTasks);
+
+    MTask *task=NULL;
+
+    //
+    // loop over all tasks for preproccesing
+    //
+    while ( (task=(MTask*)next()) )
+    {
+        cout << task->GetName() << "... " << flush;
+
+        if (!task->PreProcess( pList ))
+            return kFALSE;
+    }
+
+    cout << endl;
+
+    return kTRUE;
+}
+
+Bool_t MTaskList::Process()
+{
+  //
+  // do the event execution of all tasks in the task-list
+  //
+  
+  //
+  //  create the Iterator for the TaskList
+  //
+  TIter next(&fTasks);
+  MTask *task=NULL;
+    
+  //
+  // loop over all tasks for processing 
+  //
+  while ( (task=(MTask*)next()) )
+  {
+      if (!strcmp(GetStreamId(), task->GetStreamId()) ||
+          !strcmp(task->GetStreamId(), "All"))
+      {
+          switch (task->Process())
+          {
+          case kTRUE:
+              //
+              // everything was OK: go on
+              //
+              continue;
+
+          case kFALSE:
+              //
+              // an error occured: stop eventloop
+              //
+              return kFALSE;
+
+          case kCONTINUE:
+              //
+              // something occured: skip the rest of the tasks for this event
+              //
+              break;
+          }
+      }
+  }
+  return kTRUE;
+}
+
+Bool_t MTaskList::PostProcess()
+{
+  //
+  // do post processing (before eventloop) of all tasks in the task-list
+  //
+
+    cout << "Postprocessing... " << flush;
+
+  //
+  //  create the Iterator for the TaskList
+  //
+  TIter next(&fTasks);
+  
+  MTask *task=NULL;
+
+  //
+  //  loop over all tasks for postprocessing
+  //  
+  while ( (task=(MTask*)next()) )
+  {
+      cout << task->GetName() << "... " << flush;
+
+      if (!task->PostProcess())
+          return kFALSE;
+  }
+
+  cout << endl;
+
+  return kTRUE;
+}
+
+
+
+void MTaskList::Print(Option_t *t)
+{
+  cout << "TaskList: " << this->GetName() << " <" <<  this->GetTitle() << ">" << endl;
+  
+  fTasks.Print();
+
+  cout << endl;
+}
+
Index: trunk/MagicSoft/Mars/mbase/MTaskList.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MTaskList.h	(revision 454)
+++ trunk/MagicSoft/Mars/mbase/MTaskList.h	(revision 454)
@@ -0,0 +1,36 @@
+#ifndef MTASKLIST_H
+#define MTASKLIST_H
+
+#ifndef ROOT_TOrdCollection
+#include <TOrdCollection.h>
+#endif
+#ifndef MTASK_H
+#include "MTask.h"
+#endif
+
+class MParList;
+class MInputStreamID;
+
+class MTaskList : public MTask
+{
+private:
+    TOrdCollection fTasks;	// Container for the ordered list of different tasks
+
+
+public:
+    MTaskList(const char *title=NULL);
+
+    MTaskList(MTaskList &ts);
+
+    Bool_t AddToList(MTask *task, const char *tType="All", MTask *where = NULL);
+
+    Bool_t PreProcess(MParList *pList);
+    Bool_t Process();
+    Bool_t PostProcess();
+
+    void Print(Option_t *t = NULL);
+
+    ClassDef(MTaskList, 1)	// Collection of tasks to be performed in the eventloop
+};
+
+#endif
Index: trunk/MagicSoft/Mars/mbase/MTime.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MTime.cc	(revision 454)
+++ trunk/MagicSoft/Mars/mbase/MTime.cc	(revision 454)
@@ -0,0 +1,45 @@
+///////////////////////////////////////////////////////////////////////
+//
+//   MTime
+//
+///////////////////////////////////////////////////////////////////////
+
+#include "MTime.h"
+
+#include <iostream.h>
+#include <iomanip.h>
+
+ClassImp(MTime)
+
+void MTime::Print(Option_t *)
+{ 
+    cout << "MTime Information:  " << hex
+        << " 0x" <<setfill('0') << setw(2) << fTimeStamp[0]
+        << " 0x" <<setfill('0') << setw(2) << fTimeStamp[1] << endl << endl;
+} 
+    /*
+inline Bool_t operator<(MTime &t1, MTime &t2)
+{
+    return (t1.GetTimeHi()<=t2.GetTimeHi()) && (t1.GetTimeLo()<t2.GetTimeLo());
+}
+
+inline Bool_t operator>(MTime &t1, MTime &t2)
+{
+    return (t1.GetTimeHi()>=t2.GetTimeHi()) && (t1.GetTimeLo()>t2.GetTimeLo());
+}
+
+inline Bool_t operator<=(MTime &t1, MTime &t2)
+{
+    return (t1.GetTimeHi()<=t2.GetTimeHi()) && (t1.GetTimeLo()<=t2.GetTimeLo());
+}
+
+inline Bool_t operator>=(MTime &t1, MTime &t2)
+{
+    return (t1.GetTimeHi()>=t2.GetTimeHi()) && (t1.GetTimeLo()>=t2.GetTimeLo());
+}
+
+inline Bool_t operator==(MTime &t1, MTime &t2)
+{
+    return (t1.GetTimeLo()==t2.GetTimeLo()) && (t1.GetTimeHi()==t2.GetTimeHi());
+}
+*/
Index: trunk/MagicSoft/Mars/mbase/MTime.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MTime.h	(revision 454)
+++ trunk/MagicSoft/Mars/mbase/MTime.h	(revision 454)
@@ -0,0 +1,105 @@
+#ifndef MTIME_H
+#define MTIME_H
+
+#ifndef MPARCONTAINER_H
+#include "MParContainer.h"
+#endif
+
+class MTime : public MParContainer
+{
+private:
+    UInt_t fTimeStamp[2]; // type of raw event which should be processed by this task
+    UInt_t fDuration;     // time of validity
+
+public:
+
+    MTime(const char *name=NULL, const char *title=NULL)
+    {
+        *fName = name ? name : ClassName();
+        *fTitle = title;
+
+        SetTime(0,0);
+    }
+
+    MTime(UInt_t t1, UInt_t t0) 
+    {
+        SetTime(t1, t0);
+    }
+
+    MTime(MTime& t)
+    {
+        fTimeStamp[0] = t.fTimeStamp[0];
+        fTimeStamp[1] = t.fTimeStamp[1];
+        fDuration = t.fDuration;
+    }
+
+    void operator=(MTime &t)
+    {
+        fTimeStamp[0] = t.fTimeStamp[0];
+        fTimeStamp[1] = t.fTimeStamp[1];
+        fDuration = t.fDuration;
+    }
+
+    ~MTime() {}
+
+    void Print(Option_t *t=NULL);
+
+    void SetTime(UInt_t t1, UInt_t t0)
+    {
+	fTimeStamp[0] = t1;
+	fTimeStamp[1] = t0;
+    }
+
+    void SetDuration(UInt_t t)
+    {
+	fDuration = t;
+    }
+
+    MTime *GetTime()
+    {
+        return this;
+    }
+
+    UInt_t GetTimeLo()
+    {
+	return fTimeStamp[0];
+    }
+    UInt_t GetTimeHi()
+    {
+	return fTimeStamp[1];
+    }
+
+    UInt_t GetDuration()
+    {
+	return fDuration;
+    }
+
+    ClassDef(MTime, 1)	// A general Mars time stamp
+};
+
+inline Bool_t operator<(MTime &t1, MTime &t2)
+{
+    return (t1.GetTimeHi()<=t2.GetTimeHi()) && (t1.GetTimeLo()<t2.GetTimeLo());
+}
+
+inline Bool_t operator>(MTime &t1, MTime &t2)
+{
+    return (t1.GetTimeHi()>=t2.GetTimeHi()) && (t1.GetTimeLo()>t2.GetTimeLo());
+}
+
+inline Bool_t operator<=(MTime &t1, MTime &t2)
+{
+    return (t1.GetTimeHi()<=t2.GetTimeHi()) && (t1.GetTimeLo()<=t2.GetTimeLo());
+}
+
+inline Bool_t operator>=(MTime &t1, MTime &t2)
+{
+    return (t1.GetTimeHi()>=t2.GetTimeHi()) && (t1.GetTimeLo()>=t2.GetTimeLo());
+}
+
+inline Bool_t operator==(MTime &t1, MTime &t2)
+{
+    return (t1.GetTimeLo()==t2.GetTimeLo()) && (t1.GetTimeHi()==t2.GetTimeHi());
+}
+
+#endif
Index: trunk/MagicSoft/Mars/mbase/Makefile
===================================================================
--- trunk/MagicSoft/Mars/mbase/Makefile	(revision 454)
+++ trunk/MagicSoft/Mars/mbase/Makefile	(revision 454)
@@ -0,0 +1,132 @@
+##################################################################
+#
+#   makefile
+# 
+#   for the MARS software
+#
+##################################################################
+# @maintitle
+
+# @code
+
+#
+#  please change all system depend values in the 
+#  config.mk.${OSTYPE} file 
+#
+#
+INCLUDEMK = ../Makefile.conf.$(OSTYPE)
+include $(INCLUDEMK)
+
+# @endcode 
+
+# @code 
+
+LIB   = libmbase.a
+
+#
+#  connect the include files defined in the config.mk file
+#
+INCLUDES = -I./
+
+#
+#  ----->>>   root libraries
+#
+
+ROOTLIBS   =  `root-config --libs`
+ROOTGLIBS  =  `root-config --glibs`
+ROOTCFLAGS =  `root-config --cflags`
+
+#
+#  compiler flags
+#
+
+CXXFLAGS  = $(ROOTCFLAGS) $(INCLUDES) $(OPTIM) $(DEBUG)
+CFLAGS    = $(CXXFLAGS)
+FFLAGS    = $(CXXFLAGS)
+
+#------------------------------------------------------------------------------
+
+#.SILENT:
+
+.SUFFIXES: .c .cc .cxx .h .hxx .o 
+
+
+SRCFILES = MTask.cc \
+	   MTaskList.cc \
+           MParContainer.cc \
+	   MParList.cc \
+	   MInputStreamID.cc \
+           MEvtLoop.cc \
+           MReadTree.cc \
+	   MArray.cc \
+	   MArrayB.cc \
+	   MArrayS.cc \
+           MTime.cc
+
+SRCS    = $(SRCFILES)
+HEADERS = $(SRCFILES:.cc=.h)
+OBJS    = $(SRCFILES:.cc=.o) 
+
+############################################################
+
+all: $(LIB)
+
+depend:
+	@makedepend $(SRCS) $(INCLUDES) $(ROOTCFLAGS) \
+        -fMakefile.depend 2> kk.kk ; cat kk.kk
+
+$(LIB): $(OBJS) BaseCint.o
+	@echo " - Building Library $(LIB) ... "
+	@$(AR) $(LIB) *.o
+
+BaseCint.cc: $(HEADERS) 
+	@echo 
+	@echo " - Generating dictionary BaseCint.cc ..."
+
+	@$(ROOTSYS)/bin/rootcint -f BaseCint.cc \
+	-c $(INCLUDES) $(HEADERS) BaseIncl.h BaseLinkDef.h
+
+.cxx.o:	
+	@echo " - Compiling " $<
+	$(CXX) $(CXXFLAGS) -c $< -o $@
+
+.cc.o:	
+	@echo " - Compiling " $<
+	$(CXX) $(CXXFLAGS) -c $< -o $@
+
+.c.o:	
+	@echo " - Compiling " $<
+	$(CC) $(CFLAGS) -c $< -o $@
+
+#
+# The cleaning facility
+#
+
+rmlib:	
+	@echo "Removing libraries..."
+	@rm -f lib*.a
+
+rmcint:	
+	@echo "Removing cint-stuff..."
+	@rm -f BaseCint.*
+
+rmobjs:	
+	@echo "Removing object files..."
+	@rm -f *.o
+
+rmbin:	
+	@echo "Removing binary files..."
+	@rm -f core
+
+
+clean:	rmlib rmcint rmobjs rmbin
+
+mrproper:	clean
+	@echo "Removing *~ kk.kk html/..."
+	@rm -f *~ kk.kk
+
+cflags: 
+	@echo $(INCLUDES) $(CXXFLAGS)
+
+# @endcode
+
Index: trunk/MagicSoft/Mars/merpp.cc
===================================================================
--- trunk/MagicSoft/Mars/merpp.cc	(revision 454)
+++ trunk/MagicSoft/Mars/merpp.cc	(revision 454)
@@ -0,0 +1,130 @@
+#include <iostream.h>
+
+#include <TSystem.h>
+
+#include "MParList.h"
+#include "MTaskList.h"
+#include "MEvtLoop.h"
+
+#include "MRawFileRead.h"
+#include "MRawFileWrite.h"
+
+#include "MRawRunHeader.h"
+#include "MRawEvtHeader.h"
+#include "MRawEvtData.h"
+#include "MRawCrateArray.h"
+#include "MTime.h"
+#include "MInputStreamID.h"
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// This is an easy implementation of the Merging process (as compilable prog)
+//
+// at the moment it reads a binary file ("rawtest.bin") which was written
+// in the DAQ raw format.
+//
+// The data are stored in root container objects (classes derived from
+// TObject like MRawRunHeader)
+//
+// This containers are written to a root file ("rawtest.root")
+//
+/////////////////////////////////////////////////////////////////////////////
+
+int main(const int argc, const char **argv)
+{
+    cout << "==================================================" << endl ;
+    cout << "                   MERPP v0.1" << endl;
+    cout << "      MARS Merging and Preprocessing Program" << endl ;
+    cout << "            Compiled on <" << __DATE__ << ">" << endl ;
+    cout << "==================================================" << endl ;
+    cout << endl;
+
+    //
+    // check for the right usage of the program
+    //
+    if (argc!=3)
+    {
+        cout << "Sorry the usage is:" << endl;
+        cout << "   merpp inputfile outputfile" << endl << endl;
+        return -1;
+    }
+
+    //
+    //     initialize ROOT  (this is obligatory here)
+    //
+    TROOT simple("Merpp","Mars - Merging and Preprocessing Program");
+
+    //
+    // check whether the given files are OK.
+    //
+    if (gSystem->AccessPathName(argv[1], kFileExists))
+    {
+        cout << "Sorry, the file '" << argv[1] << "' doesn't exist." << endl;
+        return -1;
+    }
+
+    if (!gSystem->AccessPathName(argv[2], kFileExists))
+        cout << "Warning: The file '" << argv[2] << "' exists." << endl;
+    else
+        if (!gSystem->AccessPathName(argv[2], kWritePermission))
+        {
+            cout << "Sorry, you don't have write permission for '" << argv[2] << "'." << endl;
+            return -1;
+        }
+
+    //
+    // create a (empty) list of parameters which can be used by the tasks
+    // and an (empty) list of tasks which should be executed
+    //
+    MParList *plist  = new MParList;
+
+    MTaskList *tasks = new MTaskList;
+    plist->AddToList(tasks);
+
+    MRawRunHeader *runheader = new MRawRunHeader;
+    plist->AddToList(runheader);
+
+    MRawEvtHeader *evtheader = new MRawEvtHeader;
+    plist->AddToList(evtheader);
+
+    MRawEvtData *evtdata = new MRawEvtData;
+    plist->AddToList(evtdata);
+
+    MRawCrateArray *cratearray = new MRawCrateArray;
+    plist->AddToList(cratearray);
+
+    MTime *evttime = new MTime("MRawEvtTime");
+    plist->AddToList(evttime);
+
+    //
+    // create the tasks which should be executed and add them to the list
+    // in the case you don't need parameter containers, all of them can
+    // be created by MRawFileRead::PreProcess
+    //
+    MRawFileRead  *reader = new MRawFileRead(argv[1]);
+    MRawFileWrite *writer = new MRawFileWrite(argv[2], "RECREATE");
+    tasks->AddToList(reader);
+    tasks->AddToList(writer);
+
+    //
+    // create the looping object and thell it about the parameters to use
+    // and the tasks to execute
+    //
+
+    MEvtLoop magic;
+
+    magic.SetParList(plist);
+
+    //
+    // Start the eventloop which reads the raw file (MRawFileRead) and
+    // write all the information into a root file (MRawFileWrite)
+    //
+    // between reading and writing we can do, transformations, checks, etc.
+    // (I'm think of a task like MRawDataCheck)
+    //
+    magic.Eventloop();
+
+    return 0;
+}
+
+
Index: trunk/MagicSoft/Mars/mraw/MRawCrateArray.cc
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawCrateArray.cc	(revision 454)
+++ trunk/MagicSoft/Mars/mraw/MRawCrateArray.cc	(revision 454)
@@ -0,0 +1,75 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// MRawCrateArray
+//
+// This class exists to make it possible to read in the crate data
+// TClones Array. In principal we can directly write the TClonesArray
+// to the root file, but when we read in again the root file we cannot
+// put the TClonesArray into our parameter list, becaus it isn't derived
+// from TNamed. This class is derived from TNamed and can be put in the list
+//
+/////////////////////////////////////////////////////////////////////////////
+#include "MRawCrateArray.h"
+
+#include <iostream.h>
+
+#include <TClonesArray.h>
+
+ClassImp(MRawCrateArray)
+
+MRawCrateArray::MRawCrateArray(const char *name, const char *title)
+{
+    *fName  = name  ? name  : "MRawCrateArray";
+    *fTitle = title ? title : "Array of MRawCrateData Information";
+
+    //
+    // craete an (almost) empty array. The size is easily determined
+    // while filling the array
+    //
+    fArray = new TClonesArray("MRawCrateData", 0);
+}
+
+MRawCrateArray::~MRawCrateArray()
+{
+    delete fArray;
+}
+
+void MRawCrateArray::Clear(Option_t *opt)
+{
+    //
+    // clear the entries in the TClonesArray
+    //
+    fArray->Clear();
+}
+
+void MRawCrateArray::Print(Option_t *opt)
+{
+    cout << "MRawCrateArray::Print()" << endl;
+}
+
+MRawCrateData *MRawCrateArray::GetEntry(Int_t i)
+{
+    //
+    // Return a pointer the i-th entry in the array
+    //
+    return (MRawCrateData*)fArray->AddrAt(i);
+}
+
+MRawCrateData* &MRawCrateArray::operator[](Int_t i)
+{
+    //
+    // Return the i-th entry in the array
+    //
+    return (MRawCrateData*&)(*fArray)[i];
+}
+
+TClonesArray **MRawCrateArray::GetArray()
+{
+    //
+    // return a pointer to the pointer of the array
+    // (actually not used. You may need it if you want to write
+    //  the TClonesArray directly)
+    //
+    return &fArray;
+}
+
Index: trunk/MagicSoft/Mars/mraw/MRawCrateArray.h
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawCrateArray.h	(revision 454)
+++ trunk/MagicSoft/Mars/mraw/MRawCrateArray.h	(revision 454)
@@ -0,0 +1,37 @@
+#ifndef MRAWCRATEARRAY_H
+#define MRAWCRATEARRAY_H
+///////////////////////////////////////////////////////////////////////
+//                                                                   //
+// MRunHeader                                                        //
+//                                                                   //
+///////////////////////////////////////////////////////////////////////
+
+#ifndef MPARCONTAINER_H
+#include "MParContainer.h"
+#endif
+
+class TClonesArray;
+class MRawCrateData;
+
+class MRawCrateArray : public MParContainer
+{
+private:
+    TClonesArray *fArray;
+
+public:
+    MRawCrateArray(const char *name=NULL, const char *title=NULL);
+    ~MRawCrateArray();
+
+    void Clear(Option_t *opt=NULL);
+    void Print(Option_t *opt=NULL);
+
+    MRawCrateData *GetEntry(Int_t i);
+
+    MRawCrateData* &operator[](Int_t i);
+
+    TClonesArray **GetArray();
+
+    ClassDef(MRawCrateArray, 1)	// Mapping container for the MRawCrateData TClonesArray
+};
+
+#endif
Index: trunk/MagicSoft/Mars/mraw/MRawCrateData.cc
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawCrateData.cc	(revision 454)
+++ trunk/MagicSoft/Mars/mraw/MRawCrateData.cc	(revision 454)
@@ -0,0 +1,33 @@
+#include "MRawCrateData.h"
+
+#include <iostream.h>
+#include <iomanip.h>
+
+#include <fstream.h>
+
+ClassImp(MRawCrateData)
+
+MRawCrateData::MRawCrateData() : fDAQCrateNumber(0), fFADCEvtNumber(0), fFADCClockTick(0)
+{
+}
+
+void MRawCrateData::ReadEvt(ifstream& fin)
+{
+    //
+    // read the information from a binary input stream about the CRATE DATA,
+    // like specified in a TDAS note
+    //
+    fin.read((Byte_t*)&fDAQCrateNumber, 2);
+    fin.read((Byte_t*)&fFADCEvtNumber,  4);
+    fin.read((Byte_t*)&fFADCClockTick,  4);
+}
+
+void MRawCrateData::Print(Option_t *t)
+{
+    //
+    // print all stored information to screen
+    //
+    cout << "Crate Number " << fDAQCrateNumber << ":  ";
+    cout << "FADCEventNr=" << fFADCEvtNumber << "  ";
+    cout << "FADCClockTick=" << fFADCClockTick << " (20MHz)" << endl;
+}
Index: trunk/MagicSoft/Mars/mraw/MRawCrateData.h
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawCrateData.h	(revision 454)
+++ trunk/MagicSoft/Mars/mraw/MRawCrateData.h	(revision 454)
@@ -0,0 +1,49 @@
+#ifndef MRAWCRATEDATA_H
+#define MRAWCRATEDATA_H
+
+#ifndef MAGIC_H
+#include "MAGIC.h"
+#endif
+#ifndef ROOT_TObject
+#include <TObject.h>
+#endif
+
+class ifstream;
+
+class MRawCrateData : public TObject
+{
+private:
+    UShort_t fDAQCrateNumber;  // Crate number the information corresponds to
+    UInt_t   fFADCEvtNumber;   // event number from the fadc
+    UInt_t   fFADCClockTick;   // clock tick from the fadc (20MHz)
+
+public:
+    MRawCrateData();
+
+    ~MRawCrateData()
+    {
+    }
+
+    UChar_t GetDAQCrateNumber() const
+    {
+        return fDAQCrateNumber;
+    }
+
+    UInt_t  GetFADCEvtNumber() const
+    {
+        return fFADCEvtNumber;
+    }
+
+    UInt_t  GetFADCClockTick() const
+    {
+        return fFADCClockTick;
+    }
+
+    void Print(Option_t *t=NULL);
+
+    void ReadEvt(ifstream& fin);
+
+    ClassDef(MRawCrateData, 1) //Container to store the Raw CRATE DATA
+};
+
+#endif
Index: trunk/MagicSoft/Mars/mraw/MRawEvtData.cc
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawEvtData.cc	(revision 454)
+++ trunk/MagicSoft/Mars/mraw/MRawEvtData.cc	(revision 454)
@@ -0,0 +1,325 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+//  MRawEvtData
+//
+//  Storage container to store the raw FADC values.
+//
+//  MArrayS fHiGainPixId
+//  ---------------------
+//  Array of Pixel Numbers for their high voltage channel in the order the
+//  FADC values are stored in fHiGainFadcSamples
+//
+//  MArrayB fHiGainFadcSaples
+//  -------------------------
+//  FADC samples (hi gain) of all pixels
+//
+//  MArrayS fLoGainPixId
+//  --------------------
+//  see fHiGainPixId
+//
+//  MArrayB fLoGainFadcSamples
+//  --------------------------
+//  see fHiGainFadcSaples
+//
+/////////////////////////////////////////////////////////////////////////////
+
+#include "MRawEvtData.h"
+
+#include <iostream.h>
+#include <iomanip.h>
+
+#include <fstream.h>
+
+#include <TH1.h>
+#include <TGraph.h>
+#include <TArrayC.h>
+
+#include "MArrayS.h"
+#include "MArrayB.h"
+#include "MRawRunHeader.h"
+
+ClassImp(MRawEvtData)
+
+MRawEvtData::MRawEvtData(const char *name, const char *title)
+{
+    *fName  = name  ? name  : "MRawEvtData";
+    *fTitle = title ? title : "Raw Event Data Information";
+
+    InitArrays();
+}
+
+MRawEvtData::~MRawEvtData()
+{
+    DeleteArrays();
+}
+
+void MRawEvtData::Clear(Option_t *)
+{
+    //
+    // reset all arrays
+    //
+
+    /*
+     FIXME:
+     Is Reset (set all entries to zero) what you want to do
+     or Set(0) (delete the array)
+     */
+    fHiGainPixId->Reset();
+    fLoGainPixId->Reset();
+    fHiGainFadcSamples->Reset();
+    fLoGainFadcSamples->Reset();
+}
+
+Byte_t MRawEvtData::GetNumHiGainSamples() const
+{
+    return fHiGainPixId->GetSize() ? fHiGainFadcSamples->GetSize()/fHiGainPixId->GetSize() : 0;
+}
+
+Byte_t MRawEvtData::GetNumLoGainSamples() const
+{
+    return fLoGainPixId->GetSize() ? fLoGainFadcSamples->GetSize()/fLoGainPixId->GetSize() : 0;
+}
+
+Byte_t MRawEvtData::GetNumPixels() const
+{
+    return fHiGainPixId->GetSize();
+}
+
+
+void MRawEvtData::Print(Option_t *)
+{
+    //
+    // print fadc inforation to screen
+    //
+    const Byte_t nHiSamp = GetNumHiGainSamples();
+    const Byte_t nLoSamp = GetNumLoGainSamples();
+
+    const UShort_t nHiPix = fHiGainPixId->GetSize();;
+    const UShort_t nLoPix = fLoGainPixId->GetSize();;
+
+    cout << dec;
+    cout << "HiGain: " << nHiPix << " Pixels with " << (Int_t)nHiSamp << " Samples" << endl;
+    cout << "LoGain: " << nLoPix << " Pixels with " << (Int_t)nLoSamp << " Samples" << endl;
+
+    Int_t l=0;
+    for (int i=0; i<nHiPix; i++)
+    {
+        cout << " " << setfill(' ') << setw(3) << i << ": " << hex << flush;
+
+        cout << setfill('0');
+
+        for (int j=0; j<nHiSamp; j++)
+            cout << setw(2)
+                << ((UShort_t)(*fHiGainFadcSamples)[j+i*nHiSamp]&0xff) << flush;
+
+        if (l<nLoPix && (*fLoGainPixId)[l]==(*fHiGainPixId)[i])
+        {
+            for (int j=0; j<nLoSamp; j++)
+                cout << setw(2)
+                    <<((UShort_t)(*fLoGainFadcSamples)[j+i*nLoSamp]&0xff) << flush;
+            l++;
+        }
+        cout << dec << endl;
+    }
+    cout << endl;
+}
+
+void MRawEvtData::Draw(Option_t *opt)
+{
+    TString str(opt);
+
+    UInt_t num = 0;
+
+    if (str.BeginsWith("GRAPH", TString::kIgnoreCase))
+    {
+        if (str.Length()>5)
+            sscanf(&str[5], "%d", &num);
+
+        if (num>=GetNumPixels())
+            num= GetNumPixels();
+
+        cout << "Drawing Graph of Pixel " << num << endl;
+
+        const Int_t n = GetNumHiGainSamples();
+
+        Float_t *x = new Float_t[n];
+        Float_t *y = new Float_t[n];
+
+        for (int i=0; i<n; i++)
+        {
+            x[i] = i;
+            y[i] = (*fHiGainFadcSamples)[i + num*GetNumHiGainSamples()];
+        }
+
+        TGraph *graph = new TGraph(n, x, y);
+        graph->Draw("AC*");
+
+        return;
+    }
+
+    if (str.BeginsWith("HIST", TString::kIgnoreCase))
+    {
+        cout << "Length: " << str.Length() << endl;
+
+        if (str.Length()>4)
+            sscanf(&str[4], "%d", &num);
+
+        if (num>=GetNumPixels())
+            num= GetNumPixels();
+
+        cout << "Drawing Histogram of Pixel " << num << endl;
+
+        const Int_t n = GetNumHiGainSamples();
+
+        char *name = new char[16];
+
+        sprintf(name, "Pixel No.%d", (*fHiGainPixId)[num]);
+
+        TH1F *hist = new TH1F(name, "Hi Gain Samples FADC", n, 0, n);
+
+        for (int i=0; i<n; i++)
+            hist->Fill(0.5+i, (*fHiGainFadcSamples)[i + num*GetNumHiGainSamples()]);
+
+        hist->Draw();
+
+        return;
+    }
+
+    cout << "MRawEvtData::Draw: Warning: You must specify either 'GRAPH' or 'HIST'" << endl;
+}
+
+void MRawEvtData::DeletePixels()
+{
+    //
+    // Deletes all arrays describing the pixel Id and Samples in pixels
+    //
+    DeleteArrays();
+    InitArrays();
+}
+
+void MRawEvtData::DeleteArrays()
+{
+    delete fHiGainPixId;
+    delete fLoGainPixId;
+    delete fHiGainFadcSamples;
+    delete fLoGainFadcSamples;
+}
+
+void MRawEvtData::InitArrays()
+{
+    fHiGainPixId       = new MArrayS(0); //UShort_t[0];
+    fLoGainPixId       = new MArrayS(0); //new UShort_t[0];
+    fHiGainFadcSamples = new MArrayB(0); //new Byte_t[0];
+    fLoGainFadcSamples = new MArrayB(0); //new Byte_t[0];
+}
+
+void MRawEvtData::AddPixel(UShort_t nOfPixel, TArrayC *data, Bool_t lflag)
+{
+    //
+    //  This is to fill the data of one pixel to the MRawEvtHeader Class.
+    //  The parameters are the pixelnumber and the FADC_SLICES values of ADCs
+    //  Add to lo gains if lflag = 1
+    //
+
+    MArrayS *arrpix = lflag ? fLoGainPixId       : fHiGainPixId;
+    MArrayB *arrsam = lflag ? fLoGainFadcSamples : fHiGainFadcSamples;
+
+    //
+    // check whether we got the right number of new samples
+    // if there are no samples already stored: this is the new number of samples
+    //
+    const Byte_t ns    = data->GetSize();
+    const Byte_t nSamp = lflag ? GetNumLoGainSamples() : GetNumHiGainSamples();
+    if (nSamp && ns!=nSamp)
+    {
+        cout << "RawEvtData::FillPixel: Error, number of samples in ";
+        cout << "TArrayC doesn't match actual number" << endl;
+        return;
+    }
+
+    //
+    // enhance pixel array by one
+    //
+    arrpix->Set(arrpix->GetSize()+1);
+
+    //
+    // add the number of the new pixel to the array as last entry
+    //
+    arrpix->AddAt(nOfPixel, arrpix->GetSize()-1);
+
+    //
+    // enhance the array by the number of new samples
+    //
+    arrsam->Set(arrsam->GetSize()+ns);
+
+    //
+    // add the new slices as last entries to array
+    //
+    arrsam->AddAt((Byte_t*)data->GetArray(), arrsam->GetSize()-ns, ns);
+}
+
+/*
+void MRawEvtData::AddPixelLo(UShort_t nOfPixel, TArrayC *data, int nr, int pos)
+{
+    //
+    // add the number of the new pixel to the array as last entry
+    //
+    fLoGainPixId->AddAt(nOfPixel, nr);
+
+    //
+    // add the new slices as last entries to array
+    //
+    fLoGainFadcSamples->AddAt((Byte_t*)data->GetArray(), pos,  data->GetSize());
+}
+
+void MRawEvtData::AddPixelHi(UShort_t nOfPixel, TArrayC *data, int nr, int pos)
+{
+    // check whether we got the right number of new samples
+    // if there are no samples already stored: this is the new number of samples
+    //
+    const Byte_t ns = data->GetSize();
+
+    //
+    // add the number of the new pixel to the array as last entry
+    //
+    fHiGainPixId->AddAt(nOfPixel, nr);
+
+    //
+    // add the new slices as last entries to array
+    //
+    fHiGainFadcSamples->AddAt((Byte_t*)data->GetArray(), arrsam->GetSize()-ns, ns);
+}
+*/
+void MRawEvtData::ReadEvt(ifstream &fin)
+{
+    //
+    // Fills members with information from a magic binary file.
+    //   WARNING: you have to use Init() before you can do this
+    //
+    const UShort_t nlo = fRunHeader->GetNumSamplesLoGain();
+    const UShort_t nhi = fRunHeader->GetNumSamplesHiGain();
+
+    TArrayC lo(nlo);
+    TArrayC hi(nhi);
+
+    const UShort_t npic = fRunHeader->GetNumPixInCrate();
+
+    for (int i=0; i<npic; i++)
+    {
+        //
+        // get the spiral pixel number from the run header
+        //
+        const UShort_t npix = fRunHeader->GetPixAssignment(i);
+
+        // FIXME: Not implemented in the raw files yet
+        //if (IsLoGainOn(i, j))
+        //{
+        fin.read((Byte_t*)lo.GetArray(), nlo);
+        AddPixel(npix, &lo, kTRUE);
+        //}
+
+        fin.read((Byte_t*)hi.GetArray(), nhi);
+        AddPixel(npix, &hi, kFALSE);
+    }
+}
+
Index: trunk/MagicSoft/Mars/mraw/MRawEvtData.h
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawEvtData.h	(revision 454)
+++ trunk/MagicSoft/Mars/mraw/MRawEvtData.h	(revision 454)
@@ -0,0 +1,61 @@
+#ifndef MRAWEVTDATA_H
+#define MRAWEVTDATA_H
+
+#ifndef MPARCONTAINER_H
+#include "MParContainer.h"
+#endif
+
+class ifstream;
+class MRawRunHeader;
+
+class TArrayC;
+class MArrayS;
+class MArrayB;
+
+class MRawEvtData : public MParContainer
+{
+    friend class MRawEvtPixelIter;
+private:
+    MRawRunHeader *fRunHeader;    //! provides information about numbers
+
+    // FIXME: COMMENT ABOUT ORDERING
+
+    MArrayS *fHiGainPixId;        // list of pixel IDs of hi gain channel
+    MArrayB *fHiGainFadcSamples;  // list of hi gain samples of all pixels (ordering: see fHiGainPixId)
+
+    MArrayS *fLoGainPixId;        // list of pixel IDs of lo gain channel
+    MArrayB *fLoGainFadcSamples;  // list of lo gain samples of all pixels (ordering: see fLoGainPixId)
+
+    void InitArrays();
+    void DeleteArrays();
+
+public:
+    MRawEvtData(const char *name=NULL, const char *title=NULL);
+    ~MRawEvtData();
+
+    void Init(MRawRunHeader *rh)
+    {
+        //
+        // you have to set this before you can read information
+        // from a magic binary file
+        //
+        fRunHeader = rh;
+    }
+
+    void Clear(Option_t * = NULL);
+    void Print(Option_t * = NULL);
+    void Draw (Option_t * = NULL);
+
+    void DeletePixels();
+    void AddPixel(UShort_t nOfPixel, TArrayC *data, Bool_t lflag=kFALSE);
+
+    Byte_t GetNumHiGainSamples() const;
+    Byte_t GetNumLoGainSamples() const;
+    Byte_t GetNumPixels() const;
+
+    void ReadEvt(ifstream &fin);
+
+    ClassDef(MRawEvtData, 1) //Container to store the raw Event Data
+};
+
+#endif
Index: trunk/MagicSoft/Mars/mraw/MRawEvtHeader.cc
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawEvtHeader.cc	(revision 454)
+++ trunk/MagicSoft/Mars/mraw/MRawEvtHeader.cc	(revision 454)
@@ -0,0 +1,230 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// MRawEvtHeader 
+//    
+// One Event is a sample of FADC measurements of different Pixels 
+// (Photomultipliers) from the Camera of MAGIC. So all data (FADC) of the 
+// interesting pixels are the modules of an event. To describe pixels the 
+// class MRawPixel is used and the class MRawCrate to describe Crates.
+// To define a single events some other data members are needed 
+// (Time of the events, tirgger pattern of event..)
+// 
+// To describe one event on the level of FADC values the Class MRawEvtHeader is
+// created. It has the following data members: 
+//
+// UInt_t    fDAQEvtNumber
+// -----------------------
+// This it the number of the Event in one 
+// data run. The first event in this run get
+// the number zero. The next one is one bigger.
+//
+// Assuming that one run takes 1 hour and a
+// triggerrate of 1kHz the number must be able
+// to reach 3.6e6 Events. To reach this number
+// you need at least 22 bits. This is the reason
+// why we use an integer (of root type UInt_t)
+// with a range to 4.2e9. 
+//
+// MTime   fRawEvtTime
+// -------------------
+// Time of the event. 
+// The start point of the time determination can be
+// the millenium. From that start point the time is
+// measured in 200ns-count. One day for example
+// contains 432.e9 counts. An array of two unsigned Int is able to 
+// contain 1.8e19 200ns-counts. This corresponds to 41.e6
+// days. This should be more than the livetime of MAGIC.
+// Private member of MTime.h
+//
+// UInt_t  fNumTrigLvl1
+// --------------------
+//
+// Number of first level trigger
+// This member counts the number of First Level Trigger
+// between the last and this event. May be that due to 
+// dead time of the DAQ this number is different from 1.
+// If the DAQ is fast enough, this value should be 1. 
+// This may be usefull in GammaRayBursts and if we 
+// apply a data reduction in the DAQ-chain, which selects
+// only good events. 
+//
+// UInt_t  fNumTrigLvl2
+// ------------------ -
+//
+// Number of second level trigger
+// This member counts the number of Second Level Trigger
+// between the last and this event. 
+//
+// UInt_t  fTrigPattern[2]
+// -----------------------
+// Trigger Pattern used for this event
+// Each event triggers for a particular configuration and each  
+// configuration shoul have an ID (which is not fixed yet).
+//
+// UShort_t fAllLowGainOn
+// ----------------------
+// Type of Trigger. 
+// This is a Byte (8 bit) to indicated if any of the pixels 
+// have a non-negligible low gain (1) or not (0) 
+//
+/////////////////////////////////////////////////////////////////////////////
+#include "MRawEvtHeader.h"
+
+#include <iostream.h>
+#include <iomanip.h>
+#include <fstream.h>
+
+#include "MTime.h"
+#include "MArrayB.h"
+#include "MRawRunHeader.h"
+
+ClassImp(MRawEvtHeader)
+
+MRawEvtHeader::MRawEvtHeader(const char *name, const char *title) 
+{
+    *fName  = name  ? name  : "MRawEvtHeader";
+    *fTitle = title ? title : "Raw Event Header Information";
+
+    //
+    //   set all member to zero, init the pointer to ClonesArray,
+    //
+
+    fPixLoGainOn = new MArrayB;
+
+    Clear();
+}
+
+
+MRawEvtHeader::~MRawEvtHeader()
+{
+}
+
+void MRawEvtHeader::Init(MRawRunHeader *rh, MTime *t)
+{
+    //
+    // you have to init the conatainer before you can read from
+    // a raw binary file
+    //
+
+    //
+    // this is the number of entries in the array like specification
+    //
+    UInt_t fN = (rh->GetNumCrates() * rh->GetNumPixInCrate() + 7) / 8;
+
+    //
+    // initialize the array
+    //
+    fPixLoGainOn->Set(fN);
+
+    //
+    // this is the conatiner where we have to store the time of the event we
+    // read from the input stream
+    //
+    fTime = t;
+}
+
+void MRawEvtHeader::Clear(Option_t *)
+{
+    //
+    //   Implementation of the Clear function
+    //
+    //   Resets all members to zero, clear the list of Pixels
+    //
+    fDAQEvtNumber   = 0;
+    fNumTrigLvl1    = 0;
+    fNumTrigLvl2    = 0;
+    fTrigPattern[0] = 0;
+    fTrigPattern[1] = 0;
+    fTrigType       = 0;
+    fNumLoGainOn    = 0;
+}
+
+void MRawEvtHeader::Print(Option_t *o)
+{
+    //
+    //  This member function prints all Data of one Event on screen.
+    //
+    cout << "DAQEvtNr: " << dec << fDAQEvtNumber << "  (";
+    cout << "Trigger: ";
+    cout << "NumLvl1=" << fNumTrigLvl1 << " ";
+    cout << "NumLvl2=" << fNumTrigLvl2 << " ";
+    cout << "Pattern=" << hex << setfill('0');
+    cout << setw(2) << fTrigPattern[0];
+    cout << setw(2) << fTrigPattern[1] << " " << dec;
+
+    cout << "Type=";
+    switch (fTrigType)
+    {
+    case 0:
+        cout << "Trigger";
+        break;
+    case 1:
+        cout << "Pedestal";
+        break;
+    case 2:
+        cout << "Calibration";
+        break;
+    }
+    cout << ")" << endl;
+    cout << "Number of Lo Gains On: " << fNumLoGainOn << endl;
+
+    for (int i=0; i<fPixLoGainOn->GetSize(); i++)
+    {
+        for (int j=0; j<8; j++)
+        {
+            const UInt_t on = (*fPixLoGainOn)[i]&(1<<j) ? 1 : 0;
+            cout << on;
+        }
+    }
+
+    cout << endl;
+
+    cout << endl;
+
+}
+
+void MRawEvtHeader::FillHeader(UInt_t uiN, Float_t ulTP)
+{
+    //
+    // used to set the header information (eg. from MC)
+    //
+    fDAQEvtNumber = uiN;
+    fTrigPattern[0] = (UInt_t) (ulTP/4294967296.0) ;
+    fTrigPattern[1] = (UInt_t) (ulTP-fTrigPattern[0]*4294967296.0);
+}
+
+int MRawEvtHeader::ReadEvt(ifstream &fin)
+{
+    //
+    // read the EVENT HEADER information from the input stream
+    // return FALSE if there is now header anymore, else TRUE
+    //
+    fin.read((Byte_t*)&fDAQEvtNumber, 4);
+
+    UInt_t fAbsTime[2];
+    fin.read((Byte_t*)fAbsTime,       8);
+
+    //
+    // store the time of the event in the corresponding container
+    //
+    fTime->SetTime(fAbsTime[0], fAbsTime[1]);
+
+    Byte_t dummy[4];
+
+    fin.read((Byte_t*)&fNumTrigLvl1,  4);
+    fin.read((Byte_t*)&fNumTrigLvl2,  4);
+    fin.read((Byte_t*)fTrigPattern,   8);
+    fin.read((Byte_t*)&fTrigType,     2);
+    fin.read((Byte_t*)dummy,          2); // was fAllLoGainOn
+    fin.read((Byte_t*)fPixLoGainOn->GetArray(), fPixLoGainOn->GetSize());
+
+    fNumLoGainOn = 0;
+    for (int i=0; i<fPixLoGainOn->GetSize(); i++)
+        for (int j=0; j<8; j++)
+            if ((*fPixLoGainOn)[i] & (1<<j))
+                fNumLoGainOn++;
+
+    fin.read((Byte_t*)&dummy, 4);
+
+    return !fin.eof();
+}
Index: trunk/MagicSoft/Mars/mraw/MRawEvtHeader.h
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawEvtHeader.h	(revision 454)
+++ trunk/MagicSoft/Mars/mraw/MRawEvtHeader.h	(revision 454)
@@ -0,0 +1,54 @@
+#ifndef MRAWEVTHEADER_H
+#define MRAWEVTHEADER_H
+
+#ifndef MPARCONTAINER_H
+#include "MParContainer.h"
+#endif
+
+class ifstream;
+class MTime;
+class MArrayB;
+class MRawRunHeader;
+
+class MRawEvtHeader : public MParContainer
+{
+private:
+    MTime   *fTime;            //! object to store the time in (ReadEvt)
+
+    UInt_t   fDAQEvtNumber;    // Number of Event
+
+    UInt_t   fNumTrigLvl1;     // Number of 1st level tiggers between 2 events
+    UInt_t   fNumTrigLvl2;     // Number of 2nd level tiggers between 2 events
+    UInt_t   fTrigPattern[2];  // Trigger configuration
+
+    UShort_t fNumLoGainOn;     // Indicating if no pixel has a neglegible
+                               // low gain signal (0), else it is the number
+                               // of pixels with lo gain on
+
+    //
+    // Informations only needed to read the raw file
+    //
+    UShort_t fTrigType;        //! Trigger Type of this event
+    MArrayB *fPixLoGainOn;     //! Array which tell you which pixels have lo gain on
+
+public:
+
+  MRawEvtHeader(const char *name=NULL, const char *title=NULL);
+  ~MRawEvtHeader();
+
+  void Init(MRawRunHeader *rh, MTime *t);
+
+  void Clear(Option_t * = NULL);
+  void Print(Option_t * = NULL);
+
+  void FillHeader(UInt_t, Float_t=0);
+
+  UShort_t GetTrigType() const { return fTrigType; }
+
+  int ReadEvt(ifstream& fin);
+
+  ClassDef(MRawEvtHeader, 1) // Parameter Conatiner for raw EVENT HEADER
+
+}; 
+
+#endif
Index: trunk/MagicSoft/Mars/mraw/MRawEvtPixelIter.cc
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawEvtPixelIter.cc	(revision 454)
+++ trunk/MagicSoft/Mars/mraw/MRawEvtPixelIter.cc	(revision 454)
@@ -0,0 +1,62 @@
+#include "MRawEvtPixelIter.h"
+
+#include "MRawEvtData.h"
+
+#include "MArrayS.h"
+#include "MArrayB.h"
+
+ClassImp(MRawEvtPixelIter)
+
+TObject *MRawEvtPixelIter::Next()
+{
+    //
+    // if we are already at the last entry there is no 'next' entry anymore
+    //
+    if (fNumHiGainEntry==fData->fHiGainPixId->GetSize()-1)
+        return NULL;
+
+    //
+    // if we are already at the last entry there is no 'next' entry anymore
+    //
+    if (fNumLoGainEntry != fData->fLoGainPixId->GetSize()-1)
+        if (*fHiGainId == *fLoGainId)
+        {
+            //
+            // if higainpixid and logainpixid of the actual pixel are
+            // identical then we have to move the pointer to the next
+            // entry in the lo gains
+            //
+            fNumLoGainEntry++;
+            fLoGainId++;
+            fLoGainPos += fData->GetNumLoGainSamples();
+        }
+
+    //
+    // here we have to move the pointer to the next entry in the hi gains
+    //
+    fNumHiGainEntry++;
+    fHiGainId++;
+    fHiGainPos += fData->GetNumHiGainSamples();
+
+    //
+    // return a pointer to the 'source' class if we succeed
+    //
+    return fData;
+}
+
+void MRawEvtPixelIter::Reset()
+{
+    //
+    // set counter to zero
+    //
+    fNumLoGainEntry = 0;
+    fNumHiGainEntry = 0;
+
+    //
+    // set pointer to first entry of arrays
+    //
+    fHiGainId   = (UShort_t*)fData->fHiGainPixId->GetArray();
+    fLoGainId   = (UShort_t*)fData->fLoGainPixId->GetArray();
+    fHiGainPos  = (Byte_t*)fData->fHiGainFadcSamples->GetArray();
+    fLoGainPos  = (Byte_t*)fData->fLoGainFadcSamples->GetArray();
+}
Index: trunk/MagicSoft/Mars/mraw/MRawEvtPixelIter.h
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawEvtPixelIter.h	(revision 454)
+++ trunk/MagicSoft/Mars/mraw/MRawEvtPixelIter.h	(revision 454)
@@ -0,0 +1,81 @@
+#ifndef MRAWEVTPIXELITER_H
+#define MRAWEVTPIXELITER_H
+
+#ifndef MAGIC_H
+#include "MAGIC.h"
+#endif
+#ifndef ROOT_TIterator
+#include <TIterator.h>
+#endif
+
+class MRawEvtData;
+
+class MRawEvtPixelIter : public TIterator
+{
+private:
+    UShort_t fNumHiGainEntry;   //! actual number of entry in fHiGainPixId
+    UShort_t fNumLoGainEntry;   //! actual number of entry in fLoGainPixId
+
+    UShort_t *fHiGainId;        //! actual entry of fHiGainPixId
+    UShort_t *fLoGainId;        //! actual entry of fLoGainPixId
+
+    Byte_t   *fHiGainPos;       //! pointer to hi-gain samples of actual pixel
+    Byte_t   *fLoGainPos;       //! pointer to lo-gain samples of actual pixel
+
+    MRawEvtData *fData;         //! pointer to object which we are iterating
+
+public:
+    MRawEvtPixelIter(MRawEvtData *dat) : fData(dat)
+    {
+        //
+        // WARNING: The Iterator now points to the FIRST entry.
+        //          This means that you have to use a do...while loop
+        //          NOT a while() loop.
+        //
+        Reset();
+    }
+
+    TObject *Next();
+
+    UShort_t GetPixelId() const
+    {
+        //
+        // return Id of actual pixel
+        //
+        return *fHiGainId;
+    }
+
+    Byte_t *GetHiGainFadcSamples() const
+    {
+        //
+        // return a pointer to the fadc samples of the hi gains
+        // WARNING: Don't forget to get the number of valid entries
+        //          (GetNumSamples) to know how many entries of the array
+        //          belong to the actual pixel
+        //
+        return fHiGainPos;
+    }
+
+    Bool_t IsLoGain() const
+    {
+        //
+        // return kTRUE  the lo gains exist for the actual pixel, else return kFALSE
+        //
+        return *fHiGainId==*fLoGainId;
+    }
+
+    Byte_t *GetLoGainFadcSamples() const
+    {
+        //
+        // return a pointer to the fadc samples of the lo gains if they exist
+        // for the actual pixel, else return zero
+        //
+        return IsLoGain() ? fLoGainPos : NULL;
+    }
+
+    void Reset();
+
+    ClassDef(MRawEvtPixelIter, 1)
+};
+
+#endif
Index: trunk/MagicSoft/Mars/mraw/MRawFileRead.cc
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawFileRead.cc	(revision 454)
+++ trunk/MagicSoft/Mars/mraw/MRawFileRead.cc	(revision 454)
@@ -0,0 +1,150 @@
+////////////////////////////////////////////////////////////////////////
+//
+//  MRawFile
+//
+//  This tasks reads the raw binary file like specified in the TDAS???
+//  and writes the data in the corresponding containers which are
+//  either retrieved from the parameter list or created and added.
+//
+////////////////////////////////////////////////////////////////////////
+
+#include "MRawFileRead.h"
+
+#include <iostream.h>
+#include <fstream.h>
+
+#include "MTime.h"
+#include "MParList.h"
+#include "MRawRunHeader.h"
+#include "MRawEvtHeader.h"
+#include "MRawEvtData.h"
+#include "MRawCrateData.h"
+#include "MRawCrateArray.h"
+
+ClassImp(MRawFileRead)
+
+MRawFileRead::MRawFileRead(const char *fname, const char *name, const char *title)
+{
+    *fName  = name  ? name  : "MRawFileRead";
+    *fTitle = title ? title : "Read task to read DAQ binary files";
+
+    //
+    // open the input stream
+    //
+    fIn = new ifstream(fname);
+
+    /*
+     FIXME: How can I test whether the construction of
+            the instance was successfull?
+    if (!fIn->is_open())
+    cout << "Error: Trying to open file '" << fname << "'" << endl;
+    */
+}
+
+Bool_t MRawFileRead::PreProcess (MParList *pList)
+{
+    //
+    // remember the pointer to the parameter list fur further usage
+    //
+    pParList = pList;
+
+    //
+    //  check if all necessary containers exist in the Parameter list.
+    //  if not create one and add them to the list
+    //
+    fRawRunHeader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
+    if (!fRawRunHeader)
+    {
+        cout << "MRawFileRead::PreProcess - WARNING: MRawRunHeader not found... creating." << endl;
+        fRawRunHeader = new MRawRunHeader;
+        pList->AddToList(fRawRunHeader);
+    }
+
+    fRawEvtHeader = (MRawEvtHeader*)pList->FindObject("MRawEvtHeader");
+    if (!fRawEvtHeader)
+    {
+        cout << "MRawFileRead::PreProcess - WARNING: MRawEvtHeader not found... creating." << endl;
+        fRawEvtHeader = new MRawEvtHeader;
+        pList->AddToList(fRawEvtHeader);
+    }
+
+    fRawEvtData = (MRawEvtData*)pList->FindObject("MRawEvtData");
+    if (!fRawEvtData)
+    {
+        cout << "MRawFileRead::PreProcess - WARNING: MRawEvtData not found... creating." << endl;
+        fRawEvtData = new MRawEvtData;
+        pList->AddToList(fRawEvtData);
+    }
+
+    fRawCrateArray = (MRawCrateArray*)pList->FindObject("MRawCrateArray");
+    if (!fRawCrateArray)
+    {
+        cout << "MRawFileRead::PreProcess - WARNING: MRawCrateArray not found... creating." << endl;
+        fRawCrateArray = new MRawCrateArray;
+        pList->AddToList(fRawCrateArray);
+    }
+
+    fRawEvtTime = (MTime*)pList->FindObject("MRawEvtTime");
+    if (!fRawEvtTime)
+    {
+        cout << "MRawFileRead::PreProcess - WARNING: MRawEvtTime not found... creating." << endl;
+        fRawEvtTime = new MTime("MRawEvtTime");
+        pList->AddToList(fRawEvtTime);
+    }
+
+    //
+    // Read RUN HEADER (see specification) from input stream
+    //
+    fRawRunHeader->ReadEvt(*fIn);
+    fRawRunHeader->Print();
+
+    //
+    // Give the run header information to the 'sub-classes'
+    //
+    fRawEvtHeader->Init(fRawRunHeader, fRawEvtTime);
+    fRawEvtData  ->Init(fRawRunHeader);
+
+    return kTRUE;
+}
+    
+Bool_t MRawFileRead::Process()
+{
+    //
+    //  Read in the next EVENT HEADER (see specification),
+    // if there is no next event anymore stop eventloop
+    //
+    if (!fRawEvtHeader->ReadEvt(*fIn))
+        return kFALSE;
+    //fRawEvtHeader->Print();
+
+    //
+    // Delete arrays which stores the pixel information (time slices)
+    //
+    fRawEvtData->DeletePixels();
+
+    //
+    // clear the TClonesArray which stores the Crate Information
+    //
+    fRawCrateArray->Clear();
+
+    //
+    //  Get number of crates from the run header
+    //
+    const UShort_t nc = fRawRunHeader->GetNumCrates();
+
+    //
+    // read the CRATE DATA (see specification) from file
+    //
+    for (int i=0; i<nc; i++)
+    {
+        fRawCrateArray->GetEntry(i)->ReadEvt(*fIn);
+        //fRawCrateArray->GetEntry(i)->Print();
+
+        fRawEvtData->ReadEvt(*fIn);
+    }
+    //fRawEvtData->Print();
+
+    return kTRUE;
+
+}
+
Index: trunk/MagicSoft/Mars/mraw/MRawFileRead.h
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawFileRead.h	(revision 454)
+++ trunk/MagicSoft/Mars/mraw/MRawFileRead.h	(revision 454)
@@ -0,0 +1,39 @@
+#ifndef MRAWFILEREAD_H
+#define MRAWFILEREAD_H
+
+#ifndef MTASK_H
+#include "MTask.h"
+#endif
+
+class ifstream;
+
+class MTime;
+class MParList;
+class MRawRunHeader;
+class MRawEvtHeader;
+class MRawEvtData;
+class MRawCrateArray;
+
+class MRawFileRead : public MTask
+{
+private:
+    MParList *pParList;
+
+    MRawRunHeader  *fRawRunHeader;
+    MRawEvtHeader  *fRawEvtHeader;
+    MRawEvtData    *fRawEvtData;
+    MRawCrateArray *fRawCrateArray;
+    MTime          *fRawEvtTime;
+
+    ifstream *fIn; //!
+
+public:
+    MRawFileRead(const char *filename, const char *name=NULL, const char *title=NULL);
+
+    Bool_t PreProcess(MParList *pList);
+    Bool_t Process();
+
+    ClassDef(MRawFileRead, 1)	// Task to read the raw data binary file
+};
+
+#endif
Index: trunk/MagicSoft/Mars/mraw/MRawFileWrite.cc
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawFileWrite.cc	(revision 454)
+++ trunk/MagicSoft/Mars/mraw/MRawFileWrite.cc	(revision 454)
@@ -0,0 +1,178 @@
+////////////////////////////////////////////////////////////////////////
+//
+//  MRawFileWrite
+//
+//  Here we write the root containers which contains the data from a
+//  root binary file to a root file. See also MRawFileRead
+//
+////////////////////////////////////////////////////////////////////////
+
+#include "MRawFileWrite.h"
+
+#include <iostream.h>
+
+#include <TFile.h>
+#include <TTree.h>
+#include <TBranch.h>
+
+#include "MParList.h"
+#include "MRawRunHeader.h"
+#include "MRawEvtHeader.h"
+#include "MRawEvtData.h"
+#include "MRawCrateArray.h"
+
+ClassImp(MRawFileWrite)
+
+MRawFileWrite::MRawFileWrite(const char *fname, Option_t *opt,
+                             const char *ftitle, Int_t comp,
+                             const char *name, const char *title)
+{
+    *fName  = name  ? name  : "MRawFileWrite";
+    *fTitle = title ? title : "Write task to write DAQ root files";
+
+    // FIXME: move file open to preproc!
+
+    //
+    // Open a rootfile
+    //
+    fOut = new TFile(fname, opt, ftitle, comp);
+
+    //
+    // test whether file is now open or not
+    //
+    if (!fOut->IsOpen())
+    {
+        cout << "MRawFileWrite::MRawFileWrite: ERROR: Cannot open file '";
+        cout << fname << "'" << endl;
+    }
+}
+
+Bool_t MRawFileWrite::PreProcess (MParList *pList)
+{
+    //
+    // remember the pointer to the parameter list fur further usage
+    //
+    pParList = pList;
+
+    //
+    //  check if MEvtHeader exists in the Parameter list already.
+    //  if not create one and add them to the list
+    //
+    fRawEvtHeader = (MRawEvtHeader*)pList->FindObject("MRawEvtHeader");
+    if (!fRawEvtHeader)
+    {
+        cout << "MRawFileWrite::PreProcess - ERROR: MRawEvtHeader not found... aborting." << endl;
+        return kFALSE;
+    }
+
+    fRawEvtData = (MRawEvtData*)pList->FindObject("MRawEvtData");
+    if (!fRawEvtData)
+    {
+        cout << "MRawFileWrite::PreProcess - ERROR: MRawEvtData not found... aborting." << endl;
+        return kFALSE;
+    }
+
+    fRawCrateArray = (MRawCrateArray*)pList->FindObject("MRawCrateArray");
+    if (!fRawCrateArray)
+    {
+        cout << "MRawFileWrite::PreProcess - ERROR: MRawCrateArray not found... aborting." << endl;
+        return kFALSE;
+    }
+
+    fRawEvtTime = (MTime*)pList->FindObject("MRawEvtTime");
+    if (!fRawEvtTime)
+    {
+        cout << "MRawFileWrite::PreProcess - WARNING: MRawEvtTime not found... aborting." << endl;
+        return kFALSE;
+    }
+
+    fRawRunHeader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
+    if (!fRawRunHeader)
+    {
+        cout << "MRawFileWrite::PreProcess - ERROR: MRawRunHeader not found... aborting." << endl;
+        return kFALSE;
+    }
+
+    //
+    // Write the run header information to the file
+    //
+    TTree   *rh = new TTree("RunHeaders", "Run headers of all runs in this file");
+    TBranch *tb = rh->Branch("MRawRunHeader", "MRawRunHeader", &fRawRunHeader, 32000, 1);
+    rh->Fill();
+    rh->Write();
+    delete tb;
+    delete rh;
+
+    //
+    // create data trees for the three types of data
+    //
+    fTData        = new TTree("Data",       "Normal Triggered Data");
+    fTPedestal    = new TTree("Pedestal",   "Pedestal Triggered Data");
+    fTCalibration = new TTree("Calibration","Calibration Triggered Data");
+
+    //
+    // create all branches which are necessary
+    //
+    fTData       ->Branch("MTime",          "MTime",          &fRawEvtTime,    32000, 1);
+    fTPedestal   ->Branch("MTime",          "MTime",          &fRawEvtTime,    32000, 1);
+    fTCalibration->Branch("MTime",          "MTime",          &fRawEvtTime,    32000, 1);
+    fTData       ->Branch("MRawEvtHeader",  "MRawEvtHeader",  &fRawEvtHeader,  32000, 1);
+    fTPedestal   ->Branch("MRawEvtHeader",  "MRawEvtHeader",  &fRawEvtHeader,  32000, 1);
+    fTCalibration->Branch("MRawEvtHeader",  "MRawEvtHeader",  &fRawEvtHeader,  32000, 1);
+    fTData       ->Branch("MRawEvtData",    "MRawEvtData",    &fRawEvtData,    32000, 1);
+    fTPedestal   ->Branch("MRawEvtData",    "MRawEvtData",    &fRawEvtData,    320000, 1);
+    fTCalibration->Branch("MRawEvtData",    "MRawEvtData",    &fRawEvtData,    320000, 1);
+    //fTree->Branch("MRawCrateArray",  fRawCrateArray->GetArray(),      32000, 1);
+    fTData       ->Branch("MRawCrateArray", "MRawCrateArray", &fRawCrateArray, 32000, 1);
+    fTPedestal   ->Branch("MRawCrateArray", "MRawCrateArray", &fRawCrateArray, 32000, 1);
+    fTCalibration->Branch("MRawCrateArray", "MRawCrateArray", &fRawCrateArray, 32000, 1);
+
+    return kTRUE;
+}
+    
+Bool_t MRawFileWrite::Process()
+{
+    //
+    // get the trigger type of the actual event
+    //
+    const UShort_t type = fRawEvtHeader->GetTrigType();
+
+    //
+    // writa data to the tree. the tree is choosen by the type of the event
+    //
+    switch (type)
+    {
+    case 0:
+        fTData->Fill();
+        break;
+    case 1:
+        fTPedestal->Fill();
+        break;
+    case 2:
+        fTCalibration->Fill();
+        break;
+    }
+
+    return kTRUE;
+}
+
+Bool_t MRawFileWrite::PostProcess()
+{
+    //
+    // empty data stream
+    //
+    fOut->Write();
+
+    //
+    // close root file
+    //
+    fOut->Close();
+
+    //
+    // delete instance
+    //
+    delete fOut;
+
+    return kTRUE;
+}
+
Index: trunk/MagicSoft/Mars/mraw/MRawFileWrite.h
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawFileWrite.h	(revision 454)
+++ trunk/MagicSoft/Mars/mraw/MRawFileWrite.h	(revision 454)
@@ -0,0 +1,49 @@
+#ifndef MRAWFILEWRITE_H
+#define MRAWFILEWRITE_H
+
+#ifndef MTASK_H
+#include "MTask.h"
+#endif
+
+class TFile;
+class TTree;
+
+class MTime;
+class MParList;
+class MRawRunHeader;
+class MRawEvtHeader;
+class MRawCrateArray;
+class MRawEvtData;
+
+class MRawFileWrite : public MTask
+{
+private:
+    MParList *pParList;             
+
+    MTime          *fRawEvtTime;    
+    MRawRunHeader  *fRawRunHeader;  
+    MRawEvtHeader  *fRawEvtHeader;  
+    MRawEvtData    *fRawEvtData;    
+    MRawCrateArray *fRawCrateArray; 
+
+    TTree *fTData;                  //!
+    TTree *fTPedestal;              //!
+    TTree *fTCalibration;           //!
+
+    TFile *fOut;                    //!
+
+public:
+    MRawFileWrite(const char *fname,
+                  Option_t *opt="UPDATE",
+                  const char *ftitle="Unnamed",
+                  Int_t comp=9,
+                  const char *name=NULL, const char *title=NULL);
+
+    Bool_t PreProcess(MParList *pList);
+    Bool_t Process();
+    Bool_t PostProcess();
+
+    ClassDef(MRawFileWrite, 1)	// Task to write the raw data containers to a root file
+};
+
+#endif
Index: trunk/MagicSoft/Mars/mraw/MRawRunHeader.cc
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawRunHeader.cc	(revision 454)
+++ trunk/MagicSoft/Mars/mraw/MRawRunHeader.cc	(revision 454)
@@ -0,0 +1,127 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// MRawRunHeader
+//
+// Root storage container for the RUN HEADER information
+//
+////////////////////////////////////////////////////////////////////////////
+
+#include "MRawRunHeader.h"
+
+#include <fstream.h>
+#include <iomanip.h>
+
+#include "MArrayS.h"
+
+ClassImp(MRawRunHeader)
+
+MRawRunHeader::MRawRunHeader(const char *name, const char *title) : fPixAssignment(NULL)
+{
+    *fName  = name  ? name  : "MRawRunHeader";
+    *fTitle = title ? title : "Raw Run Header Information";
+
+    fPixAssignment = new MArrayS(0);
+}
+
+MRawRunHeader::~MRawRunHeader()
+{
+    delete fPixAssignment;
+}
+
+void MRawRunHeader::ReadEvt(ifstream& fin)
+{
+    //
+    // read one RUN HEADER from the input stream
+    //
+    fin.read((Byte_t*)&fMagicNumber,       2);
+
+    //
+    // check whether the the file has the right file type or not
+    //
+    if (fMagicNumber != kMagicNumber)
+    {
+        cout << "Error: Wrong Magic Number: Not a Magic File!" << endl;
+        return;
+    }
+
+    Byte_t dummy[16];
+
+    fin.read((Byte_t*)&fFormatVersion,    2);
+    fin.read((Byte_t*)&fSoftVersion,      2);
+    fin.read((Byte_t*)&fRunType,          2);
+    fin.read((Byte_t*)&fRunNumber,        4);
+    fin.read((Byte_t*)&fProjectName,     22);
+    fin.read((Byte_t*)&fSourceName,      12);
+    fin.read((Byte_t*)dummy,              4); // was RA
+    fin.read((Byte_t*)dummy,              4); // was DEC
+    fin.read((Byte_t*)&fSourceEpochChar,  2);
+    fin.read((Byte_t*)&fSourceEpochDate,  2);
+    fin.read((Byte_t*)&fMJD,              4);
+    fin.read((Byte_t*)&fDateYear,         2);
+    fin.read((Byte_t*)&fDateMonth,        2);
+    fin.read((Byte_t*)&fDateDay,          2);
+    fin.read((Byte_t*)&fNumCrates,        2);
+    fin.read((Byte_t*)&fNumPixInCrate,    2);
+    fin.read((Byte_t*)&fNumSamplesLoGain, 2);
+    fin.read((Byte_t*)&fNumSamplesHiGain, 2);
+    fin.read((Byte_t*)&fNumEvents,        4);
+
+
+    //
+    // calculate size of array, create it and fill it
+    //
+    Int_t nPixel = fNumCrates*fNumPixInCrate;
+    fPixAssignment->Set(nPixel);
+
+    fin.read((Byte_t*)fPixAssignment->GetArray(), nPixel*2);
+    fin.read((Byte_t*)&dummy, 16);
+}
+
+void MRawRunHeader::Print(Option_t *t)
+{
+    //
+    // print run header information on screen
+    //
+    cout << "MagicNumber:  0x" << hex << fMagicNumber << " - " << (fMagicNumber==0xc0c0?"OK":"Wrong!") << endl;
+    cout << "Version:      " << dec << "Format=" << fFormatVersion << "  ";
+    cout << "Software=" << fSoftVersion << endl;
+    cout << "RunNumber:    " << fRunNumber << " (Type=";
+    switch (fRunType)
+    {
+    case 0:
+        cout << "Data";
+        break;
+    case 1:
+        cout << "Pedestal";
+        break;
+    case 2:
+        cout << "Calibration";
+        break;
+    }
+    cout << ")" << endl;
+    cout << "ProjectName: '" << fProjectName << "'" << endl;
+    cout << "Source:      '" << fSourceName << "' " << "  ";
+    cout << fSourceEpochChar << dec << fSourceEpochDate << endl;
+    cout << "Date:         " << setprecision(1) << setiosflags(ios::fixed) << fMJD << " (MJD)  " << fDateYear << "/" << fDateMonth << "/" << fDateDay << endl;
+    cout << "Crates:       " << fNumCrates << " x " << fNumPixInCrate << " Pixel/Crate = " << fNumCrates*fNumPixInCrate << " Pixel/Evt" << endl;
+    cout << "Samples:      " << fNumSamplesLoGain << "/" << fNumSamplesHiGain << " (lo/hi) = " << (fNumSamplesLoGain+fNumSamplesHiGain) * fNumCrates * fNumPixInCrate /1024 << "kB/Evt" << endl;
+    cout << "Evt Counter:  " << fNumEvents << endl;
+
+    cout << hex;
+    for (int i=0; i<GetNumPixel(); i++)
+        cout << setfill('0') << setw(3) << (*fPixAssignment)[i] << " ";
+    cout << hex << endl;
+
+    cout << endl;
+}
+
+UShort_t MRawRunHeader::GetPixAssignment(UShort_t i) const
+{
+    // FIXME: Do we need a range check here?
+    return (*fPixAssignment)[i];
+}
+
+UShort_t MRawRunHeader::GetNumPixel() const
+{
+    return fPixAssignment->GetSize();
+}
Index: trunk/MagicSoft/Mars/mraw/MRawRunHeader.h
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawRunHeader.h	(revision 454)
+++ trunk/MagicSoft/Mars/mraw/MRawRunHeader.h	(revision 454)
@@ -0,0 +1,83 @@
+#ifndef MRAWRUNHEADER_H
+#define MRAWRUNHEADER_H
+///////////////////////////////////////////////////////////////////////
+//                                                                   //
+// MRunHeader                                                        //
+//                                                                   //
+///////////////////////////////////////////////////////////////////////
+
+#ifndef MPARCONTAINER_H
+#include "MParContainer.h"
+#endif
+
+class ifstream;
+class MArrayS;
+
+const UShort_t kMagicNumber = 0xc0c0;
+
+class MRawRunHeader : public MParContainer
+{
+private:
+    /* ---- Run Header Informations ---- */
+    UShort_t  fMagicNumber;
+    UShort_t  fFormatVersion;
+    UShort_t  fSoftVersion;
+    UShort_t  fRunType;
+    UInt_t    fRunNumber;
+    Char_t    fProjectName[22];
+    Char_t    fSourceName[12];
+    //Float_t   fSourceRA;
+    //Float_t   fSourceDEC;
+    Char_t    fSourceEpochChar[2];
+    UShort_t  fSourceEpochDate;
+    Float_t   fMJD;
+    UShort_t  fDateYear;
+    UShort_t  fDateMonth;
+    UShort_t  fDateDay;
+    UShort_t  fNumCrates;
+    UShort_t  fNumPixInCrate;
+    UShort_t  fNumSamplesLoGain;
+    UShort_t  fNumSamplesHiGain;
+    UInt_t    fNumEvents;
+    MArrayS  *fPixAssignment;
+
+public:
+    MRawRunHeader(const char *name=NULL, const char *title=NULL);
+    ~MRawRunHeader();
+
+    UShort_t GetMagicNumber() const      { return fMagicNumber; }
+    UShort_t GetFormatversion() const    { return fFormatVersion; }
+    UShort_t GetSoftVersion() const      { return fSoftVersion; }
+    UShort_t GetRunType() const          { return fRunType; }
+    UInt_t   GetRunNumber() const        { return fRunNumber; }
+    const Char_t  *GetProjectName() const      { return fProjectName; }
+    const Char_t  *GetSourceName() const       { return fSourceName; }
+    //Float_t  GetSourceRa() const         { return fSourceRA; }
+    //Float_t  GetSourceDec() const        { return fSourceDEC; }
+    const Char_t  *GetSourceEpocheChar() const { return fSourceEpochChar; }
+    UShort_t GetSourceEpocheDate() const { return fSourceEpochDate; }
+    Float_t  GetMJD() const              { return fMJD; }
+    UShort_t GetDateYear() const         { return fDateYear; }
+    Byte_t   GetDateMonth() const        { return fDateMonth; }
+    Byte_t   GetDateDay() const          { return fDateDay; }
+    UShort_t GetNumCrates() const        { return fNumCrates; }
+    UShort_t GetNumPixInCrate() const    { return fNumPixInCrate; }
+    UShort_t GetNumSamplesLoGain() const { return fNumSamplesLoGain; }
+    UShort_t GetNumSamplesHiGain() const { return fNumSamplesHiGain; }
+    UShort_t GetNumEvents() const        { return fNumEvents; }
+    UShort_t GetPixAssignment(UShort_t i) const;
+
+    UInt_t GetNumSamplesPerCrate() const
+    {
+        return fNumPixInCrate*(fNumSamplesLoGain+fNumSamplesHiGain);
+    }
+
+    UShort_t GetNumPixel() const;
+
+    void Print(Option_t *t=NULL);
+
+    void ReadEvt(ifstream& fin);
+
+    ClassDef(MRawRunHeader, 1)	// storage container for general info
+};
+#endif
Index: trunk/MagicSoft/Mars/mraw/Makefile
===================================================================
--- trunk/MagicSoft/Mars/mraw/Makefile	(revision 454)
+++ trunk/MagicSoft/Mars/mraw/Makefile	(revision 454)
@@ -0,0 +1,131 @@
+##################################################################
+#
+#   makefile
+# 
+#   for the MARS software
+#
+##################################################################
+# @maintitle
+
+# @code
+
+#
+#  please change all system depend values in the 
+#  config.mk.${OSTYPE} file 
+#
+#
+include ../Makefile.conf.$(OSTYPE)
+include ../Makefile.conf.general
+
+# @endcode 
+
+# @code 
+
+LIB   = libmraw.a
+
+#
+#  connect the include files defined in the config.mk file
+#
+INCLUDES = -I. -I../mbase
+
+#
+#  ----->>>   root libraries
+#
+
+ROOTLIBS   =  `root-config --libs`
+ROOTGLIBS  =  `root-config --glibs`
+ROOTCFLAGS =  `root-config --cflags`
+
+#
+#  compiler flags
+#
+
+CXXFLAGS  = $(ROOTCFLAGS) $(INCLUDES) $(OPTIM) $(DEBUG)
+CFLAGS    = $(CXXFLAGS)
+FFLAGS    = $(CXXFLAGS)
+
+#------------------------------------------------------------------------------
+
+#.SILENT:
+
+.SUFFIXES: .c .cc .cxx .h .hxx .o 
+
+
+SRCFILES = MRawRunHeader.cc \
+	   MRawEvtHeader.cc \
+	   MRawEvtData.cc \
+	   MRawEvtPixelIter.cc \
+	   MRawCrateArray.cc \
+	   MRawCrateData.cc \
+           MRawFileRead.cc \
+           MRawFileWrite.cc
+
+
+
+SRCS    = $(SRCFILES)
+HEADERS = $(SRCFILES:.cc=.h)
+OBJS    = $(SRCFILES:.cc=.o) 
+
+############################################################
+
+all: $(LIB)
+
+depend:
+	@makedepend $(SRCS) $(INCLUDES) $(ROOTCFLAGS) \
+        -f../Makefile.depend 2> kk.kk ; cat kk.kk
+
+$(LIB): $(OBJS) RawCint.o
+	@echo " - Building Library $(LIB) ... "
+	@$(AR) $(LIB) *.o
+
+RawCint.cc: $(HEADERS) 
+	@echo 
+	@echo " - Generating dictionary RawCint.cc ..."
+
+	@$(ROOTSYS)/bin/rootcint -f RawCint.cc \
+	-c $(INCLUDES) $(HEADERS) RawIncl.h RawLinkDef.h 
+
+.cxx.o:	
+	@echo " - Compiling " $<
+	$(CXX) $(CXXFLAGS) -c $< -o $@
+
+.cc.o:	
+	@echo " - Compiling " $<
+	$(CXX) $(CXXFLAGS) -c $< -o $@
+
+.c.o:	
+	@echo " - Compiling " $<
+	$(CC) $(CFLAGS) -c $< -o $@
+
+#
+# The cleaning facility
+#
+
+rmlib:	
+	@echo "Removing libraries..."
+	@rm -f lib*.a
+
+rmcint:	
+	@echo "Removing cint-stuff..."
+	@rm -f RawCint.*
+
+rmobjs:	
+	@echo "Removing object files..."
+	@rm -f *.o
+
+rmbin:	
+	@echo "Removing binary files..."
+	@rm -f core
+
+
+clean:	rmlib rmcint rmobjs rmbin
+
+mrproper:	clean
+	@echo "Removing *~ kk.kk html/..."
+	@rm -f *~ kk.kk
+
+cflags: 
+	@echo $(INCLUDES) $(CXXFLAGS)
+
+# @endcode
+
Index: trunk/MagicSoft/Mars/mraw/MerppLinkDef.h
===================================================================
--- trunk/MagicSoft/Mars/mraw/MerppLinkDef.h	(revision 454)
+++ trunk/MagicSoft/Mars/mraw/MerppLinkDef.h	(revision 454)
@@ -0,0 +1,9 @@
+#ifdef __CINT__
+
+#pragma link off all classes;
+#pragma link off all functions;
+
+#pragma link C++ class MReadRawFile ;
+#pragma link C++ class MWriteRawFile ; 
+
+#endif
Index: trunk/MagicSoft/Mars/mraw/RawIncl.h
===================================================================
--- trunk/MagicSoft/Mars/mraw/RawIncl.h	(revision 454)
+++ trunk/MagicSoft/Mars/mraw/RawIncl.h	(revision 454)
@@ -0,0 +1,10 @@
+#ifndef __CINT__
+
+#include "MTime.h"
+#include "MArrayB.h"
+#include "MArrayS.h"
+#include "MParList.h"
+
+#include <TClonesArray.h>
+
+#endif // __CINT__
Index: trunk/MagicSoft/Mars/mraw/RawLinkDef.h
===================================================================
--- trunk/MagicSoft/Mars/mraw/RawLinkDef.h	(revision 454)
+++ trunk/MagicSoft/Mars/mraw/RawLinkDef.h	(revision 454)
@@ -0,0 +1,18 @@
+#ifdef __CINT__
+
+#pragma link off all classes;
+#pragma link off all functions;
+
+#pragma link C++ class MRawRunHeader;
+
+#pragma link C++ class MRawEvtHeader;
+#pragma link C++ class MRawEvtData;
+#pragma link C++ class MRawEvtPixelIter;
+
+#pragma link C++ class MRawCrateArray;
+#pragma link C++ class MRawCrateData;
+
+#pragma link C++ class MRawFileRead;
+#pragma link C++ class MRawFileWrite;
+
+#endif
Index: trunk/MagicSoft/Mars/readraw.cc
===================================================================
--- trunk/MagicSoft/Mars/readraw.cc	(revision 454)
+++ trunk/MagicSoft/Mars/readraw.cc	(revision 454)
@@ -0,0 +1,111 @@
+#include <iostream.h>
+
+#include <TSystem.h>
+
+#include "TFile.h"
+#include "TTree.h"
+#include "TBranch.h"
+
+#include "MParList.h"
+#include "MTaskList.h"
+#include "MEvtLoop.h"
+
+#include "MRawRunHeader.h"
+#include "MRawEvtHeader.h"
+#include "MRawEvtData.h"
+#include "MRawCrateArray.h"
+#include "MTime.h"
+#include "MInputStreamID.h"
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// This is an easy implementation of the Merging process (as compilable prog)
+//
+// at the moment it reads a binary file ("rawtest.bin") which was written
+// in the DAQ raw format.
+//
+// The data are stored in root container objects (classes derived from
+// TObject like MRawRunHeader)
+//
+// This containers are written to a root file ("rawtest.root")
+//
+/////////////////////////////////////////////////////////////////////////////
+
+int main(const int argc, const char **argv)
+{
+    cout << "==================================================" << endl ;
+    cout << "                   MERPP v0.1" << endl;
+    cout << "      MARS Merging and Preprocessing Program" << endl ;
+    cout << "            Compiled on <" << __DATE__ << ">" << endl ;
+    cout << "==================================================" << endl ;
+    cout << endl;
+
+    //
+    // check for the right usage of the program
+    //
+
+    //
+    //     initialize ROOT  (this is obligatory here)
+    //
+    TROOT simple("Merpp","Mars - Merging and Preprocessing Program");
+
+    MRawRunHeader  *runheader = new MRawRunHeader();
+    MRawEvtHeader  *evtheader = new MRawEvtHeader();
+    MTime          *evttime   = new MTime();
+    MRawEvtData    *evtdata   = new MRawEvtData();
+    MRawCrateArray *evtcrate  = new MRawCrateArray();
+
+    //
+    //  open the file
+    //
+    TFile input("delme.root", "READ");
+
+    //
+    // open the Run Header and read in
+    //
+
+    TTree *runtree = (TTree*) input.Get("RunHeaders") ;
+    
+    cout << " Entries in Tree RunHeaders: " << dec << runtree->GetEntries() << endl ;
+
+    runtree->GetBranch("MRawRunHeader")->SetAddress(&runheader);
+    runtree->GetEvent(0);
+
+    runheader->Print();
+
+
+    //
+    // open the DataTree and read in 
+    //
+    TTree *evttree = (TTree*) input.Get("Data") ;
+
+    //
+    //   connnect the branches in that tree
+    //
+    evttree->GetBranch("MRawEvtHeader")->SetAddress(&evtheader);
+    evttree->GetBranch("MTime")->SetAddress(&evttime);
+    evttree->GetBranch("MRawEvtData")->SetAddress(&evtdata);
+    evttree->GetBranch("MRawCrateArray")->SetAddress(&evtcrate);
+
+    Int_t iEnt = (Int_t)evttree->GetEntries();
+    cout << " Entries in Tree Data: " << dec << iEnt << endl;
+
+    for (Int_t i = 0; i<iEnt; i++)
+    {
+        cout << "Entry: " << i << endl;
+
+        // readin event with the selected branches
+        evttree->GetEvent(i);
+
+        evtheader->Print();
+        evttime->Print();
+        evtcrate->Print();
+        evtdata->Print();
+    } 
+    
+    //   end of small readin program 
+
+    return 0;
+}
+
+
