Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
Config.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/fldo/cuda/Config.h"
25 #include "cheetah/fldo/cuda/CommonDefs.h"
26 
27 namespace ska {
28 namespace cheetah {
29 namespace fldo {
30 namespace cuda {
31 
32 //set the default values for:
33 // - the number of sub-integrations to sum up on input data
34 // - the number of sub-bands to sum up on input data
35 static const int default_phases = fldo::o_phases;
36 static const unsigned default_nsubints = fldo::o_subints;
37 static const unsigned default_nsubbands = fldo::o_bands;
38 //static uint64_t default_nsamples = 83886080; // 2^23
39 
40 Config::Config()
41  : BaseT("origami_cuda", "use the origami cuda based algorithm")
42  , _enable_split(true)
43  , _nsubints(default_nsubints)
44  , _nsubbands(default_nsubbands)
45  , _phases(default_phases)
46 {
47 }
48 
49 bool const &Config::enable_split() const
50 {
51  return _enable_split;
52 }
53 
54 size_t const& Config::phases() const
55 {
56  return _phases;
57 }
58 
59 size_t const& Config::nsubints() const
60 {
61  return _nsubints;
62 }
63 
64 size_t const& Config::nsubbands() const
65 {
66  return _nsubbands;
67 }
68 
69 void Config::phases(size_t n)
70 {
71  _phases = n;
72 }
73 
74 void Config::nsubbands(size_t n)
75 {
76  _nsubbands = n;
77 }
78 
79 void Config::nsubints(size_t n)
80 {
81  _nsubints = n;
82 }
83 
84 void Config::add_options(OptionsDescriptionEasyInit& add_options)
85 {
86  // the add_options method of the class options_description returns a
87  // special proxy object that defines the operator(). Calls to that
88  // operator actually declare options.
89  BaseT::add_options(add_options);
90  add_options("help", " FLDO receives a stream of filterbank data organized as a succession of measures, each comprising a number of frequency channels. \n\
91  The folding algorithm consists in a synchronous summation of input data in order to improve the Signal/Noise. Input data is processed in sub-integrations blocks and in frequency group (sub-bands) and summed up coherently, following the pulsar period of the current candidate in an array of maximum length of phases phases. \n\
92  doc/FldoParam.md describes the FLDO process and parameters meaning")
93  ("enable_split", boost::program_options::value<bool>(&_enable_split)->default_value(_enable_split), "enable folding phase shift")
94 
95  // The parameters of operator are: option name, information about value and option desciprtion
96  // The option can specify the address of the varuable where to store the
97  // option value and also the default value used if no value is specified
98  // by user.
99  ("phases", boost::program_options::value<size_t>(&_phases)->default_value(default_phases),
100  "specify the max number of phases used in folding")
101  ("nsubints",boost::program_options::value<size_t>(&_nsubints)->default_value(default_nsubints),
102  "specify the number of sub-integrations the whole scan is divided.")
103  ("nsubbands",boost::program_options::value<size_t>(&_nsubbands)->default_value(default_nsubbands),
104  "specify the number of frequency sub-bands");
105 
106  // check of Config variables
107  if (0 > fldo_input_check((*this))) {
108  throw panda::Error("Wrong Param Config in FLDO");
109  }
110 
111 }
112 
121 int Config::fldo_input_check(const fldo::cuda::Config& config)
122 {
123  // We access config variables directly.
124  PANDA_LOG_DEBUG << " fldo_input_check: input config parameters check " ;
125 
126  // nsubints check
127  size_t nsubints = config.nsubints();
128  if ((fldo::max_subints < nsubints) || (fldo::min_subints > nsubints)) {
129  static constexpr const char* err_msg = "fldo_input_check: invalid nsubints ";
130  PANDA_LOG_ERROR << err_msg << " (" << nsubints << ")" ;
131  return -3;
132  } else {
133  PANDA_LOG_DEBUG << "fldo_input_check: nsubints (" << nsubints << ")" ;
134  }
135 
136  // nsubbands check
137  size_t nsubbands = config.nsubbands();
138  if ((fldo::max_bands < nsubbands) || (fldo::min_bands > nsubbands)) {
139  static constexpr const char* err_msg = "fldo_input_check: invalid nsubbands ";
140  PANDA_LOG_ERROR << err_msg << " (" << nsubbands << ")" ;
141  //throw panda::Error(err_msg);
142  return -4;
143  } else {
144  PANDA_LOG_DEBUG << "fldo_input_check: nsubbands (" << nsubbands << ")" ;
145  }
146 
147  // phases check
148  // We duplicate inside _nbins
149  size_t phases = config.phases();
150  //_nbins = phases; // nbins is an alias for phases
151  if ((fldo::max_phases < phases) || (fldo::min_phases > phases)) {
152  static constexpr const char* err_msg = "fldo_input_check: invalid phases ";
153  PANDA_LOG_ERROR << err_msg << " (" << phases << ")" ;
154  //throw panda::Error(err_msg);
155  return -5;
156  } else {
157  PANDA_LOG_DEBUG << "fldo_input_check: phases (" << phases << ")" ;
158  }
159 
160  return 0;
161 
162 }
163 
164 } // namespace cuda
165 } // namespace fldo
166 } // namespace cheetah
167 } // namespace ska
size_t const & nsubints() const
return the number of sub-integrations used in the sum-up data
Definition: Config.cpp:59
size_t const & nsubbands() const
return the number of frequency sub-bands summed up
Definition: Config.cpp:64
size_t const & phases() const
return the number of phase bins
Definition: Config.cpp:54
Some limits and constants for FLDO.
Definition: Brdz.h:35