#include #include #include #include #include #include "TROOT.h" #include "TFile.h" #include "JDB/JToAshort.hh" #include "JDB/JSupport.hh" #include "JLang/JPredicate.hh" #include "JSupport/JMultipleFileScanner.hh" #include "JAcoustics/JAcousticsSupportkit.hh" #include "Jeep/JPrint.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" namespace { using namespace JPP; /** * Auxiliary class to extend JDATABASE::JToAshort. */ struct JToAshort_t : public JToAshort { /** * Constructor. * * \param data data * \param counter counter */ JToAshort_t( const JToAshort& data, const int counter) : JToAshort(data), counter(counter) {} /** * Write data to output stream. * * \param out output stream * \param object object * \return output stream */ friend inline std::ostream& operator<<(std::ostream& out, const JToAshort_t& object) { using namespace std; using namespace JPP; out << setw(6) << object.RUN << ' ' << setw(8) << object.counter << ' ' << FIXED(20,5) << object.UNIXTIMEBASE << ' ' << setw(10) << object.DOMID << ' ' << FIXED(9,6) << object.TOA_S << ' ' << FIXED(5,0) << object.QUALITYFACTOR; return out; } int counter; /** * Compare 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 */ friend inline bool operator<(const JToAshort_t& first, const JToAshort_t& second) { return (first.UNIXTIMEBASE + first.TOA_S < second.UNIXTIMEBASE + second.TOA_S); } }; } /** * \file * * Example program to test acoustic data. * \author mdejong */ int main(int argc, char **argv) { using namespace std; using namespace JPP; JMultipleFileScanner inputFile; JLimit_t& numberOfEvents = inputFile.getLimit(); double precision; bool allowed; int debug; try { JParser<> zap("Example program to test acoustic data."); zap['f'] = make_field(inputFile); zap['n'] = make_field(numberOfEvents) = JLimit::max(); zap['A'] = make_field(allowed); zap['e'] = make_field(precision) = 1.0e-7; zap['d'] = make_field(debug) = 2; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } typedef vector buffer_type; // acoustic data type map > data; // emitter -> receiver -> data for (int counter = 0; inputFile.hasNext(); ++counter) { STATUS("counter: " << setw(8) << counter << '\r' << flush); DEBUG(endl); const JToAshort* parameters = inputFile.next(); data[parameters->EMITTERID][parameters->DOMID].push_back(JToAshort_t(*parameters, counter)); } STATUS(endl); for (map >::iterator i = data.begin(); i != data.end(); ++i) { for (map< int, buffer_type>::iterator module = i->second.begin(); module != i->second.end(); ++module) { buffer_type& buffer = module->second; sort(buffer.begin(), buffer.end()); for (buffer_type::const_iterator p = buffer.begin(); p != buffer.end(); ++p) { for (buffer_type::const_iterator q = buffer.begin(); q != p; ++q) { if (labs(p->DOMID - q->DOMID) == 0 && fabs(p->QUALITYFACTOR - q->QUALITYFACTOR) <= precision && fabs((p->UNIXTIMEBASE + p->TOA_S) - (q->UNIXTIMEBASE + q->TOA_S)) <= precision) { if (!allowed || (p->TOA_S < TOAMAX_S && q->TOA_S < TOAMAX_S)) { cout << *p << endl; cout << *q << endl; cout << "Difference between absolute times " << SCIENTIFIC(12,3) << ((p->UNIXTIMEBASE + p->TOA_S) - (q->UNIXTIMEBASE + q->TOA_S)) << endl; } } } } } } }