Jpp  18.0.1-rc.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
12 #include "JGeometry3D/JVector3D.hh"
13 
14 
15 /**
16  * \file
17  *
18  * Acoustics toolkit.
19  * \author mdejong
20  */
21 namespace JACOUSTICS {}
22 namespace JPP { using namespace JACOUSTICS; }
23 
24 namespace JACOUSTICS {
25 
27  using JLANG::JPredicate;
29 
30 
31  /**
32  * Auxiliary data structure to unify weights of acoustics data
33  * according to the number of pings per emitter.
34  * The default option is to unify the weights.
35  */
36  struct JWeight :
37  public std::map<int, size_t>
38  {
39  /**
40  * Constructor.
41  *
42  * \param __begin begin of data
43  * \param __end end of data
44  */
45  template<class T>
46  JWeight(T __begin, T __end) :
47  min(std::numeric_limits<size_t>::max())
48  {
49  for (T i = __begin; i != __end; ++i) {
50  (*this)[i->getID()] += 1;
51  }
52 
53  for (const_iterator i = this->begin(); i != this->end(); ++i) {
54  if (i->second < min) {
55  min = i->second;
56  }
57  }
58  }
59 
60 
61  /**
62  * Get option to unify weights.
63  *
64  * \return option
65  */
66  static bool getUnify()
67  {
68  return get_unify();
69  }
70 
71 
72  /**
73  * Set option to unify weights.
74  *
75  * \param unify option
76  */
77  static void setUnify(const bool unify)
78  {
79  get_unify() = unify;
80  }
81 
82 
83  /**
84  * Get weight.
85  *
86  * \param id identifier
87  * \return weight
88  */
89  double operator()(const int id) const
90  {
91  if (getUnify()) {
92 
93  const_iterator p = this->find(id);
94 
95  if (p != this->end())
96  return (double) min / (double) p->second;
97  else
98  THROW(JValueOutOfRange, "Invalid identifier " << id);
99 
100  } else {
101 
102  return 1.0;
103  }
104  }
105 
106  private:
107  /**
108  * Get option to unify weights.
109  *
110  * \return option
111  */
112  static bool& get_unify()
113  {
114  static bool unify = true;
115 
116  return unify;
117  }
118 
119  size_t min;
120  };
121 
122 
123  /**
124  * Get position from element in data which corresponds to given predicate.
125  *
126  * \param __begin begin of data
127  * \param __end end of data
128  * \param predicate predicate
129  * \return position
130  */
131  template<class T, class JTypename_t, class JComparator_t>
132  inline JVector3D getPosition(T __begin,
133  T __end,
135  {
136  T p = std::find_if(__begin, __end, predicate);
137 
138  if (p != __end)
139  return p->getPosition();
140  else
141  THROW(JValueOutOfRange, "No element in container which corresponds to given predicate.");
142  }
143 
144 
145  /**
146  * Get position from element in data which corresponds to given predicate.
147  *
148  * \param __begin begin of data
149  * \param __end end of data
150  * \param predicate predicate
151  * \param position default position
152  * \return position
153  */
154  template<class T, class JTypename_t, class JComparator_t>
155  inline JVector3D getPosition(T __begin,
156  T __end,
158  const JVector3D& position)
159  {
160  try {
161  return getPosition(__begin, __end, predicate);
162  }
163  catch(const std::exception&) {
164  return position;
165  }
166  }
167 
168 
169  /**
170  * Get UNIX time of given DAQ object.
171  *
172  * \param chronometer chronometer
173  * \return UNIX time [s]
174  */
175  inline double getUNIXTime(const KM3NETDAQ::JDAQChronometer& chronometer)
176  {
177  return chronometer.getTimesliceStart().getTimeNanoSecond() * 1.0e-9;
178  }
179 }
180 
181 #endif
Exceptions.
double getUNIXTime(const KM3NETDAQ::JDAQChronometer &chronometer)
Get UNIX time of given DAQ object.
JDAQUTCExtended getTimesliceStart() const
Get start of timeslice.
double operator()(const int id) const
Get weight.
Template definition of auxiliary class to select objects.
Definition: JPredicate.hh:23
Auxiliary data structure to unify weights of acoustics data according to the number of pings per emit...
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:696
JWeight(T __begin, T __end)
Constructor.
Data structure for vector in three dimensions.
Definition: JVector3D.hh:34
static void setUnify(const bool unify)
Set option to unify weights.
do set_variable OUTPUT_DIRECTORY $WORKDIR T
JPosition3D getPosition(const Vec &pos)
Get position.
static bool & get_unify()
Get option to unify weights.
Exception for accessing a value in a collection that is outside of its range.
Definition: JException.hh:162
static bool getUnify()
Get option to unify weights.
double getTimeNanoSecond() const
Get time (limited to 16 ns cycles).