#include #include #include #include #include #include "JDetector/JModule.hh" #include "JDetector/JDetector.hh" #include "JCalibrate/JTDC_t.hh" #include "Jeep/JPrint.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" /** * \file * * Test program PMT constaints. * \author mdejong */ int main(int argc, char **argv) { using namespace std; using namespace JPP; int debug; try { JParser<> zap("Test program PMT constaints."); zap['d'] = make_field(debug, "debug.") = 1; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } JDetector detector; for (int i = 1; i <= 3; ++i) { detector.push_back(JModule(i, JLocation())); } { // Test content. JTDC_t TDC; const set pmt = { 7, 12, 20 }; for (set::const_iterator i = pmt.begin(); i != pmt.end(); ++i) { TDC.insert(-1, *i); } const JTDC_t::value_type PMT(3, 30); TDC.insert(PMT); for (JTDC_t::const_iterator tdc = TDC.begin(); tdc != TDC.end(); ++tdc) { DEBUG("PMT " << setw(2) << tdc->first << ' ' << setw(2) << tdc->second << endl); } ASSERT(TDC.is_valid(), "Test validity."); for (int i = 0; i != NUMBER_OF_PMTS; ++i) { ASSERT(TDC.has(1, i) == (pmt.count(i) != 0), "Test availability of constraint " << setw(2) << i << ' ' << pmt.count(i)); } ASSERT(TDC.has(PMT.first, PMT.second), "Test availability of constraint " << PMT.first << ' ' << PMT.second); for (JDetector::const_iterator i = detector.begin(); i != detector.end(); ++i) { JTDC_t::range_type range = TDC.equal_range(i->getID()); if (i->getID() != PMT.first) { ASSERT(distance(range.first, range.second) == (int) pmt.size(), "Test number of PMTs."); for (JTDC_t::const_iterator i = range.first; i != range.second; ++i) { ASSERT(pmt.count(i->second) != 0, "Test PMT " << setw(2) << i->first << ' ' << setw(2) << i->second); } } else { ASSERT(distance(range.first, range.second) == 1, "Test number of PMTs."); for (JTDC_t::const_iterator i = range.first; i != range.second; ++i) { ASSERT(i->second == PMT.second, "Test PMT " << setw(2) << i->first << ' ' << setw(2) << i->second); } } } // Test I/O. stringstream ios; for (set::const_iterator i = pmt.begin(); i != pmt.end(); ++i) { ios << ' ' << -1 << ' ' << *i; } ios << ' ' << PMT.first << ' ' << PMT.second; JTDC_t ABC; ios >> ABC; for (JTDC_t::const_iterator p = TDC.begin(), q = ABC.begin(); p != TDC.end() && q != ABC.end(); ++p, ++q) { DEBUG("PMT " << setw(2) << p->first << ' ' << setw(2) << p->second << " == " << setw(2) << q->first << ' ' << setw(2) << q->second << " " << (*p == *q) << endl); } ASSERT(TDC == ABC, "Test of ASCI I/O."); // Test reverse. TDC.reverse(); ASSERT(TDC.is_valid(), "Test validity."); for (JDetector::const_iterator i = detector.begin(); i != detector.end(); ++i) { JTDC_t::range_type range = TDC.equal_range(i->getID()); if (i->getID() != PMT.first) { ASSERT(distance(range.first, range.second) == NUMBER_OF_PMTS - (int) pmt.size(), "Test number of PMTs."); for (JTDC_t::const_iterator i = range.first; i != range.second; ++i) { ASSERT(pmt.count(i->second) == 0, "Test PMT " << i->first << ' ' << setw(2) << i->second); } } else { ASSERT(distance(range.first, range.second) == NUMBER_OF_PMTS - 1, "Test number of PMTs."); for (JTDC_t::const_iterator i = range.first; i != range.second; ++i) { ASSERT(i->second != PMT.second, "Test PMT " << i->first << ' ' << setw(2) << i->second); } } } } { JTDC_t TDC; TDC.insert(-1, -1); for (JTDC_t::const_iterator tdc = TDC.begin(); tdc != TDC.end(); ++tdc) { DEBUG("PMT " << setw(2) << tdc->first << ' ' << setw(2) << tdc->second << endl); } ASSERT(TDC.is_valid(), "Test validity."); for (JDetector::const_iterator i = detector.begin(); i != detector.end(); ++i) { JTDC_t::range_type range = TDC.equal_range(i->getID()); ASSERT(distance(range.first, range.second) == NUMBER_OF_PMTS, "Test number of PMTs."); } TDC.reverse(); ASSERT(TDC.is_valid(), "Test validity."); for (JDetector::const_iterator i = detector.begin(); i != detector.end(); ++i) { JTDC_t::range_type range = TDC.equal_range(i->getID()); ASSERT(distance(range.first, range.second) == 0, "Test number of PMTs."); } } return 0; }