Ignore:
Timestamp:
07/19/08 12:55:42 (16 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/mjobs
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mjobs/MSequence.cc

    r9012 r9015  
    4747//   Sequence:     31015
    4848//
    49 //   # Observation Period (not needed)
    50 //   Period:       18
     49//   # Observation Period (not needed, calculated from Night)
     50//   # Period:       18
    5151//
    5252//   # Date of sunrise of the observation night - necessary if the path
     
    7474//   # Total number of data-events in sequence (not needed)
    7575//   NumEvents:    250914
     76//
     77//   # Brightest light condition of the contained runs (not needed)
     78//   LightCondition: Twilight
    7679//
    7780//   # Whether this is MC data or not (necessary in case of MCs if
     
    661664    fLastRun   = GetEnvValue2(env, prefix, "LastRun",   -1);
    662665    fNumEvents = GetEnvValue2(env, prefix, "NumEvents", -1);
    663     fPeriod    = GetEnvValue2(env, prefix, "Period",    -1);
    664666
    665667    TString str;
    666     str = GetEnvValue2(env, prefix, "LightConditions", "n/a");
     668    str = GetEnvValue2(env, prefix, "LightCondition", "n/a");
    667669    fLightCondition = GetLightCondition(str);
    668670
     
    673675    str += " 00:00:00";
    674676    fNight.SetSqlDateTime(str);
     677
     678    fPeriod = fNight.GetMagicPeriod();
    675679
    676680    fProject      = GetEnvValue2(env, prefix, "Project", "");
     
    688692
    689693    // Dummies:
     694    env.Touch("Period");
    690695    env.Touch("ZdMin");
    691696    env.Touch("ZdMax");
     
    700705}
    701706
     707// --------------------------------------------------------------------------
     708//
     709// Create a sequence from the database, e.g.
     710//
     711//    TString mysql     = "mysql://MAGIC:password@vela/MyMagic";
     712//    Int_t   sequence  = 100002;
     713//    Int_t   telescope = 1;
     714//
     715//    MSequence seq(mysql, sequence, telescope);
     716//
     717// For more details see MSequenceSQL.
     718//
    702719MSequence::MSequence(const char *fname, UInt_t seq, UShort_t tel)
    703720{
     
    705722}
    706723
     724// --------------------------------------------------------------------------
     725//
     726// Some helper functions for the comparison functions
     727//
    707728static int operator==(const TArrayI &a, const TArrayI &b)
    708729{
    709     return a.GetSize()==b.GetSize() ?
    710         memcmp(a.GetArray(), b.GetArray(), a.GetSize()*sizeof(Int_t))==0 :
    711         false;
    712 }
    713 
    714 static int IsNull(const TArrayI &a)
    715 {
    716     if (a.GetSize()==0)
    717         return true;
    718 
    719     return a.GetSize()==0 ? true : a==TArrayI(a.GetSize());
     730    return a.GetSize()==b.GetSize() &&
     731        memcmp(a.GetArray(), b.GetArray(), a.GetSize()*sizeof(Int_t));
    720732}
    721733
    722734static int IsNull(const TArrayI &a, const TArrayI &b)
    723735{
    724     return IsNull(a) && IsNull(b);
    725 }
    726 
    727 Bool_t MSequence::IsSimilar(const MSequence &s) const
     736    return a==TArrayI(a.GetSize()) && b==TArrayI(b.GetSize());
     737}
     738
     739static int Check(const TArrayI &a, const TArrayI &b)
     740{
     741    return a==b || IsNull(a, b);
     742}
     743
     744// --------------------------------------------------------------------------
     745//
     746// Here we test all things mandatory for a sequence:
     747//   fTelescope
     748//   fSequence
     749//   fNight
     750//   fMonteCarlo
     751//   fCalRuns
     752//   fCalRunsSub
     753//   fPedRuns
     754//   fPedRunsSub
     755//   fDatRuns
     756//   fDatRunsSub
     757//   fExclRuns
     758//   fExclRunsSub
     759//
     760Bool_t MSequence::IsCompatible(const MSequence &s) const
    728761{
    729762    return // Mandatory
    730         fTelescope==s.fTelescope && fSequence==s.fSequence &&
    731         fNight==s.fNight
    732         && fLightCondition==s.fLightCondition &&
    733 
    734         fMonteCarlo==s.fMonteCarlo &&
    735 
    736         (fRunsSub    ==s.fRunsSub     || IsNull(fRunsSub,     s.fRunsSub))     &&
    737         (fCalRunsSub ==s.fCalRunsSub  || IsNull(fCalRunsSub,  s.fCalRunsSub))  &&
    738         (fPedRunsSub ==s.fPedRunsSub  || IsNull(fPedRunsSub,  s.fPedRunsSub))  &&
    739         (fDatRunsSub ==s.fDatRunsSub  || IsNull(fDatRunsSub,  s.fDatRunsSub))  &&
    740         (fExclRunsSub==s.fExclRunsSub || IsNull(fExclRunsSub, s.fExclRunsSub))
    741         ;
    742 }
    743 
     763        fTelescope   == s.fTelescope   &&
     764        fSequence    == s.fSequence    &&
     765        fNight       == s.fNight       &&
     766
     767        fMonteCarlo  == s.fMonteCarlo  &&
     768
     769        fCalRuns     == s.fCalRuns     &&
     770        fPedRuns     == s.fPedRuns     &&
     771        fDatRuns     == s.fDatRuns     &&
     772        fExclRuns    == s.fExclRuns    &&
     773
     774        Check(fCalRunsSub,  s.fCalRunsSub) &&
     775        Check(fPedRunsSub,  s.fPedRunsSub) &&
     776        Check(fDatRunsSub,  s.fDatRunsSub) &&
     777        Check(fExclRunsSub, s.fExclRunsSub);
     778}
     779
     780// --------------------------------------------------------------------------
     781//
     782// Here we test whether all values of a sequence are identical
     783//   IsCompaticle(s)
     784//   fStart
     785//   fLastRun
     786//   fNumEvents
     787//   fPeriod
     788//   fProject
     789//   fSource
     790//   fRuns
     791//   fHvSettings
     792//   fTriggerTable
     793//   fLightCondition
     794//   fRuns
     795//   fRunsSub
     796//
     797Bool_t MSequence::operator==(const MSequence &s) const
     798{
     799    return IsCompatible(s) &&
     800        // Unnecessary
     801        fStart          == s.fStart          &&
     802        fLastRun        == s.fLastRun        &&
     803        fNumEvents      == s.fNumEvents      &&
     804        fPeriod         == s.fPeriod         &&
     805        fProject        == s.fProject        &&
     806        fSource         == s.fSource         &&
     807        fRuns           == s.fRuns           &&
     808        fHvSettings     == s.fHvSettings     &&
     809        fTriggerTable   == s.fTriggerTable   &&
     810        fLightCondition == s.fLightCondition &&
     811        Check(fRunsSub, s.fRunsSub);
     812}
     813
     814// --------------------------------------------------------------------------
     815//
     816// Check whether the sequence has also identical source, i.e.
     817// the sequence filepath and the datapath in addition to operator==
     818//
    744819Bool_t MSequence::IsIdentical(const MSequence &s) const
    745820{
    746     return IsSimilar(s) &&
    747         // Unnecessary
    748         fStart==s.fStart         && fLastRun==s.fLastRun   &&
    749         fNumEvents==s.fNumEvents && fPeriod==s.fPeriod     &&
    750         fProject==s.fProject     && fSource==s.fSource     &&
    751         /*fTriggerTable==s.fTriggerTable &&*/ fHvSettings==s.fHvSettings;
    752 }
    753 
    754 Bool_t MSequence::operator==(const MSequence &s) const
    755 {
    756     return IsIdentical(s) &&
     821    return *this==s &&
    757822        // Obsolete
    758823        fDataPath==s.fDataPath && fFileName==s.fFileName;
     
    9811046        out << pre << "Night:          " << fNight.GetStringFmt("%Y-%m-%d") << endl;
    9821047    out << endl;
    983     out << pre << "LightConditions: ";
     1048    out << pre << "LightCondition: ";
    9841049    switch (fLightCondition)
    9851050    {
     
    10181083    else
    10191084    {
     1085        // FIXME: This needs more check!
     1086        // Could we make "Runs" an automatic summary of all runs?
     1087        // Should we add a check forbidding the same run in
     1088        // Cal/Ped/Data? What about the Exclude?
    10201089        str += PrintRuns(out, pre, "Runs:     ", fRuns,     fRunsSub);
    10211090        /*str +=*/ PrintRuns(out, pre, "CalRuns:  ", fCalRuns,  fCalRunsSub);
     
    11961265        f = &fCalRunsSub;
    11971266        break;
     1267    case 'X':
     1268        r = &fExclRuns;
     1269        f = &fExclRunsSub;
     1270        break;
    11981271    default:
    11991272        r = &fRuns;
     
    12041277    AddEntry(run, file, *r, *f);
    12051278
    1206     MJob::SortArray(fExclRuns);
    1207 }
    1208 
    1209 // --------------------------------------------------------------------------
    1210 //
    1211 // Exclude this run (i.e. add it to fExclRuns)
    1212 //
    1213 void MSequence::ExcludeFile(UInt_t run, UInt_t file/*, Bool_t force*/)
    1214 {
    1215 //    if (force && IsExcluded(run, file))
    1216 //        return;
    1217 
    1218     AddEntry(run, file, fExclRuns, fExclRunsSub);
    1219 
    1220     MJob::SortArray(fExclRuns);
     1279    SortArrays(*r, *f);
    12211280}
    12221281
     
    12681327    fNight.SetSqlDateTime(night);
    12691328
    1270     fPeriod = MAstro::GetMagicPeriod(fNight.GetMjd());
     1329    fPeriod = fNight.GetMagicPeriod();
    12711330}
    12721331
  • trunk/MagicSoft/Mars/mjobs/MSequence.h

    r9012 r9015  
    101101    }
    102102    MSequence(const char *fname, const char *path="", UInt_t id=(UInt_t)-1);
    103     MSequence(const char *fname, UInt_t seq, UShort_t tel=1);
     103    MSequence(const char *fname, UInt_t seq, UShort_t tel=0);
    104104    MSequence(const MSequence &s) : MParContainer(s),
    105105        fFileName(s.fFileName), fDataPath(s.fDataPath),
     
    116116        fExclRunsSub(s.fExclRunsSub), fMonteCarlo(s.fMonteCarlo) { }
    117117
    118     Bool_t IsSimilar(const MSequence &s) const;
     118    Bool_t IsCompatible(const MSequence &s) const;
    119119    Bool_t IsIdentical(const MSequence &s) const;
    120120    Bool_t operator==(const MSequence &s) const;
     
    143143    void AddFiles(UInt_t run, UInt_t f1, UInt_t f2, char type='*') { for (UInt_t i=f1; i<=f2; i++) AddFile(run, i, type); }
    144144
    145     void ExcludeFile(UInt_t num, UInt_t file=0);
     145    void ExcludeFile(UInt_t run, UInt_t file=0) { /*if (!force || !IsExcluded(run, file))*/ AddFile(run, file, 'X'); }
    146146    void ExcludeRuns(TString runs);
    147147
  • trunk/MagicSoft/Mars/mjobs/MSequenceSQL.cc

    r9013 r9015  
    5555//
    5656//
     57// A telscope number of -1 means: Take fTelescope as telescope number
     58// to request. A telescope number of 0 tries to get the sequence from
     59// the db including the telescope number. This will fail if more than
     60// one sequence with the same number exist in the db for several
     61// telescopes.
     62//
     63//
    5764// This tool will work from Period017 (2004_05_17) on...
    5865//
     
    169176    fLastRun       = atoi(data[0]);
    170177    fNumEvents     = atoi(data[8]);
     178    fTelescope     = atoi(data[11]);
    171179    fProject       = str[0];
    172180    fSource        = str[1];
     
    175183    fLightCondition = GetLightCondition(str[5]);
    176184
    177     // MISSING: ---> ZdMin, ZdMax, fComment, fMonteCarlo <---
     185    // FIXME: ZdMin (str[9]) ZdMax(str[10]) --> Comment
     186    // FIXME: fMonteCarlo
     187    // FIXME: fComment?
    178188
    179189    // Now prepare queries to request the runs from the database
    180     TString where(Form(" FROM RunData WHERE"
    181                        " fTelescopeNumber=%d AND fSequenceFirst=%d AND"
    182                        " fExcludedFDAKEY=1 AND fRunTypeKEY%%s",
    183                        fTelescope, fSequence));
     190    const TString where(Form(" FROM RunData WHERE"
     191                             " fTelescopeNumber=%d AND fSequenceFirst=%d AND"
     192                             " fExcludedFDAKEY=1 AND fRunTypeKEY%%s",
     193                             fTelescope, fSequence));
    184194
    185195    const TString query1(Form("SELECT fRunNumber, fFileNumber, fNumEvents %s", where.Data()));
     
    229239    if (res.GetRowCount()>1)
    230240    {
    231         *fLog << err << "ERROR - Database request returned unexpected number of rows." << endl;
    232         return kFALSE;
    233     }
    234 
    235     if (res.GetFieldCount()!=11)
     241        *fLog << err << "ERROR - Database request returned morethan one sequence." << endl;
     242        return kFALSE;
     243    }
     244
     245    if (res.GetFieldCount()!=12)
    236246    {
    237247        *fLog << err << "ERROR - Database request returned unexpected number of rows." << endl;
     
    268278//  kTrue in case of success.
    269279//
    270 Bool_t MSequenceSQL::GetFromDatabase(MSQLMagic &serv, Int_t sequno, Int_t tel)
     280Bool_t MSequenceSQL::GetFromDatabase(MSQLMagic &serv, UInt_t sequno, Int_t tel)
    271281{
    272282    // Check if we are connected to the sql server
     
    277287    }
    278288
    279     // check if any telescope number is avlid
    280     if (tel<=0 && fTelescope<=0)
     289    /*
     290    // check if any telescope number is valid
     291    if (tel<0 && fTelescope==0)
    281292    {
    282293        *fLog << err << "ERROR - No telescope number given in GetSeqFromDatabase." << endl;
    283294        return kFALSE;
    284295    }
    285 
    286     // check if any sequence number is avlid
    287     if (sequno<0 && fSequence<0)
     296    */
     297
     298    // check if any sequence number is valid
     299    if (sequno==(UInt_t)-1 && fSequence==(UInt_t)-1)
    288300    {
    289301        *fLog << err << "ERROR - No sequence number given in GetSeqFromDatabase." << endl;
     
    292304
    293305    // set "filename" and sequence number
    294     fFileName = serv.GetName();
    295     if (tel>0)
     306    fFileName  = serv.GetName();
     307    if (tel>=0)
    296308        fTelescope = tel;
    297     if (sequno>=0)
     309    if (sequno!=(UInt_t)-1)
    298310        fSequence = sequno;
    299311
     
    302314                  " fL1TriggerTableKEY, fL2TriggerTableKEY, fHvSettingsKEY, "
    303315                  " fLightConditionsKEY, fRunStart, fNumEvents, "
    304                   " fZenithDistanceMin, fZenithDistanceMax "
     316                  " fZenithDistanceMin, fZenithDistanceMax, fTelescopeNumber "
    305317                  " FROM Sequences WHERE ");
    306     query += Form("fTelescopeNumber=%d AND fSequenceFirst=%d",
    307                   fTelescope, fSequence);
     318    query += Form("fSequenceFirst=%d", fSequence);
     319
     320    if (tel>0)
     321        query += Form(" AND fTelescopeNumber=%d", fTelescope);
    308322
    309323    // Request information from database
     
    348362//  kTrue in case of success.
    349363//
    350 Bool_t MSequenceSQL::GetFromDatabase(const char *rc, Int_t sequno, Int_t tel)
     364Bool_t MSequenceSQL::GetFromDatabase(const char *rc, UInt_t sequno, Int_t tel)
    351365{
    352366    MSQLMagic serv(rc);
  • trunk/MagicSoft/Mars/mjobs/MSequenceSQL.h

    r9002 r9015  
    2020
    2121public:
    22     MSequenceSQL(MSQLMagic &serv, Int_t seqno=-1, Int_t tel=-1) { GetFromDatabase(serv, seqno, tel); }
    23     MSequenceSQL(const char *rc, Int_t seqno=-1, Int_t tel=-1)   { GetFromDatabase(rc, seqno, tel); }
    24     MSequenceSQL(Int_t seqno=-1, Int_t tel=-1)                   { GetFromDatabase(seqno, tel); }
     22    MSequenceSQL(MSQLMagic &serv, UInt_t seqno, Int_t tel=0) { GetFromDatabase(serv, seqno, tel); }
     23    MSequenceSQL(const char *rc, UInt_t seqno, Int_t tel=0)  { GetFromDatabase(rc, seqno, tel); }
     24    MSequenceSQL(UInt_t seqno, Int_t tel=0)                  { GetFromDatabase(seqno, tel); }
    2525
    26     Bool_t GetFromDatabase(MSQLMagic &serv, Int_t seqno=-1, Int_t tel=-1);
    27     Bool_t GetFromDatabase(const char *rc, Int_t seqno=-1, Int_t tel=-1);
    28     Bool_t GetFromDatabase(Int_t seqno=-1, Int_t tel=-1) { return GetFromDatabase("sql.rc", seqno, tel); }
     26    Bool_t GetFromDatabase(MSQLMagic &serv, UInt_t seqno=(UInt_t)-1, Int_t tel=-1);
     27    Bool_t GetFromDatabase(const char *rc, UInt_t seqno=(UInt_t)-1, Int_t tel=-1);
     28    Bool_t GetFromDatabase(UInt_t seqno=(UInt_t)-1, Int_t tel=-1) { return GetFromDatabase("sql.rc", seqno, tel); }
    2929
    3030    ClassDef(MSequenceSQL, 0) // Extension of MSequence to get a sequence from a database
Note: See TracChangeset for help on using the changeset viewer.