Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 8779)
+++ trunk/MagicSoft/Mars/Changelog	(revision 8780)
@@ -19,5 +19,43 @@
                                                  -*-*- END OF LINE -*-*-
 
- 2007/12/03 Stefan Ruegamer
+ 2007/12/10 Thomas Bretz
+
+   * mfileio/MReadReports.cc: 
+     - due to a tiny misconception the last event in trees was skipped
+       simply because no time-stamp for a next event followed...
+       fixed.
+
+   * mhflux/MAlphaFitter.[h,cc]:
+     - added a new member function FixScale() to fix the scale 
+
+   * mhflux/MHAlpha.cc:
+     - replaced the check whether the significance is >1 by a check
+       whether it is >0. 0 means calculation failed. So all
+       valid data points are shown. If no significance could 
+       be calculated (negative flux) the data point is omitted.
+     - fixed a few drawing problems, which sometimes suppressed the
+       time-histogram even if it contained valid data (this only
+       affected very very short sequences - with a single time bin)
+
+   * mjobs/MDataSet.[h,cc]:
+     - implemented a possibility to use put the sequence inside the
+       dataset file
+     - improved comments
+     - allow to exclude runs from within the dataset file
+
+   * mjobs/MSequence.[h,cc]:
+     - added a new data member to store excluded runs. This is
+       needed to be able to store everything correctly later.
+     - improved comments
+     - added possibility to exclude previously set runs
+     - added a few member functions to check which runs are contained
+     - comment out some currently obsolete member function
+     - allow to read the resources of a sequence file prefixed
+       this is used in the new option of MDataSet
+     - increased class version number accordingly
+
+
+
+ 2007/12/10 Stefan Ruegamer
 
    * steps.rc
@@ -28,4 +66,6 @@
 
 
+
+ 2007/12/03 Stefan Ruegamer
 
    * datacenter/script/sourcefile
Index: trunk/MagicSoft/Mars/NEWS
===================================================================
--- trunk/MagicSoft/Mars/NEWS	(revision 8779)
+++ trunk/MagicSoft/Mars/NEWS	(revision 8780)
@@ -1,6 +1,32 @@
                                                                -*-*- END -*-*-
 
- *** <cvs>
-
+== <cvs> ==
+
+;general
+* fixed GroupBy options in plot*.C macros
+* only display KVA points (not the Tuorla points) in plotoptical.C
+* all programs now allow to add resources to the ones from the resource
+file or overwrite them from the command line. This can be done like this
+::ganymed --config=ganymed.rc --rc=Cut1.Param1:0.25 --rc=Cut1.Param3:5.5
+:if something seems to be wrong you can debug what the program is doing
+using the option --debug-env=3
+* increased the diversity of debug levels. That also means that with -v3
+you get now less output, i.e. only the output which is important for
+an analysis. To get more output which helps for debugging try 4, 5 and 6.
+* fixed a problem in the task synchronizing the reading of the reports
+and the data stream. The effect was that in some circumstances the last
+events of some trees could have been skipped. Since this is only a
+very tiny part of the data no severe effect to your analysis results 
+is expected.
+* Dataset file now allow to include the sequence file directly within
+the dataset file and also allow to exclude single runs from the dataset.
+(for more details see Class reference of MDataSet)
+* Sequence files now allow for excluding runs from the analysis
+(for more details see Class reference of MSequence)
+;ganymed/sponde
+* Now data points are even shown correctly if they have error bars larger
+than one sigma. Points with null or negative significances are omitted.
+;sponde
+*fixed resource files ('''Spectrum''' instead of '''MJSpectrum''')
 
 
@@ -48,5 +74,5 @@
      energy)
 
-   - general: TheRandom Forest training of energy (trainenergy.c) and
+   - general: The Random Forest training of energy (trainenergy.c) and
      disp (traindisp.C) has been improved by more graphical output to
      judge the result. 
@@ -125,5 +151,5 @@
      as old files read in.
 
-   - callisto: The callibration constants of earlier updates got lost
+   - callisto: The calibration constants of earlier updates got lost
      somehow. All constants have been updated.
 
Index: trunk/MagicSoft/Mars/mfileio/MReadReports.cc
===================================================================
--- trunk/MagicSoft/Mars/mfileio/MReadReports.cc	(revision 8779)
+++ trunk/MagicSoft/Mars/mfileio/MReadReports.cc	(revision 8780)
@@ -317,4 +317,5 @@
 
     fPosEntry.Set(i);
+    fPosEntry.Reset();
 
     // Force that with the next call to Process the required events are read
@@ -415,4 +416,6 @@
     while (fChains->GetSize())
     {
+        // Find the next tree to read from checking the time-stamps
+        // of the next events which would be read
         const Int_t nmin=FindNext();
         if (nmin<0)
@@ -422,35 +425,42 @@
         }
 
-        TChain *chain = (TChain*)fChains->At(nmin);
-
-        MTask *task = (MTask*)fTrees->GetList()->At(nmin);
-
-        //Int_t before = chain->GetTreeNumber();
-        if (chain->GetEntry(++fPosEntry[nmin])>0)
-        {
-            const Int_t rc = task->CallProcess();
-            if (rc)
-                return rc;
-        }
-
-        *fLog << dbg << "Removing chain " << chain->GetName() << " from list" << flush;
-
-        delete *GetTime(chain);        // Delete MTime*
-        *fLog << "." << flush;
-        delete fChains->Remove(chain); // Remove chain from TList
-        *fLog << "." << flush;
-
-        // FIXME: Maybe MTaskList should have a member function to
-        //        reorder the tasks?
-
-        // Move this task to the end of the list so that nmin still
-        // corresponds to the correct task in the list.
-        const_cast<TList*>(fTrees->GetList())->Remove(task);
-        *fLog << "." << flush;
-        const_cast<TList*>(fTrees->GetList())->AddLast(task);
-        *fLog << "done." << endl;
-    }
-
-    return kFALSE; 
+        // Read the event from this tree
+        MTask *task = static_cast<MTask*>(fTrees->GetList()->At(nmin));
+        const Int_t rc = task->CallProcess();
+
+        // Read the time-stamp of the next event
+        TChain *chain = static_cast<TChain*>(fChains->At(nmin));
+        const Int_t cnt = chain->GetEntry(++fPosEntry[nmin]);
+
+        // In case there is no further time-stamp of an error reading the
+        // event we remove this time-stamp from the list of time-stamps to
+        // be checked for reading the next events, because there is none.
+        if (cnt<=0 || rc==kFALSE)
+        {
+            *fLog << dbg << "Removing chain " << chain->GetName() << " from list" << flush;
+
+            delete *GetTime(chain);        // Delete MTime*
+            *fLog << "." << flush;
+            delete fChains->Remove(chain); // Remove chain from TList
+            *fLog << "." << flush;
+
+            // FIXME: Maybe MTaskList should have a member function to
+            //        reorder the tasks?
+
+            // Move this task to the end of the list so that nmin still
+            // corresponds to the correct task in the list.
+            const_cast<TList*>(fTrees->GetList())->Remove(task);
+            *fLog << "." << flush;
+            const_cast<TList*>(fTrees->GetList())->AddLast(task);
+            *fLog << "done." << endl;
+        }
+
+        // If something else than kFALSE (means: stop reading from this
+        // tree) has happened we return the return code of the processing
+        if (rc!=kFALSE)
+            return rc;
+    }
+
+    return kFALSE;
 }
 
Index: trunk/MagicSoft/Mars/mhflux/MAlphaFitter.cc
===================================================================
--- trunk/MagicSoft/Mars/mhflux/MAlphaFitter.cc	(revision 8779)
+++ trunk/MagicSoft/Mars/mhflux/MAlphaFitter.cc	(revision 8780)
@@ -853,8 +853,5 @@
             fScaleMode = kUserScale;
         if (txt==(TString)"fixed")
-        {
-            fScaleMode = kUserScale;
-            fScaleUser = fScaleFactor;
-        }
+            FixScale();
         rc = kTRUE;
     }
Index: trunk/MagicSoft/Mars/mhflux/MAlphaFitter.h
===================================================================
--- trunk/MagicSoft/Mars/mhflux/MAlphaFitter.h	(revision 8779)
+++ trunk/MagicSoft/Mars/mhflux/MAlphaFitter.h	(revision 8780)
@@ -165,4 +165,10 @@
     void EnableBackgroundFit(Bool_t b=kTRUE) { fFitBackground=b; }
 
+    void FixScale()
+    {
+        fScaleMode = kUserScale;
+        fScaleUser = fScaleFactor;
+    }
+
     // Getter
     Double_t GetSignalIntegralMax() const  { return fSigInt; }
Index: trunk/MagicSoft/Mars/mhflux/MHAlpha.cc
===================================================================
--- trunk/MagicSoft/Mars/mhflux/MHAlpha.cc	(revision 8779)
+++ trunk/MagicSoft/Mars/mhflux/MHAlpha.cc	(revision 8780)
@@ -159,18 +159,15 @@
     for (int i=1; i<=n; i++)
     {
-        if (fit.FitEnergy(fHist, fOffData, i))
-        {
-            fHEnergy.SetBinContent(i, fit.GetEventsExcess());
-            if (fit.GetSignificanceExc()>1)
-                fHEnergy.SetBinError(i, fit.GetEventsExcess()/fit.GetSignificanceExc());
-            else
-                fHEnergy.SetBinError(i, fit.GetEventsExcess());
-
-            if (fit.GetSignificanceExc()>1)
-            {
-                mean += fit.GetSignificanceExc()*fit.GetSignificanceExc();
-                num++;
-            }
-        }
+        if (!fit.FitEnergy(fHist, fOffData, i))
+            continue;
+
+        if (fit.GetSignificanceExc()<=0)
+            continue;
+
+        fHEnergy.SetBinContent(i, fit.GetEventsExcess());
+        fHEnergy.SetBinError(i, fit.GetEventsExcess()/fit.GetSignificanceExc());
+
+        mean += fit.GetSignificanceExc()*fit.GetSignificanceExc();
+        num++;
     }
     return TMath::Sqrt(mean)/num;
@@ -188,12 +185,12 @@
     for (int i=1; i<=n; i++)
     {
-        if (fit.FitTheta(fHist, fOffData, i))
-        {
-            fHTheta.SetBinContent(i, fit.GetEventsExcess());
-            if (fit.GetSignificanceExc()>1)
-                fHTheta.SetBinError(i, fit.GetEventsExcess()/fit.GetSignificanceExc());
-            else
-                fHTheta.SetBinError(i, fit.GetEventsExcess());
-        }
+        if (!fit.FitTheta(fHist, fOffData, i))
+            continue;
+
+        if (fit.GetSignificanceExc()<=0)
+            continue;
+
+        fHTheta.SetBinContent(i, fit.GetEventsExcess());
+        fHTheta.SetBinError(i, fit.GetEventsExcess()/fit.GetSignificanceExc());
     }
 }
@@ -431,9 +428,9 @@
     // Fill histogram
     //
-    fHTime.SetBinContent(n+1, fit.GetEventsExcess());
-    if (fit.GetSignificanceExc()>1)
+    if (fit.GetSignificanceExc()>0)
+    {
+        fHTime.SetBinContent(n+1, fit.GetEventsExcess());
         fHTime.SetBinError(n+1, fit.GetEventsExcess()/fit.GetSignificanceExc());
-    else
-        fHTime.SetBinError(n+1, fit.GetEventsExcess());
+    }
 
     *fLog << all << *fTimeEffOn << ": " << fit.GetEventsExcess() << endl;
@@ -735,5 +732,5 @@
     AppendPad("variable");
 
-    if (fHEnergy.GetNbinsX()>1)
+    if (fHEnergy.GetNbinsX()>1 || fHEnergy.GetBinContent(1)>0)
     {
         pad->cd(2);
@@ -759,5 +756,5 @@
         delete pad->GetPad(2);
 
-    if (fTimeEffOn && fTime || fHTime.GetNbinsX()>1)
+    if (fTimeEffOn && fTime || fHTime.GetNbinsX()>1 || fHTime.GetBinContent(1)>0)
     {
         pad->cd(3);
@@ -771,5 +768,5 @@
         delete pad->GetPad(3);
 
-    if (fHTheta.GetNbinsX()>1)
+    if (fHTheta.GetNbinsX()>1 || fHTheta.GetBinContent(1)>0)
     {
         pad->cd(4);
Index: trunk/MagicSoft/Mars/mjobs/MDataSet.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MDataSet.cc	(revision 8779)
+++ trunk/MagicSoft/Mars/mjobs/MDataSet.cc	(revision 8780)
@@ -31,5 +31,5 @@
 //  Such an input file looks like:
 //
-//     crab.seq:
+//     crab.txt:
 //     ---------
 //       AnalysisNumber: 1
@@ -37,5 +37,5 @@
 //       Name: SecondCrab
 //
-//       SequencesOn: 35222 35229
+//       SequencesOn:  35222 35229
 //       SequencesOff: 36817
 //
@@ -49,4 +49,6 @@
 //       Sequence00036817.Dir: /data2/wuerzburg/Crab-Analyse/images/036817
 //
+//       Sequence00036817.Exclude: 36818 36819
+//
 //       WobbleMode: No
 //       MonteCarlo: No
@@ -55,60 +57,78 @@
 //       Catalog: /magic/datacenter/setup/magic_favorites_dc.edb
 //
+//
+// Reading the file is based on TEnv. For more details see also
+// the class reference of TEnv.
+//
+//
 // AnalysisNumber: The analysis number is an artifical number used to name
-// the output files automatically if the names are not overwritten in the
-// corresponding programs.
+//  the output files automatically if the names are not overwritten in the
+//  corresponding programs.
 //
 // SequencePath: In case it is not specified the datacenter default path is
-// used. If it is given it is the place at which the sequence files
-// are searched, if not overwritten by either a program command line
-// option (aka. a argument to the constructor) or a resource for
-// an individual sequence file. Note, that the four digits high-level
-// directories to sort the sequences are added to the given path.
+//  used. If it is given it is the place at which the sequence files
+//  are searched, if not overwritten by either a program command line
+//  option (aka. a argument to the constructor) or a resource for
+//  an individual sequence file. Note, that the four digits high-level
+//  directories to sort the sequences are added to the given path.
 //
 // DataPath: In case it is not specified the datacenter default path is
-// used. If it is given it is the place at which the data files
-// are searched, if not overwritten by either a program command line
-// option (aka. a argument to the constructor) or a resource for
-// an individual data path.  Note, that the four digits high-level
-// directories to sort the sequences are added to the given path.
+//  used. If it is given it is the place at which the data files
+//  are searched, if not overwritten by either a program command line
+//  option (aka. a argument to the constructor) or a resource for
+//  an individual data path.  Note, that the four digits high-level
+//  directories to sort the sequences are added to the given path.
 //
 // SequencesOn/Off: The sequence number are used to concatenate the filenames
-// of the sequences using the file structure used in the datacenter. Each
-// sequence can be added to the on and off data at the same time but only
-// once.
-//
-// If you have different file names you can overwrite the default file names
-// using Sequence%08d.File (make sure you have 8 digits!)
-//
-// In standard coditions (datacenter file system) paths are concatenated
-// by using the information in the sequence files (date, etc). You can
-// overwrite the directories in which the sequence-files (eg I-files) are
-// stored using Sequence%08d.Dir (make sure you have 8 digits!)
+//  of the sequences using the file structure used in the datacenter. Each
+//  sequence can be added to the on and off data at the same time but only
+//  once.
+//
+//  If you have different file names you can overwrite the default file names
+//  using Sequence%08d.File (make sure you have 8 digits!)
+//
+//  If the file name is given as "-", e.g.
+//       Sequence00035222.File: -
+//  the current dataset file is read as sequence file. In this case all
+//  resources defined for a sequence file should be prefixed by
+//  "Sequence%08d."; if not prefixed the default without the prefix
+//  is looked up. Be aware that the "Sequence" resource for sequence-files
+//  (for more details see MSequence) is ignored and the already defined
+//  number is used instead and thus should be identical to the sequence
+//  number - which normally is not necessary.
+//
+//  In standard coditions (datacenter file system) paths are concatenated
+//  by using the information in the sequence files (date, etc). You can
+//  overwrite the directories in which the sequence-files (eg I-files) are
+//  stored using Sequence%08d.Dir (make sure you have 8 digits!)
+//
+//  Using the resource Sequence%08d.Exclude you can exclude a list of
+//  runs from a sequence.
 //
 // WobbleMode: This is just a flag which is passed to the program
-// end eveluated (or not) by the individual program, which takes this
-// dataset as an input. For example this is necessary in ganymed to do
-// some wobble mode special setup. If no resource is given (or it is
-// set to "auto") wobble mode if set if the datset contains no off-
-// sequences.
+//  end eveluated (or not) by the individual program, which takes this
+//  dataset as an input. For example this is necessary in ganymed to do
+//  some wobble mode special setup. If no resource is given (or it is
+//  set to "auto") wobble mode if set if the datset contains no off-
+//  sequences.
 //
 // MonetCarlo: This is just a flag which is passed to the program
-// end eveluated (or not) by the individual program, which takes this
-// dataset as an input. For example this tells ganymed to skip some
-// parts accessing time stamps which are not available in the MCs.
+//  end eveluated (or not) by the individual program, which takes this
+//  dataset as an input. For example this tells ganymed to skip some
+//  parts accessing time stamps which are not available in the MCs.
 //
 // SequencePath/DataPath: This determined were the sequences and data-files
-// are stored. The priorities are as follows:
-//  0) Build in default path:          /magic/sequences   /magic/data/star
-//  1) Def.path from dataset file:       SequencePath         DataPath
-//  2) Indiv.path from dataset file:  12345.SequencePath   12345.DataPath
-//  3) Path from command line:            Argument in the constructors
-//  4) Path for an indiv. dataset:         Sequences00022555.File/Dir
+//  are stored. The priorities are as follows:
+//   0) Build in default path:          /magic/sequences   /magic/data/star
+//   1) Def.path from dataset file:       SequencePath         DataPath
+//   2) Indiv.path from dataset file:  12345.SequencePath   12345.DataPath
+//   3) Path from command line:            Argument in the constructors
+//   4) Path for an indiv. dataset:         Sequences00022555.File/Dir
 //
 // Catalog: This is the xephem-style file from the central control
-// containing the observed sky positions.
+//  containing the observed sky positions.
 //
 // SourceName: The source name, as defined in the catalog, of the object
-// the data corresponds to.
+//  the data corresponds to.
 //
 // Name: A name is stored for your convinience
@@ -261,6 +281,9 @@
     for (int i=0; i<num.GetSize(); i++)
     {
-        TString name = GetEnvValue2(env, prefix, Form("Sequence%08d.File", num[i]), "");
-        TString dir  = GetEnvValue2(env, prefix, Form("Sequence%08d.Dir",  num[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()), "");
 
         // Set default sequence file and dir name
@@ -270,6 +293,10 @@
             dir = Form("%s%04d/%08d", data.Data(), num[i]/10000, num[i]);
 
+        // Check if sequence information is contained in Dataset file
+        const Bool_t useds = name=="-";
+
         // FIXME: The sequence number from the sequence file is assigned!!!
-        MSequence *seq = new MSequence(name, dir);
+        MSequence *seq = new MSequence(useds?fName:name, dir, num[i]);
+        seq->ExcludeRuns(excl);
 
         if (seq->IsValid() && seq->GetSequence()!=(UInt_t)num[i])
@@ -436,4 +463,25 @@
 
     gLog << "#  " << access << " " << seq.GetFileName() << " <" << seq.GetDataPath() << ">" << endl;
+}
+
+// --------------------------------------------------------------------------
+//
+// 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;
+    if (!useds && seq.GetNumExclRuns()>0)
+        gLog << "Sequence" << Form("%08d", seq.GetSequence()) << ".Exclude: " << seq.GetExcludedRuns() << endl;
+
+    if (useds)
+    {
+        gLog << endl;
+        seq.Print("prefixed");
+        gLog << endl << "# ---" << endl;
+    }
 }
 
@@ -478,19 +526,15 @@
         gLog << endl;
 
+    // FIXME: If file==fName --> print Sequence0000.content
+
     TIter NextOn(&fSequencesOn);
     TIter NextOff(&fSequencesOff);
     MSequence *seq=0;
     while ((seq=(MSequence*)NextOn()))
-    {
-        gLog << "Sequence" << Form("%08d", seq->GetSequence()) << ".File: " << seq->GetFileName() << endl;
-        gLog << "Sequence" << Form("%08d", seq->GetSequence()) << ".Dir:  " << seq->GetDataPath() << endl;
-    }
+        PrintSeq(*seq);
     if (fSequencesOff.GetEntries()>0)
         gLog << endl;
     while ((seq=(MSequence*)NextOff()))
-    {
-        gLog << "Sequence" << Form("%08d", seq->GetSequence()) << ".File: " << seq->GetFileName() << endl;
-        gLog << "Sequence" << Form("%08d", seq->GetSequence()) << ".Dir:  " << seq->GetDataPath() << endl;
-    }
+        PrintSeq(*seq);
 
     if (TString(o).Contains("files", TString::kIgnoreCase))
Index: trunk/MagicSoft/Mars/mjobs/MDataSet.h
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MDataSet.h	(revision 8779)
+++ trunk/MagicSoft/Mars/mjobs/MDataSet.h	(revision 8780)
@@ -46,4 +46,5 @@
     Bool_t GetWobbleMode(const TEnv &env, const TString &prefix) const;
     static void PrintFile(const MSequence &obj);
+    void PrintSeq(const MSequence &seq) const;
 
     // Directory and file handling
@@ -138,4 +139,7 @@
     const TList &GetSequencesOff() const { return fSequencesOff; }
 
+    const TArrayI &GetSequencesNumOn() const  { return fNumSequencesOn; }
+    const TArrayI &GetSequencesNumOff() const { return fNumSequencesOff; }
+
     Bool_t AddFiles(MRead &read) const;
     Bool_t AddFilesOn(MRead &read) const;
Index: trunk/MagicSoft/Mars/mjobs/MSequence.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MSequence.cc	(revision 8779)
+++ trunk/MagicSoft/Mars/mjobs/MSequence.cc	(revision 8780)
@@ -18,5 +18,5 @@
 !   Author(s): Thomas Bretz, 8/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
 !
-!   Copyright: MAGIC Software Development, 2004
+!   Copyright: MAGIC Software Development, 2004-2007
 !
 !
@@ -28,10 +28,13 @@
 //
 //  This class describes a sequence. For sequences see:
-//    http://magic.astro.uni-wuerzburg.de/mars/db/queryseq.html
+//    http://db.astro.uni-wuerzburg.de
 //
 //  A sequence is a collection of runs which should be used together.
 //  Any run can be contained only once.
 //
-//  Here is an example how a file describing a sequence could look like:
+//  Here is an example how a file describing a sequence could look like.
+//
+//  Reading the file is based on TEnv. For more details see also
+//  the class reference of TEnv.
 //
 // ===========================================================================
@@ -40,55 +43,52 @@
 //  ------------
 //
-//   # Sequence number (identifier)
+//   # Sequence number (identifier) - necessary if the path
+//   # contains the sequence number, e.g. image files
 //   Sequence:     31015
-//   # Observation Period (used to get the path-names)
+//
+//   # Observation Period (not needed)
 //   Period:       18
-//   # Date of sunrise of the observation night
+//
+//   # Date of sunrise of the observation night - necessary if the path
+//   # contains the date, e.g. raw data
 //   Night:        2004-06-24
 //
-//   # Start time of the sequence (first data run)
+//   # Start time of the sequence (first data run, not needed)
 //   Start:        2004-06-24 03:12:42
-//   # Run number of last data run in sequence
+//
+//   # Run number of last data run in sequence (not needed)
 //   LastRun:      31032
-//   # Project name of data-runs of sequence
+//
+//   # Project name of data-runs of sequence (not needed)
 //   Project:      3EG2033+41
-//   # Source name of all runs of sequence
+//
+//   # Source name of all runs of sequence (not needed)
 //   Source:       3EG2033+41
-//   # Trigger table of data-runs of sequence
+//
+//   # Trigger table of data-runs of sequence (not needed)
 //   TriggerTable: L1_4NN:L2_DEFAULT
-//   # HV Setting table of data-runs of sequence
+//
+//   # HV Setting table of data-runs of sequence (not needed)
 //   HvSettings:   HVSettings_FF36q
-//   # Total number of data-events in sequence
+//
+//   # Total number of data-events in sequence (not needed)
 //   NumEvents:    250914
 //
-//   # List of all runs of this sequence
+//   # Whether this is MC data or not (necessary in case of MCs if
+//   # default paths should be used)
+//   MonteCarlo: Yes
+//
+//   # List of all runs of this sequence (not needed)
 //   Runs: 31015 31016 31017 31018 31019 31020 31021 31022 31023 31024 31025 31026 31027 31028 31029 31030 31031 31032
 //
-//   # List of all calibration runs of this sequence
+//   # List of all calibration runs of this sequence (necessary if accessed)
 //   CalRuns: 31015 31016 31017
-//   # List of pedestal runs belonging to the calibration runs of this sequence
+//   # List of pedestal runs belonging to the calibration runs of this sequence (necessary if accessed)
 //   PedRuns: 31018
-//   # List of all data runs belonging to this sequence
+//   # List of all data runs belonging to this sequence (necessary)
 //   DatRuns: 31019 31020 31022 31023 31024 31025 31027 31028 31030 31032
 //
-//   # List of run types of all runs
-//   31015: C
-//   31016: C
-//   31017: C
-//   31018: P
-//   31019: D
-//   31020: D
-//   31021: P
-//   31022: D
-//   31023: D
-//   31024: D
-//   31025: D
-//   31026: P
-//   31027: D
-//   31028: D
-//   31029: P
-//   31030: D
-//   31031: P
-//   31032: D
+//   # Just for fun ;-) (not needed, but helpful)
+//   Comment: This is a template for a sequence file
 //
 // ===========================================================================
@@ -125,4 +125,7 @@
 //  Class Version 3:
 //   + fComment
+//
+//  Class Version 4:
+//   + fExclRuns
 //
 /////////////////////////////////////////////////////////////////////////////
@@ -253,6 +256,13 @@
         d += '/';
 
+    Int_t excluded = 0;
     for (int i=0; i<arr.GetSize(); i++)
     {
+        if (IsExcluded(arr[i]))
+        {
+            excluded++;
+            continue;
+        }
+
         // R. DeLosReyes and T. Bretz
         // Changes to read the DAQ numbering format. Changes takes place
@@ -325,6 +335,9 @@
     }
 
+    // n0: The previous contents of the iter
+    // n1: The number of files which have been added to the iter
+    // n2: The number of files which should have been added from the array
     const Int_t n1 = iter.GetNumEntries()-n0;
-    const Int_t n2 = arr.GetSize();
+    const Int_t n2 = arr.GetSize()-excluded;
     if (n1==0)
     {
@@ -386,7 +399,7 @@
 //}
 
-MSequence::LightCondition_t MSequence::ReadLightCondition(TEnv &env) const
-{
-    TString str = env.GetValue("LightConditions", "n/a");
+MSequence::LightCondition_t MSequence::ReadLightCondition(TEnv &env, const char *prefix) const
+{
+    TString str = GetEnvValue2(env, prefix, "LightConditions", "n/a");
     if (!str.CompareTo("n/a", TString::kIgnoreCase))
         return kNA;
@@ -410,5 +423,5 @@
 // Read the file fname as setup file for the sequence.
 //
-MSequence::MSequence(const char *fname, const char *path)
+MSequence::MSequence(const char *fname, const char *path, UInt_t seq)
 {
     fName  = fname;
@@ -431,36 +444,40 @@
     MEnv env(fName);
 
-    fSequence  = env.GetValue("Sequence", -1);
+    fSequence = (UInt_t)env.GetValue("Sequence", (Int_t)seq);
     if (rc1 || rc2)
         fSequence = (UInt_t)-1;
 
-    fLastRun   = env.GetValue("LastRun",   -1);
-    fNumEvents = env.GetValue("NumEvents", -1);
-    fPeriod    = env.GetValue("Period",    -1);
-
-    fLightCondition = ReadLightCondition(env);
+    const TString prefix = Form("Sequence%08d", fSequence);
+
+    fLastRun   = GetEnvValue2(env, prefix, "LastRun",   -1);
+    fNumEvents = GetEnvValue2(env, prefix, "NumEvents", -1);
+    fPeriod    = GetEnvValue2(env, prefix, "Period",    -1);
+
+    fLightCondition = ReadLightCondition(env, prefix);
 
     TString str;
-    str = env.GetValue("Start", "");
+    str = GetEnvValue2(env, prefix, "Start", "");
     fStart.SetSqlDateTime(str);
-    str = env.GetValue("Night", "");
+    str = GetEnvValue2(env, prefix, "Night", "");
     str += " 00:00:00";
     fNight.SetSqlDateTime(str);
 
-    fProject      = env.GetValue("Project", "");
-    fSource       = env.GetValue("Source", "");
-    fTriggerTable = env.GetValue("TriggerTable", "");
-    fHvSettings   = env.GetValue("HvSettings", "");
-    fMonteCarlo   = env.GetValue("MonteCarlo", kFALSE);
-    fComment      = env.GetValue("Comment",    "");
-
-    str = env.GetValue("Runs", "");
+    fProject      = GetEnvValue2(env, prefix, "Project", "");
+    fSource       = GetEnvValue2(env, prefix, "Source", "");
+    fTriggerTable = GetEnvValue2(env, prefix, "TriggerTable", "");
+    fHvSettings   = GetEnvValue2(env, prefix, "HvSettings", "");
+    fMonteCarlo   = GetEnvValue2(env, prefix, "MonteCarlo", kFALSE);
+    fComment      = GetEnvValue2(env, prefix, "Comment",    "");
+
+    str = GetEnvValue2(env, prefix, "Runs", "");
     Split(str, fRuns);
-    str = env.GetValue("CalRuns", "");
+    str = GetEnvValue2(env, prefix, "CalRuns", "");
     Split(str, fCalRuns);
-    str = env.GetValue("PedRuns", "");
+    str = GetEnvValue2(env, prefix, "PedRuns", "");
     Split(str, fPedRuns);
-    str = env.GetValue("DatRuns", "");
+    str = GetEnvValue2(env, prefix, "DatRuns", "");
     Split(str, fDatRuns);
+    str = GetEnvValue2(env, prefix, "Exclude", "");
+    Split(str, fExclRuns);
 
   //  GetFileNames(env, fRuns);
@@ -470,12 +487,12 @@
 
     // Dummies:
-    env.GetValue("ZdMin", 0);
-    env.GetValue("ZdMax", 0);
-    env.GetValue("L1TriggerTable", 0);
-    env.GetValue("L2TriggerTable", 0);
-
-    if (env.GetNumUntouched()>0)
-    {
-        gLog << warn << "WARNING - At least one resource in the dataset-file has not been touched!" << endl;
+    env.Touch("ZdMin");
+    env.Touch("ZdMax");
+    env.Touch("L1TriggerTable");
+    env.Touch("L2TriggerTable");
+
+    if (seq<0 && env.GetNumUntouched()>0)
+    {
+        gLog << warn << "WARNING - At least one resource in the sequence-file has not been touched!" << endl;
         env.PrintUntouched();
     }
@@ -492,5 +509,4 @@
 }
 
-
 // --------------------------------------------------------------------------
 //
@@ -499,8 +515,10 @@
 void MSequence::Print(Option_t *o) const
 {
+    const TString pre = TString(o).Contains("prefixed") ? Form("Sequence%08d.", fSequence) : "";
+
     gLog << all;
     if (!IsValid())
     {
-        gLog << "Sequence: " << fFileName << " <invalid>" << endl;
+        gLog << pre << "Sequence: " << fFileName << " <invalid>" << endl;
         return;
     }
@@ -508,10 +526,11 @@
     gLog << "# Name: " << GetName() << endl;
     gLog << endl;
-    gLog << "Sequence:       " << fSequence << endl;
+    if (pre.IsNull())
+        gLog << "Sequence:       " << fSequence << endl;
     if (fMonteCarlo)
-        gLog << "MonteCarlo:     Yes" << endl;
-    gLog << "Period:         " << fPeriod << endl;
-    gLog << "Night:          " << fNight << endl << endl;
-    gLog << "LightCondition: ";
+        gLog << pre << "MonteCarlo:     Yes" << endl;
+    gLog << pre <<"Period:         " << fPeriod << endl;
+    gLog << pre << "Night:          " << fNight << endl << endl;
+    gLog << pre << "LightCondition: ";
     switch (fLightCondition)
     {
@@ -522,33 +541,50 @@
     case kDay:      gLog << "Day" << endl;     break;
     }
-    gLog << "Start:          " << fStart << endl;
-    gLog << "LastRun:        " << fLastRun << endl;
-    gLog << "NumEvents:      " << fNumEvents << endl;
-    gLog << "Project:        " << fProject << endl;
-    gLog << "Source:         " << fSource << endl;
-    gLog << "TriggerTable:   " << fTriggerTable << endl;
-    gLog << "HvSettings:     " << fHvSettings << endl << endl;
-    gLog << "Runs:";
-    for (int i=0; i<fRuns.GetSize(); i++)
-        gLog << " " << fRuns[i];
-    gLog << endl;
-    gLog << "CalRuns:";
-    for (int i=0; i<fCalRuns.GetSize(); i++)
-        gLog << " " << fCalRuns[i];
-    gLog << endl;
-    gLog << "PedRuns:";
-    for (int i=0; i<fPedRuns.GetSize(); i++)
-        gLog << " " << fPedRuns[i];
-    gLog << endl;
-    gLog << "DatRuns:";
-    for (int i=0; i<fDatRuns.GetSize(); i++)
-        gLog << " " << fDatRuns[i];
-    gLog << endl;
-
+    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;
+    if (fRuns.GetSize()>0)
+    {
+        gLog << pre << "Runs:";
+        for (int i=0; i<fRuns.GetSize(); i++)
+            gLog << " " << fRuns[i];
+        gLog << endl;
+    }
+    if (fCalRuns.GetSize()>0)
+    {
+        gLog << pre << "CalRuns:";
+        for (int i=0; i<fCalRuns.GetSize(); i++)
+            gLog << " " << fCalRuns[i];
+        gLog << endl;
+    }
+    if (fPedRuns.GetSize()>0)
+    {
+        gLog << pre << "PedRuns:";
+        for (int i=0; i<fPedRuns.GetSize(); i++)
+            gLog << " " << fPedRuns[i];
+        gLog << endl;
+    }
+    if (fDatRuns.GetSize()>0)
+    {
+        gLog << pre << "DatRuns:";
+        for (int i=0; i<fDatRuns.GetSize(); i++)
+            gLog << " " << fDatRuns[i];
+        gLog << endl;
+    }
+    if (fExclRuns.GetSize()>0)
+    {
+        gLog << pre << "Exclude:";
+        for (int i=0; i<fExclRuns.GetSize(); i++)
+            gLog << " " << fExclRuns[i];
+        gLog << endl;
+    }
     if (!fDataPath.IsNull())
-        gLog << endl << "DataPath: " << fDataPath << endl;
-
-    gLog << endl << "Comment: " << fComment << endl;
-
+        gLog << endl << pre << "DataPath: " << fDataPath << endl;
+
+    gLog << endl << pre << "Comment: " << fComment << endl;
 }
 
@@ -562,4 +598,6 @@
 // Return the number of files added.
 //
+// Runs which are in fExlRuns are ignored.
+//
 UInt_t MSequence::SetupPedRuns(MDirIter &iter, const char *path, Bool_t raw) const
 {
@@ -576,4 +614,6 @@
 // Return the number of files added.
 //
+// Runs which are in fExlRuns are ignored.
+//
 UInt_t MSequence::SetupDatRuns(MDirIter &iter, const char *path, Bool_t raw) const
 {
@@ -590,4 +630,6 @@
 // Return the number of files added.
 //
+// Runs which are in fExlRuns are ignored.
+//
 UInt_t MSequence::SetupAllRuns(MDirIter &iter, const char *path, Bool_t raw) const
 {
@@ -604,4 +646,6 @@
 // Return the number of files added.
 //
+// Runs which are in fExlRuns are ignored.
+//
 UInt_t MSequence::SetupCalRuns(MDirIter &iter, const char *path, Bool_t raw) const
 {
@@ -618,4 +662,6 @@
 // Return the number of files added.
 //
+// Runs which are in fExlRuns are ignored.
+//
 UInt_t MSequence::SetupDatRuns(MDirIter &iter, FileType_t type, const char *path) const
 {
@@ -653,7 +699,88 @@
         fRuns[nall+i] = first+i;
         if (runs)
-            (*runs)[nrun+i]  = first+i;
+            (*runs)[nrun+i] = first+i;
     }
     return add;
+}
+
+Bool_t MSequence::IsContained(const TArrayI &arr, UInt_t run) const
+{
+    for (int i=0; i<arr.GetSize(); i++)
+        if (run==(UInt_t)arr[i])
+            return kTRUE;
+    return kFALSE;
+}
+
+/*
+// --------------------------------------------------------------------------
+//
+// Check if num is found in arr. If it is found remove it. Copy all
+// following entries one back and decrease the array size by 1.
+//
+void MSequence::ExcludeRun(TArrayI &arr, UInt_t num)
+{
+    UInt_t *ptr = (UInt_t*)arr.GetArray();
+
+    Int_t i = 0;
+    for (i=0; i<arr.GetSize(); i++)
+        if (ptr[i]==num)
+            break;
+
+    if (i==arr.GetSize())
+        return;
+
+    for (; i<arr.GetSize()-1; i++)
+        ptr[i] = ptr[i+1];
+
+    arr.Set(arr.GetSize()-1);
+}
+*/
+
+// --------------------------------------------------------------------------
+//
+// Exclude this run (i.e. add it to fExclRuns)
+//
+void MSequence::ExcludeRun(UInt_t num)
+{
+    /*
+     ExcludeRun(fRuns,    num);
+     ExcludeRun(fCalRuns, num);
+     ExcludeRun(fPedRuns, num);
+     ExcludeRun(fDatRuns, num);
+     */
+
+    if (IsExcluded(num))
+        return;
+
+    // set new entry
+    const Int_t n = fExclRuns.GetSize();
+    fExclRuns.Set(n+1);
+    fExclRuns[n] = num;
+
+    MJob::SortArray(fExclRuns);
+}
+
+// --------------------------------------------------------------------------
+//
+// Exclude all runs which are found in the list, e.g. "100 102 105"
+//
+void MSequence::ExcludeRuns(TString runs)
+{
+    TArrayI data;
+    Split(runs, data);
+
+    for (int i=0; i<data.GetSize(); i++)
+        ExcludeRun(data[i]);
+}
+
+const TString MSequence::GetExcludedRuns() const
+{
+    TString rc;
+    for (int i=0; i<fExclRuns.GetSize(); i++)
+    {
+        rc += fExclRuns[i];
+        rc += " ";
+    }
+    return rc(0, rc.Length()-1);
 }
 
@@ -698,2 +825,3 @@
     return kFALSE;
 }
+
Index: trunk/MagicSoft/Mars/mjobs/MSequence.h
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MSequence.h	(revision 8779)
+++ trunk/MagicSoft/Mars/mjobs/MSequence.h	(revision 8780)
@@ -52,4 +52,6 @@
     TArrayI fDatRuns;
 
+    TArrayI fExclRuns;
+
     Bool_t fMonteCarlo;
 
@@ -58,5 +60,6 @@
     void Split(TString &runs, TArrayI &data) const;
     //void GetFileNames(TEnv &env, const TArrayI &arr);
-    LightCondition_t ReadLightCondition(TEnv &env) const;
+
+    LightCondition_t ReadLightCondition(TEnv &env, const char *prefix) const;
 
     const char *GetFileName(UInt_t num);
@@ -65,9 +68,11 @@
     UInt_t SetupRuns(MDirIter &iter, const TArrayI &arr, FileType_t type, const char *path=0) const;
     UInt_t AddRuns(UInt_t first, UInt_t last, TArrayI *runs);
+    void   ExcludeRun(TArrayI &arr, UInt_t num);
+    Bool_t IsContained(const TArrayI &arr, UInt_t num) const;
 
 public:
     MSequence() : fSequence((UInt_t)-1), fLastRun((UInt_t)-1),
         fNumEvents((UInt_t)-1), fPeriod((UInt_t)-1), fMonteCarlo(kFALSE) { }
-    MSequence(const char *fname, const char *path="");
+    MSequence(const char *fname, const char *path="", UInt_t id=(UInt_t)-1);
     MSequence(const MSequence &s) : fSequence(s.fSequence), fStart(s.fStart),
         fLastRun(s.fLastRun), fNumEvents(s.fNumEvents), fPeriod(s.fPeriod),
@@ -88,4 +93,6 @@
     Bool_t IsValid() const { return fSequence!=(UInt_t)-1; }
     Bool_t IsMonteCarlo() const { return fMonteCarlo; }
+    Bool_t IsExcluded(UInt_t run) const { return IsContained(fExclRuns, run); }
+    Bool_t IsContained(UInt_t run) const { return IsContained(fCalRuns, run) || IsContained(fPedRuns, run) || IsContained(fDatRuns, run); }
 
     void SetMonteCarlo(Bool_t ismc=kTRUE) { fMonteCarlo=ismc; }
@@ -102,9 +109,11 @@
     UInt_t SetupCalRuns(MDirIter &iter, FileType_t type, const char *path=0);
    */
+
     // Getter
-    UInt_t GetNumAllRuns() const { return fRuns.GetSize(); }
-    UInt_t GetNumDatRuns() const { return fDatRuns.GetSize(); }
-    UInt_t GetNumPedRuns() const { return fPedRuns.GetSize(); }
-    UInt_t GetNumCalRuns() const { return fCalRuns.GetSize(); }
+//    UInt_t GetNumAllRuns() const { return fRuns.GetSize(); }
+//    UInt_t GetNumDatRuns() const { return fDatRuns.GetSize(); }
+//    UInt_t GetNumPedRuns() const { return fPedRuns.GetSize(); }
+//    UInt_t GetNumCalRuns() const { return fCalRuns.GetSize(); }
+    UInt_t GetNumExclRuns() const { return fExclRuns.GetSize(); }
 
     UInt_t GetSequence() const { return fSequence; }
@@ -117,7 +126,8 @@
     const UInt_t GetFirstCalRun() const { return fCalRuns[0]; }
     const UInt_t GetLastCalRun() const { return fCalRuns[fCalRuns.GetSize()-1]; }
-    const TArrayI &GetPedRuns() const { return fPedRuns; } 
-    const TArrayI &GetCalRuns() const { return fCalRuns; } 
-    const TArrayI &GetDatRuns() const { return fDatRuns; } 
+//    const TArrayI &GetDatRuns() const { return fDatRuns; }
+//    const TArrayI &GetPedRuns() const { return fPedRuns; }
+//    const TArrayI &GetCalRuns() const { return fCalRuns; }
+    const TArrayI &GetExclRuns() const { return fExclRuns; }
 
     const MTime &GetStart() const { return fStart; }
@@ -129,4 +139,6 @@
     const TString &GetFileName() const { return fFileName; }
     const TString &GetDataPath() const { return fDataPath; }
+
+    const TString GetExcludedRuns() const;
 
     // Setter
@@ -143,7 +155,10 @@
     UInt_t AddDatRuns(UInt_t num) { return AddDatRuns(num, num); }
 
+    void ExcludeRun(UInt_t num);
+    void ExcludeRuns(TString runs);
+
     static Bool_t InflatePath(TString &seq, Bool_t ismc=kFALSE);
 
-    ClassDef(MSequence, 3)
+    ClassDef(MSequence, 4)
 };
 
