Removed multiSlsDetector dependency from slsDetector (#41)

* WIP

* removed multiSlsDetector dependency from slsDetector

* removed comment

* review changes
This commit is contained in:
Erik Fröjdh 2019-07-23 15:47:39 +02:00 committed by Dhanya Thattil
parent b63ec9d84a
commit 2c453fc1be
4 changed files with 273 additions and 386 deletions

View File

@ -1,5 +1,4 @@
#pragma once #pragma once
#include "ClientSocket.h" #include "ClientSocket.h"
#include "SharedMemory.h" #include "SharedMemory.h"
#include "logger.h" #include "logger.h"
@ -7,20 +6,14 @@
#include "network_utils.h" #include "network_utils.h"
#include "FixedCapacityContainer.h" #include "FixedCapacityContainer.h"
#include <cmath> #include <cmath>
#include <vector> #include <vector>
#include <array> #include <array>
class multiSlsDetector;
class ServerInterface; class ServerInterface;
#define SLS_SHMVERSION 0x190515 #define SLS_SHMVERSION 0x190515
/** /**
* @short structure allocated in shared memory to store detector settings for IPC and cache * @short structure allocated in shared memory to store detector settings for IPC and cache
*/ */
@ -365,16 +358,6 @@ class slsDetector : public virtual slsDetectorDefs{
int sendToReceiver(int fnum); int sendToReceiver(int fnum);
/**
* Free shared memory without creating objects
* If this is called, must take care to update
* multiSlsDetectors thisMultiDetector->numberofDetectors
* avoiding creating the constructor classes and mapping
* @param multi_id multi detector Id
* @param slsId slsDetectorId or position of slsDetector in detectors list
*/
static void freeSharedMemory(int multi_id, int slsId);
/** /**
* Free shared memory and delete shared memory structure * Free shared memory and delete shared memory structure
* occupied by the sharedSlsDetector structure * occupied by the sharedSlsDetector structure
@ -593,22 +576,11 @@ class slsDetector : public virtual slsDetectorDefs{
*/ */
int updateDetector(); int updateDetector();
/** /**
* Write current configuration to a file * Get detector specific commands to write into config file
* calls writeConfigurationFile giving it a stream to write to * @returns vector of strings with commands
* @param fname configuration file name
* @param m multiSlsDetector reference to parse commands
* @returns OK or FAIL
*/ */
int writeConfigurationFile(const std::string &fname, multiSlsDetector *m); std::vector<std::string> getConfigFileCommands();
/**
* Write current configuration to a stream
* @param outfile outstream
* @param m multiSlsDetector reference to parse commands
* @returns OK or FAIL
*/
int writeConfigurationFile(std::ofstream &outfile, multiSlsDetector *m);
/** /**
* Get detector settings * Get detector settings

View File

@ -216,7 +216,10 @@ std::vector<int64_t> multiSlsDetector::getDetectorNumber() {
void multiSlsDetector::freeSharedMemory(int multiId, int detPos) { void multiSlsDetector::freeSharedMemory(int multiId, int detPos) {
// single // single
if (detPos >= 0) { if (detPos >= 0) {
slsDetector::freeSharedMemory(multiId, detPos); SharedMemory<sharedSlsDetector> temp_shm(multiId, detPos);
if (temp_shm.IsExisting()) {
temp_shm.RemoveSharedMemory();
}
return; return;
} }
@ -802,59 +805,25 @@ void multiSlsDetector::readConfigurationFile(const std::string &fname) {
int multiSlsDetector::writeConfigurationFile(const std::string &fname) { int multiSlsDetector::writeConfigurationFile(const std::string &fname) {
// TODO! make exception safe! // TODO! make exception safe!
const std::vector<std::string> names = {"detsizechan", "hostname", "outdir", "threaded"}; const std::vector<std::string> header{"detsizechan", "hostname"};
int ret = OK, ret1 = OK;
std::ofstream outfile; std::ofstream outfile;
size_t iline = 0;
outfile.open(fname.c_str(), std::ios_base::out); outfile.open(fname.c_str(), std::ios_base::out);
if (outfile.is_open()) { if (outfile.is_open()) {
char *args[100]; for(const auto& cmd : header)
for (auto &arg : args) { multiSlsDetectorClient(cmd, GET_ACTION, this, outfile);
arg = new char[1000];
}
auto cmd = slsDetectorCommand(this);
// complete size of detector
FILE_LOG(logINFO) << "Command to write: " << iline << " " << names[iline];
strcpy(args[0], names[iline].c_str());
outfile << names[iline] << " " << cmd.executeLine(1, args, GET_ACTION) << std::endl;
++iline;
// hostname of the detectors
FILE_LOG(logINFO) << "Command to write: " << iline << " " << names[iline];
strcpy(args[0], names[iline].c_str());
outfile << names[iline] << " " << cmd.executeLine(1, args, GET_ACTION) << std::endl;
++iline;
// single detector configuration // single detector configuration
for (auto & detector : detectors) { for (auto & detector : detectors) {
outfile << std::endl; outfile << '\n';
ret1 = detector->writeConfigurationFile(outfile, this); auto det_commands = detector->getConfigFileCommands();
if (ret1 == FAIL) { for(const auto& cmd : det_commands)
ret = FAIL; multiSlsDetectorClient(cmd, GET_ACTION, this, outfile);
}
}
outfile << std::endl;
// other configurations
while (iline < names.size()) {
FILE_LOG(logINFO) << "Command to write:" << iline << " " << names[iline];
strcpy(args[0], names[iline].c_str());
outfile << names[iline] << " " << cmd.executeLine(1, args, GET_ACTION) << std::endl;
++iline;
}
outfile.close();
FILE_LOG(logDEBUG1) << "wrote " << iline << " lines to configuration file ";
for (auto &arg : args) {
delete[] arg;
} }
} else { } else {
throw RuntimeError("Could not open configuration file " + fname + " for writing"); throw RuntimeError("Could not open configuration file " + fname + " for writing");
} }
return ret; return OK;
} }
slsDetectorDefs::detectorSettings multiSlsDetector::getSettings(int detPos) { slsDetectorDefs::detectorSettings multiSlsDetector::getSettings(int detPos) {

View File

@ -2,7 +2,6 @@
#include "ClientSocket.h" #include "ClientSocket.h"
#include "SharedMemory.h" #include "SharedMemory.h"
#include "file_utils.h" #include "file_utils.h"
#include "multiSlsDetector.h"
#include "network_utils.h" #include "network_utils.h"
#include "slsDetectorCommand.h" #include "slsDetectorCommand.h"
#include "sls_detector_exceptions.h" #include "sls_detector_exceptions.h"
@ -37,7 +36,7 @@ slsDetector::slsDetector(detectorType type, int multi_id, int det_id,
FILE_LOG(logWARNING) << "This shared memory should have been " FILE_LOG(logWARNING) << "This shared memory should have been "
"deleted before! " "deleted before! "
<< shm.GetName() << ". Freeing it again"; << shm.GetName() << ". Freeing it again";
freeSharedMemory(multi_id, det_id); shm.RemoveSharedMemory();
} }
initSharedMemory(type, multi_id, verify); initSharedMemory(type, multi_id, verify);
@ -245,13 +244,6 @@ int slsDetector::sendToReceiver(int fnum) {
return sendToReceiver(fnum, nullptr, 0, nullptr, 0); return sendToReceiver(fnum, nullptr, 0, nullptr, 0);
} }
void slsDetector::freeSharedMemory(int multi_id, int slsId) {
SharedMemory<sharedSlsDetector> temp_shm(multi_id, slsId);
if (temp_shm.IsExisting()) {
temp_shm.RemoveSharedMemory();
}
}
void slsDetector::freeSharedMemory() { void slsDetector::freeSharedMemory() {
if (shm.IsExisting()) { if (shm.IsExisting()) {
shm.RemoveSharedMemory(); shm.RemoveSharedMemory();
@ -948,105 +940,58 @@ int slsDetector::updateDetector() {
return ret; return ret;
} }
int slsDetector::writeConfigurationFile(const std::string &fname, std::vector<std::string> slsDetector::getConfigFileCommands() {
multiSlsDetector *m) { std::vector<std::string> base{"hostname", "port", "stopport",
int iline = 0; "settingsdir", "fpath", "lock",
std::ofstream outfile; "zmqport", "rx_zmqport", "zmqip",
outfile.open(fname.c_str(), std::ios_base::out); "rx_zmqip", "rx_tcpport"};
if (outfile.is_open()) {
iline = writeConfigurationFile(outfile, m);
outfile.close();
} else {
throw RuntimeError("Could not open configuration file for writing");
}
FILE_LOG(logINFO) << iline << " lines written to configuration file";
return OK;
}
int slsDetector::writeConfigurationFile(std::ofstream &outfile,
multiSlsDetector *m) {
FILE_LOG(logDEBUG1) << "Write configuration file";
std::vector<std::string> names;
// common config
names.emplace_back("hostname");
names.emplace_back("port");
names.emplace_back("stopport");
names.emplace_back("settingsdir");
names.emplace_back("ffdir");
names.emplace_back("outdir");
names.emplace_back("lock");
// receiver config
names.emplace_back("zmqport");
names.emplace_back("rx_zmqport");
names.emplace_back("zmqip");
names.emplace_back("rx_zmqip");
names.emplace_back("rx_tcpport");
// detector specific config
switch (shm()->myDetectorType) { switch (shm()->myDetectorType) {
case GOTTHARD: case GOTTHARD:
names.emplace_back("detectormac"); base.emplace_back("detectormac");
names.emplace_back("detectorip"); base.emplace_back("detectorip");
names.emplace_back("rx_udpport"); base.emplace_back("rx_udpport");
names.emplace_back("rx_udpip"); base.emplace_back("rx_udpip");
names.emplace_back("rx_udpmac"); base.emplace_back("rx_udpmac");
names.emplace_back("rx_hostname"); base.emplace_back("extsig");
names.emplace_back("extsig:0");
names.emplace_back("vhighvoltage");
break; break;
case EIGER: case EIGER:
names.emplace_back("detectormac"); base.emplace_back("detectormac");
names.emplace_back("detectorip"); base.emplace_back("detectorip");
names.emplace_back("rx_udpport"); base.emplace_back("rx_udpport");
names.emplace_back("rx_udpport2"); base.emplace_back("rx_udpport2");
names.emplace_back("rx_udpip"); base.emplace_back("rx_udpip");
names.emplace_back("rx_udpmac"); base.emplace_back("rx_udpmac");
names.emplace_back("rx_hostname"); base.emplace_back("trimen");
base.emplace_back("iodelay");
names.emplace_back("vhighvoltage"); base.emplace_back("tengiga");
names.emplace_back("trimen");
names.emplace_back("iodelay");
names.emplace_back("tengiga");
break; break;
case JUNGFRAU: case JUNGFRAU:
names.emplace_back("detectormac"); base.emplace_back("detectormac");
names.emplace_back("detectormac2"); base.emplace_back("detectormac2");
names.emplace_back("detectorip"); base.emplace_back("detectorip");
names.emplace_back("detectorip2"); base.emplace_back("detectorip2");
names.emplace_back("rx_udpport"); base.emplace_back("rx_udpport");
names.emplace_back("rx_udpport2"); base.emplace_back("rx_udpport2");
names.emplace_back("rx_udpip"); base.emplace_back("rx_udpip");
names.emplace_back("rx_udpip2"); base.emplace_back("rx_udpip2");
names.emplace_back("rx_udpmac"); base.emplace_back("rx_udpmac");
names.emplace_back("rx_udpmac2"); base.emplace_back("rx_udpmac2");
names.emplace_back("rx_hostname"); base.emplace_back("powerchip");
names.emplace_back("powerchip");
names.emplace_back("vhighvoltage");
break; break;
case CHIPTESTBOARD: case CHIPTESTBOARD:
names.emplace_back("detectormac"); base.emplace_back("detectormac");
names.emplace_back("detectorip"); base.emplace_back("detectorip");
names.emplace_back("rx_udpport"); base.emplace_back("rx_udpport");
names.emplace_back("rx_udpip"); base.emplace_back("rx_udpip");
names.emplace_back("rx_udpmac"); base.emplace_back("rx_udpmac");
names.emplace_back("rx_hostname");
names.emplace_back("vhighvoltage");
break; break;
case MOENCH: case MOENCH:
names.emplace_back("detectormac"); base.emplace_back("detectormac");
names.emplace_back("detectorip"); base.emplace_back("detectorip");
names.emplace_back("rx_udpport"); base.emplace_back("rx_udpport");
names.emplace_back("rx_udpip"); base.emplace_back("rx_udpip");
names.emplace_back("rx_udpmac"); base.emplace_back("rx_udpmac");
names.emplace_back("rx_hostname");
names.emplace_back("powerchip");
names.emplace_back("vhighvoltage");
break; break;
default: default:
throw RuntimeError( throw RuntimeError(
@ -1054,18 +999,19 @@ int slsDetector::writeConfigurationFile(std::ofstream &outfile,
std::to_string(shm()->myDetectorType)); std::to_string(shm()->myDetectorType));
} }
names.emplace_back("r_readfreq"); base.emplace_back("vhighvoltage");
names.emplace_back("rx_udpsocksize"); base.emplace_back("rx_hostname");
names.emplace_back("rx_realudpsocksize"); base.emplace_back("r_readfreq");
base.emplace_back("rx_udpsocksize");
base.emplace_back("rx_realudpsocksize");
auto cmd = slsDetectorCommand(m); std::vector<std::string> commands;
for (auto &name : names) { for (const auto &cmd : base) {
char *args[] = {const_cast<char *>(name.c_str())}; std::ostringstream os;
outfile << detId << ":"; os << detId << ':' << cmd;
outfile << name << " " << cmd.executeLine(1, args, GET_ACTION) commands.emplace_back(os.str());
<< std::endl;
} }
return OK; return commands;
} }
slsDetectorDefs::detectorSettings slsDetector::getSettings() { slsDetectorDefs::detectorSettings slsDetector::getSettings() {

View File

@ -1,263 +1,263 @@
#include "catch.hpp" // #include "catch.hpp"
#include "container_utils.h" // #include "container_utils.h"
#include "slsDetector.h" // #include "slsDetector.h"
#include "sls_detector_defs.h" // #include "sls_detector_defs.h"
#include "string_utils.h" // #include "string_utils.h"
#include <algorithm> // #include <algorithm>
#include <iostream> // #include <iostream>
TEST_CASE("Set and get trimen", "[detector]") { // TEST_CASE("Set and get trimen", "[detector]") {
// Free shared memory to be sure that we start in a clean state // // Free shared memory to be sure that we start in a clean state
slsDetector::freeSharedMemory(20, 20); // slsDetector::freeSharedMemory(20, 20);
// Create a detector and check that the type is set correctly // // Create a detector and check that the type is set correctly
slsDetector d(slsDetectorDefs::detectorType::EIGER, 20, 20); // slsDetector d(slsDetectorDefs::detectorType::EIGER, 20, 20);
CHECK(d.getDetectorTypeAsEnum() == slsDetectorDefs::detectorType::EIGER); // CHECK(d.getDetectorTypeAsEnum() == slsDetectorDefs::detectorType::EIGER);
// At the beginning there should be no trimen set // // At the beginning there should be no trimen set
auto res = d.getTrimEn(); // auto res = d.getTrimEn();
CHECK(res.empty()); // CHECK(res.empty());
std::vector<int> energies{5200, 6400, 8500, 9900, 12000}; // std::vector<int> energies{5200, 6400, 8500, 9900, 12000};
d.setTrimEn(energies); // d.setTrimEn(energies);
auto res2 = d.getTrimEn(); // auto res2 = d.getTrimEn();
// Check that the size and every element matches what we set // // Check that the size and every element matches what we set
CHECK(res2.size() == energies.size()); // CHECK(res2.size() == energies.size());
for (size_t i = 0; i != res2.size(); ++i) // for (size_t i = 0; i != res2.size(); ++i)
CHECK(res2[i] == energies[i]); // CHECK(res2[i] == energies[i]);
// Setting trimen with too many vales throws an exception and keeps the // // Setting trimen with too many vales throws an exception and keeps the
// old values // // old values
std::vector<int> too_many(150, 1000); // std::vector<int> too_many(150, 1000);
CHECK_THROWS(d.setTrimEn(too_many)); // CHECK_THROWS(d.setTrimEn(too_many));
auto res3 = d.getTrimEn(); // auto res3 = d.getTrimEn();
CHECK(res3.size() == energies.size()); // CHECK(res3.size() == energies.size());
for (size_t i = 0; i != res3.size(); ++i) // for (size_t i = 0; i != res3.size(); ++i)
CHECK(res3[i] == energies[i]); // CHECK(res3[i] == energies[i]);
// Setting trimen without arguments resets to zero // // Setting trimen without arguments resets to zero
d.setTrimEn(); // d.setTrimEn();
CHECK(d.getTrimEn().empty()); // CHECK(d.getTrimEn().empty());
// Clean up before next test // // Clean up before next test
d.freeSharedMemory(); // d.freeSharedMemory();
} // }
TEST_CASE("Set additional JSON header", "[detector]") { // TEST_CASE("Set additional JSON header", "[detector]") {
slsDetector::freeSharedMemory(20, 20); // slsDetector::freeSharedMemory(20, 20);
slsDetector d(slsDetectorDefs::detectorType::EIGER, 20, 20); // slsDetector d(slsDetectorDefs::detectorType::EIGER, 20, 20);
auto header = d.getAdditionalJsonHeader(); // auto header = d.getAdditionalJsonHeader();
CHECK(header.empty()); // CHECK(header.empty());
// The header set is not validated // // The header set is not validated
d.setAdditionalJsonHeader("any header"); // d.setAdditionalJsonHeader("any header");
header = d.getAdditionalJsonHeader(); // header = d.getAdditionalJsonHeader();
CHECK(header == "any header"); // CHECK(header == "any header");
// make sure reset works // // make sure reset works
d.setAdditionalJsonHeader(""); // d.setAdditionalJsonHeader("");
CHECK(d.getAdditionalJsonHeader().empty()); // CHECK(d.getAdditionalJsonHeader().empty());
// Setting and getting one parameter // // Setting and getting one parameter
d.setAdditionalJsonParameter("exptime", "5"); // d.setAdditionalJsonParameter("exptime", "5");
CHECK(d.getAdditionalJsonParameter("exptime") == "5"); // CHECK(d.getAdditionalJsonParameter("exptime") == "5");
CHECK(d.getAdditionalJsonHeader() == "\"exptime\":5"); // CHECK(d.getAdditionalJsonHeader() == "\"exptime\":5");
// Making sure setting another paramer does not mess up // // Making sure setting another paramer does not mess up
// the first // // the first
d.setAdditionalJsonParameter("gain", "low"); // d.setAdditionalJsonParameter("gain", "low");
CHECK(d.getAdditionalJsonParameter("exptime") == "5"); // CHECK(d.getAdditionalJsonParameter("exptime") == "5");
CHECK(d.getAdditionalJsonParameter("gain") == "low"); // CHECK(d.getAdditionalJsonParameter("gain") == "low");
CHECK(d.getAdditionalJsonHeader() == "\"exptime\":5,\"gain\":\"low\""); // CHECK(d.getAdditionalJsonHeader() == "\"exptime\":5,\"gain\":\"low\"");
// Change a value // // Change a value
d.setAdditionalJsonParameter("exptime", "90"); // d.setAdditionalJsonParameter("exptime", "90");
CHECK(d.getAdditionalJsonParameter("exptime") == "90"); // CHECK(d.getAdditionalJsonParameter("exptime") == "90");
CHECK(d.getAdditionalJsonHeader() == "\"exptime\":90,\"gain\":\"low\""); // CHECK(d.getAdditionalJsonHeader() == "\"exptime\":90,\"gain\":\"low\"");
// Ask for a key that does not exists // // Ask for a key that does not exists
// TODO!(Erik) Is an empty string the right return or should we throw // // TODO!(Erik) Is an empty string the right return or should we throw
CHECK(d.getAdditionalJsonParameter("somerandomkey").empty()); // CHECK(d.getAdditionalJsonParameter("somerandomkey").empty());
// Throws if value or key is empty // // Throws if value or key is empty
CHECK_THROWS(d.setAdditionalJsonParameter("somekey", "")); // CHECK_THROWS(d.setAdditionalJsonParameter("somekey", ""));
CHECK_THROWS(d.setAdditionalJsonParameter("", "parameter")); // CHECK_THROWS(d.setAdditionalJsonParameter("", "parameter"));
CHECK_THROWS(d.setAdditionalJsonParameter("", "")); // CHECK_THROWS(d.setAdditionalJsonParameter("", ""));
// Throws if key or value has illegal char // // Throws if key or value has illegal char
CHECK_THROWS(d.setAdditionalJsonParameter("mykey,", "5")); // CHECK_THROWS(d.setAdditionalJsonParameter("mykey,", "5"));
CHECK_THROWS(d.setAdditionalJsonParameter("some:key", "9")); // CHECK_THROWS(d.setAdditionalJsonParameter("some:key", "9"));
CHECK_THROWS(d.setAdditionalJsonParameter("some\"key", "1")); // CHECK_THROWS(d.setAdditionalJsonParameter("some\"key", "1"));
CHECK_THROWS(d.setAdditionalJsonParameter("key", "value:")); // CHECK_THROWS(d.setAdditionalJsonParameter("key", "value:"));
CHECK_THROWS(d.setAdditionalJsonParameter("key", "va,lue")); // CHECK_THROWS(d.setAdditionalJsonParameter("key", "va,lue"));
CHECK_THROWS(d.setAdditionalJsonParameter("key", "va\"l\"ue")); // CHECK_THROWS(d.setAdditionalJsonParameter("key", "va\"l\"ue"));
d.freeSharedMemory(); // d.freeSharedMemory();
} // }
TEST_CASE("Set ROI", "[detector]") { // TEST_CASE("Set ROI", "[detector]") {
using ROI = slsDetectorDefs::ROI; // using ROI = slsDetectorDefs::ROI;
slsDetector::freeSharedMemory(20,20); // slsDetector::freeSharedMemory(20,20);
slsDetector d(slsDetectorDefs::detectorType::EIGER, 20, 20); // slsDetector d(slsDetectorDefs::detectorType::EIGER, 20, 20);
int n{0}; // int n{0};
d.getROI(n); // d.getROI(n);
CHECK(n == 0); // CHECK(n == 0);
CHECK(d.getNRoi() == 0); // CHECK(d.getNRoi() == 0);
// set one ROI // // set one ROI
ROI r; // ROI r;
r.xmin = 5; // r.xmin = 5;
r.xmax = 100; // r.xmax = 100;
r.ymin = 10; // r.ymin = 10;
r.ymax = 300; // r.ymax = 300;
d.setROI(1, &r); // d.setROI(1, &r);
auto res2 = d.getROI(n); // auto res2 = d.getROI(n);
CHECK(n == 1); // CHECK(n == 1);
CHECK(d.getNRoi() == 1); // CHECK(d.getNRoi() == 1);
CHECK(res2->xmin == 5); // CHECK(res2->xmin == 5);
CHECK(res2->xmax == 100); // CHECK(res2->xmax == 100);
CHECK(res2->ymin == 10); // CHECK(res2->ymin == 10);
CHECK(res2->ymax == 300); // CHECK(res2->ymax == 300);
d.freeSharedMemory(); // d.freeSharedMemory();
} // }
TEST_CASE("Set multiple ROIs", "[detector]") { // TEST_CASE("Set multiple ROIs", "[detector]") {
using ROI = slsDetectorDefs::ROI; // using ROI = slsDetectorDefs::ROI;
slsDetector::freeSharedMemory(20, 20); // slsDetector::freeSharedMemory(20, 20);
slsDetector d(slsDetectorDefs::detectorType::EIGER, 20, 20); // slsDetector d(slsDetectorDefs::detectorType::EIGER, 20, 20);
// set one ROI // // set one ROI
constexpr int n = 3; // constexpr int n = 3;
ROI r[n]; // ROI r[n];
r[0].xmin = 500; // r[0].xmin = 500;
r[0].xmax = 60000; // r[0].xmax = 60000;
r[0].ymin = 100; // r[0].ymin = 100;
r[0].ymax = 800; // r[0].ymax = 800;
r[1].xmin = 2; // r[1].xmin = 2;
r[1].xmax = 100; // r[1].xmax = 100;
r[1].ymin = 1; // r[1].ymin = 1;
r[1].ymax = 300; // r[1].ymax = 300;
r[2].xmin = 200; // r[2].xmin = 200;
r[2].xmax = 300; // r[2].xmax = 300;
r[2].ymin = 15; // r[2].ymin = 15;
r[2].ymax = 307; // r[2].ymax = 307;
d.setROI(n, r); // d.setROI(n, r);
int n_roi{0}; // int n_roi{0};
auto res = d.getROI(n_roi); // auto res = d.getROI(n_roi);
CHECK(n_roi == n); // CHECK(n_roi == n);
CHECK(d.getNRoi() == n); // CHECK(d.getNRoi() == n);
CHECK(res[0].xmin == 2); // CHECK(res[0].xmin == 2);
CHECK(res[0].xmax == 100); // CHECK(res[0].xmax == 100);
CHECK(res[0].ymin == 1); // CHECK(res[0].ymin == 1);
CHECK(res[0].ymax == 300); // CHECK(res[0].ymax == 300);
CHECK(res[1].xmin == 200); // CHECK(res[1].xmin == 200);
CHECK(res[1].xmax == 300); // CHECK(res[1].xmax == 300);
CHECK(res[1].ymin == 15); // CHECK(res[1].ymin == 15);
CHECK(res[1].ymax == 307); // CHECK(res[1].ymax == 307);
CHECK(res[2].xmin == 500); // CHECK(res[2].xmin == 500);
CHECK(res[2].xmax == 60000); // CHECK(res[2].xmax == 60000);
CHECK(res[2].ymin == 100); // CHECK(res[2].ymin == 100);
CHECK(res[2].ymax == 800); // CHECK(res[2].ymax == 800);
d.freeSharedMemory(); // d.freeSharedMemory();
} // }
TEST_CASE("Padding and discard policy", "[detector][new]"){ // TEST_CASE("Padding and discard policy", "[detector][new]"){
slsDetector::freeSharedMemory(20, 20); // slsDetector::freeSharedMemory(20, 20);
slsDetector d(slsDetectorDefs::detectorType::EIGER, 20, 20); // slsDetector d(slsDetectorDefs::detectorType::EIGER, 20, 20);
// // //
d.setPartialFramesPadding(false); // d.setPartialFramesPadding(false);
CHECK(d.getPartialFramesPadding() == false); // CHECK(d.getPartialFramesPadding() == false);
d.setPartialFramesPadding(true); // d.setPartialFramesPadding(true);
CHECK(d.getPartialFramesPadding() == true); // CHECK(d.getPartialFramesPadding() == true);
d.freeSharedMemory(); // d.freeSharedMemory();
} // }
TEST_CASE("create detParamets struct", "[detector][new]"){ // TEST_CASE("create detParamets struct", "[detector][new]"){
detParameters par; // detParameters par;
CHECK(sizeof(par) == 32); // CHECK(sizeof(par) == 32);
CHECK(par.nChanX == 0); // CHECK(par.nChanX == 0);
CHECK(par.nChanY == 0); // CHECK(par.nChanY == 0);
CHECK(par.nChipX == 0); // CHECK(par.nChipX == 0);
CHECK(par.nChipY == 0); // CHECK(par.nChipY == 0);
CHECK(par.nDacs == 0); // CHECK(par.nDacs == 0);
CHECK(par.dynamicRange == 0); // CHECK(par.dynamicRange == 0);
CHECK(par.nGappixelsX == 0); // CHECK(par.nGappixelsX == 0);
CHECK(par.nGappixelsY == 0); // CHECK(par.nGappixelsY == 0);
detParameters par2{slsDetectorDefs::detectorType::EIGER}; // detParameters par2{slsDetectorDefs::detectorType::EIGER};
CHECK(sizeof(par2) == 32); // CHECK(sizeof(par2) == 32);
CHECK(par2.nChanX == 256); // CHECK(par2.nChanX == 256);
CHECK(par2.nChanY == 256); // CHECK(par2.nChanY == 256);
CHECK(par2.nChipX == 4); // CHECK(par2.nChipX == 4);
CHECK(par2.nChipY == 1); // CHECK(par2.nChipY == 1);
CHECK(par2.nDacs == 16); // CHECK(par2.nDacs == 16);
CHECK(par2.dynamicRange == 16); // CHECK(par2.dynamicRange == 16);
CHECK(par2.nGappixelsX == 6); // CHECK(par2.nGappixelsX == 6);
CHECK(par2.nGappixelsY == 1); // CHECK(par2.nGappixelsY == 1);
} // }
TEST_CASE("ctb digital offset and list", "[detector][ctb]"){ // TEST_CASE("ctb digital offset and list", "[detector][ctb]"){
slsDetector::freeSharedMemory(20, 20); // slsDetector::freeSharedMemory(20, 20);
slsDetector d(slsDetectorDefs::detectorType::CHIPTESTBOARD, 20, 20); // slsDetector d(slsDetectorDefs::detectorType::CHIPTESTBOARD, 20, 20);
// dbit offset // // dbit offset
CHECK(d.getReceiverDbitOffset() == 0); // CHECK(d.getReceiverDbitOffset() == 0);
CHECK(d.setReceiverDbitOffset(-1) == 0); // CHECK(d.setReceiverDbitOffset(-1) == 0);
CHECK(d.setReceiverDbitOffset(0) == 0); // CHECK(d.setReceiverDbitOffset(0) == 0);
CHECK(d.setReceiverDbitOffset(5) == 5); // CHECK(d.setReceiverDbitOffset(5) == 5);
CHECK(d.getReceiverDbitOffset() == 5); // CHECK(d.getReceiverDbitOffset() == 5);
// dbit list // // dbit list
std::vector <int> list = d.getReceiverDbitList(); // std::vector <int> list = d.getReceiverDbitList();
CHECK(list.empty()); // CHECK(list.empty());
for (int i = 0; i < 10; ++i) // for (int i = 0; i < 10; ++i)
list.push_back(i); // list.push_back(i);
d.setReceiverDbitList(list); // d.setReceiverDbitList(list);
CHECK(d.getReceiverDbitList().size() == 10); // CHECK(d.getReceiverDbitList().size() == 10);
list.push_back(64); // list.push_back(64);
CHECK_THROWS_AS(d.setReceiverDbitList(list), sls::RuntimeError); // CHECK_THROWS_AS(d.setReceiverDbitList(list), sls::RuntimeError);
CHECK_THROWS_WITH(d.setReceiverDbitList(list), // CHECK_THROWS_WITH(d.setReceiverDbitList(list),
Catch::Matchers::Contains("be between 0 and 63")); // Catch::Matchers::Contains("be between 0 and 63"));
list.clear(); // list.clear();
for (int i = 0; i < 65; ++i) // for (int i = 0; i < 65; ++i)
list.push_back(i); // list.push_back(i);
CHECK(list.size() == 65); // CHECK(list.size() == 65);
CHECK_THROWS_WITH(d.setReceiverDbitList(list), // CHECK_THROWS_WITH(d.setReceiverDbitList(list),
Catch::Matchers::Contains("be greater than 64")); // Catch::Matchers::Contains("be greater than 64"));
list.clear(); // list.clear();
d.setReceiverDbitList(list); // d.setReceiverDbitList(list);
CHECK(d.getReceiverDbitList().empty()); // CHECK(d.getReceiverDbitList().empty());
} // }