Skip to content
Snippets Groups Projects
Commit ca6f18f4 authored by Gigg, Martyn Anthony's avatar Gigg, Martyn Anthony
Browse files

Proper fix for the static const declaration debacle in IDataFileChecker. The...

Proper fix for the static const declaration debacle in IDataFileChecker. The class was hard marked DLLExport rather than switching between the two depending on the IN_MANTID_API flag. This is the case in quite a lot if our code where DLLExport is used instead of the correct EXPORT_OPT_IN_{PACKAGE} (which I think need a more concise name for). Re #2329
parent 76d7bf60
No related merge requests found
#ifndef MANTID_API_IDATAFILECHECKER_H #ifndef MANTID_API_IDATAFILECHECKER_H
#define MANTID_API_IDATAFILECHECKER_H #define MANTID_API_IDATAFILECHECKER_H
#include "MantidAPI/DllExport.h"
#include "MantidAPI/Algorithm.h" #include "MantidAPI/Algorithm.h"
#ifdef WIN32
static const unsigned char g_hdf5_signature[] = { '\211', 'H', 'D', 'F', '\r', '\n', '\032', '\n' };
/// Magic HDF5 cookie that is stored in the first 4 bytes of the file.
static const uint32_t g_hdf5_cookie = 0x0e031301;
#endif
namespace Mantid namespace Mantid
{ {
namespace API namespace API
...@@ -43,7 +38,7 @@ namespace Mantid ...@@ -43,7 +38,7 @@ namespace Mantid
File change history is stored at: <https://svn.mantidproject.org/mantid/trunk/Code/Mantid> File change history is stored at: <https://svn.mantidproject.org/mantid/trunk/Code/Mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org> Code Documentation is available at: <http://doxygen.mantidproject.org>
*/ */
class DLLExport IDataFileChecker : public Algorithm class EXPORT_OPT_MANTID_API IDataFileChecker : public Algorithm
{ {
public: public:
///constructor ///constructor
...@@ -51,12 +46,11 @@ namespace Mantid ...@@ -51,12 +46,11 @@ namespace Mantid
/// virtual destructor /// virtual destructor
virtual ~IDataFileChecker(); virtual ~IDataFileChecker();
#ifndef WIN32
/// Magic signature identifying a HDF5 file. /// Magic signature identifying a HDF5 file.
static unsigned char const g_hdf5_signature[8]; static const unsigned char g_hdf5_signature[8];
/// Magic HDF5 cookie that is stored in the first 4 bytes of the file. /// Magic HDF5 cookie that is stored in the first 4 bytes of the file.
static uint32_t const g_hdf5_cookie; static const uint32_t g_hdf5_cookie;
#endif
/// The default number of bytes of the header to check /// The default number of bytes of the header to check
enum { g_hdr_bytes = 100 }; enum { g_hdr_bytes = 100 };
......
...@@ -7,12 +7,11 @@ namespace Mantid ...@@ -7,12 +7,11 @@ namespace Mantid
{ {
namespace API namespace API
{ {
#ifndef WIN32
// Magic HDF5 signature // Magic HDF5 signature
unsigned char const IDataFileChecker::g_hdf5_signature[8] = { '\211', 'H', 'D', 'F', '\r', '\n', '\032', '\n' }; const unsigned char IDataFileChecker::g_hdf5_signature[8] = { '\211', 'H', 'D', 'F', '\r', '\n', '\032', '\n' };
/// Magic HDF5 cookie that is stored in the first 4 bytes of the file. /// Magic HDF5 cookie that is stored in the first 4 bytes of the file.
uint32_t const IDataFileChecker::g_hdf5_cookie = 0x0e031301; const uint32_t IDataFileChecker::g_hdf5_cookie = 0x0e031301;
#endif
/// constructor /// constructor
IDataFileChecker::IDataFileChecker():API::Algorithm() IDataFileChecker::IDataFileChecker():API::Algorithm()
......
...@@ -25,11 +25,11 @@ namespace Mantid ...@@ -25,11 +25,11 @@ namespace Mantid
} }
/** /**
* Quick file always returns false here * Quick file always returns false here
* @param filePath File path * @param filePath File path
* @param nread Number of bytes read * @param nread Number of bytes read
* @param header_buffer A buffer containing the nread bytes * @param header_buffer A buffer containing the nread bytes
*/ */
bool Load::quickFileCheck(const std::string& filePath,size_t nread,const file_header& header) bool Load::quickFileCheck(const std::string& filePath,size_t nread,const file_header& header)
{ {
(void)filePath; (void)nread; (void)header; (void)filePath; (void)nread; (void)header;
...@@ -37,10 +37,10 @@ namespace Mantid ...@@ -37,10 +37,10 @@ namespace Mantid
} }
/** /**
* File check by looking at the structure of the data file * File check by looking at the structure of the data file
* @param filePath The full file path * @param filePath The full file path
* @returns -1 * @returns -1
*/ */
int Load::fileCheck(const std::string& filePath) int Load::fileCheck(const std::string& filePath)
{ {
(void)filePath; (void)filePath;
...@@ -50,7 +50,7 @@ namespace Mantid ...@@ -50,7 +50,7 @@ namespace Mantid
/// Initialisation method. /// Initialisation method.
void Load::init() void Load::init()
{ {
std::vector<std::string> exts; std::vector<std::string> exts;
exts.push_back(".raw"); exts.push_back(".raw");
exts.push_back(".s*"); exts.push_back(".s*");
...@@ -66,51 +66,58 @@ namespace Mantid ...@@ -66,51 +66,58 @@ namespace Mantid
exts.push_back(".csv"); exts.push_back(".csv");
exts.push_back(".spe"); exts.push_back(".spe");
declareProperty(new FileProperty("Filename", "", FileProperty::Load, exts), declareProperty(new FileProperty("Filename", "", FileProperty::Load, exts),
"The name of the file to read, including its full or relative\n" "The name of the file to read, including its full or relative\n"
"path. (N.B. case sensitive if running on Linux)."); "path. (N.B. case sensitive if running on Linux).");
declareProperty(new WorkspaceProperty<Workspace>("OutputWorkspace", "",Direction::Output, true), declareProperty(new WorkspaceProperty<Workspace>("OutputWorkspace", "",Direction::Output, true),
"The name of the workspace that will be created, filled with the\n" "The name of the workspace that will be created, filled with the\n"
"read-in data and stored in the Analysis Data Service."); "read-in data and stored in the Analysis Data Service.");
BoundedValidator<int> *mustBePositive = new BoundedValidator<int>();
mustBePositive->setLower(1);
declareProperty("SpectrumMin", 1, mustBePositive);
declareProperty("SpectrumMax", EMPTY_INT(), mustBePositive->clone());
declareProperty(new ArrayProperty<int>("SpectrumList"));
declareProperty("EntryNumber", 0,
"Load a particular entry, if supported by the file format (default: Load all entries)");
declareProperty("FindLoader", false, "If true the algorithm will only be run as\n" declareProperty("FindLoader", false, "If true the algorithm will only be run as\n"
"far as is necessary to discover the concrete Load algorithm to use"); "far as is necessary to discover the concrete Load algorithm to use");
declareProperty("LoaderName", std::string(""), "A string containing the name of the concrete loader used", declareProperty("LoaderName", std::string(""), "A string containing the name of the concrete loader used",
Direction::Output); Direction::Output);
} }
namespace namespace
{ {
//@cond //@cond
/** /**
* Checks this property exists in the list of algorithm properties. * Checks this property exists in the list of algorithm properties.
*/ */
struct hasProperty struct hasProperty
{ {
/** constructor which takes 1 arguement. /** constructor which takes 1 arguement.
*@param name :: name of the property *@param name :: name of the property
*/ */
hasProperty(const std::string name):m_name(name){} hasProperty(const std::string name):m_name(name){}
/**This method comapres teh property name /**This method comapres teh property name
*@param prop :: shared pointer to property *@param prop :: shared pointer to property
*@return true if the property exists in the list of properties. *@return true if the property exists in the list of properties.
*/ */
bool operator()(Mantid::Kernel::Property* prop) bool operator()(Mantid::Kernel::Property* prop)
{ {
std::string name=prop->name(); std::string name=prop->name();
return (!name.compare(m_name)); return (!name.compare(m_name));
} }
/// name of teh property /// name of teh property
std::string m_name; std::string m_name;
}; };
//@endcond //@endcond
} }
/** /**
* Executes the algorithm. * Executes the algorithm.
*/ */
void Load::exec() void Load::exec()
{ {
std::string fileName = getPropertyValue("Filename"); std::string fileName = getPropertyValue("Filename");
...@@ -125,36 +132,36 @@ namespace Mantid ...@@ -125,36 +132,36 @@ namespace Mantid
} }
else else
{ {
setPropertyValue("LoaderName", loader->name()); setPropertyValue("LoaderName", loader->name());
} }
bool findOnly = getProperty("FindLoader"); bool findOnly = getProperty("FindLoader");
if( findOnly ) return; if( findOnly ) return;
g_log.information()<<"The sub load algorithm created to execute is " g_log.information()<<"The sub load algorithm created to execute is "
<< loader->name() << " and it version is " << loader->name() << " and it version is "
<< loader->version() <<std::endl; << loader->version() <<std::endl;
double startProgress(0.0), endProgress(1.0); double startProgress(0.0), endProgress(1.0);
initialiseLoadSubAlgorithm(loader,startProgress,endProgress,true,-1); initialiseLoadSubAlgorithm(loader,startProgress,endProgress,true,-1);
//get the list of properties for this algorithm //get the list of properties for this algorithm
std::vector<Kernel::Property*> props=getProperties(); std::vector<Kernel::Property*> props=getProperties();
///get the list properties for the sub load algorithm ///get the list properties for the sub load algorithm
std::vector<Kernel::Property*>loader_props=loader->getProperties(); std::vector<Kernel::Property*>loader_props=loader->getProperties();
//loop through the properties of this algorithm //loop through the properties of this algorithm
std::vector<Kernel::Property*>::iterator itr; std::vector<Kernel::Property*>::iterator itr;
for (itr=props.begin();itr!=props.end();++itr) for (itr=props.begin();itr!=props.end();++itr)
{ {
std::vector<Mantid::Kernel::Property*>::iterator prop; std::vector<Mantid::Kernel::Property*>::iterator prop;
//if the load sub algorithm has the same property then set it. //if the load sub algorithm has the same property then set it.
prop=std::find_if(loader_props.begin(),loader_props.end(),hasProperty((*itr)->name())); prop=std::find_if(loader_props.begin(),loader_props.end(),hasProperty((*itr)->name()));
if(prop!=loader_props.end()) if(prop!=loader_props.end())
{ {
loader->setPropertyValue((*prop)->name(),getPropertyValue((*prop)->name())); loader->setPropertyValue((*prop)->name(),getPropertyValue((*prop)->name()));
} }
} }
// Execute the concrete loader // Execute the concrete loader
loader->execute(); loader->execute();
...@@ -163,18 +170,18 @@ namespace Mantid ...@@ -163,18 +170,18 @@ namespace Mantid
} }
/** Get a shared pointer to the load algorithm with highest preference for loading /** Get a shared pointer to the load algorithm with highest preference for loading
*@param filePath :: path of the file *@param filePath :: path of the file
*@return filePath - path of the file *@return filePath - path of the file
*/ */
API::IAlgorithm_sptr Load::getFileLoader(const std::string& filePath) API::IAlgorithm_sptr Load::getFileLoader(const std::string& filePath)
{ {
/* Open the file and read in the first bufferSize bytes - these will /* Open the file and read in the first bufferSize bytes - these will
* be used to determine the type of the file * be used to determine the type of the file
*/ */
FILE* fp = fopen(filePath.c_str(), "rb"); FILE* fp = fopen(filePath.c_str(), "rb");
if (fp == NULL) if (fp == NULL)
{ {
throw Kernel::Exception::FileError("Unable to open the file:", filePath); throw Kernel::Exception::FileError("Unable to open the file:", filePath);
} }
//unsigned char* header_buffer = header_buffer_union.c; //unsigned char* header_buffer = header_buffer_union.c;
//unsigned char * header_buffer = IDataFileChecker::g_hdr_buf.get(); //unsigned char * header_buffer = IDataFileChecker::g_hdr_buf.get();
...@@ -184,14 +191,14 @@ namespace Mantid ...@@ -184,14 +191,14 @@ namespace Mantid
header.full_hdr[g_hdr_bytes] = '\0'; header.full_hdr[g_hdr_bytes] = '\0';
if (nread == -1) if (nread == -1)
{ {
fclose(fp); fclose(fp);
} }
if (fclose(fp) != 0) if (fclose(fp) != 0)
{ {
throw std::runtime_error("Error while closing file \"" + filePath + "\""); throw std::runtime_error("Error while closing file \"" + filePath + "\"");
} }
// Iterate through all loaders and attempt to find the best qualified for the job. // Iterate through all loaders and attempt to find the best qualified for the job.
// Each algorithm has a quick and long file check. The long version returns an integer // Each algorithm has a quick and long file check. The long version returns an integer
// giving its certainty about be able to load the file. The highest wins. // giving its certainty about be able to load the file. The highest wins.
...@@ -200,42 +207,42 @@ namespace Mantid ...@@ -200,42 +207,42 @@ namespace Mantid
API::IAlgorithm_sptr winningLoader; API::IAlgorithm_sptr winningLoader;
std::vector<std::string>::const_iterator cend = loaderNames.end(); std::vector<std::string>::const_iterator cend = loaderNames.end();
for( std::vector<std::string>::const_iterator citr = loaderNames.begin(); citr != cend; for( std::vector<std::string>::const_iterator citr = loaderNames.begin(); citr != cend;
++citr ) ++citr )
{ {
IDataFileChecker_sptr loader = API::LoadAlgorithmFactory::Instance().create(*citr); IDataFileChecker_sptr loader = API::LoadAlgorithmFactory::Instance().create(*citr);
if( loader->quickFileCheck(filePath, nread, header) ) if( loader->quickFileCheck(filePath, nread, header) )
{ {
int pref = loader->fileCheck(filePath); int pref = loader->fileCheck(filePath);
// Can't just pick the first as there might be one later in the list with a higher // Can't just pick the first as there might be one later in the list with a higher
// preference // preference
if( pref > highestPref ) if( pref > highestPref )
{ {
highestPref = pref; highestPref = pref;
winningLoader = loader; winningLoader = loader;
} }
} }
} }
if( !winningLoader ) if( !winningLoader )
{ {
throw std::runtime_error("Cannot find a loader for \"" + filePath + "\""); throw std::runtime_error("Cannot find a loader for \"" + filePath + "\"");
} }
return winningLoader; return winningLoader;
} }
/** This method set the algorithm as a child algorithm. /** This method set the algorithm as a child algorithm.
* @param alg :: The shared pointer to a algorithm * @param alg :: The shared pointer to a algorithm
* @param startProgress :: The percentage progress value of the overall * @param startProgress :: The percentage progress value of the overall
* algorithm where this child algorithm starts * algorithm where this child algorithm starts
* @param endProgress :: The percentage progress value of the overall * @param endProgress :: The percentage progress value of the overall
* algorithm where this child algorithm ends * algorithm where this child algorithm ends
* @param enableLogging :: Set to false to disable logging from the child algorithm * @param enableLogging :: Set to false to disable logging from the child algorithm
* @param version :: The version of the child algorithm to create. * @param version :: The version of the child algorithm to create.
* By default gives the latest version. * By default gives the latest version.
*/ */
void Load::initialiseLoadSubAlgorithm(API::IAlgorithm_sptr alg, void Load::initialiseLoadSubAlgorithm(API::IAlgorithm_sptr alg,
const double startProgress, const double endProgress, const double startProgress, const double endProgress,
const bool enableLogging, const int& version) const bool enableLogging, const int& version)
{ {
(void) version; // Avoid compiler warning. (void) version; // Avoid compiler warning.
//Set as a child so that we are in control of output storage //Set as a child so that we are in control of output storage
...@@ -247,61 +254,61 @@ namespace Mantid ...@@ -247,61 +254,61 @@ namespace Mantid
const std::vector< Property*> &props = alg->getProperties(); const std::vector< Property*> &props = alg->getProperties();
for (unsigned int i = 0; i < props.size(); ++i) for (unsigned int i = 0; i < props.size(); ++i)
{ {
if (props[i]->direction() == 1 && dynamic_cast<IWorkspaceProperty*>(props[i]) ) if (props[i]->direction() == 1 && dynamic_cast<IWorkspaceProperty*>(props[i]) )
{ {
if ( props[i]->value().empty() ) props[i]->setValue("LoadChildWorkspace"); if ( props[i]->value().empty() ) props[i]->setValue("LoadChildWorkspace");
} }
} }
if (startProgress >= 0. && endProgress > startProgress && endProgress <= 1.) if (startProgress >= 0. && endProgress > startProgress && endProgress <= 1.)
{ {
alg->addObserver(m_progressObserver); alg->addObserver(m_progressObserver);
alg->setChildStartProgress(startProgress); alg->setChildStartProgress(startProgress);
alg->setChildEndProgress(endProgress); alg->setChildEndProgress(endProgress);
} }
} }
/** /**
* Set the output workspace(s) if the load's return workspace * Set the output workspace(s) if the load's return workspace
* has type API::Workspace * has type API::Workspace
*@param load :: shared pointer to load algorithm *@param load :: shared pointer to load algorithm
*/ */
void Load::setOutputWorkspace(API::IAlgorithm_sptr& load) void Load::setOutputWorkspace(API::IAlgorithm_sptr& load)
{ {
try try
{ {
Workspace_sptr ws = load->getProperty("OutputWorkspace"); Workspace_sptr ws = load->getProperty("OutputWorkspace");
WorkspaceGroup_sptr wsg = boost::dynamic_pointer_cast<WorkspaceGroup>(ws); WorkspaceGroup_sptr wsg = boost::dynamic_pointer_cast<WorkspaceGroup>(ws);
if (wsg) if (wsg)
{ {
setProperty("OutputWorkspace",ws); setProperty("OutputWorkspace",ws);
std::vector<std::string> names = wsg->getNames(); std::vector<std::string> names = wsg->getNames();
for(size_t i = 0; i < names.size(); ++i) for(size_t i = 0; i < names.size(); ++i)
{ {
std::ostringstream propName; std::ostringstream propName;
propName << "OutputWorkspace_" << (i+1); propName << "OutputWorkspace_" << (i+1);
DataObjects::Workspace2D_sptr memberwsws1 = load->getProperty(propName.str()); DataObjects::Workspace2D_sptr memberwsws1 = load->getProperty(propName.str());
std::string memberwsName = load->getPropertyValue(propName.str()); std::string memberwsName = load->getPropertyValue(propName.str());
declareProperty(new WorkspaceProperty<>(propName.str(),memberwsName,Direction::Output)); declareProperty(new WorkspaceProperty<>(propName.str(),memberwsName,Direction::Output));
setProperty(propName.str(),boost::dynamic_pointer_cast<MatrixWorkspace>(memberwsws1)); setProperty(propName.str(),boost::dynamic_pointer_cast<MatrixWorkspace>(memberwsws1));
} }
} }
else else
{ {
setProperty("OutputWorkspace",ws); setProperty("OutputWorkspace",ws);
} }
} }
catch(std::runtime_error&) catch(std::runtime_error&)
{ {
MatrixWorkspace_sptr mws=load->getProperty("OutputWorkspace"); MatrixWorkspace_sptr mws=load->getProperty("OutputWorkspace");
setProperty("OutputWorkspace",boost::dynamic_pointer_cast<Workspace>(mws)); setProperty("OutputWorkspace",boost::dynamic_pointer_cast<Workspace>(mws));
} }
} }
} // namespace DataHandling } // namespace DataHandling
} // namespace Mantid } // namespace Mantid
...@@ -147,7 +147,7 @@ public: ...@@ -147,7 +147,7 @@ public:
TS_ASSERT( saver->isExecuted() ); TS_ASSERT( saver->isExecuted() );
TS_ASSERT( Poco::File(outputFile).exists() ); TS_ASSERT( Poco::File(outputFile).exists() );
if( Poco::File(outputFile).exists() ); if( Poco::File(outputFile).exists() )
{ {
Poco::File(outputFile).remove(); Poco::File(outputFile).remove();
} }
......
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