mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-17 15:27:13 +02:00
Removeshm (#90)
* eiger: moved rate correction outside, fixed threshold energy bug in client (binaries not updated yet) * removed dr and deadtiem from shm * help for rx_status and status to point them to rx_Start, rx_stop, start and stop * moved progress to receiver * removed currentsettings from eiger shm * updated server binaries, and client api * moench and ctb virtual servers compile fix * gui: moved acquire to a concurrent qt thread so it doesnt block updateplot
This commit is contained in:
@ -785,6 +785,47 @@ std::vector<std::string> CmdProxy::DacCommands() {
|
||||
}
|
||||
|
||||
/* acquisition */
|
||||
|
||||
std::string CmdProxy::ReceiverStatus(int action) {
|
||||
std::ostringstream os;
|
||||
os << cmd << ' ';
|
||||
if (action == defs::HELP_ACTION) {
|
||||
os << "running, idle]\n\tReceiver listener status."
|
||||
<< '\n';
|
||||
} else if (action == defs::GET_ACTION) {
|
||||
if (args.size() != 0) {
|
||||
WrongNumberOfParameters(0);
|
||||
}
|
||||
auto t = det->getReceiverStatus({det_id});
|
||||
os << OutString(t) << '\n';
|
||||
} else if (action == defs::PUT_ACTION) {
|
||||
throw sls::RuntimeError("Cannot put. Did you mean to use command 'rx_start' or 'rx_stop'?");
|
||||
} else {
|
||||
throw sls::RuntimeError("Unknown action");
|
||||
}
|
||||
return os.str();
|
||||
}
|
||||
|
||||
std::string CmdProxy::DetectorStatus(int action) {
|
||||
std::ostringstream os;
|
||||
os << cmd << ' ';
|
||||
if (action == defs::HELP_ACTION) {
|
||||
os << "[running, error, transmitting, finished, waiting, idle]\n\tDetector status."
|
||||
<< '\n';
|
||||
} else if (action == defs::GET_ACTION) {
|
||||
if (args.size() != 0) {
|
||||
WrongNumberOfParameters(0);
|
||||
}
|
||||
auto t = det->getDetectorStatus({det_id});
|
||||
os << OutString(t) << '\n';
|
||||
} else if (action == defs::PUT_ACTION) {
|
||||
throw sls::RuntimeError("Cannot put. Did you mean to use command 'start' or 'stop'?");
|
||||
} else {
|
||||
throw sls::RuntimeError("Unknown action");
|
||||
}
|
||||
return os.str();
|
||||
}
|
||||
|
||||
/* Network Configuration (Detector<->Receiver) */
|
||||
|
||||
std::string CmdProxy::UDPDestinationIP(int action) {
|
||||
|
@ -691,8 +691,8 @@ class CmdProxy {
|
||||
{"rx_stop", &CmdProxy::rx_stop},
|
||||
{"start", &CmdProxy::start},
|
||||
{"stop", &CmdProxy::stop},
|
||||
{"rx_status", &CmdProxy::rx_status},
|
||||
{"status", &CmdProxy::status},
|
||||
{"rx_status", &CmdProxy::ReceiverStatus},
|
||||
{"status", &CmdProxy::DetectorStatus},
|
||||
{"rx_framescaught", &CmdProxy::rx_framescaught},
|
||||
{"rx_missingpackets", &CmdProxy::rx_missingpackets},
|
||||
{"startingfnum", &CmdProxy::startingfnum},
|
||||
@ -934,6 +934,8 @@ class CmdProxy {
|
||||
std::string DacValues(int action);
|
||||
std::vector<std::string> DacCommands();
|
||||
/* acquisition */
|
||||
std::string ReceiverStatus(int action);
|
||||
std::string DetectorStatus(int action);
|
||||
/* Network Configuration (Detector<->Receiver) */
|
||||
std::string UDPDestinationIP(int action);
|
||||
std::string UDPDestinationIP2(int action);
|
||||
@ -1363,12 +1365,6 @@ class CmdProxy {
|
||||
EXECUTE_SET_COMMAND_NOID(stop, stopDetector,
|
||||
"\n\tStops detector state machine.");
|
||||
|
||||
GET_COMMAND(rx_status, getReceiverStatus,
|
||||
"running, idle]\n\tReceiver listener status.");
|
||||
|
||||
GET_COMMAND(status, getDetectorStatus,
|
||||
"[running, error, transmitting, finished, waiting, idle]\n\tDetector status.");
|
||||
|
||||
GET_COMMAND(rx_framescaught, getFramesCaught,
|
||||
"\n\tNumber of frames caught by receiver.");
|
||||
|
||||
|
@ -234,8 +234,7 @@ Result<ns> Detector::getPeriodLeft(Positions pos) const {
|
||||
}
|
||||
|
||||
Result<defs::timingMode> Detector::getTimingMode(Positions pos) const {
|
||||
return pimpl->Parallel(&Module::setTimingMode, pos,
|
||||
defs::GET_TIMING_MODE);
|
||||
return pimpl->Parallel(&Module::getTimingMode, pos);
|
||||
}
|
||||
|
||||
void Detector::setTimingMode(defs::timingMode value, Positions pos) {
|
||||
@ -923,7 +922,7 @@ void Detector::setClientZmqIp(const IpAddr ip, Positions pos) {
|
||||
// Eiger Specific
|
||||
|
||||
Result<int> Detector::getDynamicRange(Positions pos) const {
|
||||
return pimpl->Parallel(&Module::setDynamicRange, pos, -1);
|
||||
return pimpl->Parallel(&Module::getDynamicRange, pos);
|
||||
}
|
||||
|
||||
void Detector::setDynamicRange(int value) {
|
||||
|
@ -462,6 +462,7 @@ void DetectorImpl::readFrameFromReceiver() {
|
||||
std::string currentFileName;
|
||||
uint64_t currentAcquisitionIndex = -1, currentFrameIndex = -1,
|
||||
currentFileIndex = -1;
|
||||
int currentProgress = -1;
|
||||
uint32_t currentSubFrameIndex = -1, coordX = -1, coordY = -1,
|
||||
flippedDataX = -1;
|
||||
|
||||
@ -540,6 +541,7 @@ void DetectorImpl::readFrameFromReceiver() {
|
||||
currentFileName = zHeader.fname;
|
||||
currentAcquisitionIndex = zHeader.acqIndex;
|
||||
currentFrameIndex = zHeader.frameIndex;
|
||||
currentProgress = zHeader.progress;
|
||||
currentFileIndex = zHeader.fileIndex;
|
||||
currentSubFrameIndex = zHeader.expLength;
|
||||
coordY = zHeader.row;
|
||||
@ -559,6 +561,7 @@ void DetectorImpl::readFrameFromReceiver() {
|
||||
<< "\n\tcurrentFrameIndex: " << currentFrameIndex
|
||||
<< "\n\tcurrentFileIndex: " << currentFileIndex
|
||||
<< "\n\tcurrentSubFrameIndex: " << currentSubFrameIndex
|
||||
<< "\n\tcurrentProgress: " << currentProgress
|
||||
<< "\n\tcoordX: " << coordX << "\n\tcoordY: " << coordY
|
||||
<< "\n\tflippedDataX: " << flippedDataX
|
||||
<< "\n\tcompleteImage: " << completeImage;
|
||||
@ -613,7 +616,6 @@ void DetectorImpl::readFrameFromReceiver() {
|
||||
|
||||
// send data to callback
|
||||
if (data) {
|
||||
setCurrentProgress(currentFrameIndex + 1);
|
||||
char* image = multiframe;
|
||||
int imagesize = multisize;
|
||||
|
||||
@ -630,7 +632,7 @@ void DetectorImpl::readFrameFromReceiver() {
|
||||
<< "\n\timagesize: " << imagesize
|
||||
<< "\n\tdynamicRange: " << dynamicRange;
|
||||
|
||||
thisData = new detectorData(getCurrentProgress(),
|
||||
thisData = new detectorData(currentProgress,
|
||||
currentFileName, nDetPixelsX, nDetPixelsY, image,
|
||||
imagesize, dynamicRange, currentFileIndex, completeImage);
|
||||
|
||||
@ -1004,38 +1006,6 @@ void DetectorImpl::registerDataCallback(void (*userCallback)(detectorData *,
|
||||
enableDataStreamingToClient(dataReady == nullptr ? 0 : 1);
|
||||
}
|
||||
|
||||
double DetectorImpl::setTotalProgress() {
|
||||
int64_t tot = Parallel(&Module::getTotalNumFramesToReceive, {})
|
||||
.tsquash("Inconsistent number of total frames (#frames x #triggers(or bursts) x #storage cells)");
|
||||
if (tot == 0) {
|
||||
throw RuntimeError("Invalid Total Number of frames (0)");
|
||||
}
|
||||
totalProgress = tot;
|
||||
LOG(logDEBUG1) << "Set total progress " << totalProgress << std::endl;
|
||||
return totalProgress;
|
||||
}
|
||||
|
||||
double DetectorImpl::getCurrentProgress() {
|
||||
std::lock_guard<std::mutex> lock(mp);
|
||||
return 100. * progressIndex / totalProgress;
|
||||
}
|
||||
|
||||
void DetectorImpl::incrementProgress() {
|
||||
std::lock_guard<std::mutex> lock(mp);
|
||||
progressIndex += 1;
|
||||
std::cout << std::fixed << std::setprecision(2) << std::setw(6)
|
||||
<< 100. * progressIndex / totalProgress << " \%";
|
||||
std::cout << '\r' << std::flush;
|
||||
}
|
||||
|
||||
void DetectorImpl::setCurrentProgress(int64_t i) {
|
||||
std::lock_guard<std::mutex> lock(mp);
|
||||
progressIndex = (double)i;
|
||||
std::cout << std::fixed << std::setprecision(2) << std::setw(6)
|
||||
<< 100. * progressIndex / totalProgress << " \%";
|
||||
std::cout << '\r' << std::flush;
|
||||
}
|
||||
|
||||
int DetectorImpl::acquire() {
|
||||
// ensure acquire isnt started multiple times by same client
|
||||
if (!isAcquireReady()) {
|
||||
@ -1056,7 +1026,7 @@ int DetectorImpl::acquire() {
|
||||
|
||||
bool receiver =
|
||||
Parallel(&Module::getUseReceiverFlag, {}).squash(false);
|
||||
progressIndex = 0;
|
||||
|
||||
setJoinThreadFlag(false);
|
||||
|
||||
// verify receiver is idle
|
||||
@ -1066,7 +1036,6 @@ int DetectorImpl::acquire() {
|
||||
Parallel(&Module::stopReceiver, {});
|
||||
}
|
||||
}
|
||||
setTotalProgress();
|
||||
|
||||
startProcessingThread();
|
||||
|
||||
@ -1106,12 +1075,10 @@ int DetectorImpl::acquire() {
|
||||
dataProcessingThread.join();
|
||||
|
||||
if (acquisition_finished != nullptr) {
|
||||
// same status for all, else error
|
||||
int status = static_cast<int>(ERROR);
|
||||
auto t = Parallel(&Module::getRunStatus, {});
|
||||
if (t.equal())
|
||||
status = t.front();
|
||||
acquisition_finished(getCurrentProgress(), status, acqFinished_p);
|
||||
int status = Parallel(&Module::getRunStatus, {}).squash(ERROR);
|
||||
auto a = Parallel(&Module::getReceiverProgress, {});
|
||||
int progress = (*std::min_element (a.begin(), a.end()));
|
||||
acquisition_finished((double)progress, status, acqFinished_p);
|
||||
}
|
||||
|
||||
sem_destroy(&sem_newRTAcquisition);
|
||||
@ -1130,8 +1097,14 @@ int DetectorImpl::acquire() {
|
||||
return OK;
|
||||
}
|
||||
|
||||
void DetectorImpl::printProgress(double progress) {
|
||||
std::cout << std::fixed << std::setprecision(2) << std::setw(6)
|
||||
<< progress << " \%";
|
||||
std::cout << '\r' << std::flush;
|
||||
}
|
||||
|
||||
|
||||
void DetectorImpl::startProcessingThread() {
|
||||
setTotalProgress();
|
||||
dataProcessingThread = std::thread(&DetectorImpl::processData, this);
|
||||
}
|
||||
|
||||
@ -1142,7 +1115,9 @@ void DetectorImpl::processData() {
|
||||
}
|
||||
// only update progress
|
||||
else {
|
||||
int64_t caught = -1;
|
||||
double progress = 0;
|
||||
printProgress(progress);
|
||||
|
||||
while (true) {
|
||||
// to exit acquire by typing q
|
||||
if (kbhit() != 0) {
|
||||
@ -1152,16 +1127,18 @@ void DetectorImpl::processData() {
|
||||
Parallel(&Module::stopAcquisition, {});
|
||||
}
|
||||
}
|
||||
// get progress
|
||||
caught = Parallel(&Module::getFramesCaughtByReceiver, {0})
|
||||
.squash();
|
||||
|
||||
// updating progress
|
||||
if (caught != -1) {
|
||||
setCurrentProgress(caught);
|
||||
// get and print progress
|
||||
double temp = (double)Parallel(&Module::getReceiverProgress, {0}).squash();
|
||||
if (temp != progress) {
|
||||
printProgress(progress);
|
||||
progress = temp;
|
||||
}
|
||||
|
||||
// exiting loop
|
||||
if (getJoinThreadFlag()) {
|
||||
// print progress one final time before exiting
|
||||
progress = (double)Parallel(&Module::getReceiverProgress, {0}).squash();
|
||||
printProgress(progress);
|
||||
break;
|
||||
}
|
||||
// otherwise error when connecting to the receiver too fast
|
||||
|
@ -354,13 +354,7 @@ class DetectorImpl : public virtual slsDetectorDefs {
|
||||
int InsertGapPixels(char *image, char *&gpImage, bool quadEnable, int dr,
|
||||
int &nPixelsx, int &nPixelsy);
|
||||
|
||||
double setTotalProgress();
|
||||
|
||||
double getCurrentProgress();
|
||||
|
||||
void incrementProgress();
|
||||
|
||||
void setCurrentProgress(int64_t i = 0);
|
||||
void printProgress(double progress);
|
||||
|
||||
void startProcessingThread();
|
||||
|
||||
@ -405,12 +399,6 @@ class DetectorImpl : public virtual slsDetectorDefs {
|
||||
* from ext. process) */
|
||||
sem_t sem_endRTAcquisition;
|
||||
|
||||
/** Total number of frames/images for next acquisition */
|
||||
double totalProgress{0};
|
||||
|
||||
/** Current progress or frames/images processed in current acquisition */
|
||||
double progressIndex{0};
|
||||
|
||||
/** mutex to synchronize main and data processing threads */
|
||||
mutable std::mutex mp;
|
||||
|
||||
|
@ -396,14 +396,6 @@ void Module::initializeDetectorStructure(detectorType type) {
|
||||
shm()->controlPort = DEFAULT_PORTNO;
|
||||
shm()->stopPort = DEFAULT_PORTNO + 1;
|
||||
sls::strcpy_safe(shm()->settingsDir, getenv("HOME"));
|
||||
shm()->currentSettings = UNINITIALIZED;
|
||||
shm()->nFrames = 1;
|
||||
shm()->nTriggers = 1;
|
||||
shm()->nBursts = 1;
|
||||
shm()->nAddStorageCells = 0;
|
||||
shm()->timingMode = AUTO_TIMING;
|
||||
shm()->burstMode = BURST_INTERNAL;
|
||||
shm()->deadTime = 0;
|
||||
sls::strcpy_safe(shm()->rxHostname, "none");
|
||||
shm()->rxTCPPort = DEFAULT_PORTNO + 2;
|
||||
shm()->useReceiverFlag = false;
|
||||
@ -420,7 +412,6 @@ void Module::initializeDetectorStructure(detectorType type) {
|
||||
shm()->nChip.x = parameters.nChipX;
|
||||
shm()->nChip.y = parameters.nChipY;
|
||||
shm()->nDacs = parameters.nDacs;
|
||||
shm()->dynamicRange = parameters.dynamicRange;
|
||||
}
|
||||
|
||||
int Module::sendModule(sls_detector_module *myMod,
|
||||
@ -719,54 +710,11 @@ void Module::updateCachedDetectorVariables() {
|
||||
if (client.sendCommandThenRead(fnum, nullptr, 0, nullptr, 0) ==
|
||||
FORCE_UPDATE) {
|
||||
int n = 0, i32 = 0;
|
||||
int64_t i64 = 0;
|
||||
sls::IpAddr lastClientIP;
|
||||
n += client.Receive(&lastClientIP, sizeof(lastClientIP));
|
||||
LOG(logDEBUG1)
|
||||
<< "Updating detector last modified by " << lastClientIP;
|
||||
|
||||
// dr
|
||||
n += client.Receive(&i32, sizeof(i32));
|
||||
shm()->dynamicRange = i32;
|
||||
|
||||
// settings
|
||||
if (shm()->myDetectorType == EIGER || shm()->myDetectorType == JUNGFRAU ||
|
||||
shm()->myDetectorType == GOTTHARD || shm()->myDetectorType == GOTTHARD2 ||
|
||||
shm()->myDetectorType == MOENCH) {
|
||||
n += client.Receive(&i32, sizeof(i32));
|
||||
shm()->currentSettings = static_cast<detectorSettings>(i32);
|
||||
}
|
||||
|
||||
// frame number
|
||||
n += client.Receive(&i64, sizeof(i64));
|
||||
shm()->nFrames = i64;
|
||||
|
||||
// storage cell
|
||||
if (shm()->myDetectorType == JUNGFRAU) {
|
||||
n += client.Receive(&i64, sizeof(i64));
|
||||
shm()->nAddStorageCells = i64;
|
||||
}
|
||||
|
||||
// triggers
|
||||
n += client.Receive(&i64, sizeof(i64));
|
||||
shm()->nTriggers = i64;
|
||||
|
||||
// bursts
|
||||
if (shm()->myDetectorType == GOTTHARD2) {
|
||||
n += client.Receive(&i64, sizeof(i64));
|
||||
shm()->nBursts = i64;
|
||||
}
|
||||
|
||||
// timing mode
|
||||
n += client.Receive(&i32, sizeof(i32));
|
||||
shm()->timingMode = static_cast<timingMode>(i32);
|
||||
|
||||
// burst mode
|
||||
if (shm()->myDetectorType == GOTTHARD2) {
|
||||
n += client.Receive(&i32, sizeof(i32));
|
||||
shm()->burstMode = static_cast<burstMode>(i32);
|
||||
}
|
||||
|
||||
// number of channels (depends on #samples, adcmask)
|
||||
if (shm()->myDetectorType == CHIPTESTBOARD ||
|
||||
shm()->myDetectorType == MOENCH) {
|
||||
@ -863,49 +811,21 @@ std::vector<std::string> Module::getConfigFileCommands() {
|
||||
}
|
||||
|
||||
slsDetectorDefs::detectorSettings Module::getSettings() {
|
||||
return sendSettingsOnly(GET_SETTINGS);
|
||||
int arg = -1;
|
||||
int retval = -1;
|
||||
sendToDetector(F_SET_SETTINGS, arg, retval);
|
||||
LOG(logDEBUG1) << "Settings: " << retval;
|
||||
return static_cast<detectorSettings>(retval);
|
||||
}
|
||||
|
||||
slsDetectorDefs::detectorSettings
|
||||
Module::setSettings(detectorSettings isettings) {
|
||||
LOG(logDEBUG1) << "Module setSettings " << isettings;
|
||||
|
||||
if (isettings == -1) {
|
||||
return getSettings();
|
||||
}
|
||||
|
||||
// eiger: only set shm, setting threshold loads the module data
|
||||
void Module::setSettings(detectorSettings isettings) {
|
||||
if (shm()->myDetectorType == EIGER) {
|
||||
switch (isettings) {
|
||||
case STANDARD:
|
||||
case HIGHGAIN:
|
||||
case LOWGAIN:
|
||||
case VERYHIGHGAIN:
|
||||
case VERYLOWGAIN:
|
||||
shm()->currentSettings = isettings;
|
||||
return shm()->currentSettings;
|
||||
default:
|
||||
std::ostringstream ss;
|
||||
ss << "Unknown settings " << ToString(isettings)
|
||||
<< " for this detector!";
|
||||
throw RuntimeError(ss.str());
|
||||
}
|
||||
throw RuntimeError("Cannot set settings for Eiger. Use threshold energy.");
|
||||
}
|
||||
|
||||
// others: send only the settings, detector server will update dac values
|
||||
// already in server
|
||||
return sendSettingsOnly(isettings);
|
||||
}
|
||||
|
||||
slsDetectorDefs::detectorSettings
|
||||
Module::sendSettingsOnly(detectorSettings isettings) {
|
||||
int arg = static_cast<int>(isettings);
|
||||
int retval = -1;
|
||||
LOG(logDEBUG1) << "Setting settings to " << arg;
|
||||
sendToDetector(F_SET_SETTINGS, arg, retval);
|
||||
LOG(logDEBUG1) << "Settings: " << retval;
|
||||
shm()->currentSettings = static_cast<detectorSettings>(retval);
|
||||
return shm()->currentSettings;
|
||||
}
|
||||
|
||||
int Module::getThresholdEnergy() {
|
||||
@ -944,8 +864,11 @@ void Module::setThresholdEnergy(int e_eV, detectorSettings isettings,
|
||||
else if (shm()->myDetectorType == MOENCH) {
|
||||
setAdditionalJsonParameter("threshold", std::to_string(e_eV));
|
||||
}
|
||||
throw RuntimeError(
|
||||
|
||||
else {
|
||||
throw RuntimeError(
|
||||
"Set threshold energy not implemented for this detector");
|
||||
}
|
||||
}
|
||||
|
||||
void Module::setThresholdEnergyAndSettings(int e_eV,
|
||||
@ -954,7 +877,7 @@ void Module::setThresholdEnergyAndSettings(int e_eV,
|
||||
|
||||
// if settings provided, use that, else use the shared memory variable
|
||||
detectorSettings is =
|
||||
((isettings != GET_SETTINGS) ? isettings : shm()->currentSettings);
|
||||
((isettings != GET_SETTINGS) ? isettings : getSettings());
|
||||
|
||||
// verify e_eV exists in trimEneregies[]
|
||||
if (shm()->trimEnergies.empty() || (e_eV < shm()->trimEnergies.front()) ||
|
||||
@ -999,8 +922,7 @@ void Module::setThresholdEnergyAndSettings(int e_eV,
|
||||
linearInterpolation(e_eV, trim1, trim2, myMod1.tau, myMod2.tau);
|
||||
}
|
||||
|
||||
shm()->currentSettings = is;
|
||||
myMod.reg = shm()->currentSettings;
|
||||
myMod.reg = is;
|
||||
myMod.eV = e_eV;
|
||||
setModule(myMod, tb);
|
||||
if (getSettings() != is) {
|
||||
@ -1161,101 +1083,64 @@ uint64_t Module::getStartingFrameNumber() {
|
||||
return retval;
|
||||
}
|
||||
|
||||
int64_t Module::getTotalNumFramesToReceive() {
|
||||
int64_t repeats = shm()->nTriggers;
|
||||
// gotthard2 & auto & burst mode, use nBursts instead of nTriggers
|
||||
if (shm()->myDetectorType == GOTTHARD2) {
|
||||
// auto mode (either bursts or no repeats)
|
||||
if (shm()->timingMode == AUTO_TIMING) {
|
||||
if (shm()->burstMode != BURST_OFF) {
|
||||
repeats = shm()->nBursts;
|
||||
} else {
|
||||
repeats = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return (shm()->nFrames * repeats * (int64_t)(shm()->nAddStorageCells + 1));
|
||||
}
|
||||
|
||||
void Module::sendTotalNumFramestoReceiver() {
|
||||
if (shm()->useReceiverFlag) {
|
||||
int64_t arg = getTotalNumFramesToReceive();
|
||||
LOG(logDEBUG1) << "Sending total number of frames (#f x #t x #s) to Receiver: " << arg;
|
||||
sendToReceiver(F_RECEIVER_SET_NUM_FRAMES, arg, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
int64_t Module::getNumberOfFrames() {
|
||||
int64_t retval = -1;
|
||||
sendToDetector(F_GET_NUM_FRAMES, nullptr, retval);
|
||||
LOG(logDEBUG1) << "number of frames :" << retval;
|
||||
if (shm()->nFrames != retval) {
|
||||
shm()->nFrames = retval;
|
||||
sendTotalNumFramestoReceiver();
|
||||
}
|
||||
return shm()->nFrames;
|
||||
return retval;
|
||||
}
|
||||
|
||||
void Module::setNumberOfFrames(int64_t value) {
|
||||
LOG(logDEBUG1) << "Setting number of frames to " << value;
|
||||
sendToDetector(F_SET_NUM_FRAMES, value, nullptr);
|
||||
shm()->nFrames = value;
|
||||
sendTotalNumFramestoReceiver();
|
||||
if (shm()->useReceiverFlag) {
|
||||
LOG(logDEBUG1) << "Sending number of frames to Receiver: " << value;
|
||||
sendToReceiver(F_RECEIVER_SET_NUM_FRAMES, value, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
int64_t Module::getNumberOfTriggers() {
|
||||
int64_t retval = -1;
|
||||
sendToDetector(F_GET_NUM_TRIGGERS, nullptr, retval);
|
||||
LOG(logDEBUG1) << "number of triggers :" << retval;
|
||||
if (shm()->nTriggers != retval) {
|
||||
shm()->nTriggers = retval;
|
||||
sendTotalNumFramestoReceiver();
|
||||
}
|
||||
return shm()->nTriggers;
|
||||
return retval;
|
||||
}
|
||||
|
||||
void Module::setNumberOfTriggers(int64_t value) {
|
||||
LOG(logDEBUG1) << "Setting number of triggers to " << value;
|
||||
sendToDetector(F_SET_NUM_TRIGGERS, value, nullptr);
|
||||
shm()->nTriggers = value;
|
||||
sendTotalNumFramestoReceiver();
|
||||
if (shm()->useReceiverFlag) {
|
||||
LOG(logDEBUG1) << "Sending number of triggers to Receiver: " << value;
|
||||
sendToReceiver(F_SET_RECEIVER_NUM_TRIGGERS, value, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
int64_t Module::getNumberOfBursts() {
|
||||
int64_t retval = -1;
|
||||
sendToDetector(F_GET_NUM_BURSTS, nullptr, retval);
|
||||
LOG(logDEBUG1) << "number of bursts :" << retval;
|
||||
if (shm()->nBursts != retval) {
|
||||
shm()->nBursts = retval;
|
||||
sendTotalNumFramestoReceiver();
|
||||
}
|
||||
return shm()->nBursts;
|
||||
return retval;
|
||||
}
|
||||
|
||||
void Module::setNumberOfBursts(int64_t value) {
|
||||
LOG(logDEBUG1) << "Setting number of bursts to " << value;
|
||||
sendToDetector(F_SET_NUM_BURSTS, value, nullptr);
|
||||
shm()->nBursts = value;
|
||||
sendTotalNumFramestoReceiver();
|
||||
if (shm()->useReceiverFlag) {
|
||||
LOG(logDEBUG1) << "Sending number of bursts to Receiver: " << value;
|
||||
sendToReceiver(F_SET_RECEIVER_NUM_BURSTS, value, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
int Module::getNumberOfAdditionalStorageCells() {
|
||||
int prevVal = shm()->nAddStorageCells;
|
||||
int retval = -1;
|
||||
sendToDetector(F_GET_NUM_ADDITIONAL_STORAGE_CELLS, nullptr, retval);
|
||||
LOG(logDEBUG1) << "number of storage cells :" << retval;
|
||||
shm()->nAddStorageCells = retval;
|
||||
if (prevVal != retval) {
|
||||
sendTotalNumFramestoReceiver();
|
||||
}
|
||||
return shm()->nAddStorageCells;
|
||||
return retval;
|
||||
}
|
||||
|
||||
void Module::setNumberOfAdditionalStorageCells(int value) {
|
||||
LOG(logDEBUG1) << "Setting number of storage cells to " << value;
|
||||
sendToDetector(F_SET_NUM_ADDITIONAL_STORAGE_CELLS, value, nullptr);
|
||||
shm()->nAddStorageCells = value;
|
||||
sendTotalNumFramestoReceiver();
|
||||
}
|
||||
|
||||
int Module::getNumberOfAnalogSamples() {
|
||||
@ -1305,16 +1190,13 @@ void Module::setExptime(int64_t value) {
|
||||
}
|
||||
LOG(logDEBUG1) << "Setting exptime to " << value << "ns";
|
||||
sendToDetector(F_SET_EXPTIME, value, nullptr);
|
||||
if (shm()->myDetectorType == EIGER && prevVal != value && shm()->dynamicRange == 16) {
|
||||
int r = getRateCorrection();
|
||||
if (r != 0) {
|
||||
setRateCorrection(r);
|
||||
}
|
||||
}
|
||||
if (shm()->useReceiverFlag) {
|
||||
LOG(logDEBUG1) << "Sending exptime to Receiver: " << value;
|
||||
sendToReceiver(F_RECEIVER_SET_EXPTIME, value, nullptr);
|
||||
}
|
||||
if (prevVal != value) {
|
||||
updateRateCorrection();
|
||||
}
|
||||
}
|
||||
|
||||
int64_t Module::getPeriod() {
|
||||
@ -1358,17 +1240,14 @@ void Module::setSubExptime(int64_t value) {
|
||||
prevVal = getSubExptime();
|
||||
}
|
||||
LOG(logDEBUG1) << "Setting sub exptime to " << value << "ns";
|
||||
sendToDetector(F_SET_SUB_EXPTIME, value, nullptr);
|
||||
if (shm()->myDetectorType == EIGER && prevVal != value && shm()->dynamicRange == 32) {
|
||||
int r = getRateCorrection();
|
||||
if (r != 0) {
|
||||
setRateCorrection(r);
|
||||
}
|
||||
}
|
||||
sendToDetector(F_SET_SUB_EXPTIME, value, nullptr);
|
||||
if (shm()->useReceiverFlag) {
|
||||
LOG(logDEBUG1) << "Sending sub exptime to Receiver: " << value;
|
||||
sendToReceiver(F_RECEIVER_SET_SUB_EXPTIME, value, nullptr);
|
||||
}
|
||||
if (prevVal != value) {
|
||||
updateRateCorrection();
|
||||
}
|
||||
}
|
||||
|
||||
int64_t Module::getSubDeadTime() {
|
||||
@ -1466,48 +1345,68 @@ int64_t Module::getMeasurementTime() const {
|
||||
return retval;
|
||||
}
|
||||
|
||||
slsDetectorDefs::timingMode Module::setTimingMode(timingMode value) {
|
||||
int fnum = F_SET_TIMING_MODE;
|
||||
//auto arg = static_cast<int>(pol);
|
||||
slsDetectorDefs::timingMode Module::getTimingMode() {
|
||||
int arg = -1;
|
||||
timingMode retval = GET_TIMING_MODE;
|
||||
LOG(logDEBUG1) << "Setting communication to mode " << value;
|
||||
sendToDetector(fnum, static_cast<int>(value), retval);
|
||||
sendToDetector(F_SET_TIMING_MODE, arg, retval);
|
||||
LOG(logDEBUG1) << "Timing Mode: " << retval;
|
||||
shm()->timingMode = retval;
|
||||
return retval;
|
||||
}
|
||||
|
||||
int Module::setDynamicRange(int n) {
|
||||
// TODO! Properly handle fail
|
||||
int prevDr = shm()->dynamicRange;
|
||||
void Module::setTimingMode(timingMode value) {
|
||||
timingMode retval = GET_TIMING_MODE;
|
||||
LOG(logDEBUG1) << "Setting timing mode to " << value;
|
||||
sendToDetector(F_SET_TIMING_MODE, static_cast<int>(value), retval);
|
||||
if (shm()->useReceiverFlag) {
|
||||
LOG(logDEBUG1) << "Sending timing mode to Receiver: " << value;
|
||||
sendToReceiver(F_SET_RECEIVER_TIMING_MODE, value, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
int Module::getDynamicRange() {
|
||||
int arg = -1;
|
||||
int retval = -1;
|
||||
sendToDetector(F_SET_DYNAMIC_RANGE, arg, retval);
|
||||
LOG(logDEBUG1) << "Dynamic Range: " << retval;
|
||||
return retval;
|
||||
}
|
||||
|
||||
void Module::setDynamicRange(int n) {
|
||||
int prev_val = n;
|
||||
if (shm()->myDetectorType == EIGER) {
|
||||
prev_val = getDynamicRange();
|
||||
}
|
||||
|
||||
int retval = -1;
|
||||
LOG(logDEBUG1) << "Setting dynamic range to " << n;
|
||||
sendToDetector(F_SET_DYNAMIC_RANGE, n, retval);
|
||||
LOG(logDEBUG1) << "Dynamic Range: " << retval;
|
||||
shm()->dynamicRange = retval;
|
||||
|
||||
if (shm()->useReceiverFlag) {
|
||||
n = shm()->dynamicRange;
|
||||
int arg = retval;
|
||||
retval = -1;
|
||||
LOG(logDEBUG1) << "Sending dynamic range to receiver: " << n;
|
||||
sendToReceiver(F_SET_RECEIVER_DYNAMIC_RANGE, n, retval);
|
||||
LOG(logDEBUG1) << "Sending dynamic range to receiver: " << arg;
|
||||
sendToReceiver(F_SET_RECEIVER_DYNAMIC_RANGE, arg, retval);
|
||||
LOG(logDEBUG1) << "Receiver Dynamic range: " << retval;
|
||||
}
|
||||
|
||||
// changes in dr
|
||||
int dr = shm()->dynamicRange;
|
||||
if (prevDr != dr && shm()->myDetectorType == EIGER) {
|
||||
updateRateCorrection();
|
||||
if (n != prev_val) {
|
||||
// update speed for usability
|
||||
if (dr == 32) {
|
||||
LOG(logINFO) << "Setting Clock to Quarter Speed to cope with Dynamic Range of 32"; setClockDivider(RUN_CLOCK, 2);
|
||||
} else {
|
||||
LOG(logINFO) << "Setting Clock to Full Speed to cope with Dynamic Range of " << dr; setClockDivider(RUN_CLOCK, 0);
|
||||
switch (n) {
|
||||
case 32:
|
||||
LOG(logINFO) << "Setting Clock to Quarter Speed to cope with Dynamic Range of 32";
|
||||
setClockDivider(RUN_CLOCK, 2);
|
||||
break;
|
||||
case 16:
|
||||
LOG(logINFO) << "Setting Clock to Full Speed to cope with Dynamic Range of " << n;
|
||||
setClockDivider(RUN_CLOCK, 0);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
updateRateCorrection();
|
||||
}
|
||||
|
||||
return shm()->dynamicRange;
|
||||
}
|
||||
|
||||
int Module::setDAC(int val, dacIndex index, int mV) {
|
||||
@ -1701,7 +1600,9 @@ std::string Module::setReceiverHostname(const std::string &receiverIP) {
|
||||
LOG(logDEBUG1) << printReceiverConfiguration();
|
||||
|
||||
setReceiverUDPSocketBufferSize(0);
|
||||
sendTotalNumFramestoReceiver();
|
||||
setNumberOfFrames(getNumberOfFrames());
|
||||
setNumberOfTriggers(getNumberOfTriggers());
|
||||
setTimingMode(getTimingMode());
|
||||
setExptime(getExptime());
|
||||
setPeriod(getPeriod());
|
||||
|
||||
@ -1711,7 +1612,7 @@ std::string Module::setReceiverHostname(const std::string &receiverIP) {
|
||||
case EIGER:
|
||||
setSubExptime(getSubExptime());
|
||||
setSubDeadTime(getSubDeadTime());
|
||||
setDynamicRange(shm()->dynamicRange);
|
||||
setDynamicRange(getDynamicRange());
|
||||
activate(-1);
|
||||
enableTenGigabitEthernet(-1);
|
||||
setQuad(getQuad());
|
||||
@ -1739,7 +1640,12 @@ std::string Module::setReceiverHostname(const std::string &receiverIP) {
|
||||
|
||||
case MYTHEN3:
|
||||
sendNumberofCounterstoReceiver(getCounterMask());
|
||||
setDynamicRange(shm()->dynamicRange);
|
||||
setDynamicRange(getDynamicRange());
|
||||
break;
|
||||
|
||||
case GOTTHARD2:
|
||||
setNumberOfBursts(getNumberOfBursts());
|
||||
setBurstMode(getBurstMode());
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -2374,15 +2280,17 @@ slsDetectorDefs::burstMode Module::getBurstMode() {
|
||||
int retval = -1;
|
||||
sendToDetector(F_GET_BURST_MODE, nullptr, retval);
|
||||
LOG(logDEBUG1) << "Burst mode:" << retval;
|
||||
shm()->burstMode = static_cast<slsDetectorDefs::burstMode>(retval);
|
||||
return shm()->burstMode;
|
||||
return static_cast<slsDetectorDefs::burstMode>(retval);
|
||||
}
|
||||
|
||||
void Module::setBurstMode(slsDetectorDefs::burstMode value) {
|
||||
int arg = static_cast<int>(value);
|
||||
LOG(logDEBUG1) << "Setting burst mode to " << arg;
|
||||
sendToDetector(F_SET_BURST_MODE, arg, nullptr);
|
||||
shm()->burstMode = value;
|
||||
if (shm()->useReceiverFlag) {
|
||||
LOG(logDEBUG1) << "Sending burst mode to Receiver: " << value;
|
||||
sendToReceiver(F_SET_RECEIVER_BURST_MODE, value, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
bool Module::getCurrentSource() {
|
||||
@ -2950,37 +2858,23 @@ void Module::setDefaultRateCorrection() {
|
||||
LOG(logDEBUG1) << "Setting Default Rate Correction";
|
||||
int64_t arg = -1;
|
||||
sendToDetector(F_SET_RATE_CORRECT, arg, nullptr);
|
||||
shm()->deadTime = -1;
|
||||
}
|
||||
|
||||
void Module::setRateCorrection(int64_t t) {
|
||||
LOG(logDEBUG1) << "Setting Rate Correction to " << t;
|
||||
sendToDetector(F_SET_RATE_CORRECT, t, nullptr);
|
||||
shm()->deadTime = t;
|
||||
}
|
||||
|
||||
int64_t Module::getRateCorrection() {
|
||||
int64_t retval = -1;
|
||||
LOG(logDEBUG1) << "Getting rate correction";
|
||||
sendToDetector(F_GET_RATE_CORRECT, nullptr, retval);
|
||||
shm()->deadTime = retval;
|
||||
LOG(logDEBUG1) << "Rate correction: " << retval;
|
||||
return retval;
|
||||
}
|
||||
|
||||
void Module::updateRateCorrection() {
|
||||
if (shm()->deadTime != 0) {
|
||||
switch (shm()->dynamicRange) {
|
||||
case 16:
|
||||
case 32:
|
||||
setRateCorrection(shm()->deadTime);
|
||||
break;
|
||||
default:
|
||||
setRateCorrection(0);
|
||||
throw sls::RuntimeError(
|
||||
"Rate correction Deactivated, must be in 32 or 16 bit mode");
|
||||
}
|
||||
}
|
||||
LOG(logDEBUG1) << "Updating rate correction";
|
||||
sendToDetector(F_UPDATE_RATE_CORRECTION);
|
||||
}
|
||||
|
||||
std::string Module::printReceiverConfiguration() {
|
||||
@ -3281,6 +3175,15 @@ uint64_t Module::getReceiverCurrentFrameIndex() const {
|
||||
return retval;
|
||||
}
|
||||
|
||||
int Module::getReceiverProgress() const {
|
||||
int retval = -1;
|
||||
if (shm()->useReceiverFlag) {
|
||||
sendToReceiver(F_GET_RECEIVER_PROGRESS, nullptr, retval);
|
||||
LOG(logDEBUG1) << "Current Progress of Receiver: " << retval;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
void Module::setFileWrite(bool value) {
|
||||
if (!shm()->useReceiverFlag) {
|
||||
throw RuntimeError("Set rx_hostname first to use receiver parameters (file write enable)");
|
||||
|
@ -14,7 +14,7 @@
|
||||
class ServerInterface;
|
||||
|
||||
#define SLS_SHMAPIVERSION 0x190726
|
||||
#define SLS_SHMVERSION 0x200324
|
||||
#define SLS_SHMVERSION 0x200402
|
||||
|
||||
namespace sls{
|
||||
|
||||
@ -62,33 +62,6 @@ struct sharedSlsDetector {
|
||||
/** number of dacs per module*/
|
||||
int nDacs;
|
||||
|
||||
/** dynamic range of the detector data */
|
||||
int dynamicRange;
|
||||
|
||||
/** detector settings (standard, fast, etc.) */
|
||||
slsDetectorDefs::detectorSettings currentSettings;
|
||||
|
||||
/** number of frames */
|
||||
int64_t nFrames;
|
||||
|
||||
/** number of triggers */
|
||||
int64_t nTriggers;
|
||||
|
||||
/** number of bursts */
|
||||
int64_t nBursts;
|
||||
|
||||
/** number of additional storage cells */
|
||||
int nAddStorageCells;
|
||||
|
||||
/** timing mode */
|
||||
slsDetectorDefs::timingMode timingMode;
|
||||
|
||||
/** burst mode */
|
||||
slsDetectorDefs::burstMode burstMode;
|
||||
|
||||
/** rate correction in ns (needed for default -1) */
|
||||
int64_t deadTime;
|
||||
|
||||
/** ip address/hostname of the receiver for client control via TCP */
|
||||
char rxHostname[MAX_STR_LENGTH];
|
||||
|
||||
@ -309,10 +282,6 @@ class Module : public virtual slsDetectorDefs {
|
||||
*/
|
||||
std::vector<std::string> getConfigFileCommands();
|
||||
|
||||
/**
|
||||
* Get detector settings
|
||||
* @returns current settings
|
||||
*/
|
||||
detectorSettings getSettings();
|
||||
|
||||
/** [Jungfrau] Options:DYNAMICGAIN, DYNAMICHG0, FIXGAIN1, FIXGAIN2, FORCESWITCHG1, FORCESWITCHG2
|
||||
@ -320,18 +289,8 @@ class Module : public virtual slsDetectorDefs {
|
||||
* [Gotthard2] Options: DYNAMICGAIN, FIXGAIN1, FIXGAIN2
|
||||
* [Moench] Options: G1_HIGHGAIN, G1_LOWGAIN, G2_HIGHCAP_HIGHGAIN, G2_HIGHCAP_LOWGAIN,
|
||||
* G2_LOWCAP_HIGHGAIN, G2_LOWCAP_LOWGAIN, G4_HIGHGAIN, G4_LOWGAIN
|
||||
* [Eiger] Only stores them locally in shm Options: STANDARD, HIGHGAIN, LOWGAIN, VERYHIGHGAIN, VERYLOWGAIN
|
||||
*/
|
||||
detectorSettings setSettings(detectorSettings isettings);
|
||||
|
||||
/**
|
||||
* Send detector settings only (set only for Jungfrau, Gotthard, Moench, get
|
||||
* for all) Only the settings enum is sent to the detector, where it will
|
||||
* initialize al the dacs already hard coded in the detector server
|
||||
* @param isettings settings
|
||||
* @returns current settings
|
||||
*/
|
||||
detectorSettings sendSettingsOnly(detectorSettings isettings);
|
||||
void setSettings(detectorSettings isettings);
|
||||
|
||||
/**
|
||||
* Get threshold energy (Mythen and Eiger)
|
||||
@ -445,10 +404,6 @@ class Module : public virtual slsDetectorDefs {
|
||||
*/
|
||||
uint64_t getStartingFrameNumber();
|
||||
|
||||
int64_t getTotalNumFramesToReceive();
|
||||
|
||||
void sendTotalNumFramestoReceiver();
|
||||
|
||||
int64_t getNumberOfFrames();
|
||||
|
||||
void setNumberOfFrames(int64_t value);
|
||||
@ -556,22 +511,17 @@ class Module : public virtual slsDetectorDefs {
|
||||
* [Gotthard2] only in continuous mode */
|
||||
int64_t getMeasurementTime() const;
|
||||
|
||||
/**
|
||||
* Set/get timing mode
|
||||
* @param value timing mode (-1 gets)
|
||||
* @returns current timing mode
|
||||
*/
|
||||
timingMode setTimingMode(timingMode value = GET_TIMING_MODE);
|
||||
|
||||
timingMode getTimingMode();
|
||||
void setTimingMode(timingMode value);
|
||||
|
||||
int getDynamicRange();
|
||||
/**
|
||||
* Set/get dynamic range
|
||||
* (Eiger: If i is 32, also sets clkdivider to 2, if 16, sets clkdivider to
|
||||
* 1)
|
||||
* @param i dynamic range (-1 get)
|
||||
* @returns current dynamic range
|
||||
* \sa sharedSlsDetector
|
||||
*/
|
||||
int setDynamicRange(int n = -1);
|
||||
void setDynamicRange(int n);
|
||||
|
||||
/**
|
||||
* Set/get dacs value
|
||||
@ -1467,6 +1417,7 @@ class Module : public virtual slsDetectorDefs {
|
||||
* @returns current frame index of receiver
|
||||
*/
|
||||
uint64_t getReceiverCurrentFrameIndex() const;
|
||||
int getReceiverProgress() const;
|
||||
|
||||
|
||||
void setFileWrite(bool value);
|
||||
|
Reference in New Issue
Block a user