Changeset 7813 for trunk


Ignore:
Timestamp:
07/27/06 20:36:05 (18 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/Changelog

    r7812 r7813  
    1818
    1919                                                 -*-*- END OF LINE -*-*-
     20 2006/07/26 Thomas Bretz
     21
     22   * datacenter/macros/buildsequenceentries.C:
     23     - removed some obsolete output
     24     - logging output redone
     25     - added some missing delete of TSQLResults
     26     - fixed some overwrite of local variables
     27     - added more comments
     28     - moved code building the blocks to its own function
     29     - simplified buildblocks
     30
     31
     32
    2033 2006/07/27 Daniela Dorner
    2134
  • trunk/MagicSoft/Mars/datacenter/macros/buildsequenceentries.C

    r7629 r7813  
    9292#include <TSystem.h>
    9393#include <TObjString.h>
     94#include <TObjArray.h>
    9495
    9596#include <MTime.h>
     
    258259        //       without the check for manuallychanged, all manually
    259260        //       changed sequences would be deleted
    260         cout << "found no sequence in Sequ-DB -> check other tables" << endl;
    261         cout << " deleting every sequence found in Calibration, Star or SequenceProcessStatus between "
    262             << from << " and " << to << endl;
     261        cout << "   + found no sequence in Sequ-DB -> check other tables" << endl;
     262        cout << "     deleting every sequence found in Calibration, Star or" << endl;
     263        cout << "     SequenceProcessStatus between " << from << " and " << to << endl;
    263264
    264265        //calibration table
     
    315316
    316317    case 1:
    317         cout << "found 1 sequence: " << sequences.At(0) << " -> check sequ# " << endl;
     318        cout << "   + found one sequence: " << sequences.At(0) << " -> check sequence." << endl;
    318319        if (sequences.At(0)!=from)
    319320        {
     
    324325        else
    325326        {
    326             cout << "sequence# is the same -> checking the runs " << endl;
     327            cout << "     * sequence is the same -> checking the runs." << endl;
    327328
    328329            //getting olf runs
     
    370371            else
    371372            {
    372                 cout << " number of runs is the same -> checking the single runnumbers " << endl;
     373                cout << "       · number of runs is the same -> checking the single runnumbers." << endl;
    373374
    374375                for (Int_t i=0;i<newruns.GetSize();i++)
     
    378379                        continue;
    379380
    380                     cout << i << ". run is not the same ( " << oldruns.At(i) << " -- " << newruns.At(i)
     381                    cout << "       · " << i << ". run is not the same ( " << oldruns.At(i) << " -- " << newruns.At(i)
    381382                        << ") -> deleting sequence " << sequences.At(0) << endl;
    382383                    if (!DeleteSequence(serv, datapath, sequpath, sequences.At(0), dummy))
    383384                        return -1;
    384                     rc=1;
    385                     break;
     385                    return 1;
    386386                }
    387387            }
    388388        }
    389         rc=2;
    390         break;
     389        return 2;
    391390
    392391    default:
    393         cout << "found " << numsequ << " sequences -> deleting them " << endl;
     392        cout << " - found " << numsequ << " sequences -> deleting them " << endl;
    394393
    395394        for (Int_t i=0;i<sequences.GetSize();i++)
    396395        {
    397                 cout << "deleting sequence " << sequences.At(i) << "... <" << i << ">" << endl;
     396                cout << "   + deleting sequence " << sequences.At(i) << "... <" << i << ">" << endl;
    398397                if (!DeleteSequence(serv, datapath, sequpath, sequences.At(i), dummy))
    399398                    return -1;
     
    407406Bool_t InsertSequence(MSQLServer &serv, Int_t from, Int_t to)
    408407{
    409 
    410     cout << "Inserting sequence " << from << " ... " << endl;
     408    cout << "       · Inserting sequence " << from << " ... " << endl;
    411409
    412410    // ========== Request number of events ==========
     
    481479
    482480    TString query1("INSERT Sequences SET");
    483     query1+=Form(" fSequenceFirst=%d,  fSequenceLast=%d,", from, to);
    484     query1+=Form(" fSourceKEY=%s,", (*row)[0]);
    485     query1+=Form(" fProjectKEY=%s,", (*row)[1]);
    486     query1+=Form(" fNumEvents=%s,", nevts.Data());
    487     query1+=Form(" fRunTime=%s,", secs.Data());
    488     query1+=Form(" fRunStart=\"%s\",", start.Data());
    489     query1+=Form(" fZenithDistanceMin=%s,", zdmin.Data());
    490     query1+=Form(" fZenithDistanceMax=%s,", zdmax.Data());
    491     query1+=Form(" fAzimuthMin=%s,", azmin.Data());
    492     query1+=Form(" fAzimuthMax=%s,", azmax.Data());
    493     query1+=Form(" fL1TriggerTableKEY=%s,", (*row)[2]);
    494     query1+=Form(" fL2TriggerTableKEY=%s,", (*row)[3]);
    495     query1+=Form(" fHvSettingsKEY=%s,", (*row)[4]);
    496     query1+=Form(" fDiscriminatorThresholdTableKEY=%s,", (*row)[5]);
    497     query1+=Form(" fTriggerDelayTableKEY=%s,", (*row)[6]);
    498     query1+=Form(" fLightConditionsKEY=%s,", (*row)[7]);
    499     query1+=Form(" fTestFlagKEY=%s, ", (*row)[8]);
    500     query1+=Form(" fObservationModeKEY=%s, fManuallyChangedKEY=1", (*row)[9]);
     481    query1 += Form(" fSequenceFirst=%d,  fSequenceLast=%d,", from, to);
     482    query1 += Form(" fSourceKEY=%s,",                      (*row)[0]);
     483    query1 += Form(" fProjectKEY=%s,",                     (*row)[1]);
     484    query1 += Form(" fNumEvents=%s,",                      nevts.Data());
     485    query1 += Form(" fRunTime=%s,",                        secs.Data());
     486    query1 += Form(" fRunStart=\"%s\",",                   start.Data());
     487    query1 += Form(" fZenithDistanceMin=%s,",              zdmin.Data());
     488    query1 += Form(" fZenithDistanceMax=%s,",              zdmax.Data());
     489    query1 += Form(" fAzimuthMin=%s,",                     azmin.Data());
     490    query1 += Form(" fAzimuthMax=%s,",                     azmax.Data());
     491    query1 += Form(" fL1TriggerTableKEY=%s,",              (*row)[2]);
     492    query1 += Form(" fL2TriggerTableKEY=%s,",              (*row)[3]);
     493    query1 += Form(" fHvSettingsKEY=%s,",                  (*row)[4]);
     494    query1 += Form(" fDiscriminatorThresholdTableKEY=%s,", (*row)[5]);
     495    query1 += Form(" fTriggerDelayTableKEY=%s,",           (*row)[6]);
     496    query1 += Form(" fLightConditionsKEY=%s,",             (*row)[7]);
     497    query1 += Form(" fTestFlagKEY=%s,",                    (*row)[8]);
     498    query1 += Form(" fObservationModeKEY=%s, ",            (*row)[9]);
     499    query1+="fManuallyChangedKEY=1";
    501500
    502501
     
    511510    delete res;
    512511
    513     cout << "q1: " << query1 << endl;
    514     cout << "q2: " << query2 << endl;
    515     cout << "q3: " << query3 << endl;
     512    /*
     513     cout << "q1: " << query1 << endl;
     514     cout << "q2: " << query2 << endl;
     515     cout << "q3: " << query3 << endl;
     516     */
    516517
    517518    res = serv.Query(query1);
     
    547548Bool_t NewSequence(MSQLServer &serv, TString datapath, TString sequpath, Int_t from, Int_t to, TList &sequlist, Bool_t dummy)
    548549{
    549     cout << "Found Sequence (" << from << ", " << to << ") ... checking runs..." << flush;
     550    cout << " - Found Sequence (" << from << ", " << to << ") ... checking runs..." << flush;
    550551
    551552    if (!CheckRuns(serv, from, to, 2))
     
    567568
    568569
    569     cout << "checking Sequence..." << endl;
     570    cout << "   + checking sequence..." << endl;
    570571
    571572    TObject *sequ;
     
    574575    {
    575576    case 0:
    576         cout << " sequence not found -> inserting " << from << flush ;
     577        cout << "       · sequence not found -> inserting " << from << flush;
    577578        if (dummy)
    578579        {
     
    586587
    587588    case 1:
    588         cout << " deleting successfully finished -> inserting sequence " << from << flush;
     589        cout << "       · deleting successfully finished -> inserting sequence " << from << flush;
    589590        if (dummy)
    590591        {
     
    598599
    599600    case 2:
    600         cout << " sequence " << from << " is already existing -> inserting not necessary" << endl;
     601        cout << "       · sequence " << from << " is already existing -> inserting not necessary" << endl;
    601602        if ((sequ=sequlist.Remove(sequlist.FindObject(Form("%d", from)))))
    602603            delete sequ;
     
    604605
    605606    case -1:
    606         cout << " deleting went wrong " << endl;
     607        cout << "       · deleting went wrong " << endl;
    607608        return kFALSE;
    608609    }
     
    784785}
    785786
    786 
     787void buildblocks(TSQLResult *res, TExMap &blocks)
     788{
     789    //build blocks of runs, which have the same values
     790    //for each block the first and the last run are stored in a TExMap
     791    //the values are checked with the help of an array of TStrings
     792    TString keys[7];
     793
     794    Long_t runstart = -1;
     795    Long_t runstop  = -1;
     796
     797    // "Result set closed" means "Result set empty"
     798
     799    // Loop over runs
     800    TSQLRow *row=0;
     801    while ((row=res->Next()))
     802    {
     803        // Check whether all keys for this run fit
     804        for (Int_t i=1; i<8; i++)
     805        {
     806            // Do not check project key for this runs
     807            // (this condition is never true for the first run)
     808            if (i==2 && runstart>20100 && runstop<45100)
     809                continue;
     810
     811            // Check whether key has changed for this run
     812            // (this condition is never true for the first run)
     813            if (keys[i-1] == (*row)[i])
     814                continue;
     815
     816            // Found one block with unique keys, fill values into TExMap
     817            // (except if this is the first run processed)
     818            if (runstart>0)
     819                blocks.Add((ULong_t)blocks.GetSize(), runstart, runstop);
     820
     821            // This is the runnumber of the first run in the new block
     822            runstart=atoi((*row)[0]);
     823
     824            // These are the keys corresponding to the first run in the new block
     825            for (int i=1; i<8; i++)
     826                keys[i-1] = (*row)[i];
     827
     828            break;
     829        }
     830
     831        // This is the new runnumber of the last run in this block
     832        runstop=atoi((*row)[0]);
     833    }
     834
     835    if (runstart!=runstop)
     836    {
     837        //fill values into TExMap (last value)
     838        blocks.Add((ULong_t)blocks.GetSize(), runstart, runstop);
     839    }
     840}
    787841
    788842//
     
    811865                            day.Data(), day.Data()));
    812866
     867    TString elts  = "fSourceKEY";
     868    TString eltp2 = "fProjectKEY";
     869
    813870    //get all values from the database, that are relevant for building sequences
    814     TString query(Form("SELECT fRunNumber, fSourceKEY, fProjectKEY, fHvSettingsKEY,  fLightConditionsKEY, fDiscriminatorThresholdTableKEY, fTriggerDelayTableKEY, fObservationModeKEY FROM RunData WHERE %s AND fExcludedFDAKEY=1 order by fRunNumber", cond.Data()));
     871    TString query("SELECT fRunNumber, ");
     872    query += elts;
     873    query += ", ";
     874    query += eltp2;
     875    query += Form(", fHvSettingsKEY, fLightConditionsKEY, fDiscriminatorThresholdTableKEY, "
     876                  "fTriggerDelayTableKEY, fObservationModeKEY FROM RunData "
     877                  "WHERE %s AND fExcludedFDAKEY=1 order by fRunNumber", cond.Data());
    815878
    816879    TSQLResult *res = serv.Query(query);
     
    818881        return 2;
    819882
    820     //build blocks of runs, which have the same values
    821     //for each block the first and the last run are stored in a TExMap
    822     //the values are checked with the help of an array of TStrings
    823     TString keys[7]= { "NULL", "NULL", "NULL", "NULL", "NULL", "NULL" , "NULL" };
    824     TString stop     = "NULL";
    825     TString runstart = "NULL";
    826     TString runstop  = "NULL";
    827     Int_t count = 0;
    828883    TExMap blocks;
    829     Int_t runbegin;
    830     Int_t runend;
    831 
    832     TSQLRow *row=0;
    833     while ((row=res->Next()))
    834     {
    835         if (count==0)
    836         {
    837             for (Int_t i=1 ; i<8 ; i++)
    838                 keys[i-1]=(*row)[i];
    839             runstart=(*row)[0];
    840         }
    841 
    842         for (Int_t i=1 ; i<8 ; i++)
    843         {
    844             runbegin=atoi(runstart.Data());
    845             runend=atoi(runstop.Data());
    846             if (i==2 && runbegin>20100 && runend<45100)
    847                 continue;
    848 
    849             TString value=(*row)[i];
    850             TString key=keys[i-1];
    851             if (!value.CompareTo(key))
    852                 continue;
    853 
    854             keys[i-1]=value;
    855             //fill values into TExMap
    856             blocks.Add((ULong_t)blocks.GetSize(), (Long_t)runbegin, (Long_t)runend);
    857             runstart=(*row)[0];
    858             for (Int_t i=1 ; i<8 ; i++)
    859                 keys[i-1]=(*row)[i];
    860             break;
    861         }
    862         runstop=(*row)[0];
    863         count++;
    864     }
    865 
    866     //fill values into TExMap (last value)
    867     runbegin=atoi(runstart.Data());
    868     runend=atoi(runstop.Data());
    869     blocks.Add((ULong_t)blocks.GetSize(), (Long_t)runbegin, (Long_t)runend);
    870 
     884    buildblocks(res, blocks);
     885    delete res;
     886
     887    // ---
     888    // Now the blocks containing the same observation conditions
     889    // are created...
     890    // ---
    871891
    872892    //get list of current sequence of this night from the database and store it in sequlist
     
    874894    query=Form("SELECT fSequenceFirst FROM Sequences WHERE fManuallyChangedKEY=1 AND %s order by fSequenceFirst",
    875895               cond.Data());
    876 //    cout << "Q: " << query << endl;
    877896
    878897    res = serv.Query(query);
     
    880899        return 2;
    881900
    882     cout << "old sequences: " << flush;
     901    cout << "Old sequences: " << flush;
     902    TSQLRow *row=0;
    883903    while ((row=res->Next()))
    884904    {
     
    888908    }
    889909    cout << endl;
     910
     911    delete res;
    890912
    891913    Bool_t rc = kTRUE;
     
    896918    while (nblocks.Next(key, val))
    897919    {
    898         Int_t runstart2 = (Int_t)key;
    899         Int_t runstop2 = (Int_t)val;
    900         cout << endl << "datablock from " << runstart2 << " to " << runstop2 << endl;
    901 
    902         if (!Process(serv, datapath, sequpath, runstart2, runstop2, sequlist, dummy))
     920        const Int_t runstart = (Int_t)key;
     921        const Int_t runstop  = (Int_t)val;
     922
     923        cout << endl << "Datablock from " << runstart << " to " << runstop << ":" << endl;
     924
     925        if (!Process(serv, datapath, sequpath, runstart, runstop, sequlist, dummy))
    903926            rc = kFALSE;
    904927
     
    912935    while ((obj=Next()))
    913936    {
    914         cout << "sequ: " << obj->GetName() << " deleting... " << endl;
     937        cout << " - Sequence " << obj->GetName() << " deleting... " << endl;
    915938        if (!DeleteSequence(serv, datapath, sequpath, atoi(obj->GetName()), dummy))
    916939            return 2;
     
    947970    {
    948971        date=(*row)[0];
    949         cout << "date: " << date << endl;
    950972        buildsequenceentries(date, datapath, sequpath, dummy);
    951973    }
     974
     975    delete res;
    952976
    953977    return 1;
Note: See TracChangeset for help on using the changeset viewer.