Index: /trunk/Mars/Changelog
===================================================================
--- /trunk/Mars/Changelog	(revision 9888)
+++ /trunk/Mars/Changelog	(revision 9889)
@@ -18,4 +18,14 @@
 
                                                  -*-*- END OF LINE -*-*-
+
+ 2010/08/24 Reiner Rohlfs
+
+   * mcorsika/MCorsikaFormat.[h,cc]
+     - in method MCorsikaFormatEventIO::SeekEvtEnd() the RUNE block
+       is first searched at the end of the file. It it is not found
+       the whole file is scanned for the RUNE block. Once it is 
+       found it can be accessed directly at the next call of this
+       function.
+
 
  2010/08/20 Daniela Dorner
Index: /trunk/Mars/mcorsika/MCorsikaFormat.cc
===================================================================
--- /trunk/Mars/mcorsika/MCorsikaFormat.cc	(revision 9888)
+++ /trunk/Mars/mcorsika/MCorsikaFormat.cc	(revision 9889)
@@ -233,10 +233,6 @@
 
         unsigned short fileType = blockHeader[1] & 0xFFFF;
-        if (/*memcmp(blockHeader+5, id, 4) == 0 && */
-            type == fileType                       )
-            {
-//*fLog << all << "found " << id << " type: " << type << endl;
+        if (type == fileType                       )
             break;
-            }
 
          if (type == 1202 && fileType == 1210)
@@ -248,7 +244,8 @@
         // a unknown block, we jump to the next one
 //*fLog << "unknown: " <<  id << " type: " << fileType << " sub-blocks: " <<  (blockHeader[3]>>29);
-//*fLog <<  " length: " << (blockHeader[3] & 0x3fffffff) << endl;
+//*fLog <<  " length: " << (blockHeader[3] & 0x3fffffff) <<   "  pos: " << fIn->tellg() << endl;
         int length = blockHeader[3] & 0x3fffffff;
-        fIn->seekg(length - 2 * sizeof(int), ios::cur);    
+        
+        fIn->seekg(length - 2 * (Int_t)(sizeof(int)), ios::cur);    
     }
 
@@ -261,5 +258,5 @@
 void MCorsikaFormatEventIO::UnreadLastHeader() 
 {
-    fIn->seekg( (int)(-6 * sizeof(int)), ios::cur);
+    fIn->seekg( -6 * (Int_t)(sizeof(int)), ios::cur);
 }
 
@@ -268,10 +265,39 @@
 Bool_t MCorsikaFormatEventIO::SeekEvtEnd()
 {
-    if (SeekNextBlock("RUNE", 1210))
-    {
-        UnreadLastHeader();
+    if (fRunePos != 0)
+        {
+        fIn->seekg(fRunePos, ios::beg);
         return kTRUE;
-    }
-
+        }
+    else
+        {
+        // it is the first time we are looking for the RUNE block
+
+        // is the RUNE block at the very end of the file?
+        std::streampos currentPos = fIn->tellg();
+
+        fIn->seekg(-32, ios::end);
+        unsigned int blockHeader[4];
+        fIn->read((char*)blockHeader, 4 * sizeof(int));
+        if ( blockHeader[0]               == 0xd41f8a37 &&
+            (blockHeader[1] & 0xffff)     == 1210       &&
+            (blockHeader[3] & 0x3fffffff) == 16)
+            {
+            // this seams to be a RUNE (1210)  block
+            fIn->seekg( -4 * (Int_t)(sizeof(int)), ios::cur);
+            fRunePos = fIn->tellg();
+            return kTRUE;
+            }
+
+        // we do not find a RUNE block at the end of the file
+        // we have to search in the file
+        fIn->seekg(currentPos, ios::beg);
+        if (SeekNextBlock("RUNE", 1210))
+            {
+            UnreadLastHeader();
+            fRunePos = fIn->tellg();
+            return kTRUE;
+            }
+        }
     return kFALSE;
 }
@@ -328,5 +354,4 @@
     return kTRUE;
 }
-
 // --------------------------------------------------------------------------
 //                                                                           
@@ -357,12 +382,10 @@
         unsigned short fileType = blockHeader[1] & 0xFFFF;
         if (fileType == 1204)
-{
-*fLog << all << "found new top level block 1204" << endl;
             return kTRUE;
-}
+
         if (fileType == 1209)
             {
             // we found an eventEnd block, reset file pointer
-            fIn->seekg( (Int_t)(-4 * sizeof(Int_t)), ios::cur);
+            fIn->seekg( -4 * (Int_t)(sizeof(Int_t)), ios::cur);
             length = 0;
             return kFALSE;
@@ -371,5 +394,4 @@
 
         // a unknown block, we jump to the next one
-*fLog << all << "found block " << fileType << endl;
         fIn->seekg(length, ios::cur);    
     }
Index: /trunk/Mars/mcorsika/MCorsikaFormat.h
===================================================================
--- /trunk/Mars/mcorsika/MCorsikaFormat.h	(revision 9888)
+++ /trunk/Mars/mcorsika/MCorsikaFormat.h	(revision 9889)
@@ -24,5 +24,5 @@
 public:
    MCorsikaFormat(MLog * log, std::istream * in)
-        : fIn(in) {fLog = log;} 
+        : fIn(in) {fLog = log; } 
    virtual ~MCorsikaFormat();
 
@@ -69,8 +69,9 @@
 {
 private:
+	std::streampos fRunePos; // file position of the RUNE block
 
 public:
    MCorsikaFormatEventIO(MLog * log, std::istream * in)
-        : MCorsikaFormat(log, in) {} 
+        : MCorsikaFormat(log, in) {fRunePos = 0;} 
 
    Bool_t SeekNextBlock(const char * id, unsigned short type);
