Skip to content

Commit

Permalink
Refs #6123 -- integrated SNS ICAT4 into mantid for archive search
Browse files Browse the repository at this point in the history
  • Loading branch information
Shelly-Ren committed Dec 6, 2012
1 parent 073844d commit 2df5920
Show file tree
Hide file tree
Showing 17 changed files with 412 additions and 285 deletions.
3 changes: 2 additions & 1 deletion Code/Mantid/Framework/API/inc/MantidAPI/FileFinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ namespace Mantid
FileFinderImpl& operator=(const FileFinderImpl&);
std::string extractAllowedSuffix(std::string & userString) const;
std::pair<std::string,std::string> toInstrumentAndNumber(const std::string& hint)const;
std::string getArchivePath(const std::vector<IArchiveSearch_sptr>& archs, const std::string& fName)const;
std::string getArchivePath(const std::vector<IArchiveSearch_sptr>& archs, const std::set<std::string>& filenames, const std::vector<std::string>& exts)const;
std::string toUpper(const std::string &src) const;
/// glob option - set to case sensitive or insensitive
int globOption;

Expand Down
9 changes: 6 additions & 3 deletions Code/Mantid/Framework/API/inc/MantidAPI/IArchiveSearch.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

#include <boost/shared_ptr.hpp>
#include <string>
#include <vector>
#include <set>


#define DECLARE_ARCHIVESEARCH(classname,facility) \
namespace { \
Expand Down Expand Up @@ -56,11 +59,11 @@ namespace Mantid
* Return the full path to a data file in an archive
* @param fName :: The file name
*/
virtual std::string getPath(const std::string& fName)const = 0;
virtual std::string getArchivePath(const std::set<std::string>& filenames, const std::vector<std::string>& exts)const = 0;
};

///Typedef for a shared pointer to an IArchiveSearch
typedef boost::shared_ptr<IArchiveSearch> IArchiveSearch_sptr;
///Typedef for a shared pointer to an IArchiveSearch
typedef boost::shared_ptr<IArchiveSearch> IArchiveSearch_sptr;

}
}
Expand Down
71 changes: 37 additions & 34 deletions Code/Mantid/Framework/API/src/FileFinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,13 @@ namespace Mantid

// get facility from the FacilityInfo
const Kernel::FacilityInfo facility = this->getFacility(hint);
// get facility extensions
const std::vector<std::string> facility_extensions = facility.extensions();
// select allowed extensions
std::vector < std::string > extensions;

g_log.debug() << "Add facility extensions defined in the Facility.xml file" << "\n";
extensions.assign(facility_extensions.begin(), facility_extensions.end());

// initialize the archive searcher
std::vector<IArchiveSearch_sptr> archs;
Expand All @@ -397,11 +404,15 @@ namespace Mantid
std::string extension;
if (hintPath.depth() == 0)
{
std::size_t i = filename.find_last_of('.');
if (i != std::string::npos)
for (std::vector<std::string>::iterator it = extensions.begin() ; it != extensions.end(); ++it)
{
extension = filename.substr(i);
filename.erase(i);
std::size_t found = toUpper(filename).rfind(toUpper(*it));
if (found != std::string::npos)
{
extension = filename.substr(found);
filename.erase(found);
break;
}
}
try
{
Expand Down Expand Up @@ -456,13 +467,7 @@ namespace Mantid
}
}

// work through the extensions
const std::vector<std::string> facility_extensions = facility.extensions();
// select allowed extensions
std::vector < std::string > extensions;

g_log.debug() << "Add facility extensions defined in the Facility.xml file" << "\n";
extensions.assign(facility_extensions.begin(), facility_extensions.end());
std::string path = getPath(archs, filenames, extensions);
if (!path.empty())
{
Expand Down Expand Up @@ -583,16 +588,15 @@ namespace Mantid
* @return The full path if the file exists and can be found in one of the search locations
* or an empty string otherwise.
*/
std::string FileFinderImpl::getArchivePath(const std::vector<IArchiveSearch_sptr>& archs, const std::string& fName) const
std::string FileFinderImpl::getArchivePath(const std::vector<IArchiveSearch_sptr>& archs, const std::set<std::string>& filenames, const std::vector<std::string>& exts) const
{
g_log.debug() << "getArchivePath(" << fName << ")\n";
std::string path = "";
std::vector<IArchiveSearch_sptr>::const_iterator it = archs.begin();
for (; it != archs.end(); ++it)
{
try
{
path = (*it)->getPath(fName);
path = (*it)->getArchivePath(filenames, exts);
if (!path.empty())
{
return path;
Expand Down Expand Up @@ -626,7 +630,7 @@ namespace Mantid
Kernel::ConfigService::Instance().getDataSearchDirs();

// Before we try any globbing, make sure we exhaust all reasonable attempts at constructing the possible filename.
// Avoiding the globbing of getFullPath() for as long as possible will help performance when calling findRuns()
// Avoiding the globbing of getFullPath() for as long as possible will help performance when calling findRuns()
// with a large range of files, especially when searchPaths consists of folders containing a large number of runs.
for(auto ext = extensions.begin(); ext != extensions.end(); ++ext)
{
Expand Down Expand Up @@ -672,33 +676,32 @@ namespace Mantid
if (archs.size() != 0 )
{
g_log.debug() << "Search the archive of the default facility" << "\n";
std::string path = "";
std::vector<std::string>::const_iterator ext = extensions.begin();
for (; ext != extensions.end(); ++ext)
std::string path = getArchivePath(archs, filenames, exts);
try
{
std::set<std::string>::const_iterator it = filenames.begin();
for(; it!=filenames.end(); ++it)
if (!path.empty() && Poco::File(path).exists())
{
path = getArchivePath(archs, *it + *ext);
try
{
if (!path.empty() && Poco::File(path).exists())
{
return path;
}
}
catch(std::exception& e)
{
g_log.error() << "Cannot open file " << path << ": " << e.what() << '\n';
return "";
}
} // it
} // ext
return path;
}
}
catch(std::exception& e)
{
g_log.error() << "Cannot open file " << path << ": " << e.what() << '\n';
return "";
}

} // archs

return "";
}

std::string FileFinderImpl::toUpper(const std::string &src) const
{
std::string result = src;
std::transform(result.begin(),result.end(),result.begin(),toupper);
return result;
}

}// API
}// Mantid

9 changes: 7 additions & 2 deletions Code/Mantid/Framework/API/test/FileFinderTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,13 @@ class FileFinderTest: public CxxTest::TestSuite
TS_ASSERT(file.exists());

path = FileFinder::Instance().findRun("OFFSPEC4622.log");
TS_ASSERT(path.size() > 3);
TS_ASSERT_EQUALS(path.substr(path.size() - 3), "log");
// Per discussion with Martyn on Dec 6, 2012: we decided to update this test case.
// *.log is not a valid extension for ISIS instruments. Since we modified the FileFinder to strip
// the extension using the facility extension list rather than to strip the extension after the last dot,
// the returned path should be empty now.
TS_ASSERT(path.empty() == true);
// TS_ASSERT(path.size() > 3);
// TS_ASSERT_EQUALS(path.substr(path.size() - 3), "log");
}

void testFindRunsDefaultInst()
Expand Down
6 changes: 3 additions & 3 deletions Code/Mantid/Framework/DataHandling/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,13 @@ set ( SRC_FILES
src/MonitorLiveData.cpp
src/MoveInstrumentComponent.cpp
src/NexusTester.cpp
src/OrbiterDataArchive.cpp
src/ProcessDasNexusLog.cpp
src/RawFileInfo.cpp
src/RemoveLogs.cpp
src/RenameLog.cpp
src/RotateInstrumentComponent.cpp
src/SNSDataArchive.cpp
src/SNSDataArchiveICAT2.cpp
src/SNSLiveEventDataListener.cpp
src/SaveAscii.cpp
src/SaveCSV.cpp
Expand Down Expand Up @@ -231,13 +231,13 @@ set ( INC_FILES
inc/MantidDataHandling/MonitorLiveData.h
inc/MantidDataHandling/MoveInstrumentComponent.h
inc/MantidDataHandling/NexusTester.h
inc/MantidDataHandling/OrbiterDataArchive.h
inc/MantidDataHandling/ProcessDasNexusLog.h
inc/MantidDataHandling/RawFileInfo.h
inc/MantidDataHandling/RemoveLogs.h
inc/MantidDataHandling/RenameLog.h
inc/MantidDataHandling/RotateInstrumentComponent.h
inc/MantidDataHandling/SNSDataArchive.h
inc/MantidDataHandling/SNSDataArchiveICAT2.h
inc/MantidDataHandling/SNSLiveEventDataListener.h
inc/MantidDataHandling/SaveAscii.h
inc/MantidDataHandling/SaveCSV.h
Expand Down Expand Up @@ -356,12 +356,12 @@ set ( TEST_FILES
MonitorLiveDataTest.h
MoveInstrumentComponentTest.h
NexusTesterTest.h
OrbiterDataArchiveTest.h
ProcessDasNexusLogTest.h
RawFileInfoTest.h
RemoveLogsTest.h
RenameLogTest.h
SNSDataArchiveTest.h
SNSDataArchiveICAT2Test.h
SaveAsciiTest.h
SaveCSVTest.h
SaveCalFileTest.h
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@

namespace Mantid
{
namespace Kernel
{
class Logger;
}
namespace DataHandling
{

Expand Down Expand Up @@ -43,9 +47,12 @@ namespace Mantid
class DLLExport ISISDataArchive: public API::IArchiveSearch
{
public:
std::string getArchivePath(const std::set<std::string>& filenames, const std::vector<std::string>& exts)const;
private:
// static reference to the logger class
static Mantid::Kernel::Logger & g_log;
std::string getPath(const std::string& fName)const;
};

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ class Logger;
class DLLExport SNSDataArchive: public API::IArchiveSearch
{
public:
std::string getPath(const std::string& fName) const;
//std::string getPath(const std::string& fName) const;
std::string getArchivePath(const std::set<std::string>& filenames, const std::vector<std::string>& exts) const;
private:
// static reference to the logger class
static Mantid::Kernel::Logger & g_log;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef MANTID_DATAHANDLING_ORBITERDATAARCHIVE_H_
#define MANTID_DATAHANDLING_ORBITERDATAARCHIVE_H_
#ifndef MANTID_DATAHANDLING_SNSDATAARCHIVEICAT2_H_
#define MANTID_DATAHANDLING_SNSDATAARCHIVEICAT2_H_

//----------------------------------------------------------------------
// Includes
Expand All @@ -22,10 +22,10 @@ class Logger;
namespace DataHandling
{
/**
This class is for searching the Orbiter data archive
This class is for searching the SNS data archive
@author Stuart Campbell, ORNL
@date 18/03/2010
@author Shelly Ren, ORNL
@date 02/22/2012
Copyright &copy; 2010 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
Expand All @@ -48,16 +48,17 @@ class Logger;
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/

class DLLExport OrbiterDataArchive: public API::IArchiveSearch
class DLLExport SNSDataArchiveICAT2: public API::IArchiveSearch
{
public:
std::string getPath(const std::string& fName) const;
std::string getArchivePath(const std::set<std::string>& filenames, const std::vector<std::string>& exts) const;
private:
// static reference to the logger class
std::string getPath(const std::string& fName) const;
static Mantid::Kernel::Logger & g_log;
};

}
}

#endif /* MANTID_DATAHANDLING_ORBITERDATAARCHIVE_H_ */
#endif /* MANTID_DATAHANDLING_SNSDATAARCHIVEICAT2_H_ */
46 changes: 45 additions & 1 deletion Code/Mantid/Framework/DataHandling/src/ISISDataArchive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
#include <Poco/Net/HTTPRequest.h>
#include <Poco/Net/HTTPResponse.h>
#include <Poco/URI.h>
#include <Poco/Path.h>
#include <Poco/File.h>
#include <Poco/StringTokenizer.h>
#include <Poco/Exception.h>

#include <iostream>

Expand All @@ -21,14 +25,16 @@ namespace Mantid
{
namespace DataHandling
{

Mantid::Kernel::Logger & ISISDataArchive::g_log = Mantid::Kernel::Logger::get("ISISDataArchive");
DECLARE_ARCHIVESEARCH(ISISDataArchive,ISISDataSearch);


/**
* Calls a web service to get a full path to a file
* @param fName :: The file name.
* @return The path to the file or empty string in case of error.
*/

std::string ISISDataArchive::getPath(const std::string& fName)const
{
#ifdef _WIN32
Expand Down Expand Up @@ -74,5 +80,43 @@ std::string ISISDataArchive::getPath(const std::string& fName)const
return out;
}

std::string ISISDataArchive::getArchivePath(const std::set<std::string>& filenames, const std::vector<std::string>& exts)const
{
std::set<std::string>::const_iterator iter = filenames.begin();
for(; iter!=filenames.end(); ++iter)
{
g_log.debug() << *iter << ")\n";
}
std::vector<std::string>::const_iterator iter2 = exts.begin();
for(; iter2!=exts.end(); ++iter2)
{
g_log.debug() << *iter2 << ")\n";
}

std::vector<std::string>::const_iterator ext = exts.begin();
for (; ext != exts.end(); ++ext)
{
std::set<std::string>::const_iterator it = filenames.begin();
for(; it!=filenames.end(); ++it)
{
std::string path;
path = getPath(*it + *ext);
try
{
if (!path.empty() && Poco::File(path).exists())
{
return path;
}
}
catch(std::exception& e)
{
g_log.error() << "Cannot open file " << path << ": " << e.what() << '\n';
return "";
}
} // it
} // ext
return "";
}

} // namespace DataHandling
} // namespace Mantid

0 comments on commit 2df5920

Please sign in to comment.