Skip to content
Snippets Groups Projects
Commit 03df3451 authored by Federico Montesino Pouzols's avatar Federico Montesino Pouzols
Browse files

better error msgs, new check canOpenAsNeXus, re #9248

parent c456cea7
No related branches found
No related tags found
No related merge requests found
......@@ -74,6 +74,9 @@ namespace Mantid
/// Load the logs
void runLoadLogs(const std::string filename,
API::MatrixWorkspace_sptr localWorkspace);
/// is it possible to open the file?
bool canOpenAsNeXus(const std::string& fname);
/// The name and path of the input file
std::string filename;
/// The workspace being filled out
......
......@@ -67,6 +67,11 @@ void LoadNexusMonitors::exec()
API::Progress prog1(this, 0.0, 0.2, 2);
if (!canOpenAsNeXus(this->filename))
{
throw std::runtime_error("Failed to recognize this file as a NeXus file, cannot continue.");
}
// top level file information
::NeXus::File file(this->filename);
......@@ -160,6 +165,9 @@ void LoadNexusMonitors::exec()
if (numHistMon == this->nMonitors)
{
useEventMon = false;
if (this->nMonitors == 0)
throw std::runtime_error("Not loading event data. Trying to load histogram data but failed to find monitors with histogram data or could not interpret the data. This file may be corrupted or it may not be supported");
this->WS = API::WorkspaceFactory::Instance().create("Workspace2D",
this->nMonitors, 1, 1);
// if there is a distinct monitor number for each monitor sort them by that number
......@@ -486,5 +494,32 @@ void LoadNexusMonitors::runLoadLogs(const std::string filename, API::MatrixWorks
}
}
/**
* Helper method to make sure that a file is / can be openend as a NeXus file
*
* @param: fname :: name of the file
* Returns true if opening the file as NeXus and retrieving entries succeeds
**/
bool LoadNexusMonitors::canOpenAsNeXus(const std::string& fname)
{
bool res = true;
::NeXus::File* f = NULL;
try
{
f = new ::NeXus::File(fname);
if (f)
f->getEntries();
}
catch(::NeXus::Exception& e)
{
g_log.error() << "Failed to open as a NeXus file: '" << fname <<
"', error description: " << e.what() << std::endl;
res = false;
}
if (f)
delete f;
return res;
}
} // end DataHandling
} // end Mantid
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