Changeset 8061 for trunk/MagicSoft/Mars/datacenter/macros/filldotraw.C
- Timestamp:
- 10/13/06 09:58:15 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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;
Note:
See TracChangeset
for help on using the changeset viewer.