Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 9185)
+++ trunk/MagicSoft/Mars/Changelog	(revision 9186)
@@ -23,4 +23,25 @@
    * mbase/MStatusDisplay.[h,cc], mbase/MEvtLoop.cc:
      - added Pause and Single Step option
+
+   * mcorsika/MCorsikaEvtHeader.[h,cc], mcorsika/MCorsikaRead.[h,cc].,
+     mcorsika/MCorsikaRunHeader.[h,cc]:
+     - moved filling of run header from first event header to
+       MCorsikaRunHeader
+
+   * mfileio/MWriteRootFile.cc:
+     - improved a check in the constructor if no filename is given
+
+   * mhbase/MH.cc:
+     - make SetBinning also work for TProfile2D
+
+   * mhist/MHCamera.[h,cc]:
+     - added functions to return the number of used pixels
+
+   * mjobs/MDataSet.cc, mjobs/MSequence.cc:
+     - improved by using new GetEnvValue3
+
+   * mbase/MParContainer.[h,cc]:
+     - added new member function GetEnvValue3 which is more flexible
+       in the number of leading zeroes within a resource name
 
 
Index: trunk/MagicSoft/Mars/NEWS
===================================================================
--- trunk/MagicSoft/Mars/NEWS	(revision 9185)
+++ trunk/MagicSoft/Mars/NEWS	(revision 9186)
@@ -49,4 +49,9 @@
      displayed values. (tabs.php) These plots are linked from the DB 
      websites and the wiki. 
+
+ ;statusdisplay
+
+   * The ''Loop'' entry in the menu bar now contains an option to pause
+     the loop and to process single events.
 
  ;merpp
Index: trunk/MagicSoft/Mars/mbase/MParContainer.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MParContainer.cc	(revision 9185)
+++ trunk/MagicSoft/Mars/mbase/MParContainer.cc	(revision 9186)
@@ -1090,4 +1090,36 @@
 // --------------------------------------------------------------------------
 //
+// This is a wrapper which checks the resource file for an id containing
+// a %d with different numbers of leading zeros (1 to 8).
+//
+// If athe entries in the resource file are not unambiguous a warning
+// is printed.
+//
+TString MParContainer::GetEnvValue3(const TEnv &env, const TString &prefix, TString id, UInt_t num) const
+{
+    id.ReplaceAll("%d", "%%0%dd");
+
+    TString rc;
+    for (int i=1; i<9; i++)
+    {
+        const TString form = Form(id.Data(), i);
+        const TString res  = Form(form.Data(), num);
+
+        const TString str  = GetEnvValue2(env, prefix, res, "");
+
+        if (str.IsNull())
+            continue;
+
+        if (rc.IsNull())
+            rc = str;
+        else
+            *fLog << warn << "Entry " << res << " ambigous (was also found with less leading zeros)... ignored." << endl;
+    }
+
+    return rc;
+}
+
+// --------------------------------------------------------------------------
+//
 // If object to remove is fDisplay set fDisplay to NULL.
 // If object to remove is fLog     set fLog     to NULL.
Index: trunk/MagicSoft/Mars/mbase/MParContainer.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MParContainer.h	(revision 9185)
+++ trunk/MagicSoft/Mars/mbase/MParContainer.h	(revision 9186)
@@ -149,4 +149,6 @@
     const char *GetEnvValue2(const TEnv &env, const TString &prefix, const TString &postfix, const char *dflt, Bool_t print=kFALSE) const;
 
+    TString     GetEnvValue3(const TEnv &env, const TString &prefix, TString id, UInt_t num) const;
+
     MParContainer *GetNewObject(const char *name, const char *base) const;
     MParContainer *GetNewObject(const char *name, TClass *base=MParContainer::Class()) const;
Index: trunk/MagicSoft/Mars/mcorsika/MCorsikaEvtHeader.cc
===================================================================
--- trunk/MagicSoft/Mars/mcorsika/MCorsikaEvtHeader.cc	(revision 9185)
+++ trunk/MagicSoft/Mars/mcorsika/MCorsikaEvtHeader.cc	(revision 9186)
@@ -37,5 +37,4 @@
 
 #include "MMcEvt.hxx"
-#include "MCorsikaRunHeader.h"
 
 ClassImp(MCorsikaEvtHeader);
@@ -78,5 +77,5 @@
 // return FALSE if there is no  header anymore, else TRUE
 //
-Int_t MCorsikaEvtHeader::ReadEvt(std::istream &fin, MCorsikaRunHeader &header)
+Int_t MCorsikaEvtHeader::ReadEvt(std::istream &fin)
 {
     char evth[4];
@@ -125,5 +124,5 @@
     fX =  f[117];
     fY = -f[97];
-
+/*
     if (fEvtNumber==1)
     {
@@ -138,5 +137,5 @@
         header.Print();
     }
-
+ */
     fin.seekg(1088-273*4, ios::cur);
 
Index: trunk/MagicSoft/Mars/mcorsika/MCorsikaEvtHeader.h
===================================================================
--- trunk/MagicSoft/Mars/mcorsika/MCorsikaEvtHeader.h	(revision 9185)
+++ trunk/MagicSoft/Mars/mcorsika/MCorsikaEvtHeader.h	(revision 9186)
@@ -13,6 +13,4 @@
 //class ifstream;
 #include <iosfwd>
-
-class MCorsikaRunHeader;
 
 class MCorsikaEvtHeader : public MParContainer
@@ -57,5 +55,5 @@
     Float_t GetY() const { return fY; }
 
-    Int_t ReadEvt(istream& fin, MCorsikaRunHeader &header);    // read in event header block
+    Int_t  ReadEvt(istream& fin);    // read in event header block
     Bool_t ReadEvtEnd(istream& fin); // read in event end block
 
Index: trunk/MagicSoft/Mars/mcorsika/MCorsikaRead.cc
===================================================================
--- trunk/MagicSoft/Mars/mcorsika/MCorsikaRead.cc	(revision 9185)
+++ trunk/MagicSoft/Mars/mcorsika/MCorsikaRead.cc	(revision 9186)
@@ -16,7 +16,7 @@
 !
 !
-!   Author(s): Thomas Bretz  12/2000 <mailto:tbretz@astro.uni-wuerzburg.de>
-!
-!   Copyright: MAGIC Software Development, 2000-2007
+!   Author(s): Thomas Bretz  11/2008 <mailto:tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: Software Development, 2000-2008
 !
 !
@@ -26,11 +26,4 @@
 //
 //  MCorsikaRead
-//
-//  This tasks reads the raw binary file like specified in the TDAS???
-//  and writes the data in the corresponding containers which are
-//  either retrieved from the parameter list or created and added.
-//
-//  Use SetInterleave() if you don't want to read all events, eg
-//    SetInterleave(5) reads only each 5th event.
 //
 //  Input Containers:
@@ -38,5 +31,7 @@
 //
 //  Output Containers:
-//   MCorsikaRunHeader, MCorsikaEvtHeader, MCorsikaEvtData, MCorsikaCrateArray, MCorsikaEvtTime
+//   MCorsikaRunHeader
+//   MCorsikaEvtHeader
+//   MPhotonEvent
 //
 //////////////////////////////////////////////////////////////////////////////
@@ -51,6 +46,4 @@
 #include "MLogManip.h"
 
-//#include "MZlib.h"
-//#include "MTime.h"
 #include "MParList.h"
 #include "MStatusDisplay.h"
@@ -59,5 +52,4 @@
 #include "MCorsikaEvtHeader.h"
 
-//#include "MPhotonData.h"
 #include "MPhotonEvent.h"
 
@@ -103,5 +95,5 @@
 //
 MCorsikaRead::MCorsikaRead(const char *fname, const char *name, const char *title)
-    : fRunHeader(0), fEvtHeader(0), fEvent(0), fEvtData(0), fForceMode(kFALSE),
+    : fRunHeader(0), fEvtHeader(0), fEvent(0), /*fEvtData(0),*/ fForceMode(kFALSE),
     fFileNames(0), fNumFile(0), fNumEvents(0), fNumTotalEvents(0),
     fIn(0), fParList(0)
@@ -212,5 +204,5 @@
 
     const char *expname = gSystem->ExpandPathName(name);
-    fIn = new fstream(expname);
+    fIn = new ifstream(expname);
 
     const Bool_t noexist = !(*fIn);
@@ -245,16 +237,10 @@
     if (!fRunHeader->ReadEvt(*fIn))
         return kERROR;
-
-    if (!(*fIn))
-    {
-        *fLog << err << "Error: Accessing file '" << name << "'" << endl;
-        return kERROR;
-    }
+//    if (!fEvtHeader->ReadRunHeader(*fIn, *fRunHeader))
+//        return kERROR;
 
     const streampos pos = fIn->tellg();
-
     if (!ReadEvtEnd())
         return kERROR;
-
     fIn->seekg(pos, ios::beg);
 
@@ -267,6 +253,6 @@
     //  We print it after the first event was read because
     //  we still miss information which is stored in the event header?!?
-    //if (print)
-    //    fRunHeader->Print();
+    if (print)
+        fRunHeader->Print();
 
     if (!fParList)
@@ -386,14 +372,8 @@
         return kFALSE;
 
-    fEvtData = (MPhotonData*)pList->FindCreateObj("MPhotonData");
-    if (!fEvtData)
-        return kFALSE;
-
     fEvent = (MPhotonEvent*)pList->FindCreateObj("MPhotonEvent");
     if (!fEvent)
         return kFALSE;
 
-    //*fLog << inf << "Maintaining " << fEvent->GetClassName() << " found in MCorsikaEvent." << endl;
-
     *fLog << inf << "Calculating number of total events..." << flush;
     if (!CalcNumTotalEvents())
@@ -419,5 +399,5 @@
     // if there is no next event anymore stop eventloop
     //
-    Int_t rc = fEvtHeader->ReadEvt(fin, *fRunHeader); //read event header block
+    Int_t rc = fEvtHeader->ReadEvt(fin); //read event header block
     if (!rc)
         return kFALSE;
Index: trunk/MagicSoft/Mars/mcorsika/MCorsikaRead.h
===================================================================
--- trunk/MagicSoft/Mars/mcorsika/MCorsikaRead.h	(revision 9185)
+++ trunk/MagicSoft/Mars/mcorsika/MCorsikaRead.h	(revision 9186)
@@ -12,5 +12,4 @@
 class MCorsikaRunHeader;
 class MCorsikaEvtHeader;
-class MPhotonData;
 class MPhotonEvent;
 
@@ -18,10 +17,9 @@
 {
 private:
-    MCorsikaRunHeader  *fRunHeader;  // run header information container to fill from file
-    MCorsikaEvtHeader  *fEvtHeader;  // event header information container to fill from file
+    MCorsikaRunHeader *fRunHeader;  // run header information container to fill from file
+    MCorsikaEvtHeader *fEvtHeader;  // event header information container to fill from file
     MPhotonEvent      *fEvent;      // event information
-    MPhotonData       *fEvtData;    // raw evt data information container to fill from file
 
-    Bool_t          fForceMode;     // Force mode skipping defect events
+    Bool_t          fForceMode;     // Force mode skipping defect RUNE
 
     TList    *fFileNames;      // list of file names
@@ -30,5 +28,5 @@
     UInt_t    fNumTotalEvents; //! total number of events in all files
 
-    fstream  *fIn;             //! input stream (file to read from)
+    ifstream *fIn;             //! input stream (file to read from)
 
     MParList *fParList;        //! tasklist to call ReInit from
Index: trunk/MagicSoft/Mars/mcorsika/MCorsikaRunHeader.cc
===================================================================
--- trunk/MagicSoft/Mars/mcorsika/MCorsikaRunHeader.cc	(revision 9185)
+++ trunk/MagicSoft/Mars/mcorsika/MCorsikaRunHeader.cc	(revision 9186)
@@ -170,5 +170,39 @@
     fin.seekg(1020, ios::cur);     // skip the remaining data of this block
 
-    return kTRUE;
+    // -------------------- Read first event header -------------------
+
+    char evth[4];
+    fin.read(evth, 4);
+    if (memcmp(evth, "EVTH", 4))
+    {
+        *fLog << err << "ERROR - Wrong identifier: EVTH expected." << endl;
+        return kFALSE;
+    }
+
+    Float_t g[273];
+    fin.read((char*)&g, 273*4);
+    if (fin.eof())
+        return kFALSE;
+
+    fin.seekg(-274*4, ios::cur);
+
+    const Int_t n = TMath::Nint(g[96]);
+    if (n!=1)
+    {
+        *fLog << err << "ERROR - Currently only one impact parameter per event is supported." << endl;
+        return kFALSE;
+    }
+
+    //fImpactMax = g[86];
+
+    fZdMin = g[79];
+    fZdMax = g[80];
+    fAzMin = 180-g[81];
+    fAzMax = 180-g[82];
+
+    fViewConeInnerAngle = g[151];
+    fViewConeOuterAngle = g[152];
+
+    return kTRUE;;
 }
 
Index: trunk/MagicSoft/Mars/mcorsika/MCorsikaRunHeader.h
===================================================================
--- trunk/MagicSoft/Mars/mcorsika/MCorsikaRunHeader.h	(revision 9185)
+++ trunk/MagicSoft/Mars/mcorsika/MCorsikaRunHeader.h	(revision 9186)
@@ -33,4 +33,6 @@
     Float_t  fAzMax;                     // [rad] Azimuth (north=0; west=90)
 
+    //Float_t  fImpactMax;              // [cm] Maximum simulated impact
+
     Float_t fViewConeInnerAngle;      // [deg]
     Float_t fViewConeOuterAngle;      // [deg]
@@ -48,4 +50,8 @@
     Float_t GetAzMax() const { return fAzMax; }
 
+    //Float_t GetImpactMax() const { return fImpactMax; }
+
+    Float_t GetViewConeOuterAngle() const { return fViewConeOuterAngle; }
+
     UInt_t GetNumEvents() const { return fNumEvents; }
 
Index: trunk/MagicSoft/Mars/mfileio/MWriteRootFile.cc
===================================================================
--- trunk/MagicSoft/Mars/mfileio/MWriteRootFile.cc	(revision 9185)
+++ trunk/MagicSoft/Mars/mfileio/MWriteRootFile.cc	(revision 9186)
@@ -224,5 +224,6 @@
     // If no name is given we open the TFile in some kind of dummy mode...
     //
-    if (!fname)
+    TString str(fname);
+    if (str.IsNull())
     {
         fOut = new TFile("/dev/null", "READ", ftitle, comp);
@@ -231,5 +232,4 @@
     }
 
-    TString str(fname);
     if (!str.EndsWith(".root", TString::kIgnoreCase))
         str += ".root";
Index: trunk/MagicSoft/Mars/mhbase/MH.cc
===================================================================
--- trunk/MagicSoft/Mars/mhbase/MH.cc	(revision 9185)
+++ trunk/MagicSoft/Mars/mhbase/MH.cc	(revision 9186)
@@ -1,4 +1,4 @@
 /* ======================================================================== *\
-! $Name: not supported by cvs2svn $:$Id: MH.cc,v 1.40 2008-11-11 11:42:13 tbretz Exp $
+! $Name: not supported by cvs2svn $:$Id: MH.cc,v 1.41 2008-12-02 11:22:15 tbretz Exp $
 ! --------------------------------------------------------------------------
 !
@@ -352,6 +352,17 @@
     y.SetTimeFormat(tfy);
 #else
-    h->SetBins(bx.GetNumBins(), bx.GetEdges(),
-               by.GetNumBins(), by.GetEdges());
+    if (h->InheritsFrom(TProfile2D::Class()))
+    {
+        h->SetBins(bx.GetNumBins(), 0, 1, 
+                   by.GetNumBins(), 0, 1);
+
+        h->SetBinsLength();
+
+        x.Set(bx.GetNumBins(), bx.GetEdges());
+        y.Set(by.GetNumBins(), by.GetEdges());
+    }
+    else
+        h->SetBins(bx.GetNumBins(), bx.GetEdges(),
+                   by.GetNumBins(), by.GetEdges());
 #endif
 
Index: trunk/MagicSoft/Mars/mhist/MHCamera.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHCamera.cc	(revision 9185)
+++ trunk/MagicSoft/Mars/mhist/MHCamera.cc	(revision 9186)
@@ -1,4 +1,4 @@
 /* ======================================================================== *\
-! $Name: not supported by cvs2svn $:$Id: MHCamera.cc,v 1.109 2008-06-30 09:36:38 tbretz Exp $
+! $Name: not supported by cvs2svn $:$Id: MHCamera.cc,v 1.110 2008-12-02 11:22:19 tbretz Exp $
 ! --------------------------------------------------------------------------
 !
@@ -363,4 +363,25 @@
 }
 
+UInt_t MHCamera::GetNumUsedSector(const TArrayI &sector, const TArrayI &aidx) const
+{
+    if (fNcells<=1)
+        return 0;
+
+    Int_t n=0;
+ 
+    for (int i=0; i<fNcells-2; i++)
+    {
+        if (!IsUsed(i) || !MatchSector(i, sector, aidx))
+            continue;
+
+        if (TestBit(kProfile) && fBinEntries[i+1]==0)
+            continue;
+        n++;
+    }
+
+    // return Median of the profile data
+    return n;
+}
+
 // ------------------------------------------------------------------------
 //
Index: trunk/MagicSoft/Mars/mhist/MHCamera.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHCamera.h	(revision 9185)
+++ trunk/MagicSoft/Mars/mhist/MHCamera.h	(revision 9186)
@@ -1,4 +1,4 @@
 /* ======================================================================== *\
-!  $Name: not supported by cvs2svn $:$Id: MHCamera.h,v 1.65 2008-06-30 09:36:38 tbretz Exp $
+!  $Name: not supported by cvs2svn $:$Id: MHCamera.h,v 1.66 2008-12-02 11:22:19 tbretz Exp $
 \* ======================================================================== */
 #ifndef MARS_MHCamera
@@ -133,4 +133,12 @@
     void   SetUsed(Int_t idx)      { SETBIT(fUsed[idx], kIsUsed); }
     void   SetAllUsed()            { fUsed.Reset(BIT(kIsUsed)); }
+
+    UInt_t GetNumUsedSector(const TArrayI &sector, const TArrayI &aidx) const;
+    UInt_t GetNumUsed() const { return GetNumUsedSector(TArrayI(), TArrayI()); }
+    UInt_t GetNumUsedSector(Int_t sector, Int_t aidx) const
+    {
+        return GetNumUsedSector(TArrayI(1, &sector), TArrayI(1, &aidx));
+    }
+
 
     Int_t Fill(Axis_t x, Axis_t y, Stat_t w);
Index: trunk/MagicSoft/Mars/mjobs/MDataSet.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MDataSet.cc	(revision 9185)
+++ trunk/MagicSoft/Mars/mjobs/MDataSet.cc	(revision 9186)
@@ -291,9 +291,7 @@
     for (int i=0; i<num.GetSize(); i++)
     {
-        const TString seqid = Form("Sequence%08d", num[i]);
-
-        TString name = GetEnvValue2(env, prefix, Form("%s.File",    seqid.Data()), "");
-        TString dir  = GetEnvValue2(env, prefix, Form("%s.Dir",     seqid.Data()), "");
-        TString excl = GetEnvValue2(env, prefix, Form("%s.Exclude", seqid.Data()), "");
+        TString name = GetEnvValue3(env, prefix, "Sequence%d.File",    num[i]);
+        TString dir  = GetEnvValue3(env, prefix, "Sequence%d.Dir",     num[i]);
+        TString excl = GetEnvValue3(env, prefix, "Sequence%d.Exclude", num[i]);
 
         // Set default sequence file and dir name
Index: trunk/MagicSoft/Mars/mjobs/MSequence.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MSequence.cc	(revision 9185)
+++ trunk/MagicSoft/Mars/mjobs/MSequence.cc	(revision 9186)
@@ -300,5 +300,5 @@
     TPRegexp regexp("([0-9]*:[0-9]+|[0-9]+(:[0-9]*)?)( +|$)");
 
-    TString files = GetEnvValue2(*env, prefix, Form("Run%08d", run), "");
+    TString files = GetEnvValue3(*env, prefix, "Run%d", run);
     if (files.IsNull())
     {
