Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 5159)
+++ trunk/MagicSoft/Mars/Changelog	(revision 5160)
@@ -50,4 +50,13 @@
    * mjobs/MJob.cc:
      - fixed a typo in an output
+
+   * callisto.cc:
+     - removed "-mc" option (now autodetected)
+       --> to be done in the other jobs, too
+
+   * mfileio/MRead.[h,cc], mfileio/MReadMarsFile.[h,cc],
+     mfileio/MReadTree.[h,cc], mjobs/MJCalibrateSignal.[h,cc],
+     mraw/MRawFileRead.[h,cc]:
+     - implemented IsFileValid as a first step to file auto-detection
 
 
Index: trunk/MagicSoft/Mars/callisto.cc
===================================================================
--- trunk/MagicSoft/Mars/callisto.cc	(revision 5159)
+++ trunk/MagicSoft/Mars/callisto.cc	(revision 5160)
@@ -50,6 +50,4 @@
     gLog << "   -c                        Calculate the calibration constants" << endl;
     gLog << "   -y                        Extract and calibrate signal" << endl << endl;
-    gLog << " Input File Options:" << endl;
-    gLog << "   -mc                       You must use this for MC files (PRELIMINARY)" << endl << endl;
     gLog << " Options:" << endl;
     gLog.Usage();
@@ -123,5 +121,4 @@
     const Bool_t  kOverwrite  = arg.HasOnlyAndRemove("-f");
     const Bool_t  kForceExec  = arg.HasOnlyAndRemove("-ff");
-    const Bool_t  kIsMC       = arg.HasOnlyAndRemove("-mc");
 
     const TString kInpathD    = arg.GetStringAndRemove("--ind=",  "");
@@ -377,5 +374,5 @@
 
         // Where to search for calibration files
-        if (!job2.ProcessFile(job1.GetPedestalCam(), kIsMC))
+        if (!job2.ProcessFile(job1.GetPedestalCam()))
             return -1;
 
Index: trunk/MagicSoft/Mars/mfileio/MRead.cc
===================================================================
--- trunk/MagicSoft/Mars/mfileio/MRead.cc	(revision 5159)
+++ trunk/MagicSoft/Mars/mfileio/MRead.cc	(revision 5160)
@@ -24,16 +24,18 @@
 
 /////////////////////////////////////////////////////////////////////////////
-//                                                                         //
-// MRead                                                                   //
-//                                                                         //
-// Base class for all reading tasks                                        //
-//                                                                         //
-// You can set a selector. Depending on the impelementation in the derived //
-// class it can be used to skip events, if the filter return kFALSE.       //
-// Make sure that the selector (filter) doesn't need information which     //
-// doesn't exist before reading an event!                                  //
-//                                                                         //
+//
+// MRead
+//
+// Base class for all reading tasks
+//
+// You can set a selector. Depending on the impelementation in the derived
+// class it can be used to skip events, if the filter return kFALSE.
+// Make sure that the selector (filter) doesn't need information which
+// doesn't exist before reading an event!
+//
 /////////////////////////////////////////////////////////////////////////////
 #include "MRead.h"
+
+#include <TSystem.h>
 
 #include "MLog.h"
@@ -119,2 +121,16 @@
     return i!=0;
 }
+
+// --------------------------------------------------------------------------
+//
+// Check if the file exists and has read permission. Derived classes
+// should also check whether its file type is correct.
+//
+// Returning 0 means: file doesn't exist.
+// A returned number corresponds to different file types (1 if only
+// one exists)
+//
+Byte_t MRead::IsFileValid(const char *name)
+{
+    return !gSystem->AccessPathName(name, kFileExists) ? 1 : 0;
+}
Index: trunk/MagicSoft/Mars/mfileio/MRead.h
===================================================================
--- trunk/MagicSoft/Mars/mfileio/MRead.h	(revision 5159)
+++ trunk/MagicSoft/Mars/mfileio/MRead.h	(revision 5160)
@@ -21,4 +21,6 @@
     virtual Bool_t  Rewind();
 
+    static Byte_t IsFileValid(const char *name);
+
     void SetSelector(MFilter *f) { fSelector = f; }
     MFilter *GetSelector() { return fSelector; }
Index: trunk/MagicSoft/Mars/mfileio/MReadMarsFile.cc
===================================================================
--- trunk/MagicSoft/Mars/mfileio/MReadMarsFile.cc	(revision 5159)
+++ trunk/MagicSoft/Mars/mfileio/MReadMarsFile.cc	(revision 5160)
@@ -18,5 +18,5 @@
 !   Author(s): Thomas Bretz, 12/2000 <mailto:tbretz@astro.uni-wuerzburg.de>
 !
-!   Copyright: MAGIC Software Development, 2000-2003
+!   Copyright: MAGIC Software Development, 2000-2004
 !
 !
@@ -24,14 +24,19 @@
 
 /////////////////////////////////////////////////////////////////////////////
-//                                                                         //
-// MReadMarsFile                                                           //
-//                                                                         //
-// This task works more or less like MReadTree, but in addition PreProcess //
-// reads all the information from the 'RunHeader' tree.                    //
-//                                                                         //
-// Warning: Until now this works only for 'one run header per file'        //
-//                                                                         //
+//
+// MReadMarsFile
+//
+// This task works more or less like MReadTree, but in addition PreProcess
+// reads all the information from the 'RunHeader' tree.
+//
+// Warning: Until now this works only for 'one run header per file'
+//
 /////////////////////////////////////////////////////////////////////////////
 #include "MReadMarsFile.h"
+
+#include <fstream>
+
+#include <TFile.h>
+#include <TTree.h>
 
 #include "MLog.h"
@@ -92,4 +97,34 @@
 {
     delete fRun;
+}
+
+Byte_t MReadMarsFile::IsFileValid(const char *name)
+{
+    ifstream fin(name);
+    if (!fin)
+        return 0;
+
+    Char_t c[4];
+    fin.read(c, 4);
+    if (!fin)
+        return 0;
+
+    if (!(c[0]=='r'&& c[1]=='o' && c[2]=='o' && c[3]=='t'))
+        return 0;
+
+    TFile f(name, "READ");
+
+    TTree *t = (TTree*)f.Get("Events");
+    if (!t)
+        return 0;
+
+    // FIXME: Replace numbers by enum! Maybe use bits?
+    if (t->FindBranch("MRawEvtData."))
+        return t->FindBranch("MMcEvt.") ? 2 : 1;
+
+    if (t->FindBranch("MCerPhotEvt."))
+        return t->FindBranch("MMcEvt.") ? 4 : 3;
+
+    return 0;
 }
 
Index: trunk/MagicSoft/Mars/mfileio/MReadMarsFile.h
===================================================================
--- trunk/MagicSoft/Mars/mfileio/MReadMarsFile.h	(revision 5159)
+++ trunk/MagicSoft/Mars/mfileio/MReadMarsFile.h	(revision 5160)
@@ -24,4 +24,6 @@
     ~MReadMarsFile();
 
+    static Byte_t IsFileValid(const char *name);
+
     void SortFiles();
 
Index: trunk/MagicSoft/Mars/mfileio/MReadTree.cc
===================================================================
--- trunk/MagicSoft/Mars/mfileio/MReadTree.cc	(revision 5159)
+++ trunk/MagicSoft/Mars/mfileio/MReadTree.cc	(revision 5160)
@@ -157,4 +157,18 @@
 }
 
+Byte_t MReadTree::IsFileValid(const char *name)
+{
+    ifstream fin(name);
+    if (!fin)
+        return 0;
+
+    Char_t c[4];
+    fin.read(c, 4);
+    if (!fin)
+        return 0;
+
+    return c[0]=='r'&& c[1]=='o' && c[2]=='o' && c[3]=='t' ? 1 : 0;
+}
+
 // --------------------------------------------------------------------------
 //
Index: trunk/MagicSoft/Mars/mfileio/MReadTree.h
===================================================================
--- trunk/MagicSoft/Mars/mfileio/MReadTree.h	(revision 5159)
+++ trunk/MagicSoft/Mars/mfileio/MReadTree.h	(revision 5160)
@@ -51,4 +51,6 @@
     ~MReadTree();
 
+    static Byte_t IsFileValid(const char *name);
+
     virtual void SortFiles();
 
