Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 8139)
+++ trunk/MagicSoft/Mars/Changelog	(revision 8140)
@@ -18,4 +18,24 @@
 
                                                  -*-*- END OF LINE -*-*-
+ 2006/10/20 Thomas Bretz
+
+   * datacenter/macros/plotoptical.C:
+     - improved with more interesting values
+
+   * mastro/MAstro.h:
+     - added new constant for conversion from and into hours
+
+   * mbadpixels/MBadPixelsIntensityCam.[h,cc],
+     mcalib/MCalibrationIntensityCam.[h,cc]:
+     - added a RemoveOldCam member function
+     - commented out unused GetCam functions
+
+   * mcalib/MCalibCalcFromPast.cc:
+     - removed some obsolete output in the case FindCreateObj fains
+     - if a new cam is added to the intensity cam list the old
+       cam is deleted now which fixes the bigges memory leak in callisto
+
+
+
  2006/10/20 Daniela Dorner
 
Index: trunk/MagicSoft/Mars/NEWS
===================================================================
--- trunk/MagicSoft/Mars/NEWS	(revision 8139)
+++ trunk/MagicSoft/Mars/NEWS	(revision 8140)
@@ -7,7 +7,4 @@
    - database: For sequences there is now also the stoptime available on the
      websites. 
-
-   - database: Order-by is now working also on printtable.php and when 
-     group-by is chosen. 
 
    - database: Removed ManuallyChanged flag from sequence-info websites, 
@@ -33,4 +30,8 @@
      over all possible set of weights. This also gives correct numbers
      for the lo-gains which were totally wrong before.
+
+   - callisto: drastically reduced memory consumption by not storing
+     all intermediate calibration results in memory anymore (we might
+     write them into a file in the future)
 
    - ganymed: To get a nice Theta-Sq plot (instead of the all-information
Index: trunk/MagicSoft/Mars/datacenter/macros/plotoptical.C
===================================================================
--- trunk/MagicSoft/Mars/datacenter/macros/plotoptical.C	(revision 8139)
+++ trunk/MagicSoft/Mars/datacenter/macros/plotoptical.C	(revision 8140)
@@ -1,4 +1,4 @@
 /* ======================================================================== *\
-! $Name: not supported by cvs2svn $:$Id: plotoptical.C,v 1.1 2006-10-19 18:45:51 tbretz Exp $
+! $Name: not supported by cvs2svn $:$Id: plotoptical.C,v 1.2 2006-10-20 18:26:00 tbretz Exp $
 ! --------------------------------------------------------------------------
 !
@@ -101,4 +101,5 @@
 
     TString fCondition;
+    Bool_t  fGroupBy;
 
     void PlotTable(TSQLResult &res, TString name, Float_t fmin, Float_t fmax, Float_t resolution)
@@ -298,4 +299,5 @@
 
         gz.DrawClone("AP");
+
         if (gz0.GetN()>0)
             gz0.DrawClone("P");
@@ -306,5 +308,5 @@
 public:
     MPlot(MSQLMagic &server) : fServer(server), fDataSet(NULL),
-        fRequestPeriod(-1), fPlotMin(0), fPlotMax(-1), fHistMin(0), fHistMax(-1)
+        fRequestPeriod(-1), fPlotMin(0), fPlotMax(-1), fHistMin(0), fHistMax(-1), fGroupBy(kFALSE)
     {
     }
@@ -335,4 +337,5 @@
     { fCondition = cond; }
     void SetDescription(const char *d, const char *t=0) { fDescription = d; fNameTab = t; }
+    void EnableGroupBy(Bool_t b=kTRUE) { fGroupBy=b; }
 
     Int_t QueryKeyOfSource(TString src)
@@ -343,6 +346,6 @@
     Bool_t Plot(const char *value, Float_t min=0, Float_t max=-1, Float_t resolution=0)
     {
-        TString named  = "OpticalData.fTimestamp";
-        TString named2 = "fSkyLevel";
+        TString named  = "OpticalData.fTimeStamp";
+        TString named2 = fGroupBy ? "AVG(fZenithDistance)" : "fZenithDistance";
         TString namev  = value;
         TString join   = "fSequenceFirst";
@@ -355,21 +358,12 @@
 
         TString query;
-        query  = Form("select %s, %s, %s ", valued.Data(), named2.Data(), valuev.Data());
+        query  = Form("select %s, %s, %s ", valued.Data(), named2.Data(), value);
         query += Form("from %s ",           tabled.Data());
 
-        const Bool_t interval = !fRequestFrom.IsNull() && !fRequestTo.IsNull();
-
-        if (!fDataSet && !interval && tabled=="Star")
-        {
-            if (!query.Contains("Star.fSequenceFirst"))
-                query += "left join Star on Sequences.fSequenceFirst=Star.fSequenceFirst ";
-            query += "where Star.fEffOnTime>300 ";
-        }
-
-        if (interval)
-        {
-            query += query.Contains(" where ") ? "and " : "where ";
-            query += Form("fRunStart between '%s' and '%s' ",
-                          fRequestFrom.Data(), fRequestTo.Data());
+        //const Bool_t interval = !fRequestFrom.IsNull() && !fRequestTo.IsNull();
+
+        if (TString(value).Contains("Object."))
+        {
+            query += "left join Object on Object.fObjectKEY=OpticalData.fObjectKEY ";
         }
 
@@ -381,5 +375,8 @@
         }
 
-        query += "order by fTimestamp";
+        if (fGroupBy)
+            query += " GROUP BY fTimeStamp ";
+
+        query += "order by fTimeStamp";
 
         TSQLResult *res = fServer.Query(query);
@@ -421,5 +418,5 @@
     plot.SetDescription("Aperture Radius;R_{A}", "ApRad");
     plot.Plot("OpticalData.fApertureRadius", 0, 10, 1);
-
+/*
     plot.SetDescription("Instrumental Magnitude;M_{I}\\cdot s^{-1}", "InstMag/s");
     plot.Plot("OpticalData.fInstrumentalMag/OpticalData.fExposure",  0, 0.2, 0.005);
@@ -433,4 +430,32 @@
     plot.SetDescription("Instrumental Magnitude Error;\\sigma_{M}", "MagErr");
     plot.Plot("OpticalData.fInstrumentalMagErr",  0, 1, 0.01);
+  */
+    plot.SetDescription("m_{1};m_{1}", "M1");
+    plot.Plot("OpticalData.fInstrumentalMag+2.5*log10(OpticalData.fExposure)", 10, 35, 0.2);
+
+    cond += " and Object.fObjectName not like '%/BL' and not IsNull(Object.fMagnitude) ";
+    plot.SetCondition(cond);
+
+    TString ext("3080/25.0*pow(10, (OpticalData.fInstrumentalMag+2.5*log10(OpticalData.fExposure)-Object.fMagnitude)/-2.5)");
+    ext += "+0.0028*fZenithDistance-0.08";
+/*
+    plot.SetDescription("m_{1}-m_{true} (Extinction per Object);m_{1}-m_{true}", "ExtObj");
+    plot.Plot(ext, 0.5, 1.2, 0.01);
+    */
+
+    plot.EnableGroupBy();
+    plot.SetDescription("m_{1}-m_{true} (Extinction per Image);m_{1}-m_{true}", "ExtImg");
+    plot.Plot(Form("AVG(%s)", ext.Data()), 0.05, 1.2, 0.01);
+
+    plot.SetDescription("Error m_{1}-m_{true} (Extinction per Image);ERR m_{1}-m_{true}", "ExtImgErr");
+    plot.Plot(Form("STD(%s)", ext.Data()), 0, 0.3, 0.005);
+
+    plot.SetDescription("m_{1}-m_{true} (Extinction per Hour);m_{1}-m_{true}", "ExtHour");
+    plot.Plot(Form("AVG(%s), date_format(fTimeStamp, '%%Y-%%m-%%d %%H') as fTimeStamp", ext.Data()),
+              0.5, 1.2, 0.01);
+
+    plot.SetDescription("m_{1}-m_{true} (Extinction per Night);m_{1}-m_{true}", "ExtNight");
+    plot.Plot(Form("AVG(%s), date_format(adddate(fTimeStamp,Interval 12 hour),'%%Y-%%m-%%d') as fTimeStamp", ext.Data()),
+              0.5, 1.2, 0.01);
 }
 
Index: trunk/MagicSoft/Mars/mastro/MAstro.h
===================================================================
--- trunk/MagicSoft/Mars/mastro/MAstro.h	(revision 8139)
+++ trunk/MagicSoft/Mars/mastro/MAstro.h	(revision 8140)
@@ -28,4 +28,9 @@
     static Double_t Parsec2Lighyear() { return 3.2615644; }
 
+    static Double_t DegToHor()        { return 15; }
+    static Double_t HorToDeg()        { return 1./15; }
+
+    static Double_t RadToHor()        { return 15/TMath::TwoPi(); }
+    static Double_t HorToRad()        { return TMath::TwoPi()/15; }
 
     // Angle/Time conversion functions
Index: trunk/MagicSoft/Mars/mbadpixels/MBadPixelsIntensityCam.cc
===================================================================
--- trunk/MagicSoft/Mars/mbadpixels/MBadPixelsIntensityCam.cc	(revision 8139)
+++ trunk/MagicSoft/Mars/mbadpixels/MBadPixelsIntensityCam.cc	(revision 8140)
@@ -234,5 +234,5 @@
   return static_cast<MBadPixelsCam*>(i==-1 ? fCams->Last() : fCams->At(i));
 }
-
+/*
 // --------------------------------------------------------------------------
 //
@@ -252,5 +252,5 @@
   return static_cast<MBadPixelsCam*>(fCams->FindObject(name));
 }
-
+*/
 // --------------------------------------------------------------------------
 //
Index: trunk/MagicSoft/Mars/mbadpixels/MBadPixelsIntensityCam.h
===================================================================
--- trunk/MagicSoft/Mars/mbadpixels/MBadPixelsIntensityCam.h	(revision 8139)
+++ trunk/MagicSoft/Mars/mbadpixels/MBadPixelsIntensityCam.h	(revision 8140)
@@ -15,7 +15,11 @@
 #endif
 
-class TOrdCollection;
+#ifndef ROOT_TOrdCollection
+#include <TOrdCollection.h>
+#endif
+
 class TGraph;
 class MHCamera;
+
 class MBadPixelsIntensityCam : public MParContainer, public MCamEvent
 {
@@ -42,7 +46,12 @@
         MBadPixelsCam *GetCam     ( Int_t i=-1);
   const MBadPixelsCam *GetCam     ( Int_t i=-1) const;
-
+  /*
         MBadPixelsCam *GetCam     ( const char *name );
   const MBadPixelsCam *GetCam     ( const char *name ) const;
+  */
+
+  // The "DeleteOldCam" function must not delete the first entry in
+  // the array because it is a special cam from the MParList. (see above)
+  void DeleteOldCam(MBadPixelsCam *cam) {/* if (fCams->IndexOf(cam)>0) delete fCams->Remove(cam);*/ }
 
         MBadPixelsPix &operator[] ( Int_t i );
Index: trunk/MagicSoft/Mars/mcalib/MCalibCalcFromPast.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibCalcFromPast.cc	(revision 8139)
+++ trunk/MagicSoft/Mars/mcalib/MCalibCalcFromPast.cc	(revision 8140)
@@ -167,4 +167,12 @@
     fIntensConst  = (MCalibrationIntensityConstCam*) pList->FindCreateObj("MCalibrationIntensityConstCam");
 
+    if (!fIntensCharge)
+        return kFALSE;
+    if (!fIntensQE)
+        return kFALSE;
+    if (!fIntensConst)
+        return kFALSE;
+    
+
     MCalibrationChargeCam *chargeinit = (MCalibrationChargeCam*)pList->FindObject("MCalibrationChargeCam");
     MCalibrationQECam     *qeinit     = (MCalibrationQECam*)    pList->FindObject("MCalibrationQECam");
@@ -190,16 +198,4 @@
     *fLog << inf << "Found MHCalibrationChargeCam ... " << flush;
 
-    if (!fIntensCharge)
-      {
-        *fLog << err << "Could not find nor create MCalibrationIntensityChargeCam abort... " << endl;
-        return kFALSE;
-      }
-    
-    if (!fIntensQE)
-      {
-        *fLog << err << "Could not find nor create MCalibrationIntensityQECam abort... " << endl;
-        return kFALSE;
-      }
-    
     if (!fChargeCalc)
       {
@@ -388,12 +384,19 @@
   const Int_t runnumber = fRunHeader->GetRunNumber();
 
+  // The "DeleteOldCam" function must not delete the first entry in
+  // the array because it is a special cam from the MParList. (see above)
+
   if (fIntensBad)
-    {
+  {
+      *fLog << "MBadPixelsCam...";
+      MBadPixelsCam *cold = fIntensBad->GetCam();
       fIntensBad->AddToList(Form("MBadPixelsCam%04d",fNumCam),*fGeom);
-      *fLog << "MBadPixelsCam...";
-    }
+      if (cold)
+          fIntensBad->DeleteOldCam(cold);
+  }
 
   if (fIntensCharge)
-    {
+  {
+        *fLog << "MCalibrationChargeCam...";
         MCalibrationChargeCam *cold = (MCalibrationChargeCam*)fIntensCharge->GetCam();
 
@@ -404,20 +407,28 @@
 
         if (cold)
+        {
             cnew->MergeHiLoConversionFactors(*cold);
-
-      *fLog << "MCalibrationChargeCam...";
-    }
+            fIntensCharge->DeleteOldCam(cold);
+        }
+  }
+
   if (fIntensQE)
-    {
+  {
+      *fLog << "MCalibrationQECam...";
+      MCalibrationCam *cold = fIntensQE->GetCam();
       fIntensQE->AddToList(Form("MCalibrationQECam%04d",fNumCam),*fGeom);
       fIntensQE->GetCam()->SetRunNumber(runnumber);
-      *fLog << "MCalibrationQECam...";
-    }
+      if (cold)
+          fIntensQE->DeleteOldCam(cold);
+  }
   if (fIntensBlind)
-    {
+  {
+      *fLog << "MCalibrationBlindCam...";
+      MCalibrationCam *cold = fIntensBlind->GetCam();
       fIntensBlind->AddToList(Form("MCalibrationBlindCam%04d",fNumCam),*fGeom);
       fIntensBlind->GetCam()->SetRunNumber(runnumber);
-      *fLog << "MCalibrationBlindCam...";
-    }
+      if (cold)
+          fIntensBlind->DeleteOldCam(cold);
+  }
 
   *fLog << endl;
Index: trunk/MagicSoft/Mars/mcalib/MCalibrationIntensityCam.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrationIntensityCam.cc	(revision 8139)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrationIntensityCam.cc	(revision 8140)
@@ -289,4 +289,5 @@
 // Get camera with name 'name' 
 //
+/*
 MCalibrationCam *MCalibrationIntensityCam::GetCam(const char *name)
 {
@@ -302,5 +303,5 @@
   return static_cast<MCalibrationCam*>(fCams->FindObject(name));
 }
-
+*/
 // --------------------------------------------------------------------------
 //
Index: trunk/MagicSoft/Mars/mcalib/MCalibrationIntensityCam.h
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrationIntensityCam.h	(revision 8139)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrationIntensityCam.h	(revision 8140)
@@ -42,5 +42,5 @@
   void AddHist(const MHCalibrationCam *cam);
 
-  Int_t CountNumEntries(const MCalibrationCam::PulserColor_t col) const;  
+  Int_t CountNumEntries(const MCalibrationCam::PulserColor_t col) const;
 
   const Int_t GetSize() const  { return fCams->GetSize();  }
@@ -57,11 +57,18 @@
   const MBadPixelsPix   &GetAverageBadSector ( UInt_t i )  const   { return GetCam()->GetAverageBadSector(i); }
 
-	MCalibrationCam *GetCam              ( Int_t i=-1)       { 
-	return static_cast<MCalibrationCam*>(i==-1 ? fCams->Last() : fCams->At(i)); }
-  const MCalibrationCam *GetCam              ( Int_t i=-1) const {
-        return static_cast<MCalibrationCam*>(i==-1 ? fCams->Last() : fCams->At(i)); }
+  MCalibrationCam *GetCam              ( Int_t i/*=-1*/)       {
+      return static_cast<MCalibrationCam*>(i==-1 ? fCams->Last() : fCams->At(i)); }
+  const MCalibrationCam *GetCam              ( Int_t i/*=-1*/) const {
+      return static_cast<MCalibrationCam*>(i==-1 ? fCams->Last() : fCams->At(i)); }
 
-        MCalibrationCam *GetCam              ( const char *name );
-  const MCalibrationCam *GetCam              ( const char *name ) const;
+  MCalibrationCam *GetCam() { return static_cast<MCalibrationCam*>(fCams->Last()); }
+  const MCalibrationCam *GetCam() const { return static_cast<MCalibrationCam*>(fCams->Last()); }
+
+//        MCalibrationCam *GetCam              ( const char *name );
+//  const MCalibrationCam *GetCam              ( const char *name ) const;
+
+  // The "DeleteOldCam" function must not delete the first entry in
+  // the array because it is a special cam from the MParList. (see above)
+  void DeleteOldCam(MCalibrationCam *cam) { /* if (fCams->IndexOf(cam)>0) delete fCams->Remove(cam);*/ }
 
         MHCalibrationCam *GetHist            ( Int_t i=-1);      
