Skip to content

Commit

Permalink
Re #9013 Refactoring. Date converted to Mantid format.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ricardo Ferraz Leal committed Apr 30, 2014
1 parent f19b35f commit f40a385
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 67 deletions.
Expand Up @@ -48,11 +48,12 @@ class DLLExport LoadHelper {
double getL1(const API::MatrixWorkspace_sptr&);
double getL2(const API::MatrixWorkspace_sptr&, int detId = 1);
double getInstrumentProperty(const API::MatrixWorkspace_sptr&, std::string);
void AddNexusFieldsToWsRun(NXhandle nxfileID,
void addNexusFieldsToWsRun(NXhandle nxfileID,
API::Run& runDetails,
std::string& parent_name,
std::string& parent_class,
int indent);
void dumpNexusAttributes(NXhandle nxfileID, std::string& indentStr);
std::string dateTimeInIsoFormat(std::string);
private:
/// Reference to the logger class
Expand Down
Expand Up @@ -58,8 +58,6 @@ namespace DataHandling
void loadDataIntoTheWorkSpace(NeXus::NXEntry& entry, std::vector< std::vector<int> > monitorsData);
std::vector< std::vector<int> > loadMonitors(NeXus::NXEntry& entry);

void dumpNexusAttributes(NXhandle nxfileID,
std::string& indent_str);
void runLoadInstrument();

/// Calculate error for y
Expand Down
69 changes: 66 additions & 3 deletions Code/Mantid/Framework/DataHandling/src/LoadHelper.cpp
Expand Up @@ -4,6 +4,8 @@

#include "MantidDataHandling/LoadHelper.h"

#include <boost/algorithm/string/predicate.hpp> //assert(boost::algorithm::ends_with("mystring", "ing"));

namespace Mantid {
namespace DataHandling {

Expand Down Expand Up @@ -145,7 +147,7 @@ double LoadHelper::getInstrumentProperty(const API::MatrixWorkspace_sptr& worksp
* @param level :: current level in nexus tree
*
*/
void LoadHelper::AddNexusFieldsToWsRun(NXhandle nxfileID,
void LoadHelper::addNexusFieldsToWsRun(NXhandle nxfileID,
API::Run& runDetails,
std::string& parent_name,
std::string& parent_class,
Expand Down Expand Up @@ -173,7 +175,7 @@ void LoadHelper::AddNexusFieldsToWsRun(NXhandle nxfileID,
std::string p_nxname(nxname);//current names can be useful for next level
std::string p_nxclass(nxclass);

AddNexusFieldsToWsRun(nxfileID, runDetails, p_nxname, p_nxclass, level+1);
addNexusFieldsToWsRun(nxfileID, runDetails, p_nxname, p_nxclass, level+1);

NXclosegroup(nxfileID);
}// if(NXopengroup
Expand Down Expand Up @@ -217,7 +219,13 @@ void LoadHelper::AddNexusFieldsToWsRun(NXhandle nxfileID,
}

if (type==NX_CHAR) {
runDetails.addProperty(property_name, std::string((const char *)dataBuffer));
std::string property_value((const char *)dataBuffer);
if (boost::algorithm::ends_with(property_name, "_time")) {
// That's a time value! Convert to Mantid standard
property_value = dateTimeInIsoFormat(property_value);
}
runDetails.addProperty(property_name, property_value);

} else if ((type==NX_FLOAT32)
||(type==NX_FLOAT64)
||(type==NX_INT16)
Expand Down Expand Up @@ -291,6 +299,61 @@ void LoadHelper::AddNexusFieldsToWsRun(NXhandle nxfileID,
}// RecurseForProperties


/**
* show attributes attached to current Nexus entry
*
* @param nxfileID :: The Nexus entry
* @param indent_str :: some spaces following tree level
*
*/
void LoadHelper::dumpNexusAttributes(NXhandle nxfileID, std::string& indentStr){
// Attributes
NXname pName;
int iLength, iType;
int nbuff = 127;
boost::shared_array<char> buff(new char[nbuff+1]);

while(NXgetnextattr(nxfileID, pName, &iLength, &iType) != NX_EOD)
{
g_log.debug()<<indentStr<<'@'<<pName<<" = ";
switch(iType)
{
case NX_CHAR:
{
if (iLength > nbuff + 1)
{
nbuff = iLength;
buff.reset(new char[nbuff+1]);
}
int nz = iLength + 1;
NXgetattr(nxfileID,pName,buff.get(),&nz,&iType);
g_log.debug()<<indentStr<<buff.get()<<'\n';
break;
}
case NX_INT16:
{
short int value;
NXgetattr(nxfileID,pName,&value,&iLength,&iType);
g_log.debug()<<indentStr<<value<<'\n';
break;
}
case NX_INT32:
{
int value;
NXgetattr(nxfileID,pName,&value,&iLength,&iType);
g_log.debug()<<indentStr<<value<<'\n';
break;
}
case NX_UINT16:
{
short unsigned int value;
NXgetattr(nxfileID,pName,&value,&iLength,&iType);
g_log.debug()<<indentStr<<value<<'\n';
break;
}
}// switch
}// while
}
/**
* Parses the date as formatted at the ILL:
* 29-Jun-12 11:27:26
Expand Down
69 changes: 8 additions & 61 deletions Code/Mantid/Framework/DataHandling/src/LoadILLIndirect.cpp
Expand Up @@ -255,7 +255,7 @@ void LoadILLIndirect::initWorkSpace(NeXus::NXEntry& /*entry*/, std::vector< std:
m_numberOfChannels + 1,
m_numberOfChannels);

m_localWorkspace->getAxis(0)->unit() = UnitFactory::Instance().create("TOF");
m_localWorkspace->getAxis(0)->unit() = UnitFactory::Instance().create("Empty");

m_localWorkspace->setYUnitLabel("Counts");

Expand Down Expand Up @@ -355,61 +355,7 @@ void LoadILLIndirect::loadDataIntoTheWorkSpace(NeXus::NXEntry& entry, std::vecto



/**
* show attributes attached to current Nexus entry
*
* @param nxfileID :: The Nexus entry
* @param indent_str :: some spaces following tree level
*
*/
void LoadILLIndirect::dumpNexusAttributes(NXhandle nxfileID, std::string& indentStr){
// Attributes
NXname pName;
int iLength, iType;
int nbuff = 127;
boost::shared_array<char> buff(new char[nbuff+1]);

while(NXgetnextattr(nxfileID, pName, &iLength, &iType) != NX_EOD)
{
g_log.debug()<<indentStr<<'@'<<pName<<" = ";
switch(iType)
{
case NX_CHAR:
{
if (iLength > nbuff + 1)
{
nbuff = iLength;
buff.reset(new char[nbuff+1]);
}
int nz = iLength + 1;
NXgetattr(nxfileID,pName,buff.get(),&nz,&iType);
g_log.debug()<<indentStr<<buff.get()<<'\n';
break;
}
case NX_INT16:
{
short int value;
NXgetattr(nxfileID,pName,&value,&iLength,&iType);
g_log.debug()<<indentStr<<value<<'\n';
break;
}
case NX_INT32:
{
int value;
NXgetattr(nxfileID,pName,&value,&iLength,&iType);
g_log.debug()<<indentStr<<value<<'\n';
break;
}
case NX_UINT16:
{
short unsigned int value;
NXgetattr(nxfileID,pName,&value,&iLength,&iType);
g_log.debug()<<indentStr<<value<<'\n';
break;
}
}// switch
}// while
}




Expand All @@ -426,7 +372,7 @@ void LoadILLIndirect::loadNexusEntriesIntoProperties(std::string nexusfilename)
g_log.debug() << "convertNexusToProperties: Error loading " << nexusfilename;
throw Kernel::Exception::FileError("Unable to open File:" , nexusfilename);
}
m_loader.AddNexusFieldsToWsRun(nxfileID, runDetails, nexusfilename, nexusfilename, 0);
m_loader.addNexusFieldsToWsRun(nxfileID, runDetails, nexusfilename, nexusfilename, 0);

// Add also "Facility", as asked
runDetails.addProperty("Facility", std::string("ILL"));
Expand All @@ -444,9 +390,6 @@ void LoadILLIndirect::runLoadInstrument() {

// Now execute the Child Algorithm. Catch and log any error, but don't stop.
try {

// TODO: depending on the m_numberOfPixelsPerTube we might need to load a different IDF

loadInst->setPropertyValue("InstrumentName", m_instrumentName);
loadInst->setProperty<MatrixWorkspace_sptr>("Workspace", m_localWorkspace);
loadInst->execute();
Expand All @@ -456,7 +399,6 @@ void LoadILLIndirect::runLoadInstrument() {
}
}


void LoadILLIndirect::moveComponent(const std::string &componentName, double twoTheta, double offSet) {

try {
Expand Down Expand Up @@ -489,6 +431,11 @@ void LoadILLIndirect::moveComponent(const std::string &componentName, double two

}

/**
* IN16B has a few single detectors that are place around the sample.
* They are moved according to some values in the nexus file.
* This is not implemented yet.
*/
void LoadILLIndirect::moveSingleDetectors(){


Expand Down

0 comments on commit f40a385

Please sign in to comment.