Index: trunk/MagicSoft/Mars/mjobs/MJCalibration.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJCalibration.cc	(revision 5064)
+++ trunk/MagicSoft/Mars/mjobs/MJCalibration.cc	(revision 5111)
@@ -214,4 +214,8 @@
   SetDebug             ( kFALSE );
   SetIntensity         ( kFALSE );
+
+  SetNoStorage         ( kFALSE );
+  SetHistsStorage      ( kFALSE );
+
 }
 
@@ -983,6 +987,4 @@
           
         }
-      
-      
       return;
     }
@@ -1306,14 +1308,4 @@
 
     return Form("%s/%s-F1.root", (const char*)fPathOut, (const char*)fRuns->GetRunsAsFileName());
-}
-
-Bool_t MJCalibration::IsUseBlindPixel() const 
-{
-    return TESTBIT(fDevices,kUseBlindPixel);
-}
-
-Bool_t MJCalibration::IsUsePINDiode() const 
-{
-    return TESTBIT(fDevices,kUsePINDiode);
 }
 
@@ -1490,5 +1482,5 @@
 
     // --------------------------------------------------------------------------------
-
+    
     // Setup Tasklist
     MParList plist;
@@ -1546,9 +1538,11 @@
     // Initialize two histogram containers which could be modified in this class
     //
+    MHCalibrationRelTimeCam     reltimecam;
     MHCalibrationChargeCam      chargecam;
     MHCalibrationChargeBlindCam blindcam;
     plist.AddToList(&chargecam);
     plist.AddToList(&blindcam);
-
+    if (IsRelTimes())
+      plist.AddToList(&reltimecam);
     //
     // Data Reading tasks
@@ -1614,5 +1608,5 @@
         drawoption += "datacheck";
     if (fDisplayType == kFullDisplay)
-        drawoption += " all";
+        drawoption += "all";
 
     fillcam.SetDrawOption(drawoption.Data());
@@ -1742,7 +1736,16 @@
     DisplayResult(plist);
 
-    if (!WriteResult(plist.FindObject("MGeomCam")))
-        return kFALSE;
-
+    if (!IsNoStorage())
+      {
+        if (!WriteResult(plist.FindObject("MGeomCam")))
+          return kFALSE;
+      }
+
+    if (IsHistsStorage())
+      {
+        if (!WriteHists(plist))
+          return kFALSE;
+      }
+    
     *fLog << all << GetDescriptor() << ": Done." << endl;
 
@@ -1759,4 +1762,8 @@
 Bool_t MJCalibration::ReadCalibrationCam()
 {
+  
+  if (IsNoStorage())
+    return kFALSE;
+
   const TString fname = GetOutputFile();
   
@@ -1887,8 +1894,11 @@
 // The following containers are written:
 // - MStatusDisplay
-// - MCalibrationChargeCam or MCalibrationIntensityChargeCam 
-// - MCalibrationBlindCam  or MCalibrationIntensityBlindCam
-// - MCalibrationQECam     or MCalibrationIntensityQECam     
+// - MCalibrationChargeCam  or MCalibrationIntensityChargeCam 
+// - MCalibrationBlindCam   or MCalibrationIntensityBlindCam
+// - MCalibrationQECam      or MCalibrationIntensityQECam     
+// - MCalibrationChargePINDiode
 // - MBadPixelsCam
+// If the flag kRelTimes is set, then also:
+// - MCalibrationRelTimeCam or MCalibrationIntensityRelTimeCam     
 //
 Bool_t MJCalibration::WriteResult(TObject *geom)
@@ -1926,4 +1936,5 @@
     else
     {
+        cont.Add(&fBadPixels);
         cont.Add(&fCalibrationCam);
         cont.Add(&fQECam);
@@ -1931,16 +1942,51 @@
     }
     cont.Add(&fCalibrationPINDiode);
-    cont.Add(&fBadPixels);
     if (IsRelTimes())
-          cont.Add(IsIntensity() ? (TObject*)&fIntensRelTimeCam : (TObject*)&fRelTimeCam);
+      cont.Add(IsIntensity() ? (TObject*)&fIntensRelTimeCam : (TObject*)&fRelTimeCam);
 
     if (!geom)
         *fLog << warn << " - WARNING - MGeomCam... not found!" << endl;
     else
-        cont.Add(geom);
+      cont.Add(geom);
 
     return WriteContainer(cont);
-
-    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+// Write the calibration histograms into the output file GetOutputFile(), 
+// if fOutputPath exists.
+// 
+// The following containers are written:
+// - MHCalibrationChargeCam
+// - MHCalibrationChargeBlindCam
+// - MHCalibrationChargePINDiode
+// If the flag kRelTimes is set, then also:
+// - MHCalibrationRelTimeBlindCam
+//
+Bool_t MJCalibration::WriteHists(MParList &plist)
+{
+    if (fPathOut.IsNull())
+        return kTRUE;
+
+    const TString oname(GetOutputFile());
+
+    *fLog << inf << "Writing to file: " << oname << endl;
+
+    TFile file(oname, "UPDATE", "File created by MJCalibration", 9);
+    if (!file.IsOpen())
+    {
+        *fLog << err << "ERROR - Couldn't open file " << oname << " for writing..." << endl;
+        return kFALSE;
+    }
+
+    TObjArray cont;
+    cont.Add(plist.FindObject("MHCalibrationChargeCam"));
+    cont.Add(plist.FindObject("MHCalibrationChargeBlindCam"));
+    cont.Add(plist.FindObject("MHCalibrationChargePINDiode"));
+    if (IsRelTimes())
+      cont.Add(plist.FindObject("MHCalibrationRelTimeCam"));
+
+    return WriteContainer(cont);
 }
 
