Changeset 7983 for trunk/MagicSoft/Mars/datacenter
- Timestamp:
- 09/28/06 10:36:56 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/datacenter/macros/writesequencefile.C
r7528 r7983 46 46 #include <fstream> 47 47 48 #include <MSQLServer.h>49 48 #include <TSQLRow.h> 50 49 #include <TSQLResult.h> … … 54 53 #include <TRegexp.h> 55 54 56 #include <MAstro.h> 57 #include <MTime.h> 58 #include <MDirIter.h> 55 #include "MAstro.h" 56 #include "MTime.h" 57 #include "MDirIter.h" 58 59 #include "MSQLServer.h" 59 60 60 61 using namespace std; 61 62 62 Bool_t Get AllRuns(MSQLServer &serv, ofstream &fout, TString query)63 Bool_t GetRuns(MSQLServer &serv, ofstream &fout, TString query, TString name) 63 64 { 64 65 TSQLResult *res = serv.Query(query); … … 66 67 return kFALSE; 67 68 69 Int_t cnt=0; 70 71 fout << name << ":"; 68 72 TSQLRow *row=0; 69 70 Int_t cnt = 0;71 72 fout << "Runs:";73 73 while ((row = res->Next())) 74 74 { … … 82 82 if (cnt==0) 83 83 { 84 cout << "ERROR - No runs belonging to this sequence found." << endl; 85 return kFALSE; 86 } 87 88 return kTRUE; 89 } 90 91 Bool_t GetCalRuns(MSQLServer &serv, ofstream &fout, TString query, MTime *t) 92 { 93 TSQLResult *res = serv.Query(query); 94 if (!res) 95 return kFALSE; 96 97 Int_t first = 0; 98 Int_t cnt = 0; 99 100 fout << "CalRuns:"; 101 TSQLRow *row=0; 102 while ((row = res->Next())) 103 if ((*row)[1][0]=='4') 104 { 105 fout << " " << (*row)[0]; 106 cnt++; 107 108 if (!first) 109 { 110 t[0].SetSqlDateTime((*row)[2]); 111 first = 1; 112 } 113 t[1].SetSqlDateTime((*row)[3]); 114 } 115 fout << endl; 116 117 delete res; 118 119 if (cnt==0) 120 { 121 cout << "ERROR - No calibration runs belonging to this sequence found." << endl; 122 return kFALSE; 123 } 124 125 return kTRUE; 126 } 127 128 Bool_t GetPedRuns(MSQLServer &serv, ofstream &fout, TString query, MTime *t) 129 { 130 Int_t cnt = 0; 131 132 fout << "PedRuns:"; 133 134 Int_t tot = 0; 135 136 while (tot<1000) 137 { 138 TSQLResult *res = serv.Query(query); 139 if (!res) 140 return kFALSE; 141 142 Int_t idx = 0; 143 Int_t n = 0; 144 Double_t diff = 1e35; 145 MTime start, stop; 146 147 TSQLRow *row=0; 148 while ((row=res->Next())) 149 { 150 if ((*row)[1][0]=='3' || (cnt>1 && idx==0 && (*row)[1][0]=='2')) 151 { 152 MTime t0, t1; 153 t0.SetSqlDateTime((*row)[2]); 154 t1.SetSqlDateTime((*row)[3]); 155 156 if ((Double_t)t[0]-(Double_t)t1<diff && t[0]>t1) 157 { 158 diff = (Double_t)t[0]-(Double_t)t1; 159 idx = atoi((*row)[0]); 160 n = atoi((*row)[4]); 161 start = t0; 162 stop = t1; 163 } 164 if ((Double_t)t0-(Double_t)t[1]<diff && t0>t[1]) 165 { 166 diff = (Double_t)t0-(Double_t)t[1]; 167 idx = atoi((*row)[0]); 168 n = atoi((*row)[4]); 169 start = t0; 170 stop = t1; 171 } 172 } 173 } 174 175 tot += n; 176 if (idx!=0) 177 fout << " " << idx; 178 cnt ++; 179 180 delete res; 181 182 if (start<t[0]) 183 t[0] = start; 184 if (stop>t[1]) 185 t[1] = stop; 186 } 187 188 fout << endl; 189 190 if (cnt==0) 191 { 192 cout << "ERROR - No pedestal (data) runs belonging to this sequence found." << endl; 193 return kFALSE; 194 } 195 196 return kTRUE; 197 } 198 199 Bool_t GetDatRuns(MSQLServer &serv, ofstream &fout, TString query) 200 { 201 TSQLResult *res = serv.Query(query); 202 if (!res) 203 return kFALSE; 204 205 Int_t cnt=0; 206 207 fout << "DatRuns:"; 208 TSQLRow *row=0; 209 while ((row = res->Next())) 210 if ((*row)[1][0]=='2') 211 { 212 fout << " " << (*row)[0]; 213 cnt++; 214 } 215 fout << endl; 216 217 delete res; 218 219 if (cnt==0) 220 { 221 cout << "ERROR - No data runs belonging to this sequence found." << endl; 84 cout << "ERROR - No " << name << " belonging to this sequence found." << endl; 222 85 return kFALSE; 223 86 } … … 297 160 TString query(Form("SELECT fRunNumber, fRunTypeKEY, fRunStart, fRunStop, fNumEvents" 298 161 " FROM RunData WHERE fSequenceFirst=%s AND fExcludedFDAKEY=1" 299 " ORDER BY fRunNumber",162 " AND fRunTypeKEY %%s ORDER BY fRunNumber", 300 163 data[0])); 301 164 165 166 TString queryA(Form(query.Data(), "BETWEEN 2 AND 4")); 167 TString queryC(Form(query.Data(), "BETWEEN 4 AND 4")); 168 TString queryD(Form(query.Data(), "BETWEEN 2 AND 2")); 169 TString queryP(Form(query.Data(), "BETWEEN 3 AND 3")); 170 302 171 //write runs into sequence file 303 if (!GetAllRuns(serv, fout, query)) 304 return kFALSE; 305 306 fout << endl; 307 308 MTime t[2]; 309 if (!GetCalRuns(serv, fout, query, t)) 310 return kFALSE; 311 if (!GetPedRuns(serv, fout, query, t)) 312 return kFALSE; 313 if (!GetDatRuns(serv, fout, query)) 172 if (!GetRuns(serv, fout, queryA, "Runs")) 173 return kFALSE; 174 175 fout << endl; 176 177 if (!GetRuns(serv, fout, queryC, "CalRuns")) 178 return kFALSE; 179 if (!GetRuns(serv, fout, queryP, "PedRuns")) 180 return kFALSE; 181 if (!GetRuns(serv, fout, queryD, "DatRuns")) 314 182 return kFALSE; 315 183
Note:
See TracChangeset
for help on using the changeset viewer.