Index: trunk/MagicSoft/Mars/mfileio/FileIOLinkDef.h
===================================================================
--- trunk/MagicSoft/Mars/mfileio/FileIOLinkDef.h	(revision 2132)
+++ trunk/MagicSoft/Mars/mfileio/FileIOLinkDef.h	(revision 2134)
@@ -9,4 +9,5 @@
 #pragma link C++ class MReadTree+;
 #pragma link C++ class MReadMarsFile+;
+#pragma link C++ class MReadRflFile+;
 
 #pragma link C++ class MRootFileBranch+;
Index: trunk/MagicSoft/Mars/mfileio/MCT1ReadPreProc.cc
===================================================================
--- trunk/MagicSoft/Mars/mfileio/MCT1ReadPreProc.cc	(revision 2132)
+++ trunk/MagicSoft/Mars/mfileio/MCT1ReadPreProc.cc	(revision 2134)
@@ -848,7 +848,5 @@
     const Double_t up  = fBinningT->GetEdges()[bin+1];
 
-    Double_t discreteTheta = 0.5*(up+low) * TMath::Pi()/180;
-
-    return discreteTheta;
+    return 0.5*(up+low) * TMath::Pi()/180;
 }
 
Index: trunk/MagicSoft/Mars/mfileio/MReadRflFile.cc
===================================================================
--- trunk/MagicSoft/Mars/mfileio/MReadRflFile.cc	(revision 2134)
+++ trunk/MagicSoft/Mars/mfileio/MReadRflFile.cc	(revision 2134)
@@ -0,0 +1,405 @@
+/* ======================================================================== *\
+!
+! *
+! * 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, 5/2003 <mailto:tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2003
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// MReadRflFile
+//
+// Reads a output file of the reflector program
+//
+/////////////////////////////////////////////////////////////////////////////
+#include "MReadRflFile.h"
+
+#include <fstream.h>
+
+#include <TSystem.h>
+
+#include "structures_rfl.h"
+
+#include "MParList.h"
+#include "MRflEvtData.h"
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+ClassImp(MReadRflFile);
+
+// ------------------------------------------------
+const char PROGNAME[] = "reflector";
+#define SIZE_OF_FLAGS           13
+#define SIZE_OF_SIGNATURE       13
+#define FLAG_START_OF_RUN       "\nSTART---RUN\n"
+#define FLAG_START_OF_EVENT     "\nSTART-EVENT\n"
+#define FLAG_END_OF_EVENT       "\nEND---EVENT\n"
+#define FLAG_END_OF_RUN         "\nEND-----RUN\n"
+#define FLAG_END_OF_FILE        "\nEND----FILE\n"
+#define FLAG_END_OF_STDIN       "\nEND---STDIN\n"
+// ------------------------------------------------
+
+Bool_t MReadRflFile::FlagIsA(const  char *s1, const char *flag)
+{
+    return strncmp(s1, flag, SIZE_OF_FLAGS)==0;
+}
+
+Bool_t MReadRflFile::ReadEvtHeader()
+{
+    if (fCurrentVersion <= 0.5)
+    {
+        RflEventHeader_old revth;
+        fIn->read(&revth, sizeof(RflEventHeader_old));
+        return (bool)*fIn;
+    }
+    else
+    {
+        RflEventHeader revth_new;
+        fIn->read(&revth_new, sizeof(RflEventHeader));
+        return (bool)*fIn;
+    }
+}
+
+enum {
+    kError,
+    kEndOfFile,
+    kStartOfRun,
+    kEndOfRun,
+    kStartOfEvt,
+    kEndOfEvt,
+    kUndefined
+};
+
+
+int MReadRflFile::ReadFlag()
+{
+    char flag[SIZE_OF_FLAGS];
+    fIn->read(flag, SIZE_OF_FLAGS);
+
+    if (!fIn)
+        return kError;
+
+    //*fLog << "<" << TString(&flag[1], 11)  << ">" <<endl;
+
+    if (FlagIsA(flag, FLAG_END_OF_FILE))
+        return kEndOfFile;
+    if (FlagIsA(flag, FLAG_END_OF_RUN))
+        return kEndOfRun;
+    if (FlagIsA(flag, FLAG_START_OF_RUN))
+        return kStartOfRun;
+    if (FlagIsA(flag, FLAG_END_OF_EVENT))
+        return kEndOfEvt;
+    if (FlagIsA(flag, FLAG_START_OF_EVENT))
+        return kStartOfEvt;
+
+    return kUndefined;
+}
+
+Bool_t MReadRflFile::ReadEvtData()
+{
+    Bool_t rc = kFALSE;
+    while (1)
+    {
+        cphoton data; // FIRST READ "START OF EVENT"
+        fIn->read((char*)&data, SIZE_OF_FLAGS);
+        if (!*fIn)
+            break;
+
+        if (FlagIsA((char*)&data, FLAG_END_OF_EVENT))
+        {
+            rc = kTRUE;
+            break;
+        }
+
+        fIn->read((char*)&data+SIZE_OF_FLAGS, sizeof(cphoton)-SIZE_OF_FLAGS);
+        if (!*fIn)
+            break;
+
+        MRflSinglePhoton &ph = fEvt->GetNewPhoton();
+        ph.SetXY(data.x*10, data.y*10);
+        ph.SetCosUV(data.u, data.v);
+        ph.SetTime(data.t);
+        ph.SetHeight(data.h);
+        ph.SetInclinationAngle(data.phi);
+    }
+
+    fEvt->FixSize();
+    return rc;
+}
+
+Int_t MReadRflFile::EvalFlag()
+{
+    const Int_t flag = ReadFlag();
+
+    switch (flag)
+    {
+    case kEndOfFile:
+        fCurrentVersion = ReadVersion();
+        if (fCurrentVersion<0)
+        {
+            *fLog << inf << "Found end of file...Everything OK." << endl;
+            break;
+        }
+
+        *fLog << warn << "Found flag of end of file, but file goes on..." << endl;
+        if (ReadFlag()<0)
+            return kError;
+        /* FALLTHROU */
+    case kStartOfRun:
+        if (fCurrentVersion>0.5)
+        {
+            RflRunHeader rrunh;
+            fIn->read(&rrunh, sizeof(RflRunHeader));
+            if (*fIn)
+            {
+                *fLog << inf << "FIXME: Call ReInit" << endl;
+                break;
+            }
+
+            *fLog << err << "Error! found end of file... But no EOF flag. Exiting." << endl;
+            return kError;
+        }
+        return kUndefined;
+
+    case kStartOfEvt:
+    case kEndOfRun:
+        break;
+
+    case kError:
+        *fLog << err << "ERROR - Flag 'error'" << endl;
+        return kError;
+
+    case kUndefined:
+        *fLog << err << "ERROR - Flag 'undefined'" << endl;
+        return kError;
+
+    default:
+        *fLog << err << "ERROR - Unhandled flag" << endl;
+        return kError;
+
+    }
+    return flag;
+}
+
+Bool_t MReadRflFile::Process()
+{
+    for (;;)
+    {
+        switch (EvalFlag())
+        {
+        case kError:
+            return kFALSE;
+
+        case kEndOfFile:
+            if (!OpenNextFile())
+                return kFALSE;
+            /* FALLTHROU */
+        case kStartOfRun:
+        case kEndOfRun:
+            continue;
+
+        case kStartOfEvt:
+            break;
+        }
+        break;
+    }
+
+    if (!ReadEvtHeader())
+        return kFALSE;
+
+    return ReadEvtData();
+}
+
+Bool_t MReadRflFile::PreProcess(MParList *plist)
+{
+    fEvt=(MRflEvtData*)plist->FindCreateObj("MRflEvtData");
+    if (!fEvt)
+        return kFALSE;
+
+    Rewind();
+
+    return OpenNextFile();
+}
+
+// --------------------------------------------------------------------------
+//
+// This opens the next file in the list and deletes its name from the list.
+//
+Bool_t MReadRflFile::OpenNextFile()
+{
+    //
+    // open the input stream and check if it is really open (file exists?)
+    //
+    if (fIn)
+        delete fIn;
+    fIn = NULL;
+
+    //
+    // Check for the existence of a next file to read
+    //
+    if (fNumFile >= (UInt_t)fFileNames->GetSize())
+    {
+        *fLog << inf << GetDescriptor() << ": No unread files anymore..." << endl;
+        return kFALSE;
+    }
+
+    TNamed *file = (TNamed*)fFileNames->At(fNumFile);
+
+    //TNamed *file = (TNamed*)fFileNames->GetFirst();
+    //if (!file)
+    //    return kFALSE;
+
+    //
+    // open the file which is the first one in the chain
+    //
+    const TString name = file->GetName();
+
+    const char *expname = gSystem->ExpandPathName(name);
+    const TString fname(expname);
+    delete [] expname;
+
+    //
+    // Remove this file from the list of pending files
+    //
+    //fFileNames->Remove(file);
+
+    *fLog << inf << "Open file: '" << name << "'" << endl;
+
+    fIn = new ifstream(name);
+    if (!*fIn)
+    {
+        cout << "Error openeng file " << name << "." << endl;
+        return kFALSE;
+    }
+
+    *fLog << inf;
+    fLog->Separator(name);
+
+    fCurrentVersion = ReadVersion();
+    if (fCurrentVersion<0)
+    {
+        cout << "ERROR reading signature." << endl;
+        return kFALSE;
+    }
+    cout << "Version " << fCurrentVersion << endl << endl;
+
+    fNumFile++;
+    return kTRUE;
+}
+
+/****************************************************/
+
+float MReadRflFile::ReadVersion()
+{
+    char sign[20];
+    fIn->read(sign, SIZE_OF_SIGNATURE);
+    if (!*fIn)
+        return -1;
+
+    if (strncmp(sign, PROGNAME, strlen(PROGNAME)) != 0)
+    {
+        /* For the ascii tail of the file! : */
+        if (strncmp(sign, "\n############", SIZE_OF_SIGNATURE))
+            cout << "ERROR: Signature of .rfl file is not correct: " << sign << endl;
+
+        return -1;
+    }
+
+    float version;
+    sscanf(sign, "%*s %f", &version);
+
+    //If the version is < 0.6 the signature had one more byte
+    if (version < 0.6)
+        *fIn >> sign[0];
+
+    return version;
+}
+
+
+Bool_t MReadRflFile::PostProcess()
+{
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+// Default constructor. Creates an array which stores the file names of
+// the files which should be read. If a filename is given it is added
+// to the list.
+//
+MReadRflFile::MReadRflFile(const char *fname, const char *name,
+                           const char *title) : fIn(NULL), fEntries(0)
+{
+    fName  = name  ? name  : "MRead";
+    fTitle = title ? title : "Reads a Reflector output file";
+
+    //
+    // remember file name for opening the file in the preprocessor
+    //
+    fFileNames = new TList;
+    fFileNames->SetOwner();
+
+    if (fname)
+        AddFile(fname);
+}
+
+// --------------------------------------------------------------------------
+//
+// Delete the filename list and the input stream if one exists.
+//
+MReadRflFile::~MReadRflFile()
+{
+    delete fFileNames;
+    if (fIn)
+        delete fIn;
+}
+
+// --------------------------------------------------------------------------
+//
+// Add this file as the last entry in the chain
+//
+void MReadRflFile::AddFile(const char *txt)
+{
+    const char *name = gSystem->ExpandPathName(txt);
+
+    TString fname(name);
+    delete [] name;
+/*
+    if (!CheckHeader(fname))
+    {
+        *fLog << warn << "WARNING - Problem reading header... ignored." << endl;
+        return;
+    }
+
+    const Int_t n = GetNumEvents(fname);
+    if (n==0)
+    {
+        *fLog << warn << "WARNING - File contains no data... ignored." << endl;
+        return;
+    }
+
+    fEntries += n;
+
+    *fLog << inf << "File " << txt << " contains " << n << " events (Total=" << fEntries << ")" << endl;
+*/
+    fFileNames->AddLast(new TNamed(txt, ""));
+}
+
Index: trunk/MagicSoft/Mars/mfileio/MReadRflFile.h
===================================================================
--- trunk/MagicSoft/Mars/mfileio/MReadRflFile.h	(revision 2134)
+++ trunk/MagicSoft/Mars/mfileio/MReadRflFile.h	(revision 2134)
@@ -0,0 +1,55 @@
+#ifndef MARS_MReadRflFile
+#define MARS_MReadRflFile
+
+#ifndef ROOT_TArrayF
+#include <TArrayF.h>
+#endif
+
+#ifndef MARS_MRead
+#include "MRead.h"
+#endif
+
+class TList;
+class MRflEvtData;
+
+class MReadRflFile : public MRead
+{
+private:
+    ifstream *fIn;          // the inputfile
+    TList    *fFileNames;   // Array which stores the \0-terminated filenames
+
+    MRflEvtData *fEvt;        //!
+
+    UInt_t fNumFile;
+    UInt_t fEntries; // TO BE IMPLEMENTED
+
+    Float_t fCurrentVersion; //! Version of currently open rfl file
+
+    float  ReadVersion();
+    Bool_t ReadEvtHeader();
+    Bool_t ReadEvtData();
+    int    ReadFlag();
+    Bool_t FlagIsA(const  char *s1, const char *flag);
+    Int_t  EvalFlag();
+    Bool_t OpenNextFile();
+
+    Bool_t PreProcess(MParList *pList);
+    Bool_t Process();
+    Bool_t PostProcess();
+
+public:
+    MReadRflFile(const char *filename=NULL,
+                 const char *name=NULL,
+                 const char *title=NULL);
+
+    ~MReadRflFile();
+
+    void AddFile(const char *fname);
+
+    Bool_t Rewind() { fNumFile=0; return kTRUE; }
+    UInt_t GetEntries() { return fEntries; }
+
+    ClassDef(MReadRflFile, 0) // Reads reflector files
+};
+
+#endif
Index: trunk/MagicSoft/Mars/mfileio/Makefile
===================================================================
--- trunk/MagicSoft/Mars/mfileio/Makefile	(revision 2132)
+++ trunk/MagicSoft/Mars/mfileio/Makefile	(revision 2134)
@@ -21,5 +21,5 @@
 
 INCLUDES = -I. -I../mbase -I../mraw -I../mmc -I../mdata -I../manalysis \
-	   -I../mgeom -I../mhist -I../mmain
+	   -I../mgeom -I../mhist -I../mmain -I../mreflector
 
 # @code 
@@ -36,4 +36,5 @@
 	   MReadTree.cc \
            MReadMarsFile.cc \
+           MReadRflFile.cc \
            MWriteFile.cc \
            MWriteAsciiFile.cc \
