Changeset 9377 for trunk/MagicSoft/Mars/datacenter/macros
- Timestamp:
- 03/02/09 16:20:18 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/datacenter/macros/fillganymed.C
r8996 r9377 64 64 #include <TSQLRow.h> 65 65 66 #include "MSQL Server.h"66 #include "MSQLMagic.h" 67 67 68 68 #include "MStatusArray.h" … … 72 72 using namespace std; 73 73 74 // -------------------------------------------------------------------------- 75 // 76 // Checks whether an entry is already existing 77 // 78 Bool_t ExistStr(MSQLServer &serv, const char *column, const char *table, Int_t test) 79 { 80 TString query(Form("SELECT %s FROM %s WHERE %s='%d'", column, table, column, test)); 81 TSQLResult *res = serv.Query(query); 82 if (!res) 83 return kFALSE; 84 85 TSQLRow *row; 86 87 Bool_t rc = kFALSE; 88 while ((row=res->Next())) 89 { 90 if ((*row)[0]) 91 { 92 rc = kTRUE; 93 break; 94 } 95 } 96 97 delete res; 98 99 return rc; 100 } 101 102 103 int Process(MSQLServer &serv, TString fname, Bool_t dummy) 74 int Process(MSQLMagic &serv, TString fname, Bool_t dummy) 104 75 { 105 76 TFile file(fname, "READ"); … … 168 139 // cout << " Significance Rate: " << S/TMath::Sqrt(tm/3600.) << " sigma/sqrt(h)" << endl; 169 140 141 TString vars = Form(" fExcessEvents=%d, " 142 " fBackgroundEvents=%d, " 143 " fSignalEvents=%d, " 144 " fSignificance=%s, " 145 " fScaleFactor=%s, " 146 " fEffOnTime=%d ", 147 exc, bgd, sig, 148 signif.Data(), 149 scale.Data(), tm); 170 150 171 //build query, insert information into the DB172 //if entry is already existing: update query173 //else: insert query174 TString query;175 if (!ExistStr(serv, "fDataSetNumber", "Ganymed", ds))176 {177 query = Form("INSERT Ganymed SET"178 " fDataSetNumber=%d,"179 " fExcessEvents=%d, "180 " fBackgroundEvents=%d, "181 " fSignalEvents=%d, "182 " fSignificance=%s, "183 " fScaleFactor=%s, "184 " fEffOnTime=%d ",185 ds, exc, bgd, sig,186 signif.Data(),187 scale.Data(), tm);188 }189 else190 {191 query = Form("UPDATE Ganymed SET"192 " fExcessEvents=%d, "193 " fBackgroundEvents=%d, "194 " fSignalEvents=%d, "195 " fSignificance=%s, "196 " fScaleFactor=%s, "197 " fEffOnTime=%d "198 " WHERE fDataSetNumber=%d ",199 exc, bgd, sig, signif.Data(),200 scale.Data(), tm, ds);201 }202 151 203 cout << "q: " << query << endl; 204 if (dummy) 205 return 1; 152 TString where = Form("fDataSetNumber=%d", ds); 206 153 207 TSQLResult *res = serv.Query(query); 208 if (!res) 209 { 210 cout << "ERROR - Query failed: " << query << endl; 211 return 2; 212 } 213 delete res; 214 return 1; 154 return serv.InsertUpdate("Ganymed", vars, where) ? 1 : 2; 215 155 } 216 156 217 157 int fillganymed(TString fname, Bool_t dummy=kTRUE) 218 158 { 219 MSQL Serverserv("sql.rc");159 MSQLMagic serv("sql.rc"); 220 160 if (!serv.IsConnected()) 221 161 { … … 231 171 cout << endl; 232 172 233 //process file 173 serv.SetIsDummy(dummy); 174 234 175 return Process(serv, fname, dummy); 235 176 }
Note:
See TracChangeset
for help on using the changeset viewer.