Index: trunk/MagicSoft/Mars/mraw/MRawCrateData.cc
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawCrateData.cc	(revision 651)
+++ trunk/MagicSoft/Mars/mraw/MRawCrateData.cc	(revision 654)
@@ -12,5 +12,5 @@
 }
 
-void MRawCrateData::ReadEvt(ifstream& fin)
+void MRawCrateData::ReadEvt(istream& fin)
 {
     //
Index: trunk/MagicSoft/Mars/mraw/MRawCrateData.h
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawCrateData.h	(revision 651)
+++ trunk/MagicSoft/Mars/mraw/MRawCrateData.h	(revision 654)
@@ -42,5 +42,5 @@
     void Print(Option_t *t=NULL);
 
-    void ReadEvt(ifstream& fin);
+    void ReadEvt(istream& fin);
 
     ClassDef(MRawCrateData, 1) //Container to store the Raw CRATE DATA
Index: trunk/MagicSoft/Mars/mraw/MRawEvtData.cc
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawEvtData.cc	(revision 651)
+++ trunk/MagicSoft/Mars/mraw/MRawEvtData.cc	(revision 654)
@@ -216,5 +216,5 @@
 }
 
-void MRawEvtData::DeletePixels()
+void MRawEvtData::DeletePixels(Bool_t flag)
 {
     //
@@ -222,5 +222,5 @@
     //
     DeleteArrays();
-    InitArrays();
+    InitArrays(flag);
 }
 
@@ -233,10 +233,12 @@
 }
 
-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::InitArrays(Bool_t flag)
+{
+    // const int npix = !flag ? 0 : fRunHeader->GetNumCrates()*fRunHeader->GetNumPixInCrate();
+
+    fHiGainPixId       = new MArrayS(0);//npix);
+    fLoGainPixId       = new MArrayS(0);//npix); 
+    fHiGainFadcSamples = new MArrayB(0);//npix*fRunHeader->GetNumSamplesHiGain());
+    fLoGainFadcSamples = new MArrayB(0);//npix*fRunHeader->GetNumSamplesLoGain());
 }
 
@@ -248,5 +250,4 @@
     //  Add to lo gains if lflag = 1
     //
-
     MArrayS *arrpix = lflag ? fLoGainPixId       : fHiGainPixId;
     MArrayB *arrsam = lflag ? fLoGainFadcSamples : fHiGainFadcSamples;
@@ -286,37 +287,5 @@
 }
 
-/*
-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)
+void MRawEvtData::ReadEvt(istream &fin)
 {
     //
@@ -327,8 +296,23 @@
     const UShort_t nhi = fRunHeader->GetNumSamplesHiGain();
 
-    TArrayC lo(nlo);
-    TArrayC hi(nhi);
-
     const UShort_t npic = fRunHeader->GetNumPixInCrate();
+
+    //
+    // Enhance array by the size which we'll read now
+    //
+    Byte_t lo[nlo];
+    Byte_t hi[nhi];
+
+    const int npixhi = fHiGainPixId->GetSize();
+    const int npixlo = fLoGainPixId->GetSize();
+
+    fHiGainPixId->Set(npixhi+npic);
+    fLoGainPixId->Set(npixlo+npic);
+
+    const int nsamhi = fHiGainFadcSamples->GetSize();
+    const int nsamlo = fLoGainFadcSamples->GetSize();
+
+    fHiGainFadcSamples->Set(nsamhi+nhi*npic);
+    fLoGainFadcSamples->Set(nsamlo+nlo*npic);
 
     for (int i=0; i<npic; i++)
@@ -339,12 +323,19 @@
         const UShort_t npix = fRunHeader->GetPixAssignment(i);
 
-        fin.read((Byte_t*)hi.GetArray(), nhi);
-        AddPixel(npix, &hi, kFALSE);
+        //
+        //  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
+        //
+        fin.read(hi, nhi);
+        fHiGainPixId->AddAt(npix, npixhi+i);
+        fHiGainFadcSamples->AddAt(hi, nsamhi+i*nhi, nhi);
 
         // 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(lo, nlo);
+        fLoGainPixId->AddAt(npix, npixlo+i);
+        fLoGainFadcSamples->AddAt(lo, nsamlo+i*nlo, nlo);
         //}
     }
Index: trunk/MagicSoft/Mars/mraw/MRawEvtData.h
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawEvtData.h	(revision 651)
+++ trunk/MagicSoft/Mars/mraw/MRawEvtData.h	(revision 654)
@@ -27,5 +27,5 @@
     MArrayB *fLoGainFadcSamples;  // list of lo gain samples of all pixels (ordering: see fLoGainPixId)
 
-    void InitArrays();
+    void InitArrays(Bool_t flag=kFALSE);
     void DeleteArrays();
 
@@ -47,5 +47,5 @@
     void Draw (Option_t * = NULL);
 
-    void DeletePixels();
+    void DeletePixels(Bool_t flag=kFALSE);
     void AddPixel(UShort_t nOfPixel, TArrayC *data, Bool_t lflag=kFALSE);
 
@@ -54,5 +54,5 @@
     Byte_t GetNumPixels() const;
 
-    void ReadEvt(ifstream &fin);
+    void ReadEvt(istream &fin);
 
     ClassDef(MRawEvtData, 1) //Container to store the raw Event Data
Index: trunk/MagicSoft/Mars/mraw/MRawEvtHeader.cc
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawEvtHeader.cc	(revision 651)
+++ trunk/MagicSoft/Mars/mraw/MRawEvtHeader.cc	(revision 654)
@@ -169,5 +169,5 @@
     *fLog << "Number of Lo Gains On: " << fNumLoGainOn << endl;
 
-    for (int i=0; i<fPixLoGainOn->GetSize(); i++)
+    for (unsigned int i=0; i<fPixLoGainOn->GetSize(); i++)
     {
         for (int j=0; j<8; j++)
@@ -194,5 +194,5 @@
 }
 
-int MRawEvtHeader::ReadEvt(ifstream &fin)
+int MRawEvtHeader::ReadEvt(istream &fin)
 {
     //
@@ -220,5 +220,5 @@
 
     fNumLoGainOn = 0;
-    for (int i=0; i<fPixLoGainOn->GetSize(); i++)
+    for (unsigned int i=0; i<fPixLoGainOn->GetSize(); i++)
         for (int j=0; j<8; j++)
             if ((*fPixLoGainOn)[i] & (1<<j))
Index: trunk/MagicSoft/Mars/mraw/MRawEvtHeader.h
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawEvtHeader.h	(revision 651)
+++ trunk/MagicSoft/Mars/mraw/MRawEvtHeader.h	(revision 654)
@@ -46,5 +46,5 @@
   UShort_t GetTrigType() const { return fTrigType; }
 
-  int ReadEvt(ifstream& fin);
+  int ReadEvt(istream& fin);
 
   ClassDef(MRawEvtHeader, 1) // Parameter Conatiner for raw EVENT HEADER
Index: trunk/MagicSoft/Mars/mraw/MRawFileRead.cc
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawFileRead.cc	(revision 651)
+++ trunk/MagicSoft/Mars/mraw/MRawFileRead.cc	(revision 654)
@@ -24,4 +24,35 @@
 ClassImp(MRawFileRead)
 
+/*
+  ----------- please don't delete ------------
+#define kBUFSZ 1024
+
+class bifstream : public istream, public streambuf
+{
+private:
+    char fBuffer[kBUFSZ]; //!
+    FILE *fd;
+
+    int sync()
+    {
+        memset(fBuffer, 0, kBUFSZ);
+        return 0; 
+    }
+    int underflow()
+    {
+        int sz=fread(fBuffer, 1, kBUFSZ, fd);
+        setg(fBuffer, fBuffer, fBuffer+kBUFSZ);
+
+        return sz==kBUFSZ ? *(unsigned char*)fBuffer : EOF;//EOF;
+    }
+public:
+    bifstream(const char *name) : istream(this)
+    {
+        fd = fopen(name, "rb");
+        setbuf(fBuffer, kBUFSZ);
+    }
+};
+*/
+
 MRawFileRead::MRawFileRead(const char *fname, const char *name, const char *title)
 {
@@ -38,10 +69,14 @@
 }
 
-Bool_t MRawFileRead::PreProcess (MParList *pList)
+MRawFileRead::~MRawFileRead()
+{
+    delete fIn;
+}
+
+Bool_t MRawFileRead::PreProcess(MParList *pList)
 {
     //
     // remember the pointer to the parameter list fur further usage
     //
-    pParList = pList;
 
     //
@@ -103,5 +138,5 @@
     return kTRUE;
 }
-    
+
 Bool_t MRawFileRead::Process()
 {
@@ -112,5 +147,4 @@
     if (!fRawEvtHeader->ReadEvt(*fIn))
         return kFALSE;
-    //fRawEvtHeader->Print();
 
     //
@@ -135,12 +169,9 @@
     {
         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 651)
+++ trunk/MagicSoft/Mars/mraw/MRawFileRead.h	(revision 654)
@@ -18,16 +18,15 @@
 {
 private:
-    MParList *pParList;
+    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
 
-    MRawRunHeader  *fRawRunHeader;
-    MRawEvtHeader  *fRawEvtHeader;
-    MRawEvtData    *fRawEvtData;
-    MRawCrateArray *fRawCrateArray;
-    MTime          *fRawEvtTime;
-
-    ifstream *fIn; //!
+    ifstream      *fIn;            //! buffered input stream (file to read from)
 
 public:
     MRawFileRead(const char *filename, const char *name=NULL, const char *title=NULL);
+    ~MRawFileRead();
 
     Bool_t PreProcess(MParList *pList);
Index: trunk/MagicSoft/Mars/mraw/MRawRunHeader.cc
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawRunHeader.cc	(revision 651)
+++ trunk/MagicSoft/Mars/mraw/MRawRunHeader.cc	(revision 654)
@@ -33,5 +33,5 @@
 }
 
-void MRawRunHeader::ReadEvt(ifstream& fin)
+void MRawRunHeader::ReadEvt(istream& fin)
 {
     //
@@ -87,4 +87,5 @@
     // print run header information on screen
     //
+    *fLog << endl;
     *fLog << "MagicNumber:  0x" << hex << fMagicNumber << " - " << (fMagicNumber==0xc0c0?"OK":"Wrong!") << endl;
     *fLog << "Version:      " << dec << "Format=" << fFormatVersion << "  ";
Index: trunk/MagicSoft/Mars/mraw/MRawRunHeader.h
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawRunHeader.h	(revision 651)
+++ trunk/MagicSoft/Mars/mraw/MRawRunHeader.h	(revision 654)
@@ -11,4 +11,5 @@
 #endif
 
+class TBuffer;
 class ifstream;
 class MArrayS;
@@ -77,5 +78,5 @@
     void Print(Option_t *t=NULL);
 
-    void ReadEvt(ifstream& fin);
+    void ReadEvt(istream& fin);
 
     ClassDef(MRawRunHeader, 1)	// storage container for general info
