1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
#ifndef BANDPASS_FILE_H
#define BANDPASS_FILE_H
#include <fstream>
#include <map>
#include <stdexcept>
#include <string>
#include "../../util/logger.h"
class BandpassFile {
public:
BandpassFile(const std::string& filename) {
std::ifstream file(filename);
if (!file)
throw std::runtime_error("Can not find bandpass file: '" + filename +
'\'');
std::string antenna, pol;
size_t channel;
double value;
while (file) {
file >> antenna >> pol >> channel >> value;
if (file.good()) {
char polChar = pol[0];
_values.emplace(BandpassIndex{antenna, polChar, channel}, value);
// Logger::Info << antenna << " , " << polChar << " , " << channel <<
// '\n';
}
}
Logger::Info << "Read " << _values.size() << " passband values from file "
<< filename << ".\n";
}
double GetValue(const std::string& antenna, char polarization,
size_t channel) const {
auto iter = _values.find(BandpassIndex{antenna, polarization, channel});
if (iter == _values.end()) {
throw std::runtime_error("Passband file is missing values for " +
antenna + " pol " + polarization + " ch " +
std::to_string(channel));
}
return iter->second;
}
private:
struct BandpassIndex {
std::string antenna;
char polarization;
size_t channel;
bool operator<(const BandpassIndex& rhs) const {
if (channel < rhs.channel)
return true;
else if (channel == rhs.channel) {
if (polarization < rhs.polarization)
return true;
else if (polarization == rhs.polarization && antenna < rhs.antenna)
return true;
}
return false;
}
};
/** antenna, polarization, */
std::map<BandpassIndex, double> _values;
};
#endif
|