Jpp test-rotations-new
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 <limits>
6
8
9#include "JLang/JException.hh"
10#include "JLang/JPredicate.hh"
11
13
14
15/**
16 * \file
17 *
18 * Acoustics toolkit.
19 * \author mdejong
20 */
21namespace JACOUSTICS {}
22namespace JPP { using namespace JACOUSTICS; }
23
24namespace JACOUSTICS {
25
29
30
31 /**
32 * Get waveform identifier.
33 *
34 * Conform TriDASManager configuration of acoustic data filter (DAQ_ADF_DOM_configuration), private communication Cristiano Bozza.
35 *
36 * \param id waveform identifier
37 * \return waveform identifier
38 */
39 inline int getWaveformID(int id)
40 {
41 if (id < 0)
42 return -id - 1;
43 else
44 return id;
45 }
46
47
48 /**
49 * Auxiliary data structure to unify weights of acoustics data
50 * according to the number of pings per emitter.
51 * The default option is to unify the weights.
52 */
53 struct JWeight :
54 public std::map<int, size_t>
55 {
56 /**
57 * Constructor.
58 *
59 * \param __begin begin of data
60 * \param __end end of data
61 */
62 template<class T>
63 JWeight(T __begin, T __end) :
64 min(std::numeric_limits<size_t>::max())
65 {
66 for (T i = __begin; i != __end; ++i) {
67 (*this)[i->getID()] += 1;
68 }
69
70 for (const_iterator i = this->begin(); i != this->end(); ++i) {
71 if (i->second < min) {
72 min = i->second;
73 }
74 }
75 }
76
77
78 /**
79 * Get option to unify weights.
80 *
81 * \return option
82 */
83 static bool getUnify()
84 {
85 return get_unify();
86 }
87
88
89 /**
90 * Set option to unify weights.
91 *
92 * \param unify option
93 */
94 static void setUnify(const bool unify)
95 {
96 get_unify() = unify;
97 }
98
99
100 /**
101 * Get weight.
102 *
103 * \param id identifier
104 * \return weight
105 */
106 double operator()(const int id) const
107 {
108 if (getUnify()) {
109
110 const_iterator p = this->find(id);
111
112 if (p != this->end())
113 return (double) min / (double) p->second;
114 else
115 THROW(JValueOutOfRange, "Invalid identifier " << id);
116
117 } else {
118
119 return 1.0;
120 }
121 }
122
123 private:
124 /**
125 * Get option to unify weights.
126 *
127 * \return option
128 */
129 static bool& get_unify()
130 {
131 static bool unify = true;
132
133 return unify;
134 }
135
136 size_t min;
137 };
138
139
140 /**
141 * Get position from element in data which corresponds to given predicate.
142 *
143 * \param __begin begin of data
144 * \param __end end of data
145 * \param predicate predicate
146 * \return position
147 */
148 template<class T, class JTypename_t, class JComparator_t>
149 inline JVector3D getPosition(T __begin,
150 T __end,
152 {
153 T p = std::find_if(__begin, __end, predicate);
154
155 if (p != __end)
156 return p->getPosition();
157 else
158 THROW(JValueOutOfRange, "No element in container which corresponds to given predicate.");
159 }
160
161
162 /**
163 * Get position from element in data which corresponds to given predicate.
164 *
165 * \param __begin begin of data
166 * \param __end end of data
167 * \param predicate predicate
168 * \param position default position
169 * \return position
170 */
171 template<class T, class JTypename_t, class JComparator_t>
172 inline JVector3D getPosition(T __begin,
173 T __end,
175 const JVector3D& position)
176 {
177 try {
178 return getPosition(__begin, __end, predicate);
179 }
180 catch(const std::exception&) {
181 return position;
182 }
183 }
184
185
186 /**
187 * Get UNIX time of given DAQ object.
188 *
189 * \param chronometer chronometer
190 * \return UNIX time [s]
191 */
192 inline double getUNIXTime(const KM3NETDAQ::JDAQChronometer& chronometer)
193 {
194 return chronometer.getTimesliceStart().getTimeNanoSecond() * 1.0e-9;
195 }
196}
197
198#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.