3#include "ChimeraTK/MappedImage.h"
8#include <doocs/EqCall.h>
10#include <boost/range/algorithm/find.hpp>
12const std::vector<std::string>
IGNORE_PATTERNS = {
".HIST",
".FILT",
"._FILT",
".EGU",
".DESC",
".HSTAT",
"._HSTAT",
13 "._HIST",
".LIST",
".SAVE",
".COMMENT",
".XEGU",
".POLYPARA"};
15const std::vector<std::string>
IGNORE_LIST = {
"MESSAGE.TICKER",
"SPN"};
22 fillCatalogue(serverAddress_, nSlashes);
24 catalogue_._isCatalogueComplete = !isCancelled() && !locationLookupError_ && catalogue_.getNumberOfRegisters() != 0;
26 if(!_failedPropertyFirst.empty()) {
27 std::cerr << std::format(
"DoocsBackend::CatalogueFetcher: Failed to query shape information for {} properties. "
28 "First failed property '{}' failed with error '{}'.",
29 _failedPropertyCount, _failedPropertyFirst, _failedPropertyError)
33 return {std::move(catalogue_), catalogue_._isCatalogueComplete};
38void CatalogueFetcher::fillCatalogue(std::string fixedComponents,
long level) {
42 doocs::EqData src, propList;
43 ea.adr(fixedComponents +
"/*");
44 int rc = eq.names(&ea, &propList);
48 std::cout <<
"DoocsBackend::CatalogueFetcher: Failed to query names for " + fixedComponents
49 <<
": \"" + propList.get_string() +
"\"" << std::endl;
51 locationLookupError_ =
true;
57 for(
int i = 0; i < propList.array_length() && not isCancelled(); ++i) {
59 auto u = propList.get_ustr(i);
60 std::string name(u->str_data.str_data_val);
61 name = name.substr(0, name.find_first_of(
" "));
66 fillCatalogue(fixedComponents +
"/" + name, level + 1);
77 std::string fqn = fixedComponents +
"/" + name;
80 rc = eq.get(&ea, &src, &dst);
81 if((rc && doocs::is_system_error(dst.error())) || dst.error() == eq_errors::device_error) {
86 if(rc && dst.error()) {
90 if(!locationLookupError_) {
91 _failedPropertyFirst = fqn;
92 _failedPropertyError = dst.get_string();
94 _failedPropertyCount++;
95 locationLookupError_ =
true;
99 auto regPath = fqn.substr(std::string(serverAddress_).length());
100 auto length = dst.array_length();
101 auto doocsTypeId = dst.type();
103 ChimeraTK::AccessModeFlags flags{};
104 if(checkZmqAvailability(fqn)) {
105 flags.add(ChimeraTK::AccessMode::wait_for_new_data);
107 if(doocsTypeId == DATA_IMAGE) {
110 length +=
sizeof(ChimeraTK::ImgHeader);
112 catalogue_.
addProperty(regPath, length, doocsTypeId, flags);
119bool CatalogueFetcher::checkZmqAvailability(
const std::string& fullQualifiedName)
const {
120 auto lastSlash = fullQualifiedName.find_last_of(
'/');
121 assert(lastSlash != std::string::npos && lastSlash > 0);
122 auto fullLocationPath = fullQualifiedName.substr(0, lastSlash);
123 auto propertyName = fullQualifiedName.substr(lastSlash + 1);
132 ea.adr(fullLocationPath +
"/SPN");
135 dat.set(1, 0.0F, 0.0F, time_t{0}, propertyName, 0);
138 rc = eq.get(&ea, &dat, &dst);
143 auto* ustr = dst.get_ustr();
144 if(ustr !=
nullptr) {
145 portp = ustr->i1_data;
147 if(ustr ==
nullptr || (portp == 0 &&
int(ustr->f1_data + ustr->f2_data) == 0)) {
149 rc = eq.set(&ea, &dat, &dst);
155 if(dst.type() == DATA_INT) {
156 portp = dst.get_int();
159 ustr = dst.get_ustr();
160 if(ustr !=
nullptr) {
161 portp = ustr->i1_data;
const std::vector< std::string > IGNORE_LIST
const std::vector< std::string > IGNORE_PATTERNS
std::pair< DoocsBackendRegisterCatalogue, bool > fetch()
void addProperty(const std::string &name, unsigned int length, int doocsType, ChimeraTK::AccessModeFlags flags)
std::pair< bool, std::string > endsWith(std::string const &s, const std::vector< std::string > &patterns)
long slashes(const std::string &s)