Ignore:
Timestamp:
08/08/05 17:19:04 (19 years ago)
Author:
Daniela Dorner
Message:
*** empty log message ***
File:
1 edited

Legend:

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

    r7274 r7275  
    5252#include <TRegexp.h>
    5353#include <TSystem.h>
     54#include <TObjString.h>
    5455
    5556#include <MTime.h>
     
    175176}
    176177
    177 Bool_t CheckSequence(MSQLServer &serv, TString datapath, TString sequpath, Int_t from, Int_t to, Bool_t dummy)
     178Int_t CheckSequence(MSQLServer &serv, TString datapath, TString sequpath, Int_t from, Int_t to, Bool_t dummy)
    178179{
    179180    Int_t rc=0;
     
    216217
    217218        //calibration table
    218         query(Form("SELECT fSequenceFirst FROM Calibration WHERE fSequenceFirst BETWEEN %d and %d", from, to));
     219        query=Form("SELECT fSequenceFirst FROM Calibration WHERE fSequenceFirst BETWEEN %d and %d", from, to);
    219220        res = serv.Query(query);
    220221        if (!res)
     
    225226            if (!DeleteSequence(serv, datapath, sequpath, atoi((*row)[0]), dummy))
    226227                return -1;
    227             else
    228                 rc=1;
     228            rc=1;
    229229        }
    230230        delete res;
    231231
    232232        //Star table
    233         query(Form("SELECT fSequenceFirst FROM Star WHERE fSequenceFirst BETWEEN %d and %d", from, to));
     233        query=Form("SELECT fSequenceFirst FROM Star WHERE fSequenceFirst BETWEEN %d and %d", from, to);
    234234        res = serv.Query(query);
    235235        if (!res)
     
    240240            if (!DeleteSequence(serv, datapath, sequpath, atoi((*row)[0]), dummy))
    241241                return -1;
    242             else
    243                 rc=1;
     242            rc=1;
    244243        }
    245244        delete res;
    246245
    247246        //SequenceProcessStatus table
    248         query(Form("SELECT fSequenceFirst FROM SequenceProcessStatus WHERE fSequenceFirst BETWEEN %d and %d", from, to));
     247        query=Form("SELECT fSequenceFirst FROM SequenceProcessStatus WHERE fSequenceFirst BETWEEN %d and %d", from, to);
    249248        res = serv.Query(query);
    250249        if (!res)
     
    255254            if (!DeleteSequence(serv, datapath, sequpath, atoi((*row)[0]), dummy))
    256255                return -1;
    257             else
    258                 rc=1;
     256            rc=1;
    259257        }
    260258        delete res;
     
    267265            if (!DeleteSequence(serv, datapath, sequpath, sequences.At(0), dummy))
    268266                return -1;
    269             else
    270                 rc=1;
     267            rc=1;
    271268        }
    272269        else
     
    275272
    276273            //getting olf runs
    277             query(Form("SELECT fRunNumber FROM RunData WHERE fSequenceFirst=%d ", from));
     274            query=Form("SELECT fRunNumber FROM RunData WHERE fSequenceFirst=%d ", from);
    278275            res = serv.Query(query);
    279276            if (!res)
     
    292289
    293290            //getting new runs
    294             query(Form("SELECT fRunNumber FROM RunData WHERE fRunNumber BETWEEN %d and %d AND fExcludedFDAKEY=1", from, to));
     291            query=Form("SELECT fRunNumber FROM RunData WHERE fRunNumber BETWEEN %d and %d AND fExcludedFDAKEY=1", from, to);
    295292            res = serv.Query(query);
    296293            if (!res)
     
    302299            {
    303300                count++;
    304                 oldruns.Set(count);
    305                 oldruns.AddAt(atoi((*row)[0]), count-1);
     301                newruns.Set(count);
     302                newruns.AddAt(atoi((*row)[0]), count-1);
    306303            }
    307304            delete res;
     
    310307            if (oldruns.GetSize()!=newruns.GetSize())
    311308            {
    312                 cout << " number of runs is not the same -> deleting sequence " << sequences.At(0) << endl;
     309//                cout << " number of runs (" << oldruns.GetSize() << " - " << newruns.GetSize()
     310//                    << ") is not the same -> deleting sequence " << sequences.At(0) << endl;
    313311                if (!DeleteSequence(serv, datapath, sequpath, sequences.At(0), dummy))
    314312                    return -1;
    315                 else
    316                     rc=1;
     313                rc=1;
    317314            }
    318315            else
     
    322319                for (Int_t i=0;i<newruns.GetSize();i++)
    323320                {
     321//                    cout << "i: " << i << " - new: " << newruns.At(i) << " - old: " << oldruns.At(i) << endl;
    324322                    if (newruns.At(i)==oldruns.At(i))
    325323                        continue;
     
    329327                    if (!DeleteSequence(serv, datapath, sequpath, sequences.At(0), dummy))
    330328                        return -1;
    331                     else
    332                         rc=1;
     329                    rc=1;
    333330                    break;
    334331                }
     
    346343                if (!DeleteSequence(serv, datapath, sequpath, sequences.At(i), dummy))
    347344                    return -1;
    348                 else
    349                     rc=1;
     345                rc=1;
    350346        }
    351347    }
     
    489485}
    490486
    491 Bool_t NewSequence(MSQLServer &serv, TString datapath, TString sequpath, Int_t from, Int_t to, Bool_t dummy)
     487Bool_t NewSequence(MSQLServer &serv, TString datapath, TString sequpath, Int_t from, Int_t to, TList &sequlist, Bool_t dummy)
    492488{
    493489    cout << "Found Sequence (" << from << ", " << to << ") ... checking runs..." << flush;
     
    513509    cout << "checking Sequence..." << endl;
    514510
     511    TObject *sequ;
    515512    Bool_t rc=kFALSE;
    516513    switch (CheckSequence(serv, datapath, sequpath, from, to, dummy))
     
    524521        }
    525522        cout << endl;
     523        if ((sequ=sequlist.Remove(sequlist.FindObject(Form("%d", from)))))
     524            delete sequ;
    526525        return InsertSequence(serv, from, to);
    527526
     
    534533        }
    535534        cout << endl;
     535        if ((sequ=sequlist.Remove(sequlist.FindObject(Form("%d", from)))))
     536            delete sequ;
    536537        return InsertSequence(serv, from, to);
    537538
    538539    case 2:
    539         cout << " sequence is already existing -> inserting not necessary" << endl;
     540        cout << " sequence " << from << " is already existing -> inserting not necessary" << endl;
     541        if ((sequ=sequlist.Remove(sequlist.FindObject(Form("%d", from)))))
     542            delete sequ;
    540543        return kTRUE;
    541544
     
    549552}
    550553
    551 Bool_t Process(MSQLServer &serv, TString datapath, TString sequpath, Int_t from, Int_t to, Bool_t dummy)
     554Bool_t Process(MSQLServer &serv, TString datapath, TString sequpath, Int_t from, Int_t to,  TList &sequlist, Bool_t dummy)
    552555{
    553556
     
    692695            if (n!=-1)
    693696            {
    694                 if (!NewSequence(serv, datapath, sequpath, start, last, dummy))
     697                if (!NewSequence(serv, datapath, sequpath, start, last, sequlist, dummy))
    695698                {
    696699                    rc = kFALSE;
     
    708711    if (n!=-1 && start!=last)
    709712    {
    710         if (!NewSequence(serv, datapath, sequpath, start, last, dummy))
     713        if (!NewSequence(serv, datapath, sequpath, start, last, sequlist, dummy))
    711714            rc = kFALSE;
    712715    }
     
    797800
    798801
     802    TList sequlist;
     803    query=Form("SELECT fSequenceFirst FROM Sequences WHERE %s order by fSequenceFirst",
     804               cond.Data());
     805
     806//    cout << "Q: " << query << endl;
     807
     808    res = serv.Query(query);
     809    if (!res)
     810        return 0;
     811
     812    cout << "old sequences: " << flush;
     813    while ((row=res->Next()))
     814    {
     815        const char *str =  (*row)[0];
     816        cout << str << " " << flush;
     817        sequlist.Add(new TObjString(str));
     818    }
     819    cout << endl;
     820
    799821    Bool_t rc = kTRUE;
    800822
     
    807829        cout << endl << "datablock from " << runstart2 << " to " << runstop2 << endl;
    808830
    809         if (!Process(serv, datapath, sequpath, runstart2, runstop2, dummy))
     831        if (!Process(serv, datapath, sequpath, runstart2, runstop2, sequlist, dummy))
    810832            rc = kFALSE;
    811833
    812834    }
     835
     836    TIter Next(&sequlist);
     837    TObject *obj = 0;
     838    while ((obj=Next()))
     839    {
     840        cout << "sequ: " << obj->GetName() << " deleting... " << endl;
     841        if (!DeleteSequence(serv, datapath, sequpath, atoi(obj->GetName()), dummy))
     842            return 0;
     843    }
     844
    813845    return rc ? 1 : 0;
    814846}
     
    832864        return 0;
    833865
     866    TString date;
    834867    TSQLRow *row=0;
    835868    while ((row=res->Next()))
    836869    {
    837         cout << "date: " << (*row)[0] << endl;
    838         buildsequenceentries((*row)[0], dummy);
     870        date=(*row)[0];
     871        cout << "date: " << date << endl;
     872        buildsequenceentries(date, datapath, sequpath, dummy);
    839873    }
    840874
Note: See TracChangeset for help on using the changeset viewer.