diff --git a/Framework/API/src/DeprecatedAlgorithm.cpp b/Framework/API/src/DeprecatedAlgorithm.cpp index 862cce4fb1b2d10242a8fecfb129f9161933db9f..fd07ba8e8eeaeb1d7669e12c4a14d8d4713411e4 100644 --- a/Framework/API/src/DeprecatedAlgorithm.cpp +++ b/Framework/API/src/DeprecatedAlgorithm.cpp @@ -1,6 +1,7 @@ #include "MantidAPI/DeprecatedAlgorithm.h" #include "MantidAPI/AlgorithmFactory.h" #include "MantidKernel/DateAndTime.h" +#include "MantidKernel/DateAndTimeHelpers.h" #include "MantidKernel/Logger.h" #include <sstream> @@ -9,7 +10,7 @@ namespace API { namespace { /// Static logger Kernel::Logger g_log("DeprecatedAlgorithm"); -} +} // namespace /// Does nothing other than make the compiler happy. DeprecatedAlgorithm::DeprecatedAlgorithm() @@ -42,7 +43,7 @@ void DeprecatedAlgorithm::deprecatedDate(const std::string &date) { // TODO warn people that it wasn't set return; } - if (!Kernel::DateAndTime::stringIsISO8601(date)) { + if (!Kernel::DateAndTimeHelpers::stringIsISO8601(date)) { // TODO warn people that it wasn't set return; } @@ -83,5 +84,5 @@ const std::string DeprecatedAlgorithm::deprecationMsg(const IAlgorithm *algo) { return msg.str(); } -} // namesapce API +} // namespace API } // namespace Mantid diff --git a/Framework/API/src/LogManager.cpp b/Framework/API/src/LogManager.cpp index 9734adb8438046bf39d8a7172e77d2bf2297dff8..b652554d51f2b045684c5ddf94ef4846e245dc76 100644 --- a/Framework/API/src/LogManager.cpp +++ b/Framework/API/src/LogManager.cpp @@ -138,7 +138,7 @@ const Kernel::DateAndTime LogManager::startTime() const { if (hasProperty(start_prop)) { try { DateAndTime start_time(getProperty(start_prop)->value()); - if (start_time != DateAndTimeHelpers::GPS_EPOCH) { + if (start_time != DateAndTime::GPS_EPOCH) { return start_time; } } catch (std::invalid_argument &) { /*Swallow and move on*/ @@ -149,7 +149,7 @@ const Kernel::DateAndTime LogManager::startTime() const { if (hasProperty(run_start_prop)) { try { DateAndTime start_time(getProperty(run_start_prop)->value()); - if (start_time != DateAndTimeHelpers::GPS_EPOCH) { + if (start_time != DateAndTime::GPS_EPOCH) { return start_time; } } catch (std::invalid_argument &) { /*Swallow and move on*/ diff --git a/Framework/API/test/AlgorithmHistoryTest.h b/Framework/API/test/AlgorithmHistoryTest.h index c2216d81dc1f2d3e7a7eac18fd609db1e76b609c..c12510f17ed33059a62ba8dd6da557c89ea867d6 100644 --- a/Framework/API/test/AlgorithmHistoryTest.h +++ b/Framework/API/test/AlgorithmHistoryTest.h @@ -204,7 +204,7 @@ private: timeinfo->tm_sec = 49; // Convert to time_t but assuming the tm is specified in UTC time. std::time_t execTime_t = - Mantid::Kernel::DateAndTimeHelpers::utc_mktime(timeinfo); + Mantid::Kernel::DateAndTime::utc_mktime(timeinfo); // Create a UTC datetime from it Mantid::Kernel::DateAndTime execTime; execTime.set_from_time_t(execTime_t); diff --git a/Framework/DataHandling/src/LoadEventNexus.cpp b/Framework/DataHandling/src/LoadEventNexus.cpp index 2ad9563267363cb4dd5cb55b81c86071b6437805..bc925e37bd99b1c39da9a6ad54a5d6c70b1ef846 100644 --- a/Framework/DataHandling/src/LoadEventNexus.cpp +++ b/Framework/DataHandling/src/LoadEventNexus.cpp @@ -1,7 +1,6 @@ #include "MantidDataHandling/LoadEventNexus.h" #include "MantidDataHandling/EventWorkspaceCollection.h" #include "MantidDataHandling/ProcessBankData.h" - #include "MantidAPI/Axis.h" #include "MantidAPI/FileProperty.h" #include "MantidAPI/RegisterFileLoader.h" @@ -13,6 +12,7 @@ #include "MantidGeometry/Instrument/RectangularDetector.h" #include "MantidKernel/ArrayProperty.h" #include "MantidKernel/BoundedValidator.h" +#include "MantidKernel/DateAndTimeHelpers.h" #include "MantidKernel/MultiThreaded.h" #include "MantidKernel/ThreadPool.h" #include "MantidKernel/ThreadSchedulerMutexes.h" @@ -41,6 +41,7 @@ namespace DataHandling { DECLARE_NEXUS_FILELOADER_ALGORITHM(LoadEventNexus) using namespace Kernel; +using namespace Kernel::DateAndTimeHelpers; using namespace Geometry; using namespace API; using namespace DataObjects; @@ -66,7 +67,7 @@ void copyLogs(const Mantid::DataHandling::EventWorkspaceCollection_sptr &from, } } } -} +} // namespace //============================================================================================== // Class LoadBankFromDiskTask @@ -625,7 +626,7 @@ private: //---------------------------------------------------------------------------------------------- /** Empty default constructor -*/ + */ LoadEventNexus::LoadEventNexus() : IFileLoader<Kernel::NexusDescriptor>(), m_filename(), filter_tof_min(0), filter_tof_max(0), m_specList(), m_specMin(0), m_specMax(0), @@ -649,11 +650,11 @@ LoadEventNexus::~LoadEventNexus() { //---------------------------------------------------------------------------------------------- /** -* Return the confidence with with this algorithm can load the file -* @param descriptor A descriptor for the file -* @returns An integer specifying the confidence level. 0 indicates it will not -* be used -*/ + * Return the confidence with with this algorithm can load the file + * @param descriptor A descriptor for the file + * @returns An integer specifying the confidence level. 0 indicates it will not + * be used + */ int LoadEventNexus::confidence(Kernel::NexusDescriptor &descriptor) const { int confidence(0); if (descriptor.classTypeExists("NXevent_data")) { @@ -667,7 +668,7 @@ int LoadEventNexus::confidence(Kernel::NexusDescriptor &descriptor) const { //---------------------------------------------------------------------------------------------- /** Initialisation method. -*/ + */ void LoadEventNexus::init() { const std::vector<std::string> exts{"_event.nxs", ".nxs.h5", ".nxs"}; this->declareProperty( @@ -870,7 +871,7 @@ void LoadEventNexus::init() { //---------------------------------------------------------------------------------------------- /** set the name of the top level NXentry m_top_entry_name -*/ + */ void LoadEventNexus::setTopEntryName() { std::string nxentryProperty = getProperty("NXentryName"); if (!nxentryProperty.empty()) { @@ -936,8 +937,8 @@ void LoadEventNexus::filterDuringPause<EventWorkspaceCollection_sptr>( //------------------------------------------------------------------------------------------------ /** Executes the algorithm. Reading in the file and creating and populating -* the output workspace -*/ + * the output workspace + */ void LoadEventNexus::exec() { // Retrieve the filename from the properties m_filename = getPropertyValue("Filename"); @@ -1071,16 +1072,16 @@ void LoadEventNexus::makeMapToEventLists(std::vector<std::vector<T>> &vectors) { } /** -* Get the number of events in the currently opened group. -* -* @param file The handle to the nexus file opened to the group to look at. -* @param hasTotalCounts Whether to try looking at the total_counts field. This -* variable will be changed if the field is not there. -* @param oldNeXusFileNames Whether to try using old names. This variable will -* be changed if it is determined that old names are being used. -* -* @return The number of events. -*/ + * Get the number of events in the currently opened group. + * + * @param file The handle to the nexus file opened to the group to look at. + * @param hasTotalCounts Whether to try looking at the total_counts field. This + * variable will be changed if the field is not there. + * @param oldNeXusFileNames Whether to try using old names. This variable will + * be changed if it is determined that old names are being used. + * + * @return The number of events. + */ std::size_t numEvents(::NeXus::File &file, bool &hasTotalCounts, bool &oldNeXusFileNames) { // try getting the value of total_counts @@ -1132,18 +1133,18 @@ void LoadEventNexus::createWorkspaceIndexMaps( } /** Load the instrument from the nexus file -* -* @param nexusfilename :: The name of the nexus file being loaded -* @param localWorkspace :: Templated workspace in which to put the instrument -*geometry -* @param alg :: Handle of the algorithm -* @param returnpulsetimes :: flag to return shared pointer for BankPulseTimes, -*otherwise NULL. -* @param nPeriods : Number of periods (write to) -* @param periodLog : Period logs DateAndTime to int map. -* -* @return Pulse times given in the DAS logs -*/ + * + * @param nexusfilename :: The name of the nexus file being loaded + * @param localWorkspace :: Templated workspace in which to put the instrument + *geometry + * @param alg :: Handle of the algorithm + * @param returnpulsetimes :: flag to return shared pointer for BankPulseTimes, + *otherwise NULL. + * @param nPeriods : Number of periods (write to) + * @param periodLog : Period logs DateAndTime to int map. + * + * @return Pulse times given in the DAS logs + */ template <typename T> boost::shared_ptr<BankPulseTimes> LoadEventNexus::runLoadNexusLogs( const std::string &nexusfilename, T localWorkspace, API::Algorithm &alg, @@ -1226,19 +1227,19 @@ boost::shared_ptr<BankPulseTimes> LoadEventNexus::runLoadNexusLogs( } /** Load the instrument from the nexus file -* -* @param nexusfilename :: The name of the nexus file being loaded -* @param localWorkspace :: EventWorkspaceCollection in which to put the -*instrument -*geometry -* @param alg :: Handle of the algorithm -* @param returnpulsetimes :: flag to return shared pointer for BankPulseTimes, -*otherwise NULL. -* @param nPeriods : Number of periods (write to) -* @param periodLog : Period logs DateAndTime to int map. -* -* @return Pulse times given in the DAS logs -*/ + * + * @param nexusfilename :: The name of the nexus file being loaded + * @param localWorkspace :: EventWorkspaceCollection in which to put the + *instrument + *geometry + * @param alg :: Handle of the algorithm + * @param returnpulsetimes :: flag to return shared pointer for BankPulseTimes, + *otherwise NULL. + * @param nPeriods : Number of periods (write to) + * @param periodLog : Period logs DateAndTime to int map. + * + * @return Pulse times given in the DAS logs + */ template <> boost::shared_ptr<BankPulseTimes> LoadEventNexus::runLoadNexusLogs<EventWorkspaceCollection_sptr>( @@ -1254,15 +1255,15 @@ LoadEventNexus::runLoadNexusLogs<EventWorkspaceCollection_sptr>( //----------------------------------------------------------------------------- /** -* Load events from the file. -* @param prog :: A pointer to the progress reporting object -* @param monitors :: If true the events from the monitors are loaded and not the -* main banks -* -* This also loads the instrument, but only if it has not been set in the -*workspace -* being used as input (m_ws data member). Same applies to the logs. -*/ + * Load events from the file. + * @param prog :: A pointer to the progress reporting object + * @param monitors :: If true the events from the monitors are loaded and not + *the main banks + * + * This also loads the instrument, but only if it has not been set in the + *workspace + * being used as input (m_ws data member). Same applies to the logs. + */ void LoadEventNexus::loadEvents(API::Progress *const prog, const bool monitors) { bool metaDataOnly = getProperty("MetaDataOnly"); @@ -1295,7 +1296,7 @@ void LoadEventNexus::loadEvents(API::Progress *const prog, std::string tmp; m_file->readData("start_time", tmp); m_file->closeGroup(); - run_start = DateAndTime(tmp); + run_start = createFromSanitizedISO8601(tmp); m_ws->mutableRun().addProperty("run_start", run_start.toISO8601String(), true); } @@ -1609,9 +1610,10 @@ void LoadEventNexus::loadEvents(API::Progress *const prog, g_log.warning() << "The shortest TOF was negative! At least 1 event has an " "invalid time-of-flight.\n"; if (bad_tofs > 0) - g_log.warning() << "Found " << bad_tofs << " events with TOF > 2e8. This " - "may indicate errors in the raw " - "TOF data.\n"; + g_log.warning() << "Found " << bad_tofs + << " events with TOF > 2e8. This " + "may indicate errors in the raw " + "TOF data.\n"; // Use T0 offset from TOPAZ Parameter file if it exists if (m_ws->getInstrument()->hasParameter("T0")) { @@ -1648,15 +1650,15 @@ void LoadEventNexus::loadEvents(API::Progress *const prog, //----------------------------------------------------------------------------- /** Load the instrument from the nexus file -* -* @param nexusfilename :: The name of the nexus file being loaded -* @param localWorkspace :: EventWorkspaceCollection in which to put the -*instrument -*geometry -* @param top_entry_name :: entry name at the top of the Nexus file -* @param alg :: Handle of the algorithm -* @return true if successful -*/ + * + * @param nexusfilename :: The name of the nexus file being loaded + * @param localWorkspace :: EventWorkspaceCollection in which to put the + *instrument + *geometry + * @param top_entry_name :: entry name at the top of the Nexus file + * @param alg :: Handle of the algorithm + * @return true if successful + */ template <> bool LoadEventNexus::runLoadIDFFromNexus<EventWorkspaceCollection_sptr>( const std::string &nexusfilename, @@ -1670,9 +1672,9 @@ bool LoadEventNexus::runLoadIDFFromNexus<EventWorkspaceCollection_sptr>( } /** method used to return instrument name for some old ISIS files where it is -* not written properly within the instrument -* @param hFile :: A reference to the NeXus file opened at the root entry -*/ + * not written properly within the instrument + * @param hFile :: A reference to the NeXus file opened at the root entry + */ std::string LoadEventNexus::readInstrumentFromISIS_VMSCompat(::NeXus::File &hFile) { std::string instrumentName; @@ -1697,16 +1699,16 @@ LoadEventNexus::readInstrumentFromISIS_VMSCompat(::NeXus::File &hFile) { //----------------------------------------------------------------------------- /** Load the instrument definition file specified by info in the NXS file for -* a EventWorkspaceCollection -* -* @param nexusfilename :: Used to pick the instrument. -* @param localWorkspace :: EventWorkspaceCollection in which to put the -*instrument -*geometry -* @param top_entry_name :: entry name at the top of the NXS file -* @param alg :: Handle of the algorithm -* @return true if successful -*/ + * a EventWorkspaceCollection + * + * @param nexusfilename :: Used to pick the instrument. + * @param localWorkspace :: EventWorkspaceCollection in which to put the + *instrument + *geometry + * @param top_entry_name :: entry name at the top of the NXS file + * @param alg :: Handle of the algorithm + * @return true if successful + */ template <> bool LoadEventNexus::runLoadInstrument<EventWorkspaceCollection_sptr>( const std::string &nexusfilename, @@ -1721,10 +1723,10 @@ bool LoadEventNexus::runLoadInstrument<EventWorkspaceCollection_sptr>( //----------------------------------------------------------------------------- /** -* Deletes banks for a workspace given the bank names. -* @param workspace :: The workspace to contain the spectra mapping -* @param bankNames :: Bank names that are in Nexus file -*/ + * Deletes banks for a workspace given the bank names. + * @param workspace :: The workspace to contain the spectra mapping + * @param bankNames :: Bank names that are in Nexus file + */ void LoadEventNexus::deleteBanks(EventWorkspaceCollection_sptr workspace, std::vector<std::string> bankNames) { Instrument_sptr inst = boost::const_pointer_cast<Instrument>( @@ -1809,15 +1811,15 @@ void LoadEventNexus::deleteBanks(EventWorkspaceCollection_sptr workspace, } //----------------------------------------------------------------------------- /** -* Create the required spectra mapping. If the file contains an isis_vms_compat -* block then -* the mapping is read from there, otherwise a 1:1 map with the instrument is -* created (along -* with the associated spectra axis) -* @param nxsfile :: The name of a nexus file to load the mapping from -* @param monitorsOnly :: Load only the monitors is true -* @param bankNames :: An optional bank name for loading specified banks -*/ + * Create the required spectra mapping. If the file contains an isis_vms_compat + * block then + * the mapping is read from there, otherwise a 1:1 map with the instrument is + * created (along + * with the associated spectra axis) + * @param nxsfile :: The name of a nexus file to load the mapping from + * @param monitorsOnly :: Load only the monitors is true + * @param bankNames :: An optional bank name for loading specified banks + */ void LoadEventNexus::createSpectraMapping( const std::string &nxsfile, const bool monitorsOnly, const std::vector<std::string> &bankNames) { @@ -1875,9 +1877,9 @@ void LoadEventNexus::createSpectraMapping( //----------------------------------------------------------------------------- /** -* Returns whether the file contains monitors with events in them -* @returns True if the file contains monitors with event data, false otherwise -*/ + * Returns whether the file contains monitors with events in them + * @returns True if the file contains monitors with event data, false otherwise + */ bool LoadEventNexus::hasEventMonitors() { bool result(false); // Determine whether to load histograms or events @@ -1904,16 +1906,16 @@ bool LoadEventNexus::hasEventMonitors() { } /** -* Load the Monitors from the NeXus file into an event workspace. A -* new event workspace is created and associated to the data -* workspace. The name of the new event workspace is contructed by -* appending '_monitors' to the base workspace name. -* -* This is used when the property "MonitorsAsEvents" is enabled, and -* there are monitors with events. -* -* @param prog :: progress reporter -*/ + * Load the Monitors from the NeXus file into an event workspace. A + * new event workspace is created and associated to the data + * workspace. The name of the new event workspace is contructed by + * appending '_monitors' to the base workspace name. + * + * This is used when the property "MonitorsAsEvents" is enabled, and + * there are monitors with events. + * + * @param prog :: progress reporter + */ void LoadEventNexus::runLoadMonitorsAsEvents(API::Progress *const prog) { try { // Note the reuse of the m_ws member variable below. Means I need to grab a @@ -1979,13 +1981,13 @@ void LoadEventNexus::runLoadMonitorsAsEvents(API::Progress *const prog) { //----------------------------------------------------------------------------- /** -* Load the Monitors from the NeXus file into a workspace. The original -* workspace name is used and appended with _monitors. -* -* This is used when the property "MonitorsAsEvents" is not -* enabled, and uses LoadNexusMonitors to load monitor data into a -* Workspace2D. -*/ + * Load the Monitors from the NeXus file into a workspace. The original + * workspace name is used and appended with _monitors. + * + * This is used when the property "MonitorsAsEvents" is not + * enabled, and uses LoadNexusMonitors to load monitor data into a + * Workspace2D. + */ void LoadEventNexus::runLoadMonitors() { std::string mon_wsname = this->getProperty("OutputWorkspace"); mon_wsname.append("_monitors"); @@ -2162,10 +2164,10 @@ bool LoadEventNexus::loadSpectraMapping(const std::string &filename, } /** -* Set the filters on TOF. -* @param monitors :: If true check the monitor properties else use the standard -* ones -*/ + * Set the filters on TOF. + * @param monitors :: If true check the monitor properties else use the standard + * ones + */ void LoadEventNexus::setTimeFilters(const bool monitors) { // Get the limits to the filter std::string prefix("Filter"); @@ -2193,12 +2195,12 @@ void LoadEventNexus::setTimeFilters(const bool monitors) { // ISIS event corrections //----------------------------------------------------------------------------- /** -* Check if time_of_flight can be found in the file and load it -* -* @param WS :: The event workspace collection which events will be modified. -* @param entry_name :: An NXentry tag in the file -* @param classType :: The type of the events: either detector or monitor -*/ + * Check if time_of_flight can be found in the file and load it + * + * @param WS :: The event workspace collection which events will be modified. + * @param entry_name :: An NXentry tag in the file + * @param classType :: The type of the events: either detector or monitor + */ void LoadEventNexus::loadTimeOfFlight(EventWorkspaceCollection_sptr WS, const std::string &entry_name, const std::string &classType) { @@ -2303,14 +2305,14 @@ void LoadEventNexus::loadTimeOfFlight(EventWorkspaceCollection_sptr WS, //----------------------------------------------------------------------------- /** -* Load the time of flight data. file must have open the group containing -* "time_of_flight" data set. -* @param file :: The nexus file to read from. -* @param WS :: The event workspace collection to write to. -* @param binsName :: bins name -* @param start_wi :: First workspace index to process -* @param end_wi :: Last workspace index to process -*/ + * Load the time of flight data. file must have open the group containing + * "time_of_flight" data set. + * @param file :: The nexus file to read from. + * @param WS :: The event workspace collection to write to. + * @param binsName :: bins name + * @param start_wi :: First workspace index to process + * @param end_wi :: Last workspace index to process + */ void LoadEventNexus::loadTimeOfFlightData(::NeXus::File &file, EventWorkspaceCollection_sptr WS, const std::string &binsName, @@ -2390,19 +2392,19 @@ void LoadEventNexus::loadTimeOfFlightData(::NeXus::File &file, } /** -* Load information of the sample. It is valid only for ISIS it get the -* information from the group isis_vms_compat. -* -* If it does not find this group, it assumes that there is nothing to do. -* But, if the information is there, but not in the way it was expected, it -* will log the occurrence. -* -* @note: It does essentially the same thing of the -* method: LoadISISNexus2::loadSampleData -* -* @param file : handle to the nexus file -* @param WS : pointer to the workspace -*/ + * Load information of the sample. It is valid only for ISIS it get the + * information from the group isis_vms_compat. + * + * If it does not find this group, it assumes that there is nothing to do. + * But, if the information is there, but not in the way it was expected, it + * will log the occurrence. + * + * @note: It does essentially the same thing of the + * method: LoadISISNexus2::loadSampleData + * + * @param file : handle to the nexus file + * @param WS : pointer to the workspace + */ void LoadEventNexus::loadSampleDataISIScompatibility( ::NeXus::File &file, EventWorkspaceCollection &WS) { try { @@ -2435,12 +2437,12 @@ void LoadEventNexus::loadSampleDataISIScompatibility( } /** -* Check the validity of the optional spectrum range/list provided and identify -*if partial data should be loaded. -* -* @param min :: The minimum spectrum number read from file -* @param max :: The maximum spectrum number read from file -*/ + * Check the validity of the optional spectrum range/list provided and identify + *if partial data should be loaded. + * + * @param min :: The minimum spectrum number read from file + * @param max :: The maximum spectrum number read from file + */ void LoadEventNexus::createSpectraList(int32_t min, int32_t max) { diff --git a/Framework/DataHandling/src/LoadLog.cpp b/Framework/DataHandling/src/LoadLog.cpp index cbcb0705764906daaeec3645198f915655d6ad8d..cb5d55107b81a9fc65e504a25b5667f42a98cbde 100644 --- a/Framework/DataHandling/src/LoadLog.cpp +++ b/Framework/DataHandling/src/LoadLog.cpp @@ -1,25 +1,26 @@ //---------------------------------------------------------------------- // Includes //---------------------------------------------------------------------- +#include "MantidDataHandling/LoadLog.h" #include "LoadRaw/isisraw2.h" #include "MantidAPI/FileProperty.h" -#include "MantidDataHandling/LoadLog.h" #include "MantidDataObjects/Workspace2D.h" #include "MantidKernel/ArrayProperty.h" #include "MantidKernel/Glob.h" #include "MantidKernel/LogParser.h" -#include "MantidKernel/make_unique.h" -#include "MantidKernel/Strings.h" #include "MantidKernel/PropertyWithValue.h" +#include "MantidKernel/Strings.h" #include "MantidKernel/TimeSeriesProperty.h" +#include "MantidKernel/make_unique.h" -#include <boost/regex.hpp> -#include <boost/algorithm/string.hpp> +#include <MantidKernel/DateAndTimeHelpers.h> +#include <Poco/DateTimeFormat.h> +#include <Poco/DateTimeParser.h> +#include <Poco/DirectoryIterator.h> #include <Poco/File.h> #include <Poco/Path.h> -#include <Poco/DirectoryIterator.h> -#include <Poco/DateTimeParser.h> -#include <Poco/DateTimeFormat.h> +#include <boost/algorithm/string.hpp> +#include <boost/regex.hpp> #include <fstream> // used to get ifstream #include <sstream> @@ -29,10 +30,10 @@ namespace DataHandling { DECLARE_ALGORITHM(LoadLog) using namespace Kernel; -using API::WorkspaceProperty; +using API::FileProperty; using API::MatrixWorkspace; using API::MatrixWorkspace_sptr; -using API::FileProperty; +using API::WorkspaceProperty; using DataObjects::Workspace2D; using DataObjects::Workspace2D_sptr; @@ -200,7 +201,8 @@ void LoadLog::loadThreeColumnLogFile(std::ifstream &logFileStream, std::map<std::string, std::unique_ptr<Kernel::TimeSeriesProperty<double>>> dMap; std::map<std::string, - std::unique_ptr<Kernel::TimeSeriesProperty<std::string>>> sMap; + std::unique_ptr<Kernel::TimeSeriesProperty<std::string>>> + sMap; kind l_kind(LoadLog::empty); bool isNumeric(false); @@ -471,7 +473,7 @@ bool LoadLog::isAscii(const std::string &filename) { * @returns true if the strings format matched the expected date format */ bool LoadLog::isDateTimeString(const std::string &str) const { - return DateAndTime::stringIsISO8601(str.substr(0, 19)); + return Kernel::DateAndTimeHelpers::stringIsISO8601(str.substr(0, 19)); } /** diff --git a/Framework/DataHandling/src/LoadMuonNexus2.cpp b/Framework/DataHandling/src/LoadMuonNexus2.cpp index 0d64914640397a192992c103cf683cdeb0ecfc71..30ab316243735282f2da77d60afaf1ece41d06c3 100644 --- a/Framework/DataHandling/src/LoadMuonNexus2.cpp +++ b/Framework/DataHandling/src/LoadMuonNexus2.cpp @@ -11,13 +11,14 @@ #include "MantidGeometry/Instrument/Detector.h" #include "MantidKernel/ArrayProperty.h" #include "MantidKernel/ConfigService.h" +#include "MantidKernel/DateAndTimeHelpers.h" #include "MantidKernel/TimeSeriesProperty.h" #include "MantidKernel/Unit.h" #include "MantidKernel/UnitFactory.h" #include "MantidKernel/UnitLabelTypes.h" #include "MantidNexus/NexusClasses.h" -#include <nexus/NeXusFile.hpp> #include <nexus/NeXusException.hpp> +#include <nexus/NeXusFile.hpp> #include <Poco/Path.h> #include <boost/lexical_cast.hpp> @@ -32,22 +33,23 @@ namespace DataHandling { DECLARE_NEXUS_FILELOADER_ALGORITHM(LoadMuonNexus2) using namespace Kernel; +using namespace Kernel::DateAndTimeHelpers; using namespace API; using Geometry::Instrument; -using Mantid::HistogramData::Histogram; -using Mantid::HistogramData::Counts; using Mantid::HistogramData::BinEdges; +using Mantid::HistogramData::Counts; +using Mantid::HistogramData::Histogram; using namespace Mantid::NeXus; /// Empty default constructor LoadMuonNexus2::LoadMuonNexus2() : LoadMuonNexus() {} /** Executes the right version of the muon nexus loader: versions 1 or 2. -* -* @throw Exception::FileError If the Nexus file cannot be found/opened -* @throw std::invalid_argument If the optional properties are set to invalid -*values -*/ + * + * @throw Exception::FileError If the Nexus file cannot be found/opened + * @throw std::invalid_argument If the optional properties are set to invalid + *values + */ void LoadMuonNexus2::exec() { std::string filePath = getPropertyValue("Filename"); LoadMuonNexus1 load1; @@ -79,11 +81,11 @@ void LoadMuonNexus2::exec() { } /** Read in a muon nexus file of the version 2. -* -* @throw Exception::FileError If the Nexus file cannot be found/opened -* @throw std::invalid_argument If the optional properties are set to invalid -*values -*/ + * + * @throw Exception::FileError If the Nexus file cannot be found/opened + * @throw std::invalid_argument If the optional properties are set to invalid + *values + */ void LoadMuonNexus2::doExec() { // Create the root Nexus class NXRoot root(getPropertyValue("Filename")); @@ -297,8 +299,8 @@ void LoadMuonNexus2::doExec() { } /** loadData -* Load the counts data from an NXInt into a workspace -*/ + * Load the counts data from an NXInt into a workspace + */ Histogram LoadMuonNexus2::loadData(const BinEdges &edges, const Mantid::NeXus::NXInt &counts, int period, int spec) { @@ -319,11 +321,11 @@ Histogram LoadMuonNexus2::loadData(const BinEdges &edges, } /** Load logs from Nexus file. Logs are expected to be in -* /run/sample group of the file. -* @param ws :: The workspace to load the logs to. -* @param entry :: The Nexus entry -* @param period :: The period of this workspace -*/ + * /run/sample group of the file. + * @param ws :: The workspace to load the logs to. + * @param entry :: The Nexus entry + * @param period :: The period of this workspace + */ void LoadMuonNexus2::loadLogs(API::MatrixWorkspace_sptr ws, NXEntry &entry, int period) { // Avoid compiler warning @@ -359,8 +361,8 @@ void LoadMuonNexus2::loadLogs(API::MatrixWorkspace_sptr ws, NXEntry &entry, } /** Log the run details from the file -* @param localWorkspace :: The workspace details to use -*/ + * @param localWorkspace :: The workspace details to use + */ void LoadMuonNexus2::loadRunDetails( DataObjects::Workspace2D_sptr localWorkspace) { API::Run &runDetails = localWorkspace->mutableRun(); @@ -395,8 +397,8 @@ void LoadMuonNexus2::loadRunDetails( } { // Duration taken to be stop_time minus stat_time - DateAndTime start(start_time); - DateAndTime end(stop_time); + auto start = createFromSanitizedISO8601(start_time); + auto end = createFromSanitizedISO8601(stop_time); double duration_in_secs = DateAndTime::secondsFromDuration(end - start); runDetails.addProperty("dur_secs", duration_in_secs); } diff --git a/Framework/DataHandling/src/LoadNexusMonitors2.cpp b/Framework/DataHandling/src/LoadNexusMonitors2.cpp index 7176b057c8654c4e3ef18a4e5ccc5f2f1f7752dd..c151d0b40ec51d7c02ff64c96491f3e34df252ac 100644 --- a/Framework/DataHandling/src/LoadNexusMonitors2.cpp +++ b/Framework/DataHandling/src/LoadNexusMonitors2.cpp @@ -9,6 +9,7 @@ #include "MantidDataHandling/LoadEventNexus.h" #include "MantidKernel/ConfigService.h" #include "MantidKernel/DateAndTime.h" +#include "MantidKernel/DateAndTimeHelpers.h" #include "MantidKernel/UnitFactory.h" #include <Poco/File.h> @@ -20,13 +21,14 @@ #include <map> #include <vector> -using Mantid::DataObjects::EventWorkspace; -using Mantid::DataObjects::EventWorkspace_sptr; +using namespace Mantid::Kernel::DateAndTimeHelpers; using Mantid::API::WorkspaceGroup; using Mantid::API::WorkspaceGroup_sptr; -using Mantid::HistogramData::Counts; -using Mantid::HistogramData::CountStandardDeviations; +using Mantid::DataObjects::EventWorkspace; +using Mantid::DataObjects::EventWorkspace_sptr; using Mantid::HistogramData::BinEdges; +using Mantid::HistogramData::CountStandardDeviations; +using Mantid::HistogramData::Counts; using Mantid::HistogramData::Histogram; namespace Mantid { @@ -109,9 +111,9 @@ void LoadNexusMonitors2::init() { //------------------------------------------------------------------------------ /** -* Executes the algorithm. Reading in the file and creating and populating -* the output workspace -*/ + * Executes the algorithm. Reading in the file and creating and populating + * the output workspace + */ void LoadNexusMonitors2::exec() { // Retrieve the filename from the properties m_filename = this->getPropertyValue("Filename"); @@ -366,12 +368,12 @@ void LoadNexusMonitors2::exec() { //------------------------------------------------------------------------------ /** -* Can we get a histogram (non event data) for every monitor? -* -* @param file :: NeXus file object (open) -* @param monitorNames :: names of monitors of interest -* @return If there seems to be histograms for all monitors (they have "data") -**/ + * Can we get a histogram (non event data) for every monitor? + * + * @param file :: NeXus file object (open) + * @param monitorNames :: names of monitors of interest + * @return If there seems to be histograms for all monitors (they have "data") + **/ bool LoadNexusMonitors2::allMonitorsHaveHistoData( ::NeXus::File &file, const std::vector<std::string> &monitorNames) { bool res = true; @@ -392,14 +394,14 @@ bool LoadNexusMonitors2::allMonitorsHaveHistoData( //------------------------------------------------------------------------------ /** -* Fix the detector numbers if the defaults are not correct. Currently checks -* the isis_vms_compat block and reads them from there if possible. -* -* @param det_ids :: An array of prefilled detector IDs -* @param file :: A reference to the NeXus file opened at the root entry -* @param spec_ids :: An array of spectrum numbers that the monitors have -* @param nmonitors :: The size of the det_ids and spec_ids arrays -*/ + * Fix the detector numbers if the defaults are not correct. Currently checks + * the isis_vms_compat block and reads them from there if possible. + * + * @param det_ids :: An array of prefilled detector IDs + * @param file :: A reference to the NeXus file opened at the root entry + * @param spec_ids :: An array of spectrum numbers that the monitors have + * @param nmonitors :: The size of the det_ids and spec_ids arrays + */ void LoadNexusMonitors2::fixUDets( boost::scoped_array<detid_t> &det_ids, ::NeXus::File &file, const boost::scoped_array<specnum_t> &spec_ids, @@ -459,11 +461,11 @@ void LoadNexusMonitors2::runLoadLogs(const std::string filename, //------------------------------------------------------------------------------ /** -* Helper method to make sure that a file is / can be openend as a NeXus file -* -* @param fname :: name of the file -* @return True if opening the file as NeXus and retrieving entries succeeds -**/ + * Helper method to make sure that a file is / can be openend as a NeXus file + * + * @param fname :: name of the file + * @return True if opening the file as NeXus and retrieving entries succeeds + **/ bool LoadNexusMonitors2::canOpenAsNeXus(const std::string &fname) { bool res = true; ::NeXus::File *f = nullptr; @@ -483,11 +485,11 @@ bool LoadNexusMonitors2::canOpenAsNeXus(const std::string &fname) { //------------------------------------------------------------------------------ /** -* Splits multiperiod histogram data into seperate workspaces and puts them in -* a group -* -* @param numPeriods :: number of periods -**/ + * Splits multiperiod histogram data into seperate workspaces and puts them in + * a group + * + * @param numPeriods :: number of periods + **/ void LoadNexusMonitors2::splitMutiPeriodHistrogramData( const size_t numPeriods) { // protection - we should not have entered the routine if these are not true @@ -624,16 +626,16 @@ size_t LoadNexusMonitors2::getMonitorInfo( } /** Create output workspace -* @brief LoadNexusMonitors2::createOutputWorkspace -* @param numHistMon -* @param numEventMon -* @param monitorsAsEvents -* @param monitorNames -* @param isEventMonitors -* @param monitorNumber2Name -* @param loadMonitorFlags -* @return -*/ + * @brief LoadNexusMonitors2::createOutputWorkspace + * @param numHistMon + * @param numEventMon + * @param monitorsAsEvents + * @param monitorNames + * @param isEventMonitors + * @param monitorNumber2Name + * @param loadMonitorFlags + * @return + */ bool LoadNexusMonitors2::createOutputWorkspace( size_t numHistMon, size_t numEventMon, bool monitorsAsEvents, std::vector<std::string> &monitorNames, std::vector<bool> &isEventMonitors, @@ -798,7 +800,7 @@ void LoadNexusMonitors2::readEventMonitorEntry(NeXus::File &file, size_t i) { { std::string startTime; file.getAttr("offset", startTime); - pulsetime_offset = Mantid::Kernel::DateAndTime(startTime); + pulsetime_offset = createFromSanitizedISO8601(startTime); } file.closeData(); @@ -854,5 +856,5 @@ void LoadNexusMonitors2::readHistoMonitorEntry(NeXus::File &file, size_t i, } } -} // end DataHandling -} // end Mantid +} // namespace DataHandling +} // namespace Mantid diff --git a/Framework/Kernel/inc/MantidKernel/DateAndTimeHelpers.h b/Framework/Kernel/inc/MantidKernel/DateAndTimeHelpers.h index 235e5ca176a88db30bd32d7a2e144e4799b412e9..f7628aa3b9aa637b574d046665e721a5ac6ae848 100644 --- a/Framework/Kernel/inc/MantidKernel/DateAndTimeHelpers.h +++ b/Framework/Kernel/inc/MantidKernel/DateAndTimeHelpers.h @@ -1,15 +1,20 @@ #ifndef MANTID_KERNEL_DATEANDTIMEHELPERS_H_ #define MANTID_KERNEL_DATEANDTIMEHELPERS_H_ +#include "MantidKernel/DateAndTime.h" #include "MantidKernel/DllConfig.h" namespace Mantid { namespace Kernel { namespace DateAndTimeHelpers { +MANTID_KERNEL_DLL DateAndTime +createFromSanitizedISO8601(const std::string &date); + MANTID_KERNEL_DLL bool stringIsISO8601(const std::string &date); -MANTID_KERNEL_DLL std::string verifyISO8601(const std::string &date, - bool displayWarnings = true); + +MANTID_KERNEL_DLL std::string +verifyAndSanitizeISO8601(const std::string &date, bool displayWarnings = true); } // namespace DateAndTimeHelpers } // namespace Kernel diff --git a/Framework/Kernel/src/DateAndTimeHelpers.cpp b/Framework/Kernel/src/DateAndTimeHelpers.cpp index ccc9d2ec8d3a5b4d11a6361181c5ea8a5a76f049..4976a23fb3503e6d05b98b366328bfbd820c06fd 100644 --- a/Framework/Kernel/src/DateAndTimeHelpers.cpp +++ b/Framework/Kernel/src/DateAndTimeHelpers.cpp @@ -22,6 +22,15 @@ namespace DateAndTimeHelpers { // Initialize the logger Logger g_log("DateAndTime"); +/** Creates a DateAndTime object from a date string even if the string does not + *exactly conform to ISO8601 (ARGUS File) + *@param date Date used to create DateAndTime object. May be sanitized first. + * + */ +DateAndTime createFromSanitizedISO8601(const std::string &date) { + return DateAndTime(verifyAndSanitizeISO8601(date)); +} + /** Check if a string is iso8601 format. * * @param str :: string to check @@ -41,8 +50,8 @@ bool stringIsISO8601(const std::string &date) { *@param displayWarning display warning messages in the log if the date is non *conforming. */ -std::string verifyAndCorrectToISO8601(const std::string &date, - bool displayWarnings) { +std::string verifyAndSanitizeISO8601(const std::string &date, + bool displayWarnings) { auto res = isARGUSDateTime(date); if (std::get<0>(res)) { diff --git a/Framework/Kernel/src/DateTimeValidator.cpp b/Framework/Kernel/src/DateTimeValidator.cpp index 3f96d941300f27ead237eab71a15306704ec2d1f..600c12fa248d83474cc3de51079feb71d7142389 100644 --- a/Framework/Kernel/src/DateTimeValidator.cpp +++ b/Framework/Kernel/src/DateTimeValidator.cpp @@ -1,5 +1,5 @@ #include "MantidKernel/DateTimeValidator.h" -#include "MantidKernel/DateAndTime.h" +#include "MantidKernel/DateAndTimeHelpers.h" #include "MantidKernel/System.h" #include <boost/make_shared.hpp> @@ -8,6 +8,7 @@ namespace Mantid { namespace Kernel { +using namespace DateAndTimeHelpers; /** * @return A clone of the current state of the validator */ @@ -32,15 +33,14 @@ void DateTimeValidator::allowEmpty(const bool &allow) { */ std::string DateTimeValidator::checkValidity(const std::string &value) const { // simply pass off the work DateAndTime constructor - // the DateAndTime::stringIsISO8601 does not seem strict enough, it accepts - // empty strings & strings of letters! + // the DateAndTimeHelpers::stringIsISO8601 does not seem strict enough, it + // accepts empty strings & strings of letters! if (m_allowedEmpty && value.empty()) { return ""; } else { std::string error; try { - auto displayLogs = false; - DateAndTime timestamp(value, displayLogs); + DateAndTime timestamp(value); UNUSED_ARG(timestamp); } catch (std::invalid_argument &exc) { error = exc.what(); @@ -48,5 +48,5 @@ std::string DateTimeValidator::checkValidity(const std::string &value) const { return error; } } -} -} +} // namespace Kernel +} // namespace Mantid diff --git a/Framework/LiveData/src/Kafka/KafkaEventStreamDecoder.cpp b/Framework/LiveData/src/Kafka/KafkaEventStreamDecoder.cpp index f273dfe6fb68cf243785bcd894f12498a4de3ceb..57d788447aa4c8ecf907863e351ff25709bd8f87 100644 --- a/Framework/LiveData/src/Kafka/KafkaEventStreamDecoder.cpp +++ b/Framework/LiveData/src/Kafka/KafkaEventStreamDecoder.cpp @@ -96,7 +96,7 @@ void addSampleEnvLogs( } } } -} +} // namespace namespace Mantid { namespace LiveData { @@ -211,7 +211,7 @@ bool KafkaEventStreamDecoder::hasReachedEndOfRun() noexcept { */ API::Workspace_sptr KafkaEventStreamDecoder::extractData() { if (m_exception) { - throw * m_exception; + throw *m_exception; } m_extractWaiting = true; @@ -384,7 +384,8 @@ void KafkaEventStreamDecoder::initLocalCaches() { std::ostringstream os; os << "KafkaEventStreamDecoder::initLocalEventBuffer() - Invalid " "spectra/detector mapping. Expected matched length arrays but " - "found nspec=" << nspec << ", ndet=" << nudet; + "found nspec=" + << nspec << ", ndet=" << nudet; throw std::runtime_error(os.str()); } // Create buffer @@ -415,7 +416,7 @@ void KafkaEventStreamDecoder::initLocalCaches() { auto runStartTime = static_cast<time_t>(runMsg->start_time()); char timeString[32]; strftime(timeString, 32, "%Y-%m-%dT%H:%M:%S", localtime(&runStartTime)); - m_runStart.setFromISO8601(timeString, false); + m_runStart.setFromISO8601(timeString); // Run number mutableRun.addProperty(RUN_START_PROPERTY, std::string(timeString)); m_runNumber = runMsg->run_number(); @@ -533,6 +534,6 @@ void KafkaEventStreamDecoder::loadInstrument( << "': " << exc.what() << "\n"; } } -} +} // namespace LiveData } // namespace Mantid diff --git a/Framework/LiveData/test/KafkaTesting.h b/Framework/LiveData/test/KafkaTesting.h index cf136509a24a08cb646cd9d1ecc8a9fb9d479468..5a9e37693d2e4d4fc61969d0a26c7be4c6eb11ee 100644 --- a/Framework/LiveData/test/KafkaTesting.h +++ b/Framework/LiveData/test/KafkaTesting.h @@ -135,7 +135,7 @@ public: assert(buffer); // Convert date to time_t - auto mantidTime = Mantid::Kernel::DateAndTime(m_startTime, false); + auto mantidTime = Mantid::Kernel::DateAndTime(m_startTime); auto tmb = mantidTime.to_tm(); uint64_t startTime = static_cast<uint64_t>(std::mktime(&tmb)); diff --git a/Framework/Nexus/inc/MantidNexus/NexusClasses.h b/Framework/Nexus/inc/MantidNexus/NexusClasses.h index 63b836eb72ee6c8c5b1f753d6f07bf29e9322df6..75d02031cd8169be43141db80c68c7ba6ee6bacb 100644 --- a/Framework/Nexus/inc/MantidNexus/NexusClasses.h +++ b/Framework/Nexus/inc/MantidNexus/NexusClasses.h @@ -6,13 +6,16 @@ //---------------------------------------------------------------------- #include "MantidAPI/Algorithm.h" #include "MantidAPI/Sample.h" -#include "MantidKernel/TimeSeriesProperty.h" #include "MantidKernel/DateAndTime.h" +#include "MantidKernel/DateAndTimeHelpers.h" +#include "MantidKernel/TimeSeriesProperty.h" #include <nexus/napi.h> -#include <boost/shared_ptr.hpp> #include <boost/shared_array.hpp> +#include <boost/shared_ptr.hpp> #include <map> + +using namespace Mantid::Kernel::DateAndTimeHelpers; //---------------------------------------------------------------------- // Forward declaration //---------------------------------------------------------------------- @@ -48,8 +51,8 @@ Code Documentation is available at: <http://doxygen.mantidproject.org> */ /** Structure for keeping information about a Nexus data set, -* such as the dimensions and the type -*/ + * such as the dimensions and the type + */ struct NXInfo { NXInfo() : nxname(), rank(0), dims(), type(-1), stat(NX_ERROR) {} std::string nxname; ///< name of the object @@ -61,7 +64,7 @@ struct NXInfo { }; /** Information about a Nexus class -*/ + */ struct NXClassInfo { NXClassInfo() : nxname(), nxclass(), datatype(-1), stat(NX_ERROR) {} std::string nxname; ///< name of the object @@ -73,15 +76,15 @@ struct NXClassInfo { }; /** -* LoadNexusProcessed and SaveNexusProcessed need to share some attributes, put -* them at -* namespace level here -*/ + * LoadNexusProcessed and SaveNexusProcessed need to share some attributes, put + * them at + * namespace level here + */ /// Default block size for reading and writing processed files const int g_processed_blocksize = 8; /** Nexus attributes. The type of each attribute is NX_CHAR -*/ + */ class DLLExport NXAttributes { public: int n() const { return int(m_values.size()); } ///< number of attributes @@ -103,8 +106,8 @@ private: class NXClass; /** The base abstract class for NeXus classes and data sets. -* NX classes and data sets are defined at www.nexusformat.org -*/ + * NX classes and data sets are defined at www.nexusformat.org + */ class DLLExport NXObject { friend class NXDataSet; ///< a friend class declaration friend class NXClass; ///< a friend class declaration @@ -137,18 +140,17 @@ private: }; /** Abstract base class for a Nexus data set. A typical use include: -* <ul> -* <li>Creating a dataset object using either the concrete type constructor -* or specialized methods of NXClass'es</li> -* <li>Opening the dataset with open() method. Specialized NXClass creation -* methods call open() internally -* (so no need to call it again).</li> -* <li>Loading the data using load(...) method. The data can be loaded -* either in full or by chunks of smaller rank (dimension)</li> -* </ul> -* There is no need to free the memory allocated by the NXDataSet as it is done -* at the destruction. -*/ + * <ul> + * <li>Creating a dataset object using either the concrete type + * constructor or specialized methods of NXClass'es</li> <li>Opening the dataset + * with open() method. Specialized NXClass creation methods call open() + * internally (so no need to call it again).</li> <li>Loading the data using + * load(...) method. The data can be loaded either in full or by chunks of + * smaller rank (dimension)</li> + * </ul> + * There is no need to free the memory allocated by the NXDataSet as it is done + * at the destruction. + */ class DLLExport NXDataSet : public NXObject { public: // Constructor @@ -177,23 +179,23 @@ public: /// Returns the Nexus type of the data. The types are defied in napi.h int type() const { return m_info.type; } /** Load the data from the file. Calling this method with all default - * arguments - * makes it to read in all the data. - * @param blocksize :: The size of the block of data that should be read. - * Note that this is only used for rank 2 and 3 datasets currently - * @param i :: Calling load with non-negative i reads in a chunk of dimension - * rank()-1 and i is the index - * of the chunk. The rank of the data must be >= 1 - * @param j :: Non-negative value makes it read a chunk of dimension - * rank()-2. i and j are its indices. - * The rank of the data must be >= 2 - * @param k :: Non-negative value makes it read a chunk of dimension - * rank()-3. i,j and k are its indices. - * The rank of the data must be >= 3 - * @param l :: Non-negative value makes it read a chunk of dimension - * rank()-4. i,j,k and l are its indices. - * The rank of the data must be 4 - */ + * arguments + * makes it to read in all the data. + * @param blocksize :: The size of the block of data that should be read. + * Note that this is only used for rank 2 and 3 datasets currently + * @param i :: Calling load with non-negative i reads in a chunk of + * dimension rank()-1 and i is the index of the chunk. The rank of the data + * must be >= 1 + * @param j :: Non-negative value makes it read a chunk of dimension + * rank()-2. i and j are its indices. + * The rank of the data must be >= 2 + * @param k :: Non-negative value makes it read a chunk of dimension + * rank()-3. i,j and k are its indices. + * The rank of the data must be >= 3 + * @param l :: Non-negative value makes it read a chunk of dimension + * rank()-4. i,j,k and l are its indices. + * The rank of the data must be 4 + */ virtual void load(const int blocksize = 1, int i = -1, int j = -1, int k = -1, int l = -1) { // Avoid compiler warnings @@ -214,21 +216,21 @@ private: /** Templated class implementation of NXDataSet. After loading the data it can * be accessed via operators () and []. -*/ + */ template <class T> class NXDataSetTyped : public NXDataSet { public: /** Constructor. - * @param parent :: The parent Nexus class. In terms of HDF it is the group - * containing the dataset. - * @param name :: The name of the dataset relative to its parent - */ + * @param parent :: The parent Nexus class. In terms of HDF it is the group + * containing the dataset. + * @param name :: The name of the dataset relative to its parent + */ NXDataSetTyped(const NXClass &parent, const std::string &name) : NXDataSet(parent, name), m_n(0) {} /** Returns a pointer to the internal data buffer. - * @throw runtime_error exception if the data have not been loaded / - * initialized. - * @return a pointer to the array of items - */ + * @throw runtime_error exception if the data have not been loaded / + * initialized. + * @return a pointer to the array of items + */ T *operator()() const { if (!m_data) throw std::runtime_error("Attempt to read uninitialized data from " + @@ -236,11 +238,11 @@ public: return m_data.get(); } /** Returns the i-th value in the internal buffer - * @param i :: The linear index of the data element - * @throw runtime_error if the data have not been loaded / initialized. - * @throw range_error if the index is greater than the buffer size. - * @return A reference to the value - */ + * @param i :: The linear index of the data element + * @throw runtime_error if the data have not been loaded / initialized. + * @throw range_error if the index is greater than the buffer size. + * @return A reference to the value + */ T &operator[](int i) const { if (!m_data) throw std::runtime_error("Attempt to read uninitialized data from " + @@ -250,21 +252,21 @@ public: return m_data[i]; } /** Returns a value assuming the data is a two-dimensional array - * @param i :: The index along dim0() - * @param j :: The index along dim1() - * @throw runtime_error if the data have not been loaded / initialized. - * @throw range_error if the indeces point outside the buffer. - * @return A reference to the value - */ - T &operator()(int i, int j) const { return this->operator[](i * dim1() + j); } + * @param i :: The index along dim0() + * @param j :: The index along dim1() + * @throw runtime_error if the data have not been loaded / initialized. + * @throw range_error if the indeces point outside the buffer. + * @return A reference to the value + */ + T &operator()(int i, int j) const { return this->operator[](i *dim1() + j); } /** Returns a value assuming the data is a tree-dimensional array - * @param i :: The index along dim0() - * @param j :: The index along dim1() - * @param k :: The index along dim2() - * @throw runtime_error if the data have not been loaded / initialized. - * @throw range_error if the indeces point outside the buffer. - * @return A reference to the value - */ + * @param i :: The index along dim0() + * @param j :: The index along dim1() + * @param k :: The index along dim2() + * @throw runtime_error if the data have not been loaded / initialized. + * @throw range_error if the indeces point outside the buffer. + * @return A reference to the value + */ T &operator()(int i, int j, int k) const { return this->operator[]((i * dim1() + j) * dim2() + k); } @@ -273,26 +275,26 @@ public: /// Returns the size of the data buffer int size() const { return m_n; } /** Implementation of the virtual NXDataSet::load(...) method. Internally the - * data are stored as a 1d array. - * If the data are loaded in chunks the newly read in data replace the old - * ones. The actual rank of the loaded - * data is equal or less than the rank of the dataset (returned by rank() - * method). - * @param blocksize :: The size of the block of data that should be read. - * Note that this is only used for rank 2 and 3 datasets currently - * @param i :: Calling load with non-negative i reads in a chunk of dimension - * rank()-1 and i is the index - * of the chunk. The rank of the data must be >= 1 - * @param j :: Non-negative value makes it read a chunk of dimension - * rank()-2. i and j are its indeces. - * The rank of the data must be >= 2 - * @param k :: Non-negative value makes it read a chunk of dimension - * rank()-3. i,j and k are its indeces. - * The rank of the data must be >= 3 - * @param l :: Non-negative value makes it read a chunk of dimension - * rank()-4. i,j,k and l are its indeces. - * The rank of the data must be 4 - */ + * data are stored as a 1d array. + * If the data are loaded in chunks the newly read in data replace the old + * ones. The actual rank of the loaded + * data is equal or less than the rank of the dataset (returned by rank() + * method). + * @param blocksize :: The size of the block of data that should be read. + * Note that this is only used for rank 2 and 3 datasets currently + * @param i :: Calling load with non-negative i reads in a chunk of + * dimension rank()-1 and i is the index of the chunk. The rank of the data + * must be >= 1 + * @param j :: Non-negative value makes it read a chunk of dimension + * rank()-2. i and j are its indeces. + * The rank of the data must be >= 2 + * @param k :: Non-negative value makes it read a chunk of dimension + * rank()-3. i,j and k are its indeces. + * The rank of the data must be >= 3 + * @param l :: Non-negative value makes it read a chunk of dimension + * rank()-4. i,j,k and l are its indeces. + * The rank of the data must be 4 + */ void load(const int blocksize = 1, int i = -1, int j = -1, int k = -1, int l = -1) override { if (rank() > 4) { @@ -442,8 +444,8 @@ public: private: /** Allocates memory for the data buffer - * @param n :: The number of elements to allocate. - */ + * @param n :: The number of elements to allocate. + */ void alloc(int n) { if (n <= 0) { throw std::runtime_error("Attempt to load from an empty dataset " + @@ -486,47 +488,47 @@ typedef NXDataSetTyped<unsigned int> NXUInt; //-------------------- classes --------------------------// /** The base class for a Nexus class (group). A Nexus class can contain -* datasets and other Nexus classes. -* The NeXus file format (www.nexusformat.org) specifies the content of the -* Nexus classes. -* Derived classes have specialized methods for creating classes and datasets -* specific for the particular Nexus class. -* NXClass is a conctrete C++ class so arbitrary, non-standard Nexus classes -* (groups) can be created and loaded from -* NeXus files. -*/ + * datasets and other Nexus classes. + * The NeXus file format (www.nexusformat.org) specifies the content of the + * Nexus classes. + * Derived classes have specialized methods for creating classes and datasets + * specific for the particular Nexus class. + * NXClass is a conctrete C++ class so arbitrary, non-standard Nexus classes + * (groups) can be created and loaded from + * NeXus files. + */ class DLLExport NXClass : public NXObject { friend class NXRoot; public: /** Constructor. - * @param parent :: The parent Nexus class. In terms of HDF it is the group - * containing the NXClass. - * @param name :: The name of the NXClass relative to its parent - */ + * @param parent :: The parent Nexus class. In terms of HDF it is the group + * containing the NXClass. + * @param name :: The name of the NXClass relative to its parent + */ NXClass(const NXClass &parent, const std::string &name); /// The NX class identifier std::string NX_class() const override { return "NXClass"; } /** Returns the class information about the next entry (class or dataset) in * this class. - */ + */ NXClassInfo getNextEntry(); /// Creates a new object in the NeXus file at path path. // virtual void make(const std::string& path) = 0; /// Resets the current position for getNextEntry() to the beginning void reset(); /** - * Check if a path exists relative to the current class path - * @param path :: A string representing the path to test - * @return True if it is valid - */ + * Check if a path exists relative to the current class path + * @param path :: A string representing the path to test + * @return True if it is valid + */ bool isValid(const std::string &path) const; /** Templated method for creating derived NX classes. It also opens the - * created class. - * @param name :: The name of the class - * @tparam NX Concrete Nexus class - * @return The new object - */ + * created class. + * @param name :: The name of the class + * @tparam NX Concrete Nexus class + * @return The new object + */ template <class NX> NX openNXClass(const std::string &name) const { NX nxc(*this, name); nxc.open(); @@ -534,18 +536,18 @@ public: } /** Creates and opens an arbitrary (non-standard) class (group). - * @param name :: The name of the class. - * @return The opened NXClass - */ + * @param name :: The name of the class. + * @return The opened NXClass + */ NXClass openNXGroup(const std::string &name) const { return openNXClass<NXClass>(name); } /** Templated method for creating datasets. It also opens the created set. - * @param name :: The name of the dataset - * @tparam T The type of the data (int, double, ...). - * @return The new object - */ + * @param name :: The name of the dataset + * @tparam T The type of the data (int, double, ...). + * @return The new object + */ template <class T> NXDataSetTyped<T> openNXDataSet(const std::string &name) const { NXDataSetTyped<T> data(*this, name); @@ -554,59 +556,59 @@ public: } /** Creates and opens an integer dataset - * @param name :: The name of the dataset - * @return The int - */ + * @param name :: The name of the dataset + * @return The int + */ NXInt openNXInt(const std::string &name) const { return openNXDataSet<int>(name); } /** Creates and opens a float dataset - * @param name :: The name of the dataset - * @return The float - */ + * @param name :: The name of the dataset + * @return The float + */ NXFloat openNXFloat(const std::string &name) const { return openNXDataSet<float>(name); } /** Creates and opens a double dataset - * @param name :: The name of the dataset - * @return The double - */ + * @param name :: The name of the dataset + * @return The double + */ NXDouble openNXDouble(const std::string &name) const { return openNXDataSet<double>(name); } /** Creates and opens a char dataset - * @param name :: The name of the dataset - * @return The char - */ + * @param name :: The name of the dataset + * @return The char + */ NXChar openNXChar(const std::string &name) const { return openNXDataSet<char>(name); } /** Creates and opens a size_t dataset - * @param name :: The name of the dataset - * @return The size_t - */ + * @param name :: The name of the dataset + * @return The size_t + */ NXSize openNXSize(const std::string &name) const { return openNXDataSet<std::size_t>(name); } /** Returns a string - * @param name :: The name of the NXChar dataset - * @return The string - */ + * @param name :: The name of the NXChar dataset + * @return The string + */ std::string getString(const std::string &name) const; /** Returns a double - * @param name :: The name of the NXDouble dataset - * @return The double - */ + * @param name :: The name of the NXDouble dataset + * @return The double + */ double getDouble(const std::string &name) const; /** Returns a float - * @param name :: The name of the NXFloat dataset - * @return The float - */ + * @param name :: The name of the NXFloat dataset + * @return The float + */ float getFloat(const std::string &name) const; /** Returns a int - * @param name :: The name of the NXInt dataset - * @return The int - */ + * @param name :: The name of the NXInt dataset + * @return The int + */ int getInt(const std::string &name) const; /// Returns a list of all classes (or groups) in this NXClass @@ -616,9 +618,9 @@ public: /// Returns a list of all datasets in this NXClass std::vector<NXInfo> &datasets() const { return *m_datasets; } /** Returns NXInfo for a dataset - * @param name :: The name of the dataset - * @return NXInfo::stat is set to NX_ERROR if the dataset does not exist - */ + * @param name :: The name of the dataset + * @return NXInfo::stat is set to NX_ERROR if the dataset does not exist + */ NXInfo getDataSetInfo(const std::string &name) const; /// Returns whether an individual dataset is present bool containsDataSet(const std::string &query) const; @@ -651,14 +653,14 @@ private: //------------------- auxiliary classes ----------------------------// /** Implements NXlog Nexus class. -*/ + */ class DLLExport NXLog : public NXClass { public: /** Constructor. - * @param parent :: The parent Nexus class. In terms of HDF it is the group - * containing the NXClass. - * @param name :: The name of the NXClass relative to its parent - */ + * @param parent :: The parent Nexus class. In terms of HDF it is the group + * containing the NXClass. + * @param name :: The name of the NXClass relative to its parent + */ NXLog(const NXClass &parent, const std::string &name) : NXClass(parent, name) {} /// Nexus class id @@ -682,7 +684,7 @@ private: if (start_time.empty()) { start_time = "2000-01-01T00:00:00"; } - Kernel::DateAndTime start_t = Kernel::DateAndTime(start_time); + auto start_t = createFromSanitizedISO8601(start_time); NXInfo vinfo = getDataSetInfo("value"); if (!vinfo) return nullptr; @@ -696,8 +698,7 @@ private: value.openLocal(); value.load(); for (int i = 0; i < value.dim0(); i++) { - Kernel::DateAndTime t = - start_t + boost::posix_time::seconds(int(times[i])); + auto t = start_t + boost::posix_time::seconds(int(times[i])); for (int j = 0; j < value.dim1(); j++) { char *c = &value(i, j); if (!isprint(*c)) @@ -715,8 +716,7 @@ private: value.openLocal(); value.load(); for (int i = 0; i < value.dim0(); i++) { - Kernel::DateAndTime t = - start_t + boost::posix_time::seconds(int(times[i])); + auto t = start_t + boost::posix_time::seconds(int(times[i])); logv->addValue(t, (value[i] == 0 ? false : true)); } return logv; @@ -748,8 +748,7 @@ private: value.load(); for (int i = 0; i < value.dim0(); i++) { if (i == 0 || value[i] != value[i - 1] || times[i] != times[i - 1]) { - Kernel::DateAndTime t = - start_t + boost::posix_time::seconds(int(times[i])); + auto t = start_t + boost::posix_time::seconds(int(times[i])); logv->addValue(t, value[i]); } } @@ -758,14 +757,14 @@ private: }; /** Implements NXnote Nexus class. -*/ + */ class DLLExport NXNote : public NXClass { public: /** Constructor. - * @param parent :: The parent Nexus class. In terms of HDF it is the group - * containing the NXClass. - * @param name :: The name of the NXClass relative to its parent - */ + * @param parent :: The parent Nexus class. In terms of HDF it is the group + * containing the NXClass. + * @param name :: The name of the NXClass relative to its parent + */ NXNote(const NXClass &parent, const std::string &name) : NXClass(parent, name), m_author_ok(), m_data_ok(), m_description_ok() {} /// Nexus class id @@ -787,14 +786,14 @@ protected: }; /** Implements NXnote Nexus class with binary data. -*/ + */ class DLLExport NXBinary : public NXNote { public: /** Constructor. - * @param parent :: The parent Nexus class. In terms of HDF it is the group - * containing the NXClass. - * @param name :: The name of the NXClass relative to its parent - */ + * @param parent :: The parent Nexus class. In terms of HDF it is the group + * containing the NXClass. + * @param name :: The name of the NXClass relative to its parent + */ NXBinary(const NXClass &parent, const std::string &name) : NXNote(parent, name) {} /// Return the binary data associated with the note @@ -807,44 +806,44 @@ private: //-------------------- main classes -------------------------------// /** Main class is the one that can contain auxiliary classes. -*/ + */ class DLLExport NXMainClass : public NXClass { public: /** Constructor. - * @param parent :: The parent Nexus class. In terms of HDF it is the group - * containing the NXClass. - * @param name :: The name of the NXClass relative to its parent - */ + * @param parent :: The parent Nexus class. In terms of HDF it is the group + * containing the NXClass. + * @param name :: The name of the NXClass relative to its parent + */ NXMainClass(const NXClass &parent, const std::string &name) : NXClass(parent, name) {} /** Opens a NXLog class - * @param name :: The name of the NXLog - * @return The log - */ + * @param name :: The name of the NXLog + * @return The log + */ NXLog openNXLog(const std::string &name) { return openNXClass<NXLog>(name); } /** Opens a NXNote class - * @param name :: The name of the NXNote - * @return The note - */ + * @param name :: The name of the NXNote + * @return The note + */ NXNote openNXNote(const std::string &name) { return openNXClass<NXNote>(name); } }; /** Implements NXdata Nexus class. -*/ + */ class DLLExport NXData : public NXMainClass { public: /** Constructor. - * @param parent :: The parent Nexus class. In terms of HDF it is the group - * containing the NXClass. - * @param name :: The name of the NXClass relative to its parent - */ + * @param parent :: The parent Nexus class. In terms of HDF it is the group + * containing the NXClass. + * @param name :: The name of the NXClass relative to its parent + */ NXData(const NXClass &parent, const std::string &name); /// Nexus class id std::string NX_class() const override { return "NXdata"; } /** Opens the dataset within this NXData with signal=1 attribute. - */ + */ template <typename T> NXDataSetTyped<T> openData() { for (std::vector<NXInfo>::const_iterator it = datasets().begin(); it != datasets().end(); it++) { @@ -875,14 +874,14 @@ public: }; /** Implements NXdetector Nexus class. -*/ + */ class DLLExport NXDetector : public NXMainClass { public: /** Constructor. - * @param parent :: The parent Nexus class. In terms of HDF it is the group - * containing the NXClass. - * @param name :: The name of the NXClass relative to its parent - */ + * @param parent :: The parent Nexus class. In terms of HDF it is the group + * containing the NXClass. + * @param name :: The name of the NXClass relative to its parent + */ NXDetector(const NXClass &parent, const std::string &name) : NXMainClass(parent, name) {} /// Nexus class id @@ -896,14 +895,14 @@ public: }; /** Implements NXdisk_chopper Nexus class. -*/ + */ class DLLExport NXDiskChopper : public NXMainClass { public: /** Constructor. - * @param parent :: The parent Nexus class. In terms of HDF it is the group - * containing the NXClass. - * @param name :: The name of the NXClass relative to its parent - */ + * @param parent :: The parent Nexus class. In terms of HDF it is the group + * containing the NXClass. + * @param name :: The name of the NXClass relative to its parent + */ NXDiskChopper(const NXClass &parent, const std::string &name) : NXMainClass(parent, name) {} /// Nexus class id @@ -913,66 +912,66 @@ public: }; /** Implements NXinstrument Nexus class. -*/ + */ class DLLExport NXInstrument : public NXMainClass { public: /** Constructor. - * @param parent :: The parent Nexus class. In terms of HDF it is the group - * containing the NXClass. - * @param name :: The name of the NXClass relative to its parent - */ + * @param parent :: The parent Nexus class. In terms of HDF it is the group + * containing the NXClass. + * @param name :: The name of the NXClass relative to its parent + */ NXInstrument(const NXClass &parent, const std::string &name) : NXMainClass(parent, name) {} /// Nexus class id std::string NX_class() const override { return "NXinstrument"; } /** Opens a NXDetector - * @param name :: The name of the class - * @return The detector - */ + * @param name :: The name of the class + * @return The detector + */ NXDetector openNXDetector(const std::string &name) { return openNXClass<NXDetector>(name); } /** Opens a NXDetector - * @param name :: The name of the class - * @return The detector - */ + * @param name :: The name of the class + * @return The detector + */ NXDiskChopper openNXDiskChopper(const std::string &name) { return openNXClass<NXDiskChopper>(name); } }; /** Implements NXentry Nexus class. -*/ + */ class DLLExport NXEntry : public NXMainClass { public: /** Constructor. - * @param parent :: The parent Nexus class. In terms of HDF it is the group - * containing the NXClass. - * @param name :: The name of the NXClass relative to its parent - */ + * @param parent :: The parent Nexus class. In terms of HDF it is the group + * containing the NXClass. + * @param name :: The name of the NXClass relative to its parent + */ NXEntry(const NXClass &parent, const std::string &name) : NXMainClass(parent, name) {} /// Nexus class id std::string NX_class() const override { return "NXentry"; } /** Opens a NXData - * @param name :: The name of the class - * @return the nxdata entry - */ + * @param name :: The name of the class + * @return the nxdata entry + */ NXData openNXData(const std::string &name) { return openNXClass<NXData>(name); } /** Opens a NXInstrument - * @param name :: The name of the class - * @return the instrument - */ + * @param name :: The name of the class + * @return the instrument + */ NXInstrument openNXInstrument(const std::string &name) { return openNXClass<NXInstrument>(name); } }; /** Implements NXroot Nexus class. -*/ + */ class DLLExport NXRoot : public NXClass { public: // Constructor @@ -987,9 +986,9 @@ public: /// definition. bool isStandard() const; /** Opens an entry -- a topmost Nexus class - * @param name :: The name of the entry - * @return the entry - */ + * @param name :: The name of the entry + * @return the entry + */ NXEntry openEntry(const std::string &name) { return openNXClass<NXEntry>(name); } diff --git a/qt/widgets/common/src/AlgorithmDialog.cpp b/qt/widgets/common/src/AlgorithmDialog.cpp index dc32dc1d3e0729306413f97d7bb3dc3767445575..453b561cf38115caa8343e81f887c2c120d396e7 100644 --- a/qt/widgets/common/src/AlgorithmDialog.cpp +++ b/qt/widgets/common/src/AlgorithmDialog.cpp @@ -1,6 +1,7 @@ #include "MantidAPI/AlgorithmManager.h" #include "MantidAPI/IWorkspaceProperty.h" #include "MantidKernel/DateAndTime.h" +#include "MantidKernel/DateAndTimeHelpers.h" #include "MantidKernel/IPropertySettings.h" #include "MantidKernel/Logger.h" @@ -24,6 +25,7 @@ #include <Poco/ActiveResult.h> using namespace MantidQt::API; +using namespace Mantid::Kernel::DateAndTimeHelpers; using Mantid::API::IAlgorithm; using Mantid::Kernel::DateAndTime; @@ -999,7 +1001,7 @@ void AlgorithmDialog::setPreviousValue(QWidget *widget, // String in ISO8601 format DateAndTime t = DateAndTime::getCurrentTime(); try { - t.setFromISO8601(value.toStdString()); + t.setFromISO8601(verifyAndSanitizeISO8601(value.toStdString())); } catch (std::exception &) { } dateEdit->setDate(QDate(t.year(), t.month(), t.day()));