17#include <boost/algorithm/string.hpp>
18#include <boost/lexical_cast.hpp>
20#include <Poco/AutoPtr.h>
21#include <Poco/DOM/Element.h>
22#include <Poco/DOM/NodeList.h>
23#include <Poco/DOM/Text.h>
28Logger
g_log(
"InstrumentInfo");
37 : m_facility(f), m_name(elem->getAttribute(
"name")), m_shortName(elem->getAttribute(
"shortname")),
38 m_delimiter(elem->getAttribute(
"delimiter")) {
57 return (this->
name() == rhs.
name() && this->shortName() ==
rhs.shortName());
75 if (runNumber >= padding->first)
85 if (runNumber >= it->first && runNumber < next->first) {
101 if (runNumber >= padding->first)
111 if (runNumber >= it->first && runNumber < next->first) {
146 throw std::runtime_error(
"Attempted to access live listener for " +
m_name +
147 " instrument, which has no listeners.");
159 [&
name](
const auto &listener) { return boost::iequals(listener.name(), name); });
164 throw std::runtime_error(
"Could not find connection " +
name +
" for instrument " +
m_name);
179 Poco::AutoPtr<Poco::XML::NodeList> pNL_zeropadding = elem->getElementsByTagName(
"zeropadding");
180 unsigned long n = pNL_zeropadding->length();
182 for (
unsigned long i = 0; i <
n; ++i) {
183 auto elemenent =
dynamic_cast<Poco::XML::Element *
>(pNL_zeropadding->item(i));
187 if (!elemenent->hasAttribute(
"size")) {
188 throw std::runtime_error(
"Zeropadding size is missing for instrument " +
m_name);
190 auto &sizeStr = elemenent->getAttribute(
"size");
193 throw std::runtime_error(
"Zeropadding size must be an integer value (instrument " +
m_name +
")");
196 unsigned int startRunNumber = 0;
197 if (!elemenent->hasAttribute(
"startRunNumber")) {
199 throw std::runtime_error(
"Zeropadding size is missing for instrument " +
m_name);
202 auto &startRunNumberStr = elemenent->getAttribute(
"startRunNumber");
204 startRunNumber = boost::lexical_cast<unsigned int>(startRunNumberStr);
206 throw std::runtime_error(
"Zeropadding start run number must be an "
207 "integer value (instrument " +
213 if (elemenent->hasAttribute(
"prefix")) {
214 prefix = elemenent->getAttribute(
"prefix");
216 m_zeroPadding[startRunNumber] = std::make_pair(prefix, size);
226 Poco::AutoPtr<Poco::XML::NodeList> pNL_technique = elem->getElementsByTagName(
"technique");
227 unsigned long n = pNL_technique->length();
229 for (
unsigned long i = 0; i <
n; ++i) {
230 Poco::AutoPtr<Poco::XML::NodeList> pNL = pNL_technique->item(i)->childNodes();
231 if (pNL->length() > 0) {
232 auto *txt =
dynamic_cast<Poco::XML::Text *
>(pNL->item(0));
234 const std::string &tech = txt->getData();
243 throw std::runtime_error(
"No technique is defined for instrument " +
m_name);
250 Poco::XML::Element *live = elem->getChildElement(
"livedata");
258 Poco::AutoPtr<Poco::XML::NodeList> connections = elem->getElementsByTagName(
"connection");
261 for (
unsigned long i = 0; i < connections->length(); ++i) {
262 auto *conn =
dynamic_cast<Poco::XML::Element *
>(connections->item(i));
267 <<
" instrument. Skipping faulty connection.\n";
272 Poco::AutoPtr<Poco::XML::NodeList> topics = elem->getElementsByTagName(
"topic");
273 for (
unsigned long i = 0; i < topics->length(); ++i) {
274 auto *topic =
dynamic_cast<Poco::XML::Element *
>(topics->item(i));
279 <<
" instrument. Skipping kafka topic.\n";
294 buffer << instrumentDescriptor.
name();
const std::vector< double > & rhs
A class that holds information about a facility.
int zeroPadding() const
Returns default zero padding for this facility.
const std::string & delimiter() const
Returns the default delimiter between instrument name and run number.
A class that holds information about an instrument.
void fillLiveData(const Poco::XML::Element *elem)
Called from constructor to fill live listener name.
std::string filePrefix(unsigned int runNumber) const
Returns file prefix for this instrument and a run number.
bool hasLiveListenerInfo() const
Returns true if this instrument has at least one live listener defined.
std::vector< TopicInfo > m_kafkaTopics
Kafka topics.
std::string m_name
Instrument name.
void fillZeroPadding(const Poco::XML::Element *elem)
Called from constructor to fill zero padding.
std::string m_shortName
Instrument short name.
std::string m_defaultListener
Default LiveListener connection to use.
const FacilityInfo * m_facility
Facility.
const std::string & getPrefix(ZeroPaddingMap::const_iterator it) const
get the prefix part
int getZeroPadding(ZeroPaddingMap::const_iterator it) const
get the zeropadding part
std::string liveDataAddress(const std::string &name="") const
Returns a string containing the "host:port" for default live listener.
const FacilityInfo & facility() const
The facility to which this instrument belongs.
const std::string name() const
Return the name of the instrument.
const std::set< std::string > & techniques() const
Return list of techniques.
std::set< std::string > m_technique
List of techniques the instrument can do.
const std::vector< LiveListenerInfo > & liveListenerInfoList() const
Returns all available LiveListenerInfos as a vector.
InstrumentInfo(const FacilityInfo *f, const Poco::XML::Element *elem)
Constructor.
std::string m_delimiter
Delimiter between instrument name and run number.
int zeroPadding(unsigned int runNumber) const
Returns zero padding for this instrument and a run number.
std::string delimiter() const
Returns the default delimiter between instrument name and run number.
ZeroPaddingMap m_zeroPadding
Run number-dependent zero padding.
bool operator==(const InstrumentInfo &rhs) const
Equality operator.
std::string liveListener(const std::string &name="") const
Returns the name of the default live listener.
std::vector< LiveListenerInfo > m_listeners
LiveListener connections.
const LiveListenerInfo & liveListenerInfo(std::string name="") const
Returns LiveListenerInfo for specified connection name (or default)
const std::string shortName() const
Return the short name of the instrument.
void fillTechniques(const Poco::XML::Element *elem)
Called from constructor to fill live listener name.
A class that holds information about a LiveListener connection.
const std::string & address() const
Returns the address string of this LiveListener connection.
const std::string & listener() const
Returns the classname of the specific LiveListener to use.
void error(const std::string &msg)
Logs at error level.
Logger g_log("DateAndTime")
int convert(const std::string &A, T &out)
Convert a string into a number.
MANTID_KERNEL_DLL std::ostream & operator<<(std::ostream &, CPUTimer &)
Convenience function to provide for easier debug printing.