Ignore:
Timestamp:
07/17/08 16:08:04 (16 years ago)
Author:
tbretz
Message:
*** empty log message ***
File:
1 edited

Legend:

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

    r8968 r9006  
    159159    UInt_t fMax;
    160160
     161    static UInt_t GetId(const TString &str)
     162    {
     163        const Ssiz_t dot = str.First('.');
     164
     165        const UInt_t run = str.Atoi();
     166        const UInt_t sub = dot<0 ? 0 : atoi(str.Data()+dot+1);
     167
     168        return run*1000+sub;
     169    }
     170
    161171    void Init(const TObjArray &arr, Int_t idx=0)
    162172    {
     
    179189            case 2: fRegexp1  = TPRegexp(Form("^%s$", str.Data())); break;
    180190            case 3: fRegexp2  = TPRegexp(Form("^%s$", str.Data())); break;
    181             case 4: fMin      = str.Atoi();               break;
    182             case 5: fMax      = str.Atoi();               break;
     191            case 4: fMin      = GetId(str);               break;
     192            case 5: fMax      = GetId(str);               break;
    183193            }
    184194        }
    185         //cout << endl;
    186195    }
    187196
     
    257266    TString fPathSequences;
    258267
     268    Int_t fTelescopeNumber;
     269
    259270    TMap  fMap;
    260271    TList fListRegexp;
     
    286297        const TString runtime =
    287298            "SUM(TIME_TO_SEC(TIMEDIFF(fRunStop,fRunStart))), ";
    288             //"SUM(if(TIME_TO_SEC(fRunStop)-TIME_TO_SEC(fRunStart)<0,"
    289             //" TIME_TO_SEC(fRunStop)-TIME_TO_SEC(fRunStart)+24*60*60,"
    290             //" TIME_TO_SEC(fRunStop)-TIME_TO_SEC(fRunStart))), ";
    291 
    292         const TString where = Form("(fRunNumber BETWEEN %d AND %d) AND fExcludedFDAKEY=1",
    293                                    from, to);
     299
     300        const TString where = Form("(fRunNumber*1000+fFileNumber BETWEEN %d AND %d) "
     301                                   "AND fTelescopeNumber=%d AND fExcludedFDAKEY=1",
     302                                   from, to, fTelescopeNumber);
    294303
    295304        TString query;
     
    359368        }
    360369
    361         const TString set = Form("fSequenceFirst=%d ", from);
     370        const TString set = Form("fSequenceFirst=%d, fTelescopeNumber=%d ", from/1000, fTelescopeNumber);
    362371
    363372        TString query1;
    364373        query1 += set;
    365         query1 += Form(",fSequenceLast=%d,",                   to);
     374        query1 += Form(",fSequenceLast=%d,",                   to/1000);
    366375        query1 += Form(" fSourceKEY=%s,",                      (*row)[0]);
    367376        query1 += Form(" fProjectKEY=%s,",                     (*row)[1]);
     
    400409        }
    401410
    402         if (!Insert("SequenceProcessStatus", set))
     411        TString prio = set;
     412        prio += Form(", fPriority=%d ", from/1000);
     413        if (!Insert("SequenceProcessStatus", prio))
    403414        {
    404415            cout << "ERROR - Could not insert Sequence into SequenceProcessStatus." << endl;
     
    458469    Int_t CheckSequence(Int_t runstart, Int_t runstop)
    459470    {
    460         const char *fmt1 = "SELECT fRunNumber FROM RunData WHERE";
    461         const char *fmt2 = "AND fExcludedFDAKEY=1 AND (fRunTypeKEY BETWEEN 2 AND 4) ORDER BY fRunNumber";
    462 
    463         const TString query1 = Form("%s fSequenceFirst=%d %s",            fmt1, runstart, fmt2);
    464         const TString query2 = Form("%s fRunNumber BETWEEN %d AND %d %s", fmt1, runstart, runstop, fmt2);
     471        const char *fmt1 = "SELECT fRunNumber*1000+fFileNumber AS Id FROM RunData WHERE";
     472        const char *fmt2 = "AND fExcludedFDAKEY=1 AND (fRunTypeKEY BETWEEN 2 AND 4) ORDER BY Id";
     473
     474        const TString query1 = Form("%s fTelescopeNumber=%d AND fSequenceFirst=%d %s",    fmt1, fTelescopeNumber, runstart/1000, fTelescopeNumber, fmt2);
     475        const TString query2 = Form("%s fTelescopeNumber=%d AND fRunNumber*1000+fFileNumber BETWEEN %d AND %d %s", fmt1, fTelescopeNumber, runstart, runstop, fmt2);
    465476
    466477        TSQLResult *res1 = Query(query1);
     
    499510        TString query=
    500511            Form("SELECT fSequenceFirst FROM RunData "
    501                  " WHERE fRunNumber BETWEEN %d AND %d AND "
    502                  " fSequenceFirst>0 AND "
     512                 " WHERE fRunNumber*1000+fFileNumber BETWEEN %d AND %d AND "
     513                 " fTelescopeNumber=%d AND fSequenceFirst>0 AND "
    503514                 " fExcludedFDAKEY=1 AND (fRunTypeKEY BETWEEN 2 AND 4)"
    504                  " GROUP BY fSequenceFirst", runstart, runstop);
     515                 " GROUP BY fSequenceFirst", fTelescopeNumber, runstart, runstop);
    505516
    506517        TSQLResult *res = Query(query);
     
    554565    Bool_t ReadResources(const char *fname)
    555566    {
    556         TPRegexp regexp("^\\[.*\\]$");
     567        // Check for the section header
     568        TPRegexp regexp("^\\[(Transition|Regexp):?[0-9 ]*\\]$");
     569        // Check if section header contains a number
     570        TPRegexp regnum("[0-9]");
     571        // Check if section header contains the telescope number
     572        TPRegexp regtel(Form("[^0-9]0*%d[^0-9]", fTelescopeNumber));
    557573
    558574        ifstream fin(fname);
     
    579595                continue;
    580596
    581             if (txt[0]=='[' && section!=2)
     597            if (txt[0]=='['/* && section!=2*/)
    582598            {
    583                 //cout << txt << endl;
    584                 section = 0;
    585                 if (txt(regexp)=="[Transition]")
    586                     section = 1;
    587                 if (txt(regexp)=="[Regexp]")
    588                     section = 2;
    589                 continue;
     599                TString sec = txt(regexp);
     600                if (!sec.IsNull())
     601                {
     602                    section = 0;
     603
     604                    // Skip sections with the wrong telescope number
     605                    if (!sec(regnum).IsNull() && !sec(regtel).IsNull())
     606                        continue;
     607
     608                    // Check which section we are in
     609                    if (sec.BeginsWith("[Transition"))
     610                        section = 1;
     611                    if (sec.BeginsWith("[Regexp]"))
     612                        section = 2;
     613                    continue;
     614                }
     615
     616                if (section!=2)
     617                {
     618                    cout << "WARNING - Line starts with [ but we are not in the Regexp section." << endl;
     619                    cout << txt << endl;
     620                    continue;
     621                }
    590622            }
     623
    591624
    592625            TObjArray *arr = txt.Tokenize(" ");
     
    705738    {
    706739        return Form("SELECT RunData.f%sKEY, f%sName FROM RunData "
    707                     "LEFT JOIN %s ON RunData.f%sKEY=%s.f%sKEY "
    708                     "WHERE %s GROUP BY f%sName",
    709                     col, col, col, col, col, col, cond, col);
     740                    "LEFT JOIN %s USING (f%sKEY) WHERE %s GROUP BY f%sName",
     741                    col, col, col, col, cond, col);
    710742    }
    711743
     
    864896        // Request data necessary to split block into sequences
    865897        const TString query=
    866             Form("SELECT fRunNumber, fRunTypeKEY, fRunStart, fRunStop"
     898            Form("SELECT fRunNumber*1000+fFileNumber AS Id, fRunTypeKEY, fRunStart, fRunStop"
    867899                 " FROM RunData "
    868                  " WHERE fRunNumber BETWEEN %d AND %d AND "
     900                 " WHERE fRunNumber*1000+fFileNumber BETWEEN %d AND %d AND "
    869901                 " fExcludedFDAKEY=1 AND (fRunTypeKEY BETWEEN 2 AND 4)"
    870                  " ORDER BY fRunNumber", runstart, runstop);
     902                 " ORDER BY Id", runstart, runstop);
    871903
    872904        // Send query
     
    10841116
    10851117public:
    1086     SequenceBuild(TEnv &env) : MSQLMagic(env)
    1087     {
    1088         cout << "buildsequences" << endl;
    1089         cout << "--------------" << endl;
    1090         cout << endl;
    1091         cout << "Connected to " << GetName() << endl;
    1092 
     1118    SequenceBuild(Int_t tel=1, const char *rc="sql.rc") : MSQLMagic(rc), fTelescopeNumber(tel)
     1119    {
    10931120        fListRegexp.SetOwner();
    10941121
     
    10971124            return;
    10981125    }
    1099     SequenceBuild()
     1126
     1127    SequenceBuild(TEnv &env, Int_t tel=1) : MSQLMagic(env), fTelescopeNumber(tel)
     1128    {
     1129        fListRegexp.SetOwner();
     1130
     1131        // FIXME: THIS IS NOT YET HANDLED
     1132        if (ReadResources("resources/sequences.rc"))
     1133            return;
     1134    }
     1135    ~SequenceBuild()
    11001136    {
    11011137        fMap.DeleteAll();
     
    11131149        const TString cond =
    11141150            Form("(fRunStart>ADDDATE(\"%s\", INTERVAL -1 DAY) AND fRunStart<\"%s\") "
    1115                  "AND fExcludedFDAKEY=1 AND fRunTypeKEY BETWEEN 2 AND 4 ",
    1116                  day.Data(), day.Data());
     1151                 "AND fExcludedFDAKEY=1 AND fRunTypeKEY BETWEEN 2 AND 4 "
     1152                 "AND fTelescopeNumber=%d ",
     1153                 day.Data(), day.Data(), fTelescopeNumber);
    11171154
    11181155        //query all sources observed in this night
     
    11281165        // Setup query to get all values from the database,
    11291166        // that are relevant for building sequences
    1130         TString query("SELECT fRunNumber, fRunTypeKEY, ");
     1167        TString query("SELECT fRunNumber*1000+fFileNumber AS Id, fRunTypeKEY, ");
    11311168        query += elts;
    11321169        query += ", ";
     
    11421179                query += mapkey->GetName();
    11431180            }
    1144         query += Form(" FROM RunData WHERE %s ORDER BY fRunNumber", cond.Data());
     1181        query += Form(" FROM RunData WHERE %s ORDER BY Id", cond.Data());
    11451182
    11461183        TSQLResult *res = Query(query);
     
    11761213ClassImp(SequenceBuild);
    11771214
    1178 int buildsequenceentries(TString day, TString datapath, TString sequpath, Bool_t dummy=kTRUE)
     1215int buildsequenceentries(TString day, TString datapath, TString sequpath, Int_t tel=1, Bool_t dummy=kTRUE)
    11791216{
    1180     TEnv env("sql.rc");
    1181 
    1182     SequenceBuild serv(env);
     1217    SequenceBuild serv(tel, "sql.rc");
    11831218    if (!serv.IsConnected())
    11841219    {
     
    11861221        return 0;
    11871222    }
     1223
     1224    cout << "buildsequenceentries" << endl;
     1225    cout << "--------------------" << endl;
     1226    cout << endl;
     1227    cout << "Connected to " << serv.GetName() << endl;
     1228    if (!datapath.IsNull())
     1229        cout << "DataPath:  " << datapath << endl;
     1230    if (!sequpath.IsNull())
     1231        cout << "SeqPath:   " << sequpath << endl;
     1232    cout << "Day:       " << day      << endl;
     1233    cout << "Telescope: " << tel      << endl;
     1234    cout << endl;
    11881235
    11891236    serv.SetIsDummy(dummy);
     
    11961243// Build Sequences for all Nights
    11971244//
    1198 int buildsequenceentries(TString datapath, TString sequpath, Bool_t dummy=kTRUE)
     1245int buildsequenceentries(TString datapath, TString sequpath, Int_t tel=1, Bool_t dummy=kTRUE)
    11991246{
    1200     TEnv env("sql.rc");
    1201 
    1202     SequenceBuild serv(env);
     1247    SequenceBuild serv(tel, "sql.rc");
    12031248    if (!serv.IsConnected())
    12041249    {
     
    12061251        return 0;
    12071252    }
     1253
     1254    cout << "buildsequenceentries" << endl;
     1255    cout << "--------------------" << endl;
     1256    cout << endl;
     1257    cout << "Connected to " << serv.GetName() << endl;
     1258    cout << "DataPath:  " << datapath << endl;
     1259    cout << "SeqPath:   " << sequpath << endl;
     1260    cout << "Telescope: " << tel      << endl;
     1261    cout << endl;
    12081262
    12091263    serv.SetIsDummy(dummy);
     
    12131267}
    12141268
    1215 int buildsequenceentries(Bool_t dummy=kTRUE)
     1269int buildsequenceentries(Int_t tel=1, Bool_t dummy=kTRUE)
    12161270{
    1217     return buildsequenceentries("", "", dummy);
     1271    return buildsequenceentries("", "", tel, dummy);
    12181272}
    12191273
    1220 int buildsequenceentries(TString day, Bool_t dummy=kTRUE)
     1274int buildsequenceentries(TString day, Int_t tel=1, Bool_t dummy=kTRUE)
    12211275{
    1222     return buildsequenceentries(day, "", "", dummy);
     1276    return buildsequenceentries(day, "", "", tel, dummy);
    12231277}
Note: See TracChangeset for help on using the changeset viewer.