Changeset 8107 for trunk


Ignore:
Timestamp:
10/17/06 19:13:14 (18 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/Changelog

    r8106 r8107  
    2323     - updated comments
    2424     - only add the missing functions to TDataPrimitives when not
    25        yet done. Everything lse would leak memory
     25       yet done. Everything else would leak memory
    2626
    2727   * mhbase/MH3.[h,cc], mhvstime/MHVsTime.[h,cc]:
     
    7171     mpedestal/MPedCalcFromData.cc
    7272     - fixed warnings about shadows of parameters
     73
     74   * datacenter/macros/insertdataset.C, datacenter/macros/insertdate.C,
     75     datacenter/macros/insertsequence.C:
     76     - updated to use MSQLMagic
    7377
    7478
  • trunk/MagicSoft/Mars/datacenter/macros/insertdataset.C

    r7961 r8107  
    5353#include <iostream>
    5454#include <iomanip>
    55 #include <fstream>
    5655
    5756#include <TEnv.h>
    5857
    59 #include <MSQLServer.h>
    60 #include <TSQLRow.h>
    61 #include <TSQLResult.h>
     58#include "MSQLMagic.h"
    6259
    6360using namespace std;
    64 
    65 Bool_t ExistStr(MSQLServer &serv, const char *column, const char *table, const char *test)
    66 {
    67     TString query(Form("SELECT %s FROM %s WHERE %s='%s'", column, table, column, test));
    68     TSQLResult *res = serv.Query(query);
    69     if (!res)
    70         return kFALSE;
    71 
    72     Bool_t rc = kFALSE;
    73 
    74     TSQLRow *row=res->Next();
    75     if (row && (*row)[0])
    76         rc=kTRUE;
    77 
    78     delete res;
    79     return rc;
    80 }
    81 
    82 //get key of a name
    83 // insert value, if it is not yet existing
    84 Int_t QueryNameKEY(MSQLServer &serv, Bool_t dummy, const char *col, const char *name, Bool_t insert=kTRUE)
    85 {
    86     TString query;
    87 
    88     query = Form("SELECT f%sKEY FROM %s WHERE f%sName='%s'", col, col, col, name);
    89     TSQLResult *res = serv.Query(query);
    90     if (!res)
    91         return -1;
    92 
    93     TSQLRow *row=res->Next();
    94 
    95     Int_t rc = row && (*row)[0] ? atoi((*row)[0]) : -1;
    96 
    97     delete res;
    98 
    99     if (rc>=0)
    100         return rc;
    101 
    102     if (!insert)
    103         return -1;
    104 
    105     query = Form("INSERT %s (f%sName) VALUES (\"%s\");", col, col, name);
    106 
    107     if (dummy)
    108     {
    109         cout << query << endl;
    110         return 0;
    111     }
    112 
    113     res=serv.Query(query);
    114     if (!res)
    115         return -1;
    116 
    117     delete res;
    118 
    119     Int_t key = QueryNameKEY(serv, dummy, col, name, kFALSE);
    120     if (key>0)
    121     {
    122         cout << "New " << col << ": " << name << endl;
    123         return key;
    124     }
    125 
    126     cout << "ERROR: " << query << endl;
    127     return kFALSE;
    128 }
    12961
    13062int insertdataset(TString number, TString source, TString wobble, TString comment, Bool_t dummy=kTRUE)
     
    13264    TEnv env("sql.rc");
    13365
    134     MSQLServer serv(env);
     66    MSQLMagic serv(env);
    13567    if (!serv.IsConnected())
    13668    {
     
    13870        return 0;
    13971    }
     72
     73    serv.SetIdSummy(dummy);
     74
    14075    cout << "insertdataset" << endl;
    14176    cout << "-------------" << endl;
     
    14580
    14681    //get source key
    147     Int_t sourcekey = QueryNameKEY(serv, dummy, "Source", source.Data(), kFALSE);
     82    Int_t sourcekey = serv.QueryNameKEY("Source", source.Data(), kFALSE);
    14883    if (sourcekey<0)
    14984    {
     
    15691
    15792    //if dataset is not yet in database, insert the information
    158     if (!ExistStr(serv, "fDataSetNumber", "DataSets", number.Data())) // Form("%d", number)
    159     {
    160         TString query=Form("INSERT DataSets SET fDataSetNumber='%s', "
    161                    " fSourceKEY=%d, fWobble='%s', fComment='%s' ",
    162                    number.Data(), sourcekey, wobble.Data(), comment.Data());
    163 
    164         if (dummy)
    165         {
    166             cout << query << endl;
    167             return 0;
    168         }
    169 
    170         TSQLResult *res = serv.Query(query);
    171         if (!res)
    172         {
    173             cout << "Error - could not insert dataset" << endl;
    174             return 2;
    175         }
    176         delete res;
    177 
    178         //add also entry in the table DataSetProcessStatus
    179         query=Form("INSERT DataSetProcessStatus SET fDataSetNumber='%s', "
    180                    " fDataSetInserted=Now() ",
    181                    number.Data());
    182 
    183         res = serv.Query(query);
    184         if (!res)
    185         {
    186             cout << "Error - could not insert dataset" << endl;
    187             return 2;
    188         }
    189         delete res;
    190     }
    191     else
     93    if (serv.ExistStr("fDataSetNumber", "DataSets", number.Data())) // Form("%d", number)
    19294    {
    19395        cout << number << " already exists... " << endl;
     
    19597    }
    19698
     99    TString vals = Form("fDataSetNumber='%s', fSourceKEY=%d, "
     100                        "fWobble='%s', fComment='%s' ", number.Data(),
     101                        sourcekey, wobble.Data(), comment.Data());
     102
     103    Int_t rc = serv.Insert("DataSets", vals);
     104
     105    if (rc<=0) // dummy mode or failed
     106        return 0;
     107
     108    vals = Form("fDataSetNumber='%s', fDataSetInserted=Now()", number.Data());
     109    rc = serv.Insert("DataSetProcessStatus", vals);
     110
     111    if (rc<=0) // dummy mode or failed
     112        return 0;
     113
    197114    return 1;
    198115}
  • trunk/MagicSoft/Mars/datacenter/macros/insertdate.C

    r7460 r8107  
    4545#include <iostream>
    4646#include <iomanip>
    47 #include <fstream>
    4847
    4948#include <TEnv.h>
    5049
    51 #include <MSQLServer.h>
    52 #include <TSQLRow.h>
    53 #include <TSQLResult.h>
     50#include <MSQLMagic.h>
    5451
    5552using namespace std;
    56 
    57 Bool_t ExistStr(MSQLServer &serv, const char *column, const char *table, const char *test)
    58 {
    59     TString query(Form("SELECT %s FROM %s WHERE %s='%s'", column, table, column, test));
    60 
    61     cout << "query: " << query << endl;
    62 
    63     TSQLResult *res = serv.Query(query);
    64     if (!res)
    65         return kFALSE;
    66 
    67     Bool_t rc = kFALSE;
    68 
    69     TSQLRow *row=res->Next();
    70     if (row && (*row)[0])
    71         rc=kTRUE;
    72 
    73     delete res;
    74     return rc;
    75 }
    76 
    7753
    7854int insertdate(TString date)
     
    8056    TEnv env("sql.rc");
    8157
    82     MSQLServer serv(env);
     58    MSQLMagic serv(env);
    8359    if (!serv.IsConnected())
    8460    {
     
    9470    //insert entry for date into the table SequenceBuildStatus,
    9571    // if entry is not yet existing
    96     if (!ExistStr(serv, "fDate", "SequenceBuildStatus", date))
     72    if (!serv.ExistStr("fDate", "SequenceBuildStatus", date))
    9773    {
    98         TString query(Form("INSERT SequenceBuildStatus SET fDate='%s', fCCFilled=Now() ",
    99                            date.Data()));
     74        TString vals(Form("fDate='%s', fCCFilled=Now()", date.Data()));
    10075
    101         TSQLResult *res = serv.Query(query);
    102         if (!res)
    103         {
    104             cout << "Error - could not insert entry" << endl;
    105             return 0;
    106         }
    107         delete res;
     76        const Int_t rc = serv.Insert("SequenceBuildStatus", vals);
     77        if (rc==kFALSE) // Query failed
     78            return -1;
     79        //if (rc<0)       // Dummy mode
     80        //    return 0;
    10881    }
    10982    else
     
    11184        cout << date << " already exists... do update. " << endl;
    11285
    113         TString query="UPDATE SequenceBuildStatus SET fCCFilled=Now(), fExclusionsDone=NULL, ";
    114         query +=Form("fSequenceEntriesBuilt=NULL WHERE fDate='%s' ", date.Data());
     86        const Int_t rc = serv.Update("SequenceBuildStatus",
     87                                     "fCCFilled=Now(), fExclusionsDone=NULL, fSequenceEntriesBuilt=NULL",
     88                                     Form("fDate='%s'", date.Data()));
    11589
    116         TSQLResult *res = serv.Query(query);
    117         if (!res)
    118         {
    119             cout << "Error - could not update entry" << endl;
    120             return 0;
    121         }
    122         delete res;
     90        if (rc==kFALSE) // Query failed
     91            return -1;
     92        //if (rc<0)       // Dummy mode
     93        //    return 0;
     94
    12395    }
    12496
  • trunk/MagicSoft/Mars/datacenter/macros/insertsequence.C

    r7460 r8107  
    4949#include <iostream>
    5050#include <iomanip>
    51 #include <fstream>
    5251
    5352#include <TEnv.h>
    5453
    55 #include <MSQLServer.h>
     54#include <MSQLMagic.h>
    5655#include <TSQLRow.h>
    5756#include <TSQLResult.h>
    5857
    5958using namespace std;
    60 
    61 Bool_t ExistStr(MSQLServer &serv, const char *column, const char *table, const char *test)
    62 {
    63     TString query(Form("SELECT %s FROM %s WHERE %s='%s'", column, table, column, test));
    64     TSQLResult *res = serv.Query(query);
    65     if (!res)
    66         return kFALSE;
    67 
    68     Bool_t rc = kFALSE;
    69 
    70     TSQLRow *row=res->Next();
    71     if (row && (*row)[0])
    72         rc=kTRUE;
    73 
    74     delete res;
    75     return rc;
    76 }
    77 
    78 Int_t QueryNameKEY(MSQLServer &serv, Bool_t dummy, const char *col, const char *name, Bool_t insert=kTRUE)
    79 {
    80     TString query;
    81 
    82     query = Form("SELECT f%sKEY FROM %s WHERE f%sName='%s'", col, col, col, name);
    83     TSQLResult *res = serv.Query(query);
    84     if (!res)
    85         return -1;
    86 
    87     TSQLRow *row=res->Next();
    88 
    89     Int_t rc = row && (*row)[0] ? atoi((*row)[0]) : -1;
    90 
    91     delete res;
    92 
    93     if (rc>=0)
    94         return rc;
    95 
    96     if (!insert)
    97         return -1;
    98 
    99     query = Form("INSERT %s (f%sName) VALUES (\"%s\");", col, col, name);
    100 
    101     if (dummy)
    102     {
    103         cout << "Q:" << query << endl;
    104         return 0;
    105     }
    106 
    107     res=serv.Query(query);
    108     if (!res)
    109     {
    110         cout << "Error in query " << query << endl;
    111         return -1;
    112     }
    113 
    114     delete res;
    115 
    116     Int_t key = QueryNameKEY(serv, dummy, col, name, kFALSE);
    117     if (key>0)
    118     {
    119         cout << "New " << col << ": " << name << endl;
    120         return key;
    121     }
    122 
    123     cout << "ERROR: " << query << endl;
    124     return kFALSE;
    125 }
    12659
    12760int insertsequence(TString filename, Bool_t dummy=kTRUE)
     
    13063    TEnv sequ(filename);
    13164
    132     MSQLServer serv(env);
     65    MSQLMagic serv(env);
    13366    if (!serv.IsConnected())
    13467    {
     
    13669        return 0;
    13770    }
     71
     72    serv.SetIsDummy(dummy);
     73
    13874    cout << "insertsequence" << endl;
    13975    cout << "--------------" << endl;
     
    15995    //get source key
    16096    TString sourcename = sequ.GetValue("Source", "");
    161     Int_t sourcekey = QueryNameKEY(serv, dummy, "Source", sourcename.Data());
     97    Int_t sourcekey = serv.QueryNameKEY("Source", sourcename.Data());
    16298
    16399    //get values for the sequence
     
    227163    {
    228164        cout << "new source name: " << sourcename << " -> inserting..." << endl;
    229         sourcekey = QueryNameKEY(serv, dummy, "Source", sourcename.Data(), kFALSE);
     165        sourcekey = serv.QueryNameKEY("Source", sourcename.Data(), kFALSE);
    230166        source=Form("%d",sourcekey);
    231167    }
     
    240176
    241177    //build queries
    242     TString query1="INSERT Sequences SET fManuallyChangedKEY=2, ";
    243     query1 +=Form("fSequenceFirst=%d, fSequenceLast=%s, "
    244                   "fProjectKEY=%s, fSourceKEY=%s, fNumEvents=%s, "
    245                   "fRunStart='%s', fHvSettingsKEY=%s, fRunTime=%s, "
    246                   "fTriggerDelayTableKEY=%s, fDiscriminatorThresholdTableKEY=%s, "
    247                   "fTestFlagKEY=%s, fLightConditionsKEY=%s, fAzimuthMin=%s, "
    248                   "fAzimuthMax=%s, fZenithDistanceMin=%s, fZenithDistanceMax=%s, "
    249                   "fL1TriggerTableKEY=%s, fL2TriggerTableKEY=%s ",
    250                   seq, lastrun.Data(), project.Data(), source.Data(),
    251                   numevts.Data(), starttime.Data(), hv.Data(), uptime.Data(),
    252                   delay.Data(), dt.Data(), testflag.Data(), lightcond.Data(),
    253                   azmin.Data(), azmax.Data(), zdmin.Data(), zdmax.Data(),
    254                   l1tt.Data(), l2tt.Data());
     178    TString vals=
     179        Form("fManuallyChangedKEY=2, "
     180             "fSequenceFirst=%d, fSequenceLast=%s, "
     181             "fProjectKEY=%s, fSourceKEY=%s, fNumEvents=%s, "
     182             "fRunStart='%s', fHvSettingsKEY=%s, fRunTime=%s, "
     183             "fTriggerDelayTableKEY=%s, fDiscriminatorThresholdTableKEY=%s, "
     184             "fTestFlagKEY=%s, fLightConditionsKEY=%s, fAzimuthMin=%s, "
     185             "fAzimuthMax=%s, fZenithDistanceMin=%s, fZenithDistanceMax=%s, "
     186             "fL1TriggerTableKEY=%s, fL2TriggerTableKEY=%s ",
     187             seq, lastrun.Data(), project.Data(), source.Data(),
     188             numevts.Data(), starttime.Data(), hv.Data(), uptime.Data(),
     189             delay.Data(), dt.Data(), testflag.Data(), lightcond.Data(),
     190             azmin.Data(), azmax.Data(), zdmin.Data(), zdmax.Data(),
     191             l1tt.Data(), l2tt.Data());
     192
     193    const Int_t rc1 = serv.Insert("Sequences", vals);
     194    if (rc1<0)       // dummy
     195        return 1;
     196    if (rc1==kFALSE) // insert failed
     197        return 0;
    255198
    256199    //the time of the column fSequenceFileWritten is set to 'not to be done'
    257     TString query2=Form("INSERT SequenceProcessStatus SET "
    258                         "fSequenceFirst=%d, fSequenceFileWritten='1970-01-01 00:00:00'",
    259                         seq);
    260 
    261     if (dummy)
    262     {
    263         cout << "q1: " << query1 << endl;
    264         cout << "q2: " << query2 << endl;
     200    vals=Form("fSequenceFirst=%d, fSequenceFileWritten='1970-01-01 00:00:00'", seq);
     201
     202    const Int_t rc2 = serv.Insert("SequencesProcessStatus", vals);
     203
     204    if (rc2<0)       // dummy
    265205        return 1;
    266     }
    267 
    268 
    269     res = serv.Query(query1);
    270     if (!res)
    271     {
    272         cout << "ERROR: query1 failed: " << query1 << endl;
    273         return 0;
    274     }
    275     delete res;
    276 
    277     res = serv.Query(query2);
    278     if (!res)
    279     {
    280         cout << "ERROR: query2 failed: " << query2 << endl;
    281         return 0;
    282     }
    283     delete res;
     206    if (rc2==kFALSE) // insert failed
     207        return 0;
    284208
    285209    return 1;
Note: See TracChangeset for help on using the changeset viewer.