#include #include #include #include #include "JTrigger/JTimeslice.hh" #include "JTrigger/JTimesliceClone.hh" #include "JDetector/JDetector.hh" #include "JDetector/JModuleRouter.hh" #include "Jeep/JPrint.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" /** * Auxiliary program to test JTimesliceClone class. */ int main(int argc, char **argv) { using namespace std; using namespace JPP; int debug; try { JParser<> zap; zap['d'] = make_field(debug) = 3; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } const vector t1 = { 1.0e0, 1.0e1, 1.0e2, 1.0e3, 1.0e4, 1.0e5, 1.0e6, 1.0e7, 1.0e8 }; typedef JSuperFrame1D JSuperFrame1D_t; typedef JTimeslice JTimeslice_t; typedef JTimesliceClone JTimesliceClone_t; JTimeslice_t timeslice; const JDAQChronometer chronometer; const JPosition3D position; { JSuperFrame1D_t frame(chronometer, 101, position); copy(t1.begin(), t1.end(), back_inserter(frame)); frame.putEndMarker(); timeslice.push_back(frame); } { JSuperFrame1D_t frame(chronometer, 102, position); frame.putEndMarker(); timeslice.push_back(frame); } { JTimesliceClone_t clone(timeslice); for (double ti : t1) { const double Tmax = ti + 0.1; for (typename JTimesliceClone_t::value_type::const_iterator i = clone[0].begin(); *i < Tmax; ++i) { ASSERT(distance(clone[0].begin(), i) < distance(clone[0].begin(), clone[0].end()), "Test iterator " << SCIENTIFIC(7,1) << ti); } } for (double ti : t1) { const double Tmin = ti - 0.1; const double Tmax = ti + 0.1; { clone[0].fast_forward(Tmin); int n = 0; for (typename JTimesliceClone_t::value_type::const_iterator i = clone[0].get(); *i < Tmax; ++i) { if (*i == ti) { ++n; } } ASSERT(n == 1, "Test fast_forward " << SCIENTIFIC(7,1) << ti); } { clone[1].fast_forward(Tmin); int n = 0; for (typename JTimesliceClone_t::value_type::const_iterator i = clone[1].get(); *i < Tmax; ++i) { if (*i == ti) { ++n; } } ASSERT(n == 0, "Test fast_forward " << SCIENTIFIC(7,1) << ti); } } } { JDetector detector; for (int i = 101; i <= 103; ++i) { detector.push_back(JModule(i, JLocation())); } const JModuleRouter router(detector); JTimesliceClone_t clone(timeslice, router); typedef typename JTimesliceClone_t::value_type JFrame_t; for (double ti : t1) { const double Tmin = ti - 0.1; const double Tmax = ti + 0.1; for (int i = 101; i <= 103; ++i) { JFrame_t& frame = clone[router.getIndex(i)]; int n = 0; if (!frame.empty()) { frame.fast_forward(Tmin); for (typename JTimesliceClone_t::value_type::const_iterator i = frame.get(); *i < Tmax; ++i) { if (*i == ti) { ++n; } } } ASSERT(n == (frame.empty() ? 0 : 1), "Test fast_forward " << setw(2) << frame.size() << ' ' << SCIENTIFIC(7,1) << ti); } } } return 0; }