clang-format

This commit is contained in:
Erik Frojdh 2020-05-04 16:30:00 +02:00
parent 32662baef8
commit 959fd562d3
38 changed files with 3615 additions and 3194 deletions

View File

@ -9,7 +9,6 @@
#include <string>
#include <vector>
#include "CmdProxy.h"
#include "Detector.h"
#include "sls_detector_defs.h"
@ -52,5 +51,4 @@ int main() {
auto help = replace_all(tmp, "\n\t", "\n\t\t");
fs << '\t' << cmd << usage << help << "\n";
}
}

View File

@ -1,5 +1,5 @@
#include "catch.hpp"
#include "DetectorImpl.h"
#include "catch.hpp"
#include "string_utils.h"
#include "tests/globals.h"
#include <iostream>

40
integrationTests/test-integrationDectector.cpp Executable file → Normal file
View File

@ -2,9 +2,9 @@
#include "catch.hpp"
#include "ClientSocket.h"
#include "logger.h"
#include "DetectorImpl.h"
#include "Module.h"
#include "logger.h"
#include "sls_detector_defs.h"
#include "Timer.h"
@ -79,7 +79,6 @@ TEST_CASE("Set control port then create a new object with this control port",
d.freeSharedMemory();
}
TEST_CASE("single EIGER detector no receiver basic set and get",
"[.integration][eiger]") {
// TODO! this test should take command line arguments for config
@ -130,8 +129,6 @@ TEST_CASE("single EIGER detector no receiver basic set and get",
d.freeSharedMemory();
}
TEST_CASE("Locking mechanism and last ip", "[.integration][.single]") {
Module d(test::type);
d.setHostname(test::hostname);
@ -154,13 +151,12 @@ TEST_CASE("Locking mechanism and last ip", "[.integration][.single]") {
d.freeSharedMemory();
}
TEST_CASE("Set settings", "[.integration][.single]"){
TEST_CASE("Set settings", "[.integration][.single]") {
Module d(test::type);
d.setHostname(test::hostname);
CHECK(d.setSettings(defs::STANDARD) == defs::STANDARD);
}
TEST_CASE("Timer functions", "[.integration][cli]") {
// FRAME_NUMBER, /**< number of real time frames: total number of
// acquisitions is number or frames*number of triggers */ ACQUISITION_TIME,
@ -204,8 +200,7 @@ TEST_CASE("Timer functions", "[.integration][cli]") {
if (test::type != dt::EIGER) {
auto delay = 10000;
d.setDelayAfterTrigger(delay);
CHECK(d.getDelayAfterTrigger() ==
delay);
CHECK(d.getDelayAfterTrigger() == delay);
}
auto triggers = 2;
@ -218,10 +213,9 @@ TEST_CASE("Timer functions", "[.integration][cli]") {
CHECK(d.getSubExptime() == subtime);
}
// for (int i =0; i!=frames; ++i)
d.startAndReadAll();
d.startAndReadAll();
d.freeSharedMemory();
}
// TEST_CASE("Aquire", "[.integration][eiger]"){
@ -382,8 +376,8 @@ TEST_CASE("Chiptestboard Loading Patterns", "[.ctbintegration]") {
}
}
TEST_CASE("Chiptestboard Dbit offset, list, sampling, advinvert", "[.ctbintegration][dbit]") {
TEST_CASE("Chiptestboard Dbit offset, list, sampling, advinvert",
"[.ctbintegration][dbit]") {
SingleDetectorConfig c;
// pick up multi detector from shm id 0
@ -403,7 +397,7 @@ TEST_CASE("Chiptestboard Dbit offset, list, sampling, advinvert", "[.ctbintegrat
// dbit list
std::vector <int> list = m.getReceiverDbitList();
std::vector<int> list = m.getReceiverDbitList();
list.clear();
for (int i = 0; i < 10; ++i)
list.push_back(i);
@ -414,14 +408,14 @@ TEST_CASE("Chiptestboard Dbit offset, list, sampling, advinvert", "[.ctbintegrat
list.push_back(64);
CHECK_THROWS_AS(m.setReceiverDbitList(list), sls::RuntimeError);
CHECK_THROWS_WITH(m.setReceiverDbitList(list),
Catch::Matchers::Contains("be between 0 and 63"));
Catch::Matchers::Contains("be between 0 and 63"));
list.clear();
for (int i = 0; i < 65; ++i)
list.push_back(i);
CHECK(list.size() == 65);
CHECK_THROWS_WITH(m.setReceiverDbitList(list),
Catch::Matchers::Contains("be greater than 64"));
Catch::Matchers::Contains("be greater than 64"));
list.clear();
m.setReceiverDbitList(list);
@ -441,7 +435,7 @@ TEST_CASE("Chiptestboard Dbit offset, list, sampling, advinvert", "[.ctbintegrat
m.setExternalSamplingSource(62);
CHECK(m.getExternalSamplingSource() == 62);
CHECK_THROWS_WITH(m.setExternalSamplingSource(64),
Catch::Matchers::Contains("be 0-63"));
Catch::Matchers::Contains("be 0-63"));
CHECK(m.getExternalSamplingSource() == 62);
m.setExternalSampling(1);
CHECK(m.getExternalSampling() == 1);
@ -450,20 +444,23 @@ TEST_CASE("Chiptestboard Dbit offset, list, sampling, advinvert", "[.ctbintegrat
m.setExternalSampling(1);
CHECK(m.getExternalSampling() == 1);
CHECK(m.readRegister(0x7b) == 0x1003E);
}
TEST_CASE("Eiger or Jungfrau startingfnum", "[.eigerintegration][.jungfrauintegration][startingfnum]") {
TEST_CASE("Eiger or Jungfrau startingfnum",
"[.eigerintegration][.jungfrauintegration][startingfnum]") {
SingleDetectorConfig c;
// pick up multi detector from shm id 0
DetectorImpl m(0);
// ensure ctb detector type, hostname and online
REQUIRE(((m.getDetectorTypeAsEnum() == slsDetectorDefs::detectorType::EIGER) || (m.getDetectorTypeAsEnum() == slsDetectorDefs::detectorType::JUNGFRAU)));
REQUIRE(
((m.getDetectorTypeAsEnum() == slsDetectorDefs::detectorType::EIGER) ||
(m.getDetectorTypeAsEnum() ==
slsDetectorDefs::detectorType::JUNGFRAU)));
REQUIRE(m.getHostname() == c.hostname);
CHECK(m.setNumberOfFrames(1) == 1);
CHECK(m.setNumberOfFrames(1) == 1);
// starting fnum
uint64_t val = 8;
@ -498,7 +495,8 @@ TEST_CASE("Eiger readnlines", "[.eigerintegration][readnlines]") {
DetectorImpl m(0);
// ensure detector type, hostname
REQUIRE((m.getDetectorTypeAsEnum() == slsDetectorDefs::detectorType::EIGER));
REQUIRE(
(m.getDetectorTypeAsEnum() == slsDetectorDefs::detectorType::EIGER));
REQUIRE(m.getHostname() == c.hostname);
m.setDynamicRange(16);

6
integrationTests/test-integrationMulti.cpp Executable file → Normal file
View File

@ -1,5 +1,5 @@
#include "catch.hpp"
#include "DetectorImpl.h"
#include "catch.hpp"
#include "string_utils.h"
#include "tests/globals.h"
#include <iostream>
@ -24,8 +24,6 @@ TEST_CASE("Initialize a multi detector", "[.integration][.multi]") {
d.freeSharedMemory();
}
TEST_CASE("Set and read timers", "[.integration][.multi]") {
DetectorImpl d(0, true, true);
@ -57,7 +55,6 @@ TEST_CASE("Set and read timers", "[.integration][.multi]") {
// PROGRESS, /**< fraction of measurement elapsed - only get! */
// MEASUREMENTS_NUMBER,
// FRAMES_FROM_START,
// FRAMES_FROM_START_PG,
// SAMPLES,
@ -78,7 +75,6 @@ TEST_CASE("Set and read timers", "[.integration][.multi]") {
CHECK(d.setSubFrameExposureDeadTime(-1) == Approx(subframe_deadtime));
}
if (test::type == dt::EIGER) {
// 32bit is needed for subframe exposure
d.setDynamicRange(32);

View File

@ -3,10 +3,9 @@
#include "network_utils.h"
#include "sls_detector_defs.h"
#include <chrono>
#include <map>
#include <memory>
#include <vector>
#include <map>
class detectorData;
@ -16,12 +15,11 @@ class DetectorImpl;
class MacAddr;
class IpAddr;
//Free function to avoid dependence on class
//and avoid the option to free another objects
//shm by mistake
// Free function to avoid dependence on class
// and avoid the option to free another objects
// shm by mistake
void freeSharedMemory(int multiId, int detPos = -1);
/**
* \class Detector
*/
@ -101,11 +99,12 @@ class Detector {
/** [Jungfrau][Gotthard][Gotthard2] */
Result<defs::detectorSettings> getSettings(Positions pos = {}) const;
/** [Jungfrau] Options:DYNAMICGAIN, DYNAMICHG0, FIXGAIN1, FIXGAIN2, FORCESWITCHG1, FORCESWITCHG2
* [Gotthard] Options: DYNAMICGAIN, HIGHGAIN, LOWGAIN, MEDIUMGAIN, VERYHIGHGAIN
* [Gotthard2] Options: DYNAMICGAIN, FIXGAIN1, FIXGAIN2
* [Moench] Options: G1_HIGHGAIN, G1_LOWGAIN, G2_HIGHCAP_HIGHGAIN, G2_HIGHCAP_LOWGAIN,
* G2_LOWCAP_HIGHGAIN, G2_LOWCAP_LOWGAIN, G4_HIGHGAIN, G4_LOWGAIN
/** [Jungfrau] Options:DYNAMICGAIN, DYNAMICHG0, FIXGAIN1, FIXGAIN2,
* FORCESWITCHG1, FORCESWITCHG2 [Gotthard] Options: DYNAMICGAIN, HIGHGAIN,
* LOWGAIN, MEDIUMGAIN, VERYHIGHGAIN [Gotthard2] Options: DYNAMICGAIN,
* FIXGAIN1, FIXGAIN2 [Moench] Options: G1_HIGHGAIN, G1_LOWGAIN,
* G2_HIGHCAP_HIGHGAIN, G2_HIGHCAP_LOWGAIN, G2_LOWCAP_HIGHGAIN,
* G2_LOWCAP_LOWGAIN, G4_HIGHGAIN, G4_LOWGAIN
*/
void setSettings(defs::detectorSettings value, Positions pos = {});
@ -304,10 +303,12 @@ class Detector {
void setDAC(defs::dacIndex index, int value, bool mV, Positions pos = {});
/* [Gotthard2] */
Result<int> getOnChipDAC(defs::dacIndex index, int chipIndex, Positions pos = {}) const;
Result<int> getOnChipDAC(defs::dacIndex index, int chipIndex,
Positions pos = {}) const;
/* [Gotthard2] */
void setOnChipDAC(defs::dacIndex index, int chipIndex, int value, Positions pos = {});
void setOnChipDAC(defs::dacIndex index, int chipIndex, int value,
Positions pos = {});
/**************************************************
* *
@ -326,7 +327,8 @@ class Detector {
*/
void acquire();
/** If acquisition aborted, use this to clear before starting next acquisition */
/** If acquisition aborted, use this to clear before starting next
* acquisition */
void clearAcquiringFlag();
/** Non Blocking: Start receiver listener*/
@ -348,7 +350,8 @@ class Detector {
Result<int64_t> getFramesCaught(Positions pos = {}) const;
Result<std::vector<uint64_t>> getNumMissingPackets(Positions pos = {}) const;
Result<std::vector<uint64_t>>
getNumMissingPackets(Positions pos = {}) const;
/** [Eiger][Jungfrau] */
Result<uint64_t> getStartingFrameNumber(Positions pos = {}) const;
@ -512,7 +515,8 @@ class Detector {
* Validates and sets the receiver.
* Updates local receiver cache parameters
* Configures the detector to the receiver as UDP destination
* @param receiver receiver hostname or IP address, can include tcp port eg. hostname:port
* @param receiver receiver hostname or IP address, can include tcp port eg.
* hostname:port
*/
void setRxHostname(const std::string &receiver, Positions pos = {});
@ -659,10 +663,10 @@ class Detector {
Result<int> getClientZmqPort(Positions pos = {}) const;
/**
* Modified only when using an intermediate process between receiver and gui/client.
* Module_id is -1 for all detectors, ports for each
* module is calculated (increments) Restarts client zmq sockets only if it
* was already enabled
* Modified only when using an intermediate process between receiver and
* gui/client. Module_id is -1 for all detectors, ports for each module is
* calculated (increments) Restarts client zmq sockets only if it was
* already enabled
*/
void setClientZmqPort(int port, int module_id = -1);
@ -915,7 +919,6 @@ class Detector {
void setExternalSignalFlags(defs::externalSignalFlag value,
Positions pos = {});
/**************************************************
* *
* Gotthard2 Specific *
@ -940,16 +943,21 @@ class Detector {
/** [Gotthard2]
* @param offsetChannel starting channel to be injected
* @param incrementChannel determines succeeding channels to be injected */
void setInjectChannel(const int offsetChannel, const int incrementChannel, Positions pos = {});
void setInjectChannel(const int offsetChannel, const int incrementChannel,
Positions pos = {});
/** [Gotthard2] adu values for each channel */
Result<std::vector<int>> getVetoPhoton(const int chipIndex, Positions pos = {});
Result<std::vector<int>> getVetoPhoton(const int chipIndex,
Positions pos = {});
/** [Gotthard2] energy in keV */
void setVetoPhoton(const int chipIndex, const int numPhotons, const int energy, const std::string& fname, Positions pos = {});
void setVetoPhoton(const int chipIndex, const int numPhotons,
const int energy, const std::string &fname,
Positions pos = {});
/** [Gotthard2] */
void setVetoReference(const int gainIndex, const int value, Positions pos = {});
void setVetoReference(const int gainIndex, const int value,
Positions pos = {});
/** [Gotthard2] */
Result<defs::burstMode> getBurstMode(Positions pos = {});
@ -1096,7 +1104,7 @@ class Detector {
Result<std::vector<int>> getRxDbitList(Positions pos = {}) const;
/** [CTB] list contains the set of bits (0-63) to save */
void setRxDbitList(const std::vector<int>& list, Positions pos = {});
void setRxDbitList(const std::vector<int> &list, Positions pos = {});
/** [CTB] */
Result<int> getRxDbitOffset(Positions pos = {}) const;
@ -1150,21 +1158,26 @@ class Detector {
* [Mythen3][Moench] */
void setPatternWord(int addr, uint64_t word, Positions pos = {});
/**[CTB][Moench][Mythen3] Options: level: -1 (complete pattern) and 0-2 levels
/**[CTB][Moench][Mythen3] Options: level: -1 (complete pattern) and 0-2
* levels
* @returns array of start address and stop address
*/
Result<std::array<int, 2>> getPatternLoopAddresses(int level,
Positions pos = {}) const;
Result<std::array<int, 2>>
getPatternLoopAddresses(int level, Positions pos = {}) const;
/** [CTB][Moench][Mythen3] Options: level: -1 (complete pattern) and 0-2 levels */
void setPatternLoopAddresses(int level, int start, int stop, Positions pos = {});
/** [CTB][Moench][Mythen3] Options: level: -1 (complete pattern) and 0-2
* levels */
void setPatternLoopAddresses(int level, int start, int stop,
Positions pos = {});
/**[CTB][Moench][Mythen3] Options: level: -1 (complete pattern) and 0-2 levels
/**[CTB][Moench][Mythen3] Options: level: -1 (complete pattern) and 0-2
* levels
* @returns number of loops
*/
Result<int> getPatternLoopCycles(int level, Positions pos = {}) const;
/** [CTB][Moench][Mythen3] n: 0-2, level: -1 (complete pattern) and 0-2 levels */
/** [CTB][Moench][Mythen3] n: 0-2, level: -1 (complete pattern) and 0-2
* levels */
void setPatternLoopCycles(int level, int n, Positions pos = {});
/* [CTB][Moench][Mythen3] */
@ -1182,14 +1195,15 @@ class Detector {
/** [CTB][Moench][Mythen3] */
Result<uint64_t> getPatternMask(Positions pos = {});
/** [CTB][Moench][Mythen3] Sets the mask applied to every pattern to the selected bit mask */
/** [CTB][Moench][Mythen3] Sets the mask applied to every pattern to the
* selected bit mask */
void setPatternMask(uint64_t mask, Positions pos = {});
/** [CTB][Moench][Mythen3] */
Result<uint64_t> getPatternBitMask(Positions pos = {}) const;
/** [CTB][Moench][Mythen3] Sets the bitmask that the mask will be applied to for every
* pattern
/** [CTB][Moench][Mythen3] Sets the bitmask that the mask will be applied to
* for every pattern
*/
void setPatternBitMask(uint64_t mask, Positions pos = {});
@ -1200,11 +1214,14 @@ class Detector {
* ************************************************/
/** [Moench] */
Result<std::map<std::string, std::string>> getAdditionalJsonHeader(Positions pos = {}) const;
Result<std::map<std::string, std::string>>
getAdditionalJsonHeader(Positions pos = {}) const;
/** [Moench] If empty, reset additional json header. Max 20 characters for each key/value */
void setAdditionalJsonHeader(const std::map<std::string, std::string> &jsonHeader,
Positions pos = {});
/** [Moench] If empty, reset additional json header. Max 20 characters for
* each key/value */
void setAdditionalJsonHeader(
const std::map<std::string, std::string> &jsonHeader,
Positions pos = {});
/** [Moench] */
Result<std::string> getAdditionalJsonParameter(const std::string &key,
@ -1215,7 +1232,8 @@ class Detector {
* else appends the parameter key and value
* If empty, deletes parameter. Max 20 characters for each key/value
*/
void setAdditionalJsonParameter(const std::string &key, const std::string &value,
void setAdditionalJsonParameter(const std::string &key,
const std::string &value,
Positions pos = {});
/** [Moench] TODO! How do we do this best??? Can be refactored to something

92
slsDetectorSoftware/include/detectorData.h Executable file → Normal file
View File

@ -5,56 +5,60 @@
@short data structure to hold the detector data after postprocessing
*/
class detectorData {
public:
/**
* Constructor
* @param progress progress index
* @param fname file name prefix
* @param nx number of detector channels (1D detector) or dimension in x (2D detector)
* @param ny dimension in y (2D detector)
* @param d pointer to data in char* format
* @param dbytes number of bytes of image pointed to by cval pointer
* @param dr dynamic range or bits per pixel
* @param fIndex file index
* @param complete true if complete image, else missing packets
*/
detectorData(double progress, std::string fname, int x, int y, char *d, int dbytes, int dr, uint64_t fIndex, bool complete) :
progressIndex(progress), fileName(fname), fileIndex(fIndex), nx(x), ny(y), data(d), databytes(dbytes), dynamicRange(dr), completeImage(complete) {};
public:
/**
* Constructor
* @param progress progress index
* @param fname file name prefix
* @param nx number of detector channels (1D detector) or dimension in x (2D
* detector)
* @param ny dimension in y (2D detector)
* @param d pointer to data in char* format
* @param dbytes number of bytes of image pointed to by cval pointer
* @param dr dynamic range or bits per pixel
* @param fIndex file index
* @param complete true if complete image, else missing packets
*/
detectorData(double progress, std::string fname, int x, int y, char *d,
int dbytes, int dr, uint64_t fIndex, bool complete)
: progressIndex(progress), fileName(fname), fileIndex(fIndex), nx(x),
ny(y), data(d), databytes(dbytes), dynamicRange(dr),
completeImage(complete){};
/**
* Destructor
* data has to be deleted by caller
*/
~detectorData() {};
/**
* Destructor
* data has to be deleted by caller
*/
~detectorData(){};
int64_t getChannel(int i) {
int off=dynamicRange/8;
if (off==1) {
char val=*(data+i);
return val;
}
if (off==2) {
int16_t val=*((int16_t*)(data+i*off));
return val;
}
if (off==4) {
int32_t val=*((int32_t*)(data+i*off));
return val;
}
if (off==8) {
int64_t val=*((int64_t*)(data+i*off));
return val;
}
return -1;
}
//private:
int64_t getChannel(int i) {
int off = dynamicRange / 8;
if (off == 1) {
char val = *(data + i);
return val;
}
if (off == 2) {
int16_t val = *((int16_t *)(data + i * off));
return val;
}
if (off == 4) {
int32_t val = *((int32_t *)(data + i * off));
return val;
}
if (off == 8) {
int64_t val = *((int64_t *)(data + i * off));
return val;
}
return -1;
}
// private:
double progressIndex;
std::string fileName;
uint64_t fileIndex;
uint64_t fileIndex;
int nx;
int ny;
char* data;
char *data;
int databytes;
int dynamicRange;
bool completeImage;
bool completeImage;
};

1428
slsDetectorSoftware/include/slsDetectorUsers.h Executable file → Normal file

File diff suppressed because it is too large Load Diff

10
slsDetectorSoftware/src/CmdParser.cpp Executable file → Normal file
View File

@ -45,7 +45,8 @@ void CmdParser::Parse(const std::string &s) {
auto old_size = arguments_.size();
arguments_.erase(std::remove_if(begin(arguments_), end(arguments_),
[](const std::string &item) {
return (item == "-h" || item == "--help");
return (item == "-h" ||
item == "--help");
}),
end(arguments_));
if (old_size - arguments_.size() > 0)
@ -100,16 +101,15 @@ std::vector<const char *> CmdParser::argv() const {
return vec;
}
std::string CmdParser::cli_line() const{
std::string CmdParser::cli_line() const {
std::ostringstream os;
os << command_;
for (const auto & arg : arguments_)
for (const auto &arg : arguments_)
os << " " << arg;
return os.str();
}
void CmdParser::Reset(){
void CmdParser::Reset() {
multi_id_ = 0;
detector_id_ = -1;
help_ = false;

8
slsDetectorSoftware/src/CmdParser.h Executable file → Normal file
View File

@ -28,12 +28,14 @@ class CmdParser {
int multi_id() const noexcept { return multi_id_; };
int detector_id() const noexcept { return detector_id_; };
int n_arguments() const noexcept { return arguments_.size(); }
const std::string &command() const noexcept{ return command_; }
const std::string &command() const noexcept { return command_; }
void setCommand(std::string cmd) { command_ = cmd; }
bool isHelp() const noexcept { return help_; }
const std::string &executable() const noexcept{ return executable_; }
const std::vector<std::string> &arguments() const noexcept{ return arguments_; };
const std::string &executable() const noexcept { return executable_; }
const std::vector<std::string> &arguments() const noexcept {
return arguments_;
};
std::vector<const char *> argv() const;
std::string cli_line() const;

View File

@ -169,7 +169,8 @@ std::string CmdProxy::VirtualServer(int action) {
if (det_id != -1) {
throw sls::RuntimeError("Cannot execute this at module level");
}
det->setVirtualDetectorServers(StringTo<int>(args[0]), StringTo<int>(args[1]));
det->setVirtualDetectorServers(StringTo<int>(args[0]),
StringTo<int>(args[1]));
os << sls::ToString(args);
} else {
throw sls::RuntimeError("Unknown action");
@ -394,21 +395,24 @@ std::string CmdProxy::Adcphase(int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "[n_value] [(optional)deg]\n\t[Jungfrau][Ctb][Moench][Moench][Gotthard] Phase "
os << "[n_value] "
"[(optional)deg]\n\t[Jungfrau][Ctb][Moench][Moench][Gotthard] "
"Phase "
"shift of ADC clock. \n\t[Jungfrau] Absolute phase shift. If deg "
"used, then shift in degrees. Changing Speed also resets "
"adcphase to recommended defaults.\n\t[Ctb][Moench] Absolute phase "
"adcphase to recommended defaults.\n\t[Ctb][Moench] Absolute "
"phase "
"shift. If deg used, then shift in degrees. Changing adcclk also "
"resets adcphase and sets it to previous values.\n\t[Gotthard] "
"Relative phase shift"
<< '\n';
} else {
auto det_type = det->getDetectorType().squash(defs::GENERIC);
if (det_type == defs::EIGER ||
det_type == defs::MYTHEN3 ||
if (det_type == defs::EIGER || det_type == defs::MYTHEN3 ||
det_type == defs::GOTTHARD2) {
throw sls::RuntimeError("adcphase not implemented for this detector");
}
throw sls::RuntimeError(
"adcphase not implemented for this detector");
}
if (action == defs::GET_ACTION) {
Result<int> t;
if (args.empty()) {
@ -416,7 +420,8 @@ std::string CmdProxy::Adcphase(int action) {
os << OutString(t) << '\n';
} else if (args.size() == 1) {
if (args[0] != "deg") {
throw sls::RuntimeError("Unknown adcphase argument " + args[0] +
throw sls::RuntimeError("Unknown adcphase argument " +
args[0] +
". Did you mean deg? ");
}
t = det->getADCPhaseInDegrees({det_id});
@ -426,14 +431,14 @@ std::string CmdProxy::Adcphase(int action) {
}
} else if (action == defs::PUT_ACTION) {
if (args.size() == 1) {
det->setADCPhase(StringTo<int>(args[0]), {det_id} );
det->setADCPhase(StringTo<int>(args[0]), {det_id});
os << args.front() << '\n';
} else if (args.size() == 2) {
if (args[1] != "deg") {
throw sls::RuntimeError("Unknown adcphase 2nd argument " +
args[1] + ". Did you mean deg?");
}
det->setADCPhaseInDegrees(StringTo<int>(args[0]) , {det_id});
det->setADCPhaseInDegrees(StringTo<int>(args[0]), {det_id});
os << args[0] << " " << args[1] << '\n';
} else {
WrongNumberOfParameters(1);
@ -449,17 +454,19 @@ std::string CmdProxy::Dbitphase(int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "[n_value] [(optional)deg]\n\t[Ctb][Jungfrau] Phase shift of clock to "
os << "[n_value] [(optional)deg]\n\t[Ctb][Jungfrau] Phase shift of "
"clock to "
"latch digital bits. Absolute phase shift. If deg used, then "
"shift in degrees. \n\t[Ctb]Changing dbitclk also resets dbitphase and "
"shift in degrees. \n\t[Ctb]Changing dbitclk also resets "
"dbitphase and "
"sets to previous values."
<< '\n';
} else {
auto det_type = det->getDetectorType().squash(defs::GENERIC);
if (det_type == defs::EIGER ||
det_type == defs::MYTHEN3 ||
if (det_type == defs::EIGER || det_type == defs::MYTHEN3 ||
det_type == defs::GOTTHARD2) {
throw sls::RuntimeError("dbitphase not implemented for this detector");
throw sls::RuntimeError(
"dbitphase not implemented for this detector");
}
if (action == defs::GET_ACTION) {
Result<int> t;
@ -485,7 +492,7 @@ std::string CmdProxy::Dbitphase(int action) {
throw sls::RuntimeError("Unknown dbitphase 2nd argument " +
args[1] + ". Did you mean deg? ");
}
det->setDBITPhaseInDegrees(StringTo<int>(args[0]), {det_id} );
det->setDBITPhaseInDegrees(StringTo<int>(args[0]), {det_id});
os << args[0] << " " << args[1] << '\n';
} else {
WrongNumberOfParameters(1);
@ -507,7 +514,8 @@ std::string CmdProxy::ClockFrequency(int action) {
} else {
defs::detectorType type = det->getDetectorType().squash(defs::GENERIC);
if (type != defs::GOTTHARD2 && type != defs::MYTHEN3) {
throw sls::RuntimeError("clkfreq not implemented for this detector.");
throw sls::RuntimeError(
"clkfreq not implemented for this detector.");
}
if (action == defs::GET_ACTION) {
if (args.size() != 1) {
@ -519,8 +527,8 @@ std::string CmdProxy::ClockFrequency(int action) {
if (args.size() != 2) {
WrongNumberOfParameters(2);
}
det->setClockFrequency(StringTo<int>(args[0]), StringTo<int>(args[1]),
{det_id});
det->setClockFrequency(StringTo<int>(args[0]),
StringTo<int>(args[1]), {det_id});
os << StringTo<int>(args[1]) << '\n';
} else {
throw sls::RuntimeError("Unknown action");
@ -541,7 +549,8 @@ std::string CmdProxy::ClockPhase(int action) {
} else {
defs::detectorType type = det->getDetectorType().squash(defs::GENERIC);
if (type != defs::GOTTHARD2 && type != defs::MYTHEN3) {
throw sls::RuntimeError("clkphase not implemented for this detector.");
throw sls::RuntimeError(
"clkphase not implemented for this detector.");
}
if (action == defs::GET_ACTION) {
if (args.size() == 1) {
@ -552,16 +561,16 @@ std::string CmdProxy::ClockPhase(int action) {
throw sls::RuntimeError("Cannot scan argument" + args[1] +
". Did you mean deg?");
}
auto t =
det->getClockPhaseinDegrees(StringTo<int>(args[0]), {det_id});
auto t = det->getClockPhaseinDegrees(StringTo<int>(args[0]),
{det_id});
os << OutString(t) << " deg\n";
} else {
WrongNumberOfParameters(1);
}
} else if (action == defs::PUT_ACTION) {
if (args.size() == 2) {
det->setClockPhase(StringTo<int>(args[0]), StringTo<int>(args[1]),
{det_id});
det->setClockPhase(StringTo<int>(args[0]),
StringTo<int>(args[1]), {det_id});
os << args[1] << '\n';
} else if (args.size() == 3) {
if (args[2] != "deg") {
@ -591,13 +600,15 @@ std::string CmdProxy::MaxClockPhaseShift(int action) {
} else {
defs::detectorType type = det->getDetectorType().squash(defs::GENERIC);
if (type != defs::GOTTHARD2 && type != defs::MYTHEN3) {
throw sls::RuntimeError("maxclkphaseshift not implemented for this detector.");
throw sls::RuntimeError(
"maxclkphaseshift not implemented for this detector.");
}
if (action == defs::GET_ACTION) {
if (args.size() != 1) {
WrongNumberOfParameters(1);
}
auto t = det->getMaxClockPhaseShift(StringTo<int>(args[0]), {det_id});
auto t =
det->getMaxClockPhaseShift(StringTo<int>(args[0]), {det_id});
os << OutString(t) << '\n';
} else if (action == defs::PUT_ACTION) {
throw sls::RuntimeError("Cannot put");
@ -618,7 +629,8 @@ std::string CmdProxy::ClockDivider(int action) {
} else {
defs::detectorType type = det->getDetectorType().squash(defs::GENERIC);
if (type != defs::GOTTHARD2 && type != defs::MYTHEN3) {
throw sls::RuntimeError("clkdiv not implemented for this detector.");
throw sls::RuntimeError(
"clkdiv not implemented for this detector.");
}
if (action == defs::GET_ACTION) {
if (args.size() != 1) {
@ -649,8 +661,11 @@ std::string CmdProxy::Dac(int action) {
os << "[dac index] [dac or mv value] [(optional unit) mv] "
"\n\t[Ctb] Dac."
<< '\n';
} else if (det->getDetectorType().squash(defs::GENERIC) != defs::CHIPTESTBOARD) {
throw sls::RuntimeError("Dac command can only be used for chip test board. Use daclist to get list of dac commands for current detector.");
} else if (det->getDetectorType().squash(defs::GENERIC) !=
defs::CHIPTESTBOARD) {
throw sls::RuntimeError(
"Dac command can only be used for chip test board. Use daclist to "
"get list of dac commands for current detector.");
} else if (action == defs::GET_ACTION) {
bool mv = false;
if (args.size() == 2) {
@ -662,8 +677,8 @@ std::string CmdProxy::Dac(int action) {
} else if (args.size() > 2) {
WrongNumberOfParameters(1);
}
auto t = det->getDAC(static_cast<defs::dacIndex>(StringTo<int>(args[0])),
mv, {det_id});
auto t = det->getDAC(
static_cast<defs::dacIndex>(StringTo<int>(args[0])), mv, {det_id});
os << args[0] << ' ' << OutString(t)
<< (args.size() > 1 ? " mv\n" : "\n");
} else if (action == defs::PUT_ACTION) {
@ -757,10 +772,10 @@ std::vector<std::string> CmdProxy::DacCommands() {
break;
case defs::GOTTHARD2:
return std::vector<std::string>{
"vref_h_adc", "vb_comp_fe", "vb_comp_adc", "vcom_cds",
"vref_h_adc", "vb_comp_fe", "vb_comp_adc", "vcom_cds",
"vref_rstore", "vb_opa_1st", "vref_comp_fe", "vcom_adc1",
"vref_prech", "vref_l_adc", "vref_cds", "vb_cs",
"vb_opa_fd", "vcom_adc2"};
"vref_prech", "vref_l_adc", "vref_cds", "vb_cs",
"vb_opa_fd", "vcom_adc2"};
break;
case defs::MYTHEN3:
return std::vector<std::string>{
@ -769,9 +784,9 @@ std::vector<std::string> CmdProxy::DacCommands() {
"viinsh", "vph", "vtrim", "vdcsh"};
break;
case defs::MOENCH:
return std::vector<std::string>{"vbp_colbuf", "vipre", "vin_cm",
"vb_sda", "vcasc_sfp", "vout_cm",
"vipre_cds", "ibias_sfp"};
return std::vector<std::string>{"vbp_colbuf", "vipre", "vin_cm",
"vb_sda", "vcasc_sfp", "vout_cm",
"vipre_cds", "ibias_sfp"};
break;
case defs::CHIPTESTBOARD:
return std::vector<std::string>{
@ -790,8 +805,7 @@ std::string CmdProxy::ReceiverStatus(int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "running, idle]\n\tReceiver listener status."
<< '\n';
os << "running, idle]\n\tReceiver listener status." << '\n';
} else if (action == defs::GET_ACTION) {
if (args.size() != 0) {
WrongNumberOfParameters(0);
@ -799,7 +813,8 @@ std::string CmdProxy::ReceiverStatus(int action) {
auto t = det->getReceiverStatus({det_id});
os << OutString(t) << '\n';
} else if (action == defs::PUT_ACTION) {
throw sls::RuntimeError("Cannot put. Did you mean to use command 'rx_start' or 'rx_stop'?");
throw sls::RuntimeError(
"Cannot put. Did you mean to use command 'rx_start' or 'rx_stop'?");
} else {
throw sls::RuntimeError("Unknown action");
}
@ -810,8 +825,9 @@ std::string CmdProxy::DetectorStatus(int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "[running, error, transmitting, finished, waiting, idle]\n\tDetector status."
<< '\n';
os << "[running, error, transmitting, finished, waiting, "
"idle]\n\tDetector status."
<< '\n';
} else if (action == defs::GET_ACTION) {
if (args.size() != 0) {
WrongNumberOfParameters(0);
@ -819,7 +835,8 @@ std::string CmdProxy::DetectorStatus(int action) {
auto t = det->getDetectorStatus({det_id});
os << OutString(t) << '\n';
} else if (action == defs::PUT_ACTION) {
throw sls::RuntimeError("Cannot put. Did you mean to use command 'start' or 'stop'?");
throw sls::RuntimeError(
"Cannot put. Did you mean to use command 'start' or 'stop'?");
} else {
throw sls::RuntimeError("Unknown action");
}
@ -832,8 +849,10 @@ std::string CmdProxy::UDPDestinationIP(int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "[x.x.x.x] or auto\n\tIp address of the receiver (destination) udp interface. If 'auto' used, then ip is set to ip of rx_hostname."
<< '\n';
os << "[x.x.x.x] or auto\n\tIp address of the receiver (destination) "
"udp interface. If 'auto' used, then ip is set to ip of "
"rx_hostname."
<< '\n';
} else if (action == defs::GET_ACTION) {
auto t = det->getDestinationUDPIP({det_id});
if (args.size() != 0) {
@ -845,14 +864,15 @@ std::string CmdProxy::UDPDestinationIP(int action) {
WrongNumberOfParameters(1);
}
if (args[0] == "auto") {
std::string rxHostname = det->getRxHostname({det_id}).squash("none");
std::string rxHostname =
det->getRxHostname({det_id}).squash("none");
// Hostname could be ip try to decode otherwise look up the hostname
auto val = sls::IpAddr{rxHostname};
if (val == 0) {
val = HostnameToIp(rxHostname.c_str());
}
LOG(logINFO) << "Setting udp_dstip of detector " <<
det_id << " to " << val;
LOG(logINFO) << "Setting udp_dstip of detector " << det_id << " to "
<< val;
det->setDestinationUDPIP(val, {det_id});
os << val << '\n';
} else {
@ -870,8 +890,11 @@ std::string CmdProxy::UDPDestinationIP2(int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "[x.x.x.x] or auto\n\t[Jungfrau] Ip address of the receiver (destination) udp interface where the second half of detector data is sent to. If 'auto' used, then ip is set to ip of rx_hostname."
<< '\n';
os << "[x.x.x.x] or auto\n\t[Jungfrau] Ip address of the receiver "
"(destination) udp interface where the second half of detector "
"data is sent to. If 'auto' used, then ip is set to ip of "
"rx_hostname."
<< '\n';
} else if (action == defs::GET_ACTION) {
auto t = det->getDestinationUDPIP2({det_id});
if (args.size() != 0) {
@ -883,14 +906,15 @@ std::string CmdProxy::UDPDestinationIP2(int action) {
WrongNumberOfParameters(1);
}
if (args[0] == "auto") {
std::string rxHostname = det->getRxHostname({det_id}).squash("none");
std::string rxHostname =
det->getRxHostname({det_id}).squash("none");
// Hostname could be ip try to decode otherwise look up the hostname
auto val = sls::IpAddr{rxHostname};
if (val == 0) {
val = HostnameToIp(rxHostname.c_str());
}
LOG(logINFO) << "Setting udp_dstip2 of detector " <<
det_id << " to " << val;
LOG(logINFO) << "Setting udp_dstip2 of detector " << det_id
<< " to " << val;
det->setDestinationUDPIP2(val, {det_id});
os << val << '\n';
} else {
@ -910,11 +934,13 @@ std::string CmdProxy::ReceiveHostname(int action) {
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "[hostname or ip address]\n\t"
"[hostname or ip address]:[tcp port]\n\t"
"[hostname1]:[tcp_port1]+[hostname2]:[tcp_port2]+\n\t"
"Receiver hostname or IP. If port included, then the receiver tcp port.\n\t"
"Used for TCP control communication between client and receiver "
"to configure receiver. Also updates receiver with detector parameters."
"[hostname or ip address]:[tcp port]\n\t"
"[hostname1]:[tcp_port1]+[hostname2]:[tcp_port2]+\n\t"
"Receiver hostname or IP. If port included, then the receiver "
"tcp port.\n\t"
"Used for TCP control communication between client and receiver "
"to configure receiver. Also updates receiver with detector "
"parameters."
<< '\n';
} else if (action == defs::GET_ACTION) {
if (!args.empty()) {
@ -930,10 +956,12 @@ std::string CmdProxy::ReceiveHostname(int action) {
if (args.size() > 1) {
// multiple in mulitple
if (args[0].find('+') != std::string::npos) {
throw sls::RuntimeError("Cannot add multiple receivers at module level");
throw sls::RuntimeError(
"Cannot add multiple receivers at module level");
}
if (det_id != -1) {
throw sls::RuntimeError("Cannot add multiple receivers at module level");
throw sls::RuntimeError(
"Cannot add multiple receivers at module level");
}
det->setRxHostname(args);
os << ToString(args) << '\n';
@ -943,7 +971,8 @@ std::string CmdProxy::ReceiveHostname(int action) {
// multiple receivers concatenated with +
if (args[0].find('+') != std::string::npos) {
if (det_id != -1) {
throw sls::RuntimeError("Cannot add multiple receivers at module level");
throw sls::RuntimeError(
"Cannot add multiple receivers at module level");
}
auto t = sls::split(args[0], '+');
det->setRxHostname(t);
@ -997,8 +1026,10 @@ std::string CmdProxy::Threshold(int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "[eV] [(optinal settings) standard, lowgain, veryhighgain, verylowgain]"
"\n\t[Eiger] Threshold in eV" << '\n';
os << "[eV] [(optinal settings) standard, lowgain, veryhighgain, "
"verylowgain]"
"\n\t[Eiger] Threshold in eV"
<< '\n';
} else if (action == defs::GET_ACTION) {
if (!args.empty()) {
WrongNumberOfParameters(0);
@ -1029,8 +1060,9 @@ std::string CmdProxy::ThresholdNoTb(int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "[eV] [(optional settings) standard, lowgain, veryhighgain, verylowgain]"
"\n\t[Eiger] Threshold in eV set without setting trimbits"
os << "[eV] [(optional settings) standard, lowgain, veryhighgain, "
"verylowgain]"
"\n\t[Eiger] Threshold in eV set without setting trimbits"
<< '\n';
} else if (action == defs::GET_ACTION) {
throw sls::RuntimeError("cannot get");
@ -1058,12 +1090,12 @@ std::string CmdProxy::GapPixels(int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "[0, 1]\n\t[Eiger][Jungfrau] Include Gap pixels only in data call back."
os << "[0, 1]\n\t[Eiger][Jungfrau] Include Gap pixels only in data "
"call back."
<< '\n';
} else if (action == defs::GET_ACTION) {
if (det_id != -1) {
throw sls::RuntimeError(
"Cannot get gap pixels at module level");
throw sls::RuntimeError("Cannot get gap pixels at module level");
}
if (!args.empty()) {
WrongNumberOfParameters(0);
@ -1072,8 +1104,7 @@ std::string CmdProxy::GapPixels(int action) {
os << t << '\n';
} else if (action == defs::PUT_ACTION) {
if (det_id != -1) {
throw sls::RuntimeError(
"Cannot add gap pixels at module level");
throw sls::RuntimeError("Cannot add gap pixels at module level");
}
if (args.size() != 1) {
WrongNumberOfParameters(1);
@ -1283,8 +1314,7 @@ std::string CmdProxy::Quad(int action) {
os << OutString(t) << '\n';
} else if (action == defs::PUT_ACTION) {
if (det_id != -1) {
throw sls::RuntimeError(
"Cannot execute quad at module level");
throw sls::RuntimeError("Cannot execute quad at module level");
}
if (args.size() != 1) {
WrongNumberOfParameters(1);
@ -1410,7 +1440,8 @@ std::string CmdProxy::InjectChannel(int action) {
if (args.size() != 2) {
WrongNumberOfParameters(2);
}
det->setInjectChannel(StringTo<int>(args[0]), StringTo<int>(args[1]), {det_id});
det->setInjectChannel(StringTo<int>(args[0]), StringTo<int>(args[1]),
{det_id});
os << sls::ToString(args) << '\n';
} else {
throw sls::RuntimeError("Unknown action");
@ -1459,7 +1490,8 @@ std::string CmdProxy::VetoReference(int action) {
if (args.size() != 2) {
WrongNumberOfParameters(2);
}
det->setVetoReference(StringTo<int>(args[0]), StringTo<int>(args[1]), {det_id});
det->setVetoReference(StringTo<int>(args[0]), StringTo<int>(args[1]),
{det_id});
os << sls::ToString(args) << '\n';
} else {
throw sls::RuntimeError("Unknown action");
@ -1471,7 +1503,8 @@ std::string CmdProxy::BurstMode(int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "[off or 0, internal or 1, external or 2]\n\t[Gotthard2] Default is burst internal type"
os << "[off or 0, internal or 1, external or 2]\n\t[Gotthard2] Default "
"is burst internal type"
<< '\n';
} else {
if (action == defs::GET_ACTION) {
@ -1527,7 +1560,7 @@ std::string CmdProxy::Counters(int action) {
}
auto mask = det->getCounterMask({det_id}).squash(-1);
// scan counter enable mask to get vector
std::vector <int> result;
std::vector<int> result;
for (size_t i = 0; i < 32; ++i) {
if (mask & (1 << i)) {
result.push_back(static_cast<int>(i));
@ -1579,7 +1612,7 @@ std::string CmdProxy::Samples(int action) {
int ds = d.squash(-1);
if (as == -1 || ds == -1 || as != ds) { // check if a == d?
throw sls::RuntimeError(
"Different samples. Use asamples or dsamples.");
"Different samples. Use asamples or dsamples.");
}
}
os << OutString(a) << '\n';
@ -1691,7 +1724,8 @@ std::string CmdProxy::DigitalIODelay(int action) {
if (args.size() != 2) {
WrongNumberOfParameters(2);
}
det->setDigitalIODelay(StringTo<uint64_t>(args[0]), StringTo<int>(args[1]), {det_id});
det->setDigitalIODelay(StringTo<uint64_t>(args[0]),
StringTo<int>(args[1]), {det_id});
os << sls::ToString(args) << '\n';
} else {
throw sls::RuntimeError("Unknown action");
@ -1705,7 +1739,8 @@ std::string CmdProxy::Pattern(int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "[fname]\n\t[Mythen3][Moench][Ctb][Moench] Loads binary pattern file with only pattern "
os << "[fname]\n\t[Mythen3][Moench][Ctb][Moench] Loads binary pattern "
"file with only pattern "
"words"
<< '\n';
} else if (action == defs::GET_ACTION) {
@ -1726,7 +1761,8 @@ std::string CmdProxy::PatternWord(int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "[step or address] [64 bit mask]\n\t[Ctb][Moench][Mythen3] 64 bit pattern at "
os << "[step or address] [64 bit mask]\n\t[Ctb][Moench][Mythen3] 64 "
"bit pattern at "
"address of pattern memory."
<< '\n';
} else if (action == defs::GET_ACTION) {
@ -1739,7 +1775,8 @@ std::string CmdProxy::PatternWord(int action) {
if (args.size() != 2) {
WrongNumberOfParameters(2);
}
det->setPatternWord(StringTo<int>(args[0]), StringTo<uint64_t>(args[1]), {det_id});
det->setPatternWord(StringTo<int>(args[0]), StringTo<uint64_t>(args[1]),
{det_id});
os << sls::ToString(args) << '\n';
} else {
throw sls::RuntimeError("Unknown action");
@ -1752,17 +1789,21 @@ std::string CmdProxy::PatternLoopAddresses(int action) {
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
if (cmd == "patlimits") {
os << "[start addr] [stop addr] \n\t[Ctb][Moench][Mythen3] Limits of complete "
os << "[start addr] [stop addr] \n\t[Ctb][Moench][Mythen3] Limits "
"of complete "
"pattern."
<< '\n';
} else if (cmd == "patloop0") {
os << "[start addr] [stop addr] \n\t[Ctb][Moench][Mythen3] Limits of loop 0."
os << "[start addr] [stop addr] \n\t[Ctb][Moench][Mythen3] Limits "
"of loop 0."
<< '\n';
} else if (cmd == "patloop1") {
os << "[start addr] [stop addr] \n\t[Ctb][Moench][Mythen3] Limits of loop 1."
os << "[start addr] [stop addr] \n\t[Ctb][Moench][Mythen3] Limits "
"of loop 1."
<< '\n';
} else if (cmd == "patloop2") {
os << "[start addr] [stop addr] \n\t[Ctb][Moench][Mythen3] Limits of loop 2."
os << "[start addr] [stop addr] \n\t[Ctb][Moench][Mythen3] Limits "
"of loop 2."
<< '\n';
} else {
throw sls::RuntimeError(
@ -1807,11 +1848,17 @@ std::string CmdProxy::PatternLoopCycles(int action) {
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
if (cmd == "patnloop0") {
os << "[n_cycles] \n\t[Ctb][Moench][Mythen3] Number of cycles of loop 0." << '\n';
os << "[n_cycles] \n\t[Ctb][Moench][Mythen3] Number of cycles of "
"loop 0."
<< '\n';
} else if (cmd == "patnloop1") {
os << "[n_cycles] \n\t[Ctb][Moench][Mythen3] Number of cycles of loop 1." << '\n';
os << "[n_cycles] \n\t[Ctb][Moench][Mythen3] Number of cycles of "
"loop 1."
<< '\n';
} else if (cmd == "patnloop2") {
os << "[n_cycles] \n\t[Ctb][Moench][Mythen3] Number of cycles of loop 2." << '\n';
os << "[n_cycles] \n\t[Ctb][Moench][Mythen3] Number of cycles of "
"loop 2."
<< '\n';
} else {
throw sls::RuntimeError(
"Unknown command, use list to list all commands");
@ -1897,11 +1944,17 @@ std::string CmdProxy::PatternWaitTime(int action) {
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
if (cmd == "patwaittime0") {
os << "[n_clk] \n\t[Ctb][Moench][Mythen3] Wait 0 time in clock cycles." << '\n';
os << "[n_clk] \n\t[Ctb][Moench][Mythen3] Wait 0 time in clock "
"cycles."
<< '\n';
} else if (cmd == "patwaittime1") {
os << "[n_clk] \n\t[Ctb][Moench][Mythen3] Wait 1 time in clock cycles." << '\n';
os << "[n_clk] \n\t[Ctb][Moench][Mythen3] Wait 1 time in clock "
"cycles."
<< '\n';
} else if (cmd == "patwaittime2") {
os << "[n_clk] \n\t[Ctb][Moench][Mythen3] Wait 2 time in clock cycles." << '\n';
os << "[n_clk] \n\t[Ctb][Moench][Mythen3] Wait 2 time in clock "
"cycles."
<< '\n';
} else {
throw sls::RuntimeError(
"Unknown command, use list to list all commands");
@ -1928,7 +1981,8 @@ std::string CmdProxy::PatternWaitTime(int action) {
if (args.size() != 1) {
WrongNumberOfParameters(1);
}
det->setPatternWaitTime(level, StringTo<uint64_t>(args[0]), {det_id});
det->setPatternWaitTime(level, StringTo<uint64_t>(args[0]),
{det_id});
os << args.front() << '\n';
} else {
throw sls::RuntimeError("Unknown action");
@ -1944,9 +1998,11 @@ std::string CmdProxy::AdditionalJsonHeader(int action) {
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "[key1] [value1] [key2] [value2]...[keyn] [valuen]"
"\n\tAdditional json header to be streamed out from receiver via zmq. "
"Default is empty. Use only if to be processed by an intermediate user process "
"listening to receiver zmq packets. Empty value deletes header. "
"\n\tAdditional json header to be streamed out from receiver via "
"zmq. "
"Default is empty. Use only if to be processed by an "
"intermediate user process "
"listening to receiver zmq packets. Empty value deletes header. "
<< '\n';
} else if (action == defs::GET_ACTION) {
if (args.size() != 0) {
@ -1978,7 +2034,8 @@ std::string CmdProxy::JsonParameter(int action) {
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "[key1] [value1]\n\tAdditional json header parameter streamed "
"out from receiver. If not found in header, the pair is appended. "
"out from receiver. If not found in header, the pair is "
"appended. "
"An empty values deletes parameter."
<< '\n';
} else if (action == defs::GET_ACTION) {
@ -1989,14 +2046,14 @@ std::string CmdProxy::JsonParameter(int action) {
os << OutString(t) << '\n';
} else if (action == defs::PUT_ACTION) {
switch (args.size()) {
case 1:
det->setAdditionalJsonParameter(args[0], "", {det_id});
break;
case 2:
det->setAdditionalJsonParameter(args[0], args[1], {det_id});
break;
default:
WrongNumberOfParameters(1);
case 1:
det->setAdditionalJsonParameter(args[0], "", {det_id});
break;
case 2:
det->setAdditionalJsonParameter(args[0], args[1], {det_id});
break;
default:
WrongNumberOfParameters(1);
}
if (args.size() == 1) {
os << args[0] << " deleted" << '\n';
@ -2061,9 +2118,9 @@ std::string CmdProxy::ProgramFpga(int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "[fname.pof | fname.rbf]\n\t[Jungfrau][Ctb][Moench] Programs FPGA from pof file."
<< "\n\t[Mythen3][Gotthard2] Programs FPGA from rbf file."
<< '\n';
os << "[fname.pof | fname.rbf]\n\t[Jungfrau][Ctb][Moench] Programs "
"FPGA from pof file."
<< "\n\t[Mythen3][Gotthard2] Programs FPGA from rbf file." << '\n';
} else if (action == defs::GET_ACTION) {
throw sls::RuntimeError("Cannot get");
} else if (action == defs::PUT_ACTION) {
@ -2082,7 +2139,8 @@ std::string CmdProxy::CopyDetectorServer(int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "[server_name] [pc_host_name]\n\t[Jungfrau][Ctb][Moench] Copies detector "
os << "[server_name] [pc_host_name]\n\t[Jungfrau][Ctb][Moench] Copies "
"detector "
"server via tftp from pc and changes respawn server name in "
"/etc/inittab of detector."
<< '\n';
@ -2104,7 +2162,8 @@ std::string CmdProxy::UpdateFirmwareAndDetectorServer(int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "[server_name] [pc_host_name] [fname.pof]\n\t[Jungfrau][Ctb][Moench] "
os << "[server_name] [pc_host_name] "
"[fname.pof]\n\t[Jungfrau][Ctb][Moench] "
"Updates detector server via tftp from pc, updates firmware to "
"pof file and then reboots controller (blackfin)."
<< '\n';
@ -2142,7 +2201,8 @@ std::string CmdProxy::Register(int action) {
if (args.size() != 2) {
WrongNumberOfParameters(2);
}
det->writeRegister(StringTo<uint32_t>(args[0]), StringTo<uint32_t>(args[1]), {det_id});
det->writeRegister(StringTo<uint32_t>(args[0]),
StringTo<uint32_t>(args[1]), {det_id});
os << sls::ToString(args) << '\n';
} else {
throw sls::RuntimeError("Unknown action");
@ -2154,7 +2214,8 @@ std::string CmdProxy::AdcRegister(int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "[address] [value]\n\t[Jungfrau][Ctb][Moench][Gotthard] Writes to an adc "
os << "[address] [value]\n\t[Jungfrau][Ctb][Moench][Gotthard] Writes "
"to an adc "
"register in hex."
<< '\n';
} else if (action == defs::GET_ACTION) {
@ -2163,7 +2224,8 @@ std::string CmdProxy::AdcRegister(int action) {
if (args.size() != 2) {
WrongNumberOfParameters(2);
}
det->writeAdcRegister(StringTo<uint32_t>(args[0]), StringTo<uint32_t>(args[1]), {det_id});
det->writeAdcRegister(StringTo<uint32_t>(args[0]),
StringTo<uint32_t>(args[1]), {det_id});
os << sls::ToString(args) << '\n';
} else {
throw sls::RuntimeError("Unknown action");
@ -2236,7 +2298,10 @@ std::string CmdProxy::InitialChecks(int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "[0, 1]\n\tEnable or disable intial compatibility and other checks at detector start up. It is enabled by default. Must come before 'hostname' command to take effect. Can be used to reprogram fpga when current firmware is incompatible."
os << "[0, 1]\n\tEnable or disable intial compatibility and other "
"checks at detector start up. It is enabled by default. Must "
"come before 'hostname' command to take effect. Can be used to "
"reprogram fpga when current firmware is incompatible."
<< '\n';
} else if (action == defs::GET_ACTION) {
if (det_id != -1) {
@ -2264,7 +2329,6 @@ std::string CmdProxy::InitialChecks(int action) {
return os.str();
}
/* Insignificant */
std::string CmdProxy::ExecuteCommand(int action) {

File diff suppressed because it is too large Load Diff

View File

@ -1,11 +1,11 @@
#include "Detector.h"
#include "CmdParser.h"
#include "CmdProxy.h"
#include "DetectorImpl.h"
#include "Module.h"
#include "container_utils.h"
#include "detectorData.h"
#include "logger.h"
#include "DetectorImpl.h"
#include "Module.h"
#include "sls_detector_defs.h"
#include "versionAPI.h"
@ -72,8 +72,8 @@ void Detector::loadParameters(const std::string &fname) {
if (current_line.find('#') != std::string::npos) {
current_line.erase(current_line.find('#'));
}
LOG(logDEBUG1)
<< "current_line after removing comments:\n\t" << current_line;
LOG(logDEBUG1) << "current_line after removing comments:\n\t"
<< current_line;
if (current_line.length() > 1) {
parser.Parse(current_line);
proxy.Call(parser.command(), parser.arguments(),
@ -97,13 +97,9 @@ void Detector::setVirtualDetectorServers(int numServers, int startingPort) {
int Detector::getShmId() const { return pimpl->getMultiId(); }
std::string Detector::getPackageVersion() const {
return GITBRANCH;
}
std::string Detector::getPackageVersion() const { return GITBRANCH; }
int64_t Detector::getClientVersion() const {
return APILIB;
}
int64_t Detector::getClientVersion() const { return APILIB; }
Result<int64_t> Detector::getFirmwareVersion(Positions pos) const {
return pimpl->Parallel(&Module::getFirmwareVersion, pos);
@ -242,8 +238,7 @@ void Detector::setTimingMode(defs::timingMode value, Positions pos) {
}
Result<defs::speedLevel> Detector::getSpeed(Positions pos) const {
auto res =
pimpl->Parallel(&Module::getClockDivider, pos, defs::RUN_CLOCK);
auto res = pimpl->Parallel(&Module::getClockDivider, pos, defs::RUN_CLOCK);
Result<defs::speedLevel> speedResult(res.size());
for (unsigned int i = 0; i < res.size(); ++i) {
speedResult[i] = static_cast<defs::speedLevel>(res[i]);
@ -257,13 +252,11 @@ void Detector::setSpeed(defs::speedLevel value, Positions pos) {
}
Result<int> Detector::getADCPhase(Positions pos) const {
return pimpl->Parallel(&Module::getClockPhase, pos, defs::ADC_CLOCK,
false);
return pimpl->Parallel(&Module::getClockPhase, pos, defs::ADC_CLOCK, false);
}
void Detector::setADCPhase(int value, Positions pos) {
pimpl->Parallel(&Module::setClockPhase, pos, defs::ADC_CLOCK, value,
false);
pimpl->Parallel(&Module::setClockPhase, pos, defs::ADC_CLOCK, value, false);
}
Result<int> Detector::getMaxADCPhaseShift(Positions pos) const {
@ -272,13 +265,11 @@ Result<int> Detector::getMaxADCPhaseShift(Positions pos) const {
}
Result<int> Detector::getADCPhaseInDegrees(Positions pos) const {
return pimpl->Parallel(&Module::getClockPhase, pos, defs::ADC_CLOCK,
true);
return pimpl->Parallel(&Module::getClockPhase, pos, defs::ADC_CLOCK, true);
}
void Detector::setADCPhaseInDegrees(int value, Positions pos) {
pimpl->Parallel(&Module::setClockPhase, pos, defs::ADC_CLOCK, value,
true);
pimpl->Parallel(&Module::setClockPhase, pos, defs::ADC_CLOCK, value, true);
}
Result<int> Detector::getDBITPhase(Positions pos) const {
@ -297,13 +288,11 @@ Result<int> Detector::getMaxDBITPhaseShift(Positions pos) const {
}
Result<int> Detector::getDBITPhaseInDegrees(Positions pos) const {
return pimpl->Parallel(&Module::getClockPhase, pos, defs::DBIT_CLOCK,
true);
return pimpl->Parallel(&Module::getClockPhase, pos, defs::DBIT_CLOCK, true);
}
void Detector::setDBITPhaseInDegrees(int value, Positions pos) {
pimpl->Parallel(&Module::setClockPhase, pos, defs::DBIT_CLOCK, value,
true);
pimpl->Parallel(&Module::setClockPhase, pos, defs::DBIT_CLOCK, value, true);
}
Result<int> Detector::getClockFrequency(int clkIndex, Positions pos) {
@ -343,8 +332,7 @@ void Detector::setClockDivider(int clkIndex, int value, Positions pos) {
}
Result<int> Detector::getHighVoltage(Positions pos) const {
return pimpl->Parallel(&Module::setDAC, pos, -1, defs::HIGH_VOLTAGE,
0);
return pimpl->Parallel(&Module::setDAC, pos, -1, defs::HIGH_VOLTAGE, 0);
}
void Detector::setHighVoltage(int value, Positions pos) {
@ -430,13 +418,9 @@ void Detector::acquire() { pimpl->acquire(); }
void Detector::clearAcquiringFlag() { pimpl->setAcquiringFlag(0); }
void Detector::startReceiver() {
pimpl->Parallel(&Module::startReceiver, {});
}
void Detector::startReceiver() { pimpl->Parallel(&Module::startReceiver, {}); }
void Detector::stopReceiver() {
pimpl->Parallel(&Module::stopReceiver, {});
}
void Detector::stopReceiver() { pimpl->Parallel(&Module::stopReceiver, {}); }
void Detector::startDetector() {
if (getDetectorType().squash() == defs::EIGER) {
@ -445,9 +429,7 @@ void Detector::startDetector() {
pimpl->Parallel(&Module::startAcquisition, {});
}
void Detector::stopDetector() {
pimpl->Parallel(&Module::stopAcquisition, {});
}
void Detector::stopDetector() { pimpl->Parallel(&Module::stopAcquisition, {}); }
Result<defs::runStatus> Detector::getDetectorStatus(Positions pos) const {
return pimpl->Parallel(&Module::getRunStatus, pos);
@ -461,7 +443,8 @@ Result<int64_t> Detector::getFramesCaught(Positions pos) const {
return pimpl->Parallel(&Module::getFramesCaughtByReceiver, pos);
}
Result<std::vector<uint64_t>> Detector::getNumMissingPackets(Positions pos) const {
Result<std::vector<uint64_t>>
Detector::getNumMissingPackets(Positions pos) const {
return pimpl->Parallel(&Module::getNumMissingPackets, pos);
}
@ -607,8 +590,7 @@ void Detector::setDestinationUDPPort2(int port, int module_id) {
port_list[idet]);
}
} else {
pimpl->Parallel(&Module::setDestinationUDPPort2, {module_id},
port);
pimpl->Parallel(&Module::setDestinationUDPPort2, {module_id}, port);
}
}
@ -677,9 +659,9 @@ void Detector::setRxHostname(const std::vector<std::string> &name) {
pimpl->Parallel(&Module::setReceiverHostname, {}, name[0]);
} else {
if ((int)name.size() != size()) {
throw RuntimeError("Receiver hostnames size " +
std::to_string(name.size()) + " does not match detector size " +
std::to_string(size()));
throw RuntimeError(
"Receiver hostnames size " + std::to_string(name.size()) +
" does not match detector size " + std::to_string(size()));
}
// set each rx_hostname
for (int idet = 0; idet < size(); ++idet) {
@ -699,8 +681,7 @@ void Detector::setRxPort(int port, int module_id) {
it = port++;
}
for (int idet = 0; idet < size(); ++idet) {
pimpl->Parallel(&Module::setReceiverPort, {idet},
port_list[idet]);
pimpl->Parallel(&Module::setReceiverPort, {idet}, port_list[idet]);
}
} else {
pimpl->Parallel(&Module::setReceiverPort, {module_id}, port);
@ -751,8 +732,7 @@ void Detector::setRxUDPSocketBufferSize(int64_t udpsockbufsize, Positions pos) {
}
Result<int64_t> Detector::getRxRealUDPSocketBufferSize(Positions pos) const {
return pimpl->Parallel(&Module::getReceiverRealUDPSocketBufferSize,
pos);
return pimpl->Parallel(&Module::getReceiverRealUDPSocketBufferSize, pos);
}
Result<bool> Detector::getRxLock(Positions pos) {
@ -871,8 +851,7 @@ void Detector::setRxZmqPort(int port, int module_id) {
port_list[idet]);
}
} else {
pimpl->Parallel(&Module::setReceiverStreamingPort, {module_id},
port);
pimpl->Parallel(&Module::setReceiverStreamingPort, {module_id}, port);
}
}
@ -901,8 +880,7 @@ void Detector::setClientZmqPort(int port, int module_id) {
port_list[idet]);
}
} else {
pimpl->Parallel(&Module::setClientStreamingPort, {module_id},
port);
pimpl->Parallel(&Module::setClientStreamingPort, {module_id}, port);
}
}
@ -952,8 +930,8 @@ Result<int> Detector::getThresholdEnergy(Positions pos) const {
void Detector::setThresholdEnergy(int threshold_ev,
defs::detectorSettings settings,
bool trimbits, Positions pos) {
pimpl->Parallel(&Module::setThresholdEnergy, pos, threshold_ev,
settings, static_cast<int>(trimbits));
pimpl->Parallel(&Module::setThresholdEnergy, pos, threshold_ev, settings,
static_cast<int>(trimbits));
}
Result<std::string> Detector::getSettingsPath(Positions pos) const {
@ -1146,8 +1124,7 @@ void Detector::setAutoCompDisable(bool value, Positions pos) {
}
Result<int> Detector::getNumberOfAdditionalStorageCells(Positions pos) const {
return pimpl->Parallel(&Module::getNumberOfAdditionalStorageCells,
pos);
return pimpl->Parallel(&Module::getNumberOfAdditionalStorageCells, pos);
}
void Detector::setNumberOfAdditionalStorageCells(int value) {
@ -1224,19 +1201,26 @@ Result<std::array<int, 2>> Detector::getInjectChannel(Positions pos) {
return pimpl->Parallel(&Module::getInjectChannel, pos);
}
void Detector::setInjectChannel(const int offsetChannel, const int incrementChannel, Positions pos) {
pimpl->Parallel(&Module::setInjectChannel, pos, offsetChannel, incrementChannel);
void Detector::setInjectChannel(const int offsetChannel,
const int incrementChannel, Positions pos) {
pimpl->Parallel(&Module::setInjectChannel, pos, offsetChannel,
incrementChannel);
}
Result<std::vector<int>> Detector::getVetoPhoton(const int chipIndex, Positions pos) {
Result<std::vector<int>> Detector::getVetoPhoton(const int chipIndex,
Positions pos) {
return pimpl->Parallel(&Module::getVetoPhoton, pos, chipIndex);
}
void Detector::setVetoPhoton(const int chipIndex, const int numPhotons, const int energy, const std::string& fname, Positions pos) {
pimpl->Parallel(&Module::setVetoPhoton, pos, chipIndex, numPhotons, energy, fname);
void Detector::setVetoPhoton(const int chipIndex, const int numPhotons,
const int energy, const std::string &fname,
Positions pos) {
pimpl->Parallel(&Module::setVetoPhoton, pos, chipIndex, numPhotons, energy,
fname);
}
void Detector::setVetoReference(const int gainIndex, const int value, Positions pos) {
void Detector::setVetoReference(const int gainIndex, const int value,
Positions pos) {
pimpl->Parallel(&Module::setVetoReference, pos, gainIndex, value);
}
@ -1284,10 +1268,8 @@ void Detector::setNumberOfAnalogSamples(int value, Positions pos) {
pimpl->Parallel(&Module::setNumberOfAnalogSamples, pos, value);
}
Result<int> Detector::getADCClock(Positions pos) const {
return pimpl->Parallel(&Module::getClockFrequency, pos,
defs::ADC_CLOCK);
return pimpl->Parallel(&Module::getClockFrequency, pos, defs::ADC_CLOCK);
}
void Detector::setADCClock(int value_in_MHz, Positions pos) {
@ -1296,8 +1278,7 @@ void Detector::setADCClock(int value_in_MHz, Positions pos) {
}
Result<int> Detector::getRUNClock(Positions pos) const {
return pimpl->Parallel(&Module::getClockFrequency, pos,
defs::RUN_CLOCK);
return pimpl->Parallel(&Module::getClockFrequency, pos, defs::RUN_CLOCK);
}
void Detector::setRUNClock(int value_in_MHz, Positions pos) {
@ -1306,8 +1287,7 @@ void Detector::setRUNClock(int value_in_MHz, Positions pos) {
}
Result<int> Detector::getSYNCClock(Positions pos) const {
return pimpl->Parallel(&Module::getClockFrequency, pos,
defs::SYNC_CLOCK);
return pimpl->Parallel(&Module::getClockFrequency, pos, defs::SYNC_CLOCK);
}
Result<int> Detector::getADCPipeline(Positions pos) const {
@ -1372,7 +1352,6 @@ void Detector::setTenGigaADCEnableMask(uint32_t mask, Positions pos) {
// CTB Specific
Result<int> Detector::getNumberOfDigitalSamples(Positions pos) const {
return pimpl->Parallel(&Module::getNumberOfDigitalSamples, pos);
}
@ -1390,8 +1369,7 @@ void Detector::setReadoutMode(defs::readoutMode value, Positions pos) {
}
Result<int> Detector::getDBITClock(Positions pos) const {
return pimpl->Parallel(&Module::getClockFrequency, pos,
defs::DBIT_CLOCK);
return pimpl->Parallel(&Module::getClockFrequency, pos, defs::DBIT_CLOCK);
}
void Detector::setDBITClock(int value_in_MHz, Positions pos) {
@ -1461,7 +1439,7 @@ Result<std::vector<int>> Detector::getRxDbitList(Positions pos) const {
return pimpl->Parallel(&Module::getReceiverDbitList, pos);
}
void Detector::setRxDbitList(const std::vector<int>& list, Positions pos) {
void Detector::setRxDbitList(const std::vector<int> &list, Positions pos) {
pimpl->Parallel(&Module::setReceiverDbitList, pos, list);
}
@ -1507,22 +1485,10 @@ void Detector::savePattern(const std::string &fname) {
}
// rest of pattern file
const std::vector<std::string> commands{
"patioctrl",
"patclkctrl",
"patlimits",
"patloop0",
"patnloop0",
"patloop1",
"patnloop1",
"patloop2",
"patnloop2",
"patwait0",
"patwaittime0",
"patwait1",
"patwaittime1",
"patwait2",
"patwaittime2",
"patmask",
"patioctrl", "patclkctrl", "patlimits", "patloop0",
"patnloop0", "patloop1", "patnloop1", "patloop2",
"patnloop2", "patwait0", "patwaittime0", "patwait1",
"patwaittime1", "patwait2", "patwaittime2", "patmask",
"patsetbit",
};
for (const auto &cmd : commands)
@ -1559,14 +1525,13 @@ void Detector::setPatternWord(int addr, uint64_t word, Positions pos) {
Result<std::array<int, 2>>
Detector::getPatternLoopAddresses(int level, Positions pos) const {
return pimpl->Parallel(&Module::setPatternLoopAddresses, pos, level,
-1, -1);
return pimpl->Parallel(&Module::setPatternLoopAddresses, pos, level, -1,
-1);
}
void Detector::setPatternLoopAddresses(int level, int start, int stop,
Positions pos) {
pimpl->Parallel(&Module::setPatternLoopAddresses, pos, level, start,
stop);
pimpl->Parallel(&Module::setPatternLoopAddresses, pos, level, start, stop);
}
Result<int> Detector::getPatternLoopCycles(int level, Positions pos) const {
@ -1611,12 +1576,13 @@ void Detector::setPatternBitMask(uint64_t mask, Positions pos) {
// Moench
Result<std::map<std::string, std::string>> Detector::getAdditionalJsonHeader(Positions pos) const {
Result<std::map<std::string, std::string>>
Detector::getAdditionalJsonHeader(Positions pos) const {
return pimpl->Parallel(&Module::getAdditionalJsonHeader, pos);
}
void Detector::setAdditionalJsonHeader(const std::map<std::string, std::string> &jsonHeader,
Positions pos) {
void Detector::setAdditionalJsonHeader(
const std::map<std::string, std::string> &jsonHeader, Positions pos) {
pimpl->Parallel(&Module::setAdditionalJsonHeader, pos, jsonHeader);
}
@ -1625,7 +1591,8 @@ Result<std::string> Detector::getAdditionalJsonParameter(const std::string &key,
return pimpl->Parallel(&Module::getAdditionalJsonParameter, pos, key);
}
void Detector::setAdditionalJsonParameter(const std::string &key, const std::string &value,
void Detector::setAdditionalJsonParameter(const std::string &key,
const std::string &value,
Positions pos) {
pimpl->Parallel(&Module::setAdditionalJsonParameter, pos, key, value);
}
@ -1654,8 +1621,8 @@ void Detector::setDetectorMinMaxEnergyThreshold(const bool isEmax,
}
Result<defs::frameModeType> Detector::getFrameMode(Positions pos) const {
auto res = pimpl->Parallel(&Module::getAdditionalJsonParameter, pos,
"frameMode");
auto res =
pimpl->Parallel(&Module::getAdditionalJsonParameter, pos, "frameMode");
Result<defs::frameModeType> intResult(res.size());
try {
for (unsigned int i = 0; i < res.size(); ++i) {
@ -1691,8 +1658,8 @@ Result<defs::detectorModeType> Detector::getDetectorMode(Positions pos) const {
}
void Detector::setDetectorMode(defs::detectorModeType value, Positions pos) {
pimpl->Parallel(&Module::setAdditionalJsonParameter, pos,
"detectorMode", sls::ToString(value));
pimpl->Parallel(&Module::setAdditionalJsonParameter, pos, "detectorMode",
sls::ToString(value));
}
// Advanced
@ -1753,9 +1720,7 @@ void Detector::writeAdcRegister(uint32_t addr, uint32_t value, Positions pos) {
pimpl->Parallel(&Module::writeAdcRegister, pos, addr, value);
}
bool Detector::getInitialChecks() const {
return pimpl->getInitialChecks();
}
bool Detector::getInitialChecks() const { return pimpl->getInitialChecks(); }
void Detector::setInitialChecks(const bool value) {
pimpl->setInitialChecks(value);

269
slsDetectorSoftware/src/DetectorImpl.cpp Executable file → Normal file
View File

@ -1,10 +1,10 @@
#include "DetectorImpl.h"
#include "Module.h"
#include "SharedMemory.h"
#include "ZmqSocket.h"
#include "detectorData.h"
#include "file_utils.h"
#include "logger.h"
#include "Module.h"
#include "sls_detector_exceptions.h"
#include "versionAPI.h"
@ -26,7 +26,7 @@
#include <future>
#include <vector>
namespace sls{
namespace sls {
DetectorImpl::DetectorImpl(int multi_id, bool verify, bool update)
: multiId(multi_id), multi_shm(multi_id, -1) {
@ -137,11 +137,11 @@ void DetectorImpl::initSharedMemory(bool verify) {
multi_shm.OpenSharedMemory();
if (verify && multi_shm()->shmversion != MULTI_SHMVERSION) {
LOG(logERROR) << "Multi shared memory (" << multiId
<< ") version mismatch "
"(expected 0x"
<< std::hex << MULTI_SHMVERSION << " but got 0x"
<< multi_shm()->shmversion << std::dec
<< ". Clear Shared memory to continue.";
<< ") version mismatch "
"(expected 0x"
<< std::hex << MULTI_SHMVERSION << " but got 0x"
<< multi_shm()->shmversion << std::dec
<< ". Clear Shared memory to continue.";
throw SharedMemoryError("Shared memory version mismatch!");
}
}
@ -167,8 +167,7 @@ void DetectorImpl::initializeMembers(bool verify) {
// get objects from single det shared memory (open)
for (int i = 0; i < multi_shm()->numberOfDetectors; i++) {
try {
detectors.push_back(
sls::make_unique<Module>(multiId, i, verify));
detectors.push_back(sls::make_unique<Module>(multiId, i, verify));
} catch (...) {
detectors.clear();
throw;
@ -233,9 +232,8 @@ void DetectorImpl::setVirtualDetectorServers(const int numdet, const int port) {
void DetectorImpl::setHostname(const std::vector<std::string> &name) {
// this check is there only to allow the previous detsizechan command
if (multi_shm()->numberOfDetectors != 0) {
LOG(logWARNING)
<< "There are already detector(s) in shared memory."
"Freeing Shared memory now.";
LOG(logWARNING) << "There are already detector(s) in shared memory."
"Freeing Shared memory now.";
bool initialChecks = multi_shm()->initialChecks;
freeSharedMemory();
setupMultiDetector();
@ -273,8 +271,7 @@ void DetectorImpl::addSlsDetector(const std::string &hostname) {
// get type by connecting
detectorType type = Module::getTypeFromDetector(host, port);
auto pos = detectors.size();
detectors.emplace_back(
sls::make_unique<Module>(type, multiId, pos, false));
detectors.emplace_back(sls::make_unique<Module>(type, multiId, pos, false));
multi_shm()->numberOfDetectors = detectors.size();
detectors[pos]->setControlPort(port);
detectors[pos]->setStopPort(port + 1);
@ -309,13 +306,13 @@ void DetectorImpl::updateDetectorSize() {
multi_shm()->numberOfChannels.y = det_size.y * ndety;
LOG(logDEBUG) << "\n\tNumber of Detectors in X direction:"
<< multi_shm()->numberOfDetector.x
<< "\n\tNumber of Detectors in Y direction:"
<< multi_shm()->numberOfDetector.y
<< "\n\tNumber of Channels in X direction:"
<< multi_shm()->numberOfChannels.x
<< "\n\tNumber of Channels in Y direction:"
<< multi_shm()->numberOfChannels.y;
<< multi_shm()->numberOfDetector.x
<< "\n\tNumber of Detectors in Y direction:"
<< multi_shm()->numberOfDetector.y
<< "\n\tNumber of Channels in X direction:"
<< multi_shm()->numberOfChannels.x
<< "\n\tNumber of Channels in Y direction:"
<< multi_shm()->numberOfChannels.y;
for (auto &d : detectors) {
d->updateMultiSize(multi_shm()->numberOfDetector);
@ -347,20 +344,20 @@ bool DetectorImpl::getGapPixelsinCallback() const {
void DetectorImpl::setGapPixelsinCallback(const bool enable) {
if (enable) {
switch (multi_shm()->multiDetectorType) {
case JUNGFRAU:
case JUNGFRAU:
break;
case EIGER:
if (size() && detectors[0]->getQuad()) {
break;
case EIGER:
if (size() && detectors[0]->getQuad()) {
break;
}
if (multi_shm()->numberOfDetector.y % 2 != 0) {
throw RuntimeError("Gap pixels can only be used "
"for full modules.");
}
break;
default:
throw RuntimeError("Gap Pixels is not implemented for "
+ multi_shm()->multiDetectorType);
}
if (multi_shm()->numberOfDetector.y % 2 != 0) {
throw RuntimeError("Gap pixels can only be used "
"for full modules.");
}
break;
default:
throw RuntimeError("Gap Pixels is not implemented for " +
multi_shm()->multiDetectorType);
}
}
multi_shm()->gapPixels = enable;
@ -386,8 +383,7 @@ int DetectorImpl::createReceivingDataSockets(const bool destroy) {
if (multi_shm()->multiDetectorType == EIGER) {
numSocketsPerDetector = 2;
}
if (Parallel(&Module::getNumberofUDPInterfacesFromShm, {}).squash() ==
2) {
if (Parallel(&Module::getNumberofUDPInterfacesFromShm, {}).squash() == 2) {
numSocketsPerDetector = 2;
}
numSockets *= numSocketsPerDetector;
@ -404,10 +400,9 @@ int DetectorImpl::createReceivingDataSockets(const bool destroy) {
.c_str(),
portnum));
LOG(logINFO) << "Zmq Client[" << iSocket << "] at "
<< zmqSocket.back()->GetZmqServerAddress();
<< zmqSocket.back()->GetZmqServerAddress();
} catch (...) {
LOG(logERROR)
<< "Could not create Zmq socket on port " << portnum;
LOG(logERROR) << "Could not create Zmq socket on port " << portnum;
createReceivingDataSockets(true);
return FAIL;
}
@ -429,9 +424,8 @@ void DetectorImpl::readFrameFromReceiver() {
int nDetPixelsY = 0;
bool quadEnable = false;
bool eiger = false;
bool numInterfaces =
Parallel(&Module::getNumberofUDPInterfacesFromShm, {})
.squash(); // cannot pick up from zmq
bool numInterfaces = Parallel(&Module::getNumberofUDPInterfacesFromShm, {})
.squash(); // cannot pick up from zmq
bool runningList[zmqSocket.size()], connectList[zmqSocket.size()];
int numRunning = 0;
@ -444,7 +438,7 @@ void DetectorImpl::readFrameFromReceiver() {
// to remember the list it connected to, to disconnect later
connectList[i] = false;
LOG(logERROR) << "Could not connect to socket "
<< zmqSocket[i]->GetZmqServerAddress();
<< zmqSocket[i]->GetZmqServerAddress();
runningList[i] = false;
}
}
@ -491,8 +485,8 @@ void DetectorImpl::readFrameFromReceiver() {
{
zmqHeader zHeader;
if (zmqSocket[isocket]->ReceiveHeader(
isocket, zHeader, SLS_DETECTOR_JSON_HEADER_VERSION) ==
0) {
isocket, zHeader,
SLS_DETECTOR_JSON_HEADER_VERSION) == 0) {
// parse error, version error or end of acquisition for
// socket
runningList[isocket] = false;
@ -509,7 +503,7 @@ void DetectorImpl::readFrameFromReceiver() {
multiframe = new char[multisize];
memset(multiframe, 0xFF, multisize);
// dynamic range
dynamicRange = zHeader.dynamicRange;
dynamicRange = zHeader.dynamicRange;
bytesPerPixel = (float)dynamicRange / 8;
// shape
nPixelsX = zHeader.npixelsx;
@ -522,13 +516,13 @@ void DetectorImpl::readFrameFromReceiver() {
nDetPixelsY = nY * nPixelsY;
// det type
eiger = (zHeader.detType == static_cast<int>(3))
? true
: false; // to be changed to EIGER when firmware
// updates its header data
? true
: false; // to be changed to EIGER when
// firmware updates its header data
quadEnable = (zHeader.quad == 0) ? false : true;
LOG(logDEBUG1)
<< "One Time Header Info:"
"\n\tsize: "
"\n\tsize: "
<< size << "\n\tmultisize: " << multisize
<< "\n\tdynamicRange: " << dynamicRange
<< "\n\tbytesPerPixel: " << bytesPerPixel
@ -553,9 +547,9 @@ void DetectorImpl::readFrameFromReceiver() {
if (zHeader.completeImage == 0) {
completeImage = false;
}
LOG(logDEBUG1)
<< "Header Info:"
"\n\tcurrentFileName: "
LOG(logDEBUG1)
<< "Header Info:"
"\n\tcurrentFileName: "
<< currentFileName << "\n\tcurrentAcquisitionIndex: "
<< currentAcquisitionIndex
<< "\n\tcurrentFrameIndex: " << currentFrameIndex
@ -579,10 +573,10 @@ void DetectorImpl::readFrameFromReceiver() {
uint32_t rowoffset = nX * singledetrowoffset;
if (multi_shm()->multiDetectorType == CHIPTESTBOARD) {
singledetrowoffset = size;
}
}
LOG(logDEBUG1)
<< "Multi Image Info:"
"\n\txoffset: "
<< "Multi Image Info:"
"\n\txoffset: "
<< xoffset << "\n\tyoffset: " << yoffset
<< "\n\tsingledetrowoffset: " << singledetrowoffset
<< "\n\trowoffset: " << rowoffset;
@ -608,33 +602,33 @@ void DetectorImpl::readFrameFromReceiver() {
}
}
LOG(logDEBUG)<< "Call Back Info:"
<< "\n\t nDetPixelsX: " << nDetPixelsX
<< "\n\t nDetPixelsY: " << nDetPixelsY
<< "\n\t databytes: " << multisize
<< "\n\t dynamicRange: " << dynamicRange;
LOG(logDEBUG) << "Call Back Info:"
<< "\n\t nDetPixelsX: " << nDetPixelsX
<< "\n\t nDetPixelsY: " << nDetPixelsY
<< "\n\t databytes: " << multisize
<< "\n\t dynamicRange: " << dynamicRange;
// send data to callback
if (data) {
char* image = multiframe;
char *image = multiframe;
int imagesize = multisize;
if (gapPixels) {
int n = InsertGapPixels(multiframe, multigappixels,
quadEnable, dynamicRange, nDetPixelsX, nDetPixelsY);
int n = InsertGapPixels(multiframe, multigappixels, quadEnable,
dynamicRange, nDetPixelsX, nDetPixelsY);
image = multigappixels;
imagesize = n;
}
LOG(logDEBUG)
<< "Image Info:"
<< "\n\tnDetPixelsX: " << nDetPixelsX
<< "\n\tnDetPixelsY: " << nDetPixelsY
<< "\n\timagesize: " << imagesize
<< "\n\tdynamicRange: " << dynamicRange;
LOG(logDEBUG) << "Image Info:"
<< "\n\tnDetPixelsX: " << nDetPixelsX
<< "\n\tnDetPixelsY: " << nDetPixelsY
<< "\n\timagesize: " << imagesize
<< "\n\tdynamicRange: " << dynamicRange;
thisData = new detectorData(currentProgress,
currentFileName, nDetPixelsX, nDetPixelsY, image,
imagesize, dynamicRange, currentFileIndex, completeImage);
thisData =
new detectorData(currentProgress, currentFileName, nDetPixelsX,
nDetPixelsY, image, imagesize, dynamicRange,
currentFileIndex, completeImage);
dataReady(
thisData, currentFrameIndex,
@ -680,14 +674,13 @@ void DetectorImpl::readFrameFromReceiver() {
delete[] multigappixels;
}
int DetectorImpl::InsertGapPixels(char *image, char *&gpImage,
bool quadEnable, int dr, int &nPixelsx, int &nPixelsy) {
int DetectorImpl::InsertGapPixels(char *image, char *&gpImage, bool quadEnable,
int dr, int &nPixelsx, int &nPixelsy) {
LOG(logDEBUG)<< "Insert Gap pixels:"
<< "\n\t nPixelsx: " << nPixelsx
<< "\n\t nPixelsy: " << nPixelsy
<< "\n\t quadEnable: " << quadEnable
<< "\n\t dr: " << dr;
LOG(logDEBUG) << "Insert Gap pixels:"
<< "\n\t nPixelsx: " << nPixelsx
<< "\n\t nPixelsy: " << nPixelsy
<< "\n\t quadEnable: " << quadEnable << "\n\t dr: " << dr;
// inter module gap pixels
int modGapPixelsx = 8;
@ -719,7 +712,7 @@ int DetectorImpl::InsertGapPixels(char *image, char *&gpImage,
// (setting gap pixels and then adding half module or disabling quad)
if (nPixelsy / nMod1Pixelsy == 0) {
LOG(logERROR) << "Gap pixels can only be enabled with full modules. "
"Sending dummy data without gap pixels.\n";
"Sending dummy data without gap pixels.\n";
double bytesPerPixel = (double)dr / 8.00;
int imagesize = nPixelsy * nPixelsx * bytesPerPixel;
if (gpImage == NULL) {
@ -730,8 +723,10 @@ int DetectorImpl::InsertGapPixels(char *image, char *&gpImage,
}
// total number of pixels
int nTotx = nPixelsx + (nMod1GapPixelsx * nModx) + (modGapPixelsx * (nModx - 1));
int nToty = nPixelsy + (nMod1GapPixelsy * nMody) + (modGapPixelsy * (nMody - 1));
int nTotx =
nPixelsx + (nMod1GapPixelsx * nModx) + (modGapPixelsx * (nModx - 1));
int nToty =
nPixelsy + (nMod1GapPixelsy * nMody) + (modGapPixelsy * (nMody - 1));
// total number of chips
int nChipx = nPixelsx / nChipPixelsx;
int nChipy = nPixelsy / nChipPixelsy;
@ -739,13 +734,15 @@ int DetectorImpl::InsertGapPixels(char *image, char *&gpImage,
double bytesPerPixel = (double)dr / 8.00;
int imagesize = nTotx * nToty * bytesPerPixel;
int nChipBytesx = nChipPixelsx * bytesPerPixel; // 1 chip bytes in x
int nChipGapBytesx = chipGapPixelsx * bytesPerPixel; // 2 pixel bytes
int nModGapBytesx = modGapPixelsx * bytesPerPixel; // 8 pixel bytes
int nChipBytesy = nChipPixelsy * nTotx * bytesPerPixel; // 1 chip bytes in y
int nChipGapBytesy = chipGapPixelsy * nTotx * bytesPerPixel; // 2 lines
int nModGapBytesy = modGapPixelsy * nTotx * bytesPerPixel; // 36 lines
// 4 bit mode, its 1 byte (because for 4 bit mode, we handle 1 byte at a time)
int nChipBytesx = nChipPixelsx * bytesPerPixel; // 1 chip bytes in x
int nChipGapBytesx = chipGapPixelsx * bytesPerPixel; // 2 pixel bytes
int nModGapBytesx = modGapPixelsx * bytesPerPixel; // 8 pixel bytes
int nChipBytesy = nChipPixelsy * nTotx * bytesPerPixel; // 1 chip bytes in y
int nChipGapBytesy = chipGapPixelsy * nTotx * bytesPerPixel; // 2 lines
int nModGapBytesy = modGapPixelsy * nTotx *
bytesPerPixel; // 36 lines
// 4 bit mode, its 1 byte (because for 4
// bit mode, we handle 1 byte at a time)
int pixel1 = (int)(ceil(bytesPerPixel));
int row1Bytes = nTotx * bytesPerPixel;
int nMod1TotPixelsx = nMod1Pixelsx + nMod1GapPixelsx;
@ -759,38 +756,37 @@ int DetectorImpl::InsertGapPixels(char *image, char *&gpImage,
if (detType == JUNGFRAU) {
divisionValue = 1;
}
LOG(logDEBUG)
<< "Insert Gap pixels Calculations:\n\t"
<< "nPixelsx: " << nPixelsx << "\n\t"
<< "nPixelsy: " << nPixelsy << "\n\t"
<< "nMod1Pixelsx: " << nMod1Pixelsx << "\n\t"
<< "nMod1Pixelsy: " << nMod1Pixelsy << "\n\t"
<< "nMod1GapPixelsx: " << nMod1GapPixelsx << "\n\t"
<< "nMod1GapPixelsy: " << nMod1GapPixelsy << "\n\t"
<< "nChipy: " << nChipy << "\n\t"
<< "nChipx: " << nChipx << "\n\t"
<< "nModx: " << nModx << "\n\t"
<< "nMody: " << nMody << "\n\t"
<< "nTotx: " << nTotx << "\n\t"
<< "nToty: " << nToty << "\n\t"
<< "bytesPerPixel: " << bytesPerPixel << "\n\t"
<< "imagesize: " << imagesize << "\n\t"
<< "nChipBytesx: " << nChipBytesx << "\n\t"
<< "nChipGapBytesx: " << nChipGapBytesx << "\n\t"
<< "nModGapBytesx: " << nModGapBytesx << "\n\t"
<< "nChipBytesy: " << nChipBytesy << "\n\t"
<< "nChipGapBytesy: " << nChipGapBytesy << "\n\t"
<< "nModGapBytesy: " << nModGapBytesy << "\n\t"
<< "pixel1: " << pixel1 << "\n\t"
<< "row1Bytes: " << row1Bytes << "\n\t"
<< "nMod1TotPixelsx: " << nMod1TotPixelsx << "\n\t"
<< "divisionValue: " << divisionValue << "\n\n";
LOG(logDEBUG) << "Insert Gap pixels Calculations:\n\t"
<< "nPixelsx: " << nPixelsx << "\n\t"
<< "nPixelsy: " << nPixelsy << "\n\t"
<< "nMod1Pixelsx: " << nMod1Pixelsx << "\n\t"
<< "nMod1Pixelsy: " << nMod1Pixelsy << "\n\t"
<< "nMod1GapPixelsx: " << nMod1GapPixelsx << "\n\t"
<< "nMod1GapPixelsy: " << nMod1GapPixelsy << "\n\t"
<< "nChipy: " << nChipy << "\n\t"
<< "nChipx: " << nChipx << "\n\t"
<< "nModx: " << nModx << "\n\t"
<< "nMody: " << nMody << "\n\t"
<< "nTotx: " << nTotx << "\n\t"
<< "nToty: " << nToty << "\n\t"
<< "bytesPerPixel: " << bytesPerPixel << "\n\t"
<< "imagesize: " << imagesize << "\n\t"
<< "nChipBytesx: " << nChipBytesx << "\n\t"
<< "nChipGapBytesx: " << nChipGapBytesx << "\n\t"
<< "nModGapBytesx: " << nModGapBytesx << "\n\t"
<< "nChipBytesy: " << nChipBytesy << "\n\t"
<< "nChipGapBytesy: " << nChipGapBytesy << "\n\t"
<< "nModGapBytesy: " << nModGapBytesy << "\n\t"
<< "pixel1: " << pixel1 << "\n\t"
<< "row1Bytes: " << row1Bytes << "\n\t"
<< "nMod1TotPixelsx: " << nMod1TotPixelsx << "\n\t"
<< "divisionValue: " << divisionValue << "\n\n";
if (gpImage == NULL) {
gpImage = new char[imagesize];
}
memset(gpImage, 0xFF, imagesize);
//memcpy(gpImage, image, imagesize);
// memcpy(gpImage, image, imagesize);
char *src = nullptr;
char *dst = nullptr;
@ -872,11 +868,13 @@ int DetectorImpl::InsertGapPixels(char *image, char *&gpImage,
break;
case 16:
// neighbouring gap pixels to left
temp16 = (*((uint16_t *)(dst - pixel1))) / divisionValue;
temp16 =
(*((uint16_t *)(dst - pixel1))) / divisionValue;
(*((uint16_t *)dst)) = temp16;
(*((uint16_t *)(dst - pixel1))) = temp16;
// neighbouring gap pixels to right
temp16 = (*((uint16_t *)(dst + 2 * pixel1))) / divisionValue;
temp16 =
(*((uint16_t *)(dst + 2 * pixel1))) / divisionValue;
(*((uint16_t *)(dst + pixel1))) = temp16;
(*((uint16_t *)(dst + 2 * pixel1))) = temp16;
break;
@ -890,7 +888,7 @@ int DetectorImpl::InsertGapPixels(char *image, char *&gpImage,
(*((uint32_t *)(dst + pixel1))) = temp32;
(*((uint32_t *)(dst + 2 * pixel1))) = temp32;
break;
}
}
dst += nChipGapBytesx;
}
// skip inter module gap pixels in x
@ -973,8 +971,6 @@ int DetectorImpl::InsertGapPixels(char *image, char *&gpImage,
return imagesize;
}
bool DetectorImpl::enableDataStreamingToClient(int enable) {
if (enable >= 0) {
// destroy data threads
@ -1024,8 +1020,7 @@ int DetectorImpl::acquire() {
// receiver/ext process)
sem_init(&sem_endRTAcquisition, 1, 0);
bool receiver =
Parallel(&Module::getUseReceiverFlag, {}).squash(false);
bool receiver = Parallel(&Module::getUseReceiverFlag, {}).squash(false);
setJoinThreadFlag(false);
@ -1077,7 +1072,7 @@ int DetectorImpl::acquire() {
if (acquisition_finished != nullptr) {
int status = Parallel(&Module::getRunStatus, {}).squash(ERROR);
auto a = Parallel(&Module::getReceiverProgress, {});
int progress = (*std::min_element (a.begin(), a.end()));
int progress = (*std::min_element(a.begin(), a.end()));
acquisition_finished((double)progress, status, acqFinished_p);
}
@ -1086,9 +1081,9 @@ int DetectorImpl::acquire() {
clock_gettime(CLOCK_REALTIME, &end);
LOG(logDEBUG1) << "Elapsed time for acquisition:"
<< ((end.tv_sec - begin.tv_sec) +
(end.tv_nsec - begin.tv_nsec) / 1000000000.0)
<< " seconds";
<< ((end.tv_sec - begin.tv_sec) +
(end.tv_nsec - begin.tv_nsec) / 1000000000.0)
<< " seconds";
} catch (...) {
setAcquiringFlag(false);
throw;
@ -1098,12 +1093,11 @@ int DetectorImpl::acquire() {
}
void DetectorImpl::printProgress(double progress) {
std::cout << std::fixed << std::setprecision(2) << std::setw(6)
<< progress << " \%";
std::cout << std::fixed << std::setprecision(2) << std::setw(6) << progress
<< " \%";
std::cout << '\r' << std::flush;
}
void DetectorImpl::startProcessingThread() {
dataProcessingThread = std::thread(&DetectorImpl::processData, this);
}
@ -1128,7 +1122,9 @@ void DetectorImpl::processData() {
}
}
// get and print progress
double temp = (double)Parallel(&Module::getReceiverProgress, {0}).squash();
double temp =
(double)Parallel(&Module::getReceiverProgress, {0})
.squash();
if (temp != progress) {
printProgress(progress);
progress = temp;
@ -1137,7 +1133,9 @@ void DetectorImpl::processData() {
// exiting loop
if (getJoinThreadFlag()) {
// print progress one final time before exiting
progress = (double)Parallel(&Module::getReceiverProgress, {0}).squash();
progress =
(double)Parallel(&Module::getReceiverProgress, {0})
.squash();
printProgress(progress);
break;
}
@ -1297,10 +1295,9 @@ std::vector<char> DetectorImpl::readProgrammingFile(const std::string &fname) {
"Program FPGA: Could not close destination file after converting");
}
unlink(destfname); // delete temporary file
LOG(logDEBUG1)
<< "Successfully loaded the rawbin file to program memory";
LOG(logDEBUG1) << "Successfully loaded the rawbin file to program memory";
LOG(logINFO) << "Read file into memory";
return buffer;
}
}//namespace sls
} // namespace sls

18
slsDetectorSoftware/src/DetectorImpl.h Executable file → Normal file
View File

@ -22,7 +22,7 @@ class detectorData;
#include <future>
#include <numeric>
namespace sls{
namespace sls {
class Module;
@ -74,7 +74,7 @@ class DetectorImpl : public virtual slsDetectorDefs {
* @param update true to update last user pid, date etc
*/
explicit DetectorImpl(int multi_id = 0, bool verify = true,
bool update = true);
bool update = true);
/**
* Destructor
@ -188,17 +188,18 @@ class DetectorImpl : public virtual slsDetectorDefs {
}
}
/** set acquiring flag in shared memory */
void setAcquiringFlag(bool flag);
/** return multi detector shared memory ID */
int getMultiId() const;
/** Free specific shared memory from the command line without creating object */
/** Free specific shared memory from the command line without creating
* object */
static void freeSharedMemory(int multiId, int detPos = -1);
/** Free all modules from current multi Id shared memory and delete members */
/** Free all modules from current multi Id shared memory and delete members
*/
void freeSharedMemory();
/** Get user details of shared memory */
@ -217,7 +218,8 @@ class DetectorImpl : public virtual slsDetectorDefs {
*/
void setVirtualDetectorServers(const int numdet, const int port);
/** Sets the hostname of all sls detectors in shared memory and updates local cache */
/** Sets the hostname of all sls detectors in shared memory and updates
* local cache */
void setHostname(const std::vector<std::string> &name);
/** Gets the total number of detectors */
@ -352,7 +354,7 @@ class DetectorImpl : public virtual slsDetectorDefs {
* @returns total data bytes for updated image
*/
int InsertGapPixels(char *image, char *&gpImage, bool quadEnable, int dr,
int &nPixelsx, int &nPixelsy);
int &nPixelsx, int &nPixelsy);
void printProgress(double progress);
@ -418,4 +420,4 @@ class DetectorImpl : public virtual slsDetectorDefs {
void *pCallbackArg{nullptr};
};
}//namespace sls
} // namespace sls

698
slsDetectorSoftware/src/Module.cpp Executable file → Normal file

File diff suppressed because it is too large Load Diff

81
slsDetectorSoftware/src/Module.h Executable file → Normal file
View File

@ -8,15 +8,15 @@
#include <array>
#include <cmath>
#include <vector>
#include <map>
#include <vector>
class ServerInterface;
#define SLS_SHMAPIVERSION 0x190726
#define SLS_SHMVERSION 0x200402
namespace sls{
namespace sls {
/**
* @short structure allocated in shared memory to store detector settings for
@ -96,7 +96,7 @@ class Module : public virtual slsDetectorDefs {
* one
*/
explicit Module(detectorType type, int multi_id = 0, int det_id = 0,
bool verify = true);
bool verify = true);
/**
* Constructor called when opening existing shared memory
@ -182,7 +182,6 @@ class Module : public virtual slsDetectorDefs {
*/
void updateNumberOfChannels();
slsDetectorDefs::xy getNumberOfChannels() const;
/**
@ -272,11 +271,12 @@ class Module : public virtual slsDetectorDefs {
detectorSettings getSettings();
/** [Jungfrau] Options:DYNAMICGAIN, DYNAMICHG0, FIXGAIN1, FIXGAIN2, FORCESWITCHG1, FORCESWITCHG2
* [Gotthard] Options: DYNAMICGAIN, HIGHGAIN, LOWGAIN, MEDIUMGAIN, VERYHIGHGAIN
* [Gotthard2] Options: DYNAMICGAIN, FIXGAIN1, FIXGAIN2
* [Moench] Options: G1_HIGHGAIN, G1_LOWGAIN, G2_HIGHCAP_HIGHGAIN, G2_HIGHCAP_LOWGAIN,
* G2_LOWCAP_HIGHGAIN, G2_LOWCAP_LOWGAIN, G4_HIGHGAIN, G4_LOWGAIN
/** [Jungfrau] Options:DYNAMICGAIN, DYNAMICHG0, FIXGAIN1, FIXGAIN2,
* FORCESWITCHG1, FORCESWITCHG2 [Gotthard] Options: DYNAMICGAIN, HIGHGAIN,
* LOWGAIN, MEDIUMGAIN, VERYHIGHGAIN [Gotthard2] Options: DYNAMICGAIN,
* FIXGAIN1, FIXGAIN2 [Moench] Options: G1_HIGHGAIN, G1_LOWGAIN,
* G2_HIGHCAP_HIGHGAIN, G2_HIGHCAP_LOWGAIN, G2_LOWCAP_HIGHGAIN,
* G2_LOWCAP_LOWGAIN, G4_HIGHGAIN, G4_LOWGAIN
*/
void setSettings(detectorSettings isettings);
@ -294,7 +294,7 @@ class Module : public virtual slsDetectorDefs {
* @param tb 1 to include trimbits, 0 to exclude
*/
void setThresholdEnergy(int e_eV, detectorSettings isettings = GET_SETTINGS,
int tb = 1);
int tb = 1);
/**
* Set threshold energy and settings (Eiger only)
@ -499,7 +499,6 @@ class Module : public virtual slsDetectorDefs {
* [Gotthard2] only in continuous mode */
int64_t getMeasurementTime() const;
timingMode getTimingMode();
void setTimingMode(timingMode value);
@ -524,7 +523,8 @@ class Module : public virtual slsDetectorDefs {
int getOnChipDAC(slsDetectorDefs::dacIndex index, int chipIndex);
/* [Gotthard2] */
void setOnChipDAC(slsDetectorDefs::dacIndex index, int chipIndex, int value);
void setOnChipDAC(slsDetectorDefs::dacIndex index, int chipIndex,
int value);
/**
* Get adc value
@ -581,7 +581,8 @@ class Module : public virtual slsDetectorDefs {
/**
* [Ctb]
* @param mode readout mode Options: ANALOG_ONLY, DIGITAL_ONLY, ANALOG_AND_DIGITAL
* @param mode readout mode Options: ANALOG_ONLY, DIGITAL_ONLY,
* ANALOG_AND_DIGITAL
*/
void setReadoutMode(const readoutMode mode);
@ -634,7 +635,7 @@ class Module : public virtual slsDetectorDefs {
*/
uint32_t clearBit(uint32_t addr, int n);
/**
/**
* Validates and sets the receiver.
* Also updates the receiver with all the shared memory parameters
* significant for the receiver Also configures the detector to the receiver
@ -650,7 +651,7 @@ class Module : public virtual slsDetectorDefs {
*/
std::string getReceiverHostname() const;
/**
/**
* Validates the format of the detector MAC address and sets it
* @param mac detector MAC address
*/
@ -702,14 +703,16 @@ class Module : public virtual slsDetectorDefs {
/**
* Validates the format of the receiver UDP IP address and sets it
* If slsReceiver used, Gets receiver udp mac address and sends it to the detector
* If slsReceiver used, Gets receiver udp mac address and sends it to the
* detector
* @param ip receiver UDP IP address
*/
void setDestinationUDPIP(const sls::IpAddr ip);
/**
* Returns the receiver UDP IP address
* If slsReceiver used, Gets receiver udp mac address and sends it to the detector
* If slsReceiver used, Gets receiver udp mac address and sends it to the
* detector
* @returns the receiver UDP IP address
*/
sls::IpAddr getDestinationUDPIP();
@ -717,14 +720,16 @@ class Module : public virtual slsDetectorDefs {
/**
* Validates the format of the receiver UDP IP address (bottom half) and
* sets it(Jungfrau only)
* If slsReceiver used, Gets receiver udp mac address2 and sends it to the detector
* If slsReceiver used, Gets receiver udp mac address2 and sends it to the
* detector
* @param ip receiver UDP IP address (bottom half)
*/
void setDestinationUDPIP2(const sls::IpAddr ip);
/**
* Returns the receiver UDP IP address (bottom half) Jungfrau only
* If slsReceiver used, Gets receiver udp mac address2 and sends it to the detector
* If slsReceiver used, Gets receiver udp mac address2 and sends it to the
* detector
* @returns the receiver UDP IP address (bottom half)
*/
sls::IpAddr getDestinationUDPIP2();
@ -904,13 +909,15 @@ class Module : public virtual slsDetectorDefs {
void setTransmissionDelayRight(int value);
/** empty vector deletes entire additional json header */
void setAdditionalJsonHeader(const std::map<std::string, std::string> &jsonHeader);
void setAdditionalJsonHeader(
const std::map<std::string, std::string> &jsonHeader);
std::map<std::string, std::string> getAdditionalJsonHeader();
/**
* Sets the value for the additional json header parameter key if found, else
* append it. If value empty, then deletes parameter */
void setAdditionalJsonParameter(const std::string &key, const std::string &value);
* Sets the value for the additional json header parameter key if found,
* else append it. If value empty, then deletes parameter */
void setAdditionalJsonParameter(const std::string &key,
const std::string &value);
std::string getAdditionalJsonParameter(const std::string &key);
/**
@ -947,7 +954,6 @@ class Module : public virtual slsDetectorDefs {
* Only for virtual servers */
void setImageTestMode(const int value);
/** [Gotthard2] */
std::array<int, 2> getInjectChannel();
@ -960,7 +966,8 @@ class Module : public virtual slsDetectorDefs {
std::vector<int> getVetoPhoton(const int chipIndex);
/** [Gotthard2] energy in keV */
void setVetoPhoton(const int chipIndex, const int numPhotons, const int energy, const std::string& fname);
void setVetoPhoton(const int chipIndex, const int numPhotons,
const int energy, const std::string &fname);
void setVetoReference(const int gainIndex, const int value);
@ -1021,7 +1028,7 @@ class Module : public virtual slsDetectorDefs {
*/
uint32_t getADCEnableMask();
/**
/**
* Set 10Gb ADC Enable Mask (CTB, Moench)
* @param mask ADC Enable mask
*/
@ -1078,7 +1085,7 @@ class Module : public virtual slsDetectorDefs {
int getExternalSampling();
/** digital data bits enable (CTB only) */
void setReceiverDbitList(const std::vector<int>& list);
void setReceiverDbitList(const std::vector<int> &list);
std::vector<int> getReceiverDbitList() const;
/** Set digital data offset in bytes (CTB only) */
@ -1134,7 +1141,7 @@ class Module : public virtual slsDetectorDefs {
* @param vector os trimmed energies
* @returns number of trim energies
*/
int setTrimEn(const std::vector<int>& energies = {});
int setTrimEn(const std::vector<int> &energies = {});
/**
* Returns a vector with the trimmed energies (Eiger)
@ -1330,7 +1337,7 @@ class Module : public virtual slsDetectorDefs {
int64_t getFileIndex();
void setFileIndex(int64_t file_index);
void incrementFileIndex();
fileFormat getFileFormat() ;
fileFormat getFileFormat();
void setFileFormat(fileFormat f);
int getFramesPerFile();
/** 0 will set frames per file to unlimited */
@ -1340,7 +1347,6 @@ class Module : public virtual slsDetectorDefs {
bool getPartialFramesPadding();
void setPartialFramesPadding(bool padding);
/**
* Receiver starts listening to packets
*/
@ -1373,7 +1379,6 @@ class Module : public virtual slsDetectorDefs {
uint64_t getReceiverCurrentFrameIndex() const;
int getReceiverProgress() const;
void setFileWrite(bool value);
bool getFileWrite();
void setMasterFileWrite(bool value);
@ -1468,7 +1473,7 @@ class Module : public virtual slsDetectorDefs {
* @returns array of start addr and stop addr
*/
std::array<int, 2> setPatternLoopAddresses(int level = -1, int start = -1,
int stop = -1);
int stop = -1);
/**
* Sets the pattern or loop limits (CTB/ Moench/ Mythen3)
@ -1478,7 +1483,6 @@ class Module : public virtual slsDetectorDefs {
*/
int setPatternLoopCycles(int level = -1, int n = -1);
/**
* Sets the wait address (CTB/ Moench/ Mythen3)
* @param level 0,1,2, wait level
@ -1588,8 +1592,7 @@ class Module : public virtual slsDetectorDefs {
void sendToDetector(int fnum, std::nullptr_t, Ret &retval);
void sendToDetector(int fnum);
template <typename Ret>
Ret sendToDetector(int fnum);
template <typename Ret> Ret sendToDetector(int fnum);
template <typename Ret, typename Arg>
Ret sendToDetector(int fnum, const Arg &args);
@ -1662,11 +1665,9 @@ class Module : public virtual slsDetectorDefs {
template <typename Ret>
void sendToReceiver(int fnum, std::nullptr_t, Ret &retval) const;
template <typename Ret>
Ret sendToReceiver(int fnum);
template <typename Ret> Ret sendToReceiver(int fnum);
template <typename Ret>
Ret sendToReceiver(int fnum) const;
template <typename Ret> Ret sendToReceiver(int fnum) const;
template <typename Ret, typename Arg>
Ret sendToReceiver(int fnum, const Arg &args);
@ -1779,4 +1780,4 @@ class Module : public virtual slsDetectorDefs {
mutable sls::SharedMemory<sharedSlsDetector> shm{0, 0};
};
}// sls
} // namespace sls

108
slsDetectorSoftware/src/SharedMemory.h Executable file → Normal file
View File

@ -31,16 +31,15 @@
namespace sls {
template <typename T>
class SharedMemory {
template <typename T> class SharedMemory {
public:
/**
* Constructor
* creates the single/multi detector shared memory name
* @param multiId multi detector id
* Constructor
* creates the single/multi detector shared memory name
* @param multiId multi detector id
* @param slsId sls detector id, -1 if a multi detector shared memory
*/
*/
SharedMemory(int multiId, int slsId) {
name = ConstructSharedMemoryName(multiId, slsId);
}
@ -52,18 +51,17 @@ class SharedMemory {
SharedMemory(const SharedMemory &) = delete;
SharedMemory &operator=(const SharedMemory &other) = delete;
//Move constructor
SharedMemory(SharedMemory &&other) : name(other.name),
fd(other.fd),
shmSize(other.shmSize),
shared_struct(other.shared_struct) {
// Move constructor
SharedMemory(SharedMemory &&other)
: name(other.name), fd(other.fd), shmSize(other.shmSize),
shared_struct(other.shared_struct) {
other.fd = -1;
other.shared_struct = nullptr;
other.shmSize = 0;
}
//Move assignment
// Move assignment
SharedMemory &operator=(SharedMemory &&other) {
name = other.name;
if (fd) {
@ -108,31 +106,31 @@ class SharedMemory {
}
/**
* Get shared memory name
*/
std::string GetName() const {
return name;
}
* Get shared memory name
*/
std::string GetName() const { return name; }
size_t size() const {
return shmSize;
}
size_t size() const { return shmSize; }
/**
* Create Shared memory and call MapSharedMemory to map it to an address
* throws a SharedMemoryError exception on failure to create, ftruncate or map
* throws a SharedMemoryError exception on failure to create, ftruncate or
* map
* @param sz of shared memory
*/
void CreateSharedMemory() {
fd = shm_open(name.c_str(), O_CREAT | O_TRUNC | O_EXCL | O_RDWR, S_IRUSR | S_IWUSR);
fd = shm_open(name.c_str(), O_CREAT | O_TRUNC | O_EXCL | O_RDWR,
S_IRUSR | S_IWUSR);
if (fd < 0) {
std::string msg = "Create shared memory " + name + " failed: " + strerror(errno);
std::string msg =
"Create shared memory " + name + " failed: " + strerror(errno);
LOG(logERROR) << msg;
throw SharedMemoryError(msg);
}
if (ftruncate(fd, sizeof(T)) < 0) {
std::string msg = "Create shared memory " + name + " failed at ftruncate: " + strerror(errno);
std::string msg = "Create shared memory " + name +
" failed at ftruncate: " + strerror(errno);
LOG(logERROR) << msg;
close(fd);
RemoveSharedMemory();
@ -144,14 +142,15 @@ class SharedMemory {
}
/**
* Open existing Shared memory and call MapSharedMemory to map it to an address
* throws a SharedMemoryError exception on failure to open or map
* Open existing Shared memory and call MapSharedMemory to map it to an
* address throws a SharedMemoryError exception on failure to open or map
* @param sz of shared memory
*/
void OpenSharedMemory() {
fd = shm_open(name.c_str(), O_RDWR, 0);
if (fd < 0) {
std::string msg = "Open existing shared memory " + name + " failed: " + strerror(errno);
std::string msg = "Open existing shared memory " + name +
" failed: " + strerror(errno);
LOG(logERROR) << msg;
throw SharedMemoryError(msg);
}
@ -166,7 +165,8 @@ class SharedMemory {
void UnmapSharedMemory() {
if (shared_struct != nullptr) {
if (munmap(shared_struct, shmSize) < 0) {
std::string msg = "Unmapping shared memory " + name + " failed: " + strerror(errno);
std::string msg = "Unmapping shared memory " + name +
" failed: " + strerror(errno);
LOG(logERROR) << msg;
close(fd);
throw SharedMemoryError(msg);
@ -176,15 +176,16 @@ class SharedMemory {
}
/**
* Remove existing Shared memory
*/
* Remove existing Shared memory
*/
void RemoveSharedMemory() {
UnmapSharedMemory();
if (shm_unlink(name.c_str()) < 0) {
// silent exit if shm did not exist anyway
if (errno == ENOENT)
return;
std::string msg = "Free Shared Memory " + name + " Failed: " + strerror(errno);
std::string msg =
"Free Shared Memory " + name + " Failed: " + strerror(errno);
LOG(logERROR) << msg;
throw SharedMemoryError(msg);
}
@ -197,18 +198,14 @@ class SharedMemory {
static const int NAME_MAX_LENGTH = 255;
/**
*Using the call operator to access the pointer
*/
T *operator()() {
return shared_struct;
}
*Using the call operator to access the pointer
*/
T *operator()() { return shared_struct; }
/**
*Using the call operator to access the pointer, const overload
*/
const T *operator()() const {
return shared_struct;
}
*Using the call operator to access the pointer, const overload
*/
const T *operator()() const { return shared_struct; }
private:
/**
@ -232,11 +229,16 @@ class SharedMemory {
if (slsId < 0)
ss << SHM_MULTI_PREFIX << multiId << sEnvPath;
else
ss << SHM_MULTI_PREFIX << multiId << SHM_SLS_PREFIX << slsId << sEnvPath;
ss << SHM_MULTI_PREFIX << multiId << SHM_SLS_PREFIX << slsId
<< sEnvPath;
std::string temp = ss.str();
if (temp.length() > NAME_MAX_LENGTH) {
std::string msg = "Shared memory initialization failed. " + temp + " has " + std::to_string(temp.length()) + " characters. \n" + "Maximum is " + std::to_string(NAME_MAX_LENGTH) + ". Change the environment variable " + SHM_ENV_NAME;
std::string msg =
"Shared memory initialization failed. " + temp + " has " +
std::to_string(temp.length()) + " characters. \n" +
"Maximum is " + std::to_string(NAME_MAX_LENGTH) +
". Change the environment variable " + SHM_ENV_NAME;
LOG(logERROR) << msg;
throw SharedMemoryError(msg);
}
@ -250,9 +252,11 @@ class SharedMemory {
*/
T *MapSharedMemory() {
void *addr = mmap(nullptr, sizeof(T), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
void *addr =
mmap(nullptr, sizeof(T), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (addr == MAP_FAILED) {
std::string msg = "Mapping shared memory " + name + " failed: " + strerror(errno);
std::string msg =
"Mapping shared memory " + name + " failed: " + strerror(errno);
LOG(logERROR) << msg;
close(fd);
throw SharedMemoryError(msg);
@ -264,23 +268,29 @@ class SharedMemory {
/**
* Verify if existing shared memory size matches expected size
* @param expectedSize expected size of shared memory, replaced with smaller size if size does not match
* @param expectedSize expected size of shared memory, replaced with smaller
* size if size does not match
* @return 0 for success, 1 for fail
*/
int VerifySizeMatch(size_t expectedSize) {
struct stat sb;
// could not fstat
if (fstat(fd, &sb) < 0) {
std::string msg = "Could not verify existing shared memory " + name + " size match " + "(could not fstat): " + strerror(errno);
std::string msg = "Could not verify existing shared memory " +
name + " size match " +
"(could not fstat): " + strerror(errno);
LOG(logERROR) << msg;
close(fd);
throw SharedMemoryError(msg);
}
//size does not match
// size does not match
auto sz = static_cast<size_t>(sb.st_size);
if (sz != expectedSize) {
std::string msg = "Existing shared memory " + name + " size does not match" + "Expected " + std::to_string(expectedSize) + ", found " + std::to_string(sz);
std::string msg = "Existing shared memory " + name +
" size does not match" + "Expected " +
std::to_string(expectedSize) + ", found " +
std::to_string(sz);
LOG(logERROR) << msg;
throw SharedMemoryError(msg);
return 1;

103
slsDetectorSoftware/src/slsDetectorUsers.cpp Executable file → Normal file
View File

@ -1,18 +1,18 @@
#include "slsDetectorUsers.h"
//#include "detectorData.h"
//#include "multiSlsDetectorClient.h" TODO: do we need this put and get in users api
//#include "multiSlsDetectorClient.h" TODO: do we need this put and get in users
// api
#include "Detector.h"
slsDetectorUsers::slsDetectorUsers(int shm_id) : detector(sls::make_unique<sls::Detector>(shm_id)){}
slsDetectorUsers::slsDetectorUsers(int shm_id)
: detector(sls::make_unique<sls::Detector>(shm_id)) {}
slsDetectorUsers::~slsDetectorUsers() = default;
void slsDetectorUsers::readConfigurationFile(const std::string& fname){
detector->loadConfig(fname);
void slsDetectorUsers::readConfigurationFile(const std::string &fname) {
detector->loadConfig(fname);
}
int slsDetectorUsers::size() const {
return detector->size();
}
int slsDetectorUsers::size() const { return detector->size(); }
// int slsDetectorUsers::getDetectorSize(int &nx, int &ny, int detPos){
// slsDetectorDefs::xy res = detector.getNumberOfChannels();
@ -38,7 +38,8 @@ int slsDetectorUsers::size() const {
// }
// int64_t slsDetectorUsers::getDetectorFirmwareVersion(int detPos){
// return detector.getId(slsDetectorDefs::DETECTOR_FIRMWARE_VERSION, detPos);
// return detector.getId(slsDetectorDefs::DETECTOR_FIRMWARE_VERSION,
// detPos);
// }
// int64_t slsDetectorUsers::getDetectorSerialNumber(int detPos){
@ -46,7 +47,8 @@ int slsDetectorUsers::size() const {
// }
// int64_t slsDetectorUsers::getDetectorSoftwareVersion(int detPos){
// return detector.getId(slsDetectorDefs::DETECTOR_SOFTWARE_VERSION, detPos);
// return detector.getId(slsDetectorDefs::DETECTOR_SOFTWARE_VERSION,
// detPos);
// }
// int64_t slsDetectorUsers::getClientSoftwareVersion(){
@ -103,37 +105,40 @@ int slsDetectorUsers::size() const {
// }
// int slsDetectorUsers::setSettings(int isettings, int detPos){
// return detector.setSettings((slsDetectorDefs::detectorSettings)isettings, detPos);
// return
// detector.setSettings((slsDetectorDefs::detectorSettings)isettings, detPos);
// }
// int slsDetectorUsers::getThresholdEnergy(int detPos){
// return detector.getThresholdEnergy(detPos);
// }
// int slsDetectorUsers::setThresholdEnergy(int e_ev, int tb, int isettings, int detPos) {
// return detector.setThresholdEnergy(e_ev,
// (isettings == -1) ? slsDetectorDefs::GET_SETTINGS : (slsDetectorDefs::detectorSettings)isettings,
// tb, detPos);
// int slsDetectorUsers::setThresholdEnergy(int e_ev, int tb, int isettings, int
// detPos) { return detector.setThresholdEnergy(e_ev,
// (isettings == -1) ? slsDetectorDefs::GET_SETTINGS :
// (slsDetectorDefs::detectorSettings)isettings, tb, detPos);
// }
// double slsDetectorUsers::setExposureTime(double t, bool inseconds, int detPos){
// return detector.setExposureTime(t, inseconds, detPos);
// double slsDetectorUsers::setExposureTime(double t, bool inseconds, int
// detPos){ return detector.setExposureTime(t, inseconds, detPos);
// }
// double slsDetectorUsers::setExposurePeriod(double t, bool inseconds, int detPos){
// return detector.setExposurePeriod(t, inseconds, detPos);
// double slsDetectorUsers::setExposurePeriod(double t, bool inseconds, int
// detPos){ return detector.setExposurePeriod(t, inseconds, detPos);
// }
// double slsDetectorUsers::setDelayAfterTrigger(double t, bool inseconds, int detPos){
// return detector.setDelayAfterTrigger(t, inseconds, detPos);
// double slsDetectorUsers::setDelayAfterTrigger(double t, bool inseconds, int
// detPos){ return detector.setDelayAfterTrigger(t, inseconds, detPos);
// }
// double slsDetectorUsers::setSubFrameExposureTime(double t, bool inseconds, int detPos){
// return detector.setSubFrameExposureTime(t, inseconds, detPos);
// double slsDetectorUsers::setSubFrameExposureTime(double t, bool inseconds,
// int detPos){ return detector.setSubFrameExposureTime(t, inseconds,
// detPos);
// }
// double slsDetectorUsers::setSubFrameExposureDeadTime(double t, bool inseconds, int detPos){
// return detector.setSubFrameExposureDeadTime(t, inseconds, detPos);
// double slsDetectorUsers::setSubFrameExposureDeadTime(double t, bool
// inseconds, int detPos){ return detector.setSubFrameExposureDeadTime(t,
// inseconds, detPos);
// }
// int64_t slsDetectorUsers::setNumberOfFrames(int64_t t, int detPos){
@ -152,8 +157,8 @@ int slsDetectorUsers::size() const {
// return detector.getMeasuredPeriod(inseconds, detPos);
// }
// double slsDetectorUsers::getMeasuredSubFramePeriod(bool inseconds, int detPos) {
// return detector.getMeasuredSubFramePeriod(inseconds, detPos);
// double slsDetectorUsers::getMeasuredSubFramePeriod(bool inseconds, int
// detPos) { return detector.getMeasuredSubFramePeriod(inseconds, detPos);
// }
// int slsDetectorUsers::setTimingMode(int pol, int detPos){
@ -187,7 +192,8 @@ int slsDetectorUsers::size() const {
// }
// int slsDetectorUsers::setDAC(int val, int index , int detPos) {
// return detector.setDAC(val, slsDetectorDefs::dacIndex(index), 0, detPos);
// return detector.setDAC(val, slsDetectorDefs::dacIndex(index), 0,
// detPos);
// }
// int slsDetectorUsers::getADC(int index, int detPos) {
@ -224,7 +230,6 @@ int slsDetectorUsers::size() const {
// *********************************************************************/
// void slsDetectorUsers::startReceiver(int detPos) {
// detector.startReceiver(detPos);
// }
@ -314,16 +319,16 @@ int slsDetectorUsers::size() const {
// return detector.getClientStreamingPort(detPos);
// }
// std::string slsDetectorUsers::setReceiverDataStreamingOutIP(const std::string& ip, int detPos){
// if (ip.length()) {
// std::string slsDetectorUsers::setReceiverDataStreamingOutIP(const
// std::string& ip, int detPos){ if (ip.length()) {
// detector.setReceiverDataStreamingOutIP(ip, detPos);
// }
// return detector.getReceiverStreamingIP(detPos);
// }
// std::string slsDetectorUsers::setClientDataStreamingInIP(const std::string& ip, int detPos){
// if (ip.length()) {
// detector.setClientDataStreamingInIP(ip, detPos);
// std::string slsDetectorUsers::setClientDataStreamingInIP(const std::string&
// ip, int detPos){ if (ip.length()) {
// detector.setClientDataStreamingInIP(ip, detPos);
// }
// return detector.getClientStreamingIP(detPos);
// }
@ -333,7 +338,9 @@ int slsDetectorUsers::size() const {
// }
// int slsDetectorUsers::setReceiverFramesDiscardPolicy(int f, int detPos) {
// return detector.setReceiverFramesDiscardPolicy(slsDetectorDefs::frameDiscardPolicy(f), detPos);
// return
// detector.setReceiverFramesDiscardPolicy(slsDetectorDefs::frameDiscardPolicy(f),
// detPos);
// }
// int slsDetectorUsers::setReceiverPartialFramesPadding(int f, int detPos) {
@ -352,45 +359,37 @@ int slsDetectorUsers::size() const {
// }
// }
// int slsDetectorUsers::setDetectorMinMaxEnergyThreshold(const int index, int v, int detPos) {
// int slsDetectorUsers::setDetectorMinMaxEnergyThreshold(const int index, int
// v, int detPos) {
// return detector.setDetectorMinMaxEnergyThreshold(index, v, detPos);
// }
// int slsDetectorUsers::setFrameMode(int value, int detPos) {
// return detector.setFrameMode(slsDetectorDefs::frameModeType(value), detPos);
// return detector.setFrameMode(slsDetectorDefs::frameModeType(value),
// detPos);
// }
// int slsDetectorUsers::setDetectorMode(int value, int detPos) {
// return detector.setDetectorMode(slsDetectorDefs::detectorModeType(value), detPos);
// return detector.setDetectorMode(slsDetectorDefs::detectorModeType(value),
// detPos);
// }
// /************************************************************************
// CALLBACKS & COMMAND LINE PARSING
// *********************************************************************/
// void slsDetectorUsers::registerDataCallback(void( *userCallback)(detectorData*, uint64_t, uint32_t, void*), void *pArg) {
// void slsDetectorUsers::registerDataCallback(void(
// *userCallback)(detectorData*, uint64_t, uint32_t, void*), void *pArg) {
// detector.registerDataCallback(userCallback,pArg);
// }
// void slsDetectorUsers::registerAcquisitionFinishedCallback(void( *func)(double,int, void*), void *pArg) {
// void slsDetectorUsers::registerAcquisitionFinishedCallback(void(
// *func)(double,int, void*), void *pArg) {
// detector.registerAcquisitionFinishedCallback(func,pArg);
// }
// void slsDetectorUsers::putCommand(const std::string& command){
// multiSlsDetectorClient(command, slsDetectorDefs::PUT_ACTION, &detector);
// }

14
slsDetectorSoftware/tests/test-CmdParser.cpp Executable file → Normal file
View File

@ -3,7 +3,6 @@
#include <exception>
#include <string>
// tests to add
// help for all docs
// command for all depreciated commands
@ -135,9 +134,9 @@ SCENARIO("Parsing strings with -h or --help", "[support]") {
REQUIRE(p.argv().size() == 1);
}
}
WHEN("Parsing a string with -h at a different position"){
WHEN("Parsing a string with -h at a different position") {
std::string s = "list -h something";
THEN("its also done right"){
THEN("its also done right") {
p.Parse(s);
REQUIRE(p.isHelp());
REQUIRE(p.command() == "list");
@ -145,9 +144,9 @@ SCENARIO("Parsing strings with -h or --help", "[support]") {
REQUIRE(p.arguments().front() == "something");
}
}
WHEN("Parsing a string with -help at a different position"){
WHEN("Parsing a string with -help at a different position") {
std::string s = "list --help something";
THEN("its also done right"){
THEN("its also done right") {
p.Parse(s);
REQUIRE(p.isHelp());
REQUIRE(p.command() == "list");
@ -158,7 +157,7 @@ SCENARIO("Parsing strings with -h or --help", "[support]") {
}
}
TEST_CASE("Parsing consecutive strings resets not found det id"){
TEST_CASE("Parsing consecutive strings resets not found det id") {
CmdParser p;
p.Parse("1:exptime 0.5");
REQUIRE(p.detector_id() == 1);
@ -166,10 +165,9 @@ TEST_CASE("Parsing consecutive strings resets not found det id"){
REQUIRE(p.detector_id() == -1);
p.Parse("3:exptime 0.5");
REQUIRE(p.detector_id() == 3);
}
TEST_CASE("Parsing consecutive strings resets not found multi id"){
TEST_CASE("Parsing consecutive strings resets not found multi id") {
CmdParser p;
p.Parse("1-1:exptime 0.5");
REQUIRE(p.multi_id() == 1);

View File

@ -17,7 +17,8 @@ using test::PUT;
/* dacs */
TEST_CASE("Setting and reading back Chip test board dacs", "[.cmd][.dacs][.new]") {
TEST_CASE("Setting and reading back Chip test board dacs",
"[.cmd][.dacs][.new]") {
// dac 0 to dac 17
Detector det;
@ -25,12 +26,14 @@ TEST_CASE("Setting and reading back Chip test board dacs", "[.cmd][.dacs][.new]"
auto det_type = det.getDetectorType().squash();
if (det_type == defs::CHIPTESTBOARD) {
for (int i = 0; i < 18; ++i) {
SECTION("dac " + std::to_string(i)) { test_dac(static_cast<defs::dacIndex>(i), "dac", 0); }
SECTION("dac " + std::to_string(i)) {
test_dac(static_cast<defs::dacIndex>(i), "dac", 0);
}
}
// eiger
//REQUIRE_THROWS(proxy.Call("vthreshold", {}, -1, GET));
//REQUIRE_THROWS(proxy.Call("vsvp", {}, -1, GET));
//REQUIRE_THROWS(proxy.Call("vsvn", {}, -1, GET));
// REQUIRE_THROWS(proxy.Call("vthreshold", {}, -1, GET));
// REQUIRE_THROWS(proxy.Call("vsvp", {}, -1, GET));
// REQUIRE_THROWS(proxy.Call("vsvn", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vtr", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vrf", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vrs", {}, -1, GET));
@ -53,30 +56,30 @@ TEST_CASE("Setting and reading back Chip test board dacs", "[.cmd][.dacs][.new]"
REQUIRE_THROWS(proxy.Call("vref_prech", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vb_pixbuf", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vb_ds", {}, -1, GET));
//REQUIRE_THROWS(proxy.Call("vref_ds", {}, -1, GET));
//REQUIRE_THROWS(proxy.Call("vref_comp", {}, -1, GET));
// REQUIRE_THROWS(proxy.Call("vref_ds", {}, -1, GET));
// REQUIRE_THROWS(proxy.Call("vref_comp", {}, -1, GET));
// gotthard
//REQUIRE_THROWS(proxy.Call("vref_ds", {}, -1, GET));
//REQUIRE_THROWS(proxy.Call("vcascn_pb", {}, -1, GET));
//REQUIRE_THROWS(proxy.Call("vcascp_pb", {}, -1, GET));
//REQUIRE_THROWS(proxy.Call("vout_cm", {}, -1, GET));
//REQUIRE_THROWS(proxy.Call("vcasc_out", {}, -1, GET));
//REQUIRE_THROWS(proxy.Call("vin_cm", {}, -1, GET));
//REQUIRE_THROWS(proxy.Call("vref_comp", {}, -1, GET));
//REQUIRE_THROWS(proxy.Call("ib_test_c", {}, -1, GET));
// REQUIRE_THROWS(proxy.Call("vref_ds", {}, -1, GET));
// REQUIRE_THROWS(proxy.Call("vcascn_pb", {}, -1, GET));
// REQUIRE_THROWS(proxy.Call("vcascp_pb", {}, -1, GET));
// REQUIRE_THROWS(proxy.Call("vout_cm", {}, -1, GET));
// REQUIRE_THROWS(proxy.Call("vcasc_out", {}, -1, GET));
// REQUIRE_THROWS(proxy.Call("vin_cm", {}, -1, GET));
// REQUIRE_THROWS(proxy.Call("vref_comp", {}, -1, GET));
// REQUIRE_THROWS(proxy.Call("ib_test_c", {}, -1, GET));
// mythen3
//REQUIRE_THROWS(proxy.Call("vpreamp", {}, -1, GET));
//REQUIRE_THROWS(proxy.Call("vshaper", {}, -1, GET));
//REQUIRE_THROWS(proxy.Call("vshaperneg", {}, -1, GET));
// REQUIRE_THROWS(proxy.Call("vpreamp", {}, -1, GET));
// REQUIRE_THROWS(proxy.Call("vshaper", {}, -1, GET));
// REQUIRE_THROWS(proxy.Call("vshaperneg", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vipre", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("viinsh", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vdcsh", {}, -1, GET));
//REQUIRE_THROWS(proxy.Call("vth1", {}, -1, GET));
// REQUIRE_THROWS(proxy.Call("vth1", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vth2", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vth3", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vpl", {}, -1, GET));
//REQUIRE_THROWS(proxy.Call("vph", {}, -1, GET));
//REQUIRE_THROWS(proxy.Call("vtrim", {}, -1, GET));
// REQUIRE_THROWS(proxy.Call("vph", {}, -1, GET));
// REQUIRE_THROWS(proxy.Call("vtrim", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vcassh", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vcas", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vicin", {}, -1, GET));

View File

@ -14,7 +14,6 @@ using sls::Detector;
using test::GET;
using test::PUT;
/** temperature */
TEST_CASE("temp_fpgaext", "[.cmd][.new]") {
@ -25,7 +24,7 @@ TEST_CASE("temp_fpgaext", "[.cmd][.new]") {
REQUIRE_NOTHROW(proxy.Call("temp_fpgaext", {}, -1, GET));
std::ostringstream oss;
REQUIRE_NOTHROW(proxy.Call("temp_fpgaext", {}, 0, GET, oss));
std::string s = (oss.str()).erase (0, strlen("temp_fpgaext "));
std::string s = (oss.str()).erase(0, strlen("temp_fpgaext "));
REQUIRE(std::stoi(s) != -1);
} else {
REQUIRE_THROWS(proxy.Call("temp_fpgaext", {}, -1, GET));
@ -40,7 +39,7 @@ TEST_CASE("temp_10ge", "[.cmd][.new]") {
REQUIRE_NOTHROW(proxy.Call("temp_10ge", {}, -1, GET));
std::ostringstream oss;
REQUIRE_NOTHROW(proxy.Call("temp_10ge", {}, 0, GET, oss));
std::string s = (oss.str()).erase (0, strlen("temp_10ge "));
std::string s = (oss.str()).erase(0, strlen("temp_10ge "));
REQUIRE(std::stoi(s) != -1);
} else {
REQUIRE_THROWS(proxy.Call("temp_10ge", {}, -1, GET));
@ -55,7 +54,7 @@ TEST_CASE("temp_dcdc", "[.cmd][.new]") {
REQUIRE_NOTHROW(proxy.Call("temp_dcdc", {}, -1, GET));
std::ostringstream oss;
REQUIRE_NOTHROW(proxy.Call("temp_dcdc", {}, 0, GET, oss));
std::string s = (oss.str()).erase (0, strlen("temp_dcdc "));
std::string s = (oss.str()).erase(0, strlen("temp_dcdc "));
REQUIRE(std::stoi(s) != -1);
} else {
REQUIRE_THROWS(proxy.Call("temp_dcdc", {}, -1, GET));
@ -70,7 +69,7 @@ TEST_CASE("temp_sodl", "[.cmd][.new]") {
REQUIRE_NOTHROW(proxy.Call("temp_sodl", {}, -1, GET));
std::ostringstream oss;
REQUIRE_NOTHROW(proxy.Call("temp_sodl", {}, 0, GET, oss));
std::string s = (oss.str()).erase (0, strlen("temp_sodl "));
std::string s = (oss.str()).erase(0, strlen("temp_sodl "));
REQUIRE(std::stoi(s) != -1);
} else {
REQUIRE_THROWS(proxy.Call("temp_sodl", {}, -1, GET));
@ -85,7 +84,7 @@ TEST_CASE("temp_sodr", "[.cmd][.new]") {
REQUIRE_NOTHROW(proxy.Call("temp_sodr", {}, -1, GET));
std::ostringstream oss;
REQUIRE_NOTHROW(proxy.Call("temp_sodr", {}, 0, GET, oss));
std::string s = (oss.str()).erase (0, strlen("temp_sodr "));
std::string s = (oss.str()).erase(0, strlen("temp_sodr "));
REQUIRE(std::stoi(s) != -1);
} else {
REQUIRE_THROWS(proxy.Call("temp_sodr", {}, -1, GET));
@ -100,7 +99,7 @@ TEST_CASE("temp_fpgafl", "[.cmd][.new]") {
REQUIRE_NOTHROW(proxy.Call("temp_fpgafl", {}, -1, GET));
std::ostringstream oss;
REQUIRE_NOTHROW(proxy.Call("temp_fpgafl", {}, 0, GET, oss));
std::string s = (oss.str()).erase (0, strlen("temp_fpgafl "));
std::string s = (oss.str()).erase(0, strlen("temp_fpgafl "));
REQUIRE(std::stoi(s) != -1);
} else {
REQUIRE_THROWS(proxy.Call("temp_fpgafl", {}, -1, GET));
@ -115,7 +114,7 @@ TEST_CASE("temp_fpgafr", "[.cmd][.new]") {
REQUIRE_NOTHROW(proxy.Call("temp_fpgafr", {}, -1, GET));
std::ostringstream oss;
REQUIRE_NOTHROW(proxy.Call("temp_fpgafr", {}, 0, GET, oss));
std::string s = (oss.str()).erase (0, strlen("temp_fpgafr "));
std::string s = (oss.str()).erase(0, strlen("temp_fpgafr "));
REQUIRE(std::stoi(s) != -1);
} else {
REQUIRE_THROWS(proxy.Call("temp_fpgafr", {}, -1, GET));
@ -229,30 +228,6 @@ TEST_CASE("Setting and reading back EIGER dacs", "[.cmd][.dacs][.new]") {
}
}
TEST_CASE("Eiger transmission delay", "[.cmd]") {
Detector det;
CmdProxy proxy(&det);
@ -519,8 +494,6 @@ TEST_CASE("quad", "[.cmd]") {
}
}
// TEST_CASE("trigger", "[.cmd]") {
// Detector det;
// CmdProxy proxy(&det);

View File

@ -9,7 +9,6 @@ using sls::Detector;
using test::GET;
using test::PUT;
void test_dac(defs::dacIndex index, const std::string &dacname, int dacvalue) {
Detector det;
CmdProxy proxy(&det);
@ -20,9 +19,11 @@ void test_dac(defs::dacIndex index, const std::string &dacname, int dacvalue) {
if (dacname == "dac") {
auto dacIndexstr = std::to_string(static_cast<int>(index));
proxy.Call(dacname, {dacIndexstr, dacstr}, -1, PUT, oss_set);
REQUIRE(oss_set.str() == dacname + " " + dacIndexstr + " " + dacstr + "\n");
REQUIRE(oss_set.str() ==
dacname + " " + dacIndexstr + " " + dacstr + "\n");
proxy.Call(dacname, {dacIndexstr}, -1, GET, oss_get);
REQUIRE(oss_get.str() == dacname + " " + dacIndexstr + " " + dacstr + "\n");
REQUIRE(oss_get.str() ==
dacname + " " + dacIndexstr + " " + dacstr + "\n");
}
// other detectors
else {
@ -37,12 +38,15 @@ void test_dac(defs::dacIndex index, const std::string &dacname, int dacvalue) {
}
}
void test_onchip_dac(defs::dacIndex index, const std::string &dacname, int dacvalue) {
void test_onchip_dac(defs::dacIndex index, const std::string &dacname,
int dacvalue) {
Detector det;
CmdProxy proxy(&det);
REQUIRE_THROWS(proxy.Call(dacname, {}, -1, GET));
REQUIRE_THROWS(proxy.Call(dacname, {"10", "0x0"}, -1, PUT)); // chip index (-1 to 9)
REQUIRE_THROWS(proxy.Call(dacname, {"-1", "0x400"}, -1, PUT)); // max val is 0x3ff
REQUIRE_THROWS(
proxy.Call(dacname, {"10", "0x0"}, -1, PUT)); // chip index (-1 to 9)
REQUIRE_THROWS(
proxy.Call(dacname, {"-1", "0x400"}, -1, PUT)); // max val is 0x3ff
int chipIndex = -1; // for now, it is -1 only
auto prev_val = det.getOnChipDAC(index, chipIndex);
@ -50,9 +54,11 @@ void test_onchip_dac(defs::dacIndex index, const std::string &dacname, int dacva
auto chipIndexStr = std::to_string(chipIndex);
std::ostringstream oss_set, oss_get;
proxy.Call(dacname, {chipIndexStr, dacValueStr}, -1, PUT, oss_set);
REQUIRE(oss_set.str() == dacname + " " + chipIndexStr + " " + dacValueStr + "\n");
REQUIRE(oss_set.str() ==
dacname + " " + chipIndexStr + " " + dacValueStr + "\n");
proxy.Call(dacname, {chipIndexStr}, -1, GET, oss_get);
REQUIRE(oss_get.str() == dacname + " " + chipIndexStr + " " + dacValueStr + "\n");
REQUIRE(oss_get.str() ==
dacname + " " + chipIndexStr + " " + dacValueStr + "\n");
// Reset all dacs to previous value
for (int i = 0; i != det.size(); ++i) {

View File

@ -1,5 +1,7 @@
#pragma once
#include "sls_detector_defs.h"
void test_dac(slsDetectorDefs::dacIndex index, const std::string &dacname, int dacvalue);
void test_onchip_dac(slsDetectorDefs::dacIndex index, const std::string &dacname, int dacvalue);
void test_dac(slsDetectorDefs::dacIndex index, const std::string &dacname,
int dacvalue);
void test_onchip_dac(slsDetectorDefs::dacIndex index,
const std::string &dacname, int dacvalue);

View File

@ -18,7 +18,8 @@ using test::PUT;
/* dacs */
TEST_CASE("Setting and reading back GOTTHARD dacs", "[.cmd][.dacs][.new]") {
// vref_ds, vcascn_pb, vcascp_pb, vout_cm, vcasc_out, vin_cm, vref_comp, ib_test_c
// vref_ds, vcascn_pb, vcascp_pb, vout_cm, vcasc_out, vin_cm, vref_comp,
// ib_test_c
Detector det;
CmdProxy proxy(&det);

View File

@ -22,9 +22,12 @@ TEST_CASE("bursts", "[.cmd][.new]") {
CmdProxy proxy(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::GOTTHARD2) {
auto prev_burst = det.getNumberOfBursts().tsquash("#bursts should be same to test");
auto prev_trigger = det.getNumberOfFrames().tsquash("#frames should be same to test");
auto prev_frames = det.getNumberOfTriggers().tsquash("#triggers should be same to test");
auto prev_burst =
det.getNumberOfBursts().tsquash("#bursts should be same to test");
auto prev_trigger =
det.getNumberOfFrames().tsquash("#frames should be same to test");
auto prev_frames = det.getNumberOfTriggers().tsquash(
"#triggers should be same to test");
auto prev_timingMode = det.getTimingMode();
auto prev_burstMode = det.getBurstMode();
// changing continuous mode frames and bursts
@ -100,15 +103,25 @@ TEST_CASE("Setting and reading back GOTTHARD2 dacs", "[.cmd][.dacs][.new]") {
CmdProxy proxy(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::GOTTHARD2) {
SECTION("vref_h_adc") { test_dac(defs::VREF_H_ADC, "vref_h_adc", 2099); }
SECTION("vref_h_adc") {
test_dac(defs::VREF_H_ADC, "vref_h_adc", 2099);
}
SECTION("vb_comp_fe") { test_dac(defs::VB_COMP_FE, "vb_comp_fe", 0); }
SECTION("vb_comp_adc") { test_dac(defs::VB_COMP_ADC, "vb_comp_adc", 0); }
SECTION("vb_comp_adc") {
test_dac(defs::VB_COMP_ADC, "vb_comp_adc", 0);
}
SECTION("vcom_cds") { test_dac(defs::VCOM_CDS, "vcom_cds", 1400); }
SECTION("vref_rstore") { test_dac(defs::VREF_RSTORE, "vref_rstore", 640); }
SECTION("vref_rstore") {
test_dac(defs::VREF_RSTORE, "vref_rstore", 640);
}
SECTION("vb_opa_1st") { test_dac(defs::VB_OPA_1ST, "vb_opa_1st", 0); }
SECTION("vref_comp_fe") { test_dac(defs::VREF_COMP_FE, "vref_comp_fe", 0); }
SECTION("vref_comp_fe") {
test_dac(defs::VREF_COMP_FE, "vref_comp_fe", 0);
}
SECTION("vcom_adc1") { test_dac(defs::VCOM_ADC1, "vcom_adc1", 1400); }
SECTION("vref_prech") { test_dac(defs::VREF_PRECH, "vref_prech", 1720); }
SECTION("vref_prech") {
test_dac(defs::VREF_PRECH, "vref_prech", 1720);
}
SECTION("vref_l_adc") { test_dac(defs::VREF_L_ADC, "vref_l_adc", 700); }
SECTION("vref_cds") { test_dac(defs::VREF_CDS, "vref_cds", 1200); }
SECTION("vb_cs") { test_dac(defs::VB_CS, "vb_cs", 2799); }
@ -178,7 +191,9 @@ TEST_CASE("vchip_comp_fe", "[.cmd][.onchipdacs][.new]") {
CmdProxy proxy(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::GOTTHARD2) {
SECTION("vchip_comp_fe") { test_onchip_dac(defs::VB_COMP_FE, "vchip_comp_fe", 0x137); }
SECTION("vchip_comp_fe") {
test_onchip_dac(defs::VB_COMP_FE, "vchip_comp_fe", 0x137);
}
} else {
REQUIRE_THROWS(proxy.Call("vchip_comp_fe", {}, -1, GET));
}
@ -189,7 +204,9 @@ TEST_CASE("vchip_opa_1st", "[.cmd][.onchipdacs][.new]") {
CmdProxy proxy(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::GOTTHARD2) {
SECTION("vchip_opa_1st") { test_onchip_dac(defs::VB_OPA_1ST, "vchip_opa_1st", 0x000); }
SECTION("vchip_opa_1st") {
test_onchip_dac(defs::VB_OPA_1ST, "vchip_opa_1st", 0x000);
}
} else {
REQUIRE_THROWS(proxy.Call("vchip_opa_1st", {}, -1, GET));
}
@ -200,7 +217,9 @@ TEST_CASE("vchip_opa_fd", "[.cmd][.onchipdacs][.new]") {
CmdProxy proxy(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::GOTTHARD2) {
SECTION("vchip_opa_fd") { test_onchip_dac(defs::VB_OPA_FD, "vchip_opa_fd", 0x134); }
SECTION("vchip_opa_fd") {
test_onchip_dac(defs::VB_OPA_FD, "vchip_opa_fd", 0x134);
}
} else {
REQUIRE_THROWS(proxy.Call("vchip_opa_fd", {}, -1, GET));
}
@ -211,7 +230,9 @@ TEST_CASE("vchip_comp_adc", "[.cmd][.onchipdacs][.new]") {
CmdProxy proxy(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::GOTTHARD2) {
SECTION("vchip_comp_adc") { test_onchip_dac(defs::VB_COMP_ADC, "vchip_comp_adc", 0x3FF); }
SECTION("vchip_comp_adc") {
test_onchip_dac(defs::VB_COMP_ADC, "vchip_comp_adc", 0x3FF);
}
} else {
REQUIRE_THROWS(proxy.Call("vchip_comp_adc", {}, -1, GET));
}
@ -222,7 +243,9 @@ TEST_CASE("vchip_ref_comp_fe", "[.cmd][.onchipdacs][.new]") {
CmdProxy proxy(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::GOTTHARD2) {
SECTION("vchip_ref_comp_fe") { test_onchip_dac(defs::VREF_COMP_FE, "vchip_ref_comp_fe", 0x100); }
SECTION("vchip_ref_comp_fe") {
test_onchip_dac(defs::VREF_COMP_FE, "vchip_ref_comp_fe", 0x100);
}
} else {
REQUIRE_THROWS(proxy.Call("vchip_ref_comp_fe", {}, -1, GET));
}
@ -239,22 +262,6 @@ TEST_CASE("vchip_cs", "[.cmd][.onchipdacs][.new]") {
}
}
TEST_CASE("burstmode", "[.cmd]") {
Detector det;
CmdProxy proxy(&det);
@ -286,7 +293,6 @@ TEST_CASE("burstmode", "[.cmd]") {
}
}
TEST_CASE("vetoref", "[.cmd]") {
Detector det;
CmdProxy proxy(&det);
@ -294,14 +300,14 @@ TEST_CASE("vetoref", "[.cmd]") {
if (det_type == defs::GOTTHARD2) {
REQUIRE_THROWS(proxy.Call("vetoref", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vetoref", {"3", "0x3ff"}, -1, PUT)); // invalid chip index
REQUIRE_THROWS(proxy.Call("vetoref", {"3", "0x3ff"}, -1,
PUT)); // invalid chip index
REQUIRE_NOTHROW(proxy.Call("vetoref", {"1", "0x010"}, -1, PUT));
} else {
REQUIRE_THROWS(proxy.Call("vetoref", {"3", "0x0"}, -1, PUT));
}
}
TEST_CASE("vetophoton", "[.cmd]") {
Detector det;
CmdProxy proxy(&det);
@ -310,16 +316,17 @@ TEST_CASE("vetophoton", "[.cmd]") {
if (det_type == defs::GOTTHARD2) {
REQUIRE_THROWS(proxy.Call("vetophoton", {}, -1, GET));
REQUIRE_NOTHROW(proxy.Call("vetophoton", {"-1"}, -1, GET));
REQUIRE_THROWS(proxy.Call("vetophoton", {"12", "1", "39950"}, -1, PUT));// invalid chip index
REQUIRE_THROWS(proxy.Call("vetophoton", {"-1", "0"}, -1, PUT)); // invalid photon number
REQUIRE_THROWS(proxy.Call("vetophoton", {"-1", "1", "39950"}, -1, PUT)); // invald file
REQUIRE_THROWS(proxy.Call("vetophoton", {"12", "1", "39950"}, -1,
PUT)); // invalid chip index
REQUIRE_THROWS(proxy.Call("vetophoton", {"-1", "0"}, -1,
PUT)); // invalid photon number
REQUIRE_THROWS(proxy.Call("vetophoton", {"-1", "1", "39950"}, -1,
PUT)); // invald file
} else {
REQUIRE_THROWS(proxy.Call("vetophoton", {"-1"}, -1, GET));
}
}
TEST_CASE("inj_ch", "[.cmd]") {
Detector det;
CmdProxy proxy(&det);
@ -327,8 +334,10 @@ TEST_CASE("inj_ch", "[.cmd]") {
if (det_type == defs::GOTTHARD2) {
auto inj = det.getInjectChannel();
REQUIRE_THROWS(proxy.Call("inj_ch", {"-1", "1"}, -1, PUT));// invalid offset
REQUIRE_THROWS(proxy.Call("inj_ch", {"0", "0"}, -1, PUT));// invalid increment
REQUIRE_THROWS(
proxy.Call("inj_ch", {"-1", "1"}, -1, PUT)); // invalid offset
REQUIRE_THROWS(
proxy.Call("inj_ch", {"0", "0"}, -1, PUT)); // invalid increment
{
std::ostringstream oss;
proxy.Call("inj_ch", {"0", "1"}, -1, PUT, oss);
@ -347,9 +356,6 @@ TEST_CASE("inj_ch", "[.cmd]") {
}
}
TEST_CASE("burstperiod", "[.cmd]") {
Detector det;
CmdProxy proxy(&det);
@ -372,7 +378,6 @@ TEST_CASE("burstperiod", "[.cmd]") {
}
}
TEST_CASE("currentsource", "[.cmd]") {
Detector det;
CmdProxy proxy(&det);
@ -410,11 +415,11 @@ TEST_CASE("timingsource", "[.cmd]") {
if (det_type == defs::GOTTHARD2) {
auto prev_val = det.getTimingSource();
/* { until its activated in fpga
std::ostringstream oss;
proxy.Call("timingsource", {"external"}, -1, PUT, oss);
REQUIRE(oss.str() == "timingsource external\n");
}*/
/* { until its activated in fpga
std::ostringstream oss;
proxy.Call("timingsource", {"external"}, -1, PUT, oss);
REQUIRE(oss.str() == "timingsource external\n");
}*/
{
std::ostringstream oss;
proxy.Call("timingsource", {"internal"}, -1, PUT, oss);

View File

@ -16,7 +16,8 @@ using test::PUT;
/* dacs */
TEST_CASE("Setting and reading back Jungfrau dacs", "[.cmd][.dacs][.new]") {
// vb_comp, vdd_prot, vin_com, vref_prech, vb_pixbuf, vb_ds, vref_ds, vref_comp
// vb_comp, vdd_prot, vin_com, vref_prech, vb_pixbuf, vb_ds, vref_ds,
// vref_comp
Detector det;
CmdProxy proxy(&det);
auto det_type = det.getDetectorType().squash();
@ -24,7 +25,9 @@ TEST_CASE("Setting and reading back Jungfrau dacs", "[.cmd][.dacs][.new]") {
SECTION("vb_comp") { test_dac(defs::VB_COMP, "vb_comp", 1220); }
SECTION("vdd_prot") { test_dac(defs::VDD_PROT, "vdd_prot", 3000); }
SECTION("vin_com") { test_dac(defs::VIN_COM, "vin_com", 1053); }
SECTION("vref_prech") { test_dac(defs::VREF_PRECH, "vref_prech", 1450); }
SECTION("vref_prech") {
test_dac(defs::VREF_PRECH, "vref_prech", 1450);
}
SECTION("vb_pixbuf") { test_dac(defs::VB_PIXBUF, "vb_pixbuf", 750); }
SECTION("vb_ds") { test_dac(defs::VB_DS, "vb_ds", 1000); }
SECTION("vref_ds") { test_dac(defs::VREF_DS, "vref_ds", 480); }
@ -91,38 +94,6 @@ TEST_CASE("Setting and reading back Jungfrau dacs", "[.cmd][.dacs][.new]") {
}
}
TEST_CASE("nframes", "[.cmd]") {
Detector det;
CmdProxy proxy(&det);
@ -171,7 +142,7 @@ TEST_CASE("timestamp", "[.cmd]") {
}
TEST_CASE("adcreg", "[.cmd]") {
//TODO! what is a safe value to use?
// TODO! what is a safe value to use?
Detector det;
CmdProxy proxy(&det);
auto det_type = det.getDetectorType().squash();
@ -234,5 +205,3 @@ TEST_CASE("resetfpga", "[.cmd]") {
REQUIRE_THROWS(proxy.Call("resetfpga", {}, -1, PUT));
}
}

View File

@ -18,13 +18,16 @@ using test::PUT;
/* dacs */
TEST_CASE("Setting and reading back MOENCH dacs", "[.cmd][.dacs][.new]") {
// vbp_colbuf, vipre, vin_cm", vb_sda, vcasc_sfp, vout_cm, vipre_cds, ibias_sfp
// vbp_colbuf, vipre, vin_cm", vb_sda, vcasc_sfp, vout_cm, vipre_cds,
// ibias_sfp
Detector det;
CmdProxy proxy(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::MOENCH) {
SECTION("vbp_colbuf") { test_dac(defs::VBP_COLBUF, "vbp_colbuf", 1300); }
SECTION("vbp_colbuf") {
test_dac(defs::VBP_COLBUF, "vbp_colbuf", 1300);
}
SECTION("vipre") { test_dac(defs::VIPRE, "vipre", 1000); }
SECTION("vin_cm") { test_dac(defs::VIN_CM, "vin_cm", 1400); }
SECTION("vb_sda") { test_dac(defs::VB_SDA, "vb_sda", 680); }
@ -65,16 +68,16 @@ TEST_CASE("Setting and reading back MOENCH dacs", "[.cmd][.dacs][.new]") {
REQUIRE_THROWS(proxy.Call("vref_ds", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vcascn_pb", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vcascp_pb", {}, -1, GET));
//REQUIRE_THROWS(proxy.Call("vout_cm", {}, -1, GET));
// REQUIRE_THROWS(proxy.Call("vout_cm", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vcasc_out", {}, -1, GET));
//REQUIRE_THROWS(proxy.Call("vin_cm", {}, -1, GET));
// REQUIRE_THROWS(proxy.Call("vin_cm", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vref_comp", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("ib_test_c", {}, -1, GET));
// mythen3
REQUIRE_THROWS(proxy.Call("vpreamp", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vshaper", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vshaperneg", {}, -1, GET));
//REQUIRE_THROWS(proxy.Call("vipre", {}, -1, GET));
// REQUIRE_THROWS(proxy.Call("vipre", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("viinsh", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vdcsh", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vth1", {}, -1, GET));

View File

@ -89,22 +89,6 @@ TEST_CASE("Setting and reading back MYTHEN3 dacs", "[.cmd][.dacs][.new]") {
}
}
TEST_CASE("counters", "[.cmd]") {
Detector det;
CmdProxy proxy(&det);

View File

@ -106,7 +106,6 @@ TEST_CASE("rx_framescaught", "[.cmd][.rx][.new]") {
// proxy.Call("rx_framescaught", {}, -1, GET, oss);
// REQUIRE(oss.str() == "rx_framescaught 1\n");
// }
}
TEST_CASE("rx_missingpackets", "[.cmd][.rx][.new]") {
@ -141,7 +140,6 @@ TEST_CASE("rx_printconfig", "[.cmd][.rx][.new]") {
REQUIRE_NOTHROW(proxy.Call("rx_printconfig", {}, -1, GET));
}
/* Receiver Config */
TEST_CASE("rx_hostname", "[.cmd][.rx][.new]") {
@ -149,7 +147,8 @@ TEST_CASE("rx_hostname", "[.cmd][.rx][.new]") {
CmdProxy proxy(&det);
auto prev_val = det.getRxHostname();
// Cannot set rx_hostname (will reset parameters in rxr and no shm variables to update)
// Cannot set rx_hostname (will reset parameters in rxr and no shm variables
// to update)
// {
// // disable receiver
// std::ostringstream oss;
@ -304,7 +303,8 @@ TEST_CASE("rx_padding", "[.cmd][.rx][.new]") {
TEST_CASE("rx_udpsocksize", "[.cmd][.rx][.new]") {
Detector det;
CmdProxy proxy(&det);
int64_t prev_val = det.getRxUDPSocketBufferSize().tsquash("Need same udp socket buffer size to test");
int64_t prev_val = det.getRxUDPSocketBufferSize().tsquash(
"Need same udp socket buffer size to test");
std::string s_new_val = std::to_string(prev_val - 1000);
{
std::ostringstream oss;
@ -648,7 +648,7 @@ TEST_CASE("rx_zmqport", "[.cmd][.rx][.new]") {
for (int i = 0; i != det.size(); ++i) {
det.setRxZmqPort(prev_val_zmqport[i], i);
if (det_type == defs::JUNGFRAU) {
det.setNumberofUDPInterfaces(prev_val_numinterfaces[i], {i});
det.setNumberofUDPInterfaces(prev_val_numinterfaces[i], {i});
}
}
}
@ -683,7 +683,9 @@ TEST_CASE("rx_dbitlist", "[.cmd][.rx][.new]") {
auto prev_val = det.getRxDbitList();
{
std::ostringstream oss;
proxy.Call("rx_dbitlist", {"0", "4", "5", "8", "9", "10", "52", "63"}, -1, PUT, oss);
proxy.Call("rx_dbitlist",
{"0", "4", "5", "8", "9", "10", "52", "63"}, -1, PUT,
oss);
REQUIRE(oss.str() == "rx_dbitlist [0, 4, 5, 8, 9, 10, 52, 63]\n");
}
{
@ -745,7 +747,8 @@ TEST_CASE("rx_jsonaddheader", "[.cmd][.rx][.new]") {
{
std::ostringstream oss;
proxy.Call("rx_jsonaddheader", {"key1", "value1", "key2", "value2"}, -1, PUT, oss);
proxy.Call("rx_jsonaddheader", {"key1", "value1", "key2", "value2"}, -1,
PUT, oss);
REQUIRE(oss.str() == "rx_jsonaddheader {key1: value1, key2: value2}\n");
}
{

View File

@ -2,9 +2,9 @@
#include "Detector.h"
#include "catch.hpp"
#include "sls_detector_defs.h"
#include <chrono>
#include <sstream>
#include <thread>
#include <chrono>
#include "tests/globals.h"
@ -36,24 +36,25 @@ TEST_CASE("parameters", "[.cmd][.new]") {
CmdProxy proxy(&det);
// put only
REQUIRE_THROWS(proxy.Call("parameters", {}, -1, GET));
/*
auto prev_val = det.getNumberOfFrames().tsquash("Number of frames has to be same to test");
{
system("echo 'frames 2' > /tmp/tempsetup.det ");
std::ostringstream oss;
proxy.Call("parameters", {"/tmp/tempsetup.det"}, -1, PUT, oss);
REQUIRE(oss.str() == "parameters /tmp/tempsetup.det\n");
REQUIRE(det.getNumberOfFrames().tsquash("failed") == 2);
}
{
system("echo '0:frames 1' > /tmp/tempsetup.det ");
std::ostringstream oss;
proxy.Call("parameters", {"/tmp/tempsetup.det"}, -1, PUT, oss);
REQUIRE(oss.str() == "parameters /tmp/tempsetup.det\n");
REQUIRE(det.getNumberOfFrames({0}).tsquash("failed") == 1);
}
det.setNumberOfFrames(prev_val);
*/
/*
auto prev_val = det.getNumberOfFrames().tsquash("Number of frames has to
be same to test");
{
system("echo 'frames 2' > /tmp/tempsetup.det ");
std::ostringstream oss;
proxy.Call("parameters", {"/tmp/tempsetup.det"}, -1, PUT, oss);
REQUIRE(oss.str() == "parameters /tmp/tempsetup.det\n");
REQUIRE(det.getNumberOfFrames().tsquash("failed") == 2);
}
{
system("echo '0:frames 1' > /tmp/tempsetup.det ");
std::ostringstream oss;
proxy.Call("parameters", {"/tmp/tempsetup.det"}, -1, PUT, oss);
REQUIRE(oss.str() == "parameters /tmp/tempsetup.det\n");
REQUIRE(det.getNumberOfFrames({0}).tsquash("failed") == 1);
}
det.setNumberOfFrames(prev_val);
*/
}
TEST_CASE("hostname", "[.cmd][.new]") {
@ -106,7 +107,7 @@ TEST_CASE("detectornumber", "[.cmd][.new]") {
REQUIRE_THROWS(proxy.Call("detectornumber", {"0"}, -1, PUT));
}
TEST_CASE("type", "[.cmd][.new]"){
TEST_CASE("type", "[.cmd][.new]") {
Detector det;
CmdProxy proxy(&det);
auto dt = det.getDetectorType().squash();
@ -130,46 +131,46 @@ TEST_CASE("settings", "[.cmd][.new]") {
auto det_type = det.getDetectorType().squash();
std::vector<std::string> sett;
switch (det_type) {
case defs::EIGER:
//FIXME: need to remove when settings removed
break;
case defs::JUNGFRAU:
sett.push_back("dynamicgain");
sett.push_back("dynamichg0");
sett.push_back("fixgain1");
sett.push_back("fixgain2");
sett.push_back("forceswitchg1");
sett.push_back("forceswitchg2");
break;
case defs::GOTTHARD:
sett.push_back("highgain");
sett.push_back("dynamicgain");
sett.push_back("lowgain");
sett.push_back("mediumgain");
sett.push_back("veryhighgain");
break;
case defs::GOTTHARD2:
sett.push_back("dynamicgain");
sett.push_back("fixgain1");
sett.push_back("fixgain2");
break;
case defs::MOENCH:
sett.push_back("g1_hg");
sett.push_back("g1_lg");
sett.push_back("g2_hc_hg");
sett.push_back("g2_hc_lg");
sett.push_back("g2_lc_hg");
sett.push_back("g2_lc_lg");
sett.push_back("g4_hg");
sett.push_back("g4_lg");
break;
default:
REQUIRE_THROWS(proxy.Call("settings", {}, -1, GET));
return;
case defs::EIGER:
// FIXME: need to remove when settings removed
break;
case defs::JUNGFRAU:
sett.push_back("dynamicgain");
sett.push_back("dynamichg0");
sett.push_back("fixgain1");
sett.push_back("fixgain2");
sett.push_back("forceswitchg1");
sett.push_back("forceswitchg2");
break;
case defs::GOTTHARD:
sett.push_back("highgain");
sett.push_back("dynamicgain");
sett.push_back("lowgain");
sett.push_back("mediumgain");
sett.push_back("veryhighgain");
break;
case defs::GOTTHARD2:
sett.push_back("dynamicgain");
sett.push_back("fixgain1");
sett.push_back("fixgain2");
break;
case defs::MOENCH:
sett.push_back("g1_hg");
sett.push_back("g1_lg");
sett.push_back("g2_hc_hg");
sett.push_back("g2_hc_lg");
sett.push_back("g2_lc_hg");
sett.push_back("g2_lc_lg");
sett.push_back("g4_hg");
sett.push_back("g4_lg");
break;
default:
REQUIRE_THROWS(proxy.Call("settings", {}, -1, GET));
return;
}
auto prev_val = det.getSettings();
for (auto & it : sett) {
for (auto &it : sett) {
{
std::ostringstream oss;
proxy.Call("settings", {it}, -1, PUT, oss);
@ -196,7 +197,8 @@ TEST_CASE("settings", "[.cmd][.new]") {
TEST_CASE("frames", "[.cmd][.new]") {
Detector det;
CmdProxy proxy(&det);
auto prev_val = det.getNumberOfFrames().tsquash("#frames must be same to test");
auto prev_val =
det.getNumberOfFrames().tsquash("#frames must be same to test");
{
std::ostringstream oss;
proxy.Call("frames", {"1000"}, -1, PUT, oss);
@ -219,7 +221,8 @@ TEST_CASE("frames", "[.cmd][.new]") {
TEST_CASE("triggers", "[.cmd][.new]") {
Detector det;
CmdProxy proxy(&det);
auto prev_val = det.getNumberOfTriggers().tsquash("#triggers must be same to test");
auto prev_val =
det.getNumberOfTriggers().tsquash("#triggers must be same to test");
{
std::ostringstream oss;
proxy.Call("triggers", {"1000"}, -1, PUT, oss);
@ -468,10 +471,8 @@ TEST_CASE("adcphase", "[.cmd][.new]") {
Detector det;
CmdProxy proxy(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::GOTTHARD ||
det_type == defs::JUNGFRAU ||
det_type == defs::CHIPTESTBOARD ||
det_type == defs::MOENCH) {
if (det_type == defs::GOTTHARD || det_type == defs::JUNGFRAU ||
det_type == defs::CHIPTESTBOARD || det_type == defs::MOENCH) {
if (det_type == defs::GOTTHARD) {
std::ostringstream oss1;
proxy.Call("adcphase", {"20"}, -1, PUT, oss1);
@ -509,10 +510,9 @@ TEST_CASE("maxadcphaseshift", "[.cmd][.new]") {
Detector det;
CmdProxy proxy(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::JUNGFRAU ||
det_type == defs::CHIPTESTBOARD ||
if (det_type == defs::JUNGFRAU || det_type == defs::CHIPTESTBOARD ||
det_type == defs::MOENCH ||
det_type == defs::MYTHEN3 || // only because clk index of 0 exists
det_type == defs::MYTHEN3 || // only because clk index of 0 exists
det_type == defs::GOTTHARD2) { // only because clk index of 0 exists
REQUIRE_NOTHROW(proxy.Call("maxadcphaseshift", {}, -1, GET));
} else {
@ -524,8 +524,7 @@ TEST_CASE("dbitphase", "[.cmd][.new]") {
Detector det;
CmdProxy proxy(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::JUNGFRAU ||
det_type == defs::CHIPTESTBOARD) {
if (det_type == defs::JUNGFRAU || det_type == defs::CHIPTESTBOARD) {
auto prev_val = det.getDBITPhase();
{
std::ostringstream oss1, oss2;
@ -554,9 +553,8 @@ TEST_CASE("maxdbitphaseshift", "[.cmd][.new]") {
Detector det;
CmdProxy proxy(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::JUNGFRAU ||
det_type == defs::CHIPTESTBOARD ||
det_type == defs::MYTHEN3 || // only because clk index of 0 exists
if (det_type == defs::JUNGFRAU || det_type == defs::CHIPTESTBOARD ||
det_type == defs::MYTHEN3 || // only because clk index of 0 exists
det_type == defs::GOTTHARD2) { // only because clk index of 0 exists
REQUIRE_NOTHROW(proxy.Call("maxdbitphaseshift", {}, -1, GET));
} else {
@ -654,7 +652,6 @@ TEST_CASE("maxclkphaseshift", "[.cmd][.new]") {
}
}
TEST_CASE("vhighvoltage", "[.cmd][.new]") {
Detector det;
CmdProxy proxy(&det);
@ -679,9 +676,8 @@ TEST_CASE("vhighvoltage", "[.cmd][.new]") {
}
}
// range 0, 60 - 200
else if (det_type == defs::JUNGFRAU ||
det_type == defs::CHIPTESTBOARD ||
det_type == defs::MOENCH) {
else if (det_type == defs::JUNGFRAU || det_type == defs::CHIPTESTBOARD ||
det_type == defs::MOENCH) {
REQUIRE_THROWS(proxy.Call("vhighvoltage", {"50"}, -1, PUT));
{
std::ostringstream oss1, oss2;
@ -761,10 +757,8 @@ TEST_CASE("powerchip", "[.cmd][.new]") {
CmdProxy proxy(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::JUNGFRAU ||
det_type == defs::MYTHEN3 ||
det_type == defs::GOTTHARD2 ||
det_type == defs::MOENCH) {
if (det_type == defs::JUNGFRAU || det_type == defs::MYTHEN3 ||
det_type == defs::GOTTHARD2 || det_type == defs::MOENCH) {
auto prev_val = det.getPowerChip();
{
std::ostringstream oss;
@ -812,8 +806,7 @@ TEST_CASE("imagetest", "[.cmd][.new]") {
for (int i = 0; i != det.size(); ++i) {
det.setImageTestMode(prev_val[i], {i});
}
} else if (det_type != defs::JUNGFRAU &&
det_type != defs::EIGER) {
} else if (det_type != defs::JUNGFRAU && det_type != defs::EIGER) {
// wont fail for eiger and jungfrau virtual servers
REQUIRE_THROWS(proxy.Call("imagetest", {}, -1, GET));
}
@ -829,7 +822,7 @@ TEST_CASE("temp_adc", "[.cmd][.new]") {
REQUIRE_NOTHROW(proxy.Call("temp_adc", {}, -1, GET));
std::ostringstream oss;
REQUIRE_NOTHROW(proxy.Call("temp_adc", {}, 0, GET, oss));
std::string s = (oss.str()).erase (0, strlen("temp_adc "));
std::string s = (oss.str()).erase(0, strlen("temp_adc "));
REQUIRE(std::stoi(s) != -1);
} else {
REQUIRE_THROWS(proxy.Call("temp_adc", {}, -1, GET));
@ -841,11 +834,11 @@ TEST_CASE("temp_fpga", "[.cmd][.new]") {
CmdProxy proxy(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::JUNGFRAU || det_type == defs::GOTTHARD ||
det_type == defs::EIGER) {
det_type == defs::EIGER) {
REQUIRE_NOTHROW(proxy.Call("temp_fpga", {}, -1, GET));
std::ostringstream oss;
REQUIRE_NOTHROW(proxy.Call("temp_fpga", {}, 0, GET, oss));
std::string s = (oss.str()).erase (0, strlen("temp_fpga "));
std::string s = (oss.str()).erase(0, strlen("temp_fpga "));
REQUIRE(std::stoi(s) != -1);
} else {
REQUIRE_THROWS(proxy.Call("temp_fpga", {}, -1, GET));
@ -965,44 +958,6 @@ TEST_CASE("startingfnum", "[.cmd][.new]") {
}
}
TEST_CASE("initialchecks", "[.cmd]") {
Detector det;
CmdProxy proxy(&det);
@ -1032,7 +987,6 @@ TEST_CASE("initialchecks", "[.cmd]") {
det.setInitialChecks(check);
}
TEST_CASE("user", "[.cmd]") {
Detector det;
CmdProxy proxy(&det);
@ -1313,7 +1267,6 @@ TEST_CASE("stopport", "[.cmd]") {
// REQUIRE_NOTHROW(multiSlsDetectorClient("rx_jsonaddheader \"\"", PUT));
// }
// TEST_CASE("patsetbit", "[.cmd][.ctb]") {
// if (test::type == defs::CHIPTESTBOARD) {
// uint64_t val = 0;
@ -1932,8 +1885,6 @@ TEST_CASE("stopport", "[.cmd]") {
// }
// }
// TEST_CASE("romode", "[.cmd][.ctb]") {
// if (test::type == defs::CHIPTESTBOARD) {
// {
@ -2415,8 +2366,6 @@ TEST_CASE("stopport", "[.cmd]") {
// }
// }
// TEST_CASE("trimval", "[.cmd][.eiger]") {
// if (test::type == defs::EIGER) {
// {
@ -2460,8 +2409,6 @@ TEST_CASE("stopport", "[.cmd]") {
// }
// }
// TEST_CASE("parallel", "[.cmd][.eiger]") {
// if (test::type == defs::EIGER) {
// {
@ -2556,7 +2503,9 @@ TEST_CASE("zmqport", "[.cmd]") {
for (int i = 0; i != det.size(); ++i) {
std::ostringstream oss;
proxy.Call("zmqport", {}, i, GET, oss);
REQUIRE(oss.str() == "zmqport " + std::to_string(port + i * socketsperdetector) + '\n');
REQUIRE(oss.str() == "zmqport " +
std::to_string(port + i * socketsperdetector) +
'\n');
}
port = 1954;
@ -2569,18 +2518,15 @@ TEST_CASE("zmqport", "[.cmd]") {
for (int i = 0; i != det.size(); ++i) {
std::ostringstream oss;
proxy.Call("zmqport", {}, i, GET, oss);
REQUIRE(oss.str() == "zmqport " + std::to_string(port + i * socketsperdetector) + '\n');
REQUIRE(oss.str() == "zmqport " +
std::to_string(port + i * socketsperdetector) +
'\n');
}
if (det_type == defs::JUNGFRAU) {
det.setNumberofUDPInterfaces(prev);
}
}
// TEST_CASE("txndelay", "[.cmd][.eiger][.jungfrau]") {
// if (test::type == defs::EIGER) {
// {
@ -2823,8 +2769,6 @@ TEST_CASE("zmqport", "[.cmd]") {
// REQUIRE_THROWS(multiSlsDetectorClient("numinterfaces 0", PUT));
// }
// TEST_CASE("adc", "[.cmd][.ctb]") {
// if (test::type != defs::CHIPTESTBOARD) {
// REQUIRE_THROWS(multiSlsDetectorClient("adc 8", GET));
@ -2838,9 +2782,6 @@ TEST_CASE("zmqport", "[.cmd]") {
// }
// }
// TEST_CASE("syncclk", "[.cmd][.ctb]") {
// if(test::type != defs::CHIPTESTBOARD) {
// REQUIRE_THROWS(multiSlsDetectorClient("syncclk", GET));
@ -2934,8 +2875,6 @@ TEST_CASE("zmqport", "[.cmd]") {
// }
// }
// TEST_CASE("threshold", "[.cmd]") {
// if (test::type == defs::EIGER) {
// REQUIRE_NOTHROW(multiSlsDetectorClient("threshold 6400 standard",
@ -2964,7 +2903,6 @@ TEST_CASE("zmqport", "[.cmd]") {
// CHECK_NOTHROW(multiSlsDetectorClient("type", GET));
// }
// TEST_CASE("status", "[.cmd]") {
// Detector det;
// CmdProxy proxy(&det);
@ -2999,11 +2937,6 @@ TEST_CASE("zmqport", "[.cmd]") {
// proxy.Call("frames", {"1"}, -1, PUT);
// }
TEST_CASE("lock", "[.cmd]") {
Detector det;
CmdProxy proxy(&det);
@ -3027,8 +2960,3 @@ TEST_CASE("lock", "[.cmd]") {
// TEST_CASE("lastclient", "[.cmd]") {
// REQUIRE_NOTHROW(multiSlsDetectorClient("lastclient", GET));
// }

View File

@ -1,8 +1,8 @@
#include "Result.h"
#include "ToString.h"
#include "TypeTraits.h"
#include "catch.hpp"
#include <string>
#include "ToString.h"
using sls::Result;
@ -35,13 +35,12 @@ TEST_CASE("Like vector it can be constructed from size and value") {
REQUIRE(res[4] == 7);
}
TEST_CASE("Result can be iterated using modern syntax"){
Result<int> res{0,1,2,3,4,5};
TEST_CASE("Result can be iterated using modern syntax") {
Result<int> res{0, 1, 2, 3, 4, 5};
int i = 0;
for (const auto& r:res)
for (const auto &r : res)
REQUIRE(r == i++);
}
TEST_CASE("Calling squash on an empty Result produces default value") {
@ -136,21 +135,20 @@ TEST_CASE("Convert from Result<int> to Result<ns>") {
REQUIRE(res2[2] == ns(236));
}
TEST_CASE("Result of vectors"){
TEST_CASE("Result of vectors") {
using VecVec = std::vector<std::vector<int>>;
VecVec vecvec{{1,2,3}, {4,5,6}};
VecVec vecvec{{1, 2, 3}, {4, 5, 6}};
Result<VecVec> res{vecvec};
}
TEST_CASE("Free function begin end"){
TEST_CASE("Free function begin end") {
Result<std::string> res{"ett", "nio", "sjutton"};
REQUIRE(begin(res) == res.begin());
REQUIRE(end(res) == res.end());
}
TEST_CASE("Sorting a Result"){
Result<int> res{4,5,1,3};
TEST_CASE("Sorting a Result") {
Result<int> res{4, 5, 1, 3};
std::sort(res.begin(), res.end());
REQUIRE(res[0] == 1);
REQUIRE(res[1] == 3);
@ -158,24 +156,22 @@ TEST_CASE("Sorting a Result"){
REQUIRE(res[3] == 5);
}
TEST_CASE("Printing Result<std::string>"){
TEST_CASE("Printing Result<std::string>") {
Result<std::string> res{"ein", "zwei", "drei"};
std::ostringstream os;
os << res;
REQUIRE(os.str() == "[ein, zwei, drei]");
}
TEST_CASE("Printing Result<int>"){
TEST_CASE("Printing Result<int>") {
Result<int> res{1, 2, 3};
std::ostringstream os;
os << res;
REQUIRE(os.str() == "[1, 2, 3]");
}
TEST_CASE("String conversions"){
Result<int> res{1,2,3};
TEST_CASE("String conversions") {
Result<int> res{1, 2, 3};
REQUIRE(ToString(res) == "[1, 2, 3]");
Result<std::string> res2{"one", "two", "three"};
@ -185,7 +181,7 @@ TEST_CASE("String conversions"){
Smap m;
m["one"] = "1";
Result<Smap> res3{m, m, m};
REQUIRE(res3.size()== 3);
REQUIRE(res3.size() == 3);
REQUIRE(ToString(res3) == "[{one: 1}, {one: 1}, {one: 1}]");
Smap m2;
@ -194,5 +190,6 @@ TEST_CASE("String conversions"){
m2["three"] = "3";
Result<Smap> res4{m, m2, m};
REQUIRE(ToString(res4) == "[{one: 1}, {one: 1, three: 3, two: 2}, {one: 1}]");
REQUIRE(ToString(res4) ==
"[{one: 1}, {one: 1, three: 3, two: 2}, {one: 1}]");
}

23
slsDetectorSoftware/tests/test-SharedMemory.cpp Executable file → Normal file
View File

@ -64,24 +64,24 @@ TEST_CASE("Creating a second shared memory with the same name throws",
TEST_CASE("Open two shared memories to the same place", "[detector]") {
//Create the first shared memory
// Create the first shared memory
SharedMemory<Data> shm(shm_id, -1);
shm.CreateSharedMemory();
shm()->x = 5;
CHECK(shm()->x == 5);
//Open the second shared memory with the same name
// Open the second shared memory with the same name
SharedMemory<Data> shm2(shm_id, -1);
shm2.OpenSharedMemory();
CHECK(shm2()->x == 5);
CHECK(shm.GetName() == shm2.GetName());
//Check that they still point to the same place
// Check that they still point to the same place
shm2()->x = 7;
CHECK(shm()->x == 7);
//Remove only needs to be done once since they refer
//to the same memory
// Remove only needs to be done once since they refer
// to the same memory
shm2.RemoveSharedMemory();
CHECK(shm.IsExisting() == false);
CHECK(shm2.IsExisting() == false);
@ -95,19 +95,18 @@ TEST_CASE("Move SharedMemory", "[detector]") {
shm.CreateSharedMemory();
shm()->x = 9;
CHECK(shm.size()== sizeof(Data));
CHECK(shm.size() == sizeof(Data));
SharedMemory<Data> shm2(shm_id+1, -1);
shm2 = std::move(shm); //shm is now a moved from object!
SharedMemory<Data> shm2(shm_id + 1, -1);
shm2 = std::move(shm); // shm is now a moved from object!
CHECK(shm2()->x == 9);
CHECK(shm() == nullptr);
CHECK(shm.size() == 0);
CHECK(shm2.GetName() == std::string("/slsDetectorPackage_multi_") +
std::to_string(shm_id));
CHECK(shm2.GetName() ==
std::string("/slsDetectorPackage_multi_") + std::to_string(shm_id));
shm2.RemoveSharedMemory();
}
TEST_CASE("Create several shared memories", "[detector]") {
@ -115,7 +114,7 @@ TEST_CASE("Create several shared memories", "[detector]") {
std::vector<SharedMemory<int>> v;
v.reserve(N);
for (int i = 0; i != N; ++i) {
v.emplace_back(shm_id+i, -1);
v.emplace_back(shm_id + i, -1);
CHECK(v[i].IsExisting() == false);
v[i].CreateSharedMemory();
*v[i]() = i;

9
slsDetectorSoftware/tests/test-slsDetector.cpp Executable file → Normal file
View File

@ -7,8 +7,6 @@
// #include <algorithm>
// #include <iostream>
// TEST_CASE("Set and get trimen", "[detector]") {
// // Free shared memory to be sure that we start in a clean state
// slsDetector::freeSharedMemory(20, 20);
@ -188,12 +186,10 @@
// d.setPartialFramesPadding(true);
// CHECK(d.getPartialFramesPadding() == true);
// d.freeSharedMemory();
// }
// TEST_CASE("create detParamets struct", "[detector][new]"){
// detParameters par;
// CHECK(sizeof(par) == 32);
@ -206,7 +202,6 @@
// CHECK(par.nGappixelsX == 0);
// CHECK(par.nGappixelsY == 0);
// detParameters par2{slsDetectorDefs::detectorType::EIGER};
// CHECK(sizeof(par2) == 32);
// CHECK(par2.nChanX == 256);
@ -219,7 +214,6 @@
// CHECK(par2.nGappixelsY == 1);
// }
// TEST_CASE("ctb digital offset and list", "[detector][ctb]"){
// slsDetector::freeSharedMemory(20, 20);
// slsDetector d(slsDetectorDefs::detectorType::CHIPTESTBOARD, 20, 20);
@ -235,7 +229,6 @@
// std::vector <int> list = d.getReceiverDbitList();
// CHECK(list.empty());
// for (int i = 0; i < 10; ++i)
// list.push_back(i);
// d.setReceiverDbitList(list);
@ -258,6 +251,4 @@
// d.setReceiverDbitList(list);
// CHECK(d.getReceiverDbitList().empty());
// }

View File

@ -1,12 +1,11 @@
#pragma once
#include <string>
#include "sls_detector_defs.h"
#include <string>
struct SingleDetectorConfig {
slsDetectorDefs::detectorType type_enum = slsDetectorDefs::detectorType::EIGER;
slsDetectorDefs::detectorType type_enum =
slsDetectorDefs::detectorType::EIGER;
const std::string hostname = "beb031+beb032+";
const std::string type_string = "Eiger";
const std::string my_ip = "129.129.205.171";
};

View File

@ -12,5 +12,4 @@ extern std::string my_ip;
extern decltype(defs::GET_ACTION) GET;
extern decltype(defs::PUT_ACTION) PUT;
} // namespace test

View File

@ -1,5 +1,5 @@
#pragma once
#include <cstdint>
enum class func_id{read_data, read_int, read_half_data, combined};
enum class func_id { read_data, read_int, read_half_data, combined };
constexpr size_t MB = 1048576;
constexpr size_t DATA_SIZE = 50*MB;
constexpr size_t DATA_SIZE = 50 * MB;

View File

@ -39,7 +39,7 @@ void read_int(Interface &socket) {
std::cout << "Read <int>: " << i << "\n";
}
void read_combined(Interface &socket){
void read_combined(Interface &socket) {
auto i = socket.Receive<int>();
auto d = socket.Receive<double>();
auto f = socket.Receive<float>();