Skip to content
Snippets Groups Projects
ConfigService.cpp 36.2 KiB
Newer Older
      newSearchString.append(*it);
      newSearchString.append(";");
    }
    newSearchString.append(path);
    setString("datasearch.directories", newSearchString);
  }
}

/**
 * Return the list of user search paths
 * @returns A vector of strings containing the defined search directories
 */
const std::vector<std::string>& ConfigServiceImpl::getUserSearchDirs() const
{
  return m_UserSearchDirs;
}

/**
 * Return the search directory for XML instrument definition files (IDFs)
 * @returns Full path of instrument search directory
 */
const std::string ConfigServiceImpl::getInstrumentDirectory() const
{
  // Determine the search directory for XML instrument definition files (IDFs)
  std::string directoryName = getString("instrumentDefinition.directory");
  if (directoryName.empty())
    // This is the assumed deployment directory for IDFs, where we need to be relative to the
    // directory of the executable, not the current working directory.
    directoryName = Poco::Path(getPropertiesDir()).resolve("../instrument").toString();
  if (!Poco::File(directoryName).isDirectory())
    g_log.error("Unable to locate instrument search directory at: " + directoryName);
}

/**
 * Load facility information from instrumentDir/Facilities.xml file if fName parameter
 * is not set
 * @param fName :: An alternative file name for loading facilities information.
 */
void ConfigServiceImpl::updateFacilities(const std::string& fName)
{
  m_facilities.clear();
  std::string instrDir = getString("instrumentDefinition.directory");
  std::string fileName = fName.empty() ? instrDir + "Facilities.xml" : fName;

  // Set up the DOM parser and parse xml file
  Poco::XML::DOMParser pParser;
  Poco::XML::Document* pDoc;
    try
    {
      pDoc = pParser.parse(fileName);
    } catch (...)
    {
      throw Kernel::Exception::FileError("Unable to parse file:", fileName);
    }
    // Get pointer to root element
    Poco::XML::Element* pRootElem = pDoc->documentElement();
    if (!pRootElem->hasChildNodes())
    {
      pDoc->release();
      throw std::runtime_error("No root element in Facilities.xml file");
    }
    Poco::XML::NodeList* pNL_facility = pRootElem->getElementsByTagName("facility");
    unsigned int n = pNL_facility->length();
    for (unsigned int i = 0; i < n; ++i)
    {
      Poco::XML::Element* elem = dynamic_cast<Poco::XML::Element*> (pNL_facility->item(i));
      if (elem)
      {
        m_facilities.push_back(new FacilityInfo(elem));
      }
    }

    if (m_facilities.empty())
      pNL_facility->release();
      pDoc->release();
      throw std::runtime_error("The facility definition file " + fileName + " defines no facilities");
 * @return the facility information object
 */
const FacilityInfo& ConfigServiceImpl::Facility() const
{
  std::string defFacility = getString("default.facility");
  if (defFacility.empty())
 @param observer :: Reference to the observer to add
void ConfigServiceImpl::addObserver(const Poco::AbstractObserver& observer) const
  m_notificationCenter.addObserver(observer);
 @param observer :: Reference to the observer to remove
void ConfigServiceImpl::removeObserver(const Poco::AbstractObserver& observer) const
  m_notificationCenter.removeObserver(observer);
 * @return the facility information object
 * @throw NotFoundException if the facility is not found
 */
const FacilityInfo& ConfigServiceImpl::Facility(const std::string& fName) const
{
  std::vector<FacilityInfo*>::const_iterator it = m_facilities.begin();
  for (; it != m_facilities.end(); ++it)
  g_log.error("Facility " + fName + " not found");
  throw Exception::NotFoundError("Facilities", fName);
}

/// \cond TEMPLATE
template DLLExport int ConfigServiceImpl::getValue(const std::string&, double&);
template DLLExport int ConfigServiceImpl::getValue(const std::string&, std::string&);
template DLLExport int ConfigServiceImpl::getValue(const std::string&, int&);
/// \endcond TEMPLATE

} // namespace Kernel
} // namespace Mantid