Index: trunk/MagicSoft/Mars/NEWS
===================================================================
--- trunk/MagicSoft/Mars/NEWS	(revision 6192)
+++ trunk/MagicSoft/Mars/NEWS	(revision 6193)
@@ -1,4 +1,17 @@
                                                                -*-*- END -*-*-
  *** Version <cvs>
+
+   - Reference lines in the display can be read from conf. file
+
+   - Interlaced cal. events are now handled correctly by callisto. 
+
+   - High-Gain vs. Low-Gain calibration constants can be calculated (but not 
+     yet applied) in callisto.
+
+   - class MJCalibTest can be called by callisto
+
+   - interpolated pointing positions are now in Tree "Events" after calibration
+
+   - callisto can now run with three data types: rawdata, rootdata, MC
 
    - added two classes mreport/MReportStarguider.cc and 
Index: trunk/MagicSoft/Mars/mjobs/MJCalibTest.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJCalibTest.cc	(revision 6192)
+++ trunk/MagicSoft/Mars/mjobs/MJCalibTest.cc	(revision 6193)
@@ -66,5 +66,7 @@
 
 #include "MReadMarsFile.h"
+#include "MRawFileRead.h"
 #include "MGeomApply.h"
+#include "MGeomCam.h"
 #include "MExtractTimeAndChargeSlidingWindow.h"
 #include "MExtractor.h"
@@ -239,4 +241,18 @@
 
 
+const char* MJCalibTest::GetInputFile() const
+{
+
+  if (fSequence.IsValid())
+    return Form("%s/calib%08d.root", (const char*)fPathOut, fSequence.GetSequence());
+  
+  if (!fRuns)
+    return "";
+  
+  return Form("%s/%s-F1.root", (const char*)fPathOut, (const char*)fRuns->GetRunsAsFileName());
+  
+}
+
+
 const char* MJCalibTest::GetOutputFile() const
 {
@@ -252,33 +268,120 @@
 }
 
-
-Bool_t MJCalibTest::Process(MPedestalCam &pedcam, 
-				   MCalibrationChargeCam &calcam, MCalibrationQECam &qecam, 
-				   MCalibrationRelTimeCam &reltime, 
-				   Byte_t filetype)
+Bool_t MJCalibTest::ReadCalibration(TObjArray &l, MBadPixelsCam &cam, MExtractor* &ext1, MExtractor* &ext2, TString &geom) const
+{
+
+  const TString fname = GetInputFile();
+  
+  *fLog << inf << "Reading from file: " << fname << endl;
+
+  TFile file(fname, "READ");
+  if (!file.IsOpen())
+    {
+      *fLog << err << dbginf << "ERROR - Could not open file " << fname << endl;
+      return kFALSE;
+    }
+  
+  TObject *o = file.Get("ExtractSignal");
+  if (o && !o->InheritsFrom(MExtractor::Class()))
+    {
+      *fLog << err << dbginf << "ERROR - ExtractSignal read from " << fname << " doesn't inherit from MExtractor!" << endl;
+      return kFALSE;
+    }
+  ext1 = o ? (MExtractor*)o->Clone() : NULL;
+  
+  o = file.Get("ExtractTime");
+  if (o && !o->InheritsFrom(MExtractor::Class()))
+    {
+      *fLog << err << dbginf << "ERROR - ExtractTime read from " << fname << " doesn't inherit from MExtractor!" << endl;
+      return kFALSE;
+    }
+  ext2 = o ? (MExtractor*)o->Clone() : NULL;
+  if (!ext1 && !ext2)
+    {
+      *fLog << err << dbginf << "ERROR - Neither ExtractSignal nor ExrtractTime found in " << fname << "!" << endl;
+      return kFALSE;
+    }
+  
+  o = file.Get("MGeomCam");
+  if (o && !o->InheritsFrom(MGeomCam::Class()))
+    {
+      *fLog << err << dbginf << "ERROR - MGeomCam read from " << fname << " doesn't inherit from MGeomCam!" << endl;
+      return kFALSE;
+    }
+  geom = o ? o->ClassName() : "";
+  
+  TObjArray cont(l);
+  cont.Add(&cam);
+  return ReadContainer(cont);
+}
+
+// --------------------------------------------------------------------------
+//
+// MJCalibration allows to setup several option by a resource file:
+//   MJCalibrateSignal.RawData: yes,no
+//
+// For more details see the class description and the corresponding Getters
+//
+Bool_t MJCalibTest::CheckEnvLocal()
+{
+
+  SetUseRootData();
+  
+  if (HasEnv("DataType"))
+    {
+      TString dat = GetEnv("DataType", "");
+      if (dat.BeginsWith("raw", TString::kIgnoreCase))
+        {
+          fDataFlag = 0;
+          SetUseRawData();
+        }
+      if (dat.BeginsWith("root", TString::kIgnoreCase))
+        {
+          fDataFlag = 0;
+          SetUseRootData();
+      }
+      if (dat.BeginsWith("mc", TString::kIgnoreCase))
+        {
+          fDataFlag = 0;
+          SetUseMC();
+        }
+    }
+  return kTRUE;
+}
+
+Bool_t MJCalibTest::Process(MPedestalCam &pedcam)
 {
     // const TString fname = GetOutputFile();
   
 //  if (gSystem->AccessPathName(fname, kFileExists))
-    return ProcessFile(pedcam,calcam,qecam,reltime,filetype);
+    return ProcessFile(pedcam);
   
     // return kTRUE;
 }
 
-Bool_t MJCalibTest::ProcessFile(MPedestalCam &pedcam, 
-				       MCalibrationChargeCam &calcam, MCalibrationQECam &qecam, 
-				       MCalibrationRelTimeCam &relcam,
-				       Byte_t filetype)
-{
-  if (!fRuns)
-    {
-      *fLog << err << "No Runs choosen... abort." << endl;
-      return kFALSE;
-    }
-  if (fRuns->GetNumRuns() != fRuns->GetNumEntries())
-    {
-      *fLog << err << "Number of files found doesn't match number of runs... abort." << endl;
-      return kFALSE;
-    }
+Bool_t MJCalibTest::ProcessFile(MPedestalCam &pedcam)
+{
+  
+
+  if (!fSequence.IsValid())
+    {
+      if (!fRuns)
+        {
+            *fLog << err << "ERROR - Sequence invalid and no runs chosen!" << endl;
+            return kFALSE;
+	}
+      
+      if (fRuns->GetNumRuns() != fRuns->GetNumEntries())
+        {
+          *fLog << err << "Number of files found doesn't match number of runs... abort."
+                << fRuns->GetNumRuns() << " vs. " << fRuns->GetNumEntries() << endl;
+          return kFALSE;
+        }
+      *fLog << "Calibrate data from ";
+      *fLog << "Runs " << fRuns->GetRunsAsString() << endl;
+      *fLog << endl;
+    }
+  
+  CheckEnv();
 
   *fLog << inf;
@@ -287,6 +390,68 @@
   *fLog << endl;
 
-  MBadPixelsCam badcam;
-  
+  MDirIter iter;
+
+  if (fSequence.IsValid())
+    {
+      const Int_t n0 = fSequence.SetupDatRuns(iter, fPathData, "D", IsUseRawData());
+      const Int_t n1 = fSequence.GetNumDatRuns();
+      if (n0==0)
+        {
+          *fLog << err << "ERROR - No input files of sequence found!" << endl;
+          return kFALSE;
+        }
+      if (n0!=n1)
+        {
+          *fLog << err << "ERROR - Number of files found (" << n0 << ") doesn't match number of files in sequence (" << n1 << ")" << endl;
+          return kFALSE;
+        }
+    }
+  
+  MCalibrationChargeCam      calcam;
+  MCalibrationQECam          qecam;
+  MCalibrationRelTimeCam     tmcam;
+  MBadPixelsCam              badpix;
+  
+  TObjArray calibcont;
+  calibcont.Add(&calcam);
+  calibcont.Add(&qecam);
+  calibcont.Add(&tmcam);
+    
+  MExtractor *extractor1=0;
+  MExtractor *extractor2=0;
+  TString geom;
+
+  if (!ReadCalibration(calibcont, badpix, extractor1, extractor2, geom))
+    return kFALSE;
+  
+  *fLog << all;
+  if (extractor1)
+    {
+      *fLog << underline << "Signal Extractor found in calibration file" << endl;
+      extractor1->Print();
+      *fLog << endl;
+    }
+  else
+    *fLog << inf << "No Signal Extractor: ExtractSignal in file." << endl;
+  
+  if (extractor2)
+    {
+      *fLog << underline << "Time Extractor found in calibration file" << endl;
+      extractor2->Print();
+      *fLog << endl;
+    }
+  else
+    *fLog << inf << "No Time Extractor: ExtractTime in file." << endl;
+  
+  if (!geom.IsNull())
+    *fLog << inf << "Camera geometry found in file: " << geom << endl;
+  else
+    *fLog << inf << "No Camera geometry found using default <MGeomCamMagic>" << endl;
+
+  if (fExtractor)
+    extractor1 = fExtractor;
+  if (fTimeExtractor)
+    extractor2 = fTimeExtractor;
+
   // Setup Lists
   MParList plist;
@@ -294,9 +459,9 @@
   plist.AddToList(&fTestCam);
   plist.AddToList(&fTestTimeCam);
-  plist.AddToList(&badcam);
+  plist.AddToList(&badpix);
   plist.AddToList(&pedcam);
   plist.AddToList(&calcam);
   plist.AddToList(&qecam);
-  plist.AddToList(&relcam);
+  plist.AddToList(&tmcam);
 
   MCerPhotEvt          cerphot;
@@ -314,8 +479,13 @@
 
   // Setup Task-lists
+  MRawFileRead rawread(NULL);
   MReadMarsFile read("Events");
   read.DisableAutoScheme();
-  static_cast<MRead&>(read).AddFiles(*fRuns);
-  
+
+  if (IsUseRawData())
+    rawread.AddFiles(fSequence.IsValid() ? iter : *fRuns);
+  else
+    static_cast<MRead&>(read).AddFiles(fSequence.IsValid() ? iter : *fRuns);
+
   // Check for interleaved events
   MTriggerPatternDecode decode;
@@ -325,6 +495,7 @@
 
   MGeomApply            apply; // Only necessary to craete geometry
-  apply.SetGeometry(fGeometry);  
-  MBadPixelsMerge       merge(&fBadPixels);
+  if (!geom.IsNull())
+    apply.SetGeometry(geom);  
+  MBadPixelsMerge       merge(&badpix);
 
   MExtractTimeAndChargeSlidingWindow extrsw;
@@ -335,8 +506,8 @@
   MTaskEnv taskenv2("ExtractTime");
 
-  if (fExtractor)
+  if (extractor1)
     { 
-      fExtractor->SetPedestals(&pedcam);
-      taskenv1.SetDefault(fExtractor);
+      extractor1->SetPedestals(&pedcam);
+      taskenv1.SetDefault(extractor1);
     }
   if (fTimeExtractor)
@@ -356,5 +527,5 @@
   MCalibrateData        photcalc;
   MCalibrateRelTimes    caltimes;
-  if (filetype==3) // MC file
+  if (IsUseMC()) // MC file
     {
       photcalc.SetCalibrationMode(MCalibrateData::kFfactor);
@@ -409,5 +580,5 @@
   tlist.AddToList(&conttp);
   tlist.AddToList(&taskenv1);
-  if (!fExtractor->InheritsFrom("MExtractTimeAndCharge"))
+  if (!extractor1->InheritsFrom("MExtractTimeAndCharge"))
     tlist.AddToList(&taskenv2);
   tlist.AddToList(&contcos);
@@ -448,41 +619,4 @@
 }
 
-Bool_t MJCalibTest::ReadPedPhotCam()
-{
-
-  const TString fname = GetOutputFile();
-  
-  if (gSystem->AccessPathName(fname, kFileExists))
-    {
-      *fLog << err << "Input file " << fname << " doesn't exist." << endl;
-      return kFALSE;
-    }
-  
-  *fLog << inf << "Reading from file: " << fname << endl;
-  
-  TFile file(fname, "READ");
-  if (fPedPhotCam.Read()<=0)
-    {
-      *fLog << "Unable to read MPedPhotCam from " << fname << endl;
-      return kFALSE;
-    }
-
-  if (file.FindKey("MBadPixelsCam"))
-    {
-      MBadPixelsCam bad;
-      if (bad.Read()<=0)
-        {
-          *fLog << "Unable to read MBadPixelsCam from " << fname << endl;
-          return kFALSE;
-        }
-      fBadPixels.Merge(bad);
-    }
-  
-  if (fDisplay /*&& !fDisplay->GetCanvas("Pedestals")*/) // FIXME!
-    fDisplay->Read();
-  
-  return kTRUE;
-}
-
 Bool_t MJCalibTest::WriteResult()
 {
Index: trunk/MagicSoft/Mars/mjobs/MJCalibTest.h
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJCalibTest.h	(revision 6192)
+++ trunk/MagicSoft/Mars/mjobs/MJCalibTest.h	(revision 6193)
@@ -52,6 +52,6 @@
   TString fGeometry;
   
-  Bool_t ReadPedPhotCam();
-  
+  Bool_t CheckEnvLocal();
+
   void   DisplayResult(MParList &plist);
   void   DisplayResultT(MParList &plist);
@@ -59,6 +59,8 @@
   Bool_t WriteResult();
   
-  Bool_t ProcessFile(MPedestalCam &pedcam, MCalibrationChargeCam &calcam, MCalibrationQECam &qecam, 
-		     MCalibrationRelTimeCam &rel, Byte_t filetype);
+  Bool_t ReadCalibration(TObjArray &o, MBadPixelsCam &bpix,
+                         MExtractor* &ext1, MExtractor* &ext2, TString &geom) const;
+
+  Bool_t ProcessFile(MPedestalCam &pedcam);
 
 public:
@@ -67,4 +69,5 @@
   
   const char* GetOutputFile() const;
+  const char* GetInputFile() const;
   
   MCalibrationTestCam      &GetTestCam()      { return fTestCam; }
@@ -82,6 +85,5 @@
   void SetNormalDisplay()    { fDisplayType = kNormalDisplay;    }
   
-  Bool_t Process(MPedestalCam &pedcam, MCalibrationChargeCam &calcam, MCalibrationQECam &qecam, 
-		 MCalibrationRelTimeCam &relcam,Byte_t filetype=1);
+  Bool_t Process(MPedestalCam &pedcam);
   
   ClassDef(MJCalibTest, 0) // Tool to calibrate and test the calibration run itself
