Mantid
Loading...
Searching...
No Matches
TopicInfo.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2019 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
10#include <Poco/DOM/Element.h>
11
12#include <utility>
13
14namespace Mantid::Kernel {
15
16namespace {
17// static logger object
18Logger g_log("TopicInfo");
19
20std::string typeToString(TopicType type) {
21 switch (type) {
23 return "Event";
25 return "Monitor";
27 return "Sample";
29 return "Chopper";
30 case TopicType::Run:
31 return "Run";
32 default:
33 return "unspecified";
34 }
35}
36} // namespace
37
38TopicInfo::TopicInfo(InstrumentInfo *inst, const Poco::XML::Element *elem) : m_name(elem->getAttribute("name")) {
39 if (m_name.empty())
40 g_log.warning() << "Kafka topic provided without a suitable name for instrument " << inst->name()
41 << ". No attempts will be made to connect to this topic." << std::endl;
42
43 std::string type = elem->getAttribute("type");
44
45 if (type == "event")
47 else if (type == "chopper")
49 else if (type == "sample")
51 else if (type == "run")
53 else if (type == "monitor")
55 else
56 g_log.warning() << "Kafka topic provided without a suitable type for instrument " << inst->name()
57 << ". No attempts will be made to connect to this topic." << std::endl;
58}
59
60TopicInfo::TopicInfo(std::string name, TopicType type) : m_name(std::move(name)), m_type(type) {}
61
69std::ostream &operator<<(std::ostream &buffer, const TopicInfo &topic) {
70 buffer << topic.name() << "(" << typeToString(topic.type()) << ", "
71 << ")";
72 return buffer;
73}
74} // namespace Mantid::Kernel
A class that holds information about an instrument.
const std::string name() const
Return the name of the instrument.
void warning(const std::string &msg)
Logs at warning level.
Definition: Logger.cpp:86
TopicInfo : Class that holds information on a kafka topic.
Definition: TopicInfo.h:32
const std::string & name() const
Definition: TopicInfo.h:36
TopicType type() const
Definition: TopicInfo.h:37
TopicInfo(InstrumentInfo *inst, const Poco::XML::Element *elem)
Definition: TopicInfo.cpp:38
MANTID_KERNEL_DLL std::ostream & operator<<(std::ostream &, CPUTimer &)
Convenience function to provide for easier debug printing.
Definition: CPUTimer.cpp:86
STL namespace.