Changeset 8052 for trunk


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

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/Changelog

    r8051 r8052  
    5959   * mbase/MLogHtml.cc:
    6060     - fixed a bug which caused the output to be totally corrupted
     61
     62   * datacenter/macros/writesequencefile.C:
     63     - implemented again that the 1000 pedestal events are taken which
     64       are next to the calibration run
    6165
    6266
  • trunk/MagicSoft/Mars/datacenter/macros/writesequencefile.C

    r8046 r8052  
    5757#include "MDirIter.h"
    5858
    59 #include "MSQLServer.h"
     59#include "MSQLMagic.h"
    6060
    6161using namespace std;
    6262
    63 Bool_t GetRuns(MSQLServer &serv, ofstream &fout, TString query, TString name)
     63Bool_t GetRuns(MSQLServer &serv, ofstream &fout, TString query, TString name, UInt_t nevts=(UInt_t)-1)
    6464{
    6565    TSQLResult *res = serv.Query(query);
     
    6767        return kFALSE;
    6868
    69     Int_t cnt=0;
     69    UInt_t cnt=0;
     70    UInt_t evts=0;
    7071
    7172    fout << name << ":";
    7273    TSQLRow *row=0;
    73     while ((row = res->Next()))
     74    while ((row = res->Next()) && evts<nevts)
    7475    {
    7576        fout << " " << (*row)[0];
     77        evts += atoi((*row)[1]);
    7678        cnt++;
    7779    }
     
    8991}
    9092
    91 TString GetName(MSQLServer &serv, const char *col, const char *n)
    92 {
    93     TString query(Form("SELECT f%sName FROM %s WHERE f%sKEY=%s",
    94                        col, col, col, n));
    95    
    96     TSQLResult *res = serv.Query(query);
     93TString 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
     100Int_t GetTimeC(MSQLServer &serv, const TString &str)
     101{
     102    TSQLResult *res = serv.Query(str);
    97103    if (!res)
    98     {
    99         cout << "ERROR - Resolving " << col << " failed! " << endl;
    100         return "";
    101     }
    102 
    103     TSQLRow *row = res->Next();
     104        return -1;
     105
     106    TSQLRow *row=res->Next();
    104107    if (!row)
    105108    {
    106         cout << "ERROR - No name in " << col << " for key " << n << endl;
    107         return "";
    108     }
    109 
    110     return (*row)[0];
    111 }
    112 
    113 Bool_t GetSequence(MSQLServer &serv, TSQLRow &data, TString sequpath)
     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
     118Bool_t GetSequence(MSQLMagic &serv, TSQLRow &data, TString sequpath)
    114119{
    115120    UShort_t y;
     
    125130
    126131    TString str[6];
    127     str[0] = GetName(serv, "Project",         data[2]);
    128     str[1] = GetName(serv, "Source",          data[3]);
    129     str[2] = GetName(serv, "L1TriggerTable",  data[4]);
    130     str[3] = GetName(serv, "L2TriggerTable",  data[5]);
    131     str[4] = GetName(serv, "HvSettings",      data[6]);
    132     str[5] = GetName(serv, "LightConditions", data[7]);
     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]);
    133138
    134139    if (str[0].IsNull() || str[1].IsNull() || str[2].IsNull() || str[3].IsNull() || str[4].IsNull() || str[5].IsNull())
     
    164169    fout << endl;
    165170
    166     TString query(Form("SELECT fRunNumber, fRunTypeKEY, fRunStart, fRunStop, fNumEvents"
    167                        " FROM RunData WHERE fSequenceFirst=%s AND fExcludedFDAKEY=1"
    168                        " AND fRunTypeKEY %%s ORDER BY fRunNumber",
    169                        data[0]));
    170 
    171 
    172     TString queryA(Form(query.Data(), "BETWEEN 2 AND 4"));
    173     TString queryC(Form(query.Data(), "BETWEEN 4 AND 4"));
    174     TString queryD(Form(query.Data(), "BETWEEN 2 AND 2"));
    175     TString queryP(Form(query.Data(), "BETWEEN 3 AND 3"));
     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()));
    176198
    177199    //write runs into sequence file
     
    183205    if (!GetRuns(serv, fout, queryC, "CalRuns"))
    184206        return kFALSE;
    185     if (!GetRuns(serv, fout, queryP, "PedRuns"))
     207    if (!GetRuns(serv, fout, queryP, "PedRuns", 1000))
    186208        return kFALSE;
    187209    if (!GetRuns(serv, fout, queryD, "DatRuns"))
     
    200222    TEnv env("sql.rc");
    201223
    202     MSQLServer serv(env);
     224    MSQLMagic serv(env);
    203225    if (!serv.IsConnected())
    204226    {
Note: See TracChangeset for help on using the changeset viewer.