Skip to content

Commit

Permalink
Add ability to restrict path search in HDF file by type.
Browse files Browse the repository at this point in the history
Refs #7263
  • Loading branch information
martyngigg committed Jun 29, 2013
1 parent 9b88551 commit eb79a4e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Code/Mantid/Framework/Kernel/inc/MantidKernel/HDFDescriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ namespace Mantid

/// Query if a path exists
bool pathExists(const std::string& path) const;
/// Query if a path exists of a given type
bool pathOfTypeExists(const std::string& path, const std::string &type) const;
/// Query if a given type exists somewhere in the file
bool classTypeExists(const std::string & classType) const;

Expand Down
16 changes: 16 additions & 0 deletions Code/Mantid/Framework/Kernel/src/HDFDescriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,22 @@ namespace Mantid
return false;
}

/**
* @param path A string giving a path using UNIX-style path separators (/), e.g. /raw_data_1, /entry/bank1
* @param type A string specifying the required type
* @return True if the path exists in the file, false otherwise
*/
bool HDFDescriptor::pathOfTypeExists(const std::string& path, const std::string & type) const
{
auto it = m_typesToPaths->lower_bound(type);
auto itend = m_typesToPaths->upper_bound(type);
for(; it != itend; ++it)
{
if(it->second == path) return true;
}
return false;
}

/**
* @param classType A string name giving a class type
* @return True if the type exists in the file, false otherwise
Expand Down
12 changes: 12 additions & 0 deletions Code/Mantid/Framework/Kernel/test/HDFDescriptorTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,18 @@ class HDFDescriptorTest : public CxxTest::TestSuite
TS_ASSERT(m_testHDF5->pathExists("/entry/bank1/data_x_y"));
}

void test_PathOfTypeExists_Returns_True_For_Path_Of_Right_Type_At_Any_Level_In_File()
{
TS_ASSERT(m_testHDF5->pathOfTypeExists("/entry","NXentry"));
TS_ASSERT(m_testHDF5->pathOfTypeExists("/entry/bank1_events","NXevent_data"));
}

void test_PathOfTypeExists_Returns_False_For_Path_In_File_But_Of_Wrong_Type()
{
TS_ASSERT(!m_testHDF5->pathOfTypeExists("/entry","NXlog"));
TS_ASSERT(!m_testHDF5->pathOfTypeExists("/entry/bank1_events","NXentry"));
}

void test_classTypeExists_Returns_True_For_Type_At_Any_Level_In_File()
{
TS_ASSERT(m_testHDF5->classTypeExists("NXentry"));
Expand Down

0 comments on commit eb79a4e

Please sign in to comment.