Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
RfiDetectionPipeline.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/pipeline/RfiDetectionPipeline.h"
25 #include "cheetah/pipeline/CheetahConfig.h"
26 #include <panda/TypeTraits.h>
27 
28 
29 namespace ska {
30 namespace cheetah {
31 namespace pipeline {
32 
33 
34 template<typename NumericalT, typename RfimOutputHandler, typename RfiPolicy>
35 template<typename... HandlerArgs>
36 RfiDetectionPipeline<NumericalT, RfimOutputHandler, RfiPolicy>::RfiDetectionPipeline(CheetahConfig<NumericalT> const& config, BeamConfig<NumericalT> const& beam_config, HandlerArgs&&... handler_args)
37  : BaseT(config, beam_config)
38  , _channel_mask(config.channel_mask_config())
39  , _rfim_handler(*this, std::forward<HandlerArgs>(handler_args)...)
40  , _bandpass_handler(*this)
41  , _rfim(config.rfim_config(), _rfim_handler, _bandpass_handler)
42  , _data_sequence(300)
43  , _last_data_sequence_index(_data_sequence.size(), 0)
44  , _next_data_sequence_index(_data_sequence.size(), 0)
45 {
46 }
47 
48 template<typename NumericalT, typename RfimOutputHandler, typename RfiPolicy>
49 RfiDetectionPipeline<NumericalT, RfimOutputHandler, RfiPolicy>::~RfiDetectionPipeline()
50 {
51  while(_last_data_sequence_index != _next_data_sequence_index) {
52  std::this_thread::yield();
53  }
54 }
55 
56 template<typename NumericalT, typename RfimOutputHandler, typename RfiPolicy>
58 {
59  return _rfim_handler._output;
60 }
61 
62 template<typename NumericalT, typename RfimOutputHandler, typename RfiPolicy>
64 {
65  // assumes we will only be called from a single thread
66  _data_sequence[_last_data_sequence_index] = &data;
67  ++_last_data_sequence_index;
68  bool hold=false;
69  // check we are not overruning the sequence buffer.
70  // Check needs to happen before we launch job to avoid race cdn
71  if(_last_data_sequence_index == _next_data_sequence_index) {
72  hold = true;
73  }
74  try {
75  _rfim.run(data);
76  }
77  catch(...)
78  {
79  --_last_data_sequence_index;
80  throw;
81  }
82 
83  if(hold) {
84  // slow things down until buffer has caught up
85  if(_last_data_sequence_index == _next_data_sequence_index) {
86  PANDA_LOG_WARN << "sequencing queue full. Slowing pipeline until space recovered";
87  }
88  while(_last_data_sequence_index == _next_data_sequence_index) {
89  std::this_thread::yield();
90  }
91  }
92 }
93 
94 template<typename NumericalT, typename RfimOutputHandler, typename RfiPolicy>
95 template<typename... HandlerArgs>
97  : _pipeline(pipeline)
98  , _output(std::forward<HandlerArgs>(args)...)
99 {
100 }
101 
102 template<typename NumericalT, typename RfimOutputHandler, typename RfiPolicy>
104 {
105  TimeFrequencyType& tf_data = static_cast<TimeFrequencyType&>(panda::is_pointer_wrapper<typename std::remove_reference<ReturnType>::type>::extract(data));
106 
107  // resync data stream
108  while(_pipeline._data_sequence[_pipeline._next_data_sequence_index] != &tf_data) {
109  std::this_thread::yield();
110  }
111 
112  try {
113  // process the rfim data
114  _pipeline._channel_mask(tf_data);
115  _pipeline.out().send(panda::ChannelId("rfim"), tf_data);
116  _output(data);
117  }
118  catch(...)
119  {
120  ++_pipeline._next_data_sequence_index;
121  throw;
122  }
123 
124  // now safe to let other threads push their data
125  ++_pipeline._next_data_sequence_index;
126 
127 }
128 
129 template<typename NumericalT, typename RfimOutputHandler, typename RfiPolicy>
131  : _pipeline(pipeline)
132 {
133 }
134 
135 template<typename NumericalT, typename RfimOutputHandler, typename RfiPolicy>
136 void RfiDetectionPipeline<NumericalT, RfimOutputHandler, RfiPolicy>::BandPassOutputHandler::operator()(typename BandPassOutputHandler::BandPassType const& data)
137 {
138  static const panda::ChannelId bandpass_id("bandpass");
139  _pipeline.out().send(bandpass_id, data);
140 }
141 
142 } // namespace pipeline
143 } // namespace cheetah
144 } // namespace ska
Some limits and constants for FLDO.
Definition: Brdz.h:35
Pipeline that performs only RFI detection.