Changeset 8107 for trunk/MagicSoft/Mars/datacenter/macros
- Timestamp:
- 10/17/06 19:13:14 (18 years ago)
- Location:
- trunk/MagicSoft/Mars/datacenter/macros
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/datacenter/macros/insertdataset.C
r7961 r8107 53 53 #include <iostream> 54 54 #include <iomanip> 55 #include <fstream>56 55 57 56 #include <TEnv.h> 58 57 59 #include <MSQLServer.h> 60 #include <TSQLRow.h> 61 #include <TSQLResult.h> 58 #include "MSQLMagic.h" 62 59 63 60 using 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 name83 // insert value, if it is not yet existing84 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 }129 61 130 62 int insertdataset(TString number, TString source, TString wobble, TString comment, Bool_t dummy=kTRUE) … … 132 64 TEnv env("sql.rc"); 133 65 134 MSQL Serverserv(env);66 MSQLMagic serv(env); 135 67 if (!serv.IsConnected()) 136 68 { … … 138 70 return 0; 139 71 } 72 73 serv.SetIdSummy(dummy); 74 140 75 cout << "insertdataset" << endl; 141 76 cout << "-------------" << endl; … … 145 80 146 81 //get source key 147 Int_t sourcekey = QueryNameKEY(serv, dummy,"Source", source.Data(), kFALSE);82 Int_t sourcekey = serv.QueryNameKEY("Source", source.Data(), kFALSE); 148 83 if (sourcekey<0) 149 84 { … … 156 91 157 92 //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) 192 94 { 193 95 cout << number << " already exists... " << endl; … … 195 97 } 196 98 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 197 114 return 1; 198 115 } -
trunk/MagicSoft/Mars/datacenter/macros/insertdate.C
r7460 r8107 45 45 #include <iostream> 46 46 #include <iomanip> 47 #include <fstream>48 47 49 48 #include <TEnv.h> 50 49 51 #include <MSQLServer.h> 52 #include <TSQLRow.h> 53 #include <TSQLResult.h> 50 #include <MSQLMagic.h> 54 51 55 52 using 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 77 53 78 54 int insertdate(TString date) … … 80 56 TEnv env("sql.rc"); 81 57 82 MSQL Serverserv(env);58 MSQLMagic serv(env); 83 59 if (!serv.IsConnected()) 84 60 { … … 94 70 //insert entry for date into the table SequenceBuildStatus, 95 71 // if entry is not yet existing 96 if (! ExistStr(serv,"fDate", "SequenceBuildStatus", date))72 if (!serv.ExistStr("fDate", "SequenceBuildStatus", date)) 97 73 { 98 TString query(Form("INSERT SequenceBuildStatus SET fDate='%s', fCCFilled=Now() ", 99 date.Data())); 74 TString vals(Form("fDate='%s', fCCFilled=Now()", date.Data())); 100 75 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; 108 81 } 109 82 else … … 111 84 cout << date << " already exists... do update. " << endl; 112 85 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())); 115 89 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 123 95 } 124 96 -
trunk/MagicSoft/Mars/datacenter/macros/insertsequence.C
r7460 r8107 49 49 #include <iostream> 50 50 #include <iomanip> 51 #include <fstream>52 51 53 52 #include <TEnv.h> 54 53 55 #include <MSQL Server.h>54 #include <MSQLMagic.h> 56 55 #include <TSQLRow.h> 57 56 #include <TSQLResult.h> 58 57 59 58 using 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 }126 59 127 60 int insertsequence(TString filename, Bool_t dummy=kTRUE) … … 130 63 TEnv sequ(filename); 131 64 132 MSQL Serverserv(env);65 MSQLMagic serv(env); 133 66 if (!serv.IsConnected()) 134 67 { … … 136 69 return 0; 137 70 } 71 72 serv.SetIsDummy(dummy); 73 138 74 cout << "insertsequence" << endl; 139 75 cout << "--------------" << endl; … … 159 95 //get source key 160 96 TString sourcename = sequ.GetValue("Source", ""); 161 Int_t sourcekey = QueryNameKEY(serv, dummy,"Source", sourcename.Data());97 Int_t sourcekey = serv.QueryNameKEY("Source", sourcename.Data()); 162 98 163 99 //get values for the sequence … … 227 163 { 228 164 cout << "new source name: " << sourcename << " -> inserting..." << endl; 229 sourcekey = QueryNameKEY(serv, dummy,"Source", sourcename.Data(), kFALSE);165 sourcekey = serv.QueryNameKEY("Source", sourcename.Data(), kFALSE); 230 166 source=Form("%d",sourcekey); 231 167 } … … 240 176 241 177 //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; 255 198 256 199 //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 265 205 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; 284 208 285 209 return 1;
Note:
See TracChangeset
for help on using the changeset viewer.