Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 6455)
+++ trunk/MagicSoft/Mars/Changelog	(revision 6456)
@@ -43,4 +43,7 @@
        too much by the start of data taking
      - fixed setting of mean time corresponding to rate-interval
+
+   * mraw/MRawFileRead.[h,cc]:
+     - calculate total number of events from all files in PreProcess
 
 
Index: trunk/MagicSoft/Mars/mraw/MRawFileRead.cc
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawFileRead.cc	(revision 6455)
+++ trunk/MagicSoft/Mars/mraw/MRawFileRead.cc	(revision 6456)
@@ -165,5 +165,5 @@
 // This opens the next file in the list and deletes its name from the list.
 //
-Int_t MRawFileRead::OpenNextFile()
+Int_t MRawFileRead::OpenNextFile(Bool_t print)
 {
     //
@@ -217,4 +217,7 @@
     }
 
+    if (!print)
+        return kTRUE;
+
     //
     // Print Run Header
@@ -271,4 +274,33 @@
     fNumEvents=0;
     return OpenNextFile()==kTRUE;
+}
+
+Bool_t MRawFileRead::CalcNumTotalEvents()
+{
+    fNumTotalEvents = 0;
+
+    Bool_t rc = kTRUE;
+
+    while (1)
+    {
+        switch (OpenNextFile(kFALSE))
+        {
+        case kFALSE:
+            break;
+        case kERROR:
+            rc = kFALSE;
+            break;
+        case kTRUE:
+            fNumTotalEvents += fRawRunHeader->GetNumEvents();
+            continue;
+        }
+        break;
+    }
+
+    if (fIn)
+        delete fIn;
+    fIn = NULL;
+
+    return rc;
 }
 
@@ -301,13 +333,11 @@
         return kFALSE;
 
-    //
-    // Now open next (first) file
-    //
-//      if (!Rewind())
-//          return kFALSE;
-
+    *fLog << inf << "Calculating number of total events..." << flush;
+    if (!CalcNumTotalEvents())
+        return kFALSE;
+    *fLog << inf << " " << fNumTotalEvents << " found." << endl;
 
     fNumFile=0;
-    fNumEvents=0; 
+    fNumEvents=0;
 
     return kTRUE;
Index: trunk/MagicSoft/Mars/mraw/MRawFileRead.h
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawFileRead.h	(revision 6455)
+++ trunk/MagicSoft/Mars/mraw/MRawFileRead.h	(revision 6456)
@@ -12,15 +12,17 @@
 {
 private:
-    TList     *fFileNames; // list of file names
-    UInt_t     fNumFile;   //! number of next file
-    UInt_t     fNumEvents; //! input stream (file to read from)
+    TList     *fFileNames;      // list of file names
+    UInt_t     fNumFile;        //! number of next file
+    UInt_t     fNumEvents;      //! input stream (file to read from)
+    UInt_t     fNumTotalEvents; //! total number of events in all files
 
-    ifstream  *fIn;        //! input stream (file to read from)
+    ifstream  *fIn;             //! input stream (file to read from)
 
-    MParList  *fParList;   //! tasklist to call ReInit from
+    MParList  *fParList;        //! tasklist to call ReInit from
 
     UInt_t     fInterleave;
 
-    Int_t OpenNextFile();
+    Int_t  OpenNextFile(Bool_t print=kTRUE);
+    Bool_t CalcNumTotalEvents();
 
     Int_t PreProcess(MParList *pList);
@@ -40,4 +42,5 @@
     Int_t  AddFile(const char *fname, Int_t entries=-1);
     Bool_t Rewind();
+    UInt_t GetEntries() { return fNumTotalEvents/fInterleave; }
 
     ClassDef(MRawFileRead, 0)	// Task to read the raw data binary file
