Changeset 5378

Show
Ignore:
Timestamp:
28/07/10 13:11:48 (6 weeks ago)
Author:
Roman Tolchenov
Message:

Included the archive search service into finding files. re #1393

Location:
trunk
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • trunk/Code/Mantid/API/inc/MantidAPI/IArchiveSearch.h

    r5376 r5378  
    77#include "MantidAPI/DllExport.h" 
    88 
     9#include <boost/shared_ptr.hpp> 
    910#include <string> 
    1011 
     
    5960    }; 
    6061 
     62                ///Typedef for a shared pointer to an IArchiveSearch 
     63                typedef boost::shared_ptr<IArchiveSearch> IArchiveSearch_sptr; 
     64 
    6165  } 
    6266} 
  • trunk/Code/Mantid/API/src/FileFinder.cpp

    r5365 r5378  
    33//---------------------------------------------------------------------- 
    44#include "MantidAPI/FileFinder.h" 
     5#include "MantidAPI/IArchiveSearch.h" 
     6#include "MantidAPI/ArchiveSearchFactory.h" 
    57#include "MantidKernel/ConfigService.h" 
    68#include "MantidKernel/FacilityInfo.h" 
    79#include "MantidKernel/InstrumentInfo.h" 
     10#include "MantidKernel/LibraryManager.h" 
     11#include "MantidKernel/Glob.h" 
    812 
    913#include "Poco/Path.h" 
     
    2731    FileFinderImpl::FileFinderImpl() 
    2832    { 
     33      // Make sure plugins are loaded 
     34      std::string libpath = Kernel::ConfigService::Instance().getString("plugins.directory"); 
     35      if( !libpath.empty() ) 
     36      { 
     37        Kernel::LibraryManager::Instance().OpenAllLibraries(libpath); 
     38      } 
    2939    } 
    3040 
     
    4151      for(;it != searchPaths.end(); ++it) 
    4252      { 
    43         Poco::Path path(*it,fName); 
    44         Poco::File file(path); 
    45         if (file.exists()) 
    46         { 
    47           return path.toString(); 
     53        if (fName.find("*") != std::string::npos) 
     54        { 
     55          Poco::Path path(*it,fName); 
     56          Poco::Path pathPattern(path); 
     57          std::set<std::string> files; 
     58          Kernel::Glob::glob(pathPattern, files); 
     59          if ( !files.empty() ) 
     60          { 
     61            return *files.begin(); 
     62          } 
     63        } 
     64        else 
     65        { 
     66          Poco::Path path(*it,fName); 
     67          Poco::File file(path); 
     68          if (file.exists()) 
     69          { 
     70            return path.toString(); 
     71          } 
    4872        } 
    4973      } 
     
    126150        if ( !path.empty() ) return path; 
    127151      } 
     152 
     153      // Search the archive of the default facility 
     154      std::string archiveOpt = Kernel::ConfigService::Instance().getString("datasearch.searcharchive"); 
     155      std::transform(archiveOpt.begin(),archiveOpt.end(),archiveOpt.begin(),tolower); 
     156      if ( !archiveOpt.empty() && archiveOpt != "off" ) 
     157      { 
     158        IArchiveSearch_sptr arch = ArchiveSearchFactory::Instance().create( 
     159          Kernel::ConfigService::Instance().Facility().name() 
     160          ); 
     161        if (arch) 
     162        { 
     163          std::string path = arch->getPath(fName); 
     164          if ( !path.empty() ) 
     165          { 
     166            std::vector<std::string>::const_iterator ext = exts.begin(); 
     167            for(;ext != exts.end(); ++ext) 
     168            { 
     169              Poco::Path pathPattern(path + "." + *ext); 
     170              if (ext->find("*") != std::string::npos) 
     171              { 
     172                continue; 
     173                std::set<std::string> files; 
     174                Kernel::Glob::glob(pathPattern, files); 
     175                std::cerr<<"Searching for:"<<pathPattern.toString()<<'\n'; 
     176                std::cerr<<"Found:"<<files.size()<<'\n'; 
     177              } 
     178              else 
     179              { 
     180                Poco::File file(pathPattern); 
     181                if (file.exists()) 
     182                { 
     183                  return file.path(); 
     184                } 
     185              } 
     186            } 
     187          } 
     188        } 
     189      } 
    128190      return ""; 
    129191    } 
  • trunk/Code/Mantid/API/test/FileFinderTest.h

    r5365 r5378  
    2525    const std::string xmlStr = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" 
    2626      "<facilities>" 
    27       "  <facility name=\"ISIS\" zeropadding=\"5\" FileExtensions=\"nxs,raw,sav,n*,s*\">" 
     27      "  <facility name=\"ISIS\" zeropadding=\"5\" FileExtensions=\"nxs,raw,sav,n*,N*,s*,S*\">" 
    2828      "    <instrument name=\"HRPD\" shortname=\"HRP\">" 
    2929      "      <technique>Powder Diffraction</technique>" 
     
    8585  void testFindFile() 
    8686  { 
     87    ConfigService::Instance().setString("datasearch.searcharchive","Off"); 
    8788    std::string path = FileFinder::Instance().findFile("CSP78173"); 
    8889    TS_ASSERT(path.find("CSP78173.raw") != std::string::npos); 
    8990    Poco::File file(path); 
    9091    TS_ASSERT(file.exists()); 
     92    path = FileFinder::Instance().findFile("HRP37129"); 
     93    std::cerr<<"Path: "<<path<<'\n'; 
     94    TS_ASSERT(path.size() > 3); 
     95    TS_ASSERT_EQUALS(path.substr(path.size()-3),"S02"); 
     96    //ConfigService::Instance().setString("datasearch.searcharchive","On"); 
     97    //path = FileFinder::Instance().findFile("CSP77374"); 
     98    //std::cerr<<"Path: "<<path<<'\n'; 
     99    //path = FileFinder::Instance().findFile("CSP78174"); 
     100    //std::cerr<<"Path: "<<path<<'\n'; 
    91101  } 
    92102 
  • trunk/Code/Mantid/Kernel/src/ConfigService.cpp

    r5365 r5378  
    166166  ConfigServiceImpl::~ConfigServiceImpl() 
    167167  { 
    168     std::cerr << "ConfigService destroyed." << std::endl; 
     168    //std::cerr << "ConfigService destroyed." << std::endl; 
    169169    Kernel::Logger::shutdown(); 
    170170    delete m_pSysConfig; 
  • trunk/Code/Mantid/Properties/Mantid.properties

    r5293 r5378  
    5959datasearch.directories =  
    6060 
     61# Setting this to On enables searching the facilitie's archive automatically 
     62datasearch.searcharchive = Off 
     63 
    6164# A default directory to use for saving files 
    6265# Use forward slash / for all paths 
  • trunk/Test/Instrument/Facilities.xml

    r5331 r5378  
    22<facilities> 
    33 
    4 <facility name="ISIS" zeropadding="5" FileExtensions="nxs,raw,sav,n*,s*"> 
     4<facility name="ISIS" zeropadding="5" FileExtensions="nxs,raw,sav,n*,N*,s*,S*"> 
    55  <archive> 
    66    <archiveSearch plugin="ISISDataSearch" /> 
     
    169169 
    170170<facility name="SNS" FileExtensions="nxs,dat"> 
    171    <instrument name="">  
    172       <technique>technique</technique> 
    173    </instrument>  
    174     
    175171   <instrument name="DAS">  
    176172      <technique>technique</technique>