Changeset 8169


Ignore:
Timestamp:
10/27/06 14:36:33 (18 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/Changelog

    r8168 r8169  
    2323   * datacenter/macros/buildsequenceentries.C:
    2424     - included a fix for 0000-00-00 times in the run-database
     25
     26   * datacenter/macros/plotdb.C:
     27     - implemented a possibility to show average values with RMS
    2528
    2629
  • trunk/MagicSoft/Mars/datacenter/macros/plotdb.C

    r8132 r8169  
    11/* ======================================================================== *\
    2 ! $Name: not supported by cvs2svn $:$Id: plotdb.C,v 1.28 2006-10-19 13:57:14 tbretz Exp $
     2! $Name: not supported by cvs2svn $:$Id: plotdb.C,v 1.29 2006-10-27 13:36:18 tbretz Exp $
    33! --------------------------------------------------------------------------
    44!
     
    6969#include <TFrame.h>
    7070#include <TStyle.h>
    71 #include <TGraph.h>
    7271#include <TCanvas.h>
    7372#include <TSQLRow.h>
    7473#include <TSQLResult.h>
     74#include <TGraphErrors.h>
    7575
    7676#include "MTime.h"
     
    8282class MPlot : public MParContainer
    8383{
     84public:
     85    enum GroupBy_t
     86    {
     87        kNone,
     88        kGroupByDay,
     89        kGroupByWeek,
     90        kGroupByMonth,
     91        kGroupByYear
     92    };
    8493private:
    8594    MSQLServer &fServer;
     
    8796    MDataSet *fDataSet;
    8897
    89     TString fRequestFrom;
    90     TString fRequestTo;
    91     Int_t   fRequestPeriod;
    92 
    93     Float_t fPlotMin;
    94     Float_t fPlotMax;
    95 
    96     Float_t fHistMin;
    97     Float_t fHistMax;
    98 
    99     TString fDescription;
    100     TString fNameTab;
     98    TString   fRequestFrom;
     99    TString   fRequestTo;
     100    Int_t     fRequestPeriod;
     101
     102    Float_t   fPlotMin;
     103    Float_t   fPlotMax;
     104
     105    Float_t   fHistMin;
     106    Float_t   fHistMax;
     107
     108    TString   fDescription;
     109    TString   fNameTab;
     110
     111    TString   fCondition;
     112    GroupBy_t fGroupBy;
    101113
    102114    void PlotTable(TSQLResult &res, TString name, Float_t fmin, Float_t fmax, Float_t resolution)
     
    106118        TSQLRow *row;
    107119
    108         TGraph gt;
     120        TGraph &gt = res.GetFieldCount()>4 ? *new TGraphErrors : *new TGraph;
    109121        gt.SetNameTitle(name, Form("%s vs Time", name.Data()));
    110122        gt.SetMarkerStyle(kFullDotMedium);
     
    135147            const char *val  = (*row)[2];
    136148            const char *snum = (*row)[3];
     149            const char *verr = res.GetFieldCount()>4 ? (*row)[5] : 0;
    137150            if (!date || !val || !zd || !snum)
    138151                continue;
     
    171184            gt.SetPoint(gt.GetN(), t.GetAxisTime(), value);
    172185            gz.SetPoint(gz.GetN(), zenith, value);
     186
     187            if (verr)
     188                static_cast<TGraphErrors&>(gt).SetPointError(gt.GetN()-1, 0, atof(verr));
    173189        }
    174190
     
    299315public:
    300316    MPlot(MSQLServer &server) : fServer(server), fDataSet(NULL),
    301         fRequestPeriod(-1), fPlotMin(0), fPlotMax(-1), fHistMin(0), fHistMax(-1)
     317        fRequestPeriod(-1), fPlotMin(0), fPlotMax(-1), fHistMin(0), fHistMax(-1), fGroupBy(kNone)
    302318    {
    303319    }
     
    317333            fDataSet = new MDataSet(filename);
    318334    }
    319     void SetPlotRange(Float_t min, Float_t max, Int_t n=5)
    320     { fPlotMin = min; fPlotMax = max; }
    321     void SetHistRange(Float_t min, Float_t max)
    322     { fHistMin = min; fHistMax = max; }
    323     void SetRequestRange(const char *from="", const char *to="")
    324     { fRequestFrom = from; fRequestTo = to; }
    325     void SetRequestPeriod(Int_t n=-1)
    326     { fRequestPeriod = n; }
     335    void SetPlotRange(Float_t min, Float_t max, Int_t n=5) { fPlotMin = min; fPlotMax = max; }
     336    void SetHistRange(Float_t min, Float_t max) { fHistMin = min; fHistMax = max; }
     337    void SetRequestRange(const char *from="", const char *to="") { fRequestFrom = from; fRequestTo = to; }
     338    void SetRequestPeriod(Int_t n=-1) { fRequestPeriod = n; }
    327339    void SetDescription(const char *d, const char *t=0) { fDescription = d; fNameTab = t; }
     340    void SetCondition(const char *cond="") { fCondition = cond; }
     341    void SetGroupBy(GroupBy_t b=kGroupByWeek) { fGroupBy=b; }
    328342
    329343    Bool_t Plot(const char *value, Float_t min=0, Float_t max=-1, Float_t resolution=0)
     
    341355
    342356        TString query;
    343         query  = Form("select %s, %s, %s, Sequences.fSequenceFirst ",    valued.Data(), named2.Data(), valuev.Data());
     357        if (fGroupBy==kNone)
     358            query = Form("select %s, %s, %s, Sequences.fSequenceFirst ", valued.Data(), named2.Data(), valuev.Data());
     359        else
     360            query = Form("select %s, AVG(%s), AVG(%s), Sequences.fSequenceFirst, STD(%s), STD(%s) ", valued.Data(), named2.Data(), valuev.Data(), named2.Data(), valuev.Data());
     361
     362        switch (fGroupBy)
     363        {
     364        case kNone:
     365            break;
     366        case kGroupByDay:
     367            query += Form(", date_format(adddate(%s,Interval 12 hour), '%%Y-%%m-%%d') as %s ", named.Data(), valued.Data());
     368            break;
     369        case kGroupByWeek:
     370            query += Form(", date_format(adddate(%s,Interval 12 hour), '%%x%%v') as %s ", named.Data(), valued.Data());
     371            break;
     372        case kGroupByMonth:
     373            query += Form(", date_format(adddate(%s,Interval 12 hour), '%%Y-%%m') as %s ", named.Data(), valued.Data());
     374            break;
     375        case kGroupByYear:
     376            query += Form(", date_format(adddate(%s,Interval 12 hour), '%%Y') as %s ", named.Data(), valued.Data());
     377            break;
     378        }
     379
    344380        query += Form("from %s left join %s ", tabled.Data(), tablev.Data());
    345         query += Form("on %s.%s=%s.%s ",       tabled.Data(), join.Data(), tablev.Data(), join.Data());
     381        query += Form("on %s.%s=%s.%s ", tabled.Data(), join.Data(), tablev.Data(), join.Data());
    346382
    347383        const Bool_t interval = !fRequestFrom.IsNull() && !fRequestTo.IsNull();
    348384
    349         if (!fDataSet && !interval && tabled=="Star")
     385        if (!fDataSet && !interval && tablev=="Star")
    350386        {
    351387            if (!query.Contains("Star.fSequenceFirst"))
    352388                query += "left join Star on Sequences.fSequenceFirst=Star.fSequenceFirst ";
    353             query += "where Star.fEffOnTime>300 ";
     389            // This is from a plot PSF/MuonNumber
     390            query += "where Star.fMuonNumber>300 ";
    354391        }
    355392
     
    359396            query += Form("fRunStart between '%s' and '%s' ",
    360397                          fRequestFrom.Data(), fRequestTo.Data());
     398        }
     399
     400        if (fGroupBy!=kNone)
     401        {
     402            query += Form(" GROUP BY %s ", valued.Data());
     403            //query += Form(" HAVING COUNT(%s)=(COUNT(*)+1)/2 ", valuev.Data());
    361404        }
    362405
     
    383426void plotall(MPlot &plot)
    384427{
     428    //plot.SetGroupBy(MPlot::kGroupByWeek);
     429
    385430    //inner camera
    386431    //from calib*.root
Note: See TracChangeset for help on using the changeset viewer.