Jpp 19.3.0-rc.1
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
9#include "JSystem/JStat.hh"
10
12#include "JLang/JException.hh"
13
14#include "Jeep/JComment.hh"
15
16
17/**
18 * \file
19 *
20 * Emitter identification.
21 * \author mdejong
22 */
23namespace JACOUSTICS {}
24namespace JPP { using namespace JACOUSTICS; }
25
26namespace JACOUSTICS {
27
29 using JEEP::JComment;
30
31
32 /**
33 * Auxiliary class for emitter identification.
34 *
35 * This class can be used to map the identfier of a waveform
36 * (i.e.\ column "EMITTERID" the database table "toashort" or JDATABASE::JToAshort::EMITTERID)
37 * to the identifier of the corresponding emitter (c.q.\ tripod).
38 */
39 struct JEmitterID :
40 public std::map<int, int>
41 {
42 /**
43 * Get emitter identifier for given waveform identifier.
44 *
45 * \param id waveform identifier
46 * \return emitter identifier
47 */
48 int operator()(const int id) const
49 {
50 const_iterator p = this->find(id);
51
52 if (p != this->end())
53 return p->second;
54 else
55 THROW(JValueOutOfRange, "Invalid waveform identifier " << id);
56 }
57
58
59 /**
60 * Read emitter data from input.
61 *
62 * \param in input stream
63 * \param object emitter data
64 * \return input stream
65 */
66 friend inline std::istream& operator>>(std::istream& in, JEmitterID& object)
67 {
68 using namespace JPP;
69
70 JStringStream is(in);
71
72 if (getFileStatus(is.str().c_str())) {
73 is.load();
74 }
75
76 object.clear();
77
78 is >> object.comment;
79
80 int waveform;
81 int emitter;
82
83 while (is >> waveform >> emitter) {
84 object[waveform] = emitter;
85 }
86
87 return in;
88 }
89
90
91 /**
92 * Write emitter data to output.
93 *
94 * \param out output stream
95 * \param object emitter data
96 * \return output stream
97 */
98 friend inline std::ostream& operator<<(std::ostream& out, const JEmitterID& object)
99 {
100 using namespace std;
101
102 out << object.comment;
103
104 for (JEmitterID::const_iterator i = object.begin(); i != object.end(); ++i) {
105 out << setw(3) << i->first << ' ' << setw(2) << i->second << endl;
106 }
107
108 return out;
109 }
110
111
113 };
114
115
116 /**
117 * Function object for emitter identification.
118 */
120}
121
122#endif
Exceptions.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
File status.
Wrapper class around STL stringstream class to facilitate optional loading of data from file.
void load()
Load data from file with name corresponding to current contents.
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:41
friend std::istream & operator>>(std::istream &in, JEmitterID &object)
Read emitter data from input.
Definition JEmitterID.hh:66
int operator()(const int id) const
Get emitter identifier for given waveform identifier.
Definition JEmitterID.hh:48
friend std::ostream & operator<<(std::ostream &out, const JEmitterID &object)
Write emitter data to output.
Definition JEmitterID.hh:98
Auxiliary class for comment.
Definition JComment.hh:43