mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-20 02:40:03 +02:00
Factored out time conversion (#23)
* time conversion * with comment * lround in slsDetectorCommand
This commit is contained in:
parent
877bdb8979
commit
f1a1391866
@ -2146,14 +2146,14 @@ class multiSlsDetector : public virtual slsDetectorDefs {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* add gap pixels to the image (only for Eiger in 4 bit mode)
|
||||
* @param image pointer to image without gap pixels
|
||||
* @param gpImage poiner to image with gap pixels, if NULL, allocated
|
||||
* inside function
|
||||
* @returns number of data bytes of image with gap pixels
|
||||
*/
|
||||
int processImageWithGapPixels(char *image, char *&gpImage);
|
||||
/**
|
||||
* add gap pixels to the image (only for Eiger in 4 bit mode)
|
||||
* @param image pointer to image without gap pixels
|
||||
* @param gpImage poiner to image with gap pixels, if NULL, allocated
|
||||
* inside function
|
||||
* @returns number of data bytes of image with gap pixels
|
||||
*/
|
||||
int processImageWithGapPixels(char *image, char *&gpImage);
|
||||
|
||||
/**
|
||||
* Set total progress (total number of frames/images in an acquisition)
|
||||
@ -2209,6 +2209,14 @@ class multiSlsDetector : public virtual slsDetectorDefs {
|
||||
*/
|
||||
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 */
|
||||
const int multiId{0};
|
||||
|
@ -1099,89 +1099,50 @@ int64_t multiSlsDetector::setTimer(timerIndex index, int64_t t, int detPos) {
|
||||
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) {
|
||||
if (!inseconds) {
|
||||
return setTimer(ACQUISITION_TIME, (int64_t)t, detPos);
|
||||
}
|
||||
|
||||
// + 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(ACQUISITION_TIME, tms, detPos);
|
||||
if (tms < 0) {
|
||||
return -1;
|
||||
}
|
||||
return ((1E-9) * (double)tms);
|
||||
auto t_ns = setTimer(ACQUISITION_TIME, secondsToNanoSeconds(t), detPos);
|
||||
return (t_ns < 0) ? -1 : 1E-9 * t_ns;
|
||||
}
|
||||
|
||||
double multiSlsDetector::setExposurePeriod(double t, bool inseconds, int detPos) {
|
||||
if (!inseconds) {
|
||||
return setTimer(FRAME_PERIOD, (int64_t)t, detPos);
|
||||
}
|
||||
|
||||
// + 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(FRAME_PERIOD, tms, detPos);
|
||||
if (tms < 0) {
|
||||
return -1;
|
||||
}
|
||||
return ((1E-9) * (double)tms);
|
||||
auto t_ns = setTimer(FRAME_PERIOD, secondsToNanoSeconds(t), detPos);
|
||||
return (t_ns < 0) ? -1 : 1E-9 * t_ns;
|
||||
}
|
||||
|
||||
double multiSlsDetector::setDelayAfterTrigger(double t, bool inseconds, int detPos) {
|
||||
if (!inseconds) {
|
||||
return setTimer(DELAY_AFTER_TRIGGER, (int64_t)t, detPos);
|
||||
}
|
||||
|
||||
// + 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(DELAY_AFTER_TRIGGER, tms, detPos);
|
||||
if (tms < 0) {
|
||||
return -1;
|
||||
}
|
||||
return ((1E-9) * (double)tms);
|
||||
auto t_ns = setTimer(DELAY_AFTER_TRIGGER, secondsToNanoSeconds(t), detPos);
|
||||
return (t_ns < 0) ? -1 : 1E-9 * t_ns;
|
||||
}
|
||||
|
||||
double multiSlsDetector::setSubFrameExposureTime(double t, bool inseconds, int detPos) {
|
||||
if (!inseconds) {
|
||||
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) {
|
||||
if (!inseconds) {
|
||||
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) {
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include "string_utils.h"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cmath>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#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 ||
|
||||
index == FRAME_PERIOD || index == DELAY_AFTER_TRIGGER ||
|
||||
index == SUBFRAME_DEADTIME || index == STORAGE_CELL_DELAY) {
|
||||
// +0.5 for precision of eg.0.0000325
|
||||
t = (val * 1E9 + 0.5);
|
||||
t = lround(val * 1E9);
|
||||
} else
|
||||
t = (int64_t)val;
|
||||
t = static_cast<int64_t>(val);
|
||||
}
|
||||
|
||||
myDet->setOnline(ONLINE_FLAG, detPos);
|
||||
|
Loading…
x
Reference in New Issue
Block a user