Index: trunk/MagicSoft/Mars/mjobs/MDataSet.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MDataSet.cc	(revision 8988)
+++ trunk/MagicSoft/Mars/mjobs/MDataSet.cc	(revision 8989)
@@ -18,5 +18,5 @@
 !   Author(s): Thomas Bretz, 1/2005 <mailto:tbretz@astro.uni-wuerzburg.de>
 !
-!   Copyright: MAGIC Software Development, 2004-2007
+!   Copyright: MAGIC Software Development, 2004-2008
 !
 !
@@ -177,9 +177,19 @@
 //
 //
+// ===========================================================================
+//
 // ToDO:
 //   * Default paths could be moved into the global .rootrc
 //
+// ===========================================================================
+//
+//
+// Class Version 3:
+// ----------------
+//  + fFileName
+//  + fDataSet
 //
 // Class Version 2:
+// ----------------
 //  + fMonteCarlo
 //  + fWobbleMode
@@ -297,5 +307,5 @@
 
         // FIXME: The sequence number from the sequence file is assigned!!!
-        MSequence *seq = new MSequence(useds?fName:name, dir, num[i]);
+        MSequence *seq = new MSequence(useds?fFileName:name, dir, num[i]);
         seq->ExcludeRuns(excl);
 
@@ -354,6 +364,9 @@
 void MDataSet::Init(const char *fname, const UInt_t num, TString sequences, TString &data)
 {
+    fName  = "MDataSet";
+    fTitle = "DataSet file";
+
     // Store given file name as name
-    fName = fname;
+    fFileName = fname;
 
     // Delete the stored Sequences automatically at destruction
@@ -361,22 +374,25 @@
     fSequencesOff.SetOwner();
 
+    // Expand the file name (eg $MARS or ~ are expanded)
+    gSystem->ExpandPathName(fFileName);
+
+    // Check its accessibility
+    const Bool_t access = !gSystem->AccessPathName(fFileName, kFileExists);
+    if (!access)
+    {
+        gLog << err << "ERROR - Dataset file " << fname << " not accessible!" << endl;
+        fNumAnalysis = (UInt_t)-1;
+        return;
+    }
+
     // Determin the prefix to access this resource
     const TString prefix = num==(UInt_t)-1 ? "" : Form("%d", num);
 
-    // Expand the file name (eg $MARS or ~ are expanded)
-    TString expname(fname);
-    gSystem->ExpandPathName(expname);
-
-    // Check its accessibility
-    const Bool_t access = !gSystem->AccessPathName(expname, kFileExists);
-    if (!access)
-        gLog << err << "ERROR - Dataset file " << expname << " not accessible!" << endl;
-
     // Open and read the file
-    MEnv env(expname);
+    MEnv env(fFileName);
 
     // Get analysis number and name
     fNumAnalysis = GetEnvValue2(env, prefix, "AnalysisNumber", (Int_t)num);
-    fTitle       = GetEnvValue2(env, prefix, "Name", expname);
+    fDataSet     = GetEnvValue2(env, prefix, "Name", GetBaseName());
 
     // Get sequences from file
@@ -443,10 +459,18 @@
 //---------------------------------------------------------------------------
 //
-// Make sure that the name used for writing doesn't contain a full path
-//
-const char *MDataSet::GetName() const
-{
-    const char *pos = strrchr(GetRcName(), '/');
-    return pos>0 ? pos+1 : GetRcName();
+// Return the name of the file
+//
+const char *MDataSet::GetBaseName() const
+{
+    return gSystem->BaseName(fFileName);
+}
+
+//---------------------------------------------------------------------------
+//
+// Return the directory of the file
+//
+const char *MDataSet::GetFilePath() const
+{
+    return gSystem->DirName(fFileName);
 }
 
@@ -456,5 +480,5 @@
 // Return '+' if both can be accessed, '-' otherwise.
 //
-void MDataSet::PrintFile(const MSequence &seq)
+void MDataSet::PrintFile(ostream &out, const MSequence &seq)
 {
     const Char_t access =
@@ -462,5 +486,5 @@
         !gSystem->AccessPathName(seq.GetDataPath(), kFileExists) ? '+' : '-';
 
-    gLog << "#  " << access << " " << seq.GetFileName() << " <" << seq.GetDataPath() << ">" << endl;
+    out << "#  " << access << " " << seq.GetFileName() << " <" << seq.GetDataPath() << ">" << endl;
 }
 
@@ -469,61 +493,65 @@
 // Helper to print a seqeunce in Print()
 //
-void MDataSet::PrintSeq(const MSequence &seq) const
-{
-    const Bool_t useds = seq.GetFileName()==fName;
-
-    gLog << "Sequence" << Form("%08d", seq.GetSequence()) << ".File:   " << (useds?"-":seq.GetFileName()) << endl;
-    gLog << "Sequence" << Form("%08d", seq.GetSequence()) << ".Dir:    " << seq.GetDataPath() << endl;
+void MDataSet::PrintSeq(ostream &out, const MSequence &seq) const
+{
+    const Bool_t useds = seq.GetFileName()==fFileName;
+
+    out << "Sequence" << Form("%08d", seq.GetSequence()) << ".File:   " << (useds?"-":seq.GetFileName()) << endl;
+    out << "Sequence" << Form("%08d", seq.GetSequence()) << ".Dir:    " << seq.GetDataPath() << endl;
     if (!useds && seq.GetNumExclRuns()>0)
-        gLog << "Sequence" << Form("%08d", seq.GetSequence()) << ".Exclude: " << seq.GetExcludedRuns() << endl;
+        out << "Sequence" << Form("%08d", seq.GetSequence()) << ".Exclude: " << seq.GetExcludedRuns() << endl;
 
     if (useds)
     {
-        gLog << endl;
-        seq.Print("prefixed");
-        gLog << endl << "# ---" << endl;
-    }
-}
-
-
-// --------------------------------------------------------------------------
-//
-// Print the contents of the sequence
-//
-void MDataSet::Print(Option_t *o) const
-{
-    gLog << all;
+        out << endl;
+        seq.Print(out, "prefixed");
+        out << endl << "# ---" << endl;
+    }
+}
+
+// --------------------------------------------------------------------------
+//
+// Print the contents of the dataset to the ostream out
+//
+void MDataSet::Print(ostream &out, Option_t *o) const
+{
     if (!IsValid())
     {
-        gLog << "Dataset: " << fName << " <invalid - no analysis number available>" << endl;
+        out << "Dataset: " << fFileName << " <invalid - no analysis number available>" << endl;
         return;
     }
-    gLog << "# Path: " << GetRcName() << endl;
-    gLog << "# Name: " << GetName() << endl;
-    gLog << endl;
-    gLog << "AnalysisNumber: " << fNumAnalysis << endl << endl;
-
-    if (!fTitle.IsNull())
-        gLog << "Name: " << fTitle << endl << endl;
-
-    gLog << "SequencesOn:   ";
+    out << "# Path: " << GetFilePath() << endl;
+    out << "# Name: " << GetBaseName() << endl;
+    out << endl;
+    out << "AnalysisNumber: " << fNumAnalysis << endl << endl;
+
+    if (!fDataSet.IsNull())
+        out << "Name: " << fDataSet << endl << endl;
+
+    out << "SequencesOn:   ";
     for (int i=0; i<fNumSequencesOn.GetSize(); i++)
-        gLog << " " << fNumSequencesOn[i];
-    gLog << endl;
-    gLog << "SequencesOff:  ";
-    for (int i=0; i<fNumSequencesOff.GetSize(); i++)
-        gLog << " " << fNumSequencesOff[i];
-    gLog << endl << endl;
-
-    gLog << "SourceName: " << fNameSource << endl;
-    gLog << "Catalog: " << fCatalog << endl;
-
-    gLog << "WobbleMode: " << (fWobbleMode?"Yes":"No") << endl << endl;
-    gLog << "MonteCarlo: " << (fMonteCarlo?"Yes":"No") << endl << endl;
-
-    gLog << "Comment: " << fComment << endl;
+        out << " " << fNumSequencesOn[i];
+    out << endl;
+    if (fNumSequencesOff.GetSize()>0)
+    {
+        out << "SequencesOff:  ";
+        for (int i=0; i<fNumSequencesOff.GetSize(); i++)
+            out << " " << fNumSequencesOff[i];
+        out << endl;
+    }
+
+    out << endl;
+    if (!fNameSource.IsNull())
+        out << "SourceName: " << fNameSource << endl;
+    out << "Catalog: " << fCatalog << endl;
+
+    out << "WobbleMode: " << (fWobbleMode?"Yes":"No") << endl << endl;
+    out << "MonteCarlo: " << (fMonteCarlo?"Yes":"No") << endl << endl;
+
+    if (!fComment.IsNull())
+        out << "Comment: " << fComment << endl;
 
     if (fSequencesOn.GetEntries()>0)
-        gLog << endl;
+        out << endl;
 
     // FIXME: If file==fName --> print Sequence0000.content
@@ -533,26 +561,53 @@
     MSequence *seq=0;
     while ((seq=(MSequence*)NextOn()))
-        PrintSeq(*seq);
+        PrintSeq(out, *seq);
     if (fSequencesOff.GetEntries()>0)
-        gLog << endl;
+        out << endl;
     while ((seq=(MSequence*)NextOff()))
-        PrintSeq(*seq);
+        PrintSeq(out, *seq);
 
     if (TString(o).Contains("files", TString::kIgnoreCase))
     {
-        gLog << endl;
-        gLog << "# On-Data Files:" << endl;
+        out << endl;
+        out << "# On-Data Files:" << endl;
         NextOn.Reset();
         while ((seq=(MSequence*)NextOn()))
-            PrintFile(*seq);
-
-        gLog << endl;
-        gLog << "# Off-Data Files:" << endl;
+            PrintFile(out, *seq);
+
+        out << endl;
+        out << "# Off-Data Files:" << endl;
         NextOff.Reset();
         while ((seq=(MSequence*)NextOff()))
-            PrintFile(*seq);
+            PrintFile(out, *seq);
 
         return;
     }
+}
+
+// --------------------------------------------------------------------------
+//
+// Print the contents of the dataset to the gLog stream
+//
+void MDataSet::Print(Option_t *o) const
+{
+    gLog << all;
+    Print(gLog, o);
+}
+
+// --------------------------------------------------------------------------
+//
+// Print the contents of the dataset to the file with name filename
+//
+void MDataSet::WriteFile(const char *name, const Option_t *o) const
+{
+    ofstream fout(name);
+    if (!fout)
+    {
+        gLog << err << "Cannot open file " << name << ": ";
+        gLog << strerror(errno) << endl;
+        return;
+    }
+
+    Print(fout, o);
 }
 
@@ -755,4 +810,5 @@
 }
 
+/*
 // --------------------------------------------------------------------------
 //
@@ -786,2 +842,3 @@
     }
 }
+*/
Index: trunk/MagicSoft/Mars/mjobs/MDataSet.h
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MDataSet.h	(revision 8988)
+++ trunk/MagicSoft/Mars/mjobs/MDataSet.h	(revision 8989)
@@ -21,4 +21,7 @@
 private:
     static const TString fgCatalog; //! Default Catalog path
+
+    TString fFileName;        // File name to original file (MParContainer::fName is not streamed)
+    TString fDataSet;         // Name of the dataset given by the user
 
     UInt_t  fNumAnalysis;     // Analysis number (artificial)
@@ -45,10 +48,10 @@
     void ResolveSequences(const TEnv &env, const TString &prefix, const TArrayI &num, TList &list/*, const TString &sequences, const TString &data*/) const;
     Bool_t GetWobbleMode(const TEnv &env, const TString &prefix) const;
-    static void PrintFile(const MSequence &obj);
-    void PrintSeq(const MSequence &seq) const;
+    static void PrintFile(ostream &out, const MSequence &obj);
+    void PrintSeq(ostream &out, const MSequence &seq) const;
 
     // Directory and file handling
-    void ReplaceDir(TList &list, const TString &old, const TString &news) const;
-    void ReplaceFile(TList &list, const TString &old, const TString &news) const;
+    //void ReplaceDir(TList &list, const TString &old, const TString &news) const;
+    //void ReplaceFile(TList &list, const TString &old, const TString &news) const;
 
     void SetupDefaultPath(TString &path, const TString &def) const
@@ -72,10 +75,16 @@
 
 public:
-    MDataSet() : fNumAnalysis((UInt_t)-1) { }
+    MDataSet() : fNumAnalysis((UInt_t)-1)
+    {
+        fName  = "MDataSet";
+        fTitle = "DataSet file";
+    }
     MDataSet(const char *fname, TString sequences="", TString data="");
     MDataSet(const char *fname, Int_t num, TString sequences="", TString data="");
 
-    const char *GetName() const;
-    const char *GetRcName() const { return fName; }
+    const char    *GetBaseName() const;
+    const char    *GetFilePath() const;
+    const TString &GetFileName() const { return fFileName; }
+    const TString &GetDataSet()  const { return fDataSet;  }
 
     void Copy(TObject &obj) const
@@ -154,4 +163,5 @@
     Bool_t AddFilesOff(MDirIter &iter) const;
 
+    /*
     void ReplaceDir(const TString &old, const TString &news)
     {
@@ -165,10 +175,16 @@
         ReplaceFile(fSequencesOff, old, news);
     }
+    */
+
+    // I/O
+    void WriteFile(const char *filename, const Option_t *o) const;
+    void WriteFile(const char *filename) const { WriteFile(filename,""); } //*MENU *ARGS={filename=>fBaseName}
 
     // TObject
+    void Print(ostream &out, Option_t *o) const;
     void Print(Option_t *o) const;
     void Print() const { Print(""); } //*MENU*
 
-    ClassDef(MDataSet, 2)
+    ClassDef(MDataSet, 3)
 };
 
Index: trunk/MagicSoft/Mars/mjobs/MJCut.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJCut.cc	(revision 8988)
+++ trunk/MagicSoft/Mars/mjobs/MJCut.cc	(revision 8989)
@@ -18,5 +18,5 @@
 !   Author(s): Thomas Bretz, 1/2005 <mailto:tbretz@astro.uni-wuerzburg.de>
 !
-!   Copyright: MAGIC Software Development, 2000-2007
+!   Copyright: MAGIC Software Development, 2000-2008
 !
 !
@@ -461,5 +461,5 @@
     *fLog << inf;
     fLog->Separator(GetDescriptor());
-    *fLog << "Filling MHSrcPosCam " << set.GetName() << endl;
+    *fLog << "Filling MHSrcPosCam " << set.GetBaseName() << endl;
     *fLog << endl;
 
@@ -591,5 +591,5 @@
     *fLog << inf;
     fLog->Separator(GetDescriptor());
-    *fLog << "Perform cuts for data set " << set.GetName() << endl;
+    *fLog << "Perform cuts for data set " << set.GetBaseName() << endl;
     *fLog << endl;
 
@@ -693,9 +693,12 @@
     TString fname0(path);
     TString fname1(path);
-    fname0 += fNameSummary.IsNull() ?  (TString) Form("ganymed%08d-summary.root", set.GetNumAnalysis()) : fNameSummary;
-    fname1 += fNameResult.IsNull()  ?  (TString) Form("ganymed%08d.root",         set.GetNumAnalysis()) : fNameResult;
-
-    MWriteRootFile *write0 = CanStoreSummary() ? new MWriteRootFile(fPathOut.IsNull()?0:fname0.Data(), fOverwrite?"RECREATE":"NEW") : 0;
-    MWriteRootFile *write1 = CanStoreResult()  ? new MWriteRootFile(fPathOut.IsNull()?0:fname1.Data(), fOverwrite?"RECREATE":"NEW") : 0;
+    fname0 += fNameSummary.IsNull() ? (TString) Form("ganymed%08d-summary.root", set.GetNumAnalysis()) : fNameSummary;
+    fname1 += fNameResult.IsNull()  ? (TString) Form("ganymed%08d.root",         set.GetNumAnalysis()) : fNameResult;
+
+    MWriteRootFile dummy0(fPathOut.IsNull()||!CanStoreSummary()?0:fname0.Data(), fOverwrite?"RECREATE":"NEW");
+    MWriteRootFile dummy1(fPathOut.IsNull()||!CanStoreResult() ?0:fname1.Data(), fOverwrite?"RECREATE":"NEW");
+
+    MWriteRootFile *write0 = CanStoreSummary() ? &dummy0 : 0;
+    MWriteRootFile *write1 = CanStoreResult()  ? &dummy1 : 0;
     SetupWriter(write0, "WriteAfterCut0");
     SetupWriter(write1, "WriteAfterCut3");
@@ -1046,9 +1049,4 @@
     }
 
-    if (write0)
-        delete write0;
-    if (write1)
-        delete write1;
-
     // FIXME: Perform fit and plot energy dependant alpha plots
     // and fit result to new tabs!
Index: trunk/MagicSoft/Mars/mjobs/MJSpectrum.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJSpectrum.cc	(revision 8988)
+++ trunk/MagicSoft/Mars/mjobs/MJSpectrum.cc	(revision 8989)
@@ -18,5 +18,5 @@
 !   Author(s): Thomas Bretz, 4/2005 <mailto:tbretz@astro.uni-wuerzburg.de>
 !
-!   Copyright: MAGIC Software Development, 2000-2007
+!   Copyright: MAGIC Software Development, 2000-2008
 !
 !
@@ -311,5 +311,5 @@
 
     TH1D *time   = (TH1D*)arr.FindObjectInCanvas("ExcessTime", "TH1D", "Hist");
-    if (!size)
+    if (!time)
     {
         *fLog << err;
@@ -690,5 +690,5 @@
 Bool_t MJSpectrum::Refill(MParList &plist, TH1D &h2)/*const*/
 {
-    // Try to find the class used to determin the signal!
+    // Try to find the class used to determine the signal!
     TString cls("MHAlpha");
     if (fDisplay)
@@ -1498,5 +1498,5 @@
     *fLog << inf;
     fLog->Separator(GetDescriptor());
-    *fLog << "Compile Monte Carlo sample (dataset " << set.GetName() << ")" << endl;
+    *fLog << "Compile Monte Carlo sample (dataset " << set.GetBaseName() << ")" << endl;
     *fLog << endl;
 
@@ -1539,5 +1539,5 @@
     if (ontime<0)
     {
-        *fLog << err << GetDescriptor() << ": Could not determin effective on time..." << endl;
+        *fLog << err << GetDescriptor() << ": Could not determine effective on time..." << endl;
         return kFALSE;
     }
@@ -1605,5 +1605,5 @@
     // -------------- Fill excess events versus energy ---------------
 
-    // Refill excess histogram to determin the excess events
+    // Refill excess histogram to determine the excess events
     TH1D excess;
     if (!Refill(plist, excess))
@@ -1877,5 +1877,5 @@
         return kTRUE;
 
-    TNamed ganame("ganymed.root", gSystem->BaseName(fPathIn));
+    TNamed ganame("ganymed.root", fPathIn.Data());
 
     // Write the output
Index: trunk/MagicSoft/Mars/mjobs/MSequence.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MSequence.cc	(revision 8988)
+++ trunk/MagicSoft/Mars/mjobs/MSequence.cc	(revision 8989)
@@ -141,16 +141,27 @@
 //    seq.SetupPedRuns(iter, "/mypath", "[DPC]");
 //
+//
 // ===========================================================================
 //
+// ToDO:
+//   * Default paths could be moved into the global .rootrc
+//
+// ===========================================================================
+//
+//
 //  Class Version 2:
+//  ----------------
 //   + fMonteCarlo
 //
 //  Class Version 3:
+//  ----------------
 //   + fComment
 //
 //  Class Version 4:
+//  ----------------
 //   + fExclRuns
 //
 //  Class Version 5:
+//  ----------------
 //   + fRunsSub
 //   + fDatRunsSub
@@ -163,4 +174,7 @@
 
 #include <stdlib.h>
+#include <errno.h>
+
+#include <fstream>
 
 #include <TEnv.h>
@@ -538,5 +552,5 @@
         *fLog << err;
         *fLog << "ERROR - No input files for sequence #" << GetSequence() << endl;
-        *fLog << "        read from " << GetName() << endl;
+        *fLog << "        read from " << GetBaseName() << endl;
         *fLog << "        found in" << (def?" default-path ":" ") << d << endl;
         return 0;
@@ -550,5 +564,5 @@
     *fLog << "        " << (def?" default-path ":" ") << d << endl;
     *fLog << "        but " << n2 << " files were defined in sequence file" << endl;
-    *fLog << "        " << GetName() << endl;
+    *fLog << "        " << GetBaseName() << endl;
     if (fLog->GetDebugLevel()<=4)
         return 0;
@@ -580,5 +594,5 @@
 
     gLog << warn;
-    gLog << "WARNING - in " << fFileName << ":" << endl;
+    gLog << "WARNING - in " << GetBaseName() << ":" << endl;
     gLog << "          LightCondition-tag is '" << str << "' but must be n/a, no_moon, twilight, moon or day." << endl;
     return kNA;
@@ -591,22 +605,22 @@
 MSequence::MSequence(const char *fname, const char *path, UInt_t seq)
 {
-    fName  = fname;
-    fTitle = path;
+    fName  = "MSequence";
+    fTitle = "Sequence file";
 
     fFileName = fname;
     fDataPath = path;
 
-    gSystem->ExpandPathName(fName);
-    gSystem->ExpandPathName(fTitle);
-
-    const Bool_t rc1 = gSystem->AccessPathName(fName, kFileExists);
-    const Bool_t rc2 = !fTitle.IsNull() && gSystem->AccessPathName(fTitle, kFileExists);
+    gSystem->ExpandPathName(fFileName);
+    gSystem->ExpandPathName(fDataPath);
+
+    const Bool_t rc1 = gSystem->AccessPathName(fFileName, kFileExists);
+    const Bool_t rc2 = !fDataPath.IsNull() && gSystem->AccessPathName(fDataPath, kFileExists);
 
     if (rc1)
-        gLog << err << "ERROR - Sequence file '" << fName << "' doesn't exist." << endl;
+        gLog << err << "ERROR - Sequence file '" << fname << "' doesn't exist." << endl;
     if (rc2)
-        gLog << err << "ERROR - Directory '" << fTitle << "' doesn't exist." << endl;
-
-    MEnv env(fName);
+        gLog << err << "ERROR - Directory '" << path << "' doesn't exist." << endl;
+
+    MEnv env(fFileName);
 
     fSequence = (UInt_t)env.GetValue("Sequence", (Int_t)seq);
@@ -659,8 +673,16 @@
 // Make sure that the name used for writing doesn't contain a full path
 //
-const char *MSequence::GetName() const
-{
-    const char *pos = strrchr(GetRcName(), '/');
-    return pos>0 ? pos+1 : GetRcName();
+const char *MSequence::GetBaseName() const
+{
+    return gSystem->BaseName(fFileName);
+}
+
+//---------------------------------------------------------------------------
+//
+// Make sure that the name used for writing doesn't contain a full path
+//
+const char *MSequence::GetFilePath() const
+{
+    return gSystem->DirName(fFileName);
 }
 
@@ -752,10 +774,10 @@
 // simplyfing the file setup
 //
-TString MSequence::PrintRuns(const char *pre, const char *name, const TArrayI &r, const TArrayI &f) const
+TString MSequence::PrintRuns(ostream &out, const char *pre, const char *name, const TArrayI &r, const TArrayI &f) const
 {
     if (r.GetSize()==0)
         return "";
 
-    gLog << pre << name;
+    out << pre << name;
     if (f.GetSize()==0)
         const_cast<TArrayI&>(f).Set(r.GetSize());
@@ -763,6 +785,6 @@
 #ifdef DEBUG
     for (int i=0; i<r.GetSize(); i++)
-        gLog << "  " << r[i] << "." << f[i];
-    gLog << endl;
+        out << "  " << r[i] << "." << f[i];
+    out << endl;
     return "";
 #endif
@@ -776,5 +798,5 @@
         if (!rc.IsNull())
         {
-            gLog << rc;
+            out << rc;
             continue;
         }
@@ -788,7 +810,7 @@
         if (n==1)
         {
-            gLog << " " << r[pos];
+            out << " " << r[pos];
             if (f[pos]>0)
-                gLog << "." << f[pos];
+                out << "." << f[pos];
         }
         else
@@ -802,12 +824,12 @@
             if (isseq)
             {
-                gLog << " " << r[pos] << ".";
+                out << " " << r[pos] << ".";
                 if (f[pos]!=0)
-                    gLog << f[pos];
-                gLog << ":" << f[pos+n-1];
+                    out << f[pos];
+                out << ":" << f[pos+n-1];
             }
             else
             {
-                gLog << " " << r[pos] << "+";
+                out << " " << r[pos] << "+";
 
                 str += '\n';
@@ -821,5 +843,5 @@
     }
 
-    gLog << endl;
+    out << endl;
 
     return str;
@@ -830,10 +852,10 @@
 // Print the numbers in the classical way (one run after the other)
 //
-void MSequence::PrintRunsClassic(const char *pre, const char *name, const TArrayI &r) const
-{
-    gLog << pre << name;
+void MSequence::PrintRunsClassic(ostream &out, const char *pre, const char *name, const TArrayI &r) const
+{
+    out << pre << name;
     for (int i=0; i<r.GetSize(); i++)
-        gLog << " " << r[i];
-    gLog << endl;
+        out << " " << r[i];
+    out << endl;
 }
 
@@ -842,5 +864,5 @@
 // Print the contents of the sequence
 //
-void MSequence::Print(Option_t *o) const
+void MSequence::Print(ostream &out, Option_t *o) const
 {
     const TString opt(o);
@@ -848,61 +870,102 @@
     const TString pre = opt.Contains("prefixed") ? Form("Sequence%08d.", fSequence) : "";
 
-    gLog << all;
     if (!IsValid())
     {
-        gLog << pre << "Sequence: " << fFileName << " <invalid>" << endl;
+        out << pre << "Sequence: " << fFileName << " <invalid>" << endl;
         return;
     }
-    gLog << "# Path: " << GetRcName() << endl;
-    gLog << "# Name: " << GetName() << endl;
-    gLog << endl;
+    out << "# Path: " << GetFileName() << endl;
+    out << "# Name: " << GetBaseName() << endl;
+    out << endl;
     if (pre.IsNull())
-        gLog << "Sequence:       " << fSequence << endl;
+        out << "Sequence:       " << fSequence << endl;
     if (fMonteCarlo)
-        gLog << pre << "MonteCarlo:     Yes" << endl;
-    gLog << pre <<"Period:         " << fPeriod << endl;
-    gLog << pre << "Night:          " << fNight << endl << endl;
-    gLog << pre << "LightCondition: ";
+        out << pre << "MonteCarlo:     Yes" << endl;
+    if (fPeriod>=0)
+        out << pre << "Period:         " << fPeriod << endl;
+    if (fNight!=MTime())
+        out << pre << "Night:          " << fNight << endl;
+    out << endl;
+    out << pre << "LightCondition: ";
     switch (fLightCondition)
     {
-    case kNA:       gLog << "n/a" << endl;      break;
-    case kNoMoon:   gLog << "NoMoon" << endl;   break;
-    case kTwilight: gLog << "Twilight" << endl; break;
-    case kMoon:     gLog << "Moon" << endl;     break;
-    case kDay:      gLog << "Day" << endl;     break;
-    }
-    gLog << pre << "Start:          " << fStart << endl;
-    gLog << pre << "LastRun:        " << fLastRun << endl;
-    gLog << pre << "NumEvents:      " << fNumEvents << endl;
-    gLog << pre << "Project:        " << fProject << endl;
-    gLog << pre << "Source:         " << fSource << endl;
-    gLog << pre << "TriggerTable:   " << fTriggerTable << endl;
-    gLog << pre << "HvSettings:     " << fHvSettings << endl << endl;
+    case kNA:       out << "n/a" << endl;      break;
+    case kNoMoon:   out << "NoMoon" << endl;   break;
+    case kTwilight: out << "Twilight" << endl; break;
+    case kMoon:     out << "Moon" << endl;     break;
+    case kDay:      out << "Day" << endl;     break;
+    }
+
+    if (fStart!=MTime())
+        out << pre << "Start:          " << fStart << endl;
+    if (fLastRun>=0)
+        out << pre << "LastRun:        " << fLastRun << endl;
+    if (fNumEvents>=0)
+        out << pre << "NumEvents:      " << fNumEvents << endl;
+    if (!fProject.IsNull())
+        out << pre << "Project:        " << fProject << endl;
+    if (!fSource.IsNull())
+        out << pre << "Source:         " << fSource << endl;
+    if (!fTriggerTable.IsNull())
+        out << pre << "TriggerTable:   " << fTriggerTable << endl;
+    if (!fHvSettings.IsNull())
+        out << pre << "HvSettings:     " << fHvSettings << endl;
+    out << endl;
 
     TString str;
     if (!HasSubRuns() && opt.Contains("classic"))
     {
-        PrintRunsClassic(pre, "Runs:     ", fRuns);
-        PrintRunsClassic(pre, "CalRuns:  ", fCalRuns);
-        PrintRunsClassic(pre, "PedRuns:  ", fPedRuns);
-        PrintRunsClassic(pre, "DataRuns: ", fDatRuns);
-        PrintRunsClassic(pre, "Exclude:  ", fExclRuns);
+        PrintRunsClassic(out, pre, "Runs:     ", fRuns);
+        PrintRunsClassic(out, pre, "CalRuns:  ", fCalRuns);
+        PrintRunsClassic(out, pre, "PedRuns:  ", fPedRuns);
+        PrintRunsClassic(out, pre, "DataRuns: ", fDatRuns);
+        PrintRunsClassic(out, pre, "Exclude:  ", fExclRuns);
     }
     else
     {
-        str += PrintRuns(pre, "Runs:     ", fRuns,     fRunsSub);
-        str += PrintRuns(pre, "CalRuns:  ", fCalRuns,  fCalRunsSub);
-        str += PrintRuns(pre, "PedRuns:  ", fPedRuns,  fPedRunsSub);
-        str += PrintRuns(pre, "DataRuns: ", fDatRuns,  fDatRunsSub);
-        str += PrintRuns(pre, "Exclude:  ", fExclRuns, fExclRunsSub);
+        str += PrintRuns(out, pre, "Runs:     ", fRuns,     fRunsSub);
+        str += PrintRuns(out, pre, "CalRuns:  ", fCalRuns,  fCalRunsSub);
+        str += PrintRuns(out, pre, "PedRuns:  ", fPedRuns,  fPedRunsSub);
+        str += PrintRuns(out, pre, "DataRuns: ", fDatRuns,  fDatRunsSub);
+        str += PrintRuns(out, pre, "Exclude:  ", fExclRuns, fExclRunsSub);
     }
 
     if (!fDataPath.IsNull())
-        gLog << endl << pre << "DataPath: " << fDataPath << endl;
+        out << endl << pre << "DataPath: " << fDataPath << endl;
 
     if (!str.IsNull())
-        gLog << str << endl;
-
-    gLog << endl << pre << "Comment: " << fComment << endl;
+        out << str << endl;
+
+    out << endl;
+
+    if (!fComment.IsNull())
+        out << pre << "Comment: " << fComment << endl;
+}
+
+// --------------------------------------------------------------------------
+//
+// Print the contents of the sequence to gLog
+//
+void MSequence::Print(Option_t *o) const
+{
+    gLog << all;
+    Print(gLog, o);
+}
+
+// --------------------------------------------------------------------------
+//
+// Print the contents of the sequence to the file with name filename
+//
+void MSequence::WriteFile(const char *name, const Option_t *o) const
+{
+    ofstream fout(name);
+    if (!fout)
+    {
+        gLog << err << "Cannot open file " << name << ": ";
+        gLog << strerror(errno) << endl;
+        return;
+    }
+
+    Print(fout, o);
 }
 
Index: trunk/MagicSoft/Mars/mjobs/MSequence.h
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MSequence.h	(revision 8988)
+++ trunk/MagicSoft/Mars/mjobs/MSequence.h	(revision 8989)
@@ -22,16 +22,16 @@
     };
 private:
-    TString fFileName;
-    TString fDataPath;
+    TString fFileName;         // Expanded file name
+    TString fDataPath;         // Path to data files
 
-    UInt_t fSequence;
+    UInt_t fSequence;          // Sequence number
 
-    MTime  fStart;
+    MTime  fStart;             // Start time of sequence
 
-    UInt_t fLastRun;
-    UInt_t fNumEvents;
+    UInt_t fLastRun;           // Last run in sequence (necessary?)
+    UInt_t fNumEvents;         // Number of events in sequence
 
-    UInt_t fPeriod;
-    MTime  fNight;
+    UInt_t fPeriod;            // Observation period of the sequence
+    MTime  fNight;             // Night (day of sunrise) of the sequence
 
     LightCondition_t fLightCondition;
@@ -43,20 +43,20 @@
     TString fComment;
 
-    TArrayI fRuns;
-    TArrayI fRunsSub;
+    TArrayI fRuns;            // Run numbers
+    TArrayI fRunsSub;         // Sub runs (files)
 
-    TArrayI fCalRuns;
-    TArrayI fCalRunsSub;
+    TArrayI fCalRuns;         // Numbers of calibration runs/files
+    TArrayI fCalRunsSub;      // Sub runs (files) of calibration runs
 
-    TArrayI fPedRuns;
-    TArrayI fPedRunsSub;
+    TArrayI fPedRuns;         // Numbers of pedestal runs/files
+    TArrayI fPedRunsSub;      // Sub runs (files) of pedestal runs
 
-    TArrayI fDatRuns;
-    TArrayI fDatRunsSub;
+    TArrayI fDatRuns;         // Numbers of data runs/files
+    TArrayI fDatRunsSub;      // Sub runs (files) of data runs
 
-    TArrayI fExclRuns;
-    TArrayI fExclRunsSub;
+    TArrayI fExclRuns;        // Numbers of excluded runs/files
+    TArrayI fExclRunsSub;     // Sub runs (files) of excluded runs
 
-    Bool_t fMonteCarlo;
+    Bool_t fMonteCarlo;       // Flag for Monte Carlo sequences
 
     // Helper for interpretation
@@ -78,6 +78,6 @@
     TString GetNumSequence(Int_t &pos, const TArrayI &n, const TArrayI &f) const;
 
-    void    PrintRunsClassic(const char *pre, const char *name, const TArrayI &r) const;
-    TString PrintRuns(const char *pre, const char *name, const TArrayI &r, const TArrayI &f) const;
+    void    PrintRunsClassic(ostream &out, const char *pre, const char *name, const TArrayI &r) const;
+    TString PrintRuns(ostream &out, const char *pre, const char *name, const TArrayI &r, const TArrayI &f) const;
 
     // General helper
@@ -92,7 +92,13 @@
 public:
     MSequence() : fSequence((UInt_t)-1), fLastRun((UInt_t)-1),
-        fNumEvents((UInt_t)-1), fPeriod((UInt_t)-1), fMonteCarlo(kFALSE) { }
+        fNumEvents((UInt_t)-1), fPeriod((UInt_t)-1), fMonteCarlo(kFALSE)
+    {
+        fName  = "MSequence";
+        fTitle = "Sequence file";
+    }
     MSequence(const char *fname, const char *path="", UInt_t id=(UInt_t)-1);
-    MSequence(const MSequence &s) : fSequence(s.fSequence), fStart(s.fStart),
+    MSequence(const MSequence &s) : MParContainer(s),
+        fFileName(s.fFileName), fDataPath(s.fDataPath),
+        fSequence(s.fSequence), fStart(s.fStart),
         fLastRun(s.fLastRun), fNumEvents(s.fNumEvents), fPeriod(s.fPeriod),
         fNight(s.fNight), fProject(s.fProject), fSource(s.fSource),
@@ -101,10 +107,12 @@
         fDatRuns(s.fDatRuns), fMonteCarlo(s.fMonteCarlo) { }
 
+    // I/O
+    void WriteFile(const char *filename, const Option_t *o) const;
+    void WriteFile(const char *filename) const { WriteFile(filename,""); } //*MENU *ARGS={filename=>fBaseName}
+
     // TObject
+    void Print(ostream &out, Option_t *o) const;
     void Print(Option_t *o) const;
     void Print() const { Print(""); } //*MENU*
-
-    const char *GetName() const;
-    const char *GetRcName() const { return fName; }
 
     // Genaral interface
@@ -151,4 +159,6 @@
 
     // Filesystem getter
+    const char    *GetBaseName() const;
+    const char    *GetFilePath() const;
     const TString &GetFileName() const { return fFileName; }
     const TString &GetDataPath() const { return fDataPath; }
