Index: trunk/MagicSoft/Mars/mraw/MRawFileRead.cc
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawFileRead.cc	(revision 2655)
+++ trunk/MagicSoft/Mars/mraw/MRawFileRead.cc	(revision 2675)
@@ -142,27 +142,6 @@
     }
 
-    //
-    //  check if all necessary containers exist in the Parameter list.
-    //  if not create one and add them to the list
-    //
-    fRawRunHeader = (MRawRunHeader*)pList->FindCreateObj("MRawRunHeader");
-    if (!fRawRunHeader)
+    if (!MRawRead::PreProcess(pList))
         return kFALSE;
-
-    fRawEvtHeader = (MRawEvtHeader*)pList->FindCreateObj("MRawEvtHeader");
-    if (!fRawEvtHeader)
-        return kFALSE;
-
-    fRawEvtData = (MRawEvtData*)pList->FindCreateObj("MRawEvtData");
-    if (!fRawEvtData)
-        return kFALSE;
-
-    fRawCrateArray = (MRawCrateArray*)pList->FindCreateObj("MRawCrateArray");
-    if (!fRawCrateArray)
-        return kFALSE;
-
-    fRawEvtTime = (MTime*)pList->FindCreateObj("MTime");
-    if (!fRawEvtTime)
-        return kTRUE;
 
     //
@@ -172,14 +151,5 @@
     fRawRunHeader->Print();
 
-    if (fRawRunHeader->GetMagicNumber()!=kMagicNumber)
-        return kFALSE;
-
-    //
-    // Give the run header information to the 'sub-classes'
-    //
-    fRawEvtHeader->Init(fRawRunHeader, fRawEvtTime);
-    fRawEvtData  ->Init(fRawRunHeader, fRawCrateArray);
-
-    return kTRUE;
+    return fRawRunHeader->GetMagicNumber()==kMagicNumber;
 }
 
@@ -194,73 +164,5 @@
 Int_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;
-
-    //
-    //  Get number of crates from the run header
-    //
-    const UShort_t nc = fRawRunHeader->GetNumCrates();
-
-    //
-    // Delete arrays which stores the pixel information (time slices)
-    //
-    fRawEvtData->ResetPixels();
-
-    //
-    // clear the TClonesArray which stores the Crate Information
-    // and create a new array of the correct size
-    //
-    fRawCrateArray->SetSize(nc);
-
-    //
-    //  Get file format version
-    //
-    const UShort_t ver = fRawRunHeader->GetFormatVersion();
-
-    //
-    // read the CRATE DATA (see specification) from file
-    //
-    for (int i=0; i<nc; i++)
-    {
-        fRawCrateArray->GetEntry(i)->ReadEvt(*fIn, ver);
-        if (!*fIn)
-            return kFALSE;
-
-        fRawEvtData->ReadEvt(*fIn);
-        if (!*fIn)
-            return kFALSE;
-    }
-
-    {
-        // FIXME This is a stupid workaround for the missing time stamp!
-        //       Might be used depending on the run number in the future
-        static Double_t tm = 0; // Range of roughly 8min
-        const UInt_t ct = (*fRawCrateArray)[0]->GetFADCClockTick();
-
-        tm = ct<tm ? fmod(tm, (UInt_t)(-1))+(UInt_t)(-1)+ct : ct;
-
-        const Double_t mhz = 9.375;                        // [1e6 ticks/s]
-        const Double_t t   = tm/mhz;                       // [us]
-        const UInt_t ns    = (UInt_t)fmod(t*1e3, 1e6);
-        const UShort_t ms  = (UShort_t)fmod(t/1e3, 1e3);
-        const Byte_t s     = (Byte_t)fmod(t/1e6, 60);
-
-        // Create an artificial time stamp!
-        UInt_t m = (Byte_t)fmod(t/60e6, 60);
-        //const Byte_t h     = (Byte_t)(t/3600e6);
-        m += fRawRunHeader->GetRunNumber()*10;
-        m %= 360; // 6h
-
-        fRawEvtTime->Set(fRawRunHeader->GetRunStart().Year(),
-                         fRawRunHeader->GetRunStart().Month(),
-                         fRawRunHeader->GetRunStart().Day(),
-                         m/60, m%60, s, ms, ns);
-    }
-
-    return kTRUE;
+    return ReadEvent(*fIn);
 }
 
Index: trunk/MagicSoft/Mars/mraw/MRawFileRead.h
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawFileRead.h	(revision 2655)
+++ trunk/MagicSoft/Mars/mraw/MRawFileRead.h	(revision 2675)
@@ -2,30 +2,13 @@
 #define MARS_MRawFileRead
 
-#ifndef MARS_MTask
-#include "MTask.h"
+#ifndef MARS_MRawRead
+#include "MRawRead.h"
 #endif
 
-// gcc 3.2
-//class ifstream;
-#include <iosfwd>
-
-class MTime;
-class MParList;
-class MRawRunHeader;
-class MRawEvtHeader;
-class MRawEvtData;
-class MRawCrateArray;
-
-class MRawFileRead : public MTask
+class MRawFileRead : public MRawRead
 {
 private:
-    MRawRunHeader  *fRawRunHeader;  // run header information container to fill from file
-    MRawEvtHeader  *fRawEvtHeader;  // event header information container to fill from file
-    MRawEvtData    *fRawEvtData;    // raw evt header infomation container to fill from file
-    MRawCrateArray *fRawCrateArray; // crate information array container to fill from file
-    MTime          *fRawEvtTime;    // raw evt time information container to fill from file
-
-    TString         fFileName;
-    ifstream       *fIn;            //! buffered input stream (file to read from)
+    TString   fFileName;
+    ifstream *fIn;        //! buffered input stream (file to read from)
 
     Int_t PreProcess(MParList *pList);
Index: trunk/MagicSoft/Mars/mraw/MRawRead.cc
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawRead.cc	(revision 2675)
+++ trunk/MagicSoft/Mars/mraw/MRawRead.cc	(revision 2675)
@@ -0,0 +1,197 @@
+/* ======================================================================== *\
+!
+! *
+! * This file is part of MARS, the MAGIC Analysis and Reconstruction
+! * Software. It is distributed to you in the hope that it can be a useful
+! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
+! * It is distributed WITHOUT ANY WARRANTY.
+! *
+! * Permission to use, copy, modify and distribute this software and its
+! * documentation for any purpose is hereby granted without fee,
+! * provided that the above copyright notice appear in all copies and
+! * that both that copyright notice and this permission notice appear
+! * in supporting documentation. It is provided "as is" without express
+! * or implied warranty.
+! *
+!
+!
+!   Author(s): Thomas Bretz  12/2000 <mailto:tbretz@uni-sw.gwdg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2001
+!
+!
+\* ======================================================================== */
+
+//////////////////////////////////////////////////////////////////////////////
+//                                                                          
+//  MRawRead
+//                                                                          
+//  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.          
+//                                                                          
+//  Input Containers:                                                       
+//   -/-                                                                    
+//                                                                          
+//  Output Containers:                                                      
+//   MRawRunHeader
+//   MRawEvtHeader
+//   MRawEvtData
+//   MRawCrateArray
+//   MRawEvtTime
+//                                                                          
+//////////////////////////////////////////////////////////////////////////////
+#include "MRawRead.h"
+
+#include <fstream>
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+#include "MTime.h"
+#include "MParList.h"
+#include "MRawRunHeader.h"
+#include "MRawEvtHeader.h"
+#include "MRawEvtData.h"
+#include "MRawCrateData.h"
+#include "MRawCrateArray.h"
+
+ClassImp(MRawRead);
+
+using namespace std;
+
+// --------------------------------------------------------------------------
+//
+// Default constructor. It tries to open the given file.
+//
+MRawRead::MRawRead(const char *name, const char *title)
+{
+    fName  = name  ? name  : "MRawRead";
+    fTitle = title ? title : "Bas class for reading DAQ files";
+}
+
+// --------------------------------------------------------------------------
+//
+// The PreProcess of this task checks for the following containers in the
+// list:
+//   MRawRunHeader <output>   if not found it is created
+//   MRawEvtHeader <output>   if not found it is created
+//   MRawEvtData <output>     if not found it is created
+//   MRawCrateArray <output>  if not found it is created
+//   MRawEvtTime <output>     if not found it is created (MTime)
+//
+// If all containers are found or created the run header is read from the
+// binary file and printed.  If the Magic-Number (file identification)
+// doesn't match we stop the eventloop.
+//
+// Now the EvtHeader and EvtData containers are initialized.
+//
+Int_t MRawRead::PreProcess(MParList *pList)
+{
+    if (!OpenStream())
+        return kFALSE;
+
+    //
+    //  check if all necessary containers exist in the Parameter list.
+    //  if not create one and add them to the list
+    //
+    fRawRunHeader = (MRawRunHeader*)pList->FindCreateObj("MRawRunHeader");
+    if (!fRawRunHeader)
+        return kFALSE;
+
+    fRawEvtHeader = (MRawEvtHeader*)pList->FindCreateObj("MRawEvtHeader");
+    if (!fRawEvtHeader)
+        return kFALSE;
+
+    fRawEvtData = (MRawEvtData*)pList->FindCreateObj("MRawEvtData");
+    if (!fRawEvtData)
+        return kFALSE;
+
+    fRawCrateArray = (MRawCrateArray*)pList->FindCreateObj("MRawCrateArray");
+    if (!fRawCrateArray)
+        return kFALSE;
+
+    fRawEvtTime = (MTime*)pList->FindCreateObj("MTime");
+    if (!fRawEvtTime)
+        return kFALSE;
+
+    //
+    // Give the run header information to the 'sub-classes'
+    //
+    fRawEvtHeader->Init(fRawRunHeader, fRawEvtTime);
+    fRawEvtData  ->Init(fRawRunHeader, fRawCrateArray);
+
+    return kTRUE;
+}
+
+Bool_t MRawRead::ReadEvent(istream &fin)
+{
+    //
+    //  Read in the next EVENT HEADER (see specification),
+    // if there is no next event anymore stop eventloop
+    //
+    if (!fRawEvtHeader->ReadEvt(fin))
+        return kFALSE;
+
+    //
+    //  Get number of crates from the run header
+    //
+    const UShort_t nc = fRawRunHeader->GetNumCrates();
+
+    //
+    // Delete arrays which stores the pixel information (time slices)
+    //
+    fRawEvtData->ResetPixels();
+
+    //
+    // clear the TClonesArray which stores the Crate Information
+    // and create a new array of the correct size
+    //
+    fRawCrateArray->SetSize(nc);
+
+    //
+    //  Get file format version
+    //
+    const UShort_t ver = fRawRunHeader->GetFormatVersion();
+
+    //
+    // read the CRATE DATA (see specification) from file
+    //
+    for (int i=0; i<nc; i++)
+    {
+        fRawCrateArray->GetEntry(i)->ReadEvt(fin, ver);
+        if (!fin)
+            return kFALSE;
+
+        fRawEvtData->ReadEvt(fin);
+        if (!fin)
+            return kFALSE;
+    }
+
+    {
+        // FIXME This is a stupid workaround for the missing time stamp!
+        //       Might be used depending on the run number in the future
+        static Double_t tm = 0; // Range of roughly 8min
+        const UInt_t ct = (*fRawCrateArray)[0]->GetFADCClockTick();
+
+        tm = ct<tm ? fmod(tm, (UInt_t)(-1))+(UInt_t)(-1)+ct : ct;
+
+        const Double_t mhz = 9.375;                        // [1e6 ticks/s]
+        const Double_t t   = tm/mhz;                       // [us]
+        const UInt_t ns    = (UInt_t)fmod(t*1e3, 1e6);
+        const UShort_t ms  = (UShort_t)fmod(t/1e3, 1e3);
+        const Byte_t s     = (Byte_t)fmod(t/1e6, 60);
+
+        // Create an artificial time stamp!
+        UInt_t m = (Byte_t)fmod(t/60e6, 60);
+        //const Byte_t h     = (Byte_t)(t/3600e6);
+        m += fRawRunHeader->GetRunNumber()*10;
+        m %= 360; // 6h
+
+        fRawEvtTime->Set(fRawRunHeader->GetRunStart().Year(),
+                         fRawRunHeader->GetRunStart().Month(),
+                         fRawRunHeader->GetRunStart().Day(),
+                         m/60, m%60, s, ms, ns);
+    }
+    return kTRUE;
+}
Index: trunk/MagicSoft/Mars/mraw/MRawRead.h
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawRead.h	(revision 2675)
+++ trunk/MagicSoft/Mars/mraw/MRawRead.h	(revision 2675)
@@ -0,0 +1,37 @@
+#ifndef MARS_MRawRead
+#define MARS_MRawRead
+
+#ifndef MARS_MTask
+#include "MTask.h"
+#endif
+
+class MTime;
+class MParList;
+class MRawRunHeader;
+class MRawEvtHeader;
+class MRawEvtData;
+class MRawCrateArray;
+
+class MRawRead : public MTask
+{
+protected:
+    MRawRunHeader  *fRawRunHeader;  // run header information container to fill from file
+    MRawEvtHeader  *fRawEvtHeader;  // event header information container to fill from file
+    MRawEvtData    *fRawEvtData;    // raw evt header infomation container to fill from file
+    MRawCrateArray *fRawCrateArray; // crate information array container to fill from file
+    MTime          *fRawEvtTime;    // raw evt time information container to fill from file
+
+    Bool_t ReadEvent(istream &fin);
+    Int_t  PreProcess(MParList *pList);
+
+private:
+    virtual Bool_t OpenStream() { return kTRUE; }
+
+public:
+    MRawRead(const char *name=NULL, const char *title=NULL);
+    ~MRawRead();
+
+    ClassDef(MRawRead, 0)	// Task to read the raw data binary file
+};
+
+#endif
Index: trunk/MagicSoft/Mars/mraw/MRawSocketRead.cc
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawSocketRead.cc	(revision 2655)
+++ trunk/MagicSoft/Mars/mraw/MRawSocketRead.cc	(revision 2675)
@@ -160,27 +160,6 @@
         return kFALSE;
 
-    //
-    //  check if all necessary containers exist in the Parameter list.
-    //  if not create one and add them to the list
-    //
-    fRawRunHeader = (MRawRunHeader*)pList->FindCreateObj("MRawRunHeader");
-    if (!fRawRunHeader)
-        return kFALSE;
-
-    fRawEvtHeader = (MRawEvtHeader*)pList->FindCreateObj("MRawEvtHeader");
-    if (!fRawEvtHeader)
-        return kFALSE;
-
-    fRawEvtData = (MRawEvtData*)pList->FindCreateObj("MRawEvtData");
-    if (!fRawEvtData)
-        return kFALSE;
-
-    fRawCrateArray = (MRawCrateArray*)pList->FindCreateObj("MRawCrateArray");
-    if (!fRawCrateArray)
-        return kFALSE;
-
-    fTime = (MTime*)pList->FindCreateObj("MTime");
-    if (!fTime)
-        return kTRUE;
+    if (!MRawRead::PreProcess(pList))
+        return kFALSE;
 
     fParList = pList;
@@ -273,51 +252,6 @@
     }
 
-    //
-    // Give the run header information to the 'sub-classes'
-    //
-    fRawEvtHeader->Init(fRawRunHeader, fTime);
-    fRawEvtData  ->Init(fRawRunHeader, fRawCrateArray);
-
-    //
-    //  Read in the next EVENT HEADER (see specification),
-    // if there is no next event anymore stop eventloop
-    //
-    if (!fRawEvtHeader->ReadEvt(*fIn))
-        return kFALSE;
-
-    //
-    //  Get number of crates from the run header
-    //
-    const UShort_t nc = fRawRunHeader->GetNumCrates();
-
-    //
-    // Delete arrays which stores the pixel information (time slices)
-    //
-    fRawEvtData->ResetPixels();
-
-    //
-    // clear the TClonesArray which stores the Crate Information
-    // and create a new array of the correct size
-    //
-    fRawCrateArray->SetSize(nc);
-
-    //
-    //  Get file format version
-    //
-    const UShort_t ver = fRawRunHeader->GetFormatVersion();
-
-    //
-    // read the CRATE DATA (see specification) from file
-    //
-    for (int i=0; i<nc; i++)
-    {
-        fRawCrateArray->GetEntry(i)->ReadEvt(*fIn, ver);
-        if (!*fIn)
-            return kFALSE;
-
-        fRawEvtData->ReadEvt(*fIn);
-        if (!*fIn)
-            return kFALSE;
-    }
+    if (!ReadEvent(*fIn))
+        return kFALSE;
 
     //
Index: trunk/MagicSoft/Mars/mraw/MRawSocketRead.h
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawSocketRead.h	(revision 2655)
+++ trunk/MagicSoft/Mars/mraw/MRawSocketRead.h	(revision 2675)
@@ -2,38 +2,26 @@
 #define MARS_MRawSocketRead
 
-#ifndef MARS_MTask
-#include "MTask.h"
+#ifndef MARS_MRawRead
+#include "MRawRead.h"
 #endif
 
-class MTime;
-class MParList;
 class MReadSocket;
-class MRawEvtData;
-class MRawEvtHeader;
-class MRawRunHeader;
-class MRawCrateArray;
 
-class MRawSocketRead : public MTask
+class MRawSocketRead : public MRawRead
 {
 private:
-    MRawRunHeader  *fRawRunHeader;  // run header information container to fill from file
-    MRawEvtHeader  *fRawEvtHeader;  // event header information container to fill from file
-    MRawEvtData    *fRawEvtData;    // raw evt header infomation container to fill from file
-    MRawCrateArray *fRawCrateArray; // crate information array container to fill from file
-    MTime          *fTime;          // raw evt time information container to fill from file
+    MReadSocket *fIn;         //! buffered input stream (file to read from)
+    MParList    *fParList;    //!
 
-    MReadSocket    *fIn;            //! buffered input stream (file to read from)
-    MParList       *fParList;       //!
+    UInt_t       fRunNumber;  //!
+    UInt_t       fEvtNumber;  //!
 
-    UInt_t          fRunNumber;     //!
-    UInt_t          fEvtNumber;     //!
-
-    Int_t           fPort;          // Port on which we wait for the connection
+    Int_t        fPort;       // Port on which we wait for the connection
 
     Bool_t OpenSocket();
 
-    Int_t  PreProcess(MParList *pList);
-    Int_t  Process();
-    Int_t  PostProcess();
+    Int_t PreProcess(MParList *pList);
+    Int_t Process();
+    Int_t PostProcess();
 
 public:
Index: trunk/MagicSoft/Mars/mraw/Makefile
===================================================================
--- trunk/MagicSoft/Mars/mraw/Makefile	(revision 2655)
+++ trunk/MagicSoft/Mars/mraw/Makefile	(revision 2675)
@@ -35,4 +35,5 @@
 	   MRawCrateArray.cc \
 	   MRawCrateData.cc \
+           MRawRead.cc \
            MRawFileWrite.cc \
            MRawFileRead.cc \
Index: trunk/MagicSoft/Mars/mraw/RawLinkDef.h
===================================================================
--- trunk/MagicSoft/Mars/mraw/RawLinkDef.h	(revision 2655)
+++ trunk/MagicSoft/Mars/mraw/RawLinkDef.h	(revision 2675)
@@ -14,4 +14,5 @@
 #pragma link C++ class MRawCrateData+;
 
+#pragma link C++ class MRawRead+;
 #pragma link C++ class MRawSocketRead+;
 #pragma link C++ class MRawFileRead+;
