Skip to content
Snippets Groups Projects
Commit af0089bf authored by Roman Tolchenov's avatar Roman Tolchenov
Browse files

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

parent e7d4f03a
No related branches found
No related tags found
No related merge requests found
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
//---------------------------------------------------------------------- //----------------------------------------------------------------------
#include "MantidAPI/DllExport.h" #include "MantidAPI/DllExport.h"
#include <boost/shared_ptr.hpp>
#include <string> #include <string>
#define DECLARE_ARCHIVESEARCH(classname,facility) \ #define DECLARE_ARCHIVESEARCH(classname,facility) \
...@@ -58,6 +59,9 @@ namespace Mantid ...@@ -58,6 +59,9 @@ namespace Mantid
virtual std::string getPath(const std::string& fName)const = 0; virtual std::string getPath(const std::string& fName)const = 0;
}; };
///Typedef for a shared pointer to an IArchiveSearch
typedef boost::shared_ptr<IArchiveSearch> IArchiveSearch_sptr;
} }
} }
......
...@@ -2,9 +2,13 @@ ...@@ -2,9 +2,13 @@
// Includes // Includes
//---------------------------------------------------------------------- //----------------------------------------------------------------------
#include "MantidAPI/FileFinder.h" #include "MantidAPI/FileFinder.h"
#include "MantidAPI/IArchiveSearch.h"
#include "MantidAPI/ArchiveSearchFactory.h"
#include "MantidKernel/ConfigService.h" #include "MantidKernel/ConfigService.h"
#include "MantidKernel/FacilityInfo.h" #include "MantidKernel/FacilityInfo.h"
#include "MantidKernel/InstrumentInfo.h" #include "MantidKernel/InstrumentInfo.h"
#include "MantidKernel/LibraryManager.h"
#include "MantidKernel/Glob.h"
#include "Poco/Path.h" #include "Poco/Path.h"
#include "Poco/File.h" #include "Poco/File.h"
...@@ -26,6 +30,12 @@ namespace Mantid ...@@ -26,6 +30,12 @@ namespace Mantid
*/ */
FileFinderImpl::FileFinderImpl() FileFinderImpl::FileFinderImpl()
{ {
// Make sure plugins are loaded
std::string libpath = Kernel::ConfigService::Instance().getString("plugins.directory");
if( !libpath.empty() )
{
Kernel::LibraryManager::Instance().OpenAllLibraries(libpath);
}
} }
/** /**
...@@ -40,11 +50,25 @@ namespace Mantid ...@@ -40,11 +50,25 @@ namespace Mantid
std::vector<std::string>::const_iterator it = searchPaths.begin(); std::vector<std::string>::const_iterator it = searchPaths.begin();
for(;it != searchPaths.end(); ++it) for(;it != searchPaths.end(); ++it)
{ {
Poco::Path path(*it,fName); if (fName.find("*") != std::string::npos)
Poco::File file(path); {
if (file.exists()) Poco::Path path(*it,fName);
Poco::Path pathPattern(path);
std::set<std::string> files;
Kernel::Glob::glob(pathPattern, files);
if ( !files.empty() )
{
return *files.begin();
}
}
else
{ {
return path.toString(); Poco::Path path(*it,fName);
Poco::File file(path);
if (file.exists())
{
return path.toString();
}
} }
} }
return ""; return "";
...@@ -125,6 +149,44 @@ namespace Mantid ...@@ -125,6 +149,44 @@ namespace Mantid
std::string path = getFullPath(fName + "." + *ext); std::string path = getFullPath(fName + "." + *ext);
if ( !path.empty() ) return path; if ( !path.empty() ) return path;
} }
// Search the archive of the default facility
std::string archiveOpt = Kernel::ConfigService::Instance().getString("datasearch.searcharchive");
std::transform(archiveOpt.begin(),archiveOpt.end(),archiveOpt.begin(),tolower);
if ( !archiveOpt.empty() && archiveOpt != "off" )
{
IArchiveSearch_sptr arch = ArchiveSearchFactory::Instance().create(
Kernel::ConfigService::Instance().Facility().name()
);
if (arch)
{
std::string path = arch->getPath(fName);
if ( !path.empty() )
{
std::vector<std::string>::const_iterator ext = exts.begin();
for(;ext != exts.end(); ++ext)
{
Poco::Path pathPattern(path + "." + *ext);
if (ext->find("*") != std::string::npos)
{
continue;
std::set<std::string> files;
Kernel::Glob::glob(pathPattern, files);
std::cerr<<"Searching for:"<<pathPattern.toString()<<'\n';
std::cerr<<"Found:"<<files.size()<<'\n';
}
else
{
Poco::File file(pathPattern);
if (file.exists())
{
return file.path();
}
}
}
}
}
}
return ""; return "";
} }
......
...@@ -24,7 +24,7 @@ public: ...@@ -24,7 +24,7 @@ public:
const std::string xmlStr = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" const std::string xmlStr = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
"<facilities>" "<facilities>"
" <facility name=\"ISIS\" zeropadding=\"5\" FileExtensions=\"nxs,raw,sav,n*,s*\">" " <facility name=\"ISIS\" zeropadding=\"5\" FileExtensions=\"nxs,raw,sav,n*,N*,s*,S*\">"
" <instrument name=\"HRPD\" shortname=\"HRP\">" " <instrument name=\"HRPD\" shortname=\"HRP\">"
" <technique>Powder Diffraction</technique>" " <technique>Powder Diffraction</technique>"
" </instrument>" " </instrument>"
...@@ -84,10 +84,20 @@ public: ...@@ -84,10 +84,20 @@ public:
void testFindFile() void testFindFile()
{ {
ConfigService::Instance().setString("datasearch.searcharchive","Off");
std::string path = FileFinder::Instance().findFile("CSP78173"); std::string path = FileFinder::Instance().findFile("CSP78173");
TS_ASSERT(path.find("CSP78173.raw") != std::string::npos); TS_ASSERT(path.find("CSP78173.raw") != std::string::npos);
Poco::File file(path); Poco::File file(path);
TS_ASSERT(file.exists()); TS_ASSERT(file.exists());
path = FileFinder::Instance().findFile("HRP37129");
std::cerr<<"Path: "<<path<<'\n';
TS_ASSERT(path.size() > 3);
TS_ASSERT_EQUALS(path.substr(path.size()-3),"S02");
//ConfigService::Instance().setString("datasearch.searcharchive","On");
//path = FileFinder::Instance().findFile("CSP77374");
//std::cerr<<"Path: "<<path<<'\n';
//path = FileFinder::Instance().findFile("CSP78174");
//std::cerr<<"Path: "<<path<<'\n';
} }
void testFindFiles() void testFindFiles()
......
...@@ -165,7 +165,7 @@ namespace Kernel ...@@ -165,7 +165,7 @@ namespace Kernel
*/ */
ConfigServiceImpl::~ConfigServiceImpl() ConfigServiceImpl::~ConfigServiceImpl()
{ {
std::cerr << "ConfigService destroyed." << std::endl; //std::cerr << "ConfigService destroyed." << std::endl;
Kernel::Logger::shutdown(); Kernel::Logger::shutdown();
delete m_pSysConfig; delete m_pSysConfig;
delete m_pConf; // potential double delete??? delete m_pConf; // potential double delete???
......
...@@ -58,6 +58,9 @@ pythonalgorithms.directories = ../PythonAPI/PythonAlgorithms ...@@ -58,6 +58,9 @@ pythonalgorithms.directories = ../PythonAPI/PythonAlgorithms
# Use forward slash / for all paths # Use forward slash / for all paths
datasearch.directories = datasearch.directories =
# Setting this to On enables searching the facilitie's archive automatically
datasearch.searcharchive = Off
# A default directory to use for saving files # A default directory to use for saving files
# Use forward slash / for all paths # Use forward slash / for all paths
defaultsave.directory = defaultsave.directory =
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment