#ifndef __JACOUSTICS__JEMITTERID__ #define __JACOUSTICS__JEMITTERID__ #include #include #include #include #include "JSystem/JStat.hh" #include "JLang/JStringStream.hh" #include "JLang/JException.hh" #include "Jeep/JComment.hh" /** * \file * * Emitter identification. * \author mdejong */ namespace JACOUSTICS {} namespace JPP { using namespace JACOUSTICS; } namespace JACOUSTICS { using JLANG::JValueOutOfRange; using JEEP::JComment; /** * Auxiliary class for emitter identification. * * This class can be used to map the identfier of a waveform * (i.e.\ column "EMITTERID" the database table "toashort" or JDATABASE::JToAshort::EMITTERID) * to the identifier of the corresponding emitter (c.q.\ tripod). */ struct JEmitterID : public std::map { /** * Get emitter identifier for given waveform identifier. * * \param id waveform identifier * \return emitter identifier */ int operator()(const int id) const { const_iterator p = this->find(id); if (p != this->end()) return p->second; else THROW(JValueOutOfRange, "Invalid waveform identifier " << id); } /** * Read emitter data from input. * * \param in input stream * \param object emitter data * \return input stream */ friend inline std::istream& operator>>(std::istream& in, JEmitterID& object) { using namespace JPP; JStringStream is(in); if (getFileStatus(is.str().c_str())) { is.load(); } object.clear(); is >> object.comment; int waveform; int emitter; while (is >> waveform >> emitter) { object[waveform] = emitter; } return in; } /** * Write emitter data to output. * * \param out output stream * \param object emitter data * \return output stream */ friend inline std::ostream& operator<<(std::ostream& out, const JEmitterID& object) { using namespace std; out << object.comment; for (JEmitterID::const_iterator i = object.begin(); i != object.end(); ++i) { out << setw(3) << i->first << ' ' << setw(2) << i->second << endl; } return out; } JComment comment; }; /** * Function object for emitter identification. */ static JEmitterID getEmitterID; } #endif