#include #include #include #include #include "JDB/JDB.hh" #include "JDB/JSelector.hh" #include "JDB/JSelectorSupportkit.hh" #include "JDB/JDetectorIntegration_t.hh" #include "JDB/JProductRouter.hh" #include "JDB/JCLBMap.hh" #include "JDB/JDBToolkit.hh" #include "JLang/JComparator.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" /** * \file * * Test program for building of detectors from database. * \author mdejong */ int main(int argc, char **argv) { using namespace std; using namespace JPP; JServer server; string usr; string pwd; string cookie; set filter; int debug; try { JParser<> zap("Test program for building of detectors from database."); zap['s'] = make_field(server) = getServernames(); zap['u'] = make_field(usr) = ""; zap['!'] = make_field(pwd) = ""; zap['C'] = make_field(cookie) = ""; zap['F'] = make_field(filter) = JPARSER::initialised(); zap['d'] = make_field(debug) = 3; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } JDetectorIntegration_t detector; DEBUG("Reading database table " << getTable() << endl); try { JDB::reset(usr, pwd, cookie); ResultSet& rs = getResultSet(getTable()); if (! (rs >> detector)) { THROW(JDatabaseException, "Error reading " << getTable()); } } catch(const exception& error) { FATAL(error.what() << endl); } DEBUG("Reading database table " << getTable() << endl); vector detectors; try { ResultSet& rs = getResultSet(getTable()); if (! (rs >> detectors)) { THROW(JDatabaseException, "Error reading " << getTable()); } rs.Close(); } catch(const exception& error) { FATAL(error.what() << endl); } int total_number_of_errors = 0; for (vector::const_iterator detx = detectors.begin(); detx != detectors.end(); ++detx) { if (filter.count(detx->OID) == 0) { DEBUG("Testing detector " << detx->OID << endl); vector buffer; try { ResultSet& rs = getResultSet(getTable(), getSelector(detx->OID)); if (! (rs >> buffer)) { THROW(JDatabaseException, "Error reading " << getTable()); } rs.Close(); } catch(const exception& error) { ERROR(RED << "Detector " << detx->OID << " - " << error.what() << RESET << endl); continue; } if (buffer.empty()) { ERROR(RED << "Detector " << detx->OID << " - " << " no data." << RESET << endl); continue; } map map_a; map map_b; for (vector::const_iterator i = buffer.begin(); i != buffer.end(); ++i) { map_a[JUPI_t(i->UPI)] = JLocation_t(i->DUID, i->FLOORID, -1); } detector.configure(detx->OID); const JProductRouter router(detector, PBS::CLB_SEQUENCES); const JDetectorIntegration_t::range_type range = detector.find(PBS::CLB); for (JDetectorIntegration_t::range_const_iterator i = range.first; i != range.second; ++i) { const JUPI_t upi = detector[i->second].content.getUPI(); map_b[upi] = router.getLocation(upi); } int number_of_errors = 0; for (map::const_iterator i_a = map_a.begin(); i_a != map_a.end(); ++i_a) { DEBUG(i_a->first << ' ' << i_a->second << " <--> "); map::const_iterator i_b = map_b.find(i_a->first); if (i_b != map_b.end()) { DEBUG(i_b->second); } DEBUG(endl); if (i_b == map_b.end()) ERROR("Missing data " << i_a->first << " at " << i_a->second << endl); else if (i_b->second.string != i_a->second.string) ERROR("Inconsistent string " << i_a->second.string << " != " << i_b->second.string << endl); else if (i_b->second.floor != i_a->second.floor) ERROR("Inconsistent floor " << i_a->second.floor << " != " << i_b->second.floor << endl); else continue; ++number_of_errors; } cout << (number_of_errors == 0 ? GREEN : RED) << "Detector " << detx->OID << " " << number_of_errors << " errors." << RESET << endl; total_number_of_errors += number_of_errors; } } ASSERT(total_number_of_errors == 0); return 0; }