Newer
Older
Roman Tolchenov
committed
//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include "MantidKernel/InstrumentInfo.h"
#include "MantidKernel/FacilityInfo.h"
#include "MantidKernel/Exception.h"
Janik Zikovsky
committed
#include "MantidKernel/Strings.h"
Roman Tolchenov
committed
#include <Poco/DOM/Element.h>
#include <Poco/DOM/NodeList.h>
#include <Poco/DOM/Text.h>
Roman Tolchenov
committed
#include <algorithm>
namespace Mantid
{
Gigg, Martyn Anthony
committed
namespace Kernel
{
Roman Tolchenov
committed
Gigg, Martyn Anthony
committed
Logger& InstrumentInfo::g_log = Logger::get("InstrumentInfo");
Roman Tolchenov
committed
Gigg, Martyn Anthony
committed
/** Constructor.
Janik Zikovsky
committed
* @param f :: The facility
* @param elem :: The Poco::XML::Element to read the data from
* @throw std::runtime_error if name or at least one technique are not defined
Gigg, Martyn Anthony
committed
*/
InstrumentInfo::InstrumentInfo(FacilityInfo* f,const Poco::XML::Element* elem)
:m_facility(f)
{
std::string paddingStr = elem->getAttribute("zeropadding");
Janik Zikovsky
committed
if ( paddingStr.empty() || !Mantid::Kernel::Strings::convert(paddingStr,m_zeroPadding) )
Gigg, Martyn Anthony
committed
{
m_zeroPadding = f->zeroPadding();
}
Roman Tolchenov
committed
Gigg, Martyn Anthony
committed
m_name = elem->getAttribute("name");
if (m_name.empty())
{
g_log.error("Instrument name is not defined");
throw std::runtime_error("Instrument name is not defined");
}
Roman Tolchenov
committed
// The string to separate the instrument name and the run number.
m_delimiter = elem->getAttribute("delimiter");
if (m_delimiter.empty())
{
m_delimiter = f->delimiter();
}
Gigg, Martyn Anthony
committed
m_shortName = elem->getAttribute("shortname");
if (m_shortName.empty())
{
m_shortName = m_name;
}
Roman Tolchenov
committed
Gigg, Martyn Anthony
committed
Poco::XML::NodeList* pNL_technique = elem->getElementsByTagName("technique");
unsigned long n = pNL_technique->length();
Roman Tolchenov
committed
for (unsigned long i = 0; i < n; ++i)
Roman Tolchenov
committed
{
Gigg, Martyn Anthony
committed
Poco::XML::NodeList* pNL = pNL_technique->item(i)->childNodes();
if (pNL->length() > 0)
Roman Tolchenov
committed
{
Gigg, Martyn Anthony
committed
Poco::XML::Text* txt = dynamic_cast<Poco::XML::Text*>(pNL->item(0));
if (txt)
{
std::string tech = txt->getData();
if ( !tech.empty() )
{
m_technique.insert(tech);
}
}
Roman Tolchenov
committed
}
pNL->release();
Roman Tolchenov
committed
}
pNL_technique->release();
Gigg, Martyn Anthony
committed
if (m_technique.empty())
{
g_log.error("No technique is defined for instrument "+m_name);
throw std::runtime_error("No technique is defined for instrument "+m_name);
}
Roman Tolchenov
committed
}
Gigg, Martyn Anthony
committed
/**
* Equality operator. Two objects are considered equal if their names, short names and zero padding are the same.
Janik Zikovsky
committed
* @param rhs :: The object to compare this with
Gigg, Martyn Anthony
committed
* @returns True if the objects are considered equal, false otherwise
*/
bool InstrumentInfo::operator==(const InstrumentInfo & rhs) const
{
return (this->name() == rhs.name() && this->shortName() == rhs.shortName());
Gigg, Martyn Anthony
committed
}
Roman Tolchenov
committed
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/// Returns the default delimiter between instrument name and run number
std::string InstrumentInfo::delimiter() const
{
return m_delimiter;
}
/// Return the name of the instrument
const std::string InstrumentInfo::name() const
{
return m_name;
}
/// Return the short name of the instrument
const std::string InstrumentInfo::shortName() const
{
return m_shortName;
}
/// Returns zero padding for this instrument
int InstrumentInfo::zeroPadding() const
{
return m_zeroPadding;
}
/// Return list of techniques
const std::set<std::string>& InstrumentInfo::techniques() const
{
return m_technique;
}
Gigg, Martyn Anthony
committed
} // namespace Kernel
Roman Tolchenov
committed
} // namespace Mantid