Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
Rfim.cpp
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 #include "cheetah/rfim/Rfim.h"
25 #include "cheetah/rfim/ampp/Rfim.h"
26 #include "cheetah/rfim/cuda/Rfim.h"
27 #include "cheetah/rfim/sum_threshold/Rfim.h"
28 #include "cheetah/rfim/iqrmcpu/Rfim.h"
29 #include "panda/Error.h"
30 #include "panda/Log.h"
31 
32 namespace ska {
33 namespace cheetah {
34 namespace rfim {
35 
36 namespace {
37  template<typename Policy>
38  class Null
39  {
40  typedef typename PolicyInfo<Policy>::DataArgumentType ArgumentType;
41  typedef typename PolicyInfo<Policy>::ReturnType ReturnType;
42 
43  public:
44  typedef cheetah::Cpu Architecture;
45 
46  template<typename ResourceType>
47  ReturnType operator()(ResourceType& , std::shared_ptr<typename std::remove_reference<ArgumentType>::type> const& data)
48  {
49  return _policy.null_op(*data);
50  }
51 
52 
53  private:
54  policy::Policy<Policy> _policy;
55  };
56 
57 template<typename Algo>
58 struct RfimCreateHelper {
59  template<typename ConfigT, typename BandpassHandler>
60  static inline
61  Algo create(ConfigT const& config, BandpassHandler&&)
62  {
63  return Algo(config.template config<typename Algo::Config>());
64  }
65 };
66 
67 template<typename TraitsT>
68 struct RfimCreateHelper<cuda::Rfim<TraitsT>>
69 {
70  template<typename ConfigT, typename BandpassHandler>
71  static inline
72  cuda::Rfim<TraitsT> create(ConfigT const& config, BandpassHandler&&)
73  {
74  PANDA_LOG << "rfim::cuda algorithm activated";
75  return cuda::Rfim<TraitsT>(config.cuda_algo_config());
76  }
77 };
78 
79 template<typename TraitsT>
80 struct RfimCreateHelper<iqrmcpu::Rfim<TraitsT>>
81 {
82  template<typename ConfigT, typename BandpassHandler>
83  static inline
84  iqrmcpu::Rfim<TraitsT> create(ConfigT const& config, BandpassHandler&&)
85  {
86  PANDA_LOG << "rfim::iqrmcpu algorithm activated";
87  return iqrmcpu::Rfim<TraitsT>(config.iqrmcpu_algo_config());
88  }
89 };
90 
91 template<typename TraitsT>
92 struct RfimCreateHelper<sum_threshold::Rfim<TraitsT>>
93 {
94  template<typename ConfigT, typename BandpassHandler>
95  static inline
96  sum_threshold::Rfim<TraitsT> create(ConfigT const& config, BandpassHandler&&)
97  {
98  PANDA_LOG << "rfim::sum_threshold algorithm activated";
99  return sum_threshold::Rfim<TraitsT>(config.sum_threshold_algo_config());
100  }
101 };
102 
103 template<typename TraitsT>
104 struct RfimCreateHelper<ampp::Rfim<TraitsT>>
105 {
106  template<typename ConfigT, typename BandpassHandler>
107  static inline
108  ampp::Rfim<TraitsT> create(ConfigT const& config, BandpassHandler&& handler)
109  {
110  PANDA_LOG << "rfim::ampp algorithm activated";
111  return ampp::Rfim<TraitsT>(config.ampp_algo_config(), std::forward<BandpassHandler>(handler));
112  }
113 };
114 
115 template<typename ConfigType, typename RfimTraits>
116 struct RfimFactory
117 {
118  public:
119  RfimFactory(ConfigType const& config, typename RfimTraits::BandPassHandler& bp_handler)
120  : _config(config)
121  , _bp_handler(bp_handler)
122  {}
123 
124  template<typename Algo>
125  Algo create()
126  {
127  return RfimCreateHelper<Algo>::create(_config, _bp_handler);
128  }
129 
130  template<typename Algo>
131  bool active() const {
132  return _config.template config<typename Algo::Config>().active();
133  }
134 
135  private:
136  ConfigType const& _config;
137  typename RfimTraits::BandPassHandler& _bp_handler;
138 };
139 
140 } // namespace
141 
142 
143 
144 template<typename TimeFrequencyType, typename RfimTraits, typename ConfigType>
145 Rfim<TimeFrequencyType, RfimTraits, ConfigType>::Rfim(ConfigType const& c
146  , typename RfimTraits::RfimHandler& handler
147  , typename RfimTraits::BandPassHandler& bp_handler
148  )
149  : _task(c.pool(), handler)
150 {
151  // select algos according to specified configuration options
152  RfimFactory<ConfigType, RfimTraits> factory(c, bp_handler);
153  if(!_task.configure(factory
154  , Select<rfim::sum_threshold::Rfim<RfimTraits>>(c.sum_threshold_algo_config().active())
155  , Select<rfim::cuda::Rfim<RfimTraits>>(c.cuda_algo_config().active())
156  , Select<rfim::ampp::Rfim<RfimTraits>>(c.ampp_algo_config().active())
157  , Select<rfim::iqrmcpu::Rfim<RfimTraits>>(c.iqrmcpu_algo_config().active())
158  ))
159  {
160  _task.template set_algorithms<Null<PolicyType>>(std::move(Null<PolicyType>()));
161  PANDA_LOG_WARN << "WARNING: no RFI mitigation algorithm has been specified";
162  }
163 }
164 
165 template<typename TimeFrequencyType, typename RfimTraits, typename ConfigType>
166 Rfim<TimeFrequencyType, RfimTraits, ConfigType>::~Rfim()
167 {
168 }
169 
170 template<typename TimeFrequencyType, typename RfimTraits, typename ConfigType>
172 {
173  auto ptr = data.shared_from_this();
174  _task.submit(ptr);
175 }
176 
177 } // namespace rfim
178 } // namespace cheetah
179 } // namespace ska
std::conditional< std::is_same< void, AdapterDataReturnType >::value, DataArgumentType, AdapterDataReturnType >::type ReturnType
the data type the policy will return
Definition: PolicyInfo.h:67
Some limits and constants for FLDO.
Definition: Brdz.h:35
ReturnType run(data::TimeFrequency< Cpu, NumericalRep > &data)
perform rfi clipping on the data
Definition: Rfim.cpp:504
std::conditional< std::is_member_function_pointer< AdapterFuncType >::value, typename boost::mpl::at_c< boost::function_types::parameter_types< AdapterFuncType >, 1 >::type, typename boost::mpl::at_c< boost::function_types::parameter_types< AdapterFuncType >, 0 >::type >::type DataArgumentType
The argument type that is to be expected to represent the TimeFrequencyData.
Definition: PolicyInfo.h:62