Changeset 5378
- Timestamp:
- 28/07/10 13:11:48 (6 weeks ago)
- Location:
- trunk
- Files:
-
- 6 modified
-
Code/Mantid/API/inc/MantidAPI/IArchiveSearch.h (modified) (2 diffs)
-
Code/Mantid/API/src/FileFinder.cpp (modified) (4 diffs)
-
Code/Mantid/API/test/FileFinderTest.h (modified) (2 diffs)
-
Code/Mantid/Kernel/src/ConfigService.cpp (modified) (1 diff)
-
Code/Mantid/Properties/Mantid.properties (modified) (1 diff)
-
Test/Instrument/Facilities.xml (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Code/Mantid/API/inc/MantidAPI/IArchiveSearch.h
r5376 r5378 7 7 #include "MantidAPI/DllExport.h" 8 8 9 #include <boost/shared_ptr.hpp> 9 10 #include <string> 10 11 … … 59 60 }; 60 61 62 ///Typedef for a shared pointer to an IArchiveSearch 63 typedef boost::shared_ptr<IArchiveSearch> IArchiveSearch_sptr; 64 61 65 } 62 66 } -
trunk/Code/Mantid/API/src/FileFinder.cpp
r5365 r5378 3 3 //---------------------------------------------------------------------- 4 4 #include "MantidAPI/FileFinder.h" 5 #include "MantidAPI/IArchiveSearch.h" 6 #include "MantidAPI/ArchiveSearchFactory.h" 5 7 #include "MantidKernel/ConfigService.h" 6 8 #include "MantidKernel/FacilityInfo.h" 7 9 #include "MantidKernel/InstrumentInfo.h" 10 #include "MantidKernel/LibraryManager.h" 11 #include "MantidKernel/Glob.h" 8 12 9 13 #include "Poco/Path.h" … … 27 31 FileFinderImpl::FileFinderImpl() 28 32 { 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 } 29 39 } 30 40 … … 41 51 for(;it != searchPaths.end(); ++it) 42 52 { 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 } 48 72 } 49 73 } … … 126 150 if ( !path.empty() ) return path; 127 151 } 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 } 128 190 return ""; 129 191 } -
trunk/Code/Mantid/API/test/FileFinderTest.h
r5365 r5378 25 25 const std::string xmlStr = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" 26 26 "<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*\">" 28 28 " <instrument name=\"HRPD\" shortname=\"HRP\">" 29 29 " <technique>Powder Diffraction</technique>" … … 85 85 void testFindFile() 86 86 { 87 ConfigService::Instance().setString("datasearch.searcharchive","Off"); 87 88 std::string path = FileFinder::Instance().findFile("CSP78173"); 88 89 TS_ASSERT(path.find("CSP78173.raw") != std::string::npos); 89 90 Poco::File file(path); 90 91 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'; 91 101 } 92 102 -
trunk/Code/Mantid/Kernel/src/ConfigService.cpp
r5365 r5378 166 166 ConfigServiceImpl::~ConfigServiceImpl() 167 167 { 168 std::cerr << "ConfigService destroyed." << std::endl;168 //std::cerr << "ConfigService destroyed." << std::endl; 169 169 Kernel::Logger::shutdown(); 170 170 delete m_pSysConfig; -
trunk/Code/Mantid/Properties/Mantid.properties
r5293 r5378 59 59 datasearch.directories = 60 60 61 # Setting this to On enables searching the facilitie's archive automatically 62 datasearch.searcharchive = Off 63 61 64 # A default directory to use for saving files 62 65 # Use forward slash / for all paths -
trunk/Test/Instrument/Facilities.xml
r5331 r5378 2 2 <facilities> 3 3 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*"> 5 5 <archive> 6 6 <archiveSearch plugin="ISISDataSearch" /> … … 169 169 170 170 <facility name="SNS" FileExtensions="nxs,dat"> 171 <instrument name="">172 <technique>technique</technique>173 </instrument>174 175 171 <instrument name="DAS"> 176 172 <technique>technique</technique>
