18#include <boost/algorithm/string.hpp>
22#include <Poco/DOM/Element.h>
23#include <Poco/DOM/NodeList.h>
24#include <Poco/DOM/Text.h>
26using Poco::XML::Element;
32Logger
g_log(
"FacilityInfo");
40 : m_catalogs(elem), m_name(elem->getAttribute(
"name")), m_timezone(), m_zeroPadding(0), m_delimiter(),
41 m_extensions(), m_archiveSearch(), m_instruments(), m_noFilePrefix(), m_multiFileLimit(100) {
57 std::string paddingStr = elem->getAttribute(
"zeropadding");
65 std::string noFilePrefixStr = elem->getAttribute(
"nofileprefix");
71 const std::string multiFileLimitStr = elem->getAttribute(
"multifilelimit");
72 if (!multiFileLimitStr.empty()) {
88 std::string extsStr = elem->getAttribute(
"FileExtensions");
89 if (extsStr.empty()) {
91 throw std::runtime_error(
"No file extensions defined");
95 for (
const auto &ext : exts) {
112 Poco::AutoPtr<Poco::XML::NodeList> pNL_archives = elem->getElementsByTagName(
"archive");
113 if (pNL_archives->length() > 1) {
114 g_log.
error(
"Facility must have only one archive tag");
115 throw std::runtime_error(
"Facility must have only one archive tag");
116 }
else if (pNL_archives->length() == 1) {
117 Poco::AutoPtr<Poco::XML::NodeList> pNL_interfaces = elem->getElementsByTagName(
"archiveSearch");
118 for (
unsigned int i = 0; i < pNL_interfaces->length(); ++i) {
119 auto *elemenent =
dynamic_cast<Poco::XML::Element *
>(pNL_interfaces->item(i));
120 std::string plugin = elemenent->getAttribute(
"plugin");
121 if (!plugin.empty()) {
129 Poco::AutoPtr<Poco::XML::NodeList> pNL_timezones = elem->getElementsByTagName(
"timezone");
130 if (pNL_timezones->length() == 0) {
131 g_log.
notice() <<
"No timezone specified for " <<
m_name <<
" in Facilities.xml\n";
132 }
else if (pNL_timezones->length() == 1) {
133 pNL_timezones = pNL_timezones->item(0)->childNodes();
134 if (pNL_timezones->length() > 0) {
135 auto *txt =
dynamic_cast<Poco::XML::Text *
>(pNL_timezones->item(0));
139 throw std::runtime_error(
"Facility " +
m_name +
" has more than one timezone specified");
145 Poco::AutoPtr<Poco::XML::NodeList> pNL_instrument = elem->getElementsByTagName(
"instrument");
146 unsigned long n = pNL_instrument->length();
149 for (
unsigned long i = 0; i <
n; ++i) {
150 auto *elemenent =
dynamic_cast<Poco::XML::Element *
>(pNL_instrument->item(i));
155 }
catch (std::runtime_error &e) {
162 throw std::runtime_error(
"Facility " +
m_name +
" does not have any instruments;");
175 g_log.
debug() <<
"Blank instrument specified, using default instrument of " << iName <<
".\n";
182 [&iName](
const auto &inst) { return boost::iequals(inst.name(), iName); });
187 [&iName](
const auto &inst) { return boost::iequals(inst.shortName(), iName); });
195 g_log.
debug(
"Instrument " + iName +
" not found in facility " +
name());
205 std::vector<InstrumentInfo> out;
208 if (it->techniques().count(tech)) {
209 out.emplace_back(*it);
Exception for when an item is not found in a collection.
std::vector< std::string > m_extensions
file extensions in order of preference
std::string m_timezone
Timezone designation in pytz.
void fillMultiFileLimit(const Poco::XML::Element *elem)
Called from constructor to fill the multifile limit.
const std::vector< InstrumentInfo > & instruments() const
Returns a list of instruments of this facility.
void fillNoFilePrefix(const Poco::XML::Element *elem)
Called from constructor to fill the noFilePrefix flag.
void fillInstruments(const Poco::XML::Element *elem)
Called from constructor to fill instrument list.
void fillTimezone(const Poco::XML::Element *elem)
FacilityInfo(const Poco::XML::Element *elem)
Constructor.
const std::string m_name
facility name
bool m_noFilePrefix
flag indicating if prefix is required in file names
int m_zeroPadding
default zero padding for this facility
void addExtension(const std::string &ext)
Add new extension.
void fillZeroPadding(const Poco::XML::Element *elem)
Called from constructor to fill zero padding field.
std::vector< std::string > m_archiveSearch
names of the archive search interface
std::vector< InstrumentInfo > m_instruments
list of instruments of this facility
void fillDelimiter(const Poco::XML::Element *elem)
Called from constructor to fill default delimiter.
size_t m_multiFileLimit
the multiple file limit
const std::string & name() const
Return the name of the facility.
void fillArchiveNames(const Poco::XML::Element *elem)
Called from constructor to fill archive interface names.
std::string m_delimiter
default delimiter between instrument name and run number
const InstrumentInfo & instrument(std::string iName="") const
Returns instruments with given name.
void fillExtensions(const Poco::XML::Element *elem)
Called from constructor to fill file extensions.
A class that holds information about an instrument.
const std::string name() const
Return the name of the instrument.
void debug(const std::string &msg)
Logs at debug level.
void notice(const std::string &msg)
Logs at notice level.
void error(const std::string &msg)
Logs at error level.
void warning(const std::string &msg)
Logs at warning level.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
@ TOK_IGNORE_EMPTY
ignore empty tokens
@ TOK_TRIM
remove leading and trailing whitespace from tokens
Logger g_log("DateAndTime")
int convert(const std::string &A, T &out)
Convert a string into a number.