Skip to content

Commit

Permalink
Allow stored NeXus handle to be use in ::confidence checks. Refs #7263
Browse files Browse the repository at this point in the history
  • Loading branch information
martyngigg committed Jul 3, 2013
1 parent 19119d5 commit 7aad82f
Show file tree
Hide file tree
Showing 37 changed files with 74 additions and 54 deletions.
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/API/inc/MantidAPI/IHDFFileLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace Mantid
{
public:
/// Returns a confidence value that this algorithm can load a file
virtual int confidence(const Kernel::HDFDescriptor & descriptor) const = 0;
virtual int confidence(Kernel::HDFDescriptor & descriptor) const = 0;
};

} // namespace API
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ namespace Mantid
virtual const std::string category() const { return "DataHandling\\Nexus";}

/// Returns a confidence value that this algorithm can load a file
int confidence(const Kernel::HDFDescriptor & descriptor) const;
int confidence(Kernel::HDFDescriptor & descriptor) const;

/** Sets whether the pixel counts will be pre-counted.
* @param value :: true if you want to precount. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ namespace DataHandling {
}

/// Returns a confidence value that this algorithm can load a file
int confidence(const Kernel::HDFDescriptor & descriptor) const;
int confidence(Kernel::HDFDescriptor & descriptor) const;

private:
/// Sets documentation strings for this algorithm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ namespace Mantid
virtual const std::string category() const { return "DataHandling\\Nexus"; }

/// Returns a confidence value that this algorithm can load a file
virtual int confidence(const Kernel::HDFDescriptor & descriptor) const;
virtual int confidence(Kernel::HDFDescriptor & descriptor) const;

/// Spectra block descriptor
struct SpectraBlock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class DLLExport LoadLLB: public API::IHDFFileLoader {
virtual const std::string category() const;

/// Returns a confidence value that this algorithm can load a file
virtual int confidence(const Kernel::HDFDescriptor & descriptor) const;
virtual int confidence(Kernel::HDFDescriptor & descriptor) const;

private:
virtual void initDocs();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace DataHandling
virtual const std::string category() const;

/// Returns a confidence value that this algorithm can load a file
virtual int confidence(const Kernel::HDFDescriptor & descriptor) const;
virtual int confidence(Kernel::HDFDescriptor & descriptor) const;

private:
virtual void initDocs();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ namespace Mantid
virtual const std::string category() const { return "DataHandling\\Nexus;Muon"; }

/// Returns a confidence value that this algorithm can load a file
virtual int confidence(const Kernel::HDFDescriptor & descriptor) const;
virtual int confidence(Kernel::HDFDescriptor &) const;

protected:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ namespace Mantid
virtual const std::string category() const { return "DataHandling\\Nexus;Muon"; }

/// Returns a confidence value that this algorithm can load a file
virtual int confidence(const Kernel::HDFDescriptor & descriptor) const;
virtual int confidence(Kernel::HDFDescriptor & descriptor) const;

protected:
/// Overwrites Algorithm method
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ namespace Mantid
virtual const std::string category() const { return "DataHandling\\Nexus;Muon"; }

/// Returns a confidence value that this algorithm can load a file
virtual int confidence(const Kernel::HDFDescriptor & descriptor) const;
virtual int confidence(Kernel::HDFDescriptor & descriptor) const;

private:
/// Sets documentation strings for this algorithm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ namespace DataHandling
virtual const std::string category() const { return "DataHandling\\Nexus;DataHandling\\SPE;Inelastic";}

/// Returns a confidence value that this algorithm can load a file
virtual int confidence(const Kernel::HDFDescriptor & descriptor) const;
virtual int confidence(Kernel::HDFDescriptor & descriptor) const;

private:
/// Sets documentation strings for this algorithm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ namespace Mantid
virtual const std::string category() const { return "DataHandling\\Nexus";}

/// Returns a confidence value that this algorithm can load a file
virtual int confidence(const Kernel::HDFDescriptor & descriptor) const;
virtual int confidence(Kernel::HDFDescriptor & descriptor) const;

private:
/// Sets documentation strings for this algorithm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class DLLExport LoadQKK : public API::IHDFFileLoader
virtual const std::string category() const { return "DataHandling"; }

/// Returns a confidence value that this algorithm can load a file
virtual int confidence(const Kernel::HDFDescriptor & descriptor) const;
virtual int confidence(Kernel::HDFDescriptor & descriptor) const;

private:
/// Sets documentation strings for this algorithm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class DLLExport LoadSINQ: public API::IHDFFileLoader
virtual const std::string category() const;

/// Returns a confidence value that this algorithm can load a file
virtual int confidence(const Kernel::HDFDescriptor & descriptor) const;
virtual int confidence(Kernel::HDFDescriptor & descriptor) const;

private:
virtual void initDocs();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ namespace Mantid
virtual const std::string category() const { return "Deprecated"; }

/// Returns a confidence value that this algorithm can load a file (Required by base class)
virtual int confidence(const Kernel::HDFDescriptor &) const { return 0; }
virtual int confidence(Kernel::HDFDescriptor &) const { return 0; }
};

} // namespace DataHandling
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ namespace Mantid
virtual const std::string category() const { return "DataHandling\\Sassena"; }

/// Returns a confidence value that this algorithm can load a file
virtual int confidence(const Kernel::HDFDescriptor & descriptor) const;
virtual int confidence(Kernel::HDFDescriptor & descriptor) const;

protected:
/// Add a workspace to the group and register in the analysis data service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class DLLExport LoadTOFRawNexus : public API::IHDFFileLoader
static std::string getEntryName(const std::string & filename);

/// Returns a confidence value that this algorithm can load a file
virtual int confidence(const Kernel::HDFDescriptor & descriptor) const;
virtual int confidence(Kernel::HDFDescriptor & descriptor) const;

void countPixels(const std::string &nexusfilename, const std::string & entry_name,
std::vector<std::string> & bankNames);
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/DataHandling/src/LoadEventNexus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,7 @@ LoadEventNexus::~LoadEventNexus()
* @param descriptor A descriptor for the file
* @returns An integer specifying the confidence level. 0 indicates it will not be used
*/
int LoadEventNexus::confidence(const Kernel::HDFDescriptor & descriptor) const
int LoadEventNexus::confidence(Kernel::HDFDescriptor & descriptor) const
{
int confidence(0);
if(descriptor.classTypeExists("NXevent_data"))
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/DataHandling/src/LoadILL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ namespace Mantid {
* @param descriptor A descriptor for the file
* @returns An integer specifying the confidence level. 0 indicates it will not be used
*/
int LoadILL::confidence(const Kernel::HDFDescriptor & descriptor) const
int LoadILL::confidence(Kernel::HDFDescriptor & descriptor) const
{
const std::string root = "/" + descriptor.firstEntryNameType().first + "/";
for(auto it = supportedInstruments.begin(); it != supportedInstruments.end() ; ++it)
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ namespace Mantid
* @param descriptor A descriptor for the file
* @returns An integer specifying the confidence level. 0 indicates it will not be used
*/
int LoadISISNexus2::confidence(const Kernel::HDFDescriptor & descriptor) const
int LoadISISNexus2::confidence(Kernel::HDFDescriptor & descriptor) const
{
if(descriptor.pathOfTypeExists("/raw_data_1","NXentry")) return 80;
return 0;
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/DataHandling/src/LoadLLB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const std::string LoadLLB::category() const {
* @param descriptor A descriptor for the file
* @returns An integer specifying the confidence level. 0 indicates it will not be used
*/
int LoadLLB::confidence(const Kernel::HDFDescriptor & descriptor) const
int LoadLLB::confidence(Kernel::HDFDescriptor & descriptor) const
{
const auto & firstEntry = descriptor.firstEntryNameType();
if(descriptor.pathExists("/" + firstEntry.first + "/nxinstrument/name")) return 80;
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/DataHandling/src/LoadMcStasNexus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ namespace DataHandling
* @param descriptor A descriptor for the file
* @returns An integer specifying the confidence level. 0 indicates it will not be used
*/
int LoadMcStasNexus::confidence(const Kernel::HDFDescriptor & descriptor) const
int LoadMcStasNexus::confidence(Kernel::HDFDescriptor & descriptor) const
{
using namespace ::NeXus;
// We will look at the first entry and check for a
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/DataHandling/src/LoadMuonNexus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ namespace Mantid
* @param descriptor A descriptor for the file
* @returns An integer specifying the confidence level. 0 indicates it will not be used
*/
int LoadMuonNexus::confidence(const Kernel::HDFDescriptor &) const
int LoadMuonNexus::confidence(Kernel::HDFDescriptor &) const
{
return 0; // Not to be used but LoadMuonNexus2, which inherits from this will
}
Expand Down
18 changes: 11 additions & 7 deletions Code/Mantid/Framework/DataHandling/src/LoadMuonNexus1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ namespace Mantid
* @param descriptor A descriptor for the file
* @returns An integer specifying the confidence level. 0 indicates it will not be used
*/
int LoadMuonNexus1::confidence(const Kernel::HDFDescriptor & descriptor) const
int LoadMuonNexus1::confidence(Kernel::HDFDescriptor & descriptor) const
{
const auto & firstEntryNameType = descriptor.firstEntryNameType();
const std::string root = "/" + firstEntryNameType.first;
Expand All @@ -655,20 +655,24 @@ namespace Mantid

try
{
NXRoot root(descriptor.filename());
NXEntry entry = root.openFirstEntry();
std::string versionField = "idf_version";
if(upperIDF) versionField = "IDF_version";

if ( entry.getInt( versionField ) != 1 ) return 0;
std::string definition = entry.getString( "analysis" );
if ( definition == "muonTD" || definition == "pulsedTD" )
auto &file = descriptor.data();
file.openPath(root + "/" + versionField);
int32_t version = 0;
file.getData(&version);
if ( version != 1 ) return 0;

file.openPath(root + "/analysis");
std::string def = file.getStrData();
if (def == "muonTD" || def == "pulsedTD")
{
// If all this succeeded then we'll assume this is an ISIS Muon NeXus file version 2
return 81;
}
}
catch( ... )
catch(...)
{
}
return 0;
Expand Down
22 changes: 13 additions & 9 deletions Code/Mantid/Framework/DataHandling/src/LoadMuonNexus2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,9 @@ namespace Mantid
std::string filePath = getPropertyValue("Filename");
LoadMuonNexus1 load1; load1.initialize();

int confidence1 = load1.confidence( filePath );
int confidence2 = this->confidence( filePath );
Kernel::HDFDescriptor descriptor(filePath);
int confidence1 = load1.confidence(descriptor);
int confidence2 = this->confidence(descriptor);

// if none can load the file throw
if ( confidence1 < 80 && confidence2 < 80)
Expand Down Expand Up @@ -487,7 +488,7 @@ namespace Mantid
* @param descriptor A descriptor for the file
* @returns An integer specifying the confidence level. 0 indicates it will not be used
*/
int LoadMuonNexus2::confidence(const Kernel::HDFDescriptor & descriptor) const
int LoadMuonNexus2::confidence(Kernel::HDFDescriptor & descriptor) const
{
const auto & firstEntryNameType = descriptor.firstEntryNameType();
const std::string root = "/" + firstEntryNameType.first;
Expand All @@ -503,15 +504,18 @@ namespace Mantid

try
{
NXRoot root(descriptor.filename());
NXEntry entry = root.openFirstEntry();

std::string versionField = "idf_version";
if(upperIDF) versionField = "IDF_version";

if ( entry.getInt(versionField) != 2 ) return 0;
std::string definition = entry.getString("definition");
if ( definition == "muonTD" || definition == "pulsedTD" )
auto &file = descriptor.data();
file.openPath(root + "/" + versionField);
int32_t version = 0;
file.getData(&version);
if ( version != 2 ) return 0;

file.openPath(root + "/definition");
std::string def = file.getStrData();
if ( def == "muonTD" || def == "pulsedTD" )
{
// If all this succeeded then we'll assume this is an ISIS Muon NeXus file version 2
return 81;
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/DataHandling/src/LoadNXSPE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ namespace DataHandling
* @param descriptor A descriptor for the file
* @returns An integer specifying the confidence level. 0 indicates it will not be used
*/
int LoadNXSPE::confidence(const Kernel::HDFDescriptor & descriptor) const
int LoadNXSPE::confidence(Kernel::HDFDescriptor & descriptor) const
{
int confidence(0);
typedef std::map<std::string,std::string> string_map_t;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ LoadNexusProcessed::~LoadNexusProcessed()
* @param descriptor A descriptor for the file
* @returns An integer specifying the confidence level. 0 indicates it will not be used
*/
int LoadNexusProcessed::confidence(const Kernel::HDFDescriptor & descriptor) const
int LoadNexusProcessed::confidence(Kernel::HDFDescriptor & descriptor) const
{
if(descriptor.pathExists("/mantid_workspace_1")) return 80;
else return 0;
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/DataHandling/src/LoadQKK.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace Mantid
* @param descriptor A descriptor for the file
* @returns An integer specifying the confidence level. 0 indicates it will not be used
*/
int LoadQKK::confidence(const Kernel::HDFDescriptor & descriptor) const
int LoadQKK::confidence(Kernel::HDFDescriptor & descriptor) const
{
const auto & firstEntryName = descriptor.firstEntryNameType().first;
if(descriptor.pathExists("/" + firstEntryName + "/data/hmm_xy")) return 80;
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/DataHandling/src/LoadSINQ.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void LoadSINQ::initDocs() {
* @param descriptor A descriptor for the file
* @returns An integer specifying the confidence level. 0 indicates it will not be used
*/
int LoadSINQ::confidence(const Kernel::HDFDescriptor & descriptor) const
int LoadSINQ::confidence(Kernel::HDFDescriptor & descriptor) const
{
const std::string root = "/" + descriptor.firstEntryNameType().first + "/";
for(auto it = supportedInstruments.begin(); it != supportedInstruments.end() ; ++it)
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/DataHandling/src/LoadSassena.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void LoadSassena::initDocs()
* @param descriptor A descriptor for the file
* @returns An integer specifying the confidence level. 0 indicates it will not be used
*/
int LoadSassena::confidence(const Kernel::HDFDescriptor & descriptor) const
int LoadSassena::confidence(Kernel::HDFDescriptor & descriptor) const
{
if(descriptor.hasRootAttr("sassena_version")) return 99;
return 0;
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/DataHandling/src/LoadTOFRawNexus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void LoadTOFRawNexus::init()
* @param descriptor A descriptor for the file
* @returns An integer specifying the confidence level. 0 indicates it will not be used
*/
int LoadTOFRawNexus::confidence(const Kernel::HDFDescriptor & descriptor) const
int LoadTOFRawNexus::confidence(Kernel::HDFDescriptor & descriptor) const
{
int confidence(0);
if( descriptor.pathOfTypeExists("/entry", "NXentry") ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,10 @@ namespace Mantid
if(HDFDescriptor::isHDF(filename))
{
LoadISISNexus2 isisNexus;
if(isisNexus.confidence(filename) > 0)
auto *descriptor = new Kernel::HDFDescriptor(filename);
if(isisNexus.confidence(*descriptor) > 0)
{
delete descriptor;
updateFromNeXus(filename);
return;
}
Expand Down
4 changes: 2 additions & 2 deletions Code/Mantid/Framework/DataHandling/test/LoadQKKTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class LoadQKKTest : public CxxTest::TestSuite
Mantid::DataHandling::LoadQKK loader;
loader.initialize();
loader.setPropertyValue("Filename", "QKK0029775.nx.hdf"); // find the full path

TS_ASSERT_EQUALS(80, loader.confidence(loader.getPropertyValue("Filename")));
Mantid::Kernel::HDFDescriptor descr(loader.getPropertyValue("Filename"));
TS_ASSERT_EQUALS(80, loader.confidence(descr));
}

void testInit()
Expand Down
3 changes: 2 additions & 1 deletion Code/Mantid/Framework/DataHandling/test/LoadSassenaTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ class LoadSassenaTest : public CxxTest::TestSuite
{
if( !m_alg.isInitialized() ) m_alg.initialize();
m_alg.setPropertyValue( "Filename", m_inputFile );
TS_ASSERT_EQUALS(m_alg.confidence(m_alg.getPropertyValue("Filename")), 99);
Mantid::Kernel::HDFDescriptor descr(m_alg.getPropertyValue("Filename"));
TS_ASSERT_EQUALS(m_alg.confidence(descr), 99);
}

void test_exec()
Expand Down
16 changes: 12 additions & 4 deletions Code/Mantid/Framework/DataHandling/test/LoadTOFRawNexusTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,22 @@ class LoadTOFRawNexusTest: public CxxTest::TestSuite
{
LoadTOFRawNexus alg;
TS_ASSERT_THROWS_NOTHING( alg.initialize() );

alg.setPropertyValue("Filename", "REF_L_32035.nxs");
TS_ASSERT_EQUALS( alg.confidence(alg.getPropertyValue("Filename")), 80 );
Mantid::Kernel::HDFDescriptor descr(alg.getPropertyValue("Filename"));
TS_ASSERT_EQUALS( alg.confidence(descr), 80 );

alg.setPropertyValue("Filename", "CNCS_7860_event.nxs");
TS_ASSERT_EQUALS( alg.confidence(alg.getPropertyValue("Filename")), 20 );
Mantid::Kernel::HDFDescriptor descr2(alg.getPropertyValue("Filename"));
TS_ASSERT_EQUALS( alg.confidence(descr2), 20 );

alg.setPropertyValue("Filename", "argus0026577.nxs");
TS_ASSERT_EQUALS( alg.confidence(alg.getPropertyValue("Filename")), 0 );
Mantid::Kernel::HDFDescriptor descr3(alg.getPropertyValue("Filename"));
TS_ASSERT_EQUALS( alg.confidence(descr3), 0 );

alg.setPropertyValue("Filename", "PG3_733.nxs");
TS_ASSERT_EQUALS( alg.confidence(alg.getPropertyValue("Filename")), 0 );
Mantid::Kernel::HDFDescriptor descr4(alg.getPropertyValue("Filename"));
TS_ASSERT_EQUALS( alg.confidence(descr4), 0 );

}

Expand Down

0 comments on commit 7aad82f

Please sign in to comment.