Bayeux  3.4.1
Core Foundation library for SuperNEMO
sampled_signal.h
Go to the documentation of this file.
1 /* Author(s) : Francois Mauger <mauger@lpccaen.in2p3.fr>
3  * Creation date : 2016-10-02
4  * Last modified : 2016-10-02
5  *
6  * Copyright (C) 2016 Francois Mauger <mauger@lpccaen.in2p3.fr>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or (at
11  * your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  * Boston, MA 02110-1301, USA.
22  *
23  * Description:
24  *
25  * Time sampled signal (obtained from a ADC like sampler).
26  *
27  */
28 
29 #ifndef MCTOOLS_DIGITIZATION_SAMPLED_SIGNAL_H
30 #define MCTOOLS_DIGITIZATION_SAMPLED_SIGNAL_H
31 
32 // Standard library:
33 #include <limits>
34 #include <vector>
35 #include <bitset>
36 
37 // Third party:
38 // - Bayeux/datatools:
39 #include <datatools/properties.h>
40 #include <datatools/i_tree_dump.h>
41 // - Bayeux/geomtools:
42 #include <geomtools/base_hit.h>
43 
44 // This project:
45 // #include <mctools/digitization/i_adc.h>
46 
47 namespace mctools {
48 
49  namespace digitization {
50 
53  : public geomtools::base_hit
54  {
55  public:
56 
61  };
62 
63  // Special sample values:
64  static const int32_t INVALID_SAMPLE = std::numeric_limits<int32_t>::min();
65  static const int32_t UNDERFLOW_SAMPLE = std::numeric_limits<int32_t>::min() + 1;
66  static const int32_t OVERFLOW_SAMPLE = std::numeric_limits<int32_t>::max();
67 
69  static bool sample_is_normal(const int32_t);
70 
72  static bool sample_is_invalid(const int32_t);
73 
75  static bool sample_is_underflow(const int32_t);
76 
78  static bool sample_is_overflow(const int32_t);
79 
82  SS_INVALID = 0,
85  };
86 
89 
91  sampled_signal(const double sampling_frequency_, const std::size_t nsamples_, const int32_t value_ = INVALID_SAMPLE);
92 
94  virtual ~sampled_signal();
95 
97  virtual bool is_valid() const;
98 
100  bool has_sampling_frequency() const;
101 
103  void set_sampling_frequency(const double);
104 
106  double get_sampling_frequency() const;
107 
110 
112  void set_sampling_period(const double);
113 
115  double get_sampling_period() const;
116 
118  std::size_t get_number_of_sampling_time_intervals() const;
119 
121  double get_sampling_duration() const;
122 
124  double get_min_sampling_time() const;
125 
127  double get_max_sampling_time() const;
128 
130  void set_number_of_samples(const std::size_t nsamples_, const int32_t value_ = INVALID_SAMPLE);
131 
134 
136  std::size_t get_number_of_samples() const;
137 
139  bool is_sampling_initialized() const;
140 
142  bool has_invalid_samples() const;
143 
145  bool has_underflow_samples() const;
146 
148  bool has_overflow_samples() const;
149 
151  bool has_only_valid_samples() const;
152 
154  bool has_min_sample() const;
155 
157  int32_t get_min_sample() const;
158 
160  bool has_max_sample() const;
161 
163  int32_t get_max_sample() const;
164 
166  void reset();
167 
169  void set_samples(const std::vector<int32_t> &, const bool update_ = true);
170 
172  const std::vector<int32_t> & get_samples() const;
173 
175  void set_sample(const uint32_t index_, const int32_t sample_, const bool update_ = false);
176 
178  uint32_t get_sample(const uint32_t index_) const;
179 
181  bool is_normal(const uint32_t index_) const;
182 
184  bool is_invalid(const uint32_t index_) const;
185 
187  bool is_underflow(const uint32_t index_) const;
188 
190  bool is_overflow(const uint32_t index_) const;
191 
193  double get_time(const uint32_t index_) const;
194 
196  uint32_t get_index(const double time_) const;
197 
199  void unset_sample(const uint32_t index_, const bool update_ = false);
200 
202  void set_underflow_sample(const uint32_t index_, const bool update_ = false);
203 
205  void set_overflow_sample(const uint32_t index_, const bool update_ = false);
206 
208  virtual void tree_dump(std::ostream & out_ = std::clog,
209  const std::string & title_ = "",
210  const std::string & indent_ = "",
211  bool inherit_ = false) const;
212 
214  void update();
215 
226  };
227 
229  void slice_from_to(sampled_signal & target_,
230  const std::size_t first_,
231  const std::size_t last_,
232  const uint32_t flags_ = 0) const;
233 
239  };
240 
242  void print_ascii(std::ostream & out_, const uint32_t flags_ = 0) const;
243 
244  // //! Simple ASCII terminal plot
245  // void plot_ascii(std::ostream & out_, const uint32_t flags_ = 0) const;
246 
247  protected:
248 
250  void _set_defaults();
251 
254 
257 
258  private:
259 
260  double _sampling_frequency_;
261  std::vector<int32_t> _samples_;
262 
263  // Working data:
264  std::bitset<8> _sampling_status_;
265  int32_t _min_sample_ = INVALID_SAMPLE;
266  int32_t _max_sample_ = INVALID_SAMPLE;
267 
269 
270 
271  DR_CLASS_RTTI()
272 
273  };
274 
275  } // end of namespace digitization
276 
277 } // end of namespace mctools
278 
279 // Activate reflection layer :
280 DR_CLASS_INIT(::mctools::digitization::sampled_signal)
281 
282 #endif // MCTOOLS_DIGITIZATION_SAMPLED_SIGNAL_H
283 
284 // Local Variables: --
285 // mode: c++ --
286 // c-file-style: "gnu" --
287 // tab-width: 2 --
288 // End: --
#define DR_CLASS_INIT(Introspectable)
Inform Camp that class Introspectable exists and trigger the automatic registration of dedicated refl...
Definition: reflection_interface.h:149
Index of the invalid/uninitialized samples bit.
Definition: sampled_signal.h:82
double get_sampling_period() const
Return the sampling period.
int32_t get_max_sample() const
Return the maximum sample value.
bool has_min_sample() const
Check if the minimum sample value is set.
Definition: base_step_hit.h:32
void set_samples(const std::vector< int32_t > &, const bool update_=true)
Set the array of samples.
void _recompute_working_data()
Recompute working data.
bool has_invalid_samples() const
Check if the array of samples has at least one invalid sample.
std::size_t get_number_of_samples() const
Return the number of samples.
static const uint32_t bit01
Definition: bit_mask.h:28
void reset_number_of_samples()
Reset the number of samples.
static const uint32_t bit03
Definition: bit_mask.h:30
bool has_sampling_frequency() const
Check if sampling frequency is set.
void unset_sample(const uint32_t index_, const bool update_=false)
Force the sample value at given time index to be invalid.
void _set_defaults()
Set default attributes values.
bool has_only_valid_samples() const
Check if the array of samples has only valid samples.
static const int32_t UNDERFLOW_SAMPLE
Definition: sampled_signal.h:65
void _set_default_working_data()
Set default attributes values.
static const uint32_t bit04
Definition: bit_mask.h:31
static const int32_t INVALID_SAMPLE
Definition: sampled_signal.h:64
#define DATATOOLS_SERIALIZATION_DECLARATION()
Definition: i_serializable.h:266
static bool sample_is_invalid(const int32_t)
Check if a sample value is invalid.
void set_underflow_sample(const uint32_t index_, const bool update_=false)
Force the sample value at given time index to be underflow.
static const int32_t OVERFLOW_SAMPLE
Definition: sampled_signal.h:66
virtual bool is_valid() const
Check validity.
Index of the overflow samples bit.
Definition: sampled_signal.h:84
The base class for hit objects that locate events in a geometry model.
Definition: base_hit.h:38
A simple linear ADC (Analog/Digital Converter)
Definition: sampled_signal.h:52
double get_sampling_frequency() const
Return the sampling frequency.
void update()
Update internal data.
void set_sampling_frequency(const double)
Set the sampling frequency.
static const uint32_t bit02
Definition: bit_mask.h:29
bool is_overflow(const uint32_t index_) const
Check if a sample at given time index has an overflow value.
sampled_signal()
Default constructor.
int32_t get_min_sample() const
Return the minimum sample value.
void set_sampling_period(const double)
Set the sampling period.
static bool sample_is_underflow(const int32_t)
Check if a sample value is underflow.
bool has_overflow_samples() const
Check if the array of samples has at least one overflow sample.
virtual void tree_dump(std::ostream &out_=std::clog, const std::string &title_="", const std::string &indent_="", bool inherit_=false) const
Smart print.
double get_max_sampling_time() const
Return the maximum sampling time.
double get_min_sampling_time() const
Return the minimum sampling time.
void set_number_of_samples(const std::size_t nsamples_, const int32_t value_=INVALID_SAMPLE)
Set the number of samples.
bool has_max_sample() const
Check if the maximum sample value is set.
more_store_mask_type
Masks to automatically tag the attributes to be stored.
Definition: sampled_signal.h:58
const std::vector< int32_t > & get_samples() const
Return a const reference to the array of samples.
slicing_bits
Special flags for signal slicing.
Definition: sampled_signal.h:217
sampling_status_index
Indexes of sampling status bits.
Definition: sampled_signal.h:81
void slice_from_to(sampled_signal &target_, const std::size_t first_, const std::size_t last_, const uint32_t flags_=0) const
Extract slice of the signal.
bool has_underflow_samples() const
Check if the array of samples has at least one underflow sample.
static bool sample_is_normal(const int32_t)
Check if a sample value is normal (nor invalid, underflow or overflow)
virtual ~sampled_signal()
Destructor.
bool is_invalid(const uint32_t index_) const
Check if a sample at given time index has an invalid value.
bool is_sampling_initialized() const
Check if the array of samples is initialized.
static const uint32_t bit00
Definition: bit_mask.h:27
Index of the underflow samples bit.
Definition: sampled_signal.h:83
std::size_t get_number_of_sampling_time_intervals() const
Return the number of sampling time intervals.
uint32_t get_sample(const uint32_t index_) const
Return the sample value at given time index.
void print_ascii(std::ostream &out_, const uint32_t flags_=0) const
Simple ASCII terminal dump.
#define DR_CLASS_RTTI()
Declare Camp RTTI within class declaration.
Definition: reflection_interface.h:46
void reset_sampling_frequency()
Reset sampling frequency and associated period.
Serialization mask for the sampling frequency.
Definition: sampled_signal.h:59
bool is_normal(const uint32_t index_) const
Check if a sample at given time index has a normal value.
double get_sampling_duration() const
Return the sampling duration.
void set_sample(const uint32_t index_, const int32_t sample_, const bool update_=false)
Set the sample value at given time index.
Serialization mask for the samples.
Definition: sampled_signal.h:60
double get_time(const uint32_t index_) const
Return the time associated to a given sample.
print_ascii_bits
Special flags for ASCII dump.
Definition: sampled_signal.h:235
uint32_t get_index(const double time_) const
Return the sample index associated to a given time.
bool is_underflow(const uint32_t index_) const
Check if a sample at given time index has an underflow value.
void set_overflow_sample(const uint32_t index_, const bool update_=false)
Force the sample value at given time index to be overflow.
static bool sample_is_overflow(const int32_t)
Check if a sample value is overflow.