Changeset 9327 for trunk/MagicSoft
- Timestamp:
- 02/12/09 09:16:19 (16 years ago)
- Location:
- trunk/MagicSoft/Mars
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/Changelog
r9325 r9327 18 18 19 19 -*-*- END OF LINE -*-*- 20 2009/02/12 Thomas Bretz 21 22 * datacenter/macros/fillsources.C: 23 - updated 24 25 26 20 27 2009/02/11 Thomas Bretz 21 28 -
trunk/MagicSoft/Mars/datacenter/macros/fillsources.C
r8996 r9327 34 34 #include <iostream> 35 35 #include <iomanip> 36 36 37 #include <fstream> 37 38 … … 39 40 #include <TSQLResult.h> 40 41 41 #include "MSQL Server.h"42 #include "MSQLMagic.h" 42 43 43 44 using namespace std; 44 45 45 Bool_t ExistStr(MSQLServer &serv, const char *column, const char *table, const char *test)46 int fillsources(TString catalog, Bool_t dummy=kTRUE) 46 47 { 47 TString query(Form("SELECT %s FROM %s WHERE %s='%s'", column, table, column, test)); 48 49 cout << "query: " << query << endl; 50 51 TSQLResult *res = serv.Query(query); 52 if (!res) 53 return kFALSE; 54 55 Bool_t rc = kFALSE; 56 57 TSQLRow *row=res->Next(); 58 if (row && (*row)[0]) 59 rc=kTRUE; 60 61 delete res; 62 return rc; 63 } 64 65 66 int fillsources(TString catalog) 67 { 68 MSQLServer serv("sql.rc"); 48 MSQLMagic serv("sql.rc"); 69 49 if (!serv.IsConnected()) 70 50 { … … 72 52 return 0; 73 53 } 74 cout << "insert date" << endl;75 cout << "---------- " << endl;54 cout << "insertsources" << endl; 55 cout << "-------------" << endl; 76 56 cout << endl; 77 57 cout << "Connected to " << serv.GetName() << endl; 58 cout << "Catalog file: " << catalog << endl; 78 59 cout << endl; 79 60 80 TString source; 81 TString RA; 82 TString Dec; 83 TString waste; 61 serv.SetIsDummy(dummy); 62 84 63 ifstream fin(catalog); 85 64 if (!fin) 86 65 { 87 66 cout << "Could not open file " << catalog << endl; 88 return 0;67 return 1; 89 68 } 90 69 91 70 while (1) 92 71 { 72 TString src, ra, de, dum, epoch; 73 74 src.ReadToDelim(fin, ','); 75 dum.ReadToDelim(fin, ','); 76 ra.ReadToDelim(fin, ','); 77 de.ReadToDelim(fin, ','); 78 dum.ReadToDelim(fin, ','); 79 epoch.ReadToDelim(fin, '\n'); 80 93 81 if (!fin) 94 82 break; 83 /* 84 Double_t r,d; 85 if (!MAstro::Coordinate2Angle(ra, r)) 86 { 87 cout << "ERROR - Interpreting right ascension: " << ra << endl; 88 return 2; 89 } 90 if (!MAstro::Coordinate2Angle(de, d)) 91 { 92 cout << "ERROR - Interpreting declination: " << de << endl; 93 return 2; 94 } 95 */ 96 TString vars(Form("fRightAscension='%s', fDeclination='%s', fEpoch='%s'", 97 ra.Data(), de.Data(), epoch.Data())); 95 98 96 source.ReadToDelim(fin, ','); 97 waste.ReadToDelim(fin, ','); 98 RA.ReadToDelim(fin, ','); 99 Dec.ReadToDelim(fin, ','); 100 waste.ReadToDelim(fin, '\n'); 99 TString where(Form("fSourceName='%s'", src.Data())); 101 100 102 cout << "source: " << source << endl; 103 cout << "RA: " << RA << endl; 104 cout << "Dec: " << Dec << endl; 105 106 //insert entry for date into the table SequenceBuildStatus, 107 // if entry is not yet existing 108 if (!ExistStr(serv, "fSourceName", "Source", source)) 109 { 110 TString query(Form("INSERT Source SET fSourceName='%s', fRightAscension='%s', fDeclination='%s' ", 111 source.Data(), RA.Data(), Dec.Data())); 112 113 cout << "query: " << query << endl; 114 /* 115 TSQLResult *res = serv.Query(query); 116 if (!res) 117 { 118 cout << "Error - could not insert entry" << endl; 119 return 0; 120 } 121 delete res; 122 */ 123 } 124 else 125 { 126 cout << source << " already exists... do update. " << endl; 127 128 TString query(Form("Update Source SET fRightAscension='%s', fDeclination='%s' WHERE fSourceName='%s',", 129 RA.Data(), Dec.Data(), source.Data())); 130 131 cout << "query: " << query << endl; 132 /* 133 TSQLResult *res = serv.Query(query); 134 if (!res) 135 { 136 cout << "Error - could not update entry" << endl; 137 return 0; 138 } 139 delete res;*/ 140 } 101 if (!serv.InsertUpdate("Source", vars, where)) 102 return 2; 141 103 } 142 104 143 105 return 1; 144 106 } 145 146
Note:
See TracChangeset
for help on using the changeset viewer.