3#include "ChimeraTK/MappedImage.h"
8#include <doocs/EqCall.h>
10const std::vector<std::string>
IGNORE_PATTERNS = {
".HIST",
".FILT",
"._FILT",
".EGU",
".DESC",
".HSTAT",
"._HSTAT",
11 "._HIST",
".LIST",
".SAVE",
".COMMENT",
".XEGU",
".POLYPARA",
"MESSAGE.TICKER"};
18 fillCatalogue(serverAddress_, nSlashes);
20 catalogue_._isCatalogueComplete = !isCancelled() && !locationLookupError_ && catalogue_.getNumberOfRegisters() != 0;
22 if(!_failedPropertyFirst.empty()) {
23 std::cerr << std::format(
"DoocsBackend::CatalogueFetcher: Failed to query shape information for {} properties. "
24 "First failed property '{}' failed with error '{}'.",
25 _failedPropertyCount, _failedPropertyFirst, _failedPropertyError)
29 return {std::move(catalogue_), catalogue_._isCatalogueComplete};
34void CatalogueFetcher::fillCatalogue(std::string fixedComponents,
long level) {
38 doocs::EqData src, propList;
39 ea.adr(fixedComponents +
"/*");
40 int rc = eq.names(&ea, &propList);
44 std::cout <<
"DoocsBackend::CatalogueFetcher: Failed to query names for " + fixedComponents
45 <<
": \"" + propList.get_string() +
"\"" << std::endl;
47 locationLookupError_ =
true;
53 for(
int i = 0; i < propList.array_length() && not isCancelled(); ++i) {
55 auto u = propList.get_ustr(i);
56 std::string name(u->str_data.str_data_val);
57 name = name.substr(0, name.find_first_of(
" "));
62 fillCatalogue(fixedComponents +
"/" + name, level + 1);
73 std::string fqn = fixedComponents +
"/" + name;
76 rc = eq.get(&ea, &src, &dst);
82 if(rc && dst.error()) {
86 if(!locationLookupError_) {
87 _failedPropertyFirst = fqn;
88 _failedPropertyError = dst.get_string();
90 _failedPropertyCount++;
91 locationLookupError_ =
true;
95 auto regPath = fqn.substr(std::string(serverAddress_).length());
96 auto length = dst.array_length();
97 auto doocsTypeId = dst.type();
99 ChimeraTK::AccessModeFlags flags{};
100 if(checkZmqAvailability(fqn)) {
101 flags.add(ChimeraTK::AccessMode::wait_for_new_data);
103 if(doocsTypeId == DATA_IMAGE) {
106 length +=
sizeof(ChimeraTK::ImgHeader);
108 catalogue_.
addProperty(regPath, length, doocsTypeId, flags);
115bool CatalogueFetcher::checkZmqAvailability(
const std::string& fullQualifiedName)
const {
116 auto lastSlash = fullQualifiedName.find_last_of(
'/');
117 assert(lastSlash != std::string::npos && lastSlash > 0);
118 auto fullLocationPath = fullQualifiedName.substr(0, lastSlash);
119 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 rc = dst.get_ustr(&portp, &f1, &f2, &tm, &sp, 0);
144 if(rc && !portp && !
static_cast<int>(f1 + f2)) rc = 0;
147 dst.get_ustr(&portp, &f1, &f2, &tm, &sp, 0);
149 rc = eq.set(&ea, &dat, &dst);
155 if(dst.type() == DATA_INT) {
156 portp = dst.get_int();
159 dst.get_ustr(&portp, &f1, &f2, &tm, &sp, 0);
const std::vector< std::string > IGNORE_PATTERNS
std::pair< DoocsBackendRegisterCatalogue, bool > fetch()
static bool isCommunicationError(int doocs_error)
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)