Changeset 5365

Show
Ignore:
Timestamp:
27/07/10 09:41:09 (6 weeks ago)
Author:
Roman Tolchenov
Message:

Added FileFinder class. re #1393

Location:
trunk/Code/Mantid
Files:
3 added
7 modified

Legend:

Unmodified
Added
Removed
  • trunk/Code/Mantid/API/API.vcproj

    r5353 r5365  
    232232                        </File> 
    233233                        <File 
     234                                RelativePath=".\src\FileFinder.cpp" 
     235                                > 
     236                        </File> 
     237                        <File 
    234238                                RelativePath=".\src\FrameworkManager.cpp" 
    235239                                > 
     
    473477                        <File 
    474478                                RelativePath=".\test\ExpressionTest.h" 
     479                                > 
     480                        </File> 
     481                        <File 
     482                                RelativePath=".\inc\MantidAPI\FileFinder.h" 
     483                                > 
     484                        </File> 
     485                        <File 
     486                                RelativePath=".\test\FileFinderTest.h" 
    475487                                > 
    476488                        </File> 
  • trunk/Code/Mantid/Algorithms/Algorithms.vcproj

    r5271 r5365  
    192192                        </File> 
    193193                        <File 
     194                                RelativePath=".\src\ApplyTransmissionCorrection.cpp" 
     195                                > 
     196                        </File> 
     197                        <File 
    194198                                RelativePath=".\src\BinaryOperation.cpp" 
    195199                                > 
     
    563567                        <File 
    564568                                RelativePath=".\test\AnyShapeAbsorptionTest.h" 
     569                                > 
     570                        </File> 
     571                        <File 
     572                                RelativePath=".\inc\MantidAlgorithms\ApplyTransmissionCorrection.h" 
    565573                                > 
    566574                        </File> 
  • trunk/Code/Mantid/Kernel/inc/MantidKernel/ConfigService.h

    r5348 r5365  
    9898      const std::vector<std::string>& getInstrumentPrefixes(const std::string& facility) const; 
    9999 
     100      /// Load facility information from instrumentDir/Facilities.xml file  
     101      void updateFacilities(const std::string& fName = ""); 
    100102      /// Get the default facility 
    101103      const FacilityInfo& Facility()const; 
     
    132134      /// Create the map of facility name to instrument prefix list 
    133135      void cacheInstrumentPrefixes(); 
    134       /// Load facility information from instrumentDir/Facilities.xml file 
    135       void updateFacilities(); 
    136136 
    137137      // Forward declaration of inner class 
  • trunk/Code/Mantid/Kernel/inc/MantidKernel/FacilityInfo.h

    r5333 r5365  
    7070  const std::vector<InstrumentInfo> Instruments(const std::string& tech)const; 
    7171  /// Returns instruments with given name 
    72   const InstrumentInfo Instrument(const std::string& iName)const; 
     72  const InstrumentInfo Instrument(const std::string& iName = "")const; 
    7373private: 
    7474  /// Add new extension 
  • trunk/Code/Mantid/Kernel/src/ConfigService.cpp

    r5348 r5365  
    166166  ConfigServiceImpl::~ConfigServiceImpl() 
    167167  { 
     168    std::cerr << "ConfigService destroyed." << std::endl; 
    168169    Kernel::Logger::shutdown(); 
    169170    delete m_pSysConfig; 
     
    859860 
    860861  /** 
    861     * Load facility information from instrumentDir/Facilities.xml file 
     862    * Load facility information from instrumentDir/Facilities.xml file if fName parameter 
     863    * is not set 
     864    * @param fName An alternative file name for loading facilities information. 
    862865    */ 
    863   void ConfigServiceImpl::updateFacilities() 
    864   { 
     866  void ConfigServiceImpl::updateFacilities(const std::string& fName) 
     867  { 
     868    m_facilities.clear(); 
     869 
    865870    std::string instrDir = getString("instrumentDefinition.directory"); 
    866     std::string fileName = instrDir + "Facilities.xml"; 
     871    std::string fileName = fName.empty() ? instrDir + "Facilities.xml" : fName; 
    867872 
    868873    // Set up the DOM parser and parse xml file 
     
    876881    { 
    877882      g_log.error("Unable to parse file " + fileName); 
    878       throw Kernel::Exception::FileError("Unable to parse File:" , fileName); 
     883      throw Kernel::Exception::FileError("Unable to parse file:" , fileName); 
    879884    } 
    880885    // Get pointer to root element 
     
    883888    { 
    884889      g_log.error("XML file: " + fileName + "contains no root element."); 
    885       throw Kernel::Exception::InstrumentDefinitionError("No root element in XML facilities file", fileName); 
     890      throw std::runtime_error("No root element in Facilities.xml file"); 
    886891    } 
    887892 
     
    896901        m_facilities.push_back(new FacilityInfo(elem)); 
    897902      } 
     903    } 
     904 
     905    if (m_facilities.empty()) 
     906    { 
     907      throw std::runtime_error("The facility definition file "+fileName+" defines no facilities"); 
    898908    } 
    899909 
  • trunk/Code/Mantid/Kernel/src/FacilityInfo.cpp

    r5333 r5365  
    55#include "MantidKernel/Support.h" 
    66#include "MantidKernel/Exception.h" 
     7#include "MantidKernel/ConfigService.h" 
    78 
    89#include "Poco/DOM/Element.h" 
     
    2930  if (m_name.empty()) 
    3031  { 
    31     g_log.error("Facility anme is not defined"); 
    32     throw std::runtime_error("Facility anme is not defined"); 
     32    g_log.error("Facility name is not defined"); 
     33    throw std::runtime_error("Facility name is not defined"); 
    3334  } 
    3435  std::string paddingStr = elem->getAttribute("zeropadding"); 
     
    6869    } 
    6970  } 
     71 
     72  if (m_instruments.empty()) 
     73  { 
     74    throw std::runtime_error("Facility "+m_name+" does not have any instrument;"); 
     75  } 
    7076} 
    7177 
     
    9096const InstrumentInfo FacilityInfo::Instrument(const std::string& iName)const 
    9197{ 
     98  std::string iname; 
     99  if (iName.empty()) 
     100  { 
     101    iname = ConfigService::Instance().getString("default.instrument"); 
     102    if (iname.empty()) 
     103    { 
     104      return m_instruments.front(); 
     105    } 
     106  } 
     107  else 
     108  { 
     109    iname = iName; 
     110  } 
    92111  std::vector<InstrumentInfo>::const_iterator it = m_instruments.begin(); 
    93112  for(;it != m_instruments.end(); ++it) 
    94113  { 
    95     if (it->name() == iName) 
     114    if (it->name() == iname) 
    96115    { 
    97116      return *it; 
    98117    } 
    99118  } 
    100   g_log.error("Instrument "+iName+" not found in facility "+name()); 
    101   throw Exception::NotFoundError("FacilityInfo",iName); 
     119 
     120  // if unsuccessful try shortname 
     121  for(it = m_instruments.begin(); it != m_instruments.end(); ++it) 
     122  { 
     123    if (it->shortName() == iname) 
     124    { 
     125      return *it; 
     126    } 
     127  } 
     128  g_log.error("Instrument "+iname+" not found in facility "+name()); 
     129  throw Exception::NotFoundError("FacilityInfo",iname); 
    102130} 
    103131 
  • trunk/Code/Mantid/Kernel/test/FacilitiesTest.h

    r5333 r5365  
    9090  } 
    9191 
     92  void testDefaultFacility() 
     93  { 
     94    TS_ASSERT_THROWS_NOTHING( 
     95      const FacilityInfo& fac = ConfigService::Instance().Facility() 
     96    ); 
     97    const FacilityInfo& fac = ConfigService::Instance().Facility(); 
     98    TS_ASSERT_EQUALS(fac.name(),"ISIS"); 
     99 
     100    ConfigService::Instance().setString("default.facility","SNS"); 
     101    const FacilityInfo& fac1 = ConfigService::Instance().Facility(); 
     102    TS_ASSERT_EQUALS(fac1.name(),"SNS"); 
     103 
     104    ConfigService::Instance().setString("default.facility",""); 
     105    const FacilityInfo& fac2 = ConfigService::Instance().Facility(); 
     106    TS_ASSERT_EQUALS(fac2.name(),"ISIS"); 
     107  } 
     108 
     109  void testDefaultInstrument() 
     110  { 
     111    ConfigService::Instance().setString("default.instrument","HRPD"); 
     112    const FacilityInfo& fac = ConfigService::Instance().Facility(); 
     113    InstrumentInfo instr = fac.Instrument(); 
     114    TS_ASSERT_EQUALS(instr.name(),"HRPD"); 
     115  } 
     116 
    92117private: 
    93118