Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 8945)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 8946)
@@ -22,4 +22,49 @@
  2008/06/12 Thomas Bretz
 
+   * mraw/MRawCrateData.[h,cc], mraw/MRawEvtHeader.[h,cc],
+     mraw/MRawRunHeader.[h,cc]:
+     - renamed reading the old format to ReadEvtOld
+     - implemented reading format>10
+     - added the header size as new argument to ReadEvt
+
+   * mraw/MRawEvtHeader.cc:
+     - made the argument to DecodeTime const
+     - fixed the return value in ReadEvtOld. kCONTINUE could
+       never be returned
+
+   * mraw/MRawRead.cc:
+     - gives header size for format>10 to ReadEvt
+     - if EvtHeader could not be read correctly return kFALSE
+     - let MRawCrateData::ReadEvt check end-of-file
+
+   * merpp.cc:
+     - improved explanation for -ff option
+
+   * readdaq.cc:
+     - added -ff option
+     - added an option to call MReadRawFiles::SetForceMode
+
+   * mbase/MTime.[h,cc]:
+     - added new member function SetBinary to easy processing
+       of the time from the new run header
+
+   * mhflux/MHEffectiveOnTime.cc:
+     - for the integral (Nm) we have to count also events in under and
+       overflow bins
+
+   * mjobs/MJCalibrateSignal.cc, mjobs/MJCalibration.cc, 
+     mjobs/MJPedestal.cc:
+     - call MRawFileRead::SetForceMode to get the (corrected)
+       old behaviour back (not to stop if an event time is
+       broken but to skip the event)
+
+   * mraw/MRawRunHeader.[h,cc]:
+     - the number of events in format version V9 seems to be
+       to high by one. We correct for this.
+     - added new data members for the header sizes
+     - new data member for the file number
+     - increased cize of fSourceEpochChar
+     - consequently increased class version number by 1
+
    * datacenter/macros/plotdb.C:
      - improved some titles
@@ -85,8 +130,4 @@
        This ensures that no task can crash due to this
        when processing MCs
-
-   * mraw/MRawRunHeader.cc:
-     - the number of events in format version V9 seems to be
-       to high by one. We correct for this.
 
    * msql/MSQLMagic.[h,cc]:
Index: /trunk/MagicSoft/Mars/NEWS
===================================================================
--- /trunk/MagicSoft/Mars/NEWS	(revision 8945)
+++ /trunk/MagicSoft/Mars/NEWS	(revision 8946)
@@ -70,4 +70,10 @@
 
    * Implemented cc file version 2008-20-02/0
+
+   * Implemented raw data format 11 (the most important change, except
+     from plenty of changes in the format definition, is the addition
+     of the file-number in the header) If nobody makes a mistake this
+     format should have the advantage that it is by definition forward
+     compatible, so old programs will be able to read newer formats.
 
    * Added Pyrometer information to output (stored in a new Tree
Index: /trunk/MagicSoft/Mars/mbase/MTime.cc
===================================================================
--- /trunk/MagicSoft/Mars/mbase/MTime.cc	(revision 8945)
+++ /trunk/MagicSoft/Mars/mbase/MTime.cc	(revision 8946)
@@ -827,4 +827,9 @@
 } 
 
+Bool_t MTime::SetBinary(const UInt_t t[6])
+{
+    return Set(t[0], t[1], t[2], t[3], t[4], t[5], 0);
+}
+
 istream &MTime::ReadBinary(istream &fin)
 {
Index: /trunk/MagicSoft/Mars/mbase/MTime.h
===================================================================
--- /trunk/MagicSoft/Mars/mbase/MTime.h	(revision 8945)
+++ /trunk/MagicSoft/Mars/mbase/MTime.h	(revision 8946)
@@ -98,4 +98,5 @@
     void     SetCorsikaTime(Float_t time);
     Bool_t   SetStringFmt(const char *time, const char *fmt, const char *loc=0);
+    Bool_t   SetBinary(const UInt_t t[6]);
     Bool_t   UpdMagicTime(Byte_t h, Byte_t m, Byte_t s, UInt_t ns);
     Bool_t   SetMjd(UInt_t mjd, ULong_t ms, UInt_t ns=0);
Index: /trunk/MagicSoft/Mars/merpp.cc
===================================================================
--- /trunk/MagicSoft/Mars/merpp.cc	(revision 8945)
+++ /trunk/MagicSoft/Mars/merpp.cc	(revision 8946)
@@ -79,5 +79,5 @@
     gLog << "   -u, --update              Update an existing file." << endl << endl;
     gLog << " Raw Data Options:" << endl;
-    gLog << "   -ff                       Force merpp to ignore broken events" << endl;
+    gLog << "   -ff                       Force merpp to ignore broken events and don't stop" << endl;
     gLog << "   --interleave=#            Process only each i-th event [default=1]" << endl << endl;
 //    gLog << "   --sql=mysql://user:password@url  Insert run into database" << endl << endl;
Index: /trunk/MagicSoft/Mars/mhflux/MHEffectiveOnTime.cc
===================================================================
--- /trunk/MagicSoft/Mars/mhflux/MHEffectiveOnTime.cc	(revision 8945)
+++ /trunk/MagicSoft/Mars/mhflux/MHEffectiveOnTime.cc	(revision 8946)
@@ -501,5 +501,6 @@
 Bool_t MHEffectiveOnTime::FitH(TH1D *h, Double_t *res, Bool_t paint) const
 {
-    const Double_t Nm = h->Integral();
+    // Count also events in under-/overflowbins
+    const Double_t Nm = h->Integral(0, h->GetNbinsX()+1);
 
     // FIXME: Do fit only if contents of bin has changed
Index: /trunk/MagicSoft/Mars/mjobs/MJCalibrateSignal.cc
===================================================================
--- /trunk/MagicSoft/Mars/mjobs/MJCalibrateSignal.cc	(revision 8945)
+++ /trunk/MagicSoft/Mars/mjobs/MJCalibrateSignal.cc	(revision 8946)
@@ -369,4 +369,5 @@
 
     MRawFileRead rawread(NULL);
+    reawread.SetForceMode(); // Ignore broken time-stamps
 
     MRead *read = fSequence.IsMonteCarlo() ? (MRead*)&readmc : (MRead*)&rawread;
Index: /trunk/MagicSoft/Mars/mjobs/MJCalibration.cc
===================================================================
--- /trunk/MagicSoft/Mars/mjobs/MJCalibration.cc	(revision 8945)
+++ /trunk/MagicSoft/Mars/mjobs/MJCalibration.cc	(revision 8946)
@@ -1693,4 +1693,5 @@
     MReadMarsFile read("Events");
     MRawFileRead rawread(NULL);
+    reawread.SetForceMode(); // Ignore broken time-stamps
 
     if (!fSequence.IsMonteCarlo())
Index: /trunk/MagicSoft/Mars/mjobs/MJPedestal.cc
===================================================================
--- /trunk/MagicSoft/Mars/mjobs/MJPedestal.cc	(revision 8945)
+++ /trunk/MagicSoft/Mars/mjobs/MJPedestal.cc	(revision 8946)
@@ -1015,4 +1015,5 @@
     MReadMarsFile read("Events");
     MRawFileRead rawread(NULL);
+    reawread.SetForceMode(); // Ignore broken time-stamps
 
     MDirIter iter;
Index: /trunk/MagicSoft/Mars/mraw/MRawRunHeader.cc
===================================================================
--- /trunk/MagicSoft/Mars/mraw/MRawRunHeader.cc	(revision 8945)
+++ /trunk/MagicSoft/Mars/mraw/MRawRunHeader.cc	(revision 8946)
@@ -18,5 +18,5 @@
 !   Author(s): Thomas Bretz 12/2000 <mailto:tbretz@astro.uni-wuerzburg.de>
 !
-!   Copyright: MAGIC Software Development, 2000-2007
+!   Copyright: MAGIC Software Development, 2000-2008
 !
 !
@@ -32,4 +32,19 @@
 //  RAW DATA FORMAT VERSION
 //  =======================
+//
+//  Format Version 11:
+//  -----------------
+//   * all variables got four bytes
+//   * header sizes allow to make the format backward compatible
+//   + fHeaderSizeRun
+//   + fHeaderSizeEvt
+//   + fHeaderSizeCrate
+//   + fFileNumber
+//   + fNumSamplesRemovedHead
+//   + fNumSamplesRemovedTail
+//
+//  Format Version 10:
+//  -----------------
+//    ?
 //
 //  Format Version 9:
@@ -81,4 +96,12 @@
 //  MRawRunHeader CLASS VERSION
 //  ===========================
+//
+//  Format Version 10:
+//  -----------------
+//   - added fHeaderSizeRun
+//   - added fHeaderSizeEvt
+//   - added fHeaderSizeCrate
+//   - added fFileNumber
+//   - increased fSourceEpochChar
 //
 //  Format Version 7:
@@ -127,4 +150,6 @@
 #include <iomanip>
 
+#include <TArrayC.h>
+
 #include "MLog.h"
 #include "MLogManip.h"
@@ -137,5 +162,5 @@
 
 const UShort_t MRawRunHeader::kMagicNumber      = 0xc0c0;
-const Byte_t   MRawRunHeader::kMaxFormatVersion =      9;
+const Byte_t   MRawRunHeader::kMaxFormatVersion =     11;
 
 // --------------------------------------------------------------------------
@@ -162,4 +187,5 @@
     fRunType=kRTNone;  // use 0xffff for invalidation, 0 means: Data run
     fRunNumber=0;
+    fFileNumber=0;
     memset(fProjectName,     0, 101);
     memset(fSourceName,      0,  81);
@@ -329,6 +355,4 @@
 //   "corrected" also in the signal. Hence signal swapped since 99354
 //
-// --------------------------------------------------------------------------
-
 Bool_t MRawRunHeader::FixAssignment()
 {
@@ -374,37 +398,8 @@
 // --------------------------------------------------------------------------
 //
-// Read in one run header from the binary file
-//
-Bool_t MRawRunHeader::ReadEvt(istream& fin)
-{
-    //
-    // read one RUN HEADER from the input stream
-    //
-    fMagicNumber = 0;
-
-    fin.read((char*)&fMagicNumber, 2);          // Total=2
-
-    //
-    // check whether the the file has the right file type or not
-    //
-    if (fMagicNumber != kMagicNumber && fMagicNumber != kMagicNumber+1)
-    {
-        *fLog << err << "ERROR - Wrong Magic Number (0x" << hex << fMagicNumber << "): Not a Magic File!" << endl;
-        return kFALSE;
-    }
-
-    if (fMagicNumber == kMagicNumber+1)
-        *fLog << warn << "WARNING - This file maybe broken (0xc0c1) - DAQ didn't close it correctly!" << endl;
-
-    Byte_t dummy[16];
-
-    // ----- File format version -----
-    fin.read((char*)&fFormatVersion, 2);     // Total=4
-    if (fFormatVersion>kMaxFormatVersion)
-    {
-        *fLog << err << "ERROR - File format V" << fFormatVersion << " not implemented!" << endl;
-        return kFALSE;
-    }
-
+//  Reading function to read/interpret the file formats 1-10
+//
+Bool_t MRawRunHeader::ReadEvtOld(istream& fin)
+{
     if (fFormatVersion==7)
     {
@@ -477,6 +472,7 @@
     fin.read((char*)&fNumSamplesHiGain, 2); // MUX: Number of samples per pixel
 
+    char dummy[16];
     if (fFormatVersion>8)
-        fin.read((char*)dummy, 4); // 2xU16 (NumSamplesRemovedHead and NumSamplesRemovedTail)
+        fin.read(dummy, 4); // 2xU16 (NumSamplesRemovedHead and NumSamplesRemovedTail)
 
     // ----- Number of events -----
@@ -526,5 +522,127 @@
 
     if (fFormatVersion<7)
-        fin.read((char*)&dummy, 16);
+        fin.read(dummy, 16);
+
+    return FixAssignment();
+}
+
+// --------------------------------------------------------------------------
+//
+// Read in one run header from the binary file
+//
+Bool_t MRawRunHeader::ReadEvt(istream& fin)
+{
+    //
+    // read one RUN HEADER from the input stream
+    //
+    fMagicNumber = 0;
+
+    fin.read((char*)&fMagicNumber, 2);          // Total=2
+
+    //
+    // check whether the the file has the right file type or not
+    //
+    if (fMagicNumber != kMagicNumber && fMagicNumber != kMagicNumber+1)
+    {
+        *fLog << err << "ERROR - Wrong Magic Number (0x" << hex << fMagicNumber << "): Not a Magic File!" << endl;
+        return kFALSE;
+    }
+
+    if (fMagicNumber == kMagicNumber+1)
+        *fLog << warn << "WARNING - This file maybe broken (0xc0c1) - DAQ didn't close it correctly!" << endl;
+
+    // ----- File format version -----
+    fin.read((char*)&fFormatVersion, 2);     // Total=4
+    if (fFormatVersion==10 || fFormatVersion>kMaxFormatVersion)
+    {
+        *fLog << err << "ERROR - File format V" << fFormatVersion << " not implemented!" << endl;
+        return kFALSE;
+    }
+
+    // ----- Process old file formats -----
+    if (fFormatVersion<10)
+        return ReadEvtOld(fin);
+
+    // ----- Overwrite format version for format 11 -----
+    fin.read((char*)&fFormatVersion, 4);
+    if (fFormatVersion<11)
+    {
+        *fLog << err << "ERROR - Format Version <11." << endl;
+        return kFALSE;
+    }
+
+    // ----- Read Header by size as written in the header -----
+    fin.read((char*)&fHeaderSizeRun, 4);
+    if (fHeaderSizeRun<346)
+    {
+        *fLog << err << "ERROR - Event header too small (<388b)." << endl;
+        return kFALSE;
+    }
+
+    TArrayC h(fHeaderSizeRun-12);
+    fin.read(h.GetArray(), h.GetSize());
+    if (!fin)
+        return kFALSE;
+
+    // ----- convert -----
+    const Byte_t  *Char  = reinterpret_cast<Byte_t* >(h.GetArray());
+    const UInt_t  *Int   = reinterpret_cast<UInt_t* >(h.GetArray());
+    //const Float_t *Float = reinterpret_cast<Float_t*>(h.GetArray());
+
+    // ----- Start interpretation -----
+
+    fHeaderSizeEvt   = Int[0];
+    fHeaderSizeCrate = Int[1];
+    fSoftVersion     = Int[2];
+    fFadcType        = Int[3];
+    fCameraVersion   = Int[4];
+    fTelescopeNumber = Int[5];
+    fRunType         = Int[6];
+    fRunNumber       = Int[7];
+    fFileNumber      = Int[8];
+
+    memcpy(fProjectName,     Char+ 36, 100);  // 25
+    memcpy(fSourceName,      Char+136,  80);  // 20
+    memcpy(fObservationMode, Char+216,  60);  // 15
+
+    //F32       fSourceRA     = Float[69];
+    //F32       fSourceDEC    = Float[70];
+    //F32       fTelescopeRA  = Float[71];
+    //F32       fTelescopeDEC = Float[72];
+
+    memcpy(fSourceEpochChar, Char+232, 4);
+
+    fSourceEpochDate    = Int[74];
+    fNumCrates          = Int[75];
+    fNumPixInCrate      = Int[76];
+    fNumSamplesHiGain   = Int[77];
+    fNumSamplesLoGain   = 0;
+
+    //fNumSamplesRemovedHead = Int[78];
+    //fNumSamplesRemovedTail = Int[79];
+
+    fNumEvents          = Int[80];
+    fNumEventsRead      = Int[81];
+    fNumBytesPerSample  = Int[82];
+    fSamplingFrequency  = Int[83];
+    fFadcResolution     = Int[84];
+
+    fRunStart.SetBinary(Int+85);
+    fRunStop.SetBinary(Int+91);
+
+    // ----- 388 bytes so far -----
+
+    const UInt_t n = fNumCrates*fNumPixInCrate;
+    if (fHeaderSizeRun<388+n*4)
+    {
+        *fLog << err << "ERROR - Event header too small to contain pix assignment." << endl;
+        return kFALSE;
+    }
+
+    // ----- Pixel Assignment -----
+    fPixAssignment->Set(n);
+
+    for (UInt_t i=0; i<n; i++)
+        (*fPixAssignment)[i] = Int[97+i];
 
     return FixAssignment();
@@ -578,4 +696,6 @@
         *fLog << "Camera=" << fCameraVersion;
     *fLog << endl;
+    if (fFormatVersion>10)
+        *fLog << "Header sizes: " << fHeaderSizeRun << "b (run), " << fHeaderSizeEvt << "b (evt), " << fHeaderSizeCrate << "b (crate)" << endl;
     if (fFormatVersion>5)
         *fLog << "Telescope:    " << fTelescopeNumber << endl;
Index: /trunk/MagicSoft/Mars/mraw/MRawRunHeader.h
===================================================================
--- /trunk/MagicSoft/Mars/mraw/MRawRunHeader.h	(revision 8945)
+++ /trunk/MagicSoft/Mars/mraw/MRawRunHeader.h	(revision 8946)
@@ -39,4 +39,9 @@
     /* ---- Run Header Informations ---- */
     UShort_t  fMagicNumber;          // File type identifier
+
+    UInt_t    fHeaderSizeRun;        // Size of run header
+    UInt_t    fHeaderSizeEvt;        // Size of evt header
+    UInt_t    fHeaderSizeCrate;      // Size of crate header
+
     UShort_t  fFormatVersion;        // File format version
     UShort_t  fSoftVersion;          // DAQ software version
@@ -46,8 +51,9 @@
     UShort_t  fRunType;              // Run Type
     UInt_t    fRunNumber;            // Run number
+    UInt_t    fFileNumber;           // File number
     Char_t    fProjectName[101];     // Project name
     Char_t    fSourceName[81];       // Source name
     Char_t    fObservationMode[61];  // observation mode
-    Char_t    fSourceEpochChar[2];   // epoch char of the source
+    Char_t    fSourceEpochChar[4];   // epoch char of the source
     UShort_t  fSourceEpochDate;      // epoch date of the source
     UShort_t  fNumCrates;            // number of electronic boards
@@ -66,4 +72,5 @@
     Bool_t SwapAssignment(Short_t id0, Short_t id1);
     Bool_t FixAssignment();
+    Bool_t ReadEvtOld(istream& fin);
 
 public:
@@ -90,4 +97,6 @@
     // This is to get the numbers...
     UShort_t GetMagicNumber() const       { return fMagicNumber; }
+    UInt_t   GetHeaderSizeEvt() const     { return fHeaderSizeEvt; }
+    UInt_t   GetHeaderSizeCrate() const   { return fHeaderSizeCrate; }
     UShort_t GetFormatVersion() const     { return fFormatVersion; }
     UShort_t GetSoftVersion() const       { return fSoftVersion; }
@@ -136,5 +145,5 @@
     Bool_t ReadEvt(istream& fin);
 
-    ClassDef(MRawRunHeader, 9)	// storage container for general info
+    ClassDef(MRawRunHeader, 10)	// storage container for general info
 };
 #endif
Index: /trunk/MagicSoft/Mars/readdaq.cc
===================================================================
--- /trunk/MagicSoft/Mars/readdaq.cc	(revision 8945)
+++ /trunk/MagicSoft/Mars/readdaq.cc	(revision 8946)
@@ -53,5 +53,6 @@
     gLog << "     -d1: print data in decimal values" << endl;
     gLog << "     -c1: print MRawCrateArray data" << endl;
-    gLog << "     -f:  force reading of runheader" << endl;
+    gLog << "     -ff: force reading of broken runheader" << endl;
+    gLog << "     -f:  force reading of files with problems" << endl;
     gLog << "     -?, -h, --help: This help" << endl << endl;
 }
@@ -81,7 +82,8 @@
     // Set verbosity to highest level.
     //
-    const bool kDecimal    = arg.HasOption("-d") && arg.GetIntAndRemove("-d")==1;
-    const bool kPrintArray = arg.HasOption("-c") && arg.GetIntAndRemove("-c")==1;
-    const bool kForce      = arg.HasOnlyAndRemove("-f");
+    const Bool_t kDecimal    = arg.HasOption("-d") && arg.GetIntAndRemove("-d")==1;
+    const Bool_t kPrintArray = arg.HasOption("-c") && arg.GetIntAndRemove("-c")==1;
+    const Bool_t kForce      = arg.HasOnlyAndRemove("-ff");
+    const Bool_t kForceMode  = arg.HasOnlyAndRemove("-f");
 
     //
@@ -160,4 +162,5 @@
     MRawFileRead read(kNamein);
     read.SetForce(kForce);
+    read.SetForceMode(kForceMode);
     tasks.AddToList(&read);
 
