Changeset 9018 for trunk/MagicSoft/Mars/datacenter/macros
- Timestamp:
- 07/20/08 15:47:10 (17 years ago)
- Location:
- trunk/MagicSoft/Mars/datacenter/macros
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/datacenter/macros/checkfileavail.C
r8851 r9018 18 18 ! Author(s): Daniela Dorner, 01/2005 <mailto:dorner@astro.uni-wuerzburg.de> 19 19 ! 20 ! Copyright: MAGIC Software Development, 2000-200 620 ! Copyright: MAGIC Software Development, 2000-2008 21 21 ! 22 22 ! … … 34 34 // 35 35 // executing the macro: 36 // .x checkfileavail.C+( "sequencefile")36 // .x checkfileavail.C+(100002) 37 37 // the sequencefile (including path) has to be given, as the macro retrieves 38 38 // from there the runnumbers 39 39 // 40 // the macro returns 0, if there's no connection to the database, 2 ,if a41 // file is missing, and 1 if all files are there 40 // the macro returns 0, if there's no connection to the database, 2 if a 41 // file is missing, and 1 if all files are there, 3 in case of error. 42 42 // the return value is checked by the script, that executes the macro 43 43 // … … 45 45 // 46 46 ///////////////////////////////////////////////////////////////////////////// 47 48 47 #include <iostream> 49 48 #include <iomanip> 50 #include <fstream>51 49 52 #include <TEnv.h>53 54 #include <MSQLServer.h>55 50 #include <TSQLRow.h> 56 51 #include <TSQLResult.h> 57 52 53 #include "MSQLServer.h" 54 58 55 using namespace std; 59 56 60 61 //check the value of a column for a run 62 //if a file is not available, the column contains nothing (NULL) - this value is returned 63 TString GetStatus(MSQLServer &serv, TEnv &rc, TString primary, TString table, TString column) 57 int checkfileavail(Int_t num, Int_t tel) 64 58 { 65 TString query(Form("SELECT %s FROM %s WHERE %s=%s", 66 column.Data(), table.Data(), 67 rc.GetValue(table+".Primary", ""), 68 primary.Data())); 69 70 cout << "Query: " << query << endl; 71 72 TSQLResult *res = serv.Query(query); 73 if (!res) 74 { 75 cout << "Error - no run to check" << endl; 76 return ""; 77 } 78 79 TSQLRow *row = res->Next(); 80 81 TString ret = row ? (*row)[0] : ""; 82 83 delete res; 84 85 return ret; 86 } 87 88 int checkfileavail(TString sequencefile) 89 { 90 TEnv env("sql.rc"); 91 92 MSQLServer serv(env); 59 MSQLServer serv("sql.rc"); 93 60 if (!serv.IsConnected()) 94 61 { … … 96 63 return 0; 97 64 } 65 98 66 cout << "checkfileavail" << endl; 99 67 cout << "--------------" << endl; … … 101 69 cout << "Connected to " << serv.GetName() << endl; 102 70 cout << endl; 71 cout << "Sequence: " << num << endl; 72 cout << "Telecope: " << tel << endl; 73 cout << endl; 103 74 104 TEnv rc("steps.rc");75 // ------------------------------------------- 105 76 106 //reading runnumbers from Sequencefile 107 TEnv sequ(sequencefile); 108 cout << "sequ file: " << sequencefile.Data() << endl; 109 TString runs; 110 runs = sequ.GetValue("Runs", ""); 111 runs.ReplaceAll(" ", ","); 112 if (runs.IsNull()) 113 { 114 cout << "ERROR - No runs in file " << sequencefile << " found." << endl; 115 return 0; 116 } 117 118 //getting runnumbers from database 119 //(not neccessary anymore -> can be changed) 120 TString query="SELECT fRunNumber FROM RunData WHERE fRunNumber in ("; 121 query +=runs.Data(); 122 query +=")"; 77 TString query = "MIN( NOT (" 78 "ISNULL(fRawFileAvail) OR " 79 "ISNULL(fCCFileAvail) OR " 80 "ISNULL(fCaCoFileAvail) OR " 81 "ISNULL(fCaCoFileFound) OR " 82 "ISNULL(fTimingCorrection) OR " 83 "ISNULL(fCompmux) " 84 ")) " 85 "FROM RunProcessStatus " 86 "LEFT JOIN RunData USING (fTelescopeNumber,fRunNumber,fFileNumber) " 87 query += Form("WHERE fSequenceFirst=%d AND fTelescopeNumber=%d", num, tel); 123 88 124 89 TSQLResult *res = serv.Query(query); 125 90 if (!res) 126 cout << "Error - no run to check" << endl;91 return 3; 127 92 128 //check for each run the availability of files from the table RunProcessStatus 129 //the following columns have to be checked: 130 //fCCFileAvail, fCaCoFileAvail, fCaCoFileFound, fRawFileAvail, fTimingCorrection, fCompmux 131 //fTimingCorrection has to be checked, as only rawfiles with correct timing should be calibrated 132 TSQLRow *row=0; 133 while ((row = res->Next())) 93 if (res->GetRowCount()!=1) 134 94 { 135 TString runno=(*row)[0]; 136 cout << "run#: " << runno << endl; 137 //if one value returns "" (i.e. column is NULL), 0 is returned 138 if (GetStatus(serv, rc, runno, "RunProcessStatus", "fCCFileAvail").IsNull() 139 || GetStatus(serv, rc, runno, "RunProcessStatus", "fCaCoFileAvail").IsNull() 140 || GetStatus(serv, rc, runno, "RunProcessStatus", "fCaCoFileFound").IsNull() 141 || GetStatus(serv, rc, runno, "RunProcessStatus", "fTimingCorrection").IsNull() 142 || GetStatus(serv, rc, runno, "RunProcessStatus", "fCompmux").IsNull() 143 // || GetStatus(serv, rc, runno, "RunProcessStatus", "fTimingCorrection")=="1970-01-01 00:00:00" 144 || GetStatus(serv, rc, runno, "RunProcessStatus", "fRawFileAvail").IsNull()) 145 return 2; 95 cout << "ERROR - Unexpected number of returned rows (" << res->GetRowCount() << ")" << endl; 96 delete res; 97 return 3; 146 98 } 147 //if all values are okay (i.e. files are availabel), 1 is returned148 return 1;149 99 100 TSQlRow *row = res->Next(); 101 102 if (!row || !(*row)[0]) 103 { 104 cout << "ERROR - Unexpected result." << endl; 105 delete res; 106 return 3; 107 } 108 109 const Int_t rc = atoi((*row)[0]); 110 111 delete res; 112 113 return rc==1 ? 1 : 2; 150 114 } 151 -
trunk/MagicSoft/Mars/datacenter/macros/checkstardone.C
r7859 r9018 18 18 ! Author(s): Daniela Dorner, 05/2005 <mailto:dorner@astro.uni-wuerzburg.de> 19 19 ! 20 ! Copyright: MAGIC Software Development, 2000-200 620 ! Copyright: MAGIC Software Development, 2000-2008 21 21 ! 22 22 ! … … 28 28 // =============== 29 29 // 30 // check the availability of the star files for one sequence:30 // check the availability of all star files for one dataset: 31 31 // if star has been executed successfully, this information has been inserted 32 32 // into the database (SequenceProcessStatus) with this macro this information … … 34 34 // 35 35 // executing the macro: 36 // .x checkstardone.C+( "sequencenumber")36 // .x checkstardone.C+(1) 37 37 // 38 // the macro returns 0, if there's no connection to the database, 2, if a39 // file is missing, and 1 if all files are there38 // The macro returns 0, if there's no connection to the database, 2 if 39 // star is not done, and 1 if star done, 3 in case of error. 40 40 // the return value is checked by the script, that executes the macro 41 41 // 42 // this macro is very similar to the macro checkfileavail.C42 // This macro is very similar to the macro checkfileavail.C 43 43 // 44 44 ///////////////////////////////////////////////////////////////////////////// 45 46 45 #include <iostream> 47 46 #include <iomanip> 48 #include <fstream>49 47 50 #include <TEnv.h>51 52 #include <MSQLServer.h>53 48 #include <TSQLRow.h> 54 49 #include <TSQLResult.h> 55 50 51 #include "MSQLServer.h" 52 56 53 using namespace std; 57 54 58 59 //check the value of a column for a sequence 60 TString GetStatus(MSQLServer &serv, TEnv &env, TString primary, TString table, TString column) 55 int checkstardone(Int_t num) 61 56 { 62 TString query(Form("SELECT %s FROM %s WHERE %s=%s", 63 column.Data(), table.Data(), 64 env.GetValue(table+".Primary", ""), 65 primary.Data())); 66 67 cout << "Query: " << query << endl; 68 69 TSQLResult *res = serv.Query(query); 70 if (!res) 71 { 72 cout << "Error - no sequence to check" << endl; 73 return ""; 74 } 75 76 TSQLRow *row = res->Next(); 77 78 TString rc = row ? (*row)[0] : ""; 79 80 delete res; 81 82 return rc; 83 } 84 85 int checkstardone(TString datasetno) 86 { 87 TEnv env("sql.rc"); 88 89 MSQLServer serv(env); 57 MSQLServer serv("sql.rc"); 90 58 if (!serv.IsConnected()) 91 59 { … … 93 61 return 0; 94 62 } 63 95 64 cout << "checkstardone" << endl; 96 65 cout << "-------------" << endl; … … 98 67 cout << "Connected to " << serv.GetName() << endl; 99 68 cout << endl; 69 cout << "Dataset: " << num << endl; 70 cout << endl; 100 71 101 TEnv rc("steps.rc");72 // ------------------------------------------- 102 73 103 //check if fStar not NULL for sequence104 if (GetStatus(serv, rc, datasetno, "SequenceProcessStatus", "fStar").IsNull())105 return 2;74 TString query = "NOT ISNULL(fStar) FROM SequenceProcessStatus " 75 "LEFT JOIN DataSetSequenceMapping USING (fTelescopeNumber,fSequenceFirst) "; 76 query += Form("WHERE fDataSetNumber=%d", num); 106 77 107 return 1; 78 TSQLResult *res = serv.Query(query); 79 if (!res) 80 return 3; 81 82 if (res->GetRowCount()!=1) 83 { 84 cout << "ERROR - Unexpected number of returned rows (" << res->GetRowCount() << ")" << endl; 85 delete res; 86 return 3; 87 } 88 89 TSQlRow *row = res->Next(); 90 91 if (!row || !(*row)[0]) 92 { 93 cout << "ERROR - Unexpected result." << endl; 94 delete res; 95 return 3; 96 } 97 98 const Int_t rc = atoi((*row)[0]); 99 100 delete res; 101 102 return rc==1 ? 1 : 2; 108 103 } 109
Note:
See TracChangeset
for help on using the changeset viewer.