diff --git a/Code/Mantid/Framework/API/inc/MantidAPI/IDataFileChecker.h b/Code/Mantid/Framework/API/inc/MantidAPI/IDataFileChecker.h index 8fde4aaeff0d3eb6da19492aa6c739e1a44b9325..0fd75f6445aa8feb86a68bf7a29c55c991138210 100644 --- a/Code/Mantid/Framework/API/inc/MantidAPI/IDataFileChecker.h +++ b/Code/Mantid/Framework/API/inc/MantidAPI/IDataFileChecker.h @@ -1,10 +1,7 @@ #ifndef MANTID_API_IDATAFILECHECKER_H #define MANTID_API_IDATAFILECHECKER_H -#include<string> #include "MantidAPI/Algorithm.h" -static const unsigned char hdf5_signature[] = { '\211', 'H', 'D', 'F', '\r', '\n', '\032', '\n' }; -static const int bufferSize=100; namespace Mantid { @@ -48,22 +45,34 @@ namespace Mantid /// virtual destructor virtual ~IDataFileChecker(); - /// quick file check by reading first 100 bytes of the file or by checking the extension - virtual bool quickFileCheck(const std::string& filePath,size_t nread,unsigned char* header_buffer)=0; - + protected: + /// Magic signature identifying a HDF5 file. + static unsigned char const g_hdf5_signature[8]; + /// Magic HDF5 cookie that is stored in the first 4 bytes of the file. + static uint32_t const g_hdf5_cookie; + /// The default number of bytes of the header to check + enum { g_hdr_bytes = 100 }; + /// A union representing the first g_hdr_bytes of a file + union file_header + { + /// The first four-bytes of the header + uint32_t four_bytes; + /// The full header buffer, including a null terminator + unsigned char full_hdr[g_hdr_bytes+1]; + }; + + public: + /// quick file check by reading first g_bufferSize bytes of the file or by checking the extension + virtual bool quickFileCheck(const std::string& filePath,size_t nread,const file_header & header)=0; /// file check by looking at the structure of the data file virtual int fileCheck(const std::string& filePath)=0; /// returns the extension of the file from filename std::string extension(const std::string& filePath); - /// a union used for quick file check - union { - unsigned u; - unsigned long ul; - unsigned char c[bufferSize+1]; - } header_buffer_union; - }; + /// Typedef for a shared pointer + typedef boost::shared_ptr<IDataFileChecker> IDataFileChecker_sptr; + } } #endif diff --git a/Code/Mantid/Framework/API/src/IDataFileChecker.cpp b/Code/Mantid/Framework/API/src/IDataFileChecker.cpp index 52784e2e5424fe2392dfada6053b6042c366c82a..1fb1a3dde065307bc201bfe25bd72291643d9437 100644 --- a/Code/Mantid/Framework/API/src/IDataFileChecker.cpp +++ b/Code/Mantid/Framework/API/src/IDataFileChecker.cpp @@ -1,36 +1,41 @@ -//---------------------------------------------------------------------- -// Includes -//---------------------------------------------------------------------- -#include "MantidAPI/IDataFileChecker.h" - -namespace Mantid -{ - namespace API - { - /// constructor - IDataFileChecker::IDataFileChecker():API::Algorithm() - { - } - - /// destructor - IDataFileChecker::~IDataFileChecker() - { - } - - /** returns the extension of the given file - * @param fileName :: name of the file. - */ - std::string IDataFileChecker::extension(const std::string& fileName) - { - std::size_t pos=fileName.find_last_of("."); - if(pos==std::string::npos) - { - return"" ; - } - std::string extn=fileName.substr(pos+1,fileName.length()-pos); - std::transform(extn.begin(),extn.end(),extn.begin(),tolower); - return extn; - } - - } -} +//---------------------------------------------------------------------- +// Includes +//---------------------------------------------------------------------- +#include "MantidAPI/IDataFileChecker.h" + +namespace Mantid +{ + namespace API + { + // Magic HDF5 signature + unsigned char const 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. + uint32_t const IDataFileChecker::g_hdf5_cookie = 0x0e031301; + + /// constructor + IDataFileChecker::IDataFileChecker():API::Algorithm() + { + } + + /// destructor + IDataFileChecker::~IDataFileChecker() + { + } + + /** returns the extension of the given file + * @param fileName :: name of the file. + */ + std::string IDataFileChecker::extension(const std::string& fileName) + { + std::size_t pos=fileName.find_last_of("."); + if(pos==std::string::npos) + { + return"" ; + } + std::string extn=fileName.substr(pos+1,fileName.length()-pos); + std::transform(extn.begin(),extn.end(),extn.begin(),tolower); + return extn; + } + + } +} diff --git a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/Load.h b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/Load.h index 77a8895c8f601979f1e55473e38f90af5d313b18..865baee8f049036f5243576482e245dfb0bbee67 100644 --- a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/Load.h +++ b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/Load.h @@ -4,10 +4,8 @@ //---------------------------------------------------------------------- // Includes //---------------------------------------------------------------------- -#include "MantidAPI/Algorithm.h" #include "MantidAPI/IDataFileChecker.h" - namespace Mantid { namespace DataHandling @@ -42,13 +40,11 @@ namespace Mantid */ - class DLLExport Load : public API::Algorithm + class DLLExport Load : public API::IDataFileChecker { public: /// Default constructor - Load(){} - /// Destructor - ~Load() {} + Load(); /// Algorithm's name for identification overriding a virtual method virtual const std::string name() const { return "Load"; } /// Algorithm's version for identification overriding a virtual method @@ -56,12 +52,17 @@ namespace Mantid /// Category virtual const std::string category() const { return "DataHandling"; } + private: + /// Quick file always returns false here + virtual bool quickFileCheck(const std::string& filePath,size_t nread,const file_header& header); + /// file check by looking at the structure of the data file + virtual int fileCheck(const std::string& filePath); + private: ///init void init(); /// execute void exec(); - /// This method returns shared pointer to load algorithm which got /// the highest preference after file check. API::IAlgorithm_sptr getFileLoader(const std::string& filePath); @@ -73,11 +74,11 @@ namespace Mantid private: /// union used for identifying teh file type unsigned char* m_header_buffer; - union { - unsigned u; - unsigned long ul; - unsigned char c[bufferSize+1]; - } header_buffer_union; +// union { +// unsigned u; +// unsigned long ul; +// unsigned char c[bufferSize+1]; +// } header_buffer_union; }; } // namespace DataHandling diff --git a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadAscii.h b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadAscii.h index 16e09d0aa4dda88f0a7430c79f5bc5892d2a921e..c3ab7bf44870ac6d497608463bd1fc9fde25e5f7 100644 --- a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadAscii.h +++ b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadAscii.h @@ -55,7 +55,7 @@ namespace Mantid virtual const std::string category() const { return "DataHandling"; } /// do a quick check that this file can be loaded - virtual bool quickFileCheck(const std::string& filePath,size_t nread,unsigned char* header_buffer); + virtual bool quickFileCheck(const std::string& filePath,size_t nread,const file_header& header); /// check the structure of the file and return a value between 0 and 100 of how much this file can be loaded virtual int fileCheck(const std::string& filePath); diff --git a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadCanSAS1D.h b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadCanSAS1D.h index 738725b877bf35d556d7d8fa712d122503d76466..893db61eef5488e26f34487d88a5b05eccd9da11 100644 --- a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadCanSAS1D.h +++ b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadCanSAS1D.h @@ -69,7 +69,7 @@ namespace Mantid virtual const std::string category() const { return "DataHandling"; } /// do a quick check that this file can be loaded - virtual bool quickFileCheck(const std::string& filePath,size_t nread,unsigned char* header_buffer); + virtual bool quickFileCheck(const std::string& filePath,size_t nread,const file_header& header); /// check the structure of the file and return a value between 0 and 100 of how much this file can be loaded virtual int fileCheck(const std::string& filePath); diff --git a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadGSS.h b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadGSS.h index f6c9834b636d75ccf1a676044bf427a19a15f1d8..d6361a8d80b86b9a65405263ffbb891f4d2eeb42 100644 --- a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadGSS.h +++ b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadGSS.h @@ -1,66 +1,66 @@ -#ifndef DATAHANDING_LOADGSS_H_ -#define DATAHANDING_LOADGSS_H_ - -//--------------------------------------------------- -// Includes -//--------------------------------------------------- -#include "MantidAPI/Algorithm.h" -#include "MantidAPI/IDataFileChecker.h" -namespace Mantid -{ -namespace DataHandling -{ -/** - Loads a file as saved by SaveGSS - - @author Michael Whitty, ISIS Facility, Rutherford Appleton Laboratory - @date 01/09/2010 - - Copyright © 2010 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory - - This file is part of Mantid. - - Mantid is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - Mantid is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - - File change history is stored at: <https://svn.mantidproject.org/mantid/trunk/Code/Mantid> - Code Documentation is available at: <http://doxygen.mantidproject.org> - */ -class DLLExport LoadGSS : public API::IDataFileChecker -{ -public: - /// (Empty) Constructor - LoadGSS() {} - /// Virtual destructor - virtual ~LoadGSS() {} - /// Algorithm's name - virtual const std::string name() const { return "LoadGSS"; } - /// Algorithm's version - virtual int version() const { return (1); } - /// Algorithm's category for identification - virtual const std::string category() const { return "Diffraction"; } - - /// do a quick check that this file can be loaded - virtual bool quickFileCheck(const std::string& filePath,size_t nread,unsigned char* header_buffer); - /// check the structure of the file and return a value between 0 and 100 of how much this file can be loaded - virtual int fileCheck(const std::string& filePath); - -private: - /// Initialisation code - void init(); - ///Execution code - void exec(); -}; -} -} -#endif //DATAHANDING_LOADGSS_H_ +#ifndef DATAHANDING_LOADGSS_H_ +#define DATAHANDING_LOADGSS_H_ + +//--------------------------------------------------- +// Includes +//--------------------------------------------------- +#include "MantidAPI/Algorithm.h" +#include "MantidAPI/IDataFileChecker.h" +namespace Mantid +{ +namespace DataHandling +{ +/** + Loads a file as saved by SaveGSS + + @author Michael Whitty, ISIS Facility, Rutherford Appleton Laboratory + @date 01/09/2010 + + Copyright © 2010 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory + + This file is part of Mantid. + + Mantid is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + Mantid is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + + File change history is stored at: <https://svn.mantidproject.org/mantid/trunk/Code/Mantid> + Code Documentation is available at: <http://doxygen.mantidproject.org> + */ +class DLLExport LoadGSS : public API::IDataFileChecker +{ +public: + /// (Empty) Constructor + LoadGSS() {} + /// Virtual destructor + virtual ~LoadGSS() {} + /// Algorithm's name + virtual const std::string name() const { return "LoadGSS"; } + /// Algorithm's version + virtual int version() const { return (1); } + /// Algorithm's category for identification + virtual const std::string category() const { return "Diffraction"; } + + /// do a quick check that this file can be loaded + virtual bool quickFileCheck(const std::string& filePath,size_t nread,const file_header& header); + /// check the structure of the file and return a value between 0 and 100 of how much this file can be loaded + virtual int fileCheck(const std::string& filePath); + +private: + /// Initialisation code + void init(); + ///Execution code + void exec(); +}; +} +} +#endif //DATAHANDING_LOADGSS_H_ diff --git a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadRKH.h b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadRKH.h index 85cc6a7eb64fcef235a81b50154e2b21ebdad98a..9319cc1e251682f25bbeee908d7993bcc65345cb 100644 --- a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadRKH.h +++ b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadRKH.h @@ -59,7 +59,7 @@ public: /// Algorithm's category for identification virtual const std::string category() const { return "DataHandling"; } /// do a quick check that this file can be loaded - virtual bool quickFileCheck(const std::string& filePath,size_t nread,unsigned char* header_buffer); + virtual bool quickFileCheck(const std::string& filePath,size_t nread,const file_header& header); /// check the structure of the file and return a value between 0 and 100 of how much this file can be loaded virtual int fileCheck(const std::string& filePath); private: diff --git a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadRaw3.h b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadRaw3.h index da67145b3c2b2978d278d34195d13983f9257952..5ca6acbfb364e00ee4369bd687fb456231bdaff4 100644 --- a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadRaw3.h +++ b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadRaw3.h @@ -79,7 +79,7 @@ namespace Mantid virtual const std::string category() const { return "DataHandling"; } /// do a quick check that this file can be loaded - virtual bool quickFileCheck(const std::string& filePath,size_t nread,unsigned char* header_buffer); + virtual bool quickFileCheck(const std::string& filePath,size_t nread,const file_header& header); /// check the structure of the file and return a value between 0 and 100 of how much this file can be loaded virtual int fileCheck(const std::string& filePath); diff --git a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadRawHelper.h b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadRawHelper.h index d345039a41bfac880090d8e6d80951811ff81758..830e88b8c82690c5ed1cf6ff280caaf19dc0588e 100644 --- a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadRawHelper.h +++ b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadRawHelper.h @@ -65,7 +65,7 @@ namespace Mantid void loadRunParameters(API::MatrixWorkspace_sptr localWorkspace, ISISRAW * const = NULL) const; /// do a quick check that this file can be loaded - virtual bool quickFileCheck(const std::string& filePath,size_t nread,unsigned char* header_buffer); + virtual bool quickFileCheck(const std::string& filePath,size_t nread,const file_header& header); /// check the structure of the file and if this file can be loaded return a value between 1 and 100 virtual int fileCheck(const std::string& filePath); @@ -179,6 +179,8 @@ namespace Mantid /// Overwrites Algorithm method void exec(); + /// Check if the buffer looks like a RAW file header + bool isRawFileHeader(const int nread, const unsigned char* buffer) const; /// Allowed values for the cache property std::vector<std::string> m_cache_options; @@ -205,14 +207,6 @@ namespace Mantid /// convert month label to int string std::string convertMonthLabelToIntStr(std::string month) const; - - /// union used for identifying the raw file type - unsigned char* m_buffer; - union { - unsigned u; - unsigned long ul; - unsigned char c[bufferSize+1]; - }buffer_union; }; } // namespace DataHandling diff --git a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadSNSspec.h b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadSNSspec.h index 93544888c5dbe3d653c2792ec67ab57f12b3729f..eb2628ce7a6d21a70782ec2d6538df3d6679f6e3 100644 --- a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadSNSspec.h +++ b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadSNSspec.h @@ -53,9 +53,9 @@ namespace Mantid virtual int version() const { return 1; } virtual const std::string category() const { return "DataHandling"; } - /// do a quick check that this file can be loaded - virtual bool quickFileCheck(const std::string& filePath,size_t nread,unsigned char* header_buffer); - /// check the structure of the file and return a value between 0 and 100 of how much this file can be loaded + /// do a quick check that this file can be loaded + virtual bool quickFileCheck(const std::string& filePath,size_t nread,const file_header& header); + /// check the structure of the file and return a value between 0 and 100 of how much this file can be loaded virtual int fileCheck(const std::string& filePath); private: diff --git a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadSPE.h b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadSPE.h index efd8e0fde8b925ba6a573f9593ef5548f656fc7f..b04bde1daf55328f141ea4926349423491650739 100644 --- a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadSPE.h +++ b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadSPE.h @@ -56,7 +56,7 @@ public: /// Algorithm's category for identification virtual const std::string category() const { return "DataHandling"; } ///checks the file can be loaded by reading 1st 100 bytes and looking at the file extension. - bool quickFileCheck(const std::string& filePath,size_t nread,unsigned char* header_buffer); + bool quickFileCheck(const std::string& filePath,size_t nread,const file_header& header); /// check the structure of the file and if this file can be loaded return a value between 1 and 100 int fileCheck(const std::string& filePath); private: diff --git a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadSpice2D.h b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadSpice2D.h index ec9a28f8ea1c7460bc0005c5ce481f90d2d5a4db..149fea2dbe47483fdb4ff654a5e65656f19b0fa7 100644 --- a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadSpice2D.h +++ b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadSpice2D.h @@ -65,9 +65,9 @@ namespace Mantid /// Number of monitors static const int nMonitors = 2; - /// do a quick check that this file can be loaded - virtual bool quickFileCheck(const std::string& filePath,size_t nread,unsigned char* header_buffer); - /// check the structure of the file and return a value between 0 and 100 of how much this file can be loaded + /// do a quick check that this file can be loaded + virtual bool quickFileCheck(const std::string& filePath,size_t nread,const file_header& header); + /// check the structure of the file and return a value between 0 and 100 of how much this file can be loaded virtual int fileCheck(const std::string& filePath); private: diff --git a/Code/Mantid/Framework/DataHandling/src/Load.cpp b/Code/Mantid/Framework/DataHandling/src/Load.cpp index f323279a31f5f93e4e357ca1696737c59b4a777f..b73b89880be685de9f8237a3e0c073da22df7ca8 100644 --- a/Code/Mantid/Framework/DataHandling/src/Load.cpp +++ b/Code/Mantid/Framework/DataHandling/src/Load.cpp @@ -5,7 +5,6 @@ #include "MantidAPI/FileProperty.h" #include "MantidKernel/ArrayProperty.h" #include "MantidDataObjects/Workspace2D.h" -#include "MantidAPI/IDataFileChecker.h" #include "MantidAPI/LoadAlgorithmFactory.h" #include<algorithm> @@ -15,11 +14,39 @@ namespace Mantid namespace DataHandling { // Register the algorithm into the algorithm factory - DECLARE_ALGORITHM(Load) + DECLARE_ALGORITHM(Load); using namespace Kernel; using namespace API; + /// Default constructor + Load::Load() : IDataFileChecker(), m_header_buffer(NULL) + { + } + + /** + * Quick file always returns false here + * @param filePath File path + * @param nread Number of bytes read + * @param header_buffer A buffer containing the nread bytes + */ + bool Load::quickFileCheck(const std::string& filePath,size_t nread,const file_header& header) + { + (void)filePath; (void)nread; (void)header; + return false; + } + + /** + * File check by looking at the structure of the data file + * @param filePath The full file path + * @returns -1 + */ + int Load::fileCheck(const std::string& filePath) + { + (void)filePath; + return -1; + } + /// Initialisation method. void Load::init() { @@ -54,6 +81,7 @@ namespace Mantid namespace { + //@cond /** * Checks this property exists in the list of algorithm properties. */ @@ -61,7 +89,7 @@ namespace Mantid { /** constructor which takes 1 arguement. *@param name :: name of the property - */ + */ hasProperty(const std::string name):m_name(name){} /**This method comapres teh property name @@ -76,9 +104,11 @@ namespace Mantid /// name of teh property std::string m_name; }; + + //@endcond } - /** + /** * Executes the algorithm. */ void Load::exec() @@ -88,123 +118,127 @@ namespace Mantid std::string ext = fileName.substr(i+1); std::transform(ext.begin(),ext.end(),ext.begin(),tolower); //get the shared pointer to the specialised load algorithm to execute - API::IAlgorithm_sptr alg= getFileLoader(fileName); - if(!alg) + API::IAlgorithm_sptr loader = getFileLoader(fileName); + if( !loader ) + { + throw std::runtime_error("Cannot find a loader for \"" + fileName + "\""); + } + else { - throw std::runtime_error("Cannot load file " + fileName); + setPropertyValue("LoaderName", loader->name()); } + bool findOnly = getProperty("FindLoader"); if( findOnly ) return; - g_log.information()<<"The sub load algorithm created to execute is "<<alg->name()<<" and it version is "<<alg->version()<<std::endl; - double startProgress=0,endProgress=1; - // set the load algorithm as a child algorithm - initialiseLoadSubAlgorithm(alg,startProgress,endProgress,true,-1); + g_log.information()<<"The sub load algorithm created to execute is " + << loader->name() << " and it version is " + << loader->version() <<std::endl; + double startProgress(0.0), endProgress(1.0); + initialiseLoadSubAlgorithm(loader,startProgress,endProgress,true,-1); //get the list of properties for this algorithm std::vector<Kernel::Property*> props=getProperties(); ///get the list properties for the sub load algorithm - std::vector<Kernel::Property*>loader_props=alg->getProperties(); + std::vector<Kernel::Property*>loader_props=loader->getProperties(); //loop through the properties of this algorithm std::vector<Kernel::Property*>::iterator itr; for (itr=props.begin();itr!=props.end();++itr) { - std::vector<Mantid::Kernel::Property*>::iterator prop; - //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())); - if(prop!=loader_props.end()) - { + std::vector<Mantid::Kernel::Property*>::iterator prop; + //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())); + if(prop!=loader_props.end()) + { - alg->setPropertyValue((*prop)->name(),getPropertyValue((*prop)->name())); - } + loader->setPropertyValue((*prop)->name(),getPropertyValue((*prop)->name())); + } } - //execute the load sub algorithm - alg->execute(); - //se the workspace - setOutputWorkspace(alg); - + // Execute the concrete loader + loader->execute(); + // Set the workspace. Deals with possible multiple periods + setOutputWorkspace(loader); } - - /** 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 *@return filePath - path of the file */ - API::IAlgorithm_sptr Load::getFileLoader(const std::string& filePath) - { - unsigned char* header_buffer = header_buffer_union.c; - int nread; - /* Open the file and read in the first bufferSize bytes - these will + API::IAlgorithm_sptr Load::getFileLoader(const std::string& filePath) + { + /* Open the file and read in the first bufferSize bytes - these will * be used to determine the type of the file */ - FILE* fp = fopen(filePath.c_str(), "rb"); - if (fp == NULL) - { - throw Kernel::Exception::FileError("Unable to open the file:", filePath); - } - nread = fread((char*)header_buffer,sizeof(char), bufferSize,fp); - header_buffer[bufferSize] = '\0'; - if (nread == -1) - { - fclose(fp); - } + FILE* fp = fopen(filePath.c_str(), "rb"); + if (fp == NULL) + { + throw Kernel::Exception::FileError("Unable to open the file:", filePath); + } + //unsigned char* header_buffer = header_buffer_union.c; + //unsigned char * header_buffer = IDataFileChecker::g_hdr_buf.get(); + file_header header; + int nread = fread(&header,sizeof(unsigned char), g_hdr_bytes, fp); + // Ensure the character string is null terminated. + header.full_hdr[g_hdr_bytes] = '\0'; + if (nread == -1) + { + fclose(fp); + } - if (fclose(fp) != 0) - { - } + if (fclose(fp) != 0) + { + throw std::runtime_error("Error while closing file \"" + filePath + "\""); + } + + // 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 + // giving its certainty about be able to load the file. The highest wins. + std::vector<std::string> loaderNames = API::LoadAlgorithmFactory::Instance().getKeys(); + int highestPref(0); + API::IAlgorithm_sptr winningLoader; + std::vector<std::string>::const_iterator cend = loaderNames.end(); + for( std::vector<std::string>::const_iterator citr = loaderNames.begin(); citr != cend; + ++citr ) + { + IDataFileChecker_sptr loader = API::LoadAlgorithmFactory::Instance().create(*citr); + if( loader->quickFileCheck(filePath, nread, header) ) + { + int pref = loader->fileCheck(filePath); + // Can't just pick the first as there might be one later in the list with a higher + // preference + if( pref > highestPref ) + { + highestPref = pref; + winningLoader = loader; + } + } + } - int val=0; - API::IAlgorithm_sptr load; - // now get the name of algorithms registered in the loadAlgorithmfactory - std::vector<std::string> algnames=API::LoadAlgorithmFactory::Instance().getKeys(); - std::map<std::string, boost::shared_ptr<DataHandling::IDataFileChecker> >loadalgs; - /// create load algorithms and store it in a map - std::vector<std::string>::const_iterator citr; - for (citr=algnames.begin();citr!=algnames.end();++citr) - { - loadalgs[*citr]= API::LoadAlgorithmFactory::Instance().create(*citr); - } - - std::map<std::string, boost::shared_ptr<DataHandling::IDataFileChecker> >::const_iterator alg_itr; - //loop thorugh the map and do a quick check for each load algorithm by opening the file and look at it's first 100 bytes and extensions - //if quick check succeeds then do a filecheck again by opening the file and read the structure of the file - for (alg_itr=loadalgs.begin();alg_itr!=loadalgs.end();++alg_itr) - { - bool bcheck=alg_itr->second->quickFileCheck(filePath,nread,header_buffer); - if(!bcheck) - { - continue; - } - int ret=alg_itr->second->fileCheck(filePath); - if(ret>val) - { - // algorithm with highest preference will cached. - val=ret; - load=alg_itr->second; - } - } - if( load ) - { - setPropertyValue("LoaderName", load->name()); - } - return load; - } + if( !winningLoader ) + { + throw std::runtime_error("Cannot find a loader for \"" + filePath + "\""); + } + return winningLoader; + } - /** This method set the algorithm as a child algorithm. - * @param alg :: The shared pointer to a algorithm - * @param startProgress :: The percentage progress value of the overall algorithm where this child algorithm starts - * @param endProgress :: The percentage progress value of the overall algorithm where this child algorithm ends - * @param enableLogging :: Set to false to disable logging from the child algorithm - * @param version :: The version of the child algorithm to create. By default gives the latest version. - */ - void Load::initialiseLoadSubAlgorithm(API::IAlgorithm_sptr alg, const double startProgress, const double endProgress, - const bool enableLogging, const int& version) - + /** This method set the algorithm as a child algorithm. + * @param alg :: The shared pointer to a algorithm + * @param startProgress :: The percentage progress value of the overall + * algorithm where this child algorithm starts + * @param endProgress :: The percentage progress value of the overall + * algorithm where this child algorithm ends + * @param enableLogging :: Set to false to disable logging from the child algorithm + * @param version :: The version of the child algorithm to create. + * By default gives the latest version. + */ + void Load::initialiseLoadSubAlgorithm(API::IAlgorithm_sptr alg, + const double startProgress, const double endProgress, + const bool enableLogging, const int& version) { (void) version; // Avoid compiler warning. - //set as a child + //Set as a child so that we are in control of output storage alg->initialize(); alg->setChild(true); alg->setLogging(enableLogging); @@ -213,56 +247,56 @@ namespace Mantid const std::vector< Property*> &props = alg->getProperties(); for (unsigned int i = 0; i < props.size(); ++i) { - if (props[i]->direction() == 1 && dynamic_cast<IWorkspaceProperty*>(props[i]) ) - { - if ( props[i]->value().empty() ) props[i]->setValue("ChildAlgOutput"); - } + if (props[i]->direction() == 1 && dynamic_cast<IWorkspaceProperty*>(props[i]) ) + { + 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->setChildStartProgress(startProgress); - alg->setChildEndProgress(endProgress); + alg->addObserver(m_progressObserver); + alg->setChildStartProgress(startProgress); + alg->setChildEndProgress(endProgress); } } /** - * Set the output workspace(s) if the load's return workspace - * has type API::Workspace - *@param load :: shared pointer to load algorithm - */ + * Set the output workspace(s) if the load's return workspace + * has type API::Workspace + *@param load :: shared pointer to load algorithm + */ void Load::setOutputWorkspace(API::IAlgorithm_sptr& load) { try { - Workspace_sptr ws = load->getProperty("OutputWorkspace"); - WorkspaceGroup_sptr wsg = boost::dynamic_pointer_cast<WorkspaceGroup>(ws); - if (wsg) - { - setProperty("OutputWorkspace",ws); - std::vector<std::string> names = wsg->getNames(); - for(size_t i = 0; i < names.size(); ++i) - { - std::ostringstream propName; - propName << "OutputWorkspace_" << (i+1); - DataObjects::Workspace2D_sptr memberwsws1 = load->getProperty(propName.str()); + Workspace_sptr ws = load->getProperty("OutputWorkspace"); + WorkspaceGroup_sptr wsg = boost::dynamic_pointer_cast<WorkspaceGroup>(ws); + if (wsg) + { + setProperty("OutputWorkspace",ws); + std::vector<std::string> names = wsg->getNames(); + for(size_t i = 0; i < names.size(); ++i) + { + std::ostringstream propName; + propName << "OutputWorkspace_" << (i+1); + DataObjects::Workspace2D_sptr memberwsws1 = load->getProperty(propName.str()); - std::string memberwsName = load->getPropertyValue(propName.str()); - declareProperty(new WorkspaceProperty<>(propName.str(),memberwsName,Direction::Output)); - setProperty(propName.str(),boost::dynamic_pointer_cast<MatrixWorkspace>(memberwsws1)); - } - } - else - { - setProperty("OutputWorkspace",ws); - } + std::string memberwsName = load->getPropertyValue(propName.str()); + declareProperty(new WorkspaceProperty<>(propName.str(),memberwsName,Direction::Output)); + setProperty(propName.str(),boost::dynamic_pointer_cast<MatrixWorkspace>(memberwsws1)); + } + } + else + { + setProperty("OutputWorkspace",ws); + } } catch(std::runtime_error&) { - MatrixWorkspace_sptr mws=load->getProperty("OutputWorkspace"); - setProperty("OutputWorkspace",boost::dynamic_pointer_cast<Workspace>(mws)); + MatrixWorkspace_sptr mws=load->getProperty("OutputWorkspace"); + setProperty("OutputWorkspace",boost::dynamic_pointer_cast<Workspace>(mws)); } diff --git a/Code/Mantid/Framework/DataHandling/src/LoadAscii.cpp b/Code/Mantid/Framework/DataHandling/src/LoadAscii.cpp index 850643153fc53ef73d926c20d5416da9d93bf282..2fec0f90a32e645d43c561d7e73c11df90830563 100644 --- a/Code/Mantid/Framework/DataHandling/src/LoadAscii.cpp +++ b/Code/Mantid/Framework/DataHandling/src/LoadAscii.cpp @@ -169,10 +169,10 @@ namespace Mantid /**This method does a quick file check by checking the no.of bytes read nread params and header buffer * @param filePath- path of the file including name. * @param nread :: no.of bytes read - * @param header_buffer :: buffer containing the 1st 100 bytes of the file + * @param header :: The first 100 bytes of the file as a union * @return true if the given file is of type which can be loaded by this algorithm */ - bool LoadAscii::quickFileCheck(const std::string& filePath,size_t nread,unsigned char* header_buffer) + bool LoadAscii::quickFileCheck(const std::string& filePath,size_t nread,const file_header& header) { std::string extn=extension(filePath); bool bascii(false); @@ -181,7 +181,7 @@ namespace Mantid bool is_ascii (true); for(size_t i=0; i<nread; i++) { - if (!isascii(header_buffer[i])) + if (!isascii(header.full_hdr[i])) is_ascii =false; } return(is_ascii|| bascii?true:false); diff --git a/Code/Mantid/Framework/DataHandling/src/LoadCanSAS1D.cpp b/Code/Mantid/Framework/DataHandling/src/LoadCanSAS1D.cpp index d14db0dc8e493a0ecbec4240bfaa3d2733fd9cfa..d40c9be10fa1235fe5608516c1c5a3e02cf9ecf4 100644 --- a/Code/Mantid/Framework/DataHandling/src/LoadCanSAS1D.cpp +++ b/Code/Mantid/Framework/DataHandling/src/LoadCanSAS1D.cpp @@ -293,10 +293,10 @@ void LoadCanSAS1D::createLogs(const Poco::XML::Element * const sasEntry, API::Ma /**This method does a quick file check by checking the no.of bytes read nread params and header buffer * @param filePath- path of the file including name. * @param nread :: no.of bytes read - * @param header_buffer :: buffer containing the 1st 100 bytes of the file + * @param header :: The first 100 bytes of the file as a union * @return true if the given file is of type which can be loaded by this algorithm */ -bool LoadCanSAS1D::quickFileCheck(const std::string& filePath,size_t nread,unsigned char* header_buffer) +bool LoadCanSAS1D::quickFileCheck(const std::string& filePath,size_t nread,const file_header& header) { std::string extn=extension(filePath); bool bspice2d(false); @@ -304,7 +304,7 @@ bool LoadCanSAS1D::quickFileCheck(const std::string& filePath,size_t nread,unsig const char* xml_header="<?xml version="; if ( ((unsigned)nread >= strlen(xml_header)) && - !strncmp((char*)header_buffer, xml_header, strlen(xml_header)) ) + !strncmp((char*)header.full_hdr, xml_header, strlen(xml_header)) ) { } return(bspice2d?true:false); diff --git a/Code/Mantid/Framework/DataHandling/src/LoadGSS.cpp b/Code/Mantid/Framework/DataHandling/src/LoadGSS.cpp index 01227458a642d05dad65a6bc12387c9f58f2c76f..5e0afc17693543c4b5f95cafceb11c95df6315dd 100644 --- a/Code/Mantid/Framework/DataHandling/src/LoadGSS.cpp +++ b/Code/Mantid/Framework/DataHandling/src/LoadGSS.cpp @@ -1,239 +1,239 @@ -//--------------------------------------------------- -// Includes -//--------------------------------------------------- -#include "MantidDataHandling/LoadGSS.h" -#include "MantidAPI/FileProperty.h" -#include "MantidAPI/WorkspaceValidators.h" -#include "MantidKernel/UnitFactory.h" - -#include <boost/math/special_functions/fpclassify.hpp> -#include "MantidAPI/LoadAlgorithmFactory.h" -#include "Poco/File.h" -#include <iostream> -#include <fstream> -#include <iomanip> - -using namespace Mantid::DataHandling; -using namespace Mantid::API; -using namespace Mantid::Kernel; - -// Register the algorithm into the AlgorithmFactory -DECLARE_ALGORITHM(LoadGSS) - -//register the algorithm into loadalgorithm factory -DECLARE_LOADALGORITHM(LoadGSS) -//--------------------------------------------------- -// Private member functions -//--------------------------------------------------- -/** -* Initialise the algorithm -*/ -void LoadGSS::init() -{ - declareProperty(new API::FileProperty("Filename", "", API::FileProperty::Load), "The input filename of the stored data"); - declareProperty(new API::WorkspaceProperty<>("OutputWorkspace", "", Kernel::Direction::Output)); -} - -/** -* Execute the algorithm -*/ -void LoadGSS::exec() -{ - using namespace Mantid::API; - std::string filename = getProperty("Filename"); - - std::vector<MantidVec*> gsasDataX; - std::vector<MantidVec*> gsasDataY; - std::vector<MantidVec*> gsasDataE; - - std::string wsTitle; - - std::ifstream input(filename.c_str(), std::ios_base::in); - - MantidVec* X = new MantidVec(); - MantidVec* Y = new MantidVec(); - MantidVec* E = new MantidVec(); - - int nSpec = 0; - - Progress* prog = NULL; - - char currentLine[256]; - - // Gather data - if ( input.is_open() ) - { - if ( ! input.eof() ) - { - // Get workspace title (should be first line) - input.getline(currentLine, 256); - wsTitle = currentLine; - } - while ( ! input.eof() && input.getline(currentLine, 256) ) - { - if ( nSpec != 0 && prog == NULL ) - { - prog = new Progress(this, 0.0, 1.0, nSpec); - } - double bc1; - double bc2; - double bc4; - if ( currentLine[0] == '\n' || currentLine[0] == '#' ) - { - if ( nSpec == 0 ) - { - int noSpectra = 0; - std::string line; - - std::istringstream inputLine(currentLine, std::ios::in); - inputLine.ignore(256, ' '); - inputLine >> noSpectra >> line; - - if ( ( noSpectra != 0 ) && ( line == "Histograms" ) ) - { - nSpec = noSpectra; - } - } - continue; - } - else if ( currentLine[0] == 'B' ) - { - if ( X->size() != 0 ) - { - gsasDataX.push_back(X); - gsasDataY.push_back(Y); - gsasDataE.push_back(E); - - if ( prog != NULL ) - prog->report(); - } - - /* BANK <SpectraNo> <NBins> <NBins> RALF <BC1> <BC2> <BC1> <BC4> - * BC1 = X[0] * 32 - * BC2 = X[1] * 32 - BC1 - * BC4 = ( X[1] - X[0] ) / X[0] - */ - X = new MantidVec(); - Y = new MantidVec(); - E = new MantidVec(); - - std::istringstream inputLine(currentLine, std::ios::in); - inputLine.ignore(256, 'F'); - inputLine >> bc1 >> bc2 >> bc1 >> bc4; - - double x0 = bc1 / 32; - X->push_back(x0); - } - else - { - double xValue; - double yValue; - double eValue; - - double xPrev; - - if ( X->size() != 0 ) - { - xPrev = X->back(); - } - else - { - throw Mantid::Kernel::Exception::NotImplementedError("LoadGSS: File was not in expected format."); - } - - std::istringstream inputLine(currentLine, std::ios::in); - inputLine >> xValue >> yValue >> eValue; - - xValue = (2 * xValue) - xPrev; - yValue = yValue / ( xPrev * bc4 ); - eValue = eValue / ( xPrev * bc4 ); - X->push_back(xValue); - Y->push_back(yValue); - E->push_back(eValue); - } - } - if ( X->size() != 0 ) - { // Put final spectra into data - gsasDataX.push_back(X); - gsasDataY.push_back(Y); - gsasDataE.push_back(E); - } - input.close(); - } - - int nHist = gsasDataX.size(); - int xWidth = X->size(); - int yWidth = Y->size(); - - // Create workspace - MatrixWorkspace_sptr outputWorkspace = boost::dynamic_pointer_cast<MatrixWorkspace> (WorkspaceFactory::Instance().create("Workspace2D", nHist, xWidth, yWidth)); - // GSS Files data is always in TOF - outputWorkspace->getAxis(0)->unit() = UnitFactory::Instance().create("TOF"); - // Set workspace title - outputWorkspace->setTitle(wsTitle); - // Put data from MatidVec's into outputWorkspace - for ( int i = 0; i < nHist; ++i ) - { - // Move data across - outputWorkspace->dataX(i) = *gsasDataX[i]; - outputWorkspace->dataY(i) = *gsasDataY[i]; - outputWorkspace->dataE(i) = *gsasDataE[i]; - } - - setProperty("OutputWorkspace", outputWorkspace); - return; -} - - -/**This method does a quick file type check by checking the first 100 bytes of the file - * @param filePath- path of the file including name. - * @param nread :: no.of bytes read - * @param header_buffer :: buffer containing the 1st 100 bytes of the file - * @return true if the given file is of type which can be loaded by this algorithm - */ - bool LoadGSS::quickFileCheck(const std::string& filePath,size_t nread,unsigned char* header_buffer) - { - std::string extn=extension(filePath); - bool bascii(false); - (!extn.compare("txt"))?bascii=true:bascii=false; - - bool is_ascii (true); - for(size_t i=0; i<nread; i++) - { - if (!isascii(header_buffer[i])) - is_ascii =false; - } - return(is_ascii|| bascii?true:false); - } - -/**checks the file by opening it and reading few lines - * @param filePath :: name of the file inluding its path - * @return an integer value how much this algorithm can load the file - */ - int LoadGSS::fileCheck(const std::string& filePath) - { - std::ifstream file(filePath.c_str()); - if (!file) - { - g_log.error("Unable to open file: " + filePath); - throw Exception::FileError("Unable to open file: " , filePath); - } - std::string str; - getline(file,str);//workspace ttile first line - while (!file.eof()) - { - getline(file,str); - if(str.empty()||str[0]=='#') - { - continue; - } - if(!str.substr(0,4).compare("BANK")&& (str.find("RALF")!=std::string::npos)&& (str.find("FXYE")!=std::string::npos)) - { - return 80; - } - return 0; - } - return 0; - - } - +//--------------------------------------------------- +// Includes +//--------------------------------------------------- +#include "MantidDataHandling/LoadGSS.h" +#include "MantidAPI/FileProperty.h" +#include "MantidAPI/WorkspaceValidators.h" +#include "MantidKernel/UnitFactory.h" + +#include <boost/math/special_functions/fpclassify.hpp> +#include "MantidAPI/LoadAlgorithmFactory.h" +#include "Poco/File.h" +#include <iostream> +#include <fstream> +#include <iomanip> + +using namespace Mantid::DataHandling; +using namespace Mantid::API; +using namespace Mantid::Kernel; + +// Register the algorithm into the AlgorithmFactory +DECLARE_ALGORITHM(LoadGSS) + +//register the algorithm into loadalgorithm factory +DECLARE_LOADALGORITHM(LoadGSS) +//--------------------------------------------------- +// Private member functions +//--------------------------------------------------- +/** +* Initialise the algorithm +*/ +void LoadGSS::init() +{ + declareProperty(new API::FileProperty("Filename", "", API::FileProperty::Load), "The input filename of the stored data"); + declareProperty(new API::WorkspaceProperty<>("OutputWorkspace", "", Kernel::Direction::Output)); +} + +/** +* Execute the algorithm +*/ +void LoadGSS::exec() +{ + using namespace Mantid::API; + std::string filename = getProperty("Filename"); + + std::vector<MantidVec*> gsasDataX; + std::vector<MantidVec*> gsasDataY; + std::vector<MantidVec*> gsasDataE; + + std::string wsTitle; + + std::ifstream input(filename.c_str(), std::ios_base::in); + + MantidVec* X = new MantidVec(); + MantidVec* Y = new MantidVec(); + MantidVec* E = new MantidVec(); + + int nSpec = 0; + + Progress* prog = NULL; + + char currentLine[256]; + + // Gather data + if ( input.is_open() ) + { + if ( ! input.eof() ) + { + // Get workspace title (should be first line) + input.getline(currentLine, 256); + wsTitle = currentLine; + } + while ( ! input.eof() && input.getline(currentLine, 256) ) + { + if ( nSpec != 0 && prog == NULL ) + { + prog = new Progress(this, 0.0, 1.0, nSpec); + } + double bc1; + double bc2; + double bc4; + if ( currentLine[0] == '\n' || currentLine[0] == '#' ) + { + if ( nSpec == 0 ) + { + int noSpectra = 0; + std::string line; + + std::istringstream inputLine(currentLine, std::ios::in); + inputLine.ignore(256, ' '); + inputLine >> noSpectra >> line; + + if ( ( noSpectra != 0 ) && ( line == "Histograms" ) ) + { + nSpec = noSpectra; + } + } + continue; + } + else if ( currentLine[0] == 'B' ) + { + if ( X->size() != 0 ) + { + gsasDataX.push_back(X); + gsasDataY.push_back(Y); + gsasDataE.push_back(E); + + if ( prog != NULL ) + prog->report(); + } + + /* BANK <SpectraNo> <NBins> <NBins> RALF <BC1> <BC2> <BC1> <BC4> + * BC1 = X[0] * 32 + * BC2 = X[1] * 32 - BC1 + * BC4 = ( X[1] - X[0] ) / X[0] + */ + X = new MantidVec(); + Y = new MantidVec(); + E = new MantidVec(); + + std::istringstream inputLine(currentLine, std::ios::in); + inputLine.ignore(256, 'F'); + inputLine >> bc1 >> bc2 >> bc1 >> bc4; + + double x0 = bc1 / 32; + X->push_back(x0); + } + else + { + double xValue; + double yValue; + double eValue; + + double xPrev; + + if ( X->size() != 0 ) + { + xPrev = X->back(); + } + else + { + throw Mantid::Kernel::Exception::NotImplementedError("LoadGSS: File was not in expected format."); + } + + std::istringstream inputLine(currentLine, std::ios::in); + inputLine >> xValue >> yValue >> eValue; + + xValue = (2 * xValue) - xPrev; + yValue = yValue / ( xPrev * bc4 ); + eValue = eValue / ( xPrev * bc4 ); + X->push_back(xValue); + Y->push_back(yValue); + E->push_back(eValue); + } + } + if ( X->size() != 0 ) + { // Put final spectra into data + gsasDataX.push_back(X); + gsasDataY.push_back(Y); + gsasDataE.push_back(E); + } + input.close(); + } + + int nHist = gsasDataX.size(); + int xWidth = X->size(); + int yWidth = Y->size(); + + // Create workspace + MatrixWorkspace_sptr outputWorkspace = boost::dynamic_pointer_cast<MatrixWorkspace> (WorkspaceFactory::Instance().create("Workspace2D", nHist, xWidth, yWidth)); + // GSS Files data is always in TOF + outputWorkspace->getAxis(0)->unit() = UnitFactory::Instance().create("TOF"); + // Set workspace title + outputWorkspace->setTitle(wsTitle); + // Put data from MatidVec's into outputWorkspace + for ( int i = 0; i < nHist; ++i ) + { + // Move data across + outputWorkspace->dataX(i) = *gsasDataX[i]; + outputWorkspace->dataY(i) = *gsasDataY[i]; + outputWorkspace->dataE(i) = *gsasDataE[i]; + } + + setProperty("OutputWorkspace", outputWorkspace); + return; +} + + +/**This method does a quick file type check by checking the first 100 bytes of the file + * @param filePath- path of the file including name. + * @param nread :: no.of bytes read + * @param header :: The first 100 bytes of the file as a union + * @return true if the given file is of type which can be loaded by this algorithm + */ + bool LoadGSS::quickFileCheck(const std::string& filePath,size_t nread,const file_header& header) + { + std::string extn=extension(filePath); + bool bascii(false); + (!extn.compare("txt"))?bascii=true:bascii=false; + + bool is_ascii (true); + for(size_t i=0; i<nread; i++) + { + if (!isascii(header.full_hdr[i])) + is_ascii =false; + } + return(is_ascii|| bascii?true:false); + } + +/**checks the file by opening it and reading few lines + * @param filePath :: name of the file inluding its path + * @return an integer value how much this algorithm can load the file + */ + int LoadGSS::fileCheck(const std::string& filePath) + { + std::ifstream file(filePath.c_str()); + if (!file) + { + g_log.error("Unable to open file: " + filePath); + throw Exception::FileError("Unable to open file: " , filePath); + } + std::string str; + getline(file,str);//workspace ttile first line + while (!file.eof()) + { + getline(file,str); + if(str.empty()||str[0]=='#') + { + continue; + } + if(!str.substr(0,4).compare("BANK")&& (str.find("RALF")!=std::string::npos)&& (str.find("FXYE")!=std::string::npos)) + { + return 80; + } + return 0; + } + return 0; + + } + diff --git a/Code/Mantid/Framework/DataHandling/src/LoadRKH.cpp b/Code/Mantid/Framework/DataHandling/src/LoadRKH.cpp index 6f18edf65b4238a7f285cbea9be6218d8256ad1f..9ad231d6f7dc4bb0ee0cf186f02e3e1b68262ef2 100644 --- a/Code/Mantid/Framework/DataHandling/src/LoadRKH.cpp +++ b/Code/Mantid/Framework/DataHandling/src/LoadRKH.cpp @@ -436,10 +436,10 @@ void LoadRKH::binCenter(const MantidVec oldBoundaries, MantidVec & toCenter) con /**This method does a quick file check by checking the no.of bytes read nread params and header buffer * @param filePath- path of the file including name. * @param nread :: no.of bytes read - * @param header_buffer :: buffer containing the 1st 100 bytes of the file + * @param header :: The first 100 bytes of the file as a union * @return true if the given file is of type which can be loaded by this algorithm */ -bool LoadRKH::quickFileCheck(const std::string& filePath,size_t nread,unsigned char* header_buffer) +bool LoadRKH::quickFileCheck(const std::string& filePath,size_t nread,const file_header& header) { std::string extn=extension(filePath); bool bascii(false); @@ -448,7 +448,7 @@ bool LoadRKH::quickFileCheck(const std::string& filePath,size_t nread,unsigned c bool is_ascii (true); for(size_t i=0; i<nread; i++) { - if (!isascii(header_buffer[i])) + if (!isascii(header.full_hdr[i])) is_ascii =false; } return(is_ascii|| bascii?true:false); @@ -584,4 +584,4 @@ int LoadRKH::fileCheck(const std::string& filePath) } } -} \ No newline at end of file +} diff --git a/Code/Mantid/Framework/DataHandling/src/LoadRaw/vms_convert.cpp b/Code/Mantid/Framework/DataHandling/src/LoadRaw/vms_convert.cpp index f6ffd83622e2d4b6b86a5216cf7f7ee64977bd9a..f2c53b4fc8d1601bd30bda0bf236fb3122d8cfdd 100644 --- a/Code/Mantid/Framework/DataHandling/src/LoadRaw/vms_convert.cpp +++ b/Code/Mantid/Framework/DataHandling/src/LoadRaw/vms_convert.cpp @@ -78,6 +78,7 @@ void local_to_vax_shorts(unsigned short* sa, const int* n) sa[i] = swap_short(sa[i]); } #endif /* WORDS_BIGENDIAN */ + (void)sa; (void)n; //Avoid compiler warning return; } @@ -90,6 +91,7 @@ void vax_to_local_shorts(unsigned short* sa, const int* n) sa[i] = swap_short(sa[i]); } #endif /* WORDS_BIGENDIAN */ + (void)sa; (void)n; //Avoid compiler warning return; } @@ -103,6 +105,7 @@ void local_to_vax_ints(fort_int* ia, const fort_int* n) uia[i] = swap_int(uia[i]); } #endif /* WORDS_BIGENDIAN */ + (void)ia; (void)n; //Avoid compiler warning return; } @@ -116,6 +119,7 @@ void vax_to_local_ints(fort_int* ia, const fort_int* n) uia[i] = swap_int(uia[i]); } #endif /* WORDS_BIGENDIAN */ + (void)ia; (void)n; //Avoid compiler warning return; } @@ -413,6 +417,7 @@ void local_to_vaxf(float *val, const int *n, int *errcode) void ieee_float_to_local(float *val, const int *n, int *errcode) { #if defined(IEEEFP) + (void) val; (void)n; //Avoid compiler warning *errcode=0; #elif defined(VAXFP) int i; @@ -435,6 +440,7 @@ void ieee_float_to_local(float *val, const int *n, int *errcode) void ieee_double_to_local(double *val, const int *n, int *errcode) { #if defined(IEEEFP) + (void) val; (void)n; //Avoid compiler warning *errcode=0; #elif defined(VAXFP) #include <cvtdef> @@ -458,6 +464,7 @@ void ieee_double_to_local(double *val, const int *n, int *errcode) void local_to_ieee_float(float *val, const int *n, int *errcode) { #if defined(IEEEFP) + (void) val; (void)n; //Avoid compiler warning *errcode=0; #elif defined(VAXFP) #include <cvtdef> @@ -481,6 +488,7 @@ void local_to_ieee_float(float *val, const int *n, int *errcode) void local_to_ieee_double(double *val, const int *n, int *errcode) { #if defined(IEEEFP) + (void) val; (void)n; //Avoid compiler warning *errcode=0; #elif defined(VAXFP) int i; diff --git a/Code/Mantid/Framework/DataHandling/src/LoadRaw3.cpp b/Code/Mantid/Framework/DataHandling/src/LoadRaw3.cpp index a628bdb21af06a567fa6c371607734aa7e80f916..3eb6dc4d90524072cfc44acbf02b27bf2e8358d5 100644 --- a/Code/Mantid/Framework/DataHandling/src/LoadRaw3.cpp +++ b/Code/Mantid/Framework/DataHandling/src/LoadRaw3.cpp @@ -668,12 +668,12 @@ void LoadRaw3::separateOrexcludeMonitors(DataObjects::Workspace2D_sptr localWork /**This method does a quick file check by checking the no.of bytes read nread params and header buffer * @param filePath- path of the file including name. * @param nread :: no.of bytes read - * @param header_buffer :: buffer containing the 1st 100 bytes of the file + * @param header :: The first 100 bytes of the file as a union * @return true if the given file is of type which can be loaded by this algorithm */ -bool LoadRaw3::quickFileCheck(const std::string& filePath,size_t nread,unsigned char* header_buffer) +bool LoadRaw3::quickFileCheck(const std::string& filePath,size_t nread,const file_header& header) { - return(LoadRawHelper::quickFileCheck(filePath,nread,header_buffer)?true:false); + return LoadRawHelper::quickFileCheck(filePath,nread,header); } /**checks the file by opening it and reading few lines diff --git a/Code/Mantid/Framework/DataHandling/src/LoadRawHelper.cpp b/Code/Mantid/Framework/DataHandling/src/LoadRawHelper.cpp index 856406dcba54250c827638fc2b0ec3d25b3882ff..8448c75f77a4ba488536da15bd3e1f0c3f082f1b 100644 --- a/Code/Mantid/Framework/DataHandling/src/LoadRawHelper.cpp +++ b/Code/Mantid/Framework/DataHandling/src/LoadRawHelper.cpp @@ -1021,66 +1021,76 @@ namespace Mantid } -/**This method does a quick file check by checking the no.of bytes read nread params and header buffer - * @param filePath- path of the file including name. - * @param nread :: no.of bytes read - * @param header_buffer :: buffer containing the 1st 100 bytes of the file - * @return true if the given file is of type which can be loaded by this algorithm - */ -bool LoadRawHelper::quickFileCheck(const std::string& filePath,size_t nread,unsigned char* header_buffer) -{ - std::string extn=extension(filePath); - bool braw(false); - (!extn.compare("raw")||!extn.compare("add")||extn[0]=='s')?braw=true:braw=false; - /* - * look at the "address of RUN and INST section" attribute - if there, must be an ISIS raw file - */ - if ( ((nread > 88) && (header_buffer[84] == 32) && (header_buffer[88] == 126))|| braw ) - { - return true; - } - else - { - return false; - } - -} -/**checks the file by opening it and reading few lines - * @param filePath :: name of the file inluding its path - * @return an integer value how much this algorithm can load the file - */ -int LoadRawHelper::fileCheck(const std::string& filePath) -{ - - unsigned char* hdr_buffer = buffer_union.c; - int nread; - /* Open the file and read in the first bufferSize bytes - these will - * be used to determine the type of the file - */ - int bret=0; - FILE* fp = fopen(filePath.c_str(), "rb"); - if (fp == NULL) - { - return bret; - } - nread = fread((char*)hdr_buffer,sizeof(char), bufferSize,fp); - hdr_buffer[bufferSize] = '\0'; - if (nread == -1) - { - fclose(fp); - return bret; - } + /** + * Check if the buffer looks like a RAW file header by looking at + * at the "address of RUN and INST section" attribute - if there, it's an ISIS raw file. + * @param nread The number of bytes in the buffer + * @param buffer A buffer of nread bytes of the file + * @returns True if this looks like an ISIS raw file + */ + bool LoadRawHelper::isRawFileHeader(const int nread, const unsigned char* buffer) const + { + if( nread > 88 && (buffer[84] == 32) && (buffer[88] == 126) ) + { + return true; + } + else return false; + } + - if (fclose(fp) != 0) - { - } + /**This method does a quick file check by checking the no.of bytes read nread params and header buffer + * @param filePath- path of the file including name. + * @param nread :: no.of bytes read + * @param header :: The first 100 bytes of the file as a union + * @return true if the given file is of type which can be loaded by this algorithm + */ + bool LoadRawHelper::quickFileCheck(const std::string& filePath,size_t nread,const file_header& header) + { + std::string extn=extension(filePath); + bool braw = (!extn.compare("raw")||!extn.compare("add")||extn[0]=='s') ? true : false; + if( isRawFileHeader(nread, header.full_hdr) || braw ) + { + return true; + } + else + { + return false; + } + } + /**Checks the file by opening it and reading few lines + * @param filePath :: name of the file inluding its path + * @return an integer value how much this algorithm can load the file + */ + int LoadRawHelper::fileCheck(const std::string& filePath) + { + /* Open the file and read in the first bufferSize bytes - these will + * be used to determine the type of the file + */ + int bret=0; + FILE* fp = fopen(filePath.c_str(), "rb"); + if (fp == NULL) + { + return bret; + } + file_header header; + int nread = fread(&header,sizeof(unsigned char), IDataFileChecker::g_hdr_bytes, fp); + header.full_hdr[IDataFileChecker::g_hdr_bytes] = '\0'; + if (nread == -1) + { + fclose(fp); + return bret; + } - if ((nread > 88) && (hdr_buffer[84] == 32) && (hdr_buffer[88] == 126)) - { - bret=80; - } - return bret; -} + if (fclose(fp) != 0) + { + } + + if( isRawFileHeader(nread, header.full_hdr) ) + { + bret=80; + } + return bret; + } diff --git a/Code/Mantid/Framework/DataHandling/src/LoadSNSspec.cpp b/Code/Mantid/Framework/DataHandling/src/LoadSNSspec.cpp index 7e4f517b896810f4854f718741377c89d0541d95..13a907f077ec21fc8fc085fe6027fe6467003320 100644 --- a/Code/Mantid/Framework/DataHandling/src/LoadSNSspec.cpp +++ b/Code/Mantid/Framework/DataHandling/src/LoadSNSspec.cpp @@ -16,7 +16,7 @@ namespace Mantid { // Register the algorithm into the algorithm factory DECLARE_ALGORITHM(LoadSNSspec) - //register the algorithm into loadalgorithm factory + //register the algorithm into loadalgorithm factory DECLARE_LOADALGORITHM(LoadSNSspec) using namespace Kernel; @@ -173,95 +173,95 @@ namespace Mantid } } - /**This method does a quick file check by checking the no.of bytes read nread params and header buffer - * @param filePath- path of the file including name. - * @param nread :: no.of bytes read - * @param header_buffer :: buffer containing the 1st 100 bytes of the file - * @return true if the given file is of type which can be loaded by this algorithm - */ - bool LoadSNSspec::quickFileCheck(const std::string& filePath,size_t nread,unsigned char* header_buffer) - { - std::string extn=extension(filePath); - bool bascii(false); - (!extn.compare("txt"))?bascii=true:bascii=false; - - bool is_ascii (true); - for(size_t i=0; i<nread; i++) - { - if (!isascii(header_buffer[i])) - is_ascii =false; - } - return(is_ascii|| bascii?true:false); - } - -/**checks the file by opening it and reading few lines - * @param filePath :: name of the file including its path - * @return an integer value how much this algorithm can load the file - */ - int LoadSNSspec::fileCheck(const std::string& filePath) - { - std::ifstream file(filePath.c_str()); - if (!file) - { - g_log.error("Unable to open file: " + filePath); - throw Exception::FileError("Unable to open file: " , filePath); - } - - int bret=0; - int axiscols=0; - int datacols=0; - std::string str; + /**This method does a quick file check by checking the no.of bytes read nread params and header buffer + * @param filePath- path of the file including name. + * @param nread :: no.of bytes read + * @param header :: The first 100 bytes of the file as a union + * @return true if the given file is of type which can be loaded by this algorithm + */ + bool LoadSNSspec::quickFileCheck(const std::string& filePath,size_t nread,const file_header& header) + { + std::string extn=extension(filePath); + bool bascii(false); + (!extn.compare("txt"))?bascii=true:bascii=false; + + bool is_ascii (true); + for(size_t i=0; i<nread; i++) + { + if (!isascii(header.full_hdr[i])) + is_ascii =false; + } + return(is_ascii|| bascii?true:false); + } + +/**checks the file by opening it and reading few lines + * @param filePath :: name of the file including its path + * @return an integer value how much this algorithm can load the file + */ + int LoadSNSspec::fileCheck(const std::string& filePath) + { + std::ifstream file(filePath.c_str()); + if (!file) + { + g_log.error("Unable to open file: " + filePath); + throw Exception::FileError("Unable to open file: " , filePath); + } + + int bret=0; + int axiscols=0; + int datacols=0; + std::string str; typedef boost::tokenizer<boost::char_separator<char> > tokenizer; boost::char_separator<char> sep(" "); - bool bsnsspec(false); - while(!file.eof()) - { - //read line - std::getline(file,str); - if(str.empty()) - { - continue; - } - try - { - //if it's comment line - if (str.at(0)=='#' ) - { - if(str.at(1) =='L') - { - tokenizer tok(str, sep); + bool bsnsspec(false); + while(!file.eof()) + { + //read line + std::getline(file,str); + if(str.empty()) + { + continue; + } + try + { + //if it's comment line + if (str.at(0)=='#' ) + { + if(str.at(1) =='L') + { + tokenizer tok(str, sep); for (tokenizer::iterator beg=tok.begin(); beg!=tok.end(); ++beg) { ++axiscols; - } - //if the file contains a comment line starting with "#L" followed - //by three columns this could be loadsnsspec file - if(axiscols>2) - { - bsnsspec=true; - } - } - } - else - { - //check first data line is a 3 column line + } + //if the file contains a comment line starting with "#L" followed + //by three columns this could be loadsnsspec file + if(axiscols>2) + { + bsnsspec=true; + } + } + } + else + { + //check first data line is a 3 column line tokenizer tok(str, sep); for (tokenizer::iterator beg=tok.begin(); beg!=tok.end(); ++beg) { ++datacols; - } - break; - } - } - catch(std::out_of_range& ) - { - } - } - if(bsnsspec && datacols==3 )//three column data - { - bret=80; - } - return bret; + } + break; + } + } + catch(std::out_of_range& ) + { + } + } + if(bsnsspec && datacols==3 )//three column data + { + bret=80; + } + return bret; } } // namespace DataHandling } // namespace Mantid diff --git a/Code/Mantid/Framework/DataHandling/src/LoadSPE.cpp b/Code/Mantid/Framework/DataHandling/src/LoadSPE.cpp index 04a732668f62d02fd7d88bebbdedba87d5f9b4a4..be1cf62c591e74dfdb1f6464ba1b34037d342cad 100644 --- a/Code/Mantid/Framework/DataHandling/src/LoadSPE.cpp +++ b/Code/Mantid/Framework/DataHandling/src/LoadSPE.cpp @@ -231,10 +231,10 @@ void LoadSPE::reportFormatError(const std::string& what) /**This method does a quick file check by checking the no.of bytes read nread params and header buffer * @param filePath- path of the file including name. * @param nread :: no.of bytes read - * @param header_buffer :: buffer containing the 1st 100 bytes of the file + * @param header :: The first 100 bytes of the file as a union * @return true if the given file is of type which can be loaded by this algorithm */ -bool LoadSPE::quickFileCheck(const std::string& filePath,size_t nread,unsigned char* header_buffer) +bool LoadSPE::quickFileCheck(const std::string& filePath,size_t nread,const file_header& header) { std::string extn=extension(filePath); bool bspe(false); @@ -242,7 +242,7 @@ bool LoadSPE::quickFileCheck(const std::string& filePath,size_t nread,unsigned c bool is_ascii (true); for(size_t i=0; i<nread; i++) { - if (!isascii(header_buffer[i])) + if (!isascii(header.full_hdr[i])) is_ascii =false; } return(is_ascii|| bspe?true:false); diff --git a/Code/Mantid/Framework/DataHandling/src/LoadSpice2D.cpp b/Code/Mantid/Framework/DataHandling/src/LoadSpice2D.cpp index 24c297e64857478afcc8a61f76ef473c80762e9e..121693577b044d5cc283eae63b966cf85c2c5def 100644 --- a/Code/Mantid/Framework/DataHandling/src/LoadSpice2D.cpp +++ b/Code/Mantid/Framework/DataHandling/src/LoadSpice2D.cpp @@ -88,7 +88,7 @@ namespace Mantid // Register the algorithm into the AlgorithmFactory DECLARE_ALGORITHM(LoadSpice2D) - //register the algorithm into loadalgorithm factory + //register the algorithm into loadalgorithm factory DECLARE_LOADALGORITHM(LoadSpice2D) /// Constructor @@ -403,32 +403,32 @@ namespace Mantid } } -/**This method does a quick file check by checking the no.of bytes read nread params and header buffer - * @param filePath- path of the file including name. - * @param nread :: no.of bytes read - * @param header_buffer :: buffer containing the 1st 100 bytes of the file - * @return true if the given file is of type which can be loaded by this algorithm - */ - bool LoadSpice2D::quickFileCheck(const std::string& filePath,size_t nread,unsigned char* header_buffer) - { - std::string extn=extension(filePath); - bool bspice2d(false); - (!extn.compare("xml"))?bspice2d=true:bspice2d=false; - - const char* xml_header="<?xml version="; - if ( ((unsigned)nread >= strlen(xml_header)) && - !strncmp((char*)header_buffer, xml_header, strlen(xml_header)) ) - { - } - return(bspice2d?true:false); - } - -/**checks the file by opening it and reading few lines - * @param filePath :: name of the file inluding its path - * @return an integer value how much this algorithm can load the file - */ - int LoadSpice2D::fileCheck(const std::string& filePath) - { +/**This method does a quick file check by checking the no.of bytes read nread params and header buffer + * @param filePath- path of the file including name. + * @param nread :: no.of bytes read + * @param header :: The first 100 bytes of the file as a union + * @return true if the given file is of type which can be loaded by this algorithm + */ + bool LoadSpice2D::quickFileCheck(const std::string& filePath,size_t nread,const file_header& header) + { + std::string extn=extension(filePath); + bool bspice2d(false); + (!extn.compare("xml"))?bspice2d=true:bspice2d=false; + + const char* xml_header="<?xml version="; + if ( ((unsigned)nread >= strlen(xml_header)) && + !strncmp((char*)header.full_hdr, xml_header, strlen(xml_header)) ) + { + } + return(bspice2d?true:false); + } + +/**checks the file by opening it and reading few lines + * @param filePath :: name of the file inluding its path + * @return an integer value how much this algorithm can load the file + */ + int LoadSpice2D::fileCheck(const std::string& filePath) + { // Set up the DOM parser and parse xml file DOMParser pParser; Document* pDoc; @@ -448,9 +448,9 @@ namespace Mantid return 80; } } - - return 0; - + + return 0; + } } } diff --git a/Code/Mantid/Framework/DataHandling/test/LoadTest.h b/Code/Mantid/Framework/DataHandling/test/LoadTest.h index 7321af7d837242bf8575f81b7d994f45bc427adb..0c2a15d72f4b2a2b0fac6bc09de681198640a324 100644 --- a/Code/Mantid/Framework/DataHandling/test/LoadTest.h +++ b/Code/Mantid/Framework/DataHandling/test/LoadTest.h @@ -80,9 +80,10 @@ public: AnalysisDataService::Instance().remove("LoadTest_Output_5"); AnalysisDataService::Instance().remove("LoadTest_Output_6"); } - //disabled because hdf4 can't be opened on windows 64-bit, I think - void testNexus() + + void testHDF4Nexus() { + // Note that there are no 64-bit HDF4 libraries for Windows. #ifndef _WIN64 Load loader; loader.initialize(); @@ -95,8 +96,9 @@ public: #endif } - void testNexusGroup() + void testHDF4NexusGroup() { + // Note that there are no 64-bit HDF4 libraries for Windows. #ifndef _WIN64 Load loader; loader.initialize(); @@ -130,7 +132,8 @@ public: loader.initialize(); loader.setPropertyValue("Filename","hrpd_new_072_01.cal"); loader.setPropertyValue("OutputWorkspace","LoadTest_Output"); - TS_ASSERT_THROWS_NOTHING(loader.execute()); + loader.setRethrows(true); + TS_ASSERT_THROWS(loader.execute(), std::runtime_error); TS_ASSERT( !loader.isExecuted() ); } diff --git a/Code/Mantid/Framework/Nexus/inc/MantidNexus/LoadISISNexus2.h b/Code/Mantid/Framework/Nexus/inc/MantidNexus/LoadISISNexus2.h index 80aa751e5e5b5811fb8c38860b873b5c0fa7fb1f..06ba9f3b68f5f851398e680a9ebd218fc6849868 100644 --- a/Code/Mantid/Framework/Nexus/inc/MantidNexus/LoadISISNexus2.h +++ b/Code/Mantid/Framework/Nexus/inc/MantidNexus/LoadISISNexus2.h @@ -77,7 +77,7 @@ namespace Mantid /// do a quick check that this file can be loaded - virtual bool quickFileCheck(const std::string& filePath,size_t nread,unsigned char* header_buffer); + virtual bool quickFileCheck(const std::string& filePath,size_t nread,const file_header& header); /// check the structure of the file and return a value between 0 and 100 of how much this file can be loaded virtual int fileCheck(const std::string& filePath); private: diff --git a/Code/Mantid/Framework/Nexus/inc/MantidNexus/LoadMuonNexus.h b/Code/Mantid/Framework/Nexus/inc/MantidNexus/LoadMuonNexus.h index cea8d0351fac8761301209d76d8fda99168b6339..4fceb548aa447172caa4a9ae6d402e2c985b6119 100644 --- a/Code/Mantid/Framework/Nexus/inc/MantidNexus/LoadMuonNexus.h +++ b/Code/Mantid/Framework/Nexus/inc/MantidNexus/LoadMuonNexus.h @@ -75,7 +75,7 @@ namespace Mantid virtual const std::string category() const { return "DataHandling"; } /// do a quick check that this file can be loaded - virtual bool quickFileCheck(const std::string& filePath,size_t nread,unsigned char* header_buffer); + virtual bool quickFileCheck(const std::string& filePath,size_t nread,const file_header& header); /// check the structure of the file and return a value between 0 and 100 of how much this file can be loaded virtual int fileCheck(const std::string& filePath); protected: diff --git a/Code/Mantid/Framework/Nexus/inc/MantidNexus/LoadMuonNexus2.h b/Code/Mantid/Framework/Nexus/inc/MantidNexus/LoadMuonNexus2.h index 7d7bf9469df3329ae84439d0fb385a459f525235..5cfa04d8d23367f29a09339d070f0352bf529516 100644 --- a/Code/Mantid/Framework/Nexus/inc/MantidNexus/LoadMuonNexus2.h +++ b/Code/Mantid/Framework/Nexus/inc/MantidNexus/LoadMuonNexus2.h @@ -74,7 +74,7 @@ namespace Mantid virtual const std::string category() const { return "DataHandling"; } /// do a quick check that this file can be loaded - virtual bool quickFileCheck(const std::string& filePath,size_t nread,unsigned char* header_buffer); + virtual bool quickFileCheck(const std::string& filePath,size_t nread,const file_header& header); /// check the structure of the file and return a value between 0 and 100 of how much this file can be loaded virtual int fileCheck(const std::string& filePath); private: diff --git a/Code/Mantid/Framework/Nexus/inc/MantidNexus/LoadNexusProcessed.h b/Code/Mantid/Framework/Nexus/inc/MantidNexus/LoadNexusProcessed.h index 695e3d62e22ddd834fe15a570b48cde1e7bfb8fc..75e485fb5ee8be31c4e3299428fe719500ca4069 100644 --- a/Code/Mantid/Framework/Nexus/inc/MantidNexus/LoadNexusProcessed.h +++ b/Code/Mantid/Framework/Nexus/inc/MantidNexus/LoadNexusProcessed.h @@ -64,7 +64,7 @@ namespace Mantid virtual const std::string category() const { return "DataHandling";} /// do a quick check that this file can be loaded - virtual bool quickFileCheck(const std::string& filePath,size_t nread,unsigned char* header_buffer); + virtual bool quickFileCheck(const std::string& filePath,size_t nread,const file_header& header); /// check the structure of the file and return a value between 0 and 100 of how much this file can be loaded virtual int fileCheck(const std::string& filePath); diff --git a/Code/Mantid/Framework/Nexus/inc/MantidNexus/LoadSNSNexus.h b/Code/Mantid/Framework/Nexus/inc/MantidNexus/LoadSNSNexus.h index 79ed5c4dbe8e0241da64990e726d2759bc9921b5..301fa3c152ea6429983aff216b8eea9d3a5cdba9 100644 --- a/Code/Mantid/Framework/Nexus/inc/MantidNexus/LoadSNSNexus.h +++ b/Code/Mantid/Framework/Nexus/inc/MantidNexus/LoadSNSNexus.h @@ -82,7 +82,7 @@ namespace NeXus /// Algorithm's category for identification overriding a virtual method virtual const std::string category() const { return "DataHandling"; } /// do a quick check that this file can be loaded - virtual bool quickFileCheck(const std::string& filePath,size_t nread,unsigned char* header_buffer); + virtual bool quickFileCheck(const std::string& filePath,size_t nread,const file_header& header); /// check the structure of the file and return a value between 0 and 100 of how much this file can be loaded virtual int fileCheck(const std::string& filePath); diff --git a/Code/Mantid/Framework/Nexus/src/LoadISISNexus2.cpp b/Code/Mantid/Framework/Nexus/src/LoadISISNexus2.cpp index bc2844abfeb34c82a6ce6fbb835aee5893849565..798b7f77bb5d6a3ffe2e7452ec4a5abb4a8f42a3 100644 --- a/Code/Mantid/Framework/Nexus/src/LoadISISNexus2.cpp +++ b/Code/Mantid/Framework/Nexus/src/LoadISISNexus2.cpp @@ -760,23 +760,24 @@ namespace Mantid /**This method does a quick file type check by looking at the first 100 bytes of the file * @param filePath- path of the file including name. * @param nread :: no.of bytes read - * @param header_buffer :: buffer containing the 1st 100 bytes of the file + * @param header :: The first 100 bytes of the file as a union * @return true if the given file is of type which can be loaded by this algorithm */ - bool LoadISISNexus2::quickFileCheck(const std::string& filePath, size_t nread,unsigned char* header_buffer) + bool LoadISISNexus2::quickFileCheck(const std::string& filePath, size_t nread,const file_header& header) { std::string extn=extension(filePath); bool bnexs(false); (!extn.compare("nxs")||!extn.compare("nx5"))?bnexs=true:bnexs=false; /* - * HDF files have magic cookie 0x0e031301 in the first 4 bytes + * HDF files have magic cookie in the first 4 bytes */ - if ( ((nread >= sizeof(unsigned)) && (ntohl(header_buffer_union.u) == 0x0e031301)) || bnexs ) + if ( ((nread >= sizeof(unsigned)) && (ntohl(header.four_bytes) == g_hdf5_cookie)) || bnexs ) { //hdf return true; } - else if ( (nread >= sizeof(hdf5_signature)) && (!memcmp(header_buffer, hdf5_signature, sizeof(hdf5_signature))) ) + else if ( (nread >= sizeof(g_hdf5_signature)) && + (!memcmp(header.full_hdr, g_hdf5_signature, sizeof(g_hdf5_signature))) ) { //hdf5 return true; diff --git a/Code/Mantid/Framework/Nexus/src/LoadMuonNexus.cpp b/Code/Mantid/Framework/Nexus/src/LoadMuonNexus.cpp index 7bb89e27210be01bab1428426dfbde60b1ca9b32..73c3e4ffdc235691e5857e685c8b7b52f4e10676 100644 --- a/Code/Mantid/Framework/Nexus/src/LoadMuonNexus.cpp +++ b/Code/Mantid/Framework/Nexus/src/LoadMuonNexus.cpp @@ -632,23 +632,25 @@ namespace Mantid /**This method does a quick file type check by looking at the first 100 bytes of the file * @param filePath- path of the file including name. * @param nread :: no.of bytes read - * @param header_buffer :: buffer containing the 1st 100 bytes of the file + * @param header :: The first 100 bytes of the file as a union * @return true if the given file is of type which can be loaded by this algorithm */ - bool LoadMuonNexus::quickFileCheck(const std::string& filePath,size_t nread,unsigned char* header_buffer) + bool LoadMuonNexus::quickFileCheck(const std::string& filePath,size_t nread,const file_header& header) { std::string extn=extension(filePath); bool bnexs(false); (!extn.compare("nxs")||!extn.compare(".nx5"))?bnexs=true:bnexs=false; /* - * HDF files have magic cookie 0x0e031301 in the first 4 bytes + * HDF files have magic cookie in the first 4 bytes */ - if ( ((nread >= sizeof(unsigned)) && (ntohl(header_buffer_union.u) == 0x0e031301)) || bnexs ) + if ( ((nread >= sizeof(unsigned)) && (ntohl(header.four_bytes) == g_hdf5_cookie)) || bnexs ) { //hdf return true; } - else if ( (nread >= sizeof(hdf5_signature)) && (!memcmp(header_buffer, hdf5_signature, sizeof(hdf5_signature))) ) + else if ( (nread >= sizeof(IDataFileChecker::g_hdf5_signature)) && + (!memcmp(header.full_hdr, IDataFileChecker::g_hdf5_signature, + sizeof(IDataFileChecker::g_hdf5_signature))) ) { //hdf5 return true; diff --git a/Code/Mantid/Framework/Nexus/src/LoadMuonNexus2.cpp b/Code/Mantid/Framework/Nexus/src/LoadMuonNexus2.cpp index d1ed0727557fd743c22047a340222b2411a7e96b..5e250277cab9d5eb5f791eaa4c7903c28d212a59 100644 --- a/Code/Mantid/Framework/Nexus/src/LoadMuonNexus2.cpp +++ b/Code/Mantid/Framework/Nexus/src/LoadMuonNexus2.cpp @@ -308,23 +308,24 @@ namespace Mantid /**This method does a quick file type check by looking at the first 100 bytes of the file * @param filePath- path of the file including name. * @param nread :: no.of bytes read - * @param header_buffer :: buffer containing the 1st 100 bytes of the file + * @param header :: The first 100 bytes of the file as a union * @return true if the given file is of type which can be loaded by this algorithm */ - bool LoadMuonNexus2::quickFileCheck(const std::string& filePath,size_t nread,unsigned char* header_buffer) + bool LoadMuonNexus2::quickFileCheck(const std::string& filePath,size_t nread,const file_header& header) { std::string extn=extension(filePath); bool bnexs(false); (!extn.compare("nxs")||!extn.compare("nx5"))?bnexs=true:bnexs=false; /* - * HDF files have magic cookie 0x0e031301 in the first 4 bytes + * HDF files have magic cookie in the first 4 bytes */ - if ( ((nread >= sizeof(unsigned)) && (ntohl(header_buffer_union.u) == 0x0e031301)) || bnexs ) + if ( ((nread >= sizeof(unsigned)) && (ntohl(header.four_bytes) == g_hdf5_cookie)) || bnexs ) { //hdf return true; } - else if ( (nread >= sizeof(hdf5_signature)) && (!memcmp(header_buffer, hdf5_signature, sizeof(hdf5_signature))) ) + else if ( (nread >= sizeof(g_hdf5_signature)) && + (!memcmp(header.full_hdr, g_hdf5_signature, sizeof(g_hdf5_signature))) ) { //hdf5 return true; diff --git a/Code/Mantid/Framework/Nexus/src/LoadNexusProcessed.cpp b/Code/Mantid/Framework/Nexus/src/LoadNexusProcessed.cpp index afd83234132a6b66b944b77e1ed7fd3430d9d55b..83ab6440dff12aa432b43fc08fc0f9e7ba93031c 100644 --- a/Code/Mantid/Framework/Nexus/src/LoadNexusProcessed.cpp +++ b/Code/Mantid/Framework/Nexus/src/LoadNexusProcessed.cpp @@ -1224,23 +1224,24 @@ int LoadNexusProcessed::calculateWorkspacesize(const int numberofspectra) /**This method does a quick file type check by looking at the first 100 bytes of the file * @param filePath- path of the file including name. * @param nread :: no.of bytes read - * @param header_buffer :: buffer containing the 1st 100 bytes of the file + * @param header :: The first 100 bytes of the file as a union * @return true if the given file is of type which can be loaded by this algorithm */ - bool LoadNexusProcessed::quickFileCheck(const std::string& filePath,size_t nread,unsigned char* header_buffer) + bool LoadNexusProcessed::quickFileCheck(const std::string& filePath,size_t nread,const file_header& header) { std::string extn=extension(filePath); bool bnexs(false); (!extn.compare("nxs")||!extn.compare("nx5"))?bnexs=true:bnexs=false; /* - * HDF files have magic cookie 0x0e031301 in the first 4 bytes + * HDF files have magic cookie in the first 4 bytes */ - if ( ((nread >= sizeof(unsigned)) && (ntohl(header_buffer_union.u)) == 0x0e031301)||bnexs ) + if ( ((nread >= sizeof(unsigned)) && (ntohl(header.four_bytes)) == g_hdf5_cookie)||bnexs ) { //hdf return true; } - else if ( (nread >= sizeof(hdf5_signature)) && (!memcmp(header_buffer, hdf5_signature, sizeof(hdf5_signature))) ) + else if ( (nread >= sizeof(g_hdf5_signature)) && + (!memcmp(header.full_hdr, g_hdf5_signature, sizeof(g_hdf5_signature))) ) { //hdf5 return true; diff --git a/Code/Mantid/Framework/Nexus/src/LoadSNSNexus.cpp b/Code/Mantid/Framework/Nexus/src/LoadSNSNexus.cpp index 575aa4e110bef418e1af50680a6ea86bf35e06bc..23564fb2813996278a293142d320497147bd38fc 100644 --- a/Code/Mantid/Framework/Nexus/src/LoadSNSNexus.cpp +++ b/Code/Mantid/Framework/Nexus/src/LoadSNSNexus.cpp @@ -316,23 +316,25 @@ double LoadSNSNexus::dblSqrt(double in) /**This method does a quick file type check by looking at the first 100 bytes of the file * @param filePath- path of the file including name. * @param nread :: no.of bytes read - * @param header_buffer :: buffer containing the 1st 100 bytes of the file + * @param header :: The first 100 bytes of the file as a union * @return true if the given file is of type which can be loaded by this algorithm */ - bool LoadSNSNexus::quickFileCheck(const std::string& filePath,size_t nread,unsigned char* header_buffer) + bool LoadSNSNexus::quickFileCheck(const std::string& filePath,size_t nread,const file_header& header) { std::string extn=extension(filePath); bool bnexs(false); (!extn.compare("nxs")||!extn.compare("nx5"))?bnexs=true:bnexs=false; /* - * HDF files have magic cookie 0x0e031301 in the first 4 bytes + * HDF files have magic cookie in the first 4 bytes */ - if ( ((nread >= sizeof(unsigned)) && (ntohl(header_buffer_union.u) == 0x0e031301)) || bnexs ) + if ( ((nread >= sizeof(unsigned)) && (ntohl(header.four_bytes) == g_hdf5_cookie)) || bnexs ) { //hdf return true; } - else if ( (nread >= sizeof(hdf5_signature)) && (!memcmp(header_buffer, hdf5_signature, sizeof(hdf5_signature))) ) + else if ( (nread >= sizeof(IDataFileChecker::g_hdf5_signature)) && + (!memcmp(header.full_hdr, IDataFileChecker::g_hdf5_signature, + sizeof(IDataFileChecker::g_hdf5_signature))) ) { //hdf5 return true; diff --git a/Code/Mantid/Framework/Nexus/src/NeXusFile.cpp b/Code/Mantid/Framework/Nexus/src/NeXusFile.cpp index de66cc23b1e7e4ce0ceb4e4c0fdd6552b8c980ee..91e2102c42e6ce62d404def29ae4219d7849e7b8 100644 --- a/Code/Mantid/Framework/Nexus/src/NeXusFile.cpp +++ b/Code/Mantid/Framework/Nexus/src/NeXusFile.cpp @@ -75,6 +75,7 @@ namespace NeXus { template<> NXDLL_EXPORT NXnumtype getType(char number) { + (void)number; // Avoid compiler warning return CHAR; //NOTE: I have no idea why this code (below) was there and that it was not allowed to have CHAR (Janik Zikovsky, sep 22, 2010) // stringstream msg; @@ -85,51 +86,61 @@ namespace NeXus { // template specialisations for types we know template<> NXDLL_EXPORT NXnumtype getType(float number) { + (void)number; // Avoid compiler warning return FLOAT32; } template<> NXDLL_EXPORT NXnumtype getType(double number) { + (void)number; // Avoid compiler warning return FLOAT64; } template<> NXDLL_EXPORT NXnumtype getType(int8_t number) { + (void)number; // Avoid compiler warning return INT8; } template<> NXDLL_EXPORT NXnumtype getType(uint8_t number) { + (void)number; // Avoid compiler warning return UINT8; } template<> NXDLL_EXPORT NXnumtype getType(int16_t number) { + (void)number; // Avoid compiler warning return INT16; } template<> NXDLL_EXPORT NXnumtype getType(uint16_t number) { + (void)number; // Avoid compiler warning return UINT16; } template<> NXDLL_EXPORT NXnumtype getType(int32_t number) { + (void)number; // Avoid compiler warning return INT32; } template<> NXDLL_EXPORT NXnumtype getType(uint32_t number) { + (void)number; // Avoid compiler warning return UINT32; } template<> NXDLL_EXPORT NXnumtype getType(int64_t number) { + (void)number; // Avoid compiler warning return INT64; } template<> NXDLL_EXPORT NXnumtype getType(uint64_t number) { + (void)number; // Avoid compiler warning return UINT64; }