Index: trunk/MagicSoft/include-Classes/MRawFormat/MRawCrateArray.cc
===================================================================
--- trunk/MagicSoft/include-Classes/MRawFormat/MRawCrateArray.cc	(revision 498)
+++ trunk/MagicSoft/include-Classes/MRawFormat/MRawCrateArray.cc	(revision 498)
@@ -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/include-Classes/MRawFormat/MRawCrateArray.h
===================================================================
--- trunk/MagicSoft/include-Classes/MRawFormat/MRawCrateArray.h	(revision 498)
+++ trunk/MagicSoft/include-Classes/MRawFormat/MRawCrateArray.h	(revision 498)
@@ -0,0 +1,37 @@
+#ifndef MRAWCRATEARRAY_H
+#define MRAWCRATEARRAY_H
+///////////////////////////////////////////////////////////////////////
+//                                                                   //
+// MRunHeader                                                        //
+//                                                                   //
+///////////////////////////////////////////////////////////////////////
+
+#ifndef MPARCONTAINER_H
+#include "../MBase/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/include-Classes/MRawFormat/MRawCrateData.cc
===================================================================
--- trunk/MagicSoft/include-Classes/MRawFormat/MRawCrateData.cc	(revision 498)
+++ trunk/MagicSoft/include-Classes/MRawFormat/MRawCrateData.cc	(revision 498)
@@ -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/include-Classes/MRawFormat/MRawCrateData.h
===================================================================
--- trunk/MagicSoft/include-Classes/MRawFormat/MRawCrateData.h	(revision 498)
+++ trunk/MagicSoft/include-Classes/MRawFormat/MRawCrateData.h	(revision 498)
@@ -0,0 +1,49 @@
+#ifndef MRAWCRATEDATA_H
+#define MRAWCRATEDATA_H
+
+#ifndef MAGIC_H
+#include "../MBase/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/include-Classes/MRawFormat/MRawEvtData.cc
===================================================================
--- trunk/MagicSoft/include-Classes/MRawFormat/MRawEvtData.cc	(revision 498)
+++ trunk/MagicSoft/include-Classes/MRawFormat/MRawEvtData.cc	(revision 498)
@@ -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 "../MBase/MArrayS.h"
+#include "../MBase/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/include-Classes/MRawFormat/MRawEvtData.h
===================================================================
--- trunk/MagicSoft/include-Classes/MRawFormat/MRawEvtData.h	(revision 498)
+++ trunk/MagicSoft/include-Classes/MRawFormat/MRawEvtData.h	(revision 498)
@@ -0,0 +1,61 @@
+#ifndef MRAWEVTDATA_H
+#define MRAWEVTDATA_H
+
+#ifndef MPARCONTAINER_H
+#include "../MBase/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/include-Classes/MRawFormat/MRawEvtHeader.cc
===================================================================
--- trunk/MagicSoft/include-Classes/MRawFormat/MRawEvtHeader.cc	(revision 498)
+++ trunk/MagicSoft/include-Classes/MRawFormat/MRawEvtHeader.cc	(revision 498)
@@ -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 "../MBase/MTime.h"
+#include "../MBase/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/include-Classes/MRawFormat/MRawEvtHeader.h
===================================================================
--- trunk/MagicSoft/include-Classes/MRawFormat/MRawEvtHeader.h	(revision 498)
+++ trunk/MagicSoft/include-Classes/MRawFormat/MRawEvtHeader.h	(revision 498)
@@ -0,0 +1,54 @@
+#ifndef MRAWEVTHEADER_H
+#define MRAWEVTHEADER_H
+
+#ifndef MPARCONTAINER_H
+#include "../MBase/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/include-Classes/MRawFormat/MRawEvtPixelIter.cc
===================================================================
--- trunk/MagicSoft/include-Classes/MRawFormat/MRawEvtPixelIter.cc	(revision 498)
+++ trunk/MagicSoft/include-Classes/MRawFormat/MRawEvtPixelIter.cc	(revision 498)
@@ -0,0 +1,62 @@
+#include "MRawEvtPixelIter.h"
+
+#include "MRawEvtData.h"
+
+#include "../MBase/MArrayS.h"
+#include "../MBase/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/include-Classes/MRawFormat/MRawEvtPixelIter.h
===================================================================
--- trunk/MagicSoft/include-Classes/MRawFormat/MRawEvtPixelIter.h	(revision 498)
+++ trunk/MagicSoft/include-Classes/MRawFormat/MRawEvtPixelIter.h	(revision 498)
@@ -0,0 +1,81 @@
+#ifndef MRAWEVTPIXELITER_H
+#define MRAWEVTPIXELITER_H
+
+#ifndef MAGIC_H
+#include "../MBase/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/include-Classes/MRawFormat/MRawRunHeader.cc
===================================================================
--- trunk/MagicSoft/include-Classes/MRawFormat/MRawRunHeader.cc	(revision 498)
+++ trunk/MagicSoft/include-Classes/MRawFormat/MRawRunHeader.cc	(revision 498)
@@ -0,0 +1,127 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// MRawRunHeader
+//
+// Root storage container for the RUN HEADER information
+//
+////////////////////////////////////////////////////////////////////////////
+
+#include "MRawRunHeader.h"
+
+#include <fstream.h>
+#include <iomanip.h>
+
+#include "../MBase/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/include-Classes/MRawFormat/MRawRunHeader.h
===================================================================
--- trunk/MagicSoft/include-Classes/MRawFormat/MRawRunHeader.h	(revision 498)
+++ trunk/MagicSoft/include-Classes/MRawFormat/MRawRunHeader.h	(revision 498)
@@ -0,0 +1,83 @@
+#ifndef MRAWRUNHEADER_H
+#define MRAWRUNHEADER_H
+///////////////////////////////////////////////////////////////////////
+//                                                                   //
+// MRunHeader                                                        //
+//                                                                   //
+///////////////////////////////////////////////////////////////////////
+
+#ifndef MPARCONTAINER_H
+#include "../MBase/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/include-Classes/MRawFormat/RawIncl.h
===================================================================
--- trunk/MagicSoft/include-Classes/MRawFormat/RawIncl.h	(revision 498)
+++ trunk/MagicSoft/include-Classes/MRawFormat/RawIncl.h	(revision 498)
@@ -0,0 +1,10 @@
+#ifndef __CINT__
+
+#include "../MBase/MTime.h"
+#include "../MBase/MArrayB.h"
+#include "../MBase/MArrayS.h"
+#include "../MBase/MParList.h"
+
+#include <TClonesArray.h>
+
+#endif // __CINT__
Index: trunk/MagicSoft/include-Classes/MRawFormat/RawLinkDef.h
===================================================================
--- trunk/MagicSoft/include-Classes/MRawFormat/RawLinkDef.h	(revision 498)
+++ trunk/MagicSoft/include-Classes/MRawFormat/RawLinkDef.h	(revision 498)
@@ -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
