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 // Free function to avoid dependence on class
// and avoid the option to free another objects // and avoid the option to free another objects
// shm by mistake // shm by mistake
void freeSharedMemory(int multiId, int detPos = -1); void freeSharedMemory(int detectorIndex, int moduleIndex = -1);
/** /**
* \class Detector * \class Detector

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -500,7 +500,7 @@ typedef struct {
*/ */
struct rxParameters { struct rxParameters {
detectorType detType{GENERIC}; detectorType detType{GENERIC};
xy numberOfDetector; xy numberOfModule;
int moduleIndex{0}; int moduleIndex{0};
char hostname[MAX_STR_LENGTH]; char hostname[MAX_STR_LENGTH];
int udpInterfaces{1}; 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::string ToString(const slsDetectorDefs::rxParameters &r) {
std::ostringstream oss; std::ostringstream oss;
oss << '[' << "detType:" << r.detType << std::endl oss << '[' << "detType:" << r.detType << std::endl
<< "numberOfDetector.x:" << r.numberOfDetector.x << std::endl << "numberOfModule.x:" << r.numberOfModule.x << std::endl
<< "numberOfDetector.y:" << r.numberOfDetector.y << std::endl << "numberOfModule.y:" << r.numberOfModule.y << std::endl
<< "moduleIndex:" << r.moduleIndex << std::endl << "moduleIndex:" << r.moduleIndex << std::endl
<< "hostname:" << r.hostname << std::endl << "hostname:" << r.hostname << std::endl
<< "udpInterfaces:" << r.udpInterfaces << std::endl << "udpInterfaces:" << r.udpInterfaces << std::endl