diff --git a/Device/Unit/Axes.h b/Device/Unit/Axes.h index 369b18ee595952121525b9584fb2f2de538da69a..7e4fe791875be9a18b5e9dcb9c958296c079f71a 100644 --- a/Device/Unit/Axes.h +++ b/Device/Unit/Axes.h @@ -3,7 +3,7 @@ // BornAgain: simulate and fit reflection and scattering // //! @file Device/Unit/Axes.h -//! @brief Defines interface IUnitConverter and possible axis units. +//! @brief Defines enum Axis::Units. //! //! @homepage http://www.bornagainproject.org //! @license GNU General Public License v3 or higher (see COPYING) diff --git a/Device/Unit/AxisNames.h b/Device/Unit/AxisNames.h index 005053269c39f19db7aae852e228baa4291f151d..600496a852af7465685590207c0f84c67beac4f0 100644 --- a/Device/Unit/AxisNames.h +++ b/Device/Unit/AxisNames.h @@ -3,7 +3,7 @@ // BornAgain: simulate and fit reflection and scattering // //! @file Device/Unit/AxisNames.h -//! @brief Defines namespace AxisNames. +//! @brief Defines axisUnitLabel and maps in namespace AxisNames. //! //! @homepage http://www.bornagainproject.org //! @license GNU General Public License v3 or higher (see COPYING) @@ -30,8 +30,7 @@ const std::map<Axes::Units, const char*> axisUnitLabel = { {Axes::Units::DEGREES, "deg"}, {Axes::Units::MM, "mm"}, {Axes::Units::QSPACE, "1/nm"}, {Axes::Units::QXQY, "1/nm"}, {Axes::Units::RQ4, "nm^-4?"}}; -//! Contains functions to create maps that give the right axis names for different -//! detector types and units +//! Contains const maps that give the right axis names for different detector types and units //! @ingroup detector namespace AxisNames { diff --git a/GUI/coregui/DataLoaders/AbstractDataLoader.h b/GUI/coregui/DataLoaders/AbstractDataLoader.h index 5cc28163f2f2dc45ecd7bfe51f160c0a874ba6f6..eadaa3ec6d5eb58e48caf3375f889494e07e068b 100644 --- a/GUI/coregui/DataLoaders/AbstractDataLoader.h +++ b/GUI/coregui/DataLoaders/AbstractDataLoader.h @@ -25,7 +25,7 @@ class AbstractDataLoaderResultModel; #include <QtCore> -//! Base class for all data loaders (classes which can import real data) +//! Abstract base class for all data loaders (classes to import real data). class AbstractDataLoader : public QObject { Q_OBJECT @@ -47,8 +47,9 @@ public: //! The real data item on which the import shall work. const RealDataItem* realDataItem() const; - //! Fills the widget on the import dialog pane. This base class' implementation does nothing - //! (meaning "no editable properties") + //! Fills the widget on the import dialog pane. + //! The implementation here in the base class does nothing + //! (meaning "no editable properties"). virtual void populateImportSettingsWidget(QWidget* parent); //! Read all values from the properties UI into the internal variables @@ -66,44 +67,48 @@ public: //! Returns every internal setting so it can be restored completely virtual QByteArray serialize() const; - //! Initialize from serialization data. If any error occurred, then a DeserializationException - //! has to be thrown. - //! The complete state has to be restored. Therefore if e.g. errors occurred in the former - //! serialization, but errors are not serialized, then they have to be regenerated/recalculated - //! in here. + //! Initialize from serialization data. If any error occurred, + //! then a DeserializationException has to be thrown. + //! The complete state has to be restored. + //! Therefore if e.g. errors occurred in the former serialization, + //! but errors are not serialized, then they have to be regenerated/ + //! recalculated in here. virtual void deserialize(const QByteArray& data); - //! Sets the file contents to be imported. If the file was a compressed file, here already the - //! decompressed content will be overhanded. + //! Sets the file contents to be imported. + //! If the file was a compressed file, then the decompressed content + //! will be handed over already here. virtual void setFileContents(const QByteArray& fileContent) = 0; - //! Returns the original file content. If not available any more (like for legacy project file - //! import), then an empty array will be returned. + //! Returns the original file content. + //! If not available any more (like for legacy project file import), + //! then an empty array will be returned. virtual QByteArray fileContent() const; - //! Guess appropriate settings (for example the separator in a CSV file). Is called only once, - //! directly after setting the file content. + //! Guess appropriate settings (for example the separator in a CSV file). + //! Is called only once, directly after setting the file content. virtual void guessSettings(); - //! Process the file contents. Can be called more than once, e.g. if the import settings have - //! changed. + //! Process the file contents. + //! Can be called more than once, e.g. if the import settings have changed. //! Any error has to be stored in the loader (see numErrors()). virtual void processContents() = 0; - //! Number of errors found while processing the content. An error means that either a particular - //! content (line) can't be used or may be suspicious (line related error), or that the whole - //! content can't be used (e.g. only 1 line present). + //! Number of errors found while processing the content. + //! An error means that either a particular content (line) can't be used + //! or may be suspicious (line related error), or that the whole content + //! can't be used (e.g. only 1 line present). virtual int numErrors() const; - //! Number of errors related to a specific line. Such an error means that a particular - //! content (line) can't be used or may be suspicious. + //! Number of errors related to a specific line. Such an error means that + //! a particular content (line) can't be used or may be suspicious. virtual int numLineRelatedErrors() const; //! Errors not related to a particular line. virtual QStringList lineUnrelatedErrors() const; - //! Create a table model which contains the import information like original file content, raw - //! content, processed content + //! Create a table model which contains the import information like + //! original file content, raw content, processed content. //! The returned pointer will be owned by the caller. //! This base class' implementation does nothing (return nullptr). virtual AbstractDataLoaderResultModel* createResultModel() const; @@ -115,9 +120,6 @@ signals: //! Emitted whenever contents have been processed void contentsProcessed(); -protected: - enum class Error { DifferendNumberOfColumns }; - protected: RealDataItem* m_item; //< The real-data-item which owns this loader. Never delete this! }; diff --git a/GUI/coregui/DataLoaders/AbstractDataLoader1D.h b/GUI/coregui/DataLoaders/AbstractDataLoader1D.h index a1bc6b91db50b059404d2bdae1ffa997216496d7..0a616743368154f76133ebbdc7977988cd0216d8 100644 --- a/GUI/coregui/DataLoaders/AbstractDataLoader1D.h +++ b/GUI/coregui/DataLoaders/AbstractDataLoader1D.h @@ -17,7 +17,7 @@ #include "GUI/coregui/DataLoaders/AbstractDataLoader.h" -//! Base class for data loaders for 1D import +//! Abstract base class for reflectometry data loaders. class AbstractDataLoader1D : public AbstractDataLoader { }; diff --git a/GUI/coregui/DataLoaders/AutomaticDataLoader1D.h b/GUI/coregui/DataLoaders/AutomaticDataLoader1D.h index 0f37d40e1ad492f811bcdade3aa8f3e8213306d3..82506f3bb1a637d62eeaf08d76d97877cdf6757e 100644 --- a/GUI/coregui/DataLoaders/AutomaticDataLoader1D.h +++ b/GUI/coregui/DataLoaders/AutomaticDataLoader1D.h @@ -18,7 +18,8 @@ #include "Device/Data/OutputData.h" #include "GUI/coregui/DataLoaders/AbstractDataLoader1D.h" -//! Implements the legacy importer from BornAgain with no user interaction +//! The legacy importer for reflectometry, with no user interaction. + class AutomaticDataLoader1D : public AbstractDataLoader1D { public: virtual QString name() const override; diff --git a/GUI/coregui/Models/DataItem.h b/GUI/coregui/Models/DataItem.h index 63d89ab14b88d325532aa0fc1632531b67353d92..107f1014a7d3ceefa4baee4cc99529a344e6764c 100644 --- a/GUI/coregui/Models/DataItem.h +++ b/GUI/coregui/Models/DataItem.h @@ -24,7 +24,10 @@ class ImportDataInfo; class InstrumentItem; -//! Provides common functionality for IntensityDataItem and SpecularDataItem +//! Abstract base class for IntensityDataItem and SpecularDataItem. +//! Owns one simulated data set of type OutputData<double>. + +//! For experimental data, use RealDataItem. class BA_CORE_API_ DataItem : public SessionItem, public SaveLoadInterface { private: @@ -39,9 +42,8 @@ public: //! The given pointer becomes owned by this class!! virtual void setOutputData(OutputData<double>* data) = 0; - //! Sets the raw data vector from external source - //! Checks only the equality of data size, - //! no dimension checks are applied. + //! Sets the raw data vector from external source. + //! Checks only the equality of data size; no dimension checks are applied. void setRawDataVector(std::vector<double> data); using SaveLoadInterface::fileName; @@ -62,8 +64,7 @@ public: virtual void updateAxesUnits(const InstrumentItem* instrument) = 0; virtual std::vector<int> shape() const = 0; - //! Resets data to the state defined by user (imported) - //! data. + //! Resets data to the state defined by user (imported) data. virtual void reset(ImportDataInfo data) = 0; protected: diff --git a/GUI/coregui/Models/IntensityDataItem.h b/GUI/coregui/Models/IntensityDataItem.h index 6ae86e13640e30343b67d7303865a84c8a77771c..1f7d607890afb1f6bacf15fe10fd77dc45eb24e4 100644 --- a/GUI/coregui/Models/IntensityDataItem.h +++ b/GUI/coregui/Models/IntensityDataItem.h @@ -43,23 +43,23 @@ public: int getNbinsX() const; int getNbinsY() const; - //! returns lower and upper zoom ranges of x-axis + //! Returns lower and upper zoom ranges of x-axis double getLowerX() const; double getUpperX() const; - //! returns min and max range of x-axis as given by IntensityData + //! Returns min and max range of x-axis as given by IntensityData double getXmin() const; double getXmax() const; - //! returns lower and upper zoom ranges of y-axis + //! Returns lower and upper zoom ranges of y-axis double getLowerY() const; double getUpperY() const; - //! returns min and max range of y-axis as given by IntensityData + //! Returns min and max range of y-axis as given by IntensityData double getYmin() const; double getYmax() const; - //! returns lower and upper zoom ranges of z-axis + //! Returns lower and upper zoom ranges of z-axis double getLowerZ() const; double getUpperZ() const; @@ -69,7 +69,7 @@ public: QString getXaxisTitle() const; QString getYaxisTitle() const; - //! return true if min, max range of Z-axis is locked (change not allowed) + //! Returns true if min, max range of Z-axis is locked (change not allowed) bool isZAxisLocked() const; void setZAxisLocked(bool state); @@ -100,8 +100,7 @@ public: void updateAxesUnits(const InstrumentItem* instrument) override; std::vector<int> shape() const override; - //! Returns data to the state defined by user (imported) - //! data. + //! Returns data to the state defined by user (imported) data. void reset(ImportDataInfo data) override; public slots: diff --git a/GUI/coregui/Models/JobItemUtils.cpp b/GUI/coregui/Models/JobItemUtils.cpp index d905a63ca75ccc175a15af37bb1ea3a673506d94..032911b5ececd381f90b3fc8556799d2c3d14231 100644 --- a/GUI/coregui/Models/JobItemUtils.cpp +++ b/GUI/coregui/Models/JobItemUtils.cpp @@ -69,15 +69,17 @@ void JobItemUtils::updateDataAxes(DataItem* intensityItem, const InstrumentItem* updateAxesTitle(intensityItem, *converter, requested_units); } -//! Correspondance of domain detector axes types to their gui counterpart. +//! Correspondence of domain detector axes types to their GUI counterpart. QString JobItemUtils::nameFromAxesUnits(Axes::Units units) { - return names_from_units.find(units) != names_from_units.end() ? names_from_units.at(units) - : QString(); + const auto it = names_from_units.find(units); + if (it == names_from_units.end()) + return ""; + return it->second; } -//! Correspondance of GUI axes units names to their domain counterpart. +//! Correspondence of GUI axes units names to their domain counterpart. Axes::Units JobItemUtils::axesUnitsFromName(const QString& name) { diff --git a/GUI/coregui/Models/JobItemUtils.h b/GUI/coregui/Models/JobItemUtils.h index d2c9690eaa0d0803e87ab15c02237149372e5e6b..ab394ab1a076b01db5e655651aaa4c0f74416713 100644 --- a/GUI/coregui/Models/JobItemUtils.h +++ b/GUI/coregui/Models/JobItemUtils.h @@ -25,10 +25,11 @@ class JobItem; class ISimulation; class IUnitConverter; -//! Contains set of convenience methods to set data to the IntensityDataItem from domain simulation. +//! Contains convenience methods to trasfer data from domain simulation to IntensityDataItem. //! Used to modify OutputData's axes units as requested by IntensityDataItem. namespace JobItemUtils { + //! updates axes of OutputData in IntensityData item void updateDataAxes(DataItem* intensityItem, const InstrumentItem* instrumentItem); @@ -48,6 +49,7 @@ void createDefaultDetectorMap(DataItem* intensityItem, const InstrumentItem* ins void setResults(DataItem* intensityItem, const ISimulation* simulation); ComboProperty availableUnits(const IUnitConverter& converter); + } // namespace JobItemUtils #endif // BORNAGAIN_GUI_COREGUI_MODELS_JOBITEMUTILS_H diff --git a/GUI/coregui/Models/ParameterTreeUtils.cpp b/GUI/coregui/Models/ParameterTreeUtils.cpp index d4067a247c8b6a5c1f2c6d6c04476b730780ac94..e02fa0449f760ff1f8169245c8cf261131eecacf 100644 --- a/GUI/coregui/Models/ParameterTreeUtils.cpp +++ b/GUI/coregui/Models/ParameterTreeUtils.cpp @@ -131,7 +131,7 @@ QStringList ParameterTreeUtils::translatedParameterTreeNames(const SessionItem* return result; } -//! Correspondance of parameter name to translated name for all properties found in source +//! Correspondence of parameter name to translated name for all properties found in source //! in its children. QVector<QPair<QString, QString>> ParameterTreeUtils::parameterDictionary(const SessionItem* source) diff --git a/GUI/coregui/Models/RealDataItem.h b/GUI/coregui/Models/RealDataItem.h index 6299a9e5b8c6967d2e60f64604aefb8a3357767d..c63d5a6f4ca085ce6a9158e8cc5b2663eaa5c608 100644 --- a/GUI/coregui/Models/RealDataItem.h +++ b/GUI/coregui/Models/RealDataItem.h @@ -30,7 +30,8 @@ class ImportDataInfo; class RealDataModel; class AbstractDataLoader; -//! The RealDataItem class represents intensity data imported from file and intended for fitting. +//! Provides access to experimental data, for display and fitting. +//! Owns an AbstractDataLoader. class BA_CORE_API_ RealDataItem : public QObject, public SessionItem { diff --git a/GUI/coregui/Views/ImportDataWidgets/CsvImportAssistant/CsvImportAssistant.h b/GUI/coregui/Views/ImportDataWidgets/CsvImportAssistant/CsvImportAssistant.h index 39f78c2a9af124312737b9b9b92b7af518805050..ccdc78149060768f3f7a7c52570887e0b578f620 100644 --- a/GUI/coregui/Views/ImportDataWidgets/CsvImportAssistant/CsvImportAssistant.h +++ b/GUI/coregui/Views/ImportDataWidgets/CsvImportAssistant/CsvImportAssistant.h @@ -53,7 +53,6 @@ class CsvImportAssistant : public QObject { Q_OBJECT public: CsvImportAssistant(const QString& file, const bool useGUI = false, QWidget* parent = nullptr); - ImportDataInfo getData() { return m_dataAvailable ? fillData() : ImportDataInfo(); } static void showErrorMessage(std::string message); void setIntensityColumn(int iCol, double multiplier = 1.0); void setCoordinateColumn(int iCol, Axes::Units units, double multiplier = 1.0); diff --git a/GUI/coregui/Views/ImportDataWidgets/ImportDataUtils.cpp b/GUI/coregui/Views/ImportDataWidgets/ImportDataUtils.cpp index c01fe266cea1e95310fa4a4ec08e1a871b2a32a1..4e946d87de1250e146583a621618244d694db6f6 100644 --- a/GUI/coregui/Views/ImportDataWidgets/ImportDataUtils.cpp +++ b/GUI/coregui/Views/ImportDataWidgets/ImportDataUtils.cpp @@ -33,6 +33,7 @@ #include <QMessageBox> namespace { + const QString filter_string_ba = "Intensity File (*.int *.gz *.tif *.tiff *.txt *.csv);;" "Other (*.*)"; const QString filter_string_ascii = "Intensity File (*.int *.int.gz *.txt *.csv *.dat *.ascii);;" @@ -48,18 +49,20 @@ int rank(const InstrumentItem& item) return static_cast<int>(item.shape().size()); } -} // namespace +//! Imports for 2D or 1D data, using given loader. +//! Allocates OutputData, and returns owning pointer. +//! Currently used for all 2D, and some 1D data files. -std::unique_ptr<OutputData<double>> -ImportDataUtils::ImportKnownData(const QString& fileName, - IntensityDataIOFactory::LoaderSelector loader) +std::unique_ptr<OutputData<double>> ImportKnownData( + const QString& fileName, + IntensityDataIOFactory::LoaderSelector loader = IntensityDataIOFactory::automatic) { // Try to use the canonical tools for importing data std::unique_ptr<OutputData<double>> result; try { std::unique_ptr<OutputData<double>> data( IntensityDataIOFactory::readOutputData(fileName.toStdString(), loader)); - result = CreateSimplifiedOutputData(*data); + result = ImportDataUtils::binifyAxes(*data); } catch (std::exception& ex) { QString message = QString("Error while trying to read file\n\n'%1'\n\n%2") .arg(fileName) @@ -69,22 +72,8 @@ ImportDataUtils::ImportKnownData(const QString& fileName, return result; } -std::unique_ptr<OutputData<double>> -ImportDataUtils::ImportReflectometryData(const QString& fileName) -{ - std::unique_ptr<OutputData<double>> result; - try { - std::unique_ptr<OutputData<double>> data( - IntensityDataIOFactory::readReflectometryData(fileName.toStdString())); - result.swap(data); - } catch (std::exception& ex) { - QString message = QString("Error while trying to read file\n\n'%1'\n\n%2") - .arg(fileName) - .arg(QString::fromStdString(std::string(ex.what()))); - QMessageBox::warning(nullptr, "IO Problem", message); - } - return result; -} +} // namespace + std::unique_ptr<OutputData<double>> ImportDataUtils::Import2dData(const QString& fileName, @@ -104,9 +93,9 @@ QString ImportDataUtils::Import1dData(RealDataItem* realDataItem, || DataFormatUtils::isIntFile(fileNameStdString) || DataFormatUtils::isTiffFile(fileNameStdString)) { try { - ImportDataInfo data(ImportKnownData(fileName), Axes::Units::QSPACE); - if (data) { - realDataItem->setImportData(std::move(data)); + ImportDataInfo info(ImportKnownData(fileName), Axes::Units::QSPACE); + if (info) { + realDataItem->setImportData(std::move(info)); return QString(); } } catch (std::exception& ex) { @@ -126,9 +115,8 @@ QString ImportDataUtils::Import1dData(RealDataItem* realDataItem, // -- try with selected CSV loader. If none selected, try with QRE loader QFile file(fileName); - const bool fileCouldBeOpened = file.open(QFile::ReadOnly | QIODevice::Text); - - if (!fileCouldBeOpened) + const bool ok = file.open(QFile::ReadOnly | QIODevice::Text); + if (!ok) return "File could not be opened."; QByteArray fileContent = file.readAll(); @@ -165,20 +153,12 @@ bool ImportDataUtils::Compatible(const InstrumentItem& instrumentItem, } std::unique_ptr<OutputData<double>> -ImportDataUtils::CreateSimplifiedOutputData(const OutputData<double>& data) +ImportDataUtils::binifyAxes(const OutputData<double>& data) { - const size_t data_rank = data.rank(); - if (data_rank > 2 || data_rank < 1) - throw std::runtime_error("Error in ImportDataUtils::CreateSimplifiedOutputData: passed " - "array is neither 1D nor 2D"); - std::unique_ptr<OutputData<double>> result(new OutputData<double>); - for (size_t i = 0; i < data_rank; ++i) { + for (size_t i = 0; i < data.rank(); ++i) { const IAxis& axis = data.axis(i); - const size_t axis_size = axis.size(); - const double min = 0.0; - const double max = axis_size; - result->addAxis(FixedBinAxis(axis.getName(), axis_size, min, max)); + result->addAxis(FixedBinAxis(axis.getName(), axis.size(), 0., axis.size())); } result->setRawDataVector(data.getRawDataVector()); diff --git a/GUI/coregui/Views/ImportDataWidgets/ImportDataUtils.h b/GUI/coregui/Views/ImportDataWidgets/ImportDataUtils.h index 88d97c95975de3b0e7308679a670ed24976196a2..2f82a416ce1c5e49b01a0efd708e60b33ed37551 100644 --- a/GUI/coregui/Views/ImportDataWidgets/ImportDataUtils.h +++ b/GUI/coregui/Views/ImportDataWidgets/ImportDataUtils.h @@ -24,31 +24,28 @@ template <class T> class OutputData; class RealDataItem; class InstrumentItem; -class GISASInstrumentItem; class AbstractDataLoader; //! Provides utility methods to import data files. namespace ImportDataUtils { +//! Imports 2D data, stores them as OutputData, and returns owning pointer. std::unique_ptr<OutputData<double>> Import2dData(const QString& fileName, IntensityDataIOFactory::LoaderSelector loader); -//! Import 1D data into the given item. -//! Returns an error text if a fatal error occurred (discard item). "Empty string" means "no fatal -//! error" => imported item should be kept. The imported item still can have errors, but they might -//! be solvable by different import settings or by using a different data loader. -//! selectedLoader is the one which was selected in the open-file-dialog (or null if none selected). -QString Import1dData(RealDataItem* realDataItem, const AbstractDataLoader* selectedLoader); - -std::unique_ptr<OutputData<double>> -ImportKnownData(const QString& fileName, - IntensityDataIOFactory::LoaderSelector loader = IntensityDataIOFactory::automatic); +//! Imports 1D data into the given item. -std::unique_ptr<OutputData<double>> ImportReflectometryData(const QString& fileName); +//! Returns an error text if a fatal error occurred (discard item). +//! "Empty string" means "no fatal error" => imported item should be kept. +//! The imported item still can have errors, but they might be solvable +//! by different import settings or by using a different data loader. +//! Argument selectedLoader is the one which was selected in the open-file-dialog +//! (or null if none selected). +QString Import1dData(RealDataItem* realDataItem, const AbstractDataLoader* selectedLoader); //! Creates OutputData with bin-valued axes. -std::unique_ptr<OutputData<double>> CreateSimplifiedOutputData(const OutputData<double>& data); +std::unique_ptr<OutputData<double>> binifyAxes(const OutputData<double>& data); //! Check whether data item is compatible with instrument (same rank) bool Compatible(const InstrumentItem& instrumentItem, const RealDataItem& realDataItem); diff --git a/GUI/coregui/Views/SampleDesigner/DesignerScene.h b/GUI/coregui/Views/SampleDesigner/DesignerScene.h index 30888b72c647ceb3cdadd40b7342c5926dd4d281..c3a038d18afb2356fa1ade356805bedc740e9297 100644 --- a/GUI/coregui/Views/SampleDesigner/DesignerScene.h +++ b/GUI/coregui/Views/SampleDesigner/DesignerScene.h @@ -106,7 +106,7 @@ private: bool m_block_selection; QMap<SessionItem*, IView*> m_ItemToView; - //!< Correspondance of model's item and scene's view + //!< Correspondence of model's item and scene's view QLineF m_layer_interface_line; //!< Foreground line representing appropriate interface during layer's movement diff --git a/GUI/coregui/mainwindow/OutputDataIOHistory.h b/GUI/coregui/mainwindow/OutputDataIOHistory.h index 2ccd46fba586716eb868cb1e8856edf14c1d24d7..57236eb7c5bb0e67ce32f348c64cc28acaec8f76 100644 --- a/GUI/coregui/mainwindow/OutputDataIOHistory.h +++ b/GUI/coregui/mainwindow/OutputDataIOHistory.h @@ -76,7 +76,7 @@ public: QStringList savedFileNames(const QString& dirname) const; private: - //!< Correspondance of directory name to save history. + //!< Correspondence of directory name to save history. QMap<QString, OutputDataDirHistory> m_dir_history; }; diff --git a/GUI/coregui/utils/ImportDataInfo.cpp b/GUI/coregui/utils/ImportDataInfo.cpp index beb67363b1f67a3d1426fd0c708b69a971974f2a..48e6342e440296521bfb78701be4f3a05fa215ed 100644 --- a/GUI/coregui/utils/ImportDataInfo.cpp +++ b/GUI/coregui/utils/ImportDataInfo.cpp @@ -22,8 +22,7 @@ namespace { std::vector<Axes::Units> specularUnits() { std::vector<Axes::Units> result; - const auto units_map = AxisNames::specAxis; - for (auto& pair : units_map) + for (auto& pair : AxisNames::specAxis) result.push_back(pair.first); return result; } @@ -33,8 +32,6 @@ std::map<size_t, std::vector<Axes::Units>> available_units = {{1u, specularUnits {2u, {Axes::Units::NBINS}}}; } // namespace -ImportDataInfo::ImportDataInfo() = default; - ImportDataInfo::ImportDataInfo(ImportDataInfo&& other) : m_data(std::move(other.m_data)), m_units(other.m_units) { @@ -42,7 +39,7 @@ ImportDataInfo::ImportDataInfo(ImportDataInfo&& other) ImportDataInfo::ImportDataInfo(std::unique_ptr<OutputData<double>> data, Axes::Units units) : m_data(units == Axes::Units::NBINS && data - ? ImportDataUtils::CreateSimplifiedOutputData(*data) + ? ImportDataUtils::binifyAxes(*data) : std::move(data)) , m_units(units) { diff --git a/GUI/coregui/utils/ImportDataInfo.h b/GUI/coregui/utils/ImportDataInfo.h index c2cab9935b42699f08c2c587d902474601c63509..d6242b7ad4bd0c5f9ef24214cd5adbd978563085 100644 --- a/GUI/coregui/utils/ImportDataInfo.h +++ b/GUI/coregui/utils/ImportDataInfo.h @@ -25,7 +25,7 @@ template <class T> class OutputData; class ImportDataInfo { public: - ImportDataInfo(); + ImportDataInfo() = delete; ImportDataInfo(ImportDataInfo&& other); ImportDataInfo(std::unique_ptr<OutputData<double>> data, Axes::Units units); ImportDataInfo(OutputData<double>&& data, Axes::Units units); diff --git a/Tests/Performance/GUI/CMakeLists.txt b/Tests/Performance/GUI/CMakeLists.txt index 6c94923d2ade1fb3d376a81b6354c2cbacb7172d..d8b5df1d12077853666f796c0e62e4489064d78c 100644 --- a/Tests/Performance/GUI/CMakeLists.txt +++ b/Tests/Performance/GUI/CMakeLists.txt @@ -7,5 +7,4 @@ function(PerformanceTest NAME SPEED DEPS) endif() endfunction() -PerformanceTest(CsvImportAssistantPerformanceTest "fast" "") PerformanceTest(GUIPerformanceTest "too_slow" ../Benchmark.cpp) # don't run (timeout after 1500s) diff --git a/Tests/Performance/GUI/CsvImportAssistantPerformanceTest.cpp b/Tests/Performance/GUI/CsvImportAssistantPerformanceTest.cpp deleted file mode 100644 index 23c8af506f778c626fa54c339f8c6e832f110eae..0000000000000000000000000000000000000000 --- a/Tests/Performance/GUI/CsvImportAssistantPerformanceTest.cpp +++ /dev/null @@ -1,92 +0,0 @@ -// ************************************************************************************************ -// -// BornAgain: simulate and fit reflection and scattering -// -//! @file Tests/Performance/GUI/CsvImportAssistantPerformanceTest.cpp -//! @brief Implements GUI performance functional test. -//! -//! @homepage http://www.bornagainproject.org -//! @license GNU General Public License v3 or higher (see COPYING) -//! @copyright Forschungszentrum Jülich GmbH 2018 -//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS) -// -// ************************************************************************************************ - -#include "Tests/Performance/GUI/CsvImportAssistantPerformanceTest.h" -#include "Device/Data/ArrayUtils.h" -#include "Device/Histo/IntensityDataIOFactory.h" -#include "GUI/coregui/Views/ImportDataWidgets/CsvImportAssistant/CsvImportAssistant.h" -#include <ctime> -#include <iostream> - -void CsvImportAssistantPerformanceTest::writeTestFile() -{ - remove(m_testFilename.c_str()); - OutputData<double>* data = ArrayUtils::createData(m_testVector).release(); - IntensityDataIOFactory::writeOutputData(*data, m_testFilename); -} - -void CsvImportAssistantPerformanceTest::writeTestFile(size_t nRows, size_t nCols) -{ - remove(m_testFilename.c_str()); - std::ofstream myfile; - myfile.open(m_testFilename); - for (size_t i = 0; i < nRows; i++) { - for (size_t j = 0; j < nCols; j++) { - myfile << nCols * i + j << " "; - } - myfile << "\n"; - } - myfile.close(); -} - -OutputData<double>* CsvImportAssistantPerformanceTest::readTestFile() -{ - return IntensityDataIOFactory::readOutputData(m_testFilename); -} - -bool CsvImportAssistantPerformanceTest::runTest() -{ - std::cout << "CsvImportAssistantPerformanceTest -> Running ..." << std::endl; - size_t maxRows = 1000; - size_t maxCols = 1000; - - for (size_t nRows = 10; nRows <= maxRows; nRows *= 10) { - for (size_t nCols = 10; nCols <= maxCols; nCols *= 10) { - - // Write test file - writeTestFile(nRows, nCols); - - // Time the process of reading and importing data: - std::clock_t c_start = std::clock(); - - // Reading and setting data to import: - CsvImportAssistant assistant(testFilename()); - assistant.setIntensityColumn(1); - assistant.setCoordinateColumn(9, Axes::Units::DEGREES); - assistant.setFirstRow(1); - assistant.setLastRow(int(nRows)); - - // Importing of data: - // If something goes wrong, this line may make the test fail or even crash. - // The correctness of the reading is tested in test_readFile. - std::vector<double> RawDataVec = - assistant.getData().intensityData()->getRawDataVector(); - if (RawDataVec.size() != nRows) - return false; - - // Report on the test time: - std::clock_t c_end = std::clock(); - double_t time_spent = 1000.0 * double_t(c_end - c_start) / double_t(CLOCKS_PER_SEC); - std::cout << "nRows: " << nRows << "; nCols: " << nCols << "; time: " << time_spent - << " ms\n" - << std::flush; - } - } - return true; -} - -int main() -{ - return !CsvImportAssistantPerformanceTest().runTest(); -} diff --git a/Tests/UnitTests/GUI/TestCsvImportAssistant.cpp b/Tests/UnitTests/GUI/TestCsvImportAssistant.cpp deleted file mode 100644 index df737e845bff150c5a5f5397c97d1f126c4506de..0000000000000000000000000000000000000000 --- a/Tests/UnitTests/GUI/TestCsvImportAssistant.cpp +++ /dev/null @@ -1,96 +0,0 @@ -#include "Device/Data/ArrayUtils.h" -#include "Device/Histo/IntensityDataIOFactory.h" -#include "Device/Unit/AxisNames.h" -#include "GUI/coregui/Models/JobItemUtils.h" -#include "GUI/coregui/Models/SpecularDataItem.h" -#include "GUI/coregui/Views/ImportDataWidgets/CsvImportAssistant/CsvImportAssistant.h" -#include "Tests/GTestWrapper/google_test.h" -#include <vector> - -class TestCsvImportAssistant : public ::testing::Test { -protected: - const std::string m_testFilename = "tm_TestCsvImportAssistant.txt"; - const std::vector<std::vector<double>> m_testVector = { - {0.0, 1.0, 2.0, 3.0}, {4.0, 5.0, 6.0, 7.0}, {8.0, 9.0, 10.0, 11.0}, - {12.0, 13.0, 14.0, 15.0}, {16.0, 17.0, 18.0, 19.0}, {20.0, 21.0, 22.0, 23.0}}; - - const QString testFilename() { return QString::fromStdString(m_testFilename); } - - void writeTestFile() - { - remove(m_testFilename.c_str()); - OutputData<double>* data = ArrayUtils::createData(m_testVector).release(); - IntensityDataIOFactory::writeOutputData(*data, m_testFilename); - } - - void writeTestFile(size_t nRows, size_t nCols) - { - remove(m_testFilename.c_str()); - std::ofstream myfile; - myfile.open(m_testFilename); - for (size_t i = 0; i < nRows; i++) { - for (size_t j = 0; j < nCols; j++) { - myfile << nCols * i + j << " "; - } - myfile << "\n"; - } - myfile.close(); - } - - OutputData<double>* readTestFile() - { - return IntensityDataIOFactory::readOutputData(m_testFilename); - } -}; - -//! Testing component items of particle item. -TEST_F(TestCsvImportAssistant, test_readFile) -{ - /* - * The file to read looks like this ['-' symbols added to clarify what is going on]. - * It has originaly ten columns, not four (The separator is a space). - * When the separator is a space, repeated spaces will be merged into one. - * Thus, the ImportAssistant will read this file as a four-column file. - # - BornAgain - Intensity - Data - - - - - - - - # - Simple - 2D - array - suitable - for - numpy, - matlab - etc. - - - # - [nrows=6, - ncols=4] - - - - - - - - - 0.000000000000e+00 - - - - 1.000000000000e+00 - - - - 2.000000000000e+00 - - 3.000000000000e+00 - - 4.000000000000e+00 - - - - 5.000000000000e+00 - - - - 6.000000000000e+00 - - 7.000000000000e+00 - - 8.000000000000e+00 - - - - 9.000000000000e+00 - - - - 1.000000000000e+01 - - 1.100000000000e+01 - - 1.200000000000e+01 - - - - 1.300000000000e+01 - - - - 1.400000000000e+01 - - 1.500000000000e+01 - - 1.600000000000e+01 - - - - 1.700000000000e+01 - - - - 1.800000000000e+01 - - 1.900000000000e+01 - - 2.000000000000e+01 - - - - 2.100000000000e+01 - - - - 2.200000000000e+01 - - 2.300000000000e+01 - - Number of Columns: 10 - Separator: >>> <<< - */ - writeTestFile(); - - CsvImportAssistant assistant(testFilename()); - - assistant.setIntensityColumn(1); - assistant.setCoordinateColumn(3, Axes::Units::DEGREES); - assistant.setFirstRow(5); - assistant.setLastRow(7); - - auto DataRank = assistant.getData().dataRank(); - auto AllocSize = assistant.getData().intensityData()->getAllocatedSize(); - auto RawDataVec = assistant.getData().intensityData()->getRawDataVector(); - auto UnitsLabel = assistant.getData().unitsLabel(); - auto AxisLabel0 = assistant.getData().axisLabel(0); - auto AxisLabel1 = assistant.getData().axisLabel(1); - - const std::vector<double> expected = {4.0, 8.0, 12.0}; - - EXPECT_EQ(DataRank, 1u); - EXPECT_EQ(AllocSize, 3u); - EXPECT_EQ(RawDataVec, expected); - EXPECT_EQ(UnitsLabel, JobItemUtils::nameFromAxesUnits(Axes::Units::DEGREES)); - EXPECT_EQ(AxisLabel0, QString::fromStdString(AxisNames::specAxis.at(Axes::Units::DEGREES))); - EXPECT_EQ(AxisLabel1, SpecularDataAxesNames::y_axis_default_name); -}