Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
BinMap.h
1 /*
2  * The MIT License (MIT)
3  *
4  * Copyright (c) 2016 The SKA organisation
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 #ifndef SKA_CHEETAH_UTILS_BINMAP_H
25 #define SKA_CHEETAH_UTILS_BINMAP_H
26 
27 
28 namespace ska {
29 namespace cheetah {
30 namespace utils {
31 
47 template<typename DataType>
48 class BinMap
49 {
50  public:
51  BinMap();
52  BinMap(unsigned int number_of_bins);
58  BinMap(unsigned int number_of_bins, DataType start, DataType const& end);
59  ~BinMap();
60 
62  void reset(unsigned int number_of_bins);
63 
65  void set_lower_bound(DataType);
66 
68  void set_bounds(DataType lower, DataType upper);
69 
70  // @brief assumes start is set
71  // @details sets bin_width automatically according to start and number of bins
72  void set_upper_bound(DataType const&);
73 
75  // @details end frequency will also change
76  void set_bin_width(DataType);
77 
78  inline DataType upper_bound() const;
79  inline DataType lower_bound() const;
80 
86  unsigned int bin_index(DataType const&) const;
87 
91  DataType bin_width() const;
92 
96  unsigned int number_of_bins() const;
97 
98  // the value represented by the left hand edge of the bin
99  DataType bin_start(unsigned int index) const;
100 
101  // the value represented by the right hand edge of the bin
102  DataType bin_end(unsigned int index) const;
103 
104  // return the value associated with the bin with the specified index
105  inline DataType bin_assignment_number(int index) const;
106 
107  // return the index of the last bin
108  inline unsigned last_bin_index() const;
109 
110  // return the assignment number of the last bin
111  DataType last_bin_assignment_value() const;
112  DataType first_bin_assignment_value() const;
113 
114  bool equal(const BinMap<DataType>& map_1) const;
115 
116  private:
117  unsigned int _n_bins;
118  DataType _lower;
119  DataType _width;
120  DataType _halfwidth;
121 
122 };
123 
124 template<typename DataType>
125 bool operator==(const BinMap<DataType>& map_1, const BinMap<DataType>& map_2);
126 
127 } // namespace utils
128 } // namespace cheetah
129 } // namespace ska
130 #include "cheetah/utils/detail/BinMap.cpp"
131 
132 #endif // SKA_CHEETAH_UTILS_BINMAP_H
unsigned int bin_index(DataType const &) const
give the bin Index of the value. n.b no range checks are made so passing endValue() will return an i...
Definition: BinMap.cpp:161
Explicitly map a range on to a set of constant width indexed data bins.
Definition: BinMap.h:48
Some limits and constants for FLDO.
Definition: Brdz.h:35
void reset(unsigned int number_of_bins)
reset the number of bins
Definition: BinMap.cpp:99
void set_bin_width(DataType)
set the width of each bin
Definition: BinMap.cpp:105
void set_lower_bound(DataType)
set the assignemnt value for the first bin (n.b. not the same as the lower limit of the first bin) ...
Definition: BinMap.cpp:119
unsigned int number_of_bins() const
the total number of bins
Definition: BinMap.cpp:191
DataType bin_width() const
the width of a the bin (all are the same width)
Definition: BinMap.cpp:185
void set_bounds(DataType lower, DataType upper)
set the the lower bound for first bin
Definition: BinMap.cpp:112