Skip to content

Commit

Permalink
Load Sample information in Event Data for ISIS
Browse files Browse the repository at this point in the history
It creates a new method to load the sample information from the data file.
It does essentially the same job of LoadISISNexus2::loadSampleData, but,
due to different libraries being used, I was forced to 'duplicate'
the code.

re #7985
  • Loading branch information
gesnerpassos committed Sep 19, 2013
1 parent 1d3b555 commit b3e7e78
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ namespace Mantid

static void loadEntryMetadata(const std::string &nexusfilename, Mantid::API::MatrixWorkspace_sptr WS,
const std::string &entry_name);

/// Load instrument from Nexus file if possible, else from IDF spacified by Nexus file
static bool loadInstrument(const std::string &nexusfilename, API::MatrixWorkspace_sptr localWorkspace,
const std::string & top_entry_name, Algorithm * alg);
Expand All @@ -219,6 +218,7 @@ namespace Mantid
static void loadTimeOfFlightData(::NeXus::File& file, DataObjects::EventWorkspace_sptr WS,
const std::string& binsName,size_t start_wi = 0, size_t end_wi = 0);

void loadSampleDataISIScompatibility(::NeXus::File& file, Mantid::API::MatrixWorkspace_sptr WS);
public:
/// name of top level NXentry to use
std::string m_top_entry_name;
Expand Down
55 changes: 55 additions & 0 deletions Code/Mantid/Framework/DataHandling/src/LoadEventNexus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1442,6 +1442,8 @@ void LoadEventNexus::loadEvents(API::Progress * const prog, const bool monitors)
file.closeGroup();
}
}

loadSampleDataISIScompatibility(file, WS);

//Close up the file
file.closeGroup();
Expand All @@ -1455,6 +1457,7 @@ void LoadEventNexus::loadEvents(API::Progress * const prog, const bool monitors)
// set more properties on the workspace
try
{
// this is a static method that is why it is passing the file path
loadEntryMetadata(m_filename, WS, m_top_entry_name);
}
catch (std::runtime_error & e)
Expand Down Expand Up @@ -1788,6 +1791,7 @@ void LoadEventNexus::loadEntryMetadata(const std::string &nexusfilename, Mantid:
file.close();
}


//-----------------------------------------------------------------------------
/** Load the instrument from the nexus file or if not found from the IDF file
* specified by the info in the Nexus file
Expand Down Expand Up @@ -2551,5 +2555,56 @@ void LoadEventNexus::loadTimeOfFlightData(::NeXus::File& file, DataObjects::Even
file.closeData();
}

/** Load information of the sample. It is valid only for ISIS it get the information from
* the group isis_vms_compat.
*
* If it does not find this group, it assumes that there is nothing to do.
* But, if the information is there, but not in the way it was expected, it will log the occurrence.
*
* @note: It does essentially the same thing of the method: LoadISISNexus2::loadSampleData
*
* @param nexusfilename : path for the nexus file
* @param WS : pointer to the workspace
*/
void LoadEventNexus::loadSampleDataISIScompatibility(::NeXus::File& file, Mantid::API::MatrixWorkspace_sptr WS){
try
{
file.openGroup("isis_vms_compat", "IXvms");
}
catch( ::NeXus::Exception & )
{
g_log.debug() << "No isis_vms_compat group" << std::endl;
// No problem, it just means that this entry does not exist
return;
}

// read the data
try
{
std::vector<int32_t> spb;
std::vector<float> rspb;
file.readData("SPB", spb);
file.readData("RSPB",rspb);

WS->mutableSample().setGeometryFlag(spb[2]); // the flag is in the third value
WS->mutableSample().setThickness(rspb[3]);
WS->mutableSample().setHeight(rspb[4]);
WS->mutableSample().setWidth(rspb[5]);
}
catch ( ::NeXus::Exception & ex)
{
// it means that the data was not as expected, report the problem
g_log.warning() << "Wrong definition found in isis_vms_compat :> " << ex.what() << std::endl;
}

const Sample & samp(WS->mutableSample());
g_log.debug() << "Sample geometry - ID: " << samp.getGeometryFlag() << ", thickness: " << samp.getThickness()
<< ", height: " << samp.getHeight() << ", width: "
<< samp.getWidth() << "\n";

file.closeGroup();
}


} // namespace DataHandling
} // namespace Mantid

0 comments on commit b3e7e78

Please sign in to comment.