Skip to content

Commit

Permalink
Remove file access from some NeXus checks. Refs #7263
Browse files Browse the repository at this point in the history
  • Loading branch information
martyngigg committed Jul 3, 2013
1 parent 2a330f5 commit 146d72e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 34 deletions.
12 changes: 5 additions & 7 deletions Code/Mantid/Framework/DataHandling/src/LoadILL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,12 @@ namespace Mantid {
*/
int LoadILL::confidence(const Kernel::HDFDescriptor & descriptor) const
{
// Create the root Nexus class
NXRoot root(descriptor.filename());
NXEntry entry = root.openFirstEntry();
if (std::find(supportedInstruments.begin(), supportedInstruments.end(),
getInstrumentName(entry)) != supportedInstruments.end()) {
// FOUND
return 80;
const std::string root = "/" + descriptor.firstEntryNameType().first + "/";
for(auto it = supportedInstruments.begin(); it != supportedInstruments.end() ; ++it)
{
if(descriptor.pathExists(root + *it)) return 80;
}

return 0;
}

Expand Down
12 changes: 3 additions & 9 deletions Code/Mantid/Framework/DataHandling/src/LoadLLB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,8 @@ const std::string LoadLLB::category() const {
*/
int LoadLLB::confidence(const Kernel::HDFDescriptor & descriptor) const
{
// Create the root Nexus class
NXRoot root(descriptor.filename());
NXEntry entry = root.openFirstEntry();
if (std::find(supportedInstruments.begin(), supportedInstruments.end(),
getInstrumentName(entry)) != supportedInstruments.end()) {
// FOUND
return 80;
}
const auto & firstEntry = descriptor.firstEntryNameType();
if(descriptor.pathExists("/" + firstEntry.first + "/nxinstrument/name")) return 80;
return 0;
}

Expand Down Expand Up @@ -136,7 +130,7 @@ std::string LoadLLB::getInstrumentName(NeXus::NXEntry& entry) const {

std::string instrumentName = "";

std::vector<NXClassInfo> v = entry.groups();
std::vector<NXClassInfo> & v = entry.groups();
for (auto it = v.begin(); it < v.end(); it++) {
if (it->nxclass == "NXinstrument" || it->nxname == "nxinstrument") {
std::string insNamePath = it->nxname + "/name";
Expand Down
22 changes: 15 additions & 7 deletions Code/Mantid/Framework/DataHandling/src/LoadMuonNexus2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,17 +489,25 @@ namespace Mantid
*/
int LoadMuonNexus2::confidence(const Kernel::HDFDescriptor & descriptor) const
{
const auto & firstEntryNameType = descriptor.firstEntryNameType();
const std::string root = "/" + firstEntryNameType.first;
if(!descriptor.pathExists(root + "/definition")) return 0;

bool upperIDF(true);
if(descriptor.pathExists(root + "/IDF_version")) upperIDF = true;
else
{
if(descriptor.pathExists(root + "/idf_version")) upperIDF = false;
else return 0;
}

try
{
NXRoot root(descriptor.filename());
NXEntry entry = root.openFirstEntry();
if ( ! entry.containsDataSet( "definition" ) ) return 0;
std::string versionField = "IDF_version";
if ( ! entry.containsDataSet( versionField ) )
{
versionField = "idf_version";
if ( ! entry.containsDataSet( versionField ) ) return 0;
}
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" )
Expand Down
18 changes: 7 additions & 11 deletions Code/Mantid/Framework/DataHandling/src/LoadSINQ.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,13 @@ void LoadSINQ::initDocs() {
*/
int LoadSINQ::confidence(const Kernel::HDFDescriptor & descriptor) const
{
// Create the root Nexus class
NXRoot root(descriptor.filename());
NXEntry entry = root.openFirstEntry();
std::string nexusInstrumentName;
std::string instrumentName = getInstrumentName(entry,nexusInstrumentName);
if (std::find(supportedInstruments.begin(), supportedInstruments.end(),
instrumentName) != supportedInstruments.end()) {
// FOUND
return 80;
}
return 0;
const std::string root = "/" + descriptor.firstEntryNameType().first + "/";
for(auto it = supportedInstruments.begin(); it != supportedInstruments.end() ; ++it)
{
if(descriptor.pathExists(root + *it)) return 80;
}

return 0;
}

//----------------------------------------------------------------------------------------------
Expand Down

0 comments on commit 146d72e

Please sign in to comment.