Monolithic design achieved! (jfjoch_broker is NOT up to date!)
This commit is contained in:
@@ -6,7 +6,8 @@
|
||||
#include "../common/JFJochException.h"
|
||||
#include "../common/Definitions.h"
|
||||
|
||||
void DetectorWrapper::Configure(const JFJochProtoBuf::DetectorConfig &request) {
|
||||
void DetectorWrapper::Configure(const DiffractionExperiment& experiment,
|
||||
const std::vector<AcquisitionDeviceNetConfig>& net_config) {
|
||||
logger.Info("Configure");
|
||||
try {
|
||||
if (det.size() > 0) {
|
||||
@@ -19,45 +20,43 @@ void DetectorWrapper::Configure(const JFJochProtoBuf::DetectorConfig &request) {
|
||||
det.setMaster(false, 0);
|
||||
det.setSynchronization(false);
|
||||
}
|
||||
auto module_hostname = experiment.GetDetectorModuleHostname();
|
||||
|
||||
if (request.module_hostname_size() > 0) {
|
||||
std::vector<std::string> module_hostname;
|
||||
for (const auto &iter: request.module_hostname())
|
||||
module_hostname.push_back(iter);
|
||||
if (!module_hostname.empty() > 0) {
|
||||
logger.Info("Resetting detector module host names");
|
||||
det.setHostname(module_hostname);
|
||||
}
|
||||
if (det.size() != request.modules_size()) {
|
||||
|
||||
if (det.size() != experiment.GetModulesNum()) {
|
||||
logger.Error("Discrepancy in module number between DAQ and detector");
|
||||
throw JFJochException(JFJochExceptionCategory::Detector,
|
||||
"Discrepancy in module number between DAQ and detector");
|
||||
}
|
||||
|
||||
if ((request.udp_interface_count() != 1) && (request.udp_interface_count() != 2))
|
||||
throw JFJochException(JFJochExceptionCategory::InputParameterInvalid,
|
||||
"Only 1 and 2 are supported as UDP interface count");
|
||||
det.setNumberofUDPInterfaces(request.udp_interface_count());
|
||||
det.setNumberofUDPInterfaces(experiment.GetUDPInterfaceCount());
|
||||
|
||||
for (int i = 0; i < request.modules_size(); i++) {
|
||||
auto mod_cfg = experiment.GetDetectorModuleConfig(net_config);
|
||||
|
||||
for (int i = 0; i < mod_cfg.size(); i++) {
|
||||
logger.Info("Configure network for module {}", i);
|
||||
|
||||
auto &cfg = request.modules(i);
|
||||
auto &cfg = mod_cfg[i];
|
||||
|
||||
det.setSourceUDPIP(sls::IpAddr(cfg.ipv4_src_addr_1()), {i});
|
||||
det.setSourceUDPIP(sls::IpAddr(cfg.ipv4_src_addr_1), {i});
|
||||
det.setSourceUDPMAC(sls::MacAddr(BASE_DETECTOR_MAC + i * 2), {i});
|
||||
|
||||
det.setDestinationUDPPort (cfg.udp_dest_port_1(), i);
|
||||
det.setDestinationUDPIP( sls::IpAddr(cfg.ipv4_dest_addr_1()), {i});
|
||||
det.setDestinationUDPMAC( sls::MacAddr(cfg.mac_addr_dest_1()), {i});
|
||||
det.setDestinationUDPPort (cfg.udp_dest_port_1, i);
|
||||
det.setDestinationUDPIP( sls::IpAddr(cfg.ipv4_dest_addr_1), {i});
|
||||
det.setDestinationUDPMAC( sls::MacAddr(cfg.mac_addr_dest_1), {i});
|
||||
|
||||
if (request.udp_interface_count() == 2) {
|
||||
det.setSourceUDPIP2(sls::IpAddr(cfg.ipv4_src_addr_2()), {i});
|
||||
if (experiment.GetUDPInterfaceCount() == 2) {
|
||||
det.setSourceUDPIP2(sls::IpAddr(cfg.ipv4_src_addr_2), {i});
|
||||
det.setSourceUDPMAC2(sls::MacAddr(BASE_DETECTOR_MAC + i * 2 + 1), {i});
|
||||
det.setDestinationUDPPort2(cfg.udp_dest_port_2(), i);
|
||||
det.setDestinationUDPIP2( sls::IpAddr(cfg.ipv4_dest_addr_2()), {i});
|
||||
det.setDestinationUDPMAC2(sls::MacAddr(cfg.mac_addr_dest_2()), {i});
|
||||
det.setDestinationUDPPort2(cfg.udp_dest_port_2, i);
|
||||
det.setDestinationUDPIP2( sls::IpAddr(cfg.ipv4_dest_addr_2), {i});
|
||||
det.setDestinationUDPMAC2(sls::MacAddr(cfg.mac_addr_dest_2), {i});
|
||||
}
|
||||
uint32_t tmp = (cfg.module_id_in_data_stream() * 2) % UINT16_MAX;
|
||||
uint32_t tmp = (cfg.module_id_in_data_stream * 2) % UINT16_MAX;
|
||||
uint32_t column_id_register = ((tmp + 1) << 16) | tmp;
|
||||
|
||||
det.writeRegister(0x7C, column_id_register, {i});
|
||||
@@ -87,20 +86,20 @@ void DetectorWrapper::Configure(const JFJochProtoBuf::DetectorConfig &request) {
|
||||
logger.Info(" ... done");
|
||||
}
|
||||
|
||||
void DetectorWrapper::Start(const JFJochProtoBuf::DetectorInput &request) {
|
||||
void DetectorWrapper::Start(const DiffractionExperiment& experiment) {
|
||||
logger.Info("Start");
|
||||
|
||||
if (det.size() != request.modules_num())
|
||||
if (det.size() != experiment.GetModulesNum())
|
||||
throw JFJochException(JFJochExceptionCategory::Detector,
|
||||
"Discrepancy in module number between DAQ and detector");
|
||||
|
||||
try {
|
||||
InternalStop();
|
||||
switch (request.mode()) {
|
||||
case JFJochProtoBuf::PEDESTAL_G1:
|
||||
switch (experiment.GetDetectorMode()) {
|
||||
case DetectorMode::PedestalG1:
|
||||
det.setGainMode(slsDetectorDefs::gainMode::FORCE_SWITCH_G1);
|
||||
break;
|
||||
case JFJochProtoBuf::PEDESTAL_G2:
|
||||
case DetectorMode::PedestalG2:
|
||||
det.setGainMode(slsDetectorDefs::gainMode::FORCE_SWITCH_G2);
|
||||
break;
|
||||
default:
|
||||
@@ -109,19 +108,38 @@ void DetectorWrapper::Start(const JFJochProtoBuf::DetectorInput &request) {
|
||||
}
|
||||
|
||||
det.setNextFrameNumber(1);
|
||||
det.setNumberOfFrames(request.num_frames());
|
||||
det.setNumberOfTriggers(request.num_triggers());
|
||||
det.setStorageCellStart(request.storage_cell_start());
|
||||
det.setNumberOfAdditionalStorageCells(request.storage_cell_number() - 1);
|
||||
det.setStorageCellDelay(std::chrono::nanoseconds(request.storage_cell_delay_ns() - MIN_STORAGE_CELL_DELAY_IN_NS));
|
||||
|
||||
if (request.period_us() < MIN_FRAME_TIME_HALF_SPEED_IN_US)
|
||||
if (experiment.GetNumTriggers() == 1) {
|
||||
det.setNumberOfFrames(experiment.GetFrameNumPerTrigger() + DELAY_FRAMES_STOP_AND_QUIT);
|
||||
det.setNumberOfTriggers(1);
|
||||
} else {
|
||||
// More than 1 trigger - detector needs one trigger or few more trigger
|
||||
if (experiment.GetStorageCellNumber() > 1)
|
||||
det.setNumberOfFrames(1);
|
||||
else
|
||||
det.setNumberOfFrames(experiment.GetFrameNumPerTrigger());
|
||||
|
||||
if (experiment.GetFrameNumPerTrigger() < DELAY_FRAMES_STOP_AND_QUIT)
|
||||
det.setNumberOfTriggers(experiment.GetNumTriggers() + DELAY_FRAMES_STOP_AND_QUIT);
|
||||
else
|
||||
det.setNumberOfTriggers(experiment.GetNumTriggers() + 1);
|
||||
}
|
||||
|
||||
det.setStorageCellStart(experiment.GetStorageCellStart());
|
||||
det.setNumberOfAdditionalStorageCells(experiment.GetStorageCellNumber() - 1);
|
||||
det.setStorageCellDelay(experiment.GetStorageCellDelay() - std::chrono::nanoseconds(MIN_STORAGE_CELL_DELAY_IN_NS));
|
||||
|
||||
if ((experiment.GetStorageCellNumber() > 1) || (experiment.GetFrameTime().count() < MIN_FRAME_TIME_HALF_SPEED_IN_US))
|
||||
det.setReadoutSpeed(slsDetectorDefs::speedLevel::FULL_SPEED);
|
||||
else
|
||||
det.setReadoutSpeed(slsDetectorDefs::speedLevel::HALF_SPEED);
|
||||
|
||||
det.setPeriod(std::chrono::microseconds(request.period_us()));
|
||||
det.setExptime(std::chrono::microseconds(request.count_time_us()));
|
||||
if (experiment.GetStorageCellNumber() > 1) {
|
||||
det.setPeriod((experiment.GetFrameTime() + std::chrono::microseconds(10)) * experiment.GetStorageCellNumber() );
|
||||
} else
|
||||
det.setPeriod(experiment.GetFrameTime());
|
||||
|
||||
det.setExptime(std::chrono::microseconds(experiment.GetFrameCountTime()));
|
||||
|
||||
det.startDetector();
|
||||
} catch (std::exception &e) {
|
||||
|
||||
Reference in New Issue
Block a user