#include #include #include #include #include "JDB/JDB.hh" #include "JDB/JSelector.hh" #include "JDB/JSelectorSupportkit.hh" #include "JDB/JDBToolkit.hh" #include "JDB/JDetectorIntegration.hh" #include "JDB/JPMTHV.hh" #include "JDetector/JPMTIdentifier.hh" #include "Jeep/JPrint.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" /** * \file * Auxiliary program to determine TDC constraints (input to JFitK40.cc) according HV settings from the database. * \author mdejong */ int main(const int argc, const char * const argv[]) { using namespace std; using namespace JPP; typedef pair run_type; JServer server; string usr; string pwd; string cookie; string detid; run_type runs; string outputFile; bool usePMTID; // option for old data for which correction for PMT cable swaps does not apply int debug; try { JParser<> zap("Auxiliary program to determine TDC constraints (input to JFitK40.cc) according HV settings from the database."); zap['s'] = make_field(server) = getServernames(); zap['u'] = make_field(usr) = ""; zap['!'] = make_field(pwd) = ""; zap['C'] = make_field(cookie) = ""; zap['D'] = make_field(detid, "Detector identifier"); zap['r'] = make_field(runs, "Pair of data taking runs"); zap['o'] = make_field(outputFile, "TDC file") = ""; zap['U'] = make_field(usePMTID); zap['d'] = make_field(debug) = 1; zap(argc, argv); } catch(const exception& error) { FATAL(error.what() << endl); } try { JDB::reset(usr, pwd, cookie); const int ID = getDetector (detid); detid = getDetector(detid); typedef vector detector_type; detector_type detector; { ResultSet& rs = getResultSet(getTable(), getSelector(ID)); for (JDetectorIntegration parameters; rs >> parameters; ) { detector.push_back(parameters); } rs.Close(); } const JPMTHV pmt_hv[] = { JPMTHV(ID, runs.first), JPMTHV(ID, runs.second) }; filebuf buffer; if (outputFile != "") { buffer.open(outputFile.c_str(), ios::out); } ostream os(buffer.is_open() ? &buffer : cout.rdbuf()); for (detector_type::const_iterator i = detector.begin(); i != detector.end(); ++i) { if (i->PMTUPI.getPBS() == PBS::PMT) { try { if (pmt_hv[0](i->PMTUPI).value == pmt_hv[1](i->PMTUPI).value) { if (usePMTID) os << setw(10) << i->DOMID << ' ' << setw(2) << i->PMTID << endl; else os << setw(10) << i->DOMID << ' ' << setw(2) << i->CABLEPOS << endl; } } catch(const exception& error) { ERROR("Invalid UPI " << i->PMTUPI << ' ' << setw(10) << i->DOMID << ' ' << setw(2) << i->PMTID << endl); } } } buffer.close(); } catch(const exception& error) { FATAL(error.what() << endl); } }