#include #include #include #include #include "TROOT.h" #include "TFile.h" #include "JAcoustics/JEvt.hh" #include "JAcoustics/JSupport.hh" #include "JSupport/JSingleFileScanner.hh" #include "JLang/JComparator.hh" #include "JLang/JComparison.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" namespace { using JACOUSTICS::JFit; using JACOUSTICS::JEvt; const struct { /** * Compare fits. * * \param first first fit * \param second second fit * \return true if first fit less than second; else false */ inline bool operator()(const JFit& first, const JFit& second) const { if (first.id == second.id) { if (first.tx == second.tx) { return first.ty < second.ty; } else { return first.tx < second.tx; } } else { return first.id < second.id; } } /** * Compare events. * * \param first first event * \param second second event * \return true if first event less than second; else false */ inline bool operator()(const JEvt& first, const JEvt& second) const { if (first.detid == second.detid) { if (first.UNIXTimeStart == second.UNIXTimeStart) { if (first.UNIXTimeStop == second.UNIXTimeStop) { if (first.nhit == second.nhit) { if (first.npar == second.npar) { if (first.size() == second.size()) { for (JEvt::const_iterator p0 = first .begin(), p1 = second.begin(); p0 != first.end() && p1 != second.end(); ++p0, ++p1) { if ((*this)(*p0, *p1)) { return true; } } return false; } else { return first.size() < second.size(); } } else { return first.npar < second.npar; } } else { return first.nhit < second.nhit; } } else { return first.UNIXTimeStop < second.UNIXTimeStop; } } else { return first.UNIXTimeStart < second.UNIXTimeStart; } } else { return first.detid < second.detid; } } } compare; /** * Printer. */ struct printer { int debug; size_t width; /** * Print data. * * \param out output stream * \param filename file name * \param index index * \param evt event * \param prefix prefix * \param postfix postfix * \return output stream */ std::ostream& operator()(std::ostream& out, const std::string& filename, const int index, const JEvt& evt, const std::string& prefix, const std::string& postfix) const { using namespace std; using namespace JPP; if (debug >= debug_t) { out << prefix << (prefix == "" ? "" : " ") << setw(width) << left << filename << right << ' ' << "[" << FILL(6,'0') << index << "]" << FILL() << ' ' << evt.detid << ' ' << FIXED(20,5) << evt.UNIXTimeStart << ' ' << FIXED(20,5) << evt.UNIXTimeStop << ' ' << (postfix == "" ? "" : " ") << postfix << endl; } return out; } /** * Write fit to output stream. * * \param out output stream * \param object fit * \param prefix prefix * \param postfix postfix * \return output stream */ std::ostream& operator()(std::ostream& out, const JFit& object, const std::string& prefix, const std::string& postfix) const { using namespace std; using namespace JPP; if (debug >= debug_t) { out << prefix << (prefix == "" ? "" : " ") << FILL(4,'0') << object.id << FILL() << ' ' << FIXED(9,6) << object.tx << ' ' << FIXED(9,6) << object.ty << ' ' << (postfix == "" ? "" : " ") << postfix << endl; } return out; } }; } /** * \file * * Program to compare acoustics fit data. * \author mdejong */ int main(int argc, char **argv) { using namespace std; using namespace JPP; vector inputFile; JLimit numberOfEvents; int debug; try { JParser<> zap("Program to compare acoustics fit data."); zap['f'] = make_field(inputFile, "two outputs of JKatoomba[.sh]"); zap['n'] = make_field(numberOfEvents) = JLimit::max(); zap['d'] = make_field(debug) = 2; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } if (inputFile.size() != 2u) { FATAL("Wrong number of input files " << inputFile.size() << endl); } const size_t width = max(inputFile[0].size(), inputFile[1].size()); const printer print = { debug, width }; vector buffer[2]; for (int i = 0; i != 2; ++i) { for (JSingleFileScanner in(inputFile[i], numberOfEvents); in.hasNext(); ) { buffer[i].push_back(*in.next()); } sort(buffer[i].begin(), buffer[i].end()); } if (true) { for (int i = 0; i != 2; ++i) { for (vector::iterator p = buffer[i].begin(); p != buffer[i].end(); ++p) { sort(p->begin(), p->end(), make_comparator(&JFit::id, JComparison::lt())); } } } int count[] = { 0, 0 }; for (vector::const_iterator p0 = buffer[0].begin(), p1 = buffer[1].begin(); p0 != buffer[0].end() && p1 != buffer[1].end(); ) { for ( ; p0 != buffer[0].end() && p1 != buffer[1].end() && compare(*p0,*p1); ++p0, ++count[1]) { print(cout, inputFile[0], distance(buffer[0].cbegin(),p0), *p0, ">>", ""); } for ( ; p0 != buffer[0].end() && p1 != buffer[1].end() && compare(*p1,*p0); ++p1, ++count[1]) { print(cout, inputFile[1], distance(buffer[1].cbegin(),p1), *p1, "<<", ""); } if (p0 != buffer[0].end() && p1 != buffer[1].end()) { if (!compare(*p0,*p1) && !compare(*p1,*p0)) { ++count[0]; print(cout, inputFile[0], distance(buffer[0].cbegin(),p0), *p0, "", "\\"); print(cout, inputFile[1], distance(buffer[1].cbegin(),p1), *p1, "", "/ "); } else { ++count[1]; if (p0->detid == p1->detid && p0->UNIXTimeStart == p1->UNIXTimeStart && p0->UNIXTimeStop == p1->UNIXTimeStop) { print(cout, inputFile[0], distance(buffer[0].cbegin(),p0), *p0, "", ""); print(cout, inputFile[1], distance(buffer[1].cbegin(),p1), *p1, "", ""); JEvt::const_iterator i0 = p0->begin(); JEvt::const_iterator i1 = p1->begin(); for ( ; i0 != p0->end() && i1 != p1->end(); ++i0, ++i1) { if (compare(*i0, *i1) || compare(*i1,*i0)) { print(cout, *i0, ">>", ""); print(cout, *i1, "<<", ""); } } for ( ; i0 != p0->end(); ++i0) { print(cout, *i0, ">>", ""); } for ( ; i1 != p1->end(); ++i1) { print(cout, *i1, "<<", ""); } } else { print(cout, inputFile[0], distance(buffer[0].cbegin(),p0), *p0, ">>", ""); print(cout, inputFile[1], distance(buffer[1].cbegin(),p1), *p1, "<<", ""); } } if (compare(*p0,*p1) || compare(*p1,*p0)) { } else { ++p0; ++p1; } } } STATUS("Number of differences / events: " << count[1] << " / " << count[0] << endl); if (buffer[0].size() != buffer[1].size()) { FATAL("Different size " << buffer[0].size() << ' ' << buffer[1].size() << endl); } if (count[1] != 0) { FATAL("Number of differences " << count[1] << endl); } }