Merge pull request #299 from slsdetectorgroup/naming

Naming
This commit is contained in:
Dhanya Thattil 2021-09-17 11:36:22 +02:00 committed by GitHub
commit 35d102c5ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 384 additions and 404 deletions

View File

@ -19,7 +19,7 @@ class IpAddr;
// 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);
void freeSharedMemory(int detectorIndex, int moduleIndex = -1);
/**
* \class Detector

View File

@ -17,29 +17,29 @@
namespace sls {
void freeSharedMemory(int multiId, int detPos) {
// single
if (detPos >= 0) {
SharedMemory<sharedSlsDetector> temp_shm(multiId, detPos);
if (temp_shm.IsExisting()) {
temp_shm.RemoveSharedMemory();
void freeSharedMemory(int detectorIndex, int moduleIndex) {
// single module
if (moduleIndex >= 0) {
SharedMemory<sharedModule> moduleShm(detectorIndex, moduleIndex);
if (moduleShm.IsExisting()) {
moduleShm.RemoveSharedMemory();
}
return;
}
// multi - get number of detectors from shm
SharedMemory<sharedMultiSlsDetector> multiShm(multiId, -1);
// detector - multi module - get number of detectors from shm
SharedMemory<sharedDetector> detectorShm(detectorIndex, -1);
int numDetectors = 0;
if (multiShm.IsExisting()) {
multiShm.OpenSharedMemory();
numDetectors = multiShm()->numberOfDetectors;
multiShm.RemoveSharedMemory();
if (detectorShm.IsExisting()) {
detectorShm.OpenSharedMemory();
numDetectors = detectorShm()->numberOfModules;
detectorShm.RemoveSharedMemory();
}
for (int i = 0; i < numDetectors; ++i) {
SharedMemory<sharedSlsDetector> shm(multiId, i);
shm.RemoveSharedMemory();
SharedMemory<sharedModule> moduleShm(detectorIndex, i);
moduleShm.RemoveSharedMemory();
}
}
@ -101,7 +101,7 @@ void Detector::setVirtualDetectorServers(int numServers, int startingPort) {
pimpl->setVirtualDetectorServers(numServers, startingPort);
}
int Detector::getShmId() const { return pimpl->getMultiId(); }
int Detector::getShmId() const { return pimpl->getDetectorIndex(); }
std::string Detector::getPackageVersion() const { return GITBRANCH; }
@ -136,7 +136,7 @@ int Detector::size() const { return pimpl->size(); }
bool Detector::empty() const { return pimpl->size() == 0; }
defs::xy Detector::getModuleGeometry() const {
return pimpl->getNumberOfDetectors();
return pimpl->getNumberOfModules();
}
Result<defs::xy> Detector::getModuleSize(Positions pos) const {

View File

@ -28,14 +28,14 @@
namespace sls {
DetectorImpl::DetectorImpl(int multi_id, bool verify, bool update)
: multiId(multi_id), multi_shm(multi_id, -1) {
setupMultiDetector(verify, update);
DetectorImpl::DetectorImpl(int detector_index, bool verify, bool update)
: detectorIndex(detector_index), shm(detector_index, -1) {
setupDetector(verify, update);
}
DetectorImpl::~DetectorImpl() = default;
void DetectorImpl::setupMultiDetector(bool verify, bool update) {
void DetectorImpl::setupDetector(bool verify, bool update) {
initSharedMemory(verify);
initializeMembers(verify);
if (update) {
@ -43,104 +43,100 @@ void DetectorImpl::setupMultiDetector(bool verify, bool update) {
}
}
void DetectorImpl::setAcquiringFlag(bool flag) {
multi_shm()->acquiringFlag = flag;
}
void DetectorImpl::setAcquiringFlag(bool flag) { shm()->acquiringFlag = flag; }
int DetectorImpl::getMultiId() const { return multiId; }
int DetectorImpl::getDetectorIndex() const { return detectorIndex; }
void DetectorImpl::freeSharedMemory(int multiId, int detPos) {
void DetectorImpl::freeSharedMemory(int detectorIndex, int detPos) {
// single
if (detPos >= 0) {
SharedMemory<sharedSlsDetector> temp_shm(multiId, detPos);
if (temp_shm.IsExisting()) {
temp_shm.RemoveSharedMemory();
SharedMemory<sharedModule> moduleShm(detectorIndex, detPos);
if (moduleShm.IsExisting()) {
moduleShm.RemoveSharedMemory();
}
return;
}
// multi - get number of detectors from shm
SharedMemory<sharedMultiSlsDetector> multiShm(multiId, -1);
int numDetectors = 0;
// multi - get number of modules from shm
SharedMemory<sharedDetector> detectorShm(detectorIndex, -1);
int numModules = 0;
if (multiShm.IsExisting()) {
multiShm.OpenSharedMemory();
numDetectors = multiShm()->numberOfDetectors;
multiShm.RemoveSharedMemory();
if (detectorShm.IsExisting()) {
detectorShm.OpenSharedMemory();
numModules = detectorShm()->numberOfModules;
detectorShm.RemoveSharedMemory();
}
for (int i = 0; i < numDetectors; ++i) {
SharedMemory<sharedSlsDetector> shm(multiId, i);
shm.RemoveSharedMemory();
for (int i = 0; i < numModules; ++i) {
SharedMemory<sharedModule> moduleShm(detectorIndex, i);
moduleShm.RemoveSharedMemory();
}
}
void DetectorImpl::freeSharedMemory() {
zmqSocket.clear();
for (auto &d : detectors) {
d->freeSharedMemory();
for (auto &module : modules) {
module->freeSharedMemory();
}
detectors.clear();
modules.clear();
// clear multi detector shm
multi_shm.RemoveSharedMemory();
// clear detector shm
shm.RemoveSharedMemory();
client_downstream = false;
}
std::string DetectorImpl::getUserDetails() {
if (detectors.empty()) {
if (modules.empty()) {
return std::string("none");
}
std::ostringstream sstream;
sstream << "\nHostname: ";
for (auto &d : detectors) {
sstream << (d->isFixedPatternSharedMemoryCompatible() ? d->getHostname()
: "Unknown")
for (auto &module : modules) {
sstream << (module->isFixedPatternSharedMemoryCompatible()
? module->getHostname()
: "Unknown")
<< "+";
}
sstream << "\nType: ";
// get type from multi shm
if (multi_shm()->shmversion >= MULTI_SHMAPIVERSION) {
sstream << ToString(multi_shm()->multiDetectorType);
// get type from detector version shm
if (shm()->shmversion >= DETECTOR_SHMAPIVERSION) {
sstream << ToString(shm()->detType);
}
// get type from slsdet shm
// get type from module shm
else {
for (auto &d : detectors) {
sstream << (d->isFixedPatternSharedMemoryCompatible()
? ToString(d->getDetectorType())
for (auto &module : modules) {
sstream << (module->isFixedPatternSharedMemoryCompatible()
? ToString(module->getDetectorType())
: "Unknown")
<< "+";
}
}
sstream << "\nPID: " << multi_shm()->lastPID
<< "\nUser: " << multi_shm()->lastUser
<< "\nDate: " << multi_shm()->lastDate << std::endl;
sstream << "\nPID: " << shm()->lastPID << "\nUser: " << shm()->lastUser
<< "\nDate: " << shm()->lastDate << std::endl;
return sstream.str();
}
bool DetectorImpl::getInitialChecks() const {
return multi_shm()->initialChecks;
}
bool DetectorImpl::getInitialChecks() const { return shm()->initialChecks; }
void DetectorImpl::setInitialChecks(const bool value) {
multi_shm()->initialChecks = value;
shm()->initialChecks = value;
}
void DetectorImpl::initSharedMemory(bool verify) {
if (!multi_shm.IsExisting()) {
multi_shm.CreateSharedMemory();
if (!shm.IsExisting()) {
shm.CreateSharedMemory();
initializeDetectorStructure();
} else {
multi_shm.OpenSharedMemory();
if (verify && multi_shm()->shmversion != MULTI_SHMVERSION) {
LOG(logERROR) << "Multi shared memory (" << multiId
shm.OpenSharedMemory();
if (verify && shm()->shmversion != DETECTOR_SHMVERSION) {
LOG(logERROR) << "Detector shared memory (" << detectorIndex
<< ") version mismatch "
"(expected 0x"
<< std::hex << MULTI_SHMVERSION << " but got 0x"
<< multi_shm()->shmversion << std::dec
<< std::hex << DETECTOR_SHMVERSION << " but got 0x"
<< shm()->shmversion << std::dec
<< ". Clear Shared memory to continue.";
throw SharedMemoryError("Shared memory version mismatch!");
}
@ -148,18 +144,18 @@ void DetectorImpl::initSharedMemory(bool verify) {
}
void DetectorImpl::initializeDetectorStructure() {
multi_shm()->shmversion = MULTI_SHMVERSION;
multi_shm()->numberOfDetectors = 0;
multi_shm()->multiDetectorType = GENERIC;
multi_shm()->numberOfDetector.x = 0;
multi_shm()->numberOfDetector.y = 0;
multi_shm()->numberOfChannels.x = 0;
multi_shm()->numberOfChannels.y = 0;
multi_shm()->acquiringFlag = false;
multi_shm()->initialChecks = true;
multi_shm()->gapPixels = false;
shm()->shmversion = DETECTOR_SHMVERSION;
shm()->numberOfModules = 0;
shm()->detType = GENERIC;
shm()->numberOfModule.x = 0;
shm()->numberOfModule.y = 0;
shm()->numberOfChannels.x = 0;
shm()->numberOfChannels.y = 0;
shm()->acquiringFlag = false;
shm()->initialChecks = true;
shm()->gapPixels = false;
// zmqlib default
multi_shm()->zmqHwm = -1;
shm()->zmqHwm = -1;
}
void DetectorImpl::initializeMembers(bool verify) {
@ -167,38 +163,39 @@ void DetectorImpl::initializeMembers(bool verify) {
zmqSocket.clear();
// get objects from single det shared memory (open)
for (int i = 0; i < multi_shm()->numberOfDetectors; i++) {
for (int i = 0; i < shm()->numberOfModules; i++) {
try {
detectors.push_back(sls::make_unique<Module>(multiId, i, verify));
modules.push_back(
sls::make_unique<Module>(detectorIndex, i, verify));
} catch (...) {
detectors.clear();
modules.clear();
throw;
}
}
}
void DetectorImpl::updateUserdetails() {
multi_shm()->lastPID = getpid();
memset(multi_shm()->lastUser, 0, sizeof(multi_shm()->lastUser));
memset(multi_shm()->lastDate, 0, sizeof(multi_shm()->lastDate));
shm()->lastPID = getpid();
memset(shm()->lastUser, 0, sizeof(shm()->lastUser));
memset(shm()->lastDate, 0, sizeof(shm()->lastDate));
try {
sls::strcpy_safe(multi_shm()->lastUser, exec("whoami").c_str());
sls::strcpy_safe(multi_shm()->lastDate, exec("date").c_str());
sls::strcpy_safe(shm()->lastUser, exec("whoami").c_str());
sls::strcpy_safe(shm()->lastDate, exec("date").c_str());
} catch (...) {
sls::strcpy_safe(multi_shm()->lastUser, "errorreading");
sls::strcpy_safe(multi_shm()->lastDate, "errorreading");
sls::strcpy_safe(shm()->lastUser, "errorreading");
sls::strcpy_safe(shm()->lastDate, "errorreading");
}
}
bool DetectorImpl::isAcquireReady() {
if (multi_shm()->acquiringFlag) {
if (shm()->acquiringFlag) {
LOG(logWARNING)
<< "Acquire has already started. "
"If previous acquisition terminated unexpectedly, "
"reset busy flag to restart.(sls_detector_put clearbusy)";
return false;
}
multi_shm()->acquiringFlag = true;
shm()->acquiringFlag = true;
return true;
}
@ -233,22 +230,22 @@ 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."
if (shm()->numberOfModules != 0) {
LOG(logWARNING) << "There are already module(s) in shared memory."
"Freeing Shared memory now.";
bool initialChecks = multi_shm()->initialChecks;
bool initialChecks = shm()->initialChecks;
freeSharedMemory();
setupMultiDetector();
multi_shm()->initialChecks = initialChecks;
setupDetector();
shm()->initialChecks = initialChecks;
}
for (const auto &hostname : name) {
addSlsDetector(hostname);
addModule(hostname);
}
updateDetectorSize();
}
void DetectorImpl::addSlsDetector(const std::string &hostname) {
LOG(logINFO) << "Adding detector " << hostname;
void DetectorImpl::addModule(const std::string &hostname) {
LOG(logINFO) << "Adding module " << hostname;
int port = DEFAULT_PORTNO;
std::string host = hostname;
@ -259,11 +256,11 @@ void DetectorImpl::addSlsDetector(const std::string &hostname) {
}
if (host != "localhost") {
for (auto &d : detectors) {
if (d->getHostname() == host) {
for (auto &module : modules) {
if (module->getHostname() == host) {
LOG(logWARNING)
<< "Detector " << host
<< "already part of the multiDetector!" << std::endl
<< "Module " << host << "already part of the Detector!"
<< std::endl
<< "Remove it before adding it back in a new position!";
return;
}
@ -272,33 +269,33 @@ 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));
multi_shm()->numberOfDetectors = detectors.size();
detectors[pos]->setControlPort(port);
detectors[pos]->setStopPort(port + 1);
detectors[pos]->setHostname(host, multi_shm()->initialChecks);
// detector type updated by now
multi_shm()->multiDetectorType =
Parallel(&Module::getDetectorType, {})
.tsquash("Inconsistent detector types.");
auto pos = modules.size();
modules.emplace_back(
sls::make_unique<Module>(type, detectorIndex, pos, false));
shm()->numberOfModules = modules.size();
modules[pos]->setControlPort(port);
modules[pos]->setStopPort(port + 1);
modules[pos]->setHostname(host, shm()->initialChecks);
// module type updated by now
shm()->detType = Parallel(&Module::getDetectorType, {})
.tsquash("Inconsistent detector types.");
// for moench and ctb
detectors[pos]->updateNumberOfChannels();
modules[pos]->updateNumberOfChannels();
}
void DetectorImpl::updateDetectorSize() {
LOG(logDEBUG) << "Updating Multi-Detector Size: " << size();
LOG(logDEBUG) << "Updating Detector Size: " << size();
const slsDetectorDefs::xy det_size = detectors[0]->getNumberOfChannels();
const slsDetectorDefs::xy det_size = modules[0]->getNumberOfChannels();
if (det_size.x == 0 || det_size.y == 0) {
throw sls::RuntimeError("Module size for x or y dimensions is 0. Unable to proceed in updating detector size. ");
}
int maxx = multi_shm()->numberOfChannels.x;
int maxy = multi_shm()->numberOfChannels.y;
int maxx = shm()->numberOfChannels.x;
int maxy = shm()->numberOfChannels.y;
int ndetx = 0, ndety = 0;
// 1d, add detectors along x axis
// 1d, add modules along x axis
if (det_size.y == 1) {
if (maxx == 0) {
maxx = det_size.x * size();
@ -309,7 +306,7 @@ void DetectorImpl::updateDetectorSize() {
++ndety;
}
}
// 2d, add detectors along y axis (due to eiger top/bottom)
// 2d, add modules along y axis (due to eiger top/bottom)
else {
if (maxy == 0) {
maxy = det_size.y * size();
@ -321,33 +318,33 @@ void DetectorImpl::updateDetectorSize() {
}
}
multi_shm()->numberOfDetector.x = ndetx;
multi_shm()->numberOfDetector.y = ndety;
multi_shm()->numberOfChannels.x = det_size.x * ndetx;
multi_shm()->numberOfChannels.y = det_size.y * ndety;
shm()->numberOfModule.x = ndetx;
shm()->numberOfModule.y = ndety;
shm()->numberOfChannels.x = det_size.x * ndetx;
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
LOG(logDEBUG) << "\n\tNumber of Modules in X direction:"
<< shm()->numberOfModule.x
<< "\n\tNumber of Modules in Y direction:"
<< shm()->numberOfModule.y
<< "\n\tNumber of Channels in X direction:"
<< multi_shm()->numberOfChannels.x
<< shm()->numberOfChannels.x
<< "\n\tNumber of Channels in Y direction:"
<< multi_shm()->numberOfChannels.y;
<< shm()->numberOfChannels.y;
for (auto &d : detectors) {
d->updateNumberOfDetector(multi_shm()->numberOfDetector);
for (auto &module : modules) {
module->updateNumberOfModule(shm()->numberOfModule);
}
}
int DetectorImpl::size() const { return detectors.size(); }
int DetectorImpl::size() const { return modules.size(); }
slsDetectorDefs::xy DetectorImpl::getNumberOfDetectors() const {
return multi_shm()->numberOfDetector;
slsDetectorDefs::xy DetectorImpl::getNumberOfModules() const {
return shm()->numberOfModule;
}
slsDetectorDefs::xy DetectorImpl::getNumberOfChannels() const {
return multi_shm()->numberOfChannels;
return shm()->numberOfChannels;
}
void DetectorImpl::setNumberOfChannels(const slsDetectorDefs::xy c) {
@ -355,33 +352,31 @@ void DetectorImpl::setNumberOfChannels(const slsDetectorDefs::xy c) {
throw RuntimeError(
"Set the number of channels before setting hostname.");
}
multi_shm()->numberOfChannels = c;
shm()->numberOfChannels = c;
}
bool DetectorImpl::getGapPixelsinCallback() const {
return multi_shm()->gapPixels;
}
bool DetectorImpl::getGapPixelsinCallback() const { return shm()->gapPixels; }
void DetectorImpl::setGapPixelsinCallback(const bool enable) {
if (enable) {
switch (multi_shm()->multiDetectorType) {
switch (shm()->detType) {
case JUNGFRAU:
break;
case EIGER:
if (size() && detectors[0]->getQuad()) {
if (size() && modules[0]->getQuad()) {
break;
}
if (multi_shm()->numberOfDetector.y % 2 != 0) {
if (shm()->numberOfModule.y % 2 != 0) {
throw RuntimeError("Gap pixels can only be used "
"for full modules.");
}
break;
default:
throw RuntimeError("Gap Pixels is not implemented for " +
ToString(multi_shm()->multiDetectorType));
ToString(shm()->detType));
}
}
multi_shm()->gapPixels = enable;
shm()->gapPixels = enable;
}
int DetectorImpl::destroyReceivingDataSockets() {
@ -400,33 +395,33 @@ int DetectorImpl::createReceivingDataSockets() {
}
LOG(logINFO) << "Going to create data sockets";
size_t numSockets = detectors.size();
size_t numSocketsPerDetector = 1;
if (multi_shm()->multiDetectorType == EIGER) {
numSocketsPerDetector = 2;
size_t numSockets = modules.size();
size_t numSocketsPerModule = 1;
if (shm()->detType == EIGER) {
numSocketsPerModule = 2;
}
// gotthard2 second interface is only for veto debugging
else if (multi_shm()->multiDetectorType != GOTTHARD2) {
else if (shm()->detType != GOTTHARD2) {
if (Parallel(&Module::getNumberofUDPInterfacesFromShm, {}).squash() ==
2) {
numSocketsPerDetector = 2;
numSocketsPerModule = 2;
}
}
numSockets *= numSocketsPerDetector;
numSockets *= numSocketsPerModule;
for (size_t iSocket = 0; iSocket < numSockets; ++iSocket) {
uint32_t portnum = (detectors[iSocket / numSocketsPerDetector]
->getClientStreamingPort());
portnum += (iSocket % numSocketsPerDetector);
uint32_t portnum =
(modules[iSocket / numSocketsPerModule]->getClientStreamingPort());
portnum += (iSocket % numSocketsPerModule);
try {
zmqSocket.push_back(sls::make_unique<ZmqSocket>(
detectors[iSocket / numSocketsPerDetector]
modules[iSocket / numSocketsPerModule]
->getClientStreamingIP()
.str()
.c_str(),
portnum));
// set high water mark
int hwm = multi_shm()->zmqHwm;
int hwm = shm()->zmqHwm;
if (hwm >= 0) {
zmqSocket[iSocket]->SetReceiveHighWaterMark(hwm);
if (zmqSocket[iSocket]->GetReceiveHighWaterMark() != hwm) {
@ -451,7 +446,7 @@ int DetectorImpl::createReceivingDataSockets() {
void DetectorImpl::readFrameFromReceiver() {
bool gapPixels = multi_shm()->gapPixels;
bool gapPixels = shm()->gapPixels;
LOG(logDEBUG) << "Gap pixels: " << gapPixels;
int nX = 0;
int nY = 0;
@ -461,7 +456,7 @@ void DetectorImpl::readFrameFromReceiver() {
bool eiger = false;
bool numInterfaces = 1;
// gotthard2 second interface is veto debugging
if (multi_shm()->multiDetectorType != GOTTHARD2) {
if (shm()->detType != GOTTHARD2) {
numInterfaces = Parallel(&Module::getNumberofUDPInterfacesFromShm, {})
.squash(); // cannot pick up from zmq
}
@ -540,7 +535,7 @@ void DetectorImpl::readFrameFromReceiver() {
// shape
nPixelsX = zHeader.npixelsx;
nPixelsY = zHeader.npixelsy;
// detector shape
// module shape
nX = zHeader.ndetx;
nY = zHeader.ndety;
nY *= numInterfaces;
@ -603,7 +598,7 @@ void DetectorImpl::readFrameFromReceiver() {
uint32_t yoffset = coordY * nPixelsY;
uint32_t singledetrowoffset = nPixelsX * bytesPerPixel;
uint32_t rowoffset = nX * singledetrowoffset;
if (multi_shm()->multiDetectorType == CHIPTESTBOARD) {
if (shm()->detType == CHIPTESTBOARD) {
singledetrowoffset = size;
}
LOG(logDEBUG1)
@ -765,7 +760,7 @@ int DetectorImpl::InsertGapPixels(char *image, char *&gpImage, bool quadEnable,
// eiger requires inter chip gap pixels are halved
// jungfrau prefers same inter chip gap pixels as the boundary pixels
int divisionValue = 2;
slsDetectorDefs::detectorType detType = multi_shm()->multiDetectorType;
slsDetectorDefs::detectorType detType = shm()->detType;
if (detType == JUNGFRAU) {
divisionValue = 1;
}
@ -1001,7 +996,7 @@ void DetectorImpl::setDataStreamingToClient(bool enable) {
int DetectorImpl::getClientStreamingHwm() const {
// disabled
if (!client_downstream) {
return multi_shm()->zmqHwm;
return shm()->zmqHwm;
}
// enabled
sls::Result<int> result;
@ -1019,7 +1014,7 @@ void DetectorImpl::setClientStreamingHwm(const int limit) {
"Cannot set hwm to less than -1 (-1 is lib default).");
}
// update shm
multi_shm()->zmqHwm = limit;
shm()->zmqHwm = limit;
// streaming enabled
if (client_downstream) {
@ -1028,7 +1023,7 @@ void DetectorImpl::setClientStreamingHwm(const int limit) {
for (auto &it : zmqSocket) {
it->SetReceiveHighWaterMark(limit);
if (it->GetReceiveHighWaterMark() != limit) {
multi_shm()->zmqHwm = -1;
shm()->zmqHwm = -1;
throw sls::ZmqSocketError("Could not set zmq rcv hwm to " +
std::to_string(limit));
}
@ -1096,13 +1091,13 @@ int DetectorImpl::acquire() {
// start and read all
try {
if(detector_type == defs::MYTHEN3 && detectors.size() > 1){
if (detector_type == defs::MYTHEN3 && modules.size() > 1) {
//Multi module mythen
std::vector<int> master;
std::vector<int> slaves;
auto is_master = Parallel(&Module::isMaster, {});
slaves.reserve(detectors.size()-1); //check this one!!
for (size_t i = 0; i<detectors.size(); ++i){
slaves.reserve(modules.size() - 1); // check this one!!
for (size_t i = 0; i < modules.size(); ++i) {
if(is_master[i])
master.push_back(i);
else
@ -1110,11 +1105,11 @@ int DetectorImpl::acquire() {
}
Parallel(&Module::startAcquisition, slaves);
Parallel(&Module::startAndReadAll, master);
}else{
} else {
//Normal acquire
Parallel(&Module::startAndReadAll, {});
}
} catch (...) {
if (receiver)
Parallel(&Module::stopReceiver, {});
@ -1243,7 +1238,7 @@ int DetectorImpl::kbhit() {
std::vector<char> DetectorImpl::readProgrammingFile(const std::string &fname) {
// validate type of file
bool isPof = false;
switch (multi_shm()->multiDetectorType) {
switch (shm()->detType) {
case JUNGFRAU:
case CHIPTESTBOARD:
case MOENCH:

View File

@ -15,8 +15,8 @@ class detectorData;
#include <thread>
#include <vector>
#define MULTI_SHMAPIVERSION 0x190809
#define MULTI_SHMVERSION 0x201007
#define DETECTOR_SHMAPIVERSION 0x190809
#define DETECTOR_SHMVERSION 0x201007
#define SHORT_STRING_LENGTH 50
#include <future>
@ -30,7 +30,7 @@ class Module;
* @short structure allocated in shared memory to store detector settings
* for IPC and cache
*/
struct sharedMultiSlsDetector {
struct sharedDetector {
/* FIXED PATTERN FOR STATIC FUNCTIONS. DO NOT CHANGE, ONLY APPEND
* ------*/
@ -47,14 +47,14 @@ struct sharedMultiSlsDetector {
/** last time stamp when accessing the shared memory */
char lastDate[SHORT_STRING_LENGTH];
int numberOfDetectors;
slsDetectorDefs::detectorType multiDetectorType;
int numberOfModules;
slsDetectorDefs::detectorType detType;
/** END OF FIXED PATTERN
* -----------------------------------------------*/
/** Number of detectors operated at once */
slsDetectorDefs::xy numberOfDetector;
/** Number of modules operated at once */
slsDetectorDefs::xy numberOfModule;
/** max number of channels for complete detector*/
slsDetectorDefs::xy numberOfChannels;
@ -69,13 +69,11 @@ struct sharedMultiSlsDetector {
class DetectorImpl : public virtual slsDetectorDefs {
public:
/**
* Constructor
* @param multi_id multi detector id
* @param verify true to verify if shared memory version matches existing
* one
* @param update true to update last user pid, date etc
*/
explicit DetectorImpl(int multi_id = 0, bool verify = true,
explicit DetectorImpl(int detector_index = 0, bool verify = true,
bool update = true);
/**
@ -89,20 +87,20 @@ class DetectorImpl : public virtual slsDetectorDefs {
std::vector<int> positions,
typename NonDeduced<CT>::type... Args) {
if (detectors.empty())
throw sls::RuntimeError("No detectors added");
if (modules.empty())
throw sls::RuntimeError("No modules added");
if (positions.empty() ||
(positions.size() == 1 && positions[0] == -1)) {
positions.resize(detectors.size());
positions.resize(modules.size());
std::iota(begin(positions), end(positions), 0);
}
std::vector<std::future<RT>> futures;
futures.reserve(positions.size());
for (size_t i : positions) {
if (i >= detectors.size())
throw sls::RuntimeError("Detector out of range");
if (i >= modules.size())
throw sls::RuntimeError("Module out of range");
futures.push_back(std::async(std::launch::async, somefunc,
detectors[i].get(), Args...));
modules[i].get(), Args...));
}
sls::Result<RT> result;
result.reserve(positions.size());
@ -117,20 +115,20 @@ class DetectorImpl : public virtual slsDetectorDefs {
std::vector<int> positions,
typename NonDeduced<CT>::type... Args) const {
if (detectors.empty())
throw sls::RuntimeError("No detectors added");
if (modules.empty())
throw sls::RuntimeError("No modules added");
if (positions.empty() ||
(positions.size() == 1 && positions[0] == -1)) {
positions.resize(detectors.size());
positions.resize(modules.size());
std::iota(begin(positions), end(positions), 0);
}
std::vector<std::future<RT>> futures;
futures.reserve(positions.size());
for (size_t i : positions) {
if (i >= detectors.size())
throw sls::RuntimeError("Detector out of range");
if (i >= modules.size())
throw sls::RuntimeError("Module out of range");
futures.push_back(std::async(std::launch::async, somefunc,
detectors[i].get(), Args...));
modules[i].get(), Args...));
}
sls::Result<RT> result;
result.reserve(positions.size());
@ -145,20 +143,20 @@ class DetectorImpl : public virtual slsDetectorDefs {
std::vector<int> positions,
typename NonDeduced<CT>::type... Args) {
if (detectors.empty())
throw sls::RuntimeError("No detectors added");
if (modules.empty())
throw sls::RuntimeError("No modules added");
if (positions.empty() ||
(positions.size() == 1 && positions[0] == -1)) {
positions.resize(detectors.size());
positions.resize(modules.size());
std::iota(begin(positions), end(positions), 0);
}
std::vector<std::future<void>> futures;
futures.reserve(positions.size());
for (size_t i : positions) {
if (i >= detectors.size())
throw sls::RuntimeError("Detector out of range");
if (i >= modules.size())
throw sls::RuntimeError("Module out of range");
futures.push_back(std::async(std::launch::async, somefunc,
detectors[i].get(), Args...));
modules[i].get(), Args...));
}
for (auto &i : futures) {
i.get();
@ -170,20 +168,20 @@ class DetectorImpl : public virtual slsDetectorDefs {
std::vector<int> positions,
typename NonDeduced<CT>::type... Args) const {
if (detectors.empty())
throw sls::RuntimeError("No detectors added");
if (modules.empty())
throw sls::RuntimeError("No modules added");
if (positions.empty() ||
(positions.size() == 1 && positions[0] == -1)) {
positions.resize(detectors.size());
positions.resize(modules.size());
std::iota(begin(positions), end(positions), 0);
}
std::vector<std::future<void>> futures;
futures.reserve(positions.size());
for (size_t i : positions) {
if (i >= detectors.size())
throw sls::RuntimeError("Detector out of range");
if (i >= modules.size())
throw sls::RuntimeError("Module out of range");
futures.push_back(std::async(std::launch::async, somefunc,
detectors[i].get(), Args...));
modules[i].get(), Args...));
}
for (auto &i : futures) {
i.get();
@ -193,12 +191,12 @@ class DetectorImpl : public virtual slsDetectorDefs {
/** set acquiring flag in shared memory */
void setAcquiringFlag(bool flag);
/** return multi detector shared memory ID */
int getMultiId() const;
/** return detector index in shared memory */
int getDetectorIndex() const;
/** Free specific shared memory from the command line without creating
* object */
static void freeSharedMemory(int multiId, int detPos = -1);
static void freeSharedMemory(int detectorIndex, int detPos = -1);
/** Free all modules from current multi Id shared memory and delete members
*/
@ -215,24 +213,24 @@ class DetectorImpl : public virtual slsDetectorDefs {
/**
* Connect to Virtual Detector Servers at local host
* @param numdet number of detectors
* @param numdet number of modules
* @param port starting port number
*/
void setVirtualDetectorServers(const int numdet, const int port);
/** Sets the hostname of all sls detectors in shared memory and updates
/** Sets the hostname of all sls modules in shared memory and updates
* local cache */
void setHostname(const std::vector<std::string> &name);
/** Gets the total number of detectors */
/** Gets the total number of modules */
int size() const;
slsDetectorDefs::xy getNumberOfDetectors() const;
slsDetectorDefs::xy getNumberOfModules() const;
slsDetectorDefs::xy getNumberOfChannels() const;
/** Must be set before setting hostname
* Sets maximum number of channels of all sls detectors */
* Sets maximum number of channels of all sls modules */
void setNumberOfChannels(const slsDetectorDefs::xy c);
/** [Eiger][Jungfrau] */
@ -248,14 +246,14 @@ class DetectorImpl : public virtual slsDetectorDefs {
/**
* register callback for accessing acquisition final data
* @param func function to be called at the end of the acquisition.
* gets detector status and progress index as arguments
* gets module status and progress index as arguments
* @param pArg argument
*/
void registerAcquisitionFinishedCallback(void (*func)(double, int, void *),
void *pArg);
/**
* register calbback for accessing detector final data,
* register calbback for accessing module final data,
* also enables data streaming in client and receiver
* @param userCallback function for plotting/analyzing the data.
* Its arguments are
@ -307,7 +305,7 @@ class DetectorImpl : public virtual slsDetectorDefs {
* one
* @param update true to update last user pid, date etc
*/
void setupMultiDetector(bool verify = true, bool update = true);
void setupDetector(bool verify = true, bool update = true);
/**
* Creates shm and initializes shm structure OR
@ -319,7 +317,7 @@ class DetectorImpl : public virtual slsDetectorDefs {
/** Initialize detector structure for the shared memory just created */
void initializeDetectorStructure();
/** Initialize members (eg. slsDetectors from shm, zmqsockets)
/** Initialize members (eg. modules from shm, zmqsockets)
* @param verify true to verify if shm size matches existing one
*/
void initializeMembers(bool verify = true);
@ -332,7 +330,7 @@ class DetectorImpl : public virtual slsDetectorDefs {
/** Execute command in terminal and return result */
std::string exec(const char *cmd);
void addSlsDetector(const std::string &hostname);
void addModule(const std::string &hostname);
void updateDetectorSize();
@ -380,22 +378,13 @@ class DetectorImpl : public virtual slsDetectorDefs {
*/
int kbhit();
/** Multi detector Id */
const int multiId{0};
/** Shared Memory object */
sls::SharedMemory<sharedMultiSlsDetector> multi_shm{0, -1};
/** pointers to the Module structures */
std::vector<std::unique_ptr<sls::Module>> detectors;
const int detectorIndex{0};
sls::SharedMemory<sharedDetector> shm{0, -1};
std::vector<std::unique_ptr<sls::Module>> modules;
/** data streaming (down stream) enabled in client (zmq sckets created) */
bool client_downstream{false};
/** ZMQ Socket - Receiver to Client */
std::vector<std::unique_ptr<ZmqSocket>> zmqSocket;
/** number of zmq sockets running currently */
volatile int numZmqRunning{0};
/** mutex to synchronize main and data processing threads */

View File

@ -59,7 +59,7 @@ void Module::freeSharedMemory() {
}
bool Module::isFixedPatternSharedMemoryCompatible() const {
return (shm()->shmversion >= SLS_SHMAPIVERSION);
return (shm()->shmversion >= MODULE_SHMAPIVERSION);
}
std::string Module::getHostname() const { return shm()->hostname; }
@ -71,7 +71,7 @@ void Module::setHostname(const std::string &hostname,
client.close();
try {
checkDetectorVersionCompatibility();
LOG(logINFO) << "Detector Version Compatibility - Success";
LOG(logINFO) << "Module Version Compatibility - Success";
} catch (const DetectorError &e) {
if (!initialChecks) {
LOG(logWARNING) << "Bypassing Initial Checks at your own risk!";
@ -79,7 +79,7 @@ void Module::setHostname(const std::string &hostname,
throw;
}
}
if (shm()->myDetectorType == EIGER) {
if (shm()->detType == EIGER) {
setActivate(true);
}
}
@ -108,22 +108,21 @@ int64_t Module::getReceiverSoftwareVersion() const {
// static function
slsDetectorDefs::detectorType
Module::getTypeFromDetector(const std::string &hostname, int cport) {
LOG(logDEBUG1) << "Getting detector type ";
LOG(logDEBUG1) << "Getting Module type ";
sls::ClientSocket socket("Detector", hostname, cport);
socket.Send(F_GET_DETECTOR_TYPE);
socket.Receive<int>(); // TODO! Should we look at this OK/FAIL?
auto retval = socket.Receive<detectorType>();
LOG(logDEBUG1) << "Detector type is " << retval;
LOG(logDEBUG1) << "Module type is " << retval;
return retval;
}
slsDetectorDefs::detectorType Module::getDetectorType() const {
return shm()->myDetectorType;
return shm()->detType;
}
void Module::updateNumberOfChannels() {
if (shm()->myDetectorType == CHIPTESTBOARD ||
shm()->myDetectorType == MOENCH) {
if (shm()->detType == CHIPTESTBOARD || shm()->detType == MOENCH) {
std::array<int, 2> retvals{};
sendToDetector(F_GET_NUM_CHANNELS, nullptr, retvals);
shm()->nChan.x = retvals[0];
@ -138,9 +137,9 @@ slsDetectorDefs::xy Module::getNumberOfChannels() const {
return coord;
}
void Module::updateNumberOfDetector(slsDetectorDefs::xy det) {
shm()->numberOfDetector = det;
int args[2] = {shm()->numberOfDetector.y, moduleIndex};
void Module::updateNumberOfModule(slsDetectorDefs::xy det) {
shm()->numberOfModule = det;
int args[2] = {shm()->numberOfModule.y, moduleIndex};
sendToDetector(F_SET_POSITION, args, nullptr);
}
@ -149,7 +148,7 @@ slsDetectorDefs::detectorSettings Module::getSettings() const {
}
void Module::setSettings(detectorSettings isettings) {
if (shm()->myDetectorType == EIGER) {
if (shm()->detType == EIGER) {
throw RuntimeError(
"Cannot set settings for Eiger. Use threshold energy.");
}
@ -177,7 +176,7 @@ void Module::setThresholdEnergy(int e_eV, detectorSettings isettings,
std::all_of(shm()->trimEnergies.begin(), shm()->trimEnergies.end(),
[e_eV](const int &e) { return e != e_eV; });
sls_detector_module myMod{shm()->myDetectorType};
sls_detector_module myMod{shm()->detType};
if (!interpolate) {
std::string settingsfname = getTrimbitFilename(isettings, e_eV);
@ -214,7 +213,7 @@ void Module::setThresholdEnergy(int e_eV, detectorSettings isettings,
setModule(myMod, trimbits);
if (getSettings() != isettings) {
throw RuntimeError("setThresholdEnergyAndSettings: Could not set "
"settings in detector");
"settings in Module");
}
if (shm()->useReceiverFlag) {
@ -249,7 +248,7 @@ void Module::setAllThresholdEnergy(std::array<int, 3> e_eV,
M_VDCSH
};
std::vector<sls_detector_module> myMods{shm()->myDetectorType};
std::vector<sls_detector_module> myMods{shm()->detType};
std::vector<int> energy(e_eV.begin(), e_eV.end());
// if all energies are same
if (allEqualTo(energy, energy[0])) {
@ -307,7 +306,7 @@ void Module::setAllThresholdEnergy(std::array<int, 3> e_eV,
}
}
sls_detector_module myMod{shm()->myDetectorType};
sls_detector_module myMod{shm()->detType};
myMod = myMods[0];
// if multiple thresholds, combine
@ -392,7 +391,7 @@ void Module::setAllThresholdEnergy(std::array<int, 3> e_eV,
setModule(myMod, trimbits);
if (getSettings() != isettings) {
throw RuntimeError("setThresholdEnergyAndSettings: Could not set "
"settings in detector");
"settings in Module");
}
if (shm()->useReceiverFlag) {
@ -411,11 +410,11 @@ std::string Module::setSettingsDir(const std::string &dir) {
void Module::loadTrimbits(const std::string &fname) {
// find specific file if it has detid in file name (.snxxx)
if (shm()->myDetectorType == EIGER || shm()->myDetectorType == MYTHEN3) {
if (shm()->detType == EIGER || shm()->detType == MYTHEN3) {
std::ostringstream ostfn;
ostfn << fname;
int moduleIdWidth = 3;
if (shm()->myDetectorType == MYTHEN3) {
if (shm()->detType == MYTHEN3) {
moduleIdWidth = 4;
}
if ((fname.find(".sn") == std::string::npos) &&
@ -439,7 +438,7 @@ void Module::setAllTrimbits(int val) {
}
std::vector<int> Module::getTrimEn() const {
if (shm()->myDetectorType != EIGER && shm()->myDetectorType != MYTHEN3) {
if (shm()->detType != EIGER && shm()->detType != MYTHEN3) {
throw RuntimeError("getTrimEn not implemented for this detector.");
}
return std::vector<int>(shm()->trimEnergies.begin(),
@ -447,7 +446,7 @@ std::vector<int> Module::getTrimEn() const {
}
int Module::setTrimEn(const std::vector<int> &energies) {
if (shm()->myDetectorType != EIGER && shm()->myDetectorType != MYTHEN3) {
if (shm()->detType != EIGER && shm()->detType != MYTHEN3) {
throw RuntimeError("setTrimEn not implemented for this detector.");
}
if (energies.size() > MAX_TRIMEN) {
@ -463,14 +462,14 @@ int Module::setTrimEn(const std::vector<int> &energies) {
}
bool Module::getFlipRows() const {
if (shm()->myDetectorType == EIGER) {
if (shm()->detType == EIGER) {
return sendToReceiver<int>(F_GET_FLIP_ROWS_RECEIVER);
}
return sendToDetector<int>(F_GET_FLIP_ROWS);
}
void Module::setFlipRows(bool value) {
if (shm()->myDetectorType == EIGER) {
if (shm()->detType == EIGER) {
sendToReceiver<int>(F_SET_FLIP_ROWS_RECEIVER, static_cast<int>(value));
} else {
sendToDetector(F_SET_FLIP_ROWS, static_cast<int>(value), nullptr);
@ -509,7 +508,7 @@ int64_t Module::getExptime(int gateIndex) const {
void Module::setExptime(int gateIndex, int64_t value) {
int64_t prevVal = value;
if (shm()->myDetectorType == EIGER) {
if (shm()->detType == EIGER) {
prevVal = getExptime(-1);
}
int64_t args[]{static_cast<int64_t>(gateIndex), value};
@ -563,7 +562,7 @@ int Module::getDynamicRange() const {
void Module::setDynamicRange(int dr) {
int prev_val = dr;
if (shm()->myDetectorType == EIGER) {
if (shm()->detType == EIGER) {
prev_val = getDynamicRange();
}
@ -573,7 +572,7 @@ void Module::setDynamicRange(int dr) {
}
// update speed
if (shm()->myDetectorType == EIGER) {
if (shm()->detType == EIGER) {
if (dr == 32) {
LOG(logINFO) << "Setting Clock to Quarter Speed to cope with "
"Dynamic Range of 32";
@ -995,7 +994,7 @@ void Module::setDestinationUDPIP(const IpAddr ip) {
if (shm()->useReceiverFlag) {
sls::MacAddr retval(0LU);
sendToReceiver(F_SET_RECEIVER_UDP_IP, ip, retval);
LOG(logINFO) << "Setting destination udp mac of detector " << moduleIndex
LOG(logINFO) << "Setting destination udp mac of Module " << moduleIndex
<< " to " << retval;
sendToDetector(F_SET_DEST_UDP_MAC, retval, nullptr);
}
@ -1015,7 +1014,7 @@ void Module::setDestinationUDPIP2(const IpAddr ip) {
if (shm()->useReceiverFlag) {
sls::MacAddr retval(0LU);
sendToReceiver(F_SET_RECEIVER_UDP_IP2, ip, retval);
LOG(logINFO) << "Setting destination udp mac2 of detector " << moduleIndex
LOG(logINFO) << "Setting destination udp mac2 of Module " << moduleIndex
<< " to " << retval;
sendToDetector(F_SET_DEST_UDP_MAC2, retval, nullptr);
}
@ -1073,27 +1072,28 @@ void Module::validateUDPConfiguration() {
std::string Module::printReceiverConfiguration() {
std::ostringstream os;
os << "\n\nDetector " << moduleIndex << "\nReceiver Hostname:\t"
os << "\n\nModule " << moduleIndex << "\nReceiver Hostname:\t"
<< getReceiverHostname();
if (shm()->myDetectorType == JUNGFRAU) {
if (shm()->detType == JUNGFRAU) {
os << "\nNumber of Interfaces:\t" << getNumberofUDPInterfaces()
<< "\nSelected Interface:\t" << getSelectedUDPInterface();
}
os << "\nDetector UDP IP:\t" << getSourceUDPIP() << "\nDetector UDP MAC:\t"
<< getSourceUDPMAC() << "\nReceiver UDP IP:\t" << getDestinationUDPIP()
<< "\nReceiver UDP MAC:\t" << getDestinationUDPMAC();
os << "\nSource UDP IP:\t" << getSourceUDPIP() << "\nSource UDP MAC:\t"
<< getSourceUDPMAC() << "\nDestination UDP IP:\t"
<< getDestinationUDPIP() << "\nReceiver UDP MAC:\t"
<< getDestinationUDPMAC();
if (shm()->myDetectorType == JUNGFRAU) {
os << "\nDetector UDP IP2:\t" << getSourceUDPIP2()
<< "\nDetector UDP MAC2:\t" << getSourceUDPMAC2()
<< "\nReceiver UDP IP2:\t" << getDestinationUDPIP2()
<< "\nReceiver UDP MAC2:\t" << getDestinationUDPMAC2();
if (shm()->detType == JUNGFRAU) {
os << "\nSource UDP IP2:\t" << getSourceUDPIP2()
<< "\nSource UDP MAC2:\t" << getSourceUDPMAC2()
<< "\nDestination UDP IP2:\t" << getDestinationUDPIP2()
<< "\nDestination UDP MAC2:\t" << getDestinationUDPMAC2();
}
os << "\nReceiver UDP Port:\t" << getDestinationUDPPort();
if (shm()->myDetectorType == JUNGFRAU || shm()->myDetectorType == EIGER) {
os << "\nReceiver UDP Port2:\t" << getDestinationUDPPort2();
os << "\nDestination UDP Port:\t" << getDestinationUDPPort();
if (shm()->detType == JUNGFRAU || shm()->detType == EIGER) {
os << "\nDestination UDP Port2:\t" << getDestinationUDPPort2();
}
os << "\n";
return os.str();
@ -1184,25 +1184,25 @@ void Module::setReceiverHostname(const std::string &receiverIP) {
sendToDetector(F_GET_RECEIVER_PARAMETERS, nullptr, retval);
// populate from shared memory
retval.detType = shm()->myDetectorType;
retval.numberOfDetector.x = shm()->numberOfDetector.x;
retval.numberOfDetector.y = shm()->numberOfDetector.y;
retval.detType = shm()->detType;
retval.numberOfModule.x = shm()->numberOfModule.x;
retval.numberOfModule.y = shm()->numberOfModule.y;
retval.moduleIndex = moduleIndex;
memset(retval.hostname, 0, sizeof(retval.hostname));
strcpy_safe(retval.hostname, shm()->hostname);
sls::MacAddr retvals[2];
sendToReceiver(F_SETUP_RECEIVER, retval, retvals);
// update detectors with dest mac
// update Modules with dest mac
if (retval.udp_dstmac == 0 && retvals[0] != 0) {
LOG(logINFO) << "Setting destination udp mac of "
"detector "
"Module "
<< moduleIndex << " to " << retvals[0];
sendToDetector(F_SET_DEST_UDP_MAC, retvals[0], nullptr);
}
if (retval.udp_dstmac2 == 0 && retvals[1] != 0) {
LOG(logINFO) << "Setting destination udp mac2 of "
"detector "
"Module "
<< moduleIndex << " to " << retvals[1];
sendToDetector(F_SET_DEST_UDP_MAC2, retvals[1], nullptr);
}
@ -1467,7 +1467,7 @@ int64_t Module::getSubExptime() const {
void Module::setSubExptime(int64_t value) {
int64_t prevVal = value;
if (shm()->myDetectorType == EIGER) {
if (shm()->detType == EIGER) {
prevVal = getSubExptime();
}
sendToDetector(F_SET_SUB_EXPTIME, value, nullptr);
@ -1512,7 +1512,7 @@ void Module::setRateCorrection(int64_t t) {
}
void Module::sendReceiverRateCorrections(const std::vector<int64_t> &t) {
LOG(logDEBUG) << "Sending to detector [rate corrections: " << ToString(t)
LOG(logDEBUG) << "Sending to Module [rate corrections: " << ToString(t)
<< ']';
auto receiver = ReceiverSocket(shm()->rxHostname, shm()->rxTCPPort);
receiver.Send(F_SET_RECEIVER_RATE_CORRECT);
@ -1824,7 +1824,7 @@ void Module::getVetoPhoton(const int chipIndex,
void Module::setVetoPhoton(const int chipIndex, const int numPhotons,
const int energy, const std::string &fname) {
if (shm()->myDetectorType != GOTTHARD2) {
if (shm()->detType != GOTTHARD2) {
throw RuntimeError(
"Set Veto reference is not implemented for this detector");
}
@ -1905,7 +1905,7 @@ void Module::setVetoReference(const int gainIndex, const int value) {
}
void Module::setVetoFile(const int chipIndex, const std::string &fname) {
if (shm()->myDetectorType != GOTTHARD2) {
if (shm()->detType != GOTTHARD2) {
throw RuntimeError(
"Set Veto file is not implemented for this detector");
}
@ -2225,7 +2225,7 @@ void Module::setReadoutMode(const slsDetectorDefs::readoutMode mode) {
auto arg = static_cast<uint32_t>(mode); // TODO! unit?
sendToDetector(F_SET_READOUT_MODE, arg, nullptr);
// update #nchan, as it depends on #samples, adcmask,
if (shm()->myDetectorType == CHIPTESTBOARD) {
if (shm()->detType == CHIPTESTBOARD) {
updateNumberOfChannels();
}
if (shm()->useReceiverFlag) {
@ -2481,7 +2481,7 @@ void Module::setAdditionalJsonParameter(const std::string &key,
// Advanced
void Module::programFPGA(std::vector<char> buffer) {
switch (shm()->myDetectorType) {
switch (shm()->detType) {
case JUNGFRAU:
case CHIPTESTBOARD:
case MOENCH:
@ -3003,42 +3003,42 @@ slsDetectorDefs::detectorType Module::getDetectorTypeFromShm(int det_id,
}
shm.OpenSharedMemory();
if (verify && shm()->shmversion != SLS_SHMVERSION) {
if (verify && shm()->shmversion != MODULE_SHMVERSION) {
std::ostringstream ss;
ss << "Single shared memory (" << det_id << "-" << moduleIndex
<< ":)version mismatch (expected 0x" << std::hex << SLS_SHMVERSION
<< ":)version mismatch (expected 0x" << std::hex << MODULE_SHMVERSION
<< " but got 0x" << shm()->shmversion << ")" << std::dec
<< ". Clear Shared memory to continue.";
shm.UnmapSharedMemory();
throw SharedMemoryError(ss.str());
}
return shm()->myDetectorType;
return shm()->detType;
}
void Module::initSharedMemory(detectorType type, int det_id, bool verify) {
shm = SharedMemory<sharedSlsDetector>(det_id, moduleIndex);
shm = SharedMemory<sharedModule>(det_id, moduleIndex);
if (!shm.IsExisting()) {
shm.CreateSharedMemory();
initializeDetectorStructure(type);
initializeModuleStructure(type);
} else {
shm.OpenSharedMemory();
if (verify && shm()->shmversion != SLS_SHMVERSION) {
if (verify && shm()->shmversion != MODULE_SHMVERSION) {
std::ostringstream ss;
ss << "Single shared memory (" << det_id << "-" << moduleIndex
<< ":) version mismatch (expected 0x" << std::hex
<< SLS_SHMVERSION << " but got 0x" << shm()->shmversion << ")"
<< MODULE_SHMVERSION << " but got 0x" << shm()->shmversion << ")"
<< std::dec << ". Clear Shared memory to continue.";
throw SharedMemoryError(ss.str());
}
}
}
void Module::initializeDetectorStructure(detectorType type) {
shm()->shmversion = SLS_SHMVERSION;
void Module::initializeModuleStructure(detectorType type) {
shm()->shmversion = MODULE_SHMVERSION;
memset(shm()->hostname, 0, MAX_STR_LENGTH);
shm()->myDetectorType = type;
shm()->numberOfDetector.x = 0;
shm()->numberOfDetector.y = 0;
shm()->detType = type;
shm()->numberOfModule.x = 0;
shm()->numberOfModule.y = 0;
shm()->controlPort = DEFAULT_PORTNO;
shm()->stopPort = DEFAULT_PORTNO + 1;
sls::strcpy_safe(shm()->settingsDir, getenv("HOME"));
@ -3046,12 +3046,12 @@ void Module::initializeDetectorStructure(detectorType type) {
shm()->rxTCPPort = DEFAULT_PORTNO + 2;
shm()->useReceiverFlag = false;
shm()->zmqport = DEFAULT_ZMQ_CL_PORTNO +
(moduleIndex * ((shm()->myDetectorType == EIGER) ? 2 : 1));
(moduleIndex * ((shm()->detType == EIGER) ? 2 : 1));
shm()->zmqip = IpAddr{};
shm()->numUDPInterfaces = 1;
shm()->stoppedFlag = false;
// get the detector parameters based on type
// get the Module parameters based on type
detParameters parameters{type};
shm()->nChan.x = parameters.nChanX;
shm()->nChan.y = parameters.nChanY;
@ -3062,7 +3062,7 @@ void Module::initializeDetectorStructure(detectorType type) {
void Module::checkDetectorVersionCompatibility() {
int64_t arg = 0;
switch (shm()->myDetectorType) {
switch (shm()->detType) {
case EIGER:
arg = APIEIGER;
break;
@ -3140,7 +3140,7 @@ int Module::sendModule(sls_detector_module *myMod, sls::ClientSocket &client) {
ts += n;
LOG(level) << "dacs sent. " << n << " bytes";
if (shm()->myDetectorType == EIGER || shm()->myDetectorType == MYTHEN3) {
if (shm()->detType == EIGER || shm()->detType == MYTHEN3) {
n = client.Send(myMod->chanregs, sizeof(int) * (myMod->nchan));
ts += n;
LOG(level) << "channels sent. " << n << " bytes";
@ -3187,12 +3187,12 @@ sls_detector_module Module::interpolateTrim(sls_detector_module *a,
const int energy, const int e1,
const int e2, bool trimbits) {
// dacs specified only for eiger and mythen3
if (shm()->myDetectorType != EIGER && shm()->myDetectorType != MYTHEN3) {
if (shm()->detType != EIGER && shm()->detType != MYTHEN3) {
throw NotImplementedError(
"Interpolation of Trim values not implemented for this detector!");
}
sls_detector_module myMod{shm()->myDetectorType};
sls_detector_module myMod{shm()->detType};
enum eiger_DacIndex {
E_SVP,
E_VTR,
@ -3232,7 +3232,7 @@ sls_detector_module Module::interpolateTrim(sls_detector_module *a,
// create copy and interpolate dac lists
std::vector<int> dacs_to_copy, dacs_to_interpolate;
if (shm()->myDetectorType == EIGER) {
if (shm()->detType == EIGER) {
dacs_to_copy.insert(
dacs_to_copy.end(),
{E_SVP, E_VTR, E_SVN, E_VTGSTV, E_RXB_RB, E_RXB_LB, E_VCN, E_VIS});
@ -3267,7 +3267,7 @@ sls_detector_module Module::interpolateTrim(sls_detector_module *a,
}
// Copy irrelevant dacs (without failing)
if (shm()->myDetectorType == EIGER) {
if (shm()->detType == EIGER) {
// CAL
if (a->dacs[E_CAL] != b->dacs[E_CAL]) {
LOG(logWARNING)
@ -3315,16 +3315,16 @@ std::string Module::getTrimbitFilename(detectorSettings s, int e_eV) {
}
std::ostringstream ostfn;
ostfn << shm()->settingsDir << ssettings << "/" << e_eV << "eV";
if (shm()->myDetectorType == EIGER) {
if (shm()->detType == EIGER) {
ostfn << "/noise.sn";
} else if (shm()->myDetectorType == MYTHEN3) {
} else if (shm()->detType == MYTHEN3) {
ostfn << "/trim.sn";
} else {
throw RuntimeError(
"Settings or trimbit files not defined for this detector.");
}
int moduleIdWidth = 3;
if (shm()->myDetectorType == MYTHEN3) {
if (shm()->detType == MYTHEN3) {
moduleIdWidth = 4;
}
ostfn << std::setfill('0') << std::setw(moduleIdWidth) << std::dec
@ -3335,10 +3335,10 @@ std::string Module::getTrimbitFilename(detectorSettings s, int e_eV) {
sls_detector_module Module::readSettingsFile(const std::string &fname,
bool trimbits) {
LOG(logDEBUG1) << "Read settings file " << fname;
sls_detector_module myMod(shm()->myDetectorType);
sls_detector_module myMod(shm()->detType);
// open file
std::ifstream infile;
if (shm()->myDetectorType == EIGER || shm()->myDetectorType == MYTHEN3) {
if (shm()->detType == EIGER || shm()->detType == MYTHEN3) {
infile.open(fname.c_str(), std::ifstream::binary);
} else {
infile.open(fname.c_str(), std::ios_base::in);
@ -3350,7 +3350,7 @@ sls_detector_module Module::readSettingsFile(const std::string &fname,
auto file_size = getFileSize(infile);
// eiger
if (shm()->myDetectorType == EIGER) {
if (shm()->detType == EIGER) {
infile.read(reinterpret_cast<char *>(myMod.dacs),
sizeof(int) * (myMod.ndac));
infile.read(reinterpret_cast<char *>(&myMod.iodelay),
@ -3373,7 +3373,7 @@ sls_detector_module Module::readSettingsFile(const std::string &fname,
}
// mythen3 (dacs, trimbits)
else if (shm()->myDetectorType == MYTHEN3) {
else if (shm()->detType == MYTHEN3) {
int expected_size = sizeof(int) * myMod.ndac +
sizeof(int) * myMod.nchan + sizeof(myMod.reg);
if (file_size != expected_size) {
@ -3427,7 +3427,7 @@ void Module::programFPGAviaBlackfin(std::vector<char> buffer) {
if (client.Receive<int>() == FAIL) {
std::cout << '\n';
std::ostringstream os;
os << "Detector " << moduleIndex << " (" << shm()->hostname << ")"
os << "Module " << moduleIndex << " (" << shm()->hostname << ")"
<< " returned error: " << client.readErrorMessage();
throw RuntimeError(os.str());
}
@ -3447,7 +3447,7 @@ void Module::programFPGAviaBlackfin(std::vector<char> buffer) {
if (client.Receive<int>() == FAIL) {
std::cout << '\n';
std::ostringstream os;
os << "Detector " << moduleIndex << " (" << shm()->hostname << ")"
os << "Module " << moduleIndex << " (" << shm()->hostname << ")"
<< " returned error: " << client.readErrorMessage();
throw RuntimeError(os.str());
}
@ -3458,7 +3458,7 @@ void Module::programFPGAviaBlackfin(std::vector<char> buffer) {
// checksum
if (client.Receive<int>() == FAIL) {
std::ostringstream os;
os << "Detector " << moduleIndex << " (" << shm()->hostname << ")"
os << "Module " << moduleIndex << " (" << shm()->hostname << ")"
<< " returned error: " << client.readErrorMessage();
throw RuntimeError(os.str());
}
@ -3510,7 +3510,7 @@ void Module::programFPGAviaBlackfin(std::vector<char> buffer) {
if (client.Receive<int>() == FAIL) {
std::ostringstream os;
os << "Detector " << moduleIndex << " (" << shm()->hostname << ")"
os << "Module " << moduleIndex << " (" << shm()->hostname << ")"
<< " returned error: " << client.readErrorMessage();
throw RuntimeError(os.str());
}
@ -3523,7 +3523,7 @@ void Module::programFPGAviaBlackfin(std::vector<char> buffer) {
}
void Module::programFPGAviaNios(std::vector<char> buffer) {
LOG(logINFO) << "Sending programming binary (from rbf) to detector "
LOG(logINFO) << "Sending programming binary (from rbf) to Module "
<< moduleIndex << " (" << shm()->hostname << ")";
auto client = DetectorSocket(shm()->hostname, shm()->controlPort);
@ -3542,7 +3542,7 @@ void Module::programFPGAviaNios(std::vector<char> buffer) {
// validate file size before sending program
if (client.Receive<int>() == FAIL) {
std::ostringstream os;
os << "Detector " << moduleIndex << " (" << shm()->hostname << ")"
os << "Module " << moduleIndex << " (" << shm()->hostname << ")"
<< " returned error: " << client.readErrorMessage();
throw RuntimeError(os.str());
}
@ -3592,7 +3592,7 @@ void Module::programFPGAviaNios(std::vector<char> buffer) {
}
if (client.Receive<int>() == FAIL) {
std::ostringstream os;
os << "Detector " << moduleIndex << " (" << shm()->hostname << ")"
os << "Module " << moduleIndex << " (" << shm()->hostname << ")"
<< " returned error: " << client.readErrorMessage();
throw RuntimeError(os.str());
}

View File

@ -14,30 +14,30 @@
class ServerInterface;
#define SLS_SHMAPIVERSION 0x190726
#define SLS_SHMVERSION 0x200402
#define MODULE_SHMAPIVERSION 0x190726
#define MODULE_SHMVERSION 0x200402
namespace sls {
/**
* @short structure allocated in shared memory to store detector settings for
* @short structure allocated in shared memory to store Module settings for
* IPC and cache
*/
struct sharedSlsDetector {
struct sharedModule {
/* FIXED PATTERN FOR STATIC FUNCTIONS. DO NOT CHANGE, ONLY APPEND ------*/
int shmversion;
char hostname[MAX_STR_LENGTH];
slsDetectorDefs::detectorType myDetectorType;
slsDetectorDefs::detectorType detType;
/** END OF FIXED PATTERN -----------------------------------------------*/
slsDetectorDefs::xy numberOfDetector;
slsDetectorDefs::xy numberOfModule;
int controlPort;
int stopPort;
char settingsDir[MAX_STR_LENGTH];
/** list of the energies at which the detector has been trimmed */
/** list of the energies at which the Module has been trimmed */
sls::StaticVector<int, MAX_TRIMEN> trimEnergies;
/** number of channels per chip */
slsDetectorDefs::xy nChan;
@ -76,7 +76,7 @@ class Module : public virtual slsDetectorDefs {
virtual ~Module();
/** Frees shared memory and deletes shared memory structure
Safe to call only if detector shm also deleted or its numberOfDetectors is
Safe to call only if detector shm also deleted or its numberOfModules is
updated */
void freeSharedMemory();
bool isFixedPatternSharedMemoryCompatible() const;
@ -99,7 +99,7 @@ class Module : public virtual slsDetectorDefs {
detectorType getDetectorType() const;
void updateNumberOfChannels();
slsDetectorDefs::xy getNumberOfChannels() const;
void updateNumberOfDetector(slsDetectorDefs::xy det);
void updateNumberOfModule(slsDetectorDefs::xy det);
detectorSettings getSettings() const;
void setSettings(detectorSettings isettings);
int getThresholdEnergy() const;
@ -702,9 +702,9 @@ class Module : public virtual slsDetectorDefs {
verify is if shm size matches existing one */
void initSharedMemory(detectorType type, int det_id, bool verify = true);
/** Initialize detector structure to defaults,
/** Initialize module structure to defaults,
Called when new shared memory is created */
void initializeDetectorStructure(detectorType type);
void initializeModuleStructure(detectorType type);
void checkDetectorVersionCompatibility();
void checkReceiverVersionCompatibility();
@ -747,7 +747,7 @@ class Module : public virtual slsDetectorDefs {
void programFPGAviaNios(std::vector<char> buffer);
const int moduleIndex;
mutable sls::SharedMemory<sharedSlsDetector> shm{0, 0};
mutable sls::SharedMemory<sharedModule> shm{0, 0};
};
} // namespace sls

View File

@ -22,8 +22,8 @@
#include <sys/stat.h> // fstat
#include <unistd.h>
#define SHM_MULTI_PREFIX "/slsDetectorPackage_multi_"
#define SHM_SLS_PREFIX "_sls_"
#define SHM_DETECTOR_PREFIX "/slsDetectorPackage_detector_"
#define SHM_MODULE_PREFIX "_module_"
#define SHM_ENV_NAME "SLSDETNAME"
#include <iostream>
@ -35,13 +35,10 @@ template <typename T> class SharedMemory {
public:
/**
* 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
* moduleid of -1 creates a detector only shared memory
*/
SharedMemory(int multiId, int slsId) {
name = ConstructSharedMemoryName(multiId, slsId);
SharedMemory(int detectorId, int moduleIndex) {
name = ConstructSharedMemoryName(detectorId, moduleIndex);
}
/**
@ -208,11 +205,11 @@ template <typename T> class SharedMemory {
/**
* Create Shared memory name
* throws exception if name created is longer than required 255(manpages)
* @param multiId multi detector id
* @param slsId sls detector id, -1 if a multi detector shared memory
* @param detectorId detector id
* @param moduleIndex module id, -1 if a detector shared memory
* @returns shared memory name
*/
std::string ConstructSharedMemoryName(int multiId, int slsId) {
std::string ConstructSharedMemoryName(int detectorId, int moduleIndex) {
// using environment path
std::string sEnvPath;
@ -223,11 +220,11 @@ template <typename T> class SharedMemory {
}
std::stringstream ss;
if (slsId < 0)
ss << SHM_MULTI_PREFIX << multiId << sEnvPath;
if (moduleIndex < 0)
ss << SHM_DETECTOR_PREFIX << detectorId << sEnvPath;
else
ss << SHM_MULTI_PREFIX << multiId << SHM_SLS_PREFIX << slsId
<< sEnvPath;
ss << SHM_DETECTOR_PREFIX << detectorId << SHM_MODULE_PREFIX
<< moduleIndex << sEnvPath;
std::string temp = ss.str();
if (temp.length() > NAME_MAX_LENGTH) {

View File

@ -29,7 +29,7 @@ TEST_CASE("Is shm fixed pattern shm compatible") {
REQUIRE(m.isFixedPatternSharedMemoryCompatible() == true);
// Set shm version to 0
sls::SharedMemory<sls::sharedSlsDetector> shm(0, 0);
sls::SharedMemory<sls::sharedModule> shm(0, 0);
REQUIRE(shm.IsExisting() == true);
shm.OpenSharedMemory();
shm()->shmversion = 0;

View File

@ -35,7 +35,7 @@ ClientInterface::~ClientInterface() {
}
ClientInterface::ClientInterface(int portNumber)
: myDetectorType(GOTTHARD),
: detType(GOTTHARD),
portNumber(portNumber > 0 ? portNumber : DEFAULT_PORTNO + 2),
server(portNumber) {
functionTable();
@ -334,7 +334,7 @@ int ClientInterface::setup_receiver(Interface &socket) {
// basic setup
setDetectorType(arg.detType);
{
int msize[2] = {arg.numberOfDetector.x, arg.numberOfDetector.y};
int msize[2] = {arg.numberOfModule.x, arg.numberOfModule.y};
impl()->setDetectorSize(msize);
}
impl()->setModulePositionId(arg.moduleIndex);
@ -359,7 +359,7 @@ int ClientInterface::setup_receiver(Interface &socket) {
}
impl()->setUDPPortNumber(arg.udp_dstport);
impl()->setUDPPortNumber2(arg.udp_dstport2);
if (myDetectorType == JUNGFRAU || myDetectorType == GOTTHARD2) {
if (detType == JUNGFRAU || detType == GOTTHARD2) {
try {
impl()->setNumberofUDPInterfaces(arg.udpInterfaces);
} catch (const RuntimeError &e) {
@ -372,13 +372,13 @@ int ClientInterface::setup_receiver(Interface &socket) {
// acquisition parameters
impl()->setNumberOfFrames(arg.frames);
impl()->setNumberOfTriggers(arg.triggers);
if (myDetectorType == GOTTHARD2) {
if (detType == GOTTHARD2) {
impl()->setNumberOfBursts(arg.bursts);
}
if (myDetectorType == JUNGFRAU) {
if (detType == JUNGFRAU) {
impl()->setNumberOfAdditionalStorageCells(arg.additionalStorageCells);
}
if (myDetectorType == MOENCH || myDetectorType == CHIPTESTBOARD) {
if (detType == MOENCH || detType == CHIPTESTBOARD) {
try {
impl()->setNumberofAnalogSamples(arg.analogSamples);
} catch (const RuntimeError &e) {
@ -387,7 +387,7 @@ int ClientInterface::setup_receiver(Interface &socket) {
" due to fifo structure memory allocation.");
}
}
if (myDetectorType == CHIPTESTBOARD) {
if (detType == CHIPTESTBOARD) {
try {
impl()->setNumberofDigitalSamples(arg.digitalSamples);
} catch (const RuntimeError &e) {
@ -396,11 +396,11 @@ int ClientInterface::setup_receiver(Interface &socket) {
" due to fifo structure memory allocation.");
}
}
if (myDetectorType != MYTHEN3) {
if (detType != MYTHEN3) {
impl()->setAcquisitionTime(std::chrono::nanoseconds(arg.expTimeNs));
}
impl()->setAcquisitionPeriod(std::chrono::nanoseconds(arg.periodNs));
if (myDetectorType == EIGER) {
if (detType == EIGER) {
impl()->setSubExpTime(std::chrono::nanoseconds(arg.subExpTimeNs));
impl()->setSubPeriod(std::chrono::nanoseconds(arg.subExpTimeNs) +
std::chrono::nanoseconds(arg.subDeadTimeNs));
@ -416,17 +416,17 @@ int ClientInterface::setup_receiver(Interface &socket) {
}
impl()->setThresholdEnergy(arg.thresholdEnergyeV[0]);
}
if (myDetectorType == EIGER || myDetectorType == JUNGFRAU) {
if (detType == EIGER || detType == JUNGFRAU) {
impl()->setReadNRows(arg.readNRows);
}
if (myDetectorType == MYTHEN3) {
if (detType == MYTHEN3) {
std::array<int, 3> val;
for (int i = 0; i < 3; ++i) {
val[i] = arg.thresholdEnergyeV[i];
}
impl()->setThresholdEnergy(val);
}
if (myDetectorType == EIGER || myDetectorType == MYTHEN3) {
if (detType == EIGER || detType == MYTHEN3) {
try {
impl()->setDynamicRange(arg.dynamicRange);
} catch (const RuntimeError &e) {
@ -436,15 +436,15 @@ int ClientInterface::setup_receiver(Interface &socket) {
}
}
impl()->setTimingMode(arg.timMode);
if (myDetectorType == EIGER || myDetectorType == MOENCH ||
myDetectorType == CHIPTESTBOARD || myDetectorType == MYTHEN3) {
if (detType == EIGER || detType == MOENCH || detType == CHIPTESTBOARD ||
detType == MYTHEN3) {
try {
impl()->setTenGigaEnable(arg.tenGiga);
} catch (const RuntimeError &e) {
throw RuntimeError("Could not set 10GbE.");
}
}
if (myDetectorType == CHIPTESTBOARD) {
if (detType == CHIPTESTBOARD) {
try {
impl()->setReadoutMode(arg.roMode);
} catch (const RuntimeError &e) {
@ -452,7 +452,7 @@ int ClientInterface::setup_receiver(Interface &socket) {
"due to fifo memory allocation.");
}
}
if (myDetectorType == CHIPTESTBOARD || myDetectorType == MOENCH) {
if (detType == CHIPTESTBOARD || detType == MOENCH) {
try {
impl()->setADCEnableMask(arg.adcMask);
} catch (const RuntimeError &e) {
@ -466,14 +466,14 @@ int ClientInterface::setup_receiver(Interface &socket) {
"due to fifo memory allcoation");
}
}
if (myDetectorType == GOTTHARD) {
if (detType == GOTTHARD) {
try {
impl()->setROI(arg.roi);
} catch (const RuntimeError &e) {
throw RuntimeError("Could not set ROI");
}
}
if (myDetectorType == MYTHEN3) {
if (detType == MYTHEN3) {
impl()->setCounterMask(arg.countermask);
impl()->setAcquisitionTime1(std::chrono::nanoseconds(arg.expTime1Ns));
impl()->setAcquisitionTime2(std::chrono::nanoseconds(arg.expTime2Ns));
@ -483,7 +483,7 @@ int ClientInterface::setup_receiver(Interface &socket) {
impl()->setGateDelay3(std::chrono::nanoseconds(arg.gateDelay3Ns));
impl()->setNumberOfGates(arg.gates);
}
if (myDetectorType == GOTTHARD2) {
if (detType == GOTTHARD2) {
impl()->setBurstMode(arg.burstType);
}
impl()->setScan(arg.scanParams);
@ -507,9 +507,9 @@ void ClientInterface::setDetectorType(detectorType arg) {
}
try {
myDetectorType = GENERIC;
detType = GENERIC;
receiver = sls::make_unique<Implementation>(arg);
myDetectorType = arg;
detType = arg;
} catch (...) {
throw RuntimeError("Could not set detector type");
}
@ -535,7 +535,7 @@ int ClientInterface::set_roi(Interface &socket) {
auto arg = socket.Receive<ROI>();
LOG(logDEBUG1) << "Set ROI: [" << arg.xmin << ", " << arg.xmax << "]";
if (myDetectorType != GOTTHARD)
if (detType != GOTTHARD)
functionNotImplemented();
verifyIdle(socket);
@ -616,7 +616,7 @@ int ClientInterface::set_burst_mode(Interface &socket) {
int ClientInterface::set_num_analog_samples(Interface &socket) {
auto value = socket.Receive<int>();
LOG(logDEBUG1) << "Setting num analog samples to " << value;
if (myDetectorType != CHIPTESTBOARD && myDetectorType != MOENCH) {
if (detType != CHIPTESTBOARD && detType != MOENCH) {
functionNotImplemented();
}
try {
@ -632,7 +632,7 @@ int ClientInterface::set_num_analog_samples(Interface &socket) {
int ClientInterface::set_num_digital_samples(Interface &socket) {
auto value = socket.Receive<int>();
LOG(logDEBUG1) << "Setting num digital samples to " << value;
if (myDetectorType != CHIPTESTBOARD) {
if (detType != CHIPTESTBOARD) {
functionNotImplemented();
}
try {
@ -654,7 +654,7 @@ int ClientInterface::set_exptime(Interface &socket) {
<< " (gateIndex: " << gateIndex << ")";
switch (gateIndex) {
case -1:
if (myDetectorType == MYTHEN3) {
if (detType == MYTHEN3) {
impl()->setAcquisitionTime1(value);
impl()->setAcquisitionTime2(value);
impl()->setAcquisitionTime3(value);
@ -663,19 +663,19 @@ int ClientInterface::set_exptime(Interface &socket) {
}
break;
case 0:
if (myDetectorType != MYTHEN3) {
if (detType != MYTHEN3) {
functionNotImplemented();
}
impl()->setAcquisitionTime1(value);
break;
case 1:
if (myDetectorType != MYTHEN3) {
if (detType != MYTHEN3) {
functionNotImplemented();
}
impl()->setAcquisitionTime2(value);
break;
case 2:
if (myDetectorType != MYTHEN3) {
if (detType != MYTHEN3) {
functionNotImplemented();
}
impl()->setAcquisitionTime3(value);
@ -723,19 +723,19 @@ int ClientInterface::set_dynamic_range(Interface &socket) {
exists = true;
break;
/*case 1: //TODO: Not yet implemented in firmware
if (myDetectorType == MYTHEN3) {
if (detType == MYTHEN3) {
exists = true;
}
break;
*/
case 4:
if (myDetectorType == EIGER) {
if (detType == EIGER) {
exists = true;
}
break;
case 8:
case 32:
if (myDetectorType == EIGER || myDetectorType == MYTHEN3) {
if (detType == EIGER || detType == MYTHEN3) {
exists = true;
}
break;
@ -935,8 +935,8 @@ int ClientInterface::get_overwrite(Interface &socket) {
int ClientInterface::enable_tengiga(Interface &socket) {
auto val = socket.Receive<int>();
if (myDetectorType != EIGER && myDetectorType != CHIPTESTBOARD &&
myDetectorType != MOENCH && myDetectorType != MYTHEN3)
if (detType != EIGER && detType != CHIPTESTBOARD && detType != MOENCH &&
detType != MYTHEN3)
functionNotImplemented();
if (val >= 0) {
@ -974,7 +974,7 @@ int ClientInterface::set_fifo_depth(Interface &socket) {
int ClientInterface::set_activate(Interface &socket) {
auto enable = socket.Receive<int>();
if (myDetectorType != EIGER)
if (detType != EIGER)
functionNotImplemented();
if (enable >= 0) {
@ -1025,7 +1025,7 @@ int ClientInterface::set_streaming_timer(Interface &socket) {
}
int ClientInterface::get_flip_rows(Interface &socket) {
if (myDetectorType != EIGER)
if (detType != EIGER)
functionNotImplemented();
int retval = impl()->getFlipRows();
@ -1036,7 +1036,7 @@ int ClientInterface::get_flip_rows(Interface &socket) {
int ClientInterface::set_flip_rows(Interface &socket) {
auto arg = socket.Receive<int>();
if (myDetectorType != EIGER)
if (detType != EIGER)
functionNotImplemented();
if (arg != 0 && arg != 1) {
@ -1277,7 +1277,7 @@ int ClientInterface::get_padding_enable(Interface &socket) {
int ClientInterface::set_deactivated_padding_enable(Interface &socket) {
auto enable = socket.Receive<int>();
if (myDetectorType != EIGER) {
if (detType != EIGER) {
functionNotImplemented();
}
if (enable < 0) {
@ -1291,7 +1291,7 @@ int ClientInterface::set_deactivated_padding_enable(Interface &socket) {
}
int ClientInterface::get_deactivated_padding_enable(Interface &socket) {
if (myDetectorType != EIGER)
if (detType != EIGER)
functionNotImplemented();
auto retval = static_cast<int>(impl()->getDeactivatedPadding());
LOG(logDEBUG1) << "Deactivated Padding Enable: " << retval;
@ -1301,7 +1301,7 @@ int ClientInterface::get_deactivated_padding_enable(Interface &socket) {
int ClientInterface::set_readout_mode(Interface &socket) {
auto arg = socket.Receive<readoutMode>();
if (myDetectorType != CHIPTESTBOARD)
if (detType != CHIPTESTBOARD)
functionNotImplemented();
if (arg >= 0) {
@ -1345,7 +1345,7 @@ int ClientInterface::set_adc_mask(Interface &socket) {
int ClientInterface::set_dbit_list(Interface &socket) {
sls::StaticVector<int, MAX_RX_DBIT> args;
socket.Receive(args);
if (myDetectorType != CHIPTESTBOARD)
if (detType != CHIPTESTBOARD)
functionNotImplemented();
LOG(logDEBUG1) << "Setting DBIT list";
for (auto &it : args) {
@ -1358,7 +1358,7 @@ int ClientInterface::set_dbit_list(Interface &socket) {
}
int ClientInterface::get_dbit_list(Interface &socket) {
if (myDetectorType != CHIPTESTBOARD)
if (detType != CHIPTESTBOARD)
functionNotImplemented();
sls::StaticVector<int, MAX_RX_DBIT> retval;
retval = impl()->getDbitList();
@ -1368,7 +1368,7 @@ int ClientInterface::get_dbit_list(Interface &socket) {
int ClientInterface::set_dbit_offset(Interface &socket) {
auto arg = socket.Receive<int>();
if (myDetectorType != CHIPTESTBOARD)
if (detType != CHIPTESTBOARD)
functionNotImplemented();
if (arg < 0) {
throw RuntimeError("Invalid dbit offset: " + std::to_string(arg));
@ -1380,7 +1380,7 @@ int ClientInterface::set_dbit_offset(Interface &socket) {
}
int ClientInterface::get_dbit_offset(Interface &socket) {
if (myDetectorType != CHIPTESTBOARD)
if (detType != CHIPTESTBOARD)
functionNotImplemented();
int retval = impl()->getDbitOffset();
LOG(logDEBUG1) << "Dbit offset retval: " << retval;
@ -1410,7 +1410,7 @@ int ClientInterface::set_read_n_rows(Interface &socket) {
auto arg = socket.Receive<int>();
if (arg >= 0) {
verifyIdle(socket);
if (myDetectorType != EIGER && myDetectorType != JUNGFRAU) {
if (detType != EIGER && detType != JUNGFRAU) {
throw RuntimeError("Could not set number of rows. Not implemented for this detector");
}
LOG(logDEBUG1) << "Setting number of rows:" << arg;
@ -1436,7 +1436,7 @@ sls::MacAddr ClientInterface::setUdpIp(sls::IpAddr arg) {
<< ". Got " << eth;
}
impl()->setEthernetInterface(eth);
if (myDetectorType == EIGER) {
if (detType == EIGER) {
impl()->setEthernetInterface2(eth);
}
// get mac address
@ -1485,7 +1485,7 @@ sls::MacAddr ClientInterface::setUdpIp2(sls::IpAddr arg) {
int ClientInterface::set_udp_ip2(Interface &socket) {
auto arg = socket.Receive<sls::IpAddr>();
verifyIdle(socket);
if (myDetectorType != JUNGFRAU && myDetectorType != GOTTHARD2) {
if (detType != JUNGFRAU && detType != GOTTHARD2) {
throw RuntimeError(
"UDP Destination IP2 not implemented for this detector");
}
@ -1504,8 +1504,7 @@ int ClientInterface::set_udp_port(Interface &socket) {
int ClientInterface::set_udp_port2(Interface &socket) {
auto arg = socket.Receive<int>();
verifyIdle(socket);
if (myDetectorType != JUNGFRAU && myDetectorType != EIGER &&
myDetectorType != GOTTHARD2) {
if (detType != JUNGFRAU && detType != EIGER && detType != GOTTHARD2) {
throw RuntimeError(
"UDP Destination Port2 not implemented for this detector");
}
@ -1518,7 +1517,7 @@ int ClientInterface::set_num_interfaces(Interface &socket) {
auto arg = socket.Receive<int>();
arg = (arg > 1 ? 2 : 1);
verifyIdle(socket);
if (myDetectorType != JUNGFRAU && myDetectorType != GOTTHARD2) {
if (detType != JUNGFRAU && detType != GOTTHARD2) {
throw RuntimeError(
"Number of interfaces not implemented for this detector");
}
@ -1596,7 +1595,7 @@ int ClientInterface::get_progress(Interface &socket) {
int ClientInterface::set_num_gates(Interface &socket) {
auto value = socket.Receive<int>();
LOG(logDEBUG1) << "Setting num gates to " << value;
if (myDetectorType != MYTHEN3) {
if (detType != MYTHEN3) {
functionNotImplemented();
}
impl()->setNumberOfGates(value);
@ -1610,7 +1609,7 @@ int ClientInterface::set_gate_delay(Interface &socket) {
auto value = std::chrono::nanoseconds(args[1]);
LOG(logDEBUG1) << "Setting gate delay to " << sls::ToString(value)
<< " (gateIndex: " << gateIndex << ")";
if (myDetectorType != MYTHEN3) {
if (detType != MYTHEN3) {
functionNotImplemented();
}
switch (gateIndex) {
@ -1685,7 +1684,7 @@ int ClientInterface::set_scan(Interface &socket) {
int ClientInterface::set_threshold(Interface &socket) {
auto arg = socket.Receive<int>();
LOG(logDEBUG) << "Threshold: " << arg << " eV";
if (myDetectorType != EIGER)
if (detType != EIGER)
functionNotImplemented();
verifyIdle(socket);
impl()->setThresholdEnergy(arg);
@ -1712,7 +1711,7 @@ int ClientInterface::set_streaming_hwm(Interface &socket) {
int ClientInterface::set_all_threshold(Interface &socket) {
auto eVs = socket.Receive<std::array<int, 3>>();
LOG(logDEBUG) << "Threshold:" << sls::ToString(eVs);
if (myDetectorType != MYTHEN3)
if (detType != MYTHEN3)
functionNotImplemented();
verifyIdle(socket);
impl()->setThresholdEnergy(eVs);
@ -1733,7 +1732,7 @@ int ClientInterface::set_detector_datastream(Interface &socket) {
bool enable = static_cast<int>(args[1]);
LOG(logDEBUG1) << "Setting datastream (" << sls::ToString(port) << ") to "
<< sls::ToString(enable);
if (myDetectorType != EIGER)
if (detType != EIGER)
functionNotImplemented();
verifyIdle(socket);
impl()->setDetectorDataStream(port, enable);

View File

@ -11,7 +11,7 @@ class ServerInterface;
class ClientInterface : private virtual slsDetectorDefs {
enum numberMode { DEC, HEX };
detectorType myDetectorType;
detectorType detType;
int portNumber{0};
sls::ServerSocket server;
std::unique_ptr<Implementation> receiver;

View File

@ -500,7 +500,7 @@ typedef struct {
*/
struct rxParameters {
detectorType detType{GENERIC};
xy numberOfDetector;
xy numberOfModule;
int moduleIndex{0};
char hostname[MAX_STR_LENGTH];
int udpInterfaces{1};

View File

@ -26,8 +26,8 @@ std::ostream &operator<<(std::ostream &os, const slsDetectorDefs::ROI &roi) {
std::string ToString(const slsDetectorDefs::rxParameters &r) {
std::ostringstream oss;
oss << '[' << "detType:" << r.detType << std::endl
<< "numberOfDetector.x:" << r.numberOfDetector.x << std::endl
<< "numberOfDetector.y:" << r.numberOfDetector.y << std::endl
<< "numberOfModule.x:" << r.numberOfModule.x << std::endl
<< "numberOfModule.y:" << r.numberOfModule.y << std::endl
<< "moduleIndex:" << r.moduleIndex << std::endl
<< "hostname:" << r.hostname << std::endl
<< "udpInterfaces:" << r.udpInterfaces << std::endl