mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-21 03:10:02 +02:00
removed pointers added constructor
This commit is contained in:
parent
b46e107f35
commit
ee20cfab1e
@ -1321,7 +1321,7 @@ class slsDetector : public virtual slsDetectorDefs{
|
||||
* @returns ok or fail
|
||||
* \sa ::sls_detector_module
|
||||
*/
|
||||
int setModule(sls_detector_module module, int tb = 1);
|
||||
int setModule(sls_detector_module& module, int tb = 1);
|
||||
|
||||
/**
|
||||
* Get module structure from detector (all detectors)
|
||||
@ -1805,7 +1805,7 @@ class slsDetector : public virtual slsDetectorDefs{
|
||||
* @param tb 1 to include trimbits, 0 to exclude (used for eiger)
|
||||
* @returns the pointer to the module structure with interpolated values or NULL if error
|
||||
*/
|
||||
sls_detector_module *interpolateTrim(
|
||||
sls_detector_module interpolateTrim(
|
||||
sls_detector_module *a, sls_detector_module *b, const int energy,
|
||||
const int e1, const int e2, int tb = 1);
|
||||
|
||||
|
@ -1280,10 +1280,7 @@ int slsDetector::setThresholdEnergyAndSettings(int e_eV,
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// fill detector module structure
|
||||
sls_detector_module *myMod = nullptr;
|
||||
|
||||
sls_detector_module myMod{detector_shm()->myDetectorType};
|
||||
// normal
|
||||
if (interpolate == false) {
|
||||
// find their directory names
|
||||
@ -1294,13 +1291,7 @@ int slsDetector::setThresholdEnergyAndSettings(int e_eV,
|
||||
std::string settingsfname = ostfn.str();
|
||||
FILE_LOG(logDEBUG1) << "Settings File is " << settingsfname;
|
||||
|
||||
// read the files
|
||||
// myMod = createModule(); // readSettings also checks if create module
|
||||
// is null
|
||||
if (readSettingsFile(settingsfname, myMod, tb) == nullptr) {
|
||||
if (myMod != nullptr) {
|
||||
deleteModule(myMod);
|
||||
}
|
||||
if (readSettingsFile(settingsfname, &myMod, tb) == nullptr) {
|
||||
return FAIL;
|
||||
}
|
||||
}else{
|
||||
@ -1330,51 +1321,33 @@ int slsDetector::setThresholdEnergyAndSettings(int e_eV,
|
||||
// read the files
|
||||
FILE_LOG(logDEBUG1) << "Settings Files are " << settingsfname1
|
||||
<< " and " << settingsfname2;
|
||||
sls_detector_module *myMod1 = createModule();
|
||||
sls_detector_module *myMod2 = createModule();
|
||||
if (nullptr == readSettingsFile(settingsfname1, myMod1, tb)) {
|
||||
|
||||
deleteModule(myMod1);
|
||||
deleteModule(myMod2);
|
||||
sls_detector_module myMod1{detector_shm()->myDetectorType};
|
||||
sls_detector_module myMod2{detector_shm()->myDetectorType};
|
||||
if (readSettingsFile(settingsfname1, &myMod1, tb) == nullptr) {
|
||||
throw RuntimeError(
|
||||
"setThresholdEnergyAndSettings: Could not open settings file");
|
||||
}
|
||||
if (nullptr == readSettingsFile(settingsfname2, myMod2, tb)) {
|
||||
deleteModule(myMod1);
|
||||
deleteModule(myMod2);
|
||||
if (readSettingsFile(settingsfname2, &myMod2, tb) == nullptr) {
|
||||
throw RuntimeError(
|
||||
"setThresholdEnergyAndSettings: Could not open settings file");
|
||||
}
|
||||
if (myMod1->iodelay != myMod2->iodelay) {
|
||||
deleteModule(myMod1);
|
||||
deleteModule(myMod2);
|
||||
if (myMod1.iodelay != myMod2.iodelay) {
|
||||
throw RuntimeError("setThresholdEnergyAndSettings: Iodelays do not "
|
||||
"match between files");
|
||||
}
|
||||
|
||||
// interpolate module
|
||||
myMod = interpolateTrim(myMod1, myMod2, e_eV, trim1, trim2, tb);
|
||||
if (myMod == nullptr) {
|
||||
deleteModule(myMod1);
|
||||
deleteModule(myMod2);
|
||||
throw RuntimeError("setThresholdEnergyAndSettings: Could not "
|
||||
"interpolate, different "
|
||||
"dac values in files");
|
||||
}
|
||||
// interpolate tau
|
||||
myMod->iodelay = myMod1->iodelay;
|
||||
myMod->tau =
|
||||
linearInterpolation(e_eV, trim1, trim2, myMod1->tau, myMod2->tau);
|
||||
// printf("new tau:%d\n",tau);
|
||||
myMod = interpolateTrim(&myMod1, &myMod2, e_eV, trim1, trim2, tb);
|
||||
|
||||
deleteModule(myMod1);
|
||||
deleteModule(myMod2);
|
||||
// // interpolate tau
|
||||
myMod.iodelay = myMod1.iodelay;
|
||||
myMod.tau =
|
||||
linearInterpolation(e_eV, trim1, trim2, myMod1.tau, myMod2.tau);
|
||||
}
|
||||
|
||||
myMod->reg = detector_shm()->currentSettings;
|
||||
myMod->eV = e_eV;
|
||||
setModule(*myMod, tb);
|
||||
deleteModule(myMod);
|
||||
myMod.reg = detector_shm()->currentSettings;
|
||||
myMod.eV = e_eV;
|
||||
setModule(myMod, tb);
|
||||
if (getSettings() != is) {
|
||||
throw RuntimeError("setThresholdEnergyAndSettings: Could not set "
|
||||
"settings in detector");
|
||||
@ -3670,7 +3643,7 @@ int slsDetector::getChanRegs(double *retval) {
|
||||
return n;
|
||||
}
|
||||
|
||||
int slsDetector::setModule(sls_detector_module module, int tb) {
|
||||
int slsDetector::setModule(sls_detector_module& module, int tb) {
|
||||
int fnum = F_SET_MODULE;
|
||||
int ret = FAIL;
|
||||
int retval = -1;
|
||||
@ -4810,7 +4783,7 @@ int slsDetector::setDigitalIODelay(uint64_t pinMask, int delay) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
sls_detector_module *
|
||||
sls_detector_module
|
||||
slsDetector::interpolateTrim(sls_detector_module *a, sls_detector_module *b,
|
||||
const int energy, const int e1, const int e2,
|
||||
int tb) {
|
||||
@ -4821,10 +4794,7 @@ slsDetector::interpolateTrim(sls_detector_module *a, sls_detector_module *b,
|
||||
"Interpolation of Trim values not implemented for this detector!");
|
||||
}
|
||||
|
||||
sls_detector_module *myMod = createModule(detector_shm()->myDetectorType);
|
||||
if (myMod == nullptr) {
|
||||
throw RuntimeError("Could not create module");
|
||||
}
|
||||
sls_detector_module myMod{detector_shm()->myDetectorType};
|
||||
enum eiger_DacIndex {
|
||||
SVP,
|
||||
VTR,
|
||||
@ -4849,10 +4819,9 @@ slsDetector::interpolateTrim(sls_detector_module *a, sls_detector_module *b,
|
||||
int num_dacs_to_copy = sizeof(dacs_to_copy) / sizeof(dacs_to_copy[0]);
|
||||
for (int i = 0; i < num_dacs_to_copy; ++i) {
|
||||
if (a->dacs[dacs_to_copy[i]] != b->dacs[dacs_to_copy[i]]) {
|
||||
deleteModule(myMod);
|
||||
return nullptr;
|
||||
throw RuntimeError("Interpolate module: dacs different");
|
||||
}
|
||||
myMod->dacs[dacs_to_copy[i]] = a->dacs[dacs_to_copy[i]];
|
||||
myMod.dacs[dacs_to_copy[i]] = a->dacs[dacs_to_copy[i]];
|
||||
}
|
||||
|
||||
// Copy irrelevant dacs (without failing): CAL
|
||||
@ -4864,7 +4833,7 @@ slsDetector::interpolateTrim(sls_detector_module *a, sls_detector_module *b,
|
||||
"Taking first: "
|
||||
<< a->dacs[CAL];
|
||||
}
|
||||
myMod->dacs[CAL] = a->dacs[CAL];
|
||||
myMod.dacs[CAL] = a->dacs[CAL];
|
||||
|
||||
// Interpolate vrf, vcmp, vcp
|
||||
int dacs_to_interpolate[] = {VRF, VCMP_LL, VCMP_LR, VCMP_RL,
|
||||
@ -4872,15 +4841,15 @@ slsDetector::interpolateTrim(sls_detector_module *a, sls_detector_module *b,
|
||||
int num_dacs_to_interpolate =
|
||||
sizeof(dacs_to_interpolate) / sizeof(dacs_to_interpolate[0]);
|
||||
for (int i = 0; i < num_dacs_to_interpolate; ++i) {
|
||||
myMod->dacs[dacs_to_interpolate[i]] =
|
||||
myMod.dacs[dacs_to_interpolate[i]] =
|
||||
linearInterpolation(energy, e1, e2, a->dacs[dacs_to_interpolate[i]],
|
||||
b->dacs[dacs_to_interpolate[i]]);
|
||||
}
|
||||
|
||||
// Interpolate all trimbits
|
||||
if (tb != 0) {
|
||||
for (int i = 0; i < myMod->nchan; ++i) {
|
||||
myMod->chanregs[i] = linearInterpolation(
|
||||
for (int i = 0; i < myMod.nchan; ++i) {
|
||||
myMod.chanregs[i] = linearInterpolation(
|
||||
energy, e1, e2, a->chanregs[i], b->chanregs[i]);
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include <stdint.h>
|
||||
#ifdef __cplusplus
|
||||
#include "sls_detector_exceptions.h"
|
||||
#include <algorithm>
|
||||
#include <bitset>
|
||||
#include <string>
|
||||
#endif
|
||||
@ -1043,18 +1044,43 @@ typedef struct {
|
||||
sls_detector_module()
|
||||
: serialnumber(0), nchan(0), nchip(0), ndac(0), reg(0), iodelay(0),
|
||||
tau(0), eV(0), dacs(nullptr), chanregs(nullptr) {}
|
||||
|
||||
sls_detector_module(slsDetectorDefs::detectorType type) {
|
||||
detParameters parameters{type};
|
||||
int nch = parameters.nChanX * parameters.nChanY;
|
||||
int nc = parameters.nChipX * parameters.nChipY;
|
||||
int nd = parameters.nDacs;
|
||||
// int nd = parameters.nDacs;
|
||||
|
||||
ndac = nd;
|
||||
ndac = parameters.nDacs;
|
||||
nchip = nc;
|
||||
nchan = nch * nc;
|
||||
dacs = new int[nd];
|
||||
chanregs = new int[nch * nc];
|
||||
dacs = new int[ndac];
|
||||
chanregs = new int[nchan];
|
||||
}
|
||||
|
||||
sls_detector_module(const sls_detector_module &other)
|
||||
: dacs(nullptr), chanregs(nullptr) {
|
||||
*this = other;
|
||||
}
|
||||
|
||||
sls_detector_module &operator=(const sls_detector_module &other) {
|
||||
delete[] dacs;
|
||||
delete[] chanregs;
|
||||
serialnumber = other.serialnumber;
|
||||
nchan = other.nchan;
|
||||
nchip = other.nchip;
|
||||
ndac = other.ndac;
|
||||
reg = other.reg;
|
||||
iodelay = other.iodelay;
|
||||
tau = other.tau;
|
||||
eV = other.eV;
|
||||
dacs = new int[ndac];
|
||||
std::copy(other.dacs, other.dacs + ndac, dacs);
|
||||
chanregs = new int[nchan];
|
||||
std::copy(other.chanregs, other.chanregs + nchan, chanregs);
|
||||
return *this;
|
||||
}
|
||||
|
||||
~sls_detector_module() {
|
||||
delete[] dacs;
|
||||
delete[] chanregs;
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "catch.hpp"
|
||||
#include "sls_detector_defs.h"
|
||||
#include "slsDetector.h"
|
||||
#include "sls_detector_defs.h"
|
||||
|
||||
using dt = slsDetectorDefs::detectorType;
|
||||
|
||||
@ -18,7 +18,7 @@ TEST_CASE("sls_detector_module default construction", "[support][new]") {
|
||||
CHECK(m.chanregs == nullptr);
|
||||
}
|
||||
|
||||
TEST_CASE("sls_detector_module from type", "[support][new]") {
|
||||
TEST_CASE("sls_detector_module from type", "[support]") {
|
||||
sls_detector_module m(dt::EIGER);
|
||||
CHECK(m.serialnumber == 0);
|
||||
CHECK(m.nchan == 256 * 256 * 4);
|
||||
@ -31,3 +31,23 @@ TEST_CASE("sls_detector_module from type", "[support][new]") {
|
||||
CHECK(m.dacs != nullptr);
|
||||
CHECK(m.chanregs != nullptr);
|
||||
}
|
||||
|
||||
TEST_CASE("assign module", "[support]") {
|
||||
sls_detector_module m0;
|
||||
sls_detector_module m1(dt::EIGER);
|
||||
m1.serialnumber = 14;
|
||||
m1.reg = 500;
|
||||
m1.iodelay = 750;
|
||||
|
||||
m0 = m1; // Assignment operator
|
||||
CHECK(m0.serialnumber == 14);
|
||||
CHECK(m0.reg == 500);
|
||||
CHECK(m0.iodelay == 750);
|
||||
CHECK(m0.nchan == 256 * 256 * 4);
|
||||
|
||||
auto m3 = m1; // Copy constructor
|
||||
CHECK(m3.serialnumber == 14);
|
||||
CHECK(m3.reg == 500);
|
||||
CHECK(m3.iodelay == 750);
|
||||
CHECK(m3.nchan == 256 * 256 * 4);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user