#ifndef __JACOUSTICS__JTRANSMISSION__ #define __JACOUSTICS__JTRANSMISSION__ #include #include #include #include "JIO/JSerialisable.hh" /** * \file * * Acoustic transmission. * \author mdejong */ namespace JACOUSTICS {} namespace JPP { using namespace JACOUSTICS; } namespace JACOUSTICS { using JIO::JReader; using JIO::JWriter; /** * Acoustic transmission. */ struct JTransmission : public TObject { /** * Default constructor. */ JTransmission() : run(-1), id (-1), q (0.0), w (0.0), toa(0.0), toe(0.0) {} /** * Constructor. * * \param run run number * \param id identifier * \param Q quality * \param W normalisation * \param toa_s time-of-arrival [s] * \param toe_s time-of-emission [s] */ JTransmission(const int run, const int id, const double Q, const double W, const double toa_s, const double toe_s) : run(run), id (id), q (Q), w (W), toa(toa_s), toe(toe_s) {} /** * Virtual destructor. */ virtual ~JTransmission() {} /** * Get run number. * * \return run number */ int getRunNumber() const { return run; } /** * Get identifier. * * \return identifier */ int getID() const { return id; } /** * Get quality. * * \return quality */ double getQ() const { return q; } /** * Get normalisation. * * \return normalisation */ double getW() const { return w; } /** * Get calibrated time of arrival. * * \return time [s] */ double getToA() const { return toa; } /** * Get estimated time of emission. * * \return time [s] */ double getToE() const { return toe; } /** * Set estimated time of emission. * * \param toe time [s] */ void setToE(const double toe) { this->toe = toe; } /** * Read transmission from input. * * \param in reader * \param object transmission * \return reader */ friend inline JReader& operator>>(JReader& in, JTransmission& object) { in >> object.run; in >> object.id; in >> object.q; in >> object.w; in >> object.toa; in >> object.toe; return in; } /** * Write transmission to output. * * \param out writer * \param object transmission * \return writer */ friend inline JWriter& operator<<(JWriter& out, const JTransmission& object) { out << object.run; out << object.id; out << object.q; out << object.w; out << object.toa; out << object.toe; return out; } ClassDef(JTransmission, 3); /** * Auxiliary class to compare transmissions. */ struct equals { /** * Constructor. * * \param precision time-of-arrival precision [s] */ equals(const double precision) : precision(precision) {} /** * Compare two transmissions. * * \param first first transmission * \param second second transmission * \return true if times-of-arrival are similar; else false */ bool operator()(const JTransmission& first, const JTransmission& second) const { return fabs(first.getToA() - second.getToA()) <= precision; } const double precision; }; /** * Auxiliary class to compare transmissions. */ struct compare : public equals { /** * Constructor. * * \param precision time-of-arrival precision [s] */ compare(const double precision) : equals(precision) {} /** * Compare two transmissions. * * The transmission wih the earliest time-of-arrival comes first.\n * If the two transmissions are equal within the specified precision, * the transmission with the highest quality comes first.\n * If also the qualities are the same, the time-of-arrival is again used. * * \param first first transmission * \param second second transmission * \return true if time-of-arrival of first transmission earlier than that of second; else false */ bool operator()(const JTransmission& first, const JTransmission& second) const { if (static_cast(*this)(first, second)) { if (first.getQ() == second.getQ()) return first.getToA() < second.getToA(); else return first.getQ() > second.getQ(); } else { return first.getToA() < second.getToA(); } } }; protected: int run; int id; double q; double w; double toa; double toe; }; /** * Less-than operator for two transmissions. * * The less-than operator is first applied to the time-of-emission and then to the identifier. * * \param first first transmission * \param second second transmission * \return true if first transmission earlier than second; else false */ static inline bool operator<(const JTransmission& first, const JTransmission& second) { if (first.getToE() == second.getToE()) return first.getID() < second.getID(); else return first.getToE() < second.getToE(); } /** * Equals operator for two transmissions. * * The equal operator is applied to the time-of-emission and the identifier. * * \param first first transmission * \param second second transmission * \return true if first transmission equal to second; else false */ static inline bool operator==(const JTransmission& first, const JTransmission& second) { return (first.getID() == second.getID() && first.getToE() == second.getToE()); } } #endif