Index: trunk/MagicSoft/Mars/msim/MPhotonData.cc
===================================================================
--- trunk/MagicSoft/Mars/msim/MPhotonData.cc	(revision 9595)
+++ trunk/MagicSoft/Mars/msim/MPhotonData.cc	(revision 9616)
@@ -245,4 +245,33 @@
 // --------------------------------------------------------------------------
 //
+// Set the data member according to the 8 floats read from a eventio-file.
+// This function MUST reset all data-members, no matter whether these are
+// contained in the input stream.
+//
+// Currently we exchange x and y and set y=-y to convert Corsikas coordinate
+// system into our own.
+//
+Int_t MPhotonData::FillEventIO(Float_t f[8])
+{
+    fPosX             =  f[1]; // xpos relative to telescope [cm]
+    fPosY             = -f[0]; // ypos relative to telescope [cm]
+    fCosU             =  f[3]; // cos to x
+    fCosV             = -f[2]; // cos to y
+    fTime             =  f[4]; // a relative arival time [ns]
+    fProductionHeight =  f[5]; // altitude of emission [cm]
+    fNumPhotons       =  f[6]; // photons in this bunch
+    fWavelength       =  f[7]; // so far always zeor = unspec. [nm]
+
+
+    // Now reset all data members which are not in the stream
+    fPrimary    = MMcEvtBasic::kUNDEFINED;
+    fTag        = -1;
+    fWeight     =  1;
+
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
 // Read seven floats from the stream and call FillCorsika for them.
 //
Index: trunk/MagicSoft/Mars/msim/MPhotonData.h
===================================================================
--- trunk/MagicSoft/Mars/msim/MPhotonData.h	(revision 9595)
+++ trunk/MagicSoft/Mars/msim/MPhotonData.h	(revision 9616)
@@ -133,4 +133,5 @@
 
     Int_t FillCorsika(Float_t f[7]);
+    Int_t FillEventIO(Float_t f[7]);
     Int_t FillRfl(Float_t f[8]);
 
Index: trunk/MagicSoft/Mars/msim/MPhotonEvent.cc
===================================================================
--- trunk/MagicSoft/Mars/msim/MPhotonEvent.cc	(revision 9595)
+++ trunk/MagicSoft/Mars/msim/MPhotonEvent.cc	(revision 9616)
@@ -121,4 +121,5 @@
 
 #include "MPhotonData.h"
+#include "MCorsikaFormat.h"
 
 ClassImp(MPhotonEvent);
@@ -452,5 +453,5 @@
 // Read the Event section from the file
 //
-Int_t MPhotonEvent::ReadCorsikaEvt(istream &fin)
+Int_t MPhotonEvent::ReadCorsikaEvt(MCorsikaFormat * fInFormat)
 {
     Int_t n = 0;
@@ -482,24 +483,63 @@
     // 1.06GB/ 3s   CPU
     // 1.06GB/22s   REAL
+    Bool_t readError = kFALSE;
+    Float_t * buffer;
+
+    if ( fInFormat->IsEventioFormat() )
+        {
+        while (fInFormat->GetNextEvent(&buffer, readError))
+            {
+
+            const Int_t rc = Add(n).FillEventIO(buffer);
+            switch (rc)
+            {
+            case kCONTINUE:  continue;        // No data in this bunch... skip it.
+            case kERROR:     return kERROR;   // Error occured
+            //case kFALSE:     return kFALSE;   // End of stream
+            }
+
+            // This is a photon we would like to keep later.
+            // Increase the counter by one
+            n++;
+            }
+        }
+    else
+        {
+        while (fInFormat->GetNextEvent(&buffer, readError))
+            {
+
+            const Int_t rc = Add(n).FillCorsika(buffer);
+            switch (rc)
+            {
+            case kCONTINUE:  continue;        // No data in this bunch... skip it.
+            case kERROR:     return kERROR;   // Error occured
+            //case kFALSE:     return kFALSE;   // End of stream
+            }
+
+            // This is a photon we would like to keep later.
+            // Increase the counter by one
+            n++;
+            }
+        }
+     if (readError)      return kFALSE;
+
+/*
 
     while (1)
     {
-        // Stprage for one block
-        char c[273*4];
-
-        // Read the first four byte to check whether the next block
-        // doen't belong to the event anymore
-        fin.read(c, 4);
-        if (!fin)
+        Float_t buffer[273];
+        Float_t * ptr = buffer;
+
+
+        if (!fInFormat->ReadData(273, buffer))
             return kFALSE;
 
-        // Check if the event is finished
-        if (!memcmp(c, "EVTE", 4))
+        if (!memcmp(ptr, "EVTE", 4))
+            {
+
+            fInFormat->UnreadLastData();
             break;
-
-        // Now read the rest of the data
-        fin.read(c+4, 272*4);
-
-        Float_t *ptr = reinterpret_cast<Float_t*>(c);
+            }
+
         Float_t *end = ptr + 273;
 
@@ -525,4 +565,89 @@
         }
     }
+
+*/
+    Resize(n);
+    fData.UnSort();
+
+    SetReadyToSave();
+
+    //*fLog << all << "Number of photon bunches: " << fData.GetEntriesFast() << endl;
+    return kTRUE;
+
+}
+
+Int_t MPhotonEvent::ReadCorsikaEvt(istream &fin)
+{
+    Int_t n = 0;
+
+    // --- old I/O ---
+    // Read only + Reflector (no absorption)
+    // Muons:   1.06GB/115s =  9.2MB/s (100kEvs)
+    // Gammas:  1.57GB/275s =  5.7MB/s (  1kEvs)
+
+    // Read only:
+    // Gammas:  1.57GB/158s =  9.9MB/s (  1kEvs)
+    // Muons:   1.06GB/ 77s = 13.8MB/s (100kEvs)
+
+    // --- new I/O ---
+    // Read only (don't allocate storage space):
+    // Gammas:  1.57GB/143s = 11.0MB/s (  1kEvs)
+    // Muons:   1.06GB/ 77s = 13.8MB/s (100kEvs)
+
+    // Read only in blocks (with storage allocation):
+    // Gammas:  1.57GB/28s  =  56MB/s (  1kEvs)
+    // Muons:   1.06GB/5.2s = 204MB/s (100kEvs)
+
+    // Read only in blocks (without storage allocation):
+    // similar to just copy
+
+    // Copy with cp
+    // 1.57GB/ 5s   CPU
+    // 1.57GB/28s   REAL
+    // 1.06GB/ 3s   CPU
+    // 1.06GB/22s   REAL
+
+    while (1)
+    {
+        // Stprage for one block
+        char c[273*4];
+
+        // Read the first four byte to check whether the next block
+        // doen't belong to the event anymore
+        fin.read(c, 4);
+        if (!fin)
+            return kFALSE;
+
+        // Check if the event is finished
+        if (!memcmp(c, "EVTE", 4))
+            break;
+
+        // Now read the rest of the data
+        fin.read(c+4, 272*4);
+
+        Float_t *ptr = reinterpret_cast<Float_t*>(c);
+        Float_t *end = ptr + 273;
+
+        // Loop over all sub-blocks (photons) in the block and if
+        // they contain valid data add them to the array
+        while (ptr<end)
+        {
+            // Get/Add the n-th entry from the array and
+            // fill it with the current 7 floats
+            const Int_t rc = Add(n).FillCorsika(ptr);
+            ptr += 7;
+
+            switch (rc)
+            {
+            case kCONTINUE:  continue;        // No data in this bunch... skip it.
+            case kERROR:     return kERROR;   // Error occured
+            //case kFALSE:     return kFALSE;   // End of stream
+            }
+
+            // This is a photon we would like to keep later.
+            // Increase the counter by one
+            n++;
+        }
+    }
 /*
     while (1)
Index: trunk/MagicSoft/Mars/msim/MPhotonEvent.h
===================================================================
--- trunk/MagicSoft/Mars/msim/MPhotonEvent.h	(revision 9595)
+++ trunk/MagicSoft/Mars/msim/MPhotonEvent.h	(revision 9616)
@@ -16,4 +16,5 @@
 class MPhotonData;
 class MCorsikaRunHeader;
+class MCorsikaFormat;
 
 class MPhotonEvent : public MParContainer
@@ -52,4 +53,5 @@
 
     // I/O
+    Int_t ReadCorsikaEvt(MCorsikaFormat * fInFormat);
     Int_t ReadCorsikaEvt(istream &fin);
     Int_t ReadRflEvt(istream &fin);
