Index: /trunk/Mars/Changelog
===================================================================
--- /trunk/Mars/Changelog	(revision 9948)
+++ /trunk/Mars/Changelog	(revision 9949)
@@ -23,4 +23,16 @@
    * msimreflector/MMirrorSquare.[h,cc]:
      - implemented WriteM
+
+   * mcorsika/MCorsikaEvtHeader.cc, mcorsika/MCorsikaFormat.[h,cc],
+     mcorsika/MCorsikaRunHeader.cc:
+     - fixed a problem with reading the RUNE section in corsikas 
+       raw format
+
+   * readcorsika.cc:
+     - speed up reading by ot printing the single photons if debug
+       level less than 3
+
+   * msim/MPhotonEvent.cc:
+     - don't loop over all (mostly empty) slots in Print()
 
 
Index: /trunk/Mars/mcorsika/MCorsikaEvtHeader.cc
===================================================================
--- /trunk/Mars/mcorsika/MCorsikaEvtHeader.cc	(revision 9948)
+++ /trunk/Mars/mcorsika/MCorsikaEvtHeader.cc	(revision 9949)
@@ -129,10 +129,11 @@
 Int_t MCorsikaEvtHeader::ReadEvt(MCorsikaFormat *fInFormat)
 {
-    if (!fInFormat->SeekNextBlock("EVTH", 1202))
-        return kFALSE;
+    const Int_t rc=fInFormat->SeekNextBlock("EVTH", 1202);
+    if (rc!=kTRUE)
+        return rc;
 
     Float_t f[273];
     if (!fInFormat->ReadData(272, f))
-        return kFALSE;
+        return kERROR;
 
     fEvtNumber  = TMath::Nint(f[0]);
@@ -169,5 +170,5 @@
     fWeightedNumPhotons = 0;
 
-    return !fInFormat->Eof();
+    return fInFormat->Eof() ? kERROR : kTRUE;
 }
 
@@ -177,13 +178,12 @@
 Int_t MCorsikaEvtHeader::ReadEvtEnd(MCorsikaFormat * fInFormat)
 {
-    if (!fInFormat->SeekNextBlock("EVTE", 1209))
-        return kFALSE;
+    if (fInFormat->SeekNextBlock("EVTE", 1209)!=kTRUE)
+        return kERROR;
 
     //fin.seekg(-1088,ios::cur);
 
     Float_t f[2];
-
     if (!fInFormat->ReadData(2, f))
-        return kFALSE;
+        return kERROR;
 
     const UInt_t evtnum = TMath::Nint(f[0]);
@@ -199,4 +199,4 @@
     fWeightedNumPhotons = f[1];
 
-    return !fInFormat->Eof();
-}
+    return fInFormat->Eof() ? kERROR : kTRUE;
+}
Index: /trunk/Mars/mcorsika/MCorsikaFormat.cc
===================================================================
--- /trunk/Mars/mcorsika/MCorsikaFormat.cc	(revision 9948)
+++ /trunk/Mars/mcorsika/MCorsikaFormat.cc	(revision 9949)
@@ -151,5 +151,5 @@
 // of the id.
 //
-Bool_t MCorsikaFormatRaw::SeekNextBlock(const char * id, unsigned short type) const
+Int_t MCorsikaFormatRaw::SeekNextBlock(const char * id, unsigned short type) const
 {
     char blockHeader[5]="\0\0\0\0";
@@ -162,11 +162,11 @@
     // but find the end of a run. This is expected, therefor no error
     // message.
-    if (strcmp(id, "EVTH")==0 && strcmp(blockHeader, "RUNE")==0)
-        return kTRUE;
+    if (strcmp(blockHeader, "RUNE")==0)
+        return kFALSE;
 
     gLog << err << "ERROR - Wrong identifier: " << id << " expected.";
     gLog << " But read " << blockHeader << " from file." << endl;
 
-    return kFALSE;
+    return kERROR;
 }
 
@@ -182,5 +182,4 @@
 Bool_t MCorsikaFormatRaw::SeekEvtEnd()
 {
-
     // Search subblockwise backward (Block: 5733*4 = 21*273*4)
     for (int i=1; i<22; i++)
@@ -250,5 +249,5 @@
 // of the id.
 //
-Bool_t MCorsikaFormatEventIO::SeekNextBlock(const char * id, unsigned short type) const
+Int_t MCorsikaFormatEventIO::SeekNextBlock(const char * id, unsigned short type) const
 {
     cout << "Seek " << type << endl;
@@ -267,5 +266,5 @@
         {
             gLog << err << "MCorsikaFormatEventIO::SeekNextBlock: ERROR - Unexpected end-of-file seeking " << id << " (" << type << ")." << endl;
-            return kFALSE;
+            return kERROR;
         }
 
@@ -343,5 +342,5 @@
     // we have to search in the file
     fIn->seekg(currentPos, ios::beg);
-    if (!SeekNextBlock("RUNE", 1210))
+    if (SeekNextBlock("RUNE", 1210)!=kTRUE)
         return kFALSE;
 
Index: /trunk/Mars/mcorsika/MCorsikaFormat.h
===================================================================
--- /trunk/Mars/mcorsika/MCorsikaFormat.h	(revision 9948)
+++ /trunk/Mars/mcorsika/MCorsikaFormat.h	(revision 9949)
@@ -27,5 +27,5 @@
    virtual ~MCorsikaFormat();
 
-   virtual Bool_t SeekNextBlock(const char * id, unsigned short type) const = 0;
+   virtual Int_t  SeekNextBlock(const char * id, unsigned short type) const = 0;
    virtual void   UnreadLastHeader() const = 0;
 
@@ -60,5 +60,5 @@
         : MCorsikaFormat(in) {}
 
-   Bool_t SeekNextBlock(const char * id, unsigned short type) const;
+   Int_t  SeekNextBlock(const char * id, unsigned short type) const;
    void   UnreadLastHeader() const;
 
@@ -79,5 +79,5 @@
         : MCorsikaFormat(in) {fRunePos = std::streampos(0);}
 
-    Bool_t SeekNextBlock(const char *id, unsigned short type) const;
+    Int_t  SeekNextBlock(const char *id, unsigned short type) const;
     void   UnreadLastHeader() const;
 
Index: /trunk/Mars/mcorsika/MCorsikaRunHeader.cc
===================================================================
--- /trunk/Mars/mcorsika/MCorsikaRunHeader.cc	(revision 9948)
+++ /trunk/Mars/mcorsika/MCorsikaRunHeader.cc	(revision 9949)
@@ -85,5 +85,5 @@
 Bool_t MCorsikaRunHeader::ReadEvt(MCorsikaFormat * fInFormat)
 {
-    if (!fInFormat->SeekNextBlock("RUNH", 1200))
+    if (fInFormat->SeekNextBlock("RUNH", 1200)!=kTRUE)
         return kFALSE;
 
@@ -158,5 +158,5 @@
     // f[145] Muon multiple scattering flag
 
-    if (!fInFormat->SeekNextBlock("EVTH", 1202))
+    if (fInFormat->SeekNextBlock("EVTH", 1202)!=kTRUE)
         return kFALSE;
 
@@ -221,6 +221,5 @@
 Bool_t MCorsikaRunHeader::ReadEvtEnd(MCorsikaFormat * fInFormat)
 {
-
-    if (!fInFormat->SeekNextBlock("RUNE", 1210))
+    if (fInFormat->SeekNextBlock("RUNE", 1210)!=kTRUE)
         return kFALSE;
 
Index: /trunk/Mars/msim/MPhotonEvent.cc
===================================================================
--- /trunk/Mars/msim/MPhotonEvent.cc	(revision 9948)
+++ /trunk/Mars/msim/MPhotonEvent.cc	(revision 9949)
@@ -398,11 +398,12 @@
 Int_t MPhotonEvent::GetNumExternal() const
 {
-    Int_t n=0;
-
-    for (int i=0; i<GetNumPhotons(); i++)
+    const Int_t n=GetNumPhotons();
+
+    Int_t rc = 0;
+    for (int i=0; i<n; i++)
         if ((*this)[i].GetPrimary()!=MMcEvtBasic::kNightSky)
-            n++;
-
-    return n;
+            rc++;
+
+    return rc;
 }
 
@@ -816,4 +817,5 @@
 }
 */
+
 // --------------------------------------------------------------------------
 //
@@ -822,5 +824,9 @@
 void MPhotonEvent::Print(Option_t *) const
 {
-    fData.Print();
+    // This is much faster than looping over all entries and discarding
+    // the empty ones
+    const UInt_t n = GetNumPhotons();
+    for (UInt_t i=0; i<n; i++)
+        operator[](i).Print();
 }
 
Index: /trunk/Mars/readcorsika.cc
===================================================================
--- /trunk/Mars/readcorsika.cc	(revision 9948)
+++ /trunk/Mars/readcorsika.cc	(revision 9949)
@@ -164,5 +164,6 @@
         tasks.AddToList(&print0);
         tasks.AddToList(&print1);
-        tasks.AddToList(&print4);
+        if (gLog.GetDebugLevel()>2)
+            tasks.AddToList(&print4);
     }
     else
