Ignore:
Timestamp:
07/17/08 15:58:20 (16 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/datacenter/macros
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/datacenter/macros/fillsignal.C

    r8999 r9005  
    114114    if (!cam)
    115115    {
    116         cout << "WARNING - Reading of PedRMS;avg failed." << endl;
     116        cout << "ERROR - Reading of PedRMS;avg failed." << endl;
    117117        return 2;
    118118    }
     
    122122    if (!pul)
    123123    {
    124         cout << "WARNING - Reading of PulsePos;avg failed." << endl;
     124        cout << "ERROR - Reading of PulsePos;avg failed." << endl;
    125125        return 2;
    126126    }
     
    129129    if (!difflo)
    130130    {
    131         cout << "WARNING - Reading of DiffLo;avg failed." << endl;
     131        cout << "ERROR - Reading of DiffLo;avg failed." << endl;
    132132        return 2;
    133133    }
     
    135135    if (!diffhi)
    136136    {
    137         cout << "WARNING - Reading of DiffHi;avg failed." << endl;
     137        cout << "ERROR - Reading of DiffHi;avg failed." << endl;
    138138        return 2;
    139139    }
     
    144144    if (sequence.IsNull())
    145145    {
    146         cout << "WARNING - Sequ# empty" << endl;
     146        cout << "ERROR - Sequ# empty" << endl;
    147147        cout << "Sequ# " << sequence << endl;
    148148        return 2;
     
    161161        if (!hilooff)
    162162        {
    163             cout << "WARNING - Reading of HiLoOff failed." << endl;
     163            cout << "ERROR - Reading of HiLoOff failed." << endl;
    164164            return 2;
    165165        }
     
    168168        if (!hilocal)
    169169        {
    170             cout << "WARNING - Reading of HiLoCal failed." << endl;
     170            cout << "ERROR - Reading of HiLoCal failed." << endl;
    171171            return 2;
    172172        }
     
    191191    if (meanrmsi<0 || meanrmso<0)
    192192    {
    193         cout << "WARNING - MeanPedRMS inner or outer < 0 " << endl;
     193        cout << "ERROR - MeanPedRMS inner or outer < 0 " << endl;
    194194        cout << "MeanPedRMS inner " << meanrmsi << endl;
    195195        cout << "MeanPedRMS outer " << meanrmso << endl;
     
    203203    if (!cam)
    204204    {
    205         cout << "WARNING - Reading of Interp'd;avg failed." << endl;
     205        cout << "ERROR - Reading of Interp'd;avg failed." << endl;
    206206        return 2;
    207207    }
     
    212212    if (meansigi<0 || meansigo<0)
    213213    {
    214         cout << "WARNING - MeanInterp'd inner or outer < 0 " << endl;
     214        cout << "ERRROR - MeanInterp'd inner or outer < 0 " << endl;
    215215        cout << "MeanInterp'd inner " << meansigi << endl;
    216216        cout << "MeanInterp'd outer " << meansigo << endl;
     
    225225    if (pul->GetMean()<0 || pul->GetRMS()<0)
    226226    {
    227         cout << "WARNING - PulsePos'd mean or rms < 0 " << endl;
     227        cout << "ERROR - PulsePos'd mean or rms < 0 " << endl;
    228228        cout << "PulsePos'd mean " << pul->GetMean() << endl;
    229229        cout << "PulsePos'd rms  " << pul->GetRMS() << endl;
     
    258258    if (!cam)
    259259    {
    260         cout << "WARNING - Reading of Unsuitable;avg failed." << endl;
     260        cout << "ERROR - Reading of Unsuitable;avg failed." << endl;
    261261        return 2;
    262262    }
     
    375375
    376376
    377     return serv.Update("Calibration", vars, Form("fSequenceFirst=%d", seq));
     377    return serv.Update("Calibration", vars, Form("fSequenceFirst=%d", seq)) ? 1 : 2;
    378378}
    379379
  • trunk/MagicSoft/Mars/datacenter/macros/writesequencefile.C

    r8052 r9005  
    4141// to the database is not working.
    4242//
     43//
     44// This tool will work from Period017 (2004_05_17) on...
     45//
     46// For more details see MSequence and MSequenceSQL
     47//
    4348/////////////////////////////////////////////////////////////////////////////
    44 #include <iostream>
    45 #include <iomanip>
    46 #include <fstream>
    47 
    48 #include <TSQLRow.h>
    49 #include <TSQLResult.h>
    50 
    51 #include <TEnv.h>
    52 #include <TMath.h>
    53 #include <TRegexp.h>
    54 
    55 #include "MAstro.h"
    56 #include "MTime.h"
    57 #include "MDirIter.h"
    58 
    59 #include "MSQLMagic.h"
     49#include "MSequence.h"
    6050
    6151using namespace std;
    6252
    63 Bool_t GetRuns(MSQLServer &serv, ofstream &fout, TString query, TString name, UInt_t nevts=(UInt_t)-1)
     53int writeseq(Int_t sequno, Int_t tel, TString sequpath="")
    6454{
    65     TSQLResult *res = serv.Query(query);
    66     if (!res)
    67         return kFALSE;
    68 
    69     UInt_t cnt=0;
    70     UInt_t evts=0;
    71 
    72     fout << name << ":";
    73     TSQLRow *row=0;
    74     while ((row = res->Next()) && evts<nevts)
    75     {
    76         fout << " " << (*row)[0];
    77         evts += atoi((*row)[1]);
    78         cnt++;
    79     }
    80     fout << endl;
    81 
    82     delete res;
    83 
    84     if (cnt==0)
    85     {
    86         cout << "ERROR - No " << name << " belonging to this sequence found." << endl;
    87         return kFALSE;
    88     }
    89 
    90     return kTRUE;
    91 }
    92 
    93 TString GetTime(const char *type)
    94 {
    95     return Form("if(TIME_TO_SEC(fRun%s)<12*60*60,"
    96                 " TIME_TO_SEC(fRun%s)+24*60*60,"
    97                 " TIME_TO_SEC(fRun%s))", type, type, type);
    98 }
    99 
    100 Int_t GetTimeC(MSQLServer &serv, const TString &str)
    101 {
    102     TSQLResult *res = serv.Query(str);
    103     if (!res)
    104         return -1;
    105 
    106     TSQLRow *row=res->Next();
    107     if (!row)
    108     {
    109         delete res;
    110         return -1;
    111     }
    112 
    113     Int_t rc = (*row)[0] ? atoi((*row)[0]) : -1;
    114     delete res;
    115     return rc;
    116 }
    117 
    118 Bool_t GetSequence(MSQLMagic &serv, TSQLRow &data, TString sequpath)
    119 {
    120     UShort_t y;
    121     Byte_t m, d;
    122 
    123     MTime time;
    124     time.SetSqlDateTime(data[8]);
    125     time.GetDateOfSunrise(y, m, d);
    126 
    127     TString date = Form("%04d-%02d-%02d", y, (int)m, (int)d);
    128 
    129     Int_t period = MAstro::GetMagicPeriod(time.GetMjd());
    130 
    131     TString str[6];
    132     str[0] = serv.QueryNameOfKey("Project",         data[2]);
    133     str[1] = serv.QueryNameOfKey("Source",          data[3]);
    134     str[2] = serv.QueryNameOfKey("L1TriggerTable",  data[4]);
    135     str[3] = serv.QueryNameOfKey("L2TriggerTable",  data[5]);
    136     str[4] = serv.QueryNameOfKey("HvSettings",      data[6]);
    137     str[5] = serv.QueryNameOfKey("LightConditions", data[7]);
    138 
    139     if (str[0].IsNull() || str[1].IsNull() || str[2].IsNull() || str[3].IsNull() || str[4].IsNull() || str[5].IsNull())
    140         return kFALSE;
    141 
    142     //create sequence file
    143     TString fname(Form("%s/%04d/sequence%08d.txt", sequpath.Data(), atoi(data[0])/10000, atoi(data[0])));
    144     cout << "Creating " << fname << "..." << flush;
    145 
    146     ofstream fout(fname);
    147     if (!fout)
    148     {
    149         cout << "ERROR - Cannot open file." << endl;
    150         return kFALSE;
    151     }
    152 
    153     //write information into file
    154     fout << "Sequence:        " << data[0]  << endl;
    155     fout << "Period:          " << period   << endl;
    156     fout << "Night:           " << date     << endl;
    157     fout << "LightConditions: " << str[5]   << endl;
    158     fout << endl;
    159     fout << "Start:           " << data[8]  << endl;
    160     fout << "LastRun:         " << data[1]  << endl;
    161     fout << "Project:         " << str[0]   << endl;
    162     fout << "Source:          " << str[1]   << endl;
    163     fout << "ZdMin:           " << data[10] << endl;
    164     fout << "ZdMax:           " << data[11] << endl;
    165     fout << "L1TriggerTable:  " << str[2]   << endl;
    166     fout << "L2TriggerTable:  " << str[3]   << endl;
    167     fout << "HvSettings:      " << str[4]   << endl;
    168     fout << "NumEvents:       " << data[9]  << endl;
    169     fout << endl;
    170 
    171     TString where(Form(" FROM RunData WHERE fSequenceFirst=%s AND fExcludedFDAKEY=1"
    172                        " AND fRunTypeKEY%%s", data[0]));
    173 
    174     TString query1(Form("SELECT fRunNumber, fNumEvents %s", where.Data()));
    175     TString query2(Form("SELECT %s %s", GetTime("Start").Data(), where.Data()));
    176     TString query3(Form("SELECT %s %s", GetTime("Stop").Data(),  where.Data()));
    177 
    178     TString queryA(Form(query1.Data(), " BETWEEN 2 AND 4 ORDER BY fRunNumber"));
    179     TString queryC(Form(query1.Data(), "=4 ORDER BY fRunNumber"));
    180     TString queryD(Form(query1.Data(), "=2 ORDER BY fRunNumber"));
    181     TString queryT(Form(query2.Data(), "=4 ORDER BY fRunNumber LIMIT 1"));
    182 
    183     Int_t timec = GetTimeC(serv, queryT);
    184     if (timec<0)
    185     {
    186         cout << "WARNING - Requesting start time of first calibration run failed." << endl;
    187         queryT = Form(query3.Data(), "=4 ORDER BY fRunNumber LIMIT 1");
    188         timec = GetTimeC(serv, queryT);
    189         if (timec<0)
    190         {
    191             cout << "ERROR - Neither start nor stop time of first calibration could be requested." << endl;
    192             return kFALSE;
    193         }
    194     }
    195 
    196     TString query4(Form("=3 ORDER BY ABS(%s-%d) ASC", GetTime("Stop").Data(), timec));
    197     TString queryP(Form(query1.Data(), query4.Data()));
    198 
    199     //write runs into sequence file
    200     if (!GetRuns(serv, fout, queryA, "Runs"))
    201         return kFALSE;
    202 
    203     fout << endl;
    204 
    205     if (!GetRuns(serv, fout, queryC, "CalRuns"))
    206         return kFALSE;
    207     if (!GetRuns(serv, fout, queryP, "PedRuns", 1000))
    208         return kFALSE;
    209     if (!GetRuns(serv, fout, queryD, "DatRuns"))
    210         return kFALSE;
    211 
    212     fout << endl;
    213 
    214     cout << " done <Nevts=" << data[9] << ">" << endl;
    215 
    216     return kTRUE;
    217 }
    218 
    219 // This tool will work from Period017 (2004_05_17) on...
    220 int writesequencefile(Int_t sequno, TString sequpath)
    221 {
    222     TEnv env("sql.rc");
    223 
    224     MSQLMagic serv(env);
     55    MSQLMagic serv("sql.rc");
    22556    if (!serv.IsConnected())
    22657    {
     
    23364    cout << endl;
    23465    cout << "Connected to " << serv.GetName() << endl;
     66    cout << "Sequence:  " << sequno << endl;
     67    cout << "Telescope: " << tel << endl;
    23568    cout << endl;
    23669
    237     //get sequence information from database
    238     TString query(Form("SELECT fSequenceFirst, fSequenceLast, fProjectKEY, fSourceKEY,"
    239                        " fL1TriggerTableKEY, fL2TriggerTableKEY, fHvSettingsKEY, "
    240                        " fLightConditionsKEY, fRunStart, fNumEvents, "
    241                        " fZenithDistanceMin, fZenithDistanceMax "
    242                        " FROM Sequences WHERE fSequenceFirst=%d", sequno));
    243     TSQLResult *res = serv.Query(query);
     70    const MSequenceSQL s(serv, sequno, tel);
     71    if (!s.IsValid())
     72        return 2;
    24473
    245     TSQLRow *row = 0;
    246     while ((row = res->Next()))
    247         if (!GetSequence(serv, *row, sequpath))
    248             return 2;
     74    if (sequpath.IsNull())
     75    {
     76        s.Print();
     77        return 1;
     78    }
    24979
    250     delete res;
     80    const TString fname(Form("%s/%04d/sequence%08d.txt", sequpath.Data(), sequno/10000, sequno));
    25181
    252     cout << endl;
     82    cout << "File:     " << fname << endl;
    25383
    254     return 1;
     84    return s.WriteFile(fname) ? 1 : 2;
    25585}
Note: See TracChangeset for help on using the changeset viewer.