JFModuleGainCalibration: remove dependence on pointers, which could be not updated in case of copy/assignment
This commit is contained in:
@@ -8,25 +8,15 @@
|
||||
|
||||
#include "../common/JFJochException.h"
|
||||
|
||||
void JFModuleGainCalibration::SetPointers() {
|
||||
gain_g0 = gain.data();
|
||||
gain_g1 = gain.data() + RAW_MODULE_SIZE;
|
||||
gain_g2 = gain.data() + 2 * RAW_MODULE_SIZE;
|
||||
}
|
||||
|
||||
JFModuleGainCalibration::JFModuleGainCalibration() : gain(RAW_MODULE_SIZE * 3) {
|
||||
SetPointers();
|
||||
|
||||
for (int i = 0; i < RAW_MODULE_SIZE; i++) {
|
||||
gain_g0[i] = DEFAULT_G0_FACTOR;
|
||||
gain_g1[i] = DEFAULT_G1_FACTOR;
|
||||
gain_g2[i] = DEFAULT_G2_FACTOR;
|
||||
gain[i + offset_g0] = DEFAULT_G0_FACTOR;
|
||||
gain[i + offset_g1] = DEFAULT_G1_FACTOR;
|
||||
gain[i + offset_g2] = DEFAULT_G2_FACTOR;
|
||||
}
|
||||
}
|
||||
|
||||
JFModuleGainCalibration::JFModuleGainCalibration(const std::string &filename) : gain(RAW_MODULE_SIZE * 3) {
|
||||
SetPointers();
|
||||
|
||||
std::ifstream file(filename.c_str(), std::fstream::binary);
|
||||
if (!file.is_open())
|
||||
throw JFJochException(JFJochExceptionCategory::GainFileOpenError, "Gain file cannot be opened");
|
||||
@@ -43,7 +33,6 @@ JFModuleGainCalibration::JFModuleGainCalibration(const std::vector<double> &vec)
|
||||
"Wrong size of input vector for gain calibration");
|
||||
}
|
||||
gain = vec;
|
||||
SetPointers();
|
||||
}
|
||||
|
||||
const std::vector<double> &JFModuleGainCalibration::GetGainCalibration() const {
|
||||
@@ -52,17 +41,17 @@ const std::vector<double> &JFModuleGainCalibration::GetGainCalibration() const {
|
||||
|
||||
void JFModuleGainCalibration::ExportG0(uint16_t *output) const {
|
||||
for (int i = 0; i < RAW_MODULE_SIZE; i++)
|
||||
output[i] = to_fixed(GAIN_G0_MULTIPLIER / gain_g0[i], 14);
|
||||
output[i] = to_fixed(GAIN_G0_MULTIPLIER / gain[offset_g0 + i], 14);
|
||||
}
|
||||
|
||||
void JFModuleGainCalibration::ExportG1(uint16_t *output) const {
|
||||
for (int i = 0; i < RAW_MODULE_SIZE; i++)
|
||||
output[i] = to_fixed(GAIN_G1_MULTIPLIER / gain_g1[i], 12);
|
||||
output[i] = to_fixed(GAIN_G1_MULTIPLIER / gain[offset_g1 + i], 12);
|
||||
}
|
||||
|
||||
void JFModuleGainCalibration::ExportG2(uint16_t *output) const {
|
||||
for (int i = 0; i < RAW_MODULE_SIZE; i++)
|
||||
output[i] = to_fixed(GAIN_G2_MULTIPLIER / gain_g2[i], 10);
|
||||
output[i] = to_fixed(GAIN_G2_MULTIPLIER / gain[offset_g2 + i], 10);
|
||||
}
|
||||
|
||||
double JFModuleGainCalibration::GetMean(const double *ptr) {
|
||||
@@ -73,13 +62,13 @@ double JFModuleGainCalibration::GetMean(const double *ptr) {
|
||||
}
|
||||
|
||||
double JFModuleGainCalibration::GetG0Mean() const {
|
||||
return GetMean(gain_g0);
|
||||
return GetMean(gain.data() + offset_g0);
|
||||
}
|
||||
|
||||
double JFModuleGainCalibration::GetG1Mean() const {
|
||||
return GetMean(gain_g1);
|
||||
return GetMean(gain.data() + offset_g1);
|
||||
}
|
||||
|
||||
double JFModuleGainCalibration::GetG2Mean() const {
|
||||
return GetMean(gain_g2);
|
||||
return GetMean(gain.data() + offset_g2);
|
||||
}
|
||||
|
||||
@@ -12,11 +12,10 @@
|
||||
#include "../common/Definitions.h"
|
||||
|
||||
class JFModuleGainCalibration {
|
||||
constexpr const static size_t offset_g0 = 0;
|
||||
constexpr const static size_t offset_g1 = RAW_MODULE_SIZE;
|
||||
constexpr const static size_t offset_g2 = 2 * RAW_MODULE_SIZE;
|
||||
std::vector<double> gain;
|
||||
double *gain_g0;
|
||||
double *gain_g1;
|
||||
double *gain_g2;
|
||||
void SetPointers();
|
||||
static double GetMean(const double *ptr) ;
|
||||
public:
|
||||
JFModuleGainCalibration();
|
||||
|
||||
Reference in New Issue
Block a user