#include #include #include #include #include "TROOT.h" #include "TFile.h" #include "JAcoustics/JToA.hh" #include "JAcoustics/JSupport.hh" #include "JSupport/JSingleFileScanner.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" namespace { using JACOUSTICS::JToA; /** * Compare measured times of arrival. * * \param first first time-of-arrival * \param second second time-of-arrival * \return true if first time-of-arrival less than second; else false */ inline bool compare(const JToA& first, const JToA& second) { if (first.DETID == second.DETID) { if (first.RUN == second.RUN) { if (first.DOMID == second.DOMID) { if (first.WAVEFORMID == second.WAVEFORMID) { if (first.TOA_NS == second.TOA_NS) { if (first.SECONDS == second.SECONDS) { if (first.TICKS == second.TICKS) { if (first.QUALITYFACTOR == second.QUALITYFACTOR ) { return first.QUALITYNORMALISATION < second.QUALITYNORMALISATION; } else { return first.QUALITYFACTOR < second.QUALITYFACTOR; } } else { return first.TICKS < second.TICKS; } } else { return first.SECONDS < second.SECONDS; } } else { return first.TOA_NS < second.TOA_NS; } } else { return first.WAVEFORMID < second.WAVEFORMID; } } else { return first.DOMID < second.DOMID; } } else { return first.RUN < second.RUN; } } else { return first.DETID < second.DETID; } } /** * Write time-of-arrival to outout stream. * * \param out output stream * \param object time-of-arrival * \return output stream */ std::ostream& operator<<(std::ostream& out, const JToA& object) { using namespace std; using namespace JPP; out << setw(8) << object.RUN << ' ' << setw(8) << object.DOMID << ' ' << setw(2) << object.WAVEFORMID << ' ' << FIXED(15,1) << (static_cast(object.SECONDS) + static_cast(object.TICKS)*16E-9) << ' ' << FIXED( 9,6) << object.TOA_NS << ' ' << FIXED( 9,3) << object.QUALITYFACTOR; return out; } } /** * \file * * Program to compare toa 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 toa data."); zap['f'] = make_field(inputFile, "two outputs of JToA"); 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()); 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(), compare); } 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]) { DEBUG(">> " << setw(width) << left << inputFile[0] << right << ' ' << *p0 << endl); } for ( ; p0 != buffer[0].end() && p1 != buffer[1].end() && compare(*p1,*p0); ++p1, ++count[1]) { DEBUG("<< " << setw(width) << left << inputFile[1] << right << ' ' << *p1 << endl); } if (p0 != buffer[0].end() && p1 != buffer[1].end() && !compare(*p0,*p1) && !compare(*p1,*p0)) { ++count[0]; DEBUG(setw(width) << left << inputFile[0] << right << ' ' << *p0 << " \\" << endl); DEBUG(setw(width) << left << inputFile[1] << right << ' ' << *p1 << " / " << endl); ++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); } }