Jpp 21.0.0
the software that should make you happy
Loading...
Searching...
No Matches
JEmitterID.hh
Go to the documentation of this file.
1#ifndef __JACOUSTICS__JEMITTERID__
2#define __JACOUSTICS__JEMITTERID__
3
4#include <istream>
5#include <ostream>
6#include <iomanip>
7#include <map>
8
10#include "JLang/JException.hh"
11
12#include "Jeep/JComment.hh"
13
14
15/**
16 * \file
17 *
18 * Emitter identification.
19 * \author mdejong
20 */
21namespace JACOUSTICS {}
22namespace JPP { using namespace JACOUSTICS; }
23
24namespace JACOUSTICS {
25
27 using JEEP::JComment;
28
29
30 /**
31 * Auxiliary class for emitter identification.
32 *
33 * This class can be used to map the identfier of a waveform
34 * (i.e.\ column "EMITTERID" the database table "toashort" or JDATABASE::JToAshort::EMITTERID)
35 * to the identifier of the corresponding emitter (c.q.\ tripod).
36 */
37 struct JEmitterID :
38 public std::map<int, int>
39 {
40 /**
41 * Get emitter identifier for given waveform identifier.
42 *
43 * \param id waveform identifier
44 * \return emitter identifier
45 */
46 int operator()(const int id) const
47 {
48 const_iterator p = this->find(id);
49
50 if (p != this->end())
51 return p->second;
52 else
53 THROW(JValueOutOfRange, "Invalid waveform identifier " << id);
54 }
55
56
57 /**
58 * Read emitter data from input.
59 *
60 * \param in input stream
61 * \param object emitter data
62 * \return input stream
63 */
64 friend inline std::istream& operator>>(std::istream& in, JEmitterID& object)
65 {
66 using namespace JPP;
67
68 JStringStream is(in);
69
70 object.clear();
71
72 is >> object.comment;
73
74 int waveform;
75 int emitter;
76
77 while (is >> waveform >> emitter) {
78 object[waveform] = emitter;
79 }
80
81 return in;
82 }
83
84
85 /**
86 * Write emitter data to output.
87 *
88 * \param out output stream
89 * \param object emitter data
90 * \return output stream
91 */
92 friend inline std::ostream& operator<<(std::ostream& out, const JEmitterID& object)
93 {
94 using namespace std;
95
96 out << object.comment;
97
98 for (JEmitterID::const_iterator i = object.begin(); i != object.end(); ++i) {
99 out << setw(3) << i->first << ' ' << setw(2) << i->second << endl;
100 }
101
102 return out;
103 }
104
105
107 };
108
109
110 /**
111 * Function object for emitter identification.
112 */
114}
115
116#endif
Exceptions.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Wrapper class around STL stringstream class to facilitate optional loading of data from file.
Exception for accessing a value in a collection that is outside of its range.
Auxiliary classes and methods for acoustic position calibration.
static JEmitterID getEmitterID
Function object for emitter identification.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary class for emitter identification.
Definition JEmitterID.hh:39
friend std::istream & operator>>(std::istream &in, JEmitterID &object)
Read emitter data from input.
Definition JEmitterID.hh:64
int operator()(const int id) const
Get emitter identifier for given waveform identifier.
Definition JEmitterID.hh:46
friend std::ostream & operator<<(std::ostream &out, const JEmitterID &object)
Write emitter data to output.
Definition JEmitterID.hh:92
Auxiliary class for comment.
Definition JComment.hh:43