Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 4739)
+++ trunk/MagicSoft/Mars/Changelog	(revision 4740)
@@ -41,4 +41,8 @@
      - added GetMinPixId
      - added GetMaxPixId
+
+   * merpp.cc: 
+     - added a new option --auto-time to get the time range for 
+       cc and/or caco data from the run header of the raw data
 
 
Index: trunk/MagicSoft/Mars/NEWS
===================================================================
--- trunk/MagicSoft/Mars/NEWS	(revision 4739)
+++ trunk/MagicSoft/Mars/NEWS	(revision 4740)
@@ -40,4 +40,7 @@
    - implemented support for pixels with negative IDs (Raw file format
      version 4)
+
+   - implemented an new option in merpp (--auto-time) to get the time
+     range for cc and/or caco data from the run header of the raw data
 
 
Index: trunk/MagicSoft/Mars/merpp.cc
===================================================================
--- trunk/MagicSoft/Mars/merpp.cc	(revision 4739)
+++ trunk/MagicSoft/Mars/merpp.cc	(revision 4740)
@@ -1,3 +1,6 @@
 #include <TSystem.h>
+
+#include <TFile.h>
+#include <TTree.h>
 
 #include "MParList.h"
@@ -79,4 +82,6 @@
 //    gLog << "   --sql=mysql://user:password@url  Insert run into database" << endl << endl;
     gLog << " Report File Options:" << endl;
+    gLog << "   --auto-time               Take time automatically from MRawRunHeader" << endl;
+    gLog << "                             (overwrites --start= and/or --stop=)" << endl;
     gLog << "   --start=date/time         Start event time" << endl;
     gLog << "   --stop=date/time          Stop  event time" << endl;
@@ -110,4 +115,30 @@
 }
 
+void GetTimeFromFile(const char *fname, MTime &start, MTime &stop)
+{
+    TFile f(fname, "READ");
+
+    TTree *t = (TTree*)f.Get("RunHeaders");
+    if (t->GetEntries()!=1)
+    {
+        gLog << warn << "WARNING - File " << fname << " contains no or more than one entry in RunHeaders... Times unchanged." << endl;
+        return;
+    }
+
+    MRawRunHeader *h = 0;
+    t->SetBranchAddress("MRawRunHeader.", &h);
+    t->GetEntry(0);
+    if (!h)
+    {
+        gLog << warn << "WARNING - File " << fname << " did not contain RunHeaders.MRawRunHeader... Times unchanged." << endl;
+        return;
+    }
+
+    if (!start)
+        start = h->GetRunStart();
+    if (!stop)
+        stop = h->GetRunEnd();
+}
+
 int main(const int argc, char **argv)
 {
@@ -132,4 +163,5 @@
     const Bool_t kForceProc  = arg.HasOnlyAndRemove("-ff");
     const Int_t  kRunNumber  = arg.GetIntAndRemove("--run=", -1);
+    const Bool_t kAutoTime   = arg.HasOnlyAndRemove("--auto-time");
           Int_t  kRunFile    = arg.GetIntAndRemove("--runfile=", -1);
           Bool_t kUpdate     = arg.HasOnlyAndRemove("--update") || arg.HasOnlyAndRemove("-u");
@@ -147,4 +179,83 @@
         kRunFile = 0;
 
+    if (arg.GetNumOptions()>0)
+    {
+        gLog << warn << "WARNING - Unknown commandline options..." << endl;
+        arg.Print("options");
+        gLog << endl;
+    }
+
+    //
+    // check for the right usage of the program
+    //
+    if (arg.GetNumArguments()<1 || arg.GetNumArguments()>2)
+    {
+        Usage();
+        return -1;
+    }
+
+    //
+    // This is to make argv[i] more readable insidethe code
+    //
+    TString kNamein  = arg.GetArgumentStr(0);
+    TString kNameout = arg.GetArgumentStr(1);
+
+    const Bool_t isreport = kNamein.EndsWith(".rep");
+    const Bool_t isdc     = kNamein.EndsWith(".txt");
+    const Bool_t israw    = !isreport && !isdc;
+
+    if (!kNamein.EndsWith(".raw") && israw)
+        kNamein += ".raw";
+
+    if (kNameout.IsNull())
+        kNameout = kNamein(0, kNamein.Last('.'));
+
+    if (!kNameout.EndsWith(".root"))
+        kNameout += ".root";
+
+//    if (!kSqlDataBase.IsNull() && !israw)
+//        gLog << warn << "WARNING - Option '--sql=' only valid for raw-files... ignored." << endl;
+
+    //
+    // Initialize Non-GUI (batch) mode
+    //
+    gROOT->SetBatch();
+
+    //
+    // check whether the given files are OK.
+    //
+    if (gSystem->AccessPathName(kNamein, kFileExists))
+    {
+        gLog << err << "Sorry, the input file '" << kNamein << "' doesn't exist." << endl;
+        return -1;
+    }
+
+    const Bool_t fileexist = !gSystem->AccessPathName(kNameout, kFileExists);
+    const Bool_t writeperm = !gSystem->AccessPathName(kNameout, kWritePermission);
+
+    if (fileexist && !writeperm)
+    {
+        gLog << err << "Sorry, you don't have write permission for '" << kNameout << "'." << endl;
+        return -1;
+    }
+
+    if (fileexist && !kUpdate && !kForce)
+    {
+        gLog << err << "Sorry, file '" << kNameout << "' already existing." << endl;
+        return -1;
+    }
+
+    if (!fileexist && kUpdate)
+    {
+        gLog << warn << "File '" << kNameout << "' doesn't yet exist." << endl;
+        kUpdate=kFALSE;
+    }
+
+    //
+    // Evaluate possible start-/stop-time
+    //
+    if (kAutoTime && kUpdate && (isreport || isdc))
+        GetTimeFromFile(kNameout, kTimeStart, kTimeStop);
+
     if (kTimeStart)
         gLog << inf << "Start Time: " << kTimeStart << endl;
@@ -152,77 +263,7 @@
         gLog << inf << "Stop  Time: " << kTimeStop << endl;
 
-    if (arg.GetNumOptions()>0)
-    {
-        gLog << warn << "WARNING - Unknown commandline options..." << endl;
-        arg.Print("options");
-        gLog << endl;
-    }
-
-    //
-    // check for the right usage of the program
-    //
-    if (arg.GetNumArguments()<1 || arg.GetNumArguments()>2)
-    {
-        Usage();
-        return -1;
-    }
-
-    //
-    // This is to make argv[i] more readable insidethe code
-    //
-    TString kNamein  = arg.GetArgumentStr(0);
-    TString kNameout = arg.GetArgumentStr(1);
-
-    const Bool_t isreport = kNamein.EndsWith(".rep");
-    const Bool_t isdc     = kNamein.EndsWith(".txt");
-    const Bool_t israw    = !isreport && !isdc;
-
-    if (!kNamein.EndsWith(".raw") && israw)
-        kNamein += ".raw";
-
-    if (kNameout.IsNull())
-        kNameout = kNamein(0, kNamein.Last('.'));
-
-    if (!kNameout.EndsWith(".root"))
-        kNameout += ".root";
-
-//    if (!kSqlDataBase.IsNull() && !israw)
-//        gLog << warn << "WARNING - Option '--sql=' only valid for raw-files... ignored." << endl;
-
-    //
-    // Initialize Non-GUI (batch) mode
-    //
-    gROOT->SetBatch();
-
-    //
-    // check whether the given files are OK.
-    //
-    if (gSystem->AccessPathName(kNamein, kFileExists))
-    {
-        gLog << err << "Sorry, the input file '" << kNamein << "' doesn't exist." << endl;
-        return -1;
-    }
-
-    const Bool_t fileexist = !gSystem->AccessPathName(kNameout, kFileExists);
-    const Bool_t writeperm = !gSystem->AccessPathName(kNameout, kWritePermission);
-
-    if (fileexist && !writeperm)
-    {
-        gLog << err << "Sorry, you don't have write permission for '" << kNameout << "'." << endl;
-        return -1;
-    }
-
-    if (fileexist && !kUpdate && !kForce)
-    {
-        gLog << err << "Sorry, file '" << kNameout << "' already existing." << endl;
-        return -1;
-    }
-
-    if (!fileexist && kUpdate)
-    {
-        gLog << warn << "File '" << kNameout << "' doesn't yet exist." << endl;
-        kUpdate=kFALSE;
-    }
-
+    //
+    // Ignore TObject Streamer (bits, uniqueid) for MArray and MParContainer
+    //
     MArray::Class()->IgnoreTObjectStreamer();
     MParContainer::Class()->IgnoreTObjectStreamer();
