Merge branch 'developer' into numudp

This commit is contained in:
maliakal_d 2022-03-25 10:50:51 +01:00
commit 9ff43efdc5
24 changed files with 299 additions and 304 deletions

View File

@ -47,10 +47,14 @@ This document describes the differences between v7.0.0 and v6.x.x
- stop servers also check for errors at startup( in case it was running with an older version) - stop servers also check for errors at startup( in case it was running with an older version)
- hostname cmd failed when connecting to servers in update mode (ctb, moench, jungfrau, eiger) - hostname cmd failed when connecting to servers in update mode (ctb, moench, jungfrau, eiger)
- missingpackets signed (negative => extra packets) - missingpackets signed (negative => extra packets)
- framescaught and frameindex now returns a vector for each port
- progress looks at activated or enabled ports, so progress does not stagnate
- (eiger) disable datastreaming also for virtual servers only for 10g
- missing packets also takes care of disabled ports
- added geometry to metadata - added geometry to metadata
- 10g eiger nextframenumber get fixed. - 10g eiger nextframenumber get fixed.
- stop, able to set nextframenumber to a consistent (max + 1) for all modules if different (eiger/ctb/jungfrau/moench) - stop, able to set nextframenumber to a consistent (max + 1) for all modules if different (eiger/ctb/jungfrau/moench)
- gotthard 25 um image reconstructed in gui and virtual hdf5 (firmware updated for slave to reverse channels)
2. Resolved Issues 2. Resolved Issues
================== ==================

View File

@ -599,7 +599,7 @@ class Detector(CppDetectorApi):
@property @property
@element @element
def rx_framescaught(self): def rx_framescaught(self):
"""Number of frames caught by receiver.""" """Number of frames caught by each port in receiver."""
return self.getFramesCaught() return self.getFramesCaught()
@property @property
@ -1918,7 +1918,7 @@ class Detector(CppDetectorApi):
@property @property
@element @element
def rx_frameindex(self): def rx_frameindex(self):
"""Current frame index received in receiver during acquisition.""" """Current frame index received for each port in receiver during acquisition."""
return self.getRxCurrentFrameIndex() return self.getRxCurrentFrameIndex()
@property @property

View File

@ -493,13 +493,17 @@ void init_det(py::module &m) {
Detector::getReceiverStatus, Detector::getReceiverStatus,
py::arg() = Positions{}) py::arg() = Positions{})
.def("getFramesCaught", .def("getFramesCaught",
(Result<int64_t>(Detector::*)(sls::Positions) const) & (Result<std::vector<int64_t>>(Detector::*)(sls::Positions) const) &
Detector::getFramesCaught, Detector::getFramesCaught,
py::arg() = Positions{}) py::arg() = Positions{})
.def("getNumMissingPackets", .def("getNumMissingPackets",
(Result<std::vector<int64_t>>(Detector::*)(sls::Positions) const) & (Result<std::vector<int64_t>>(Detector::*)(sls::Positions) const) &
Detector::getNumMissingPackets, Detector::getNumMissingPackets,
py::arg() = Positions{}) py::arg() = Positions{})
.def("getRxCurrentFrameIndex",
(Result<std::vector<int64_t>>(Detector::*)(sls::Positions) const) &
Detector::getRxCurrentFrameIndex,
py::arg() = Positions{})
.def("getNextFrameNumber", .def("getNextFrameNumber",
(Result<uint64_t>(Detector::*)(sls::Positions) const) & (Result<uint64_t>(Detector::*)(sls::Positions) const) &
Detector::getNextFrameNumber, Detector::getNextFrameNumber,
@ -1656,9 +1660,5 @@ void init_det(py::module &m) {
Detector::getMeasurementTime, Detector::getMeasurementTime,
py::arg() = Positions{}) py::arg() = Positions{})
.def("getUserDetails", .def("getUserDetails",
(std::string(Detector::*)() const) & Detector::getUserDetails) (std::string(Detector::*)() const) & Detector::getUserDetails);
.def("getRxCurrentFrameIndex",
(Result<uint64_t>(Detector::*)(sls::Positions) const) &
Detector::getRxCurrentFrameIndex,
py::arg() = Positions{});
} }

View File

@ -91,8 +91,10 @@ class qDrawPlot : public QWidget, private Ui::PlotObject {
void Update2dPlot(); void Update2dPlot();
void Update1dXYRange(); void Update1dXYRange();
void Update2dXYRange(); void Update2dXYRange();
void rearrangeGotthard25data(double *data);
static const int NUM_PEDESTAL_FRAMES = 20; static const int NUM_PEDESTAL_FRAMES = 20;
static const int NUM_GOTTHARD25_CHANS = 1280;
sls::Detector *det; sls::Detector *det;
slsDetectorDefs::detectorType detType; slsDetectorDefs::detectorType detType;
@ -164,4 +166,5 @@ class qDrawPlot : public QWidget, private Ui::PlotObject {
uint32_t pixelMask{0}; uint32_t pixelMask{0};
uint32_t gainMask{0}; uint32_t gainMask{0};
int gainOffset{0}; int gainOffset{0};
bool gotthard25;
}; };

View File

@ -80,6 +80,10 @@ void qDrawPlot::SetupWidgetWindow() {
fileSaveName = "Image"; fileSaveName = "Image";
} }
gotthard25 = ((detType == slsDetectorDefs::GOTTHARD2 ||
detType == slsDetectorDefs::GOTTHARD) &&
det->size() == 2);
SetupPlots(); SetupPlots();
SetDataCallBack(true); SetDataCallBack(true);
det->registerAcquisitionFinishedCallback(&(GetAcquisitionFinishedCallBack), det->registerAcquisitionFinishedCallback(&(GetAcquisitionFinishedCallBack),
@ -807,6 +811,11 @@ void qDrawPlot::GetData(detectorData *data, uint64_t frameIndex,
isGainDataExtracted = false; isGainDataExtracted = false;
} }
// gotthard25um rearranging
if (gotthard25) {
rearrangeGotthard25data(rawData);
}
// title and frame index titles // title and frame index titles
plotTitle = plotTitle =
plotTitlePrefix + QString(data->fileName.c_str()).section('/', -1); plotTitlePrefix + QString(data->fileName.c_str()).section('/', -1);
@ -1145,6 +1154,18 @@ void qDrawPlot::toDoublePixelData(double *dest, char *source, int size,
} }
} }
void qDrawPlot::rearrangeGotthard25data(double *data) {
const int nChans = NUM_GOTTHARD25_CHANS;
double temp[nChans * 2] = {0.0};
for (int i = 0; i != nChans; ++i) {
// master module
temp[i * 2] = data[i];
// slave module
temp[i * 2 + 1] = data[nChans + i];
}
memcpy(data, temp, nChans * 2 * sizeof(double));
}
void qDrawPlot::UpdatePlot() { void qDrawPlot::UpdatePlot() {
std::lock_guard<std::mutex> lock(mPlots); std::lock_guard<std::mutex> lock(mPlots);
LOG(logDEBUG) << "Update Plot"; LOG(logDEBUG) << "Update Plot";

View File

@ -2448,15 +2448,17 @@ void *start_timer(void *arg) {
} }
int skipData = 0; int skipData = 0;
int tgEnable = send_to_ten_gig;
if (!eiger_virtual_activate || if (!eiger_virtual_activate ||
(!eiger_virtual_left_datastream && !eiger_virtual_right_datastream)) { (tgEnable &&
(!eiger_virtual_left_datastream && !eiger_virtual_right_datastream))) {
skipData = 1; skipData = 1;
LOG(logWARNING, ("Not sending Left and Right datastream\n")); LOG(logWARNING, ("Not sending Left and Right datastream\n"));
} }
if (!eiger_virtual_left_datastream) { if (tgEnable && !eiger_virtual_left_datastream) {
LOG(logWARNING, ("Not sending Left datastream\n")); LOG(logWARNING, ("Not sending Left datastream\n"));
} }
if (!eiger_virtual_right_datastream) { if (tgEnable && !eiger_virtual_right_datastream) {
LOG(logWARNING, ("Not sending Right datastream\n")); LOG(logWARNING, ("Not sending Right datastream\n"));
} }
@ -2466,7 +2468,6 @@ void *start_timer(void *arg) {
int dr = eiger_dynamicrange; int dr = eiger_dynamicrange;
double bytesPerPixel = (double)dr / 8.00; double bytesPerPixel = (double)dr / 8.00;
int tgEnable = send_to_ten_gig;
int datasize = (tgEnable ? 4096 : 1024); int datasize = (tgEnable ? 4096 : 1024);
int packetsize = datasize + sizeof(sls_detector_header); int packetsize = datasize + sizeof(sls_detector_header);
int maxPacketsPerFrame = (tgEnable ? 4 : 16) * dr; int maxPacketsPerFrame = (tgEnable ? 4 : 16) * dr;
@ -2672,14 +2673,16 @@ void *start_timer(void *arg) {
} }
} }
} }
if (eiger_virtual_left_datastream && i >= startval && if ((!tgEnable ||
i <= endval) { (tgEnable && eiger_virtual_left_datastream)) &&
i >= startval && i <= endval) {
usleep(eiger_virtual_transmission_delay_left); usleep(eiger_virtual_transmission_delay_left);
sendUDPPacket(iRxEntry, 0, packetData, packetsize); sendUDPPacket(iRxEntry, 0, packetData, packetsize);
LOG(logDEBUG1, ("Sent left packet: %d\n", i)); LOG(logDEBUG1, ("Sent left packet: %d\n", i));
} }
if (eiger_virtual_right_datastream && i >= startval && if ((!tgEnable ||
i <= endval) { (tgEnable && eiger_virtual_right_datastream)) &&
i >= startval && i <= endval) {
usleep(eiger_virtual_transmission_delay_right); usleep(eiger_virtual_transmission_delay_right);
sendUDPPacket(iRxEntry, 1, packetData2, packetsize); sendUDPPacket(iRxEntry, 1, packetData2, packetsize);
LOG(logDEBUG1, ("Sent right packet: %d\n", i)); LOG(logDEBUG1, ("Sent right packet: %d\n", i));

View File

@ -592,12 +592,17 @@ class Detector {
/** Options: IDLE, TRANSMITTING, RUNNING */ /** Options: IDLE, TRANSMITTING, RUNNING */
Result<defs::runStatus> getReceiverStatus(Positions pos = {}) const; Result<defs::runStatus> getReceiverStatus(Positions pos = {}) const;
Result<int64_t> getFramesCaught(Positions pos = {}) const; /** Gets the number of frames caught for each port in receiver. */
Result<std::vector<int64_t>> getFramesCaught(Positions pos = {}) const;
/** Gets the number of missing packets for each port in receiver. Negative /** Gets the number of missing packets for each port in receiver. Negative
* number denotes extra packets. */ * number denotes extra packets. */
Result<std::vector<int64_t>> getNumMissingPackets(Positions pos = {}) const; Result<std::vector<int64_t>> getNumMissingPackets(Positions pos = {}) const;
/** Gets frame index for each port in receiver. */
Result<std::vector<int64_t>>
getRxCurrentFrameIndex(Positions pos = {}) const;
/** [Eiger][Jungfrau][Moench][CTB] */ /** [Eiger][Jungfrau][Moench][CTB] */
Result<uint64_t> getNextFrameNumber(Positions pos = {}) const; Result<uint64_t> getNextFrameNumber(Positions pos = {}) const;
@ -1911,7 +1916,6 @@ class Detector {
*/ */
std::string getUserDetails() const; std::string getUserDetails() const;
Result<uint64_t> getRxCurrentFrameIndex(Positions pos = {}) const;
///@} ///@}
private: private:

View File

@ -1274,40 +1274,6 @@ std::string CmdProxy::DetectorStatus(int action) {
return os.str(); return os.str();
} }
std::string CmdProxy::RxMissingPackets(int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "Number of missing packets for each port in receiver. If "
"negative, they are packets in excess. "
<< '\n';
} else if (action == defs::GET_ACTION) {
if (!args.empty()) {
WrongNumberOfParameters(0);
}
auto mp = det->getNumMissingPackets(std::vector<int>{det_id});
/*
auto tmp = det->getNumMissingPackets(std::vector<int>{det_id});
// convert to signed missing packets (to get excess)
Result<std::vector<int64_t>> mp(tmp.size());
for (unsigned int i = 0; i < mp.size(); ++i) {
mp[i] = static_cast<int64_t>(tmp[i]);
}
OR
Result<std::vector<int64_t>> tmp;
for (auto val : tmp) {
mp.push_back(static_cast<int64_t>(val));
}
*/
os << OutString(mp) << '\n';
} else if (action == defs::PUT_ACTION) {
throw sls::RuntimeError("Cannot put");
} else {
throw sls::RuntimeError("Unknown action");
}
return os.str();
}
std::string CmdProxy::Scan(int action) { std::string CmdProxy::Scan(int action) {
std::ostringstream os; std::ostringstream os;
os << cmd << ' '; os << cmd << ' ';

View File

@ -860,7 +860,8 @@ class CmdProxy {
{"rx_status", &CmdProxy::ReceiverStatus}, {"rx_status", &CmdProxy::ReceiverStatus},
{"status", &CmdProxy::DetectorStatus}, {"status", &CmdProxy::DetectorStatus},
{"rx_framescaught", &CmdProxy::rx_framescaught}, {"rx_framescaught", &CmdProxy::rx_framescaught},
{"rx_missingpackets", &CmdProxy::RxMissingPackets}, {"rx_missingpackets", &CmdProxy::rx_missingpackets},
{"rx_frameindex", &CmdProxy::rx_frameindex},
{"nextframenumber", &CmdProxy::nextframenumber}, {"nextframenumber", &CmdProxy::nextframenumber},
{"trigger", &CmdProxy::Trigger}, {"trigger", &CmdProxy::Trigger},
{"scan", &CmdProxy::Scan}, {"scan", &CmdProxy::Scan},
@ -1086,8 +1087,7 @@ class CmdProxy {
{"framecounter", &CmdProxy::framecounter}, {"framecounter", &CmdProxy::framecounter},
{"runtime", &CmdProxy::runtime}, {"runtime", &CmdProxy::runtime},
{"frametime", &CmdProxy::frametime}, {"frametime", &CmdProxy::frametime},
{"user", &CmdProxy::UserDetails}, {"user", &CmdProxy::UserDetails}
{"rx_frameindex", &CmdProxy::rx_frameindex}
}; };
@ -1540,11 +1540,15 @@ class CmdProxy {
"to IDLE or STOPPED. Goes to stop server."); "to IDLE or STOPPED. Goes to stop server.");
GET_COMMAND(rx_framescaught, getFramesCaught, GET_COMMAND(rx_framescaught, getFramesCaught,
"\n\tNumber of frames caught by receiver."); "\n\tNumber of frames caught by each port in receiver.");
GET_COMMAND(rx_missingpackets, getNumMissingPackets, GET_COMMAND(rx_missingpackets, getNumMissingPackets,
"\n\tNumber of missing packets for each port in receiver. " "\n\tNumber of missing packets for each port in receiver. If "
"Negative number denotes extra packets."); "negative, they are packets in excess. ");
GET_COMMAND(rx_frameindex, getRxCurrentFrameIndex,
"\n\tCurrent frame index received for each port in receiver "
"during acquisition.");
INTEGER_COMMAND_VEC_ID( INTEGER_COMMAND_VEC_ID(
nextframenumber, getNextFrameNumber, setNextFrameNumber, nextframenumber, getNextFrameNumber, setNextFrameNumber,
@ -2262,10 +2266,6 @@ class CmdProxy {
"ns|us|ms|s]\n\t[Jungfrau][Mythen3][Gotthard2][Moench][" "ns|us|ms|s]\n\t[Jungfrau][Mythen3][Gotthard2][Moench]["
"CTB] Timestamp at a frame start." "CTB] Timestamp at a frame start."
"\n\t[Gotthard2] not in burst and auto mode."); "\n\t[Gotthard2] not in burst and auto mode.");
GET_COMMAND(
rx_frameindex, getRxCurrentFrameIndex,
"\n\tCurrent frame index received in receiver during acquisition.");
}; };
} // namespace sls } // namespace sls

View File

@ -829,7 +829,7 @@ Result<defs::runStatus> Detector::getReceiverStatus(Positions pos) const {
return pimpl->Parallel(&Module::getReceiverStatus, pos); return pimpl->Parallel(&Module::getReceiverStatus, pos);
} }
Result<int64_t> Detector::getFramesCaught(Positions pos) const { Result<std::vector<int64_t>> Detector::getFramesCaught(Positions pos) const {
return pimpl->Parallel(&Module::getFramesCaughtByReceiver, pos); return pimpl->Parallel(&Module::getFramesCaughtByReceiver, pos);
} }
@ -838,6 +838,11 @@ Detector::getNumMissingPackets(Positions pos) const {
return pimpl->Parallel(&Module::getNumMissingPackets, pos); return pimpl->Parallel(&Module::getNumMissingPackets, pos);
} }
Result<std::vector<int64_t>>
Detector::getRxCurrentFrameIndex(Positions pos) const {
return pimpl->Parallel(&Module::getReceiverCurrentFrameIndex, pos);
}
Result<uint64_t> Detector::getNextFrameNumber(Positions pos) const { Result<uint64_t> Detector::getNextFrameNumber(Positions pos) const {
return pimpl->Parallel(&Module::getNextFrameNumber, pos); return pimpl->Parallel(&Module::getNextFrameNumber, pos);
} }
@ -2350,10 +2355,6 @@ Result<ns> Detector::getMeasurementTime(Positions pos) const {
std::string Detector::getUserDetails() const { return pimpl->getUserDetails(); } std::string Detector::getUserDetails() const { return pimpl->getUserDetails(); }
Result<uint64_t> Detector::getRxCurrentFrameIndex(Positions pos) const {
return pimpl->Parallel(&Module::getReceiverCurrentFrameIndex, pos);
}
std::vector<int> Detector::getPortNumbers(int start_port) { std::vector<int> Detector::getPortNumbers(int start_port) {
int num_sockets_per_detector = getNumberofUDPInterfaces({}).tsquash( int num_sockets_per_detector = getNumberofUDPInterfaces({}).tsquash(
"Number of UDP Interfaces is not consistent among modules"); "Number of UDP Interfaces is not consistent among modules");

View File

@ -272,6 +272,13 @@ void DetectorImpl::addModule(const std::string &hostname) {
// get type by connecting // get type by connecting
detectorType type = Module::getTypeFromDetector(host, port); detectorType type = Module::getTypeFromDetector(host, port);
// gotthard cannot have more than 2 modules (50um=1, 25um=2
if ((type == GOTTHARD || type == GOTTHARD2) && modules.size() > 2) {
freeSharedMemory();
throw sls::RuntimeError("Gotthard cannot have more than 2 modules");
}
auto pos = modules.size(); auto pos = modules.size();
modules.emplace_back( modules.emplace_back(
sls::make_unique<Module>(type, detectorIndex, pos, false)); sls::make_unique<Module>(type, detectorIndex, pos, false));
@ -1142,7 +1149,7 @@ int DetectorImpl::acquire() {
if (acquisition_finished != nullptr) { if (acquisition_finished != nullptr) {
int status = Parallel(&Module::getRunStatus, {}).squash(ERROR); int status = Parallel(&Module::getRunStatus, {}).squash(ERROR);
auto a = Parallel(&Module::getReceiverProgress, {}); auto a = Parallel(&Module::getReceiverProgress, {});
double progress = (*std::min_element(a.begin(), a.end())); double progress = (*std::max_element(a.begin(), a.end()));
acquisition_finished(progress, status, acqFinished_p); acquisition_finished(progress, status, acqFinished_p);
} }

View File

@ -873,8 +873,26 @@ double Module::getReceiverProgress() const {
return sendToReceiver<double>(F_GET_RECEIVER_PROGRESS); return sendToReceiver<double>(F_GET_RECEIVER_PROGRESS);
} }
int64_t Module::getFramesCaughtByReceiver() const { std::vector<int64_t> Module::getFramesCaughtByReceiver() const {
return sendToReceiver<int64_t>(F_GET_RECEIVER_FRAMES_CAUGHT); // TODO!(Erik) Refactor
LOG(logDEBUG1) << "Getting frames caught";
if (shm()->useReceiverFlag) {
auto client = ReceiverSocket(shm()->rxHostname, shm()->rxTCPPort);
client.Send(F_GET_RECEIVER_FRAMES_CAUGHT);
if (client.Receive<int>() == FAIL) {
throw ReceiverError(
"Receiver " + std::to_string(moduleIndex) +
" returned error: " + client.readErrorMessage());
} else {
auto nports = client.Receive<int>();
std::vector<int64_t> retval(nports);
client.Receive(retval);
LOG(logDEBUG1) << "Frames caught of Receiver" << moduleIndex << ": "
<< sls::ToString(retval);
return retval;
}
}
throw RuntimeError("No receiver to get frames caught.");
} }
std::vector<int64_t> Module::getNumMissingPackets() const { std::vector<int64_t> Module::getNumMissingPackets() const {
@ -899,6 +917,28 @@ std::vector<int64_t> Module::getNumMissingPackets() const {
throw RuntimeError("No receiver to get missing packets."); throw RuntimeError("No receiver to get missing packets.");
} }
std::vector<int64_t> Module::getReceiverCurrentFrameIndex() const {
// TODO!(Erik) Refactor
LOG(logDEBUG1) << "Getting frame index";
if (shm()->useReceiverFlag) {
auto client = ReceiverSocket(shm()->rxHostname, shm()->rxTCPPort);
client.Send(F_GET_RECEIVER_FRAME_INDEX);
if (client.Receive<int>() == FAIL) {
throw ReceiverError(
"Receiver " + std::to_string(moduleIndex) +
" returned error: " + client.readErrorMessage());
} else {
auto nports = client.Receive<int>();
std::vector<int64_t> retval(nports);
client.Receive(retval);
LOG(logDEBUG1) << "Frame index of Receiver" << moduleIndex << ": "
<< sls::ToString(retval);
return retval;
}
}
throw RuntimeError("No receiver to get frame index.");
}
uint64_t Module::getNextFrameNumber() const { uint64_t Module::getNextFrameNumber() const {
return sendToDetector<uint64_t>(F_GET_NEXT_FRAME_NUMBER); return sendToDetector<uint64_t>(F_GET_NEXT_FRAME_NUMBER);
} }
@ -2755,10 +2795,6 @@ int64_t Module::getMeasurementTime() const {
return sendToDetectorStop<int64_t>(F_GET_MEASUREMENT_TIME); return sendToDetectorStop<int64_t>(F_GET_MEASUREMENT_TIME);
} }
uint64_t Module::getReceiverCurrentFrameIndex() const {
return sendToReceiver<uint64_t>(F_GET_RECEIVER_FRAME_INDEX);
}
// private // private
void Module::checkArgs(const void *args, size_t args_size, void *retval, void Module::checkArgs(const void *args, size_t args_size, void *retval,

View File

@ -203,8 +203,9 @@ class Module : public virtual slsDetectorDefs {
runStatus getRunStatus() const; runStatus getRunStatus() const;
runStatus getReceiverStatus() const; runStatus getReceiverStatus() const;
double getReceiverProgress() const; double getReceiverProgress() const;
int64_t getFramesCaughtByReceiver() const; std::vector<int64_t> getFramesCaughtByReceiver() const;
std::vector<int64_t> getNumMissingPackets() const; std::vector<int64_t> getNumMissingPackets() const;
std::vector<int64_t> getReceiverCurrentFrameIndex() const;
uint64_t getNextFrameNumber() const; uint64_t getNextFrameNumber() const;
void setNextFrameNumber(uint64_t value); void setNextFrameNumber(uint64_t value);
void sendSoftwareTrigger(const bool block); void sendSoftwareTrigger(const bool block);
@ -581,7 +582,6 @@ class Module : public virtual slsDetectorDefs {
int64_t getNumberOfFramesFromStart() const; int64_t getNumberOfFramesFromStart() const;
int64_t getActualTime() const; int64_t getActualTime() const;
int64_t getMeasurementTime() const; int64_t getMeasurementTime() const;
uint64_t getReceiverCurrentFrameIndex() const;
private: private:
void checkArgs(const void *args, size_t args_size, void *retval, void checkArgs(const void *args, size_t args_size, void *retval,

View File

@ -93,13 +93,19 @@ TEST_CASE("rx_framescaught", "[.cmd][.rx]") {
CmdProxy proxy(&det); CmdProxy proxy(&det);
// This ensures 0 caught frames // This ensures 0 caught frames
auto prev_val = det.getFileWrite();
det.setFileWrite(false); // avoid writing or error on file creation det.setFileWrite(false); // avoid writing or error on file creation
det.startReceiver(); det.startReceiver();
det.stopReceiver(); det.stopReceiver();
{ {
std::ostringstream oss; std::ostringstream oss;
proxy.Call("rx_framescaught", {}, -1, GET, oss); proxy.Call("rx_framescaught", {}, -1, GET, oss);
REQUIRE(oss.str() == "rx_framescaught 0\n"); if (det.getNumberofUDPInterfaces().tsquash(
"inconsistent number of interfaces") == 1) {
REQUIRE(oss.str() == "rx_framescaught [0]\n");
} else {
REQUIRE(oss.str() == "rx_framescaught [0, 0]\n");
}
} }
// Currently disabled may activate if we have a stable env // Currently disabled may activate if we have a stable env
@ -111,10 +117,15 @@ TEST_CASE("rx_framescaught", "[.cmd][.rx]") {
// proxy.Call("rx_framescaught", {}, -1, GET, oss); // proxy.Call("rx_framescaught", {}, -1, GET, oss);
// REQUIRE(oss.str() == "rx_framescaught 1\n"); // REQUIRE(oss.str() == "rx_framescaught 1\n");
// } // }
for (int i = 0; i != det.size(); ++i) {
det.setFileWrite(prev_val[i], {i});
}
} }
TEST_CASE("rx_missingpackets", "[.cmd][.rx]") { TEST_CASE("rx_missingpackets", "[.cmd][.rx]") {
Detector det; Detector det;
auto prev_val = det.getFileWrite();
det.setFileWrite(false); // avoid writing or error on file creation det.setFileWrite(false); // avoid writing or error on file creation
CmdProxy proxy(&det); CmdProxy proxy(&det);
{ {
@ -123,8 +134,12 @@ TEST_CASE("rx_missingpackets", "[.cmd][.rx]") {
det.stopReceiver(); det.stopReceiver();
std::ostringstream oss; std::ostringstream oss;
proxy.Call("rx_missingpackets", {}, -1, GET, oss); proxy.Call("rx_missingpackets", {}, -1, GET, oss);
std::string s = (oss.str()).erase(0, strlen("rx_missingpackets [")); if (det.getNumberofUDPInterfaces().tsquash(
REQUIRE(std::stoi(s) > 0); "inconsistent number of interfaces") == 1) {
REQUIRE(oss.str() != "rx_missingpackets [0]\n");
} else {
REQUIRE(oss.str() != "rx_missingpackets [0, 0]\n");
}
} }
{ {
// 0 missing packets (takes into account that acquisition is stopped) // 0 missing packets (takes into account that acquisition is stopped)
@ -133,9 +148,25 @@ TEST_CASE("rx_missingpackets", "[.cmd][.rx]") {
det.stopReceiver(); det.stopReceiver();
std::ostringstream oss; std::ostringstream oss;
proxy.Call("rx_missingpackets", {}, -1, GET, oss); proxy.Call("rx_missingpackets", {}, -1, GET, oss);
std::string s = (oss.str()).erase(0, strlen("rx_missingpackets [")); if (det.getNumberofUDPInterfaces().tsquash(
REQUIRE(std::stoi(s) == 0); "inconsistent number of interfaces") == 1) {
REQUIRE(oss.str() == "rx_missingpackets [0]\n");
} else {
REQUIRE(oss.str() == "rx_missingpackets [0, 0]\n");
} }
}
for (int i = 0; i != det.size(); ++i) {
det.setFileWrite(prev_val[i], {i});
}
}
TEST_CASE("rx_frameindex", "[.cmd][.rx]") {
Detector det;
CmdProxy proxy(&det);
proxy.Call("rx_frameindex", {}, -1, GET);
// This is a get only command
REQUIRE_THROWS(proxy.Call("rx_frameindex", {"2"}, -1, PUT));
} }
/* Network Configuration (Detector<->Receiver) */ /* Network Configuration (Detector<->Receiver) */
@ -884,16 +915,3 @@ TEST_CASE("rx_jsonpara", "[.cmd][.rx]") {
} }
/* Insignificant */ /* Insignificant */
TEST_CASE("rx_frameindex", "[.cmd][.rx]") {
Detector det;
CmdProxy proxy(&det);
proxy.Call("rx_frameindex", {}, -1, GET);
// This is a get only command
REQUIRE_THROWS(proxy.Call("rx_frameindex", {"2"}, -1, PUT));
std::ostringstream oss;
proxy.Call("rx_frameindex", {}, 0, GET, oss);
std::string s = (oss.str()).erase(0, strlen("rx_frameindex "));
REQUIRE(std::stoi(s) >= 0);
}

View File

@ -848,9 +848,13 @@ int ClientInterface::get_file_index(Interface &socket) {
} }
int ClientInterface::get_frame_index(Interface &socket) { int ClientInterface::get_frame_index(Interface &socket) {
uint64_t retval = impl()->getCurrentFrameIndex(); auto retval = impl()->getCurrentFrameIndex();
LOG(logDEBUG1) << "frame index:" << retval; LOG(logDEBUG1) << "frames index:" << sls::ToString(retval);
return socket.sendResult(retval); auto size = static_cast<int>(retval.size());
socket.Send(OK);
socket.Send(size);
socket.Send(retval);
return OK;
} }
int ClientInterface::get_missing_packets(Interface &socket) { int ClientInterface::get_missing_packets(Interface &socket) {
@ -864,9 +868,13 @@ int ClientInterface::get_missing_packets(Interface &socket) {
} }
int ClientInterface::get_frames_caught(Interface &socket) { int ClientInterface::get_frames_caught(Interface &socket) {
int64_t retval = impl()->getFramesCaught(); auto retval = impl()->getFramesCaught();
LOG(logDEBUG1) << "frames caught:" << retval; LOG(logDEBUG1) << "frames caught:" << sls::ToString(retval);
return socket.sendResult(retval); auto size = static_cast<int>(retval.size());
socket.Send(OK);
socket.Send(size);
socket.Send(retval);
return OK;
} }
int ClientInterface::set_file_write(Interface &socket) { int ClientInterface::set_file_write(Interface &socket) {

View File

@ -52,19 +52,7 @@ DataProcessor::~DataProcessor() { DeleteFiles(); }
/** getters */ /** getters */
bool DataProcessor::GetStartedFlag() { return startedFlag_; } bool DataProcessor::GetStartedFlag() const { return startedFlag_; }
uint64_t DataProcessor::GetNumFramesCaught() { return numFramesCaught_; }
uint64_t DataProcessor::GetNumCompleteFramesCaught() {
return numCompleteFramesCaught_;
}
uint64_t DataProcessor::GetCurrentFrameIndex() { return currentFrameIndex_; }
uint64_t DataProcessor::GetProcessedIndex() {
return currentFrameIndex_ - firstIndex_;
}
void DataProcessor::SetFifo(Fifo *fifo) { fifo_ = fifo; } void DataProcessor::SetFifo(Fifo *fifo) { fifo_ = fifo; }
@ -72,7 +60,6 @@ void DataProcessor::ResetParametersforNewAcquisition() {
StopRunning(); StopRunning();
startedFlag_ = false; startedFlag_ = false;
numFramesCaught_ = 0; numFramesCaught_ = 0;
numCompleteFramesCaught_ = 0;
firstIndex_ = 0; firstIndex_ = 0;
currentFrameIndex_ = 0; currentFrameIndex_ = 0;
firstStreamerFrame_ = true; firstStreamerFrame_ = true;
@ -213,12 +200,14 @@ void DataProcessor::CreateVirtualFile(
if (virtualFile_) { if (virtualFile_) {
delete virtualFile_; delete virtualFile_;
} }
virtualFile_ = new HDF5VirtualFile(hdf5Lib); bool gotthard25um =
((detectorType_ == GOTTHARD || detectorType_ == GOTTHARD2) &&
(numModX * numModY) == 2);
virtualFile_ = new HDF5VirtualFile(hdf5Lib, gotthard25um);
uint64_t numImagesProcessed = GetProcessedIndex() + 1;
// maxframesperfile = 0 for infinite files // maxframesperfile = 0 for infinite files
uint32_t framesPerFile = uint32_t framesPerFile =
((maxFramesPerFile == 0) ? numImagesProcessed + 1 : maxFramesPerFile); ((maxFramesPerFile == 0) ? numFramesCaught_ : maxFramesPerFile);
// TODO: assumption 1: create virtual file even if no data in other // TODO: assumption 1: create virtual file even if no data in other
// files (they exist anyway) assumption2: virtual file max frame index // files (they exist anyway) assumption2: virtual file max frame index
@ -228,7 +217,7 @@ void DataProcessor::CreateVirtualFile(
filePath, fileNamePrefix, fileIndex, overWriteEnable, silentMode, filePath, fileNamePrefix, fileIndex, overWriteEnable, silentMode,
modulePos, numUnitsPerReadout, framesPerFile, numImages, modulePos, numUnitsPerReadout, framesPerFile, numImages,
generalData_->nPixelsX, generalData_->nPixelsY, dynamicRange, generalData_->nPixelsX, generalData_->nPixelsY, dynamicRange,
numImagesProcessed, numModX, numModY, dataFile_->GetPDataType(), numFramesCaught_, numModX, numModY, dataFile_->GetPDataType(),
dataFile_->GetParameterNames(), dataFile_->GetParameterDataTypes()); dataFile_->GetParameterNames(), dataFile_->GetParameterDataTypes());
} }
@ -344,9 +333,6 @@ uint64_t DataProcessor::ProcessAnImage(char *buf) {
currentFrameIndex_ = fnum; currentFrameIndex_ = fnum;
numFramesCaught_++; numFramesCaught_++;
uint32_t nump = header.packetNumber; uint32_t nump = header.packetNumber;
if (nump == generalData_->packetsPerFrame) {
numCompleteFramesCaught_++;
}
LOG(logDEBUG1) << "DataProcessing " << index << ": fnum:" << fnum; LOG(logDEBUG1) << "DataProcessing " << index << ": fnum:" << fnum;

View File

@ -36,13 +36,7 @@ class DataProcessor : private virtual slsDetectorDefs, public ThreadObject {
~DataProcessor() override; ~DataProcessor() override;
bool GetStartedFlag(); bool GetStartedFlag() const;
uint64_t GetNumFramesCaught();
uint64_t GetNumCompleteFramesCaught();
/** (-1 if no frames have been caught */
uint64_t GetCurrentFrameIndex();
/** (-1 if no frames have been caught) */
uint64_t GetProcessedIndex();
void SetFifo(Fifo *f); void SetFifo(Fifo *f);
void ResetParametersforNewAcquisition(); void ResetParametersforNewAcquisition();
@ -178,9 +172,6 @@ class DataProcessor : private virtual slsDetectorDefs, public ThreadObject {
/** Number of frames caught */ /** Number of frames caught */
uint64_t numFramesCaught_{0}; uint64_t numFramesCaught_{0};
/** Number of complete frames caught */
uint64_t numCompleteFramesCaught_{0};
/** Frame Number of latest processed frame number */ /** Frame Number of latest processed frame number */
std::atomic<uint64_t> currentFrameIndex_{0}; std::atomic<uint64_t> currentFrameIndex_{0};

View File

@ -5,8 +5,8 @@
#include <iomanip> #include <iomanip>
HDF5VirtualFile::HDF5VirtualFile(std::mutex *hdf5Lib) HDF5VirtualFile::HDF5VirtualFile(std::mutex *hdf5Lib, bool g25)
: File(HDF5), hdf5Lib_(hdf5Lib) {} : File(HDF5), hdf5Lib_(hdf5Lib), gotthard25um(g25) {}
HDF5VirtualFile::~HDF5VirtualFile() { CloseFile(); } HDF5VirtualFile::~HDF5VirtualFile() { CloseFile(); }
@ -73,12 +73,10 @@ void HDF5VirtualFile::CreateVirtualFile(
"version", PredType::NATIVE_DOUBLE, dataspace_attr); "version", PredType::NATIVE_DOUBLE, dataspace_attr);
attribute.write(PredType::NATIVE_DOUBLE, &dValue); attribute.write(PredType::NATIVE_DOUBLE, &dValue);
// virtual data dataspace // virtual dataspace
hsize_t vdsDims[3] = {numImagesCaught, numModY * nDimy, hsize_t vdsDims[3] = {numImagesCaught, numModY * nDimy,
numModZ * nDimz}; numModZ * nDimz};
DataSpace vdsDataSpace(3, vdsDims, nullptr); DataSpace vdsDataSpace(3, vdsDims, nullptr);
// virtual parameter dataspace
hsize_t vdsDimsPara[2] = {numImagesCaught, hsize_t vdsDimsPara[2] = {numImagesCaught,
(unsigned int)numModY * numModZ}; (unsigned int)numModY * numModZ};
DataSpace vdsDataSpacePara(2, vdsDimsPara, nullptr); DataSpace vdsDataSpacePara(2, vdsDimsPara, nullptr);
@ -91,37 +89,54 @@ void HDF5VirtualFile::CreateVirtualFile(
// property list for parameters (datatype) // property list for parameters (datatype)
std::vector<DSetCreatPropList> plistPara(paraSize); std::vector<DSetCreatPropList> plistPara(paraSize);
// hyperslab // hyperslab (files)
int numMajorHyperslab = numImagesCaught / maxFramesPerFile; int numFiles = numImagesCaught / maxFramesPerFile;
if (numImagesCaught % maxFramesPerFile) if (numImagesCaught % maxFramesPerFile)
++numMajorHyperslab; ++numFiles;
uint64_t framesSaved = 0; uint64_t framesSaved = 0;
// loop through files for (int iFile = 0; iFile < numFiles; ++iFile) {
for (int hyperSlab = 0; hyperSlab < numMajorHyperslab; ++hyperSlab) {
uint64_t nDimx = uint64_t nDimx =
((numImagesCaught - framesSaved) > maxFramesPerFile) ((numImagesCaught - framesSaved) > maxFramesPerFile)
? maxFramesPerFile ? maxFramesPerFile
: (numImagesCaught - framesSaved); : (numImagesCaught - framesSaved);
hsize_t start[3] = {framesSaved, 0, 0};
hsize_t count[3] = {nDimx, nDimy, nDimz};
hsize_t startPara[2] = {framesSaved, 0};
hsize_t countPara[2] = {nDimx, 1};
// loop through readouts
for (unsigned int i = 0; i < numModY * numModZ; ++i) {
// setect data hyperslabs hsize_t startLocation[3] = {framesSaved, 0, 0};
vdsDataSpace.selectHyperslab(H5S_SELECT_SET, count, start); hsize_t strideBetweenBlocks[3] = {1, 1, 1};
hsize_t numBlocks[3] = {nDimx, nDimy, nDimz};
hsize_t blockSize[3] = {1, 1, 1};
// select parameter hyperslabs hsize_t startLocationPara[2] = {framesSaved, 0};
vdsDataSpacePara.selectHyperslab(H5S_SELECT_SET, countPara, hsize_t strideBetweenBlocksPara[3] = {1, 1};
startPara); hsize_t numBlocksPara[2] = {1, 1};
hsize_t blockSizePara[3] = {nDimx, 1};
// interleaving for g2
if (gotthard25um) {
strideBetweenBlocks[2] = 2;
}
for (unsigned int iReadout = 0; iReadout < numModY * numModZ;
++iReadout) {
// interleaving for g2 (startLocation is 0 and 1)
if (gotthard25um) {
startLocation[2] = iReadout;
}
vdsDataSpace.selectHyperslab(H5S_SELECT_SET, numBlocks,
startLocation, strideBetweenBlocks,
blockSize);
vdsDataSpacePara.selectHyperslab(
H5S_SELECT_SET, numBlocksPara, startLocationPara,
strideBetweenBlocksPara, blockSizePara);
// source file name // source file name
std::ostringstream os; std::ostringstream os;
os << filePath << "/" << fileNamePrefix << "_d" os << filePath << "/" << fileNamePrefix << "_d"
<< (modulePos * numUnitsPerReadout + i) << "_f" << hyperSlab << (modulePos * numUnitsPerReadout + iReadout) << "_f"
<< '_' << fileIndex << ".h5"; << iFile << '_' << fileIndex << ".h5";
std::string srcFileName = os.str(); std::string srcFileName = os.str();
LOG(logDEBUG1) << srcFileName; LOG(logDEBUG1) << srcFileName;
@ -138,25 +153,20 @@ void HDF5VirtualFile::CreateVirtualFile(
std::ostringstream osfn; std::ostringstream osfn;
osfn << "/data"; osfn << "/data";
if (numImages > 1) if (numImages > 1)
osfn << "_f" << std::setfill('0') << std::setw(12) osfn << "_f" << std::setfill('0') << std::setw(12) << iFile;
<< hyperSlab;
std::string srcDatasetName = osfn.str(); std::string srcDatasetName = osfn.str();
// source data dataspace // source dataspace
hsize_t srcDims[3] = {nDimx, nDimy, nDimz}; hsize_t srcDims[3] = {nDimx, nDimy, nDimz};
hsize_t srcDimsMax[3] = {H5S_UNLIMITED, nDimy, nDimz}; hsize_t srcDimsMax[3] = {H5S_UNLIMITED, nDimy, nDimz};
DataSpace srcDataSpace(3, srcDims, srcDimsMax); DataSpace srcDataSpace(3, srcDims, srcDimsMax);
// source parameter dataspace
hsize_t srcDimsPara[1] = {nDimx}; hsize_t srcDimsPara[1] = {nDimx};
hsize_t srcDimsMaxPara[1] = {H5S_UNLIMITED}; hsize_t srcDimsMaxPara[1] = {H5S_UNLIMITED};
DataSpace srcDataSpacePara(1, srcDimsPara, srcDimsMaxPara); DataSpace srcDataSpacePara(1, srcDimsPara, srcDimsMaxPara);
// mapping of data property list // mapping of property list
plist.setVirtual(vdsDataSpace, relative_srcFileName.c_str(), plist.setVirtual(vdsDataSpace, relative_srcFileName.c_str(),
srcDatasetName.c_str(), srcDataSpace); srcDatasetName.c_str(), srcDataSpace);
// mapping of parameter property list
for (unsigned int p = 0; p < paraSize; ++p) { for (unsigned int p = 0; p < paraSize; ++p) {
plistPara[p].setVirtual( plistPara[p].setVirtual(
vdsDataSpacePara, relative_srcFileName.c_str(), vdsDataSpacePara, relative_srcFileName.c_str(),
@ -165,21 +175,23 @@ void HDF5VirtualFile::CreateVirtualFile(
// H5Sclose(srcDataspace); // H5Sclose(srcDataspace);
// H5Sclose(srcDataspace_para); // H5Sclose(srcDataspace_para);
start[2] += nDimz;
if (start[2] >= (numModZ * nDimz)) { if (!gotthard25um) {
start[2] = 0; startLocation[2] += nDimz;
start[1] += nDimy; if (startLocation[2] >= (numModZ * nDimz)) {
startLocation[2] = 0;
startLocation[1] += nDimy;
} }
startPara[1]++; }
startLocationPara[1]++;
} }
framesSaved += nDimx; framesSaved += nDimx;
} }
// data dataset // datasets
dataSetName_ = "data"; dataSetName_ = "data";
DataSet vdsDataSet(fd_->createDataSet(dataSetName_.c_str(), dataType, DataSet vdsDataSet(fd_->createDataSet(dataSetName_.c_str(), dataType,
vdsDataSpace, plist)); vdsDataSpace, plist));
// parameter dataset
for (unsigned int p = 0; p < paraSize; ++p) { for (unsigned int p = 0; p < paraSize; ++p) {
DataSet vdsDataSetPara(fd_->createDataSet( DataSet vdsDataSetPara(fd_->createDataSet(
parameterNames[p].c_str(), parameterDataTypes[p], parameterNames[p].c_str(), parameterDataTypes[p],

View File

@ -9,7 +9,7 @@
class HDF5VirtualFile : private virtual slsDetectorDefs, public File { class HDF5VirtualFile : private virtual slsDetectorDefs, public File {
public: public:
HDF5VirtualFile(std::mutex *hdf5Lib); HDF5VirtualFile(std::mutex *hdf5Lib, bool g25);
~HDF5VirtualFile(); ~HDF5VirtualFile();
std::array<std::string, 2> GetFileAndDatasetName() const override; std::array<std::string, 2> GetFileAndDatasetName() const override;
@ -30,4 +30,5 @@ class HDF5VirtualFile : private virtual slsDetectorDefs, public File {
H5File *fd_{nullptr}; H5File *fd_{nullptr};
std::string fileName_; std::string fileName_;
std::string dataSetName_; std::string dataSetName_;
bool gotthard25um;
}; };

View File

@ -453,51 +453,51 @@ void Implementation::setFramesPerFile(const uint32_t i) {
* ************************************************/ * ************************************************/
slsDetectorDefs::runStatus Implementation::getStatus() const { return status; } slsDetectorDefs::runStatus Implementation::getStatus() const { return status; }
uint64_t Implementation::getFramesCaught() const { std::vector<int64_t> Implementation::getFramesCaught() const {
uint64_t min = -1; std::vector<int64_t> numFramesCaught(numUDPInterfaces);
uint32_t flagsum = 0; int index = 0;
for (const auto &it : listener) {
for (const auto &it : dataProcessor) { if (it->GetStartedFlag()) {
flagsum += it->GetStartedFlag(); numFramesCaught[index] = it->GetNumCompleteFramesCaught();
min = std::min(min, it->GetNumCompleteFramesCaught());
} }
// no data processed ++index;
if (flagsum != dataProcessor.size()) }
return 0; return numFramesCaught;
return min;
} }
uint64_t Implementation::getCurrentFrameIndex() const { std::vector<int64_t> Implementation::getCurrentFrameIndex() const {
uint64_t max = 0; std::vector<int64_t> frameIndex(numUDPInterfaces);
uint32_t flagsum = 0; int index = 0;
for (const auto &it : listener) { for (const auto &it : listener) {
flagsum += it->GetStartedFlag(); if (it->GetStartedFlag()) {
max = std::max(max, it->GetCurrentFrameIndex()); frameIndex[index] = it->GetCurrentFrameIndex();
} }
// no data processed ++index;
if (flagsum != listener.size()) }
return 0; return frameIndex;
return max;
} }
double Implementation::getProgress() const { double Implementation::getProgress() const {
// get minimum of processed frame indices if (!activated || (!detectorDataStream[0] && !detectorDataStream[1])) {
uint64_t currentFrameIndex = 0; return 100.00;
uint32_t flagsum = 0; }
// if disabled, considering only 1 port
double totalFrames = (double)(numberOfTotalFrames * listener.size());
if (!detectorDataStream[0] || !detectorDataStream[1]) {
totalFrames /= 2;
}
double progress = 0;
int index = 0;
for (const auto &it : listener) { for (const auto &it : listener) {
flagsum += it->GetStartedFlag(); if (detectorDataStream[index] && it->GetStartedFlag()) {
currentFrameIndex = std::max(currentFrameIndex, it->GetListenedIndex()); progress += (it->GetListenedIndex() + 1) / totalFrames;
} }
// no data processed ++index;
if (flagsum != listener.size()) {
currentFrameIndex = -1;
} }
progress *= 100;
return (100.00 * return progress;
((double)(currentFrameIndex + 1) / (double)numberOfTotalFrames));
} }
std::vector<int64_t> Implementation::getNumMissingPackets() const { std::vector<int64_t> Implementation::getNumMissingPackets() const {
@ -627,7 +627,7 @@ void Implementation::stopReceiver() {
// print summary // print summary
uint64_t tot = 0; uint64_t tot = 0;
for (int i = 0; i < numUDPInterfaces; i++) { for (int i = 0; i < numUDPInterfaces; i++) {
int nf = dataProcessor[i]->GetNumCompleteFramesCaught(); int nf = listener[i]->GetNumCompleteFramesCaught();
tot += nf; tot += nf;
std::string mpMessage = std::to_string(mp[i]); std::string mpMessage = std::to_string(mp[i]);
if (mp[i] < 0) { if (mp[i] < 0) {

View File

@ -84,8 +84,8 @@ class Implementation : private virtual slsDetectorDefs {
* * * *
* ************************************************/ * ************************************************/
runStatus getStatus() const; runStatus getStatus() const;
uint64_t getFramesCaught() const; std::vector<int64_t> getFramesCaught() const;
uint64_t getCurrentFrameIndex() const; std::vector<int64_t> getCurrentFrameIndex() const;
double getProgress() const; double getProgress() const;
std::vector<int64_t> getNumMissingPackets() const; std::vector<int64_t> getNumMissingPackets() const;
void setScan(slsDetectorDefs::scanParameters s); void setScan(slsDetectorDefs::scanParameters s);

View File

@ -36,12 +36,22 @@ Listener::~Listener() = default;
uint64_t Listener::GetPacketsCaught() const { return numPacketsCaught; } uint64_t Listener::GetPacketsCaught() const { return numPacketsCaught; }
uint64_t Listener::GetNumCompleteFramesCaught() const {
return numCompleteFramesCaught;
}
uint64_t Listener::GetLastFrameIndexCaught() const { uint64_t Listener::GetLastFrameIndexCaught() const {
return lastCaughtFrameIndex; return lastCaughtFrameIndex;
} }
int64_t Listener::GetNumMissingPacket(bool stoppedFlag, int64_t Listener::GetNumMissingPacket(bool stoppedFlag,
uint64_t numPackets) const { uint64_t numPackets) const {
if (!activated) {
return 0;
}
if (!(*detectorDataStream)) {
return 0;
}
if (!stoppedFlag) { if (!stoppedFlag) {
return (numPackets - numPacketsCaught); return (numPackets - numPacketsCaught);
} }
@ -53,11 +63,11 @@ int64_t Listener::GetNumMissingPacket(bool stoppedFlag,
numPacketsCaught; numPacketsCaught;
} }
bool Listener::GetStartedFlag() { return startedFlag; } bool Listener::GetStartedFlag() const { return startedFlag; }
uint64_t Listener::GetCurrentFrameIndex() { return lastCaughtFrameIndex; } uint64_t Listener::GetCurrentFrameIndex() const { return lastCaughtFrameIndex; }
uint64_t Listener::GetListenedIndex() { uint64_t Listener::GetListenedIndex() const {
return lastCaughtFrameIndex - firstIndex; return lastCaughtFrameIndex - firstIndex;
} }
@ -67,6 +77,7 @@ void Listener::ResetParametersforNewAcquisition() {
StopRunning(); StopRunning();
startedFlag = false; startedFlag = false;
numPacketsCaught = 0; numPacketsCaught = 0;
numCompleteFramesCaught = 0;
firstIndex = 0; firstIndex = 0;
currentFrameIndex = 0; currentFrameIndex = 0;
lastCaughtFrameIndex = 0; lastCaughtFrameIndex = 0;
@ -607,6 +618,9 @@ uint32_t Listener::ListenToAnImage(char *buf) {
// complete image // complete image
new_header->detHeader.packetNumber = numpackets; // number of packets caught new_header->detHeader.packetNumber = numpackets; // number of packets caught
new_header->detHeader.frameNumber = currentFrameIndex; new_header->detHeader.frameNumber = currentFrameIndex;
if (numpackets == pperFrame) {
++numCompleteFramesCaught;
}
++currentFrameIndex; ++currentFrameIndex;
return imageSize; return imageSize;
} }

View File

@ -51,53 +51,19 @@ class Listener : private virtual slsDetectorDefs, public ThreadObject {
*/ */
~Listener(); ~Listener();
/**
* Get Packets caught
* @return Packets caught
*/
uint64_t GetPacketsCaught() const; uint64_t GetPacketsCaught() const;
uint64_t GetNumCompleteFramesCaught() const;
/**
* Get Last Frame index caught
* @return last frame index caught
*/
uint64_t GetLastFrameIndexCaught() const; uint64_t GetLastFrameIndexCaught() const;
/** negative values in case of extra packets */
/** Get number of missing packets, returns negative values in case to extra
* packet */
int64_t GetNumMissingPacket(bool stoppedFlag, uint64_t numPackets) const; int64_t GetNumMissingPacket(bool stoppedFlag, uint64_t numPackets) const;
bool GetStartedFlag() const;
uint64_t GetCurrentFrameIndex() const;
uint64_t GetListenedIndex() const;
bool GetStartedFlag();
uint64_t GetCurrentFrameIndex();
/** (-1 if no frames have been caught) */
uint64_t GetListenedIndex();
/**
* Set Fifo pointer to the one given
* @param f address of Fifo pointer
*/
void SetFifo(Fifo *f); void SetFifo(Fifo *f);
/**
* Reset parameters for new acquisition
*/
void ResetParametersforNewAcquisition(); void ResetParametersforNewAcquisition();
/**
* Set GeneralData pointer to the one given
* @param g address of GeneralData (Detector Data) pointer
*/
void SetGeneralData(GeneralData *g); void SetGeneralData(GeneralData *g);
/**
* Creates UDP Sockets
*/
void CreateUDPSockets(); void CreateUDPSockets();
/**
* Shuts down and deletes UDP Sockets
*/
void ShutDownUDPSocket(); void ShutDownUDPSocket();
/** /**
@ -116,10 +82,6 @@ class Listener : private virtual slsDetectorDefs, public ThreadObject {
void SetHardCodedPosition(uint16_t r, uint16_t c); void SetHardCodedPosition(uint16_t r, uint16_t c);
private: private:
/**
* Record First Acquisition Index
* @param fnum frame index to record
*/
void RecordFirstIndex(uint64_t fnum); void RecordFirstIndex(uint64_t fnum);
/** /**
@ -146,55 +108,25 @@ class Listener : private virtual slsDetectorDefs, public ThreadObject {
*/ */
uint32_t ListenToAnImage(char *buf); uint32_t ListenToAnImage(char *buf);
/**
* Print Fifo Statistics
*/
void PrintFifoStatistics(); void PrintFifoStatistics();
/** type of thread */
static const std::string TypeName; static const std::string TypeName;
/** GeneralData (Detector Data) object */
GeneralData *generalData{nullptr}; GeneralData *generalData{nullptr};
/** Fifo structure */
Fifo *fifo; Fifo *fifo;
// individual members // individual members
/** Detector Type */
detectorType myDetectorType; detectorType myDetectorType;
/** Receiver Status */
std::atomic<runStatus> *status; std::atomic<runStatus> *status;
/** UDP Socket - Detector to Receiver */
std::unique_ptr<sls::UdpRxSocket> udpSocket{nullptr}; std::unique_ptr<sls::UdpRxSocket> udpSocket{nullptr};
/** UDP Port Number */
uint32_t *udpPortNumber; uint32_t *udpPortNumber;
/** ethernet interface */
std::string *eth; std::string *eth;
/** UDP Socket Buffer Size */
int *udpSocketBufferSize; int *udpSocketBufferSize;
/** double due to kernel bookkeeping */
/** actual UDP Socket Buffer Size (double due to kernel bookkeeping) */
int *actualUDPSocketBufferSize; int *actualUDPSocketBufferSize;
/** frames per file */
uint32_t *framesPerFile; uint32_t *framesPerFile;
/** frame discard policy */
frameDiscardPolicy *frameDiscardMode; frameDiscardPolicy *frameDiscardMode;
/** Activated/Deactivated */
bool *activated; bool *activated;
/** detector data stream */
bool *detectorDataStream; bool *detectorDataStream;
/** Silent Mode */
bool *silentMode; bool *silentMode;
/** row hardcoded as 1D or 2d, /** row hardcoded as 1D or 2d,
@ -209,15 +141,12 @@ class Listener : private virtual slsDetectorDefs, public ThreadObject {
// acquisition start // acquisition start
/** Aquisition Started flag */ /** Aquisition Started flag */
std::atomic<bool> startedFlag{false}; std::atomic<bool> startedFlag{false};
/** Frame Number of First Frame */ /** Frame Number of First Frame */
uint64_t firstIndex{0}; uint64_t firstIndex{0};
// for acquisition summary // for acquisition summary
/** Number of complete Packets caught */
std::atomic<uint64_t> numPacketsCaught{0}; std::atomic<uint64_t> numPacketsCaught{0};
std::atomic<uint64_t> numCompleteFramesCaught{0};
/** Last Frame Index caught from udp network */
std::atomic<uint64_t> lastCaughtFrameIndex{0}; std::atomic<uint64_t> lastCaughtFrameIndex{0};
// parameters to acquire image // parameters to acquire image
@ -225,25 +154,16 @@ class Listener : private virtual slsDetectorDefs, public ThreadObject {
* ( always check startedFlag for validity first) * ( always check startedFlag for validity first)
*/ */
uint64_t currentFrameIndex{0}; uint64_t currentFrameIndex{0};
/** True if there is a packet carry over from previous Image */ /** True if there is a packet carry over from previous Image */
bool carryOverFlag{false}; bool carryOverFlag{false};
/** Carry over packet buffer */
std::unique_ptr<char[]> carryOverPacket; std::unique_ptr<char[]> carryOverPacket;
/** Listening buffer for one packet - might be removed when we can peek and /** Listening buffer for one packet - might be removed when we can peek and
* eiger fnum is in header */ * eiger fnum is in header */
std::unique_ptr<char[]> listeningPacket; std::unique_ptr<char[]> listeningPacket;
/** if the udp socket is connected */
std::atomic<bool> udpSocketAlive{false}; std::atomic<bool> udpSocketAlive{false};
// for print progress during acquisition // for print progress during acquisition*/
/** number of packets for statistic */
uint32_t numPacketsStatistic{0}; uint32_t numPacketsStatistic{0};
/** number of images for statistic */
uint32_t numFramesStatistic{0}; uint32_t numFramesStatistic{0};
/** /**

View File

@ -34,8 +34,8 @@ TEST_CASE("Push pop") {
for (size_t i = 0; i != vec.size(); ++i) { for (size_t i = 0; i != vec.size(); ++i) {
fifo.push(p); fifo.push(p);
++p; ++p;
CHECK(fifo.getDataValue() == i + 1); CHECK(fifo.getDataValue() == (int)(i + 1));
CHECK(fifo.getFreeValue() == 4 - i); CHECK(fifo.getFreeValue() == (int)(4 - i));
} }
CHECK(fifo.isEmpty() == false); CHECK(fifo.isEmpty() == false);
@ -44,8 +44,8 @@ TEST_CASE("Push pop") {
for (size_t i = 0; i != vec.size(); ++i) { for (size_t i = 0; i != vec.size(); ++i) {
fifo.pop(p); fifo.pop(p);
CHECK(*p == vec[i]); CHECK(*p == vec[i]);
CHECK(fifo.getDataValue() == 4 - i); CHECK(fifo.getDataValue() == (int)(4 - i));
CHECK(fifo.getFreeValue() == i + 1); CHECK(fifo.getFreeValue() == (int)(i + 1));
} }
CHECK(fifo.isEmpty() == true); CHECK(fifo.isEmpty() == true);