Changeset 8185 for trunk/MagicSoft


Ignore:
Timestamp:
11/01/06 08:29:46 (18 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/Changelog

    r8182 r8185  
    1818
    1919                                                 -*-*- END OF LINE -*-*-
     20
     21 2006/11/01 Thomas Bretz
     22
     23   * datacenter/macros/plotdb.C, datacenter/macros/plotoptical.C:
     24     - a lot of changes starting to unify the different plot macros
     25     - use the new function to get the joins automatically
     26     - further improved grouping
     27
     28   * msql/MSQLServer.[h,cc]:
     29     - implemented a new function returning the primary key of a table
     30     - added a new function to return the joins automatically
     31       necessary to do a query
     32     - changed the call to GetTables and GetColumns
     33
     34
    2035
    2136 2006/10/31 Daniela Dorner
  • trunk/MagicSoft/Mars/datacenter/macros/plotdb.C

    r8169 r8185  
    11/* ======================================================================== *\
    2 ! $Name: not supported by cvs2svn $:$Id: plotdb.C,v 1.29 2006-10-27 13:36:18 tbretz Exp $
     2! $Name: not supported by cvs2svn $:$Id: plotdb.C,v 1.30 2006-11-01 08:29:45 tbretz Exp $
    33! --------------------------------------------------------------------------
    44!
     
    7070#include <TStyle.h>
    7171#include <TCanvas.h>
     72#include <TPRegexp.h>
    7273#include <TSQLRow.h>
    7374#include <TSQLResult.h>
     
    7778#include "MAstro.h"
    7879#include "MDataSet.h"
    79 #include "MSQLServer.h"
     80#include "MSQLMagic.h"
    8081#include "MStatusDisplay.h"
    8182
     
    8687    {
    8788        kNone,
    88         kGroupByDay,
     89        kGroupByPrimary,
     90        kGroupByHour,
     91        kGroupByNight,
    8992        kGroupByWeek,
    9093        kGroupByMonth,
     
    9295    };
    9396private:
    94     MSQLServer &fServer;
     97    MSQLMagic &fServer;
    9598
    9699    MDataSet *fDataSet;
     100
     101    TString   fPrimary;
     102    TString   fSecondary;
    97103
    98104    TString   fRequestFrom;
     
    146152            const char *zd   = (*row)[1];
    147153            const char *val  = (*row)[2];
    148             const char *snum = (*row)[3];
     154            const char *snum = res.GetFieldCount()>3 ? (*row)[3] : 0;
    149155            const char *verr = res.GetFieldCount()>4 ? (*row)[5] : 0;
    150             if (!date || !val || !zd || !snum)
     156            if (!date || !val || !zd)
    151157                continue;
    152158
     
    162168            last = TMath::Nint(TMath::Ceil(t.GetMjd()));
    163169
    164             UInt_t seq = atoi(snum);
     170            UInt_t seq = snum ? atoi(snum) : 0;
    165171   
    166172            Float_t value = atof(val);
     
    207213
    208214        cerr << setprecision(4) << setw(10) << title << ":   ";
     215        if (gt.GetN()==0)
     216        {
     217            cerr << "     <empty>" << endl;
     218            return;
     219        }
    209220        cerr << setw(8) << gt.GetMean(2) << "+-" << setw(8) << gt.GetRMS(2) << "   ";
    210221        if (gt0.GetN()>0 || gt1.GetN()>0)
     
    314325
    315326public:
    316     MPlot(MSQLServer &server) : fServer(server), fDataSet(NULL),
     327    MPlot(MSQLMagic &server) : fServer(server), fDataSet(NULL),
    317328        fRequestPeriod(-1), fPlotMin(0), fPlotMax(-1), fHistMin(0), fHistMax(-1), fGroupBy(kNone)
    318329    {
     
    337348    void SetRequestRange(const char *from="", const char *to="") { fRequestFrom = from; fRequestTo = to; }
    338349    void SetRequestPeriod(Int_t n=-1) { fRequestPeriod = n; }
     350    void SetCondition(const char *cond="") { fCondition = cond; }
    339351    void SetDescription(const char *d, const char *t=0) { fDescription = d; fNameTab = t; }
    340     void SetCondition(const char *cond="") { fCondition = cond; }
    341352    void SetGroupBy(GroupBy_t b=kGroupByWeek) { fGroupBy=b; }
     353    void SetPrimary(const char *ts) { fPrimary=ts; }
     354    void SetSecondary(const char *ts) { fSecondary=ts; }
    342355
    343356    Bool_t Plot(const char *value, Float_t min=0, Float_t max=-1, Float_t resolution=0)
    344357    {
    345         TString named  = "Sequences.fRunStart";
    346         TString named2 = "(Sequences.fZenithDistanceMin+Sequences.fZenithDistanceMax)/2";
     358        TString named  = fPrimary;
     359        TString named2 = fSecondary;
    347360        TString namev  = value;
    348361        TString join   = "fSequenceFirst";
     
    354367        TString valued = named(named.First('.')+1, named.Length());
    355368
    356         TString query;
     369        TString query="SELECT ";
     370        query += valued;
    357371        if (fGroupBy==kNone)
    358             query = Form("select %s, %s, %s, Sequences.fSequenceFirst ", valued.Data(), named2.Data(), valuev.Data());
     372        {
     373            query += ", ";
     374            query += fSecondary;
     375            query += ", ";
     376            query += value;
     377            query += ", ";
     378            query += " Sequences.fSequenceFirst ";
     379        }
    359380        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());
     381        {
     382            query += ", AVG(";
     383            query += fSecondary;
     384            query += "), AVG(";
     385            query += value;
     386            query += "), Sequences.fSequenceFirst, STD(";
     387            query += fSecondary;
     388            query += "), STD(";
     389            query += value;
     390            query += ") ";
     391        }
    361392
    362393        switch (fGroupBy)
    363394        {
    364395        case kNone:
     396        case kGroupByPrimary:
    365397            break;
    366         case kGroupByDay:
    367             query += Form(", date_format(adddate(%s,Interval 12 hour), '%%Y-%%m-%%d') as %s ", named.Data(), valued.Data());
     398        case kGroupByHour:
     399            query += Form(", DATE_FORMAT(%s, '%%Y-%%m-%%d %%H') AS %s ", named.Data(), valued.Data());
     400            break;
     401        case kGroupByNight:
     402            query += Form(", DATE_FORMAT(ADDDATE(%s,Interval 12 hour), '%%Y-%%m-%%d') AS %s ", named.Data(), valued.Data());
    368403            break;
    369404        case kGroupByWeek:
    370             query += Form(", date_format(adddate(%s,Interval 12 hour), '%%x%%v') as %s ", named.Data(), valued.Data());
     405            query += Form(", DATE_FORMAT(ADDDATE(%s,Interval 12 hour), '%%x%%v') AS %s ", named.Data(), valued.Data());
    371406            break;
    372407        case kGroupByMonth:
    373             query += Form(", date_format(adddate(%s,Interval 12 hour), '%%Y-%%m') as %s ", named.Data(), valued.Data());
     408            query += Form(", DATE_FORMAT(ADDDATE(%s,Interval 12 hour), '%%Y-%%m') AS %s ", named.Data(), valued.Data());
    374409            break;
    375410        case kGroupByYear:
    376             query += Form(", date_format(adddate(%s,Interval 12 hour), '%%Y') as %s ", named.Data(), valued.Data());
     411            query += Form(", DATE_FORMAT(ADDDATE(%s,Interval 12 hour), '%%Y') AS %s ", named.Data(), valued.Data());
    377412            break;
    378413        }
    379414
    380         query += Form("from %s left join %s ", tabled.Data(), tablev.Data());
    381         query += Form("on %s.%s=%s.%s ", tabled.Data(), join.Data(), tablev.Data(), join.Data());
     415        query += Form("FROM %s ", tabled.Data());
    382416
    383417        const Bool_t interval = !fRequestFrom.IsNull() && !fRequestTo.IsNull();
    384418
     419        TString where(fCondition);
    385420        if (!fDataSet && !interval && tablev=="Star")
    386421        {
    387             if (!query.Contains("Star.fSequenceFirst"))
    388                 query += "left join Star on Sequences.fSequenceFirst=Star.fSequenceFirst ";
    389             // This is from a plot PSF/MuonNumber
    390             query += "where Star.fMuonNumber>300 ";
     422            if (!where.IsNull())
     423                where += " AND ";
     424            where += "Star.fMuonNumber>300 ";
    391425        }
    392426
    393427        if (interval)
    394428        {
    395             query += query.Contains(" where ") ? "and " : "where ";
    396             query += Form("fRunStart between '%s' and '%s' ",
    397                           fRequestFrom.Data(), fRequestTo.Data());
     429            if (!where.IsNull())
     430                where += " AND ";
     431            where += Form("%s BETWEEN '%s' AND '%s' ",
     432                          fPrimary.Data(), fRequestFrom.Data(), fRequestTo.Data());
     433        }
     434
     435        // ------------------------------
     436
     437        query += fServer.GetJoins(tabled, query+" "+where);
     438
     439        if (!where.IsNull())
     440        {
     441            query += "WHERE ";
     442            query += where;
    398443        }
    399444
    400445        if (fGroupBy!=kNone)
    401446        {
    402             query += Form(" GROUP BY %s ", valued.Data());
     447            query += Form("GROUP BY %s ", valued.Data());
    403448            //query += Form(" HAVING COUNT(%s)=(COUNT(*)+1)/2 ", valuev.Data());
    404449        }
    405 
    406         query += "order by fRunStart";
     450        query += Form("ORDER BY %s ", fPrimary.Data());
     451
     452
     453        // ------------------------------
    407454
    408455        TSQLResult *res = fServer.Query(query);
     
    427474{
    428475    //plot.SetGroupBy(MPlot::kGroupByWeek);
     476
     477    plot.SetPrimary("Sequences.fRunStart");
     478    plot.SetSecondary("(Sequences.fZenithDistanceMin+Sequences.fZenithDistanceMax)/2");
    429479
    430480    //inner camera
     
    457507    plot.SetDescription("Hi-/Lo-Gain ratio;", "HiLoRatio");
    458508    plot.Plot("Calibration.fHiLoGainRatioMed", 10, 12.5, 0.05);
     509
     510    //plot.SetDescription("Pulse Variance;", "PulVar");
     511    //plot.Plot("Calibration.fPulsePosVar", 0, 0.03, 0.001);
    459512
    460513    //from star*.root
     
    522575    TEnv env("sql.rc");
    523576
    524     MSQLServer serv(env);
     577    MSQLMagic serv(env);
    525578    if (!serv.IsConnected())
    526579    {
     
    554607    TEnv env("sql.rc");
    555608
    556     MSQLServer serv(env);
     609    MSQLMagic serv(env);
    557610    if (!serv.IsConnected())
    558611    {
     
    586639    TEnv env("sql.rc");
    587640
    588     MSQLServer serv(env);
     641    MSQLMagic serv(env);
    589642    if (!serv.IsConnected())
    590643    {
  • trunk/MagicSoft/Mars/datacenter/macros/plotoptical.C

    r8140 r8185  
    11/* ======================================================================== *\
    2 ! $Name: not supported by cvs2svn $:$Id: plotoptical.C,v 1.2 2006-10-20 18:26:00 tbretz Exp $
     2! $Name: not supported by cvs2svn $:$Id: plotoptical.C,v 1.3 2006-11-01 08:29:45 tbretz Exp $
    33! --------------------------------------------------------------------------
    44!
     
    6969#include <TFrame.h>
    7070#include <TStyle.h>
    71 #include <TGraph.h>
    7271#include <TCanvas.h>
     72#include <TPRegexp.h>
    7373#include <TSQLRow.h>
    7474#include <TSQLResult.h>
     75#include <TGraphErrors.h>
    7576
    7677#include "MTime.h"
     
    8283class MPlot : public MParContainer
    8384{
     85public:
     86    enum GroupBy_t
     87    {
     88        kNone,
     89        kGroupByPrimary,
     90        kGroupByHour,
     91        kGroupByNight,
     92        kGroupByWeek,
     93        kGroupByMonth,
     94        kGroupByYear
     95    };
    8496private:
    8597    MSQLMagic &fServer;
     
    8799    MDataSet *fDataSet;
    88100
    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;
    101 
    102     TString fCondition;
    103     Bool_t  fGroupBy;
     101    TString   fPrimary;
     102    TString   fSecondary;
     103
     104    TString   fRequestFrom;
     105    TString   fRequestTo;
     106    Int_t     fRequestPeriod;
     107
     108    Float_t   fPlotMin;
     109    Float_t   fPlotMax;
     110
     111    Float_t   fHistMin;
     112    Float_t   fHistMax;
     113
     114    TString   fDescription;
     115    TString   fNameTab;
     116
     117    TString   fCondition;
     118    GroupBy_t fGroupBy;
    104119
    105120    void PlotTable(TSQLResult &res, TString name, Float_t fmin, Float_t fmax, Float_t resolution)
     
    109124        TSQLRow *row;
    110125
    111         TGraph gt;
     126        TGraph &gt = res.GetFieldCount()>4 ? *new TGraphErrors : *new TGraph;
    112127        gt.SetNameTitle(name, Form("%s vs Time", name.Data()));
    113128        gt.SetMarkerStyle(kFullDotMedium);
     
    138153            const char *val  = (*row)[2];
    139154            const char *snum = res.GetFieldCount()>3 ? (*row)[3] : 0;
     155            const char *verr = res.GetFieldCount()>4 ? (*row)[5] : 0;
    140156            if (!date || !val || !zd)
    141157                continue;
     
    174190            gt.SetPoint(gt.GetN(), t.GetAxisTime(), value);
    175191            gz.SetPoint(gz.GetN(), zenith, value);
    176         }
    177 
    178         TString title = fNameTab.IsNull() ? name(name.First('.')+2, name.Length()) : fNameTab;
    179         cerr << setprecision(4) << setw(10) << title << ":   ";
    180         if (gt.GetN()==0)
    181         {
    182             cerr << "     <empty>" << endl;
    183             return;
    184         }
    185         cerr << setw(8) << gt.GetMean(2) << "+-" << setw(8) << gt.GetRMS(2) << "   ";
    186         if (gt0.GetN()>0 || gt1.GetN()>0)
    187         {
    188             cerr << setw(8) << gt1.GetMean(2) << "+-" << setw(8) << gt1.GetRMS(2) << "   ";
    189             cerr << setw(8) << gt0.GetMean(2) << "+-" << setw(8) << gt0.GetRMS(2);
    190         }
    191         cerr << endl;
     192
     193            if (verr)
     194                static_cast<TGraphErrors&>(gt).SetPointError(gt.GetN()-1, 0, atof(verr));
     195        }
    192196
    193197        // If this is done earlier the plots remain empty since root 5.12/00
     
    202206        gROOT->SetSelectedPad(0);
    203207
     208        TString title = fNameTab.IsNull() ? name(name.First('.')+2, name.Length()) : fNameTab;
    204209        TCanvas &c = fDisplay ? fDisplay->AddTab(title) : *new TCanvas;
    205210        c.SetFillColor(kWhite);
    206211        c.SetBorderMode(0);
    207212        c.Divide(1,2);
     213
     214        cerr << setprecision(4) << setw(10) << title << ":   ";
     215        if (gt.GetN()==0)
     216        {
     217            cerr << "     <empty>" << endl;
     218            return;
     219        }
     220        cerr << setw(8) << gt.GetMean(2) << "+-" << setw(8) << gt.GetRMS(2) << "   ";
     221        if (gt0.GetN()>0 || gt1.GetN()>0)
     222        {
     223            cerr << setw(8) << gt1.GetMean(2) << "+-" << setw(8) << gt1.GetRMS(2) << "   ";
     224            cerr << setw(8) << gt0.GetMean(2) << "+-" << setw(8) << gt0.GetRMS(2);
     225        }
     226        cerr << endl;
    208227
    209228        TVirtualPad *pad = gPad;
     
    308327public:
    309328    MPlot(MSQLMagic &server) : fServer(server), fDataSet(NULL),
    310         fRequestPeriod(-1), fPlotMin(0), fPlotMax(-1), fHistMin(0), fHistMax(-1), fGroupBy(kFALSE)
     329        fRequestPeriod(-1), fPlotMin(0), fPlotMax(-1), fHistMin(0), fHistMax(-1), fGroupBy(kNone)
    311330    {
    312331    }
     
    326345            fDataSet = new MDataSet(filename);
    327346    }
    328     void SetPlotRange(Float_t min, Float_t max, Int_t n=5)
    329     { fPlotMin = min; fPlotMax = max; }
    330     void SetHistRange(Float_t min, Float_t max)
    331     { fHistMin = min; fHistMax = max; }
    332     void SetRequestRange(const char *from="", const char *to="")
    333     { fRequestFrom = from; fRequestTo = to; }
    334     void SetRequestPeriod(Int_t n=-1)
    335     { fRequestPeriod = n; }
    336     void SetCondition(const char *cond="")
    337     { fCondition = cond; }
     347    void SetPlotRange(Float_t min, Float_t max, Int_t n=5) { fPlotMin = min; fPlotMax = max; }
     348    void SetHistRange(Float_t min, Float_t max) { fHistMin = min; fHistMax = max; }
     349    void SetRequestRange(const char *from="", const char *to="") { fRequestFrom = from; fRequestTo = to; }
     350    void SetRequestPeriod(Int_t n=-1) { fRequestPeriod = n; }
     351    void SetCondition(const char *cond="") { fCondition = cond; }
    338352    void SetDescription(const char *d, const char *t=0) { fDescription = d; fNameTab = t; }
    339     void EnableGroupBy(Bool_t b=kTRUE) { fGroupBy=b; }
     353    void SetGroupBy(GroupBy_t b=kGroupByWeek) { fGroupBy=b; }
     354    void SetPrimary(const char *ts) { fPrimary=ts; }
     355    void SetSecondary(const char *ts) { fSecondary=ts; }
    340356
    341357    Int_t QueryKeyOfSource(TString src)
     
    346362    Bool_t Plot(const char *value, Float_t min=0, Float_t max=-1, Float_t resolution=0)
    347363    {
    348         TString named  = "OpticalData.fTimeStamp";
    349         TString named2 = fGroupBy ? "AVG(fZenithDistance)" : "fZenithDistance";
     364        TString named  = fPrimary;
     365        TString named2 = fSecondary;
    350366        TString namev  = value;
    351367        TString join   = "fSequenceFirst";
     
    357373        TString valued = named(named.First('.')+1, named.Length());
    358374
    359         TString query;
    360         query  = Form("select %s, %s, %s ", valued.Data(), named2.Data(), value);
    361         query += Form("from %s ",           tabled.Data());
    362 
    363         //const Bool_t interval = !fRequestFrom.IsNull() && !fRequestTo.IsNull();
    364 
    365         if (TString(value).Contains("Object."))
    366         {
    367             query += "left join Object on Object.fObjectKEY=OpticalData.fObjectKEY ";
    368         }
    369 
    370         if (!fCondition.IsNull())
    371         {
    372             query += "where ";
    373             query += fCondition;
    374             query += " ";
    375         }
    376 
    377         if (fGroupBy)
    378             query += " GROUP BY fTimeStamp ";
    379 
    380         query += "order by fTimeStamp";
     375        TString query="SELECT ";
     376        query += valued;
     377        if (fGroupBy==kNone)
     378        {
     379            query += ", ";
     380            query += fSecondary;
     381            query += ", ";
     382            query += value;
     383            query += ", 0 ";
     384        }
     385        else
     386        {
     387            query += ", AVG(";
     388            query += fSecondary;
     389            query += "), AVG(";
     390            query += value;
     391            query += "), COUNT(*), STD(";
     392            query += fSecondary;
     393            query += "), STD(";
     394            query += value;
     395            query += ") ";
     396        }
     397
     398        switch (fGroupBy)
     399        {
     400        case kNone:
     401        case kGroupByPrimary:
     402            break;
     403        case kGroupByHour:
     404            query += Form(", DATE_FORMAT(%s, '%%Y-%%m-%%d %%H') AS %s ", named.Data(), valued.Data());
     405            break;
     406        case kGroupByNight:
     407            query += Form(", DATE_FORMAT(ADDDATE(%s,Interval 12 hour), '%%Y-%%m-%%d') AS %s ", named.Data(), valued.Data());
     408            break;
     409        case kGroupByWeek:
     410            query += Form(", DATE_FORMAT(ADDDATE(%s,Interval 12 hour), '%%x%%v') AS %s ", named.Data(), valued.Data());
     411            break;
     412        case kGroupByMonth:
     413            query += Form(", DATE_FORMAT(ADDDATE(%s,Interval 12 hour), '%%Y-%%m') AS %s ", named.Data(), valued.Data());
     414            break;
     415        case kGroupByYear:
     416            query += Form(", DATE_FORMAT(ADDDATE(%s,Interval 12 hour), '%%Y') AS %s ", named.Data(), valued.Data());
     417            break;
     418        }
     419
     420        query += Form("FROM %s ", tabled.Data());
     421
     422        TString where(fCondition);
     423
     424        if (!where.IsNull())
     425            where += " AND ";
     426
     427        where += fCondition;
     428        where += " ";
     429
     430        // ------------------------------
     431
     432        query += fServer.GetJoins(tabled, query+" "+where);
     433
     434        if (!where.IsNull())
     435        {
     436            query += "WHERE ";
     437            query += where;
     438        }
     439
     440        if (fGroupBy!=kNone)
     441        {
     442            query += Form("GROUP BY %s ", valued.Data());
     443            //query += Form(" HAVING COUNT(%s)=(COUNT(*)+1)/2 ", valuev.Data());
     444        }
     445        query += Form("ORDER BY %s ", fPrimary.Data());
     446
     447
     448        // ------------------------------
    381449
    382450        TSQLResult *res = fServer.Query(query);
     
    396464void plotall(MPlot &plot, TString source)
    397465{
     466    plot.SetPrimary("OpticalData.fTimeStamp");
     467    plot.SetSecondary("fZenithDistance");
     468
     469
     470
    398471    TString cond = "fStatusKEY=13";
    399472    if (!source.IsNull())
     
    402475        if (key<0)
    403476            return;
    404         cond += Form(" and fObjectKEY=%d", key);
     477        cond += Form(" AND Object.fObjectKEY=%d", key);
    405478
    406479    }
     
    418491    plot.SetDescription("Aperture Radius;R_{A}", "ApRad");
    419492    plot.Plot("OpticalData.fApertureRadius", 0, 10, 1);
    420 /*
    421     plot.SetDescription("Instrumental Magnitude;M_{I}\\cdot s^{-1}", "InstMag/s");
    422     plot.Plot("OpticalData.fInstrumentalMag/OpticalData.fExposure",  0, 0.2, 0.005);
    423 
    424     plot.SetDescription("Instrumental Magnitude Error;\\sigma_{M}\\cdot s^{-1}", "MagErr/s");
    425     plot.Plot("OpticalData.fInstrumentalMagErr/OpticalData.fExposure",  0, 0.01, 0.0002);
    426 
    427     plot.SetDescription("Instrumental Magnitude;M_{I}", "InstMag");
    428     plot.Plot("OpticalData.fInstrumentalMag",  0, 30, 0.5);
    429 
    430     plot.SetDescription("Instrumental Magnitude Error;\\sigma_{M}", "MagErr");
    431     plot.Plot("OpticalData.fInstrumentalMagErr",  0, 1, 0.01);
    432   */
     493
     494    /*
     495     plot.SetDescription("Instrumental Magnitude;M_{I}\\cdot s^{-1}", "InstMag/s");
     496     plot.Plot("OpticalData.fInstrumentalMag/OpticalData.fExposure",  0, 0.2, 0.005);
     497
     498     plot.SetDescription("Instrumental Magnitude Error;\\sigma_{M}\\cdot s^{-1}", "MagErr/s");
     499     plot.Plot("OpticalData.fInstrumentalMagErr/OpticalData.fExposure",  0, 0.01, 0.0002);
     500
     501     plot.SetDescription("Instrumental Magnitude;M_{I}", "InstMag");
     502     plot.Plot("OpticalData.fInstrumentalMag",  0, 30, 0.5);
     503
     504     plot.SetDescription("Instrumental Magnitude Error;\\sigma_{M}", "MagErr");
     505     plot.Plot("OpticalData.fInstrumentalMagErr",  0, 1, 0.01);
     506     */
     507
    433508    plot.SetDescription("m_{1};m_{1}", "M1");
    434509    plot.Plot("OpticalData.fInstrumentalMag+2.5*log10(OpticalData.fExposure)", 10, 35, 0.2);
    435510
    436     cond += " and Object.fObjectName not like '%/BL' and not IsNull(Object.fMagnitude) ";
     511    cond += " AND Object.fObjectName NOT LIKE '%/BL' AND NOT ISNULL(Object.fMagnitude) ";
    437512    plot.SetCondition(cond);
    438513
    439514    TString ext("3080/25.0*pow(10, (OpticalData.fInstrumentalMag+2.5*log10(OpticalData.fExposure)-Object.fMagnitude)/-2.5)");
    440515    ext += "+0.0028*fZenithDistance-0.08";
    441 /*
    442     plot.SetDescription("m_{1}-m_{true} (Extinction per Object);m_{1}-m_{true}", "ExtObj");
    443     plot.Plot(ext, 0.5, 1.2, 0.01);
    444     */
    445 
    446     plot.EnableGroupBy();
     516
     517    plot.SetGroupBy(MPlot::kGroupByPrimary);
    447518    plot.SetDescription("m_{1}-m_{true} (Extinction per Image);m_{1}-m_{true}", "ExtImg");
    448     plot.Plot(Form("AVG(%s)", ext.Data()), 0.05, 1.2, 0.01);
    449 
    450     plot.SetDescription("Error m_{1}-m_{true} (Extinction per Image);ERR m_{1}-m_{true}", "ExtImgErr");
    451     plot.Plot(Form("STD(%s)", ext.Data()), 0, 0.3, 0.005);
    452 
     519    plot.Plot(ext/*Form("AVG(%s)", ext.Data())*/, 0.05, 1.2, 0.01);
     520
     521    plot.SetGroupBy(MPlot::kGroupByHour);
    453522    plot.SetDescription("m_{1}-m_{true} (Extinction per Hour);m_{1}-m_{true}", "ExtHour");
    454     plot.Plot(Form("AVG(%s), date_format(fTimeStamp, '%%Y-%%m-%%d %%H') as fTimeStamp", ext.Data()),
     523    plot.Plot(ext/*Form("AVG(%s), date_format(fTimeStamp, '%%Y-%%m-%%d %%H') as fTimeStamp", ext.Data())*/,
    455524              0.5, 1.2, 0.01);
    456525
     526    plot.SetGroupBy(MPlot::kGroupByNight);
    457527    plot.SetDescription("m_{1}-m_{true} (Extinction per Night);m_{1}-m_{true}", "ExtNight");
    458     plot.Plot(Form("AVG(%s), date_format(adddate(fTimeStamp,Interval 12 hour),'%%Y-%%m-%%d') as fTimeStamp", ext.Data()),
     528    plot.Plot(ext/*Form("AVG(%s), date_format(adddate(fTimeStamp,Interval 12 hour),'%%Y-%%m-%%d') as fTimeStamp", ext.Data())*/,
    459529              0.5, 1.2, 0.01);
    460530}
  • trunk/MagicSoft/Mars/mhflux/MHFalseSource.cc

    r8106 r8185  
    11/* ======================================================================== *\
    2 ! $Name: not supported by cvs2svn $:$Id: MHFalseSource.cc,v 1.20 2006-10-17 17:16:00 tbretz Exp $
     2! $Name: not supported by cvs2svn $:$Id: MHFalseSource.cc,v 1.21 2006-11-01 08:29:45 tbretz Exp $
    33! --------------------------------------------------------------------------
    44!
     
    121121#include <TF2.h>
    122122#include <TH2.h>
     123#include <TLatex.h>
    123124#include <TGraph.h>
    124125#include <TStyle.h>
    125126#include <TCanvas.h>
    126127#include <TRandom.h>
     128#include <TEllipse.h>
    127129#include <TPaveText.h>
    128130#include <TStopwatch.h>
     
    640642// source plot.
    641643//
    642 TObject *MHFalseSource::GetCatalog()
    643 {
    644     const Double_t maxr = 0.98*TMath::Abs(fHist.GetBinCenter(1));
     644TObject *MHFalseSource::GetCatalog() const
     645{
     646    const Double_t maxr = TMath::Abs(fHist.GetBinLowEdge(1))*TMath::Sqrt(2);
    645647
    646648    // Create catalog...
     
    12511253    }
    12521254}
     1255
     1256void MHFalseSource::DrawNicePlot() const
     1257{
     1258    Int_t newc = kTRUE;
     1259    Float_t zoom = 0.95;
     1260    Int_t col = kBlue+180;
     1261
     1262    if (!newc && !fDisplay)
     1263        return;
     1264
     1265    TH1 *h = dynamic_cast<TH1*>(FindObjectInPad("Alpha_yx_on"));
     1266    if (!h)
     1267        return;
     1268
     1269    // Open and setup canvas/pad
     1270    TCanvas &c = newc ? *new TCanvas("Excess", "Excess Plot", TMath::Nint(500.), TMath::Nint(500*0.77/0.89)) : fDisplay->AddTab("ThetsSq");
     1271
     1272    //c.SetPad(0.15, 0, 0.90, 1);
     1273
     1274    c.SetBorderMode(0);
     1275    c.SetFrameBorderMode(0);
     1276    c.SetFillColor(kWhite);
     1277
     1278    c.SetLeftMargin(0.11);
     1279    c.SetRightMargin(0.12);
     1280    c.SetBottomMargin(0.10);
     1281    c.SetTopMargin(0.01);
     1282
     1283    TH1 *h1 = (TH1*)h->Clone("");
     1284    h1->SetDirectory(0);
     1285    h1->SetTitle("");
     1286    h1->SetContour(99);
     1287    h1->SetBit(TH1::kNoStats);
     1288    h1->SetBit(TH1::kCanDelete);
     1289
     1290    if (h1->FindObject("stats"))
     1291        delete h1->FindObject("stats");
     1292
     1293    TAxis &x = *h1->GetXaxis();
     1294    TAxis &y = *h1->GetYaxis();
     1295    TAxis &z = *h1->GetZaxis();
     1296
     1297    x.SetRangeUser(-zoom, zoom);
     1298    y.SetRangeUser(-zoom, zoom);
     1299
     1300    x.SetTitleOffset(1.1);
     1301    y.SetTitleOffset(1.3);
     1302
     1303    x.SetTickLength(0.025);
     1304    y.SetTickLength(0.025);
     1305
     1306    x.SetAxisColor(kWhite);
     1307    y.SetAxisColor(kWhite);
     1308
     1309    x.CenterTitle();
     1310    y.CenterTitle();
     1311
     1312    x.SetTitle("Offset [#circ]");
     1313    y.SetTitle("Offset [#circ]");
     1314
     1315    x.SetDecimals();
     1316    y.SetDecimals();
     1317    z.SetDecimals();
     1318
     1319    MH::SetPalette("glowsym", 99);
     1320
     1321    const Float_t max = TMath::Max(h1->GetMinimum(), h1->GetMaximum());
     1322
     1323    h1->SetMinimum(-max);
     1324    h1->SetMaximum(max);
     1325
     1326    h1->Draw("colz");
     1327
     1328    // ------
     1329    // Convert pave coordinates from NDC to Pad coordinates.
     1330
     1331    gPad->Update();
     1332
     1333    Float_t x0 = 0.80;
     1334    Float_t y0 = 0.88;
     1335
     1336    Double_t dx  = gPad->GetX2() - gPad->GetX1();
     1337    Double_t dy  = gPad->GetY2() - gPad->GetY1();
     1338
     1339    // Check if pave initialisation has been done.
     1340    // This operation cannot take place in the Pave constructor because
     1341    // the Pad range may not be known at this time.
     1342    Float_t px = gPad->GetX1() + x0*dx;
     1343    Float_t py = gPad->GetY1() + y0*dy;
     1344    // -------
     1345
     1346    TEllipse *el = new TEllipse(px, py, 0.12, 0.12, 0, 360, 0);
     1347    el->SetFillStyle(4100);
     1348    el->SetFillColor(kBlack);
     1349    el->SetLineWidth(2);
     1350    el->SetLineColor(kWhite);
     1351    el->SetBit(kCanDelete);
     1352    el->Draw();
     1353
     1354    TString str1("el.SetX1(gPad->GetX1()+0.9*(gPad->GetX2()-gPad->GetX1()));");
     1355    TString str2("el.SetY1(gPad->GetY1()+0.9*(gPad->GetY2()-gPad->GetY1()));");
     1356
     1357    str1.ReplaceAll("el.", Form("((TEllipse*)%p)->", el));
     1358    str2.ReplaceAll("el.", Form("((TEllipse*)%p)->", el));
     1359
     1360    str1.ReplaceAll("0.9", Form("%f", x0));
     1361    str2.ReplaceAll("0.9", Form("%f", y0));
     1362
     1363    TLatex tex;
     1364    tex.SetBit(TText::kTextNDC);
     1365    tex.SetTextColor(kWhite);
     1366    tex.SetTextAlign(22);
     1367    tex.SetTextSize(0.04);
     1368    tex.SetTextAngle(0);
     1369    tex.DrawLatex(x0, y0, "psf");
     1370
     1371    TPad *pad = new TPad("pad", "Catalog Pad",
     1372                         c.GetLeftMargin(), c.GetBottomMargin(),
     1373                         1-c.GetRightMargin(), 1-c.GetTopMargin());
     1374
     1375    pad->SetFillStyle(4000);
     1376    pad->SetFillColor(kBlack);
     1377    pad->SetBorderMode(0);
     1378    pad->SetFrameBorderMode(0);
     1379    pad->SetBit(kCanDelete);
     1380    pad->Draw();
     1381
     1382    pad->Range(x.GetBinLowEdge(x.GetFirst()),
     1383               y.GetBinLowEdge(y.GetFirst()),
     1384               x.GetBinLowEdge(x.GetLast()+1),
     1385               y.GetBinLowEdge(y.GetLast()+1));
     1386
     1387    TString str3("pad->Range(x.GetBinLowEdge(x.GetFirst()),"
     1388                 "y.GetBinLowEdge(y.GetFirst()),"
     1389                 "x.GetBinLowEdge(x.GetLast()+1),"
     1390                 "y.GetBinLowEdge(y.GetLast()+1));");
     1391
     1392    str3.ReplaceAll("x.", Form("((TAxis*)%p)->", &x));
     1393    str3.ReplaceAll("y.", Form("((TAxis*)%p)->", &y));
     1394    // str3.ReplaceAll("pad", Form("((TPad*)(%p))", pad));
     1395
     1396    c.AddExec("SetPosX", str1);
     1397    c.AddExec("SetPosY", str2);
     1398    c.AddExec("Resize",  str3);
     1399
     1400    pad->cd();
     1401    gROOT->SetSelectedPad(0);
     1402
     1403    MAstroCatalog *cat = (MAstroCatalog*)GetCatalog();
     1404
     1405    cat->GetAttLineSky().SetLineColor(col);
     1406    cat->GetAttLineSky().SetLineWidth(2);
     1407    cat->GetAttLineSky().SetLineStyle(7);
     1408
     1409    cat->GetList()->Clear();
     1410    cat->SetBit(kCanDelete);
     1411    //    cat->AddObject(MAstro::Hms2Hor(12,17,52)*TMath::Pi()/12, TMath::DegToRad()*MAstro::Dms2Deg(30,7,0),   6, "1ES1215+303");
     1412    //    cat->AddObject(MAstro::Hms2Hor(12,18,27)*TMath::Pi()/12, TMath::DegToRad()*MAstro::Dms2Deg(29,48,46), 6, "Mrk766");
     1413
     1414    cat->Draw("mirror same");
     1415
     1416    /*
     1417     Int_t col = kBlue+180;
     1418
     1419     TLatex tex;
     1420     tex.SetTextColor(col);
     1421     tex.SetTextAlign(21);
     1422     tex.SetTextSize(0.04);
     1423     tex.DrawLatex(-0.79, -0.8, "43.0\\circ");
     1424     tex.DrawLatex(-0.78,  0.2, "42.0\\circ");
     1425
     1426     tex.SetTextAngle(-90);
     1427     tex.DrawLatex(-0.45, -0.55, "22.00h");
     1428     tex.DrawLatex( 0.30, -0.55, "22.07h");
     1429     */
     1430}
  • trunk/MagicSoft/Mars/mhflux/MHFalseSource.h

    r7188 r8185  
    4646    Double_t fDec;
    4747
    48     TObject *GetCatalog();
     48    TObject *GetCatalog() const;
    4949    void MakeSymmetric(TH1 *h);
    5050
     
    8787    }
    8888
     89    void DrawNicePlot() const; //*MENU*
     90
    8991    // MParContainer
    9092    Int_t ReadEnv(const TEnv &env, TString prefix, Bool_t print=kFALSE);
  • trunk/MagicSoft/Mars/msql/MSQLServer.cc

    r7940 r8185  
    11/* ======================================================================== *\
     2! $Name: not supported by cvs2svn $:$Id: MSQLServer.cc,v 1.13 2006-11-01 08:29:45 tbretz Exp $
     3! --------------------------------------------------------------------------
    24!
    35! *
     
    1820!   Author(s): Thomas Bretz 2/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
    1921!
    20 !   Copyright: MAGIC Software Development, 2000-2004
     22!   Copyright: MAGIC Software Development, 2000-2006
    2123!
    2224!
     
    4749#include <TH1.h>
    4850#include <TEnv.h>
     51#include <TPRegexp.h>
    4952
    5053#include <TSQLResult.h>
     
    519522}
    520523
    521 TSQLResult *MSQLServer::GetTables(const char *dbname, const char *wild) /*FOLD00*/
    522 {
    523     return fType==kIsServer && fServ ? fServ->GetTables(dbname, wild) : NULL;
    524 }
    525 
    526 TSQLResult *MSQLServer::GetColumns(const char *dbname, const char *table, const char *wild) /*FOLD00*/
    527 {
    528     return fType==kIsServer && fServ ? fServ->GetColumns(dbname, table, wild) : NULL;
     524TSQLResult *MSQLServer::GetTables(const char *wild, const char *dbname) /*FOLD00*/
     525{
     526    return fType==kIsServer && fServ ? fServ->GetTables(dbname?dbname:fDataBase.Data(), wild) : NULL;
     527}
     528
     529TSQLResult *MSQLServer::GetColumns(const char *table, const char *wild, const char *dbname) /*FOLD00*/
     530{
     531    return fType==kIsServer && fServ ? fServ->GetColumns(dbname?dbname:fDataBase.Data(), table, wild) : NULL;
    529532}
    530533
     
    604607    }
    605608    else
    606         SetBit(kZombie);
     609        fType = kIsZombie;
    607610
    608611    fList.SetOwner();
     
    749752}
    750753
     754// --------------------------------------------------------------------------
     755//
     756// Return the name of the (first) column with a primary key
     757//
     758TString MSQLServer::GetPrimaryKey(const char *table)
     759{
     760    TSQLResult *res = GetColumns(table);
     761    if (!res)
     762        return "";
     763
     764    TString rc;
     765
     766    TSQLRow *row = 0;
     767    while ((row=res->Next()))
     768    {
     769        TString key = (*row)[3];
     770        if (key!="PRI")
     771            continue;
     772
     773        rc = (*row)[0];
     774        break;
     775    }
     776
     777    delete res;
     778    return rc;
     779}
     780
     781// --------------------------------------------------------------------------
     782//
     783// Searches in the text for patterns like "Table.Column". If such a pettern
     784// is found the primary key of the table is requested a "LEFT JOIN"
     785// with this Table is added ON the identity of the primary key of Table
     786// with the given table.
     787//
     788TString MSQLServer::GetJoins(const char *table, const TString text)
     789{
     790    Int_t p=0;
     791
     792    TString mods;
     793    TArrayI pos;
     794
     795    // Find all Table.Column expression. Because also floating point
     796    // numbers can contain a dot the result has to be checked carefully
     797    TString joins;
     798    TPRegexp reg = TPRegexp("\\w+[.]\\w+");
     799    while (1)
     800    {
     801        // Check whether expression is found
     802        if (reg.Match(text, mods, p, 130, &pos)==0)
     803            break;
     804
     805        // Get expression from text
     806        const TString expr = text(pos[0], pos[1]-pos[0]);
     807        p = pos[1];
     808
     809        if (expr.IsFloat())
     810            continue;
     811
     812        const TString tab = expr(0, expr.First('.'));
     813        const TString var = expr(expr.First('.')+1, expr.Length());
     814
     815        // If the table found is the primary table itself skip it.
     816        if (tab==table)
     817            continue;
     818
     819        // If this join has already be set, skip it.
     820        if (joins.Contains(Form(" %s ", tab.Data())))
     821            continue;
     822
     823        // Now get the primary key of the table to be joined
     824        const TString prim = GetPrimaryKey(tab);
     825        if (prim.IsNull())
     826            continue;
     827
     828        joins += Form("LEFT JOIN %s ON %s.%s=%s.%s ", tab.Data(),
     829                      table, prim.Data(), tab.Data(), prim.Data());
     830    }
     831
     832    if (!joins.IsNull())
     833        joins += " ";
     834
     835    return joins;
     836}
     837
    751838void MSQLServer::RecursiveRemove(TObject *obj)
    752839{
  • trunk/MagicSoft/Mars/msql/MSQLServer.h

    r7940 r8185  
    113113    Int_t       SelectDataBase(const char *dbname);
    114114    TSQLResult *GetDataBases(const char *wild = 0);
    115     TSQLResult *GetTables(const char *dbname, const char *wild = 0);
    116     TSQLResult *GetColumns(const char *dbname, const char *table, const char *wild = 0);
     115    TSQLResult *GetTables(const char *wild = 0, const char *dbname = 0);
     116    TSQLResult *GetColumns(const char *table, const char *wild = 0, const char *dbname = 0);
    117117    Int_t       CreateDataBase(const char *dbname);
    118118    Int_t       DropDataBase(const char *dbname);
     
    123123
    124124    TString     GetEntry(const char *where, const char *col=0, const char *table=0) const;
     125    TString     GetPrimaryKey(const char *table);
     126    TString     GetJoins(const char *table, const TString text);
    125127
    126128    void RecursiveRemove(TObject *obj);
Note: See TracChangeset for help on using the changeset viewer.