Changeset 9005 for trunk/MagicSoft/Mars/datacenter/macros
- Timestamp:
- 07/17/08 15:58:20 (16 years ago)
- Location:
- trunk/MagicSoft/Mars/datacenter/macros
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/datacenter/macros/fillsignal.C
r8999 r9005 114 114 if (!cam) 115 115 { 116 cout << " WARNING- Reading of PedRMS;avg failed." << endl;116 cout << "ERROR - Reading of PedRMS;avg failed." << endl; 117 117 return 2; 118 118 } … … 122 122 if (!pul) 123 123 { 124 cout << " WARNING- Reading of PulsePos;avg failed." << endl;124 cout << "ERROR - Reading of PulsePos;avg failed." << endl; 125 125 return 2; 126 126 } … … 129 129 if (!difflo) 130 130 { 131 cout << " WARNING- Reading of DiffLo;avg failed." << endl;131 cout << "ERROR - Reading of DiffLo;avg failed." << endl; 132 132 return 2; 133 133 } … … 135 135 if (!diffhi) 136 136 { 137 cout << " WARNING- Reading of DiffHi;avg failed." << endl;137 cout << "ERROR - Reading of DiffHi;avg failed." << endl; 138 138 return 2; 139 139 } … … 144 144 if (sequence.IsNull()) 145 145 { 146 cout << " WARNING- Sequ# empty" << endl;146 cout << "ERROR - Sequ# empty" << endl; 147 147 cout << "Sequ# " << sequence << endl; 148 148 return 2; … … 161 161 if (!hilooff) 162 162 { 163 cout << " WARNING- Reading of HiLoOff failed." << endl;163 cout << "ERROR - Reading of HiLoOff failed." << endl; 164 164 return 2; 165 165 } … … 168 168 if (!hilocal) 169 169 { 170 cout << " WARNING- Reading of HiLoCal failed." << endl;170 cout << "ERROR - Reading of HiLoCal failed." << endl; 171 171 return 2; 172 172 } … … 191 191 if (meanrmsi<0 || meanrmso<0) 192 192 { 193 cout << " WARNING- MeanPedRMS inner or outer < 0 " << endl;193 cout << "ERROR - MeanPedRMS inner or outer < 0 " << endl; 194 194 cout << "MeanPedRMS inner " << meanrmsi << endl; 195 195 cout << "MeanPedRMS outer " << meanrmso << endl; … … 203 203 if (!cam) 204 204 { 205 cout << " WARNING- Reading of Interp'd;avg failed." << endl;205 cout << "ERROR - Reading of Interp'd;avg failed." << endl; 206 206 return 2; 207 207 } … … 212 212 if (meansigi<0 || meansigo<0) 213 213 { 214 cout << " WARNING- MeanInterp'd inner or outer < 0 " << endl;214 cout << "ERRROR - MeanInterp'd inner or outer < 0 " << endl; 215 215 cout << "MeanInterp'd inner " << meansigi << endl; 216 216 cout << "MeanInterp'd outer " << meansigo << endl; … … 225 225 if (pul->GetMean()<0 || pul->GetRMS()<0) 226 226 { 227 cout << " WARNING- PulsePos'd mean or rms < 0 " << endl;227 cout << "ERROR - PulsePos'd mean or rms < 0 " << endl; 228 228 cout << "PulsePos'd mean " << pul->GetMean() << endl; 229 229 cout << "PulsePos'd rms " << pul->GetRMS() << endl; … … 258 258 if (!cam) 259 259 { 260 cout << " WARNING- Reading of Unsuitable;avg failed." << endl;260 cout << "ERROR - Reading of Unsuitable;avg failed." << endl; 261 261 return 2; 262 262 } … … 375 375 376 376 377 return serv.Update("Calibration", vars, Form("fSequenceFirst=%d", seq)) ;377 return serv.Update("Calibration", vars, Form("fSequenceFirst=%d", seq)) ? 1 : 2; 378 378 } 379 379 -
trunk/MagicSoft/Mars/datacenter/macros/writesequencefile.C
r8052 r9005 41 41 // to the database is not working. 42 42 // 43 // 44 // This tool will work from Period017 (2004_05_17) on... 45 // 46 // For more details see MSequence and MSequenceSQL 47 // 43 48 ///////////////////////////////////////////////////////////////////////////// 44 #include <iostream> 45 #include <iomanip> 46 #include <fstream> 47 48 #include <TSQLRow.h> 49 #include <TSQLResult.h> 50 51 #include <TEnv.h> 52 #include <TMath.h> 53 #include <TRegexp.h> 54 55 #include "MAstro.h" 56 #include "MTime.h" 57 #include "MDirIter.h" 58 59 #include "MSQLMagic.h" 49 #include "MSequence.h" 60 50 61 51 using namespace std; 62 52 63 Bool_t GetRuns(MSQLServer &serv, ofstream &fout, TString query, TString name, UInt_t nevts=(UInt_t)-1)53 int writeseq(Int_t sequno, Int_t tel, TString sequpath="") 64 54 { 65 TSQLResult *res = serv.Query(query); 66 if (!res) 67 return kFALSE; 68 69 UInt_t cnt=0; 70 UInt_t evts=0; 71 72 fout << name << ":"; 73 TSQLRow *row=0; 74 while ((row = res->Next()) && evts<nevts) 75 { 76 fout << " " << (*row)[0]; 77 evts += atoi((*row)[1]); 78 cnt++; 79 } 80 fout << endl; 81 82 delete res; 83 84 if (cnt==0) 85 { 86 cout << "ERROR - No " << name << " belonging to this sequence found." << endl; 87 return kFALSE; 88 } 89 90 return kTRUE; 91 } 92 93 TString GetTime(const char *type) 94 { 95 return Form("if(TIME_TO_SEC(fRun%s)<12*60*60," 96 " TIME_TO_SEC(fRun%s)+24*60*60," 97 " TIME_TO_SEC(fRun%s))", type, type, type); 98 } 99 100 Int_t GetTimeC(MSQLServer &serv, const TString &str) 101 { 102 TSQLResult *res = serv.Query(str); 103 if (!res) 104 return -1; 105 106 TSQLRow *row=res->Next(); 107 if (!row) 108 { 109 delete res; 110 return -1; 111 } 112 113 Int_t rc = (*row)[0] ? atoi((*row)[0]) : -1; 114 delete res; 115 return rc; 116 } 117 118 Bool_t GetSequence(MSQLMagic &serv, TSQLRow &data, TString sequpath) 119 { 120 UShort_t y; 121 Byte_t m, d; 122 123 MTime time; 124 time.SetSqlDateTime(data[8]); 125 time.GetDateOfSunrise(y, m, d); 126 127 TString date = Form("%04d-%02d-%02d", y, (int)m, (int)d); 128 129 Int_t period = MAstro::GetMagicPeriod(time.GetMjd()); 130 131 TString str[6]; 132 str[0] = serv.QueryNameOfKey("Project", data[2]); 133 str[1] = serv.QueryNameOfKey("Source", data[3]); 134 str[2] = serv.QueryNameOfKey("L1TriggerTable", data[4]); 135 str[3] = serv.QueryNameOfKey("L2TriggerTable", data[5]); 136 str[4] = serv.QueryNameOfKey("HvSettings", data[6]); 137 str[5] = serv.QueryNameOfKey("LightConditions", data[7]); 138 139 if (str[0].IsNull() || str[1].IsNull() || str[2].IsNull() || str[3].IsNull() || str[4].IsNull() || str[5].IsNull()) 140 return kFALSE; 141 142 //create sequence file 143 TString fname(Form("%s/%04d/sequence%08d.txt", sequpath.Data(), atoi(data[0])/10000, atoi(data[0]))); 144 cout << "Creating " << fname << "..." << flush; 145 146 ofstream fout(fname); 147 if (!fout) 148 { 149 cout << "ERROR - Cannot open file." << endl; 150 return kFALSE; 151 } 152 153 //write information into file 154 fout << "Sequence: " << data[0] << endl; 155 fout << "Period: " << period << endl; 156 fout << "Night: " << date << endl; 157 fout << "LightConditions: " << str[5] << endl; 158 fout << endl; 159 fout << "Start: " << data[8] << endl; 160 fout << "LastRun: " << data[1] << endl; 161 fout << "Project: " << str[0] << endl; 162 fout << "Source: " << str[1] << endl; 163 fout << "ZdMin: " << data[10] << endl; 164 fout << "ZdMax: " << data[11] << endl; 165 fout << "L1TriggerTable: " << str[2] << endl; 166 fout << "L2TriggerTable: " << str[3] << endl; 167 fout << "HvSettings: " << str[4] << endl; 168 fout << "NumEvents: " << data[9] << endl; 169 fout << endl; 170 171 TString where(Form(" FROM RunData WHERE fSequenceFirst=%s AND fExcludedFDAKEY=1" 172 " AND fRunTypeKEY%%s", data[0])); 173 174 TString query1(Form("SELECT fRunNumber, fNumEvents %s", where.Data())); 175 TString query2(Form("SELECT %s %s", GetTime("Start").Data(), where.Data())); 176 TString query3(Form("SELECT %s %s", GetTime("Stop").Data(), where.Data())); 177 178 TString queryA(Form(query1.Data(), " BETWEEN 2 AND 4 ORDER BY fRunNumber")); 179 TString queryC(Form(query1.Data(), "=4 ORDER BY fRunNumber")); 180 TString queryD(Form(query1.Data(), "=2 ORDER BY fRunNumber")); 181 TString queryT(Form(query2.Data(), "=4 ORDER BY fRunNumber LIMIT 1")); 182 183 Int_t timec = GetTimeC(serv, queryT); 184 if (timec<0) 185 { 186 cout << "WARNING - Requesting start time of first calibration run failed." << endl; 187 queryT = Form(query3.Data(), "=4 ORDER BY fRunNumber LIMIT 1"); 188 timec = GetTimeC(serv, queryT); 189 if (timec<0) 190 { 191 cout << "ERROR - Neither start nor stop time of first calibration could be requested." << endl; 192 return kFALSE; 193 } 194 } 195 196 TString query4(Form("=3 ORDER BY ABS(%s-%d) ASC", GetTime("Stop").Data(), timec)); 197 TString queryP(Form(query1.Data(), query4.Data())); 198 199 //write runs into sequence file 200 if (!GetRuns(serv, fout, queryA, "Runs")) 201 return kFALSE; 202 203 fout << endl; 204 205 if (!GetRuns(serv, fout, queryC, "CalRuns")) 206 return kFALSE; 207 if (!GetRuns(serv, fout, queryP, "PedRuns", 1000)) 208 return kFALSE; 209 if (!GetRuns(serv, fout, queryD, "DatRuns")) 210 return kFALSE; 211 212 fout << endl; 213 214 cout << " done <Nevts=" << data[9] << ">" << endl; 215 216 return kTRUE; 217 } 218 219 // This tool will work from Period017 (2004_05_17) on... 220 int writesequencefile(Int_t sequno, TString sequpath) 221 { 222 TEnv env("sql.rc"); 223 224 MSQLMagic serv(env); 55 MSQLMagic serv("sql.rc"); 225 56 if (!serv.IsConnected()) 226 57 { … … 233 64 cout << endl; 234 65 cout << "Connected to " << serv.GetName() << endl; 66 cout << "Sequence: " << sequno << endl; 67 cout << "Telescope: " << tel << endl; 235 68 cout << endl; 236 69 237 //get sequence information from database 238 TString query(Form("SELECT fSequenceFirst, fSequenceLast, fProjectKEY, fSourceKEY," 239 " fL1TriggerTableKEY, fL2TriggerTableKEY, fHvSettingsKEY, " 240 " fLightConditionsKEY, fRunStart, fNumEvents, " 241 " fZenithDistanceMin, fZenithDistanceMax " 242 " FROM Sequences WHERE fSequenceFirst=%d", sequno)); 243 TSQLResult *res = serv.Query(query); 70 const MSequenceSQL s(serv, sequno, tel); 71 if (!s.IsValid()) 72 return 2; 244 73 245 TSQLRow *row = 0; 246 while ((row = res->Next())) 247 if (!GetSequence(serv, *row, sequpath)) 248 return 2; 74 if (sequpath.IsNull()) 75 { 76 s.Print(); 77 return 1; 78 } 249 79 250 delete res;80 const TString fname(Form("%s/%04d/sequence%08d.txt", sequpath.Data(), sequno/10000, sequno)); 251 81 252 cout << endl;82 cout << "File: " << fname << endl; 253 83 254 return 1;84 return s.WriteFile(fname) ? 1 : 2; 255 85 }
Note:
See TracChangeset
for help on using the changeset viewer.