- Timestamp:
- 10/13/06 09:58:15 (18 years ago)
- Location:
- trunk/MagicSoft/Mars
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/Changelog
r8059 r8061 18 18 19 19 -*-*- END OF LINE -*-*- 20 2006/10/13 Thomas Bretz 21 22 * datacenter/macros/filldotraw.C: 23 - allow inserting missing runs 24 25 * msql/MSQLMagic.[h,cc]: 26 - adde also function to request the value not only key and name 27 28 29 20 30 2006/10/12 Daniela Dorner 21 31 -
trunk/MagicSoft/Mars/datacenter/macros/filldotraw.C
r7860 r8061 68 68 69 69 #include "MZlib.h" 70 #include "MSQL Server.h"70 #include "MSQLMagic.h" 71 71 #include "MRawRunHeader.h" 72 72 #include "MDirIter.h" … … 74 74 using namespace std; 75 75 76 Int_t QueryFromName(MSQLMagic &serv, const char *col, const char *val) 77 { 78 const TString query1 = Form("SELECT f%sKEY FROM %s WHERE f%s='%s'", 79 col, col, col, val); 80 81 TSQLResult *res1 = serv.Query(query1); 82 if (!res1) 83 { 84 cout << "ERROR - Query has failed: " << query1 << endl; 85 return -1; 86 } 87 88 TSQLRow *row=res1->Next(); 89 90 const Int_t rc1 = row && (*row)[0] ? atoi((*row)[0]) : -1; 91 delete res1; 92 return rc1; 93 } 94 76 95 //get key for a magic number 77 Int_t MagicNumber(MSQLServer &serv, const MRawRunHeader &h) 78 { 79 TString query(Form("SELECT fMagicNumberKEY FROM MagicNumber WHERE fMagicNumber=%d", 80 h.GetMagicNumber())); 96 Int_t MagicNumber(MSQLMagic &serv, const MRawRunHeader &h) 97 { 98 return QueryFromName(serv, "MagicNumber", Form("%d", h.GetMagicNumber())); 99 } 100 101 Bool_t ReadRaw(TString fname, MRawRunHeader &h) 102 { 103 MZlib fin(fname); 104 if (!fin) 105 { 106 cout << "ERROR - Couldn't open file " << fname << endl; 107 return kFALSE; 108 } 109 110 if (!h.ReadEvt(fin)) 111 { 112 cout << "ERROR - Reading header from file " << fname << endl; 113 return kFALSE; 114 } 115 return kTRUE; 116 } 117 118 Bool_t ReadRoot(TString fname, MRawRunHeader *h) 119 { 120 TFile file(fname, "READ"); 121 if (file.IsZombie()) 122 { 123 cout << "ERROR - Cannot open file " << fname << endl; 124 return kFALSE; 125 } 126 127 TTree *t = (TTree*)file.Get("RunHeaders"); 128 if (!t) 129 { 130 cout << "ERROR - Tree RunHeaders not found." << endl; 131 return kFALSE; 132 } 133 134 t->SetBranchAddress("MRawRunHeader.", &h); 135 t->GetEntry(0); 136 137 return kTRUE; 138 } 139 140 Bool_t CheckRunNumber(MSQLMagic &serv, Int_t num) 141 { 142 TString query(Form("SELECT fRunNumber from RunData where fRunNumber=%d", num)); 81 143 82 144 TSQLResult *res = serv.Query(query); … … 84 146 { 85 147 cout << "ERROR - Query failed: " << query << endl; 148 return kFALSE; 149 } 150 151 TSQLRow *row = res->Next(); 152 153 Bool_t rc = row && (*row)[0] ? atoi((*row)[0])==num : kFALSE; 154 delete res; 155 return rc; 156 157 } 158 159 Bool_t InsertEntry(MSQLMagic &serv, MRawRunHeader &h) 160 { 161 const Int_t magickey = MagicNumber(serv, h); 162 const Int_t runkey = QueryFromName(serv, "RunType", h.GetRunTypeStr()); 163 const Int_t projkey = serv.QueryKeyOfName("Project", h.GetProjectName()); 164 const Int_t sourcekey = serv.QueryKeyOfName("Source", h.GetSourceName()); 165 const Int_t modekey = serv.QueryKeyOfName("ObservationMode", h.GetObservationMode()); 166 167 if (magickey<0 || runkey<0 || projkey<0 || sourcekey<0 || modekey<0) 86 168 return -1; 87 } 88 89 TSQLRow *row = res->Next(); 90 91 TString rc = row ? (*row)[0] : ""; 92 93 delete res; 94 95 if (rc.IsNull()) 96 { 97 cout << "ERROR - No result from query: " << query << endl; 169 170 TString query; 171 172 query += Form("fRunNumber=%d, ", h.GetRunNumber()); 173 query += Form("fMagicNumberKEY=%d, ", magickey); 174 query += Form("fFormatVersion=%d, ", h.GetFormatVersion()); 175 query += Form("fRunTypeKEY=%d, ", runkey); 176 query += Form("fProjectKEY=%d, ", projkey); 177 query += Form("fSourceKEY=%d, ", sourcekey); 178 query += Form("fNumEvents=%d, ", h.GetNumEvents()); 179 query += Form("fRunStart='%s', ", h.GetRunStart().GetSqlDateTime().Data()); 180 query += Form("fRunStop='%s', ", h.GetRunEnd().GetSqlDateTime().Data()); 181 query += Form("fObservationModeKEY=%d, ", modekey); 182 183 query += "fExcludedFDAKEY=1, fTestFlagKEY=1, fLightConditionsKEY=1, "; 184 query += "fCalibrationScriptKEY=1, fDiscriminatorThresholdTableKEY=1, "; 185 query += "fTriggerDelayTableKEY=1, fL1TriggerTableKEY=1, fL2TriggerTableKEY=1, "; 186 query += "fHvSettingsKEY=1, fZenithDistance=0, fAzimuth=0, "; 187 query += "fDaqStoreRate=0, fDaqTriggerRate=0, fMeanTRiggerRate=0, "; 188 query += "fL2RatePresc=0, fL2RateUnpresc=0 "; 189 190 return serv.Insert("RunData", query); 191 } 192 193 Int_t UpdateEntry(MSQLMagic &serv, MRawRunHeader &h) 194 { 195 //get key for the magic number 196 const Int_t key = MagicNumber(serv, h); 197 if (key<0) 98 198 return -1; 99 } 100 101 return rc.Atoi(); 102 } 103 104 Bool_t ReadRaw(TString fname, MRawRunHeader &h) 105 { 106 MZlib fin(fname); 107 if (!fin) 108 { 109 cout << "ERROR - Couldn't open file " << fname << endl; 110 return kFALSE; 111 } 112 113 if (!h.ReadEvt(fin)) 114 { 115 cout << "ERROR - Reading header from file " << fname << endl; 116 return kFALSE; 117 } 118 return kTRUE; 119 } 120 121 Bool_t ReadRoot(TString fname, MRawRunHeader *h) 122 { 123 TFile file(fname, "READ"); 124 if (file.IsZombie()) 125 { 126 cout << "ERROR - Cannot open file " << fname << endl; 127 return kFALSE; 128 } 129 130 TTree *t = (TTree*)file.Get("RunHeaders"); 131 if (!t) 132 { 133 cout << "ERROR - Tree RunHeaders not found." << endl; 134 return kFALSE; 135 } 136 137 t->SetBranchAddress("MRawRunHeader.", &h); 138 t->GetEntry(0); 139 140 return kTRUE; 141 } 142 143 int Process(MSQLServer &serv, TString fname, Bool_t dummy) 199 200 TString vars(Form("fMagicNumberKEY=%d, fFormatVersion=%d", 201 key, h.GetFormatVersion())); 202 TString where(Form("fRunNumber=%d", h.GetRunNumber())); 203 204 return serv.Update("RunData", vars, where); 205 } 206 207 208 int Process(MSQLMagic &serv, TString fname, Bool_t dummy) 144 209 { 145 210 MRawRunHeader h; … … 154 219 155 220 if (dummy) 156 {157 221 h.Print("header"); 158 return 1; 159 } 160 161 //get key for the magic number 162 const Int_t key = MagicNumber(serv, h); 163 if (key<0) 164 return 2; 165 166 TString query(Form("UPDATE RunData SET fMagicNumberKEY=%d, fFormatVersion=%d WHERE fRunNumber=%d", 167 key, h.GetFormatVersion(), h.GetRunNumber())); 168 169 TSQLResult *res = serv.Query(query); 170 if (!res) 171 { 172 cout << "ERROR - Query failed: " << query << endl; 173 return 2; 174 } 175 delete res; 176 return 1; 222 223 Int_t rc = CheckRunNumber(serv, h.GetRunNumber()) ? 224 UpdateEntry(serv, h) : InsertEntry(serv, h); 225 226 return rc==0 ? 2 : 1; 177 227 } 178 228 … … 181 231 TEnv env("sql.rc"); 182 232 183 MSQL Serverserv(env);233 MSQLMagic serv(env); 184 234 if (!serv.IsConnected()) 185 235 { … … 187 237 return 0; 188 238 } 239 240 serv.SetIsDummy(dummy); 189 241 190 242 cout << "filldotraw" << endl; … … 202 254 TEnv env("sql.rc"); 203 255 204 MSQL Serverserv(env);256 MSQLMagic serv(env); 205 257 if (!serv.IsConnected()) 206 258 { … … 208 260 return 0; 209 261 } 262 263 serv.SetIsDummy(dummy); 210 264 211 265 cout << "filldotraw" << endl; -
trunk/MagicSoft/Mars/msql/MSQLMagic.cc
r7952 r8061 51 51 // On success the name of the key is returned. 52 52 // 53 TString MSQLMagic::Query NameOfKey(TString col, const char *key)53 TString MSQLMagic::QueryValOf(TString col, const char *ext, const char *key) 54 54 { 55 55 if (col.EndsWith("KEY")) … … 58 58 col.Remove(0, 1); 59 59 60 const TString query=Form("SELECT f%s NameFROM %s WHERE f%sKEY=%s",61 col.Data(), col.Data(), col.Data(), key);60 const TString query=Form("SELECT f%s%s FROM %s WHERE f%sKEY=%s", 61 col.Data(), ext, col.Data(), col.Data(), key); 62 62 63 63 TSQLResult *res = Query(query); … … 75 75 // -------------------------------------------------------------------------- 76 76 // 77 // Return the name corresponding to a key. If col starts with f or 78 // end with KEY it is stripped. 79 // 80 // If the query fails an empty string is returned. 81 // 82 // On success the name of the key is returned. 83 // 84 TString MSQLMagic::QueryNameOfKey(TString col, const char *key) 85 { 86 return QueryValOf(col, "Name", key); 87 } 88 89 // -------------------------------------------------------------------------- 90 // 91 // Return the value corresponding to a key. If col starts with f or 92 // end with KEY it is stripped. 93 // 94 // If the query fails an empty string is returned. 95 // 96 // On success the value of the key is returned. 97 // 98 TString MSQLMagic::QueryValOfKey(TString col, const char *key) 99 { 100 return QueryValOf(col, "", key); 101 } 102 103 // -------------------------------------------------------------------------- 104 // 105 // return the key of f[col]KEY where f[col][ext]=[val] 106 // 107 // return -1 if the query failed or the KEY was not found 108 // return 0 if the KEY could not be determined after inserting 109 // return the KEY in case of success 110 // 111 Int_t MSQLMagic::QueryKeyOf(const char *col, const char *ext, const char *val) 112 { 113 const TString query1 = Form("SELECT f%sKEY FROM %s WHERE f%s%s='%s'", 114 col, col, col, ext, val); 115 116 TSQLResult *res1 = Query(query1); 117 if (!res1) 118 { 119 cout << "ERROR - Query has failed: " << query1 << endl; 120 return -1; 121 } 122 123 TSQLRow *row=res1->Next(); 124 125 const Int_t rc1 = row && (*row)[0] ? atoi((*row)[0]) : -1; 126 delete res1; 127 return rc1; 128 } 129 130 // -------------------------------------------------------------------------- 131 // 132 // return the key of f[col]KEY where f[col]=[val] 133 // 134 // return -1 if the query failed or the KEY was not found 135 // return 0 if the KEY could not be determined after inserting 136 // return the KEY in case of success 137 // 138 Int_t MSQLMagic::QueryKeyOfVal(const char *col, const char *val) 139 { 140 return QueryKeyOf(col, "", val); 141 } 142 143 // -------------------------------------------------------------------------- 144 // 77 145 // return the key of f[col]KEY where f[col]Name=[name] 78 146 // … … 86 154 Int_t MSQLMagic::QueryKeyOfName(const char *col, const char *name, Bool_t insert) 87 155 { 88 const TString query1 = Form("SELECT f%sKEY FROM %s WHERE f%sName='%s'", 89 col, col, col, name); 90 91 TSQLResult *res1 = Query(query1); 92 if (!res1) 93 { 94 cout << "ERROR - Query has failed: " << query1 << endl; 95 return -1; 96 } 97 98 TSQLRow *row=res1->Next(); 99 100 const Int_t rc1 = row && (*row)[0] ? atoi((*row)[0]) : -1; 101 102 delete res1; 156 const Int_t rc1 = QueryKeyOf(col, "Name", name); 103 157 104 158 if (rc1>=0) -
trunk/MagicSoft/Mars/msql/MSQLMagic.h
r7940 r8061 38 38 Bool_t IsDummy() const { return fIsDummy; } 39 39 40 TString QueryValOf(TString col, const char *ext, const char *key); 41 TString QueryValOfKey(TString col, const char *key); 40 42 TString QueryNameOfKey(TString col, const char *key); 41 43 Int_t QueryKeyOfName(const char *col, const char *name, Bool_t insert=kTRUE); 44 Int_t QueryKeyOfVal(const char *col, const char *val); 45 Int_t QueryKeyOf(const char *col, const char *ext, const char *val); 42 46 Bool_t ExistStr(const char *column, const char *table, const char *test); 43 47
Note:
See TracChangeset
for help on using the changeset viewer.