mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-21 03:10:02 +02:00
Factored out time conversion (#23)
* time conversion * with comment * lround in slsDetectorCommand
This commit is contained in:
parent
877bdb8979
commit
f1a1391866
@ -2209,6 +2209,14 @@ class multiSlsDetector : public virtual slsDetectorDefs {
|
|||||||
*/
|
*/
|
||||||
std::vector<char> readPofFile(const std::string &fname);
|
std::vector<char> readPofFile(const std::string &fname);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert a double holding time in seconds to an int64_t with nano seconds
|
||||||
|
* Used for conversion when sending time to detector
|
||||||
|
* @param t time in seconds
|
||||||
|
* @returns time in nano seconds
|
||||||
|
*/
|
||||||
|
int64_t secondsToNanoSeconds(double t);
|
||||||
|
|
||||||
|
|
||||||
/** Multi detector Id */
|
/** Multi detector Id */
|
||||||
const int multiId{0};
|
const int multiId{0};
|
||||||
|
@ -1099,89 +1099,50 @@ int64_t multiSlsDetector::setTimer(timerIndex index, int64_t t, int detPos) {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int64_t multiSlsDetector::secondsToNanoSeconds(double t){
|
||||||
|
int64_t ns = lround(t * 1E9);
|
||||||
|
return (ns < 0) ? -1: ns;
|
||||||
|
}
|
||||||
|
|
||||||
double multiSlsDetector::setExposureTime(double t, bool inseconds, int detPos) {
|
double multiSlsDetector::setExposureTime(double t, bool inseconds, int detPos) {
|
||||||
if (!inseconds) {
|
if (!inseconds) {
|
||||||
return setTimer(ACQUISITION_TIME, (int64_t)t, detPos);
|
return setTimer(ACQUISITION_TIME, (int64_t)t, detPos);
|
||||||
}
|
}
|
||||||
|
auto t_ns = setTimer(ACQUISITION_TIME, secondsToNanoSeconds(t), detPos);
|
||||||
// + 0.5 to round for precision lost from converting double to int64_t
|
return (t_ns < 0) ? -1 : 1E-9 * t_ns;
|
||||||
int64_t tms = (int64_t)(t * (1E+9) + 0.5);
|
|
||||||
if (t < 0) {
|
|
||||||
tms = -1;
|
|
||||||
}
|
|
||||||
tms = setTimer(ACQUISITION_TIME, tms, detPos);
|
|
||||||
if (tms < 0) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return ((1E-9) * (double)tms);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
double multiSlsDetector::setExposurePeriod(double t, bool inseconds, int detPos) {
|
double multiSlsDetector::setExposurePeriod(double t, bool inseconds, int detPos) {
|
||||||
if (!inseconds) {
|
if (!inseconds) {
|
||||||
return setTimer(FRAME_PERIOD, (int64_t)t, detPos);
|
return setTimer(FRAME_PERIOD, (int64_t)t, detPos);
|
||||||
}
|
}
|
||||||
|
auto t_ns = setTimer(FRAME_PERIOD, secondsToNanoSeconds(t), detPos);
|
||||||
// + 0.5 to round for precision lost from converting double to int64_t
|
return (t_ns < 0) ? -1 : 1E-9 * t_ns;
|
||||||
int64_t tms = (int64_t)(t * (1E+9) + 0.5);
|
|
||||||
if (t < 0) {
|
|
||||||
tms = -1;
|
|
||||||
}
|
|
||||||
tms = setTimer(FRAME_PERIOD, tms, detPos);
|
|
||||||
if (tms < 0) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return ((1E-9) * (double)tms);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
double multiSlsDetector::setDelayAfterTrigger(double t, bool inseconds, int detPos) {
|
double multiSlsDetector::setDelayAfterTrigger(double t, bool inseconds, int detPos) {
|
||||||
if (!inseconds) {
|
if (!inseconds) {
|
||||||
return setTimer(DELAY_AFTER_TRIGGER, (int64_t)t, detPos);
|
return setTimer(DELAY_AFTER_TRIGGER, (int64_t)t, detPos);
|
||||||
}
|
}
|
||||||
|
auto t_ns = setTimer(DELAY_AFTER_TRIGGER, secondsToNanoSeconds(t), detPos);
|
||||||
// + 0.5 to round for precision lost from converting double to int64_t
|
return (t_ns < 0) ? -1 : 1E-9 * t_ns;
|
||||||
int64_t tms = (int64_t)(t * (1E+9) + 0.5);
|
|
||||||
if (t < 0) {
|
|
||||||
tms = -1;
|
|
||||||
}
|
|
||||||
tms = setTimer(DELAY_AFTER_TRIGGER, tms, detPos);
|
|
||||||
if (tms < 0) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return ((1E-9) * (double)tms);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
double multiSlsDetector::setSubFrameExposureTime(double t, bool inseconds, int detPos) {
|
double multiSlsDetector::setSubFrameExposureTime(double t, bool inseconds, int detPos) {
|
||||||
if (!inseconds) {
|
if (!inseconds) {
|
||||||
return setTimer(SUBFRAME_ACQUISITION_TIME, (int64_t)t, detPos);
|
return setTimer(SUBFRAME_ACQUISITION_TIME, (int64_t)t, detPos);
|
||||||
} else {
|
|
||||||
// + 0.5 to round for precision lost from converting double to int64_t
|
|
||||||
int64_t tms = (int64_t)(t * (1E+9) + 0.5);
|
|
||||||
if (t < 0) {
|
|
||||||
tms = -1;
|
|
||||||
}
|
|
||||||
tms = setTimer(SUBFRAME_ACQUISITION_TIME, tms, detPos);
|
|
||||||
if (tms < 0) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return ((1E-9) * (double)tms);
|
|
||||||
}
|
}
|
||||||
|
auto t_ns = setTimer(SUBFRAME_ACQUISITION_TIME, secondsToNanoSeconds(t), detPos);
|
||||||
|
return (t_ns < 0) ? -1 : 1E-9 * t_ns;
|
||||||
}
|
}
|
||||||
|
|
||||||
double multiSlsDetector::setSubFrameExposureDeadTime(double t, bool inseconds, int detPos) {
|
double multiSlsDetector::setSubFrameExposureDeadTime(double t, bool inseconds, int detPos) {
|
||||||
if (!inseconds) {
|
if (!inseconds) {
|
||||||
return setTimer(SUBFRAME_DEADTIME, (int64_t)t, detPos);
|
return setTimer(SUBFRAME_DEADTIME, (int64_t)t, detPos);
|
||||||
} else {
|
|
||||||
// + 0.5 to round for precision lost from converting double to int64_t
|
|
||||||
int64_t tms = (int64_t)(t * (1E+9) + 0.5);
|
|
||||||
if (t < 0) {
|
|
||||||
tms = -1;
|
|
||||||
}
|
|
||||||
tms = setTimer(SUBFRAME_DEADTIME, tms, detPos);
|
|
||||||
if (tms < 0) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return ((1E-9) * (double)tms);
|
|
||||||
}
|
}
|
||||||
|
auto t_ns = setTimer(SUBFRAME_DEADTIME, secondsToNanoSeconds(t), detPos);
|
||||||
|
return (t_ns < 0) ? -1 : 1E-9 * t_ns;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t multiSlsDetector::setNumberOfFrames(int64_t t, int detPos) {
|
int64_t multiSlsDetector::setNumberOfFrames(int64_t t, int detPos) {
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include "string_utils.h"
|
#include "string_utils.h"
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
#include <cmath>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
@ -4496,10 +4497,9 @@ std::string slsDetectorCommand::cmdTimer(int narg, char *args[], int action, int
|
|||||||
if (index == ACQUISITION_TIME || index == SUBFRAME_ACQUISITION_TIME ||
|
if (index == ACQUISITION_TIME || index == SUBFRAME_ACQUISITION_TIME ||
|
||||||
index == FRAME_PERIOD || index == DELAY_AFTER_TRIGGER ||
|
index == FRAME_PERIOD || index == DELAY_AFTER_TRIGGER ||
|
||||||
index == SUBFRAME_DEADTIME || index == STORAGE_CELL_DELAY) {
|
index == SUBFRAME_DEADTIME || index == STORAGE_CELL_DELAY) {
|
||||||
// +0.5 for precision of eg.0.0000325
|
t = lround(val * 1E9);
|
||||||
t = (val * 1E9 + 0.5);
|
|
||||||
} else
|
} else
|
||||||
t = (int64_t)val;
|
t = static_cast<int64_t>(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
myDet->setOnline(ONLINE_FLAG, detPos);
|
myDet->setOnline(ONLINE_FLAG, detPos);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user