12 #ifndef AARTFAACREADER_ANTENNACONFIG_H_
13 #define AARTFAACREADER_ANTENNACONFIG_H_
28 #include <casacore/measures/Measures/MPosition.h>
33 void LTrim(std::string &s) {
34 s.erase(s.begin(), std::find_if(s.begin(), s.end(),
35 [](
int ch) { return !std::isspace(ch); }));
39 void RTrim(std::string &s) {
40 s.erase(std::find_if(s.rbegin(), s.rend(),
41 [](
int ch) { return !std::isspace(ch); })
47 void Trim(std::string &s) {
62 return GetPositions(
"LBA");
66 return GetPositions(
"HBA");
70 return GetAxes(
"LBA_ROTATION_MATRIX");
74 return GetAxes(
"HBA0_ROTATION_MATRIX");
78 return GetAxes(
"HBA1_ROTATION_MATRIX");
94 throw std::runtime_error(
"Wrong RCU mode");
111 throw std::runtime_error(
"Wrong RCU mode");
119 std::vector<double> data;
125 while (ReadArray(a.name, a.band, a.data)) {
130 key = a.band +
"_" + a.name;
131 values_.insert(std::make_pair(key, a));
134 const std::vector<double> &GetArray(
const std::string &name)
const {
135 return values_.find(name)->second.data;
137 std::vector<casacore::MPosition> GetPositions(
138 const std::string &arrayName)
const {
139 const std::vector<double> &arr = GetArray(arrayName);
140 std::vector<casacore::MPosition> position;
141 for (
size_t index = 0; index < arr.size(); index += 6) {
142 position.emplace_back(casacore::MPosition{
143 casacore::MVPosition{arr[index], arr[index + 1], arr[index + 2]},
144 casacore::MPosition::ITRF});
149 std::array<double, 9> GetAxes(
const std::string &arrayName)
const {
150 const std::vector<double> &arr = GetArray(arrayName);
152 throw std::runtime_error(
153 "The array for coordinate axes in the antenna "
154 "config file had an incorrect size");
156 std::array<double, 9> axes;
157 for (
size_t index = 0; index < 9; ++index) axes[index] = arr[index];
162 if (line_.empty() || line_position_ >= line_.size()) {
164 std::getline(file_, line_);
171 }
while (line_.empty() || line_[0] ==
'#');
174 size_t pos = line_.find_first_of(
" \t", line_position_);
175 if (pos == std::string::npos) {
176 token_ = line_.substr(line_position_);
181 token_ = line_.substr(line_position_, pos - line_position_);
182 line_position_ = pos + 1;
183 while (line_position_ < line_.size() &&
184 (line_[line_position_] ==
' ' || line_[line_position_] ==
'\t'))
194 std::vector<int> ReadDimensions() {
195 std::vector<int> dimensions = {std::atoi(token_.c_str())};
198 throw std::runtime_error(
199 "Antenna config file has bad format: expected dimensions");
202 throw std::runtime_error(
203 "Antenna config file has bad format: "
204 "expected another dimension after x");
205 int dimension_value = std::atoi(token_.c_str());
206 dimensions.push_back(dimension_value);
207 }
else if (token_ !=
"[") {
208 throw std::runtime_error(
"Antenna config file has bad format");
210 }
while (token_ !=
"[");
214 const std::vector<double> ReadData(
const std::vector<int> &dimensions) {
215 int count = std::accumulate(dimensions.begin(), dimensions.end(), 1,
216 [](
int a,
int b) { return a * b; });
217 std::vector<double> values(count);
218 for (
int i = 0; i != count; ++i) {
220 throw std::runtime_error(
"Missing numbers");
222 values[i] = std::atof(token_.c_str());
228 bool ReadArray(std::string &name, std::string &band,
229 std::vector<double> &values) {
231 if (!std::isalpha(token_[0]))
return false;
235 if (std::isalpha(token_[0])) {
242 std::vector<int> dimensions1 = ReadDimensions();
243 std::vector<double> data1 = ReadData(dimensions1);
244 if (Next() && token_[0] >=
'0' && token_[0] <=
'9') {
245 std::vector<int> dimensions2 = ReadDimensions();
246 std::vector<double> data2 = ReadData(dimensions2);
249 values = std::move(data2);
250 for (
size_t i = 0; i != values.size(); ++i)
251 values[i] += data1[i % data1.size()];
253 values = std::move(data1);
258 std::map<std::string, Array> values_;
262 size_t line_position_;
Definition: AntennaConfig.h:55
std::vector< casacore::MPosition > GetHBAPositions() const
Definition: AntennaConfig.h:65
std::vector< casacore::MPosition > GetLBAPositions() const
Definition: AntennaConfig.h:61
std::array< double, 9 > GetAxesFromMode(base::RcuMode mode)
Definition: AntennaConfig.h:81
std::array< double, 9 > GetHBA0Axes() const
Definition: AntennaConfig.h:73
std::array< double, 9 > GetHBA1Axes() const
Definition: AntennaConfig.h:77
AntennaConfig(const char *filename)
Definition: AntennaConfig.h:57
std::array< double, 9 > GetLBAAxes() const
Definition: AntennaConfig.h:69
std::vector< casacore::MPosition > GetArrayFromMode(base::RcuMode mode)
Definition: AntennaConfig.h:98
@ LBAInner30_90
Definition: RcuMode.h:31
@ LBAOuter10_90
Definition: RcuMode.h:28
@ LBAInner10_90
Definition: RcuMode.h:30
@ HBA110_190
Definition: RcuMode.h:32
@ HBA170_230
Definition: RcuMode.h:33
@ LBAOuter30_90
Definition: RcuMode.h:29
@ HBA210_270
Definition: RcuMode.h:34
enum dp3::base::RcuMode::Mode mode
Definition: AntennaConfig.h:53