Jpp 21.0.0-rc.3
the software that should make you happy
Loading...
Searching...
No Matches
JAcousticsToolkit.hh
Go to the documentation of this file.
1#ifndef __JACOUSTICS__JACOUSTICSTOOLKIT__
2#define __JACOUSTICS__JACOUSTICSTOOLKIT__
3
4#include <map>
5#include <algorithm>
6#include <limits>
7
9
10#include "JLang/JException.hh"
11#include "JLang/JPredicate.hh"
12
14
15
16/**
17 * \file
18 *
19 * Acoustics toolkit.
20 * \author mdejong
21 */
22namespace JACOUSTICS {}
23namespace JPP { using namespace JACOUSTICS; }
24
25namespace JACOUSTICS {
26
30
31
32 /**
33 * Get waveform identifier.
34 *
35 * Conform TriDASManager configuration of acoustic data filter (DAQ_ADF_DOM_configuration), private communication Cristiano Bozza.
36 *
37 * \param id waveform identifier
38 * \return waveform identifier
39 */
40 inline int getWaveformID(int id)
41 {
42 if (id < 0)
43 return -id - 1;
44 else
45 return id;
46 }
47
48
49 /**
50 * Auxiliary data structure to unify weights of acoustics data
51 * according to the number of pings per emitter.
52 * The default option is to unify the weights.
53 */
54 struct JWeight :
55 public std::map<int, size_t>
56 {
57 /**
58 * Constructor.
59 *
60 * \param __begin begin of data
61 * \param __end end of data
62 */
63 template<class T>
64 JWeight(T __begin, T __end) :
65 min(std::numeric_limits<size_t>::max())
66 {
67 for (T i = __begin; i != __end; ++i) {
68 (*this)[i->getID()] += 1;
69 }
70
71 for (const_iterator i = this->begin(); i != this->end(); ++i) {
72 if (i->second < min) {
73 min = i->second;
74 }
75 }
76 }
77
78
79 /**
80 * Get option to unify weights.
81 *
82 * \return option
83 */
84 static bool getUnify()
85 {
86 return get_unify();
87 }
88
89
90 /**
91 * Set option to unify weights.
92 *
93 * \param unify option
94 */
95 static void setUnify(const bool unify)
96 {
97 get_unify() = unify;
98 }
99
100
101 /**
102 * Get weight.
103 *
104 * \param id identifier
105 * \return weight
106 */
107 double operator()(const int id) const
108 {
109 if (getUnify()) {
110
111 const_iterator p = this->find(id);
112
113 if (p != this->end())
114 return (double) min / (double) p->second;
115 else
116 THROW(JValueOutOfRange, "Invalid identifier " << id);
117
118 } else {
119
120 return 1.0;
121 }
122 }
123
124 private:
125 /**
126 * Get option to unify weights.
127 *
128 * \return option
129 */
130 static bool& get_unify()
131 {
132 static bool unify = true;
133
134 return unify;
135 }
136
137 size_t min;
138 };
139
140
141 /**
142 * Get position from element in data which corresponds to given predicate.
143 *
144 * \param __begin begin of data
145 * \param __end end of data
146 * \param predicate predicate
147 * \return position
148 */
149 template<class T, class JTypename_t, class JComparator_t>
150 inline JVector3D getPosition(T __begin,
151 T __end,
153 {
154 T p = std::find_if(__begin, __end, predicate);
155
156 if (p != __end)
157 return p->getPosition();
158 else
159 THROW(JValueOutOfRange, "No element in container which corresponds to given predicate.");
160 }
161
162
163 /**
164 * Get position from element in data which corresponds to given predicate.
165 *
166 * \param __begin begin of data
167 * \param __end end of data
168 * \param predicate predicate
169 * \param position default position
170 * \return position
171 */
172 template<class T, class JTypename_t, class JComparator_t>
173 inline JVector3D getPosition(T __begin,
174 T __end,
176 const JVector3D& position)
177 {
178 try {
179 return getPosition(__begin, __end, predicate);
180 }
181 catch(const std::exception&) {
182 return position;
183 }
184 }
185
186
187 /**
188 * Get UNIX time of given DAQ object.
189 *
190 * \param chronometer chronometer
191 * \return UNIX time [s]
192 */
193 inline double getUNIXTime(const KM3NETDAQ::JDAQChronometer& chronometer)
194 {
195 return chronometer.getTimesliceStart().getTimeNanoSecond() * 1.0e-9;
196 }
197}
198
199#endif
Exceptions.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Data structure for vector in three dimensions.
Definition JVector3D.hh:36
Template definition of auxiliary class to select objects.
Definition JPredicate.hh:23
Exception for accessing a value in a collection that is outside of its range.
JDAQUTCExtended getTimesliceStart() const
Get start of timeslice.
double getTimeNanoSecond() const
Get time (limited to 16 ns cycles).
Auxiliary classes and methods for acoustic position calibration.
int getWaveformID(int id)
Get waveform identifier.
double getUNIXTime(const KM3NETDAQ::JDAQChronometer &chronometer)
Get UNIX time of given DAQ object.
JVector3D getPosition(T __begin, T __end, const JPredicate< JTypename_t, JComparator_t > &predicate)
Get position from element in data which corresponds to given predicate.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary data structure to unify weights of acoustics data according to the number of pings per emit...
double operator()(const int id) const
Get weight.
static bool & get_unify()
Get option to unify weights.
static bool getUnify()
Get option to unify weights.
JWeight(T __begin, T __end)
Constructor.
static void setUnify(const bool unify)
Set option to unify weights.