diff --git a/.gitignore b/.gitignore index 1e78a1f3c6ae6ac752d1d031ca6db8b3d9a4634e..0c7d91a11b3e911b8aa0ab96afca66c197ded486 100644 --- a/.gitignore +++ b/.gitignore @@ -167,6 +167,8 @@ Desktop.ini .tags .tags_sorted_by_file +#Dynamically created files +Framework/Kernel/inc/MantidKernel/GitHubApiHelper.h Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/LibHelper.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 1a55c27ade90043fe266cc813771f27e0b79745b..a09673e2de73d652add4877cf3668a61d8fd4c0e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,21 +1,8 @@ ########################################################################### # CMake version check. -# Require >= 3.3 for Windows as previous versions contained a bug that -# prevented external data from working correctly. Other systems require -# 2.8.12 to avoid recompiling system packages +# Require CMake 3.5, required by ParaView 5.1.0 ########################################################################### -if (CMAKE_HOST_WIN32) - cmake_minimum_required ( VERSION 3.3.0 ) -else() - cmake_minimum_required ( VERSION 2.8.12 ) -endif() - -if(POLICY CMP0053) - #Simplify variable reference and escape sequence evaluation. - #Claims to dramatically improve CMake configure and generate time - #requires CMake 3.1 or later - cmake_policy(SET CMP0053 NEW) -endif() +cmake_minimum_required ( VERSION 3.5 ) # Define the project name. project ( Mantid ) @@ -306,9 +293,9 @@ if ( ENABLE_CPACK ) "libpocofoundation11,libpocoutil11,libpoconet11,libpoconetssl11,libpococrypto11,libpocoxml11," "python-pycifrw (>= 4.2.1)" ) set ( PERFTOOLS_DEB_PACKAGE "libgoogle-perftools4 (>= 1.7)" ) - if( "${UNIX_CODENAME}" STREQUAL "wily" OR "${UNIX_CODENAME}" STREQUAL "xenial") - list ( APPEND DEPENDS_LIST ", libnexus0v5 (>= 4.3),libjsoncpp0v5 (>= 0.7.0),libqscintilla2-12v5, libmuparser2v5,libqwtplot3d-qt4-0v5") - list (REMOVE_ITEM DEPENDS_LIST "libjsoncpp0 (>=0.7.0)," "libqscintilla2-11," "libmuparser2," "libnexus0 (>= 4.3)," "libqwtplot3d-qt4-0,") + if( "${UNIX_CODENAME}" STREQUAL "xenial") + list ( APPEND DEPENDS_LIST ", libnexus0v5 (>= 4.3),libjsoncpp1,libqscintilla2-12v5, libmuparser2v5,libqwtplot3d-qt4-0v5,libgsl2,liboce-foundation10,liboce-modeling10") + list (REMOVE_ITEM DEPENDS_LIST "libjsoncpp0 (>=0.7.0)," "libqscintilla2-11," "libmuparser2," "libnexus0 (>= 4.3)," "libqwtplot3d-qt4-0," "libgsl0ldbl," "liboce-foundation8,liboce-modeling8,") endif() # parse list to string required for deb package string ( REPLACE ";" "" CPACK_DEBIAN_PACKAGE_DEPENDS ${DEPENDS_LIST} ) diff --git a/Framework/API/inc/MantidAPI/AlgorithmFactory.h b/Framework/API/inc/MantidAPI/AlgorithmFactory.h index a9d7bb805be8bdfb2fdeea1352aaa408e5d67e24..c0e1afdd9d16d8c078ab1c10c090ca5417c2d5bb 100644 --- a/Framework/API/inc/MantidAPI/AlgorithmFactory.h +++ b/Framework/API/inc/MantidAPI/AlgorithmFactory.h @@ -168,16 +168,7 @@ private: VersionMap m_vmap; }; -/// Forward declaration of a specialisation of SingletonHolder for -/// AlgorithmFactoryImpl (needed for dllexport/dllimport) and a typedef for it. -#ifdef _WIN32 -// this breaks new namespace declaraion rules; need to find a better fix -template class MANTID_API_DLL - Mantid::Kernel::SingletonHolder<AlgorithmFactoryImpl>; -#endif /* _WIN32 */ - -typedef MANTID_API_DLL Mantid::Kernel::SingletonHolder<AlgorithmFactoryImpl> - AlgorithmFactory; +typedef Mantid::Kernel::SingletonHolder<AlgorithmFactoryImpl> AlgorithmFactory; /// Convenient typedef for an UpdateNotification typedef Mantid::Kernel::DynamicFactory<Algorithm>::UpdateNotification @@ -188,4 +179,11 @@ typedef const Poco::AutoPtr<Mantid::Kernel::DynamicFactory< } // namespace API } // namespace Mantid +namespace Mantid { +namespace Kernel { +EXTERN_MANTID_API template class MANTID_API_DLL + Mantid::Kernel::SingletonHolder<Mantid::API::AlgorithmFactoryImpl>; +} +} + #endif /*MANTID_API_ALGORITHMFACTORY_H_*/ diff --git a/Framework/API/inc/MantidAPI/AlgorithmManager.h b/Framework/API/inc/MantidAPI/AlgorithmManager.h index abb76dfe13c11a2e71a659d0cbf534111d47c0ae..cc777057963bfc3a4aefe26fa213f946b3bc5997 100644 --- a/Framework/API/inc/MantidAPI/AlgorithmManager.h +++ b/Framework/API/inc/MantidAPI/AlgorithmManager.h @@ -102,16 +102,16 @@ private: mutable std::mutex m_managedMutex; }; -/// Forward declaration of a specialisation of SingletonHolder for -/// AlgorithmManagerImpl (needed for dllexport/dllimport) and a typedef for it. -#ifdef _WIN32 -// this breaks new namespace declaraion rules; need to find a better fix -template class MANTID_API_DLL - Mantid::Kernel::SingletonHolder<AlgorithmManagerImpl>; -#endif /* _WIN32 */ typedef Mantid::Kernel::SingletonHolder<AlgorithmManagerImpl> AlgorithmManager; } // namespace API } // Namespace Mantid +namespace Mantid { +namespace Kernel { +EXTERN_MANTID_API template class MANTID_API_DLL + Mantid::Kernel::SingletonHolder<Mantid::API::AlgorithmManagerImpl>; +} +} + #endif /* MANTID_API_ALGORITHMMANAGER_H_ */ diff --git a/Framework/API/inc/MantidAPI/AnalysisDataService.h b/Framework/API/inc/MantidAPI/AnalysisDataService.h index b99dfb0f5dd135756d256f8bcffb0c1f4035216d..d46cd86ba7f8521020432c596d9594e5a98496c0 100644 --- a/Framework/API/inc/MantidAPI/AnalysisDataService.h +++ b/Framework/API/inc/MantidAPI/AnalysisDataService.h @@ -178,15 +178,7 @@ private: std::string m_illegalChars; }; -/// Forward declaration of a specialisation of SingletonHolder for -/// AnalysisDataServiceImpl (needed for dllexport/dllimport) and a typedef for -/// it. -#ifdef _WIN32 -// this breaks new namespace declaration rules; need to find a better fix -template class MANTID_API_DLL - Mantid::Kernel::SingletonHolder<AnalysisDataServiceImpl>; -#endif /* _WIN32 */ -typedef MANTID_API_DLL Mantid::Kernel::SingletonHolder<AnalysisDataServiceImpl> +typedef Mantid::Kernel::SingletonHolder<AnalysisDataServiceImpl> AnalysisDataService; typedef Mantid::Kernel::DataService<Mantid::API::Workspace>::AddNotification @@ -249,4 +241,11 @@ typedef const Poco::AutoPtr<AnalysisDataServiceImpl::GroupUpdatedNotification> & } // Namespace API } // Namespace Mantid +namespace Mantid { +namespace Kernel { +EXTERN_MANTID_API template class MANTID_API_DLL + Mantid::Kernel::SingletonHolder<Mantid::API::AnalysisDataServiceImpl>; +} +} + #endif /*MANTID_KERNEL_ANALYSISDATASERVICE_H_*/ diff --git a/Framework/API/inc/MantidAPI/ArchiveSearchFactory.h b/Framework/API/inc/MantidAPI/ArchiveSearchFactory.h index 78a4d211d36a27307ad223922c6bed82dc6ccd54..a08b918d1fd23651341c27c703665444fc950a73 100644 --- a/Framework/API/inc/MantidAPI/ArchiveSearchFactory.h +++ b/Framework/API/inc/MantidAPI/ArchiveSearchFactory.h @@ -56,17 +56,16 @@ private: ~ArchiveSearchFactoryImpl() override = default; }; -/// Forward declaration of a specialisation of SingletonHolder for -/// AlgorithmFactoryImpl (needed for dllexport/dllimport) and a typedef for it. -#ifdef _WIN32 -// this breaks new namespace declaraion rules; need to find a better fix -template class MANTID_API_DLL - Mantid::Kernel::SingletonHolder<ArchiveSearchFactoryImpl>; -#endif /* _WIN32 */ - -typedef MANTID_API_DLL Mantid::Kernel::SingletonHolder<ArchiveSearchFactoryImpl> +typedef Mantid::Kernel::SingletonHolder<ArchiveSearchFactoryImpl> ArchiveSearchFactory; } } +namespace Mantid { +namespace Kernel { +EXTERN_MANTID_API template class MANTID_API_DLL + Mantid::Kernel::SingletonHolder<Mantid::API::ArchiveSearchFactoryImpl>; +} +} + #endif // MANTID_API_ARCHIVESEARCHFACTORY_H_ diff --git a/Framework/API/inc/MantidAPI/CatalogFactory.h b/Framework/API/inc/MantidAPI/CatalogFactory.h index 391bcf6753f3db35e0e2de3166e9c2798277b696..b6133d3315da6d90d751b8945c3a9e603c90a989 100644 --- a/Framework/API/inc/MantidAPI/CatalogFactory.h +++ b/Framework/API/inc/MantidAPI/CatalogFactory.h @@ -76,19 +76,18 @@ private: mutable std::map<std::string, boost::shared_ptr<ICatalog>> m_createdCatalogs; }; -/// Forward declaration of a specialisation of SingletonHolder for -/// CatalogFactoryImpl (needed for dllexport/dllimport) . -#ifdef _WIN32 -// this breaks new namespace declaraion rules; need to find a better fix -template class MANTID_API_DLL - Mantid::Kernel::SingletonHolder<CatalogFactoryImpl>; -#endif /* _WIN32 */ /// The specialisation of the SingletonHolder class that holds the /// CatalogFactory -typedef MANTID_API_DLL Mantid::Kernel::SingletonHolder<CatalogFactoryImpl> - CatalogFactory; +typedef Mantid::Kernel::SingletonHolder<CatalogFactoryImpl> CatalogFactory; } // namespace API } // namespace Mantid +namespace Mantid { +namespace Kernel { +EXTERN_MANTID_API template class MANTID_API_DLL + Mantid::Kernel::SingletonHolder<Mantid::API::CatalogFactoryImpl>; +} +} + #endif /*MANTID_API_CATALOGFACTORYIMPL_H_*/ diff --git a/Framework/API/inc/MantidAPI/CatalogManager.h b/Framework/API/inc/MantidAPI/CatalogManager.h index 7b8cf565a7b0827eaa4f863ed7481cce604d91e5..d7bc46ddcffeefbd6927bda3bbf474e4265cecf0 100644 --- a/Framework/API/inc/MantidAPI/CatalogManager.h +++ b/Framework/API/inc/MantidAPI/CatalogManager.h @@ -67,11 +67,14 @@ private: std::map<CatalogSession_sptr, ICatalog_sptr> m_activeCatalogs; }; -#ifdef _WIN32 -template class MANTID_API_DLL Kernel::SingletonHolder<CatalogManagerImpl>; -#endif -typedef MANTID_API_DLL Kernel::SingletonHolder<CatalogManagerImpl> - CatalogManager; +typedef Kernel::SingletonHolder<CatalogManagerImpl> CatalogManager; +} +} + +namespace Mantid { +namespace Kernel { +EXTERN_MANTID_API template class MANTID_API_DLL + Kernel::SingletonHolder<Mantid::API::CatalogManagerImpl>; } } #endif /* MANTID_ICAT_CATALOGMANAGERIMPL_H_ */ diff --git a/Framework/API/inc/MantidAPI/ColumnFactory.h b/Framework/API/inc/MantidAPI/ColumnFactory.h index 2d85aa0759298b3fd0d1b35325f6b15efc31b2af..df6a3d92e9815754d3eb65eb913c70c4bfe9988e 100644 --- a/Framework/API/inc/MantidAPI/ColumnFactory.h +++ b/Framework/API/inc/MantidAPI/ColumnFactory.h @@ -63,17 +63,16 @@ private: ~ColumnFactoryImpl() override = default; }; -/// Forward declaration of a specialisation of SingletonHolder for -/// AlgorithmFactoryImpl (needed for dllexport/dllimport) and a typedef for it. -#ifdef _WIN32 -// this breaks new namespace declaraion rules; need to find a better fix -template class MANTID_API_DLL - Mantid::Kernel::SingletonHolder<ColumnFactoryImpl>; -#endif /* _WIN32 */ -typedef MANTID_API_DLL Mantid::Kernel::SingletonHolder<ColumnFactoryImpl> - ColumnFactory; +typedef Mantid::Kernel::SingletonHolder<ColumnFactoryImpl> ColumnFactory; } // namespace API } // namespace Mantid +namespace Mantid { +namespace Kernel { +EXTERN_MANTID_API template class MANTID_API_DLL + Mantid::Kernel::SingletonHolder<Mantid::API::ColumnFactoryImpl>; +} +} + #endif /*MANTID_API_COLUMNFACTORY_H_*/ diff --git a/Framework/API/inc/MantidAPI/ConstraintFactory.h b/Framework/API/inc/MantidAPI/ConstraintFactory.h index aa39886f7937faf8ac3b698e92cbac6494af1834..560770e3bc4f3ebb6076e64a18ca526a59251d18 100644 --- a/Framework/API/inc/MantidAPI/ConstraintFactory.h +++ b/Framework/API/inc/MantidAPI/ConstraintFactory.h @@ -72,19 +72,19 @@ private: ~ConstraintFactoryImpl() override = default; }; -/// Forward declaration of a specialisation of SingletonHolder for -/// AlgorithmFactoryImpl (needed for dllexport/dllimport) and a typedef for it. -#ifdef _WIN32 -// this breaks new namespace declaraion rules; need to find a better fix -template class MANTID_API_DLL - Mantid::Kernel::SingletonHolder<ConstraintFactoryImpl>; -#endif /* _WIN32 */ -typedef MANTID_API_DLL Mantid::Kernel::SingletonHolder<ConstraintFactoryImpl> +typedef Mantid::Kernel::SingletonHolder<ConstraintFactoryImpl> ConstraintFactory; } // namespace API } // namespace Mantid +namespace Mantid { +namespace Kernel { +EXTERN_MANTID_API template class MANTID_API_DLL + Mantid::Kernel::SingletonHolder<Mantid::API::ConstraintFactoryImpl>; +} +} + /** * Macro for declaring a new type of function to be used with the * FunctionFactory diff --git a/Framework/API/inc/MantidAPI/CostFunctionFactory.h b/Framework/API/inc/MantidAPI/CostFunctionFactory.h index c6675f363ff3e0ec93508c499bb8dc162730a6a7..26d5b33867beff0ae7a09d168fe54bf604bf2699 100644 --- a/Framework/API/inc/MantidAPI/CostFunctionFactory.h +++ b/Framework/API/inc/MantidAPI/CostFunctionFactory.h @@ -63,17 +63,17 @@ private: CostFunctionFactoryImpl(); }; -/// Forward declaration of a specialisation of SingletonHolder for -/// AlgorithmFactoryImpl (needed for dllexport/dllimport) and a typedef for it. -#ifdef _WIN32 -// this breaks new namespace declaraion rules; need to find a better fix -template class MANTID_API_DLL - Mantid::Kernel::SingletonHolder<CostFunctionFactoryImpl>; -#endif /* _WIN32 */ -typedef MANTID_API_DLL Mantid::Kernel::SingletonHolder<CostFunctionFactoryImpl> +typedef Mantid::Kernel::SingletonHolder<CostFunctionFactoryImpl> CostFunctionFactory; } // namespace API } // namespace Mantid +namespace Mantid { +namespace Kernel { +EXTERN_MANTID_API template class MANTID_API_DLL + Mantid::Kernel::SingletonHolder<Mantid::API::CostFunctionFactoryImpl>; +} +} + #endif /*MANTID_API_COSTFUNCTIONFACTORY_H_*/ diff --git a/Framework/API/inc/MantidAPI/DllConfig.h b/Framework/API/inc/MantidAPI/DllConfig.h index ff00439cca87c79e51166aca4a6e0e0eeeea87ef..28be254b9c811af4f432ef66e488b9f055271104 100644 --- a/Framework/API/inc/MantidAPI/DllConfig.h +++ b/Framework/API/inc/MantidAPI/DllConfig.h @@ -32,8 +32,10 @@ #ifdef IN_MANTID_API #define MANTID_API_DLL DLLExport +#define EXTERN_MANTID_API #else #define MANTID_API_DLL DLLImport +#define EXTERN_MANTID_API EXTERN_IMPORT #endif /* IN_MANTID_API*/ #endif // MANTID_API_DLLCONFIG_H_ diff --git a/Framework/API/inc/MantidAPI/DomainCreatorFactory.h b/Framework/API/inc/MantidAPI/DomainCreatorFactory.h index d88d4212241357149a9c0f4fd1416d3bc6197a53..9aace3d1ea1820d254450e6e0d2c9ece7dca261a 100644 --- a/Framework/API/inc/MantidAPI/DomainCreatorFactory.h +++ b/Framework/API/inc/MantidAPI/DomainCreatorFactory.h @@ -68,18 +68,17 @@ private: using Kernel::DynamicFactory<IDomainCreator>::createUnwrapped; }; -/// Forward declaration of a specialisation of SingletonHolder for -/// DomainCreatorFactoryImpl (needed for dllexport/dllimport) and a typedef for -/// it. -#ifdef _WIN32 -// this breaks new namespace declaraion rules; need to find a better fix -template class MANTID_API_DLL - Mantid::Kernel::SingletonHolder<DomainCreatorFactoryImpl>; -#endif /* _WIN32 */ -typedef MANTID_API_DLL Mantid::Kernel::SingletonHolder<DomainCreatorFactoryImpl> +typedef Mantid::Kernel::SingletonHolder<DomainCreatorFactoryImpl> DomainCreatorFactory; } // namespace API } // namespace Mantid +namespace Mantid { +namespace Kernel { +EXTERN_MANTID_API template class MANTID_API_DLL + Mantid::Kernel::SingletonHolder<Mantid::API::DomainCreatorFactoryImpl>; +} +} + #endif /* MANTID_API_DOMAINCREATORFACTORY_H_ */ diff --git a/Framework/API/inc/MantidAPI/FileFinder.h b/Framework/API/inc/MantidAPI/FileFinder.h index 7c52f42ca2b71cf1e94a048e5248759ee98eb16b..ffd119eda4326e6eb14c92dff37be914ce9a2bbf 100644 --- a/Framework/API/inc/MantidAPI/FileFinder.h +++ b/Framework/API/inc/MantidAPI/FileFinder.h @@ -94,15 +94,14 @@ private: int m_globOption; }; -/// Forward declaration of a specialisation of SingletonHolder for -/// AlgorithmFactoryImpl (needed for dllexport/dllimport) and a typedef for it. -#ifdef _WIN32 -// this breaks new namespace declaraion rules; need to find a better fix -template class MANTID_API_DLL Mantid::Kernel::SingletonHolder<FileFinderImpl>; -#endif /* _WIN32 */ - -typedef MANTID_API_DLL Mantid::Kernel::SingletonHolder<FileFinderImpl> - FileFinder; +typedef Mantid::Kernel::SingletonHolder<FileFinderImpl> FileFinder; +} +} + +namespace Mantid { +namespace Kernel { +EXTERN_MANTID_API template class MANTID_API_DLL + Mantid::Kernel::SingletonHolder<Mantid::API::FileFinderImpl>; } } diff --git a/Framework/API/inc/MantidAPI/FileLoaderRegistry.h b/Framework/API/inc/MantidAPI/FileLoaderRegistry.h index 02fd7a228b4cdef90a9ad293537fec99db5d1701..c53d1efb878f78e4820a02aed53bbe6f113d8aba 100644 --- a/Framework/API/inc/MantidAPI/FileLoaderRegistry.h +++ b/Framework/API/inc/MantidAPI/FileLoaderRegistry.h @@ -144,20 +144,18 @@ private: mutable Kernel::Logger m_log; }; -/// Forward declaration of a specialisation of SingletonHolder for -/// FileLoaderRegistryImpl (needed for dllexport/dllimport) and a typedef for -/// it. -#ifdef _WIN32 -// this breaks new namespace declaration rules; need to find a better fix -template class MANTID_API_DLL - Mantid::Kernel::SingletonHolder<FileLoaderRegistryImpl>; -#endif /* _WIN32 */ - /// Type for the actual singleton instance -typedef MANTID_API_DLL Mantid::Kernel::SingletonHolder<FileLoaderRegistryImpl> +typedef Mantid::Kernel::SingletonHolder<FileLoaderRegistryImpl> FileLoaderRegistry; } // namespace API } // namespace Mantid +namespace Mantid { +namespace Kernel { +EXTERN_MANTID_API template class MANTID_API_DLL + Mantid::Kernel::SingletonHolder<Mantid::API::FileLoaderRegistryImpl>; +} +} + #endif /* MANTID_API_FILELOADERREGISTRY_H_ */ diff --git a/Framework/API/inc/MantidAPI/FrameworkManager.h b/Framework/API/inc/MantidAPI/FrameworkManager.h index e62304b667e4977b5da8d6d0885574147b85645e..583f5aec33ad97b5c3a1eff7b56f894b0ffbf28b 100644 --- a/Framework/API/inc/MantidAPI/FrameworkManager.h +++ b/Framework/API/inc/MantidAPI/FrameworkManager.h @@ -137,17 +137,16 @@ private: #endif }; -/// Forward declaration of a specialisation of SingletonHolder for -/// AlgorithmFactoryImpl (needed for dllexport/dllimport) and a typedef for it. -#ifdef _WIN32 -// this breaks new namespace declaration rules; need to find a better fix -template class MANTID_API_DLL - Mantid::Kernel::SingletonHolder<FrameworkManagerImpl>; -#endif /* _WIN32 */ -typedef MANTID_API_DLL Mantid::Kernel::SingletonHolder<FrameworkManagerImpl> - FrameworkManager; +typedef Mantid::Kernel::SingletonHolder<FrameworkManagerImpl> FrameworkManager; } // namespace Kernel } // namespace Mantid +namespace Mantid { +namespace Kernel { +EXTERN_MANTID_API template class MANTID_API_DLL + Mantid::Kernel::SingletonHolder<Mantid::API::FrameworkManagerImpl>; +} +} + #endif /*MANTID_API_FRAMEWORKMANAGER_H_*/ diff --git a/Framework/API/inc/MantidAPI/FuncMinimizerFactory.h b/Framework/API/inc/MantidAPI/FuncMinimizerFactory.h index e8864ac53d08137b19175c0e8ca8186ee1725b2f..7944b5e2f915c9ae3bc403f6f7f6893fc4a1fe83 100644 --- a/Framework/API/inc/MantidAPI/FuncMinimizerFactory.h +++ b/Framework/API/inc/MantidAPI/FuncMinimizerFactory.h @@ -61,19 +61,19 @@ private: FuncMinimizerFactoryImpl(); }; -/// Forward declaration of a specialisation of SingletonHolder for -/// AlgorithmFactoryImpl (needed for dllexport/dllimport) and a typedef for it. -#ifdef _WIN32 -// this breaks new namespace declaraion rules; need to find a better fix -template class MANTID_API_DLL - Mantid::Kernel::SingletonHolder<FuncMinimizerFactoryImpl>; -#endif /* _WIN32 */ -typedef MANTID_API_DLL Mantid::Kernel::SingletonHolder<FuncMinimizerFactoryImpl> +typedef Mantid::Kernel::SingletonHolder<FuncMinimizerFactoryImpl> FuncMinimizerFactory; } // namespace API } // namespace Mantid +namespace Mantid { +namespace Kernel { +EXTERN_MANTID_API template class MANTID_API_DLL + Mantid::Kernel::SingletonHolder<Mantid::API::FuncMinimizerFactoryImpl>; +} +} + /** * Macro for declaring a new type of minimizers to be used with the * FuncMinimizerFactory diff --git a/Framework/API/inc/MantidAPI/FunctionFactory.h b/Framework/API/inc/MantidAPI/FunctionFactory.h index 76a21ecdf0c5dc766f410baab8542f8a9caa8bfd..36962ff28982c4314a0c205ddad372e288284dde 100644 --- a/Framework/API/inc/MantidAPI/FunctionFactory.h +++ b/Framework/API/inc/MantidAPI/FunctionFactory.h @@ -142,15 +142,7 @@ const std::vector<std::string> &FunctionFactoryImpl::getFunctionNames() const { return typeNames; } -/// Forward declaration of a specialisation of SingletonHolder for -/// AlgorithmFactoryImpl (needed for dllexport/dllimport) and a typedef for it. -#ifdef _WIN32 -// this breaks new namespace declaraion rules; need to find a better fix -template class MANTID_API_DLL - Mantid::Kernel::SingletonHolder<FunctionFactoryImpl>; -#endif /* _WIN32 */ -typedef MANTID_API_DLL Mantid::Kernel::SingletonHolder<FunctionFactoryImpl> - FunctionFactory; +typedef Mantid::Kernel::SingletonHolder<FunctionFactoryImpl> FunctionFactory; /// Convenient typedef for an UpdateNotification typedef FunctionFactoryImpl::UpdateNotification @@ -161,6 +153,13 @@ typedef const Poco::AutoPtr<FunctionFactoryUpdateNotification> & } // namespace API } // namespace Mantid +namespace Mantid { +namespace Kernel { +EXTERN_MANTID_API template class MANTID_API_DLL + Mantid::Kernel::SingletonHolder<Mantid::API::FunctionFactoryImpl>; +} +} + /** * Macro for declaring a new type of function to be used with the * FunctionFactory diff --git a/Framework/API/inc/MantidAPI/ImplicitFunctionFactory.h b/Framework/API/inc/MantidAPI/ImplicitFunctionFactory.h index c0083dc3a6194c20d4fa8d6320391b9f65490a6d..10b8c9f04b4eb515313e6a0ca0b03df4e1c2318d 100644 --- a/Framework/API/inc/MantidAPI/ImplicitFunctionFactory.h +++ b/Framework/API/inc/MantidAPI/ImplicitFunctionFactory.h @@ -64,17 +64,15 @@ private: ~ImplicitFunctionFactoryImpl() override = default; }; -/// Forward declaration of a specialisation of SingletonHolder for -/// ImplicitFunctionFactoryImpl (needed for dllexport/dllimport) and a typedef -/// for it. -#ifdef _WIN32 -// this breaks new namespace declaraion rules; need to find a better fix -template class MANTID_API_DLL - Mantid::Kernel::SingletonHolder<ImplicitFunctionFactoryImpl>; -#endif /* _WIN32 */ - -typedef MANTID_API_DLL Mantid::Kernel::SingletonHolder< - ImplicitFunctionFactoryImpl> ImplicitFunctionFactory; +typedef Mantid::Kernel::SingletonHolder<ImplicitFunctionFactoryImpl> + ImplicitFunctionFactory; +} +} + +namespace Mantid { +namespace Kernel { +EXTERN_MANTID_API template class MANTID_API_DLL + Mantid::Kernel::SingletonHolder<Mantid::API::ImplicitFunctionFactoryImpl>; } } diff --git a/Framework/API/inc/MantidAPI/ImplicitFunctionParameterParserFactory.h b/Framework/API/inc/MantidAPI/ImplicitFunctionParameterParserFactory.h index f7722e5d9f26e890e5e052209443462c51175518..98578f7383c4f556d821c2e5c82922993fe392f2 100644 --- a/Framework/API/inc/MantidAPI/ImplicitFunctionParameterParserFactory.h +++ b/Framework/API/inc/MantidAPI/ImplicitFunctionParameterParserFactory.h @@ -62,18 +62,16 @@ private: ~ImplicitFunctionParameterParserFactoryImpl() override = default; }; -/// Forward declaration of a specialisation of SingletonHolder for -/// ImplicitFunctionFactoryImpl (needed for dllexport/dllimport) and a typedef -/// for it. -#ifdef _WIN32 -// this breaks new namespace declaraion rules; need to find a better fix -template class MANTID_API_DLL - Mantid::Kernel::SingletonHolder<ImplicitFunctionParameterParserFactoryImpl>; -#endif /* _WIN32 */ - -typedef MANTID_API_DLL - Mantid::Kernel::SingletonHolder<ImplicitFunctionParameterParserFactoryImpl> - ImplicitFunctionParameterParserFactory; +typedef Mantid::Kernel::SingletonHolder< + ImplicitFunctionParameterParserFactoryImpl> + ImplicitFunctionParameterParserFactory; +} +} + +namespace Mantid { +namespace Kernel { +EXTERN_MANTID_API template class MANTID_API_DLL Mantid::Kernel::SingletonHolder< + Mantid::API::ImplicitFunctionParameterParserFactoryImpl>; } } diff --git a/Framework/API/inc/MantidAPI/ImplicitFunctionParserFactory.h b/Framework/API/inc/MantidAPI/ImplicitFunctionParserFactory.h index 703dafa5b12f45384648c96878faede20919f465..0c6b2e00f18791a05aa0a4b5f4685beb39060825 100644 --- a/Framework/API/inc/MantidAPI/ImplicitFunctionParserFactory.h +++ b/Framework/API/inc/MantidAPI/ImplicitFunctionParserFactory.h @@ -66,17 +66,15 @@ private: ~ImplicitFunctionParserFactoryImpl() override = default; }; -/// Forward declaration of a specialisation of SingletonHolder for -/// ImplicitFunctionFactoryImpl (needed for dllexport/dllimport) and a typedef -/// for it. -#ifdef _WIN32 -// this breaks new namespace declaraion rules; need to find a better fix -template class MANTID_API_DLL - Mantid::Kernel::SingletonHolder<ImplicitFunctionParserFactoryImpl>; -#endif /* _WIN32 */ - -typedef MANTID_API_DLL Mantid::Kernel::SingletonHolder< - ImplicitFunctionParserFactoryImpl> ImplicitFunctionParserFactory; +typedef Mantid::Kernel::SingletonHolder<ImplicitFunctionParserFactoryImpl> + ImplicitFunctionParserFactory; +} +} + +namespace Mantid { +namespace Kernel { +EXTERN_MANTID_API template class MANTID_API_DLL Mantid::Kernel::SingletonHolder< + Mantid::API::ImplicitFunctionParserFactoryImpl>; } } diff --git a/Framework/API/inc/MantidAPI/InstrumentDataService.h b/Framework/API/inc/MantidAPI/InstrumentDataService.h index c4d5a2d4cf4bcd7b76da2decbc8c3a7e814664e2..3ff486fb1cecc7484085b00fb9fd8522c14496bd 100644 --- a/Framework/API/inc/MantidAPI/InstrumentDataService.h +++ b/Framework/API/inc/MantidAPI/InstrumentDataService.h @@ -48,17 +48,17 @@ private: operator=(const InstrumentDataServiceImpl &) = delete; }; -/// Forward declaration of a specialisation of SingletonHolder for -/// AnalysisDataServiceImpl (needed for dllexport/dllimport) and a typedef for -/// it. -#ifdef _WIN32 -// this breaks new namespace declaraion rules; need to find a better fix -template class MANTID_API_DLL - Mantid::Kernel::SingletonHolder<InstrumentDataServiceImpl>; -#endif /* _WIN32 */ -typedef MANTID_API_DLL Mantid::Kernel::SingletonHolder< - InstrumentDataServiceImpl> InstrumentDataService; +typedef Mantid::Kernel::SingletonHolder<InstrumentDataServiceImpl> + InstrumentDataService; } // Namespace API } // Namespace Mantid + +namespace Mantid { +namespace Kernel { +EXTERN_MANTID_API template class MANTID_API_DLL + Mantid::Kernel::SingletonHolder<Mantid::API::InstrumentDataServiceImpl>; +} +} + #endif /*INSTRUMENTDATASERVICE_*/ diff --git a/Framework/API/inc/MantidAPI/LiveListenerFactory.h b/Framework/API/inc/MantidAPI/LiveListenerFactory.h index d48e45071bfcf451a7679a981f9eee94b6218ac5..585c40015e3bcc0d703aa25dca64fca477cd01bf 100644 --- a/Framework/API/inc/MantidAPI/LiveListenerFactory.h +++ b/Framework/API/inc/MantidAPI/LiveListenerFactory.h @@ -73,17 +73,16 @@ private: ILiveListener *createUnwrapped(const std::string &className) const override; }; -/// Forward declaration of a specialisation of SingletonHolder (needed for -/// dllexport/dllimport). -#ifdef _WIN32 -// this breaks new namespace declaration rules; need to find a better fix -template class MANTID_API_DLL Kernel::SingletonHolder<LiveListenerFactoryImpl>; -#endif /* _WIN32 */ -/// The specialisation of the SingletonHolder class that holds the -/// LiveListenerFactory typedef Kernel::SingletonHolder<LiveListenerFactoryImpl> LiveListenerFactory; } // namespace API } // namespace Mantid +namespace Mantid { +namespace Kernel { +EXTERN_MANTID_API template class MANTID_API_DLL + Kernel::SingletonHolder<Mantid::API::LiveListenerFactoryImpl>; +} +} + #endif /* MANTID_API_LIVELISTENERFACTORYIMPL_H_ */ diff --git a/Framework/API/inc/MantidAPI/RemoteJobManagerFactory.h b/Framework/API/inc/MantidAPI/RemoteJobManagerFactory.h index 814981add0505aa6a3115e8090a960a042cfe54d..8fb819cd541c8f6c73d71136f15eb1b97910405c 100644 --- a/Framework/API/inc/MantidAPI/RemoteJobManagerFactory.h +++ b/Framework/API/inc/MantidAPI/RemoteJobManagerFactory.h @@ -86,21 +86,20 @@ private: using Kernel::DynamicFactory<IRemoteJobManager>::create; }; -/// Forward declaration of a specialisation of SingletonHolder for -/// RemoteJobManagerFactoryImpl (needed for dllexport) and a typedef for it. -#ifdef _WIN32 -// this breaks new namespace declaraion rules; need to find a better fix -template class MANTID_API_DLL - Mantid::Kernel::SingletonHolder<RemoteJobManagerFactoryImpl>; -#endif /* _WIN32 */ - // The factory is just a specialisation of SingletonHolder -typedef MANTID_API_DLL Mantid::Kernel::SingletonHolder< - RemoteJobManagerFactoryImpl> RemoteJobManagerFactory; +typedef Mantid::Kernel::SingletonHolder<RemoteJobManagerFactoryImpl> + RemoteJobManagerFactory; } // namespace API } // namespace Mantid +namespace Mantid { +namespace Kernel { +EXTERN_MANTID_API template class MANTID_API_DLL + Mantid::Kernel::SingletonHolder<Mantid::API::RemoteJobManagerFactoryImpl>; +} +} + /* Macro to register (remote job manager) classes into the factory. As * with the equivalent macros of the workspace factory or the * algorithm factory, this creates a global object in an anonymous diff --git a/Framework/API/inc/MantidAPI/ScriptRepositoryFactory.h b/Framework/API/inc/MantidAPI/ScriptRepositoryFactory.h index 61886bebd0d30b289042794c6f1478231c745017..f5bad9732e7069cbea92017de01573c7e2e31be6 100644 --- a/Framework/API/inc/MantidAPI/ScriptRepositoryFactory.h +++ b/Framework/API/inc/MantidAPI/ScriptRepositoryFactory.h @@ -67,19 +67,19 @@ private: ~ScriptRepositoryFactoryImpl() override = default; }; -/// Forward declaration of a specialisation of SingletonHolder for -/// AlgorithmFactoryImpl (needed for dllexport/dllimport) and a typedef for it. -#ifdef _WIN32 -// this breaks new namespace declaraion rules; need to find a better fix -template class MANTID_API_DLL - Mantid::Kernel::SingletonHolder<ScriptRepositoryFactoryImpl>; -#endif /* _WIN32 */ -typedef MANTID_API_DLL Mantid::Kernel::SingletonHolder< - ScriptRepositoryFactoryImpl> ScriptRepositoryFactory; +typedef Mantid::Kernel::SingletonHolder<ScriptRepositoryFactoryImpl> + ScriptRepositoryFactory; } // namespace API } // namespace Mantid +namespace Mantid { +namespace Kernel { +EXTERN_MANTID_API template class MANTID_API_DLL + Mantid::Kernel::SingletonHolder<Mantid::API::ScriptRepositoryFactoryImpl>; +} +} + /** * Macro for declaring a new type of function to be used with the * FunctionFactory diff --git a/Framework/API/inc/MantidAPI/TransformScaleFactory.h b/Framework/API/inc/MantidAPI/TransformScaleFactory.h index e2101893d4c3f0580a41be78dfd6592a97aa2d31..8d58b0832101d2d9bb628bfb2679f1f0b1e5d72c 100644 --- a/Framework/API/inc/MantidAPI/TransformScaleFactory.h +++ b/Framework/API/inc/MantidAPI/TransformScaleFactory.h @@ -67,18 +67,17 @@ private: // Do not use default methods }; -/// Forward declaration of a specialisation of SingletonHolder for -/// TransformScaleFactoryImpl (needed for dllexport/dllimport) and a typedef for -/// it. -#ifdef _WIN32 -// this breaks new namespace declaraion rules; need to find a better fix -template class MANTID_API_DLL - Mantid::Kernel::SingletonHolder<TransformScaleFactoryImpl>; -#endif /* _WIN32 */ -typedef MANTID_API_DLL Mantid::Kernel::SingletonHolder< - TransformScaleFactoryImpl> TransformScaleFactory; +typedef Mantid::Kernel::SingletonHolder<TransformScaleFactoryImpl> + TransformScaleFactory; } // namespace API } // namespace Mantid +namespace Mantid { +namespace Kernel { +EXTERN_MANTID_API template class MANTID_API_DLL + Mantid::Kernel::SingletonHolder<Mantid::API::TransformScaleFactoryImpl>; +} +} + #endif /* MANTID_API_TRANSFORMSCALEFACTORY_H_ */ diff --git a/Framework/API/inc/MantidAPI/WorkspaceFactory.h b/Framework/API/inc/MantidAPI/WorkspaceFactory.h index b6070b6f7c514bc5b943b8c5535bee5fa60e76b3..72c840e567f27634e773b241f94afa6787092081 100644 --- a/Framework/API/inc/MantidAPI/WorkspaceFactory.h +++ b/Framework/API/inc/MantidAPI/WorkspaceFactory.h @@ -99,15 +99,7 @@ private: using Kernel::DynamicFactory<Workspace>::create; }; -/// Forward declaration of a specialisation of SingletonHolder for -/// AlgorithmFactoryImpl (needed for dllexport/dllimport) and a typedef for it. -#ifdef _WIN32 -// this breaks new namespace declaraion rules; need to find a better fix -template class MANTID_API_DLL - Mantid::Kernel::SingletonHolder<WorkspaceFactoryImpl>; -#endif /* _WIN32 */ -typedef MANTID_API_DLL Mantid::Kernel::SingletonHolder<WorkspaceFactoryImpl> - WorkspaceFactory; +typedef Mantid::Kernel::SingletonHolder<WorkspaceFactoryImpl> WorkspaceFactory; template <class T, class... InitArgs> boost::shared_ptr<T> createWorkspace(InitArgs... args) { @@ -116,7 +108,14 @@ boost::shared_ptr<T> createWorkspace(InitArgs... args) { return ws; } -} // namespace Kernel +} // namespace API } // namespace Mantid +namespace Mantid { +namespace Kernel { +EXTERN_MANTID_API template class MANTID_API_DLL + Mantid::Kernel::SingletonHolder<Mantid::API::WorkspaceFactoryImpl>; +} +} + #endif /*MANTID_KERNEL_WORKSPACEFACTORY_H_*/ diff --git a/Framework/API/src/ArchiveSearchFactory.cpp b/Framework/API/src/ArchiveSearchFactory.cpp index c05b3aa0aefac4cc9f5ef871f07ac352800c198c..bdca4a699c15ea61795d1c045698269ac777b70b 100644 --- a/Framework/API/src/ArchiveSearchFactory.cpp +++ b/Framework/API/src/ArchiveSearchFactory.cpp @@ -8,6 +8,5 @@ namespace API { /// Default constructor ArchiveSearchFactoryImpl::ArchiveSearchFactoryImpl() {} - } // namespace API } // namespace Mantid diff --git a/Framework/API/src/Expression.cpp b/Framework/API/src/Expression.cpp index f918e836db5f2f1c691810a1b77b157d5060e9a1..7daa152eb27f24bc5ed55fe8944903d777bd363a 100644 --- a/Framework/API/src/Expression.cpp +++ b/Framework/API/src/Expression.cpp @@ -311,7 +311,7 @@ void Expression::tokenize() { if (!tokens.empty()) { // remove operators of higher prec - m_tokens.push_back(Token(tokens[0])); + m_tokens.emplace_back(tokens[0]); for (size_t i = 0; i < tokens.size(); i++) { Token &tok = tokens[i]; std::string op = m_expr.substr(tok.ie + 1, tok.is1 - tok.ie - 1); //? @@ -320,7 +320,7 @@ void Expression::tokenize() { last_tok.ie = tok.ie; last_tok.is1 = tok.is1; if (i != tokens.size() - 1) - m_tokens.push_back(Token(tokens[i + 1])); + m_tokens.emplace_back(tokens[i + 1]); } } } diff --git a/Framework/API/src/TransformScaleFactory.cpp b/Framework/API/src/TransformScaleFactory.cpp index 6de6bb9fe86e075bcd30a0019616e7255ca19618..d0cccf43747d1b2493a27e9f6c3e2556d8ecede3 100644 --- a/Framework/API/src/TransformScaleFactory.cpp +++ b/Framework/API/src/TransformScaleFactory.cpp @@ -43,5 +43,6 @@ TransformScaleFactoryImpl::createUnwrapped(const std::string &className) const { throw Kernel::Exception::NotImplementedError( "Don't use this method - use the safe one!!!"); } + } // namespace Mantid } // namespace API diff --git a/Framework/API/src/WorkspaceProperty.cpp b/Framework/API/src/WorkspaceProperty.cpp index 42a78b0855103388853f61fcbc70374f528eefc9..7284be35e7295e92e9817ebe53f17d798499c33a 100644 --- a/Framework/API/src/WorkspaceProperty.cpp +++ b/Framework/API/src/WorkspaceProperty.cpp @@ -9,18 +9,18 @@ namespace Mantid { namespace API { ///@cond TEMPLATE -template MANTID_API_DLL class Mantid::API::WorkspaceProperty< - Mantid::API::Workspace>; -template MANTID_API_DLL class Mantid::API::WorkspaceProperty< - Mantid::API::IEventWorkspace>; -template MANTID_API_DLL class Mantid::API::WorkspaceProperty< - Mantid::API::IMDEventWorkspace>; -template MANTID_API_DLL class Mantid::API::WorkspaceProperty< - Mantid::API::IMDWorkspace>; -template MANTID_API_DLL class Mantid::API::WorkspaceProperty< - Mantid::API::MatrixWorkspace>; -template MANTID_API_DLL class Mantid::API::WorkspaceProperty< - Mantid::API::ITableWorkspace>; +template class MANTID_API_DLL + Mantid::API::WorkspaceProperty<Mantid::API::Workspace>; +template class MANTID_API_DLL + Mantid::API::WorkspaceProperty<Mantid::API::IEventWorkspace>; +template class MANTID_API_DLL + Mantid::API::WorkspaceProperty<Mantid::API::IMDEventWorkspace>; +template class MANTID_API_DLL + Mantid::API::WorkspaceProperty<Mantid::API::IMDWorkspace>; +template class MANTID_API_DLL + Mantid::API::WorkspaceProperty<Mantid::API::MatrixWorkspace>; +template class MANTID_API_DLL + Mantid::API::WorkspaceProperty<Mantid::API::ITableWorkspace>; ///@endcond TEMPLATE } // namespace API } // namespace Mantid diff --git a/Framework/Algorithms/CMakeLists.txt b/Framework/Algorithms/CMakeLists.txt index 7942576c62f9338b16ae85373affb8a231b5f9af..e5b7fe79b1f4d131ff86940cf22fc700c063e765 100644 --- a/Framework/Algorithms/CMakeLists.txt +++ b/Framework/Algorithms/CMakeLists.txt @@ -77,6 +77,7 @@ set ( SRC_FILES src/CreateTransmissionWorkspace.cpp src/CreateTransmissionWorkspaceAuto.cpp src/CreateWorkspace.cpp + src/CropToComponent.cpp src/CropWorkspace.cpp src/CrossCorrelate.cpp src/CuboidGaugeVolumeAbsorption.cpp @@ -314,7 +315,7 @@ set ( INC_FILES inc/MantidAlgorithms/AverageLogData.h inc/MantidAlgorithms/BinaryOperateMasks.h inc/MantidAlgorithms/BinaryOperation.h - inc/MantidAlgorithms/BoostOptionalToAlgorithmProperty.h + inc/MantidAlgorithms/BoostOptionalToAlgorithmProperty.h inc/MantidAlgorithms/CalMuonDeadTime.h inc/MantidAlgorithms/CalMuonDetectorPhases.h inc/MantidAlgorithms/CalculateDIFC.h @@ -374,6 +375,7 @@ set ( INC_FILES inc/MantidAlgorithms/CreateTransmissionWorkspace.h inc/MantidAlgorithms/CreateTransmissionWorkspaceAuto.h inc/MantidAlgorithms/CreateWorkspace.h + inc/MantidAlgorithms/CropToComponent.h inc/MantidAlgorithms/CropWorkspace.h inc/MantidAlgorithms/CrossCorrelate.h inc/MantidAlgorithms/CuboidGaugeVolumeAbsorption.h @@ -685,6 +687,7 @@ set ( TEST_FILES CreateTransmissionWorkspaceAutoTest.h CreateTransmissionWorkspaceTest.h CreateWorkspaceTest.h + CropToComponentTest.h CropWorkspaceTest.h CuboidGaugeVolumeAbsorptionTest.h CylinderAbsorptionTest.h @@ -736,7 +739,7 @@ set ( TEST_FILES GetDetOffsetsMultiPeaksTest.h GetDetectorOffsetsTest.h GetEiTest.h - GetEiV1Test.h + GetEiV1Test.h GetTimeSeriesLogInformationTest.h GroupWorkspacesTest.h HRPDSlabCanAbsorptionTest.h @@ -759,8 +762,8 @@ set ( TEST_FILES MaxEnt/MaxentEntropyPositiveValuesTest.h MaxEnt/MaxentSpaceComplexTest.h MaxEnt/MaxentSpaceRealTest.h - MaxEntTest.h MaxEnt/MaxentTransformFourierTest.h + MaxEntTest.h MaxMinTest.h MayersSampleCorrectionStrategyTest.h MayersSampleCorrectionTest.h diff --git a/Framework/Algorithms/inc/MantidAlgorithms/CropToComponent.h b/Framework/Algorithms/inc/MantidAlgorithms/CropToComponent.h new file mode 100644 index 0000000000000000000000000000000000000000..f679c542f35dcd7a8f1230654673a97a63c68e02 --- /dev/null +++ b/Framework/Algorithms/inc/MantidAlgorithms/CropToComponent.h @@ -0,0 +1,50 @@ +#ifndef MANTID_ALGORITHMS_CROPTOCOMPONENT_H_ +#define MANTID_ALGORITHMS_CROPTOCOMPONENT_H_ + +#include "MantidAPI/Algorithm.h" +#include "MantidAlgorithms/DllConfig.h" +namespace Mantid { +namespace Algorithms { + +/** CropToComponent : Crops a workspace to a set of components. + + Copyright © 2016 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge + National Laboratory & European Spallation Source + + This file is part of Mantid. + + Mantid is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + Mantid is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + + File change history is stored at: <https://github.com/mantidproject/mantid> + Code Documentation is available at: <http://doxygen.mantidproject.org> +*/ +class MANTID_ALGORITHMS_DLL CropToComponent final : public API::Algorithm { +public: + const std::string name() const override final; + int version() const override final; + const std::string category() const override final; + const std::string summary() const override final; + +protected: + std::map<std::string, std::string> validateInputs() override; + +private: + void init() override final; + void exec() override final; +}; + +} // namespace Algorithms +} // namespace Mantid + +#endif /* MANTID_ALGORITHMS_CROPTOCOMPONENT_H_ */ diff --git a/Framework/Algorithms/src/CropToComponent.cpp b/Framework/Algorithms/src/CropToComponent.cpp new file mode 100644 index 0000000000000000000000000000000000000000..87d41f8fa02e1b22098f251e74f6ef0bf286fb00 --- /dev/null +++ b/Framework/Algorithms/src/CropToComponent.cpp @@ -0,0 +1,133 @@ +#include "MantidAPI/AlgorithmManager.h" +#include "MantidAPI/MatrixWorkspace.h" +#include "MantidAlgorithms/CropToComponent.h" +#include "MantidGeometry/IDetector.h" +#include "MantidGeometry/Instrument.h" +#include "MantidKernel/ArrayProperty.h" + +namespace { + +void getDetectors( + Mantid::API::MatrixWorkspace_sptr workspace, + const std::vector<std::string> &componentNames, + std::vector<Mantid::Geometry::IDetector_const_sptr> &detectors) { + auto instrument = workspace->getInstrument(); + for (const auto &componentName : componentNames) { + instrument->getDetectorsInBank(detectors, componentName); + } +} + +void getDetectorIDs( + std::vector<Mantid::Geometry::IDetector_const_sptr> &detectors, + std::vector<Mantid::detid_t> &detectorIDs) { + auto numberOfDetectors = static_cast<int>(detectors.size()); + PARALLEL_FOR_NO_WSP_CHECK() + for (int index = 0; index < numberOfDetectors; ++index) { + auto det = detectors[index]; + detectorIDs[index] = det->getID(); + } +} +} + +namespace Mantid { +namespace Algorithms { + +using Mantid::Kernel::Direction; +using Mantid::API::WorkspaceProperty; + +// Register the algorithm into the AlgorithmFactory +DECLARE_ALGORITHM(CropToComponent) + +//---------------------------------------------------------------------------------------------- + +/// Algorithms name for identification. @see Algorithm::name +const std::string CropToComponent::name() const { return "CropToComponent"; } + +/// Algorithm's version for identification. @see Algorithm::version +int CropToComponent::version() const { return 1; } + +/// Algorithm's category for identification. @see Algorithm::category +const std::string CropToComponent::category() const { + return "Transforms\\Splitting"; +} + +/// Algorithm's summary for use in the GUI and help. @see Algorithm::summary +const std::string CropToComponent::summary() const { + return "Crops a workspace to a set of components."; +} + +//---------------------------------------------------------------------------------------------- +/** Initialize the algorithm's properties. + */ +void CropToComponent::init() { + declareProperty( + Kernel::make_unique<WorkspaceProperty<Mantid::API::MatrixWorkspace>>( + "InputWorkspace", "", Direction::Input), + "An input workspace."); + declareProperty( + Kernel::make_unique<WorkspaceProperty<Mantid::API::MatrixWorkspace>>( + "OutputWorkspace", "", Direction::Output), + "An output workspace."); + declareProperty( + Kernel::make_unique<Mantid::Kernel::ArrayProperty<std::string>>( + "ComponentNames"), + "List of component names which are used to crop the workspace." + "to."); +} + +//---------------------------------------------------------------------------------------------- +/** Execute the algorithm. + */ +void CropToComponent::exec() { + // Get the names of the components + std::vector<std::string> componentNames = getProperty("ComponentNames"); + Mantid::API::MatrixWorkspace_sptr inputWorkspace = + getProperty("InputWorkspace"); + + // Get all detectors + std::vector<Mantid::Geometry::IDetector_const_sptr> detectors; + getDetectors(inputWorkspace, componentNames, detectors); + + // Get the detector IDs from the Detectors + std::vector<detid_t> detectorIDs(detectors.size()); + getDetectorIDs(detectors, detectorIDs); + + // Run ExtractSpectra in order to obtain the cropped workspace + auto extract_alg = Mantid::API::AlgorithmManager::Instance().createUnmanaged( + "ExtractSpectra"); + extract_alg->setChild(true); + extract_alg->initialize(); + extract_alg->setProperty("InputWorkspace", inputWorkspace); + extract_alg->setProperty("OutputWorkspace", "dummy"); + extract_alg->setProperty("DetectorList", detectorIDs); + extract_alg->execute(); + Mantid::API::MatrixWorkspace_sptr outputWorkspace = + extract_alg->getProperty("OutputWorkspace"); + + // Set the output + setProperty("OutputWorkspace", outputWorkspace); +} + +std::map<std::string, std::string> CropToComponent::validateInputs() { + std::map<std::string, std::string> result; + Mantid::API::MatrixWorkspace_sptr inputWorkspace = + getProperty("InputWorkspace"); + std::vector<std::string> componentNames = getProperty("ComponentNames"); + + // Make sure that the component exists on the input workspace + auto instrument = inputWorkspace->getInstrument(); + for (auto &componentName : componentNames) { + auto detector = instrument->getComponentByName(componentName); + if (!detector) { + std::string message = + "The component name " + componentName + + " does not exist on the workspace. Specify a valid component."; + result["ComponentNames"] = message; + break; + } + } + return result; +} + +} // namespace Algorithms +} // namespace Mantid diff --git a/Framework/Algorithms/src/EQSANSTofStructure.cpp b/Framework/Algorithms/src/EQSANSTofStructure.cpp index 71844e0682a2f09cc7066dd92efb03abda09e53b..83bb0bf2f2156c0439de1727efa4bd35e7ed91e4 100644 --- a/Framework/Algorithms/src/EQSANSTofStructure.cpp +++ b/Framework/Algorithms/src/EQSANSTofStructure.cpp @@ -182,7 +182,7 @@ void EQSANSTofStructure::execEvent( // At this point the events in the second frame are still off by a frame if (frame_skipping && rel_tof > tof_frame_width) newtof += tof_frame_width; - clean_events.push_back(TofEvent(newtof, it->pulseTime())); + clean_events.emplace_back(newtof, it->pulseTime()); } events.clear(); events.reserve(clean_events.size()); diff --git a/Framework/Algorithms/src/FilterByLogValue.cpp b/Framework/Algorithms/src/FilterByLogValue.cpp index ba5bc4ccb20a1da577f3a95b42a9e929027536e3..8d0c0766ee42b29cd26248e39b900899acd1ed11 100644 --- a/Framework/Algorithms/src/FilterByLogValue.cpp +++ b/Framework/Algorithms/src/FilterByLogValue.cpp @@ -153,7 +153,7 @@ void FilterByLogValue::exec() { splitter.push_back(interval); } // And the last one - splitter.push_back(SplittingInterval(lastTime, run_stop, 0)); + splitter.emplace_back(lastTime, run_stop, 0); } else { // ----- Filter by value ------ diff --git a/Framework/Algorithms/src/FindPeakBackground.cpp b/Framework/Algorithms/src/FindPeakBackground.cpp index 9afbfb852636424795dd2585755c4f91ecb3c62b..e73aef39c2364960a35b084e675e29d018f9667d 100644 --- a/Framework/Algorithms/src/FindPeakBackground.cpp +++ b/Framework/Algorithms/src/FindPeakBackground.cpp @@ -176,12 +176,12 @@ void FindPeakBackground::exec() { // for loop can start > 1 for multiple peaks vector<cont_peak> peaks; if (mask[0] == 1) { - peaks.push_back(cont_peak()); + peaks.emplace_back(); peaks.back().start = l0; } for (size_t l = 1; l < n - l0; ++l) { if (mask[l] != mask[l - 1] && mask[l] == 1) { - peaks.push_back(cont_peak()); + peaks.emplace_back(); peaks.back().start = l + l0; } else if (!peaks.empty()) { size_t ipeak = peaks.size() - 1; diff --git a/Framework/Algorithms/src/GetAllEi.cpp b/Framework/Algorithms/src/GetAllEi.cpp index 1eb440656c48e3f2c6e4d50ae9d1ba78899f4839..894da3e4857164458c20c753c1c4fd8d11e52a0b 100644 --- a/Framework/Algorithms/src/GetAllEi.cpp +++ b/Framework/Algorithms/src/GetAllEi.cpp @@ -340,7 +340,7 @@ void GetAllEi::exec() { bool found = findMonitorPeak(monitorWS, guess_ei[i], monsRangeMin, monsRangeMax, energy, height, twoSigma); if (found) { - peaks.push_back(peakKeeper(energy, height, 0.5 * twoSigma)); + peaks.emplace_back(energy, height, 0.5 * twoSigma); if (peaks.back().energy > maxPeakEnergy) maxPeakEnergy = peaks.back().energy; } diff --git a/Framework/Algorithms/src/SmoothNeighbours.cpp b/Framework/Algorithms/src/SmoothNeighbours.cpp index d4ff294cd7fe083e408e06bb255b52be6bb17728..8425a3f741b37b8c9863337aa2d3e461775367c6 100644 --- a/Framework/Algorithms/src/SmoothNeighbours.cpp +++ b/Framework/Algorithms/src/SmoothNeighbours.cpp @@ -249,7 +249,7 @@ void SmoothNeighbours::findNeighboursRectangular() { // Build a map to sort by the detectorID std::vector<std::pair<int, int>> v1; for (int i = 0; i < static_cast<int>(detList.size()); i++) - v1.push_back(std::pair<int, int>(detList[i]->getAtXY(0, 0)->getID(), i)); + v1.emplace_back(detList[i]->getAtXY(0, 0)->getID(), i); // To sort in descending order if (sum) @@ -286,7 +286,7 @@ void SmoothNeighbours::findNeighboursRectangular() { auto mapEntry = pixel_to_wi.find(pixelID); if (mapEntry != pixel_to_wi.end()) { size_t wi = mapEntry->second; - neighbours.push_back(weightedNeighbour(wi, smweight)); + neighbours.emplace_back(wi, smweight); // Count the total weight totalWeight += smweight; } @@ -420,7 +420,7 @@ void SmoothNeighbours::findNeighboursUbiqutious() { noNeigh++; used[neighWI] = true; } - neighbours.push_back(weightedNeighbour(neighWI, weight)); + neighbours.emplace_back(neighWI, weight); totalWeight += weight; } } diff --git a/Framework/Algorithms/test/CropToComponentTest.h b/Framework/Algorithms/test/CropToComponentTest.h new file mode 100644 index 0000000000000000000000000000000000000000..7353994ea187d8a9dd3bf12a05f6edf0545ed266 --- /dev/null +++ b/Framework/Algorithms/test/CropToComponentTest.h @@ -0,0 +1,157 @@ +#ifndef MANTID_ALGORITHMS_CROPTOCOMPONENTTEST_H_ +#define MANTID_ALGORITHMS_CROPTOCOMPONENTTEST_H_ + +#include <cxxtest/TestSuite.h> + +#include "MantidAPI/AlgorithmManager.h" +#include "MantidAlgorithms/CropToComponent.h" +#include "MantidGeometry/Instrument.h" +#include "MantidTestHelpers/WorkspaceCreationHelper.h" +#include <numeric> + +class CropToComponentTest : public CxxTest::TestSuite { +public: + // This pair of boilerplate methods prevent the suite being created statically + // This means the constructor isn't called when running other tests + static CropToComponentTest *createSuite() { + return new CropToComponentTest(); + } + static void destroySuite(CropToComponentTest *suite) { delete suite; } + + void test_Init() { + Mantid::Algorithms::CropToComponent alg; + TS_ASSERT_THROWS_NOTHING(alg.initialize()) + TS_ASSERT(alg.isInitialized()) + } + + void test_exec() { + // Arrange + int numberOfBanks = 4; + int numberOfPixelsPerBank = 3; + + auto inputWorkspace = + getSampleWorkspace(numberOfBanks, numberOfPixelsPerBank); + std::vector<std::string> componentNames = {"bank2", "bank3"}; + + // Act + Mantid::Algorithms::CropToComponent crop; + crop.setChild(true); + crop.initialize(); + crop.setProperty("InputWorkspace", inputWorkspace); + crop.setProperty("OutputWorkspace", "dummy"); + crop.setProperty("ComponentNames", componentNames); + crop.execute(); + TS_ASSERT(crop.isExecuted()) + Mantid::API::MatrixWorkspace_sptr outputWorkspace = + crop.getProperty("OutputWorkspace"); + + // Assert + size_t expectedNumberOfHistograms = 18; + std::vector<Mantid::detid_t> expectedIDs(expectedNumberOfHistograms); + std::iota(expectedIDs.begin(), expectedIDs.end(), 18); + doAsssert(outputWorkspace, expectedIDs, expectedNumberOfHistograms); + } + + void test_that_no_specified_bank_returns_everything() { + // Arrange + int numberOfBanks = 4; + int numberOfPixelsPerBank = 3; + + auto inputWorkspace = + getSampleWorkspace(numberOfBanks, numberOfPixelsPerBank); + std::vector<std::string> componentNames = {}; + + // Act + Mantid::Algorithms::CropToComponent crop; + crop.setChild(true); + crop.initialize(); + crop.setProperty("InputWorkspace", inputWorkspace); + crop.setProperty("OutputWorkspace", "dummy"); + crop.setProperty("ComponentNames", componentNames); + crop.execute(); + TS_ASSERT(crop.isExecuted()) + Mantid::API::MatrixWorkspace_sptr outputWorkspace = + crop.getProperty("OutputWorkspace"); + + // Assert + size_t expectedNumberOfHistograms = 36; + std::vector<Mantid::detid_t> expectedIDs(expectedNumberOfHistograms); + std::iota(expectedIDs.begin(), expectedIDs.end(), 9); + doAsssert(outputWorkspace, expectedIDs, expectedNumberOfHistograms); + } + + void test_that_single_bank_can_be_extracted() { + // Arrange + int numberOfBanks = 4; + int numberOfPixelsPerBank = 3; + + auto inputWorkspace = + getSampleWorkspace(numberOfBanks, numberOfPixelsPerBank); + std::vector<std::string> componentNames = {"bank3"}; + + // Act + Mantid::Algorithms::CropToComponent crop; + crop.setChild(true); + crop.initialize(); + crop.setProperty("InputWorkspace", inputWorkspace); + crop.setProperty("OutputWorkspace", "dummy"); + crop.setProperty("ComponentNames", componentNames); + crop.execute(); + TS_ASSERT(crop.isExecuted()) + Mantid::API::MatrixWorkspace_sptr outputWorkspace = + crop.getProperty("OutputWorkspace"); + + // Assert + size_t expectedNumberOfHistograms = 9; + std::vector<Mantid::detid_t> expectedIDs(expectedNumberOfHistograms); + std::iota(expectedIDs.begin(), expectedIDs.end(), 27); + } + + void test_that_incorrect_component_name_is_not_accepeted() { + // Arrange + int numberOfBanks = 4; + int numberOfPixelsPerBank = 3; + + auto inputWorkspace = + getSampleWorkspace(numberOfBanks, numberOfPixelsPerBank); + std::vector<std::string> componentNames = {"wrong_detector_name"}; + + // Act + Mantid::Algorithms::CropToComponent crop; + crop.setChild(true); + crop.initialize(); + crop.setRethrows(true); + crop.setProperty("InputWorkspace", inputWorkspace); + crop.setProperty("OutputWorkspace", "dummy"); + crop.setProperty("ComponentNames", componentNames); + TSM_ASSERT_THROWS("Invalid detector names will throw.", crop.execute(), + std::runtime_error) + } + +private: + Mantid::API::MatrixWorkspace_sptr + getSampleWorkspace(int numberOfBanks, int numbersOfPixelPerBank) { + return WorkspaceCreationHelper::create2DWorkspaceWithRectangularInstrument( + numberOfBanks, numbersOfPixelPerBank, 2); + } + + void doAsssert(Mantid::API::MatrixWorkspace_sptr workspace, + std::vector<Mantid::detid_t> &expectedIDs, + size_t expectedNumberOfHistograms) { + // Assert + const auto numberOfHistograms = workspace->getNumberHistograms(); + TS_ASSERT_EQUALS(numberOfHistograms, expectedNumberOfHistograms); + + std::vector<size_t> indices(numberOfHistograms); + std::iota(indices.begin(), indices.end(), 0); + + for (const auto index : indices) { + auto det = workspace->getDetector(index); + Mantid::detid_t detectorID = det->getID(); + TSM_ASSERT_EQUALS("The detector IDs should match.", expectedIDs[index], + detectorID); + } + } +}; + +#endif /* MANTID_ALGORITHMS_CROPTOCOMPONENTTEST_H_ */ diff --git a/Framework/CMakeLists.txt b/Framework/CMakeLists.txt index 594e0bb4406a6ccee97dcba9f30ec5b8360decea..254833ef76fc6a0ad9fa44b9ccf9376e88024666 100644 --- a/Framework/CMakeLists.txt +++ b/Framework/CMakeLists.txt @@ -1,5 +1,5 @@ # This is mainly here so you don't get a complaint when running cmake -cmake_minimum_required (VERSION 2.8.12) +cmake_minimum_required (VERSION 3.5) # Add the path to our custom 'find' modules set ( CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../buildconfig/CMake") diff --git a/Framework/Crystal/src/ConnectedComponentLabeling.cpp b/Framework/Crystal/src/ConnectedComponentLabeling.cpp index 92394ec1385ecde81a5817b00a69758d96c421ee..920b852f6ff40a16667a14155518ee925957d22f 100644 --- a/Framework/Crystal/src/ConnectedComponentLabeling.cpp +++ b/Framework/Crystal/src/ConnectedComponentLabeling.cpp @@ -143,7 +143,7 @@ size_t doConnectedComponentLabeling(IMDIterator *iterator, correcly provided for all neighbours until the end. We must store indexes instead. */ - edgeIndexVec.push_back(EdgeIndexPair(currentIndex, neighIndex)); + edgeIndexVec.emplace_back(currentIndex, neighIndex); continue; } diff --git a/Framework/Crystal/src/IntegratePeakTimeSlices.cpp b/Framework/Crystal/src/IntegratePeakTimeSlices.cpp index 7ceca56b992ee2a54b52663908b6eb1fb6415134..b9f67285fa603209d1ba29f1471b56ab6dd46f4a 100644 --- a/Framework/Crystal/src/IntegratePeakTimeSlices.cpp +++ b/Framework/Crystal/src/IntegratePeakTimeSlices.cpp @@ -1944,11 +1944,11 @@ DataModeHandler::CalcConstraints(std::vector<std::pair<double, double>> &Bounds, double min = max<double>(0.0, back_calc - NSigs * (1 + relError) * sqrt(backVar)); double maxx = back + NSigs * (1.8 + relError) * sqrt(backVar); - Bounds.push_back(pair<double, double>(min, maxx)); - Bounds.push_back(pair<double, double>( + Bounds.emplace_back(min, maxx); + Bounds.emplace_back( max<double>(0.0, Intensity_calc - NSigs * (1 + relError) * sqrt(IntensVar)), - Intensity_calc + NSigs * (1 + relError) * sqrt(IntensVar))); + Intensity_calc + NSigs * (1 + relError) * sqrt(IntensVar)); double relErr1 = relError * .75; double val = col_calc; double minn = std::max<double>(MinCol - .5, (1 - relErr1) * val); @@ -1957,7 +1957,7 @@ DataModeHandler::CalcConstraints(std::vector<std::pair<double, double>> &Bounds, str << "," << minn << "<" << "Mcol" << "<" << maxx; - Bounds.push_back(pair<double, double>(minn, maxx)); + Bounds.emplace_back(minn, maxx); val = row_calc; @@ -1966,7 +1966,7 @@ DataModeHandler::CalcConstraints(std::vector<std::pair<double, double>> &Bounds, str << "," << minn << "<" << "Mrow" << "<" << maxx; - Bounds.push_back(pair<double, double>(minn, maxx)); + Bounds.emplace_back(minn, maxx); if (N >= 5) { val = Vx_calc; @@ -1981,8 +1981,7 @@ DataModeHandler::CalcConstraints(std::vector<std::pair<double, double>> &Bounds, str << "," << (1 - relErr1) * valmin << "<" << "SScol" << "<" << (1 + relErr1) * valmax; - Bounds.push_back( - pair<double, double>((1 - relErr1) * valmin, (1 + relErr1) * valmax)); + Bounds.emplace_back((1 - relErr1) * valmin, (1 + relErr1) * valmax); val = Vy_calc; valmin = val; @@ -1994,8 +1993,7 @@ DataModeHandler::CalcConstraints(std::vector<std::pair<double, double>> &Bounds, str << "," << (1 - relErr1) * valmin << "<" << "SSrow" << "<" << (1 + relErr1) * valmax; - Bounds.push_back( - pair<double, double>((1 - relErr1) * valmin, (1 + relErr1) * valmax)); + Bounds.emplace_back((1 - relErr1) * valmin, (1 + relErr1) * valmax); } return str.str(); diff --git a/Framework/Crystal/src/OptimizeCrystalPlacement.cpp b/Framework/Crystal/src/OptimizeCrystalPlacement.cpp index 9ab37743fad8824c88b50018a110f80dc15ef2b2..4a69009583a71a0264a654a218ac49485070708f 100644 --- a/Framework/Crystal/src/OptimizeCrystalPlacement.cpp +++ b/Framework/Crystal/src/OptimizeCrystalPlacement.cpp @@ -190,8 +190,7 @@ void OptimizeCrystalPlacement::exec() { Geometry::Goniometer Gon(peak.getGoniometerMatrix()); std::vector<double> phichiOmega = Gon.getEulerAngles("YZY"); - ChiPhiOmega.push_back( - V3D(phichiOmega[1], phichiOmega[2], phichiOmega[0])); + ChiPhiOmega.emplace_back(phichiOmega[1], phichiOmega[2], phichiOmega[0]); } if (use) // add to lists for workspace diff --git a/Framework/CurveFitting/inc/MantidCurveFitting/DllConfig.h b/Framework/CurveFitting/inc/MantidCurveFitting/DllConfig.h index c6d841c31d5554f5df6587fdc6fbb891559b7b66..37a8e248edd09f772bfa4859828e089477a77262 100644 --- a/Framework/CurveFitting/inc/MantidCurveFitting/DllConfig.h +++ b/Framework/CurveFitting/inc/MantidCurveFitting/DllConfig.h @@ -32,8 +32,10 @@ #ifdef IN_MANTID_CURVEFITTING #define MANTID_CURVEFITTING_DLL DLLExport +#define EXTERN_MANTID_CURVEFITTING #else #define MANTID_CURVEFITTING_DLL DLLImport +#define EXTERN_MANTID_CURVEFITTING EXTERN_IMPORT #endif /* IN_MANTID_CURVEFITTING*/ #endif // MANTID_CURVEFITTING_DLLCONFIG_H_ diff --git a/Framework/DataHandling/src/CheckMantidVersion.cpp b/Framework/DataHandling/src/CheckMantidVersion.cpp index bdfb17058b34c62c55a884704219877d488891e2..4f9929c48c692a132382cb2ad569c68f1688ade4 100644 --- a/Framework/DataHandling/src/CheckMantidVersion.cpp +++ b/Framework/DataHandling/src/CheckMantidVersion.cpp @@ -1,5 +1,5 @@ #include "MantidDataHandling/CheckMantidVersion.h" -#include "MantidKernel/InternetHelper.h" +#include "MantidKernel/GitHubApiHelper.h" #include "MantidKernel/MantidVersion.h" #include "MantidKernel/Strings.h" @@ -226,11 +226,11 @@ behaviour. */ std::string CheckMantidVersion::getVersionsFromGitHub(const std::string &url) { - Kernel::InternetHelper inetHelper; + Kernel::GitHubApiHelper inetHelper; std::ostringstream os; int tzd = 0; - inetHelper.headers().emplace( + inetHelper.addHeader( "if-modified-since", Poco::DateTimeFormatter::format( Poco::DateTimeParser::parse(MantidVersion::releaseDate(), tzd), diff --git a/Framework/DataHandling/src/DownloadInstrument.cpp b/Framework/DataHandling/src/DownloadInstrument.cpp index e446b377eb72c40a444f3a10731bdcdd37172d4b..d47dd8fa33fe422b2d9678d1689308a598ee8f3e 100644 --- a/Framework/DataHandling/src/DownloadInstrument.cpp +++ b/Framework/DataHandling/src/DownloadInstrument.cpp @@ -1,7 +1,7 @@ #include "MantidDataHandling/DownloadInstrument.h" #include "MantidKernel/ChecksumHelper.h" #include "MantidKernel/ConfigService.h" -#include "MantidKernel/InternetHelper.h" +#include "MantidKernel/GitHubApiHelper.h" // Poco #include <Poco/DateTimeFormat.h> @@ -362,8 +362,8 @@ int DownloadInstrument::doDownloadFile(const std::string &urlFile, } int retStatus = 0; - InternetHelper inetHelper; - inetHelper.headers() = headers; + GitHubApiHelper inetHelper; + inetHelper.headers().insert(headers.begin(), headers.end()); retStatus = inetHelper.downloadFile(urlFile, localFilePath); return retStatus; } diff --git a/Framework/DataHandling/src/LoadEventNexus.cpp b/Framework/DataHandling/src/LoadEventNexus.cpp index 1fe5cb378f9a7f588d7d289f24040b2817dd77dc..71760e76dcdb1c874d418c4bb9085ccef632054d 100644 --- a/Framework/DataHandling/src/LoadEventNexus.cpp +++ b/Framework/DataHandling/src/LoadEventNexus.cpp @@ -1803,6 +1803,7 @@ void LoadEventNexus::loadEvents(API::Progress *const prog, m_ws->setAllX(axis); createWorkspaceIndexMaps(monitors, std::vector<std::string>()); + return; } // --------- Loading only one bank ? ---------------------------------- diff --git a/Framework/DataHandling/src/LoadEventPreNexus.cpp b/Framework/DataHandling/src/LoadEventPreNexus.cpp index 601c0c149c527ab15691dcebdebe1aeca91ca182..83c5f156bbe6dd8e5530d20956bb7c199315b650 100644 --- a/Framework/DataHandling/src/LoadEventPreNexus.cpp +++ b/Framework/DataHandling/src/LoadEventPreNexus.cpp @@ -933,9 +933,8 @@ void LoadEventPreNexus::readPulseidFile(const std::string &filename, if (num_pulses > 0) { this->pulsetimes.reserve(num_pulses); for (const auto &pulse : pulses) { - this->pulsetimes.push_back( - DateAndTime(static_cast<int64_t>(pulse.seconds), - static_cast<int64_t>(pulse.nanoseconds))); + this->pulsetimes.emplace_back(static_cast<int64_t>(pulse.seconds), + static_cast<int64_t>(pulse.nanoseconds)); this->event_indices.push_back(pulse.event_index); temp = pulse.pCurrent; diff --git a/Framework/DataHandling/src/LoadILLSANS.cpp b/Framework/DataHandling/src/LoadILLSANS.cpp index d3b64ee0809c785f1a03562daea51f91b645c0b6..d3f787b171862dacf76e1cd38f8c36269851ddc8 100644 --- a/Framework/DataHandling/src/LoadILLSANS.cpp +++ b/Framework/DataHandling/src/LoadILLSANS.cpp @@ -25,7 +25,7 @@ DECLARE_NEXUS_FILELOADER_ALGORITHM(LoadILLSANS) /** Constructor */ LoadILLSANS::LoadILLSANS() - : m_supportedInstruments{"D33"}, m_defaultBinning{2} {} + : m_supportedInstruments{"D33"}, m_defaultBinning{0, 0} {} //---------------------------------------------------------------------------------------------- /// Algorithm's name for identification. @see Algorithm::name diff --git a/Framework/DataHandling/src/LoadRKH.cpp b/Framework/DataHandling/src/LoadRKH.cpp index 93c209d27b53911407ed7cd8a477a85f9c26e935..8ee788fae7ce9b94f93acf3704b3ab4f1d4ef44a 100644 --- a/Framework/DataHandling/src/LoadRKH.cpp +++ b/Framework/DataHandling/src/LoadRKH.cpp @@ -20,6 +20,25 @@ #include <MantidKernel/StringTokenizer.h> #include <istream> +#include <numeric> +#include <boost/regex.hpp> + +namespace { +// Check if we are dealing with a unit line +bool isUnit(const Mantid::Kernel::StringTokenizer &codes) { + // The unit line needs to have the format of + // 1. Either 0 or 6 [06] + // 2. Then several characters [\w] + // 3. Open bracket + // 4. Several characters + // 5. Close bracket + std::string input = + std::accumulate(codes.begin(), codes.end(), std::string("")); + std::string reg("^[06][\\w]+\\([/ \\w\\^-]+\\)$"); + boost::regex baseRegex(reg); + return boost::regex_match(input, baseRegex); +} +} namespace Mantid { namespace DataHandling { @@ -192,15 +211,20 @@ void LoadRKH::exec() { // Set the output workspace setProperty("OutputWorkspace", result); } + /** Determines if the file is 1D or 2D based on the first after the workspace's * title * @param testLine :: the first line in the file after the title * @return true if the file must contain 1D data */ bool LoadRKH::is2D(const std::string &testLine) { - // check the line part of a valid for 2D data else assume the file is 1D - return readUnit(testLine) != "C++ no unit found"; + // split the line into words + const Mantid::Kernel::StringTokenizer codes( + testLine, " ", Mantid::Kernel::StringTokenizer::TOK_TRIM | + Mantid::Kernel::StringTokenizer::TOK_IGNORE_EMPTY); + return isUnit(codes); } + /** Read a data file that contains only one spectrum into a workspace * @return the new workspace */ @@ -466,6 +490,11 @@ const std::string LoadRKH::readUnit(const std::string &line) { const Mantid::Kernel::StringTokenizer codes( line, " ", Mantid::Kernel::StringTokenizer::TOK_TRIM | Mantid::Kernel::StringTokenizer::TOK_IGNORE_EMPTY); + + if (!isUnit(codes)) { + return "C++ no unit found"; + } + if (codes.count() < 1) { return "C++ no unit found"; } @@ -493,8 +522,9 @@ const std::string LoadRKH::readUnit(const std::string &line) { if (unit.find('(') != 0 || unit.find(')') != unit.size()) { std::string qCode = std::to_string(SaveRKH::Q_CODE); if (symbol == qCode && theQuantity == "q" && - unit == "(1/Angstrom)") { // 6 q (1/Angstrom) is the synatx for - // MomentumTransfer + (unit == "(1/Angstrom)" || + unit == "(Angstrom^-1)")) { // 6 q (1/Angstrom) is the synatx for + // MomentumTransfer return "MomentumTransfer"; } diff --git a/Framework/DataHandling/src/LoadSassena.cpp b/Framework/DataHandling/src/LoadSassena.cpp index 8bbb51bc0422f3e2f402b37881bf029d15a75c19..785472d7a1053611bc14d117794f021840c0b5d3 100644 --- a/Framework/DataHandling/src/LoadSassena.cpp +++ b/Framework/DataHandling/src/LoadSassena.cpp @@ -137,7 +137,7 @@ MantidVec LoadSassena::loadQvectors(const hid_t &h5file, if (getProperty("SortByQVectors")) { std::vector<mypair> qvmodpair; for (int iq = 0; iq < nq; iq++) - qvmodpair.push_back(mypair(qvmod[iq], iq)); + qvmodpair.emplace_back(qvmod[iq], iq); std::sort(qvmodpair.begin(), qvmodpair.end(), compare); for (int iq = 0; iq < nq; iq++) sorting_indexes.push_back(qvmodpair[iq].second); diff --git a/Framework/DataHandling/src/LoadTBL.cpp b/Framework/DataHandling/src/LoadTBL.cpp index 91292b3504df6bf75305e9126195e57f2f5360e6..ae4c43054450fb4ae83c17235da814bedcb23e88 100644 --- a/Framework/DataHandling/src/LoadTBL.cpp +++ b/Framework/DataHandling/src/LoadTBL.cpp @@ -330,15 +330,11 @@ void LoadTBL::exec() { auto colScale = ws->addColumn("str", "Scale"); auto colOptions = ws->addColumn("str", "Options"); - colStitch->setPlotType(0); - colRuns->setPlotType(0); - colTheta->setPlotType(0); - colTrans->setPlotType(0); - colQmin->setPlotType(0); - colQmax->setPlotType(0); - colDqq->setPlotType(0); - colScale->setPlotType(0); - colOptions->setPlotType(0); + for (size_t i = 0; i < ws->columnCount(); i++) { + auto col = ws->getColumn(i); + col->setPlotType(0); + } + // we are using the old ReflTBL format // where all of the entries are on one line // so we must reset the stream to reread the first line. diff --git a/Framework/DataHandling/src/SaveNXcanSAS.cpp b/Framework/DataHandling/src/SaveNXcanSAS.cpp index 88e6ec7c618a0756a526c2c0d2b8c28241bc1360..93e757a5bcc47865e5e755167728155ef473a2f9 100644 --- a/Framework/DataHandling/src/SaveNXcanSAS.cpp +++ b/Framework/DataHandling/src/SaveNXcanSAS.cpp @@ -385,9 +385,9 @@ void addData1D(H5::Group &data, Mantid::API::MatrixWorkspace_sptr workspace) { std::map<std::string, std::string> qAttributes; auto qUnit = getUnitFromMDDimension(workspace->getDimension(0)); qUnit = getMomentumTransferLabel(qUnit); - qAttributes.insert(std::make_pair(sasUnitAttr, qUnit)); + qAttributes.emplace(sasUnitAttr, qUnit); if (workspace->hasDx(0)) { - qAttributes.insert(std::make_pair(sasUncertaintyAttr, sasDataQdev)); + qAttributes.emplace(sasUncertaintyAttr, sasDataQdev); } if (workspace->isHistogramData()) { @@ -404,8 +404,8 @@ void addData1D(H5::Group &data, Mantid::API::MatrixWorkspace_sptr workspace) { std::map<std::string, std::string> iAttributes; auto iUnit = getIntensityUnit(workspace); iUnit = getIntensityUnitLabel(iUnit); - iAttributes.insert(std::make_pair(sasUnitAttr, iUnit)); - iAttributes.insert(std::make_pair(sasUncertaintyAttr, sasDataIdev)); + iAttributes.emplace(sasUnitAttr, iUnit); + iAttributes.emplace(sasUncertaintyAttr, sasDataIdev); writeArray1DWithStrAttributes(data, sasDataI, intensity, iAttributes); @@ -424,7 +424,7 @@ void addData1D(H5::Group &data, Mantid::API::MatrixWorkspace_sptr workspace) { if (workspace->hasDx(0)) { const auto qResolution = workspace->readDx(0); std::map<std::string, std::string> xUncertaintyAttributes; - xUncertaintyAttributes.insert(std::make_pair(sasUnitAttr, qUnit)); + xUncertaintyAttributes.emplace(sasUnitAttr, qUnit); if (workspace->isHistogramData()) { std::vector<double> qResolutionCentres; @@ -567,7 +567,7 @@ void addData2D(H5::Group &data, Mantid::API::MatrixWorkspace_sptr workspace) { std::map<std::string, std::string> qxAttributes; auto qxUnit = getUnitFromMDDimension(workspace->getXDimension()); qxUnit = getMomentumTransferLabel(qxUnit); - qxAttributes.insert(std::make_pair(sasUnitAttr, qxUnit)); + qxAttributes.emplace(sasUnitAttr, qxUnit); QxExtractor<double> qxExtractor; write2DWorkspace(data, workspace, sasDataQx, qxExtractor, qxAttributes); @@ -575,7 +575,7 @@ void addData2D(H5::Group &data, Mantid::API::MatrixWorkspace_sptr workspace) { std::map<std::string, std::string> qyAttributes; auto qyUnit = getUnitFromMDDimension(workspace->getDimension(1)); qyUnit = getMomentumTransferLabel(qyUnit); - qyAttributes.insert(std::make_pair(sasUnitAttr, qyUnit)); + qyAttributes.emplace(sasUnitAttr, qyUnit); SpectrumAxisValueProvider spectrumAxisValueProvider(workspace); write2DWorkspace(data, workspace, sasDataQy, spectrumAxisValueProvider, @@ -585,8 +585,8 @@ void addData2D(H5::Group &data, Mantid::API::MatrixWorkspace_sptr workspace) { std::map<std::string, std::string> iAttributes; auto iUnit = getIntensityUnit(workspace); iUnit = getIntensityUnitLabel(iUnit); - iAttributes.insert(std::make_pair(sasUnitAttr, iUnit)); - iAttributes.insert(std::make_pair(sasUncertaintyAttr, sasDataIdev)); + iAttributes.emplace(sasUnitAttr, iUnit); + iAttributes.emplace(sasUncertaintyAttr, sasDataIdev); auto iExtractor = [](Mantid::API::MatrixWorkspace_sptr ws, int index) { return ws->dataY(index).data(); @@ -658,9 +658,9 @@ void addTransmission(H5::Group &group, if (unit.empty()) { unit = sasNone; } - transmissionAttributes.insert(std::make_pair(sasUnitAttr, unit)); - transmissionAttributes.insert( - std::make_pair(sasUncertaintyAttr, sasTransmissionSpectrumTdev)); + transmissionAttributes.emplace(sasUnitAttr, unit); + transmissionAttributes.emplace(sasUncertaintyAttr, + sasTransmissionSpectrumTdev); writeArray1DWithStrAttributes(transmission, sasTransmissionSpectrumT, transmissionData, transmissionAttributes); @@ -669,7 +669,7 @@ void addTransmission(H5::Group &group, // Add Tdev with units const auto transmissionErrors = workspace->readE(0); std::map<std::string, std::string> transmissionErrorAttributes; - transmissionErrorAttributes.insert(std::make_pair(sasUnitAttr, unit)); + transmissionErrorAttributes.emplace(sasUnitAttr, unit); writeArray1DWithStrAttributes(transmission, sasTransmissionSpectrumTdev, transmissionErrors, @@ -683,7 +683,7 @@ void addTransmission(H5::Group &group, if (lambdaUnit.empty() || lambdaUnit == "Angstrom") { lambdaUnit = sasAngstrom; } - lambdaAttributes.insert(std::make_pair(sasUnitAttr, lambdaUnit)); + lambdaAttributes.emplace(sasUnitAttr, lambdaUnit); writeArray1DWithStrAttributes(transmission, sasTransmissionSpectrumLambda, lambda, lambdaAttributes); @@ -747,14 +747,14 @@ std::map<std::string, std::string> SaveNXcanSAS::validateInputs() { if (!workspace || !boost::dynamic_pointer_cast<const Mantid::DataObjects::Workspace2D>( workspace)) { - result.insert(std::make_pair("InputWorkspace", - "The InputWorkspace must be a Workspace2D.")); + result.emplace("InputWorkspace", + "The InputWorkspace must be a Workspace2D."); } // Don't allow ragged workspaces for now if (!API::WorkspaceHelpers::commonBoundaries(workspace)) { - result.insert(std::make_pair( - "InputWorkspace", "The InputWorkspace cannot be a ragged workspace.")); + result.emplace("InputWorkspace", + "The InputWorkspace cannot be a ragged workspace."); } // Transmission data should be 1D @@ -765,9 +765,8 @@ std::map<std::string, std::string> SaveNXcanSAS::validateInputs() { auto checkTransmission = [&result](Mantid::API::MatrixWorkspace_sptr trans, std::string propertyName) { if (trans->getNumberHistograms() != 1) { - result.insert(std::make_pair( - propertyName, - "The input workspaces for transmissions have to be 1D.")); + result.emplace(propertyName, + "The input workspaces for transmissions have to be 1D."); } }; diff --git a/Framework/DataHandling/src/SetSample.cpp b/Framework/DataHandling/src/SetSample.cpp index 0d68c11241dd45128b46b5a91d68e0d4b3bae117..da1ded253448ef3ec6abf62909a9ad97a2ad7490 100644 --- a/Framework/DataHandling/src/SetSample.cpp +++ b/Framework/DataHandling/src/SetSample.cpp @@ -225,8 +225,8 @@ void SetSample::setSampleShape(API::MatrixWorkspace_sptr &workspace, for (const auto &prop : props) { // assume in cm const double val = args->getProperty(prop->name()); - shapeArgs.insert(std::make_pair( - boost::algorithm::to_lower_copy(prop->name()), val * 0.01)); + shapeArgs.emplace(boost::algorithm::to_lower_copy(prop->name()), + val * 0.01); } } auto shapeObject = can->createSampleShape(shapeArgs); diff --git a/Framework/DataHandling/test/LoadRKHTest.h b/Framework/DataHandling/test/LoadRKHTest.h index 19350604e026edf359b58c2cd552a727e7e47160..eed7b29b0d96e0e7f6633b88d1bcf224e0ffaf9d 100644 --- a/Framework/DataHandling/test/LoadRKHTest.h +++ b/Framework/DataHandling/test/LoadRKHTest.h @@ -22,7 +22,8 @@ public: // A sample file is in the repository LoadRKHTest() : dataFile(""), tempFile("LoadRKH_test_file_2D"), - tempFile2("LoadRKH_test_file_1D_with_DX") { + tempFile2("LoadRKH_test_file_1D_with_DX"), + tempFile3("LoadRKL_with_second_header") { dataFile = "DIRECT.041"; } @@ -187,7 +188,7 @@ public: TS_ASSERT(data->isHistogramData()) - remove(tempFile.c_str()); + // remove(tempFile.c_str()); } void test1DWithDx() { @@ -250,8 +251,61 @@ public: remove(tempFile2.c_str()); } + void test_LoadRKH_with_second_header() { + // Arrange + ConfigService::Instance().setString("default.facility", "ISIS"); + writeTestFileWithSecondHeader(); + std::string outputSpace = "rkh_with_second_header"; + + // Act + Mantid::DataHandling::LoadRKH rkhAlg; + rkhAlg.initialize(); + rkhAlg.setPropertyValue("Filename", tempFile3); + rkhAlg.setPropertyValue("OutputWorkspace", outputSpace); + + // Assert + std::string result; + TS_ASSERT_THROWS_NOTHING(result = rkhAlg.getPropertyValue("Filename")) + TS_ASSERT_THROWS_NOTHING(result = + rkhAlg.getPropertyValue("OutputWorkspace")) + TS_ASSERT(result == outputSpace); + TS_ASSERT_THROWS_NOTHING(rkhAlg.execute()); + TS_ASSERT(rkhAlg.isExecuted()); + + using namespace Mantid::API; + using namespace Mantid::DataObjects; + // Now need to test the resultant workspace, first retrieve it + Workspace_sptr rkhspace; + + TS_ASSERT_THROWS_NOTHING( + rkhspace = AnalysisDataService::Instance().retrieve(outputSpace)); + Workspace2D_sptr data = boost::dynamic_pointer_cast<Workspace2D>(rkhspace); + + TS_ASSERT_EQUALS(data->getNumberHistograms(), 1); + + TS_ASSERT_EQUALS(static_cast<int>(data->dataX(0).size()), 4); + TS_ASSERT_EQUALS(static_cast<int>(data->dataY(0).size()), 4); + TS_ASSERT_EQUALS(static_cast<int>(data->dataE(0).size()), 4); + + double tolerance(1e-06); + + TS_ASSERT_DELTA(data->dataX(0)[0], 0.00520, tolerance); + TS_ASSERT_DELTA(data->dataX(0)[1], 0.00562, tolerance); + TS_ASSERT_DELTA(data->dataX(0)[2], 0.00607, tolerance); + + TS_ASSERT_DELTA(data->dataY(0)[0], 1.055855e+00, tolerance); + TS_ASSERT_DELTA(data->dataY(0)[1], 9.784999e-01, tolerance); + TS_ASSERT_DELTA(data->dataY(0)[2], 1.239836e+00, tolerance); + + TS_ASSERT_DELTA(data->dataE(0)[0], 2.570181e-01, tolerance); + TS_ASSERT_DELTA(data->dataE(0)[1], 1.365013e-01, tolerance); + TS_ASSERT_DELTA(data->dataE(0)[2], 9.582824e-02, tolerance); + + remove(tempFile3.c_str()); + } + private: - std::string dataFile, tempFile, tempFile2; + std::string dataFile, tempFile, tempFile2, tempFile3; /** Create a tiny 2x2 workspace in a tempory file that should * be deleted @@ -296,6 +350,21 @@ private: file << " 9.50000 1.000000e+00 1.000000e+00 3.081139e+00\n"; file.close(); } + + void writeTestFileWithSecondHeader() { + std::ofstream file(tempFile3.c_str()); + file << " SANS2D Fri 08-JUL-2016 11:10 Workspace: " + "M3_42_3rd-MT_rear_cloned_temp\n"; + file << " M3-42_third_SANS\n"; + file << " 4 0 0 0 1 4 0\n"; + file << " 0 0 0 0\n"; + file << " 3 (F12.5,2E16.6)\n"; + file << " 0.00520 1.055855e+00 2.570181e-01\n"; + file << " 0.00562 9.784999e-01 1.365013e-01\n"; + file << " 0.00607 1.239836e+00 9.582824e-02\n"; + file << " 0.00655 1.260936e+00 7.041577e-02\n"; + file.close(); + } }; #endif // LOADRKHTEST_H_ diff --git a/Framework/DataObjects/inc/MantidDataObjects/DllConfig.h b/Framework/DataObjects/inc/MantidDataObjects/DllConfig.h index f1206f38ba247ba62ca03ae03d69d74241037964..52148c235fb13c57ae9c1e628dc1bcdbaafff24b 100644 --- a/Framework/DataObjects/inc/MantidDataObjects/DllConfig.h +++ b/Framework/DataObjects/inc/MantidDataObjects/DllConfig.h @@ -32,8 +32,10 @@ #ifdef IN_MANTID_DATAOBJECTS #define MANTID_DATAOBJECTS_DLL DLLExport +#define EXTERN_MANTID_DATAOBJECTS #else #define MANTID_DATAOBJECTS_DLL DLLImport +#define EXTERN_MANTID_DATAOBJECTS EXTERN_IMPORT #endif /* IN_MANTID_DATAOBJECTS*/ #endif // MANTID_DATAOBJECTS_DLLCONFIG_H_ diff --git a/Framework/DataObjects/inc/MantidDataObjects/MDBox.h b/Framework/DataObjects/inc/MantidDataObjects/MDBox.h index 2f6e83de79a7ec344df8a1421766fc7fc3a6f944..fcf58a8f83d54481c999609b892d26c5e6459538 100644 --- a/Framework/DataObjects/inc/MantidDataObjects/MDBox.h +++ b/Framework/DataObjects/inc/MantidDataObjects/MDBox.h @@ -247,8 +247,8 @@ public: const std::vector<coord_t> &Coord, const std::vector<uint16_t> &runIndex, const std::vector<uint32_t> &detectorId, size_t nEvents) { for (size_t i = 0; i < nEvents; i++) { - data.push_back(MDE(sigErrSq[2 * i], sigErrSq[2 * i + 1], runIndex[i], - detectorId[i], &Coord[i * nd])); + data.emplace_back(sigErrSq[2 * i], sigErrSq[2 * i + 1], runIndex[i], + detectorId[i], &Coord[i * nd]); } } // create single generic event from event's data @@ -269,8 +269,7 @@ public: const std::vector<uint32_t> & /*detectorId*/, size_t nEvents) { for (size_t i = 0; i < nEvents; i++) { - data.push_back(MDLeanEvent<nd>(sigErrSq[2 * i], sigErrSq[2 * i + 1], - &Coord[i * nd])); + data.emplace_back(sigErrSq[2 * i], sigErrSq[2 * i + 1], &Coord[i * nd]); } } // create single lean event from event's data diff --git a/Framework/DataObjects/inc/MantidDataObjects/MDBoxBase.tcc b/Framework/DataObjects/inc/MantidDataObjects/MDBoxBase.tcc index 453dfa4df4dc4dc90418278b9c781121a951b1d9..99c8f9aab90bacfe24b8c71410afc1224a9a89e7 100644 --- a/Framework/DataObjects/inc/MantidDataObjects/MDBoxBase.tcc +++ b/Framework/DataObjects/inc/MantidDataObjects/MDBoxBase.tcc @@ -54,8 +54,7 @@ TMDE(MDBoxBase)::MDBoxBase( } //----------------------------------------------------------------------------------------------- -/** Copy constructor. Copies the extents, depth, etc. - * and recalculates the boxes' volume. +/** Copy constructor. Copies the extents, volume, depth, etc. * @param box :: incoming box to copy. * @param otherBC :: if present, other (different from the current one) box * controller pointer diff --git a/Framework/DataObjects/inc/MantidDataObjects/MDEvent.h b/Framework/DataObjects/inc/MantidDataObjects/MDEvent.h index e9ef368044c992424538b51a792aa0dae8b8ca7a..e61d090f859d8cdbc994a75bd51b3865f4c2b0c7 100644 --- a/Framework/DataObjects/inc/MantidDataObjects/MDEvent.h +++ b/Framework/DataObjects/inc/MantidDataObjects/MDEvent.h @@ -247,9 +247,10 @@ public: coord_t const *const centers = &(data[ii + 4]); // Create the event with signal, error squared, and the centers - events.push_back(MDEvent<nd>(signal_t(data[ii]), signal_t(data[ii + 1]), - uint16_t(data[ii + 2]), - int32_t(data[ii + 3]), centers)); + events.emplace_back(static_cast<signal_t>(data[ii]), + static_cast<signal_t>(data[ii + 1]), + static_cast<uint16_t>(data[ii + 2]), + static_cast<int32_t>(data[ii + 3]), centers); } } }; diff --git a/Framework/DataObjects/inc/MantidDataObjects/MDEventFactory.h b/Framework/DataObjects/inc/MantidDataObjects/MDEventFactory.h index f6d2bda641f1574d616e6a3bd5f0d9064ef9e5c5..2bad03cb31849bf534038eb558f0b49180688af7 100644 --- a/Framework/DataObjects/inc/MantidDataObjects/MDEventFactory.h +++ b/Framework/DataObjects/inc/MantidDataObjects/MDEventFactory.h @@ -133,9 +133,8 @@ private: }; //### BEGIN AUTO-GENERATED CODE -//################################################################# /* Code below Auto-generated by 'generate_mdevent_declarations.py' - * on 2013-05-30 12:36:57.329000 + * on 2016-06-03 10:28:44.608989 * * DO NOT EDIT! */ @@ -149,51 +148,6 @@ private: #define CALL_MDEVENT_FUNCTION(funcname, workspace) \ { \ - MDEventWorkspace<MDEvent<1>, 1>::sptr MDEW_MDEVENT_1 = \ - boost::dynamic_pointer_cast<MDEventWorkspace<MDEvent<1>, 1>>( \ - workspace); \ - if (MDEW_MDEVENT_1) \ - funcname<MDEvent<1>, 1>(MDEW_MDEVENT_1); \ - MDEventWorkspace<MDEvent<2>, 2>::sptr MDEW_MDEVENT_2 = \ - boost::dynamic_pointer_cast<MDEventWorkspace<MDEvent<2>, 2>>( \ - workspace); \ - if (MDEW_MDEVENT_2) \ - funcname<MDEvent<2>, 2>(MDEW_MDEVENT_2); \ - MDEventWorkspace<MDEvent<3>, 3>::sptr MDEW_MDEVENT_3 = \ - boost::dynamic_pointer_cast<MDEventWorkspace<MDEvent<3>, 3>>( \ - workspace); \ - if (MDEW_MDEVENT_3) \ - funcname<MDEvent<3>, 3>(MDEW_MDEVENT_3); \ - MDEventWorkspace<MDEvent<4>, 4>::sptr MDEW_MDEVENT_4 = \ - boost::dynamic_pointer_cast<MDEventWorkspace<MDEvent<4>, 4>>( \ - workspace); \ - if (MDEW_MDEVENT_4) \ - funcname<MDEvent<4>, 4>(MDEW_MDEVENT_4); \ - MDEventWorkspace<MDEvent<5>, 5>::sptr MDEW_MDEVENT_5 = \ - boost::dynamic_pointer_cast<MDEventWorkspace<MDEvent<5>, 5>>( \ - workspace); \ - if (MDEW_MDEVENT_5) \ - funcname<MDEvent<5>, 5>(MDEW_MDEVENT_5); \ - MDEventWorkspace<MDEvent<6>, 6>::sptr MDEW_MDEVENT_6 = \ - boost::dynamic_pointer_cast<MDEventWorkspace<MDEvent<6>, 6>>( \ - workspace); \ - if (MDEW_MDEVENT_6) \ - funcname<MDEvent<6>, 6>(MDEW_MDEVENT_6); \ - MDEventWorkspace<MDEvent<7>, 7>::sptr MDEW_MDEVENT_7 = \ - boost::dynamic_pointer_cast<MDEventWorkspace<MDEvent<7>, 7>>( \ - workspace); \ - if (MDEW_MDEVENT_7) \ - funcname<MDEvent<7>, 7>(MDEW_MDEVENT_7); \ - MDEventWorkspace<MDEvent<8>, 8>::sptr MDEW_MDEVENT_8 = \ - boost::dynamic_pointer_cast<MDEventWorkspace<MDEvent<8>, 8>>( \ - workspace); \ - if (MDEW_MDEVENT_8) \ - funcname<MDEvent<8>, 8>(MDEW_MDEVENT_8); \ - MDEventWorkspace<MDEvent<9>, 9>::sptr MDEW_MDEVENT_9 = \ - boost::dynamic_pointer_cast<MDEventWorkspace<MDEvent<9>, 9>>( \ - workspace); \ - if (MDEW_MDEVENT_9) \ - funcname<MDEvent<9>, 9>(MDEW_MDEVENT_9); \ MDEventWorkspace<MDLeanEvent<1>, 1>::sptr MDEW_MDLEANEVENT_1 = \ boost::dynamic_pointer_cast<MDEventWorkspace<MDLeanEvent<1>, 1>>( \ workspace); \ @@ -239,17 +193,16 @@ private: workspace); \ if (MDEW_MDLEANEVENT_9) \ funcname<MDLeanEvent<9>, 9>(MDEW_MDLEANEVENT_9); \ - } - -/** Macro that makes it possible to call a templated method for - * a MDEventWorkspace using a IMDEventWorkspace_sptr as the input. - * - * @param funcname :: name of the function that will be called. - * @param workspace :: IMDEventWorkspace_sptr input workspace. -*/ - -#define CALL_MDEVENT_FUNCTION3(funcname, workspace) \ - { \ + MDEventWorkspace<MDEvent<1>, 1>::sptr MDEW_MDEVENT_1 = \ + boost::dynamic_pointer_cast<MDEventWorkspace<MDEvent<1>, 1>>( \ + workspace); \ + if (MDEW_MDEVENT_1) \ + funcname<MDEvent<1>, 1>(MDEW_MDEVENT_1); \ + MDEventWorkspace<MDEvent<2>, 2>::sptr MDEW_MDEVENT_2 = \ + boost::dynamic_pointer_cast<MDEventWorkspace<MDEvent<2>, 2>>( \ + workspace); \ + if (MDEW_MDEVENT_2) \ + funcname<MDEvent<2>, 2>(MDEW_MDEVENT_2); \ MDEventWorkspace<MDEvent<3>, 3>::sptr MDEW_MDEVENT_3 = \ boost::dynamic_pointer_cast<MDEventWorkspace<MDEvent<3>, 3>>( \ workspace); \ @@ -285,6 +238,17 @@ private: workspace); \ if (MDEW_MDEVENT_9) \ funcname<MDEvent<9>, 9>(MDEW_MDEVENT_9); \ + } + +/** Macro that makes it possible to call a templated method for + * a MDEventWorkspace using a IMDEventWorkspace_sptr as the input. + * + * @param funcname :: name of the function that will be called. + * @param workspace :: IMDEventWorkspace_sptr input workspace. +*/ + +#define CALL_MDEVENT_FUNCTION3(funcname, workspace) \ + { \ MDEventWorkspace<MDLeanEvent<3>, 3>::sptr MDEW_MDLEANEVENT_3 = \ boost::dynamic_pointer_cast<MDEventWorkspace<MDLeanEvent<3>, 3>>( \ workspace); \ @@ -320,6 +284,41 @@ private: workspace); \ if (MDEW_MDLEANEVENT_9) \ funcname<MDLeanEvent<9>, 9>(MDEW_MDLEANEVENT_9); \ + MDEventWorkspace<MDEvent<3>, 3>::sptr MDEW_MDEVENT_3 = \ + boost::dynamic_pointer_cast<MDEventWorkspace<MDEvent<3>, 3>>( \ + workspace); \ + if (MDEW_MDEVENT_3) \ + funcname<MDEvent<3>, 3>(MDEW_MDEVENT_3); \ + MDEventWorkspace<MDEvent<4>, 4>::sptr MDEW_MDEVENT_4 = \ + boost::dynamic_pointer_cast<MDEventWorkspace<MDEvent<4>, 4>>( \ + workspace); \ + if (MDEW_MDEVENT_4) \ + funcname<MDEvent<4>, 4>(MDEW_MDEVENT_4); \ + MDEventWorkspace<MDEvent<5>, 5>::sptr MDEW_MDEVENT_5 = \ + boost::dynamic_pointer_cast<MDEventWorkspace<MDEvent<5>, 5>>( \ + workspace); \ + if (MDEW_MDEVENT_5) \ + funcname<MDEvent<5>, 5>(MDEW_MDEVENT_5); \ + MDEventWorkspace<MDEvent<6>, 6>::sptr MDEW_MDEVENT_6 = \ + boost::dynamic_pointer_cast<MDEventWorkspace<MDEvent<6>, 6>>( \ + workspace); \ + if (MDEW_MDEVENT_6) \ + funcname<MDEvent<6>, 6>(MDEW_MDEVENT_6); \ + MDEventWorkspace<MDEvent<7>, 7>::sptr MDEW_MDEVENT_7 = \ + boost::dynamic_pointer_cast<MDEventWorkspace<MDEvent<7>, 7>>( \ + workspace); \ + if (MDEW_MDEVENT_7) \ + funcname<MDEvent<7>, 7>(MDEW_MDEVENT_7); \ + MDEventWorkspace<MDEvent<8>, 8>::sptr MDEW_MDEVENT_8 = \ + boost::dynamic_pointer_cast<MDEventWorkspace<MDEvent<8>, 8>>( \ + workspace); \ + if (MDEW_MDEVENT_8) \ + funcname<MDEvent<8>, 8>(MDEW_MDEVENT_8); \ + MDEventWorkspace<MDEvent<9>, 9>::sptr MDEW_MDEVENT_9 = \ + boost::dynamic_pointer_cast<MDEventWorkspace<MDEvent<9>, 9>>( \ + workspace); \ + if (MDEW_MDEVENT_9) \ + funcname<MDEvent<9>, 9>(MDEW_MDEVENT_9); \ } /** Macro that makes it possible to call a templated method for @@ -331,51 +330,6 @@ private: #define CONST_CALL_MDEVENT_FUNCTION(funcname, workspace) \ { \ - const MDEventWorkspace<MDEvent<1>, 1>::sptr CONST_MDEW_MDEVENT_1 = \ - boost::dynamic_pointer_cast<const MDEventWorkspace<MDEvent<1>, 1>>( \ - workspace); \ - if (CONST_MDEW_MDEVENT_1) \ - funcname<MDEvent<1>, 1>(CONST_MDEW_MDEVENT_1); \ - const MDEventWorkspace<MDEvent<2>, 2>::sptr CONST_MDEW_MDEVENT_2 = \ - boost::dynamic_pointer_cast<const MDEventWorkspace<MDEvent<2>, 2>>( \ - workspace); \ - if (CONST_MDEW_MDEVENT_2) \ - funcname<MDEvent<2>, 2>(CONST_MDEW_MDEVENT_2); \ - const MDEventWorkspace<MDEvent<3>, 3>::sptr CONST_MDEW_MDEVENT_3 = \ - boost::dynamic_pointer_cast<const MDEventWorkspace<MDEvent<3>, 3>>( \ - workspace); \ - if (CONST_MDEW_MDEVENT_3) \ - funcname<MDEvent<3>, 3>(CONST_MDEW_MDEVENT_3); \ - const MDEventWorkspace<MDEvent<4>, 4>::sptr CONST_MDEW_MDEVENT_4 = \ - boost::dynamic_pointer_cast<const MDEventWorkspace<MDEvent<4>, 4>>( \ - workspace); \ - if (CONST_MDEW_MDEVENT_4) \ - funcname<MDEvent<4>, 4>(CONST_MDEW_MDEVENT_4); \ - const MDEventWorkspace<MDEvent<5>, 5>::sptr CONST_MDEW_MDEVENT_5 = \ - boost::dynamic_pointer_cast<const MDEventWorkspace<MDEvent<5>, 5>>( \ - workspace); \ - if (CONST_MDEW_MDEVENT_5) \ - funcname<MDEvent<5>, 5>(CONST_MDEW_MDEVENT_5); \ - const MDEventWorkspace<MDEvent<6>, 6>::sptr CONST_MDEW_MDEVENT_6 = \ - boost::dynamic_pointer_cast<const MDEventWorkspace<MDEvent<6>, 6>>( \ - workspace); \ - if (CONST_MDEW_MDEVENT_6) \ - funcname<MDEvent<6>, 6>(CONST_MDEW_MDEVENT_6); \ - const MDEventWorkspace<MDEvent<7>, 7>::sptr CONST_MDEW_MDEVENT_7 = \ - boost::dynamic_pointer_cast<const MDEventWorkspace<MDEvent<7>, 7>>( \ - workspace); \ - if (CONST_MDEW_MDEVENT_7) \ - funcname<MDEvent<7>, 7>(CONST_MDEW_MDEVENT_7); \ - const MDEventWorkspace<MDEvent<8>, 8>::sptr CONST_MDEW_MDEVENT_8 = \ - boost::dynamic_pointer_cast<const MDEventWorkspace<MDEvent<8>, 8>>( \ - workspace); \ - if (CONST_MDEW_MDEVENT_8) \ - funcname<MDEvent<8>, 8>(CONST_MDEW_MDEVENT_8); \ - const MDEventWorkspace<MDEvent<9>, 9>::sptr CONST_MDEW_MDEVENT_9 = \ - boost::dynamic_pointer_cast<const MDEventWorkspace<MDEvent<9>, 9>>( \ - workspace); \ - if (CONST_MDEW_MDEVENT_9) \ - funcname<MDEvent<9>, 9>(CONST_MDEW_MDEVENT_9); \ const MDEventWorkspace<MDLeanEvent<1>, 1>::sptr CONST_MDEW_MDLEANEVENT_1 = \ boost::dynamic_pointer_cast< \ const MDEventWorkspace<MDLeanEvent<1>, 1>>(workspace); \ @@ -421,28 +375,55 @@ private: const MDEventWorkspace<MDLeanEvent<9>, 9>>(workspace); \ if (CONST_MDEW_MDLEANEVENT_9) \ funcname<MDLeanEvent<9>, 9>(CONST_MDEW_MDLEANEVENT_9); \ + const MDEventWorkspace<MDEvent<1>, 1>::sptr CONST_MDEW_MDEVENT_1 = \ + boost::dynamic_pointer_cast<const MDEventWorkspace<MDEvent<1>, 1>>( \ + workspace); \ + if (CONST_MDEW_MDEVENT_1) \ + funcname<MDEvent<1>, 1>(CONST_MDEW_MDEVENT_1); \ + const MDEventWorkspace<MDEvent<2>, 2>::sptr CONST_MDEW_MDEVENT_2 = \ + boost::dynamic_pointer_cast<const MDEventWorkspace<MDEvent<2>, 2>>( \ + workspace); \ + if (CONST_MDEW_MDEVENT_2) \ + funcname<MDEvent<2>, 2>(CONST_MDEW_MDEVENT_2); \ + const MDEventWorkspace<MDEvent<3>, 3>::sptr CONST_MDEW_MDEVENT_3 = \ + boost::dynamic_pointer_cast<const MDEventWorkspace<MDEvent<3>, 3>>( \ + workspace); \ + if (CONST_MDEW_MDEVENT_3) \ + funcname<MDEvent<3>, 3>(CONST_MDEW_MDEVENT_3); \ + const MDEventWorkspace<MDEvent<4>, 4>::sptr CONST_MDEW_MDEVENT_4 = \ + boost::dynamic_pointer_cast<const MDEventWorkspace<MDEvent<4>, 4>>( \ + workspace); \ + if (CONST_MDEW_MDEVENT_4) \ + funcname<MDEvent<4>, 4>(CONST_MDEW_MDEVENT_4); \ + const MDEventWorkspace<MDEvent<5>, 5>::sptr CONST_MDEW_MDEVENT_5 = \ + boost::dynamic_pointer_cast<const MDEventWorkspace<MDEvent<5>, 5>>( \ + workspace); \ + if (CONST_MDEW_MDEVENT_5) \ + funcname<MDEvent<5>, 5>(CONST_MDEW_MDEVENT_5); \ + const MDEventWorkspace<MDEvent<6>, 6>::sptr CONST_MDEW_MDEVENT_6 = \ + boost::dynamic_pointer_cast<const MDEventWorkspace<MDEvent<6>, 6>>( \ + workspace); \ + if (CONST_MDEW_MDEVENT_6) \ + funcname<MDEvent<6>, 6>(CONST_MDEW_MDEVENT_6); \ + const MDEventWorkspace<MDEvent<7>, 7>::sptr CONST_MDEW_MDEVENT_7 = \ + boost::dynamic_pointer_cast<const MDEventWorkspace<MDEvent<7>, 7>>( \ + workspace); \ + if (CONST_MDEW_MDEVENT_7) \ + funcname<MDEvent<7>, 7>(CONST_MDEW_MDEVENT_7); \ + const MDEventWorkspace<MDEvent<8>, 8>::sptr CONST_MDEW_MDEVENT_8 = \ + boost::dynamic_pointer_cast<const MDEventWorkspace<MDEvent<8>, 8>>( \ + workspace); \ + if (CONST_MDEW_MDEVENT_8) \ + funcname<MDEvent<8>, 8>(CONST_MDEW_MDEVENT_8); \ + const MDEventWorkspace<MDEvent<9>, 9>::sptr CONST_MDEW_MDEVENT_9 = \ + boost::dynamic_pointer_cast<const MDEventWorkspace<MDEvent<9>, 9>>( \ + workspace); \ + if (CONST_MDEW_MDEVENT_9) \ + funcname<MDEvent<9>, 9>(CONST_MDEW_MDEVENT_9); \ } // ------------- Typedefs for MDBox ------------------ -/// Typedef for a MDBox with 1 dimension -typedef MDBox<MDEvent<1>, 1> MDBox1; -/// Typedef for a MDBox with 2 dimensions -typedef MDBox<MDEvent<2>, 2> MDBox2; -/// Typedef for a MDBox with 3 dimensions -typedef MDBox<MDEvent<3>, 3> MDBox3; -/// Typedef for a MDBox with 4 dimensions -typedef MDBox<MDEvent<4>, 4> MDBox4; -/// Typedef for a MDBox with 5 dimensions -typedef MDBox<MDEvent<5>, 5> MDBox5; -/// Typedef for a MDBox with 6 dimensions -typedef MDBox<MDEvent<6>, 6> MDBox6; -/// Typedef for a MDBox with 7 dimensions -typedef MDBox<MDEvent<7>, 7> MDBox7; -/// Typedef for a MDBox with 8 dimensions -typedef MDBox<MDEvent<8>, 8> MDBox8; -/// Typedef for a MDBox with 9 dimensions -typedef MDBox<MDEvent<9>, 9> MDBox9; /// Typedef for a MDBox with 1 dimension typedef MDBox<MDLeanEvent<1>, 1> MDBox1Lean; /// Typedef for a MDBox with 2 dimensions @@ -461,27 +442,27 @@ typedef MDBox<MDLeanEvent<7>, 7> MDBox7Lean; typedef MDBox<MDLeanEvent<8>, 8> MDBox8Lean; /// Typedef for a MDBox with 9 dimensions typedef MDBox<MDLeanEvent<9>, 9> MDBox9Lean; +/// Typedef for a MDBox with 1 dimension +typedef MDBox<MDEvent<1>, 1> MDBox1; +/// Typedef for a MDBox with 2 dimensions +typedef MDBox<MDEvent<2>, 2> MDBox2; +/// Typedef for a MDBox with 3 dimensions +typedef MDBox<MDEvent<3>, 3> MDBox3; +/// Typedef for a MDBox with 4 dimensions +typedef MDBox<MDEvent<4>, 4> MDBox4; +/// Typedef for a MDBox with 5 dimensions +typedef MDBox<MDEvent<5>, 5> MDBox5; +/// Typedef for a MDBox with 6 dimensions +typedef MDBox<MDEvent<6>, 6> MDBox6; +/// Typedef for a MDBox with 7 dimensions +typedef MDBox<MDEvent<7>, 7> MDBox7; +/// Typedef for a MDBox with 8 dimensions +typedef MDBox<MDEvent<8>, 8> MDBox8; +/// Typedef for a MDBox with 9 dimensions +typedef MDBox<MDEvent<9>, 9> MDBox9; // ------------- Typedefs for MDBoxBase ------------------ -/// Typedef for a MDBoxBase with 1 dimension -typedef MDBoxBase<MDEvent<1>, 1> MDBoxBase1; -/// Typedef for a MDBoxBase with 2 dimensions -typedef MDBoxBase<MDEvent<2>, 2> MDBoxBase2; -/// Typedef for a MDBoxBase with 3 dimensions -typedef MDBoxBase<MDEvent<3>, 3> MDBoxBase3; -/// Typedef for a MDBoxBase with 4 dimensions -typedef MDBoxBase<MDEvent<4>, 4> MDBoxBase4; -/// Typedef for a MDBoxBase with 5 dimensions -typedef MDBoxBase<MDEvent<5>, 5> MDBoxBase5; -/// Typedef for a MDBoxBase with 6 dimensions -typedef MDBoxBase<MDEvent<6>, 6> MDBoxBase6; -/// Typedef for a MDBoxBase with 7 dimensions -typedef MDBoxBase<MDEvent<7>, 7> MDBoxBase7; -/// Typedef for a MDBoxBase with 8 dimensions -typedef MDBoxBase<MDEvent<8>, 8> MDBoxBase8; -/// Typedef for a MDBoxBase with 9 dimensions -typedef MDBoxBase<MDEvent<9>, 9> MDBoxBase9; /// Typedef for a MDBoxBase with 1 dimension typedef MDBoxBase<MDLeanEvent<1>, 1> MDBoxBase1Lean; /// Typedef for a MDBoxBase with 2 dimensions @@ -500,27 +481,27 @@ typedef MDBoxBase<MDLeanEvent<7>, 7> MDBoxBase7Lean; typedef MDBoxBase<MDLeanEvent<8>, 8> MDBoxBase8Lean; /// Typedef for a MDBoxBase with 9 dimensions typedef MDBoxBase<MDLeanEvent<9>, 9> MDBoxBase9Lean; +/// Typedef for a MDBoxBase with 1 dimension +typedef MDBoxBase<MDEvent<1>, 1> MDBoxBase1; +/// Typedef for a MDBoxBase with 2 dimensions +typedef MDBoxBase<MDEvent<2>, 2> MDBoxBase2; +/// Typedef for a MDBoxBase with 3 dimensions +typedef MDBoxBase<MDEvent<3>, 3> MDBoxBase3; +/// Typedef for a MDBoxBase with 4 dimensions +typedef MDBoxBase<MDEvent<4>, 4> MDBoxBase4; +/// Typedef for a MDBoxBase with 5 dimensions +typedef MDBoxBase<MDEvent<5>, 5> MDBoxBase5; +/// Typedef for a MDBoxBase with 6 dimensions +typedef MDBoxBase<MDEvent<6>, 6> MDBoxBase6; +/// Typedef for a MDBoxBase with 7 dimensions +typedef MDBoxBase<MDEvent<7>, 7> MDBoxBase7; +/// Typedef for a MDBoxBase with 8 dimensions +typedef MDBoxBase<MDEvent<8>, 8> MDBoxBase8; +/// Typedef for a MDBoxBase with 9 dimensions +typedef MDBoxBase<MDEvent<9>, 9> MDBoxBase9; // ------------- Typedefs for MDGridBox ------------------ -/// Typedef for a MDGridBox with 1 dimension -typedef MDGridBox<MDEvent<1>, 1> MDGridBox1; -/// Typedef for a MDGridBox with 2 dimensions -typedef MDGridBox<MDEvent<2>, 2> MDGridBox2; -/// Typedef for a MDGridBox with 3 dimensions -typedef MDGridBox<MDEvent<3>, 3> MDGridBox3; -/// Typedef for a MDGridBox with 4 dimensions -typedef MDGridBox<MDEvent<4>, 4> MDGridBox4; -/// Typedef for a MDGridBox with 5 dimensions -typedef MDGridBox<MDEvent<5>, 5> MDGridBox5; -/// Typedef for a MDGridBox with 6 dimensions -typedef MDGridBox<MDEvent<6>, 6> MDGridBox6; -/// Typedef for a MDGridBox with 7 dimensions -typedef MDGridBox<MDEvent<7>, 7> MDGridBox7; -/// Typedef for a MDGridBox with 8 dimensions -typedef MDGridBox<MDEvent<8>, 8> MDGridBox8; -/// Typedef for a MDGridBox with 9 dimensions -typedef MDGridBox<MDEvent<9>, 9> MDGridBox9; /// Typedef for a MDGridBox with 1 dimension typedef MDGridBox<MDLeanEvent<1>, 1> MDGridBox1Lean; /// Typedef for a MDGridBox with 2 dimensions @@ -539,27 +520,27 @@ typedef MDGridBox<MDLeanEvent<7>, 7> MDGridBox7Lean; typedef MDGridBox<MDLeanEvent<8>, 8> MDGridBox8Lean; /// Typedef for a MDGridBox with 9 dimensions typedef MDGridBox<MDLeanEvent<9>, 9> MDGridBox9Lean; +/// Typedef for a MDGridBox with 1 dimension +typedef MDGridBox<MDEvent<1>, 1> MDGridBox1; +/// Typedef for a MDGridBox with 2 dimensions +typedef MDGridBox<MDEvent<2>, 2> MDGridBox2; +/// Typedef for a MDGridBox with 3 dimensions +typedef MDGridBox<MDEvent<3>, 3> MDGridBox3; +/// Typedef for a MDGridBox with 4 dimensions +typedef MDGridBox<MDEvent<4>, 4> MDGridBox4; +/// Typedef for a MDGridBox with 5 dimensions +typedef MDGridBox<MDEvent<5>, 5> MDGridBox5; +/// Typedef for a MDGridBox with 6 dimensions +typedef MDGridBox<MDEvent<6>, 6> MDGridBox6; +/// Typedef for a MDGridBox with 7 dimensions +typedef MDGridBox<MDEvent<7>, 7> MDGridBox7; +/// Typedef for a MDGridBox with 8 dimensions +typedef MDGridBox<MDEvent<8>, 8> MDGridBox8; +/// Typedef for a MDGridBox with 9 dimensions +typedef MDGridBox<MDEvent<9>, 9> MDGridBox9; // ------------- Typedefs for MDEventWorkspace ------------------ -/// Typedef for a MDEventWorkspace with 1 dimension -typedef MDEventWorkspace<MDEvent<1>, 1> MDEventWorkspace1; -/// Typedef for a MDEventWorkspace with 2 dimensions -typedef MDEventWorkspace<MDEvent<2>, 2> MDEventWorkspace2; -/// Typedef for a MDEventWorkspace with 3 dimensions -typedef MDEventWorkspace<MDEvent<3>, 3> MDEventWorkspace3; -/// Typedef for a MDEventWorkspace with 4 dimensions -typedef MDEventWorkspace<MDEvent<4>, 4> MDEventWorkspace4; -/// Typedef for a MDEventWorkspace with 5 dimensions -typedef MDEventWorkspace<MDEvent<5>, 5> MDEventWorkspace5; -/// Typedef for a MDEventWorkspace with 6 dimensions -typedef MDEventWorkspace<MDEvent<6>, 6> MDEventWorkspace6; -/// Typedef for a MDEventWorkspace with 7 dimensions -typedef MDEventWorkspace<MDEvent<7>, 7> MDEventWorkspace7; -/// Typedef for a MDEventWorkspace with 8 dimensions -typedef MDEventWorkspace<MDEvent<8>, 8> MDEventWorkspace8; -/// Typedef for a MDEventWorkspace with 9 dimensions -typedef MDEventWorkspace<MDEvent<9>, 9> MDEventWorkspace9; /// Typedef for a MDEventWorkspace with 1 dimension typedef MDEventWorkspace<MDLeanEvent<1>, 1> MDEventWorkspace1Lean; /// Typedef for a MDEventWorkspace with 2 dimensions @@ -578,27 +559,27 @@ typedef MDEventWorkspace<MDLeanEvent<7>, 7> MDEventWorkspace7Lean; typedef MDEventWorkspace<MDLeanEvent<8>, 8> MDEventWorkspace8Lean; /// Typedef for a MDEventWorkspace with 9 dimensions typedef MDEventWorkspace<MDLeanEvent<9>, 9> MDEventWorkspace9Lean; +/// Typedef for a MDEventWorkspace with 1 dimension +typedef MDEventWorkspace<MDEvent<1>, 1> MDEventWorkspace1; +/// Typedef for a MDEventWorkspace with 2 dimensions +typedef MDEventWorkspace<MDEvent<2>, 2> MDEventWorkspace2; +/// Typedef for a MDEventWorkspace with 3 dimensions +typedef MDEventWorkspace<MDEvent<3>, 3> MDEventWorkspace3; +/// Typedef for a MDEventWorkspace with 4 dimensions +typedef MDEventWorkspace<MDEvent<4>, 4> MDEventWorkspace4; +/// Typedef for a MDEventWorkspace with 5 dimensions +typedef MDEventWorkspace<MDEvent<5>, 5> MDEventWorkspace5; +/// Typedef for a MDEventWorkspace with 6 dimensions +typedef MDEventWorkspace<MDEvent<6>, 6> MDEventWorkspace6; +/// Typedef for a MDEventWorkspace with 7 dimensions +typedef MDEventWorkspace<MDEvent<7>, 7> MDEventWorkspace7; +/// Typedef for a MDEventWorkspace with 8 dimensions +typedef MDEventWorkspace<MDEvent<8>, 8> MDEventWorkspace8; +/// Typedef for a MDEventWorkspace with 9 dimensions +typedef MDEventWorkspace<MDEvent<9>, 9> MDEventWorkspace9; // ------------- Typedefs for MDBin ------------------ -/// Typedef for a MDBin with 1 dimension -typedef MDBin<MDEvent<1>, 1> MDBin1; -/// Typedef for a MDBin with 2 dimensions -typedef MDBin<MDEvent<2>, 2> MDBin2; -/// Typedef for a MDBin with 3 dimensions -typedef MDBin<MDEvent<3>, 3> MDBin3; -/// Typedef for a MDBin with 4 dimensions -typedef MDBin<MDEvent<4>, 4> MDBin4; -/// Typedef for a MDBin with 5 dimensions -typedef MDBin<MDEvent<5>, 5> MDBin5; -/// Typedef for a MDBin with 6 dimensions -typedef MDBin<MDEvent<6>, 6> MDBin6; -/// Typedef for a MDBin with 7 dimensions -typedef MDBin<MDEvent<7>, 7> MDBin7; -/// Typedef for a MDBin with 8 dimensions -typedef MDBin<MDEvent<8>, 8> MDBin8; -/// Typedef for a MDBin with 9 dimensions -typedef MDBin<MDEvent<9>, 9> MDBin9; /// Typedef for a MDBin with 1 dimension typedef MDBin<MDLeanEvent<1>, 1> MDBin1Lean; /// Typedef for a MDBin with 2 dimensions @@ -617,6 +598,24 @@ typedef MDBin<MDLeanEvent<7>, 7> MDBin7Lean; typedef MDBin<MDLeanEvent<8>, 8> MDBin8Lean; /// Typedef for a MDBin with 9 dimensions typedef MDBin<MDLeanEvent<9>, 9> MDBin9Lean; +/// Typedef for a MDBin with 1 dimension +typedef MDBin<MDEvent<1>, 1> MDBin1; +/// Typedef for a MDBin with 2 dimensions +typedef MDBin<MDEvent<2>, 2> MDBin2; +/// Typedef for a MDBin with 3 dimensions +typedef MDBin<MDEvent<3>, 3> MDBin3; +/// Typedef for a MDBin with 4 dimensions +typedef MDBin<MDEvent<4>, 4> MDBin4; +/// Typedef for a MDBin with 5 dimensions +typedef MDBin<MDEvent<5>, 5> MDBin5; +/// Typedef for a MDBin with 6 dimensions +typedef MDBin<MDEvent<6>, 6> MDBin6; +/// Typedef for a MDBin with 7 dimensions +typedef MDBin<MDEvent<7>, 7> MDBin7; +/// Typedef for a MDBin with 8 dimensions +typedef MDBin<MDEvent<8>, 8> MDBin8; +/// Typedef for a MDBin with 9 dimensions +typedef MDBin<MDEvent<9>, 9> MDBin9; /* CODE ABOWE WAS AUTO-GENERATED BY generate_mdevent_declarations.py - DO NOT * EDIT! */ diff --git a/Framework/DataObjects/inc/MantidDataObjects/MDLeanEvent.h b/Framework/DataObjects/inc/MantidDataObjects/MDLeanEvent.h index f91764777ef0501fde68122d84d30d6453594964..7da1bb3b3e5973dc9c7b813680b27949dcc3ee1c 100644 --- a/Framework/DataObjects/inc/MantidDataObjects/MDLeanEvent.h +++ b/Framework/DataObjects/inc/MantidDataObjects/MDLeanEvent.h @@ -297,8 +297,8 @@ public: const coord_t *centers = &(coord[ii + 2]); // Create the event with signal, error squared, and the centers - events.push_back(MDLeanEvent<nd>(signal_t(coord[ii]), - signal_t(coord[ii + 1]), centers)); + events.emplace_back(static_cast<signal_t>(coord[ii]), + static_cast<signal_t>(coord[ii + 1]), centers); } } }; diff --git a/Framework/DataObjects/inc/MantidDataObjects/TableColumn.h b/Framework/DataObjects/inc/MantidDataObjects/TableColumn.h index edefcc18e475bec3a2617c54e91b5512d5d5ccbb..d0d16857279150e892c2cff27fdab63fcfe638f4 100644 --- a/Framework/DataObjects/inc/MantidDataObjects/TableColumn.h +++ b/Framework/DataObjects/inc/MantidDataObjects/TableColumn.h @@ -216,7 +216,7 @@ protected: if (index < m_data.size()) m_data.insert(m_data.begin() + index, Type()); else - m_data.push_back(Type()); + m_data.emplace_back(); } /// Removes an item at index. void remove(size_t index) override { m_data.erase(m_data.begin() + index); } diff --git a/Framework/DataObjects/src/EventList.cpp b/Framework/DataObjects/src/EventList.cpp index aca4dcb9bd6dee1653ef7510d80332ac4d7e5372..2f6d4e28e94a733d19427908c2c83481acbeebd8 100644 --- a/Framework/DataObjects/src/EventList.cpp +++ b/Framework/DataObjects/src/EventList.cpp @@ -249,8 +249,7 @@ void EventList::createFromHistogram(const ISpectrum *inSpec, bool GenerateZeros, double tof = X[i] + tofStep * (0.5 + double(j)); // Create and add the event // TODO: try emplace_back() here. - weightedEventsNoTime.push_back( - WeightedEventNoTime(tof, weight, errorSquared)); + weightedEventsNoTime.emplace_back(tof, weight, errorSquared); } } else { // --------- Single event per bin ---------- @@ -260,8 +259,7 @@ void EventList::createFromHistogram(const ISpectrum *inSpec, bool GenerateZeros, double errorSquared = E[i]; errorSquared *= errorSquared; // Create and add the event - weightedEventsNoTime.push_back( - WeightedEventNoTime(tof, weight, errorSquared)); + weightedEventsNoTime.emplace_back(tof, weight, errorSquared); } } // error is nont NAN or infinite } // weight is non-zero, not NAN, and non-infinite @@ -308,11 +306,11 @@ EventList &EventList::operator+=(const TofEvent &event) { break; case WEIGHTED: - this->weightedEvents.push_back(WeightedEvent(event)); + this->weightedEvents.emplace_back(event); break; case WEIGHTED_NOTIME: - this->weightedEventsNoTime.push_back(WeightedEventNoTime(event)); + this->weightedEventsNoTime.emplace_back(event); break; } @@ -685,14 +683,9 @@ void EventList::switchToWeightedEvents() { break; case TOF: - weightedEvents.clear(); weightedEventsNoTime.clear(); // Convert and copy all TofEvents to the weightedEvents list. - std::vector<TofEvent>::const_iterator it; - std::vector<TofEvent>::const_iterator it_end = - events.end(); // Cache for speed - for (it = events.begin(); it != it_end; ++it) - this->weightedEvents.push_back(WeightedEvent(*it)); + this->weightedEvents.assign(events.cbegin(), events.cend()); // Get rid of the old events events.clear(); eventType = WEIGHTED; @@ -712,12 +705,7 @@ void EventList::switchToWeightedEventsNoTime() { case TOF: { // Convert and copy all TofEvents to the weightedEvents list. - weightedEventsNoTime.clear(); - std::vector<TofEvent>::const_iterator it; - std::vector<TofEvent>::const_iterator it_end = - events.end(); // Cache for speed - for (it = events.begin(); it != it_end; ++it) - this->weightedEventsNoTime.push_back(WeightedEventNoTime(*it)); + this->weightedEventsNoTime.assign(events.cbegin(), events.cend()); // Get rid of the old events events.clear(); weightedEvents.clear(); @@ -726,12 +714,8 @@ void EventList::switchToWeightedEventsNoTime() { case WEIGHTED: { // Convert and copy all TofEvents to the weightedEvents list. - weightedEventsNoTime.clear(); - std::vector<WeightedEvent>::const_iterator it; - std::vector<WeightedEvent>::const_iterator it_end = - weightedEvents.end(); // Cache for speed - for (it = weightedEvents.begin(); it != it_end; ++it) - this->weightedEventsNoTime.push_back(WeightedEventNoTime(*it)); + this->weightedEventsNoTime.assign(weightedEvents.cbegin(), + weightedEvents.cend()); // Get rid of the old events events.clear(); weightedEvents.clear(); @@ -1676,8 +1660,7 @@ EventList::compressEventsHelper(const std::vector<T> &events, if (num > 0) { // Create a new event with the average TOF and summed weights and // squared errors. - out.push_back( - WeightedEventNoTime(totalTof / num, weight, errorSquared)); + out.emplace_back(totalTof / num, weight, errorSquared); } // Start a new combined object num = 1; @@ -1692,7 +1675,7 @@ EventList::compressEventsHelper(const std::vector<T> &events, if (num > 0) { // Create a new event with the average TOF and summed weights and squared // errors. - out.push_back(WeightedEventNoTime(totalTof / num, weight, errorSquared)); + out.emplace_back(totalTof / num, weight, errorSquared); } // If you have over-allocated by more than 5%, reduce the size. @@ -1761,8 +1744,7 @@ void EventList::compressEventsParallelHelper( if (num > 0) { // Create a new event with the average TOF and summed weights and // squared errors. - localOut.push_back( - WeightedEventNoTime(totalTof / num, weight, errorSquared)); + localOut.emplace_back(totalTof / num, weight, errorSquared); } // Start a new combined object num = 1; @@ -1777,8 +1759,7 @@ void EventList::compressEventsParallelHelper( if (num > 0) { // Create a new event with the average TOF and summed weights and squared // errors. - localOut.push_back( - WeightedEventNoTime(totalTof / num, weight, errorSquared)); + localOut.emplace_back(totalTof / num, weight, errorSquared); } } diff --git a/Framework/DataObjects/src/EventWorkspace.cpp b/Framework/DataObjects/src/EventWorkspace.cpp index 72de1075f25fbfa13b32fd99b4e7d04982ef3f05..250b5734b272024a9a57024601a614c5d4bdeaf4 100644 --- a/Framework/DataObjects/src/EventWorkspace.cpp +++ b/Framework/DataObjects/src/EventWorkspace.cpp @@ -879,8 +879,8 @@ void EventWorkspace::getIntegratedSpectra(std::vector<double> &out, } // namespace Mantid ///\cond TEMPLATE -template DLLExport class Mantid::API::WorkspaceProperty< - Mantid::DataObjects::EventWorkspace>; +template class DLLExport + Mantid::API::WorkspaceProperty<Mantid::DataObjects::EventWorkspace>; namespace Mantid { namespace Kernel { diff --git a/Framework/DataObjects/src/MDEventFactory.cpp b/Framework/DataObjects/src/MDEventFactory.cpp index ed506943b9a3aae9813e365fc23e0cd3801d3450..7d61b9210739894d1a30f3df4e92fdbd7e7d29dd 100644 --- a/Framework/DataObjects/src/MDEventFactory.cpp +++ b/Framework/DataObjects/src/MDEventFactory.cpp @@ -25,152 +25,151 @@ namespace Mantid { namespace DataObjects { //### BEGIN AUTO-GENERATED CODE -//################################################################# /* Code below Auto-generated by 'generate_mdevent_declarations.py' - * on 2013-05-30 12:36:57.329000 + * on 2016-06-03 10:28:44.608989 * * DO NOT EDIT! */ -// Instantiations for MDEvent -template DLLExport class MDEvent<1>; -template DLLExport class MDEvent<2>; -template DLLExport class MDEvent<3>; -template DLLExport class MDEvent<4>; -template DLLExport class MDEvent<5>; -template DLLExport class MDEvent<6>; -template DLLExport class MDEvent<7>; -template DLLExport class MDEvent<8>; -template DLLExport class MDEvent<9>; // Instantiations for MDLeanEvent -template DLLExport class MDLeanEvent<1>; -template DLLExport class MDLeanEvent<2>; -template DLLExport class MDLeanEvent<3>; -template DLLExport class MDLeanEvent<4>; -template DLLExport class MDLeanEvent<5>; -template DLLExport class MDLeanEvent<6>; -template DLLExport class MDLeanEvent<7>; -template DLLExport class MDLeanEvent<8>; -template DLLExport class MDLeanEvent<9>; +template class DLLExport MDLeanEvent<1>; +template class DLLExport MDLeanEvent<2>; +template class DLLExport MDLeanEvent<3>; +template class DLLExport MDLeanEvent<4>; +template class DLLExport MDLeanEvent<5>; +template class DLLExport MDLeanEvent<6>; +template class DLLExport MDLeanEvent<7>; +template class DLLExport MDLeanEvent<8>; +template class DLLExport MDLeanEvent<9>; +// Instantiations for MDEvent +template class DLLExport MDEvent<1>; +template class DLLExport MDEvent<2>; +template class DLLExport MDEvent<3>; +template class DLLExport MDEvent<4>; +template class DLLExport MDEvent<5>; +template class DLLExport MDEvent<6>; +template class DLLExport MDEvent<7>; +template class DLLExport MDEvent<8>; +template class DLLExport MDEvent<9>; // Instantiations for MDBoxBase -template DLLExport class MDBoxBase<MDEvent<1>, 1>; -template DLLExport class MDBoxBase<MDEvent<2>, 2>; -template DLLExport class MDBoxBase<MDEvent<3>, 3>; -template DLLExport class MDBoxBase<MDEvent<4>, 4>; -template DLLExport class MDBoxBase<MDEvent<5>, 5>; -template DLLExport class MDBoxBase<MDEvent<6>, 6>; -template DLLExport class MDBoxBase<MDEvent<7>, 7>; -template DLLExport class MDBoxBase<MDEvent<8>, 8>; -template DLLExport class MDBoxBase<MDEvent<9>, 9>; -template DLLExport class MDBoxBase<MDLeanEvent<1>, 1>; -template DLLExport class MDBoxBase<MDLeanEvent<2>, 2>; -template DLLExport class MDBoxBase<MDLeanEvent<3>, 3>; -template DLLExport class MDBoxBase<MDLeanEvent<4>, 4>; -template DLLExport class MDBoxBase<MDLeanEvent<5>, 5>; -template DLLExport class MDBoxBase<MDLeanEvent<6>, 6>; -template DLLExport class MDBoxBase<MDLeanEvent<7>, 7>; -template DLLExport class MDBoxBase<MDLeanEvent<8>, 8>; -template DLLExport class MDBoxBase<MDLeanEvent<9>, 9>; +template class DLLExport MDBoxBase<MDLeanEvent<1>, 1>; +template class DLLExport MDBoxBase<MDLeanEvent<2>, 2>; +template class DLLExport MDBoxBase<MDLeanEvent<3>, 3>; +template class DLLExport MDBoxBase<MDLeanEvent<4>, 4>; +template class DLLExport MDBoxBase<MDLeanEvent<5>, 5>; +template class DLLExport MDBoxBase<MDLeanEvent<6>, 6>; +template class DLLExport MDBoxBase<MDLeanEvent<7>, 7>; +template class DLLExport MDBoxBase<MDLeanEvent<8>, 8>; +template class DLLExport MDBoxBase<MDLeanEvent<9>, 9>; +template class DLLExport MDBoxBase<MDEvent<1>, 1>; +template class DLLExport MDBoxBase<MDEvent<2>, 2>; +template class DLLExport MDBoxBase<MDEvent<3>, 3>; +template class DLLExport MDBoxBase<MDEvent<4>, 4>; +template class DLLExport MDBoxBase<MDEvent<5>, 5>; +template class DLLExport MDBoxBase<MDEvent<6>, 6>; +template class DLLExport MDBoxBase<MDEvent<7>, 7>; +template class DLLExport MDBoxBase<MDEvent<8>, 8>; +template class DLLExport MDBoxBase<MDEvent<9>, 9>; // Instantiations for MDBox -template DLLExport class MDBox<MDEvent<1>, 1>; -template DLLExport class MDBox<MDEvent<2>, 2>; -template DLLExport class MDBox<MDEvent<3>, 3>; -template DLLExport class MDBox<MDEvent<4>, 4>; -template DLLExport class MDBox<MDEvent<5>, 5>; -template DLLExport class MDBox<MDEvent<6>, 6>; -template DLLExport class MDBox<MDEvent<7>, 7>; -template DLLExport class MDBox<MDEvent<8>, 8>; -template DLLExport class MDBox<MDEvent<9>, 9>; -template DLLExport class MDBox<MDLeanEvent<1>, 1>; -template DLLExport class MDBox<MDLeanEvent<2>, 2>; -template DLLExport class MDBox<MDLeanEvent<3>, 3>; -template DLLExport class MDBox<MDLeanEvent<4>, 4>; -template DLLExport class MDBox<MDLeanEvent<5>, 5>; -template DLLExport class MDBox<MDLeanEvent<6>, 6>; -template DLLExport class MDBox<MDLeanEvent<7>, 7>; -template DLLExport class MDBox<MDLeanEvent<8>, 8>; -template DLLExport class MDBox<MDLeanEvent<9>, 9>; +template class DLLExport MDBox<MDLeanEvent<1>, 1>; +template class DLLExport MDBox<MDLeanEvent<2>, 2>; +template class DLLExport MDBox<MDLeanEvent<3>, 3>; +template class DLLExport MDBox<MDLeanEvent<4>, 4>; +template class DLLExport MDBox<MDLeanEvent<5>, 5>; +template class DLLExport MDBox<MDLeanEvent<6>, 6>; +template class DLLExport MDBox<MDLeanEvent<7>, 7>; +template class DLLExport MDBox<MDLeanEvent<8>, 8>; +template class DLLExport MDBox<MDLeanEvent<9>, 9>; +template class DLLExport MDBox<MDEvent<1>, 1>; +template class DLLExport MDBox<MDEvent<2>, 2>; +template class DLLExport MDBox<MDEvent<3>, 3>; +template class DLLExport MDBox<MDEvent<4>, 4>; +template class DLLExport MDBox<MDEvent<5>, 5>; +template class DLLExport MDBox<MDEvent<6>, 6>; +template class DLLExport MDBox<MDEvent<7>, 7>; +template class DLLExport MDBox<MDEvent<8>, 8>; +template class DLLExport MDBox<MDEvent<9>, 9>; // Instantiations for MDEventWorkspace -template DLLExport class MDEventWorkspace<MDEvent<1>, 1>; -template DLLExport class MDEventWorkspace<MDEvent<2>, 2>; -template DLLExport class MDEventWorkspace<MDEvent<3>, 3>; -template DLLExport class MDEventWorkspace<MDEvent<4>, 4>; -template DLLExport class MDEventWorkspace<MDEvent<5>, 5>; -template DLLExport class MDEventWorkspace<MDEvent<6>, 6>; -template DLLExport class MDEventWorkspace<MDEvent<7>, 7>; -template DLLExport class MDEventWorkspace<MDEvent<8>, 8>; -template DLLExport class MDEventWorkspace<MDEvent<9>, 9>; -template DLLExport class MDEventWorkspace<MDLeanEvent<1>, 1>; -template DLLExport class MDEventWorkspace<MDLeanEvent<2>, 2>; -template DLLExport class MDEventWorkspace<MDLeanEvent<3>, 3>; -template DLLExport class MDEventWorkspace<MDLeanEvent<4>, 4>; -template DLLExport class MDEventWorkspace<MDLeanEvent<5>, 5>; -template DLLExport class MDEventWorkspace<MDLeanEvent<6>, 6>; -template DLLExport class MDEventWorkspace<MDLeanEvent<7>, 7>; -template DLLExport class MDEventWorkspace<MDLeanEvent<8>, 8>; -template DLLExport class MDEventWorkspace<MDLeanEvent<9>, 9>; +template class DLLExport MDEventWorkspace<MDLeanEvent<1>, 1>; +template class DLLExport MDEventWorkspace<MDLeanEvent<2>, 2>; +template class DLLExport MDEventWorkspace<MDLeanEvent<3>, 3>; +template class DLLExport MDEventWorkspace<MDLeanEvent<4>, 4>; +template class DLLExport MDEventWorkspace<MDLeanEvent<5>, 5>; +template class DLLExport MDEventWorkspace<MDLeanEvent<6>, 6>; +template class DLLExport MDEventWorkspace<MDLeanEvent<7>, 7>; +template class DLLExport MDEventWorkspace<MDLeanEvent<8>, 8>; +template class DLLExport MDEventWorkspace<MDLeanEvent<9>, 9>; +template class DLLExport MDEventWorkspace<MDEvent<1>, 1>; +template class DLLExport MDEventWorkspace<MDEvent<2>, 2>; +template class DLLExport MDEventWorkspace<MDEvent<3>, 3>; +template class DLLExport MDEventWorkspace<MDEvent<4>, 4>; +template class DLLExport MDEventWorkspace<MDEvent<5>, 5>; +template class DLLExport MDEventWorkspace<MDEvent<6>, 6>; +template class DLLExport MDEventWorkspace<MDEvent<7>, 7>; +template class DLLExport MDEventWorkspace<MDEvent<8>, 8>; +template class DLLExport MDEventWorkspace<MDEvent<9>, 9>; // Instantiations for MDGridBox -template DLLExport class MDGridBox<MDEvent<1>, 1>; -template DLLExport class MDGridBox<MDEvent<2>, 2>; -template DLLExport class MDGridBox<MDEvent<3>, 3>; -template DLLExport class MDGridBox<MDEvent<4>, 4>; -template DLLExport class MDGridBox<MDEvent<5>, 5>; -template DLLExport class MDGridBox<MDEvent<6>, 6>; -template DLLExport class MDGridBox<MDEvent<7>, 7>; -template DLLExport class MDGridBox<MDEvent<8>, 8>; -template DLLExport class MDGridBox<MDEvent<9>, 9>; -template DLLExport class MDGridBox<MDLeanEvent<1>, 1>; -template DLLExport class MDGridBox<MDLeanEvent<2>, 2>; -template DLLExport class MDGridBox<MDLeanEvent<3>, 3>; -template DLLExport class MDGridBox<MDLeanEvent<4>, 4>; -template DLLExport class MDGridBox<MDLeanEvent<5>, 5>; -template DLLExport class MDGridBox<MDLeanEvent<6>, 6>; -template DLLExport class MDGridBox<MDLeanEvent<7>, 7>; -template DLLExport class MDGridBox<MDLeanEvent<8>, 8>; -template DLLExport class MDGridBox<MDLeanEvent<9>, 9>; +template class DLLExport MDGridBox<MDLeanEvent<1>, 1>; +template class DLLExport MDGridBox<MDLeanEvent<2>, 2>; +template class DLLExport MDGridBox<MDLeanEvent<3>, 3>; +template class DLLExport MDGridBox<MDLeanEvent<4>, 4>; +template class DLLExport MDGridBox<MDLeanEvent<5>, 5>; +template class DLLExport MDGridBox<MDLeanEvent<6>, 6>; +template class DLLExport MDGridBox<MDLeanEvent<7>, 7>; +template class DLLExport MDGridBox<MDLeanEvent<8>, 8>; +template class DLLExport MDGridBox<MDLeanEvent<9>, 9>; +template class DLLExport MDGridBox<MDEvent<1>, 1>; +template class DLLExport MDGridBox<MDEvent<2>, 2>; +template class DLLExport MDGridBox<MDEvent<3>, 3>; +template class DLLExport MDGridBox<MDEvent<4>, 4>; +template class DLLExport MDGridBox<MDEvent<5>, 5>; +template class DLLExport MDGridBox<MDEvent<6>, 6>; +template class DLLExport MDGridBox<MDEvent<7>, 7>; +template class DLLExport MDGridBox<MDEvent<8>, 8>; +template class DLLExport MDGridBox<MDEvent<9>, 9>; // Instantiations for MDBin -template DLLExport class MDBin<MDEvent<1>, 1>; -template DLLExport class MDBin<MDEvent<2>, 2>; -template DLLExport class MDBin<MDEvent<3>, 3>; -template DLLExport class MDBin<MDEvent<4>, 4>; -template DLLExport class MDBin<MDEvent<5>, 5>; -template DLLExport class MDBin<MDEvent<6>, 6>; -template DLLExport class MDBin<MDEvent<7>, 7>; -template DLLExport class MDBin<MDEvent<8>, 8>; -template DLLExport class MDBin<MDEvent<9>, 9>; -template DLLExport class MDBin<MDLeanEvent<1>, 1>; -template DLLExport class MDBin<MDLeanEvent<2>, 2>; -template DLLExport class MDBin<MDLeanEvent<3>, 3>; -template DLLExport class MDBin<MDLeanEvent<4>, 4>; -template DLLExport class MDBin<MDLeanEvent<5>, 5>; -template DLLExport class MDBin<MDLeanEvent<6>, 6>; -template DLLExport class MDBin<MDLeanEvent<7>, 7>; -template DLLExport class MDBin<MDLeanEvent<8>, 8>; -template DLLExport class MDBin<MDLeanEvent<9>, 9>; +template class DLLExport MDBin<MDLeanEvent<1>, 1>; +template class DLLExport MDBin<MDLeanEvent<2>, 2>; +template class DLLExport MDBin<MDLeanEvent<3>, 3>; +template class DLLExport MDBin<MDLeanEvent<4>, 4>; +template class DLLExport MDBin<MDLeanEvent<5>, 5>; +template class DLLExport MDBin<MDLeanEvent<6>, 6>; +template class DLLExport MDBin<MDLeanEvent<7>, 7>; +template class DLLExport MDBin<MDLeanEvent<8>, 8>; +template class DLLExport MDBin<MDLeanEvent<9>, 9>; +template class DLLExport MDBin<MDEvent<1>, 1>; +template class DLLExport MDBin<MDEvent<2>, 2>; +template class DLLExport MDBin<MDEvent<3>, 3>; +template class DLLExport MDBin<MDEvent<4>, 4>; +template class DLLExport MDBin<MDEvent<5>, 5>; +template class DLLExport MDBin<MDEvent<6>, 6>; +template class DLLExport MDBin<MDEvent<7>, 7>; +template class DLLExport MDBin<MDEvent<8>, 8>; +template class DLLExport MDBin<MDEvent<9>, 9>; // Instantiations for MDBoxIterator -template DLLExport class MDBoxIterator<MDEvent<1>, 1>; -template DLLExport class MDBoxIterator<MDEvent<2>, 2>; -template DLLExport class MDBoxIterator<MDEvent<3>, 3>; -template DLLExport class MDBoxIterator<MDEvent<4>, 4>; -template DLLExport class MDBoxIterator<MDEvent<5>, 5>; -template DLLExport class MDBoxIterator<MDEvent<6>, 6>; -template DLLExport class MDBoxIterator<MDEvent<7>, 7>; -template DLLExport class MDBoxIterator<MDEvent<8>, 8>; -template DLLExport class MDBoxIterator<MDEvent<9>, 9>; -template DLLExport class MDBoxIterator<MDLeanEvent<1>, 1>; -template DLLExport class MDBoxIterator<MDLeanEvent<2>, 2>; -template DLLExport class MDBoxIterator<MDLeanEvent<3>, 3>; -template DLLExport class MDBoxIterator<MDLeanEvent<4>, 4>; -template DLLExport class MDBoxIterator<MDLeanEvent<5>, 5>; -template DLLExport class MDBoxIterator<MDLeanEvent<6>, 6>; -template DLLExport class MDBoxIterator<MDLeanEvent<7>, 7>; -template DLLExport class MDBoxIterator<MDLeanEvent<8>, 8>; -template DLLExport class MDBoxIterator<MDLeanEvent<9>, 9>; +template class DLLExport MDBoxIterator<MDLeanEvent<1>, 1>; +template class DLLExport MDBoxIterator<MDLeanEvent<2>, 2>; +template class DLLExport MDBoxIterator<MDLeanEvent<3>, 3>; +template class DLLExport MDBoxIterator<MDLeanEvent<4>, 4>; +template class DLLExport MDBoxIterator<MDLeanEvent<5>, 5>; +template class DLLExport MDBoxIterator<MDLeanEvent<6>, 6>; +template class DLLExport MDBoxIterator<MDLeanEvent<7>, 7>; +template class DLLExport MDBoxIterator<MDLeanEvent<8>, 8>; +template class DLLExport MDBoxIterator<MDLeanEvent<9>, 9>; +template class DLLExport MDBoxIterator<MDEvent<1>, 1>; +template class DLLExport MDBoxIterator<MDEvent<2>, 2>; +template class DLLExport MDBoxIterator<MDEvent<3>, 3>; +template class DLLExport MDBoxIterator<MDEvent<4>, 4>; +template class DLLExport MDBoxIterator<MDEvent<5>, 5>; +template class DLLExport MDBoxIterator<MDEvent<6>, 6>; +template class DLLExport MDBoxIterator<MDEvent<7>, 7>; +template class DLLExport MDBoxIterator<MDEvent<8>, 8>; +template class DLLExport MDBoxIterator<MDEvent<9>, 9>; /* CODE ABOWE WAS AUTO-GENERATED BY generate_mdevent_declarations.py - DO NOT * EDIT! */ diff --git a/Framework/DataObjects/src/Workspace2D.cpp b/Framework/DataObjects/src/Workspace2D.cpp index cae60d1028b281cc3e58cc7b73a82f48b9a079ab..ace3bdc1dea77347c3e0564f3ab5f3f38140e769 100644 --- a/Framework/DataObjects/src/Workspace2D.cpp +++ b/Framework/DataObjects/src/Workspace2D.cpp @@ -316,8 +316,8 @@ void Workspace2D::generateHistogram(const std::size_t index, const MantidVec &X, } // NamespaceMantid ///\cond TEMPLATE -template DLLExport class Mantid::API::WorkspaceProperty< - Mantid::DataObjects::Workspace2D>; +template class DLLExport + Mantid::API::WorkspaceProperty<Mantid::DataObjects::Workspace2D>; namespace Mantid { namespace Kernel { diff --git a/Framework/DataObjects/src/WorkspaceSingleValue.cpp b/Framework/DataObjects/src/WorkspaceSingleValue.cpp index 115a5a70cf73789219b78c48cf2dd5b91207e83b..26088dfd7f6da7225c9899343cfc01111133bb18 100644 --- a/Framework/DataObjects/src/WorkspaceSingleValue.cpp +++ b/Framework/DataObjects/src/WorkspaceSingleValue.cpp @@ -73,8 +73,8 @@ size_t WorkspaceSingleValue::getNumDims() const { return 0; } ///\cond TEMPLATE -template DLLExport class Mantid::API::WorkspaceProperty< - Mantid::DataObjects::WorkspaceSingleValue>; +template class DLLExport + Mantid::API::WorkspaceProperty<Mantid::DataObjects::WorkspaceSingleValue>; namespace Mantid { namespace Kernel { diff --git a/Framework/DataObjects/src/generate_mdevent_declarations.py b/Framework/DataObjects/src/generate_mdevent_declarations.py index 4f0eede0b83b6d230df866556c395d2d76b0de99..0ba66aacd29352e3d656734701182a4d4537524a 100644 --- a/Framework/DataObjects/src/generate_mdevent_declarations.py +++ b/Framework/DataObjects/src/generate_mdevent_declarations.py @@ -7,7 +7,7 @@ import datetime import re # List of every possible MDEvent or MDLeanEvent types. -mdevent_types = ["MDEvent", "MDLeanEvent"] +mdevent_types = ["MDLeanEvent", "MDEvent"] header = """/* Code below Auto-generated by '%s' * on %s @@ -160,8 +160,8 @@ def generate(): classes = classes_cpp + mdevent_types padding,lines,lines_after=parse_file("../inc/MantidDataObjects/MDEventFactory.h", - "//### BEGIN AUTO-GENERATED CODE ###", - "//### END AUTO-GENERATED CODE ###"); + "//### BEGIN AUTO-GENERATED CODE", + "//### END AUTO-GENERATED CODE"); nDim = int(find_num_dim(lines)); print " numDimensions to be generated: ",nDim @@ -189,18 +189,17 @@ def generate(): classes = ["MDBox", "MDBoxBase", "MDGridBox", "MDEventWorkspace", "MDBin"] for c in classes: lines.append("\n%s// ------------- Typedefs for %s ------------------\n" % (padding, c)); - mdevent_type = "MDEvent" - for nd in dimensions: - lines.append("%s/// Typedef for a %s with %d dimension%s " % (padding,c, nd, ['','s'][nd>1]) ) - lines.append("%stypedef %s<%s<%d>, %d> %s%d;" % (padding,c, mdevent_type, nd, nd, c, nd) ) mdevent_type = "MDLeanEvent" for nd in dimensions: lines.append("%s/// Typedef for a %s with %d dimension%s " % (padding,c, nd, ['','s'][nd>1]) ) lines.append("%s typedef %s<%s<%d>, %d> %s%dLean;" % (padding,c, mdevent_type, nd, nd, c, nd) ) - + mdevent_type = "MDEvent" + for nd in dimensions: + lines.append("%s/// Typedef for a %s with %d dimension%s " % (padding,c, nd, ['','s'][nd>1]) ) + lines.append("%stypedef %s<%s<%d>, %d> %s%d;" % (padding,c, mdevent_type, nd, nd, c, nd) ) + lines.append("\n"); - lines += footer_lines + lines_after f = open("../inc/MantidDataObjects/MDEventFactory.h", 'w') @@ -212,8 +211,8 @@ def generate(): # =========== Do the Source File =========== padding,lines,lines_after=parse_file("./MDEventFactory.cpp", - "//### BEGIN AUTO-GENERATED CODE ###", - "//### END AUTO-GENERATED CODE ###"); + "//### BEGIN AUTO-GENERATED CODE", + "//### END AUTO-GENERATED CODE"); header_lines = map(lambda x : padding+x,header.split("\n")); footer_lines = map(lambda x : padding+x,footer.split("\n")); @@ -224,14 +223,14 @@ def generate(): for c in mdevent_types: lines.append("%s// Instantiations for %s" % (padding,c)) for nd in dimensions: - lines.append("%s template DLLExport class %s<%d>;" % (padding,c, nd) ) + lines.append("%s template class DLLExport %s<%d>;" % (padding,c, nd) ) # Classes with MDLeanEvent<x>,x for c in classes_cpp: lines.append("%s// Instantiations for %s" %(padding, c) ) for mdevent_type in mdevent_types: for nd in dimensions: - lines.append("%s template DLLExport class %s<%s<%d>, %d>;" % (padding,c, mdevent_type, nd, nd) ) + lines.append("%s template class DLLExport %s<%s<%d>, %d>;" % (padding,c, mdevent_type, nd, nd) ) lines.append("\n ") diff --git a/Framework/Geometry/inc/MantidGeometry/Crystal/BraggScattererFactory.h b/Framework/Geometry/inc/MantidGeometry/Crystal/BraggScattererFactory.h index 46ef06832bf434851a1a2d6693bd20d0c1c6e3d3..a9782105dc3dc6b7f1b78931580ca5d323dcc5f9 100644 --- a/Framework/Geometry/inc/MantidGeometry/Crystal/BraggScattererFactory.h +++ b/Framework/Geometry/inc/MantidGeometry/Crystal/BraggScattererFactory.h @@ -85,18 +85,19 @@ private: BraggScattererFactoryImpl(); }; -// This is taken from FuncMinimizerFactory -#ifdef _WIN32 -template class MANTID_GEOMETRY_DLL - Mantid::Kernel::SingletonHolder<BraggScattererFactoryImpl>; -#endif - typedef Mantid::Kernel::SingletonHolder<BraggScattererFactoryImpl> BraggScattererFactory; } // namespace Geometry } // namespace Mantid +namespace Mantid { +namespace Kernel { +EXTERN_MANTID_GEOMETRY template class MANTID_GEOMETRY_DLL Mantid::Kernel:: + SingletonHolder<Mantid::Geometry::BraggScattererFactoryImpl>; +} +} + #define DECLARE_BRAGGSCATTERER(classname) \ namespace { \ Mantid::Kernel::RegistrationHelper register_scatterer_##classname( \ diff --git a/Framework/Geometry/inc/MantidGeometry/Crystal/CenteringGroup.h b/Framework/Geometry/inc/MantidGeometry/Crystal/CenteringGroup.h index 32a59668721f0e3001f217a0d68789243133d9be..85c03b85504d7b981875cee0339262179b378bc0 100644 --- a/Framework/Geometry/inc/MantidGeometry/Crystal/CenteringGroup.h +++ b/Framework/Geometry/inc/MantidGeometry/Crystal/CenteringGroup.h @@ -94,15 +94,17 @@ private: friend struct Mantid::Kernel::CreateUsingNew<CenteringGroupCreatorImpl>; }; -#ifdef _WIN32 -template class MANTID_GEOMETRY_DLL - Mantid::Kernel::SingletonHolder<CenteringGroupCreatorImpl>; -#endif - typedef Mantid::Kernel::SingletonHolder<CenteringGroupCreatorImpl> CenteringGroupCreator; } // namespace Geometry } // namespace Mantid +namespace Mantid { +namespace Kernel { +EXTERN_MANTID_GEOMETRY template class MANTID_GEOMETRY_DLL Mantid::Kernel:: + SingletonHolder<Mantid::Geometry::CenteringGroupCreatorImpl>; +} +} + #endif /* MANTID_GEOMETRY_CENTERINGGROUP_H_ */ diff --git a/Framework/Geometry/inc/MantidGeometry/Crystal/PointGroupFactory.h b/Framework/Geometry/inc/MantidGeometry/Crystal/PointGroupFactory.h index bcdd02a809683962da4af9e5439a6cb802caa82f..6e22e4a622a6bcb1ea75aaec3072cba60d138d72 100644 --- a/Framework/Geometry/inc/MantidGeometry/Crystal/PointGroupFactory.h +++ b/Framework/Geometry/inc/MantidGeometry/Crystal/PointGroupFactory.h @@ -120,18 +120,19 @@ private: boost::regex m_originChoiceRegex; }; -// This is taken from FuncMinimizerFactory -#ifdef _WIN32 -template class MANTID_GEOMETRY_DLL - Mantid::Kernel::SingletonHolder<PointGroupFactoryImpl>; -#endif - typedef Mantid::Kernel::SingletonHolder<PointGroupFactoryImpl> PointGroupFactory; } // namespace Geometry } // namespace Mantid +namespace Mantid { +namespace Kernel { +EXTERN_MANTID_GEOMETRY template class MANTID_GEOMETRY_DLL + Mantid::Kernel::SingletonHolder<Mantid::Geometry::PointGroupFactoryImpl>; +} +} + #define PGF_CONCAT_IMPL(x, y) x##y #define PGF_CONCAT(x, y) PGF_CONCAT_IMPL(x, y) diff --git a/Framework/Geometry/inc/MantidGeometry/Crystal/SpaceGroupFactory.h b/Framework/Geometry/inc/MantidGeometry/Crystal/SpaceGroupFactory.h index 40cb653cfcf3e2ab4674ec89708e935c9c976fb3..fd45198f439afd19a9be63a2f4e8d27661211ae1 100644 --- a/Framework/Geometry/inc/MantidGeometry/Crystal/SpaceGroupFactory.h +++ b/Framework/Geometry/inc/MantidGeometry/Crystal/SpaceGroupFactory.h @@ -265,18 +265,19 @@ private: friend struct Mantid::Kernel::CreateUsingNew<SpaceGroupFactoryImpl>; }; -// This is taken from FuncMinimizerFactory -#ifdef _WIN32 -template class MANTID_GEOMETRY_DLL - Mantid::Kernel::SingletonHolder<SpaceGroupFactoryImpl>; -#endif - typedef Mantid::Kernel::SingletonHolder<SpaceGroupFactoryImpl> SpaceGroupFactory; } // namespace Geometry } // namespace Mantid +namespace Mantid { +namespace Kernel { +EXTERN_MANTID_GEOMETRY template class MANTID_GEOMETRY_DLL + Mantid::Kernel::SingletonHolder<Mantid::Geometry::SpaceGroupFactoryImpl>; +} +} + /* Macros for compile time space group registration * * The macros are a bit different than in other factories, diff --git a/Framework/Geometry/inc/MantidGeometry/Crystal/SymmetryElementFactory.h b/Framework/Geometry/inc/MantidGeometry/Crystal/SymmetryElementFactory.h index 05a48e621d1f05b08a82716636511f43139fd8d9..30dd5b1603e8e81f29754c69f72cdb0ee8a1c620 100644 --- a/Framework/Geometry/inc/MantidGeometry/Crystal/SymmetryElementFactory.h +++ b/Framework/Geometry/inc/MantidGeometry/Crystal/SymmetryElementFactory.h @@ -257,17 +257,19 @@ private: friend struct Mantid::Kernel::CreateUsingNew<SymmetryElementFactoryImpl>; }; -#ifdef _WIN32 -template class MANTID_GEOMETRY_DLL - Mantid::Kernel::SingletonHolder<SymmetryElementFactoryImpl>; -#endif - typedef Mantid::Kernel::SingletonHolder<SymmetryElementFactoryImpl> SymmetryElementFactory; } // namespace Geometry } // namespace Mantid +namespace Mantid { +namespace Kernel { +EXTERN_MANTID_GEOMETRY template class MANTID_GEOMETRY_DLL Mantid::Kernel:: + SingletonHolder<Mantid::Geometry::SymmetryElementFactoryImpl>; +} +} + #define DECLARE_SYMMETRY_ELEMENT_GENERATOR(classname) \ namespace { \ Mantid::Kernel::RegistrationHelper \ diff --git a/Framework/Geometry/inc/MantidGeometry/Crystal/SymmetryOperationFactory.h b/Framework/Geometry/inc/MantidGeometry/Crystal/SymmetryOperationFactory.h index 7a348ca0714e503a5f47be15dbb56d9b9290dcb0..e9fa3cb12dea67dcb9f6ee93cd271cdc4181e53f 100644 --- a/Framework/Geometry/inc/MantidGeometry/Crystal/SymmetryOperationFactory.h +++ b/Framework/Geometry/inc/MantidGeometry/Crystal/SymmetryOperationFactory.h @@ -78,18 +78,19 @@ private: SymmetryOperationFactoryImpl(); }; -// This is taken from FuncMinimizerFactory -#ifdef _WIN32 -template class MANTID_GEOMETRY_DLL - Mantid::Kernel::SingletonHolder<SymmetryOperationFactoryImpl>; -#endif - typedef Mantid::Kernel::SingletonHolder<SymmetryOperationFactoryImpl> SymmetryOperationFactory; } // namespace Geometry } // namespace Mantid +namespace Mantid { +namespace Kernel { +EXTERN_MANTID_GEOMETRY template class MANTID_GEOMETRY_DLL Mantid::Kernel:: + SingletonHolder<Mantid::Geometry::SymmetryOperationFactoryImpl>; +} +} + #define DECLARE_SYMMETRY_OPERATION(operation, name) \ namespace { \ Mantid::Kernel::RegistrationHelper register_symop_##name( \ diff --git a/Framework/Geometry/inc/MantidGeometry/DllConfig.h b/Framework/Geometry/inc/MantidGeometry/DllConfig.h index 6b9088226e1659905d861231092bf84496fa24be..432aa7bb7a828949e9349f7b45689208390d256e 100644 --- a/Framework/Geometry/inc/MantidGeometry/DllConfig.h +++ b/Framework/Geometry/inc/MantidGeometry/DllConfig.h @@ -32,8 +32,10 @@ #ifdef IN_MANTID_GEOMETRY #define MANTID_GEOMETRY_DLL DLLExport +#define EXTERN_MANTID_GEOMETRY #else #define MANTID_GEOMETRY_DLL DLLImport +#define EXTERN_MANTID_GEOMETRY EXTERN_IMPORT #endif /* IN_MANTID_GEOMETRY*/ #endif // MANTID_GEOMETRY_DLLCONFIG_H_ diff --git a/Framework/Geometry/inc/MantidGeometry/Instrument/Parameter.h b/Framework/Geometry/inc/MantidGeometry/Instrument/Parameter.h index c1ae2f418e7cfb4475ebc570e7fc338b32f2da13..47691bd996599d6d7fa30af9591a52b5c9e29099 100644 --- a/Framework/Geometry/inc/MantidGeometry/Instrument/Parameter.h +++ b/Framework/Geometry/inc/MantidGeometry/Instrument/Parameter.h @@ -237,17 +237,17 @@ ParameterType<Type> &ParameterType<Type>::operator=(const Type &value) { /// Typedef for the shared pointer typedef boost::shared_ptr<Parameter> Parameter_sptr; /// Parameter of type int -typedef MANTID_GEOMETRY_DLL ParameterType<int> ParameterInt; +typedef ParameterType<int> ParameterInt; /// Parameter of type double -typedef MANTID_GEOMETRY_DLL ParameterType<double> ParameterDouble; +typedef ParameterType<double> ParameterDouble; /// Parameter of type bool -typedef MANTID_GEOMETRY_DLL ParameterType<bool> ParameterBool; +typedef ParameterType<bool> ParameterBool; /// Parameter of type std::string -typedef MANTID_GEOMETRY_DLL ParameterType<std::string> ParameterString; +typedef ParameterType<std::string> ParameterString; /// Parameter of type V3D -typedef MANTID_GEOMETRY_DLL ParameterType<Kernel::V3D> ParameterV3D; +typedef ParameterType<Kernel::V3D> ParameterV3D; /// Parameter of type Quat -typedef MANTID_GEOMETRY_DLL ParameterType<Kernel::Quat> ParameterQuat; +typedef ParameterType<Kernel::Quat> ParameterQuat; } // namespace Geometry } // namespace Mantid diff --git a/Framework/Geometry/inc/MantidGeometry/Instrument/ParameterFactory.h b/Framework/Geometry/inc/MantidGeometry/Instrument/ParameterFactory.h index 3fcf8fb646a8b82ecd3d9ff2268720e3e2c2dcf9..68738d6152cc275aea54f45e806d2c4bd3fe2f67 100644 --- a/Framework/Geometry/inc/MantidGeometry/Instrument/ParameterFactory.h +++ b/Framework/Geometry/inc/MantidGeometry/Instrument/ParameterFactory.h @@ -12,16 +12,6 @@ #include <map> #include <vector> -#ifdef _WIN32 -#if (IN_MANTID_GEOMETRY) -#define GEOMETRY_DLL_EXPORT DLLExport -#else -#define GEOMETRY_DLL_EXPORT DLLImport -#endif -#else -#define GEOMETRY_DLL_EXPORT -#endif - namespace Mantid { namespace Kernel { @@ -61,7 +51,7 @@ class Parameter; File change history is stored at: <https://github.com/mantidproject/mantid> */ -class GEOMETRY_DLL_EXPORT ParameterFactory { +class MANTID_GEOMETRY_DLL ParameterFactory { public: template <class C> static void subscribe(const std::string &className); diff --git a/Framework/Geometry/inc/MantidGeometry/MDGeometry/MDGeometryXMLBuilder.h b/Framework/Geometry/inc/MantidGeometry/MDGeometry/MDGeometryXMLBuilder.h index f410f3be7db5a32aad8182d87fd4fab07ae96077..15addeb270351e4b842b85724ff2220849c366c5 100644 --- a/Framework/Geometry/inc/MantidGeometry/MDGeometry/MDGeometryXMLBuilder.h +++ b/Framework/Geometry/inc/MantidGeometry/MDGeometry/MDGeometryXMLBuilder.h @@ -125,7 +125,7 @@ private: @date May 2011 @version 1.0 */ -struct StrictDimensionPolicy +struct MANTID_GEOMETRY_DLL StrictDimensionPolicy : public std::unary_function<IMDDimension_const_sptr, void> { public: StrictDimensionPolicy() {} @@ -147,7 +147,7 @@ public: @author Owen Arnold @date May 2011 */ -struct NoDimensionPolicy +struct MANTID_GEOMETRY_DLL NoDimensionPolicy : public std::unary_function<IMDDimension_const_sptr, void> { void operator()(IMDDimension_const_sptr) { // Do nothing. diff --git a/Framework/Geometry/src/Instrument/SampleEnvironmentFactory.cpp b/Framework/Geometry/src/Instrument/SampleEnvironmentFactory.cpp index 8c6bc107899009d5ec1b3fa5208d93d3482b4347..1e9e0e7598ebf19ceab3e997e0c00aa10de621ce 100644 --- a/Framework/Geometry/src/Instrument/SampleEnvironmentFactory.cpp +++ b/Framework/Geometry/src/Instrument/SampleEnvironmentFactory.cpp @@ -77,7 +77,7 @@ SampleEnvironment_uptr SampleEnvironmentFactory::create( } else { auto specUPtr = m_finder->find(facility, instrument, specName); spec = specUPtr.get(); - specCache.insert(std::make_pair(cacheKey, std::move(specUPtr))); + specCache.emplace(cacheKey, std::move(specUPtr)); } return spec->buildEnvironment(canName); } diff --git a/Framework/Geometry/src/Instrument/SampleEnvironmentSpec.cpp b/Framework/Geometry/src/Instrument/SampleEnvironmentSpec.cpp index 1ce9901a7cfa3d4da01078734790a660416fe835..9d8200f5cc7c2505facbe35af86416c2a1290e51 100644 --- a/Framework/Geometry/src/Instrument/SampleEnvironmentSpec.cpp +++ b/Framework/Geometry/src/Instrument/SampleEnvironmentSpec.cpp @@ -53,7 +53,7 @@ void SampleEnvironmentSpec::addContainer(const Container_const_sptr &can) { "SampleEnvironmentSpec::addContainer() - Container must " "have an id field. Empty string found."); } - m_cans.insert(std::make_pair(can->id(), can)); + m_cans.emplace(can->id(), can); } /** diff --git a/Framework/Geometry/src/Instrument/SampleEnvironmentSpecParser.cpp b/Framework/Geometry/src/Instrument/SampleEnvironmentSpecParser.cpp index 6bd8d38f0bf22dfba5f794fbef0a6e5dcb8d798c..4bd481f98a8883d1f4a6e99853ff754f8a94915c 100644 --- a/Framework/Geometry/src/Instrument/SampleEnvironmentSpecParser.cpp +++ b/Framework/Geometry/src/Instrument/SampleEnvironmentSpecParser.cpp @@ -127,7 +127,7 @@ void SampleEnvironmentSpecParser::parseMaterials(Poco::XML::Element *element) { MaterialXMLParser parser; while (node) { auto material = parser.parse(static_cast<Poco::XML::Element *>(node)); - m_materials.insert(std::make_pair(material.name(), material)); + m_materials.emplace(material.name(), material); node = nodeIter.nextNode(); } } diff --git a/Framework/Geometry/src/Objects/Object.cpp b/Framework/Geometry/src/Objects/Object.cpp index da55d68945e9a57b35b94a95e57569e185a2230a..a899e1e293e42ccc436edf57af7a01f8ec0b280c 100644 --- a/Framework/Geometry/src/Objects/Object.cpp +++ b/Framework/Geometry/src/Objects/Object.cpp @@ -22,6 +22,7 @@ #include <boost/make_shared.hpp> +#include <array> #include <deque> #include <iostream> #include <stack> @@ -1828,17 +1829,10 @@ int Object::searchForObject(Kernel::V3D &point) const { Kernel::V3D testPt; if (isValid(point)) return 1; - std::vector<Kernel::V3D> axes; - axes.reserve(6); - axes.push_back(Kernel::V3D(1, 0, 0)); - axes.push_back(Kernel::V3D(-1, 0, 0)); - axes.push_back(Kernel::V3D(0, 1, 0)); - axes.push_back(Kernel::V3D(0, -1, 0)); - axes.push_back(Kernel::V3D(0, 0, 1)); - axes.push_back(Kernel::V3D(0, 0, -1)); - std::vector<Kernel::V3D>::const_iterator dir; - for (dir = axes.begin(); dir != axes.end(); ++dir) { - Geometry::Track tr(point, (*dir)); + for (const auto &dir : + {V3D(1., 0., 0.), V3D(-1., 0., 0.), V3D(0., 1., 0.), V3D(0., -1., 0.), + V3D(0., 0., 1.), V3D(0., 0., -1.)}) { + Geometry::Track tr(point, dir); if (this->interceptSurface(tr) > 0) { point = tr.cbegin()->entryPoint; return 1; diff --git a/Framework/ICat/inc/MantidICat/DllConfig.h b/Framework/ICat/inc/MantidICat/DllConfig.h index 04e784e0e434adaa8d61e1e1e07e368a23eb0c2b..08ae1527dac6d75b04f6debf397fa606a26dfc30 100644 --- a/Framework/ICat/inc/MantidICat/DllConfig.h +++ b/Framework/ICat/inc/MantidICat/DllConfig.h @@ -32,8 +32,10 @@ #ifdef IN_MANTID_ICAT #define MANTID_ICAT_DLL DLLExport +#define EXTERN_MANTID_ICAT #else #define MANTID_ICAT_DLL DLLImport +#define EXTERN_MANTID_ICAT EXTERN_IMPORT #endif /* IN_MANTID_ICAT */ #endif // MANTID_ICAT_DLLCONFIG_H_ diff --git a/Framework/Kernel/CMakeLists.txt b/Framework/Kernel/CMakeLists.txt index 6861bb2a09d5c0b2c042ff6f05b5182bffb5fd5b..6559043a037eae79df842270d67182451f8c6c57 100644 --- a/Framework/Kernel/CMakeLists.txt +++ b/Framework/Kernel/CMakeLists.txt @@ -32,6 +32,7 @@ set ( SRC_FILES src/FilteredTimeSeriesProperty.cpp src/FloatingPointComparison.cpp src/FreeBlock.cpp + src/GitHubApiHelper.cpp src/Glob.cpp src/ICatalogInfo.cpp src/IPropertyManager.cpp @@ -180,6 +181,7 @@ set ( INC_FILES inc/MantidKernel/FloatingPointComparison.h inc/MantidKernel/FreeBlock.h inc/MantidKernel/FunctionTask.h + inc/MantidKernel/GitHubApiHelper.h inc/MantidKernel/Glob.h inc/MantidKernel/ICatalogInfo.h inc/MantidKernel/IPropertyManager.h @@ -508,6 +510,20 @@ configure_file ( ${CMAKE_CURRENT_SOURCE_DIR}/inc/MantidKernel/PocoVersion.h.in configure_file ( ${CMAKE_CURRENT_SOURCE_DIR}/src/ParaViewVersion.cpp.in ${CMAKE_CURRENT_SOURCE_DIR}/src/ParaViewVersion.cpp ) +########################################################################### +# This section deals with creating the GithubApiHelper implementation +########################################################################### + +if ( WIN32 ) + set ( GITHUB_AUTHORIZATION_TOKEN "8ec7afc857540ee60af78cba1cf7779a6ed0b6b9") +elseif ( APPLE ) + set ( GITHUB_AUTHORIZATION_TOKEN "9f1c1acd61ecb87b21ad0382f6b403c8294992c5") +else() + set ( GITHUB_AUTHORIZATION_TOKEN "ccacbaf39a7ad8151fca03b4ea99a29b28f0993b") +endif() +configure_file ( ${CMAKE_CURRENT_SOURCE_DIR}/inc/MantidKernel/GitHubApiHelper.h.in + ${CMAKE_CURRENT_SOURCE_DIR}/inc/MantidKernel/GitHubApiHelper.h +) ########################################################################### # Manipulate the Mantid.properties file to work wherever you build to @@ -607,14 +623,7 @@ else () set ( MANTID_ROOT .. ) endif () -# Whether or not to check for updates is tied to a patch version being defined -# nighly/unstable is basically ISO8601 so it will be longer than 8 char. -# This affects Mantid.properties.install only. -string( LENGTH "VERSION_PATCH ${VERSION_PATCH}" VERSION_PATCH_LENGTH) -set (ENABLE_WEB_UPDATES 0) -if (${VERSION_PATCH_LENGTH} LESS 8) - set (ENABLE_WEB_UPDATES 1) -endif() +set (ENABLE_WEB_UPDATES 1) set ( PLUGINS ${MANTID_ROOT}/plugins ) set ( PYTHONPLUGIN_DIRS "${PLUGINS}/python" ) diff --git a/Framework/Kernel/inc/MantidKernel/ANN/ANN.h b/Framework/Kernel/inc/MantidKernel/ANN/ANN.h index 84db71c5ad26fca32c60c5a0d43329d327270631..11e2f98825fe4497c1544b47c3c69096cb4e86cb 100644 --- a/Framework/Kernel/inc/MantidKernel/ANN/ANN.h +++ b/Framework/Kernel/inc/MantidKernel/ANN/ANN.h @@ -96,9 +96,12 @@ #else #define DLL_API __declspec(dllimport) #endif -//---------------------------------------------------------------------- -// DLL_API is ignored for all other systems -//---------------------------------------------------------------------- +#elif defined(__GNUC__) && !defined(__clang__) +#ifdef IN_MANTID_KERNEL +#define DLL_API __attribute__((visibility("default"))) +#else +#define DLL_API +#endif #else #define DLL_API #endif diff --git a/Framework/Kernel/inc/MantidKernel/ConfigService.h b/Framework/Kernel/inc/MantidKernel/ConfigService.h index e405fd2739453b340c946805626d88f0dcebf9ce..3132f313e22b21f38a3d07240ea161210ced3936 100644 --- a/Framework/Kernel/inc/MantidKernel/ConfigService.h +++ b/Framework/Kernel/inc/MantidKernel/ConfigService.h @@ -354,15 +354,9 @@ private: std::vector<std::string> m_filterChannels; }; -/// Forward declaration of a specialisation of SingletonHolder for -/// AlgorithmFactoryImpl (needed for dllexport/dllimport) and a typedef for it. -#if defined(__APPLE__) && defined(__INTEL_COMPILER) -inline -#endif - template class MANTID_KERNEL_DLL - Mantid::Kernel::SingletonHolder<ConfigServiceImpl>; -typedef MANTID_KERNEL_DLL Mantid::Kernel::SingletonHolder<ConfigServiceImpl> - ConfigService; +EXTERN_MANTID_KERNEL template class MANTID_KERNEL_DLL + Mantid::Kernel::SingletonHolder<ConfigServiceImpl>; +typedef Mantid::Kernel::SingletonHolder<ConfigServiceImpl> ConfigService; typedef Mantid::Kernel::ConfigServiceImpl::ValueChanged ConfigValChangeNotification; diff --git a/Framework/Kernel/inc/MantidKernel/DllConfig.h b/Framework/Kernel/inc/MantidKernel/DllConfig.h index f7a6020c17f1a55441c6777b773c05d894e72c55..d894bc1e0b1fb69e6fe60c747fb110dcdb0c4413 100644 --- a/Framework/Kernel/inc/MantidKernel/DllConfig.h +++ b/Framework/Kernel/inc/MantidKernel/DllConfig.h @@ -32,8 +32,10 @@ #ifdef IN_MANTID_KERNEL #define MANTID_KERNEL_DLL DLLExport +#define EXTERN_MANTID_KERNEL #else #define MANTID_KERNEL_DLL DLLImport +#define EXTERN_MANTID_KERNEL EXTERN_IMPORT #endif /* IN_MANTID_KERNEL*/ #endif // MANTID_KERNEL_DLLCONFIG_H_ diff --git a/Framework/Kernel/inc/MantidKernel/GitHubApiHelper.h.in b/Framework/Kernel/inc/MantidKernel/GitHubApiHelper.h.in new file mode 100644 index 0000000000000000000000000000000000000000..d0840d40f87a9fdc392cc5098167cd52a5638acc --- /dev/null +++ b/Framework/Kernel/inc/MantidKernel/GitHubApiHelper.h.in @@ -0,0 +1,60 @@ +#ifndef MANTID_KERNEL_GitHubApiHelper_H_ +#define MANTID_KERNEL_GitHubApiHelper_H_ + +#include "MantidKernel/InternetHelper.h" + +namespace Mantid { +namespace Kernel { + +/** GitHubApiHelper : A helper class for supporting access to the github api +through HTTP and HTTPS, inherits from the InternetHelper. +This class automatically adds the authorization to a read only account. + +Copyright © 2016 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge +National Laboratory & European Spallation Source + +This file is part of Mantid. + +Mantid is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3 of the License, or +(at your option) any later version. + +Mantid is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. + +File change history is stored at: <https://github.com/mantidproject/mantid> +Code Documentation is available at: <http://doxygen.mantidproject.org> +*/ +class MANTID_KERNEL_DLL GitHubApiHelper : public InternetHelper { +public: + GitHubApiHelper(); + GitHubApiHelper(const Kernel::ProxyInfo &proxy); + virtual ~GitHubApiHelper() = default; + + void reset() override; + bool isAuthenticated(); + +protected: + virtual void processResponseHeaders(const Poco::Net::HTTPResponse &res) override; + virtual int sendRequestAndProcess(Poco::Net::HTTPClientSession &session, + Poco::URI &uri, std::ostream &responseStream) override; +private: + int processAnonymousRequest(const Poco::Net::HTTPResponse &response, + Poco::URI &uri, + std::ostream &responseStream); + void addAuthenticationToken() { + addHeader("Authorization", + "token @GITHUB_AUTHORIZATION_TOKEN@"); + } +}; + +} // namespace Kernel +} // namespace Mantid + +#endif /* MANTID_KERNEL_GitHubApiHelper_H_ */ diff --git a/Framework/Kernel/inc/MantidKernel/InternetHelper.h b/Framework/Kernel/inc/MantidKernel/InternetHelper.h index 771a819cc33a388237f9f2be13a1594370286cac..7e1f6e47e57689c3b27fc813d9f290f8b32eaecf 100644 --- a/Framework/Kernel/inc/MantidKernel/InternetHelper.h +++ b/Framework/Kernel/inc/MantidKernel/InternetHelper.h @@ -130,7 +130,7 @@ public: const std::string &getHeader(const std::string &key); void clearHeaders(); StringToStringMap &headers(); - void reset(); + virtual void reset(); // Proxy methods Kernel::ProxyInfo &getProxy(const std::string &url); @@ -147,15 +147,16 @@ protected: std::ostream &responseStream); virtual int sendHTTPRequest(const std::string &url, std::ostream &responseStream); + virtual void processResponseHeaders(const Poco::Net::HTTPResponse &res); virtual int processErrorStates(const Poco::Net::HTTPResponse &res, std::istream &rs, const std::string &url); + virtual int sendRequestAndProcess(Poco::Net::HTTPClientSession &session, + Poco::URI &uri, + std::ostream &responseStream); -private: void setupProxyOnSession(Poco::Net::HTTPClientSession &session, const std::string &proxyUrl); void createRequest(Poco::URI &uri); - int sendRequestAndProcess(Poco::Net::HTTPClientSession &session, - Poco::URI &uri, std::ostream &responseStream); int processRelocation(const Poco::Net::HTTPResponse &response, std::ostream &responseStream); bool isRelocated(const int response); diff --git a/Framework/Kernel/inc/MantidKernel/LibraryManager.h b/Framework/Kernel/inc/MantidKernel/LibraryManager.h index de77712ad2f67da494918a3fed90b18a6acf53b7..ae95398fc06fc474f4788e348bdd699d4d528111 100644 --- a/Framework/Kernel/inc/MantidKernel/LibraryManager.h +++ b/Framework/Kernel/inc/MantidKernel/LibraryManager.h @@ -69,15 +69,9 @@ private: OpenLibs; }; -/// Forward declaration of a specialisation of SingletonHolder for -/// LibraryManagerImpl (needed for dllexport/dllimport) and a typedef for it. -#if defined(__APPLE__) && defined(__INTEL_COMPILER) -inline -#endif - template class MANTID_KERNEL_DLL - Mantid::Kernel::SingletonHolder<LibraryManagerImpl>; -typedef MANTID_KERNEL_DLL Mantid::Kernel::SingletonHolder<LibraryManagerImpl> - LibraryManager; +EXTERN_MANTID_KERNEL template class MANTID_KERNEL_DLL + Mantid::Kernel::SingletonHolder<LibraryManagerImpl>; +typedef Mantid::Kernel::SingletonHolder<LibraryManagerImpl> LibraryManager; } // namespace Kernel } // namespace Mantid diff --git a/Framework/Kernel/inc/MantidKernel/PropertyManagerDataService.h b/Framework/Kernel/inc/MantidKernel/PropertyManagerDataService.h index 49aa7c28a21a8cc7db68b04e5bd36083530f0570..6caae94d1fb16dc89a9d8ba82bc023a38a09730d 100644 --- a/Framework/Kernel/inc/MantidKernel/PropertyManagerDataService.h +++ b/Framework/Kernel/inc/MantidKernel/PropertyManagerDataService.h @@ -46,16 +46,10 @@ private: ~PropertyManagerDataServiceImpl() override = default; }; -/// Forward declaration of a specialisation of SingletonHolder for -/// PropertyManagerDataServiceImpl (needed for dllexport/dllimport) and a -/// typedef for it. -#ifdef _WIN32 -// this breaks new namespace declaraion rules; need to find a better fix -template class MANTID_KERNEL_DLL +EXTERN_MANTID_KERNEL template class MANTID_KERNEL_DLL Mantid::Kernel::SingletonHolder<PropertyManagerDataServiceImpl>; -#endif /* _WIN32 */ -typedef MANTID_KERNEL_DLL Mantid::Kernel::SingletonHolder< - PropertyManagerDataServiceImpl> PropertyManagerDataService; +typedef Mantid::Kernel::SingletonHolder<PropertyManagerDataServiceImpl> + PropertyManagerDataService; } // Namespace Kernel } // Namespace Mantid diff --git a/Framework/Kernel/inc/MantidKernel/System.h b/Framework/Kernel/inc/MantidKernel/System.h index 0aee62559f1c5c0ffd0bb3133619d76a99e6e583..65fbb9545cb6645eb132c260747bb09e13ebe237 100644 --- a/Framework/Kernel/inc/MantidKernel/System.h +++ b/Framework/Kernel/inc/MantidKernel/System.h @@ -60,9 +60,15 @@ // Export/Import declarations #define DLLExport __declspec(dllexport) #define DLLImport __declspec(dllimport) +#define EXTERN_IMPORT extern +#elif defined(__GNUC__) && !defined(__clang__) +#define DLLExport __attribute__((visibility("default"))) +#define DLLImport +#define EXTERN_IMPORT extern #else #define DLLExport #define DLLImport +#define EXTERN_IMPORT #endif /** diff --git a/Framework/Kernel/inc/MantidKernel/ThreadPool.h b/Framework/Kernel/inc/MantidKernel/ThreadPool.h index c383d334d1b91912243d54c7fa9ea9846f0407ee..256eacf6b68d499d7ed3a6d82b60995e3963c36b 100644 --- a/Framework/Kernel/inc/MantidKernel/ThreadPool.h +++ b/Framework/Kernel/inc/MantidKernel/ThreadPool.h @@ -93,7 +93,7 @@ private: // template class MANTID_KERNEL_DLL // Mantid::Kernel::SingletonHolder<ThreadPoolImpl>; //#endif /* _WIN32 */ -// typedef MANTID_KERNEL_DLL Mantid::Kernel::SingletonHolder<ThreadPoolImpl> +// typedef Mantid::Kernel::SingletonHolder<ThreadPoolImpl> // ThreadPool; } // namespace Kernel diff --git a/Framework/Kernel/inc/MantidKernel/Timer.h b/Framework/Kernel/inc/MantidKernel/Timer.h index 017452e4c90b79eacda45f2a7b65892836be5780..195a835976678e6dbbd54235ebc27f633e7bb3c1 100644 --- a/Framework/Kernel/inc/MantidKernel/Timer.h +++ b/Framework/Kernel/inc/MantidKernel/Timer.h @@ -63,7 +63,7 @@ private: m_start; ///< The starting time (implementation dependent format) }; -std::ostream &operator<<(std::ostream &, const Timer &); +MANTID_KERNEL_DLL std::ostream &operator<<(std::ostream &, const Timer &); } // namespace Kernel } // namespace Mantid diff --git a/Framework/Kernel/inc/MantidKernel/UnitFactory.h b/Framework/Kernel/inc/MantidKernel/UnitFactory.h index e3a0c045c25d181883e324c6a81f0105b56ec530..d8de9c7e8fa7cee1ce9d57baebd04564b0a8dd84 100644 --- a/Framework/Kernel/inc/MantidKernel/UnitFactory.h +++ b/Framework/Kernel/inc/MantidKernel/UnitFactory.h @@ -83,14 +83,9 @@ private: ~UnitFactoryImpl() override = default; }; -/// Forward declaration of a specialisation of SingletonHolder for -/// AlgorithmFactoryImpl (needed for dllexport/dllimport) . -#ifdef _WIN32 -// this breaks new namespace declaraion rules; need to find a better fix -template class MANTID_KERNEL_DLL +EXTERN_MANTID_KERNEL template class MANTID_KERNEL_DLL Mantid::Kernel::SingletonHolder<UnitFactoryImpl>; -#endif /* _WIN32 */ -/// The specialisation of the SingletonHolder class that holds the UnitFactory + typedef SingletonHolder<UnitFactoryImpl> UnitFactory; } // namespace Kernel diff --git a/Framework/Kernel/inc/MantidKernel/UsageService.h b/Framework/Kernel/inc/MantidKernel/UsageService.h index f77ba2d5a15358c189de50eb674cd7ac59d76a18..c1310ec69e5b7e5c0bd99d967963ffbd57b14357 100644 --- a/Framework/Kernel/inc/MantidKernel/UsageService.h +++ b/Framework/Kernel/inc/MantidKernel/UsageService.h @@ -137,17 +137,11 @@ private: Poco::ActiveMethod<int, std::string, UsageServiceImpl> m_featureActiveMethod; }; -/// Forward declaration of a specialisation of SingletonHolder for -/// AlgorithmFactoryImpl (needed for dllexport/dllimport) and a typedef for it. -#if defined(__APPLE__) && defined(__INTEL_COMPILER) -inline -#endif - template class MANTID_KERNEL_DLL - Mantid::Kernel::SingletonHolder<UsageServiceImpl>; -typedef MANTID_KERNEL_DLL Mantid::Kernel::SingletonHolder<UsageServiceImpl> - UsageService; - -} // namespace API +EXTERN_MANTID_KERNEL template class MANTID_KERNEL_DLL + Mantid::Kernel::SingletonHolder<UsageServiceImpl>; +typedef Mantid::Kernel::SingletonHolder<UsageServiceImpl> UsageService; + +} // namespace Kernel } // namespace Mantid #endif /* MANTID_KERNEL_USAGESERVICE_H_ */ diff --git a/Framework/Kernel/inc/MantidKernel/WarningSuppressions.h b/Framework/Kernel/inc/MantidKernel/WarningSuppressions.h index 25fadd77765b555a2367006afaff3ffa6a8c2849..6240e9ee9c25bb28f61bdb0e7758c2878bb5f800 100644 --- a/Framework/Kernel/inc/MantidKernel/WarningSuppressions.h +++ b/Framework/Kernel/inc/MantidKernel/WarningSuppressions.h @@ -89,4 +89,10 @@ #endif // clang-format on +#ifdef GCC_VERSION +#define GCC_UNUSED_FUNCTION __attribute__((unused)) +#else +#define GCC_UNUSED_FUNCTION +#endif + #endif /*MANTID_KERNEL_WARNINGSUPPRESSIONS_H_*/ diff --git a/Framework/Kernel/inc/MantidKernel/cow_ptr.h b/Framework/Kernel/inc/MantidKernel/cow_ptr.h index 39083a92de7751d1d582798cdaf1933b5ae78b82..6d90a463d59071e9d8427017f7187b33664f910a 100644 --- a/Framework/Kernel/inc/MantidKernel/cow_ptr.h +++ b/Framework/Kernel/inc/MantidKernel/cow_ptr.h @@ -64,22 +64,22 @@ private: std::mutex copyMutex; public: - cow_ptr(ptr_type &&resourceSptr); - cow_ptr(const ptr_type &resourceSptr); + cow_ptr(ptr_type &&resourceSptr) noexcept; + cow_ptr(const ptr_type &resourceSptr) noexcept; explicit cow_ptr(DataType *resourcePtr); cow_ptr(); /// Constructs a cow_ptr with no managed object, i.e. empty cow_ptr. - constexpr cow_ptr(std::nullptr_t) : Data(nullptr) {} - cow_ptr(const cow_ptr<DataType> &); + constexpr cow_ptr(std::nullptr_t) noexcept : Data(nullptr) {} + cow_ptr(const cow_ptr<DataType> &) noexcept; // Move is hand-written, since std::mutex member prevents auto-generation. cow_ptr(cow_ptr<DataType> &&other) noexcept : Data(std::move(other.Data)) {} - cow_ptr<DataType> &operator=(const cow_ptr<DataType> &); + cow_ptr<DataType> &operator=(const cow_ptr<DataType> &) noexcept; // Move is hand-written, since std::mutex member prevents auto-generation. cow_ptr<DataType> &operator=(cow_ptr<DataType> &&rhs) noexcept { Data = std::move(rhs.Data); return *this; } - cow_ptr<DataType> &operator=(const ptr_type &); + cow_ptr<DataType> &operator=(const ptr_type &) noexcept; /// Returns the stored pointer. const DataType *get() const noexcept { return Data.get(); } @@ -101,7 +101,7 @@ public: const DataType *operator->() const { return Data.get(); } ///<indirectrion dereference access - bool operator==(const cow_ptr<DataType> &A) { + bool operator==(const cow_ptr<DataType> &A) noexcept { return Data == A.Data; } ///< Based on ptr equality DataType &access(); @@ -128,8 +128,8 @@ cow_ptr<DataType>::cow_ptr() */ // Note: Need custom implementation, since std::mutex is not copyable. template <typename DataType> -cow_ptr<DataType>::cow_ptr(const cow_ptr<DataType> &A) - : Data(A.Data) {} +cow_ptr<DataType>::cow_ptr(const cow_ptr<DataType> &A) noexcept : Data(A.Data) { +} /** Assignment operator : double references the data object @@ -139,7 +139,8 @@ cow_ptr<DataType>::cow_ptr(const cow_ptr<DataType> &A) */ // Note: Need custom implementation, since std::mutex is not copyable. template <typename DataType> -cow_ptr<DataType> &cow_ptr<DataType>::operator=(const cow_ptr<DataType> &A) { +cow_ptr<DataType> &cow_ptr<DataType>:: +operator=(const cow_ptr<DataType> &A) noexcept { if (this != &A) { Data = A.Data; } @@ -153,7 +154,7 @@ cow_ptr<DataType> &cow_ptr<DataType>::operator=(const cow_ptr<DataType> &A) { @return *this */ template <typename DataType> -cow_ptr<DataType> &cow_ptr<DataType>::operator=(const ptr_type &A) { +cow_ptr<DataType> &cow_ptr<DataType>::operator=(const ptr_type &A) noexcept { if (this->Data != A) { Data = A; } @@ -187,12 +188,12 @@ template <typename DataType> DataType &cow_ptr<DataType>::access() { } template <typename DataType> -cow_ptr<DataType>::cow_ptr(ptr_type &&resourceSptr) { +cow_ptr<DataType>::cow_ptr(ptr_type &&resourceSptr) noexcept { this->Data = std::move(resourceSptr); } template <typename DataType> -cow_ptr<DataType>::cow_ptr(const ptr_type &resourceSptr) { +cow_ptr<DataType>::cow_ptr(const ptr_type &resourceSptr) noexcept { this->Data = resourceSptr; } diff --git a/Framework/Kernel/src/ArrayProperty.cpp b/Framework/Kernel/src/ArrayProperty.cpp index 0405a9b1f33f940492e12ebf4433b7e1d8676bdf..e1192f60a83b0d1b9da4d67fb48049b0544b444f 100644 --- a/Framework/Kernel/src/ArrayProperty.cpp +++ b/Framework/Kernel/src/ArrayProperty.cpp @@ -8,13 +8,13 @@ namespace Kernel { /// @cond -template DLLExport class ArrayProperty<int32_t>; -template DLLExport class ArrayProperty<int64_t>; -template DLLExport class ArrayProperty<size_t>; -template DLLExport class ArrayProperty<double>; -template DLLExport class ArrayProperty<std::string>; +template class DLLExport ArrayProperty<int32_t>; +template class DLLExport ArrayProperty<int64_t>; +template class DLLExport ArrayProperty<size_t>; +template class DLLExport ArrayProperty<double>; +template class DLLExport ArrayProperty<std::string>; -template DLLExport class ArrayProperty<std::vector<std::string>>; +template class DLLExport ArrayProperty<std::vector<std::string>>; /// @endcond diff --git a/Framework/Kernel/src/ConfigService.cpp b/Framework/Kernel/src/ConfigService.cpp index beac070365585ddbfd607982a3a39307ea9aa13e..c9106861fe21a0d25c383685604f6851e0f0c0e8 100644 --- a/Framework/Kernel/src/ConfigService.cpp +++ b/Framework/Kernel/src/ConfigService.cpp @@ -2048,6 +2048,7 @@ int ConfigServiceImpl::FindLowestFilterLevel() const { return lowestPriority; } + /// \cond TEMPLATE template DLLExport int ConfigServiceImpl::getValue(const std::string &, double &); diff --git a/Framework/Kernel/src/FilteredTimeSeriesProperty.cpp b/Framework/Kernel/src/FilteredTimeSeriesProperty.cpp index d9d361ec330f25e2be9b63ceb2755e9a8a35b270..d470367a290a25111a91bc11f0347d24a5cc2b5a 100644 --- a/Framework/Kernel/src/FilteredTimeSeriesProperty.cpp +++ b/Framework/Kernel/src/FilteredTimeSeriesProperty.cpp @@ -49,7 +49,7 @@ FilteredTimeSeriesProperty<HeldType>::unfiltered() const { // -------------------------- Macro to instantiation concrete types // -------------------------------- #define INSTANTIATE(TYPE) \ - template MANTID_KERNEL_DLL class FilteredTimeSeriesProperty<TYPE>; + template class MANTID_KERNEL_DLL FilteredTimeSeriesProperty<TYPE>; // -------------------------- Concrete instantiation // ----------------------------------------------- diff --git a/Framework/Kernel/src/GitHubApiHelper.cpp b/Framework/Kernel/src/GitHubApiHelper.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0392c0d6e9b98d285314932d5c56b58a12622528 --- /dev/null +++ b/Framework/Kernel/src/GitHubApiHelper.cpp @@ -0,0 +1,115 @@ +#include "MantidKernel/GitHubApiHelper.h" +#include "MantidKernel/DateAndTime.h" +#include "MantidKernel/Logger.h" +#include <Poco/StreamCopier.h> +#include <Poco/URI.h> +#include <Poco/Net/HTTPRequest.h> +#include <Poco/Net/HTTPResponse.h> +#include <Poco/Net/HTTPSClientSession.h> + +namespace Mantid { +namespace Kernel { + +using namespace Poco::Net; +using std::map; +using std::string; + +namespace { +// anonymous namespace for some utility functions +/// static Logger object +Logger g_log("InternetHelper"); +} + +//---------------------------------------------------------------------------------------------- +/** Constructor +*/ +GitHubApiHelper::GitHubApiHelper() : InternetHelper() { + addAuthenticationToken(); +} + +//---------------------------------------------------------------------------------------------- +/** Constructor +*/ +GitHubApiHelper::GitHubApiHelper(const Kernel::ProxyInfo &proxy) + : InternetHelper(proxy) { + addAuthenticationToken(); +} + +void GitHubApiHelper::reset() { + InternetHelper::reset(); + addAuthenticationToken(); +} + +bool GitHubApiHelper::isAuthenticated() { + return (m_headers.find("Authorization") != m_headers.end()); +} + +void GitHubApiHelper::processResponseHeaders( + const Poco::Net::HTTPResponse &res) { + // get github api rate limit information if available; + int rateLimitRemaining = 0; + int rateLimitLimit; + DateAndTime rateLimitReset; + try { + rateLimitLimit = + boost::lexical_cast<int>(res.get("X-RateLimit-Limit", "-1")); + rateLimitRemaining = + boost::lexical_cast<int>(res.get("X-RateLimit-Remaining", "-1")); + rateLimitReset.set_from_time_t( + boost::lexical_cast<int>(res.get("X-RateLimit-Reset", "0"))); + } catch (boost::bad_lexical_cast const &) { + rateLimitLimit = -1; + } + if (rateLimitLimit > -1) { + g_log.debug() << "GitHub API " << rateLimitRemaining << " of " + << rateLimitLimit << " calls left. Resets at " + << rateLimitReset.toSimpleString() << " GMT\n"; + } +} + +int GitHubApiHelper::processAnonymousRequest( + const Poco::Net::HTTPResponse &response, Poco::URI &uri, + std::ostream &responseStream) { + if (isAuthenticated()) { + g_log.debug("Repeating API call anonymously\n"); + removeHeader("Authorization"); + return this->sendRequest(uri.toString(), responseStream); + } else { + g_log.warning("Authentication failed and anonymous access refused\n"); + return response.getStatus(); + } +} + +int GitHubApiHelper::sendRequestAndProcess(HTTPClientSession &session, + Poco::URI &uri, + std::ostream &responseStream) { + // create a request + this->createRequest(uri); + session.sendRequest(*m_request) << m_body; + + std::istream &rs = session.receiveResponse(*m_response); + int retStatus = m_response->getStatus(); + g_log.debug() << "Answer from web: " << retStatus << " " + << m_response->getReason() << "\n"; + + if (retStatus == HTTP_OK || + (retStatus == HTTP_CREATED && m_method == HTTPRequest::HTTP_POST)) { + Poco::StreamCopier::copyStream(rs, responseStream); + processResponseHeaders(*m_response); + return retStatus; + } else if ((retStatus == HTTP_FORBIDDEN && isAuthenticated()) || + (retStatus == HTTP_UNAUTHORIZED) || + (retStatus == HTTP_NOT_FOUND)) { + // If authentication fails you can get HTTP_UNAUTHORIZED or HTTP_NOT_FOUND + // If the limit runs out you can get HTTP_FORBIDDEN + return this->processAnonymousRequest(*m_response, uri, responseStream); + } else if (isRelocated(retStatus)) { + return this->processRelocation(*m_response, responseStream); + } else { + Poco::StreamCopier::copyStream(rs, responseStream); + return processErrorStates(*m_response, rs, uri.toString()); + } +} + +} // namespace Kernel +} // namespace Mantid diff --git a/Framework/Kernel/src/InternetHelper.cpp b/Framework/Kernel/src/InternetHelper.cpp index 9e9ba64ba5e8fafb29974bb1390e4086e0fb9918..ac3d579f1f198904a7cae3e6aa42ac7516fde795 100644 --- a/Framework/Kernel/src/InternetHelper.cpp +++ b/Framework/Kernel/src/InternetHelper.cpp @@ -134,6 +134,7 @@ int InternetHelper::sendRequestAndProcess(HTTPClientSession &session, if (retStatus == HTTP_OK || (retStatus == HTTP_CREATED && m_method == HTTPRequest::HTTP_POST)) { Poco::StreamCopier::copyStream(rs, responseStream); + processResponseHeaders(*m_response); return retStatus; } else if (isRelocated(retStatus)) { return this->processRelocation(*m_response, responseStream); @@ -301,6 +302,11 @@ void InternetHelper::setProxy(const Kernel::ProxyInfo &proxy) { m_isProxySet = true; } +/** Process any headers from the response stream +Basic implementation does nothing. +*/ +void InternetHelper::processResponseHeaders(const Poco::Net::HTTPResponse &) {} + /** Process any HTTP errors states. @param res : The http response @@ -349,7 +355,7 @@ int InternetHelper::processErrorStates(const Poco::Net::HTTPResponse &res, } else if ((retStatus == HTTP_FORBIDDEN) && (rateLimitRemaining == 0)) { throw Exception::InternetError( "The Github API rate limit has been reached, try again after " + - rateLimitReset.toSimpleString(), + rateLimitReset.toSimpleString() + " GMT", retStatus); } else { std::stringstream info; diff --git a/Framework/Kernel/src/MaskedProperty.cpp b/Framework/Kernel/src/MaskedProperty.cpp index 527e148051c1666aafa19b0a8adff566f88d3947..71a173945907c9d114e76257c3f3e2dec4d2103c 100644 --- a/Framework/Kernel/src/MaskedProperty.cpp +++ b/Framework/Kernel/src/MaskedProperty.cpp @@ -77,7 +77,7 @@ template <typename TYPE> void MaskedProperty<TYPE>::doMasking() const { //--------------------------------------------------------------------------- ///@cond TEMPLATE -template MANTID_KERNEL_DLL class Mantid::Kernel::MaskedProperty<std::string>; +template class MANTID_KERNEL_DLL Mantid::Kernel::MaskedProperty<std::string>; ///@endcond TEMPLATE } // namespace API diff --git a/Framework/Kernel/src/Matrix.cpp b/Framework/Kernel/src/Matrix.cpp index b0febc89129c238611fa78ef4d048a670901b53d..4037e3bd37b2c49e2d9178026e98f50dae624b93 100644 --- a/Framework/Kernel/src/Matrix.cpp +++ b/Framework/Kernel/src/Matrix.cpp @@ -1598,7 +1598,13 @@ void fillFromStream(std::istream &is, Kernel::Matrix<T> &in, // Symbol definitions for common types template class MANTID_KERNEL_DLL Matrix<double>; -template class MANTID_KERNEL_DLL Matrix<int>; +// The explicit template instantiation for int does not have an export macro +// since this produces a warning on "gcc: warning: type attributes ignored after +// type is already define" The reason for this is the use of Matrix<int> +// in a template specialization above, causing an implicit sepcialization. +// This, most likely, obtains a visibility setting from the general template +// definition. +template class Matrix<int>; template class MANTID_KERNEL_DLL Matrix<float>; template MANTID_KERNEL_DLL std::ostream &operator<<(std::ostream &, diff --git a/Framework/Kernel/src/PropertyWithValue.cpp b/Framework/Kernel/src/PropertyWithValue.cpp index b853a1196ae43cd124cacd742b1965de138282ef..ba8ba9cecf3650785be6ac8d8381234c7e3c70ff 100644 --- a/Framework/Kernel/src/PropertyWithValue.cpp +++ b/Framework/Kernel/src/PropertyWithValue.cpp @@ -25,21 +25,40 @@ PROPERTYWITHVALUE_SAVEPROPERTY(std::vector<double>) PROPERTYWITHVALUE_SAVEPROPERTY(std::vector<int32_t>) /// @cond -#define INSTANTIATE(Type) \ - template DLLExport class PropertyWithValue<Type>; \ - template DLLExport class PropertyWithValue<std::vector<Type>>; +#define INSTANTIATE_WITH_EXPORT(Type) \ + template class DLLExport PropertyWithValue<Type>; // Explicit instantiations -INSTANTIATE(int32_t) -INSTANTIATE(int64_t) -INSTANTIATE(uint16_t) -INSTANTIATE(uint32_t) -INSTANTIATE(uint64_t) -INSTANTIATE(bool) -INSTANTIATE(OptionalBool) -INSTANTIATE(double) -INSTANTIATE(std::string) +INSTANTIATE_WITH_EXPORT(uint16_t) +INSTANTIATE_WITH_EXPORT(bool) +INSTANTIATE_WITH_EXPORT(OptionalBool) /// @endcond +#define INSTANTIATE_WITH_EXPORT_VECTOR(Type) \ + template class DLLExport PropertyWithValue<std::vector<Type>>; +INSTANTIATE_WITH_EXPORT_VECTOR(uint16_t) +INSTANTIATE_WITH_EXPORT_VECTOR(uint32_t) +INSTANTIATE_WITH_EXPORT_VECTOR(int64_t) +INSTANTIATE_WITH_EXPORT_VECTOR(uint64_t) +INSTANTIATE_WITH_EXPORT_VECTOR(bool) +INSTANTIATE_WITH_EXPORT_VECTOR(OptionalBool) +INSTANTIATE_WITH_EXPORT_VECTOR(std::string) + +// The explicit template instantiations for some types does not have an export +// macro +// since this produces a warning on "gcc: warning: type attributes ignored after +// type is already define". We can remove the issue, by removing the visibility +// attribute +template class PropertyWithValue<double>; +template class PropertyWithValue<std::vector<double>>; + +template class PropertyWithValue<int32_t>; +template class PropertyWithValue<std::vector<int32_t>>; + +template class PropertyWithValue<uint32_t>; +template class PropertyWithValue<int64_t>; +template class PropertyWithValue<uint64_t>; +template class PropertyWithValue<std::string>; + } // namespace Kernel } // namespace Mantid diff --git a/Framework/Kernel/src/TimeSeriesProperty.cpp b/Framework/Kernel/src/TimeSeriesProperty.cpp index d80ebe54607357f843c7bf5f8e76ba16a87d8227..791dbd219bc69d42c95f71cfc0fd4dbe151cf744 100644 --- a/Framework/Kernel/src/TimeSeriesProperty.cpp +++ b/Framework/Kernel/src/TimeSeriesProperty.cpp @@ -368,12 +368,10 @@ void TimeSeriesProperty<TYPE>::filterByTimes( TimeValueUnit<TYPE> temp(t_start, m_values[tstartindex].value()); mp_copy.push_back(temp); } else { - mp_copy.push_back( - TimeValueUnit<TYPE>(t_start, m_values[tstartindex].value())); + mp_copy.emplace_back(t_start, m_values[tstartindex].value()); for (size_t im = size_t(tstartindex + 1); im <= size_t(tstopindex); ++im) { - mp_copy.push_back( - TimeValueUnit<TYPE>(m_values[im].time(), m_values[im].value())); + mp_copy.emplace_back(m_values[im].time(), m_values[im].value()); } } } // ENDFOR @@ -615,7 +613,7 @@ void TimeSeriesProperty<TYPE>::makeFilterByValue( // boundaries are centred. // Otherwise, use the first 'bad' time. stop = centre ? lastTime + tol : t; - split.push_back(SplittingInterval(start, stop, 0)); + split.emplace_back(start, stop, 0); // Reset the number of good ones, for next time numgood = 0; } @@ -627,7 +625,7 @@ void TimeSeriesProperty<TYPE>::makeFilterByValue( // The log ended on "good" so we need to close it using the last time we // found stop = t + tol; - split.push_back(SplittingInterval(start, stop, 0)); + split.emplace_back(start, stop, 0); } } @@ -678,7 +676,7 @@ void TimeSeriesProperty<TYPE>::expandFilterToRange( double val = firstValue(); if ((val >= min) && (val <= max)) { TimeSplitterType extraFilter; - extraFilter.push_back(SplittingInterval(range.begin(), firstTime(), 0)); + extraFilter.emplace_back(range.begin(), firstTime(), 0); // Include everything from the start of the run to the first time measured // (which may be a null time interval; this'll be ignored) split = split | extraFilter; @@ -688,7 +686,7 @@ void TimeSeriesProperty<TYPE>::expandFilterToRange( val = lastValue(); if ((val >= min) && (val <= max)) { TimeSplitterType extraFilter; - extraFilter.push_back(SplittingInterval(lastTime(), range.end(), 0)); + extraFilter.emplace_back(lastTime(), range.end(), 0); // Include everything from the start of the run to the first time measured // (which may be a null time interval; this'll be ignored) split = split | extraFilter; @@ -767,7 +765,7 @@ double TimeSeriesProperty<TYPE>::timeAverageValue() const { double retVal = 0.0; try { TimeSplitterType filter; - filter.push_back(SplittingInterval(this->firstTime(), this->lastTime())); + filter.emplace_back(this->firstTime(), this->lastTime()); retVal = this->averageValueInFilter(filter); } catch (std::exception &) { // just return nan @@ -2145,8 +2143,7 @@ void TimeSeriesProperty<TYPE>::saveProperty(::NeXus::File *file) { /// @cond // -------------------------- Macro to instantiation concrete types // -------------------------------- -#define INSTANTIATE(TYPE) \ - template MANTID_KERNEL_DLL class TimeSeriesProperty<TYPE>; +#define INSTANTIATE(TYPE) template class TimeSeriesProperty<TYPE>; // -------------------------- Concrete instantiation // ----------------------------------------------- diff --git a/Framework/Kernel/src/TimeSplitter.cpp b/Framework/Kernel/src/TimeSplitter.cpp index 2a3f0068b8cb4b28a01c62c0254a3474dbf44cb2..f4bcd032e6d64940e0595d95ecfaa7a969d34957 100644 --- a/Framework/Kernel/src/TimeSplitter.cpp +++ b/Framework/Kernel/src/TimeSplitter.cpp @@ -168,6 +168,7 @@ TimeSplitterType operator&(const TimeSplitterType &a, */ TimeSplitterType removeFilterOverlap(const TimeSplitterType &a) { TimeSplitterType out; + out.reserve(a.size()); // Now we have to merge duplicate/overlapping intervals together auto it = a.cbegin(); @@ -186,7 +187,7 @@ TimeSplitterType removeFilterOverlap(const TimeSplitterType &a) { ++it; } // We've reached a gap point. Output this merged interval and move on. - out.push_back(SplittingInterval(start, stop, 0)); + out.emplace_back(start, stop, 0); } return out; @@ -242,8 +243,7 @@ TimeSplitterType operator~(const TimeSplitterType &a) { // No entries: then make a "filter" that keeps everything if ((temp.empty())) { - out.push_back( - SplittingInterval(DateAndTime::minimum(), DateAndTime::maximum(), 0)); + out.emplace_back(DateAndTime::minimum(), DateAndTime::maximum(), 0); return out; } @@ -251,7 +251,7 @@ TimeSplitterType operator~(const TimeSplitterType &a) { ait = temp.begin(); if (ait != temp.end()) { // First entry; start at -infinite time - out.push_back(SplittingInterval(DateAndTime::minimum(), ait->start(), 0)); + out.emplace_back(DateAndTime::minimum(), ait->start(), 0); // Now start at the second entry while (ait != temp.end()) { DateAndTime start, stop; @@ -262,7 +262,7 @@ TimeSplitterType operator~(const TimeSplitterType &a) { } else { // Stop at the start of the next entry stop = ait->start(); } - out.push_back(SplittingInterval(start, stop, 0)); + out.emplace_back(start, stop, 0); } } return out; diff --git a/Framework/Kernel/src/UsageService.cpp b/Framework/Kernel/src/UsageService.cpp index 36fcb194cbcf1e9498f101c4d6a2ca14cac31383..22184353c65389924d11330abda5903e6b744aab 100644 --- a/Framework/Kernel/src/UsageService.cpp +++ b/Framework/Kernel/src/UsageService.cpp @@ -301,5 +301,5 @@ int UsageServiceImpl::sendReport(const std::string &message, return status; } -} // namespace API +} // namespace Kernel } // namespace Mantid diff --git a/Framework/Kernel/src/VMD.cpp b/Framework/Kernel/src/VMD.cpp index 18f55ed21339e43cc4818aa8b4c4ce93113ff506..2d0a526fff2e2208c0ecec8e172dff8271809b2f 100644 --- a/Framework/Kernel/src/VMD.cpp +++ b/Framework/Kernel/src/VMD.cpp @@ -5,22 +5,6 @@ using namespace Mantid::Kernel; namespace Mantid { namespace Kernel { -/** - Prints a text representation of itself - @param os :: the Stream to output to - @param v :: the vector to output - @return the output stream - */ -std::ostream &operator<<(std::ostream &os, const VMDBase<double> &v) { - os << v.toString(); - return os; -} - -std::ostream &operator<<(std::ostream &os, const VMDBase<float> &v) { - os << v.toString(); - return os; -} - //------------------------------------------------------------------------------------------------- /** Make an orthogonal system with 2 input 3D vectors. * Currently only works in 3D! @@ -133,8 +117,24 @@ VMDBase<TYPE>::getNormalVector(const std::vector<VMDBase<TYPE>> &vectors) { } /// Instantiate VMDBase classes -template MANTID_KERNEL_DLL class VMDBase<double>; -template MANTID_KERNEL_DLL class VMDBase<float>; +template class MANTID_KERNEL_DLL VMDBase<double>; +template class MANTID_KERNEL_DLL VMDBase<float>; + +/** + Prints a text representation of itself + @param os :: the Stream to output to + @param v :: the vector to output + @return the output stream + */ +std::ostream &operator<<(std::ostream &os, const VMDBase<double> &v) { + os << v.toString(); + return os; +} + +std::ostream &operator<<(std::ostream &os, const VMDBase<float> &v) { + os << v.toString(); + return os; +} } // namespace Mantid } // namespace Kernel diff --git a/Framework/MDAlgorithms/CMakeLists.txt b/Framework/MDAlgorithms/CMakeLists.txt index a8c540120e64314cfbbb1e143d769a26a653ea0a..375a9b07e1a0978bed52e53ca2104d58d1ace761 100644 --- a/Framework/MDAlgorithms/CMakeLists.txt +++ b/Framework/MDAlgorithms/CMakeLists.txt @@ -57,6 +57,7 @@ set ( SRC_FILES src/IntegrateMDHistoWorkspace.cpp src/IntegratePeaksMD.cpp src/IntegratePeaksMD2.cpp + src/IntegratePeaksMDHKL.cpp src/IntegratePeaksCWSD.cpp src/InvalidParameter.cpp src/InvalidParameterParser.cpp @@ -185,6 +186,7 @@ set ( INC_FILES inc/MantidMDAlgorithms/IntegrateMDHistoWorkspace.h inc/MantidMDAlgorithms/IntegratePeaksMD.h inc/MantidMDAlgorithms/IntegratePeaksMD2.h + inc/MantidMDAlgorithms/IntegratePeaksMDHKL.h inc/MantidMDAlgorithms/IntegratePeaksCWSD.h inc/MantidMDAlgorithms/InvalidParameter.h inc/MantidMDAlgorithms/InvalidParameterParser.h @@ -312,6 +314,7 @@ set ( TEST_FILES IntegrateFluxTest.h IntegrateMDHistoWorkspaceTest.h IntegratePeaksMD2Test.h + IntegratePeaksMDHKLTest.h IntegratePeaksMDTest.h IntegratePeaksCWSDTest.h InvalidParameterParserTest.h diff --git a/Framework/MDAlgorithms/inc/MantidMDAlgorithms/CreateMDWorkspace.h b/Framework/MDAlgorithms/inc/MantidMDAlgorithms/CreateMDWorkspace.h index 918b60de6ae186126d1f00085fe6f568712744ae..5b9c8aaa67bb0a0ff90ecf0f9e72c6d6474f0d01 100644 --- a/Framework/MDAlgorithms/inc/MantidMDAlgorithms/CreateMDWorkspace.h +++ b/Framework/MDAlgorithms/inc/MantidMDAlgorithms/CreateMDWorkspace.h @@ -6,10 +6,14 @@ #include "MantidDataObjects/MDEventFactory.h" #include "MantidDataObjects/MDEventWorkspace.h" #include "MantidGeometry/MDGeometry/MDFrame.h" +#include "MantidMDAlgorithms/DllConfig.h" namespace Mantid { namespace MDAlgorithms { +std::vector<std::string> MANTID_MDALGORITHMS_DLL +parseNames(const std::string &names_string); + /** CreateMDWorkspace : * * Algorithm to create an empty MDEventWorkspace with a given number of diff --git a/Framework/MDAlgorithms/inc/MantidMDAlgorithms/DllConfig.h b/Framework/MDAlgorithms/inc/MantidMDAlgorithms/DllConfig.h index db73b6e65b00a1ebb4da0f9f2318d1d56545e357..afcde3a7a0c16a8c5dc8871b47e464290e7df0bd 100644 --- a/Framework/MDAlgorithms/inc/MantidMDAlgorithms/DllConfig.h +++ b/Framework/MDAlgorithms/inc/MantidMDAlgorithms/DllConfig.h @@ -32,8 +32,10 @@ #ifdef IN_MANTID_MDALGORITHMS #define MANTID_MDALGORITHMS_DLL DLLExport +#define EXTERN_MANTID_MDALGORITHMS #else #define MANTID_MDALGORITHMS_DLL DLLImport +#define EXTERN_MANTID_MDALGORITHMS EXTERN_IMPORT #endif /* IN_MANTID_MDALGORITHMS*/ #endif // MANTID_MDALGORITHMS_DLLCONFIG_H_ diff --git a/Framework/MDAlgorithms/inc/MantidMDAlgorithms/IntegratePeaksMDHKL.h b/Framework/MDAlgorithms/inc/MantidMDAlgorithms/IntegratePeaksMDHKL.h new file mode 100644 index 0000000000000000000000000000000000000000..b97d605f74cb6d492c9eaf12735852cff22e0199 --- /dev/null +++ b/Framework/MDAlgorithms/inc/MantidMDAlgorithms/IntegratePeaksMDHKL.h @@ -0,0 +1,59 @@ +#ifndef MANTID_MDALGORITHMS_INTEGRATEPEAKSMDHKL_H_ +#define MANTID_MDALGORITHMS_INTEGRATEPEAKSMDHKL_H_ + +#include "MantidAPI/Algorithm.h" +#include "MantidAPI/IMDHistoWorkspace_fwd.h" +#include "MantidDataObjects/PeaksWorkspace.h" +#include "MantidKernel/System.h" +#include "MantidDataObjects/MDHistoWorkspace.h" +#include "MantidAPI/IMDEventWorkspace_fwd.h" +#include "MantidDataObjects/MDEventWorkspace.h" + +namespace Mantid { +namespace MDAlgorithms { + +/** Integrate single-crystal peaks in reciprocal-space. + * + * @author Vickie Lynch + * @date 2016-06-23 + */ +class DLLExport IntegratePeaksMDHKL : public API::Algorithm { +public: + /// Algorithm's name for identification + const std::string name() const override { return "IntegratePeaksMDHKL"; }; + /// Summary of algorithms purpose + const std::string summary() const override { + return "Integrate single-crystal peaks in reciprocal space, for " + "MDHistoWorkspaces."; + } + + /// Algorithm's version for identification + int version() const override { return 1; }; + /// Algorithm's category for identification + const std::string category() const override { return "MDAlgorithms\\Peaks"; } + +private: + /// Initialise the properties + void init() override; + /// Run the algorithm + void exec() override; + + DataObjects::MDHistoWorkspace_sptr + normalize(int h, int k, int l, double box, int gridPts, + const API::MatrixWorkspace_sptr &flux, + const API::MatrixWorkspace_sptr &sa, + const API::IMDEventWorkspace_sptr &ws); + DataObjects::MDHistoWorkspace_sptr binEvent(int h, int k, int l, double box, + int gridPts, + const API::IMDWorkspace_sptr &ws); + DataObjects::MDHistoWorkspace_sptr + cropHisto(int h, int k, int l, double box, const API::IMDWorkspace_sptr &ws); + void integratePeak(const int neighborPts, + DataObjects::MDHistoWorkspace_sptr out, double &intensity, + double &errorSquared); +}; + +} // namespace Mantid +} // namespace DataObjects + +#endif /* MANTID_MDALGORITHMS_INTEGRATEPEAKSMDHKL_H_ */ diff --git a/Framework/MDAlgorithms/inc/MantidMDAlgorithms/MDTransfFactory.h b/Framework/MDAlgorithms/inc/MantidMDAlgorithms/MDTransfFactory.h index a50b86a7cacff84fb7bc3167b002f15cc831af6b..bfe1777de9836966c00e43a674df35523bf9c337 100644 --- a/Framework/MDAlgorithms/inc/MantidMDAlgorithms/MDTransfFactory.h +++ b/Framework/MDAlgorithms/inc/MantidMDAlgorithms/MDTransfFactory.h @@ -108,13 +108,6 @@ private: m_createdTransf; }; -/// Forward declaration of a specialization of SingletonHolder for -/// AlgorithmFactoryImpl (needed for dllexport/dllimport) . -#ifdef _WIN32 -// this breaks new namespace declaration rules; need to find a better fix -template class MANTID_MDALGORITHMS_DLL - Mantid::Kernel::SingletonHolder<MDTransfFactoryImpl>; -#endif /* _WIN32 */ /// The specialization of the SingletonHolder class that holds the /// MDTransformations Factory typedef Kernel::SingletonHolder<MDTransfFactoryImpl> MDTransfFactory; @@ -122,4 +115,11 @@ typedef Kernel::SingletonHolder<MDTransfFactoryImpl> MDTransfFactory; } // namespace MDAlgorithms } // namespace Mantid +namespace Mantid { +namespace Kernel { +EXTERN_MANTID_MDALGORITHMS template class MANTID_MDALGORITHMS_DLL + Mantid::Kernel::SingletonHolder<Mantid::MDAlgorithms::MDTransfFactoryImpl>; +} +} + #endif diff --git a/Framework/MDAlgorithms/inc/MantidMDAlgorithms/Quantification/ForegroundModelFactory.h b/Framework/MDAlgorithms/inc/MantidMDAlgorithms/Quantification/ForegroundModelFactory.h index 5bb9e80788bd51ee5eaf9c963a97c4494df16fff..18c411cffe9073d70a0df91e4c27f102d16fdcc6 100644 --- a/Framework/MDAlgorithms/inc/MantidMDAlgorithms/Quantification/ForegroundModelFactory.h +++ b/Framework/MDAlgorithms/inc/MantidMDAlgorithms/Quantification/ForegroundModelFactory.h @@ -64,16 +64,16 @@ private: using BaseClass::createUnwrapped; }; -/// Forward declaration of a specialisation of SingletonHolder for -/// ForegroundModelFactoryImpl (needed for dllexport/dllimport). -#ifdef _WIN32 -// this breaks new namespace declaraion rules; need to find a better fix -template class MANTID_MDALGORITHMS_DLL - Kernel::SingletonHolder<ForegroundModelFactoryImpl>; -#endif /* _WIN32 */ /// Typedef singleton instance to ForegroundFactory -typedef MANTID_MDALGORITHMS_DLL - Kernel::SingletonHolder<ForegroundModelFactoryImpl> ForegroundModelFactory; +typedef Kernel::SingletonHolder<ForegroundModelFactoryImpl> + ForegroundModelFactory; +} +} + +namespace Mantid { +namespace Kernel { +EXTERN_MANTID_MDALGORITHMS template class MANTID_MDALGORITHMS_DLL + Kernel::SingletonHolder<Mantid::MDAlgorithms::ForegroundModelFactoryImpl>; } } diff --git a/Framework/MDAlgorithms/inc/MantidMDAlgorithms/Quantification/MDResolutionConvolutionFactory.h b/Framework/MDAlgorithms/inc/MantidMDAlgorithms/Quantification/MDResolutionConvolutionFactory.h index 005d9af1314d58cff2318dc97757c62c9421ac9d..104df8efe99c2cefb300b73fd40c6668d17dc3b4 100644 --- a/Framework/MDAlgorithms/inc/MantidMDAlgorithms/Quantification/MDResolutionConvolutionFactory.h +++ b/Framework/MDAlgorithms/inc/MantidMDAlgorithms/Quantification/MDResolutionConvolutionFactory.h @@ -63,16 +63,16 @@ private: using BaseClass::createUnwrapped; }; -/// Forward declaration of a specialisation of SingletonHolder for -/// MDResolutionConvolutionFactoryImpl (needed for dllexport/dllimport). -#ifdef _WIN32 -// this breaks new namespace declaraion rules; need to find a better fix -template class MANTID_MDALGORITHMS_DLL - Kernel::SingletonHolder<MDResolutionConvolutionFactoryImpl>; -#endif /* _WIN32 */ /// Typedef singleton instance to MDResolutionConvolutionFactory -typedef MANTID_MDALGORITHMS_DLL Kernel::SingletonHolder< - MDResolutionConvolutionFactoryImpl> MDResolutionConvolutionFactory; +typedef Kernel::SingletonHolder<MDResolutionConvolutionFactoryImpl> + MDResolutionConvolutionFactory; +} +} + +namespace Mantid { +namespace Kernel { +EXTERN_MANTID_MDALGORITHMS template class MANTID_MDALGORITHMS_DLL Kernel:: + SingletonHolder<Mantid::MDAlgorithms::MDResolutionConvolutionFactoryImpl>; } } diff --git a/Framework/MDAlgorithms/src/CreateMDWorkspace.cpp b/Framework/MDAlgorithms/src/CreateMDWorkspace.cpp index e78104c9860facec466c46f8930ceda69534cd4e..7a23dca48eabeb2633cf9cfcd9a3547d07535fd0 100644 --- a/Framework/MDAlgorithms/src/CreateMDWorkspace.cpp +++ b/Framework/MDAlgorithms/src/CreateMDWorkspace.cpp @@ -14,6 +14,9 @@ #include "MantidKernel/ListValidator.h" #include "MantidKernel/Memory.h" #include "MantidKernel/System.h" +#include "MantidKernel/MandatoryValidator.h" +#include <boost/algorithm/string.hpp> +#include <boost/regex.hpp> #include <cmath> namespace Mantid { @@ -22,6 +25,32 @@ using namespace Mantid::Kernel; using namespace Mantid::API; using namespace Mantid::Geometry; using namespace Mantid::DataObjects; +using boost::regex; + +/* + * The list of dimension names often looks like "[H,0,0],[0,K,0]" with "[H,0,0]" + * being the first dimension but getProperty returns a vector of + * the string split on every comma + * This function parses the string, and does not split on commas within brackets + */ +std::vector<std::string> parseNames(const std::string &names_string) { + + // This regex has two parts which are separated by the "|" (or) + // The first part matches anything which is bounded by square brackets + // unless they contain square brackets (so that it only matches inner pairs) + // The second part matches anything that doesn't contain a comma + // NB, the order of the two parts matters + + regex expression("\\[([^\\[]*)\\]|[^,]+"); + + boost::sregex_token_iterator iter(names_string.begin(), names_string.end(), + expression, 0); + boost::sregex_token_iterator end; + + std::vector<std::string> names_result(iter, end); + + return names_result; +} // Register the algorithm into the AlgorithmFactory DECLARE_ALGORITHM(CreateMDWorkspace) @@ -43,8 +72,9 @@ void CreateMDWorkspace::init() { "A comma separated list of min, max for each dimension,\n" "specifying the extents of each dimension."); - declareProperty(make_unique<ArrayProperty<std::string>>("Names"), - "A comma separated list of the name of each dimension."); + declareProperty( + make_unique<ArrayProperty<std::string>>("Names", Direction::Input), + "A comma separated list of the name of each dimension."); declareProperty(make_unique<ArrayProperty<std::string>>("Units"), "A comma separated list of the units of each dimension."); @@ -131,7 +161,9 @@ void CreateMDWorkspace::exec() { size_t ndims = static_cast<size_t>(ndims_prop); std::vector<double> extents = getProperty("Extents"); - std::vector<std::string> names = getProperty("Names"); + std::string dimensions_string = getPropertyValue("Names"); + std::vector<std::string> names = parseNames(dimensions_string); + std::vector<std::string> units = getProperty("Units"); std::vector<std::string> frames = getProperty("Frames"); diff --git a/Framework/MDAlgorithms/src/IntegratePeaksMDHKL.cpp b/Framework/MDAlgorithms/src/IntegratePeaksMDHKL.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b15a998f7b079b427b5e96061d82fe192bca29e9 --- /dev/null +++ b/Framework/MDAlgorithms/src/IntegratePeaksMDHKL.cpp @@ -0,0 +1,314 @@ +#include "MantidMDAlgorithms/IntegratePeaksMDHKL.h" +#include "MantidDataObjects/MDFramesToSpecialCoordinateSystem.h" +#include "MantidAPI/CommonBinsValidator.h" +#include "MantidAPI/InstrumentValidator.h" +#include "MantidAPI/WorkspaceUnitValidator.h" +#include "MantidDataObjects/EventWorkspace.h" +#include "MantidDataObjects/MDEventWorkspace.h" +#include "MantidDataObjects/MDHistoWorkspace.h" +#include "MantidGeometry/Instrument.h" +#include "MantidKernel/CompositeValidator.h" +#include "MantidGeometry/Crystal/IPeak.h" +#include <boost/math/special_functions/round.hpp> +#include <algorithm> +#include <limits> + +namespace Mantid { +namespace MDAlgorithms { + +using Mantid::Kernel::Direction; +// using Mantid::API::WorkspaceProperty; +using namespace Mantid::DataObjects; +using namespace Mantid::API; +using namespace Mantid::Kernel; +using namespace Mantid::Geometry; + +// Register the algorithm into the AlgorithmFactory +DECLARE_ALGORITHM(IntegratePeaksMDHKL) + +//---------------------------------------------------------------------------------------------- +/** + * Initialize the algorithm's properties. + */ +void IntegratePeaksMDHKL::init() { + declareProperty( + make_unique<WorkspaceProperty<IMDWorkspace>>("InputWorkspace", "", + Direction::Input), + "An input Sample MDHistoWorkspace or MDEventWorkspace in HKL."); + declareProperty("DeltaHKL", 0.5, + "Distance from integer HKL to integrate peak."); + declareProperty("GridPoints", 201, + "Number of grid points for each dimension of HKL box."); + declareProperty("NeighborPoints", 10, "Number of points in 5^3 surrounding " + "points above intensity threshold for " + "point to be part of peak."); + auto fluxValidator = boost::make_shared<CompositeValidator>(); + fluxValidator->add<WorkspaceUnitValidator>("Momentum"); + fluxValidator->add<InstrumentValidator>(); + fluxValidator->add<CommonBinsValidator>(); + auto solidAngleValidator = fluxValidator->clone(); + + declareProperty( + make_unique<WorkspaceProperty<>>("FluxWorkspace", "", Direction::Input, + PropertyMode::Optional, fluxValidator), + "An optional input workspace containing momentum dependent flux for " + "normalization."); + declareProperty(make_unique<WorkspaceProperty<>>( + "SolidAngleWorkspace", "", Direction::Input, + PropertyMode::Optional, solidAngleValidator), + "An optional input workspace containing momentum integrated " + "vanadium for normalization " + "(a measure of the solid angle)."); + + declareProperty(make_unique<WorkspaceProperty<PeaksWorkspace>>( + "PeaksWorkspace", "", Direction::Input), + "A PeaksWorkspace containing the peaks to integrate."); + + declareProperty( + make_unique<WorkspaceProperty<PeaksWorkspace>>("OutputWorkspace", "", + Direction::Output), + "The output PeaksWorkspace will be a copy of the input PeaksWorkspace " + "with the peaks' integrated intensities."); +} + +//---------------------------------------------------------------------------------------------- +/** + * Execute the algorithm. + */ +void IntegratePeaksMDHKL::exec() { + IMDWorkspace_sptr m_inputWS = getProperty("InputWorkspace"); + Mantid::DataObjects::MDFramesToSpecialCoordinateSystem converter; + boost::optional<Mantid::Kernel::SpecialCoordinateSystem> coordinateSystem = + converter(m_inputWS.get()); + if (*coordinateSystem != Mantid::Kernel::SpecialCoordinateSystem::HKL) { + std::stringstream errmsg; + errmsg << "Input MDWorkspace's coordinate system is not HKL."; + throw std::invalid_argument(errmsg.str()); + } + + /// Peak workspace to integrate + PeaksWorkspace_sptr inPeakWS = getProperty("PeaksWorkspace"); + const double box = getProperty("DeltaHKL"); + const int gridPts = getProperty("GridPoints"); + const int neighborPts = getProperty("NeighborPoints"); + /// Output peaks workspace, create if needed + PeaksWorkspace_sptr peakWS = getProperty("OutputWorkspace"); + if (peakWS != inPeakWS) + peakWS = inPeakWS->clone(); + + MatrixWorkspace_sptr flux = getProperty("FluxWorkspace"); + MatrixWorkspace_sptr sa = getProperty("SolidAngleWorkspace"); + + IMDEventWorkspace_sptr m_eventWS = + boost::dynamic_pointer_cast<IMDEventWorkspace>(m_inputWS); + IMDHistoWorkspace_sptr m_histoWS = + boost::dynamic_pointer_cast<IMDHistoWorkspace>(m_inputWS); + int npeaks = peakWS->getNumberPeaks(); + + auto prog = make_unique<Progress>(this, 0.3, 1.0, npeaks); + PARALLEL_FOR1(peakWS) + for (int i = 0; i < npeaks; i++) { + PARALLEL_START_INTERUPT_REGION + + IPeak &p = peakWS->getPeak(i); + // round to integer + int h = static_cast<int>(boost::math::iround(p.getH())); + int k = static_cast<int>(boost::math::iround(p.getK())); + int l = static_cast<int>(boost::math::iround(p.getL())); + MDHistoWorkspace_sptr histoBox; + if (m_histoWS) { + histoBox = cropHisto(h, k, l, box, m_histoWS); + } else if (sa && flux) { + histoBox = normalize(h, k, l, box, gridPts, flux, sa, m_eventWS); + } else { + histoBox = binEvent(h, k, l, box, gridPts, m_eventWS); + } + double intensity = 0.0; + double errorSquared = 0.0; + integratePeak(neighborPts, histoBox, intensity, errorSquared); + p.setIntensity(intensity); + p.setSigmaIntensity(sqrt(errorSquared)); + prog->report(); + PARALLEL_END_INTERUPT_REGION + } + PARALLEL_CHECK_INTERUPT_REGION + // Save the output + setProperty("OutputWorkspace", peakWS); +} + +MDHistoWorkspace_sptr +IntegratePeaksMDHKL::normalize(int h, int k, int l, double box, int gridPts, + const MatrixWorkspace_sptr &flux, + const MatrixWorkspace_sptr &sa, + const IMDEventWorkspace_sptr &ws) { + IAlgorithm_sptr normAlg = createChildAlgorithm("MDNormSCD"); + normAlg->setProperty("InputWorkspace", ws); + normAlg->setProperty("AlignedDim0", + "[H,0,0]," + boost::lexical_cast<std::string>(h - box) + + "," + boost::lexical_cast<std::string>(h + box) + + "," + std::to_string(gridPts)); + normAlg->setProperty("AlignedDim1", + "[0,K,0]," + boost::lexical_cast<std::string>(k - box) + + "," + boost::lexical_cast<std::string>(k + box) + + "," + std::to_string(gridPts)); + normAlg->setProperty("AlignedDim2", + "[0,0,L]," + boost::lexical_cast<std::string>(l - box) + + "," + boost::lexical_cast<std::string>(l + box) + + "," + std::to_string(gridPts)); + normAlg->setProperty("FluxWorkspace", flux); + normAlg->setProperty("SolidAngleWorkspace", sa); + normAlg->setProperty("OutputWorkspace", "mdout"); + normAlg->setProperty("OutputNormalizationWorkspace", "mdnorm"); + normAlg->executeAsChildAlg(); + Workspace_sptr mdout = normAlg->getProperty("OutputWorkspace"); + Workspace_sptr mdnorm = normAlg->getProperty("OutputNormalizationWorkspace"); + + IAlgorithm_sptr alg = createChildAlgorithm("DivideMD"); + alg->setProperty("LHSWorkspace", mdout); + alg->setProperty("RHSWorkspace", mdnorm); + alg->setPropertyValue("OutputWorkspace", "out"); + alg->execute(); + IMDWorkspace_sptr out = alg->getProperty("OutputWorkspace"); + return boost::dynamic_pointer_cast<MDHistoWorkspace>(out); +} + +void IntegratePeaksMDHKL::integratePeak(const int neighborPts, + MDHistoWorkspace_sptr out, + double &intensity, + double &errorSquared) { + std::vector<int> gridPts; + const size_t dimensionality = out->getNumDims(); + for (size_t i = 0; i < dimensionality; ++i) { + gridPts.push_back(static_cast<int>(out->getDimension(i)->getNBins())); + } + + double *F = out->getSignalArray(); + double Fmax = 0.; + double Fmin = std::numeric_limits<double>::max(); + double sum = 0.0; + for (int i = 0; i < gridPts[0] * gridPts[1] * gridPts[2]; i++) { + if (std::isnormal(F[i])) { + sum += F[i]; + Fmin = std::min(Fmin, F[i]); + Fmax = std::max(Fmax, F[i]); + } + } + double *SqError = out->getErrorSquaredArray(); + + double minIntensity = Fmin + 0.01 * (Fmax - Fmin); + int measuredPoints = 0; + int peakPoints = 0; + double peakSum = 0.0; + double measuredSum = 0.0; + double errSqSum = 0.0; + double measuredErrSqSum = 0.0; + for (int Hindex = 0; Hindex < gridPts[0]; Hindex++) { + for (int Kindex = 0; Kindex < gridPts[1]; Kindex++) { + for (int Lindex = 0; Lindex < gridPts[2]; Lindex++) { + int iHKL = Hindex + gridPts[0] * (Kindex + gridPts[1] * Lindex); + if (std::isfinite(F[iHKL])) { + measuredPoints = measuredPoints + 1; + measuredSum = measuredSum + F[iHKL]; + measuredErrSqSum = measuredErrSqSum + SqError[iHKL]; + if (F[iHKL] > minIntensity) { + int neighborPoints = 0; + for (int Hj = -2; Hj < 3; Hj++) { + for (int Kj = -2; Kj < 3; Kj++) { + for (int Lj = -2; Lj < 3; Lj++) { + int jHKL = + Hindex + Hj + + gridPts[0] * (Kindex + Kj + gridPts[1] * (Lindex + Lj)); + if (Lindex + Lj >= 0 && Lindex + Lj < gridPts[2] && + Kindex + Kj >= 0 && Kindex + Kj < gridPts[1] && + Hindex + Hj >= 0 && Hindex + Hj < gridPts[0] && + F[jHKL] > minIntensity) { + neighborPoints = neighborPoints + 1; + } + } + } + } + if (neighborPoints >= neighborPts) { + peakPoints = peakPoints + 1; + peakSum = peakSum + F[iHKL]; + errSqSum = errSqSum + SqError[iHKL]; + } + } + } else { + double minR = + sqrt(std::pow(float(Hindex) / float(gridPts[0]) - 0.5, 2) + + std::pow(float(Kindex) / float(gridPts[1]) - 0.5, 2) + + std::pow(float(Lindex) / float(gridPts[0]) - 0.5, 2)); + if (minR < 0.05) { + intensity = 0.0; + errorSquared = 0.0; + return; + } + } + } + } + } + double ratio = float(peakPoints) / float(measuredPoints - peakPoints); + intensity = peakSum - ratio * (measuredSum - peakSum); + errorSquared = errSqSum + ratio * (measuredErrSqSum - errSqSum); + return; +} + +/** + * Runs the BinMD algorithm on the input to provide the output workspace + * All slicing algorithm properties are passed along + * @return MDHistoWorkspace as a result of the binning + */ +MDHistoWorkspace_sptr +IntegratePeaksMDHKL::binEvent(int h, int k, int l, double box, int gridPts, + const IMDWorkspace_sptr &ws) { + IAlgorithm_sptr binMD = createChildAlgorithm("BinMD", 0.0, 0.3); + binMD->setProperty("InputWorkspace", ws); + binMD->setProperty("AlignedDim0", + "[H,0,0]," + boost::lexical_cast<std::string>(h - box) + + "," + boost::lexical_cast<std::string>(h + box) + "," + + std::to_string(gridPts)); + binMD->setProperty("AlignedDim1", + "[0,K,0]," + boost::lexical_cast<std::string>(k - box) + + "," + boost::lexical_cast<std::string>(k + box) + "," + + std::to_string(gridPts)); + binMD->setProperty("AlignedDim2", + "[0,0,L]," + boost::lexical_cast<std::string>(l - box) + + "," + boost::lexical_cast<std::string>(l + box) + "," + + std::to_string(gridPts)); + binMD->setPropertyValue("AxisAligned", "1"); + binMD->setPropertyValue("OutputWorkspace", "out"); + binMD->executeAsChildAlg(); + Workspace_sptr outputWS = binMD->getProperty("OutputWorkspace"); + return boost::dynamic_pointer_cast<MDHistoWorkspace>(outputWS); +} + +/** + * Runs the BinMD algorithm on the input to provide the output workspace + * All slicing algorithm properties are passed along + * @return MDHistoWorkspace as a result of the binning + */ +MDHistoWorkspace_sptr +IntegratePeaksMDHKL::cropHisto(int h, int k, int l, double box, + const IMDWorkspace_sptr &ws) { + IAlgorithm_sptr cropMD = + createChildAlgorithm("IntegrateMDHistoWorkspace", 0.0, 0.3); + cropMD->setProperty("InputWorkspace", ws); + + cropMD->setProperty("P1Bin", boost::lexical_cast<std::string>(h - box) + + ",0," + + boost::lexical_cast<std::string>(h + box)); + cropMD->setProperty("P2Bin", boost::lexical_cast<std::string>(k - box) + + ",0," + + boost::lexical_cast<std::string>(k + box)); + cropMD->setProperty("P3Bin", boost::lexical_cast<std::string>(l - box) + + ",0," + + boost::lexical_cast<std::string>(l + box)); + + cropMD->setPropertyValue("OutputWorkspace", "out"); + cropMD->executeAsChildAlg(); + IMDHistoWorkspace_sptr outputWS = cropMD->getProperty("OutputWorkspace"); + return boost::dynamic_pointer_cast<MDHistoWorkspace>(outputWS); +} + +} // namespace MDAlgorithms +} // namespace Mantid diff --git a/Framework/MDAlgorithms/src/ReplicateMD.cpp b/Framework/MDAlgorithms/src/ReplicateMD.cpp index 3f58978075d568c5eb27cf9f47eed12e59d6d969..9966a1f2210600af0078ed386607611240c9c20a 100644 --- a/Framework/MDAlgorithms/src/ReplicateMD.cpp +++ b/Framework/MDAlgorithms/src/ReplicateMD.cpp @@ -293,8 +293,24 @@ void ReplicateMD::exec() { the linear index -> linear index calculation below will not work correctly. */ MDHistoWorkspace_const_sptr transposedDataWS = dataWS; - if (dataWS->getNumDims() == shapeWS->getNumDims()) { + if (nDimsData <= nDimsShape) { auto axes = findAxes(*shapeWS, *dataWS); + // Check that the indices stored in axes are compatible with the + // dimensionality of the data workspace + const auto numberOfDimensionsOfDataWorkspace = static_cast<int>(nDimsData); + for (const auto &axis : axes) { + if (axis >= numberOfDimensionsOfDataWorkspace) { + std::string message = + "ReplicateMD: Cannot transpose the data workspace. Attempting to " + "swap dimension index " + + std::to_string( + std::distance(static_cast<const int *>(&axes[0]), &axis)) + + " with index " + std::to_string(axis) + + ", but the dimensionality of the data workspace is " + + std::to_string(nDimsData); + throw std::runtime_error(message); + } + } transposedDataWS = transposeMD(dataWS, axes); nDimsData = transposedDataWS->getNumDims(); } diff --git a/Framework/MDAlgorithms/test/IntegratePeaksMDHKLTest.h b/Framework/MDAlgorithms/test/IntegratePeaksMDHKLTest.h new file mode 100644 index 0000000000000000000000000000000000000000..13cc818f4c9d55d10e2076f03d838830c8238c9e --- /dev/null +++ b/Framework/MDAlgorithms/test/IntegratePeaksMDHKLTest.h @@ -0,0 +1,192 @@ +#ifndef MANTID_MDAGORITHMS_INTEGRATEPEAKSMDHKLTEST_H_ +#define MANTID_MDAGORITHMS_INTEGRATEPEAKSMDHKLTEST_H_ + +#include "MantidAPI/AnalysisDataService.h" +#include "MantidAPI/IMDEventWorkspace.h" +#include "MantidAPI/FrameworkManager.h" +#include "MantidDataObjects/MDEventFactory.h" +#include "MantidDataObjects/PeaksWorkspace.h" +#include "MantidDataObjects/PeakShapeSpherical.h" +#include "MantidGeometry/MDGeometry/MDHistoDimension.h" +#include "MantidGeometry/MDGeometry/HKL.h" +#include "MantidMDAlgorithms/IntegratePeaksMDHKL.h" +#include "MantidMDAlgorithms/CreateMDWorkspace.h" +#include "MantidMDAlgorithms/FakeMDEventData.h" +#include "MantidTestHelpers/ComponentCreationHelper.h" +#include "MantidKernel/UnitLabelTypes.h" + +#include <boost/math/distributions/normal.hpp> +#include <boost/math/special_functions/fpclassify.hpp> +#include <boost/math/special_functions/pow.hpp> +#include <boost/random/linear_congruential.hpp> +#include <boost/random/mersenne_twister.hpp> +#include <boost/random/uniform_int.hpp> +#include <boost/random/uniform_real.hpp> +#include <boost/random/variate_generator.hpp> + +#include <cxxtest/TestSuite.h> + +#include <Poco/File.h> + +using Mantid::Geometry::MDHistoDimension; +using namespace Mantid::API; +using namespace Mantid::DataObjects; +using namespace Mantid::Geometry; +using namespace Mantid::MDAlgorithms; +using Mantid::Kernel::V3D; + +class IntegratePeaksMDHKLTest : public CxxTest::TestSuite { +public: + IntegratePeaksMDHKLTest() { Mantid::API::FrameworkManager::Instance(); } + ~IntegratePeaksMDHKLTest() override {} + + void test_Init() { + IntegratePeaksMDHKL alg; + TS_ASSERT_THROWS_NOTHING(alg.initialize()) + TS_ASSERT(alg.isInitialized()) + } + + //------------------------------------------------------------------------------- + /** Run the IntegratePeaksMDHKL with the given peak radius integration param + */ + static void + doRun(std::string OutputWorkspace = "IntegratePeaksMDHKLTest_peaks") { + IntegratePeaksMDHKL alg; + TS_ASSERT_THROWS_NOTHING(alg.initialize()) + TS_ASSERT(alg.isInitialized()) + TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue( + "InputWorkspace", "IntegratePeaksMDHKLTest_MDEWS")); + TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue( + "PeaksWorkspace", "IntegratePeaksMDHKLTest_peaks")); + TS_ASSERT_THROWS_NOTHING( + alg.setPropertyValue("OutputWorkspace", OutputWorkspace)); + TS_ASSERT_THROWS_NOTHING(alg.execute()); + TS_ASSERT(alg.isExecuted()); + } + + //------------------------------------------------------------------------------- + /** Create the (blank) MDEW */ + static void createMDEW() { + // ---- Start with empty MDEW ---- + + CreateMDWorkspace algC; + TS_ASSERT_THROWS_NOTHING(algC.initialize()) + TS_ASSERT(algC.isInitialized()) + TS_ASSERT_THROWS_NOTHING(algC.setProperty("Dimensions", "3")); + TS_ASSERT_THROWS_NOTHING( + algC.setProperty("Extents", "-10,10,-10,10,-10,10")); + + TS_ASSERT_THROWS_NOTHING( + algC.setProperty("Names", "[H,0,0],[0,K,0],[0,0,L]")); + std::string units = Mantid::Kernel::Units::Symbol::RLU.ascii() + "," + + Mantid::Kernel::Units::Symbol::RLU.ascii() + "," + + Mantid::Kernel::Units::Symbol::RLU.ascii(); + TS_ASSERT_THROWS_NOTHING(algC.setProperty("Units", units)); + TS_ASSERT_THROWS_NOTHING(algC.setProperty("SplitInto", "5")); + TS_ASSERT_THROWS_NOTHING(algC.setProperty("MaxRecursionDepth", "2")); + std::string frames = Mantid::Geometry::HKL::HKLName + "," + + Mantid::Geometry::HKL::HKLName + "," + + Mantid::Geometry::HKL::HKLName; + TS_ASSERT_THROWS_NOTHING(algC.setProperty("Frames", frames)); + TS_ASSERT_THROWS_NOTHING(algC.setPropertyValue( + "OutputWorkspace", "IntegratePeaksMDHKLTest_MDEWS")); + TS_ASSERT_THROWS_NOTHING(algC.execute()); + TS_ASSERT(algC.isExecuted()); + } + + //------------------------------------------------------------------------------- + /** Add a fake peak */ + static void addPeak(size_t num, double x, double y, double z, double radius) { + std::ostringstream mess; + mess << num << ", " << x << ", " << y << ", " << z << ", " << radius; + FakeMDEventData algF; + TS_ASSERT_THROWS_NOTHING(algF.initialize()) + TS_ASSERT(algF.isInitialized()) + TS_ASSERT_THROWS_NOTHING(algF.setPropertyValue( + "InputWorkspace", "IntegratePeaksMDHKLTest_MDEWS")); + TS_ASSERT_THROWS_NOTHING( + algF.setProperty("PeakParams", mess.str().c_str())); + TS_ASSERT_THROWS_NOTHING(algF.setProperty("RandomSeed", "63759")); + TS_ASSERT_THROWS_NOTHING(algF.setProperty("RandomizeSignal", "1")); + TS_ASSERT_THROWS_NOTHING(algF.execute()); + TS_ASSERT(algF.isExecuted()); + } + + //------------------------------------------------------------------------------- + /** Full test using faked-out peak data */ + void test_exec() { + // --- Fake workspace with 3 peaks ------ + createMDEW(); + addPeak(1000, 1., 1., 1., 0.1); + addPeak(1000, 2., 3., 4., 0.15); + addPeak(1000, 6., 6., 6., 0.2); + + MDEventWorkspace3Lean::sptr mdews = + AnalysisDataService::Instance().retrieveWS<MDEventWorkspace3Lean>( + "IntegratePeaksMDHKLTest_MDEWS"); + auto &frame = mdews->getDimension(0)->getMDFrame(); + TSM_ASSERT_EQUALS("Should be HKL", Mantid::Geometry::HKL::HKLName, + frame.name()); + TS_ASSERT_EQUALS(mdews->getNPoints(), 3000); + TS_ASSERT_DELTA(mdews->getBox()->getSignal(), 3021.7071, 1e-2); + + // Make a fake instrument - doesn't matter, we won't use it really + Instrument_sptr inst = + ComponentCreationHelper::createTestInstrumentRectangular(1, 100, 0.05); + + // --- Make a fake PeaksWorkspace --- + PeaksWorkspace_sptr peakWS0(new PeaksWorkspace()); + peakWS0->setInstrument(inst); + Peak Pin(inst, 15050, 1.0); + Pin.setHKL(V3D(1, 1, 1)); + peakWS0->addPeak(Pin); + + TS_ASSERT_EQUALS(peakWS0->getPeak(0).getIntensity(), 0.0); + AnalysisDataService::Instance().add("IntegratePeaksMDHKLTest_peaks", + peakWS0); + + // ------------- Integrating with cylinder ------------------------ + doRun("IntegratePeaksMDHKLTest_peaks"); + + TS_ASSERT_DELTA(peakWS0->getPeak(0).getIntensity(), 29.4284, 1e-2); + + // Error is also calculated + TS_ASSERT_DELTA(peakWS0->getPeak(0).getSigmaIntensity(), 5.2813, 1e-2); + } + + //------------------------------------------------------------------------------- + /// Integrate background between start/end background radius + void test_exec_shellBackground() { + createMDEW(); + /* Create 3 overlapping shells so that density goes like this: + * r < 1 : density 1.0 + * 1 < r < 2 : density 1/2 + * 2 < r < 3 : density 1/3 + */ + addPeak(1000, 1., 1., 1., 0.1); + addPeak(1000 * 4, 0., 0., 0., + 2.0); // 8 times the volume / 4 times the counts = 1/2 density + addPeak(1000 * 9, 0., 0., 0., + 3.0); // 27 times the volume / 9 times the counts = 1/3 density + + // --- Make a fake PeaksWorkspace --- + PeaksWorkspace_sptr peakWS(new PeaksWorkspace()); + Instrument_sptr inst = + ComponentCreationHelper::createTestInstrumentCylindrical(5); + Peak Pin(inst, 1, 1.0); + Pin.setHKL(V3D(1, 1, 1)); + peakWS->addPeak(Pin); + TS_ASSERT_EQUALS(peakWS->getPeak(0).getIntensity(), 0.0); + AnalysisDataService::Instance().addOrReplace( + "IntegratePeaksMDHKLTest_peaks", peakWS); + + // Set background from 2.0 to 3.0. + doRun("IntegratePeaksMDHKLTest_peaks"); + TS_ASSERT_DELTA(peakWS->getPeak(0).getIntensity(), 29.4275, 0.1); + // Error is larger, since it is error of peak + error of background + TSM_ASSERT_DELTA("Error has increased", + peakWS->getPeak(0).getSigmaIntensity(), 5.2814, 0.1); + } +}; + +#endif /* MANTID_MDEVENTS_INTEGRATEPEAKSMDHKLTEST_H_ */ diff --git a/Framework/PythonInterface/mantid/kernel/src/Converters/NDArrayToVector.cpp b/Framework/PythonInterface/mantid/kernel/src/Converters/NDArrayToVector.cpp index 513895f6a0c1f4933357ecd24bf391da5646db57..849aa072f524bdffbedeeeab060c54d12b01a775 100644 --- a/Framework/PythonInterface/mantid/kernel/src/Converters/NDArrayToVector.cpp +++ b/Framework/PythonInterface/mantid/kernel/src/Converters/NDArrayToVector.cpp @@ -139,7 +139,7 @@ void NDArrayToVector<DestElementType>::typeCheck() { // Explicit instantiations //------------------------------------------------------------------------ #define INSTANTIATE_TOVECTOR(ElementType) \ - template DLLExport struct NDArrayToVector<ElementType>; + template struct DLLExport NDArrayToVector<ElementType>; ///@cond Doxygen doesn't seem to like this... INSTANTIATE_TOVECTOR(int) diff --git a/Framework/PythonInterface/mantid/kernel/src/Converters/NDArrayTypeIndex.cpp b/Framework/PythonInterface/mantid/kernel/src/Converters/NDArrayTypeIndex.cpp index 1f7250a6a35fc573304b90e489acd1e88ebf8705..71f5fb8ff70e63833b8bad08725615286b1edf04 100644 --- a/Framework/PythonInterface/mantid/kernel/src/Converters/NDArrayTypeIndex.cpp +++ b/Framework/PythonInterface/mantid/kernel/src/Converters/NDArrayTypeIndex.cpp @@ -17,7 +17,7 @@ namespace Converters { /// Macro to define mappings between the CType and Numpy enum #define DEFINE_TYPE_MAPPING(CType, NDTypeNum) \ template <> int NDArrayTypeIndex<CType>::typenum = NDTypeNum; \ - template PYTHON_KERNEL_DLL struct NDArrayTypeIndex<CType>; + template struct NDArrayTypeIndex<CType>; DEFINE_TYPE_MAPPING(int, NPY_INT) DEFINE_TYPE_MAPPING(long, NPY_LONG) diff --git a/Framework/PythonInterface/mantid/kernel/src/Registry/SequenceTypeHandler.cpp b/Framework/PythonInterface/mantid/kernel/src/Registry/SequenceTypeHandler.cpp index b7dab52f39d5bd2930f395a8602cf70a5cced985..2324e1ac3d115809351fc372c5a544dc18bb4dea 100644 --- a/Framework/PythonInterface/mantid/kernel/src/Registry/SequenceTypeHandler.cpp +++ b/Framework/PythonInterface/mantid/kernel/src/Registry/SequenceTypeHandler.cpp @@ -117,7 +117,7 @@ std::unique_ptr<Kernel::Property> SequenceTypeHandler<ContainerType>::create( //----------------------------------------------------------------------- ///@cond #define INSTANTIATE(ElementType) \ - template DLLExport struct SequenceTypeHandler<std::vector<ElementType>>; + template struct DLLExport SequenceTypeHandler<std::vector<ElementType>>; INSTANTIATE(int) INSTANTIATE(long) diff --git a/Framework/PythonInterface/plugins/algorithms/CylinderPaalmanPingsCorrection2.py b/Framework/PythonInterface/plugins/algorithms/CylinderPaalmanPingsCorrection2.py index 42cac4b651b87fb14dea9159abe84910f9c84bcc..6e1711c3be3440967dd9983d9d7cdf9fb8818a9c 100644 --- a/Framework/PythonInterface/plugins/algorithms/CylinderPaalmanPingsCorrection2.py +++ b/Framework/PythonInterface/plugins/algorithms/CylinderPaalmanPingsCorrection2.py @@ -105,8 +105,8 @@ class CylinderPaalmanPingsCorrection(PythonAlgorithm): doc='Number of wavelengths for calculation') self.declareProperty(name='Emode', defaultValue='Elastic', - validator=StringListValidator(['Elastic', 'Indirect']), - doc='Emode: Elastic or Indirect') + validator=StringListValidator(['Elastic', 'Indirect', 'Direct']), + doc='Energy transfer mode') self.declareProperty(name='Efixed', defaultValue=1.0, doc='Analyser energy') @@ -358,9 +358,7 @@ class CylinderPaalmanPingsCorrection(PythonAlgorithm): if self._emode == 'Elastic': self._elastic = self._waves[int(len(self._waves) / 2)] - elif self._emode == 'Direct': - self._elastic = math.sqrt(81.787/self._efixed) # elastic wavelength - elif self._emode == 'Indirect': + else: self._elastic = math.sqrt(81.787/self._efixed) # elastic wavelength logger.information('Elastic lambda : %f' % (self._elastic)) diff --git a/Framework/PythonInterface/plugins/algorithms/ExportSpectraMask.py b/Framework/PythonInterface/plugins/algorithms/ExportSpectraMask.py new file mode 100644 index 0000000000000000000000000000000000000000..471d89b6d7e95a2da45b85c0933d01dca4b03f37 --- /dev/null +++ b/Framework/PythonInterface/plugins/algorithms/ExportSpectraMask.py @@ -0,0 +1,208 @@ +#pylint: disable=invalid-name, no-init +import os +from mantid import config +from mantid.api import PythonAlgorithm, AlgorithmFactory, WorkspaceProperty, mtd, FileProperty, FileAction +from mantid.kernel import Direction, logger, IntArrayProperty + +def export_masks(ws,fileName='',returnMasksOnly=False): + """Exports masks applied to Mantid workspace + (e.g. drawn using the instrument view) and write these masks + into the old fashioned ASCII .msk file containing masked spectra numbers. + + The file is Libisis/Mantid old ISIS format compatible and can be read by Libisis + or Mantid LoadMasks algorithm + + If optional parameter fileName is present, the masks are saved + in the file with this name + Otherwise, the file with the name equal to the workspace + name and the extension .msk is used. + + If returnMasks is set to True, the function does not write to file but returns + list of masks instead. + """ + # get pointer to the workspace + if type(ws) == str: + pws = mtd[ws] + else: + pws = ws + + + ws_name=pws.getName() + nhist = pws.getNumberHistograms() + + no_detectors = 0 + masks = [] + for i in range(nhist): + # set provisional spectra ID + ms = i+1 + try: + sp = pws.getSpectrum(i) + # got real spectra ID, which would correspond real spectra num to spectra ID map + ms = sp.getSpectrumNo() +#pylint: disable=W0703 + except Exception: + logger.notice("Can not retrieve spectra No: " + str(i) + ". Have masked it") + masks.append(ms) + continue + try: + det = pws.getDetector(i) +#pylint: disable=W0703 + except Exception: + no_detectors = no_detectors +1 + masks.append(ms) + continue + if det.isMasked(): + masks.append(ms) + + filename='' + if len(fileName)==0 : + filename = os.path.join(config.getString('defaultsave.directory'),ws_name+'.msk') + else: + filename = fileName + + + nMasks = len(masks) + if nMasks == 0: + if returnMasksOnly: + logger.warning("Workspace {0} have no masked spectra. File {1} have not been created".format(ws_name,filename)) + else: + logger.notice("Workspace "+ws_name+" have no masked spectra") + return masks + + logger.notice("Workspace {0} has {1} masked spectra, including {2} spectra without detectors".format(ws_name,nMasks,no_detectors)) + + + if not returnMasksOnly : + writeISISmasks(filename,masks,8) + return masks + + + +def flushOutString(f,OutString,BlockSize,BlockLimit): + """Internal function for writeISISmasks procedure, + which writes down specified number of mask blocks, + not to exceed the specified number of masks in row. + """ + BlockSize+=1 + if BlockSize >= BlockLimit: + if len(OutString)>0: + f.write(OutString+'\n') + OutString = '' + BlockSize = 0 + return (f,BlockSize,OutString) + + +def writeISISmasks(filename,masks,nSpectraInRow=8): + """Function writes input array in the form of ISSI mask file array + This is the helper function for export_mask procedure, + which can be used separately + + namely, if one have array 1,2,3,4, 20, 30,31,32 + file will have the following ASCII stings: + 1-4 20 30-32 + + nSpectaInRow indicates the number of the separate spectra ID (numbers) which the program + needs to fit into one row. For the example above the number has to be 5 or more + to fit all spectra into a single row. Setting it to one will produce 8 rows with single number in each. + + Usage: + >>writeISISmasks(fileName,masks) + where: + fileName -- the name of the output file + masks -- the array with data + """ + ext = os.path.splitext(filename)[1] + if len(ext) == 0 : + filename=filename+'.msk' + + OutString = '' + LastSpectraN= '' + BlockSize = 0 + iDash = 0 + im1=masks[0] + + with open(filename,'w') as f: + # prepare and write mask data in conventional msk format + # where adjusted spectra are separated by "-" sign + for i in masks: + if len(OutString)== 0: + OutString = str(i) + (f,BlockSize,OutString) = flushOutString(f,OutString,BlockSize,nSpectraInRow) + im1 = i + continue + # if the current spectra is different from the previous one by 1 only, we may want to skip it + if im1+1 == i : + LastSpectraN = str(i) + iDash += 1 + else : # it is different and should be dealt separately + if iDash > 0 : + OutString = OutString+'-'+LastSpectraN + iDash = 0 + LastSpectraN='' + # write the string if it is finished + (f,BlockSize,OutString) = flushOutString(f,OutString,BlockSize,nSpectraInRow) + + if len(OutString) == 0: + OutString = str(i) + else: + OutString = OutString + ' ' + str(i) + # write the string if it is finished + (f,BlockSize,OutString) = flushOutString(f,OutString,BlockSize,nSpectraInRow) + #endif + + # current spectra is the previous now + im1 = i + # end masks loop + if iDash > 0 : + OutString = OutString+'-'+LastSpectraN + (f,OutString,BlockSize)=flushOutString(f,OutString,BlockSize,0) + + + +class ExportSpectraMask(PythonAlgorithm): + """ Export workspace's mask + """ + def category(self): + """ Return category + """ + return "DataHandling\\Masking" + + def name(self): + """ Return name + """ + return "ExportSpectraMask" + + def summary(self): + return "Returns list of spectra numbers which are masked on a workspace"\ + " and can save these numbers as legacy .msk file." + + def PyInit(self): + """ Declare properties + """ + self.declareProperty(WorkspaceProperty("Workspace", "",Direction.Input), "The workspace to export masks from.") + + self.declareProperty(FileProperty(name="Filename",defaultValue="",action=FileAction.OptionalSave,\ + extensions = [".msk"],direction=Direction.Input),\ + doc="The name or full path to the file to save mask to."\ + " If empty, the name of the input workspace and default save directory are used.") + self.declareProperty("ExportMaskOnly",False,"If true, algorithm will not save mask in a file"\ + "and only returns the list containing numbers of masked spectra.",\ + Direction.Input) + self.declareProperty(IntArrayProperty(name="SpectraMasks",direction = Direction.Output),\ + doc="List of the masked spectra numbers.") + return + + def PyExec(self): + """ Main execution body + """ + #get parameters + ws = self.getProperty("Workspace").value + out_file_name = self.getProperty("Filename").value + export_masks_only = self.getProperty("ExportMaskOnly").value + + masks = export_masks(ws,out_file_name ,export_masks_only) + self.setProperty("SpectraMasks", masks) + return + + +AlgorithmFactory.subscribe(ExportSpectraMask) diff --git a/Framework/PythonInterface/plugins/algorithms/LoadPreNexusLive.py b/Framework/PythonInterface/plugins/algorithms/LoadPreNexusLive.py new file mode 100644 index 0000000000000000000000000000000000000000..cf2a3cccfac89e69e544069d6ba58c74aac05479 --- /dev/null +++ b/Framework/PythonInterface/plugins/algorithms/LoadPreNexusLive.py @@ -0,0 +1,118 @@ +from mantid import mtd +from mantid.api import AlgorithmFactory, DataProcessorAlgorithm, FileAction, \ + FileProperty, WorkspaceProperty +from mantid.kernel import Direction, EnabledWhenProperty, \ + PropertyCriterion, StringListValidator +from mantid.simpleapi import * +import os + + +class LoadPreNexusLive(DataProcessorAlgorithm): + def category(self): + return 'DataHandling' + + def findLivefile(self, instrument): + livepath = '/SNS/%s/shared/live/' % instrument + filenames = os.listdir(livepath) + + filenames = [name for name in filenames + if name.startswith(instrument)] + filenames = [name for name in filenames + if name.endswith('_live_neutron_event.dat')] + + if len(filenames) <= 0: + raise RuntimeError("Failed to find live file for '%s'" % instrument) + + filenames.sort() + + return os.path.join(livepath, filenames[-1]) + + def findLogfile(self, instrument, runNumber): + filename = self.getProperty('LogFilename').value + if len(filename) > 0 and os.path.exists(filename): + return filename + + try: + iptsdir = GetIPTS(Instrument=instrument, RunNumber=runNumber) + self.log().information('ipts %s' % iptsdir) + except RuntimeError: + msg = 'Failed to determine the IPTS containing %s_%d' % (instrument, runNumber) + self.log().warning(msg) + return '' + + direc = os.path.join(iptsdir, 'data') + + filenames = os.listdir(direc) + filenames = [name for name in filenames + if name.endswith('_event.nxs')] + + if len(filenames) <= 0: + raise RuntimeError("Failed to find existing nexus file in '%s'" % iptsdir) + + filenames.sort() + + return os.path.join(direc, filenames[-1]) + + def PyInit(self): + instruments = ['BSS', 'SNAP', 'REF_M', 'CNCS', 'EQSANS', 'VULCAN', + 'VENUS', 'MANDI', 'TOPAZ', 'ARCS'] + self.declareProperty('Instrument', '', + StringListValidator(instruments), + 'Empty uses default instrument') + + self.declareProperty(WorkspaceProperty('OutputWorkspace', '', + direction=Direction.Output)) + + self.declareProperty('NormalizeByCurrent', True, 'Normalize by current') + + self.declareProperty('LoadLogs', True, + 'Attempt to load logs from an existing file') + + self.declareProperty(FileProperty('LogFilename', '', + direction=Direction.Input, + action=FileAction.OptionalLoad, + extensions=['_event.nxs']), + doc='File containing logs to use (Optional)') + self.setPropertySettings('LogFilename', + EnabledWhenProperty('LoadLogs', + PropertyCriterion.IsDefault)) + + def PyExec(self): + instrument = self.getProperty('Instrument').value + + eventFilename = self.findLivefile(instrument) + + self.log().information("Loading '%s'" % eventFilename) + wkspName = self.getPropertyValue('OutputWorkspace') + LoadEventPreNexus(EventFilename=eventFilename, + OutputWorkspace=wkspName) + + # let people know what was just loaded + wksp = mtd[wkspName] + instrument = str(wksp.getInstrument().getName()) + runNumber = int(wksp.run()['run_number'].value) + startTime = str(wksp.run().startTime()) + self.log().information('Loaded %s live run %d - starttime=%s' + % (instrument, runNumber, startTime)) + + if self.getProperty('NormalizeByCurrent').value: + self.log().information('Normalising by current') + NormaliseByCurrent(InputWorkspace=wkspName, + Outputworkspace=wkspName) + + if self.getProperty('LoadLogs').value: + logFilename = self.findLogfile(instrument, runNumber) + if len(logFilename) > 0: + self.log().information('Loading logs from %s' % logFilename) + LoadNexusLogs(Workspace=wkspName, Filename=logFilename) + wksp = mtd[wkspName] + instrFilename = wksp.getInstrumentFilename(instrument, startTime) + LoadInstrument(Workspace=wkspName, Filename=instrFilename, + RewriteSpectraMap=True) + + # gets rid of many simple DAS errors + FilterByXValue(InputWorkspace=wkspName, XMin=1) + + self.setProperty('OutputWorkspace', mtd[wkspName]) + +AlgorithmFactory.subscribe(LoadPreNexusLive) diff --git a/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/FlatPlatePaalmanPingsCorrection.py b/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/FlatPlatePaalmanPingsCorrection.py index a0a9224d4a800ad3542065ad2c053da8c95420a4..0991d85cf98383310567e83480792f8c1fa7aea1 100644 --- a/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/FlatPlatePaalmanPingsCorrection.py +++ b/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/FlatPlatePaalmanPingsCorrection.py @@ -87,8 +87,8 @@ class FlatPlatePaalmanPingsCorrection(PythonAlgorithm): doc='Interpolate the correction workspaces to match the sample workspace') self.declareProperty(name='Emode', defaultValue='Elastic', - validator=StringListValidator(['Elastic', 'Indirect']), - doc='Emode: Elastic or Indirect') + validator=StringListValidator(['Elastic', 'Indirect', 'Direct']), + doc='Energy transfer mode') self.declareProperty(name='Efixed', defaultValue=1.0, doc='Analyser energy') @@ -281,7 +281,7 @@ class FlatPlatePaalmanPingsCorrection(PythonAlgorithm): if self._emode == 'Elastic': self._elastic = self._waves[int(number_waves / 2)] - elif self._emode == 'Indirect': + else: self._elastic = math.sqrt(81.787 / self._efixed) # elastic wavelength logger.information('Elastic lambda %f' % self._elastic) diff --git a/Framework/PythonInterface/test/python/plugins/algorithms/CMakeLists.txt b/Framework/PythonInterface/test/python/plugins/algorithms/CMakeLists.txt index 99fa18305588ef6aa15630bd610c81228b6b6be1..884e808c89eb5285586cfe431983c583177141d0 100644 --- a/Framework/PythonInterface/test/python/plugins/algorithms/CMakeLists.txt +++ b/Framework/PythonInterface/test/python/plugins/algorithms/CMakeLists.txt @@ -30,6 +30,7 @@ set ( TEST_PY_FILES EnggFitPeaksTest.py EnggFocusTest.py EnggVanadiumCorrectionsTest.py + ExportSpectraMaskTest.py FilterLogByTimeTest.py FindEPPTest.py FindReflectometryLinesTest.py diff --git a/Framework/PythonInterface/test/python/plugins/algorithms/CylinderPaalmanPingsCorrection2Test.py b/Framework/PythonInterface/test/python/plugins/algorithms/CylinderPaalmanPingsCorrection2Test.py index 206e169f0d0996b8a547795b9bfef65ac185a971..657864282ca96c5c2fb38b1f0b20c7d514e74817 100644 --- a/Framework/PythonInterface/test/python/plugins/algorithms/CylinderPaalmanPingsCorrection2Test.py +++ b/Framework/PythonInterface/test/python/plugins/algorithms/CylinderPaalmanPingsCorrection2Test.py @@ -83,9 +83,9 @@ class CylinderPaalmanPingsCorrection2Test(unittest.TestCase): self._verify_workspace(workspace) - def test_sampleOnly(self): + def test_sampleOnly_Indirect(self): """ - Test simple run with sample workspace only. + Test simple run with sample workspace only for indirect mode """ CylinderPaalmanPingsCorrection(OutputWorkspace=self._corrections_ws_name, @@ -97,7 +97,23 @@ class CylinderPaalmanPingsCorrection2Test(unittest.TestCase): Efixed=1.845) ass_ws_name = self._corrections_ws_name + '_ass' - self. _verify_workspace(ass_ws_name) + self._verify_workspace(ass_ws_name) + + def test_sampleOnly_Direct(self): + """ + Test simple run with sample workspace only for direct mode + """ + + CylinderPaalmanPingsCorrection(OutputWorkspace=self._corrections_ws_name, + SampleWorkspace=self._sample_ws, + SampleChemicalFormula='H2-O', + SampleInnerRadius=0.05, + SampleOuterRadius=0.1, + Emode='Direct', + Efixed=1.845) + + ass_ws_name = self._corrections_ws_name + '_ass' + self._verify_workspace(ass_ws_name) def test_sampleAndCan(self): diff --git a/Framework/PythonInterface/test/python/plugins/algorithms/ExportSpectraMaskTest.py b/Framework/PythonInterface/test/python/plugins/algorithms/ExportSpectraMaskTest.py new file mode 100644 index 0000000000000000000000000000000000000000..2ec72d02986ff0bb34e2fb781e8e60d0f75dffe7 --- /dev/null +++ b/Framework/PythonInterface/test/python/plugins/algorithms/ExportSpectraMaskTest.py @@ -0,0 +1,92 @@ +import os +import sys +import numpy as np +import unittest +import mantid +from mantid.simpleapi import ExportSpectraMask,DeleteWorkspace + +class ExportSpectraMaskTest(unittest.TestCase): + def __init__(self,method_name): + unittest.TestCase.__init__(self,method_name) + + self.this_path = os.path.dirname(os.path.realpath(__file__)) + test_path = self.this_path; + for i in xrange(0,4): + test_path,_ = os.path.split(test_path) + self.test_mod_path = os.path.join(test_path,'plugins/algorithms') + sys.path.append(self.test_mod_path) + + self.test_files_path = mantid.config.getString('defaultsave.directory') + self.test_file = os.path.join(self.test_files_path,'test_mask_file') + + + def setUp(self): + """ """ + + self.masks = [1,4,8,10,199,200] + if not 'test_ws' in mantid.api.mtd: + test_ws = mantid.simpleapi.CreateSampleWorkspace() + test_ws.maskDetectors(self.masks) + if not hasattr(self,'write_f'): + import ExportSpectraMask as amc + self.test_write_f = amc.writeISISmasks + self.test_export_f = amc.export_masks + + return super(ExportSpectraMaskTest, self).setUp() + + def tearDown(self): + if 'test_ws' in mantid.api.mtd: + DeleteWorkspace('test_ws') + test_file = self.test_file + '.msk' + if os.path.isfile(test_file ): + os.remove(test_file) + return super(ExportSpectraMaskTest, self).tearDown() + + def test_writeISISmasks(self): + masks = [1,20,30,40,41,42,43]; + + test_file = self.test_file + + # Test single row writing + self.test_write_f(test_file,masks) + + self.assertTrue(os.path.isfile(test_file + '.msk')) + with open(test_file + '.msk','r') as tf: + for line in tf: + self.assertEqual(line,'1 20 30 40-43\n') + os.remove(test_file + '.msk') + + # Test multiple row writing + test_file = test_file + '.msk' + masks = masks + [46,47,49,50] + self.test_write_f(test_file,masks,4) + self.assertTrue(os.path.isfile(test_file)) + + sample = ['1 20 30 40\n','41-43 46-47\n','49-50\n'] + with open(test_file,'r') as tf: + for line,s in zip(tf,sample): + self.assertEqual(line,s) + + def test_exportMasks(self): + r_masks = self.test_export_f('test_ws','',True) + self.assertEqual(self.masks,r_masks) + + def test_ExportAlgosWork(self): + r_masks = ExportSpectraMask('test_ws',ExportMaskOnly=True) + self.assertTrue((np.array(self.masks)==r_masks).all()) + + test_file = self.test_file + '.msk' + self.assertFalse(os.path.isfile(test_file)) + + r_masks = ExportSpectraMask('test_ws',Filename = test_file) + self.assertTrue(os.path.isfile(test_file)) + self.assertTrue((np.array(self.masks)==r_masks).all()) + + default_tf = os.path.join(mantid.config.getString('defaultsave.directory'),'test_ws.msk') + ExportSpectraMask('test_ws') + self.assertTrue(os.path.isfile(default_tf)) + os.remove(default_tf) + + +if __name__=="__main__": + unittest.main() diff --git a/Framework/PythonInterface/test/python/plugins/algorithms/FlatPlatePaalmanPingsCorrectionTest.py b/Framework/PythonInterface/test/python/plugins/algorithms/FlatPlatePaalmanPingsCorrectionTest.py index 8577eb0f1a3007e99ed1108a6dcf4e95d664602a..e3d68386e57abe782f4cbf4ae9abc170789ec977 100644 --- a/Framework/PythonInterface/test/python/plugins/algorithms/FlatPlatePaalmanPingsCorrectionTest.py +++ b/Framework/PythonInterface/test/python/plugins/algorithms/FlatPlatePaalmanPingsCorrectionTest.py @@ -82,9 +82,9 @@ class FlatPlatePaalmanPingsCorrectionTest(unittest.TestCase): self._verify_workspace(workspace) - def test_sampleOnly(self): + def test_sampleOnly_indirect(self): """ - Test simple run with sample workspace only. + Test simple run with sample workspace only for indirect mode """ FlatPlatePaalmanPingsCorrection(OutputWorkspace=self._corrections_ws_name, @@ -99,6 +99,23 @@ class FlatPlatePaalmanPingsCorrectionTest(unittest.TestCase): ass_ws_name = self._corrections_ws_name + '_ass' self. _verify_workspace(ass_ws_name) + def test_sampleOnly_direct(self): + """ + Test simple run with sample workspace only for direct mode + """ + + FlatPlatePaalmanPingsCorrection(OutputWorkspace=self._corrections_ws_name, + SampleWorkspace=self._sample_ws, + SampleChemicalFormula='H2-O', + SampleThickness=0.1, + SampleAngle=45, + NumberWavelengths=10, + Emode='Direct', + Efixed=1.845) + + ass_ws_name = self._corrections_ws_name + '_ass' + self. _verify_workspace(ass_ws_name) + def test_sampleAndCan(self): """ diff --git a/Framework/SINQ/inc/MantidSINQ/DllConfig.h b/Framework/SINQ/inc/MantidSINQ/DllConfig.h index 5cfc4e6ce4152d3ff80fbf8b5b2502dfc945c3e0..ad53b637512b49bd75caee14963d173b78157662 100644 --- a/Framework/SINQ/inc/MantidSINQ/DllConfig.h +++ b/Framework/SINQ/inc/MantidSINQ/DllConfig.h @@ -30,8 +30,10 @@ #ifdef IN_MANTID_SINQ #define MANTID_SINQ_DLL DLLExport +#define EXTERN_MANTID_SINQ #else #define MANTID_SINQ_DLL DLLImport +#define EXTERN_MANTID_SINQ EXTERN_IMPORT #endif /* IN_MANTID_SINQ */ #endif // MANTID_SINQ_DLLCONFIG_H_ diff --git a/Framework/ScriptRepository/CMakeLists.txt b/Framework/ScriptRepository/CMakeLists.txt index f16cbbf784a460ac614c7e9cf6287e89c29cb6b4..c2bc2704c9296569fedb1b0b78e4eacb25456c77 100644 --- a/Framework/ScriptRepository/CMakeLists.txt +++ b/Framework/ScriptRepository/CMakeLists.txt @@ -4,6 +4,7 @@ set ( SRC_FILES ) set ( INC_FILES + inc/MantidScriptRepository/DllConfig.h inc/MantidScriptRepository/ScriptRepositoryImpl.h ) diff --git a/Framework/ScriptRepository/inc/MantidScriptRepository/DllConfig.h b/Framework/ScriptRepository/inc/MantidScriptRepository/DllConfig.h new file mode 100644 index 0000000000000000000000000000000000000000..4f13d0ab5156b7351cdebe854034fa54508e004a --- /dev/null +++ b/Framework/ScriptRepository/inc/MantidScriptRepository/DllConfig.h @@ -0,0 +1,22 @@ +#ifndef MANTID_MANTIDSCRIPTREPOSITORY_DLLCONFIG_H_ +#define MANTID_MANTIDSCRIPTREPOSITORY_DLLCONFIG_H_ + +#include "MantidKernel/System.h" + +#ifdef _WIN32 +#if (IN_MANTID_SCRIPTREPO) +#define SCRIPT_DLL_EXPORT DLLExport +#else +#define SCRIPT_DLL_EXPORT DLLImport +#endif +#elif defined(__GNUC__) && !defined(__clang__) +#if (IN_MANTID_SCRIPTREPO) +#define SCRIPT_DLL_EXPORT DLLExport +#else +#define SCRIPT_DLL_EXPORT DLLImport +#endif +#else +#define SCRIPT_DLL_EXPORT +#endif + +#endif // MANTID_DATAOBJECTS_DLLCONFIG_H_ diff --git a/Framework/ScriptRepository/inc/MantidScriptRepository/ScriptRepositoryImpl.h b/Framework/ScriptRepository/inc/MantidScriptRepository/ScriptRepositoryImpl.h index b00c700e8171c714db7a37e32c582a2c27d02508..696d84d641353076bf3bec1d88e5341e41b274f3 100644 --- a/Framework/ScriptRepository/inc/MantidScriptRepository/ScriptRepositoryImpl.h +++ b/Framework/ScriptRepository/inc/MantidScriptRepository/ScriptRepositoryImpl.h @@ -3,19 +3,10 @@ #include "MantidAPI/ScriptRepository.h" #include "MantidKernel/DateAndTime.h" +#include "MantidScriptRepository/DllConfig.h" #include <map> #include <json/value.h> -#ifdef _WIN32 -#if (IN_MANTID_SCRIPTREPO) -#define SCRIPT_DLL_EXPORT DLLExport -#else -#define SCRIPT_DLL_EXPORT DLLImport -#endif -#else -#define SCRIPT_DLL_EXPORT -#endif - namespace Mantid { namespace API { diff --git a/Framework/TestHelpers/src/MDEventsTestHelper.cpp b/Framework/TestHelpers/src/MDEventsTestHelper.cpp index c899f51bb86482c4a5a06247ea1e98853c9ac731..dad353bac4237afef6b886d9ed79f06b5c639980 100644 --- a/Framework/TestHelpers/src/MDEventsTestHelper.cpp +++ b/Framework/TestHelpers/src/MDEventsTestHelper.cpp @@ -193,9 +193,10 @@ MDBox<MDLeanEvent<3>, 3> *makeMDBox3() { */ std::vector<MDLeanEvent<1>> makeMDEvents1(size_t num) { std::vector<MDLeanEvent<1>> out; - for (std::size_t i = 0; i < num; i++) { - double coords[1] = {static_cast<double>(i) * 1.0 + 0.5}; - out.push_back(MDLeanEvent<1>(1.0, 1.0, coords)); + out.reserve(num); + for (std::size_t i = 0; i < num; ++i) { + float coords[1] = {static_cast<float>(i) + 0.5f}; + out.emplace_back(1.0f, 1.0f, coords); } return out; } diff --git a/MantidPlot/src/FloatingWindow.cpp b/MantidPlot/src/FloatingWindow.cpp index 070b8d56704d63f1aedc8a7c3195849c5399b21d..4b79f3ac5fb7e5824c734d7f6bcc12e376412880 100644 --- a/MantidPlot/src/FloatingWindow.cpp +++ b/MantidPlot/src/FloatingWindow.cpp @@ -39,6 +39,14 @@ FloatingWindow::FloatingWindow(ApplicationWindow *appWindow, Qt::WindowFlags f) // Instead, the ApplicationWindow->removeFloatingWindow() call takes care of // calling deleteLater(). setAttribute(Qt::WA_DeleteOnClose, false); + +#ifdef Q_OS_MAC + // Work around to ensure that floating windows remain on top of the main + // application window, but below other applications on Mac + Qt::WindowFlags flags = windowFlags(); + Qt::WindowFlags new_flags = flags | Qt::Tool; + setWindowFlags(new_flags); +#endif } FloatingWindow::~FloatingWindow() { diff --git a/MantidQt/API/inc/MantidQtAPI/AlgorithmInputHistory.h b/MantidQt/API/inc/MantidQtAPI/AlgorithmInputHistory.h index d44602964f2dfb94389f27591942a5bc0ecbad02..52c28ce400cf1b43e2c9a526ff3071ebca3f005b 100644 --- a/MantidQt/API/inc/MantidQtAPI/AlgorithmInputHistory.h +++ b/MantidQt/API/inc/MantidQtAPI/AlgorithmInputHistory.h @@ -96,14 +96,15 @@ private: friend struct Mantid::Kernel::CreateUsingNew<AlgorithmInputHistoryImpl>; }; -#ifdef _WIN32 -// this breaks new namespace declaraion rules; need to find a better fix -template class EXPORT_OPT_MANTIDQT_API - Mantid::Kernel::SingletonHolder<AlgorithmInputHistoryImpl>; -#endif /* _WIN32 */ -/// The specific instantiation of the templated type -typedef EXPORT_OPT_MANTIDQT_API Mantid::Kernel::SingletonHolder< - AlgorithmInputHistoryImpl> AlgorithmInputHistory; +typedef Mantid::Kernel::SingletonHolder<AlgorithmInputHistoryImpl> + AlgorithmInputHistory; +} +} + +namespace Mantid { +namespace Kernel { +EXTERN_MANTIDQT_API template class EXPORT_OPT_MANTIDQT_API + Mantid::Kernel::SingletonHolder<MantidQt::API::AlgorithmInputHistoryImpl>; } } diff --git a/MantidQt/API/inc/MantidQtAPI/DllOption.h b/MantidQt/API/inc/MantidQtAPI/DllOption.h index 2d64b43438a4ed64aa4242c227e15d059f4139a0..6f9368b556877adc55be365e075fb253e795c8eb 100644 --- a/MantidQt/API/inc/MantidQtAPI/DllOption.h +++ b/MantidQt/API/inc/MantidQtAPI/DllOption.h @@ -5,8 +5,10 @@ #ifdef IN_MANTIDQT_API #define EXPORT_OPT_MANTIDQT_API DLLExport +#define EXTERN_MANTIDQT_API #else #define EXPORT_OPT_MANTIDQT_API DLLImport +#define EXTERN_MANTIDQT_API extern #endif /* IN_MANTIDQT_API */ #endif // MANTIDQT_API_DLLOPTION_H_ diff --git a/MantidQt/API/inc/MantidQtAPI/InterfaceFactory.h b/MantidQt/API/inc/MantidQtAPI/InterfaceFactory.h index f57fbe104c34af08aff6e43307ebcb14b7d85666..ff9b7a0247a64fbca176a6110e23bee1335b5c8b 100644 --- a/MantidQt/API/inc/MantidQtAPI/InterfaceFactory.h +++ b/MantidQt/API/inc/MantidQtAPI/InterfaceFactory.h @@ -69,14 +69,9 @@ private: ~AlgorithmDialogFactoryImpl() override = default; }; -#ifdef _WIN32 -// this breaks new namespace declaraion rules; need to find a better fix -template class EXPORT_OPT_MANTIDQT_API - Mantid::Kernel::SingletonHolder<AlgorithmDialogFactoryImpl>; -#endif /* _WIN32 */ /// The specific instantiation of the templated type -typedef EXPORT_OPT_MANTIDQT_API Mantid::Kernel::SingletonHolder< - AlgorithmDialogFactoryImpl> AlgorithmDialogFactory; +typedef Mantid::Kernel::SingletonHolder<AlgorithmDialogFactoryImpl> + AlgorithmDialogFactory; /** The UserSubWindowFactory is responsible for creating concrete instances of @@ -184,14 +179,18 @@ void UserSubWindowFactoryImpl::saveAliasNames(const std::string &realName) { } } -#ifdef _WIN32 -// this breaks new namespace declaraion rules; need to find a better fix -template class EXPORT_OPT_MANTIDQT_API - Mantid::Kernel::SingletonHolder<UserSubWindowFactoryImpl>; -#endif /* _WIN32 */ /// The specific instantiation of the templated type -typedef EXPORT_OPT_MANTIDQT_API Mantid::Kernel::SingletonHolder< - UserSubWindowFactoryImpl> UserSubWindowFactory; +typedef Mantid::Kernel::SingletonHolder<UserSubWindowFactoryImpl> + UserSubWindowFactory; +} +} + +namespace Mantid { +namespace Kernel { +EXTERN_MANTIDQT_API template class EXPORT_OPT_MANTIDQT_API + Mantid::Kernel::SingletonHolder<MantidQt::API::AlgorithmDialogFactoryImpl>; +EXTERN_MANTIDQT_API template class EXPORT_OPT_MANTIDQT_API + Mantid::Kernel::SingletonHolder<MantidQt::API::UserSubWindowFactoryImpl>; } } diff --git a/MantidQt/API/inc/MantidQtAPI/SelectionNotificationService.h b/MantidQt/API/inc/MantidQtAPI/SelectionNotificationService.h index f0d06640beb0f3c0eceff558a2b3c6be7cd7d9dd..37a55319fd9f312709a79c65825187f39af814c1 100644 --- a/MantidQt/API/inc/MantidQtAPI/SelectionNotificationService.h +++ b/MantidQt/API/inc/MantidQtAPI/SelectionNotificationService.h @@ -63,16 +63,14 @@ private: SelectionNotificationServiceImpl>; }; -/// Forward declaration of a specialisation of SingletonHolder for -/// SelectionNotificationServiceImpl -/// (needed for dllexport/dllimport) and a typedef for it. -#ifdef _WIN32 -template class EXPORT_OPT_MANTIDQT_API - Mantid::Kernel::SingletonHolder<SelectionNotificationServiceImpl>; -#endif /* _WIN32 */ - -typedef EXPORT_OPT_MANTIDQT_API Mantid::Kernel::SingletonHolder< - SelectionNotificationServiceImpl> SelectionNotificationService; +typedef Mantid::Kernel::SingletonHolder<SelectionNotificationServiceImpl> + SelectionNotificationService; +} +} +namespace Mantid { +namespace Kernel { +EXTERN_MANTIDQT_API template class EXPORT_OPT_MANTIDQT_API Mantid::Kernel:: + SingletonHolder<MantidQt::API::SelectionNotificationServiceImpl>; } } diff --git a/MantidQt/API/src/SignalBlocker.cpp b/MantidQt/API/src/SignalBlocker.cpp index bb1ac18c91adeead2e22cacca30d0857fdab905f..7423758ddc4d6da97e177752b15c3dbd9b96b5b7 100644 --- a/MantidQt/API/src/SignalBlocker.cpp +++ b/MantidQt/API/src/SignalBlocker.cpp @@ -40,10 +40,10 @@ template <typename Type> Type *SignalBlocker<Type>::operator->() { template <typename Type> void SignalBlocker<Type>::release() { m_obj = NULL; } // Template instances we need. -template class SignalBlocker<QObject>; -template class SignalBlocker<QAction>; -template class SignalBlocker<QPushButton>; -template class SignalBlocker<QComboBox>; +template class EXPORT_OPT_MANTIDQT_API SignalBlocker<QObject>; +template class EXPORT_OPT_MANTIDQT_API SignalBlocker<QAction>; +template class EXPORT_OPT_MANTIDQT_API SignalBlocker<QPushButton>; +template class EXPORT_OPT_MANTIDQT_API SignalBlocker<QComboBox>; } // namespace API } // namespace Mantid diff --git a/MantidQt/CustomDialogs/src/ConvertTableToMatrixWorkspaceDialog.cpp b/MantidQt/CustomDialogs/src/ConvertTableToMatrixWorkspaceDialog.cpp index 4541e22535110d03199f6b19834c8c8591f67f6e..982808cb9d92f21b20d52b185f6fe49d9f6288b5 100644 --- a/MantidQt/CustomDialogs/src/ConvertTableToMatrixWorkspaceDialog.cpp +++ b/MantidQt/CustomDialogs/src/ConvertTableToMatrixWorkspaceDialog.cpp @@ -63,9 +63,9 @@ void ConvertTableToMatrixWorkspaceDialog::fillColumnNames( for (std::vector<std::string>::const_iterator column = columns.begin(); column != columns.end(); ++column) { QString qName = QString::fromStdString(*column); - m_form.cbColumnX->insertItem(-1, qName); - m_form.cbColumnY->insertItem(-1, qName); - m_form.cbColumnE->insertItem(-1, qName); + m_form.cbColumnX->addItem(qName); + m_form.cbColumnY->addItem(qName); + m_form.cbColumnE->addItem(qName); Mantid::API::Column_sptr col = tws->getColumn(*column); if (col->getPlotType() == 1 && defaultXColumn.isEmpty()) // type X { diff --git a/MantidQt/CustomInterfaces/CMakeLists.txt b/MantidQt/CustomInterfaces/CMakeLists.txt index 9df3b315ab805e294bfe25e92c8a306c87a2f7a5..2d6e0604e5a9b32c2c1473750f20c57441d2922b 100644 --- a/MantidQt/CustomInterfaces/CMakeLists.txt +++ b/MantidQt/CustomInterfaces/CMakeLists.txt @@ -9,6 +9,8 @@ set ( SRC_FILES src/DynamicPDF/DPDFInputDataControl.cpp src/DynamicPDF/DisplayCurveFitTest.cpp src/DynamicPDF/SliceSelector.cpp + src/EnggDiffraction/EnggDiffFittingPresenter.cpp + src/EnggDiffraction/EnggDiffFittingViewQtWidget.cpp src/EnggDiffraction/EnggDiffractionPresenter.cpp src/EnggDiffraction/EnggDiffractionViewQtGUI.cpp src/Homer.cpp @@ -147,9 +149,13 @@ set ( INC_FILES inc/MantidQtCustomInterfaces/DynamicPDF/DisplayCurveFitTest.h inc/MantidQtCustomInterfaces/DynamicPDF/SliceSelector.h inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffCalibSettings.h + inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffFittingPresenter.h + inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffFittingPresWorker.h + inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffFittingViewQtWidget.h inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffractionPresWorker.h inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffractionPresenter.h inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffractionViewQtGUI.h + inc/MantidQtCustomInterfaces/EnggDiffraction/IEnggDiffFittingPresenter.h inc/MantidQtCustomInterfaces/EnggDiffraction/IEnggDiffractionPresenter.h inc/MantidQtCustomInterfaces/EnggDiffraction/IEnggDiffractionView.h inc/MantidQtCustomInterfaces/Homer.h @@ -305,6 +311,9 @@ set ( MOC_FILES inc/MantidQtCustomInterfaces/Background.h inc/MantidQtCustomInterfaces/DynamicPDF/DPDFFourierTransform.h inc/MantidQtCustomInterfaces/DynamicPDF/DPDFInputDataControl.h inc/MantidQtCustomInterfaces/DynamicPDF/SliceSelector.h + inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffFittingPresenter.h + inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffFittingPresWorker.h + inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffFittingViewQtWidget.h inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffractionPresenter.h inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffractionPresWorker.h inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffractionViewQtGUI.h @@ -480,6 +489,7 @@ set ( TEST_FILES ALCLatestFileFinderTest.h ALCPeakFittingModelTest.h ALCPeakFittingPresenterTest.h + EnggDiffFittingPresenterTest.h EnggDiffractionPresenterTest.h IO_MuonGroupingTest.h ImageROIPresenterTest.h diff --git a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/DllConfig.h b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/DllConfig.h index b2a8a6eb63d570295ca32d50d5c4752601cbc136..0b29436adda096f1ea734c1edc00c43d357f501f 100644 --- a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/DllConfig.h +++ b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/DllConfig.h @@ -30,8 +30,10 @@ */ #ifdef IN_MANTIDQT_CUSTOMINTERFACES #define MANTIDQT_CUSTOMINTERFACES_DLL DLLExport +#define EXTERN_MANTIDQT_CUSTOMINTERFACES #else #define MANTIDQT_CUSTOMINTERFACES_DLL DLLImport +#define EXTERN_MANTIDQT_CUSTOMINTERFACES EXTERN_IMPORT #endif #endif // MANTIDQTCUSTOMINTERFACES_DLLCONFIG_H_ diff --git a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffFittingPresWorker.h b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffFittingPresWorker.h new file mode 100644 index 0000000000000000000000000000000000000000..0998bbafcd59cc726ffbb7770a25ae49761e313a --- /dev/null +++ b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffFittingPresWorker.h @@ -0,0 +1,69 @@ +#ifndef MANTIDQTCUSTOMINTERFACES_ENGGDIFFRACTION_ENGGDIFFFITTINGPRESWORKER_H_ +#define MANTIDQTCUSTOMINTERFACES_ENGGDIFFRACTION_ENGGDIFFFITTINGPRESWORKER_H_ + +#include "MantidQtCustomInterfaces/EnggDiffraction/EnggDiffFittingPresenter.h" + +#include <QThread> + +namespace MantidQt { +namespace CustomInterfaces { + +/** +Worker to run long tasks for the presenter of the fitting tab of the +EnggDiffraction GUI. It has a finished() signal, and it is expected to +emit it when the hard/long-work methods finish. + +Copyright © 2016 ISIS Rutherford Appleton Laboratory, NScD +Oak Ridge National Laboratory & European Spallation Source + +This file is part of Mantid. + +Mantid is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3 of the License, or +(at your option) any later version. + +Mantid is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. + +File change history is stored at: <https://github.com/mantidproject/mantid> +Code Documentation is available at: <http://doxygen.mantidproject.org> +*/ +class EnggDiffFittingWorker : public QObject { + Q_OBJECT + +public: + // for fitting (single peak fits) + EnggDiffFittingWorker(EnggDiffFittingPresenter *pres, + const std::string &focusedRunNo, + const std::string &ExpectedPeaks) + : m_pres(pres), m_runNo(focusedRunNo), m_expectedPeaks(ExpectedPeaks) {} + +private slots: + + void fitting() { + m_pres->doFitting(m_runNo, m_expectedPeaks); + emit finished(); + } + +signals: + void finished(); + +private: + EnggDiffFittingPresenter *m_pres; + + /// sample run to process + const std::string m_runNo; + // parameters for fitting, list of peaks + const std::string m_expectedPeaks; +}; + +} // namespace CustomInterfaces +} // namespace MantidQt + +#endif // MANTIDQTCUSTOMINTERFACES_ENGGDIFFRACTION_ENGGDIFFFITTINGPRESWORKER_H_ diff --git a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffFittingPresenter.h b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffFittingPresenter.h new file mode 100644 index 0000000000000000000000000000000000000000..12f12f4eb9f6e0a718872a5d4984db6e11288c71 --- /dev/null +++ b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffFittingPresenter.h @@ -0,0 +1,167 @@ +#ifndef MANTIDQTCUSTOMINTERFACES_ENGGDIFFRACTION_ENGGDIFFFITTINGPRESENTER_H_ +#define MANTIDQTCUSTOMINTERFACES_ENGGDIFFRACTION_ENGGDIFFFITTINGPRESENTER_H_ + +#include "MantidAPI/ITableWorkspace_fwd.h" +#include "MantidAPI/MatrixWorkspace_fwd.h" +#include "MantidQtCustomInterfaces/DllConfig.h" +#include "MantidQtCustomInterfaces/EnggDiffraction/IEnggDiffractionCalibration.h" +#include "MantidQtCustomInterfaces/EnggDiffraction/IEnggDiffFittingPresenter.h" +#include "MantidQtCustomInterfaces/EnggDiffraction/IEnggDiffFittingView.h" + +#include <string> +#include <vector> + +#include <QObject> + +class QThread; + +namespace MantidQt { +namespace CustomInterfaces { + +/** +Presenter for the fitting tab/widget of the enggineering diffraction +GUI (presenter as in the MVP Model-View-Presenter pattern). + +Copyright © 2016 ISIS Rutherford Appleton Laboratory, NScD +Oak Ridge National Laboratory & European Spallation Source + +This file is part of Mantid. + +Mantid is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3 of the License, or +(at your option) any later version. + +Mantid is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. + +File change history is stored at: <https://github.com/mantidproject/mantid> +Code Documentation is available at: <http://doxygen.mantidproject.org> +*/ +// needs to be dll-exported for the tests +class MANTIDQT_CUSTOMINTERFACES_DLL EnggDiffFittingPresenter + : public QObject, + public IEnggDiffFittingPresenter, + public IEnggDiffractionCalibration { + // Q_OBJECT for 'connect' with thread/worker + Q_OBJECT + +public: + EnggDiffFittingPresenter( + IEnggDiffFittingView *view, + boost::shared_ptr<IEnggDiffractionCalibration> mainCalib); + ~EnggDiffFittingPresenter() override; + + void notify(IEnggDiffFittingPresenter::Notification notif) override; + + /// From the IEnggDiffractionCalibration interface + //@{ + std::vector<GSASCalibrationParms> currentCalibration() const override; + //@} + + /// the fitting hard work that a worker / thread will run + void doFitting(const std::string &focusedRunNo, + const std::string &expectedPeaks); + + void runFittingAlgs(std::string FocusedFitPeaksTableName, + std::string FocusedWSName); + + std::string + functionStrFactory(Mantid::API::ITableWorkspace_sptr ¶mTableWS, + std::string tableName, size_t row, std::string &startX, + std::string &endX); + + void plotFitPeaksCurves(); + + void runEvaluateFunctionAlg(const std::string &bk2BkExpFunction, + const std::string &InputName, + const std::string &OutputName, + const std::string &startX, + const std::string &endX); + + void runCropWorkspaceAlg(std::string workspaceName); + + void runAppendSpectraAlg(std::string workspace1Name, + std::string workspace2Name); + + void runRebinToWorkspaceAlg(std::string workspaceName); + + void convertUnits(std::string workspaceName); + void runConvertUnitsAlg(std::string workspaceName); + void runAlignDetectorsAlg(std::string workspaceName); + + void setDifcTzero(Mantid::API::MatrixWorkspace_sptr wks) const; + void getDifcTzero(Mantid::API::MatrixWorkspace_const_sptr wks, double &difc, + double &difa, double &tzero) const; + + void runCloneWorkspaceAlg(std::string inputWorkspace, + const std::string &outputWorkspace); + + void setDataToClonedWS(std::string ¤t_WS, const std::string &cloned_WS); + + void setBankItems(); + + void setRunNoItems(std::vector<std::string> runNumVector, bool multiRun); + + void setDefaultBank(const std::vector<std::string> &splittedBaseName, + const std::string &selectedFile); + +protected: + void processStart(); + void processFitPeaks(); + void processShutDown(); + void processLogMsg(); + + /// clean shut down of model, view, etc. + void cleanup(); + +protected slots: + + void fittingFinished(); + void fittingRunNoChanged(); + +private: + bool isDigit(std::string text); + + // Methods related single peak fits + virtual void startAsyncFittingWorker(const std::string &focusedRunNo, + const std::string &expectedPeaks); + + std::string validateFittingexpectedPeaks(std::string &expectedPeaks) const; + + void inputChecksBeforeFitting(const std::string &focusedRunNo, + const std::string &expectedPeaks); + + void updateFittingDirVec(const std::string &bankDir, + const std::string &focusedFile, const bool multi_run, + std::vector<std::string> &fittingRunNoDirVec); + + void enableMultiRun(std::string firstRun, std::string lastRun, + std::vector<std::string> &fittingRunNoDirVec); + + // whether to use AlignDetectors to convert units + static const bool g_useAlignDetectors; + + // name of the workspace with the focused ws being used for fitting + static const std::string g_focusedFittingWSName; + + /// true if the last fitting completed successfully + bool m_fittingFinishedOK; + + QThread *m_workerThread; + + /// interface for the 'current' calibration + boost::shared_ptr<IEnggDiffractionCalibration> m_mainCalib; + + /// Associated view for this presenter (MVP pattern) + IEnggDiffFittingView *const m_view; +}; + +} // namespace CustomInterfaces +} // namespace MantidQt +#endif // MANTIDQTCUSTOMINTERFACES_ENGGDIFFRACTION_ENGGDIFFFITTINGPRESENTER_H_ diff --git a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffFittingViewQtWidget.h b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffFittingViewQtWidget.h new file mode 100644 index 0000000000000000000000000000000000000000..64cc5084a8b65c5e67d121ed8dfa185c2ac84820 --- /dev/null +++ b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffFittingViewQtWidget.h @@ -0,0 +1,239 @@ +#ifndef MANTIDQTCUSTOMINTERFACES_ENGGDIFFRACTION_IENGGDIFFFITTINGVIEWQTWIDGET_H_ +#define MANTIDQTCUSTOMINTERFACES_ENGGDIFFRACTION_IENGGDIFFFITTINGVIEWQTWIDGET_H_ + +#include "MantidAPI/IPeakFunction.h" +#include "MantidQtCustomInterfaces/DllConfig.h" +#include "MantidQtCustomInterfaces/EnggDiffraction/IEnggDiffFittingPresenter.h" +#include "MantidQtCustomInterfaces/EnggDiffraction/IEnggDiffFittingView.h" + +#include "ui_EnggDiffractionQtTabFitting.h" + +#include <boost/scoped_ptr.hpp> + +// Qt classes forward declarations +class QMessageBox; +class QMutex; + +class QwtPlotCurve; +class QwtPlotZoomer; + +namespace MantidQt { + +namespace MantidWidgets { +class PeakPicker; +} + +namespace CustomInterfaces { + +/** +Qt-based view of the Engineering Diffraction (EnggDiff) fitting +widget/tab. Provides a concrete view that is Qt-based and is probably +the only one that will be implemented in a foreseeable horizon. The +interface of this class is given by IEnggDiffFittingView so that it +fits in the MVP (Model-View-Presenter) design of this GUI. + +Copyright © 2016 ISIS Rutherford Appleton Laboratory, NScD +Oak Ridge National Laboratory & European Spallation Source + +This file is part of Mantid. + +Mantid is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3 of the License, or +(at your option) any later version. + +Mantid is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. + +File change history is stored at: <https://github.com/mantidproject/mantid> +Code Documentation is available at: <http://doxygen.mantidproject.org> +*/ +class MANTIDQT_CUSTOMINTERFACES_DLL EnggDiffFittingViewQtWidget + : public QWidget, + public IEnggDiffFittingView { + Q_OBJECT + +public: + EnggDiffFittingViewQtWidget( + QWidget *parent, boost::shared_ptr<IEnggDiffractionUserMsg> mainMsg, + boost::shared_ptr<IEnggDiffractionSettings> mainSettings, + boost::shared_ptr<IEnggDiffractionCalibration> mainCalib, + boost::shared_ptr<IEnggDiffractionPythonRunner> mainPyhonRunner); + ~EnggDiffFittingViewQtWidget() override; + + /// From the IEnggDiffractionUserMsg interface + //@{ + void showStatus(const std::string &sts) override; + + void userWarning(const std::string &warn, + const std::string &description) override; + + void userError(const std::string &err, + const std::string &description) override; + void enableCalibrateFocusFitUserActions(bool enable) override; + //@} + + /// From the IEnggDiffractionSettings interface + //@{ + EnggDiffCalibSettings currentCalibSettings() const override; + + std::string focusingDir() const override; + //@} + + /// From the IEnggDiffractionPythonRunner interface + //@{ + virtual std::string enggRunPythonCode(const std::string &pyCode) override; + //@} + + void enable(bool enable); + + std::vector<std::string> logMsgs() const override { return m_logMsgs; } + + void setFittingRunNo(const std::string &path) override; + + std::string getFittingRunNo() const override; + + void clearFittingComboBox() const override; + + void enableFittingComboBox(bool enable) const override; + + int getFittingComboIdx(std::string bank) const override; + + void clearFittingListWidget() const override; + + void enableFittingListWidget(bool enable) const override; + + int getFittingListWidgetCurrentRow() const override; + + void setFittingListWidgetCurrentRow(int idx) const override; + + std::string fittingPeaksData() const override; + + void setPeakList(const std::string &peakList) const override; + + std::vector<std::string> + splitFittingDirectory(std::string &selectedfPath) override; + + void setBankEmit() override; + + void setDataVector(std::vector<boost::shared_ptr<QwtData>> &data, + bool focused, bool plotSinglePeaks) override; + + void addBankItem(std::string bankID) override; + + void addRunNoItem(std::string runNo) override; + + std::vector<std::string> getFittingRunNumVec() override; + + void setFittingRunNumVec(std::vector<std::string> assignVec) override; + + bool getFittingMultiRunMode() override; + + void setFittingMultiRunMode(bool mode) override; + + std::string fittingRunNoFactory(std::string bank, std::string fileName, + std::string &bankDir, std::string fileDir); + + std::string readPeaksFile(std::string fileDir); + + void dataCurvesFactory(std::vector<boost::shared_ptr<QwtData>> &data, + std::vector<QwtPlotCurve *> &dataVector, bool focused); + + void setPeakPickerEnabled(bool enabled); + + void setPeakPicker(const Mantid::API::IPeakFunction_const_sptr &peak); + + double getPeakCentre() const; + + void fittingWriteFile(const std::string &fileDir); + + void setZoomTool(bool enabled); + + void resetView(); + +protected: + void initLayout(); + +signals: + void getBanks(); + void setBank(); + +private slots: + // slot of the fitting peaks per part of the interface + void browseFitFocusedRun(); + void resetFittingMultiMode(); + void setBankIdComboBox(int idx) override; + void browsePeaksToFit(); + void setPeakPick(); + void addPeakToList(); + void savePeakList(); + void clearPeakList(); + void fitClicked(); + void FittingRunNo(); + void plotSeparateWindow(); + void setBankDir(int idx); + void listViewFittingRun(); + +private: + /// Setup the interface (tab UI) + void doSetup(); + + /// Load saved/default interface settings + void readSettings(); + /// save settings (before closing) + void saveSettings() const override; + + /// converts QList to a vector + std::vector<std::string> qListToVector(QStringList list, + bool validator) const; + + // path/name for the persistent settings group of this interface + static const std::string g_settingsGroup; + + static const std::string g_peaksListExt; + + /// indentifier for fitting multi-run or single run input + static bool m_fittingMutliRunMode; + + // vector holding directory of focused bank file + static std::vector<std::string> m_fitting_runno_dir_vec; + + Ui::EnggDiffractionQtTabFitting m_ui; + + // here the view puts messages before notifying the presenter to show them + std::vector<std::string> m_logMsgs; + + /// Loaded focused workspace + std::vector<QwtPlotCurve *> m_focusedDataVector; + + /// Loaded data curves + std::vector<QwtPlotCurve *> m_fittedDataVector; + + /// Peak picker tool for fitting - only one on the plot at any given moment + MantidWidgets::PeakPicker *m_peakPicker = nullptr; + + /// zoom-in/zoom-out tool for fitting + QwtPlotZoomer *m_zoomTool = nullptr; + + /// user messages interface provided by a main view/widget + boost::shared_ptr<IEnggDiffractionUserMsg> m_mainMsgProvider; + + /// settings from the user + boost::shared_ptr<IEnggDiffractionSettings> m_mainSettings; + + /// interface for the Python runner + boost::shared_ptr<IEnggDiffractionPythonRunner> m_mainPythonRunner; + + /// presenter as in the model-view-presenter + boost::scoped_ptr<IEnggDiffFittingPresenter> m_presenter; +}; + +} // namespace CustomInterfaces +} // namespace MantidQt + +#endif // MANTIDQTCUSTOMINTERFACES_ENGGDIFFRACTION_IENGGDIFFFITTINGVIEWQTWIDGET_H_ diff --git a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffractionPresWorker.h b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffractionPresWorker.h index 526b85e4aa45fc922479250947715eead5d0eac0..4ccdbe570d37f8df7715dacd19013355ae785c9f 100644 --- a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffractionPresWorker.h +++ b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffractionPresWorker.h @@ -67,13 +67,6 @@ public: : m_pres(pres), m_runNo(runNo), m_bin(timeStep), m_nperiods(nperiods), m_outWSName(outWSName) {} - // for fitting (single peak fits) - EnggDiffWorker(EnggDiffractionPresenter *pres, - const std::string &focusedRunNo, - const std::string &ExpectedPeaks) - : m_pres(pres), m_runNo(focusedRunNo), m_expectedPeaks(ExpectedPeaks), - m_bin(.0), m_nperiods(0) {} - private slots: /** @@ -110,11 +103,6 @@ private slots: emit finished(); } - void fitting() { - m_pres->doFitting(m_runNo, m_expectedPeaks); - emit finished(); - } - signals: void finished(); @@ -139,8 +127,6 @@ private: const std::string m_SpectrumNos; // for focusing "texture" const std::string m_dgFile; - // parameters for fitting - const std::string m_expectedPeaks; // parameters for pre-processing/rebinning const double m_bin; const size_t m_nperiods; diff --git a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffractionPresenter.h b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffractionPresenter.h index 5b3fdcaa5c4f2c990a0901cfece74acb0c35e941..fc7097609e2fff9898d0946266b1bce0950d5092 100644 --- a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffractionPresenter.h +++ b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffractionPresenter.h @@ -5,11 +5,10 @@ #include "MantidAPI/MatrixWorkspace_fwd.h" #include "MantidAPI/Workspace_fwd.h" #include "MantidQtCustomInterfaces/DllConfig.h" +#include "MantidQtCustomInterfaces/EnggDiffraction/IEnggDiffractionCalibration.h" #include "MantidQtCustomInterfaces/EnggDiffraction/IEnggDiffractionPresenter.h" #include "MantidQtCustomInterfaces/EnggDiffraction/IEnggDiffractionView.h" -// #include "MantidQtCustomInterfaces/EnggDiffraction/EnggDiffractionModel.h" - #include <boost/scoped_ptr.hpp> #include <QObject> @@ -23,8 +22,6 @@ class QThread; namespace MantidQt { namespace CustomInterfaces { -struct GSASCalibrationParms; - /** Presenter for the Enggineering Diffraction GUI (presenter as in the MVP Model-View-Presenter pattern). In principle, in a strict MVP @@ -55,12 +52,12 @@ Code Documentation is available at: <http://doxygen.mantidproject.org> // needs to be dll-exported for the tests class MANTIDQT_CUSTOMINTERFACES_DLL EnggDiffractionPresenter : public QObject, - public IEnggDiffractionPresenter { + public IEnggDiffractionPresenter, + public IEnggDiffractionCalibration { // Q_OBJECT for 'connect' with thread/worker Q_OBJECT public: - /// Default constructor - normally used from the concrete view EnggDiffractionPresenter(IEnggDiffractionView *view); ~EnggDiffractionPresenter() override; @@ -92,55 +89,6 @@ public: void doRebinningPulses(const std::string &runNo, size_t nperiods, double bin, const std::string &outWSName); - /// the fitting hard work that a worker / thread will run - void doFitting(const std::string &focusedRunNo, - const std::string &expectedPeaks); - - void runFittingAlgs(std::string FocusedFitPeaksTableName, - std::string FocusedWSName); - - std::string - functionStrFactory(Mantid::API::ITableWorkspace_sptr ¶mTableWS, - std::string tableName, size_t row, std::string &startX, - std::string &endX); - - void plotFitPeaksCurves(); - - void runEvaluateFunctionAlg(const std::string &bk2BkExpFunction, - const std::string &InputName, - const std::string &OutputName, - const std::string &startX, - const std::string &endX); - - void runCropWorkspaceAlg(std::string workspaceName); - - void runAppendSpectraAlg(std::string workspace1Name, - std::string workspace2Name); - - void runRebinToWorkspaceAlg(std::string workspaceName); - - void convertUnits(std::string workspaceName); - void runConvertUnitsAlg(std::string workspaceName); - void runAlignDetectorsAlg(std::string workspaceName); - - void setDifcTzero(Mantid::API::MatrixWorkspace_sptr wks) const; - void getDifcTzero(Mantid::API::MatrixWorkspace_const_sptr wks, double &difc, - double &difa, double &tzero) const; - - void runCloneWorkspaceAlg(std::string inputWorkspace, - const std::string &outputWorkspace); - - void setDataToClonedWS(std::string ¤t_WS, const std::string &cloned_WS); - - void setBankItems(); - - void setRunNoItems(std::vector<std::string> runNumVector, bool multiRun); - - void setDefaultBank(std::vector<std::string> splittedBaseName, - QString selectedFile); - - bool isDigit(std::string text); - protected: void initialize(); @@ -157,7 +105,6 @@ protected: void processResetFocus(); void processRebinTime(); void processRebinMultiperiod(); - void processFitPeaks(); void processLogMsg(); void processInstChange(); void processRBNumberChange(); @@ -168,8 +115,6 @@ protected slots: void calibrationFinished(); void focusingFinished(); void rebinningFinished(); - void fittingFinished(); - void fittingRunNoChanged(); private: bool validateRBNumber(const std::string &rbn) const; @@ -207,6 +152,7 @@ private: const std::string &ceriaNo, const std::string &bankName = "") const; + std::vector<GSASCalibrationParms> currentCalibration() const override; //@} /// @name Focusing related private methods @@ -298,22 +244,6 @@ private: const std::string &outWSName); //@} - // Methods related single peak fits - virtual void startAsyncFittingWorker(const std::string &focusedRunNo, - const std::string &expectedPeaks); - - std::string validateFittingexpectedPeaks(std::string &expectedPeaks) const; - - void inputChecksBeforeFitting(const std::string &focusedRunNo, - const std::string &expectedPeaks); - - void updateFittingDirVec(const std::string &bankDir, - const std::string &focusedFile, const bool multi_run, - std::vector<std::string> &fittingRunNoDirVec); - - void enableMultiRun(std::string firstRun, std::string lastRun, - std::vector<std::string> &fittingRunNoDirVec); - // plots workspace according to the user selection void plotFocusedWorkspace(std::string outWSName); @@ -386,9 +316,6 @@ private: // name of the workspace with the vanadium (smoothed) curves static const std::string g_vanCurvesWSName; - // name of the workspace with the focused ws being used for fitting - static const std::string g_focusedFittingWSName; - // for the GSAS parameters (difc, difa, tzero) of the banks static const std::string g_calibBanksParms; @@ -422,11 +349,6 @@ private: bool m_focusFinishedOK; /// true if the last pre-processing/re-binning completed successfully bool m_rebinningFinishedOK; - /// true if the last fitting completed successfully - bool m_fittingFinishedOK; - - // whether to use AlignDetectors to convert units - static bool g_useAlignDetectors; /// Counter for the cropped output files static int g_croppedCounter; diff --git a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffractionViewQtGUI.h b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffractionViewQtGUI.h index bebbdb4c7d596f79de6841a8f1e80b39c8b0f5ba..dcd0e181eb8744e1b55f5fca4de22e0dbd5823cd 100644 --- a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffractionViewQtGUI.h +++ b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffractionViewQtGUI.h @@ -4,24 +4,26 @@ #include "MantidAPI/IPeakFunction.h" #include "MantidQtAPI/UserSubWindow.h" #include "MantidQtCustomInterfaces/DllConfig.h" +#include "MantidQtCustomInterfaces/EnggDiffraction/EnggDiffFittingViewQtWidget.h" #include "MantidQtCustomInterfaces/EnggDiffraction/IEnggDiffractionPresenter.h" #include "MantidQtCustomInterfaces/EnggDiffraction/IEnggDiffractionView.h" #include "MantidQtMantidWidgets/PeakPicker.h" #include "ui_EnggDiffractionQtGUI.h" #include "ui_EnggDiffractionQtTabCalib.h" -#include "ui_EnggDiffractionQtTabFitting.h" #include "ui_EnggDiffractionQtTabFocus.h" #include "ui_EnggDiffractionQtTabPreproc.h" #include "ui_EnggDiffractionQtTabSettings.h" #include <boost/scoped_ptr.hpp> -#include <qwt_plot_zoomer.h> // Qt classes forward declarations class QMessageBox; class QMutex; +class QwtPlotCurve; +class QwtPlotZoomer; + namespace MantidQt { namespace CustomInterfaces { @@ -106,8 +108,6 @@ public: std::vector<std::string> newCeriaNo() const override; - std::string outCalibFilename() const override { return m_outCalibFilename; } - int currentCropCalibBankName() const override { return m_currentCropCalibBankName; } @@ -123,7 +123,7 @@ public: void enableTabs(bool enable) override; - void enableCalibrateAndFocusActions(bool enable) override; + void enableCalibrateFocusFitUserActions(bool enable) override; std::string focusingDir() const override; @@ -153,70 +153,6 @@ public: double rebinningPulsesTime() const override; - void setFittingRunNo(QString path) override; - - std::string getFittingRunNo() const override; - - void clearFittingComboBox() const override; - - void enableFittingComboBox(bool enable) const override; - - int getFittingComboIdx(std::string bank) const override; - - void clearFittingListWidget() const override; - - void enableFittingListWidget(bool enable) const override; - - int getFittingListWidgetCurrentRow() const override; - - void setFittingListWidgetCurrentRow(int idx) const override; - - std::string fittingPeaksData() const override; - - void setPeakList(std::string peakList) const override; - - std::vector<std::string> - splitFittingDirectory(std::string &selectedfPath) override; - - void setBankEmit() override; - - std::string getFocusDir() override; - - void setDataVector(std::vector<boost::shared_ptr<QwtData>> &data, - bool focused, bool plotSinglePeaks) override; - - void addBankItem(std::string bankID) override; - - void addRunNoItem(std::string runNo) override; - - std::vector<std::string> getFittingRunNumVec() override; - - void setFittingRunNumVec(std::vector<std::string> assignVec) override; - - bool getFittingMultiRunMode() override; - - void setFittingMultiRunMode(bool mode) override; - - std::string fittingRunNoFactory(std::string bank, std::string fileName, - std::string &bankDir, std::string fileDir); - - std::string readPeaksFile(std::string fileDir); - - void dataCurvesFactory(std::vector<boost::shared_ptr<QwtData>> &data, - std::vector<QwtPlotCurve *> &dataVector, bool focused); - - void setPeakPickerEnabled(bool enabled); - - void setPeakPicker(const Mantid::API::IPeakFunction_const_sptr &peak); - - double getPeakCentre() const; - - void fittingWriteFile(const std::string &fileDir); - - void setZoomTool(bool enabled); - - void resetView(); - void plotFocusedSpectrum(const std::string &wsName) override; void plotWaterfallSpectrum(const std::string &wsName) override; @@ -282,21 +218,6 @@ private slots: // enables the text field when appropriate bank name is selected void enableSpecNos(); - // slot of the fitting peaks per part of the interface - void browseFitFocusedRun(); - void resetFittingMultiMode(); - void setBankIdComboBox(int idx) override; - void browsePeaksToFit(); - void setPeakPick(); - void addPeakToList(); - void savePeakList(); - void clearPeakList(); - void fitClicked(); - void FittingRunNo(); - void plotSeparateWindow(); - void setBankDir(int idx); - void listViewFittingRun(); - // show the standard Mantid help window with this interface's help void openHelpWin(); @@ -308,7 +229,6 @@ private: void doSetupTabCalib(); void doSetupTabFocus(); void doSetupTabPreproc(); - void doSetupTabFitting(); void doSetupTabSettings(); std::string guessGSASTemplatePath() const; @@ -323,7 +243,7 @@ private: void closeEvent(QCloseEvent *ev) override; // path/name for the persistent settings group of this interface - const static std::string m_settingsGroup; + const static std::string g_settingsGroup; // here the view puts messages before notifying the presenter to show them std::vector<std::string> m_logMsgs; @@ -336,7 +256,8 @@ private: Ui::EnggDiffractionQtTabCalib m_uiTabCalib; Ui::EnggDiffractionQtTabFocus m_uiTabFocus; Ui::EnggDiffractionQtTabPreproc m_uiTabPreproc; - Ui::EnggDiffractionQtTabFitting m_uiTabFitting; + // Ui::EnggDiffractionQtTabFitting m_uiTabFitting; + EnggDiffFittingViewQtWidget *m_fittingWidget; Ui::EnggDiffractionQtTabSettings m_uiTabSettings; /// converts QList to a vector @@ -361,17 +282,8 @@ private: // multi-run focus mode type selected int static m_currentRunMode; - /// indentifier for fitting multi-run or single run input - bool static m_fittingMutliRunMode; - - // vector holding directory of focused bank file - std::vector<std::string> static m_fitting_runno_dir_vec; - - /// current calibration produced in the 'Calibration' tab - std::string m_currentCalibFilename; /// calibration settings - from/to the 'settings' tab EnggDiffCalibSettings m_calibSettings; - std::string m_outCalibFilename; /// To show important non-modal messages QMessageBox *m_splashMsg; @@ -391,20 +303,8 @@ private: /// (focusing) static const std::string g_DetGrpExtStr; - /// Loaded focused workspace - std::vector<QwtPlotCurve *> m_focusedDataVector; - - /// Loaded data curves - std::vector<QwtPlotCurve *> m_fittedDataVector; - - /// Peak picker tool for fitting - only one on the plot at any given moment - MantidWidgets::PeakPicker *m_peakPicker; - - /// zoom-in/zoom-out tool for fitting - QwtPlotZoomer *m_zoomTool; - /// presenter as in the model-view-presenter - boost::scoped_ptr<IEnggDiffractionPresenter> m_presenter; + boost::shared_ptr<IEnggDiffractionPresenter> m_presenter; }; } // namespace CustomInterfaces diff --git a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/IEnggDiffFittingPresenter.h b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/IEnggDiffFittingPresenter.h new file mode 100644 index 0000000000000000000000000000000000000000..7faec353e39617140d08c21911f7e915240a6315 --- /dev/null +++ b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/IEnggDiffFittingPresenter.h @@ -0,0 +1,64 @@ +#ifndef MANTIDQTCUSTOMINTERFACES_ENGGDIFFRACTION_IENGGDIFFFITTINGPRESENTER_H_ +#define MANTIDQTCUSTOMINTERFACES_ENGGDIFFRACTION_IENGGDIFFFITTINGPRESENTER_H_ + +#include "MantidQtCustomInterfaces/EnggDiffraction/IEnggDiffractionCalibration.h" + +namespace MantidQt { +namespace CustomInterfaces { + +/** +Interface of the presenter of the fitting widget/tab of the Engg +Diffraction GUI. Here the term presenter is used as in the MVP +(Model-View-Presenter) pattern. The view should be as passive as +possible and just notify any user actions. + +Copyright © 2016 ISIS Rutherford Appleton Laboratory, NScD +Oak Ridge National Laboratory & European Spallation Source + +This file is part of Mantid. + +Mantid is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3 of the License, or +(at your option) any later version. + +Mantid is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. + +File change history is stored at: <https://github.com/mantidproject/mantid> +Code Documentation is available at: <http://doxygen.mantidproject.org> +*/ +class IEnggDiffFittingPresenter { + +public: + virtual ~IEnggDiffFittingPresenter() = default; + + /// These are user actions, triggered from the (passive) view, that need + /// handling by the presenter + enum Notification { + Start, ///< Start and setup interface + FittingRunNo, ///< Creates widgets and handles multi/run numbers + FitPeaks, ///< Preforms single peak fits + ShutDown, ///< closing the interface + LogMsg, ///< need to send a message to the Mantid log system + }; + + /** + * Notifications sent through the presenter when something changes + * in the view. This plays the role of signals emitted by the view + * to this presenter. + * + * @param notif Type of notification to process. + */ + virtual void notify(IEnggDiffFittingPresenter::Notification notif) = 0; +}; + +} // namespace CustomInterfaces +} // namespace MantidQt + +#endif // MANTIDQTCUSTOMINTERFACES_ENGGDIFFRACTION_IENGGDIFFFITTINGPRESENTER_H_ diff --git a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/IEnggDiffFittingView.h b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/IEnggDiffFittingView.h new file mode 100644 index 0000000000000000000000000000000000000000..0b26ab575c98956aa8ce42ed12247b9fb835d138 --- /dev/null +++ b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/IEnggDiffFittingView.h @@ -0,0 +1,222 @@ +#ifndef MANTIDQTCUSTOMINTERFACES_ENGGDIFFRACTION_IENGGDIFFFITTINGVIEW_H_ +#define MANTIDQTCUSTOMINTERFACES_ENGGDIFFRACTION_IENGGDIFFFITTINGVIEW_H_ + +#include "MantidQtCustomInterfaces/EnggDiffraction/IEnggDiffractionUserMsg.h" +#include "MantidQtCustomInterfaces/EnggDiffraction/IEnggDiffractionSettings.h" +#include "MantidQtCustomInterfaces/EnggDiffraction/IEnggDiffractionPythonRunner.h" + +#include <string> +#include <vector> + +class QwtData; + +namespace MantidQt { +namespace CustomInterfaces { + +/** +Engineering diffraction custom interface / GUI. This is the base class +(interface) for the view of the the fitting tab/widget (view in the +sense of the Model-View-Presenter, MVP pattern). This class is +Qt-free. Qt specific functionality/dependencies are added in a class +derived from this. + +Copyright © 2016 ISIS Rutherford Appleton Laboratory, NScD +Oak Ridge National Laboratory & European Spallation Source + +This file is part of Mantid. + +Mantid is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3 of the License, or +(at your option) any later version. + +Mantid is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. + +File change history is stored at: <https://github.com/mantidproject/mantid> +Code Documentation is available at: <http://doxygen.mantidproject.org> +*/ +class IEnggDiffFittingView : public IEnggDiffractionUserMsg, + public IEnggDiffractionSettings, + public IEnggDiffractionPythonRunner { + +public: + virtual ~IEnggDiffFittingView() = default; + + /** + * returns directory of the file name to preform fitting on + * + * @return directory as std::string + */ + virtual std::string getFittingRunNo() const = 0; + + /** + * A list of dSpacing values to be translated into TOF + * to find expected peaks. + * + * @return list of dSpacing values as std::string + */ + virtual std::string fittingPeaksData() const = 0; + + /** + * Sets the peak list according to the string given + * + * @param peakList list of expected peaks to be fitted as std::string + */ + virtual void setPeakList(const std::string &peakList) const = 0; + + /** + * Splits the file name in to sections of '_' and 'ENGINX' text + * within the filename + * + * @param selectedfPath is the selected file's path + * + * @return std::vector<std::string> of splitted file name with run + * number & bank + */ + virtual std::vector<std::string> + splitFittingDirectory(std::string &selectedfPath) = 0; + + /** + * adds the number of banks to the combo-box widget on the interface + * + * @param bankID the bank number to add to combo-box + */ + virtual void addBankItem(std::string bankID) = 0; + + /** + * adds the run number to the list view widget on the interface + * + * @param runNo run number which needs to be added to + * the list widget + */ + virtual void addRunNoItem(std::string runNo) = 0; + + /** + * emits the signal within view when run number/bank changed + */ + virtual void setBankEmit() = 0; + + /** + * sets the bank combo-box according to given index + * + * @param idx as int of the bank to set + */ + virtual void setBankIdComboBox(int idx) = 0; + + /** + * Deletes all items from the fitting combo-box widget + */ + virtual void clearFittingComboBox() const = 0; + + /** + * Enables or disables the fitting combo-box + * + * @param enable or disable the fitting combo-box widget + */ + virtual void enableFittingComboBox(bool enable) const = 0; + + /** + * gets the index of the bank according to text found + * + * @param bank as a std::string to find in widget + * + * @returns int index of the combo-box where the + * string is found + */ + virtual int getFittingComboIdx(std::string bank) const = 0; + + /** + * Deletes all items from the fitting list widget + */ + virtual void clearFittingListWidget() const = 0; + + /** + * Enables or disables the fitting list widget + * + * @param enable or disable the fitting list widget + */ + virtual void enableFittingListWidget(bool enable) const = 0; + + /** + * @return idx of current selected row of list widget + */ + virtual int getFittingListWidgetCurrentRow() const = 0; + + /** + * Sets the current row of the fitting list widget + * + * @param idx number to set as for the list widget + */ + virtual void setFittingListWidgetCurrentRow(int idx) const = 0; + + /** + * sets the fitting run number according to path + * + * @param path of the selected focused run file + */ + virtual void setFittingRunNo(const std::string &path) = 0; + + /** + * gets the global vector in view containing focused file directory + * + * @return std::vector<std::string> containing the focused bank files + */ + virtual std::vector<std::string> getFittingRunNumVec() = 0; + + /** + * sets the global vector in view containing focused file directory + * + * @param assignVec of the all the focused bank files + * per run number + */ + virtual void setFittingRunNumVec(std::vector<std::string> assignVec) = 0; + + /** + * to determine whether the current loop is multi-run or single to avoid + * regenerating the list-view widget when not required + * + * @return bool whether given multi-run or singular file + */ + virtual bool getFittingMultiRunMode() = 0; + + /** + * sets the fitting mode to multi-run or single to avoid + * regenerating the list-view widget when not required + * + * @param mode true if its multi-run + */ + virtual void setFittingMultiRunMode(bool mode) = 0; + + /** + * generates and sets the curves on the fitting tab + * + * @param data of the workspace to be passed as QwtData + * @param focused to check whether focused workspace + * @param plotSinglePeaks whether to plot single peak fitting ws + */ + virtual void setDataVector(std::vector<boost::shared_ptr<QwtData>> &data, + bool focused, bool plotSinglePeaks) = 0; + + /** + * Messages that this view wants to send to the logging system. + * + * @return list of messages to log, one by one. + */ + virtual std::vector<std::string> logMsgs() const = 0; + + /** + * Save user settings (normally when closing the interface). + */ + virtual void saveSettings() const = 0; +}; + +} // namespace CustomInterfaces +} // namespace MantidQt + +#endif // MANTIDQTCUSTOMINTERFACES_ENGGDIFFRACTION_IENGGDIFFFITTINGVIEW_H_ diff --git a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/IEnggDiffractionCalibration.h b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/IEnggDiffractionCalibration.h new file mode 100644 index 0000000000000000000000000000000000000000..2ac34269ac024dbc151153b906942127491a509e --- /dev/null +++ b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/IEnggDiffractionCalibration.h @@ -0,0 +1,64 @@ +#ifndef MANTIDQTCUSTOMINTERFACES_ENGGDIFFRACTION_IENGGDIFFRACTIONCALIBRATION_H_ +#define MANTIDQTCUSTOMINTERFACES_ENGGDIFFRACTION_IENGGDIFFRACTIONCALIBRATION_H_ + +#include <vector> + +namespace MantidQt { +namespace CustomInterfaces { + +/** + * Parameters from a GSAS calibration. They define a conversion of + * units time-of-flight<->d-spacing that can be calculated with the + * algorithm AlignDetectors for example. + */ +struct GSASCalibrationParms { + GSASCalibrationParms(size_t bid, double dc, double da, double tz) + : bankid(bid), difc(dc), difa(da), tzero(tz) {} + + size_t bankid{0}; + double difc{0}; + double difa{0}; + double tzero{0}; +}; + +/** +Interface to the current calibration functionality of the Engineering +Diffraction (EnggDiffraction) GUI. This can be used in different +tabs/widgets as well as in the main/central view. Normally this +interface will be provided by the presenters of the widgets (assuming +an MVP design). The individual / area specific tabs/widgets (their +presenters) will forward to the widget responsible for the +calibration. + +Copyright © 2016 ISIS Rutherford Appleton Laboratory, NScD +Oak Ridge National Laboratory & European Spallation Source + +This file is part of Mantid. + +Mantid is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3 of the License, or +(at your option) any later version. + +Mantid is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. + +File change history is stored at: <https://github.com/mantidproject/mantid> +Code Documentation is available at: <http://doxygen.mantidproject.org> +*/ +class IEnggDiffractionCalibration { +public: + virtual ~IEnggDiffractionCalibration() = default; + + virtual std::vector<GSASCalibrationParms> currentCalibration() const = 0; +}; + +} // namespace CustomInterfaces +} // namespace MantidQt + +#endif // MANTIDQTCUSTOMINTERFACES_ENGGDIFFRACTION_IENGGDIFFRACTIOPYTHONRUNNER_H_ diff --git a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/IEnggDiffractionPresenter.h b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/IEnggDiffractionPresenter.h index 22d6277c6a7216df58831702a4802d0f7f3a0a36..0152a1bd15cef727f083fa04c4ad37bcfa6e102e 100644 --- a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/IEnggDiffractionPresenter.h +++ b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/IEnggDiffractionPresenter.h @@ -32,8 +32,9 @@ File change history is stored at: <https://github.com/mantidproject/mantid> Code Documentation is available at: <http://doxygen.mantidproject.org> */ class IEnggDiffractionPresenter { + public: - virtual ~IEnggDiffractionPresenter() {} + virtual ~IEnggDiffractionPresenter() = default; /// These are user actions, triggered from the (passive) view, that need /// handling by the presenter @@ -48,8 +49,6 @@ public: ResetFocus, ///< Re-set / clear all focus inputs and options RebinTime, ///< From event to histo, with a time bin RebinMultiperiod, ///< From event to histo, multiperiod event data - FittingRunNo, ///< Creates widgets and handles multi/run numbers - FitPeaks, ///< Preforms single peak fits LogMsg, ///< need to send a message to the Mantid log system InstrumentChange, ///< Instrument selection updated RBNumberChange, ///< RBNumber filled-in/changed diff --git a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/IEnggDiffractionPythonRunner.h b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/IEnggDiffractionPythonRunner.h new file mode 100644 index 0000000000000000000000000000000000000000..dd105e318f8cd8896819ef7f7fbf507de4ac6281 --- /dev/null +++ b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/IEnggDiffractionPythonRunner.h @@ -0,0 +1,56 @@ +#ifndef MANTIDQTCUSTOMINTERFACES_ENGGDIFFRACTION_IENGGDIFFRACTIONPYTHONRUNNER_H_ +#define MANTIDQTCUSTOMINTERFACES_ENGGDIFFRACTION_IENGGDIFFRACTIONPYTHONRUNNER_H_ + +namespace MantidQt { +namespace CustomInterfaces { + +/** +Interface to the python script runner functionality of the Engineering +Diffraction (EnggDiffraction) GUI. This can be used in different +tabs/widgets as well as in the main/central view. Normally the +individual / area specific tabs/widgets will forward to the main view. + +Copyright © 2016 ISIS Rutherford Appleton Laboratory, NScD +Oak Ridge National Laboratory & European Spallation Source + +This file is part of Mantid. + +Mantid is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3 of the License, or +(at your option) any later version. + +Mantid is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. + +File change history is stored at: <https://github.com/mantidproject/mantid> +Code Documentation is available at: <http://doxygen.mantidproject.org> +*/ +class IEnggDiffractionPythonRunner { +public: + virtual ~IEnggDiffractionPythonRunner() = default; + + /** + * Run Python code received as a script string. This is used for + * example to write GSAS instrument parameters file, to plot using + * the 'plotSpectrum' python functions, or other code included with + * the Engg scripts. In the first case, this is done temporarily + * here until we have a more final way of generating these files. A + * SaveGSAS algorithm that can handle ENGIN-X files would be ideal. + * + * @param pyCode Python script as a string + * + * @return status string from running the code + */ + virtual std::string enggRunPythonCode(const std::string &pyCode) = 0; +}; + +} // namespace CustomInterfaces +} // namespace MantidQt + +#endif // MANTIDQTCUSTOMINTERFACES_ENGGDIFFRACTION_IENGGDIFFRACTIOPYTHONRUNNER_H_ diff --git a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/IEnggDiffractionSettings.h b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/IEnggDiffractionSettings.h new file mode 100644 index 0000000000000000000000000000000000000000..729f852d322bcf0c50813ee8c667684cd27caf68 --- /dev/null +++ b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/IEnggDiffractionSettings.h @@ -0,0 +1,60 @@ +#ifndef MANTIDQTCUSTOMINTERFACES_ENGGDIFFRACTION_IENGGDIFFRACTIONSETTINGS_H_ +#define MANTIDQTCUSTOMINTERFACES_ENGGDIFFRACTION_IENGGDIFFRACTIONSETTINGS_H_ + +#include <string> + +#include "MantidQtCustomInterfaces/EnggDiffraction/EnggDiffCalibSettings.h" + +namespace MantidQt { +namespace CustomInterfaces { + +/** +Interface to settings of the Engineering Diffraction (EnggDiffraction) +GUI. This can be used in different tabs/widgets as well as in the +main/central view. Normally the individual / area specific +tabs/widgets will forward to the main view. + +Copyright © 2016 ISIS Rutherford Appleton Laboratory, NScD +Oak Ridge National Laboratory & European Spallation Source + +This file is part of Mantid. + +Mantid is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3 of the License, or +(at your option) any later version. + +Mantid is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. + +File change history is stored at: <https://github.com/mantidproject/mantid> +Code Documentation is available at: <http://doxygen.mantidproject.org> +*/ +class IEnggDiffractionSettings { +public: + virtual ~IEnggDiffractionSettings() = default; + + /** + * Calibration settings as defined by the user. + * + * @return calibration settings object with current user settings + */ + virtual EnggDiffCalibSettings currentCalibSettings() const = 0; + + /** + * Directory set for outputs from focusing calculations. + * + * @return directory path as a string + */ + virtual std::string focusingDir() const = 0; +}; + +} // namespace CustomInterfaces +} // namespace MantidQt + +#endif // MANTIDQTCUSTOMINTERFACES_ENGGDIFFRACTION_IENGGDIFFRACTIONSETTINGS_H_ diff --git a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/IEnggDiffractionUserMsg.h b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/IEnggDiffractionUserMsg.h new file mode 100644 index 0000000000000000000000000000000000000000..85383d100762fa9e4f0660e79f3d14e2d6c88bd2 --- /dev/null +++ b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/IEnggDiffractionUserMsg.h @@ -0,0 +1,92 @@ +#ifndef MANTIDQTCUSTOMINTERFACES_ENGGDIFFRACTION_IENGGDIFFRACTIONUSERMSG_H_ +#define MANTIDQTCUSTOMINTERFACES_ENGGDIFFRACTION_IENGGDIFFRACTIONUSERMSG_H_ + +#include <string> +#include <vector> + +namespace MantidQt { +namespace CustomInterfaces { + +/** +Interface for user message related functionality in the engineering +diffraction custom interface / GUI view(s). This can be used in +different tabs/widgets as well as in the main/central view. Normally +the individual / area specific tabs/widgets will forward to the main +view. + +Copyright © 2016 ISIS Rutherford Appleton Laboratory, NScD +Oak Ridge National Laboratory & European Spallation Source + +This file is part of Mantid. + +Mantid is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3 of the License, or +(at your option) any later version. + +Mantid is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. + +File change history is stored at: <https://github.com/mantidproject/mantid> +Code Documentation is available at: <http://doxygen.mantidproject.org> +*/ +class IEnggDiffractionUserMsg { + +public: + virtual ~IEnggDiffractionUserMsg() = default; + + /** + * Display the current status (running some algorithms, finished, + * ready, etc.), in a status bar or similar. + * + * @param sts status message which should be concise + */ + virtual void showStatus(const std::string &sts) = 0; + + /// @name Direct (and usually modal, or at least top/pop-up level) user + /// interaction + //@{ + /** + * Display a warning to the user (for example as a pop-up window). + * + * @param warn warning title, should be short and would normally be + * shown as the title of the window or a big banner. + * + * @param description longer, free form description of the issue. + */ + virtual void userWarning(const std::string &warn, + const std::string &description) = 0; + + /** + * Display an error message (for example as a pop-up window). + * + * @param err Error title, should be short and would normally be + * shown as the title of the window or a big banner. + * + * @param description longer, free form description of the issue. + */ + virtual void userError(const std::string &err, + const std::string &description) = 0; + //@} + + /** + * Enable/disable all user actions to + * calibrate+focus+fitting+.... The idea is that actions / buttons + * like 'calibrate', 'load calibration', 'focus', 'fit' can be + * disabled while other work is done (be it calibration, focusing, + * fitting or anything). + * + * @param enable true to enable actions (default initial state) + */ + virtual void enableCalibrateFocusFitUserActions(bool enable) = 0; +}; + +} // namespace CustomInterfaces +} // namespace MantidQt + +#endif // MANTIDQTCUSTOMINTERFACES_ENGGDIFFRACTION_IENGGDIFFRACTIONUSERMSG_H_ diff --git a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/IEnggDiffractionView.h b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/IEnggDiffractionView.h index b33289bcda5aca660cb254b410027303fae586b9..e8fa79fc09802a2b64ff2eda3e69a00c83679e9f 100644 --- a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/IEnggDiffractionView.h +++ b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/IEnggDiffractionView.h @@ -1,14 +1,12 @@ #ifndef MANTIDQTCUSTOMINTERFACES_ENGGDIFFRACTION_IENGGDIFFRACTIONVIEW_H_ #define MANTIDQTCUSTOMINTERFACES_ENGGDIFFRACTION_IENGGDIFFRACTIONVIEW_H_ -#include <QStringList> -#include <qwt_plot_curve.h> #include <string> #include <vector> -#include "MantidAPI/IPeakFunction.h" -#include "MantidAPI/MatrixWorkspace_fwd.h" -#include "MantidQtCustomInterfaces/EnggDiffraction/EnggDiffCalibSettings.h" +#include "MantidQtCustomInterfaces/EnggDiffraction/IEnggDiffractionUserMsg.h" +#include "MantidQtCustomInterfaces/EnggDiffraction/IEnggDiffractionSettings.h" +#include "MantidQtCustomInterfaces/EnggDiffraction/IEnggDiffractionPythonRunner.h" namespace MantidQt { namespace CustomInterfaces { @@ -41,11 +39,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. File change history is stored at: <https://github.com/mantidproject/mantid> Code Documentation is available at: <http://doxygen.mantidproject.org> */ -class IEnggDiffractionView { +class IEnggDiffractionView : public IEnggDiffractionUserMsg, + public IEnggDiffractionSettings, + public IEnggDiffractionPythonRunner { public: - IEnggDiffractionView(){}; - virtual ~IEnggDiffractionView(){}; + virtual ~IEnggDiffractionView() = default; /// @name Direct (and usually modal, or at least top/pop-up level) user /// interaction @@ -64,36 +63,6 @@ public: virtual void splashMessage(bool visible, const std::string &shortMsg, const std::string &description) = 0; - /** - * Display the current status (running some algorithms, finished, - * ready, etc.), in a status bar or similar. - * - * @param sts status message which should be concise - */ - virtual void showStatus(const std::string &sts) = 0; - - /** - * Display a warning to the user (for example as a pop-up window). - * - * @param warn warning title, should be short and would normally be - * shown as the title of the window or a big banner. - * - * @param description longer, free form description of the issue. - */ - virtual void userWarning(const std::string &warn, - const std::string &description) = 0; - - /** - * Display an error message (for example as a pop-up window). - * - * @param err Error title, should be short and would normally be - * shown as the title of the window or a big banner. - * - * @param description longer, free form description of the issue. - */ - virtual void userError(const std::string &err, - const std::string &description) = 0; - /** * Gets a filename from the user, to use for a new calibration file. * @@ -128,12 +97,6 @@ public: */ virtual std::string getRBNumber() const = 0; - /** - * - * @return calibration settings object with current user settings - */ - virtual EnggDiffCalibSettings currentCalibSettings() const = 0; - /** * What's the instrument this interface is using? * @@ -216,13 +179,6 @@ public: */ virtual std::vector<std::string> newCeriaNo() const = 0; - /** - * The filename (can be full path) selected to write a calibration - * - * @return file name - */ - virtual std::string outCalibFilename() const = 0; - /** * A new calibration is calculated or loaded => update display and * widgets. This becomes the new 'current' calibration. @@ -235,19 +191,6 @@ public: const std::string &ceriaNo, const std::string &fname) = 0; - /** - * Run Python code received as a script string. This is used for - * example to write GSAS instrument parameters file, or other code - * included with the Engg scripts. Temporarily here until we have a - * more final way of generating these files. A SaveGSAS algorithm - * that can handle ENGIN-X files would be ideal. - * - * @param pyCode Python script as a string - * - * @return status string from running the code - */ - virtual std::string enggRunPythonCode(const std::string &pyCode) = 0; - /** * Enable/disable all the sections or tabs of the interface. To be * used with required parameters, like a valid instrument, a valid @@ -258,22 +201,6 @@ public: */ virtual void enableTabs(bool enable) = 0; - /** - * Enable/disable calibrate+focus actions. The idea is that actions - * / buttons like 'calibrate', 'load calibration', or 'focus' can be - * disabled while a calibration of a focusing is being calculated. - * - * @param enable true to enable actions (default initial state) - */ - virtual void enableCalibrateAndFocusActions(bool enable) = 0; - - /** - * Directory set for focusing outputs - * - * @return directory path as a string - */ - virtual std::string focusingDir() const = 0; - /** * A (sample) run to focus * @@ -371,167 +298,6 @@ public: */ virtual double rebinningPulsesTime() const = 0; - /** - * returns directory of the file name to preform fitting on - * - * @return directory as std::string - */ - virtual std::string getFittingRunNo() const = 0; - - /** - * A list of dSpacing values to be translated into TOF - * to find expected peaks. - * - * @return list of dSpacing values as std::string - */ - virtual std::string fittingPeaksData() const = 0; - - /** - * Sets the peak list according to the QString given - * - * @param peakList list of expected peaks to be fitted as std::string - */ - virtual void setPeakList(std::string peakList) const = 0; - - /** - * Splits the file name in to sections of '_' and 'ENGINX' text - * within the filename - * - * @param selectedfPath is the selected file's path - * - * @return std::vector<std::string> of splitted file name with run - * number & bank - */ - virtual std::vector<std::string> - splitFittingDirectory(std::string &selectedfPath) = 0; - - /** - * adds the number of banks to the combo-box widget on the interface - * - * @param bankID the bank number to add to combo-box - */ - virtual void addBankItem(std::string bankID) = 0; - - /** - * adds the run number to the list view widget on the interface - * - * @param runNo run number which needs to be added to - * the list widget - */ - virtual void addRunNoItem(std::string runNo) = 0; - - /** - * emits the signal within view when run number/bank changed - */ - virtual void setBankEmit() = 0; - - /** - * sets the bank combo-box according to given index - * - * @param idx as int of the bank to set - */ - virtual void setBankIdComboBox(int idx) = 0; - - /** - * deletes all items from the fitting combo-box widget - */ - virtual void clearFittingComboBox() const = 0; - - /** - * enables or disables the fitting combo-box - * - * @param enable or disable the fitting combo-box widget - */ - virtual void enableFittingComboBox(bool enable) const = 0; - - /** - * gets the index of the bank according to text found - * - * @param bank as a std::string to find in widget - * - * @returns int index of the combo-box where the - * string is found - */ - virtual int getFittingComboIdx(std::string bank) const = 0; - - /* - * deletes all items from the fitting list widget - */ - virtual void clearFittingListWidget() const = 0; - - /** - * enables or disables the fitting list widget - * - * @param enable or disable the fitting list widget - */ - virtual void enableFittingListWidget(bool enable) const = 0; - - /* - * @return idx of current selected row of list widget - */ - virtual int getFittingListWidgetCurrentRow() const = 0; - - /** - * sets the current row of the fitting list widget - * - * @param idx number to set as for the list widget - */ - virtual void setFittingListWidgetCurrentRow(int idx) const = 0; - - /** - * gets the set focus directory within the setting tab - * - * @return std::string of focus directory - */ - virtual std::string getFocusDir() = 0; - - /** - * sets the fitting run number according to path - * - * @param path of the selected focused run file - */ - virtual void setFittingRunNo(QString path) = 0; - - /** - * gets the global vector in view containing focused file directory - * - * @return std::vector<std::string> containing the focused bank files - */ - virtual std::vector<std::string> getFittingRunNumVec() = 0; - - /** - * sets the global vector in view containing focused file directory - * - * @param assignVec of the all the focused bank files - * per run number - */ - virtual void setFittingRunNumVec(std::vector<std::string> assignVec) = 0; - - /** - * to determine whether the current loop is multi-run or single to avoid - * regenerating the list-view widget when not required - * - * @return bool whether given multi-run or singular file - */ - virtual bool getFittingMultiRunMode() = 0; - - /** - * sets the fitting mode to multi-run or single to avoid - * regenerating the list-view widget when not required - * - * @param mode true if its multi-run - */ - virtual void setFittingMultiRunMode(bool mode) = 0; - - /** - * generates and sets the curves on the fitting tab - * @param data of the workspace to be passed as QwtData - * @param focused to check whether focused workspace - * @param plotSinglePeaks whether to plot single peak fitting ws - * - */ - virtual void setDataVector(std::vector<boost::shared_ptr<QwtData>> &data, - bool focused, bool plotSinglePeaks) = 0; //@} /** diff --git a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/Elwin.h b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/Elwin.h index ca203d47165c6d5592156d8b931ea3d294faa4d3..87fdeae8fdf10227568357a251776f7596a299eb 100644 --- a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/Elwin.h +++ b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/Elwin.h @@ -33,7 +33,8 @@ private slots: void unGroupInput(bool error); private: - void addSaveAlgorithm(QString workspaceName, QString filename = ""); + void addSaveAlgorithm(const std::string &workspaceName, + std::string filename = ""); Ui::Elwin m_uiForm; QtTreePropertyBrowser *m_elwTree; diff --git a/MantidQt/CustomInterfaces/src/EnggDiffraction/EnggDiffFittingPresenter.cpp b/MantidQt/CustomInterfaces/src/EnggDiffraction/EnggDiffFittingPresenter.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9cb0fda741ecb5127e4a5b341dade3e9f48e223c --- /dev/null +++ b/MantidQt/CustomInterfaces/src/EnggDiffraction/EnggDiffFittingPresenter.cpp @@ -0,0 +1,1126 @@ +#include "MantidQtCustomInterfaces/EnggDiffraction/EnggDiffFittingPresenter.h" +#include "MantidAPI/AlgorithmManager.h" +#include "MantidAPI/ITableWorkspace.h" +#include "MantidAPI/MatrixWorkspace.h" +#include "MantidAPI/TableRow.h" +#include "MantidAPI/WorkspaceFactory.h" +#include "MantidQtCustomInterfaces/EnggDiffraction/EnggDiffFittingPresWorker.h" +#include "MantidQtCustomInterfaces/Muon/ALCHelper.h" + +#include <boost/lexical_cast.hpp> + +#include <Poco/DirectoryIterator.h> +#include <Poco/File.h> + +using namespace Mantid::API; +using namespace MantidQt::CustomInterfaces; + +namespace MantidQt { +namespace CustomInterfaces { + +namespace { +Mantid::Kernel::Logger g_log("EngineeringDiffractionGUI"); +} + +const bool EnggDiffFittingPresenter::g_useAlignDetectors = true; + +const std::string EnggDiffFittingPresenter::g_focusedFittingWSName = + "engggui_fitting_focused_ws"; + +/** + * Constructs a presenter for a fitting tab/widget view, which has a + * handle on the current calibration (produced and updated elsewhere). + * + * @param view the view that is attached to this presenter + * @param mainCalib provides the current calibration parameters/status + */ +EnggDiffFittingPresenter::EnggDiffFittingPresenter( + IEnggDiffFittingView *view, + boost::shared_ptr<IEnggDiffractionCalibration> mainCalib) + : m_fittingFinishedOK(false), m_workerThread(nullptr), + m_mainCalib(mainCalib), m_view(view) {} + +EnggDiffFittingPresenter::~EnggDiffFittingPresenter() { cleanup(); } + +/** +* Close open sessions, kill threads etc., for a graceful window +* close/destruction +*/ +void EnggDiffFittingPresenter::cleanup() { + // m_model->cleanup(); + + // this may still be running + if (m_workerThread) { + if (m_workerThread->isRunning()) { + g_log.notice() << "A fitting process is currently running, shutting " + "it down immediately...\n"; + m_workerThread->wait(10); + } + delete m_workerThread; + m_workerThread = nullptr; + } +} + +void EnggDiffFittingPresenter::notify( + IEnggDiffFittingPresenter::Notification notif) { + switch (notif) { + + case IEnggDiffFittingPresenter::Start: + processStart(); + break; + + case IEnggDiffFittingPresenter::FittingRunNo: + fittingRunNoChanged(); + break; + + case IEnggDiffFittingPresenter::FitPeaks: + processFitPeaks(); + break; + + case IEnggDiffFittingPresenter::ShutDown: + processShutDown(); + break; + + case IEnggDiffFittingPresenter::LogMsg: + processLogMsg(); + break; + } +} + +std::vector<GSASCalibrationParms> +EnggDiffFittingPresenter::currentCalibration() const { + return m_mainCalib->currentCalibration(); +} + +void EnggDiffFittingPresenter::startAsyncFittingWorker( + const std::string &focusedRunNo, const std::string &expectedPeaks) { + + delete m_workerThread; + m_workerThread = new QThread(this); + EnggDiffFittingWorker *worker = + new EnggDiffFittingWorker(this, focusedRunNo, expectedPeaks); + worker->moveToThread(m_workerThread); + + connect(m_workerThread, SIGNAL(started()), worker, SLOT(fitting())); + connect(worker, SIGNAL(finished()), this, SLOT(fittingFinished())); + // early delete of thread and worker + connect(m_workerThread, SIGNAL(finished()), m_workerThread, + SLOT(deleteLater()), Qt::DirectConnection); + connect(worker, SIGNAL(finished()), worker, SLOT(deleteLater())); + m_workerThread->start(); +} + +void EnggDiffFittingPresenter::fittingFinished() { + if (!m_view) + return; + + if (!m_fittingFinishedOK) { + g_log.warning() << "The single peak fitting did not finish correctly.\n"; + if (m_workerThread) { + delete m_workerThread; + m_workerThread = nullptr; + } + + m_view->showStatus( + "Single peak fitting process did not complete successfully"); + } else { + g_log.notice() << "The single peak fitting finished - the output " + "workspace is ready.\n"; + + m_view->showStatus("Single peak fittin process finished. Ready"); + if (m_workerThread) { + delete m_workerThread; + m_workerThread = nullptr; + } + } + + try { + // should now plot the focused workspace when single peak fitting + // process fails + plotFitPeaksCurves(); + + } catch (std::runtime_error &re) { + g_log.error() << "Unable to finish the plotting of the graph for " + "engggui_fitting_focused_fitpeaks workspace. Error " + "description: " + + static_cast<std::string>(re.what()) + + " Please check also the log message for detail."; + throw; + } + g_log.notice() << "EnggDiffraction GUI: plotting of peaks for single peak " + "fits has completed. \n"; + + // enable the GUI + m_view->enableCalibrateFocusFitUserActions(true); +} + +// Fitting Tab Run Number & Bank handling here +void EnggDiffFittingPresenter::fittingRunNoChanged() { + + try { + auto strFocusedFile = m_view->getFittingRunNo(); + auto focusedFile = strFocusedFile; + // file name + Poco::Path selectedfPath(strFocusedFile); + Poco::Path bankDir; + + // handling of vectors + auto runnoDirVector = m_view->getFittingRunNumVec(); + runnoDirVector.clear(); + + std::string strFPath = selectedfPath.toString(); + // returns empty if no directory is found + std::vector<std::string> splitBaseName = + m_view->splitFittingDirectory(strFPath); + // runNo when single focused file selected + std::vector<std::string> runNoVec; + + if (selectedfPath.isFile() && !splitBaseName.empty()) { + +#ifdef __unix__ + bankDir = selectedfPath.parent(); +#else + bankDir = (bankDir).expand(selectedfPath.parent().toString()); +#endif + if (!splitBaseName.empty() && splitBaseName.size() > 3) { + std::string foc_file = splitBaseName[0] + "_" + splitBaseName[1] + "_" + + splitBaseName[2] + "_" + splitBaseName[3]; + std::string strBankDir = bankDir.toString(); + + if (strBankDir.empty()) { + m_view->userWarning( + "Invalid Input", + "Please check that a valid directory is " + "set for Output Folder under Focusing Settings on the " + "settings tab. " + "Please try again"); + } else { + + updateFittingDirVec(strBankDir, foc_file, false, runnoDirVector); + m_view->setFittingRunNumVec(runnoDirVector); + + // add bank to the combo-box and list view + setBankItems(); + setDefaultBank(splitBaseName, focusedFile); + runNoVec.clear(); + runNoVec.push_back(splitBaseName[1]); + auto fittingMultiRunMode = m_view->getFittingMultiRunMode(); + if (!fittingMultiRunMode) + setRunNoItems(runNoVec, false); + } + } + // assuming that no directory is found so look for number + // if run number length greater + } else if (focusedFile.size() > 4) { + if (strFocusedFile.find("-") != std::string::npos) { + std::vector<std::string> firstLastRunNoVec; + boost::split(firstLastRunNoVec, strFocusedFile, boost::is_any_of("-")); + std::string firstRun; + std::string lastRun; + if (!firstLastRunNoVec.empty()) { + firstRun = firstLastRunNoVec[0]; + lastRun = firstLastRunNoVec[1]; + + m_view->setFittingMultiRunMode(true); + enableMultiRun(firstRun, lastRun, runnoDirVector); + } + + } else { + // if given a single run number instead + auto focusDir = m_view->focusingDir(); + + if (focusDir.empty()) { + m_view->userWarning( + "Invalid Input", + "Please check that a valid directory is " + "set for Output Folder under Focusing Settings on the " + "settings tab. " + "Please try again"); + } else { + + updateFittingDirVec(focusDir, strFocusedFile, false, runnoDirVector); + m_view->setFittingRunNumVec(runnoDirVector); + + // add bank to the combo-box and list view + setBankItems(); + setDefaultBank(splitBaseName, focusedFile); + runNoVec.clear(); + runNoVec.push_back(strFocusedFile); + + auto fittingMultiRunMode = m_view->getFittingMultiRunMode(); + if (!fittingMultiRunMode) + setRunNoItems(runNoVec, false); + } + } + } + // set the directory here to the first in the vector if its not empty + if (!runnoDirVector.empty() && !selectedfPath.isFile()) { + auto firstDir = runnoDirVector[0]; + m_view->setFittingRunNo(firstDir); + + } else if (m_view->getFittingRunNo().empty()) { + m_view->userWarning("Invalid Input", + "Invalid directory or run number given. " + "Please try again"); + } + + } catch (std::runtime_error &re) { + m_view->userWarning("Invalid file", + "Unable to select the file; " + + static_cast<std::string>(re.what())); + return; + } +} + +void EnggDiffFittingPresenter::updateFittingDirVec( + const std::string &bankDir, const std::string &focusedFile, bool multi_run, + std::vector<std::string> &fittingRunNoDirVec) { + + try { + std::string cwd(bankDir); + Poco::DirectoryIterator it(cwd); + Poco::DirectoryIterator end; + while (it != end) { + if (it->isFile()) { + std::string itFilePath = it->path(); + Poco::Path itBankfPath(itFilePath); + + std::string itbankFileName = itBankfPath.getBaseName(); + // check if it not any other file.. e.g: texture + if (itbankFileName.find(focusedFile) != std::string::npos) { + fittingRunNoDirVec.push_back(itFilePath); + if (multi_run) + return; + } + } + ++it; + } + } catch (std::runtime_error &re) { + m_view->userWarning("Invalid file", + "File not found in the following directory; " + + bankDir + ". " + + static_cast<std::string>(re.what())); + } +} + +void EnggDiffFittingPresenter::enableMultiRun( + std::string firstRun, std::string lastRun, + std::vector<std::string> &fittingRunNoDirVec) { + + bool firstDig = isDigit(firstRun); + bool lastDig = isDigit(lastRun); + + std::vector<std::string> RunNumberVec; + if (firstDig && lastDig) { + int firstNum = std::stoi(firstRun); + int lastNum = std::stoi(lastRun); + + if ((lastNum - firstNum) > 200) { + m_view->userWarning( + "Please try again", + "The specified run number range is " + "far to big, please try a smaller range of consecutive run numbers."); + } + + else if (firstNum <= lastNum) { + + for (int i = firstNum; i <= lastNum; i++) { + RunNumberVec.push_back(std::to_string(i)); + } + + auto focusDir = m_view->focusingDir(); + if (focusDir.empty()) { + m_view->userWarning( + "Invalid Input", + "Please check that a valid directory is " + "set for Output Folder under Focusing Settings on the " + "settings tab. " + "Please try again"); + } else { + // if given a single run number instead + for (size_t i = 0; i < RunNumberVec.size(); i++) { + updateFittingDirVec(focusDir, RunNumberVec[i], true, + fittingRunNoDirVec); + } + int diff = (lastNum - firstNum) + 1; + auto global_vec_size = fittingRunNoDirVec.size(); + if (size_t(diff) == global_vec_size) { + + setRunNoItems(RunNumberVec, true); + + m_view->setBankEmit(); + } + } + } else { + m_view->userWarning("Invalid Run Number", + "One or more run file not found " + "from the specified range of runs." + "Please try again"); + } + } else { + m_view->userWarning("Invalid Run Number", + "The specfied range of run number " + "entered is invalid. Please try again"); + } +} + +void EnggDiffFittingPresenter::processStart() {} + +void EnggDiffFittingPresenter::processShutDown() { + m_view->saveSettings(); + cleanup(); +} + +void EnggDiffFittingPresenter::processLogMsg() { + std::vector<std::string> msgs = m_view->logMsgs(); + for (size_t i = 0; i < msgs.size(); i++) { + g_log.information() << msgs[i] << '\n'; + } +} + +void EnggDiffFittingPresenter::processFitPeaks() { + const std::string focusedRunNo = m_view->getFittingRunNo(); + std::string fittingPeaks = m_view->fittingPeaksData(); + + const std::string fitPeaksData = validateFittingexpectedPeaks(fittingPeaks); + + g_log.debug() << "the expected peaks are: " << fitPeaksData << '\n'; + + try { + inputChecksBeforeFitting(focusedRunNo, fitPeaksData); + } catch (std::invalid_argument &ia) { + m_view->userWarning("Error in the inputs required for fitting", ia.what()); + return; + } + + const std::string outWSName = "engggui_fitting_fit_peak_ws"; + g_log.notice() << "EnggDiffraction GUI: starting new " + "single peak fits into workspace '" + + outWSName + "'. This " + "may take some seconds... \n"; + + m_view->showStatus("Fitting single peaks..."); + // disable GUI to avoid any double threads + m_view->enableCalibrateFocusFitUserActions(false); + // startAsyncFittingWorker + // doFitting() + startAsyncFittingWorker(focusedRunNo, fitPeaksData); +} + +void EnggDiffFittingPresenter::inputChecksBeforeFitting( + const std::string &focusedRunNo, const std::string &expectedPeaks) { + if (focusedRunNo.size() == 0) { + throw std::invalid_argument( + "Focused Run " + "cannot be empty and must be a valid directory"); + } + + Poco::File file(focusedRunNo); + if (!file.exists()) { + throw std::invalid_argument("The focused workspace file for single peak " + "fitting could not be found: " + + focusedRunNo); + } + + if (expectedPeaks.empty()) { + g_log.warning() << "Expected peaks were not passed, via fitting interface, " + "the default list of " + "expected peaks will be utilised instead.\n"; + } + bool contains_non_digits = + expectedPeaks.find_first_not_of("0123456789,. ") != std::string::npos; + if (contains_non_digits) { + throw std::invalid_argument("The expected peaks provided " + expectedPeaks + + " is invalid, " + "fitting process failed. Please try again!"); + } +} + +std::string EnggDiffFittingPresenter::validateFittingexpectedPeaks( + std::string &expectedPeaks) const { + + if (!expectedPeaks.empty()) { + + g_log.debug() << "Validating the expected peak list.\n"; + + auto *comma = ","; + + for (size_t i = 0; i < expectedPeaks.size() - 1; i++) { + size_t j = i + 1; + + if (expectedPeaks[i] == *comma && expectedPeaks[i] == expectedPeaks[j]) { + expectedPeaks.erase(j, 1); + i--; + + } else { + ++j; + } + } + + size_t strLength = expectedPeaks.length() - 1; + if (expectedPeaks.at(size_t(0)) == ',') { + expectedPeaks.erase(size_t(0), 1); + strLength -= size_t(1); + } + + if (expectedPeaks.at(strLength) == ',') { + expectedPeaks.erase(strLength, 1); + } + + m_view->setPeakList(expectedPeaks); + } + + return expectedPeaks; +} + +void EnggDiffFittingPresenter::setDifcTzero(MatrixWorkspace_sptr wks) const { + size_t bankID = 1; + // attempt to guess bankID - this should be done in code that is currently + // in the view + auto fittingFilename = m_view->getFittingRunNo(); + Poco::File fittingFile(fittingFilename); + if (fittingFile.exists()) { + Poco::Path path(fittingFile.path()); + auto name = path.getBaseName(); + std::vector<std::string> chunks; + boost::split(chunks, name, boost::is_any_of("_")); + if (!chunks.empty()) { + try { + bankID = boost::lexical_cast<size_t>(chunks.back()); + } catch (std::runtime_error &) { + } + } + } + + const std::string units = "none"; + auto &run = wks->mutableRun(); + + std::vector<GSASCalibrationParms> calibParms = currentCalibration(); + if (calibParms.empty()) { + run.addProperty<int>("bankid", 1, units, true); + run.addProperty<double>("difc", 18400.0, units, true); + run.addProperty<double>("difa", 0.0, units, true); + run.addProperty<double>("tzero", 4.0, units, true); + } else { + GSASCalibrationParms parms(0, 0.0, 0.0, 0.0); + for (const auto &p : calibParms) { + if (p.bankid == bankID) { + parms = p; + break; + } + } + if (0 == parms.difc) + parms = calibParms.front(); + + run.addProperty<int>("bankid", static_cast<int>(parms.bankid), units, true); + run.addProperty<double>("difc", parms.difc, units, true); + run.addProperty<double>("difa", parms.difa, units, true); + run.addProperty<double>("tzero", parms.tzero, units, true); + } +} + +void EnggDiffFittingPresenter::doFitting(const std::string &focusedRunNo, + const std::string &expectedPeaks) { + g_log.notice() << "EnggDiffraction GUI: starting new fitting with file " + << focusedRunNo << ". This may take a few seconds... \n"; + + MatrixWorkspace_sptr focusedWS; + m_fittingFinishedOK = false; + + // load the focused workspace file to perform single peak fits + try { + auto load = + Mantid::API::AlgorithmManager::Instance().createUnmanaged("Load"); + load->initialize(); + load->setPropertyValue("Filename", focusedRunNo); + load->setPropertyValue("OutputWorkspace", g_focusedFittingWSName); + load->execute(); + + AnalysisDataServiceImpl &ADS = Mantid::API::AnalysisDataService::Instance(); + focusedWS = ADS.retrieveWS<MatrixWorkspace>(g_focusedFittingWSName); + } catch (std::runtime_error &re) { + g_log.error() + << "Error while loading focused data. " + "Could not run the algorithm Load succesfully for the Fit " + "peaks (file name: " + + focusedRunNo + "). Error description: " + re.what() + + " Please check also the previous log messages for details."; + return; + } + + setDifcTzero(focusedWS); + + // run the algorithm EnggFitPeaks with workspace loaded above + // requires unit in Time of Flight + auto enggFitPeaks = + Mantid::API::AlgorithmManager::Instance().createUnmanaged("EnggFitPeaks"); + const std::string focusedFitPeaksTableName = + "engggui_fitting_fitpeaks_params"; + + // delete existing table workspace to avoid confusion + AnalysisDataServiceImpl &ADS = Mantid::API::AnalysisDataService::Instance(); + if (ADS.doesExist(focusedFitPeaksTableName)) { + ADS.remove(focusedFitPeaksTableName); + } + + try { + enggFitPeaks->initialize(); + enggFitPeaks->setProperty("InputWorkspace", focusedWS); + if (!expectedPeaks.empty()) { + enggFitPeaks->setProperty("expectedPeaks", expectedPeaks); + } + enggFitPeaks->setProperty("FittedPeaks", focusedFitPeaksTableName); + enggFitPeaks->execute(); + } catch (std::exception &re) { + g_log.error() << "Could not run the algorithm EnggFitPeaks " + "successfully for bank, " + // bank name + "Error description: " + + static_cast<std::string>(re.what()) + + " Please check also the log message for detail.\n"; + } + + try { + runFittingAlgs(focusedFitPeaksTableName, g_focusedFittingWSName); + + } catch (std::invalid_argument &ia) { + g_log.error() << "Error, Fitting could not finish off correctly, " + + std::string(ia.what()) << '\n'; + return; + } +} + +void EnggDiffFittingPresenter::runFittingAlgs( + std::string focusedFitPeaksTableName, std::string focusedWSName) { + // retrieve the table with parameters + auto &ADS = Mantid::API::AnalysisDataService::Instance(); + if (!ADS.doesExist(focusedFitPeaksTableName)) { + // convert units so valid dSpacing peaks can still be added to gui + if (ADS.doesExist(g_focusedFittingWSName)) { + convertUnits(g_focusedFittingWSName); + } + + throw std::invalid_argument( + focusedFitPeaksTableName + + " workspace could not be found. " + "Please check the log messages for more details."); + } + + auto table = ADS.retrieveWS<ITableWorkspace>(focusedFitPeaksTableName); + size_t rowCount = table->rowCount(); + const std::string single_peak_out_WS = "engggui_fitting_single_peaks"; + std::string currentPeakOutWS; + + std::string Bk2BkExpFunctionStr; + std::string startX = ""; + std::string endX = ""; + for (size_t i = 0; i < rowCount; i++) { + // get the functionStrFactory to generate the string for function + // property, returns the string with i row from table workspace + // table is just passed so it works? + Bk2BkExpFunctionStr = + functionStrFactory(table, focusedFitPeaksTableName, i, startX, endX); + + g_log.debug() << "startX: " + startX + " . endX: " + endX << '\n'; + + currentPeakOutWS = "__engggui_fitting_single_peaks" + std::to_string(i); + + // run EvaluateFunction algorithm with focused workspace to produce + // the correct fit function + // focusedWSName is not going to change as its always going to be from + // single workspace + runEvaluateFunctionAlg(Bk2BkExpFunctionStr, focusedWSName, currentPeakOutWS, + startX, endX); + + // crop workspace so only the correct workspace index is plotted + runCropWorkspaceAlg(currentPeakOutWS); + + // apply the same binning as a focused workspace + runRebinToWorkspaceAlg(currentPeakOutWS); + + // if the first peak + if (i == size_t(0)) { + + // create a workspace clone of bank focus file + // this will import all information of the previous file + runCloneWorkspaceAlg(focusedWSName, single_peak_out_WS); + + setDataToClonedWS(currentPeakOutWS, single_peak_out_WS); + ADS.remove(currentPeakOutWS); + } else { + const std::string currentPeakClonedWS = + "__engggui_fitting_cloned_peaks" + std::to_string(i); + + runCloneWorkspaceAlg(focusedWSName, currentPeakClonedWS); + + setDataToClonedWS(currentPeakOutWS, currentPeakClonedWS); + + // append all peaks in to single workspace & remove + runAppendSpectraAlg(single_peak_out_WS, currentPeakClonedWS); + ADS.remove(currentPeakOutWS); + ADS.remove(currentPeakClonedWS); + } + } + + convertUnits(g_focusedFittingWSName); + + // convert units for both workspaces to dSpacing from ToF + if (rowCount > size_t(0)) { + auto swks = ADS.retrieveWS<MatrixWorkspace>(single_peak_out_WS); + setDifcTzero(swks); + convertUnits(single_peak_out_WS); + } else { + g_log.error() << "The engggui_fitting_fitpeaks_params table produced is" + "empty. Please try again!\n"; + } + + m_fittingFinishedOK = true; +} + +std::string EnggDiffFittingPresenter::functionStrFactory( + Mantid::API::ITableWorkspace_sptr ¶mTableWS, std::string tableName, + size_t row, std::string &startX, std::string &endX) { + const double windowLeft = 9; + const double windowRight = 12; + + AnalysisDataServiceImpl &ADS = Mantid::API::AnalysisDataService::Instance(); + paramTableWS = ADS.retrieveWS<ITableWorkspace>(tableName); + + double A0 = paramTableWS->cell<double>(row, size_t(1)); + double A1 = paramTableWS->cell<double>(row, size_t(3)); + double I = paramTableWS->cell<double>(row, size_t(13)); + double A = paramTableWS->cell<double>(row, size_t(7)); + double B = paramTableWS->cell<double>(row, size_t(9)); + double X0 = paramTableWS->cell<double>(row, size_t(5)); + double S = paramTableWS->cell<double>(row, size_t(11)); + + startX = boost::lexical_cast<std::string>(X0 - (windowLeft * S)); + endX = boost::lexical_cast<std::string>(X0 + (windowRight * S)); + + std::string functionStr = + "name=LinearBackground,A0=" + boost::lexical_cast<std::string>(A0) + + ",A1=" + boost::lexical_cast<std::string>(A1) + + ";name=BackToBackExponential,I=" + boost::lexical_cast<std::string>(I) + + ",A=" + boost::lexical_cast<std::string>(A) + ",B=" + + boost::lexical_cast<std::string>(B) + ",X0=" + + boost::lexical_cast<std::string>(X0) + ",S=" + + boost::lexical_cast<std::string>(S); + + return functionStr; +} + +void EnggDiffFittingPresenter::runEvaluateFunctionAlg( + const std::string &bk2BkExpFunction, const std::string &InputName, + const std::string &OutputName, const std::string &startX, + const std::string &endX) { + + auto evalFunc = Mantid::API::AlgorithmManager::Instance().createUnmanaged( + "EvaluateFunction"); + g_log.notice() << "EvaluateFunction algorithm has started\n"; + try { + evalFunc->initialize(); + evalFunc->setProperty("Function", bk2BkExpFunction); + evalFunc->setProperty("InputWorkspace", InputName); + evalFunc->setProperty("OutputWorkspace", OutputName); + evalFunc->setProperty("StartX", startX); + evalFunc->setProperty("EndX", endX); + evalFunc->execute(); + } catch (std::runtime_error &re) { + g_log.error() << "Could not run the algorithm EvaluateFunction, " + "Error description: " + + static_cast<std::string>(re.what()) << '\n'; + } +} + +void EnggDiffFittingPresenter::runCropWorkspaceAlg(std::string workspaceName) { + auto cropWS = Mantid::API::AlgorithmManager::Instance().createUnmanaged( + "CropWorkspace"); + try { + cropWS->initialize(); + cropWS->setProperty("InputWorkspace", workspaceName); + cropWS->setProperty("OutputWorkspace", workspaceName); + cropWS->setProperty("StartWorkspaceIndex", 1); + cropWS->setProperty("EndWorkspaceIndex", 1); + cropWS->execute(); + } catch (std::runtime_error &re) { + g_log.error() << "Could not run the algorithm CropWorkspace, " + "Error description: " + + static_cast<std::string>(re.what()) << '\n'; + } +} + +void EnggDiffFittingPresenter::runAppendSpectraAlg(std::string workspace1Name, + std::string workspace2Name) { + auto appendSpec = Mantid::API::AlgorithmManager::Instance().createUnmanaged( + "AppendSpectra"); + try { + appendSpec->initialize(); + appendSpec->setProperty("InputWorkspace1", workspace1Name); + appendSpec->setProperty("InputWorkspace2", workspace2Name); + appendSpec->setProperty("OutputWorkspace", workspace1Name); + appendSpec->execute(); + } catch (std::runtime_error &re) { + g_log.error() << "Could not run the algorithm AppendWorkspace, " + "Error description: " + + static_cast<std::string>(re.what()) << '\n'; + } +} + +void EnggDiffFittingPresenter::runRebinToWorkspaceAlg( + std::string workspaceName) { + auto RebinToWs = Mantid::API::AlgorithmManager::Instance().createUnmanaged( + "RebinToWorkspace"); + try { + RebinToWs->initialize(); + RebinToWs->setProperty("WorkspaceToRebin", workspaceName); + RebinToWs->setProperty("WorkspaceToMatch", g_focusedFittingWSName); + RebinToWs->setProperty("OutputWorkspace", workspaceName); + RebinToWs->execute(); + } catch (std::runtime_error &re) { + g_log.error() << "Could not run the algorithm RebinToWorkspace, " + "Error description: " + + static_cast<std::string>(re.what()) << '\n'; + } +} + +/** + * Converts from time-of-flight to d-spacing + * + * @param workspaceName name of the workspace to convert (in place) + */ +void EnggDiffFittingPresenter::convertUnits(std::string workspaceName) { + // Here using the GSAS (DIFC, TZERO) parameters seems preferred + if (g_useAlignDetectors) { + runAlignDetectorsAlg(workspaceName); + } else { + runConvertUnitsAlg(workspaceName); + } +} + +void EnggDiffFittingPresenter::getDifcTzero(MatrixWorkspace_const_sptr wks, + double &difc, double &difa, + double &tzero) const { + + try { + const auto run = wks->run(); + // long, step by step way: + // auto propC = run.getLogData("difc"); + // auto doubleC = + // dynamic_cast<Mantid::Kernel::PropertyWithValue<double> *>(propC); + // if (!doubleC) + // throw Mantid::Kernel::Exception::NotFoundError( + // "Required difc property not found in workspace.", "difc"); + difc = run.getPropertyValueAsType<double>("difc"); + difa = run.getPropertyValueAsType<double>("difa"); + tzero = run.getPropertyValueAsType<double>("tzero"); + + } catch (std::runtime_error &rexc) { + // fallback to something reasonable / approximate values so + // the fitting tab can work minimally + difa = tzero = 0.0; + difc = 18400; + g_log.warning() + << "Could not retrieve the DIFC, DIFA, TZERO values from the workspace " + << wks->name() << ". Using default, which is not adjusted for this " + "workspace/run: DIFA: " << difa << ", DIFC: " << difc + << ", TZERO: " << tzero << ". Error details: " << rexc.what() << '\n'; + } +} + +/** + * Converts units from time-of-flight to d-spacing, using + * AlignDetectors. This is the GSAS-style alternative to using the + * algorithm ConvertUnits. Needs to make sure that the workspace is + * not of distribution type (and use the algorithm + * ConvertFromDistribution if it is). This is a requirement of + * AlignDetectors. + * + * @param workspaceName name of the workspace to convert + */ +void EnggDiffFittingPresenter::runAlignDetectorsAlg(std::string workspaceName) { + const std::string targetUnit = "dSpacing"; + const std::string algName = "AlignDetectors"; + + const auto &ADS = Mantid::API::AnalysisDataService::Instance(); + auto inputWS = ADS.retrieveWS<MatrixWorkspace>(workspaceName); + if (!inputWS) + return; + + double difc, difa, tzero; + getDifcTzero(inputWS, difc, difa, tzero); + + // create a table with the GSAS calibration parameters + ITableWorkspace_sptr difcTable; + try { + difcTable = Mantid::API::WorkspaceFactory::Instance().createTable(); + if (!difcTable) { + return; + } + difcTable->addColumn("int", "detid"); + difcTable->addColumn("double", "difc"); + difcTable->addColumn("double", "difa"); + difcTable->addColumn("double", "tzero"); + TableRow row = difcTable->appendRow(); + auto &spec = inputWS->getSpectrum(0); + Mantid::detid_t detID = *(spec.getDetectorIDs().cbegin()); + + row << detID << difc << difa << tzero; + } catch (std::runtime_error &rexc) { + g_log.error() << "Failed to prepare calibration table input to convert " + "units with the algorithm " << algName + << ". Error details: " << rexc.what() << '\n'; + return; + } + + // AlignDetectors doesn't take distribution workspaces (it enforces + // RawCountValidator) + if (inputWS->isDistribution()) { + try { + auto alg = Mantid::API::AlgorithmManager::Instance().createUnmanaged( + "ConvertFromDistribution"); + alg->initialize(); + alg->setProperty("Workspace", workspaceName); + alg->execute(); + } catch (std::runtime_error &rexc) { + g_log.error() << "Could not run ConvertFromDistribution. Error: " + << rexc.what() << '\n'; + return; + } + } + + try { + auto alg = + Mantid::API::AlgorithmManager::Instance().createUnmanaged(algName); + alg->initialize(); + alg->setProperty("InputWorkspace", workspaceName); + alg->setProperty("OutputWorkspace", workspaceName); + alg->setProperty("CalibrationWorkspace", difcTable); + alg->execute(); + } catch (std::runtime_error &rexc) { + g_log.error() << "Could not run the algorithm " << algName + << " to convert workspace to " << targetUnit + << ", Error details: " + static_cast<std::string>(rexc.what()) + << '\n'; + } +} + +void EnggDiffFittingPresenter::runConvertUnitsAlg(std::string workspaceName) { + const std::string targetUnit = "dSpacing"; + auto ConvertUnits = + Mantid::API::AlgorithmManager::Instance().createUnmanaged("ConvertUnits"); + try { + ConvertUnits->initialize(); + ConvertUnits->setProperty("InputWorkspace", workspaceName); + ConvertUnits->setProperty("OutputWorkspace", workspaceName); + ConvertUnits->setProperty("Target", targetUnit); + ConvertUnits->setPropertyValue("EMode", "Elastic"); + ConvertUnits->execute(); + } catch (std::runtime_error &re) { + g_log.error() << "Could not run the algorithm ConvertUnits to convert " + "workspace to " << targetUnit + << ", Error description: " + + static_cast<std::string>(re.what()) << '\n'; + } +} + +void EnggDiffFittingPresenter::runCloneWorkspaceAlg( + std::string inputWorkspace, const std::string &outputWorkspace) { + + auto cloneWorkspace = + Mantid::API::AlgorithmManager::Instance().createUnmanaged( + "CloneWorkspace"); + try { + cloneWorkspace->initialize(); + cloneWorkspace->setProperty("InputWorkspace", inputWorkspace); + cloneWorkspace->setProperty("OutputWorkspace", outputWorkspace); + cloneWorkspace->execute(); + } catch (std::runtime_error &re) { + g_log.error() << "Could not run the algorithm CreateWorkspace, " + "Error description: " + + static_cast<std::string>(re.what()) << '\n'; + } +} + +void EnggDiffFittingPresenter::setDataToClonedWS(std::string ¤t_WS, + const std::string &cloned_WS) { + AnalysisDataServiceImpl &ADS = Mantid::API::AnalysisDataService::Instance(); + auto currentPeakWS = ADS.retrieveWS<MatrixWorkspace>(current_WS); + auto currentClonedWS = ADS.retrieveWS<MatrixWorkspace>(cloned_WS); + currentClonedWS->dataY(0) = currentPeakWS->readY(0); + currentClonedWS->dataE(0) = currentPeakWS->readE(0); +} + +void EnggDiffFittingPresenter::setBankItems() { + try { + auto fitting_runno_vector = m_view->getFittingRunNumVec(); + + if (!fitting_runno_vector.empty()) { + + // delete previous bank added to the list + m_view->clearFittingComboBox(); + + for (size_t i = 0; i < fitting_runno_vector.size(); i++) { + Poco::Path vecFile(fitting_runno_vector[i]); + std::string strVecFile = vecFile.toString(); + // split the directory from m_fitting_runno_dir_vec + std::vector<std::string> vecFileSplit = + m_view->splitFittingDirectory(strVecFile); + + // get the last split in vector which will be bank + std::string bankID = (vecFileSplit.back()); + + bool digit = isDigit(bankID); + + if (digit || bankID == "cropped") { + m_view->addBankItem(bankID); + } else { + QString qBank = QString("Bank %1").arg(i + 1); + m_view->addBankItem(qBank.toStdString()); + } + } + + m_view->enableFittingComboBox(true); + } else { + // upon invalid file + // disable the widgets when only one related file found + m_view->enableFittingComboBox(false); + + m_view->clearFittingComboBox(); + } + + } catch (std::runtime_error &re) { + m_view->userWarning("Unable to insert items: ", + "Could not add banks to " + "combo-box or list widget; " + + static_cast<std::string>(re.what()) + + ". Please try again"); + } +} + +void EnggDiffFittingPresenter::setRunNoItems( + std::vector<std::string> runNumVector, bool multiRun) { + try { + if (!runNumVector.empty()) { + + // delete previous bank added to the list + m_view->clearFittingListWidget(); + + for (size_t i = 0; i < runNumVector.size(); i++) { + + // get the last split in vector which will be bank + std::string currentRun = (runNumVector[i]); + + m_view->addRunNoItem(currentRun); + } + + if (multiRun) { + m_view->enableFittingListWidget(true); + + auto currentIndex = m_view->getFittingListWidgetCurrentRow(); + if (currentIndex == -1) + m_view->setFittingListWidgetCurrentRow(0); + } else { + m_view->enableFittingListWidget(false); + } + } + + else { + // upon invalid file + // disable the widgets when only one related file found + m_view->enableFittingListWidget(false); + + m_view->clearFittingListWidget(); + } + + } catch (std::runtime_error &re) { + m_view->userWarning("Unable to insert items: ", + "Could not add list widget; " + + static_cast<std::string>(re.what()) + + ". Please try again"); + } +} + +void EnggDiffFittingPresenter::setDefaultBank( + const std::vector<std::string> &splittedBaseName, + const std::string &selectedFile) { + + if (!splittedBaseName.empty()) { + + std::string bankID = (splittedBaseName.back()); + auto combo_data = m_view->getFittingComboIdx(bankID); + + if (combo_data > -1) { + m_view->setBankIdComboBox(combo_data); + } else { + m_view->setFittingRunNo(selectedFile); + } + } + // check if the vector is not empty so that the first directory + // can be assigned to text-field when number is given + else if (!m_view->getFittingRunNumVec().empty()) { + auto firstDir = m_view->getFittingRunNumVec().at(0); + auto intialDir = firstDir; + m_view->setFittingRunNo(intialDir); + } + // if nothing found related to text-field input + else if (!m_view->getFittingRunNo().empty()) + m_view->setFittingRunNo(selectedFile); +} + +bool EnggDiffFittingPresenter::isDigit(std::string text) { + for (size_t i = 0; i < text.size(); i++) { + char *str = &text[i]; + if (std::isdigit(*str)) { + return true; + } + } + return false; +} + +void EnggDiffFittingPresenter::plotFitPeaksCurves() { + AnalysisDataServiceImpl &ADS = Mantid::API::AnalysisDataService::Instance(); + std::string singlePeaksWs = "engggui_fitting_single_peaks"; + + if (!ADS.doesExist(singlePeaksWs) && !ADS.doesExist(g_focusedFittingWSName)) { + g_log.error() << "Fitting results could not be plotted as there is no " + + singlePeaksWs + " or " + g_focusedFittingWSName + + " workspace found.\n"; + m_view->showStatus("Error while fitting peaks"); + return; + } + + try { + auto focusedPeaksWS = + ADS.retrieveWS<MatrixWorkspace>(g_focusedFittingWSName); + auto focusedData = ALCHelper::curveDataFromWs(focusedPeaksWS); + m_view->setDataVector(focusedData, true, m_fittingFinishedOK); + + if (m_fittingFinishedOK) { + g_log.debug() << "single peaks fitting being plotted now.\n"; + auto singlePeaksWS = ADS.retrieveWS<MatrixWorkspace>(singlePeaksWs); + auto singlePeaksData = ALCHelper::curveDataFromWs(singlePeaksWS); + m_view->setDataVector(singlePeaksData, false, true); + m_view->showStatus("Peaks fitted successfully"); + + } else { + g_log.notice() + << "Focused workspace has been plotted to the " + "graph; further peaks can be adding using Peak Tools.\n"; + g_log.warning() << "Peaks could not be plotted as the fitting process " + "did not finish correctly.\n"; + m_view->showStatus("No peaks could be fitted"); + } + + } catch (std::runtime_error) { + g_log.error() + << "Unable to finish of the plotting of the graph for " + "engggui_fitting_focused_fitpeaks workspace. Error " + "description. Please check also the log message for detail."; + + m_view->showStatus("Error while plotting the peaks fitted"); + throw; + } +} + +} // namespace CustomInterfaces +} // namespace MantidQt diff --git a/MantidQt/CustomInterfaces/src/EnggDiffraction/EnggDiffFittingViewQtWidget.cpp b/MantidQt/CustomInterfaces/src/EnggDiffraction/EnggDiffFittingViewQtWidget.cpp new file mode 100644 index 0000000000000000000000000000000000000000..396f0e9435ded258725495b598a4a32b299273df --- /dev/null +++ b/MantidQt/CustomInterfaces/src/EnggDiffraction/EnggDiffFittingViewQtWidget.cpp @@ -0,0 +1,666 @@ +#include "MantidQtCustomInterfaces/EnggDiffraction/EnggDiffFittingViewQtWidget.h" +#include "MantidAPI/IPeakFunction.h" +#include "MantidAPI/FunctionFactory.h" +#include "MantidQtAPI/AlgorithmInputHistory.h" +#include "MantidQtCustomInterfaces/EnggDiffraction/EnggDiffFittingPresenter.h" +#include "MantidQtMantidWidgets/PeakPicker.h" + +#include <array> +#include <fstream> +#include <iomanip> +#include <random> +#include <sstream> + +#include <boost/algorithm/string.hpp> + +#include <Poco/Path.h> + +#include <QFileDialog> +#include <QSettings> + +#include <qwt_plot_curve.h> +#include <qwt_plot_zoomer.h> +#include <qwt_symbol.h> + +using namespace Mantid::API; +using namespace MantidQt::CustomInterfaces; + +namespace MantidQt { +namespace CustomInterfaces { + +const std::string EnggDiffFittingViewQtWidget::g_settingsGroup = + "CustomInterfaces/EnggDiffraction/FittingView"; + +const std::string EnggDiffFittingViewQtWidget::g_peaksListExt = + "Peaks list File: CSV " + "(*.csv *.txt);;" + "Other extensions/all files (*.*)"; + +bool EnggDiffFittingViewQtWidget::m_fittingMutliRunMode = false; +std::vector<std::string> EnggDiffFittingViewQtWidget::m_fitting_runno_dir_vec; + +EnggDiffFittingViewQtWidget::EnggDiffFittingViewQtWidget( + QWidget * /*parent*/, boost::shared_ptr<IEnggDiffractionUserMsg> mainMsg, + boost::shared_ptr<IEnggDiffractionSettings> mainSettings, + boost::shared_ptr<IEnggDiffractionCalibration> mainCalib, + boost::shared_ptr<IEnggDiffractionPythonRunner> mainPythonRunner) + : IEnggDiffFittingView(), m_fittedDataVector(), m_mainMsgProvider(mainMsg), + m_mainSettings(mainSettings), m_mainPythonRunner(mainPythonRunner), + m_presenter(nullptr) { + + initLayout(); + + m_presenter.reset(new EnggDiffFittingPresenter(this, mainCalib)); + m_presenter->notify(IEnggDiffFittingPresenter::Start); +} + +EnggDiffFittingViewQtWidget::~EnggDiffFittingViewQtWidget() { + m_presenter->notify(IEnggDiffFittingPresenter::ShutDown); + + for (auto curves : m_focusedDataVector) { + curves->detach(); + delete curves; + } + + for (auto curves : m_fittedDataVector) { + curves->detach(); + delete curves; + } +} + +void EnggDiffFittingViewQtWidget::initLayout() { + m_ui.setupUi(this); + + readSettings(); + doSetup(); +} + +void EnggDiffFittingViewQtWidget::doSetup() { + connect(m_ui.pushButton_fitting_browse_run_num, SIGNAL(released()), this, + SLOT(browseFitFocusedRun())); + + connect(m_ui.lineEdit_pushButton_run_num, SIGNAL(textEdited(const QString &)), + this, SLOT(resetFittingMultiMode())); + + connect(m_ui.lineEdit_pushButton_run_num, SIGNAL(editingFinished()), this, + SLOT(FittingRunNo())); + + connect(m_ui.lineEdit_pushButton_run_num, SIGNAL(returnPressed()), this, + SLOT(FittingRunNo())); + + connect(this, SIGNAL(getBanks()), this, SLOT(FittingRunNo())); + + connect(this, SIGNAL(setBank()), this, SLOT(listViewFittingRun())); + + connect(m_ui.listWidget_fitting_run_num, SIGNAL(itemSelectionChanged()), this, + SLOT(listViewFittingRun())); + + connect(m_ui.comboBox_bank, SIGNAL(currentIndexChanged(int)), this, + SLOT(setBankDir(int))); + + connect(m_ui.pushButton_fitting_browse_peaks, SIGNAL(released()), this, + SLOT(browsePeaksToFit())); + + connect(m_ui.pushButton_fit, SIGNAL(released()), this, SLOT(fitClicked())); + + // add peak by clicking the button + connect(m_ui.pushButton_select_peak, SIGNAL(released()), SLOT(setPeakPick())); + + connect(m_ui.pushButton_add_peak, SIGNAL(released()), SLOT(addPeakToList())); + + connect(m_ui.pushButton_save_peak_list, SIGNAL(released()), + SLOT(savePeakList())); + + connect(m_ui.pushButton_clear_peak_list, SIGNAL(released()), + SLOT(clearPeakList())); + + connect(m_ui.pushButton_plot_separate_window, SIGNAL(released()), + SLOT(plotSeparateWindow())); + + m_ui.dataPlot->setCanvasBackground(Qt::white); + m_ui.dataPlot->setAxisTitle(QwtPlot::xBottom, "d-Spacing (A)"); + m_ui.dataPlot->setAxisTitle(QwtPlot::yLeft, "Counts (us)^-1"); + QFont font("MS Shell Dlg 2", 8); + m_ui.dataPlot->setAxisFont(QwtPlot::xBottom, font); + m_ui.dataPlot->setAxisFont(QwtPlot::yLeft, font); + + // constructor of the peakPicker + // XXX: Being a QwtPlotItem, should get deleted when m_ui.plot gets deleted + // (auto-delete option) + m_peakPicker = new MantidWidgets::PeakPicker(m_ui.dataPlot, Qt::red); + setPeakPickerEnabled(false); + + m_zoomTool = + new QwtPlotZoomer(QwtPlot::xBottom, QwtPlot::yLeft, + QwtPicker::DragSelection | QwtPicker::CornerToCorner, + QwtPicker::AlwaysOff, m_ui.dataPlot->canvas()); + m_zoomTool->setRubberBandPen(QPen(Qt::black)); + setZoomTool(false); +} + +void EnggDiffFittingViewQtWidget::readSettings() { + QSettings qs; + qs.beginGroup(QString::fromStdString(g_settingsGroup)); + + // user params + m_ui.lineEdit_pushButton_run_num->setText( + qs.value("user-params-fitting-focused-file", "").toString()); + m_ui.comboBox_bank->setCurrentIndex(0); + m_ui.lineEdit_fitting_peaks->setText( + qs.value("user-params-fitting-peaks-to-fit", "").toString()); + + qs.endGroup(); +} + +void EnggDiffFittingViewQtWidget::saveSettings() const { + QSettings qs; + qs.beginGroup(QString::fromStdString(g_settingsGroup)); + + qs.setValue("user-params-fitting-focused-file", + m_ui.lineEdit_pushButton_run_num->text()); + qs.setValue("user-params-fitting-peaks-to-fit", + m_ui.lineEdit_fitting_peaks->text()); + + qs.endGroup(); +} + +void EnggDiffFittingViewQtWidget::enable(bool enable) { + m_ui.pushButton_fitting_browse_run_num->setEnabled(enable); + m_ui.lineEdit_pushButton_run_num->setEnabled(enable); + m_ui.pushButton_fitting_browse_peaks->setEnabled(enable); + m_ui.lineEdit_fitting_peaks->setEnabled(enable); + m_ui.pushButton_fit->setEnabled(enable); + m_ui.pushButton_clear_peak_list->setEnabled(enable); + m_ui.pushButton_save_peak_list->setEnabled(enable); + m_ui.comboBox_bank->setEnabled(enable); + m_ui.groupBox_fititng_preview->setEnabled(enable); +} + +void EnggDiffFittingViewQtWidget::showStatus(const std::string &sts) { + m_mainMsgProvider->showStatus(sts); +} + +void EnggDiffFittingViewQtWidget::userWarning(const std::string &err, + const std::string &description) { + m_mainMsgProvider->userWarning(err, description); +} + +void EnggDiffFittingViewQtWidget::userError(const std::string &err, + const std::string &description) { + m_mainMsgProvider->userError(err, description); +} + +void EnggDiffFittingViewQtWidget::enableCalibrateFocusFitUserActions( + bool enable) { + m_mainMsgProvider->enableCalibrateFocusFitUserActions(enable); +} + +EnggDiffCalibSettings +EnggDiffFittingViewQtWidget::currentCalibSettings() const { + return m_mainSettings->currentCalibSettings(); +} + +std::string EnggDiffFittingViewQtWidget::focusingDir() const { + return m_mainSettings->focusingDir(); +} + +std::string +EnggDiffFittingViewQtWidget::enggRunPythonCode(const std::string &pyCode) { + return m_mainPythonRunner->enggRunPythonCode(pyCode); +} + +void EnggDiffFittingViewQtWidget::fitClicked() { + m_presenter->notify(IEnggDiffFittingPresenter::FitPeaks); +} + +void EnggDiffFittingViewQtWidget::FittingRunNo() { + m_presenter->notify(IEnggDiffFittingPresenter::FittingRunNo); +} + +void EnggDiffFittingViewQtWidget::setBankDir(int idx) { + + if (m_fitting_runno_dir_vec.size() >= size_t(idx)) { + + std::string bankDir = m_fitting_runno_dir_vec[idx]; + Poco::Path fpath(bankDir); + + setFittingRunNo(bankDir); + } +} + +void EnggDiffFittingViewQtWidget::listViewFittingRun() { + + if (m_fittingMutliRunMode) { + auto listView = m_ui.listWidget_fitting_run_num; + auto currentRow = listView->currentRow(); + auto item = listView->item(currentRow); + QString itemText = item->text(); + + setFittingRunNo(itemText.toStdString()); + FittingRunNo(); + } +} + +void EnggDiffFittingViewQtWidget::resetFittingMultiMode() { + // resets the global variable so the list view widgets + // adds the run number to for single runs too + m_fittingMutliRunMode = false; +} + +std::string EnggDiffFittingViewQtWidget::fittingRunNoFactory( + std::string bank, std::string fileName, std::string &bankDir, + std::string fileDir) { + + std::string genDir = fileName.substr(0, fileName.size() - 1); + Poco::Path bankFile(genDir + bank + ".nxs"); + if (bankFile.isFile()) { + bankDir = fileDir + genDir + bank + ".nxs"; + } + return bankDir; +} + +std::string EnggDiffFittingViewQtWidget::readPeaksFile(std::string fileDir) { + std::string fileData = ""; + std::string line; + std::string comma = ", "; + + std::ifstream peakFile(fileDir); + + if (peakFile.is_open()) { + while (std::getline(peakFile, line)) { + fileData += line; + if (!peakFile.eof()) + fileData += comma; + } + peakFile.close(); + } + + else + fileData = ""; + + return fileData; +} + +void EnggDiffFittingViewQtWidget::setDataVector( + std::vector<boost::shared_ptr<QwtData>> &data, bool focused, + bool plotSinglePeaks) { + + if (!plotSinglePeaks) { + // clear vector and detach curves to avoid plot crash + // when only plotting focused workspace + for (auto curves : m_fittedDataVector) { + if (curves) { + curves->detach(); + delete curves; + } + } + + if (m_fittedDataVector.size() > 0) + m_fittedDataVector.clear(); + + // set it as false as there will be no valid workspace to plot + m_ui.pushButton_plot_separate_window->setEnabled(false); + } + + if (focused) { + dataCurvesFactory(data, m_focusedDataVector, focused); + } else { + dataCurvesFactory(data, m_fittedDataVector, focused); + } +} + +void EnggDiffFittingViewQtWidget::dataCurvesFactory( + std::vector<boost::shared_ptr<QwtData>> &data, + std::vector<QwtPlotCurve *> &dataVector, bool focused) { + + // clear vector + for (auto curves : dataVector) { + if (curves) { + curves->detach(); + delete curves; + } + } + + if (dataVector.size() > 0) + dataVector.clear(); + resetView(); + + // dark colours could be removed so that the coloured peaks stand out more + const std::array<QColor, 16> QPenList{ + {Qt::white, Qt::red, Qt::darkRed, Qt::green, Qt::darkGreen, Qt::blue, + Qt::darkBlue, Qt::cyan, Qt::darkCyan, Qt::magenta, Qt::darkMagenta, + Qt::yellow, Qt::darkYellow, Qt::gray, Qt::lightGray, Qt::black}}; + + std::mt19937 gen; + std::uniform_int_distribution<std::size_t> dis(0, QPenList.size() - 1); + + for (size_t i = 0; i < data.size(); i++) { + auto *peak = data[i].get(); + + QwtPlotCurve *dataCurve = new QwtPlotCurve(); + if (!focused) { + dataCurve->setStyle(QwtPlotCurve::Lines); + auto randIndex = dis(gen); + dataCurve->setPen(QPen(QPenList[randIndex], 2)); + + // only set enabled when single peak workspace plotted + m_ui.pushButton_plot_separate_window->setEnabled(true); + } else { + dataCurve->setStyle(QwtPlotCurve::NoCurve); + // focused workspace in bg set as darkGrey crosses insted of line + dataCurve->setSymbol(QwtSymbol(QwtSymbol::XCross, QBrush(), + QPen(Qt::darkGray, 1), QSize(3, 3))); + } + dataCurve->setRenderHint(QwtPlotItem::RenderAntialiased, true); + + dataVector.push_back(dataCurve); + + dataVector[i]->setData(*peak); + dataVector[i]->attach(m_ui.dataPlot); + } + + m_ui.dataPlot->replot(); + m_zoomTool->setZoomBase(); + // enable zoom & select peak btn after the plotting on graph + setZoomTool(true); + m_ui.pushButton_select_peak->setEnabled(true); + data.clear(); +} + +void EnggDiffFittingViewQtWidget::setPeakPickerEnabled(bool enabled) { + m_peakPicker->setEnabled(enabled); + m_peakPicker->setVisible(enabled); + m_ui.dataPlot->replot(); // PeakPicker might get hidden/shown + m_ui.pushButton_add_peak->setEnabled(enabled); + if (enabled) { + QString btnText = "Reset Peak Selector"; + m_ui.pushButton_select_peak->setText(btnText); + } +} + +void EnggDiffFittingViewQtWidget::setPeakPicker( + const IPeakFunction_const_sptr &peak) { + m_peakPicker->setPeak(peak); + m_ui.dataPlot->replot(); +} + +double EnggDiffFittingViewQtWidget::getPeakCentre() const { + auto peak = m_peakPicker->peak(); + auto centre = peak->centre(); + return centre; +} + +void EnggDiffFittingViewQtWidget::fittingWriteFile(const std::string &fileDir) { + std::ofstream outfile(fileDir.c_str()); + if (!outfile) { + userWarning("File not found", + "File " + fileDir + " , could not be found. Please try again!"); + } else { + auto expPeaks = m_ui.lineEdit_fitting_peaks->text(); + outfile << expPeaks.toStdString(); + } +} + +void EnggDiffFittingViewQtWidget::setZoomTool(bool enabled) { + m_zoomTool->setEnabled(enabled); +} + +void EnggDiffFittingViewQtWidget::resetView() { + // Resets the view to a sensible default + // Auto scale the axis + m_ui.dataPlot->setAxisAutoScale(QwtPlot::xBottom); + m_ui.dataPlot->setAxisAutoScale(QwtPlot::yLeft); + + // Set this as the default zoom level + m_zoomTool->setZoomBase(true); +} + +void EnggDiffFittingViewQtWidget::browsePeaksToFit() { + + // TODO: the logic, checks and decision on what message to show should be + // moved to the presenter + + try { + QString prevPath = QString::fromStdString(focusingDir()); + if (prevPath.isEmpty()) { + prevPath = MantidQt::API::AlgorithmInputHistory::Instance() + .getPreviousDirectory(); + } + + QString path( + QFileDialog::getOpenFileName(this, tr("Open Peaks To Fit"), prevPath, + QString::fromStdString(g_peaksListExt))); + + if (path.isEmpty()) { + return; + } + + MantidQt::API::AlgorithmInputHistory::Instance().setPreviousDirectory(path); + + std::string peaksData = readPeaksFile(path.toStdString()); + + m_ui.lineEdit_fitting_peaks->setText(QString::fromStdString(peaksData)); + } catch (...) { + userWarning("Unable to import the peaks from a file: ", + "File corrupted or could not be opened. Please try again"); + return; + } +} + +void EnggDiffFittingViewQtWidget::browseFitFocusedRun() { + resetFittingMultiMode(); + QString prevPath = QString::fromStdString(focusingDir()); + if (prevPath.isEmpty()) { + prevPath = + MantidQt::API::AlgorithmInputHistory::Instance().getPreviousDirectory(); + } + std::string nexusFormat = "Nexus file with calibration table: NXS, NEXUS" + "(*.nxs *.nexus);;"; + + QString path( + QFileDialog::getOpenFileName(this, tr("Open Focused File "), prevPath, + QString::fromStdString(nexusFormat))); + + if (path.isEmpty()) { + return; + } + + MantidQt::API::AlgorithmInputHistory::Instance().setPreviousDirectory(path); + setFittingRunNo(path.toStdString()); + getBanks(); +} + +void EnggDiffFittingViewQtWidget::setFittingRunNo(const std::string &path) { + m_ui.lineEdit_pushButton_run_num->setText(QString::fromStdString(path)); +} + +std::string EnggDiffFittingViewQtWidget::getFittingRunNo() const { + return m_ui.lineEdit_pushButton_run_num->text().toStdString(); +} + +void EnggDiffFittingViewQtWidget::clearFittingComboBox() const { + m_ui.comboBox_bank->clear(); +} + +void EnggDiffFittingViewQtWidget::enableFittingComboBox(bool enable) const { + m_ui.comboBox_bank->setEnabled(enable); +} + +void EnggDiffFittingViewQtWidget::clearFittingListWidget() const { + m_ui.listWidget_fitting_run_num->clear(); +} + +void EnggDiffFittingViewQtWidget::enableFittingListWidget(bool enable) const { + m_ui.listWidget_fitting_run_num->setEnabled(enable); +} + +int EnggDiffFittingViewQtWidget::getFittingListWidgetCurrentRow() const { + return m_ui.listWidget_fitting_run_num->currentRow(); +} + +void EnggDiffFittingViewQtWidget::setFittingListWidgetCurrentRow( + int idx) const { + m_ui.listWidget_fitting_run_num->setCurrentRow(idx); +} + +int EnggDiffFittingViewQtWidget::getFittingComboIdx(std::string bank) const { + return m_ui.comboBox_bank->findText(QString::fromStdString(bank)); +} + +void EnggDiffFittingViewQtWidget::plotSeparateWindow() { + std::string pyCode = + + "fitting_single_peaks_twin_ws = \"__engggui_fitting_single_peaks_twin\"\n" + "if (mtd.doesExist(fitting_single_peaks_twin_ws)):\n" + " DeleteWorkspace(fitting_single_peaks_twin_ws)\n" + + "single_peak_ws = CloneWorkspace(InputWorkspace = " + "\"engggui_fitting_single_peaks\", OutputWorkspace = " + "fitting_single_peaks_twin_ws)\n" + "tot_spec = single_peak_ws.getNumberHistograms()\n" + + "spec_list = []\n" + "for i in range(0, tot_spec):\n" + " spec_list.append(i)\n" + + "fitting_plot = plotSpectrum(single_peak_ws, spec_list).activeLayer()\n" + "fitting_plot.setTitle(\"Engg GUI Single Peaks Fitting Workspace\")\n"; + + std::string status = m_mainPythonRunner->enggRunPythonCode(pyCode); + m_logMsgs.emplace_back("Plotted output focused data, with status string " + + status); + m_presenter->notify(IEnggDiffFittingPresenter::LogMsg); +} + +std::string EnggDiffFittingViewQtWidget::fittingPeaksData() const { + + return m_ui.lineEdit_fitting_peaks->text().toStdString(); +} + +void EnggDiffFittingViewQtWidget::setPeakList( + const std::string &peakList) const { + m_ui.lineEdit_fitting_peaks->setText(QString::fromStdString(peakList)); +} + +std::vector<std::string> +EnggDiffFittingViewQtWidget::splitFittingDirectory(std::string &selectedfPath) { + + Poco::Path PocofPath(selectedfPath); + std::string selectedbankfName = PocofPath.getBaseName(); + std::vector<std::string> splitBaseName; + if (selectedbankfName.find("ENGINX_") != std::string::npos) { + boost::split(splitBaseName, selectedbankfName, boost::is_any_of("_.")); + } + return splitBaseName; +} + +void EnggDiffFittingViewQtWidget::setBankEmit() { emit setBank(); } + +void EnggDiffFittingViewQtWidget::setBankIdComboBox(int idx) { + QComboBox *bankName = m_ui.comboBox_bank; + bankName->setCurrentIndex(idx); +} + +void EnggDiffFittingViewQtWidget::addBankItem(std::string bankID) { + + m_ui.comboBox_bank->addItem(QString::fromStdString(bankID)); +} + +void EnggDiffFittingViewQtWidget::addRunNoItem(std::string runNo) { + m_ui.listWidget_fitting_run_num->addItem(QString::fromStdString(runNo)); +} + +std::vector<std::string> EnggDiffFittingViewQtWidget::getFittingRunNumVec() { + return m_fitting_runno_dir_vec; +} + +void EnggDiffFittingViewQtWidget::setFittingRunNumVec( + std::vector<std::string> assignVec) { + m_fitting_runno_dir_vec.clear(); + m_fitting_runno_dir_vec = assignVec; +} + +void EnggDiffFittingViewQtWidget::setFittingMultiRunMode(bool mode) { + m_fittingMutliRunMode = mode; +} + +bool EnggDiffFittingViewQtWidget::getFittingMultiRunMode() { + return m_fittingMutliRunMode; +} + +void EnggDiffFittingViewQtWidget::setPeakPick() { + auto bk2bk = + FunctionFactory::Instance().createFunction("BackToBackExponential"); + auto bk2bkFunc = boost::dynamic_pointer_cast<IPeakFunction>(bk2bk); + // set the peak to BackToBackExponential function + setPeakPicker(bk2bkFunc); + setPeakPickerEnabled(true); +} + +void EnggDiffFittingViewQtWidget::addPeakToList() { + + if (m_peakPicker->isEnabled()) { + auto peakCentre = getPeakCentre(); + + std::stringstream stream; + stream << std::fixed << std::setprecision(4) << peakCentre; + auto strPeakCentre = stream.str(); + + auto curExpPeaksList = m_ui.lineEdit_fitting_peaks->text(); + QString comma = ","; + + if (!curExpPeaksList.isEmpty()) { + // when further peak added to list + std::string expPeakStr = curExpPeaksList.toStdString(); + std::string lastTwoChr = expPeakStr.substr(expPeakStr.size() - 2); + auto lastChr = expPeakStr.back(); + if (lastChr == ',' || lastTwoChr == ", ") { + curExpPeaksList.append(QString::fromStdString(strPeakCentre)); + } else { + curExpPeaksList.append(comma + QString::fromStdString(strPeakCentre)); + } + m_ui.lineEdit_fitting_peaks->setText(curExpPeaksList); + } else { + // when new peak given when list is empty + curExpPeaksList.append(QString::fromStdString(strPeakCentre)); + curExpPeaksList.append(comma); + m_ui.lineEdit_fitting_peaks->setText(curExpPeaksList); + } + } +} + +void EnggDiffFittingViewQtWidget::savePeakList() { + // call function in EnggPresenter.. + + // TODO: the logic, checks and decision on what message to show should be + // moved to the presenter + + try { + QString prevPath = QString::fromStdString(focusingDir()); + if (prevPath.isEmpty()) { + prevPath = MantidQt::API::AlgorithmInputHistory::Instance() + .getPreviousDirectory(); + } + + QString path(QFileDialog::getSaveFileName( + this, tr("Save Expected Peaks List"), prevPath, + QString::fromStdString(g_peaksListExt))); + + if (path.isEmpty()) { + return; + } + const std::string strPath = path.toStdString(); + fittingWriteFile(strPath); + } catch (...) { + userWarning("Unable to save the peaks file: ", + "Invalid file path or or could not be saved. Please try again"); + return; + } +} + +void EnggDiffFittingViewQtWidget::clearPeakList() { + m_ui.lineEdit_fitting_peaks->clear(); +} + +} // namespace CustomInterfaces +} // namespace MantidQt diff --git a/MantidQt/CustomInterfaces/src/EnggDiffraction/EnggDiffractionPresenter.cpp b/MantidQt/CustomInterfaces/src/EnggDiffraction/EnggDiffractionPresenter.cpp index b6f8c78ff6d3c56afe79ddd918d549643db7dac3..18e9d1e52e7214993e8e7598533b7214a54c94c9 100644 --- a/MantidQt/CustomInterfaces/src/EnggDiffraction/EnggDiffractionPresenter.cpp +++ b/MantidQt/CustomInterfaces/src/EnggDiffraction/EnggDiffractionPresenter.cpp @@ -1,24 +1,22 @@ +#include "MantidAPI/AlgorithmManager.h" #include "MantidAPI/ITableWorkspace.h" #include "MantidAPI/MatrixWorkspace.h" #include "MantidAPI/TableRow.h" -#include "MantidAPI/WorkspaceFactory.h" #include "MantidKernel/Property.h" +#include "MantidKernel/StringTokenizer.h" #include "MantidQtAPI/PythonRunner.h" -#include <MantidKernel/StringTokenizer.h> // #include "MantidQtCustomInterfaces/EnggDiffraction/EnggDiffractionModel.h" #include "MantidQtCustomInterfaces/EnggDiffraction/EnggDiffractionPresWorker.h" #include "MantidQtCustomInterfaces/EnggDiffraction/EnggDiffractionPresenter.h" #include "MantidQtCustomInterfaces/EnggDiffraction/IEnggDiffractionView.h" -#include "MantidQtCustomInterfaces/Muon/ALCHelper.h" #include <fstream> #include <boost/lexical_cast.hpp> -#include "Poco/DirectoryIterator.h" #include <Poco/File.h> +#include <Poco/Path.h> -#include <MantidAPI/AlgorithmManager.h> #include <QThread> using namespace Mantid::API; @@ -27,21 +25,6 @@ using namespace MantidQt::CustomInterfaces; namespace MantidQt { namespace CustomInterfaces { -/** - * Parameters from a GSAS calibration. They define a conversion of - * units time-of-flight<->d-spacing that can be calculated with the - * algorithm AlignDetectors for example. - */ -struct GSASCalibrationParms { - GSASCalibrationParms(size_t bid, double dc, double da, double tz) - : bankid(bid), difc(dc), difa(da), tzero(tz) {} - - size_t bankid{0}; - double difc{0}; - double difa{0}; - double tzero{0}; -}; - namespace { Mantid::Kernel::Logger g_log("EngineeringDiffractionGUI"); } @@ -70,13 +53,9 @@ const std::string EnggDiffractionPresenter::g_vanIntegrationWSName = const std::string EnggDiffractionPresenter::g_vanCurvesWSName = "engggui_vanadium_curves_ws"; -const std::string EnggDiffractionPresenter::g_focusedFittingWSName = - "engggui_fitting_focused_ws"; - const std::string EnggDiffractionPresenter::g_calibBanksParms = "engggui_calibration_banks_parameters"; -bool EnggDiffractionPresenter::g_useAlignDetectors = true; int EnggDiffractionPresenter::g_croppedCounter = 0; int EnggDiffractionPresenter::g_plottingCounter = 0; bool EnggDiffractionPresenter::g_abortThread = false; @@ -85,8 +64,8 @@ std::string EnggDiffractionPresenter::g_calibCropIdentifier = "SpectrumNumbers"; std::string EnggDiffractionPresenter::g_sumOfFilesFocus = ""; EnggDiffractionPresenter::EnggDiffractionPresenter(IEnggDiffractionView *view) - : m_workerThread(NULL), m_calibFinishedOK(false), m_focusFinishedOK(false), - m_rebinningFinishedOK(false), m_fittingFinishedOK(false), + : m_workerThread(nullptr), m_calibFinishedOK(false), + m_focusFinishedOK(false), m_rebinningFinishedOK(false), m_view(view) /*, m_model(new EnggDiffractionModel()), */ { if (!m_view) { throw std::runtime_error( @@ -113,7 +92,7 @@ void EnggDiffractionPresenter::cleanup() { m_workerThread->wait(10); } delete m_workerThread; - m_workerThread = NULL; + m_workerThread = nullptr; } } @@ -162,15 +141,6 @@ void EnggDiffractionPresenter::notify( processRebinMultiperiod(); break; - case IEnggDiffractionPresenter::FittingRunNo: - fittingRunNoChanged(); - break; - - case IEnggDiffractionPresenter::FitPeaks: - processFitPeaks(); - - break; - case IEnggDiffractionPresenter::LogMsg: processLogMsg(); break; @@ -349,7 +319,7 @@ void EnggDiffractionPresenter::processCalcCalib() { const std::string outFilename = outputCalibFilename(vanNo, ceriaNo); m_view->showStatus("Calculating calibration..."); - m_view->enableCalibrateAndFocusActions(false); + m_view->enableCalibrateFocusFitUserActions(false); // alternatively, this would be GUI-blocking: // doNewCalibration(outFilename, vanNo, ceriaNo, specNos); // calibrationFinished() @@ -397,7 +367,7 @@ void EnggDiffractionPresenter::ProcessCropCalib() { } m_view->showStatus("Calculating cropped calibration..."); - m_view->enableCalibrateAndFocusActions(false); + m_view->enableCalibrateFocusFitUserActions(false); // alternatively, this would be GUI-blocking: // doNewCalibration(outFilename, vanNo, ceriaNo, specNo/bankName); // calibrationFinished() @@ -547,7 +517,7 @@ void EnggDiffractionPresenter::startFocusing( const std::string focusDir = m_view->focusingDir(); m_view->showStatus("Focusing..."); - m_view->enableCalibrateAndFocusActions(false); + m_view->enableCalibrateFocusFitUserActions(false); // GUI-blocking alternative: // doFocusRun(focusDir, outFilenames, runNo, banks, specNos, dgFile) // focusingFinished() @@ -576,7 +546,7 @@ void EnggDiffractionPresenter::processRebinTime() { "may take some seconds... \n"; m_view->showStatus("Rebinning by time..."); - m_view->enableCalibrateAndFocusActions(false); + m_view->enableCalibrateFocusFitUserActions(false); // GUI-blocking alternative: // doRebinningTime(runNo, bin, outWSName) // rebinningFinished() @@ -603,1030 +573,13 @@ void EnggDiffractionPresenter::processRebinMultiperiod() { "may take some seconds... \n"; m_view->showStatus("Rebinning by pulses..."); - m_view->enableCalibrateAndFocusActions(false); + m_view->enableCalibrateFocusFitUserActions(false); // GUI-blocking alternative: // doRebinningPulses(runNo, nperiods, timeStep, outWSName) // rebinningFinished() startAsyncRebinningPulsesWorker(runNo, nperiods, timeStep, outWSName); } -// Fitting Tab Run Number & Bank handling here -void MantidQt::CustomInterfaces::EnggDiffractionPresenter:: - fittingRunNoChanged() { - - try { - std::string strFocusedFile = m_view->getFittingRunNo(); - QString focusedFile = QString::fromStdString(strFocusedFile); - // file name - Poco::Path selectedfPath(strFocusedFile); - Poco::Path bankDir; - - // handling of vectors - auto runnoDirVector = m_view->getFittingRunNumVec(); - runnoDirVector.clear(); - - std::string strFPath = selectedfPath.toString(); - // returns empty if no directory is found - std::vector<std::string> splitBaseName = - m_view->splitFittingDirectory(strFPath); - // runNo when single focused file selected - std::vector<std::string> runNoVec; - - if (selectedfPath.isFile() && !splitBaseName.empty()) { - -#ifdef __unix__ - bankDir = selectedfPath.parent(); -#else - bankDir = (bankDir).expand(selectedfPath.parent().toString()); -#endif - if (!splitBaseName.empty() && splitBaseName.size() > 3) { - std::string foc_file = splitBaseName[0] + "_" + splitBaseName[1] + "_" + - splitBaseName[2] + "_" + splitBaseName[3]; - std::string strBankDir = bankDir.toString(); - - if (strBankDir.empty()) { - m_view->userWarning( - "Invalid Input", - "Please check that a valid directory is " - "set for Output Folder under Focusing Settings on the " - "settings tab. " - "Please try again"); - } else { - - updateFittingDirVec(strBankDir, foc_file, false, runnoDirVector); - m_view->setFittingRunNumVec(runnoDirVector); - - // add bank to the combo-box and list view - setBankItems(); - setDefaultBank(splitBaseName, focusedFile); - runNoVec.clear(); - runNoVec.push_back(splitBaseName[1]); - auto fittingMultiRunMode = m_view->getFittingMultiRunMode(); - if (!fittingMultiRunMode) - setRunNoItems(runNoVec, false); - } - } - // assuming that no directory is found so look for number - // if run number length greater - } else if (focusedFile.count() > 4) { - if (strFocusedFile.find("-") != std::string::npos) { - std::vector<std::string> firstLastRunNoVec; - boost::split(firstLastRunNoVec, strFocusedFile, boost::is_any_of("-")); - std::string firstRun; - std::string lastRun; - if (!firstLastRunNoVec.empty()) { - firstRun = firstLastRunNoVec[0]; - lastRun = firstLastRunNoVec[1]; - - m_view->setFittingMultiRunMode(true); - enableMultiRun(firstRun, lastRun, runnoDirVector); - } - - } else { - // if given a single run number instead - auto focusDir = m_view->getFocusDir(); - - if (focusDir.empty()) { - m_view->userWarning( - "Invalid Input", - "Please check that a valid directory is " - "set for Output Folder under Focusing Settings on the " - "settings tab. " - "Please try again"); - } else { - - updateFittingDirVec(focusDir, strFocusedFile, false, runnoDirVector); - m_view->setFittingRunNumVec(runnoDirVector); - - // add bank to the combo-box and list view - setBankItems(); - setDefaultBank(splitBaseName, focusedFile); - runNoVec.clear(); - runNoVec.push_back(strFocusedFile); - - auto fittingMultiRunMode = m_view->getFittingMultiRunMode(); - if (!fittingMultiRunMode) - setRunNoItems(runNoVec, false); - } - } - } - // set the directory here to the first in the vector if its not empty - if (!runnoDirVector.empty() && !selectedfPath.isFile()) { - QString firstDir = QString::fromStdString(runnoDirVector[0]); - m_view->setFittingRunNo(firstDir); - - } else if (m_view->getFittingRunNo().empty()) { - m_view->userWarning("Invalid Input", - "Invalid directory or run number given. " - "Please try again"); - } - - } catch (std::runtime_error &re) { - m_view->userWarning("Invalid file", - "Unable to select the file; " + - static_cast<std::string>(re.what())); - return; - } -} - -void EnggDiffractionPresenter::updateFittingDirVec( - const std::string &bankDir, const std::string &focusedFile, bool multi_run, - std::vector<std::string> &fittingRunNoDirVec) { - - try { - std::string cwd(bankDir); - Poco::DirectoryIterator it(cwd); - Poco::DirectoryIterator end; - while (it != end) { - if (it->isFile()) { - std::string itFilePath = it->path(); - Poco::Path itBankfPath(itFilePath); - - std::string itbankFileName = itBankfPath.getBaseName(); - // check if it not any other file.. e.g: texture - if (itbankFileName.find(focusedFile) != std::string::npos) { - fittingRunNoDirVec.push_back(itFilePath); - if (multi_run) - return; - } - } - ++it; - } - } catch (std::runtime_error &re) { - m_view->userWarning("Invalid file", - "File not found in the following directory; " + - bankDir + ". " + - static_cast<std::string>(re.what())); - } -} - -void EnggDiffractionPresenter::enableMultiRun( - std::string firstRun, std::string lastRun, - std::vector<std::string> &fittingRunNoDirVec) { - - bool firstDig = isDigit(firstRun); - bool lastDig = isDigit(lastRun); - - std::vector<std::string> RunNumberVec; - if (firstDig && lastDig) { - int firstNum = std::stoi(firstRun); - int lastNum = std::stoi(lastRun); - - if ((lastNum - firstNum) > 200) { - m_view->userWarning( - "Please try again", - "The specified run number range is " - "far to big, please try a smaller range of consecutive run numbers."); - } - - else if (firstNum <= lastNum) { - - for (int i = firstNum; i <= lastNum; i++) { - RunNumberVec.push_back(std::to_string(i)); - } - - auto focusDir = m_view->getFocusDir(); - if (focusDir.empty()) { - m_view->userWarning( - "Invalid Input", - "Please check that a valid directory is " - "set for Output Folder under Focusing Settings on the " - "settings tab. " - "Please try again"); - } else { - // if given a single run number instead - for (size_t i = 0; i < RunNumberVec.size(); i++) { - updateFittingDirVec(focusDir, RunNumberVec[i], true, - fittingRunNoDirVec); - } - int diff = (lastNum - firstNum) + 1; - auto global_vec_size = fittingRunNoDirVec.size(); - if (size_t(diff) == global_vec_size) { - - setRunNoItems(RunNumberVec, true); - - m_view->setBankEmit(); - } - } - } else { - m_view->userWarning("Invalid Run Number", - "One or more run file not found " - "from the specified range of runs." - "Please try again"); - } - } else { - m_view->userWarning("Invalid Run Number", - "The specfied range of run number " - "entered is invalid. Please try again"); - } -} - -// Process Fitting Peaks begins here - -void EnggDiffractionPresenter::processFitPeaks() { - const std::string focusedRunNo = m_view->getFittingRunNo(); - std::string fittingPeaks = m_view->fittingPeaksData(); - - const std::string fitPeaksData = validateFittingexpectedPeaks(fittingPeaks); - - g_log.debug() << "the expected peaks are: " << fitPeaksData << '\n'; - - try { - inputChecksBeforeFitting(focusedRunNo, fitPeaksData); - } catch (std::invalid_argument &ia) { - m_view->userWarning("Error in the inputs required for fitting", ia.what()); - return; - } - - const std::string outWSName = "engggui_fitting_fit_peak_ws"; - g_log.notice() << "EnggDiffraction GUI: starting new " - "single peak fits into workspace '" + - outWSName + "'. This " - "may take some seconds... \n"; - - m_view->showStatus("Fitting single peaks..."); - // disable GUI to avoid any double threads - m_view->enableCalibrateAndFocusActions(false); - // startAsyncFittingWorker - // doFitting() - startAsyncFittingWorker(focusedRunNo, fitPeaksData); -} - -void EnggDiffractionPresenter::inputChecksBeforeFitting( - const std::string &focusedRunNo, const std::string &expectedPeaks) { - if (focusedRunNo.size() == 0) { - throw std::invalid_argument( - "Focused Run " - "cannot be empty and must be a valid directory"); - } - - Poco::File file(focusedRunNo); - if (!file.exists()) { - throw std::invalid_argument("The focused workspace file for single peak " - "fitting could not be found: " + - focusedRunNo); - } - - if (expectedPeaks.empty()) { - g_log.warning() << "Expected peaks were not passed, via fitting interface, " - "the default list of " - "expected peaks will be utilised instead.\n"; - } - bool contains_non_digits = - expectedPeaks.find_first_not_of("0123456789,. ") != std::string::npos; - if (contains_non_digits) { - throw std::invalid_argument("The expected peaks provided " + expectedPeaks + - " is invalid, " - "fitting process failed. Please try again!"); - } -} - -std::string EnggDiffractionPresenter::validateFittingexpectedPeaks( - std::string &expectedPeaks) const { - - if (!expectedPeaks.empty()) { - - g_log.debug() << "Validating the expected peak list.\n"; - - auto *comma = ","; - - for (size_t i = 0; i < expectedPeaks.size() - 1; i++) { - size_t j = i + 1; - - if (expectedPeaks[i] == *comma && expectedPeaks[i] == expectedPeaks[j]) { - expectedPeaks.erase(j, 1); - i--; - - } else { - ++j; - } - } - - size_t strLength = expectedPeaks.length() - 1; - if (expectedPeaks.at(size_t(0)) == ',') { - expectedPeaks.erase(size_t(0), 1); - strLength -= size_t(1); - } - - if (expectedPeaks.at(strLength) == ',') { - expectedPeaks.erase(strLength, 1); - } - - m_view->setPeakList(expectedPeaks); - } - - return expectedPeaks; -} - -void EnggDiffractionPresenter::startAsyncFittingWorker( - const std::string &focusedRunNo, const std::string &expectedPeaks) { - - delete m_workerThread; - m_workerThread = new QThread(this); - EnggDiffWorker *worker = - new EnggDiffWorker(this, focusedRunNo, expectedPeaks); - worker->moveToThread(m_workerThread); - - connect(m_workerThread, SIGNAL(started()), worker, SLOT(fitting())); - connect(worker, SIGNAL(finished()), this, SLOT(fittingFinished())); - // early delete of thread and worker - connect(m_workerThread, SIGNAL(finished()), m_workerThread, - SLOT(deleteLater()), Qt::DirectConnection); - connect(worker, SIGNAL(finished()), worker, SLOT(deleteLater())); - m_workerThread->start(); -} - -void EnggDiffractionPresenter::setDifcTzero(MatrixWorkspace_sptr wks) const { - size_t bankID = 1; - // attempt to guess bankID - this should be done in code that is currently - // in the view - auto fittingFilename = m_view->getFittingRunNo(); - Poco::File fittingFile(fittingFilename); - if (fittingFile.exists()) { - Poco::Path path(fittingFile.path()); - auto name = path.getBaseName(); - std::vector<std::string> chunks; - boost::split(chunks, name, boost::is_any_of("_")); - if (!chunks.empty()) { - try { - bankID = boost::lexical_cast<size_t>(chunks.back()); - } catch (std::runtime_error &) { - } - } - } - - const std::string units = "none"; - auto &run = wks->mutableRun(); - - if (m_currentCalibParms.empty()) { - run.addProperty<int>("bankid", 1, units, true); - run.addProperty<double>("difc", 18400.0, units, true); - run.addProperty<double>("difa", 0.0, units, true); - run.addProperty<double>("tzero", 4.0, units, true); - } else { - GSASCalibrationParms parms(0, 0.0, 0.0, 0.0); - for (const auto &p : m_currentCalibParms) { - if (p.bankid == bankID) { - parms = p; - break; - } - } - if (0 == parms.difc) - parms = m_currentCalibParms.front(); - - run.addProperty<int>("bankid", static_cast<int>(parms.bankid), units, true); - run.addProperty<double>("difc", parms.difc, units, true); - run.addProperty<double>("difa", parms.difa, units, true); - run.addProperty<double>("tzero", parms.tzero, units, true); - } -} - -void EnggDiffractionPresenter::doFitting(const std::string &focusedRunNo, - const std::string &expectedPeaks) { - g_log.notice() << "EnggDiffraction GUI: starting new fitting with file " - << focusedRunNo << ". This may take a few seconds... \n"; - - MatrixWorkspace_sptr focusedWS; - m_fittingFinishedOK = false; - - // load the focused workspace file to perform single peak fits - try { - auto load = - Mantid::API::AlgorithmManager::Instance().createUnmanaged("Load"); - load->initialize(); - load->setPropertyValue("Filename", focusedRunNo); - load->setPropertyValue("OutputWorkspace", g_focusedFittingWSName); - load->execute(); - - AnalysisDataServiceImpl &ADS = Mantid::API::AnalysisDataService::Instance(); - focusedWS = ADS.retrieveWS<MatrixWorkspace>(g_focusedFittingWSName); - } catch (std::runtime_error &re) { - g_log.error() - << "Error while loading focused data. " - "Could not run the algorithm Load succesfully for the Fit " - "peaks (file name: " + - focusedRunNo + "). Error description: " + re.what() + - " Please check also the previous log messages for details."; - return; - } - - setDifcTzero(focusedWS); - - // run the algorithm EnggFitPeaks with workspace loaded above - // requires unit in Time of Flight - auto enggFitPeaks = - Mantid::API::AlgorithmManager::Instance().createUnmanaged("EnggFitPeaks"); - const std::string focusedFitPeaksTableName = - "engggui_fitting_fitpeaks_params"; - - // delete existing table workspace to avoid confusion - AnalysisDataServiceImpl &ADS = Mantid::API::AnalysisDataService::Instance(); - if (ADS.doesExist(focusedFitPeaksTableName)) { - ADS.remove(focusedFitPeaksTableName); - } - - try { - enggFitPeaks->initialize(); - enggFitPeaks->setProperty("InputWorkspace", focusedWS); - if (!expectedPeaks.empty()) { - enggFitPeaks->setProperty("expectedPeaks", expectedPeaks); - } - enggFitPeaks->setProperty("FittedPeaks", focusedFitPeaksTableName); - enggFitPeaks->execute(); - } catch (std::exception &re) { - g_log.error() << "Could not run the algorithm EnggFitPeaks " - "successfully for bank, " - // bank name - "Error description: " + - static_cast<std::string>(re.what()) + - " Please check also the log message for detail.\n"; - } - - try { - runFittingAlgs(focusedFitPeaksTableName, g_focusedFittingWSName); - - } catch (std::invalid_argument &ia) { - g_log.error() << "Error, Fitting could not finish off correctly, " + - std::string(ia.what()) << '\n'; - return; - } -} - -void EnggDiffractionPresenter::runFittingAlgs( - std::string focusedFitPeaksTableName, std::string focusedWSName) { - // retrieve the table with parameters - auto &ADS = Mantid::API::AnalysisDataService::Instance(); - if (!ADS.doesExist(focusedFitPeaksTableName)) { - // convert units so valid dSpacing peaks can still be added to gui - if (ADS.doesExist(g_focusedFittingWSName)) { - convertUnits(g_focusedFittingWSName); - } - - throw std::invalid_argument( - focusedFitPeaksTableName + - " workspace could not be found. " - "Please check the log messages for more details."); - } - - auto table = ADS.retrieveWS<ITableWorkspace>(focusedFitPeaksTableName); - size_t rowCount = table->rowCount(); - const std::string single_peak_out_WS = "engggui_fitting_single_peaks"; - std::string currentPeakOutWS; - - std::string Bk2BkExpFunctionStr; - std::string startX = ""; - std::string endX = ""; - for (size_t i = 0; i < rowCount; i++) { - // get the functionStrFactory to generate the string for function - // property, returns the string with i row from table workspace - // table is just passed so it works? - Bk2BkExpFunctionStr = - functionStrFactory(table, focusedFitPeaksTableName, i, startX, endX); - - g_log.debug() << "startX: " + startX + " . endX: " + endX << '\n'; - - currentPeakOutWS = "__engggui_fitting_single_peaks" + std::to_string(i); - - // run EvaluateFunction algorithm with focused workspace to produce - // the correct fit function - // focusedWSName is not going to change as its always going to be from - // single workspace - runEvaluateFunctionAlg(Bk2BkExpFunctionStr, focusedWSName, currentPeakOutWS, - startX, endX); - - // crop workspace so only the correct workspace index is plotted - runCropWorkspaceAlg(currentPeakOutWS); - - // apply the same binning as a focused workspace - runRebinToWorkspaceAlg(currentPeakOutWS); - - // if the first peak - if (i == size_t(0)) { - - // create a workspace clone of bank focus file - // this will import all information of the previous file - runCloneWorkspaceAlg(focusedWSName, single_peak_out_WS); - - setDataToClonedWS(currentPeakOutWS, single_peak_out_WS); - ADS.remove(currentPeakOutWS); - } else { - const std::string currentPeakClonedWS = - "__engggui_fitting_cloned_peaks" + std::to_string(i); - - runCloneWorkspaceAlg(focusedWSName, currentPeakClonedWS); - - setDataToClonedWS(currentPeakOutWS, currentPeakClonedWS); - - // append all peaks in to single workspace & remove - runAppendSpectraAlg(single_peak_out_WS, currentPeakClonedWS); - ADS.remove(currentPeakOutWS); - ADS.remove(currentPeakClonedWS); - } - } - - convertUnits(g_focusedFittingWSName); - - // convert units for both workspaces to dSpacing from ToF - if (rowCount > size_t(0)) { - auto swks = ADS.retrieveWS<MatrixWorkspace>(single_peak_out_WS); - setDifcTzero(swks); - convertUnits(single_peak_out_WS); - } else { - g_log.error() << "The engggui_fitting_fitpeaks_params table produced is" - "empty. Please try again!\n"; - } - - m_fittingFinishedOK = true; -} - -std::string EnggDiffractionPresenter::functionStrFactory( - Mantid::API::ITableWorkspace_sptr ¶mTableWS, std::string tableName, - size_t row, std::string &startX, std::string &endX) { - const double windowLeft = 9; - const double windowRight = 12; - - AnalysisDataServiceImpl &ADS = Mantid::API::AnalysisDataService::Instance(); - paramTableWS = ADS.retrieveWS<ITableWorkspace>(tableName); - - double A0 = paramTableWS->cell<double>(row, size_t(1)); - double A1 = paramTableWS->cell<double>(row, size_t(3)); - double I = paramTableWS->cell<double>(row, size_t(13)); - double A = paramTableWS->cell<double>(row, size_t(7)); - double B = paramTableWS->cell<double>(row, size_t(9)); - double X0 = paramTableWS->cell<double>(row, size_t(5)); - double S = paramTableWS->cell<double>(row, size_t(11)); - - startX = boost::lexical_cast<std::string>(X0 - (windowLeft * S)); - endX = boost::lexical_cast<std::string>(X0 + (windowRight * S)); - - std::string functionStr = - "name=LinearBackground,A0=" + boost::lexical_cast<std::string>(A0) + - ",A1=" + boost::lexical_cast<std::string>(A1) + - ";name=BackToBackExponential,I=" + boost::lexical_cast<std::string>(I) + - ",A=" + boost::lexical_cast<std::string>(A) + ",B=" + - boost::lexical_cast<std::string>(B) + ",X0=" + - boost::lexical_cast<std::string>(X0) + ",S=" + - boost::lexical_cast<std::string>(S); - - return functionStr; -} - -void EnggDiffractionPresenter::runEvaluateFunctionAlg( - const std::string &bk2BkExpFunction, const std::string &InputName, - const std::string &OutputName, const std::string &startX, - const std::string &endX) { - - auto evalFunc = Mantid::API::AlgorithmManager::Instance().createUnmanaged( - "EvaluateFunction"); - g_log.notice() << "EvaluateFunction algorithm has started\n"; - try { - evalFunc->initialize(); - evalFunc->setProperty("Function", bk2BkExpFunction); - evalFunc->setProperty("InputWorkspace", InputName); - evalFunc->setProperty("OutputWorkspace", OutputName); - evalFunc->setProperty("StartX", startX); - evalFunc->setProperty("EndX", endX); - evalFunc->execute(); - } catch (std::runtime_error &re) { - g_log.error() << "Could not run the algorithm EvaluateFunction, " - "Error description: " + - static_cast<std::string>(re.what()) << '\n'; - } -} - -void EnggDiffractionPresenter::runCropWorkspaceAlg(std::string workspaceName) { - auto cropWS = Mantid::API::AlgorithmManager::Instance().createUnmanaged( - "CropWorkspace"); - try { - cropWS->initialize(); - cropWS->setProperty("InputWorkspace", workspaceName); - cropWS->setProperty("OutputWorkspace", workspaceName); - cropWS->setProperty("StartWorkspaceIndex", 1); - cropWS->setProperty("EndWorkspaceIndex", 1); - cropWS->execute(); - } catch (std::runtime_error &re) { - g_log.error() << "Could not run the algorithm CropWorkspace, " - "Error description: " + - static_cast<std::string>(re.what()) << '\n'; - } -} - -void EnggDiffractionPresenter::runAppendSpectraAlg(std::string workspace1Name, - std::string workspace2Name) { - auto appendSpec = Mantid::API::AlgorithmManager::Instance().createUnmanaged( - "AppendSpectra"); - try { - appendSpec->initialize(); - appendSpec->setProperty("InputWorkspace1", workspace1Name); - appendSpec->setProperty("InputWorkspace2", workspace2Name); - appendSpec->setProperty("OutputWorkspace", workspace1Name); - appendSpec->execute(); - } catch (std::runtime_error &re) { - g_log.error() << "Could not run the algorithm AppendWorkspace, " - "Error description: " + - static_cast<std::string>(re.what()) << '\n'; - } -} - -void EnggDiffractionPresenter::runRebinToWorkspaceAlg( - std::string workspaceName) { - auto RebinToWs = Mantid::API::AlgorithmManager::Instance().createUnmanaged( - "RebinToWorkspace"); - try { - RebinToWs->initialize(); - RebinToWs->setProperty("WorkspaceToRebin", workspaceName); - RebinToWs->setProperty("WorkspaceToMatch", g_focusedFittingWSName); - RebinToWs->setProperty("OutputWorkspace", workspaceName); - RebinToWs->execute(); - } catch (std::runtime_error &re) { - g_log.error() << "Could not run the algorithm RebinToWorkspace, " - "Error description: " + - static_cast<std::string>(re.what()) << '\n'; - } -} - -/** - * Converts from time-of-flight to d-spacing - * - * @param workspaceName name of the workspace to convert (in place) - */ -void EnggDiffractionPresenter::convertUnits(std::string workspaceName) { - // Here using the GSAS (DIFC, TZERO) parameters seems preferred - if (g_useAlignDetectors) { - runAlignDetectorsAlg(workspaceName); - } else { - runConvertUnitsAlg(workspaceName); - } -} - -void EnggDiffractionPresenter::getDifcTzero(MatrixWorkspace_const_sptr wks, - double &difc, double &difa, - double &tzero) const { - - try { - const auto run = wks->run(); - // long, step by step way: - // auto propC = run.getLogData("difc"); - // auto doubleC = - // dynamic_cast<Mantid::Kernel::PropertyWithValue<double> *>(propC); - // if (!doubleC) - // throw Mantid::Kernel::Exception::NotFoundError( - // "Required difc property not found in workspace.", "difc"); - difc = run.getPropertyValueAsType<double>("difc"); - difa = run.getPropertyValueAsType<double>("difa"); - tzero = run.getPropertyValueAsType<double>("tzero"); - - } catch (std::runtime_error &rexc) { - // fallback to something reasonable / approximate values so - // the fitting tab can work minimally - difa = tzero = 0.0; - difc = 18400; - g_log.warning() - << "Could not retrieve the DIFC, DIFA, TZERO values from the workspace " - << wks->name() << ". Using default, which is not adjusted for this " - "workspace/run: DIFA: " << difa << ", DIFC: " << difc - << ", TZERO: " << tzero << ". Error details: " << rexc.what() << '\n'; - } -} - -/** - * Converts units from time-of-flight to d-spacing, using - * AlignDetectors. This is the GSAS-style alternative to using the - * algorithm ConvertUnits. Needs to make sure that the workspace is - * not of distribution type (and use the algorithm - * ConvertFromDistribution if it is). This is a requirement of - * AlignDetectors. - * - * @param workspaceName name of the workspace to convert - */ -void EnggDiffractionPresenter::runAlignDetectorsAlg(std::string workspaceName) { - const std::string targetUnit = "dSpacing"; - const std::string algName = "AlignDetectors"; - - const auto &ADS = Mantid::API::AnalysisDataService::Instance(); - auto inputWS = ADS.retrieveWS<MatrixWorkspace>(workspaceName); - if (!inputWS) - return; - - double difc, difa, tzero; - getDifcTzero(inputWS, difc, difa, tzero); - - // create a table with the GSAS calibration parameters - ITableWorkspace_sptr difcTable; - try { - difcTable = Mantid::API::WorkspaceFactory::Instance().createTable(); - if (!difcTable) { - return; - } - difcTable->addColumn("int", "detid"); - difcTable->addColumn("double", "difc"); - difcTable->addColumn("double", "difa"); - difcTable->addColumn("double", "tzero"); - TableRow row = difcTable->appendRow(); - auto &spec = inputWS->getSpectrum(0); - Mantid::detid_t detID = *(spec.getDetectorIDs().cbegin()); - - row << detID << difc << difa << tzero; - } catch (std::runtime_error &rexc) { - g_log.error() << "Failed to prepare calibration table input to convert " - "units with the algorithm " << algName - << ". Error details: " << rexc.what() << '\n'; - return; - } - - // AlignDetectors doesn't take distribution workspaces (it enforces - // RawCountValidator) - if (inputWS->isDistribution()) { - try { - auto alg = Mantid::API::AlgorithmManager::Instance().createUnmanaged( - "ConvertFromDistribution"); - alg->initialize(); - alg->setProperty("Workspace", workspaceName); - alg->execute(); - } catch (std::runtime_error &rexc) { - g_log.error() << "Could not run ConvertFromDistribution. Error: " - << rexc.what() << '\n'; - return; - } - } - - try { - auto alg = - Mantid::API::AlgorithmManager::Instance().createUnmanaged(algName); - alg->initialize(); - alg->setProperty("InputWorkspace", workspaceName); - alg->setProperty("OutputWorkspace", workspaceName); - alg->setProperty("CalibrationWorkspace", difcTable); - alg->execute(); - } catch (std::runtime_error &rexc) { - g_log.error() << "Could not run the algorithm " << algName - << " to convert workspace to " << targetUnit - << ", Error details: " + static_cast<std::string>(rexc.what()) - << '\n'; - } -} - -void EnggDiffractionPresenter::runConvertUnitsAlg(std::string workspaceName) { - const std::string targetUnit = "dSpacing"; - auto ConvertUnits = - Mantid::API::AlgorithmManager::Instance().createUnmanaged("ConvertUnits"); - try { - ConvertUnits->initialize(); - ConvertUnits->setProperty("InputWorkspace", workspaceName); - ConvertUnits->setProperty("OutputWorkspace", workspaceName); - ConvertUnits->setProperty("Target", targetUnit); - ConvertUnits->setPropertyValue("EMode", "Elastic"); - ConvertUnits->execute(); - } catch (std::runtime_error &re) { - g_log.error() << "Could not run the algorithm ConvertUnits to convert " - "workspace to " << targetUnit - << ", Error description: " + - static_cast<std::string>(re.what()) << '\n'; - } -} - -void EnggDiffractionPresenter::runCloneWorkspaceAlg( - std::string inputWorkspace, const std::string &outputWorkspace) { - - auto cloneWorkspace = - Mantid::API::AlgorithmManager::Instance().createUnmanaged( - "CloneWorkspace"); - try { - cloneWorkspace->initialize(); - cloneWorkspace->setProperty("InputWorkspace", inputWorkspace); - cloneWorkspace->setProperty("OutputWorkspace", outputWorkspace); - cloneWorkspace->execute(); - } catch (std::runtime_error &re) { - g_log.error() << "Could not run the algorithm CreateWorkspace, " - "Error description: " + - static_cast<std::string>(re.what()) << '\n'; - } -} - -void EnggDiffractionPresenter::setDataToClonedWS(std::string ¤t_WS, - const std::string &cloned_WS) { - AnalysisDataServiceImpl &ADS = Mantid::API::AnalysisDataService::Instance(); - auto currentPeakWS = ADS.retrieveWS<MatrixWorkspace>(current_WS); - auto currentClonedWS = ADS.retrieveWS<MatrixWorkspace>(cloned_WS); - currentClonedWS->dataY(0) = currentPeakWS->readY(0); - currentClonedWS->dataE(0) = currentPeakWS->readE(0); -} - -void EnggDiffractionPresenter::setBankItems() { - try { - auto fitting_runno_vector = m_view->getFittingRunNumVec(); - - if (!fitting_runno_vector.empty()) { - - // delete previous bank added to the list - m_view->clearFittingComboBox(); - - for (size_t i = 0; i < fitting_runno_vector.size(); i++) { - Poco::Path vecFile(fitting_runno_vector[i]); - std::string strVecFile = vecFile.toString(); - // split the directory from m_fitting_runno_dir_vec - std::vector<std::string> vecFileSplit = - m_view->splitFittingDirectory(strVecFile); - - // get the last split in vector which will be bank - std::string bankID = (vecFileSplit.back()); - - bool digit = isDigit(bankID); - - if (digit || bankID == "cropped") { - m_view->addBankItem(bankID); - } else { - QString qBank = QString("Bank %1").arg(i + 1); - m_view->addBankItem(qBank.toStdString()); - } - } - - m_view->enableFittingComboBox(true); - } else { - // upon invalid file - // disable the widgets when only one related file found - m_view->enableFittingComboBox(false); - - m_view->clearFittingComboBox(); - } - - } catch (std::runtime_error &re) { - m_view->userWarning("Unable to insert items: ", - "Could not add banks to " - "combo-box or list widget; " + - static_cast<std::string>(re.what()) + - ". Please try again"); - } -} - -void EnggDiffractionPresenter::setRunNoItems( - std::vector<std::string> runNumVector, bool multiRun) { - try { - if (!runNumVector.empty()) { - - // delete previous bank added to the list - m_view->clearFittingListWidget(); - - for (size_t i = 0; i < runNumVector.size(); i++) { - - // get the last split in vector which will be bank - std::string currentRun = (runNumVector[i]); - - m_view->addRunNoItem(currentRun); - } - - if (multiRun) { - m_view->enableFittingListWidget(true); - - auto currentIndex = m_view->getFittingListWidgetCurrentRow(); - if (currentIndex == -1) - m_view->setFittingListWidgetCurrentRow(0); - } else { - m_view->enableFittingListWidget(false); - } - } - - else { - // upon invalid file - // disable the widgets when only one related file found - m_view->enableFittingListWidget(false); - - m_view->clearFittingListWidget(); - } - - } catch (std::runtime_error &re) { - m_view->userWarning("Unable to insert items: ", - "Could not add list widget; " + - static_cast<std::string>(re.what()) + - ". Please try again"); - } -} - -void EnggDiffractionPresenter::setDefaultBank( - std::vector<std::string> splittedBaseName, QString selectedFile) { - - if (!splittedBaseName.empty()) { - - std::string bankID = (splittedBaseName.back()); - auto combo_data = m_view->getFittingComboIdx(bankID); - - if (combo_data > -1) { - m_view->setBankIdComboBox(combo_data); - } else { - m_view->setFittingRunNo(selectedFile); - } - } - // check if the vector is not empty so that the first directory - // can be assigned to text-field when number is given - else if (!m_view->getFittingRunNumVec().empty()) { - auto firstDir = m_view->getFittingRunNumVec().at(0); - auto intialDir = QString::fromStdString(firstDir); - m_view->setFittingRunNo(intialDir); - } - // if nothing found related to text-field input - else if (!m_view->getFittingRunNo().empty()) - m_view->setFittingRunNo(selectedFile); -} - -bool EnggDiffractionPresenter::isDigit(std::string text) { - for (size_t i = 0; i < text.size(); i++) { - char *str = &text[i]; - if (std::isdigit(*str)) { - return true; - } - } - return false; -} - -void EnggDiffractionPresenter::plotFitPeaksCurves() { - AnalysisDataServiceImpl &ADS = Mantid::API::AnalysisDataService::Instance(); - std::string singlePeaksWs = "engggui_fitting_single_peaks"; - - if (!ADS.doesExist(singlePeaksWs) && !ADS.doesExist(g_focusedFittingWSName)) { - g_log.error() << "Fitting results could not be plotted as there is no " + - singlePeaksWs + " or " + g_focusedFittingWSName + - " workspace found.\n"; - m_view->showStatus("Error while fitting peaks"); - return; - } - - try { - auto focusedPeaksWS = - ADS.retrieveWS<MatrixWorkspace>(g_focusedFittingWSName); - auto focusedData = ALCHelper::curveDataFromWs(focusedPeaksWS); - m_view->setDataVector(focusedData, true, m_fittingFinishedOK); - - if (m_fittingFinishedOK) { - g_log.debug() << "single peaks fitting being plotted now.\n"; - auto singlePeaksWS = ADS.retrieveWS<MatrixWorkspace>(singlePeaksWs); - auto singlePeaksData = ALCHelper::curveDataFromWs(singlePeaksWS); - m_view->setDataVector(singlePeaksData, false, true); - m_view->showStatus("Peaks fitted successfully"); - - } else { - g_log.notice() - << "Focused workspace has been plotted to the " - "graph; further peaks can be adding using Peak Tools.\n"; - g_log.warning() << "Peaks could not be plotted as the fitting process " - "did not finish correctly.\n"; - m_view->showStatus("No peaks could be fitted"); - } - - } catch (std::runtime_error) { - g_log.error() - << "Unable to finish of the plotting of the graph for " - "engggui_fitting_focused_fitpeaks workspace. Error " - "description. Please check also the log message for detail."; - - m_view->showStatus("Error while plotting the peaks fitted"); - throw; - } -} - -void EnggDiffractionPresenter::fittingFinished() { - if (!m_view) - return; - - if (!m_fittingFinishedOK) { - g_log.warning() << "The single peak fitting did not finish correctly.\n"; - if (m_workerThread) { - delete m_workerThread; - m_workerThread = NULL; - } - - m_view->showStatus( - "Single peak fitting process did not complete successfully"); - } else { - g_log.notice() << "The single peak fitting finished - the output " - "workspace is ready.\n"; - - m_view->showStatus("Single peak fittin process finished. Ready"); - if (m_workerThread) { - delete m_workerThread; - m_workerThread = NULL; - } - } - - try { - // should now plot the focused workspace when single peak fitting - // process fails - plotFitPeaksCurves(); - - } catch (std::runtime_error &re) { - g_log.error() << "Unable to finish the plotting of the graph for " - "engggui_fitting_focused_fitpeaks workspace. Error " - "description: " + - static_cast<std::string>(re.what()) + - " Please check also the log message for detail."; - throw; - } - g_log.notice() << "EnggDiffraction GUI: plotting of peaks for single peak " - "fits has completed. \n"; - - // enable the GUI - m_view->enableCalibrateAndFocusActions(true); -} - void EnggDiffractionPresenter::processLogMsg() { std::vector<std::string> msgs = m_view->logMsgs(); for (size_t i = 0; i < msgs.size(); i++) { @@ -2025,7 +978,7 @@ void EnggDiffractionPresenter::calibrationFinished() { if (!m_view) return; - m_view->enableCalibrateAndFocusActions(true); + m_view->enableCalibrateFocusFitUserActions(true); if (!m_calibFinishedOK) { g_log.warning() << "The calibration did not finish correctly. Please " "check previous log messages for details.\n"; @@ -2081,6 +1034,11 @@ std::string EnggDiffractionPresenter::buildCalibrateSuggestedFilename( return sugg; } +std::vector<GSASCalibrationParms> +EnggDiffractionPresenter::currentCalibration() const { + return m_currentCalibParms; +} + /** * Calculate a calibration, responding the the "new calibration" * action/button. @@ -2653,10 +1611,10 @@ void EnggDiffractionPresenter::focusingFinished() { } if (m_workerThread) { delete m_workerThread; - m_workerThread = NULL; + m_workerThread = nullptr; } - m_view->enableCalibrateAndFocusActions(true); + m_view->enableCalibrateFocusFitUserActions(true); // display warning and information to the users regarding Stop Focus if (g_abortThread) { @@ -3365,10 +2323,10 @@ void EnggDiffractionPresenter::rebinningFinished() { } if (m_workerThread) { delete m_workerThread; - m_workerThread = NULL; + m_workerThread = nullptr; } - m_view->enableCalibrateAndFocusActions(true); + m_view->enableCalibrateFocusFitUserActions(true); } /** diff --git a/MantidQt/CustomInterfaces/src/EnggDiffraction/EnggDiffractionViewQtGUI.cpp b/MantidQt/CustomInterfaces/src/EnggDiffraction/EnggDiffractionViewQtGUI.cpp index cbc1a2e1880c089b2dd74f8bc9271c02553b2208..f9ab409f3296a8970e1d471646a82e8389feb091 100644 --- a/MantidQt/CustomInterfaces/src/EnggDiffraction/EnggDiffractionViewQtGUI.cpp +++ b/MantidQt/CustomInterfaces/src/EnggDiffraction/EnggDiffractionViewQtGUI.cpp @@ -1,22 +1,13 @@ #include "MantidQtCustomInterfaces/EnggDiffraction/EnggDiffractionViewQtGUI.h" -#include "MantidAPI/FunctionFactory.h" #include "MantidKernel/ConfigService.h" #include "MantidQtAPI/AlgorithmInputHistory.h" #include "MantidQtAPI/AlgorithmRunner.h" #include "MantidQtAPI/HelpWindow.h" #include "MantidQtCustomInterfaces/EnggDiffraction/EnggDiffractionPresenter.h" #include "MantidQtMantidWidgets/MWRunFiles.h" -#include "Poco/DirectoryIterator.h" - -using namespace Mantid::API; -using namespace MantidQt::CustomInterfaces; - -#include <array> -#include <fstream> -#include <random> +#include <Poco/DirectoryIterator.h> #include <Poco/Path.h> -#include <boost/lexical_cast.hpp> #include <QCheckBox> #include <QCloseEvent> @@ -24,7 +15,8 @@ using namespace MantidQt::CustomInterfaces; #include <QMessageBox> #include <QSettings> -#include <qwt_symbol.h> +using namespace Mantid::API; +using namespace MantidQt::CustomInterfaces; namespace MantidQt { namespace CustomInterfaces { @@ -36,9 +28,7 @@ const double EnggDiffractionViewQtGUI::g_defaultRebinWidth = -0.0005; int EnggDiffractionViewQtGUI::m_currentType = 0; int EnggDiffractionViewQtGUI::m_currentRunMode = 0; -bool EnggDiffractionViewQtGUI::m_fittingMutliRunMode = false; int EnggDiffractionViewQtGUI::m_currentCropCalibBankName = 0; -std::vector<std::string> EnggDiffractionViewQtGUI::m_fitting_runno_dir_vec; const std::string EnggDiffractionViewQtGUI::g_iparmExtStr = "GSAS instrument parameters, IPARM file: PRM, PAR, IPAR, IPARAM " @@ -59,7 +49,7 @@ const std::string EnggDiffractionViewQtGUI::g_DetGrpExtStr = "(*.csv *.txt);;" "Other extensions/all files (*.*)"; -const std::string EnggDiffractionViewQtGUI::m_settingsGroup = +const std::string EnggDiffractionViewQtGUI::g_settingsGroup = "CustomInterfaces/EnggDiffractionView"; /** @@ -69,25 +59,20 @@ const std::string EnggDiffractionViewQtGUI::m_settingsGroup = */ EnggDiffractionViewQtGUI::EnggDiffractionViewQtGUI(QWidget *parent) : UserSubWindow(parent), IEnggDiffractionView(), m_currentInst("ENGINX"), - m_currentCalibFilename(""), m_splashMsg(nullptr), m_focusedDataVector(), - m_fittedDataVector(), m_peakPicker(nullptr), m_zoomTool(nullptr), - m_presenter(nullptr) {} - -EnggDiffractionViewQtGUI::~EnggDiffractionViewQtGUI() { - for (auto curves : m_focusedDataVector) { - curves->detach(); - delete curves; - } + m_splashMsg(nullptr), m_presenter(nullptr) {} - for (auto curves : m_fittedDataVector) { - curves->detach(); - delete curves; - } -} +EnggDiffractionViewQtGUI::~EnggDiffractionViewQtGUI() {} void EnggDiffractionViewQtGUI::initLayout() { // setup container ui m_ui.setupUi(this); + + // presenter that knows how to handle a IEnggDiffractionView should + // take care of all the logic. Note that the view needs to know the + // concrete presenter + auto fullPres = boost::make_shared<EnggDiffractionPresenter>(this); + m_presenter = fullPres; + // add tab contents and set up their ui's QWidget *wCalib = new QWidget(m_ui.tabMain); m_uiTabCalib.setupUi(wCalib); @@ -101,9 +86,13 @@ void EnggDiffractionViewQtGUI::initLayout() { m_uiTabPreproc.setupUi(wPreproc); m_ui.tabMain->addTab(wPreproc, QString("Pre-processing")); - QWidget *wFitting = new QWidget(m_ui.tabMain); - m_uiTabFitting.setupUi(wFitting); - m_ui.tabMain->addTab(wFitting, QString("Fitting")); + // This is created from a QWidget* -> use null-deleter to prevent double-free + // with Qt + boost::shared_ptr<EnggDiffractionViewQtGUI> sharedView( + this, [](EnggDiffractionViewQtGUI *) {}); + m_fittingWidget = new EnggDiffFittingViewQtWidget( + m_ui.tabMain, sharedView, sharedView, fullPres, sharedView); + m_ui.tabMain->addTab(m_fittingWidget, QString("Fitting")); QWidget *wSettings = new QWidget(m_ui.tabMain); m_uiTabSettings.setupUi(wSettings); @@ -124,16 +113,8 @@ void EnggDiffractionViewQtGUI::initLayout() { doSetupTabCalib(); doSetupTabFocus(); doSetupTabPreproc(); - doSetupTabFitting(); doSetupTabSettings(); - // presenter that knows how to handle a IEnggDiffractionView should take care - // of all the logic - // note that the view needs to know the concrete presenter - m_presenter.reset(new EnggDiffractionPresenter(this)); - - // it will know what compute resources and tools we have available: - // This view doesn't even know the names of compute resources, etc. m_presenter->notify(IEnggDiffractionPresenter::Start); m_presenter->notify(IEnggDiffractionPresenter::RBNumberChange); } @@ -175,7 +156,7 @@ void EnggDiffractionViewQtGUI::doSetupTabCalib() { connect(m_uiTabCalib.comboBox_calib_cropped_bank_name, SIGNAL(currentIndexChanged(int)), this, SLOT(enableSpecNos())); - enableCalibrateAndFocusActions(true); + enableCalibrateFocusFitUserActions(true); } void EnggDiffractionViewQtGUI::doSetupTabFocus() { @@ -216,75 +197,6 @@ void EnggDiffractionViewQtGUI::doSetupTabPreproc() { SLOT(rebinMultiperiodClicked())); } -void EnggDiffractionViewQtGUI::doSetupTabFitting() { - - connect(m_uiTabFitting.pushButton_fitting_browse_run_num, SIGNAL(released()), - this, SLOT(browseFitFocusedRun())); - - connect(m_uiTabFitting.lineEdit_pushButton_run_num, - SIGNAL(textEdited(const QString &)), this, - SLOT(resetFittingMultiMode())); - - connect(m_uiTabFitting.lineEdit_pushButton_run_num, SIGNAL(editingFinished()), - this, SLOT(FittingRunNo())); - - connect(m_uiTabFitting.lineEdit_pushButton_run_num, SIGNAL(returnPressed()), - this, SLOT(FittingRunNo())); - - connect(this, SIGNAL(getBanks()), this, SLOT(FittingRunNo())); - - connect(this, SIGNAL(setBank()), this, SLOT(listViewFittingRun())); - - connect(m_uiTabFitting.listWidget_fitting_run_num, - SIGNAL(itemSelectionChanged()), this, SLOT(listViewFittingRun())); - - connect(m_uiTabFitting.comboBox_bank, SIGNAL(currentIndexChanged(int)), this, - SLOT(setBankDir(int))); - - connect(m_uiTabFitting.pushButton_fitting_browse_peaks, SIGNAL(released()), - this, SLOT(browsePeaksToFit())); - - connect(m_uiTabFitting.pushButton_fit, SIGNAL(released()), this, - SLOT(fitClicked())); - - // add peak by clicking the button - connect(m_uiTabFitting.pushButton_select_peak, SIGNAL(released()), - SLOT(setPeakPick())); - - connect(m_uiTabFitting.pushButton_add_peak, SIGNAL(released()), - SLOT(addPeakToList())); - - connect(m_uiTabFitting.pushButton_save_peak_list, SIGNAL(released()), - SLOT(savePeakList())); - - connect(m_uiTabFitting.pushButton_clear_peak_list, SIGNAL(released()), - SLOT(clearPeakList())); - - connect(m_uiTabFitting.pushButton_plot_separate_window, SIGNAL(released()), - SLOT(plotSeparateWindow())); - - m_uiTabFitting.dataPlot->setCanvasBackground(Qt::white); - m_uiTabFitting.dataPlot->setAxisTitle(QwtPlot::xBottom, "d-Spacing (A)"); - m_uiTabFitting.dataPlot->setAxisTitle(QwtPlot::yLeft, "Counts (us)^-1"); - QFont font("MS Shell Dlg 2", 8); - m_uiTabFitting.dataPlot->setAxisFont(QwtPlot::xBottom, font); - m_uiTabFitting.dataPlot->setAxisFont(QwtPlot::yLeft, font); - - // constructor of the peakPicker - // XXX: Being a QwtPlotItem, should get deleted when m_ui.plot gets deleted - // (auto-delete option) - m_peakPicker = - new MantidWidgets::PeakPicker(m_uiTabFitting.dataPlot, Qt::red); - setPeakPickerEnabled(false); - - m_zoomTool = new QwtPlotZoomer( - QwtPlot::xBottom, QwtPlot::yLeft, - QwtPicker::DragSelection | QwtPicker::CornerToCorner, - QwtPicker::AlwaysOff, m_uiTabFitting.dataPlot->canvas()); - m_zoomTool->setRubberBandPen(QPen(Qt::black)); - setZoomTool(false); -} - void EnggDiffractionViewQtGUI::doSetupTabSettings() { // line edits that display paths and the like m_uiTabSettings.lineEdit_input_dir_calib->setText( @@ -357,7 +269,7 @@ void EnggDiffractionViewQtGUI::doSetupSplashMsg() { void EnggDiffractionViewQtGUI::readSettings() { QSettings qs; - qs.beginGroup(QString::fromStdString(m_settingsGroup)); + qs.beginGroup(QString::fromStdString(g_settingsGroup)); m_ui.lineEdit_RBNumber->setText( qs.value("user-params-RBNumber", "").toString()); @@ -368,7 +280,6 @@ void EnggDiffractionViewQtGUI::readSettings() { qs.value("user-params-current-ceria-num", "").toString()); QString calibFname = qs.value("current-calib-filename", "").toString(); m_uiTabCalib.lineEdit_current_calib_filename->setText(calibFname); - m_currentCalibFilename = calibFname.toStdString(); m_uiTabCalib.MWRunFiles_new_vanadium_num->setUserInput( qs.value("user-params-new-vanadium-num", "").toString()); @@ -447,13 +358,6 @@ void EnggDiffractionViewQtGUI::readSettings() { m_uiTabPreproc.doubleSpinBox_step_time->setValue( qs.value("user-params-step-time", 1).toDouble()); - // user params - fitting - m_uiTabFitting.lineEdit_pushButton_run_num->setText( - qs.value("user-params-fitting-focused-file", "").toString()); - m_uiTabFitting.comboBox_bank->setCurrentIndex(0); - m_uiTabFitting.lineEdit_fitting_peaks->setText( - qs.value("user-params-fitting-peaks-to-fit", "").toString()); - // settings QString lastPath = MantidQt::API::AlgorithmInputHistory::Instance().getPreviousDirectory(); @@ -490,7 +394,7 @@ void EnggDiffractionViewQtGUI::readSettings() { void EnggDiffractionViewQtGUI::saveSettings() const { QSettings qs; - qs.beginGroup(QString::fromStdString(m_settingsGroup)); + qs.beginGroup(QString::fromStdString(g_settingsGroup)); qs.setValue("user-params-RBNumber", m_ui.lineEdit_RBNumber->text()); @@ -569,13 +473,6 @@ void EnggDiffractionViewQtGUI::saveSettings() const { qs.value("user-params-step-time", m_uiTabPreproc.doubleSpinBox_step_time->value()); - // fitting tab - - qs.setValue("user-params-fitting-focused-file", - m_uiTabFitting.lineEdit_pushButton_run_num->text()); - qs.setValue("user-params-fitting-peaks-to-fit", - m_uiTabFitting.lineEdit_fitting_peaks->text()); - // TODO: this should become << >> operators on EnggDiffCalibSettings qs.setValue("input-dir-calib-files", QString::fromStdString(m_calibSettings.m_inputDirCalib)); @@ -718,7 +615,7 @@ void EnggDiffractionViewQtGUI::newCalibLoaded(const std::string &vanadiumNo, } } -void EnggDiffractionViewQtGUI::enableCalibrateAndFocusActions(bool enable) { +void EnggDiffractionViewQtGUI::enableCalibrateFocusFitUserActions(bool enable) { // calibrate m_uiTabCalib.groupBox_make_new_calib->setEnabled(enable); m_uiTabCalib.groupBox_current_calib->setEnabled(enable); @@ -744,15 +641,7 @@ void EnggDiffractionViewQtGUI::enableCalibrateAndFocusActions(bool enable) { m_uiTabPreproc.pushButton_rebin_multiperiod->setEnabled(enable); // fitting - m_uiTabFitting.pushButton_fitting_browse_run_num->setEnabled(enable); - m_uiTabFitting.lineEdit_pushButton_run_num->setEnabled(enable); - m_uiTabFitting.pushButton_fitting_browse_peaks->setEnabled(enable); - m_uiTabFitting.lineEdit_fitting_peaks->setEnabled(enable); - m_uiTabFitting.pushButton_fit->setEnabled(enable); - m_uiTabFitting.pushButton_clear_peak_list->setEnabled(enable); - m_uiTabFitting.pushButton_save_peak_list->setEnabled(enable); - m_uiTabFitting.comboBox_bank->setEnabled(enable); - m_uiTabFitting.groupBox_fititng_preview->setEnabled(enable); + m_fittingWidget->enable(enable); } void EnggDiffractionViewQtGUI::enableTabs(bool enable) { @@ -779,207 +668,6 @@ double EnggDiffractionViewQtGUI::rebinningPulsesTime() const { return m_uiTabPreproc.doubleSpinBox_step_time->value(); } -void EnggDiffractionViewQtGUI::setBankDir(int idx) { - - if (m_fitting_runno_dir_vec.size() >= size_t(idx)) { - - std::string bankDir = m_fitting_runno_dir_vec[idx]; - Poco::Path fpath(bankDir); - - setFittingRunNo(QString::fromUtf8(bankDir.c_str())); - } -} - -void MantidQt::CustomInterfaces::EnggDiffractionViewQtGUI:: - listViewFittingRun() { - - if (m_fittingMutliRunMode) { - auto listView = m_uiTabFitting.listWidget_fitting_run_num; - auto currentRow = listView->currentRow(); - auto item = listView->item(currentRow); - QString itemText = item->text(); - - setFittingRunNo(itemText); - FittingRunNo(); - } -} - -void MantidQt::CustomInterfaces::EnggDiffractionViewQtGUI:: - resetFittingMultiMode() { - // resets the global variable so the list view widgets - // adds the run number to for single runs too - m_fittingMutliRunMode = false; -} - -std::string EnggDiffractionViewQtGUI::fittingRunNoFactory(std::string bank, - std::string fileName, - std::string &bankDir, - std::string fileDir) { - - std::string genDir = fileName.substr(0, fileName.size() - 1); - Poco::Path bankFile(genDir + bank + ".nxs"); - if (bankFile.isFile()) { - bankDir = fileDir + genDir + bank + ".nxs"; - } - return bankDir; -} - -std::string EnggDiffractionViewQtGUI::readPeaksFile(std::string fileDir) { - std::string fileData = ""; - std::string line; - std::string comma = ", "; - - std::ifstream peakFile(fileDir); - - if (peakFile.is_open()) { - while (std::getline(peakFile, line)) { - fileData += line; - if (!peakFile.eof()) - fileData += comma; - } - peakFile.close(); - } - - else - fileData = ""; - - return fileData; -} - -void EnggDiffractionViewQtGUI::setDataVector( - std::vector<boost::shared_ptr<QwtData>> &data, bool focused, - bool plotSinglePeaks) { - - if (!plotSinglePeaks) { - // clear vector and detach curves to avoid plot crash - // when only plotting focused workspace - for (auto curves : m_fittedDataVector) { - if (curves) { - curves->detach(); - delete curves; - } - } - - if (m_fittedDataVector.size() > 0) - m_fittedDataVector.clear(); - - // set it as false as there will be no valid workspace to plot - m_uiTabFitting.pushButton_plot_separate_window->setEnabled(false); - } - - if (focused) { - dataCurvesFactory(data, m_focusedDataVector, focused); - } else { - dataCurvesFactory(data, m_fittedDataVector, focused); - } -} - -void EnggDiffractionViewQtGUI::dataCurvesFactory( - std::vector<boost::shared_ptr<QwtData>> &data, - std::vector<QwtPlotCurve *> &dataVector, bool focused) { - - // clear vector - for (auto curves : dataVector) { - if (curves) { - curves->detach(); - delete curves; - } - } - - if (dataVector.size() > 0) - dataVector.clear(); - resetView(); - - // dark colours could be removed so that the coloured peaks stand out more - const std::array<QColor, 16> QPenList{ - {Qt::white, Qt::red, Qt::darkRed, Qt::green, Qt::darkGreen, Qt::blue, - Qt::darkBlue, Qt::cyan, Qt::darkCyan, Qt::magenta, Qt::darkMagenta, - Qt::yellow, Qt::darkYellow, Qt::gray, Qt::lightGray, Qt::black}}; - - std::mt19937 gen; - std::uniform_int_distribution<std::size_t> dis(0, QPenList.size() - 1); - - for (size_t i = 0; i < data.size(); i++) { - auto *peak = data[i].get(); - - QwtPlotCurve *dataCurve = new QwtPlotCurve(); - if (!focused) { - dataCurve->setStyle(QwtPlotCurve::Lines); - auto randIndex = dis(gen); - dataCurve->setPen(QPen(QPenList[randIndex], 2)); - - // only set enabled when single peak workspace plotted - m_uiTabFitting.pushButton_plot_separate_window->setEnabled(true); - } else { - dataCurve->setStyle(QwtPlotCurve::NoCurve); - // focused workspace in bg set as darkGrey crosses insted of line - dataCurve->setSymbol(QwtSymbol(QwtSymbol::XCross, QBrush(), - QPen(Qt::darkGray, 1), QSize(3, 3))); - } - dataCurve->setRenderHint(QwtPlotItem::RenderAntialiased, true); - - dataVector.push_back(dataCurve); - - dataVector[i]->setData(*peak); - dataVector[i]->attach(m_uiTabFitting.dataPlot); - } - - m_uiTabFitting.dataPlot->replot(); - m_zoomTool->setZoomBase(); - // enable zoom & select peak btn after the plotting on graph - setZoomTool(true); - m_uiTabFitting.pushButton_select_peak->setEnabled(true); - data.clear(); -} - -void EnggDiffractionViewQtGUI::setPeakPickerEnabled(bool enabled) { - m_peakPicker->setEnabled(enabled); - m_peakPicker->setVisible(enabled); - m_uiTabFitting.dataPlot->replot(); // PeakPicker might get hidden/shown - m_uiTabFitting.pushButton_add_peak->setEnabled(enabled); - if (enabled) { - QString btnText = "Reset Peak Selector"; - m_uiTabFitting.pushButton_select_peak->setText(btnText); - } -} - -void EnggDiffractionViewQtGUI::setPeakPicker( - const IPeakFunction_const_sptr &peak) { - m_peakPicker->setPeak(peak); - m_uiTabFitting.dataPlot->replot(); -} - -double EnggDiffractionViewQtGUI::getPeakCentre() const { - auto peak = m_peakPicker->peak(); - auto centre = peak->centre(); - return centre; -} - -void EnggDiffractionViewQtGUI::fittingWriteFile(const std::string &fileDir) { - std::ofstream outfile(fileDir.c_str()); - if (!outfile) { - userWarning("File not found", - "File " + fileDir + " , could not be found. Please try again!"); - } else { - auto expPeaks = m_uiTabFitting.lineEdit_fitting_peaks->text(); - outfile << expPeaks.toStdString(); - } -} - -void EnggDiffractionViewQtGUI::setZoomTool(bool enabled) { - m_zoomTool->setEnabled(enabled); -} - -void EnggDiffractionViewQtGUI::resetView() { - // Resets the view to a sensible default - // Auto scale the axis - m_uiTabFitting.dataPlot->setAxisAutoScale(QwtPlot::xBottom); - m_uiTabFitting.dataPlot->setAxisAutoScale(QwtPlot::yLeft); - - // Set this as the default zoom level - m_zoomTool->setZoomBase(true); -} - void EnggDiffractionViewQtGUI::plotFocusedSpectrum(const std::string &wsName) { std::string pyCode = "win=plotSpectrum('" + wsName + "', 0, error_bars=False, type=0)"; @@ -1111,14 +799,6 @@ void EnggDiffractionViewQtGUI::rebinMultiperiodClicked() { m_presenter->notify(IEnggDiffractionPresenter::RebinMultiperiod); } -void EnggDiffractionViewQtGUI::fitClicked() { - m_presenter->notify(IEnggDiffractionPresenter::FitPeaks); -} - -void EnggDiffractionViewQtGUI::FittingRunNo() { - m_presenter->notify(IEnggDiffractionPresenter::FittingRunNo); -} - void EnggDiffractionViewQtGUI::browseInputDirCalib() { QString prevPath = QString::fromStdString(m_calibSettings.m_inputDirCalib); if (prevPath.isEmpty()) { @@ -1211,8 +891,7 @@ void EnggDiffractionViewQtGUI::browseDirFocusing() { MantidQt::API::AlgorithmInputHistory::Instance().setPreviousDirectory(dir); m_focusDir = dir.toStdString(); - m_uiTabSettings.lineEdit_dir_focusing->setText( - QString::fromStdString(m_focusDir)); + m_uiTabSettings.lineEdit_dir_focusing->setText(dir); } void EnggDiffractionViewQtGUI::browseTextureDetGroupingFile() { @@ -1234,59 +913,6 @@ void EnggDiffractionViewQtGUI::browseTextureDetGroupingFile() { m_uiTabFocus.lineEdit_texture_grouping_file->setText(path); } -void EnggDiffractionViewQtGUI::browseFitFocusedRun() { - resetFittingMultiMode(); - QString prevPath = QString::fromStdString(m_focusDir); - if (prevPath.isEmpty()) { - prevPath = - MantidQt::API::AlgorithmInputHistory::Instance().getPreviousDirectory(); - } - std::string nexusFormat = "Nexus file with calibration table: NXS, NEXUS" - "(*.nxs *.nexus);;"; - - QString path( - QFileDialog::getOpenFileName(this, tr("Open Focused File "), prevPath, - QString::fromStdString(nexusFormat))); - - if (path.isEmpty()) { - return; - } - - MantidQt::API::AlgorithmInputHistory::Instance().setPreviousDirectory(path); - setFittingRunNo(path); - getBanks(); -} - -void EnggDiffractionViewQtGUI::browsePeaksToFit() { - - try { - QString prevPath = QString::fromStdString(m_focusDir); - if (prevPath.isEmpty()) { - prevPath = MantidQt::API::AlgorithmInputHistory::Instance() - .getPreviousDirectory(); - } - - QString path( - QFileDialog::getOpenFileName(this, tr("Open Peaks To Fit"), prevPath, - QString::fromStdString(g_DetGrpExtStr))); - - if (path.isEmpty()) { - return; - } - - MantidQt::API::AlgorithmInputHistory::Instance().setPreviousDirectory(path); - - std::string peaksData = readPeaksFile(path.toStdString()); - - m_uiTabFitting.lineEdit_fitting_peaks->setText( - QString::fromStdString(peaksData)); - } catch (...) { - userWarning("Unable to import the peaks from a file: ", - "File corrupted or could not be opened. Please try again"); - return; - } -} - std::vector<std::string> EnggDiffractionViewQtGUI::focusingRunNo() const { return qListToVector(m_uiTabFocus.MWRunFiles_run_num->getFilenames(), m_uiTabFocus.MWRunFiles_run_num->isValid()); @@ -1394,211 +1020,6 @@ void EnggDiffractionViewQtGUI::plotRepChanged(int /*idx*/) { m_currentType = plotType->currentIndex(); } -void EnggDiffractionViewQtGUI::setBankIdComboBox(int idx) { - QComboBox *bankName = m_uiTabFitting.comboBox_bank; - bankName->setCurrentIndex(idx); -} - -void EnggDiffractionViewQtGUI::setFittingRunNo(QString path) { - m_uiTabFitting.lineEdit_pushButton_run_num->setText(path); -} - -std::string EnggDiffractionViewQtGUI::getFittingRunNo() const { - return m_uiTabFitting.lineEdit_pushButton_run_num->text().toStdString(); -} - -void MantidQt::CustomInterfaces::EnggDiffractionViewQtGUI:: - clearFittingComboBox() const { - m_uiTabFitting.comboBox_bank->clear(); -} - -void MantidQt::CustomInterfaces::EnggDiffractionViewQtGUI:: - enableFittingComboBox(bool enable) const { - m_uiTabFitting.comboBox_bank->setEnabled(enable); -} - -void MantidQt::CustomInterfaces::EnggDiffractionViewQtGUI:: - clearFittingListWidget() const { - m_uiTabFitting.listWidget_fitting_run_num->clear(); -} - -void MantidQt::CustomInterfaces::EnggDiffractionViewQtGUI:: - enableFittingListWidget(bool enable) const { - m_uiTabFitting.listWidget_fitting_run_num->setEnabled(enable); -} - -int MantidQt::CustomInterfaces::EnggDiffractionViewQtGUI:: - getFittingListWidgetCurrentRow() const { - return m_uiTabFitting.listWidget_fitting_run_num->currentRow(); -} - -void MantidQt::CustomInterfaces::EnggDiffractionViewQtGUI:: - setFittingListWidgetCurrentRow(int idx) const { - m_uiTabFitting.listWidget_fitting_run_num->setCurrentRow(idx); -} - -int EnggDiffractionViewQtGUI::getFittingComboIdx(std::string bank) const { - return m_uiTabFitting.comboBox_bank->findText(QString::fromStdString(bank)); -} - -void EnggDiffractionViewQtGUI::plotSeparateWindow() { - std::string pyCode = - - "fitting_single_peaks_twin_ws = \"__engggui_fitting_single_peaks_twin\"\n" - "if (mtd.doesExist(fitting_single_peaks_twin_ws)):\n" - " DeleteWorkspace(fitting_single_peaks_twin_ws)\n" - - "single_peak_ws = CloneWorkspace(InputWorkspace = " - "\"engggui_fitting_single_peaks\", OutputWorkspace = " - "fitting_single_peaks_twin_ws)\n" - "tot_spec = single_peak_ws.getNumberHistograms()\n" - - "spec_list = []\n" - "for i in range(0, tot_spec):\n" - " spec_list.append(i)\n" - - "fitting_plot = plotSpectrum(single_peak_ws, spec_list).activeLayer()\n" - "fitting_plot.setTitle(\"Engg GUI Single Peaks Fitting Workspace\")\n"; - - std::string status = - runPythonCode(QString::fromStdString(pyCode), false).toStdString(); - m_logMsgs.emplace_back("Plotted output focused data, with status string " + - status); - m_presenter->notify(IEnggDiffractionPresenter::LogMsg); -} - -std::string EnggDiffractionViewQtGUI::fittingPeaksData() const { - - return m_uiTabFitting.lineEdit_fitting_peaks->text().toStdString(); -} - -void MantidQt::CustomInterfaces::EnggDiffractionViewQtGUI::setPeakList( - std::string peakList) const { - m_uiTabFitting.lineEdit_fitting_peaks->setText( - QString::fromStdString(peakList)); -} - -std::vector<std::string> -EnggDiffractionViewQtGUI::splitFittingDirectory(std::string &selectedfPath) { - - Poco::Path PocofPath(selectedfPath); - std::string selectedbankfName = PocofPath.getBaseName(); - std::vector<std::string> splitBaseName; - if (selectedbankfName.find("ENGINX_") != std::string::npos) { - boost::split(splitBaseName, selectedbankfName, boost::is_any_of("_.")); - } - return splitBaseName; -} - -void MantidQt::CustomInterfaces::EnggDiffractionViewQtGUI::setBankEmit() { - emit setBank(); -} - -std::string -MantidQt::CustomInterfaces::EnggDiffractionViewQtGUI::getFocusDir() { - return m_focusDir; -} - -void EnggDiffractionViewQtGUI::addBankItem(std::string bankID) { - - m_uiTabFitting.comboBox_bank->addItem(QString::fromStdString(bankID)); -} - -void MantidQt::CustomInterfaces::EnggDiffractionViewQtGUI::addRunNoItem( - std::string runNo) { - m_uiTabFitting.listWidget_fitting_run_num->addItem( - QString::fromStdString(runNo)); -} - -std::vector<std::string> EnggDiffractionViewQtGUI::getFittingRunNumVec() { - return m_fitting_runno_dir_vec; -} - -void EnggDiffractionViewQtGUI::setFittingRunNumVec( - std::vector<std::string> assignVec) { - m_fitting_runno_dir_vec.clear(); - m_fitting_runno_dir_vec = assignVec; -} - -void EnggDiffractionViewQtGUI::setFittingMultiRunMode(bool mode) { - m_fittingMutliRunMode = mode; -} - -bool EnggDiffractionViewQtGUI::getFittingMultiRunMode() { - return m_fittingMutliRunMode; -} - -void MantidQt::CustomInterfaces::EnggDiffractionViewQtGUI::setPeakPick() { - auto bk2bk = - FunctionFactory::Instance().createFunction("BackToBackExponential"); - auto bk2bkFunc = boost::dynamic_pointer_cast<IPeakFunction>(bk2bk); - // set the peak to BackToBackExponential function - setPeakPicker(bk2bkFunc); - setPeakPickerEnabled(true); -} - -void MantidQt::CustomInterfaces::EnggDiffractionViewQtGUI::addPeakToList() { - - if (m_peakPicker->isEnabled()) { - auto peakCentre = getPeakCentre(); - - std::stringstream stream; - stream << std::fixed << std::setprecision(4) << peakCentre; - auto strPeakCentre = stream.str(); - - auto curExpPeaksList = m_uiTabFitting.lineEdit_fitting_peaks->text(); - QString comma = ","; - - if (!curExpPeaksList.isEmpty()) { - // when further peak added to list - std::string expPeakStr = curExpPeaksList.toStdString(); - std::string lastTwoChr = expPeakStr.substr(expPeakStr.size() - 2); - auto lastChr = expPeakStr.back(); - if (lastChr == ',' || lastTwoChr == ", ") { - curExpPeaksList.append(QString::fromStdString(strPeakCentre)); - } else { - curExpPeaksList.append(comma + QString::fromStdString(strPeakCentre)); - } - m_uiTabFitting.lineEdit_fitting_peaks->setText(curExpPeaksList); - } else { - // when new peak given when list is empty - curExpPeaksList.append(QString::fromStdString(strPeakCentre)); - curExpPeaksList.append(comma); - m_uiTabFitting.lineEdit_fitting_peaks->setText(curExpPeaksList); - } - } -} - -void MantidQt::CustomInterfaces::EnggDiffractionViewQtGUI::savePeakList() { - // call function in EnggPresenter.. - - try { - QString prevPath = QString::fromStdString(m_focusDir); - if (prevPath.isEmpty()) { - prevPath = MantidQt::API::AlgorithmInputHistory::Instance() - .getPreviousDirectory(); - } - - QString path(QFileDialog::getSaveFileName( - this, tr("Save Expected Peaks List"), prevPath, - QString::fromStdString(g_DetGrpExtStr))); - - if (path.isEmpty()) { - return; - } - const std::string strPath = path.toStdString(); - fittingWriteFile(strPath); - } catch (...) { - userWarning("Unable to save the peaks file: ", - "Invalid file path or or could not be saved. Please try again"); - return; - } -} - -void MantidQt::CustomInterfaces::EnggDiffractionViewQtGUI::clearPeakList() { - m_uiTabFitting.lineEdit_fitting_peaks->clear(); -} - void EnggDiffractionViewQtGUI::instrumentChanged(int /*idx*/) { QComboBox *inst = m_ui.comboBox_instrument; if (!inst) @@ -1665,7 +1086,7 @@ void EnggDiffractionViewQtGUI::closeEvent(QCloseEvent *event) { void EnggDiffractionViewQtGUI::openHelpWin() { MantidQt::API::HelpWindow::showCustomInterface( - NULL, QString("Engineering_Diffraction")); + nullptr, QString("Engineering_Diffraction")); } } // namespace CustomInterfaces diff --git a/MantidQt/CustomInterfaces/src/Indirect/Elwin.cpp b/MantidQt/CustomInterfaces/src/Indirect/Elwin.cpp index 2ca587d79c0ae67c977dddc108a5a124bb4373bf..ccb4027fb165fb7b72ec30f82063cb3e7a3bb40f 100644 --- a/MantidQt/CustomInterfaces/src/Indirect/Elwin.cpp +++ b/MantidQt/CustomInterfaces/src/Indirect/Elwin.cpp @@ -115,17 +115,43 @@ void Elwin::run() { std::string inputGroupWsName = "IDA_Elwin_Input"; QFileInfo firstFileInfo(inputFilenames[0]); - QString filename = firstFileInfo.baseName(); - QString workspaceBaseName = - filename.left(filename.lastIndexOf("_")) + "_elwin_"; + const auto filename = firstFileInfo.baseName(); + + auto workspaceBaseName = filename.left(filename.lastIndexOf("_")); + + if (inputFilenames.size() > 1) { + QFileInfo fileInfo(inputFilenames[inputFilenames.length() - 1]); + auto runNumber = fileInfo.baseName().toStdString(); + runNumber = runNumber.substr(0, runNumber.find_first_of("_")); + size_t runNumberStart = 0; + const auto strLength = runNumber.length(); + for (size_t i = 0; i < strLength; i++) { + if (std::isdigit(runNumber[i])) { + runNumberStart = i; + break; + } + } + // reassemble workspace base name with additional run number + runNumber = runNumber.substr(runNumberStart, strLength); + auto baseName = firstFileInfo.baseName(); + const auto prefix = baseName.left(baseName.indexOf("_")); + auto testPre = prefix.toStdString(); + const auto suffix = + baseName.right(baseName.length() - baseName.indexOf("_")); + auto testsuf = suffix.toStdString(); + workspaceBaseName = + prefix + QString::fromStdString("-" + runNumber) + suffix; + } - QString qWorkspace = workspaceBaseName + "eq"; - QString qSquaredWorkspace = workspaceBaseName + "eq2"; - QString elfWorkspace = workspaceBaseName + "elf"; - QString eltWorkspace = workspaceBaseName + "elt"; + workspaceBaseName += "_elwin_"; + + const auto qWorkspace = (workspaceBaseName + "eq").toStdString(); + const auto qSquaredWorkspace = (workspaceBaseName + "eq2").toStdString(); + const auto elfWorkspace = (workspaceBaseName + "elf").toStdString(); + const auto eltWorkspace = (workspaceBaseName + "elt").toStdString(); // Load input files - std::vector<std::string> inputWorkspaceNames; + std::string inputWorkspacesString; for (auto it = inputFilenames.begin(); it != inputFilenames.end(); ++it) { QFileInfo inputFileInfo(*it); @@ -137,17 +163,18 @@ void Elwin::run() { loadAlg->setProperty("OutputWorkspace", workspaceName); m_batchAlgoRunner->addAlgorithm(loadAlg); - inputWorkspaceNames.push_back(workspaceName); + inputWorkspacesString += workspaceName + ","; } // Group input workspaces IAlgorithm_sptr groupWsAlg = AlgorithmManager::Instance().create("GroupWorkspaces"); groupWsAlg->initialize(); - groupWsAlg->setProperty("InputWorkspaces", inputWorkspaceNames); + API::BatchAlgorithmRunner::AlgorithmRuntimeProps runTimeProps; + runTimeProps["InputWorkspaces"] = inputWorkspacesString; groupWsAlg->setProperty("OutputWorkspace", inputGroupWsName); - m_batchAlgoRunner->addAlgorithm(groupWsAlg); + m_batchAlgoRunner->addAlgorithm(groupWsAlg, runTimeProps); // Configure ElasticWindowMultiple algorithm IAlgorithm_sptr elwinMultAlg = @@ -156,10 +183,9 @@ void Elwin::run() { elwinMultAlg->setProperty("Plot", m_uiForm.ckPlot->isChecked()); - elwinMultAlg->setProperty("OutputInQ", qWorkspace.toStdString()); - elwinMultAlg->setProperty("OutputInQSquared", - qSquaredWorkspace.toStdString()); - elwinMultAlg->setProperty("OutputELF", elfWorkspace.toStdString()); + elwinMultAlg->setProperty("OutputInQ", qWorkspace); + elwinMultAlg->setProperty("OutputInQSquared", qSquaredWorkspace); + elwinMultAlg->setProperty("OutputELF", elfWorkspace); elwinMultAlg->setProperty("SampleEnvironmentLogName", m_uiForm.leLogName->text().toStdString()); @@ -183,7 +209,7 @@ void Elwin::run() { } if (m_blnManager->value(m_properties["Normalise"])) { - elwinMultAlg->setProperty("OutputELT", eltWorkspace.toStdString()); + elwinMultAlg->setProperty("OutputELT", eltWorkspace); } BatchAlgorithmRunner::AlgorithmRuntimeProps elwinInputProps; @@ -206,7 +232,7 @@ void Elwin::run() { m_batchAlgoRunner->executeBatchAsync(); // Set the result workspace for Python script export - m_pythonExportWsName = qSquaredWorkspace.toStdString(); + m_pythonExportWsName = qSquaredWorkspace; } /** @@ -232,18 +258,19 @@ void Elwin::unGroupInput(bool error) { * @param workspaceName Name of the workspace to save * @param filename Name of the file to save it as */ -void Elwin::addSaveAlgorithm(QString workspaceName, QString filename) { +void Elwin::addSaveAlgorithm(const std::string &workspaceName, + std::string filename) { // Set a default filename if none provided - if (filename.isEmpty()) + if (filename.length() == 0) filename = workspaceName + ".nxs"; // Configure the algorithm IAlgorithm_sptr loadAlg = AlgorithmManager::Instance().create("SaveNexus"); loadAlg->initialize(); - loadAlg->setProperty("Filename", filename.toStdString()); + loadAlg->setProperty("Filename", filename); BatchAlgorithmRunner::AlgorithmRuntimeProps saveAlgProps; - saveAlgProps["InputWorkspace"] = workspaceName.toStdString(); + saveAlgProps["InputWorkspace"] = workspaceName; // Add it to the batch runner m_batchAlgoRunner->addAlgorithm(loadAlg, saveAlgProps); diff --git a/MantidQt/CustomInterfaces/src/Reflectometry/TransferResults.cpp b/MantidQt/CustomInterfaces/src/Reflectometry/TransferResults.cpp index 6fee46731d1322cabc37ac1f03b6a8f49ca451a0..e5edd5f2e56d8c7a575d13bd4aaaa5825554e935 100644 --- a/MantidQt/CustomInterfaces/src/Reflectometry/TransferResults.cpp +++ b/MantidQt/CustomInterfaces/src/Reflectometry/TransferResults.cpp @@ -24,12 +24,7 @@ void TransferResults::addTransferRow(const COLUMN_MAP_TYPE &row) { } void TransferResults::addErrorRow(COLUMN_NAME_TYPE id, COLUMN_VALUE_TYPE error) { - - COLUMN_MAP_TYPE row; - std::pair<COLUMN_NAME_TYPE, COLUMN_VALUE_TYPE> pair(id, error); - row.insert(pair); - m_errorRuns.push_back(row); - // m_errorRuns.push_back(row); + m_errorRuns.push_back({{id, error}}); } } } diff --git a/MantidQt/CustomInterfaces/test/EnggDiffFittingPresenterTest.h b/MantidQt/CustomInterfaces/test/EnggDiffFittingPresenterTest.h new file mode 100644 index 0000000000000000000000000000000000000000..c424c0315e462e90d4b39441b69e389249a9b7a4 --- /dev/null +++ b/MantidQt/CustomInterfaces/test/EnggDiffFittingPresenterTest.h @@ -0,0 +1,419 @@ +#ifndef MANTID_CUSTOMINTERFACES_ENGGDIFFFITTINGPRESENTERTEST_H +#define MANTID_CUSTOMINTERFACES_ENGGDIFFFITTINGPRESENTERTEST_H + +#include "MantidAPI/FrameworkManager.h" +#include "MantidQtCustomInterfaces/EnggDiffraction/EnggDiffFittingPresenter.h" + +#include "EnggDiffFittingViewMock.h" +#include <cxxtest/TestSuite.h> + +using namespace MantidQt::CustomInterfaces; +using testing::TypedEq; +using testing::Return; + +// Use this mocked presenter for tests that will start the focusing +// workers/threads. Otherwise you'll run into trouble with issues like +// "QEventLoop: Cannot be used without QApplication", as there is not +// Qt application here and the normal Qt thread used by the presenter +// uses signals/slots. +class EnggDiffFittingPresenterNoThread : public EnggDiffFittingPresenter { +public: + EnggDiffFittingPresenterNoThread(IEnggDiffFittingView *view) + : EnggDiffFittingPresenter(view, nullptr) {} + +private: + // not async at all + void startAsyncFittingWorker(const std::string &focusedRunNo, + const std::string &ExpectedPeaks) override { + doFitting(focusedRunNo, ExpectedPeaks); + fittingFinished(); + } +}; + +class EnggDiffFittingPresenterTest : public CxxTest::TestSuite { + +public: + // This pair of boilerplate methods prevent tghe suite being created + // statically + // This means the constructor isn't called when running other tests + static EnggDiffFittingPresenterTest *createSuite() { + return new EnggDiffFittingPresenterTest(); + } + + static void destroySuite(EnggDiffFittingPresenterTest *suite) { + delete suite; + } + + EnggDiffFittingPresenterTest() { + Mantid::API::FrameworkManager::Instance(); // make sure framework is + // initialized + } + + void setUp() override { + m_view.reset(new testing::NiceMock<MockEnggDiffFittingView>()); + m_presenter.reset(new MantidQt::CustomInterfaces::EnggDiffFittingPresenter( + m_view.get(), nullptr)); + + // default banks + m_ex_enginx_banks.push_back(true); + m_ex_enginx_banks.push_back(false); + + // default run number + m_ex_empty_run_num.emplace_back(""); + m_invalid_run_number.emplace_back(""); + m_ex_run_number.push_back(g_validRunNo); + g_vanNo.emplace_back("8899999988"); + g_ceriaNo.emplace_back("9999999999"); + + // provide personal directories in order to carry out the full disable tests + m_basicCalibSettings.m_inputDirCalib = "GUI_calib_folder/"; + m_basicCalibSettings.m_inputDirRaw = "GUI_calib_folder/"; + + m_basicCalibSettings.m_pixelCalibFilename = + "ENGINX_full_pixel_calibration.csv"; + + m_basicCalibSettings.m_templateGSAS_PRM = "GUI_calib_folder/" + "template_ENGINX_241391_236516_" + "North_and_South_banks.prm"; + + m_basicCalibSettings.m_forceRecalcOverwrite = false; + m_basicCalibSettings.m_rebinCalibrate = 1; + } + + void tearDown() override { + TS_ASSERT(testing::Mock::VerifyAndClearExpectations(m_view.get())); + } + + void test_fitting_with_missing_param() { + testing::NiceMock<MockEnggDiffFittingView> mockView; + MantidQt::CustomInterfaces::EnggDiffFittingPresenter pres(&mockView, + nullptr); + + EXPECT_CALL(mockView, getFittingRunNo()).Times(1).WillOnce(Return("")); + EXPECT_CALL(mockView, fittingPeaksData()).Times(1).WillOnce(Return("")); + + EXPECT_CALL(mockView, setPeakList(testing::_)).Times(0); + + // should not get to the point where the status is updated + EXPECT_CALL(mockView, showStatus(testing::_)).Times(0); + + // No errors/1 warnings. There will be an error log from the algorithms + EXPECT_CALL(mockView, userError(testing::_, testing::_)).Times(0); + EXPECT_CALL(mockView, userWarning(testing::_, testing::_)).Times(1); + + pres.notify(IEnggDiffFittingPresenter::FitPeaks); + TSM_ASSERT( + "Mock not used as expected. Some EXPECT_CALL conditions were not " + "satisfied.", + testing::Mock::VerifyAndClearExpectations(&mockView)) + } + + // This would test the fitting tab with no focused workspace + // which should produce a warning + void test_fitting_without_focused_run() { + testing::NiceMock<MockEnggDiffFittingView> mockView; + EnggDiffFittingPresenterNoThread pres(&mockView); + + // inputs from user + const std::string mockFname = ""; + EXPECT_CALL(mockView, getFittingRunNo()) + .Times(1) + .WillOnce(Return(mockFname)); + EXPECT_CALL(mockView, fittingPeaksData()) + .Times(1) + .WillOnce(Return("2.57,,4.88,5.78")); + + EXPECT_CALL(mockView, setPeakList(testing::_)).Times(1); + + // should not get to the point where the status is updated + EXPECT_CALL(mockView, showStatus(testing::_)).Times(0); + + // No errors/1 warnings. There will be an error log from the algorithms + EXPECT_CALL(mockView, userError(testing::_, testing::_)).Times(0); + EXPECT_CALL(mockView, userWarning(testing::_, testing::_)).Times(1); + + pres.notify(IEnggDiffFittingPresenter::FitPeaks); + TSM_ASSERT( + "Mock not used as expected. Some EXPECT_CALL conditions were not " + "satisfied.", + testing::Mock::VerifyAndClearExpectations(&mockView)) + } + + // This would test the fitting tab with invalid expected peaks but should only + // produce a warning + void test_fitting_with_invalid_expected_peaks() { + testing::NiceMock<MockEnggDiffFittingView> mockView; + EnggDiffFittingPresenterNoThread pres(&mockView); + + // inputs from user + EXPECT_CALL(mockView, getFittingRunNo()) + .Times(1) + .WillOnce(Return(g_focusedRun)); + EXPECT_CALL(mockView, fittingPeaksData()) + .Times(1) + .WillOnce(Return(",3.5,7.78,r43d")); + EXPECT_CALL(mockView, setPeakList(testing::_)).Times(1); + + // should not get to the point where the status is updated + EXPECT_CALL(mockView, showStatus(testing::_)).Times(0); + + // No errors/1 warnings. There will be an error log from the algorithms + EXPECT_CALL(mockView, userError(testing::_, testing::_)).Times(0); + EXPECT_CALL(mockView, userWarning(testing::_, testing::_)).Times(1); + + pres.notify(IEnggDiffFittingPresenter::FitPeaks); + TSM_ASSERT( + "Mock not used as expected. Some EXPECT_CALL conditions were not " + "satisfied.", + testing::Mock::VerifyAndClearExpectations(&mockView)) + } + + // Fitting test begin here + void test_fitting_runno_valid_single_run() { + testing::NiceMock<MockEnggDiffFittingView> mockView; + EnggDiffFittingPresenterNoThread pres(&mockView); + + // inputs from user + EXPECT_CALL(mockView, getFittingRunNo()) + .Times(2) + .WillRepeatedly(Return(std::string(g_focusedBankFile))); + + EXPECT_CALL(mockView, getFittingRunNumVec()) + .Times(1) + .WillOnce(Return(m_ex_run_number)); + + EXPECT_CALL(mockView, splitFittingDirectory(testing::_)) + .Times(1) + .WillOnce(Return(m_ex_run_number)); + + // should not get to the point where the status is updated + EXPECT_CALL(mockView, showStatus(testing::_)).Times(0); + + // No errors/0 warnings. There will be no errors or warnings + EXPECT_CALL(mockView, userError(testing::_, testing::_)).Times(0); + EXPECT_CALL(mockView, userWarning(testing::_, testing::_)).Times(1); + + pres.notify(IEnggDiffFittingPresenter::FittingRunNo); + } + + void test_fitting_runno_invalid_run() { + testing::NiceMock<MockEnggDiffFittingView> mockView; + EnggDiffFittingPresenterNoThread pres(&mockView); + + // inputs from user - empty run number given + EXPECT_CALL(mockView, getFittingRunNo()) + .Times(2) + .WillRepeatedly(Return(std::string(""))); + + EXPECT_CALL(mockView, getFittingRunNumVec()) + .Times(1) + .WillOnce(Return(m_ex_run_number)); + + EXPECT_CALL(mockView, splitFittingDirectory(testing::_)) + .Times(1) + .WillOnce(Return(m_ex_run_number)); + + // should not get to the point where the status is updated + EXPECT_CALL(mockView, showStatus(testing::_)).Times(0); + + // No errors/1 warnings. There will be an warning for invalid run number + EXPECT_CALL(mockView, userError(testing::_, testing::_)).Times(0); + EXPECT_CALL(mockView, userWarning(testing::_, testing::_)).Times(1); + + pres.notify(IEnggDiffFittingPresenter::FittingRunNo); + } + + void test_fitting_runno_multiple_run() { + testing::NiceMock<MockEnggDiffFittingView> mockView; + EnggDiffFittingPresenterNoThread pres(&mockView); + // 23931-23934 + std::vector<std::string> RunNumDir; + RunNumDir.emplace_back("241391"); + RunNumDir.emplace_back("241392"); + RunNumDir.emplace_back("241393"); + RunNumDir.emplace_back("241394"); + + // empty vector + std::vector<std::string> splittedFileVec; + + // inputs from user - given multiple run + EXPECT_CALL(mockView, getFittingRunNo()) + .Times(2) + .WillRepeatedly(Return(g_focusedFittingRunNo)); + + EXPECT_CALL(mockView, getFittingRunNumVec()) + .Times(1) + .WillOnce(Return(RunNumDir)); + + EXPECT_CALL(mockView, splitFittingDirectory(testing::_)) + .Times(1) + .WillOnce(Return(splittedFileVec)); + + // could possibly feature to create unique path + EXPECT_CALL(mockView, focusingDir()).Times(1); + + // should not get to the point where the status is updated + EXPECT_CALL(mockView, showStatus(testing::_)).Times(0); + + // No errors/1 warnings. The warning will be produced because there + // is no focus output directory within the settings tab + EXPECT_CALL(mockView, userError(testing::_, testing::_)).Times(0); + EXPECT_CALL(mockView, userWarning(testing::_, testing::_)).Times(1); + + pres.notify(IEnggDiffFittingPresenter::FittingRunNo); + } + + void diable_test_fitting_runno_single_run() { + testing::NiceMock<MockEnggDiffFittingView> mockView; + EnggDiffFittingPresenterNoThread pres(&mockView); + + // focus directory need to be set for this in the settings + + // 23931-23934 + std::vector<std::string> RunNumDir; + RunNumDir.emplace_back("241391"); + + // empty vector + std::vector<std::string> splittedFileVec; + + // inputs from user - given multiple run + EXPECT_CALL(mockView, getFittingRunNo()) + .Times(2) + .WillRepeatedly(Return("241391")); + + EXPECT_CALL(mockView, getFittingRunNumVec()) + .Times(1) + .WillOnce(Return(RunNumDir)); + + EXPECT_CALL(mockView, splitFittingDirectory(testing::_)) + .Times(1) + .WillOnce(Return(splittedFileVec)); + + EXPECT_CALL(mockView, getFittingMultiRunMode()) + .Times(1) + .WillOnce(Return(false)); + + EXPECT_CALL(mockView, setFittingRunNumVec(testing::_)).Times(1); + + EXPECT_CALL(mockView, addRunNoItem(testing::_)).Times(1); + + EXPECT_CALL(mockView, addBankItem(testing::_)).Times(1); + + EXPECT_CALL(mockView, focusingDir()).Times(0); + + // should not get to the point where the status is updated + EXPECT_CALL(mockView, showStatus(testing::_)).Times(0); + + // No errors/0 warnings. + EXPECT_CALL(mockView, userError(testing::_, testing::_)).Times(0); + EXPECT_CALL(mockView, userWarning(testing::_, testing::_)).Times(0); + + pres.notify(IEnggDiffFittingPresenter::FittingRunNo); + } + + void test_fitting_runno_browsed_run_add_run_item() { + testing::NiceMock<MockEnggDiffFittingView> mockView; + EnggDiffFittingPresenterNoThread pres(&mockView); + // Tests the browse directory file + std::vector<std::string> RunNumDir; + RunNumDir.emplace_back("241395"); + + std::vector<std::string> splittedFileVec; + splittedFileVec.emplace_back("ENGINX"); + splittedFileVec.emplace_back("241395"); + splittedFileVec.emplace_back("focused"); + splittedFileVec.emplace_back("bank"); + splittedFileVec.emplace_back("1"); + + // inputs from user - given multiple run + EXPECT_CALL(mockView, getFittingRunNo()) + .Times(2) + .WillRepeatedly(Return(g_focusedBankFile)); + + EXPECT_CALL(mockView, getFittingRunNumVec()) + .Times(1) + .WillOnce(Return(RunNumDir)); + + EXPECT_CALL(mockView, splitFittingDirectory(testing::_)) + .Times(1) + .WillOnce(Return(splittedFileVec)); + + EXPECT_CALL(mockView, getFittingMultiRunMode()).Times(0); + + EXPECT_CALL(mockView, setFittingRunNumVec(testing::_)).Times(0); + + EXPECT_CALL(mockView, addBankItem(testing::_)).Times(0); + + EXPECT_CALL(mockView, setBankIdComboBox(testing::_)).Times(0); + + EXPECT_CALL(mockView, addRunNoItem(testing::_)).Times(0); + + EXPECT_CALL(mockView, setFittingListWidgetCurrentRow(testing::_)).Times(0); + + EXPECT_CALL(mockView, focusingDir()).Times(0); + + // No errors/0 warnings. File entered is not found + EXPECT_CALL(mockView, userError(testing::_, testing::_)).Times(0); + EXPECT_CALL(mockView, userWarning(testing::_, testing::_)).Times(1); + + pres.notify(IEnggDiffFittingPresenter::FittingRunNo); + } + + void test_shutDown() { + testing::NiceMock<MockEnggDiffFittingView> mockView; + MantidQt::CustomInterfaces::EnggDiffFittingPresenter pres(&mockView, + nullptr); + + EXPECT_CALL(mockView, setPeakList(testing::_)).Times(0); + EXPECT_CALL(mockView, getFittingRunNo()).Times(0); + EXPECT_CALL(mockView, getFittingRunNumVec()).Times(0); + EXPECT_CALL(mockView, splitFittingDirectory(testing::_)).Times(0); + EXPECT_CALL(mockView, focusingDir()).Times(0); + + EXPECT_CALL(mockView, getFittingMultiRunMode()).Times(0); + + EXPECT_CALL(mockView, showStatus(testing::_)).Times(0); + + EXPECT_CALL(mockView, saveSettings()).Times(1); + // No errors, no warnings + EXPECT_CALL(mockView, userError(testing::_, testing::_)).Times(0); + EXPECT_CALL(mockView, userWarning(testing::_, testing::_)).Times(0); + + pres.notify(IEnggDiffFittingPresenter::ShutDown); + TSM_ASSERT( + "Mock not used as expected. Some EXPECT_CALL conditions were not " + "satisfied.", + testing::Mock::VerifyAndClearExpectations(&mockView)) + } + +private: + std::unique_ptr<testing::NiceMock<MockEnggDiffFittingView>> m_view; + std::unique_ptr<MantidQt::CustomInterfaces::EnggDiffFittingPresenter> + m_presenter; + + std::vector<bool> m_ex_enginx_banks; + const static std::string g_validRunNo; + const static std::string g_focusedRun; + const static std::string g_focusedBankFile; + const static std::string g_focusedFittingRunNo; + EnggDiffCalibSettings m_basicCalibSettings; + + std::vector<std::string> m_ex_empty_run_num; + std::vector<std::string> m_invalid_run_number; + std::vector<std::string> m_ex_run_number; + std::vector<std::string> g_vanNo; + std::vector<std::string> g_ceriaNo; +}; + +const std::string EnggDiffFittingPresenterTest::g_focusedRun = + "focused_texture_bank_1"; + +const std::string EnggDiffFittingPresenterTest::g_validRunNo = "228061"; + +const std::string EnggDiffFittingPresenterTest::g_focusedBankFile = + "ENGINX_241395_focused_texture_bank_1"; + +const std::string EnggDiffFittingPresenterTest::g_focusedFittingRunNo = + "241391-241394"; + +#endif // MANTID_CUSTOMINTERFACES_ENGGDIFFFITTINGPRESENTERTEST_H diff --git a/MantidQt/CustomInterfaces/test/EnggDiffFittingViewMock.h b/MantidQt/CustomInterfaces/test/EnggDiffFittingViewMock.h new file mode 100644 index 0000000000000000000000000000000000000000..1436ff427ced7a35865aa3ee767c11b69a523128 --- /dev/null +++ b/MantidQt/CustomInterfaces/test/EnggDiffFittingViewMock.h @@ -0,0 +1,122 @@ +#ifndef MANTID_CUSTOMINTERFACES_ENGGDIFFFITTINGVIEWMOCK_H +#define MANTID_CUSTOMINTERFACES_ENGGDIFFFITTINGVIEWMOCK_H + +#include "MantidKernel/WarningSuppressions.h" +#include "MantidQtCustomInterfaces/EnggDiffraction/IEnggDiffFittingView.h" + +#include <gmock/gmock.h> + +GCC_DIAG_OFF_SUGGEST_OVERRIDE + +// This is a simple mock for the tomo interface view when using SCARF. +class MockEnggDiffFittingView + : public MantidQt::CustomInterfaces::IEnggDiffFittingView { + +public: + // virtual void showStatus(const std::string &sts); + MOCK_METHOD1(showStatus, void(const std::string &sts)); + + // virtual void userWarning(const std::string &warn, const std::string + // &description); + MOCK_METHOD2(userWarning, + void(const std::string &warn, const std::string &description)); + + // virtual void userError(const std::string &err, const std::string + // &description); + MOCK_METHOD2(userError, + void(const std::string &err, const std::string &description)); + + // virtual void enableCalibrateFocusFitUserActions(bool enable); + MOCK_METHOD1(enableCalibrateFocusFitUserActions, void(bool)); + + // virtual EnggDiffCalibSettings currentCalibSettings() const; + MOCK_CONST_METHOD0(currentCalibSettings, + MantidQt::CustomInterfaces::EnggDiffCalibSettings()); + + // virtual std::string focusingDir() const; + MOCK_CONST_METHOD0(focusingDir, std::string()); + + // virtual std::string enggRunPythonCode(const std::string &pyCode) + MOCK_METHOD1(enggRunPythonCode, std::string(const std::string &)); + + // virtual std::string fittingRunNo() const; + MOCK_CONST_METHOD0(getFittingRunNo, std::string()); + + // virtual std::string fittingPeaksData() const; + MOCK_CONST_METHOD0(fittingPeaksData, std::string()); + + // virtual bool focusedOutWorkspace() const; + MOCK_CONST_METHOD0(focusedOutWorkspace, bool()); + + // virtual Splits the fitting directory if the ENGINX found + MOCK_METHOD1(splitFittingDirectory, + std::vector<std::string>(std::string &selectedfPath)); + + // adds the number of banks to the combo-box widget on the interface + MOCK_METHOD1(addBankItem, void(std::string bankID)); + + // adds the run number to the list view widget on the interface + MOCK_METHOD1(addRunNoItem, void(std::string runNo)); + + // emits the signal within view when run number / bank changed + MOCK_METHOD0(setBankEmit, void()); + + // sets the bank combo-box according to given index + MOCK_METHOD1(setBankIdComboBox, void(int idx)); + + // deletes all items from the fitting combo-box widget + MOCK_CONST_METHOD0(clearFittingComboBox, void()); + + // enables or disables the fitting combo-box + MOCK_CONST_METHOD1(enableFittingComboBox, void(bool enable)); + + // gets the index of the bank according to text found + MOCK_CONST_METHOD1(getFittingComboIdx, int(std::string bank)); + + // deletes all items from the fitting list widget + MOCK_CONST_METHOD0(clearFittingListWidget, void()); + + // enables or disables the fitting list widget + MOCK_CONST_METHOD1(enableFittingListWidget, void(bool enable)); + + // return idx of current selected row of list widget + MOCK_CONST_METHOD0(getFittingListWidgetCurrentRow, int()); + + // sets the current row of the fitting list widget + MOCK_CONST_METHOD1(setFittingListWidgetCurrentRow, void(int idx)); + + // sets the peak list according to the QString given + MOCK_CONST_METHOD1(setPeakList, void(const std::string &peakList)); + + // std::vector<std::string> logMsgs() const; + MOCK_CONST_METHOD0(logMsgs, std::vector<std::string>()); + + // gets the global vector in view containing focused file directory + MOCK_METHOD0(getFittingRunNumVec, std::vector<std::string>()); + + // sets the global vector in view containing focused file directory + MOCK_METHOD1(setFittingRunNumVec, void(std::vector<std::string> assignVec)); + + // sets the fitting run number according to path + MOCK_METHOD1(setFittingRunNo, void(const std::string &path)); + + // To determine whether the current loop is multi-run or single to avoid + // regenerating the list - view widget when not required + MOCK_METHOD0(getFittingMultiRunMode, bool()); + + // sets the fitting mode to multi-run or single to avoid + // regenerating the list - view widget when not required + MOCK_METHOD1(setFittingMultiRunMode, void(bool mode)); + + // void saveSettings() const; + MOCK_CONST_METHOD0(saveSettings, void()); + + // virtual void setDataVector + MOCK_METHOD3(setDataVector, + void(std::vector<boost::shared_ptr<QwtData>> &data, bool focused, + bool plotSinglePeaks)); +}; + +GCC_DIAG_ON_SUGGEST_OVERRIDE + +#endif // MANTID_CUSTOMINTERFACES_ENGGDIFFFITTINGVIEWMOCK_H diff --git a/MantidQt/CustomInterfaces/test/EnggDiffractionPresenterTest.h b/MantidQt/CustomInterfaces/test/EnggDiffractionPresenterTest.h index 6028ed566d4fb01187e55205e4379196c3e1157b..f1dc97e15ea65a739564de7b1fef8d51914c8c1d 100644 --- a/MantidQt/CustomInterfaces/test/EnggDiffractionPresenterTest.h +++ b/MantidQt/CustomInterfaces/test/EnggDiffractionPresenterTest.h @@ -57,12 +57,6 @@ private: doRebinningPulses(runNo, nperiods, timeStep, outWSName); rebinningFinished(); } - - void startAsyncFittingWorker(const std::string &focusedRunNo, - const std::string &ExpectedPeaks) override { - doFitting(focusedRunNo, ExpectedPeaks); - fittingFinished(); - } }; class EnggDiffractionPresenterTest : public CxxTest::TestSuite { @@ -324,12 +318,12 @@ public: // only after the error, it should disable actions at the beginning of the // calculations - EXPECT_CALL(mockView, enableCalibrateAndFocusActions(false)).Times(0); + EXPECT_CALL(mockView, enableCalibrateFocusFitUserActions(false)).Times(0); // and only after the error it should enable them again at the // (unsuccessful) end - this happens when a separate thread // finished (here the thread is mocked) - EXPECT_CALL(mockView, enableCalibrateAndFocusActions(true)).Times(0); + EXPECT_CALL(mockView, enableCalibrateFocusFitUserActions(true)).Times(0); // plots peaks and curves // the test doesnt get to here as it finishes at EnggCalibrate algo @@ -537,11 +531,11 @@ public: // with the normal thread should disable actions at the beginning // of the calculations - EXPECT_CALL(mockView, enableCalibrateAndFocusActions(false)).Times(0); + EXPECT_CALL(mockView, enableCalibrateFocusFitUserActions(false)).Times(0); // and should enable them again at the (unsuccessful) end - this happens // when a separate thread finished (here the thread is mocked) - EXPECT_CALL(mockView, enableCalibrateAndFocusActions(true)).Times(0); + EXPECT_CALL(mockView, enableCalibrateFocusFitUserActions(true)).Times(0); // tests whether the plot functions have been called EXPECT_CALL(mockView, plotCalibWorkspace()).Times(0); @@ -614,11 +608,11 @@ public: // it will not get to the next steps: // should disable actions at the beginning of the calculations - EXPECT_CALL(mockView, enableCalibrateAndFocusActions(false)).Times(0); + EXPECT_CALL(mockView, enableCalibrateFocusFitUserActions(false)).Times(0); // and should enable them again at the (unsuccessful) end - this happens // when a separate thread finished (here the thread is mocked) - EXPECT_CALL(mockView, enableCalibrateAndFocusActions(true)).Times(0); + EXPECT_CALL(mockView, enableCalibrateFocusFitUserActions(true)).Times(0); // A warning about the vanadium EXPECT_CALL(mockView, userWarning(testing::_, testing::_)).Times(1); @@ -768,8 +762,8 @@ public: EXPECT_CALL(mockView, plotFocusedSpectrum(testing::_)).Times(0); // it should not get there - EXPECT_CALL(mockView, enableCalibrateAndFocusActions(false)).Times(0); - EXPECT_CALL(mockView, enableCalibrateAndFocusActions(true)).Times(0); + EXPECT_CALL(mockView, enableCalibrateFocusFitUserActions(false)).Times(0); + EXPECT_CALL(mockView, enableCalibrateFocusFitUserActions(true)).Times(0); // should not get to the point where the status is updated EXPECT_CALL(mockView, showStatus(testing::_)).Times(0); @@ -1307,276 +1301,6 @@ public: testing::Mock::VerifyAndClearExpectations(&mockView)) } - void test_fitting_with_missing_param() { - testing::NiceMock<MockEnggDiffractionView> mockView; - MantidQt::CustomInterfaces::EnggDiffractionPresenter pres(&mockView); - - EXPECT_CALL(mockView, getFittingRunNo()).Times(1).WillOnce(Return("")); - EXPECT_CALL(mockView, fittingPeaksData()).Times(1).WillOnce(Return("")); - - EXPECT_CALL(mockView, setPeakList(testing::_)).Times(0); - - // should not get to the point where the status is updated - EXPECT_CALL(mockView, showStatus(testing::_)).Times(0); - - // No errors/1 warnings. There will be an error log from the algorithms - EXPECT_CALL(mockView, userError(testing::_, testing::_)).Times(0); - EXPECT_CALL(mockView, userWarning(testing::_, testing::_)).Times(1); - - pres.notify(IEnggDiffractionPresenter::FitPeaks); - TSM_ASSERT( - "Mock not used as expected. Some EXPECT_CALL conditions were not " - "satisfied.", - testing::Mock::VerifyAndClearExpectations(&mockView)) - } - - // This would test the fitting tab with no focused workspace - // which should produce a warning - void test_fitting_without_focused_run() { - testing::NiceMock<MockEnggDiffractionView> mockView; - EnggDiffPresenterNoThread pres(&mockView); - - // inputs from user - const std::string mockFname = ""; - EXPECT_CALL(mockView, getFittingRunNo()) - .Times(1) - .WillOnce(Return(mockFname)); - EXPECT_CALL(mockView, fittingPeaksData()) - .Times(1) - .WillOnce(Return("2.57,,4.88,5.78")); - - EXPECT_CALL(mockView, setPeakList(testing::_)).Times(1); - - // should not get to the point where the status is updated - EXPECT_CALL(mockView, showStatus(testing::_)).Times(0); - - // No errors/1 warnings. There will be an error log from the algorithms - EXPECT_CALL(mockView, userError(testing::_, testing::_)).Times(0); - EXPECT_CALL(mockView, userWarning(testing::_, testing::_)).Times(1); - - pres.notify(IEnggDiffractionPresenter::FitPeaks); - TSM_ASSERT( - "Mock not used as expected. Some EXPECT_CALL conditions were not " - "satisfied.", - testing::Mock::VerifyAndClearExpectations(&mockView)) - } - - // This would test the fitting tab with invalid expected peaks but should only - // produce a warning - void test_fitting_with_invalid_expected_peaks() { - testing::NiceMock<MockEnggDiffractionView> mockView; - EnggDiffPresenterNoThread pres(&mockView); - - // inputs from user - EXPECT_CALL(mockView, getFittingRunNo()) - .Times(1) - .WillOnce(Return(g_focusedRun)); - EXPECT_CALL(mockView, fittingPeaksData()) - .Times(1) - .WillOnce(Return(",3.5,7.78,r43d")); - EXPECT_CALL(mockView, setPeakList(testing::_)).Times(1); - - // should not get to the point where the status is updated - EXPECT_CALL(mockView, showStatus(testing::_)).Times(0); - - // No errors/1 warnings. There will be an error log from the algorithms - EXPECT_CALL(mockView, userError(testing::_, testing::_)).Times(0); - EXPECT_CALL(mockView, userWarning(testing::_, testing::_)).Times(1); - - pres.notify(IEnggDiffractionPresenter::FitPeaks); - TSM_ASSERT( - "Mock not used as expected. Some EXPECT_CALL conditions were not " - "satisfied.", - testing::Mock::VerifyAndClearExpectations(&mockView)) - } - - // Fitting test begin here - void test_fitting_runno_valid_single_run() { - testing::NiceMock<MockEnggDiffractionView> mockView; - EnggDiffPresenterNoThread pres(&mockView); - - // inputs from user - EXPECT_CALL(mockView, getFittingRunNo()) - .Times(2) - .WillRepeatedly(Return(std::string(g_focusedBankFile))); - - EXPECT_CALL(mockView, getFittingRunNumVec()) - .Times(1) - .WillOnce(Return(m_ex_run_number)); - - EXPECT_CALL(mockView, splitFittingDirectory(testing::_)) - .Times(1) - .WillOnce(Return(m_ex_run_number)); - - // should not get to the point where the status is updated - EXPECT_CALL(mockView, showStatus(testing::_)).Times(0); - - // No errors/0 warnings. There will be no errors or warnings - EXPECT_CALL(mockView, userError(testing::_, testing::_)).Times(0); - EXPECT_CALL(mockView, userWarning(testing::_, testing::_)).Times(1); - - pres.notify(IEnggDiffractionPresenter::FittingRunNo); - } - - void test_fitting_runno_invalid_run() { - testing::NiceMock<MockEnggDiffractionView> mockView; - EnggDiffPresenterNoThread pres(&mockView); - - // inputs from user - empty run number given - EXPECT_CALL(mockView, getFittingRunNo()) - .Times(2) - .WillRepeatedly(Return(std::string(""))); - - EXPECT_CALL(mockView, getFittingRunNumVec()) - .Times(1) - .WillOnce(Return(m_ex_run_number)); - - EXPECT_CALL(mockView, splitFittingDirectory(testing::_)) - .Times(1) - .WillOnce(Return(m_ex_run_number)); - - // should not get to the point where the status is updated - EXPECT_CALL(mockView, showStatus(testing::_)).Times(0); - - // No errors/1 warnings. There will be an warning for invalid run number - EXPECT_CALL(mockView, userError(testing::_, testing::_)).Times(0); - EXPECT_CALL(mockView, userWarning(testing::_, testing::_)).Times(1); - - pres.notify(IEnggDiffractionPresenter::FittingRunNo); - } - - void test_fitting_runno_multiple_run() { - testing::NiceMock<MockEnggDiffractionView> mockView; - EnggDiffPresenterNoThread pres(&mockView); - // 23931-23934 - std::vector<std::string> RunNumDir; - RunNumDir.emplace_back("241391"); - RunNumDir.emplace_back("241392"); - RunNumDir.emplace_back("241393"); - RunNumDir.emplace_back("241394"); - - // empty vector - std::vector<std::string> splittedFileVec; - - // inputs from user - given multiple run - EXPECT_CALL(mockView, getFittingRunNo()) - .Times(2) - .WillRepeatedly(Return(g_focusedFittingRunNo)); - - EXPECT_CALL(mockView, getFittingRunNumVec()) - .Times(1) - .WillOnce(Return(RunNumDir)); - - EXPECT_CALL(mockView, splitFittingDirectory(testing::_)) - .Times(1) - .WillOnce(Return(splittedFileVec)); - - // could possibly feature to create unique path - EXPECT_CALL(mockView, getFocusDir()).Times(1); - - // should not get to the point where the status is updated - EXPECT_CALL(mockView, showStatus(testing::_)).Times(0); - - // No errors/1 warnings. The warning will be produced because there - // is no focus output directory within the settings tab - EXPECT_CALL(mockView, userError(testing::_, testing::_)).Times(0); - EXPECT_CALL(mockView, userWarning(testing::_, testing::_)).Times(1); - - pres.notify(IEnggDiffractionPresenter::FittingRunNo); - } - - void diable_test_fitting_runno_single_run() { - testing::NiceMock<MockEnggDiffractionView> mockView; - EnggDiffPresenterNoThread pres(&mockView); - - // focus directory need to be set for this in the settings - - // 23931-23934 - std::vector<std::string> RunNumDir; - RunNumDir.emplace_back("241391"); - - // empty vector - std::vector<std::string> splittedFileVec; - - // inputs from user - given multiple run - EXPECT_CALL(mockView, getFittingRunNo()) - .Times(2) - .WillRepeatedly(Return("241391")); - - EXPECT_CALL(mockView, getFittingRunNumVec()) - .Times(1) - .WillOnce(Return(RunNumDir)); - - EXPECT_CALL(mockView, splitFittingDirectory(testing::_)) - .Times(1) - .WillOnce(Return(splittedFileVec)); - - EXPECT_CALL(mockView, getFittingMultiRunMode()) - .Times(1) - .WillOnce(Return(false)); - - EXPECT_CALL(mockView, setFittingRunNumVec(testing::_)).Times(1); - - EXPECT_CALL(mockView, addRunNoItem(testing::_)).Times(1); - - EXPECT_CALL(mockView, addBankItem(testing::_)).Times(1); - - // should not get to the point where the status is updated - EXPECT_CALL(mockView, showStatus(testing::_)).Times(0); - - // No errors/0 warnings. - EXPECT_CALL(mockView, userError(testing::_, testing::_)).Times(0); - EXPECT_CALL(mockView, userWarning(testing::_, testing::_)).Times(0); - - pres.notify(IEnggDiffractionPresenter::FittingRunNo); - } - - void test_fitting_runno_browsed_run_add_run_item() { - testing::NiceMock<MockEnggDiffractionView> mockView; - EnggDiffPresenterNoThread pres(&mockView); - // Tests the browse directory file - std::vector<std::string> RunNumDir; - RunNumDir.emplace_back("241395"); - - std::vector<std::string> splittedFileVec; - splittedFileVec.emplace_back("ENGINX"); - splittedFileVec.emplace_back("241395"); - splittedFileVec.emplace_back("focused"); - splittedFileVec.emplace_back("bank"); - splittedFileVec.emplace_back("1"); - - // inputs from user - given multiple run - EXPECT_CALL(mockView, getFittingRunNo()) - .Times(2) - .WillRepeatedly(Return(g_focusedBankFile)); - - EXPECT_CALL(mockView, getFittingRunNumVec()) - .Times(1) - .WillOnce(Return(RunNumDir)); - - EXPECT_CALL(mockView, splitFittingDirectory(testing::_)) - .Times(1) - .WillOnce(Return(splittedFileVec)); - - EXPECT_CALL(mockView, getFittingMultiRunMode()).Times(0); - - EXPECT_CALL(mockView, setFittingRunNumVec(testing::_)).Times(0); - - EXPECT_CALL(mockView, addBankItem(testing::_)).Times(0); - - EXPECT_CALL(mockView, setBankIdComboBox(testing::_)).Times(0); - - EXPECT_CALL(mockView, addRunNoItem(testing::_)).Times(0); - - EXPECT_CALL(mockView, setFittingListWidgetCurrentRow(testing::_)).Times(0); - - // No errors/0 warnings. File entered is not found - EXPECT_CALL(mockView, userError(testing::_, testing::_)).Times(0); - EXPECT_CALL(mockView, userWarning(testing::_, testing::_)).Times(1); - - pres.notify(IEnggDiffractionPresenter::FittingRunNo); - } - void test_logMsg() { testing::NiceMock<MockEnggDiffractionView> mockView; MantidQt::CustomInterfaces::EnggDiffractionPresenter pres(&mockView); @@ -1688,8 +1412,6 @@ private: const static std::string g_eventModeRunNo; const static std::string g_validRunNo; const static std::string g_focusedRun; - const static std::string g_focusedBankFile; - const static std::string g_focusedFittingRunNo; EnggDiffCalibSettings m_basicCalibSettings; std::vector<std::string> m_ex_empty_run_num; @@ -1707,15 +1429,6 @@ private: const std::string EnggDiffractionPresenterTest::g_eventModeRunNo = "ENGINX00228061"; // could also be given as "ENGINX228061" -const std::string EnggDiffractionPresenterTest::g_focusedRun = - "focused_texture_bank_1"; - const std::string EnggDiffractionPresenterTest::g_validRunNo = "228061"; -const std::string EnggDiffractionPresenterTest::g_focusedBankFile = - "ENGINX_241395_focused_texture_bank_1"; - -const std::string EnggDiffractionPresenterTest::g_focusedFittingRunNo = - "241391-241394"; - #endif // MANTID_CUSTOMINTERFACES_ENGGDIFFRACTIONPRESENTERTEST_H diff --git a/MantidQt/CustomInterfaces/test/EnggDiffractionViewMock.h b/MantidQt/CustomInterfaces/test/EnggDiffractionViewMock.h index d0956af59b7acfbc12d8cf9a46a8b6699c0a6e6d..70d8beebac5f2d4132d664314968e09c8f8fedea 100644 --- a/MantidQt/CustomInterfaces/test/EnggDiffractionViewMock.h +++ b/MantidQt/CustomInterfaces/test/EnggDiffractionViewMock.h @@ -6,6 +6,8 @@ #include <gmock/gmock.h> +class QwtData; + GCC_DIAG_OFF_SUGGEST_OVERRIDE // This is a simple mock for the tomo interface view when using SCARF. @@ -90,14 +92,19 @@ public: MOCK_METHOD3(newCalibLoaded, void(const std::string &, const std::string &, const std::string &)); + // virtual std::vector<GSASCalibrationParms> currentCalibration() const + MOCK_CONST_METHOD0( + currentCalibration, + std::vector<MantidQt::CustomInterfaces::GSASCalibrationParms>()); + // virtual std::string enggRunPythonCode(const std::string &pyCode) MOCK_METHOD1(enggRunPythonCode, std::string(const std::string &)); // virtual void enableTabs(bool enable); MOCK_METHOD1(enableTabs, void(bool)); - // virtual void enableCalibrateAndFocusActions(bool enable); - MOCK_METHOD1(enableCalibrateAndFocusActions, void(bool)); + // virtual void enableCalibrateFocusFitUserActions(bool enable); + MOCK_METHOD1(enableCalibrateFocusFitUserActions, void(bool)); // virtual std::string focusingDir() const; MOCK_CONST_METHOD0(focusingDir, std::string()); @@ -135,75 +142,9 @@ public: // virtual double rebinningPulsesPerPeriod() const; MOCK_CONST_METHOD0(rebinningPulsesTime, double()); - // virtual std::string fittingRunNo() const; - MOCK_CONST_METHOD0(getFittingRunNo, std::string()); - - // virtual std::string fittingPeaksData() const; - MOCK_CONST_METHOD0(fittingPeaksData, std::string()); - // virtual bool focusedOutWorkspace() const; MOCK_CONST_METHOD0(focusedOutWorkspace, bool()); - // virtual Splits the fitting directory if the ENGINX found - MOCK_METHOD1(splitFittingDirectory, - std::vector<std::string>(std::string &selectedfPath)); - - // adds the number of banks to the combo-box widget on the interface - MOCK_METHOD1(addBankItem, void(std::string bankID)); - - // adds the run number to the list view widget on the interface - MOCK_METHOD1(addRunNoItem, void(std::string runNo)); - - // emits the signal within view when run number / bank changed - MOCK_METHOD0(setBankEmit, void()); - - // sets the bank combo-box according to given index - MOCK_METHOD1(setBankIdComboBox, void(int idx)); - - // deletes all items from the fitting combo-box widget - MOCK_CONST_METHOD0(clearFittingComboBox, void()); - - // enables or disables the fitting combo-box - MOCK_CONST_METHOD1(enableFittingComboBox, void(bool enable)); - - // gets the index of the bank according to text found - MOCK_CONST_METHOD1(getFittingComboIdx, int(std::string bank)); - - // deletes all items from the fitting list widget - MOCK_CONST_METHOD0(clearFittingListWidget, void()); - - // enables or disables the fitting list widget - MOCK_CONST_METHOD1(enableFittingListWidget, void(bool enable)); - - // return idx of current selected row of list widget - MOCK_CONST_METHOD0(getFittingListWidgetCurrentRow, int()); - - // sets the current row of the fitting list widget - MOCK_CONST_METHOD1(setFittingListWidgetCurrentRow, void(int idx)); - - // sets the peak list according to the QString given - MOCK_CONST_METHOD1(setPeakList, void(std::string peakList)); - - // gets the set focus directory within the setting tab - MOCK_METHOD0(getFocusDir, std::string()); - - // gets the global vector in view containing focused file directory - MOCK_METHOD0(getFittingRunNumVec, std::vector<std::string>()); - - // sets the global vector in view containing focused file directory - MOCK_METHOD1(setFittingRunNumVec, void(std::vector<std::string> assignVec)); - - // sets the fitting run number according to path - MOCK_METHOD1(setFittingRunNo, void(QString path)); - - // To determine whether the current loop is multi-run or single to avoid - // regenerating the list - view widget when not required - MOCK_METHOD0(getFittingMultiRunMode, bool()); - - // sets the fitting mode to multi-run or single to avoid - // regenerating the list - view widget when not required - MOCK_METHOD1(setFittingMultiRunMode, void(bool mode)); - // virtual bool plotCalibWorkspace MOCK_CONST_METHOD0(plotCalibWorkspace, bool()); diff --git a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorAppendGroupCommand.h b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorAppendGroupCommand.h index 92ea727f07800316f95f324861bad913ad3c4cc5..c288990a45b7f27bf50ccc447af89ef73a6e1b62 100644 --- a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorAppendGroupCommand.h +++ b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorAppendGroupCommand.h @@ -10,7 +10,7 @@ namespace MantidWidgets { DataProcessorAppendGroupCommand defines the action "Insert Group" -Copyright © 2011-14 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge +Copyright © 2011-16 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge National Laboratory & European Spallation Source This file is part of Mantid. @@ -45,4 +45,4 @@ public: }; } } -#endif /*MANTIDQTMANTIDWIDGETS_DATAPROCESSORAPPENDGROUPCOMMAND_H*/ \ No newline at end of file +#endif /*MANTIDQTMANTIDWIDGETS_DATAPROCESSORAPPENDGROUPCOMMAND_H*/ diff --git a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorAppendRowCommand.h b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorAppendRowCommand.h index fb58d6e6ccc6dbd757d1ed9f6f133710670cec20..e113d5c9e7e49583169e3e5b654146039583a2ec 100644 --- a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorAppendRowCommand.h +++ b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorAppendRowCommand.h @@ -10,7 +10,7 @@ namespace MantidWidgets { DataProcessorAppendRowCommand defines the action "Insert Row After" -Copyright © 2011-14 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge +Copyright © 2011-16 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge National Laboratory & European Spallation Source This file is part of Mantid. @@ -45,4 +45,4 @@ public: }; } } -#endif /*MANTIDQTMANTIDWIDGETS_DATAPROCESSORAPPENDROWCOMMAND_H*/ \ No newline at end of file +#endif /*MANTIDQTMANTIDWIDGETS_DATAPROCESSORAPPENDROWCOMMAND_H*/ diff --git a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorClearSelectedCommand.h b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorClearSelectedCommand.h index 0c87af67fbc23fbca271b1af418c88f9f50b2994..92270dc1234a337acdc4f565a839eb7ec9ba3a9d 100644 --- a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorClearSelectedCommand.h +++ b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorClearSelectedCommand.h @@ -9,7 +9,7 @@ namespace MantidWidgets { DataProcessorClearSelectedCommand defines the action "Clear Selected" -Copyright © 2011-14 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge +Copyright © 2011-16 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge National Laboratory & European Spallation Source This file is part of Mantid. @@ -44,4 +44,4 @@ public: }; } } -#endif /*MANTIDQTMANTIDWIDGETS_DATAPROCESSORCLEARSELECTEDCOMMAND_H*/ \ No newline at end of file +#endif /*MANTIDQTMANTIDWIDGETS_DATAPROCESSORCLEARSELECTEDCOMMAND_H*/ diff --git a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorCommand.h b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorCommand.h index 3d242f04e31fe99029b5291b0594477ee17ecc70..f862282aa293a730d097d3c92d0892e9918b166a 100644 --- a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorCommand.h +++ b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorCommand.h @@ -10,10 +10,9 @@ namespace MantidWidgets { /** @class DataProcessorCommand DataProcessorCommand is an interface which defines the functions any data -processor -action needs to support. +processor action needs to support. -Copyright © 2011-14 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge +Copyright © 2011-16 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge National Laboratory & European Spallation Source This file is part of Mantid. @@ -60,4 +59,4 @@ protected: typedef std::unique_ptr<DataProcessorCommand> DataProcessorCommand_uptr; } } -#endif /*MANTIDQTMANTIDWIDGETS_DATAPROCESSORCOMMAND_H*/ \ No newline at end of file +#endif /*MANTIDQTMANTIDWIDGETS_DATAPROCESSORCOMMAND_H*/ diff --git a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorCopySelectedCommand.h b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorCopySelectedCommand.h index 0df84f2be9043bccd74442657ef56198017c2a34..c650005e6e8a03d31e5aaf4fadfc1fd590956fce 100644 --- a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorCopySelectedCommand.h +++ b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorCopySelectedCommand.h @@ -9,7 +9,7 @@ namespace MantidWidgets { DataProcessorCopySelectedCommand defines the action "Copy Selected" -Copyright © 2011-14 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge +Copyright © 2011-16 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge National Laboratory & European Spallation Source This file is part of Mantid. @@ -44,4 +44,4 @@ public: }; } } -#endif /*MANTIDQTMANTIDWIDGETS_DATAPROCESSORCOPYSELECTEDCOMMAND_H*/ \ No newline at end of file +#endif /*MANTIDQTMANTIDWIDGETS_DATAPROCESSORCOPYSELECTEDCOMMAND_H*/ diff --git a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorCutSelectedCommand.h b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorCutSelectedCommand.h index 0e0039827251b45d2f9637e6bc8d98f92ee5596e..a928ffd6a59d4b22b1b5d80b416248eaa4b2eeea 100644 --- a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorCutSelectedCommand.h +++ b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorCutSelectedCommand.h @@ -9,7 +9,7 @@ namespace MantidWidgets { DataProcessorCutSelectedCommand defines the action "Cut Selected" -Copyright © 2011-14 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge +Copyright © 2011-16 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge National Laboratory & European Spallation Source This file is part of Mantid. @@ -44,4 +44,4 @@ public: }; } } -#endif /*MANTIDQTMANTIDWIDGETS_DATAPROCESSORCUTSELECTEDCOMMAND_H*/ \ No newline at end of file +#endif /*MANTIDQTMANTIDWIDGETS_DATAPROCESSORCUTSELECTEDCOMMAND_H*/ diff --git a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorDeleteGroupCommand.h b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorDeleteGroupCommand.h index 8e82fd7fb79b2c766f9f1e96ecc2c3b7eae5d136..f5439df1ef82cdffa5378d2f3880dba11523bfaa 100644 --- a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorDeleteGroupCommand.h +++ b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorDeleteGroupCommand.h @@ -10,7 +10,7 @@ namespace MantidWidgets { DataProcessorDeleteGroupCommand defines the action "Delete Group" -Copyright © 2011-14 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge +Copyright © 2011-16 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge National Laboratory & European Spallation Source This file is part of Mantid. @@ -45,4 +45,4 @@ public: }; } } -#endif /*MANTIDQTMANTIDWIDGETS_DATAPROCESSORDELETEGROUPCOMMAND_H*/ \ No newline at end of file +#endif /*MANTIDQTMANTIDWIDGETS_DATAPROCESSORDELETEGROUPCOMMAND_H*/ diff --git a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorDeleteRowCommand.h b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorDeleteRowCommand.h index 082d8bee81a72a9b2af22a9f741a5c5c7284eae7..9563c50d86ca2554d9aef3e909cf0abbfac3643d 100644 --- a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorDeleteRowCommand.h +++ b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorDeleteRowCommand.h @@ -10,7 +10,7 @@ namespace MantidWidgets { DataProcessorDeleteRowCommand defines the action "Delete Row" -Copyright © 2011-14 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge +Copyright © 2011-16 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge National Laboratory & European Spallation Source This file is part of Mantid. @@ -45,4 +45,4 @@ public: }; } } -#endif /*MANTIDQTMANTIDWIDGETS_DATAPROCESSORDELETEROWCOMMAND_H*/ \ No newline at end of file +#endif /*MANTIDQTMANTIDWIDGETS_DATAPROCESSORDELETEROWCOMMAND_H*/ diff --git a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorExpandCommand.h b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorExpandCommand.h index 8e197707e03a4860efefaaedf87eeed3202ad402..f0ccee1d39c1c5c7d9ba500dc3a038c04b5e9966 100644 --- a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorExpandCommand.h +++ b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorExpandCommand.h @@ -9,7 +9,7 @@ namespace MantidWidgets { DataProcessorExpandCommand defines the action "Expand Selection" -Copyright © 2011-14 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge +Copyright © 2011-16 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge National Laboratory & European Spallation Source This file is part of Mantid. @@ -44,4 +44,4 @@ public: }; } } -#endif /*MANTIDQTMANTIDWIDGETS_DATAPROCESSOREXPANDCOMMAND_H*/ \ No newline at end of file +#endif /*MANTIDQTMANTIDWIDGETS_DATAPROCESSOREXPANDCOMMAND_H*/ diff --git a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorExportTableCommand.h b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorExportTableCommand.h index 466392d6cf1ba709319a9bf7cd75e6f2f271dfd8..75302adbcdc7813695b498131bef9afdd2e34727 100644 --- a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorExportTableCommand.h +++ b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorExportTableCommand.h @@ -11,7 +11,7 @@ DataProcessorExportTableCommand defines the action "Export .TBL" processor interface presenter needs to support. -Copyright © 2011-14 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge +Copyright © 2011-16 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge National Laboratory & European Spallation Source This file is part of Mantid. @@ -46,4 +46,4 @@ public: }; } } -#endif /*MANTIDQTMANTIDWIDGETS_DATAPROCESSOREXPORTTABLECOMMAND_H*/ \ No newline at end of file +#endif /*MANTIDQTMANTIDWIDGETS_DATAPROCESSOREXPORTTABLECOMMAND_H*/ diff --git a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorGroupRowsCommand.h b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorGroupRowsCommand.h index f2319e69c59d966749aadf9c893407cb471a73f8..f8a3fb6023804f771efb7b674dd41bd4236c7630 100644 --- a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorGroupRowsCommand.h +++ b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorGroupRowsCommand.h @@ -9,7 +9,7 @@ namespace MantidWidgets { DataProcessorGroupRowsCommand defines the action "Group Selected" -Copyright © 2011-14 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge +Copyright © 2011-16 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge National Laboratory & European Spallation Source This file is part of Mantid. @@ -44,4 +44,4 @@ public: }; } } -#endif /*MANTIDQTMANTIDWIDGETS_DATAPROCESSORGROUPROWSCOMMAND_H*/ \ No newline at end of file +#endif /*MANTIDQTMANTIDWIDGETS_DATAPROCESSORGROUPROWSCOMMAND_H*/ diff --git a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorImportTableCommand.h b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorImportTableCommand.h index 01386c8e5f636ad332a6540f8f5cc7c55ae328f9..09c8f26064519f909f9b3a401d1abc0dd3708885 100644 --- a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorImportTableCommand.h +++ b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorImportTableCommand.h @@ -9,7 +9,7 @@ namespace MantidWidgets { DataProcessorImportTableCommand defines the action "Import .TBL" -Copyright © 2011-14 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge +Copyright © 2011-16 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge National Laboratory & European Spallation Source This file is part of Mantid. @@ -44,4 +44,4 @@ public: }; } } -#endif /*MANTIDQTMANTIDWIDGETS_DATAPROCESSORIMPORTTABLECOMMAND_H*/ \ No newline at end of file +#endif /*MANTIDQTMANTIDWIDGETS_DATAPROCESSORIMPORTTABLECOMMAND_H*/ diff --git a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorNewTableCommand.h b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorNewTableCommand.h index fde681d0742e5679f795d3b16d3a787c61351162..91e74b6e5961f99cb871aac09d1e770a330987f2 100644 --- a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorNewTableCommand.h +++ b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorNewTableCommand.h @@ -9,7 +9,7 @@ namespace MantidWidgets { DataProcessorNewTableCommand defines the action "New Table" -Copyright © 2011-14 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge +Copyright © 2011-16 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge National Laboratory & European Spallation Source This file is part of Mantid. @@ -44,4 +44,4 @@ public: }; } } -#endif /*MANTIDQTMANTIDWIDGETS_DATAPROCESSORNEWTABLECOMMAND_H*/ \ No newline at end of file +#endif /*MANTIDQTMANTIDWIDGETS_DATAPROCESSORNEWTABLECOMMAND_H*/ diff --git a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorOpenTableCommand.h b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorOpenTableCommand.h index b960a08fc86c9cc8dd4f5b20708f33080642bad9..cd09308792bf64383907bb0e5c7a74190d8055e8 100644 --- a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorOpenTableCommand.h +++ b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorOpenTableCommand.h @@ -9,7 +9,7 @@ namespace MantidWidgets { DataProcessorOpenTableCommand defines the action "Open Table" -Copyright © 2011-14 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge +Copyright © 2011-16 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge National Laboratory & European Spallation Source This file is part of Mantid. @@ -44,4 +44,4 @@ public: }; } } -#endif /*MANTIDQTMANTIDWIDGETS_DATAPROCESSOROPENTABLECOMMAND_H*/ \ No newline at end of file +#endif /*MANTIDQTMANTIDWIDGETS_DATAPROCESSOROPENTABLECOMMAND_H*/ diff --git a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorOptionsCommand.h b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorOptionsCommand.h index 5f47213330390735b538c2864ab88bcada46a8dc..be6a3e760c7e39400c8a2d2508f1dcc0b3818217 100644 --- a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorOptionsCommand.h +++ b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorOptionsCommand.h @@ -9,7 +9,7 @@ namespace MantidWidgets { DataProcessorOptionsCommand defines the action "Import .TBL" -Copyright © 2011-14 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge +Copyright © 2011-16 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge National Laboratory & European Spallation Source This file is part of Mantid. @@ -44,4 +44,4 @@ public: }; } } -#endif /*MANTIDQTMANTIDWIDGETS_DATAPROCESSOROPTIONSTABLECOMMAND_H*/ \ No newline at end of file +#endif /*MANTIDQTMANTIDWIDGETS_DATAPROCESSOROPTIONSTABLECOMMAND_H*/ diff --git a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorPasteSelectedCommand.h b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorPasteSelectedCommand.h index 04ce9387f15fda1a6c05f00c3515f2624b0064be..bd95252faabe29c0148d441749259e9cbb80c81b 100644 --- a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorPasteSelectedCommand.h +++ b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorPasteSelectedCommand.h @@ -9,7 +9,7 @@ namespace MantidWidgets { DataProcessorPasteSelectedCommand defines the action "Paste Selected" -Copyright © 2011-14 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge +Copyright © 2011-16 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge National Laboratory & European Spallation Source This file is part of Mantid. @@ -44,4 +44,4 @@ public: }; } } -#endif /*MANTIDQTMANTIDWIDGETS_DATAPROCESSORPASTESELECTEDCOMMAND_H*/ \ No newline at end of file +#endif /*MANTIDQTMANTIDWIDGETS_DATAPROCESSORPASTESELECTEDCOMMAND_H*/ diff --git a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorPlotGroupCommand.h b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorPlotGroupCommand.h index 4df37ca733d1fe47c6f860b29d0317fa3c278314..b18566abf28ea5e9724392e1a765b955f4b5e121 100644 --- a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorPlotGroupCommand.h +++ b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorPlotGroupCommand.h @@ -9,7 +9,7 @@ namespace MantidWidgets { DataProcessorPlotGroupCommand defines the action "Plot Selected Groups" -Copyright © 2011-14 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge +Copyright © 2011-16 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge National Laboratory & European Spallation Source This file is part of Mantid. @@ -44,4 +44,4 @@ public: }; } } -#endif /*MANTIDQTMANTIDWIDGETS_DATAPROCESSORPLOTGROUPCOMMAND_H*/ \ No newline at end of file +#endif /*MANTIDQTMANTIDWIDGETS_DATAPROCESSORPLOTGROUPCOMMAND_H*/ diff --git a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorPlotRowCommand.h b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorPlotRowCommand.h index 052766aac290e124a9f6ae19f582d3ee93d374a8..1a0c6f3c67132072738bc8431400758d16c63be7 100644 --- a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorPlotRowCommand.h +++ b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorPlotRowCommand.h @@ -9,7 +9,7 @@ namespace MantidWidgets { DataProcessorPlotRowCommand defines the action "Plot Selected Rows" -Copyright © 2011-14 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge +Copyright © 2011-16 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge National Laboratory & European Spallation Source This file is part of Mantid. @@ -44,4 +44,4 @@ public: }; } } -#endif /*MANTIDQTMANTIDWIDGETS_DATAPROCESSORPLOTROWCOMMAND_H*/ \ No newline at end of file +#endif /*MANTIDQTMANTIDWIDGETS_DATAPROCESSORPLOTROWCOMMAND_H*/ diff --git a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorProcessCommand.h b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorProcessCommand.h index f0d6e20ac55b22af9e90d02131bc804ad6db04c8..03f7ce1c27af1cf679f85d2c8303d26649100593 100644 --- a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorProcessCommand.h +++ b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorProcessCommand.h @@ -9,7 +9,7 @@ namespace MantidWidgets { DataProcessorProcessCommand defines the action "Process" -Copyright © 2011-14 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge +Copyright © 2011-16 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge National Laboratory & European Spallation Source This file is part of Mantid. @@ -44,4 +44,4 @@ public: }; } } -#endif /*MANTIDQTMANTIDWIDGETS_DATAPROCESSORPROCESSCOMMAND_H*/ \ No newline at end of file +#endif /*MANTIDQTMANTIDWIDGETS_DATAPROCESSORPROCESSCOMMAND_H*/ diff --git a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorSaveTableAsCommand.h b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorSaveTableAsCommand.h index e00c8ca16484f42799d292d6012939d4aec94b41..ccb14070295a578b4d3a38ce2643a2ae24c0c6f4 100644 --- a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorSaveTableAsCommand.h +++ b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorSaveTableAsCommand.h @@ -9,7 +9,7 @@ namespace MantidWidgets { DataProcessorSaveTableAsCommand defines the action "Save Table As" -Copyright © 2011-14 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge +Copyright © 2011-16 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge National Laboratory & European Spallation Source This file is part of Mantid. @@ -44,4 +44,4 @@ public: }; } } -#endif /*MANTIDQTMANTIDWIDGETS_DATAPROCESSORSAVETABLEASCOMMAND_H*/ \ No newline at end of file +#endif /*MANTIDQTMANTIDWIDGETS_DATAPROCESSORSAVETABLEASCOMMAND_H*/ diff --git a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorSaveTableCommand.h b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorSaveTableCommand.h index 74bf105a1a35fef4652c6e857ad350566afa637b..e96c7808e67cb0553aa34ba1079a534cea81f96d 100644 --- a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorSaveTableCommand.h +++ b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorSaveTableCommand.h @@ -9,7 +9,7 @@ namespace MantidWidgets { DataProcessorSaveTableCommand defines the action "Save Table" -Copyright © 2011-14 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge +Copyright © 2011-16 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge National Laboratory & European Spallation Source This file is part of Mantid. @@ -44,4 +44,4 @@ public: }; } } -#endif /*MANTIDQTMANTIDWIDGETS_DATAPROCESSORSAVETABLECOMMAND_H*/ \ No newline at end of file +#endif /*MANTIDQTMANTIDWIDGETS_DATAPROCESSORSAVETABLECOMMAND_H*/ diff --git a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorSeparatorCommand.h b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorSeparatorCommand.h index 17fefb19454124118f5419f1e67ebdf6305967f5..4234d01032ed56da076ebe32e6075f9619c6faf8 100644 --- a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorSeparatorCommand.h +++ b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorSeparatorCommand.h @@ -11,7 +11,7 @@ DataProcessorSeparatorCommand defines a separator. It has no name, no icon and empty execute() method -Copyright © 2011-14 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge +Copyright © 2011-16 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge National Laboratory & European Spallation Source This file is part of Mantid. @@ -44,4 +44,4 @@ public: }; } } -#endif /*MANTIDQTMANTIDWIDGETS_DATAPROCESSORSEPARATORCOMMAND_H*/ \ No newline at end of file +#endif /*MANTIDQTMANTIDWIDGETS_DATAPROCESSORSEPARATORCOMMAND_H*/ diff --git a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorWorkspaceCommand.h b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorWorkspaceCommand.h index e4abca0ec333dc8e085b0a01adecb9c632e011bc..84670355d6c61998a720461bf72ccf6d387e5cd0 100644 --- a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorWorkspaceCommand.h +++ b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorWorkspaceCommand.h @@ -9,7 +9,7 @@ namespace MantidWidgets { DataProcessorWorkspaceCommand defines a workspace action -Copyright © 2011-14 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge +Copyright © 2011-16 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge National Laboratory & European Spallation Source This file is part of Mantid. @@ -51,4 +51,4 @@ private: }; } } -#endif /*MANTIDQTMANTIDWIDGETS_DATAPROCESSORWORKSPACECOMMAND_H*/ \ No newline at end of file +#endif /*MANTIDQTMANTIDWIDGETS_DATAPROCESSORWORKSPACECOMMAND_H*/ diff --git a/MantidQt/MantidWidgets/src/DataProcessorUI/DataProcessorGenerateNotebook.cpp b/MantidQt/MantidWidgets/src/DataProcessorUI/DataProcessorGenerateNotebook.cpp index 3d3fe8f7fc95809d3a518a83da713d6899ee6092..4da117847ea9aa465e1baf9e15735e37f537748e 100644 --- a/MantidQt/MantidWidgets/src/DataProcessorUI/DataProcessorGenerateNotebook.cpp +++ b/MantidQt/MantidWidgets/src/DataProcessorUI/DataProcessorGenerateNotebook.cpp @@ -86,10 +86,10 @@ std::string DataProcessorGenerateNotebook::generateNotebook( notebook->markdownCell(tableString(m_model, m_whitelist, rows)); - for (auto gIt = rows.begin(); gIt != rows.end(); ++gIt) { + for (const auto &item : rows) { - const int groupId = gIt->first; - const std::set<int> rowSet = gIt->second; + const int groupId = item.first; + const std::set<int> rowSet = item.second; /** Announce the stitch group in the notebook **/ @@ -106,11 +106,11 @@ std::string DataProcessorGenerateNotebook::generateNotebook( // workspaces std::vector<std::string> output_ws; - for (auto rIt = rowSet.begin(); rIt != rowSet.end(); ++rIt) { + for (const auto &row : rowSet) { code_string << "#Load and reduce\n"; auto reduce_row_string = reduceRowString( - groupId, *rIt, m_instrument, m_model, m_whitelist, m_preprocessMap, + groupId, row, m_instrument, m_model, m_whitelist, m_preprocessMap, m_processor, m_preprocessingOptionsMap, m_processingOptions); // The reduction code code_string << boost::get<0>(reduce_row_string); @@ -211,7 +211,7 @@ std::string plotsString(const std::vector<std::string> &output_ws, std::vector<std::string> wsNames; // Iterate through the elements of output_ws - for (auto &outws : output_ws) { + for (const auto &outws : output_ws) { auto workspaces = splitByCommas(outws); @@ -259,24 +259,24 @@ std::string tableString(QDataProcessorTreeModel_sptr model, table_string << "---" << "\n"; - for (auto groupIt = rows.begin(); groupIt != rows.end(); ++groupIt) { + for (const auto &item : rows) { - auto groupId = groupIt->first; - auto rowSet = groupIt->second; + auto groupId = item.first; + auto rowSet = item.second; - for (auto rowIt = rowSet.begin(); rowIt != rowSet.end(); ++rowIt) { + for (const auto &row : rowSet) { table_string << model->data(model->index(groupId, 0)).toString().toStdString(); table_string << " | "; for (int col = 0; col < ncols - 1; col++) - table_string << model->data(model->index(*rowIt, col, + table_string << model->data(model->index(row, col, model->index(groupId, 0))) .toString() .toStdString() << " | "; - table_string << model->data(model->index(*rowIt, ncols - 1, + table_string << model->data(model->index(row, ncols - 1, model->index(groupId, 0))) .toString() .toStdString() << "\n"; @@ -314,13 +314,13 @@ boost::tuple<std::string, std::string> postprocessGroupString( std::vector<std::string> outputName; // Go through each row and prepare the input and output properties - for (auto groupIt = groups.begin(); groupIt != groups.end(); ++groupIt) { + for (const auto &group : groups) { - int nrows = model->rowCount(model->index(*groupIt, 0)); + int nrows = model->rowCount(model->index(group, 0)); for (int row = 0; row < nrows; row++) { // The reduced ws name without prefix (for example 'TOF_13460_13462') - auto suffix = getReducedWorkspaceName(*groupIt, row, model, whitelist); + auto suffix = getReducedWorkspaceName(group, row, model, whitelist); // The reduced ws name: 'IvsQ_TOF_13460_13462' inputNames.emplace_back(processor.prefix(0) + suffix); @@ -565,8 +565,8 @@ loadWorkspaceString(const std::string &runStr, const std::string &instrument, std::ostringstream load_strings; // Remove leading/trailing whitespace from each run - for (auto runIt = runs.begin(); runIt != runs.end(); ++runIt) - boost::trim(*runIt); + for (auto &run : runs) + boost::trim(run); const std::string prefix = preprocessor.prefix(); const std::string outputName = prefix + boost::algorithm::join(runs, "_"); diff --git a/MantidQt/MantidWidgets/src/DataProcessorUI/GenericDataProcessorPresenter.cpp b/MantidQt/MantidWidgets/src/DataProcessorUI/GenericDataProcessorPresenter.cpp index c8164b7f58a1ba143b60a9818cb181139e17ccda..375911f8fce7e0402e4c3dc0b995aea081d5ba7c 100644 --- a/MantidQt/MantidWidgets/src/DataProcessorUI/GenericDataProcessorPresenter.cpp +++ b/MantidQt/MantidWidgets/src/DataProcessorUI/GenericDataProcessorPresenter.cpp @@ -253,24 +253,26 @@ void GenericDataProcessorPresenter::process() { } else { // They may have selected a group, in this case we want to process and // post-process the whole group, so populate group with every row - for (auto idxGroup = groups.begin(); idxGroup != groups.end(); ++idxGroup) { - for (int row = 0; row < numRowsInGroup(*idxGroup); row++) - rows[*idxGroup].insert(row); + for (const auto &group : groups) { + for (int row = 0; row < numRowsInGroup(group); row++) + rows[group].insert(row); } } // Check each group and warn if we're only partially processing it - for (auto gIt = rows.begin(); gIt != rows.end(); ++gIt) { + for (const auto &item : rows) { - const int &groupId = gIt->first; - const std::set<int> &rowIds = gIt->second; + const int &groupId = item.first; + const std::set<int> &rowIds = item.second; // Are we only partially processing a group? - if (static_cast<int>(rowIds.size()) < numRowsInGroup(gIt->first) && + if (static_cast<int>(rowIds.size()) < numRowsInGroup(groupId) && m_options["WarnProcessPartialGroup"].toBool()) { + const std::string groupName = + m_model->data(m_model->index(groupId, 0)).toString().toStdString(); std::stringstream err; err << "You have only selected " << rowIds.size() << " of the "; - err << numRowsInGroup(groupId) << " rows in group " << groupId << "."; + err << numRowsInGroup(groupId) << " rows in group '" << groupName << "'."; err << " Are you sure you want to continue?"; if (!m_mainPresenter->askUserYesNo(err.str(), "Continue Processing?")) return; @@ -410,13 +412,13 @@ bool GenericDataProcessorPresenter::processGroups( auto rows = it->second; // Reduce each row - for (auto rIt = rows.begin(); rIt != rows.end(); ++rIt) { + for (const auto &row : rows) { try { - reduceRow(groupId, *rIt); + reduceRow(groupId, row); progressReporter.report(); } catch (std::exception &ex) { const std::string rowNo = - Mantid::Kernel::Strings::toString<int>(*rIt + 1); + Mantid::Kernel::Strings::toString<int>(row + 1); const std::string groupNo = Mantid::Kernel::Strings::toString<int>(groupId); const std::string message = "Error encountered while processing row " + @@ -928,7 +930,7 @@ void GenericDataProcessorPresenter::groupRows() { // If they don't, remove rows from their groups and add them to a // new group - auto selectedRows = m_view->getSelectedRows(); + const auto selectedRows = m_view->getSelectedRows(); if (selectedRows.size() < 2) { // Rows belong to the same group (size == 1) or @@ -942,20 +944,20 @@ void GenericDataProcessorPresenter::groupRows() { appendGroup(); // Append as many rows as the number of selected rows minus one int rowsToAppend = -1; - for (auto it = selectedRows.begin(); it != selectedRows.end(); ++it) - rowsToAppend += static_cast<int>(it->second.size()); + for (const auto &row : selectedRows) + rowsToAppend += static_cast<int>(row.second.size()); for (int i = 0; i < rowsToAppend; i++) insertRow(groupId, i); // Now we just have to set the data int rowIndex = 0; - for (auto it = selectedRows.begin(); it != selectedRows.end(); ++it) { - int oldGroupId = it->first; - auto rows = it->second; - for (auto row = rows.begin(); row != rows.end(); ++row) { + for (const auto &item : selectedRows) { + int oldGroupId = item.first; + auto rows = item.second; + for (const auto &row : rows) { for (int col = 0; col < m_columns; col++) { auto value = m_model->data( - m_model->index(*row, col, m_model->index(oldGroupId, 0))); + m_model->index(row, col, m_model->index(oldGroupId, 0))); m_model->setData( m_model->index(rowIndex, col, m_model->index(groupId, 0)), value); } @@ -1261,16 +1263,15 @@ void GenericDataProcessorPresenter::expandSelection() { /** Clear the currently selected rows */ void GenericDataProcessorPresenter::clearSelected() { - auto selectedRows = m_view->getSelectedRows(); + const auto selectedRows = m_view->getSelectedRows(); - for (auto group = selectedRows.begin(); group != selectedRows.end(); - ++group) { - int groupIndex = group->first; - auto rows = group->second; - for (auto row = rows.begin(); row != rows.end(); ++row) { + for (const auto &item : selectedRows) { + int group = item.first; + auto rows = item.second; + for (const auto &row : rows) { for (auto col = 0; col < m_model->columnCount(); col++) - m_model->setData( - m_model->index(*row, col, m_model->index(groupIndex, 0)), ""); + m_model->setData(m_model->index(row, col, m_model->index(group, 0)), + ""); } } m_tableDirty = true; @@ -1280,18 +1281,18 @@ void GenericDataProcessorPresenter::clearSelected() { void GenericDataProcessorPresenter::copySelected() { std::vector<std::string> lines; - auto selectedRows = m_view->getSelectedRows(); - for (auto it = selectedRows.begin(); it != selectedRows.end(); ++it) { - const int groupId = it->first; - auto rows = it->second; + const auto selectedRows = m_view->getSelectedRows(); + for (const auto &item : selectedRows) { + const int group = item.first; + auto rows = item.second; - for (auto row = rows.begin(); row != rows.end(); ++row) { + for (const auto &row : rows) { std::vector<std::string> line; - line.push_back(std::to_string(groupId)); + line.push_back(std::to_string(group)); for (int col = 0; col < m_columns; ++col) { line.push_back( - m_model->data(m_model->index(*row, col, m_model->index(groupId, 0))) + m_model->data(m_model->index(row, col, m_model->index(group, 0))) .toString() .toStdString()); } @@ -1318,7 +1319,7 @@ void GenericDataProcessorPresenter::pasteSelected() { // If we have rows selected, we'll overwrite them. If not, we'll append new // rows. - auto selectedRows = m_view->getSelectedRows(); + const auto selectedRows = m_view->getSelectedRows(); if (selectedRows.empty()) { // No rows were selected // Use group where rows in clipboard belong and paste new rows to it diff --git a/MantidQt/MantidWidgets/test/DataProcessorUI/DataProcessorGenerateNotebookTest.h b/MantidQt/MantidWidgets/test/DataProcessorUI/DataProcessorGenerateNotebookTest.h index 78deeafcd775b9e34fd9f38c66190d17cef934ac..4d6e9b23847ddbcdabe235efaf4a9a04c9d0c370 100644 --- a/MantidQt/MantidWidgets/test/DataProcessorUI/DataProcessorGenerateNotebookTest.h +++ b/MantidQt/MantidWidgets/test/DataProcessorUI/DataProcessorGenerateNotebookTest.h @@ -229,9 +229,8 @@ public: "1 | 24682 | 1.5 | | 1.4 | 2.9 | 0.04 | 1 | ", ""}; int i = 0; - for (auto it = notebookLines.begin(); it != notebookLines.end(); - ++it, ++i) { - TS_ASSERT_EQUALS(*it, result[i]) + for (const auto &line : notebookLines) { + TS_ASSERT_EQUALS(line, result[i++]) } } @@ -267,9 +266,8 @@ public: boost::split(notebookLines, output, boost::is_any_of("\n")); int i = 0; - for (auto it = notebookLines.begin(); it != notebookLines.end(); - ++it, ++i) { - TS_ASSERT_EQUALS(*it, result[i]) + for (const auto &line : notebookLines) { + TS_ASSERT_EQUALS(line, result[i++]) } // Test without workspace name @@ -282,9 +280,8 @@ public: boost::split(notebookLinesEmptyStr, outputEmptyStr, boost::is_any_of("\n")); i = 0; - for (auto it = notebookLinesEmptyStr.begin(); - it != notebookLinesEmptyStr.end(); ++it, ++i) { - TS_ASSERT_EQUALS(*it, resultEmptyStr[i]) + for (const auto &line : notebookLinesEmptyStr) { + TS_ASSERT_EQUALS(line, resultEmptyStr[i++]) } } @@ -320,9 +317,8 @@ public: boost::split(notebookLines, boost::get<0>(output), boost::is_any_of("\n")); int i = 0; - for (auto it = notebookLines.begin(); it != notebookLines.end(); - ++it, ++i) { - TS_ASSERT_EQUALS(*it, result[i]) + for (const auto &line : notebookLines) { + TS_ASSERT_EQUALS(line, result[i++]) } } @@ -355,9 +351,8 @@ public: boost::split(notebookLines, output, boost::is_any_of("\n")); int i = 0; - for (auto it = notebookLines.begin(); it != notebookLines.end(); - ++it, ++i) { - TS_ASSERT_EQUALS(*it, result[i]) + for (const auto &line : notebookLines) { + TS_ASSERT_EQUALS(line, result[i++]) } } @@ -383,9 +378,8 @@ public: boost::split(notebookLines, boost::get<0>(output), boost::is_any_of("\n")); int i = 0; - for (auto it = notebookLines.begin(); it != notebookLines.end(); - ++it, ++i) { - TS_ASSERT_EQUALS(*it, result[i]) + for (const auto &line : notebookLines) { + TS_ASSERT_EQUALS(line, result[i++]) } } @@ -415,9 +409,8 @@ public: boost::split(notebookLines, boost::get<0>(output), boost::is_any_of("\n")); int i = 0; - for (auto it = notebookLines.begin(); it != notebookLines.end(); - ++it, ++i) { - TS_ASSERT_EQUALS(*it, result[i]) + for (const auto &line : notebookLines) { + TS_ASSERT_EQUALS(line, result[i++]) } } diff --git a/MantidQt/Python/sip_mantidqt.cpp.in b/MantidQt/Python/sip_mantidqt.cpp.in index 7574d01d9ba250aa3c56292978eb69d3b89b1768..e7a4e84085b676cbf1474630aa9b456e410e258e 100644 --- a/MantidQt/Python/sip_mantidqt.cpp.in +++ b/MantidQt/Python/sip_mantidqt.cpp.in @@ -10,4 +10,13 @@ // special debugging build of the Python library. #include <boost/python/detail/wrap_python.hpp> + +#if defined(__GNUC__) && !defined(__clang__) +#pragma GCC visibility push(default) +#endif + #include "sipmantidqtpythonpart0.cpp" + +#if defined(__GNUC__) && !defined(__clang__) +#pragma GCC visibility pop +#endif diff --git a/MantidQt/SliceViewer/inc/MantidQtSliceViewer/PeakPalette.h b/MantidQt/SliceViewer/inc/MantidQtSliceViewer/PeakPalette.h index f6a038683fec5f61cf1dfad452482694a4aead34..b211476fba58fd10bd97a9b5c3ceee0a25611849 100644 --- a/MantidQt/SliceViewer/inc/MantidQtSliceViewer/PeakPalette.h +++ b/MantidQt/SliceViewer/inc/MantidQtSliceViewer/PeakPalette.h @@ -130,8 +130,8 @@ bool PeakPalette<C>::operator==(const PeakPalette &other) const { } // Forward declaration for template specialization -template <> PeakPalette<QColor>::PeakPalette(); -template <> PeakPalette<PeakViewColor>::PeakPalette(); +template <> DLLExport PeakPalette<QColor>::PeakPalette(); +template <> DLLExport PeakPalette<PeakViewColor>::PeakPalette(); } // namespace } diff --git a/QtPropertyBrowser/CMakeLists.txt b/QtPropertyBrowser/CMakeLists.txt index 7b55adf73368ac84a06ef3e2960cfe92a39af92d..b319d08c68980dc46f48b913fb914016b10ee475 100644 --- a/QtPropertyBrowser/CMakeLists.txt +++ b/QtPropertyBrowser/CMakeLists.txt @@ -133,9 +133,13 @@ endif () target_link_libraries ( ${PROJECT_NAME} LINK_PRIVATE ${TCMALLOC_LIBRARIES_LINKTIME} ${QT_LIBRARIES} ) -if ( WIN32 ) + +if(WIN32) + add_definitions ( -DQT_QTPROPERTYBROWSER_EXPORT ) +elseif(CMAKE_COMPILER_IS_GNUCXX) add_definitions ( -DQT_QTPROPERTYBROWSER_EXPORT ) -endif ( WIN32 ) +endif() + # This is, for the most part, not our code so disable an Intel compiler # warning that crops up a lot in this package diff --git a/QtPropertyBrowser/src/qtpropertybrowser.h b/QtPropertyBrowser/src/qtpropertybrowser.h index a5586d0e21de4bc69351cce01d696dcd5950500e..d3f01f37957c7ac4f4c2883b6f9daf11d8201133 100644 --- a/QtPropertyBrowser/src/qtpropertybrowser.h +++ b/QtPropertyBrowser/src/qtpropertybrowser.h @@ -95,7 +95,7 @@ QT_BEGIN_NAMESPACE #endif -#if defined(Q_WS_WIN) +#if defined(Q_OS_WIN) # if !defined(QT_QTPROPERTYBROWSER_EXPORT) && !defined(QT_QTPROPERTYBROWSER_IMPORT) # define QT_QTPROPERTYBROWSER_EXPORT # elif defined(QT_QTPROPERTYBROWSER_IMPORT) @@ -107,6 +107,18 @@ QT_BEGIN_NAMESPACE # undef QT_QTPROPERTYBROWSER_EXPORT # define QT_QTPROPERTYBROWSER_EXPORT __declspec(dllexport) # endif +#elif defined(Q_OS_LINUX) +# if !defined(QT_QTPROPERTYBROWSER_EXPORT) && !defined(QT_QTPROPERTYBROWSER_IMPORT) +# define QT_QTPROPERTYBROWSER_EXPORT +# elif defined(QT_QTPROPERTYBROWSER_IMPORT) +# if defined(QT_QTPROPERTYBROWSER_EXPORT) +# undef QT_QTPROPERTYBROWSER_EXPORT +# endif +# define QT_QTPROPERTYBROWSER_EXPORT +# elif defined(QT_QTPROPERTYBROWSER_EXPORT) +# undef QT_QTPROPERTYBROWSER_EXPORT +# define QT_QTPROPERTYBROWSER_EXPORT __attribute__ ((visibility ("default"))) +# endif #else # define QT_QTPROPERTYBROWSER_EXPORT #endif diff --git a/Testing/Data/SystemTest/osiris97944_graphite002_red.nxs.md5 b/Testing/Data/SystemTest/osiris97944_graphite002_red.nxs.md5 new file mode 100644 index 0000000000000000000000000000000000000000..1fe030df3a9b6b216d1661eaf8b3519f641c16a2 --- /dev/null +++ b/Testing/Data/SystemTest/osiris97944_graphite002_red.nxs.md5 @@ -0,0 +1 @@ +8c431c304cde7d4af57f0bc4991a5ea4 diff --git a/Testing/SystemTests/tests/analysis/ISISIndirectInelastic.py b/Testing/SystemTests/tests/analysis/ISISIndirectInelastic.py index 8c6393919f47fe641c5b0c059ea8f47ccc7f8a50..3c0297ab7ac596745111c698f2aae8bde4158bde 100644 --- a/Testing/SystemTests/tests/analysis/ISISIndirectInelastic.py +++ b/Testing/SystemTests/tests/analysis/ISISIndirectInelastic.py @@ -1013,37 +1013,33 @@ class ISISIndirectInelasticIqtAndIqtFitMulti(ISISIndirectInelasticBase): class OSIRISIqtAndIqtFitMulti(ISISIndirectInelasticIqtAndIqtFitMulti): def skipTests(self): - operating_sys = platform.system() - # Skip Test on Windows and OSX - if operating_sys == "Darwin" or operating_sys == "Windows": + # Skip Test OSX + if platform.system() == "Darwin": return True def __init__(self): ISISIndirectInelasticIqtAndIqtFitMulti.__init__(self) # TransformToIqt - self.samples = ['osi97935_graphite002_red.nxs'] + self.samples = ['osiris97944_graphite002_red.nxs'] self.resolution = 'osi97935_graphite002_res.nxs' self.e_min = -0.4 self.e_max = 0.4 self.num_bins = 4 # Iqt Fit - self.func = r'name=LinearBackground,A0=0.510595,A1=0,ties=(A1=0);name=UserFunction,Formula=Intensity*exp( -(x/Tau)^Beta),'\ - 'Intensity=0.489405,Tau=0.105559,Beta=1.61112e-14;ties=(f1.Intensity=1-f0.A0)' + self.func = r'name=LinearBackground,A0=0.213439,A1=0,ties=(A1=0);name=UserFunction,'\ + 'Formula=Intensity*exp(-(x/Tau)^Beta),Intensity=0.786561,Tau=0.0247894,'\ + 'Beta=1;ties=(f1.Intensity=1-f0.A0)' self.ftype = '1E_s' self.startx = 0.0 - self.endx = 0.119681 + self.endx = 0.12 self.spec_min = 0 self.spec_max = 41 def get_reference_files(self): - ref_files = ['II.OSIRISFury.nxs'] - if platform.system() == "Windows": - ref_files += ['II.OSIRISFuryFitMulti_win.nxs'] - else: - ref_files += ['II.OSIRISFuryFitMulti_lin.nxs'] - return ref_files + return ['II.OSIRISIqt.nxs', + 'II.OSIRISIqtFitMulti.nxs'] #------------------------- IRIS tests ----------------------------------------- diff --git a/Testing/SystemTests/tests/analysis/reference/II.OSIRISIqt.nxs.md5 b/Testing/SystemTests/tests/analysis/reference/II.OSIRISIqt.nxs.md5 new file mode 100644 index 0000000000000000000000000000000000000000..b3e62099f579e6df9315e9a9ad4c610035eca41a --- /dev/null +++ b/Testing/SystemTests/tests/analysis/reference/II.OSIRISIqt.nxs.md5 @@ -0,0 +1 @@ +5cf2d9f68b600408319cbea8cc274351 diff --git a/Testing/SystemTests/tests/analysis/reference/II.OSIRISIqtFitMulti.nxs.md5 b/Testing/SystemTests/tests/analysis/reference/II.OSIRISIqtFitMulti.nxs.md5 new file mode 100644 index 0000000000000000000000000000000000000000..028c3607761993215e58e4a84a9337a2b339c25b --- /dev/null +++ b/Testing/SystemTests/tests/analysis/reference/II.OSIRISIqtFitMulti.nxs.md5 @@ -0,0 +1 @@ +66d56e31c925e9cba84ae18f8115c174 diff --git a/Testing/Tools/CMakeLists.txt b/Testing/Tools/CMakeLists.txt index 27c1f014e676027dc7b2cd06ee38b2f4f8ce16fc..c26a5adb4aca3547b1eadf25fcce2f8389d859e5 100644 --- a/Testing/Tools/CMakeLists.txt +++ b/Testing/Tools/CMakeLists.txt @@ -15,7 +15,7 @@ elseif(CMAKE_COMPILER_IS_GNUCXX) string(REPLACE "-Wsuggest-override" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") endif() -if (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang") +if (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-missing-field-initializers" ) endif() diff --git a/Testing/Tools/gmock-1.7.0/CMakeLists.txt b/Testing/Tools/gmock-1.7.0/CMakeLists.txt index 572d0444bf14834b1fde7f3e7398638cf4e4b7ce..aa60cba07323445920a8452b224f0d3dfdc6c01b 100644 --- a/Testing/Tools/gmock-1.7.0/CMakeLists.txt +++ b/Testing/Tools/gmock-1.7.0/CMakeLists.txt @@ -38,7 +38,7 @@ endif() # ${gmock_BINARY_DIR}. # Language "C" is required for find_package(Threads). project(gmock CXX C) -cmake_minimum_required(VERSION 2.6.2) +cmake_minimum_required(VERSION 3.5) if (COMMAND set_up_hermetic_build) set_up_hermetic_build() diff --git a/Testing/Tools/gmock-1.7.0/gtest/CMakeLists.txt b/Testing/Tools/gmock-1.7.0/gtest/CMakeLists.txt index 57470c84f3af0772c411bbb8bbbb41b515747ecd..b49273ae4da21642e83a0c3d59d5c9fb6a370ad3 100644 --- a/Testing/Tools/gmock-1.7.0/gtest/CMakeLists.txt +++ b/Testing/Tools/gmock-1.7.0/gtest/CMakeLists.txt @@ -40,7 +40,7 @@ endif() # ${gtest_BINARY_DIR}. # Language "C" is required for find_package(Threads). project(gtest CXX C) -cmake_minimum_required(VERSION 2.6.2) +cmake_minimum_required(VERSION 3.5) if (COMMAND set_up_hermetic_build) set_up_hermetic_build() diff --git a/Vates/VatesAPI/CMakeLists.txt b/Vates/VatesAPI/CMakeLists.txt index 648511653f6feb47c751d8f5f646b2a73fc7e3f1..7299847c40c5af7e068f03697c1451e3deac6559 100644 --- a/Vates/VatesAPI/CMakeLists.txt +++ b/Vates/VatesAPI/CMakeLists.txt @@ -1,5 +1,5 @@ #This is mainly here so you don't get a complaint when running cmake -cmake_minimum_required( VERSION 2.8.12 ) +cmake_minimum_required( VERSION 3.5 ) project( VatesAPI ) diff --git a/Vates/VatesAPI/inc/MantidVatesAPI/vtkMDHWSignalArray.h b/Vates/VatesAPI/inc/MantidVatesAPI/vtkMDHWSignalArray.h index c30a70a3aefadb759184142626c6332f23aa4665..6a023df1145561273c9e88deba5087da852bfe66 100644 --- a/Vates/VatesAPI/inc/MantidVatesAPI/vtkMDHWSignalArray.h +++ b/Vates/VatesAPI/inc/MantidVatesAPI/vtkMDHWSignalArray.h @@ -63,9 +63,9 @@ public: void GetTuple(vtkIdType i, double *tuple) override; vtkIdType LookupTypedValue(Scalar value) override; void LookupTypedValue(Scalar value, vtkIdList *ids) override; - Scalar GetValue(vtkIdType idx) override; + Scalar GetValue(vtkIdType idx) const override; Scalar &GetValueReference(vtkIdType idx) override; - void GetTupleValue(vtkIdType idx, Scalar *t) override; + void GetTypedTuple(vtkIdType idx, Scalar *t) const override; // Description: // This container is read only -- this method does nothing but print a @@ -97,9 +97,9 @@ public: void RemoveTuple(vtkIdType id) override; void RemoveFirstTuple() override; void RemoveLastTuple() override; - void SetTupleValue(vtkIdType i, const Scalar *t) override; - void InsertTupleValue(vtkIdType i, const Scalar *t) override; - vtkIdType InsertNextTupleValue(const Scalar *t) override; + void SetTypedTuple(vtkIdType i, const Scalar *t) override; + void InsertTypedTuple(vtkIdType i, const Scalar *t) override; + vtkIdType InsertNextTypedTuple(const Scalar *t) override; void SetValue(vtkIdType idx, Scalar value) override; vtkIdType InsertNextValue(Scalar v) override; void InsertVariantValue(vtkIdType idx, vtkVariant value) override; @@ -290,7 +290,7 @@ vtkIdType vtkMDHWSignalArray<Scalar>::Lookup(const Scalar &val, //------------------------------------------------------------------------------ template <class Scalar> -Scalar vtkMDHWSignalArray<Scalar>::GetValue(vtkIdType idx) { +Scalar vtkMDHWSignalArray<Scalar>::GetValue(vtkIdType idx) const { m_iterator->jumpTo(m_offset + idx); return m_iterator->getNormalizedSignal(); } @@ -304,8 +304,8 @@ Scalar &vtkMDHWSignalArray<Scalar>::GetValueReference(vtkIdType idx) { //------------------------------------------------------------------------------ template <class Scalar> -void vtkMDHWSignalArray<Scalar>::GetTupleValue(vtkIdType tupleId, - Scalar *tuple) { +void vtkMDHWSignalArray<Scalar>::GetTypedTuple(vtkIdType tupleId, + Scalar *tuple) const { m_iterator->jumpTo(m_offset + tupleId); tuple[0] = m_iterator->getNormalizedSignal(); } @@ -451,19 +451,19 @@ template <class Scalar> void vtkMDHWSignalArray<Scalar>::RemoveLastTuple() { //------------------------------------------------------------------------------ template <class Scalar> -void vtkMDHWSignalArray<Scalar>::SetTupleValue(vtkIdType, const Scalar *) { +void vtkMDHWSignalArray<Scalar>::SetTypedTuple(vtkIdType, const Scalar *) { vtkErrorMacro("Read only container.") return; } //------------------------------------------------------------------------------ template <class Scalar> -void vtkMDHWSignalArray<Scalar>::InsertTupleValue(vtkIdType, const Scalar *) { +void vtkMDHWSignalArray<Scalar>::InsertTypedTuple(vtkIdType, const Scalar *) { vtkErrorMacro("Read only container.") return; } //------------------------------------------------------------------------------ template <class Scalar> -vtkIdType vtkMDHWSignalArray<Scalar>::InsertNextTupleValue(const Scalar *) { +vtkIdType vtkMDHWSignalArray<Scalar>::InsertNextTypedTuple(const Scalar *) { vtkErrorMacro("Read only container.") return -1; } diff --git a/Vates/VatesAPI/src/ADSWorkspaceProvider.cpp b/Vates/VatesAPI/src/ADSWorkspaceProvider.cpp index a198f450cb18f42bcffff0d986ccd6f075bc9cae..126ebd059d4afd354c245564dc3c4d45f86db305 100644 --- a/Vates/VatesAPI/src/ADSWorkspaceProvider.cpp +++ b/Vates/VatesAPI/src/ADSWorkspaceProvider.cpp @@ -41,9 +41,11 @@ void ADSWorkspaceProvider<Workspace_Type>::disposeWorkspace( AnalysisDataService::Instance().remove(wsName); } +///@cond // Templated assembled types. -template class ADSWorkspaceProvider<Mantid::API::IMDWorkspace>; -template class ADSWorkspaceProvider<Mantid::API::IMDEventWorkspace>; -template class ADSWorkspaceProvider<Mantid::API::IMDHistoWorkspace>; +template class DLLExport ADSWorkspaceProvider<Mantid::API::IMDWorkspace>; +template class DLLExport ADSWorkspaceProvider<Mantid::API::IMDEventWorkspace>; +template class DLLExport ADSWorkspaceProvider<Mantid::API::IMDHistoWorkspace>; +///@endcond } } diff --git a/Vates/VatesAPI/src/vtkPeakMarkerFactory.cpp b/Vates/VatesAPI/src/vtkPeakMarkerFactory.cpp index 9bb5a96592b6d2251ff4e28431b4a70fb215c117..3003756dacf10cfe75be1f718e01be09fb07c810 100644 --- a/Vates/VatesAPI/src/vtkPeakMarkerFactory.cpp +++ b/Vates/VatesAPI/src/vtkPeakMarkerFactory.cpp @@ -231,12 +231,12 @@ vtkPeakMarkerFactory::create(ProgressAction &progressUpdating) const { } else if (shape.shapeName() == Mantid::DataObjects::PeakShapeEllipsoid::ellipsoidShapeName()) { vtkNew<vtkFloatArray> transformSignal; - transformSignal->Allocate(1); transformSignal->SetNumberOfComponents(9); + transformSignal->SetNumberOfTuples(1); auto tensor = getTransformTensor( dynamic_cast<const Mantid::DataObjects::PeakShapeEllipsoid &>(shape), peak); - transformSignal->InsertNextTupleValue(tensor.data()); + transformSignal->SetTypedTuple(0, tensor.data()); peakDataSet->GetPointData()->SetTensors(transformSignal.GetPointer()); vtkNew<vtkRegularPolygonSource> polygonSource; diff --git a/Vates/VatesAPI/test/MockObjects.h b/Vates/VatesAPI/test/MockObjects.h index 32a482510b1b8dfe7c174a0e8189f543de44f9a0..90355657d8328428e7b186c673f904a244128046 100644 --- a/Vates/VatesAPI/test/MockObjects.h +++ b/Vates/VatesAPI/test/MockObjects.h @@ -31,17 +31,6 @@ using Mantid::Geometry::MDHistoDimension; using Mantid::Geometry::MDHistoDimension_sptr; using Mantid::coord_t; -// Allow unused functions. -#if __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wunused-function" -#endif - -#if defined(GCC_VERSION) && GCC_VERSION >= 50000 -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wunused-function" -#endif - //===================================================================================== // Test Helper Types. These are shared by several tests in VatesAPI //===================================================================================== @@ -195,7 +184,8 @@ Create a field data entry containing (as contents) the argument text. @param testData : Text to enter @return new vtkFieldData object containing text. */ -vtkFieldData *createFieldDataWithCharArray(std::string testData) { +GCC_UNUSED_FUNCTION vtkFieldData * +createFieldDataWithCharArray(std::string testData) { vtkFieldData *fieldData = vtkFieldData::New(); vtkCharArray *charArray = vtkCharArray::New(); charArray->SetName(Mantid::VATES::XMLDefinitions::metaDataId().c_str()); @@ -279,10 +269,11 @@ view. view. @return full xml as string. */ -std::string constructXML(const std::string &xDimensionIdMapping, - const std::string &yDimensionIdMapping, - const std::string &zDimensionIdMapping, - const std::string &tDimensionIdMapping) { +GCC_UNUSED_FUNCTION std::string +constructXML(const std::string &xDimensionIdMapping, + const std::string &yDimensionIdMapping, + const std::string &zDimensionIdMapping, + const std::string &tDimensionIdMapping) { return std::string("<?xml version=\"1.0\" encoding=\"utf-8\"?>") + "<MDInstruction>" + "<MDWorkspaceName>Input</MDWorkspaceName>" + "<MDWorkspaceLocation>test_horace_reader.sqw</MDWorkspaceLocation>" + @@ -376,7 +367,7 @@ view. view. @return full xml as string. */ -std::string +GCC_UNUSED_FUNCTION std::string constructXMLForMDEvHelperData(const std::string &xDimensionIdMapping, const std::string &yDimensionIdMapping, const std::string &zDimensionIdMapping, @@ -407,8 +398,8 @@ Mantid::API::Workspace_sptr createSimple3DWorkspace() { return outWs; } -Mantid::API::Workspace_sptr get3DWorkspace(bool integratedTDimension, - bool sliceMD) { +GCC_UNUSED_FUNCTION Mantid::API::Workspace_sptr +get3DWorkspace(bool integratedTDimension, bool sliceMD) { using namespace Mantid::API; using namespace Mantid::DataObjects; @@ -446,7 +437,8 @@ Mantid::API::Workspace_sptr get3DWorkspace(bool integratedTDimension, * @param fieldName : The requested field data entry * @return The value of the requested field data entry */ -std::string getStringFieldDataValue(vtkDataSet *ds, std::string fieldName) { +GCC_UNUSED_FUNCTION std::string getStringFieldDataValue(vtkDataSet *ds, + std::string fieldName) { vtkAbstractArray *value = ds->GetFieldData()->GetAbstractArray(fieldName.c_str()); vtkStringArray *array = vtkStringArray::SafeDownCast(value); @@ -455,12 +447,4 @@ std::string getStringFieldDataValue(vtkDataSet *ds, std::string fieldName) { } // namespace -#if __clang__ -#pragma clang diagnostic pop -#endif - -#if defined(GCC_VERSION) && GCC_VERSION >= 50000 -#pragma GCC diagnostic pop -#endif - #endif diff --git a/Vates/VatesAPI/test/vtkDataSetToNonOrthogonalDataSetTest.h b/Vates/VatesAPI/test/vtkDataSetToNonOrthogonalDataSetTest.h index 604d50192bc3b2d28b432abc2822dbf8f99f364b..658ef648a845840993ec98253b749963d4d82804 100644 --- a/Vates/VatesAPI/test/vtkDataSetToNonOrthogonalDataSetTest.h +++ b/Vates/VatesAPI/test/vtkDataSetToNonOrthogonalDataSetTest.h @@ -15,14 +15,14 @@ #include "MantidGeometry/MDGeometry/HKL.h" #include "MantidKernel/MDUnit.h" +#include "MantidVatesAPI/vtkRectilinearGrid_Silent.h" #include <vtkDataArray.h> #include <vtkFieldData.h> #include <vtkFloatArray.h> -#include <vtkPoints.h> -#include "MantidVatesAPI/vtkRectilinearGrid_Silent.h" -#include <vtkUnstructuredGrid.h> #include <vtkNew.h> +#include <vtkPoints.h> #include <vtkSmartPointer.h> +#include <vtkUnstructuredGrid.h> using namespace Mantid::API; using namespace Mantid::Kernel; @@ -125,12 +125,11 @@ private: return ds; } - template <typename T> - std::vector<T> getRangeComp(vtkDataSet *ds, std::string fieldname, int size) { - vtkDataArray *arr = ds->GetFieldData()->GetArray(fieldname.c_str()); - vtkTypedDataArray<T> *tarr = vtkTypedDataArray<T>::FastDownCast(arr); - std::vector<T> vals(size); - tarr->GetTupleValue(0, &vals[0]); + std::vector<double> getRangeComp(vtkDataSet *ds, const char *fieldname) { + vtkDataArray *arr = ds->GetFieldData()->GetArray(fieldname); + std::vector<double> vals(arr->GetNumberOfComponents()); + TS_ASSERT_EQUALS(vals.size(), 16); + arr->GetTuple(0, vals.data()); return vals; } @@ -146,8 +145,7 @@ private: TS_ASSERT_DELTA(point[2], 0.8660254, eps); // See if the basis vectors are available - std::vector<double> basisMatrix = - getRangeComp<double>(grid, "ChangeOfBasisMatrix", 16); + std::vector<double> basisMatrix = getRangeComp(grid, "ChangeOfBasisMatrix"); // Row by row check @@ -299,8 +297,7 @@ public: TS_ASSERT_DELTA(point[1], 1.0, eps); TS_ASSERT_DELTA(point[2], 1.0, eps); // See if the basis vectors are available - std::vector<double> basisMatrix = - getRangeComp<double>(ds, "ChangeOfBasisMatrix", 16); + std::vector<double> basisMatrix = getRangeComp(ds, "ChangeOfBasisMatrix"); // Row by row check @@ -361,8 +358,7 @@ public: TS_ASSERT_DELTA(point[1], 1.0, eps); TS_ASSERT_DELTA(point[2], 0.75592895, eps); // See if the basis vectors are available - std::vector<double> basisMatrix = - getRangeComp<double>(ds, "ChangeOfBasisMatrix", 16); + std::vector<double> basisMatrix = getRangeComp(ds, "ChangeOfBasisMatrix"); // Row by row check diff --git a/Vates/VatesAPI/test/vtkMDHWSignalArrayTest.h b/Vates/VatesAPI/test/vtkMDHWSignalArrayTest.h index 1af27a920197c563dac291a21af676509f8f4ea2..014ec76ddf29ecd5903aca1ac28414da1fb455d0 100644 --- a/Vates/VatesAPI/test/vtkMDHWSignalArrayTest.h +++ b/Vates/VatesAPI/test/vtkMDHWSignalArrayTest.h @@ -52,7 +52,7 @@ public: // test alternate member function. double output3[1]; - signal->GetTupleValue(index, output3); + signal->GetTypedTuple(index, output3); TS_ASSERT_DELTA(1.0, output3[0], 0.0001); // test alternate member function. @@ -97,8 +97,8 @@ public: for (auto idx = 0; idx < imageSize / 4; ++idx) { double output1[1], output2[1]; - signal->GetTupleValue(idx * 4, output1); - doubleArray->GetTupleValue(idx, output2); + signal->GetTypedTuple(idx * 4, output1); + doubleArray->GetTypedTuple(idx, output2); TS_ASSERT_DELTA(output1[0], output2[0], 0.0001); } } @@ -153,8 +153,8 @@ public: for (auto idx = 0; idx < 100; ++idx) { double output1[1], output2[1]; - signal->GetTupleValue(idx, output1); - doubleArray->GetTupleValue(idx, output2); + signal->GetTypedTuple(idx, output1); + doubleArray->GetTypedTuple(idx, output2); TS_ASSERT_DELTA(output1[0], output2[0], 0.0001); } } @@ -235,7 +235,7 @@ public: for (auto index = 0; index < imageSize; ++index) { // test member function. double output[1]; - m_signal->GetTupleValue(index, output); + m_signal->GetTypedTuple(index, output); TS_ASSERT_DELTA(0.25, output[0], 0.0001); } } diff --git a/Vates/VatesSimpleGui/StandAloneExec/CMakeLists.txt b/Vates/VatesSimpleGui/StandAloneExec/CMakeLists.txt index 2bdfc7277df66faf5af88b406bf70dfb58cce8c1..70bc8aaa8be65d7fda901182406c2703ec7fd244 100644 --- a/Vates/VatesSimpleGui/StandAloneExec/CMakeLists.txt +++ b/Vates/VatesSimpleGui/StandAloneExec/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required( VERSION 2.8.12 ) +cmake_minimum_required( VERSION 3.5 ) project( VatesSimpleGui ) set( PROJECT_NAME VatesSimpleGui ) diff --git a/Vates/VatesSimpleGui/ViewWidgets/src/SaveScreenshotReaction.cpp b/Vates/VatesSimpleGui/ViewWidgets/src/SaveScreenshotReaction.cpp index fbb079c5ee30402ef61a6b1f883ec18212673171..b857e53c80fa8820a9a91ddc5516937d5a83fdee 100644 --- a/Vates/VatesSimpleGui/ViewWidgets/src/SaveScreenshotReaction.cpp +++ b/Vates/VatesSimpleGui/ViewWidgets/src/SaveScreenshotReaction.cpp @@ -4,6 +4,7 @@ #pragma warning disable 1170 #endif +#include "MantidVatesAPI/vtkImageData_Silent.h" #include <pqActiveObjects.h> #include <pqCoreUtilities.h> #include <pqFileDialog.h> @@ -12,14 +13,13 @@ #include <pqRenderViewBase.h> #include <pqSaveSnapshotDialog.h> #include <pqSettings.h> +#include <pqStereoModeHelper.h> #include <pqTabbedMultiViewWidget.h> #include <pqView.h> -#include "MantidVatesAPI/vtkImageData_Silent.h" +#include <vtkPVConfig.h> #include <vtkPVXMLElement.h> -#include <vtkSmartPointer.h> #include <vtkSMSessionProxyManager.h> -#include <vtkPVConfig.h> - +#include <vtkSmartPointer.h> #if defined(__INTEL_COMPILER) #pragma warning enable 1170 #endif @@ -113,10 +113,10 @@ void SaveScreenshotReaction::saveScreenshot() { colorPalette->Copy(chosenPalette); } + // temporarily set stereo mode from dialog. int stereo = ssDialog.getStereoMode(); - if (stereo) { - pqRenderViewBase::setStereo(stereo); - } + pqStereoModeHelper setStereo(stereo, + pqActiveObjects::instance().activeServer()); SaveScreenshotReaction::saveScreenshot(file, size, ssDialog.quality()); @@ -125,11 +125,6 @@ void SaveScreenshotReaction::saveScreenshot() { colorPalette->Copy(clone); } - // restore stereo - if (stereo) { - pqRenderViewBase::setStereo(0); - } - // check if need to render to clear the changes we did // while saving the screenshot. if (clone || stereo) { diff --git a/buildconfig/CMake/Bootstrap.cmake b/buildconfig/CMake/Bootstrap.cmake index 47c9630020545d81daf9cb97395be4354a0fedfd..567e9fb3c8df95c5de4417845af8381baa4be85b 100644 --- a/buildconfig/CMake/Bootstrap.cmake +++ b/buildconfig/CMake/Bootstrap.cmake @@ -10,7 +10,7 @@ if( MSVC ) include ( ExternalProject ) set( EXTERNAL_ROOT ${PROJECT_SOURCE_DIR}/external ) set( THIRD_PARTY_GIT_URL "https://github.com/mantidproject/thirdparty-msvc2015.git" ) - set ( THIRD_PARTY_GIT_SHA1 988f1be53a5dbbac30afb5ed11320862d06627aa ) + set ( THIRD_PARTY_GIT_SHA1 ed449e33b8a40bfc56c8d3a886ce2aeb4660d071 ) set ( THIRD_PARTY_DIR ${EXTERNAL_ROOT}/src/ThirdParty ) # Generates a script to do the clone/update in tmp set ( _project_name ThirdParty ) diff --git a/buildconfig/CMake/CommonSetup.cmake b/buildconfig/CMake/CommonSetup.cmake index 2548b60c9939fe552eb2a222bdd7edbf9c0a0706..3a38ccc220f2680037d17a60a2eb318c6c166798 100644 --- a/buildconfig/CMake/CommonSetup.cmake +++ b/buildconfig/CMake/CommonSetup.cmake @@ -247,7 +247,7 @@ endif () ########################################################################### if ( CMAKE_COMPILER_IS_GNUCXX ) include ( GNUSetup ) -elseif ( ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang" ) +elseif ( ${CMAKE_CXX_COMPILER_ID} MATCHES "Clang" ) include ( GNUSetup ) endif () @@ -311,6 +311,13 @@ if ( CXXTEST_FOUND OR PYUNITTEST_FOUND ) include( SetupDataTargets ) endif() +########################################################################### +# Visibility Setting +########################################################################### +if ( CMAKE_COMPILER_IS_GNUCXX ) + set(CMAKE_CXX_VISIBILITY_PRESET hidden CACHE STRING "") +endif() + ########################################################################### # Set a flag to indicate that this script has been called ########################################################################### diff --git a/buildconfig/CMake/Coveralls.cmake b/buildconfig/CMake/Coveralls.cmake index b6a93eb5f5923f10d23ca235748731bfb076fc32..73b163d0b48fed354c27e9c721349db2e0a2e5a0 100644 --- a/buildconfig/CMake/Coveralls.cmake +++ b/buildconfig/CMake/Coveralls.cmake @@ -109,7 +109,7 @@ endfunction() macro(coveralls_turn_on_coverage) if(NOT (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) - AND (NOT "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")) + AND (NOT "${CMAKE_C_COMPILER_ID}" MATCHES "Clang")) message(FATAL_ERROR "Coveralls: Compiler ${CMAKE_C_COMPILER_ID} is not GNU gcc! Aborting... You can set this on the command line using CC=/usr/bin/gcc CXX=/usr/bin/g++ cmake <options> ..") endif() diff --git a/buildconfig/CMake/GNUSetup.cmake b/buildconfig/CMake/GNUSetup.cmake index a1d3722f87e5f06bfea9f3e1bca1e8ba9ff220fd..c1cf0e4452e395a1ac536c8654ad808dc1f78112 100644 --- a/buildconfig/CMake/GNUSetup.cmake +++ b/buildconfig/CMake/GNUSetup.cmake @@ -17,7 +17,7 @@ if ( CMAKE_COMPILER_IS_GNUCXX ) add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0) endif() endif() -elseif ( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" ) +elseif ( "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" ) message( STATUS "clang version ${CMAKE_CXX_COMPILER_VERSION}" ) endif() @@ -36,7 +36,7 @@ if ( CMAKE_COMPILER_IS_GNUCXX ) if (NOT (GCC_COMPILER_VERSION VERSION_LESS "4.5")) set(GNUFLAGS "${GNUFLAGS} -Wno-unused-result -pedantic") endif () -elseif ( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" ) +elseif ( "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" ) set(GNUFLAGS "${GNUFLAGS} -Wno-sign-conversion") endif() @@ -80,19 +80,8 @@ set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${GNUFLAGS}" ) # -Wno-overloaded-virtual is down here because it's not applicable to the C_FLAGS set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GNUFLAGS} -Woverloaded-virtual -fno-operator-names" ) -if(${CMAKE_VERSION} VERSION_GREATER 3.1.0 OR ${CMAKE_VERSION} VERSION_EQUAL 3.1.0) - set(CMAKE_CXX_STANDARD 14) - set(CMAKE_CXX_STANDARD_REQUIRED 11) -else() - include(CheckCXXCompilerFlag) - CHECK_CXX_COMPILER_FLAG("-std=c++14" COMPILER_SUPPORTS_CXX14) - CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11) - if(COMPILER_SUPPORTS_CXX14) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14") - elseif(COMPILER_SUPPORTS_CXX11) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") - endif() -endif() +set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD_REQUIRED 11) # XCode isn't picking up the standard set above. if(CMAKE_GENERATOR STREQUAL Xcode) diff --git a/buildconfig/CMake/LinuxPackageScripts.cmake b/buildconfig/CMake/LinuxPackageScripts.cmake index 837ce4b3a7381ab87d5caf0925fada1c5e324953..7bfefbfd0f47950704295bcf5f80f26410c4fb38 100644 --- a/buildconfig/CMake/LinuxPackageScripts.cmake +++ b/buildconfig/CMake/LinuxPackageScripts.cmake @@ -148,7 +148,7 @@ execute_process ( COMMAND "chmod" "+x" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/mantid OUTPUT_QUIET ERROR_QUIET ) # Package version -set ( EXTRA_LDPATH "\${INSTALLDIR}/../lib/paraview-5.0" ) +set ( EXTRA_LDPATH "\${INSTALLDIR}/../lib/paraview-5.1" ) set ( MANTIDPLOT_EXEC MantidPlot_exe ) configure_file ( ${CMAKE_MODULE_PATH}/Packaging/launch_mantidplot.sh.in ${CMAKE_CURRENT_BINARY_DIR}/launch_mantidplot.sh.install @ONLY ) diff --git a/buildconfig/CMake/ParaViewSetup.cmake b/buildconfig/CMake/ParaViewSetup.cmake index f3c05b2df7bbd19681d197fff886350812605a28..c74702f3298e5a88c16b03fe93c7ac6913f8c1be 100644 --- a/buildconfig/CMake/ParaViewSetup.cmake +++ b/buildconfig/CMake/ParaViewSetup.cmake @@ -1,7 +1,7 @@ # This file will setup some common items that later setups depend on # Set the version of ParaView that is compatible with the Mantid code base -set ( COMPATIBLE_PARAVIEW_VERSION "5.0.0" ) +set ( COMPATIBLE_PARAVIEW_VERSION "5.1.0" ) # Set the name of the OSX application as this tends to be different set ( OSX_PARAVIEW_APP "paraview.app" ) diff --git a/buildconfig/CMake/SquishTestScript.cmake b/buildconfig/CMake/SquishTestScript.cmake index 9c84a97cea474a3e97c7c399549ab00d42b6363d..b6258ec2c88e4e97c034b64fb8367d15f423eb72 100644 --- a/buildconfig/CMake/SquishTestScript.cmake +++ b/buildconfig/CMake/SquishTestScript.cmake @@ -10,7 +10,7 @@ # # Based on the SQUISH_ADD_TEST macro # -cmake_minimum_required(VERSION 2.6 FATAL_ERROR) +cmake_minimum_required(VERSION 3.5 FATAL_ERROR) message(STATUS "squish_server_executable='${squish_server_executable}'") message(STATUS "squish_aut='${squish_aut}'") diff --git a/buildconfig/Jenkins/buildscript b/buildconfig/Jenkins/buildscript index 8f82a01cfe246d3e5a2d54d81b34bfc24dc82224..1d11d37cc3077a407d18006fdbcefc8867bf502d 100755 --- a/buildconfig/Jenkins/buildscript +++ b/buildconfig/Jenkins/buildscript @@ -14,9 +14,9 @@ SCRIPT_DIR=$(dirname "$0") BUILDPKG=true ############################################################################### -# All node currently have PARAVIEW_DIR=4.3.b40280 and PARAVIEW_NEXT_DIR=4.3.1 +# All node currently have PARAVIEW_DIR=5.1.0 and PARAVIEW_NEXT_DIR=5.0.0 ############################################################################### -export PARAVIEW_DIR=${PARAVIEW_NEXT_DIR} +#export PARAVIEW_DIR=${PARAVIEW_NEXT_DIR} ############################################################################### # Print out the versions of things we are using diff --git a/buildconfig/Jenkins/buildscript.bat b/buildconfig/Jenkins/buildscript.bat index 2654b589cff2062789361836470191433e0c473c..da8a9cbaeebf897df82d1fc89e67762b896d9ece 100755 --- a/buildconfig/Jenkins/buildscript.bat +++ b/buildconfig/Jenkins/buildscript.bat @@ -8,7 +8,7 @@ setlocal enableextensions enabledelayedexpansion :: BUILD_THREADS & PARAVIEW_DIR should be set in the configuration of each slave. :: CMake, git & git-lfs should be on the PATH :: -:: All nodes currently have PARAVIEW_DIR=4.3.b40280, PARAVIEW_NEXT_DIR=5.0.0 +:: All nodes currently have PARAVIEW_DIR=5.1.0, PARAVIEW_NEXT_DIR=5.0.0 :: and PARAVIEW_MSVC2015_DIR=4.3.b40280-msvc2015 ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: call cmake.exe --version @@ -28,7 +28,7 @@ echo %sha1% set VS_VERSION=14 call "%VS140COMNTOOLS%\..\..\VC\vcvarsall.bat" amd64 set CM_GENERATOR=Visual Studio 14 2015 Win64 -set PARAVIEW_DIR=%PARAVIEW_NEXT_DIR% +:: set PARAVIEW_DIR=%PARAVIEW_NEXT_DIR% ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :: Set up the location for local object store outside of the build and source diff --git a/buildconfig/Jenkins/doctests b/buildconfig/Jenkins/doctests index 66635fa927eee5a8d8a25ae7eeb2e0bdb54a44d2..8a758fa3f4dffc98202132de6494be94d14692e4 100755 --- a/buildconfig/Jenkins/doctests +++ b/buildconfig/Jenkins/doctests @@ -46,8 +46,9 @@ fi ############################################################################### # Create the build directory if it doesn't exist ############################################################################### -[ -d $WORKSPACE/build ] || mkdir $WORKSPACE/build -cd $WORKSPACE/build +BUILD_DIR=$WORKSPACE/build +[ -d $BUILD_DIR ] || mkdir $BUILD_DIR +cd $BUILD_DIR ############################################################################### # CMake configuration. We only need a minimal configuration as we will actually @@ -79,11 +80,16 @@ fi ##################################################################################### # Run tests ##################################################################################### +# Remove doctrees directory so it forces a full reparse. This will then pick up all +# reference warnings +if [ -d $BUILD_DIR/docs/doctrees ]; then + rm -rf $BUILD_DIR/docs/doctrees/* +fi # Create clean user properties with UsageData search path userprops=~/.mantid/Mantid.user.properties rm -f $userprops -data_binary_root=${WORKSPACE}/build/ExternalData +data_binary_root=$BUILD_DIR/ExternalData testdata_dir=${data_binary_root}/Testing/Data instrument_dir=${WORKSPACE}/instrument echo "datasearch.directories=${testdata_dir}/DocTest;${testdata_dir}/UnitTest;${instrument_dir}" > $userprops @@ -91,7 +97,8 @@ echo "UpdateInstrumentDefinitions.OnStartup = 0" >> $userprops echo "usagereports.enabled = 0" >> $userprops set +e #don't immediately exit on failure so that we can remove the package -${MANTIDPLOT_EXE} -xq docs/runsphinx_doctest.py +$SCL_ON_RHEL6 "bin/MantidPlot -xq docs/runsphinx_html.py" +$SCL_ON_RHEL6 "bin/MantidPlot -xq docs/runsphinx_doctest.py" status=$? set -e #exit on failures from now on diff --git a/buildconfig/Jenkins/pylint-buildscript b/buildconfig/Jenkins/pylint-buildscript index 397eb64869343095ebabf1e27dfbda13b2a30472..ab01d46b95683d57a2eb3e25ba098cb058cd3dac 100755 --- a/buildconfig/Jenkins/pylint-buildscript +++ b/buildconfig/Jenkins/pylint-buildscript @@ -8,6 +8,10 @@ if [ -z "$BUILD_DIR" ]; then exit 1 fi PYLINT_OUTPUT_DIR=$BUILD_DIR/pylint +############################################################################### +# Purge old logs +############################################################################### +rm -f $PYLINT_OUTPUT_DIR/PYLINT-* ############################################################################### # Check if python files have changed @@ -29,11 +33,6 @@ then fi echo "running pylint" -############################################################################### -# Purge old logs -############################################################################### -rm -f $BUILD_DIR/pylint/PYLINT-* - ############################################################################### # Print out the versions of things we are using ############################################################################### diff --git a/docs/source/algorithms/BASISReduction311-v1.rst b/docs/source/algorithms/BASISReduction311-v1.rst new file mode 100644 index 0000000000000000000000000000000000000000..430fb2017b6f7710fa927ced1bebaa18b7039c85 --- /dev/null +++ b/docs/source/algorithms/BASISReduction311-v1.rst @@ -0,0 +1,68 @@ +.. algorithm:: + +.. summary:: + +.. alias:: + +.. properties:: + +For each property, the algorithm will remember the last value used. If user deletes +this value and leaves blank the property field, the default value will be used. Default +values are typical of the silicon311 reflection. + +Description +----------- + +**Run numbers**: +The syntax for the run numbers designation allows runs to be segregated +into sets. The semicolon symbol ";" is used to separate the runs into sets. +Runs within each set are jointly reduced. + +Examples: + +- 2144-2147,2149,2156 is a single set. All runs jointly reduced. + +- 2144-2147,2149;2156 is set 2144-2147,2149 and set 2156. The sets are reduced separately from each other. + +If *DoIndividual* is checked, then each run number is reduced separately +from the rest. The semicolon symbol is ignored. + +**Momentum transfer binning scheme**: Three values are required, the +lower boundary the bin with the minimum momentum, the bin width, and the +upper boundary ofthe bin with the maximum momentum. + +Reflection Selector +=================== + +There are typical values for the properties of the 311 reflection: + ++------------+----------------+------------------------+ +| Reflection | Energy bins | Momentum transfer bins | +| | (micro-eV) | (inverse Angstroms) | ++============+================+========================+ +| silicon311 | -740, 1.6, 740 | 0.5, 0.2, 3.7 | ++------------+----------------+------------------------+ + +Also the following mask files is associated to the 311 reflection: + ++-----------+------------------------------------------------------------------------------------------------+ +|Reflection | Mask file | ++===========+================================================================================================+ +|silicon311 | BASIS_Mask_OneQuarterRemains_SouthBottom.xml | ++-----------+------------------------------------------------------------------------------------------------+ + +This mask files can be found in the SNS filesystem +(**/SNS/BSS/shared/autoreduce/new_masks_08_12_2015/**) + + +Usage +----- + +.. warning:: + + This algorithm is not meant to be run from the command line. + +.. categories:: + +.. sourcelink:: + diff --git a/docs/source/algorithms/CropToComponent-v1.rst b/docs/source/algorithms/CropToComponent-v1.rst new file mode 100644 index 0000000000000000000000000000000000000000..dd58e21b903daecfda47dbbec548d84d997de739 --- /dev/null +++ b/docs/source/algorithms/CropToComponent-v1.rst @@ -0,0 +1,50 @@ + +.. algorithm:: + +.. summary:: + +.. alias:: + +.. properties:: + +Description +----------- + +This algorithm takes a list of component names and an input workspaces and produces an output workspace which only contains the detectors which are part of the specified components. If no components are specified then the full workspace is returned. + +The workspace allows users to select a specific bank for exclusive investigation in subsequent operations. + +Workflow +######## + +.. diagram:: AccumulateMD-v1_wkflw.dot + +Usage +----- + +**Example - CropToComponent** + +.. testcode:: CropToComponentExample + + # Create sample workspace with four banks where each bank has 3x3 detectors + sample_workspace = CreateSampleWorkspace(NumBanks=4, BankPixelWidth=3) + + # Crop to a component, we select bank2 here + cropped_workspace = CropToComponent(InputWorkspace=sample_workspace, ComponentNames="bank2") + + # Check the number of histograms + sample_number_of_histograms = sample_workspace.getNumberHistograms() + cropped_number_of_histograms = cropped_workspace.getNumberHistograms() + + print("The original workspace has {0} histograms and the cropped workspace has {1} histograms.".format(sample_number_of_histograms, cropped_number_of_histograms)) + +Output: + +.. testoutput:: CropToComponentExample + + The original workspace has 36 histograms and the cropped workspace has 9 histograms. + +.. categories:: + +.. sourcelink:: + diff --git a/docs/source/algorithms/ExportSpectraMask-v1.rst b/docs/source/algorithms/ExportSpectraMask-v1.rst new file mode 100644 index 0000000000000000000000000000000000000000..92b65de4497b03674b20339ace2d1e3d58599b64 --- /dev/null +++ b/docs/source/algorithms/ExportSpectraMask-v1.rst @@ -0,0 +1,65 @@ +.. algorithm:: + +.. summary:: + +.. alias:: + +.. properties:: + +Description +----------- + +The algorithm extracts list of the spectra numbers which are masked on the input workspace and, +if requested, saves these spectra as legacy *.msk* file in ISIS ASCII format. + +The format is described on :ref:`LoadMask <algm-LoadMask>` algorithm pages. + +**Note** It is not recommended to use exported *.msk* files for masking workspaces during reduction as +the result of applying such mask will be different depending on the stage of reduction of the source and target files. +You need to make additional efforts (see :ref:`LoadMask <algm-LoadMask>` algorithm description) to avoid this effect. +It is better to use :ref:`SaveMask <algm-SaveMask>` algorithm instead. This algorithm produces *.xml* files, +containing lists of masked detectors, which will produce identical masking regardless of the workspace grouping and +spectra-detector map, defined for data acquisition electronics during experiment. + +Usage +----- + +**Example: Export Spectra Masks** + +.. testcode:: ExExportSpectraMask + + import sys + #prepare the data: + masks = [1,4,8,10,11,12,12,198,199,200] + test_ws = CreateSampleWorkspace() + test_ws.maskDetectors(masks) + + f_name = 'test_ws_mask.msk' + + #extract mask: + r_masks = ExportSpectraMask(test_ws,Filename=f_name) + + # Compare results: + wmsk = '' + final_fname = os.path.join(config.getString('defaultsave.directory'),f_name) + with open(final_fname,'r') as res_file: + for line in res_file: + wmsk = line + os.remove(final_fname) + + sys.stdout.write("Input mask: {0}\n".format(masks)) + sys.stdout.write("Extracted mask: {0}\n".format(r_masks)) + sys.stdout.write("Saved mask: {0}".format(wmsk)) + + +Output: + +.. testoutput:: ExExportSpectraMask + + Input mask: [1, 4, 8, 10, 11, 12, 12, 198, 199, 200] + Extracted mask: [ 1 4 8 10 11 12 198 199 200] + Saved mask: 1 4 8 10-12 198-200 + +.. categories:: + +.. sourcelink:: diff --git a/docs/source/algorithms/IntegratePeaksMDHKL-v1.rst b/docs/source/algorithms/IntegratePeaksMDHKL-v1.rst new file mode 100644 index 0000000000000000000000000000000000000000..e92e4980063be9e4fc327cd78e3ac446da59c603 --- /dev/null +++ b/docs/source/algorithms/IntegratePeaksMDHKL-v1.rst @@ -0,0 +1,103 @@ + +.. algorithm:: + +.. summary:: + +.. alias:: + +.. properties:: + +Description +----------- + +:ref:`IntegratePeaksMDHKL <algm-IntegratePeaksMDHKL>` provides integration of a +:ref:`MDHistoWorkspace <MDHistoWorkspace>` or :ref:`MDEventWorkspace <MDWorkspace>` in 3-dimensions. +The units of the workspace must be HKL. The main usage will be for data normalized by +:ref:`MDNormSCD <algm-MDNormSCD>`. +A 3D box is created for each peak and the background and peak data are separated. The intensity and sigma of the +intensity is found from the grid inside the peak and the background is subtracted. The boxes are created and integrated +in parallel and less memory is required than binning all HKL at once. + +:math:`I_{corr} = I_{peak} - pts_{peak}/pts_{bg} * I_{bg}` + +with the errors summed in quadrature: + +:math:`\sigma_{I,corr}^2 = \sigma_{I,peak}^2 + pts_{peak}/pts_{bg} * \sigma_{I,bg}^2` + +Using the DeltaHKL parameter, the problem of nearly peaks or regions of diffuse scattering can be avoided. Also for +normalized data, the unmeasured data points are excluded from the background. See white regions in last figure. + +.. figure:: /images/peak3d.png + :alt: peak3d.png + :width: 400px + :align: center + + Peak Integration Input. 3D Box. + +.. figure:: /images/IntegratePeaksMDHKLbox.png + :alt: IntegratePeaksMDHKLbox.png + :width: 400px + :align: center + + Integration slice at center of box. + +.. figure:: /images/IntegratePeaksMDHKLpeak.png + :alt: IntegratePeaksMDHKLpeak.png + :width: 400px + :align: center + + Integration slice of peak grid points. + +.. figure:: /images/IntegratePeaksMDHKLbkg.png + :alt: IntegratePeaksMDHKLbkg.png + :width: 400px + :align: center + + Integration slice of background grid points. + + +Usage +----- + +**Example - IntegratePeaksMDHKL event histo** + +.. testcode:: IntegratePeaksMDHKLExample + + #Create PeaksWorkspace + sampleWs = CreateSampleWorkspace() + pws = CreatePeaksWorkspace(InstrumentWorkspace=sampleWs,NumberOfPeaks=3) + p = pws.getPeak(0) + p.setHKL(5,0,0) + p = pws.getPeak(1) + p.setHKL(0,0,0) + p = pws.getPeak(2) + p.setHKL(-5,0,0) + #Test with MDEventWorkspace + mdws = CreateMDWorkspace(Dimensions=3, Extents=[-10,10,-10,10,-10,10], Names='[H,0,0],[0,K,0],[0,0,L]',Units='A^-1,A^-1,A^-1',Frames='HKL,HKL,HKL') + FakeMDEventData(InputWorkspace=mdws, PeakParams=[100000,-5,0,0,1]) + FakeMDEventData(InputWorkspace=mdws, PeakParams=[100000,0,0,0,1]) + FakeMDEventData(InputWorkspace=mdws, PeakParams=[100000,5,0,0,1]) + pws =IntegratePeaksMDHKL(InputWorkspace=mdws,PeaksWorkspace=pws,DeltaHKL=1.5,GridPoints=21) + for i in range(3): + p = pws.getPeak(i) + print p.getIntensity(),p.getSigmaIntensity() + #Test with MDHistoWorkspace + mdws = BinMD(InputWorkspace=mdws,AlignedDim0="[H,0,0],-10,10,101",AlignedDim1="[0,K,0],-10,10,101",AlignedDim2="[0,0,L],-10,10,101") + pws =IntegratePeaksMDHKL(InputWorkspace=mdws,PeaksWorkspace=pws,DeltaHKL=1.5,GridPoints=21) + for i in range(3): + p = pws.getPeak(i) + print p.getIntensity(),p.getSigmaIntensity() + + +Output: + +.. testoutput:: IntegratePeaksMDHKLExample + + 99913.3212993 316.143446399 + 99913.3212993 316.143446399 + 99913.3212993 316.143446399 + 99945.2374619 316.168987268 + 99951.6716018 316.174385251 + 99926.3456269 316.148488307 + + diff --git a/docs/source/algorithms/LoadPreNexusLive-v1.rst b/docs/source/algorithms/LoadPreNexusLive-v1.rst new file mode 100644 index 0000000000000000000000000000000000000000..674c3b5a99d9ea0fefa350fb1cefb4904d4eaa7d --- /dev/null +++ b/docs/source/algorithms/LoadPreNexusLive-v1.rst @@ -0,0 +1,32 @@ + +.. algorithm:: + +.. summary:: + +.. alias:: + +.. properties:: + +Description +----------- + +This loads a 'live' file that is periodically saved by the legacy DAS +at SNS. If the ``LoadLogs`` option is specified, it will attempt to +load logs from the most recent saved run. Specifying ``LogFilename`` +will turn off the search capability. + +.. warning:: + + This only works at ORNL. + +Usage +----- + +.. code-block:: python + + LoadPreNexusLive(Instrument='SNAP', OutputWorkspace='SNAP_live') + + +.. categories:: + +.. sourcelink:: diff --git a/docs/source/algorithms/ReplicateMD-v1.rst b/docs/source/algorithms/ReplicateMD-v1.rst index 02ce3ab784136ac8296e67b5db91b74753e27677..cb2f2b631b4bf49efb39ed592f6f1baebaec96ad 100644 --- a/docs/source/algorithms/ReplicateMD-v1.rst +++ b/docs/source/algorithms/ReplicateMD-v1.rst @@ -27,8 +27,8 @@ Usage .. testcode:: ReplicateMDExample1D import numpy as np - data = CreateMDHistoWorkspace(1, SignalInput=np.arange(100), ErrorInput=np.arange(100), NumberOfEvents=np.arange(100), Extents=[-10, 10], NumberOfBins=[100], Names='E', Units='MeV') - shape = CreateMDHistoWorkspace(2, SignalInput=np.tile([1], 10000), ErrorInput=np.tile([1], 10000), NumberOfEvents=np.tile([1], 10000), Extents=[-1,1, -10, 10], NumberOfBins=[100,100], Names='Q,E', Units='A^-1, MeV') + data = CreateMDHistoWorkspace(2, SignalInput=np.arange(20*30), ErrorInput=np.arange(20*30), NumberOfEvents=np.arange(20*30), Extents=[-10, 10, -1,1], NumberOfBins=[20, 30], Names='E,Qx', Units='MeV,A^-1') + shape = CreateMDHistoWorkspace(3, SignalInput=np.tile([1], 20*30*10), ErrorInput=np.tile([1], 20*30*10), NumberOfEvents=np.tile([1], 20*30*10), Extents=[-1,1, -10, 10, -10,10], NumberOfBins=[30,20,10], Names='Qx,E,Qy', Units='A^-1, MeV, A^-1') replicated = ReplicateMD(ShapeWorkspace=shape, DataWorkspace=data) @@ -39,8 +39,8 @@ Output: .. testoutput:: ReplicateMDExample1D - Num dims: 2 - Num points: 10000 + Num dims: 3 + Num points: 6000 .. categories:: diff --git a/docs/source/concepts/HistogramData.rst b/docs/source/concepts/HistogramData.rst index 7e1a154c05d7311eeaa721fb37724b3aae7e539b..7aa4975ebcdda158c2a65e0eff17e8c787e7ed65 100644 --- a/docs/source/concepts/HistogramData.rst +++ b/docs/source/concepts/HistogramData.rst @@ -86,7 +86,7 @@ In its final form, we will be able to do things like the following (things not i .. code-block:: c++ :linenos: - BinEdges edges{1.0, 2.0, 4.0}; + BinEdges edges{1.0, 2.0, 4.0, 8.0}; Counts counts1{4, 100, 4}; Counts counts2{0, 100, 0}; Histogram histogram1(edges, counts1); @@ -111,7 +111,7 @@ In its final form, we will be able to do things like the following (things not i errors[1]; // sqrt(200.0) errors[2]; // 2.0 - // Need bin centers (points data) instead of bin edges? + // Need bin centers (point data) instead of bin edges? auto points = histogram.points(); // Need variance instead of standard deviation? auto variances = histogram.countVariances(); @@ -131,7 +131,7 @@ Further planned features: - Arithmetics will all sub-types (``BinEdges``, ``Points``, ``Counts``, and ``Frequencies``, and also their respective ``Variances`` and ``StandardDeviations``). - Generating bin edges (linear, logarithmic, ...). - Extend the ``Histogram`` interface with more common operations. -- Non-member functions for more complex operations on histogram such as rebinning. +- Non-member functions for more complex operations on histograms such as rebinning. - Validation of data, e.g., non-zero bin widths and positivity of uncertainties. **Any feedback on additional capabilities of the new data types is highly appreciated. @@ -386,7 +386,7 @@ Working with bin edges and counts ///////////////////////////////////////////////////// BinEdges edges = {1.0, 2.0, 4.0}; if(edges.cbegin() != edges.cend()) - *(edges.begin()) += 2.0; + *(edges.begin()) += 0.1; // Range-based for works thanks to iterators: for (auto &edge : edges) edge += 0.1; @@ -400,7 +400,7 @@ Working with bin edges and counts edges[2]; // 4.0 // Only const! This is not possible: - edges[0] += 2.0; // DOES NOT COMPILE + edges[0] += 0.1; // DOES NOT COMPILE // REASON: BinEdges contains a copy-on-write pointer to data, dereferencing in // tight loop is expensive, so interface prevents things like this: @@ -509,7 +509,7 @@ Working with the new ``MatrixWorkspace`` interface // Preserve sharing outputWS->setSharedY(i, inputWS->sharedY(i)); outputWS->setCounts(i, inputWS->counts(i)); // also shares, 'Counts' wraps a cow_ptr - outputWS->setBinEdges(i, inputWS->binEdges(i)); + outputWS->setBinEdges(i, inputWS->binEdges(i)); // shares if input storage mode is 'XMode::BinEdges' @@ -571,7 +571,7 @@ There are two issues you might encounter when implementing new algorithms or whe This happens rarely, typically by creating a workspace that contains histogram data (bin edges) and modifying the size via the legacy interface to store point data (or vice versa). These size modifications are only possible via the legacy interface. The best solution is to determine the storage mode at creation time of the workspace, by specifying the correct length of the X data. - If that is not possible, use the new setters such as `setBinEdges()`, they will trigger a conversion of the internal storage mode (not yet available in Python). + If that is not possible, use the new setters such as ``setBinEdges()``, they will trigger a conversion of the internal storage mode (not yet available in Python). diff --git a/docs/source/images/IntegratePeaksMDHKLbkg.png b/docs/source/images/IntegratePeaksMDHKLbkg.png new file mode 100644 index 0000000000000000000000000000000000000000..ccd1b56e3e6e287d79a8da5a49262ca1a0e9c4a9 Binary files /dev/null and b/docs/source/images/IntegratePeaksMDHKLbkg.png differ diff --git a/docs/source/images/IntegratePeaksMDHKLbox.png b/docs/source/images/IntegratePeaksMDHKLbox.png new file mode 100644 index 0000000000000000000000000000000000000000..4f7780c213a35afecf436aab79fe9d4bad06d2aa Binary files /dev/null and b/docs/source/images/IntegratePeaksMDHKLbox.png differ diff --git a/docs/source/images/IntegratePeaksMDHKLpeak.png b/docs/source/images/IntegratePeaksMDHKLpeak.png new file mode 100644 index 0000000000000000000000000000000000000000..dac29340d0110d853a7050b1e972c14a2193fc17 Binary files /dev/null and b/docs/source/images/IntegratePeaksMDHKLpeak.png differ diff --git a/docs/source/images/peak3d.png b/docs/source/images/peak3d.png new file mode 100644 index 0000000000000000000000000000000000000000..a2a4a1b9c727ae2cb1c4a383ce4e10065231d6e2 Binary files /dev/null and b/docs/source/images/peak3d.png differ diff --git a/docs/source/release/v3.8.0/diffraction.rst b/docs/source/release/v3.8.0/diffraction.rst index 5df3e8a3f15fba6a4b8467b95f05d594e4722158..111d3f7fda6cb6be03dcdf7e1ebbf0ff772f102b 100644 --- a/docs/source/release/v3.8.0/diffraction.rst +++ b/docs/source/release/v3.8.0/diffraction.rst @@ -15,6 +15,20 @@ Single Crystal Diffraction has been expanded and improved from previous release. It provides an integrated user-friendly interface for instrument scientists and users to access data, calculate and refine UB matrix, merge multiple data sets for slice-view and peak integration. + +- :ref:`IntegratePeaksMDHKL <algm-IntegratePeaksMDHKL>` has been added to integrate data in HKL space. The + main usage will be to normalize the data using + :ref:`MDNormSCD <algm-MDNormSCD>` and then integrate the resulting MDHistoWorkspace, + but it also integrates MDHistoWorkspaces and MDEventWorkspaces without normalizing. + The MD data must be in units of HKL. A 3D box is created for each peak and the background + and peak data are separated. The intensity and sigma of the intensity is found from the grid inside the peak and + the background is subtracted. The boxes are created and integrated in parallel and less memory is required than + binning all HKL space at once. The figure shows the grid points within an HKL box that are in one peak from Si data. + +.. figure:: ../../images/peak3d.png + :width: 487 + :align: center + Engineering Diffraction diff --git a/docs/source/release/v3.8.0/direct_inelastic.rst b/docs/source/release/v3.8.0/direct_inelastic.rst index 92823b7141189421cd1281aecb331eb3e30ea337..7152e0f2f5314a524de7ac94429e7b43480c116c 100644 --- a/docs/source/release/v3.8.0/direct_inelastic.rst +++ b/docs/source/release/v3.8.0/direct_inelastic.rst @@ -10,6 +10,11 @@ Improvements - :ref:`MDNormDirectSC <algm-MDNormDirectSC>` has an option to skip safety checks. This improves the speed when acting on workspace groups. +- A qtiGenie method *export_masks* was brought to Mantid as :ref:`ExportSpectraMask <algm-ExportSpectraMask>` Python algorithm and got documentation, unit tests and Python GUI. + The algorithm allows to export list of masked workspace spectra and save these spectra as ISIS *.msk* file. + The export mask procedure is often used by instrument scientists in ISIS, and they had to initialize qtiGenie to do this operation before these changes. + + `Full list of changes on GitHub <http://github.com/mantidproject/mantid/pulls?q=is%3Apr+milestone%3A%22Release+3.8%22+is%3Amerged+label%3A%22Component%3A+Direct+Inelastic%22>`_ Crystal Field @@ -17,3 +22,4 @@ Crystal Field - A fitting function was added (:ref:`CrystalFieldMultiSpectrum <func-CrystalFieldMultiSpectrum>`) that fits crystal field parameters to multiple spectra simultaneously. + diff --git a/docs/source/release/v3.8.0/framework.rst b/docs/source/release/v3.8.0/framework.rst index dafa7b60cd50e56115178361d8ab05ee12acb330..4e03492eb4c60fdc106d6a1d3f93bd168437464e 100644 --- a/docs/source/release/v3.8.0/framework.rst +++ b/docs/source/release/v3.8.0/framework.rst @@ -22,10 +22,17 @@ Algorithms New ### +- :ref:`LoadPreNexusLive <algm-LoadPreNexusLive>` will load "live" + data from file on legacy SNS DAS instruments. + +- :ref:`CropToComponent <algm-CropToComponent>` allows for cropping a workspace to a list of component names. Improved ######## +- :ref:`FlatPlatePaalmanPingsCorrection <algm-FlatPlatePaalmanPingsCorrection>` & :ref:`CylinderPaalmanPingsCorrection <algm-CylinderPaalmanPingsCorrection>` + now accept 'Direct' as a possible ``EMode`` parameter. + - :ref:`FilterEvents <algm-FilterEvents>` now produces output workspaces with the same workspace numbers as specified by the ``SplittersWorkspace``. @@ -33,6 +40,10 @@ Improved - :ref:`SavePlot1D <algm-SavePlot1D>` has options for writing out plotly html files. +- :ref:`ConvertTableToMatrixWorkspace <algm-ConvertTableToMatrixWorkspace>` The input dialog + had a bug where the table columns were in a reversed order in the dialogue's combo boxes. + This is now fixed and the order is correct. + Deprecated ########## diff --git a/docs/source/release/v3.8.0/indirect_inelastic.rst b/docs/source/release/v3.8.0/indirect_inelastic.rst index f560c071e49f7bec4d714dc3acfa06a4e5818fae..0f6e2b0ee5e9f93336f952f301f9cc7b6ea624a4 100644 --- a/docs/source/release/v3.8.0/indirect_inelastic.rst +++ b/docs/source/release/v3.8.0/indirect_inelastic.rst @@ -20,6 +20,8 @@ Elwin ~~~~~ - Additional option to ungroup Elwin output +- When using multiple input files, the naming convention for the outputworkspace contains the `first-final` run number. + An example of this would be `osi92764-92767_graphite002_red_elwin_elf` for OSIRIS run between 92764-92767 Jump Fit ~~~~~~~~ @@ -33,6 +35,7 @@ Improvements - Range bars colours in the *ISIS Calibration* interface have been updated to match the convention in the fit wizard. - Vesuvio sigma_theta value updated for single and double differencing in both forward and back scattering. The new value is 0.016 for all. + Bugfixes -------- @@ -43,4 +46,5 @@ Bugfixes * The *ResNorm* interface should no longer crash when using workspaces (rather than files) as input. * Fix bug showing incorrect doublet peaks in :ref:`ISISIndirectDiffractionReduction <algm-ISISIndirectDiffractionReduction>` + `Full list of changes on GitHub <http://github.com/mantidproject/mantid/pulls?q=is%3Apr+milestone%3A%22Release+3.8%22+is%3Amerged+label%3A%22Component%3A+Indirect+Inelastic%22>`_ diff --git a/docs/source/release/v3.8.0/sans.rst b/docs/source/release/v3.8.0/sans.rst index 1c0fc53dea5d32eb309f0d7e5aa9cd49e55f24bd..8342672271279029792b467b754d2c83afe663f2 100644 --- a/docs/source/release/v3.8.0/sans.rst +++ b/docs/source/release/v3.8.0/sans.rst @@ -5,12 +5,18 @@ SANS Changes .. contents:: Table of Contents :local: +Algorithms +---------- + +- :ref:`CropToComponent <algm-CropToComponent>` allows for cropping a workspace to a list of component names. + + Bug Fixes --------- - Fix for beam center finder - Fix loading of multiperiod event files - Fix period selection when loading multiperiod files. - +- Fix the loading of RKH files `Full list of changes on github <http://github.com/mantidproject/mantid/pulls?q=is%3Apr+milestone%3A%22Release+3.8%22+is%3Amerged+label%3A%22Component%3A+SANS%22>`__ diff --git a/docs/source/release/v3.8.0/ui.rst b/docs/source/release/v3.8.0/ui.rst index cd9b65d494b16fb0603bc409a478f53fa4d0b201..b8b9db600cfcb6e44e0bff71a304fcf21723dccb 100644 --- a/docs/source/release/v3.8.0/ui.rst +++ b/docs/source/release/v3.8.0/ui.rst @@ -11,6 +11,8 @@ Installation Windows ####### +* IPython has been upgraded to version 3.2.1 + OS X #### @@ -51,11 +53,16 @@ Documentation Bugs Resolved ------------- + - Floating windows now always stay on top of the main window in OSX SliceViewer Improvements ------------------------ * When opening the sliceviewer, it will default to showing the first two non-integrated dimensions +VSI Improvements +---------------- +* ParaView updated to version 5.1.0 + | Full list of diff --git a/instrument/TOPAZ_Definition_2016-04-06.xml b/instrument/TOPAZ_Definition_2016-04-06.xml index dfcb1b5c1d76dc7e95f332294bb9a32e6b6d48f2..8da0778ce9f67c41d5e292706524a53c1e251cd9 100644 --- a/instrument/TOPAZ_Definition_2016-04-06.xml +++ b/instrument/TOPAZ_Definition_2016-04-06.xml @@ -5,12 +5,11 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mantidproject.org/IDF/1.0 http://schema.mantidproject.org/IDF/1.0/IDFSchema.xsd" name="TOPAZ" valid-from ="2016-04-06 16:24:01" - valid-to ="2100-12-31 23:59:59" - last-modified="2016-04-06 13:45:00"> + valid-to ="2016-07-13 23:59:59" + last-modified="2016-07-16 18:35:00"> <!--Created by Vickie Lynch--> <!--Modified by Vickie Lynch using the TOPAZ.py script from the Translation Service calibration/geometry/ code. --> - <!--Modified valid-to by A.Savici--> <!--DEFAULTS--> <defaults> <length unit="metre"/> diff --git a/instrument/TOPAZ_Definition_2016-07-14.xml b/instrument/TOPAZ_Definition_2016-07-14.xml new file mode 100644 index 0000000000000000000000000000000000000000..cbd6aa254266a5c0b42257afc33a5082bfd7adf4 --- /dev/null +++ b/instrument/TOPAZ_Definition_2016-07-14.xml @@ -0,0 +1,259 @@ +<?xml version='1.0' encoding='UTF-8'?> +<!-- For help on the notation used to specify an Instrument Definition File + see http://www.mantidproject.org/IDF --> +<instrument xmlns="http://www.mantidproject.org/IDF/1.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.mantidproject.org/IDF/1.0 http://schema.mantidproject.org/IDF/1.0/IDFSchema.xsd" + name="TOPAZ" valid-from ="2016-07-14 00:00:00" + valid-to ="2100-12-31 23:59:59" + last-modified="2016-07-16 18:35:00"> + + <!--Created by Vickie Lynch--> + <!--Modified by Vickie Lynch using the TOPAZ.py script from the Translation Service calibration/geometry/ code. --> + <!--DEFAULTS--> + <defaults> + <length unit="metre"/> + <angle unit="degree"/> + <reference-frame> + <along-beam axis="z"/> + <pointing-up axis="y"/> + <handedness val="right"/> + </reference-frame> + <default-view view="spherical_y"/> + </defaults> + + <!--SOURCE--> + <component type="moderator"> + <location z="-18.0"/> + </component> + <type name="moderator" is="Source"/> + + <!--SAMPLE--> + <component type="sample-position"> + <location y="0.0" x="0.0" z="0.0"/> + </component> + <type name="sample-position" is="SamplePos"/> + + <!--MONITORS--> + <component type="monitors" idlist="monitors"> + <location/> + </component> + <type name="monitors"> + <component type="monitor"> + <location z="-2.488" name="monitor1"/> + </component> + <component type="monitor"> + <location z="1.049" name="monitor2"/> + </component> + </type> + +<!-- XML Code automatically generated on 2016-07-14 13:35:00.720701 for the Mantid instrument definition file --> +<component type="panel" idstart="851968" idfillbyfirst="y" idstepbyrow="256"> +<location r="0.455000" t="105.192621" p="-33.305992" name="bank13" rot="-99.919712" axis-x="0" axis-y="1" axis-z="0"> + <rot val="53.154399"> + <rot val="41.466968" axis-x="0" axis-y="1" axis-z="0" /> + </rot> +</location> +</component> +<component type="panel" idstart="917504" idfillbyfirst="y" idstepbyrow="256"> +<location r="0.455000" t="133.320872" p="-46.751427" name="bank14" rot="-63.920201" axis-x="0" axis-y="1" axis-z="0"> + <rot val="53.154399"> + <rot val="41.466968" axis-x="0" axis-y="1" axis-z="0" /> + </rot> +</location> +</component> +<component type="panel" idstart="1048576" idfillbyfirst="y" idstepbyrow="256"> +<location r="0.455000" t="133.320872" p="-133.248573" name="bank16" rot="8.080272" axis-x="0" axis-y="1" axis-z="0"> + <rot val="53.154399"> + <rot val="41.466968" axis-x="0" axis-y="1" axis-z="0" /> + </rot> +</location> +</component> +<component type="panel" idstart="1114112" idfillbyfirst="y" idstepbyrow="256"> +<location r="0.455000" t="105.192621" p="-146.694008" name="bank17" rot="44.079783" axis-x="0" axis-y="1" axis-z="0"> + <rot val="53.154399"> + <rot val="41.466968" axis-x="0" axis-y="1" axis-z="0" /> + </rot> +</location> +</component> +<component type="panel" idstart="1179648" idfillbyfirst="y" idstepbyrow="256"> +<location r="0.455000" t="74.807731" p="-146.694071" name="bank18" rot="80.079867" axis-x="0" axis-y="1" axis-z="0"> + <rot val="53.154399"> + <rot val="41.466968" axis-x="0" axis-y="1" axis-z="0" /> + </rot> +</location> +</component> +<component type="panel" idstart="1245184" idfillbyfirst="y" idstepbyrow="256"> +<location r="0.455000" t="46.678985" p="-133.248429" name="bank19" rot="116.080009" axis-x="0" axis-y="1" axis-z="0"> + <rot val="53.154399"> + <rot val="41.466968" axis-x="0" axis-y="1" axis-z="0" /> + </rot> +</location> +</component> +<component type="panel" idstart="1310720" idfillbyfirst="y" idstepbyrow="256"> +<location r="0.425000" t="23.905622" p="-42.859145" name="bank20" rot="-177.410228" axis-x="0" axis-y="1" axis-z="0"> + <rot val="47.178655"> + <rot val="22.073524" axis-x="0" axis-y="1" axis-z="0" /> + </rot> +</location> +</component> +<component type="panel" idstart="1376256" idfillbyfirst="y" idstepbyrow="256"> +<location r="0.425000" t="55.596651" p="-19.516218" name="bank21" rot="-141.410201" axis-x="0" axis-y="1" axis-z="0"> + <rot val="47.178655"> + <rot val="22.073524" axis-x="0" axis-y="1" axis-z="0" /> + </rot> +</location> +</component> +<component type="panel" idstart="1441792" idfillbyfirst="y" idstepbyrow="256"> +<location r="0.425000" t="90.000202" p="-16.000018" name="bank22" rot="-105.410002" axis-x="0" axis-y="1" axis-z="0"> + <rot val="47.178655"> + <rot val="22.073524" axis-x="0" axis-y="1" axis-z="0" /> + </rot> +</location> +</component> +<component type="panel" idstart="1507328" idfillbyfirst="y" idstepbyrow="256"> +<location r="0.425000" t="124.403098" p="-19.516157" name="bank23" rot="-69.410491" axis-x="0" axis-y="1" axis-z="0"> + <rot val="47.178655"> + <rot val="22.073524" axis-x="0" axis-y="1" axis-z="0" /> + </rot> +</location> +</component> +<component type="panel" idstart="1703936" idfillbyfirst="y" idstepbyrow="256"> +<location r="0.425000" t="124.403098" p="-160.483843" name="bank26" rot="38.590066" axis-x="0" axis-y="1" axis-z="0"> + <rot val="47.178655"> + <rot val="22.073524" axis-x="0" axis-y="1" axis-z="0" /> + </rot> +</location> +</component> +<component type="panel" idstart="1769472" idfillbyfirst="y" idstepbyrow="256"> +<location r="0.425000" t="90.000202" p="-163.999982" name="bank27" rot="74.589577" axis-x="0" axis-y="1" axis-z="0"> + <rot val="47.178655"> + <rot val="22.073524" axis-x="0" axis-y="1" axis-z="0" /> + </rot> +</location> +</component> +<component type="panel" idstart="1835008" idfillbyfirst="y" idstepbyrow="256"> +<location r="0.425000" t="55.596651" p="-160.483782" name="bank28" rot="110.589776" axis-x="0" axis-y="1" axis-z="0"> + <rot val="47.178655"> + <rot val="22.073524" axis-x="0" axis-y="1" axis-z="0" /> + </rot> +</location> +</component> +<component type="panel" idstart="1900544" idfillbyfirst="y" idstepbyrow="256"> +<location r="0.425000" t="23.905622" p="-137.140855" name="bank29" rot="146.589803" axis-x="0" axis-y="1" axis-z="0"> + <rot val="47.178655"> + <rot val="22.073524" axis-x="0" axis-y="1" axis-z="0" /> + </rot> +</location> +</component> +<component type="panel" idstart="2162688" idfillbyfirst="y" idstepbyrow="256"> +<location r="0.395000" t="108.000253" p="0.000000" name="bank33" rot="-71.999747" axis-x="0" axis-y="1" axis-z="0"> + <rot val="45.000000"> + <rot val="0.000000" axis-x="0" axis-y="1" axis-z="0" /> + </rot> +</location> +</component> +<component type="panel" idstart="2228224" idfillbyfirst="y" idstepbyrow="256"> +<location r="0.395000" t="143.999764" p="0.000000" name="bank34" rot="-36.000236" axis-x="0" axis-y="1" axis-z="0"> + <rot val="45.000000"> + <rot val="0.000000" axis-x="0" axis-y="1" axis-z="0" /> + </rot> +</location> +</component> +<component type="panel" idstart="2359296" idfillbyfirst="y" idstepbyrow="256"> +<location r="0.395000" t="143.999764" p="180.000000" name="bank36" rot="36.000236" axis-x="0" axis-y="1" axis-z="0"> + <rot val="45.000000"> + <rot val="0.000000" axis-x="0" axis-y="1" axis-z="0" /> + </rot> +</location> +</component> +<component type="panel" idstart="2424832" idfillbyfirst="y" idstepbyrow="256"> +<location r="0.395000" t="108.000253" p="180.000000" name="bank37" rot="71.999747" axis-x="0" axis-y="1" axis-z="0"> + <rot val="45.000000"> + <rot val="0.000000" axis-x="0" axis-y="1" axis-z="0" /> + </rot> +</location> +</component> +<component type="panel" idstart="2490368" idfillbyfirst="y" idstepbyrow="256"> +<location r="0.395000" t="72.000168" p="180.000000" name="bank38" rot="107.999832" axis-x="0" axis-y="1" axis-z="0"> + <rot val="45.000000"> + <rot val="0.000000" axis-x="0" axis-y="1" axis-z="0" /> + </rot> +</location> +</component> +<component type="panel" idstart="2555904" idfillbyfirst="y" idstepbyrow="256"> +<location r="0.395000" t="36.000027" p="180.000000" name="bank39" rot="143.999973" axis-x="0" axis-y="1" axis-z="0"> + <rot val="45.000000"> + <rot val="0.000000" axis-x="0" axis-y="1" axis-z="0" /> + </rot> +</location> +</component> +<component type="panel" idstart="3014656" idfillbyfirst="y" idstepbyrow="256"> +<location r="0.425000" t="124.403098" p="160.483843" name="bank46" rot="69.410491" axis-x="0" axis-y="1" axis-z="0"> + <rot val="47.178655"> + <rot val="-22.073524" axis-x="0" axis-y="1" axis-z="0" /> + </rot> +</location> +</component> +<component type="panel" idstart="3080192" idfillbyfirst="y" idstepbyrow="256"> +<location r="0.425000" t="90.000202" p="163.999982" name="bank47" rot="105.410002" axis-x="0" axis-y="1" axis-z="0"> + <rot val="47.178655"> + <rot val="-22.073524" axis-x="0" axis-y="1" axis-z="0" /> + </rot> +</location> +</component> +<component type="panel" idstart="3145728" idfillbyfirst="y" idstepbyrow="256"> +<location r="0.425000" t="55.596651" p="160.483782" name="bank48" rot="141.410201" axis-x="0" axis-y="1" axis-z="0"> + <rot val="47.178655"> + <rot val="-22.073524" axis-x="0" axis-y="1" axis-z="0" /> + </rot> +</location> +</component> +<component type="panel" idstart="3211264" idfillbyfirst="y" idstepbyrow="256"> +<location r="0.425000" t="23.905622" p="137.140855" name="bank49" rot="177.410228" axis-x="0" axis-y="1" axis-z="0"> + <rot val="47.178655"> + <rot val="-22.073524" axis-x="0" axis-y="1" axis-z="0" /> + </rot> +</location> +</component> +<!-- List of all the bank names: + bank13,bank14,bank16,bank17,bank18,bank19,bank20,bank21,bank22,bank23,bank26,bank27,bank28,bank29,bank33,bank34,bank36,bank37,bank38,bank39,bank46,bank47,bank48,bank49 +--> + +<!-- NOTE: This detector is the same as the SNAP detector --> +<!-- Rectangular Detector Panel --> +<type name="panel" is="rectangular_detector" type="pixel" + xpixels="256" xstart="-0.078795" xstep="+0.000618" + ypixels="256" ystart="-0.078795" ystep="+0.000618" > + <properties/> +</type> + + <!-- Pixel for Detectors--> + <type is="detector" name="pixel"> + <cuboid id="pixel-shape"> + <left-front-bottom-point y="-0.000309" x="-0.000309" z="0.0"/> + <left-front-top-point y="0.000309" x="-0.000309" z="0.0"/> + <left-back-bottom-point y="-0.000309" x="-0.000309" z="-0.0001"/> + <right-front-bottom-point y="-0.000309" x="0.000309" z="0.0"/> + </cuboid> + <algebra val="pixel-shape"/> + </type> + + <!-- Shape for Monitors--> + <!-- TODO: Update to real shape --> + <type is="monitor" name="monitor"> + <cylinder id="some-shape"> + <centre-of-bottom-base p="0.0" r="0.0" t="0.0"/> + <axis y="0.0" x="0.0" z="1.0"/> + <radius val="0.01"/> + <height val="0.03"/> + </cylinder> + <algebra val="some-shape"/> + </type> + + <!--MONITOR IDs--> + <idlist idname="monitors"> + <id val="-1"/> + <id val="-2"/> + </idlist> +</instrument> diff --git a/scripts/HFIR_4Circle_Reduction/MainWindow.ui b/scripts/HFIR_4Circle_Reduction/MainWindow.ui index ecf49a32d81394f26b93cb8119cf3c685a1a609b..1edb19a13994ea5c47e337543087a50b23b155e4 100644 --- a/scripts/HFIR_4Circle_Reduction/MainWindow.ui +++ b/scripts/HFIR_4Circle_Reduction/MainWindow.ui @@ -193,7 +193,7 @@ <bool>true</bool> </property> <property name="currentIndex"> - <number>3</number> + <number>6</number> </property> <widget class="QWidget" name="tab"> <attribute name="title"> @@ -1931,6 +1931,13 @@ p, li { white-space: pre-wrap; } </item> </layout> </item> + <item> + <widget class="QProgressBar" name="progressBar_add_ub_peaks"> + <property name="value"> + <number>24</number> + </property> + </widget> + </item> <item> <layout class="QHBoxLayout" name="horizontalLayout_13"> <item> @@ -2936,6 +2943,13 @@ p, li { white-space: pre-wrap; } </property> </widget> </item> + <item> + <widget class="QPushButton" name="pushButton_sortMergeTable"> + <property name="text"> + <string>Sort</string> + </property> + </widget> + </item> <item> <spacer name="verticalSpacer_10"> <property name="orientation"> @@ -3112,7 +3126,7 @@ p, li { white-space: pre-wrap; } </item> </layout> </item> - <item row="4" column="1"> + <item row="5" column="1"> <layout class="QGridLayout" name="gridLayout_23"> <item row="1" column="0"> <widget class="QPushButton" name="pushButton_exportPeaks"> @@ -3146,32 +3160,8 @@ p, li { white-space: pre-wrap; } </item> </layout> </item> - <item row="4" column="0"> + <item row="5" column="0"> <layout class="QGridLayout" name="gridLayout_22"> - <item row="1" column="6"> - <widget class="QLabel" name="label_48"> - <property name="text"> - <string>Background</string> - </property> - </widget> - </item> - <item row="1" column="10"> - <widget class="QPushButton" name="pushButton_setupPeakIntegration"> - <property name="toolTip"> - <string><html><head/><body><p>Switch to tab 'Peak Integrate' to set up options for peak integration</p></body></html></string> - </property> - <property name="text"> - <string>Single Pt. Set up</string> - </property> - </widget> - </item> - <item row="1" column="0"> - <widget class="QLabel" name="label_47"> - <property name="text"> - <string>Peak integration configuration:</string> - </property> - </widget> - </item> <item row="1" column="2"> <widget class="QComboBox" name="comboBox_mergePeakNormType"> <item> @@ -3251,6 +3241,42 @@ p, li { white-space: pre-wrap; } </property> </widget> </item> + <item row="1" column="6"> + <widget class="QLabel" name="label_48"> + <property name="text"> + <string>Background</string> + </property> + </widget> + </item> + <item row="1" column="11"> + <widget class="QPushButton" name="pushButton_setupPeakIntegration"> + <property name="font"> + <font> + <pointsize>11</pointsize> + </font> + </property> + <property name="toolTip"> + <string><html><head/><body><p>Switch to tab 'Peak Integrate' to set up options for peak integration</p></body></html></string> + </property> + <property name="text"> + <string>Single Pt. Set up</string> + </property> + </widget> + </item> + <item row="1" column="0"> + <widget class="QLabel" name="label_47"> + <property name="text"> + <string>Peak integration configuration:</string> + </property> + </widget> + </item> + <item row="1" column="10"> + <widget class="QLineEdit" name="lineEdit_scaleFactor"> + <property name="toolTip"> + <string><html><head/><body><p>Peak intensity scale factor</p><p><br/></p></body></html></string> + </property> + </widget> + </item> <item row="1" column="8"> <widget class="QLineEdit" name="lineEdit_numPt4BackgroundRight"> <property name="toolTip"> @@ -3258,7 +3284,7 @@ p, li { white-space: pre-wrap; } </property> </widget> </item> - <item row="1" column="11"> + <item row="1" column="12"> <spacer name="horizontalSpacer_19"> <property name="orientation"> <enum>Qt::Horizontal</enum> @@ -3274,7 +3300,7 @@ p, li { white-space: pre-wrap; } </property> </spacer> </item> - <item row="4" column="11"> + <item row="4" column="12"> <spacer name="horizontalSpacer_22"> <property name="orientation"> <enum>Qt::Horizontal</enum> @@ -3326,7 +3352,7 @@ p, li { white-space: pre-wrap; } </property> </widget> </item> - <item row="4" column="9"> + <item row="4" column="10"> <widget class="QCheckBox" name="checkBox_roundHKL"> <property name="font"> <font> @@ -3365,8 +3391,22 @@ p, li { white-space: pre-wrap; } </property> </spacer> </item> + <item row="1" column="9"> + <widget class="QLabel" name="label_39"> + <property name="text"> + <string>Scale Factor</string> + </property> + </widget> + </item> </layout> </item> + <item row="4" column="0"> + <widget class="QProgressBar" name="progressBar_mergeScans"> + <property name="value"> + <number>24</number> + </property> + </widget> + </item> </layout> </widget> <widget class="QWidget" name="tab_indexPeak"> @@ -3578,20 +3618,6 @@ p, li { white-space: pre-wrap; } </item> <item row="1" column="0"> <layout class="QGridLayout" name="gridLayout_21"> - <item row="0" column="0"> - <widget class="QPushButton" name="pushButton_integratePt"> - <property name="text"> - <string>Integrate Pt</string> - </property> - </widget> - </item> - <item row="0" column="1"> - <widget class="QCheckBox" name="checkBox_applyMask"> - <property name="text"> - <string>Mask</string> - </property> - </widget> - </item> <item row="1" column="0"> <widget class="QPushButton" name="pushButton_calBkgd"> <property name="font"> @@ -3604,10 +3630,10 @@ p, li { white-space: pre-wrap; } </property> </widget> </item> - <item row="1" column="1"> - <widget class="QCheckBox" name="checkBox_selectPt"> + <item row="0" column="0"> + <widget class="QPushButton" name="pushButton_integratePt"> <property name="text"> - <string>Select</string> + <string>Integrate Pt</string> </property> </widget> </item> diff --git a/scripts/HFIR_4Circle_Reduction/View3DWidget.ui b/scripts/HFIR_4Circle_Reduction/View3DWidget.ui index 87ef8c317a029175effb9a9565f46bdeeae54962..e18cc0d3c34da5a7c30c27763e1ddf9ed5badef0 100644 --- a/scripts/HFIR_4Circle_Reduction/View3DWidget.ui +++ b/scripts/HFIR_4Circle_Reduction/View3DWidget.ui @@ -23,9 +23,15 @@ <item> <layout class="QGridLayout" name="gridLayout_2"> <item row="12" column="2"> - <widget class="QPushButton" name="pushButton_6"> + <widget class="QLabel" name="label_5"> + <property name="frameShadow"> + <enum>QFrame::Sunken</enum> + </property> <property name="text"> - <string>Zoom In (X)</string> + <string>X</string> + </property> + <property name="alignment"> + <set>Qt::AlignCenter</set> </property> </widget> </item> @@ -39,56 +45,112 @@ </property> </widget> </item> - <item row="12" column="3"> - <widget class="QPushButton" name="pushButton_5"> + <item row="17" column="4"> + <widget class="QPushButton" name="pushButton_2"> <property name="text"> - <string>Zoom Out (X)</string> + <string>Zoom</string> </property> </widget> </item> - <item row="0" column="2"> - <widget class="QComboBox" name="comboBox_scans"> - <property name="toolTip"> - <string><html><head/><body><p>List of available scans</p></body></html></string> + <item row="12" column="4"> + <widget class="QPushButton" name="pushButton_zoomInX"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> </property> - </widget> - </item> - <item row="10" column="2"> - <widget class="QPushButton" name="pushButton_plot3D"> <property name="text"> - <string>Plot</string> + <string>Zoom</string> </property> </widget> </item> - <item row="19" column="3"> - <widget class="QPushButton" name="pushButton_quit"> - <property name="text"> - <string>Close</string> - </property> - </widget> + <item row="7" column="3"> + <layout class="QHBoxLayout" name="horizontalLayout_3"> + <item> + <widget class="QLineEdit" name="lineEdit_countsThresholdLower"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="maximumSize"> + <size> + <width>200</width> + <height>16777215</height> + </size> + </property> + <property name="toolTip"> + <string><html><head/><body><p>Data points underthreashold will not be plot on the canvas</p></body></html></string> + </property> + </widget> + </item> + </layout> </item> - <item row="5" column="3"> - <widget class="QLineEdit" name="lineEdit_baseColorGreen"> + <item row="4" column="3"> + <widget class="QLineEdit" name="lineEdit_baseColorRed"> <property name="sizePolicy"> <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> </property> + <property name="toolTip"> + <string><html><head/><body><p>3 floats from 0 to 1 for RGB</p></body></html></string> + </property> </widget> </item> - <item row="4" column="2"> - <layout class="QHBoxLayout" name="horizontalLayout_2"> + <item row="5" column="2"> + <layout class="QHBoxLayout" name="horizontalLayout_4"> <item> - <widget class="QCheckBox" name="checkBox_changeRed"> + <widget class="QLabel" name="label_2"> <property name="layoutDirection"> <enum>Qt::LeftToRight</enum> </property> <property name="text"> - <string/> + <string>Green</string> + </property> + <property name="alignment"> + <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set> </property> </widget> </item> + </layout> + </item> + <item row="9" column="2"> + <widget class="QPushButton" name="pushButton_checkCounts"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="maximumSize"> + <size> + <width>700</width> + <height>16777215</height> + </size> + </property> + <property name="text"> + <string>Check</string> + </property> + </widget> + </item> + <item row="9" column="3"> + <widget class="QLabel" name="label_numberDataPoints"> + <property name="font"> + <font> + <pointsize>9</pointsize> + </font> + </property> + <property name="text"> + <string>Number of Counts</string> + </property> + </widget> + </item> + <item row="4" column="2"> + <layout class="QHBoxLayout" name="horizontalLayout_2"> <item> <widget class="QLabel" name="label"> <property name="layoutDirection"> @@ -130,15 +192,8 @@ </property> </spacer> </item> - <item row="17" column="3"> - <widget class="QPushButton" name="pushButton_2"> - <property name="text"> - <string>PushButton</string> - </property> - </widget> - </item> - <item row="14" column="3"> - <widget class="QLineEdit" name="lineEdit_4"> + <item row="5" column="3"> + <widget class="QLineEdit" name="lineEdit_baseColorGreen"> <property name="sizePolicy"> <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> <horstretch>0</horstretch> @@ -149,16 +204,6 @@ </item> <item row="6" column="2"> <layout class="QHBoxLayout" name="horizontalLayout_5"> - <item> - <widget class="QCheckBox" name="checkBox_changeBlue"> - <property name="layoutDirection"> - <enum>Qt::LeftToRight</enum> - </property> - <property name="text"> - <string/> - </property> - </widget> - </item> <item> <widget class="QLabel" name="label_4"> <property name="layoutDirection"> @@ -174,14 +219,7 @@ </item> </layout> </item> - <item row="17" column="2"> - <widget class="QPushButton" name="pushButton"> - <property name="text"> - <string>PushButton</string> - </property> - </widget> - </item> - <item row="18" column="3"> + <item row="19" column="3"> <spacer name="verticalSpacer"> <property name="orientation"> <enum>Qt::Vertical</enum> @@ -194,64 +232,22 @@ </property> </spacer> </item> - <item row="0" column="3"> + <item row="0" column="4"> <widget class="QComboBox" name="comboBox_dataKey"> <property name="toolTip"> <string><html><head/><body><p>List of data keys</p></body></html></string> </property> </widget> </item> - <item row="19" column="2"> - <widget class="QPushButton" name="pushButton_clearPlots"> + <item row="14" column="4"> + <widget class="QPushButton" name="pushButton"> <property name="text"> - <string>Clear</string> + <string>Zoom</string> </property> </widget> </item> - <item row="7" column="3"> - <layout class="QHBoxLayout" name="horizontalLayout_3"> - <item> - <widget class="QLineEdit" name="lineEdit_countsThresholdLower"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="maximumSize"> - <size> - <width>60</width> - <height>16777215</height> - </size> - </property> - <property name="toolTip"> - <string><html><head/><body><p>Data points underthreashold will not be plot on the canvas</p></body></html></string> - </property> - </widget> - </item> - <item> - <widget class="QLineEdit" name="lineEdit_countsThresholdUpper"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="maximumSize"> - <size> - <width>60</width> - <height>16777215</height> - </size> - </property> - <property name="toolTip"> - <string><html><head/><body><p>Data points underthreashold will not be plot on the canvas</p></body></html></string> - </property> - </widget> - </item> - </layout> - </item> - <item row="14" column="2"> - <widget class="QLineEdit" name="lineEdit_3"> + <item row="14" column="3"> + <widget class="QLineEdit" name="lineEdit"> <property name="sizePolicy"> <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> <horstretch>0</horstretch> @@ -260,21 +256,18 @@ </property> </widget> </item> - <item row="4" column="3"> - <widget class="QLineEdit" name="lineEdit_baseColorRed"> + <item row="12" column="3"> + <widget class="QLineEdit" name="lineEdit_xMax"> <property name="sizePolicy"> <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> </property> - <property name="toolTip"> - <string><html><head/><body><p>3 floats from 0 to 1 for RGB</p></body></html></string> - </property> </widget> </item> - <item row="16" column="3"> - <widget class="QLineEdit" name="lineEdit_6"> + <item row="17" column="3"> + <widget class="QLineEdit" name="lineEdit_3"> <property name="sizePolicy"> <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> <horstretch>0</horstretch> @@ -283,45 +276,41 @@ </property> </widget> </item> - <item row="5" column="2"> - <layout class="QHBoxLayout" name="horizontalLayout_4"> - <item> - <widget class="QCheckBox" name="checkBox_changeGreen"> - <property name="layoutDirection"> - <enum>Qt::LeftToRight</enum> - </property> - <property name="text"> - <string/> - </property> - </widget> - </item> - <item> - <widget class="QLabel" name="label_2"> - <property name="layoutDirection"> - <enum>Qt::LeftToRight</enum> - </property> - <property name="text"> - <string>Green</string> - </property> - <property name="alignment"> - <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set> - </property> - </widget> - </item> - </layout> + <item row="14" column="2"> + <widget class="QLabel" name="label_6"> + <property name="frameShadow"> + <enum>QFrame::Sunken</enum> + </property> + <property name="text"> + <string>Y</string> + </property> + <property name="alignment"> + <set>Qt::AlignCenter</set> + </property> + </widget> </item> - <item row="16" column="2"> - <widget class="QLineEdit" name="lineEdit_5"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> + <item row="9" column="4"> + <widget class="QPushButton" name="pushButton_plot3D"> + <property name="text"> + <string>Plot</string> </property> </widget> </item> - <item row="9" column="2"> - <widget class="QPushButton" name="pushButton_checkCounts"> + <item row="17" column="2"> + <widget class="QLabel" name="label_7"> + <property name="frameShadow"> + <enum>QFrame::Sunken</enum> + </property> + <property name="text"> + <string>Z</string> + </property> + <property name="alignment"> + <set>Qt::AlignCenter</set> + </property> + </widget> + </item> + <item row="7" column="4"> + <widget class="QLineEdit" name="lineEdit_countsThresholdUpper"> <property name="sizePolicy"> <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> <horstretch>0</horstretch> @@ -330,24 +319,63 @@ </property> <property name="maximumSize"> <size> - <width>700</width> + <width>200</width> <height>16777215</height> </size> </property> + <property name="toolTip"> + <string><html><head/><body><p>Data points underthreashold will not be plot on the canvas</p></body></html></string> + </property> + </widget> + </item> + <item row="4" column="4"> + <widget class="QCheckBox" name="checkBox_changeRed"> + <property name="layoutDirection"> + <enum>Qt::LeftToRight</enum> + </property> <property name="text"> - <string>Check</string> + <string/> </property> </widget> </item> - <item row="9" column="3"> - <widget class="QLabel" name="label_numberDataPoints"> - <property name="font"> - <font> - <pointsize>9</pointsize> - </font> + <item row="5" column="4"> + <widget class="QCheckBox" name="checkBox_changeGreen"> + <property name="layoutDirection"> + <enum>Qt::LeftToRight</enum> </property> <property name="text"> - <string>Number of Counts</string> + <string/> + </property> + </widget> + </item> + <item row="6" column="4"> + <widget class="QCheckBox" name="checkBox_changeBlue"> + <property name="layoutDirection"> + <enum>Qt::LeftToRight</enum> + </property> + <property name="text"> + <string/> + </property> + </widget> + </item> + <item row="0" column="3"> + <widget class="QComboBox" name="comboBox_scans"> + <property name="toolTip"> + <string><html><head/><body><p>List of available scans</p></body></html></string> + </property> + </widget> + </item> + <item row="20" column="3"> + <widget class="QPushButton" name="pushButton_clearPlots"> + <property name="text"> + <string>Clear</string> + </property> + </widget> + </item> + <item row="20" column="4"> + <widget class="QPushButton" name="pushButton_quit"> + <property name="text"> + <string>Close</string> </property> </widget> </item> diff --git a/scripts/HFIR_4Circle_Reduction/__init__.py b/scripts/HFIR_4Circle_Reduction/__init__.py index 04a95e8315757618d54dc05da33da722b0774d94..ce584152d8f29f7e79885193dd9ecbd845a6a62b 100644 --- a/scripts/HFIR_4Circle_Reduction/__init__.py +++ b/scripts/HFIR_4Circle_Reduction/__init__.py @@ -1,2 +1 @@ -#pylint: disable=invalid-name -#pylint: disable=invalid-name +#pylint: disable=invalid-name,C0103 diff --git a/scripts/HFIR_4Circle_Reduction/detector2dview.py b/scripts/HFIR_4Circle_Reduction/detector2dview.py index 0d7c93e30ba035d3aec3834d4ab357a517c91cd7..c728c6044885d5f2c23784819a0e7359d78c6736 100644 --- a/scripts/HFIR_4Circle_Reduction/detector2dview.py +++ b/scripts/HFIR_4Circle_Reduction/detector2dview.py @@ -98,8 +98,6 @@ class Detector2DView(mpl2dgraphicsview.Mpl2dGraphicsView): assert self._roiStart is not None assert self._roiEnd is not None - print '[DB] Polygon corner = [%s, %s]' % (str(self._roiStart), str(self._roiEnd)) - # create a vertex list of a rectangular vertex_array = np.ndarray(shape=(4, 2)) # upper left corner @@ -130,8 +128,6 @@ class Detector2DView(mpl2dgraphicsview.Mpl2dGraphicsView): """ if self._myPolygon is not None: # polygon is of type matplotlib.patches.Polygon - # print 'My polygon is of type %s.' % str(type(self._myPolygon)) - # print dir(self._myPolygon) self._myPolygon.remove() self._myPolygon = None @@ -200,7 +196,6 @@ class Detector2DView(mpl2dgraphicsview.Mpl2dGraphicsView): if self._roiSelectMode is True and self._mousePressed == Detector2DView.MousePress.LEFT: # start to select a region self._roiStart = (self._currX, self._currY) - print '[DB] Set RIO start to ', self._roiStart return diff --git a/scripts/HFIR_4Circle_Reduction/fourcircle_utility.py b/scripts/HFIR_4Circle_Reduction/fourcircle_utility.py index 9dedf54a7923709cf704177f5e9f4dabc72febab..d83878d4381e71fc25f1170d96165369d13b5cd1 100644 --- a/scripts/HFIR_4Circle_Reduction/fourcircle_utility.py +++ b/scripts/HFIR_4Circle_Reduction/fourcircle_utility.py @@ -111,7 +111,6 @@ def generate_mask_file(file_path, ll_corner, ur_corner, rectangular=True): start_det_id = 1 + col_number * NUM_DET_ROW + start_row end_det_id = 1 + col_number * NUM_DET_ROW + end_row det_sub_xml += '%d-%d,' % (start_det_id, end_det_id) - print '[DB] Detector %d - %d' % (start_det_id, end_det_id) # END-FOR # remove last ',' det_sub_xml = det_sub_xml[:-1] diff --git a/scripts/HFIR_4Circle_Reduction/fputility.py b/scripts/HFIR_4Circle_Reduction/fputility.py index c84244f246d051c43f9c8cb1e0a2a644eb1f87cb..28d79a605e8d140979f836b3c83db9f4c0df1e0b 100644 --- a/scripts/HFIR_4Circle_Reduction/fputility.py +++ b/scripts/HFIR_4Circle_Reduction/fputility.py @@ -1,3 +1,4 @@ +#pylint: disable=R0914 # Utility methods for Fullprof diff --git a/scripts/HFIR_4Circle_Reduction/guiutility.py b/scripts/HFIR_4Circle_Reduction/guiutility.py index 497feb2d208c9a22eb16466b37a70a09884fcda0..adfd639272537772ef283eef356bc0237bcaafb8 100644 --- a/scripts/HFIR_4Circle_Reduction/guiutility.py +++ b/scripts/HFIR_4Circle_Reduction/guiutility.py @@ -128,13 +128,11 @@ def parse_float_array(array_str): :param array_str: :return: boolean, list of floats/error message """ - print array_str - assert isinstance(array_str, str) + assert isinstance(array_str, str), 'Input array for parsing must be of type string.' array_str = array_str.replace(',', ' ') array_str = array_str.replace('\n', ' ') array_str = array_str.replace('\t ', ' ') array_str = array_str.strip() - print '[DB] After processing: ', array_str float_str_list = array_str.split() float_list = list() diff --git a/scripts/HFIR_4Circle_Reduction/hfctables.py b/scripts/HFIR_4Circle_Reduction/hfctables.py index 0d0591e8cf6073595c8c47d5cb044dc3bd2ac576..19e5d373770343d03ffbf96c076434e987c2c646 100644 --- a/scripts/HFIR_4Circle_Reduction/hfctables.py +++ b/scripts/HFIR_4Circle_Reduction/hfctables.py @@ -260,7 +260,6 @@ class UBMatrixTable(tableBase.NTableWidget): Guarantees: return a 3 x 3 ndarray :return: """ - # print '[DB] MatrixTable: _Matrix = ', self._matrix return self._matrix.copy() def get_matrix_str(self): @@ -477,7 +476,7 @@ class ProcessTableWidget(tableBase.NTableWidget): """ TableSetup = [('Scan', 'int'), ('Intensity', 'float'), - ('Corrected Intensity', 'float'), + ('Corrected', 'float'), ('Status', 'str'), ('Peak Centre', 'str'), ('HKL', 'str'), @@ -499,6 +498,7 @@ class ProcessTableWidget(tableBase.NTableWidget): # some commonly used column index self._colIndexKIndex = None self._colIndexHKL = None + self._colIndexStatus = None return @@ -558,11 +558,11 @@ class ProcessTableWidget(tableBase.NTableWidget): assert isinstance(scans, list) if allow_duplicate_scans is False: - scan_list = self.get_scan_list() + scan_list = self.get_scan_list(output_row_number=False) else: scan_list = list() - print '[DB...BAT] <append scans> in-table scans: ' % scan_list + print '[DB...BAT] Existing scan list: ', scan_list # set value as default # Append rows @@ -633,10 +633,11 @@ class ProcessTableWidget(tableBase.NTableWidget): return self.get_cell_value(i_row, j_col_merged) - def get_scan_list(self): + def get_scan_list(self, output_row_number=True): """ Get all scans that are already listed in the table. - :return: + :param output_row_number: + :return: list of 2-tuple or integer according to value of output_row_number """ scan_list = list() num_rows = self.rowCount() @@ -644,7 +645,11 @@ class ProcessTableWidget(tableBase.NTableWidget): for i_row in xrange(num_rows): scan_num = self.get_cell_value(i_row, col_scan_index) - scan_list.append((scan_num, i_row)) + if output_row_number: + scan_list.append((scan_num, i_row)) + else: + scan_list.append(scan_num) + # END-FOR (i_row) return scan_list @@ -685,6 +690,7 @@ class ProcessTableWidget(tableBase.NTableWidget): # set up column index self._colIndexKIndex = self.TableSetup.index(('K-Index', 'int')) self._colIndexHKL = self.TableSetup.index(('HKL', 'str')) + self._colIndexStatus = self.TableSetup.index(('Status', 'str')) return @@ -792,7 +798,7 @@ class ProcessTableWidget(tableBase.NTableWidget): # END-IF if lorentz_corrected: - col_name = ('Corrected Intensity', 'float') + col_name = ('Corrected', 'float') else: col_name = ('Intensity', 'float') intensity_col_index = ProcessTableWidget.TableSetup.index(col_name) @@ -828,7 +834,7 @@ class ProcessTableWidget(tableBase.NTableWidget): for i_row in xrange(num_rows): tmp_scan_no = self.get_cell_value(i_row, 0) if scan_no == tmp_scan_no: - self.update_cell_value(i_row, 2, status) + self.update_cell_value(i_row, self._colIndexStatus, status) set_done = True break # END-FOR @@ -850,8 +856,7 @@ class ProcessTableWidget(tableBase.NTableWidget): assert isinstance(status, str), 'Status (description) must be a string, but not %s.' % str(type(status)) # Set - i_status = self.TableSetup.index(('Status', 'str')) - self.update_cell_value(row_number, i_status, status) + self.update_cell_value(row_number, self._colIndexStatus, status) return diff --git a/scripts/HFIR_4Circle_Reduction/multi_threads_helpers.py b/scripts/HFIR_4Circle_Reduction/multi_threads_helpers.py new file mode 100644 index 0000000000000000000000000000000000000000..25701583973606f1e35f55a6f42a33d057b7a5d8 --- /dev/null +++ b/scripts/HFIR_4Circle_Reduction/multi_threads_helpers.py @@ -0,0 +1,252 @@ +#pylint: disable=W0403,R0913 + +from PyQt4 import QtCore +from PyQt4.QtCore import QThread + +import reduce4circleControl as r4c + + +class AddPeaksThread(QThread): + """ + A QThread class to add peaks to Mantid to calculate UB matrix + """ + # signal for a peak is added: int_0 = experiment number, int_1 = scan number + peakAddedSignal = QtCore.pyqtSignal(int, int) + # signal for status: int_0 = experiment number, int_1 = scan number, int_2 = progress (0...) + peakStatusSignal = QtCore.pyqtSignal(int, int, int) + + def __init__(self, main_window, exp_number, scan_number_list): + """ + Initialization + :param main_window: + :param exp_number: + :param scan_number_list: + """ + QThread.__init__(self) + + # check + assert main_window is not None, 'Main window cannot be None' + assert isinstance(exp_number, int), 'Experiment number must be an integer.' + assert isinstance(scan_number_list, list), 'Scan number list must be a list but not %s.' \ + '' % str(type(scan_number_list)) + + # set values + self._mainWindow = main_window + self._expNumber = exp_number + self._scanNumberList = scan_number_list + + # connect to the updateTextEdit slot defined in app1.py + self.peakAddedSignal.connect(self._mainWindow.update_peak_added_info) + self.peakStatusSignal.connect(self._mainWindow.update_adding_peaks_status) + + return + + def __del__(self): + """ + Delete signal + :return: + """ + self.wait() + + return + + def run(self): + """ + method for thread is running + :return: + """ + # declare list of failed + failed_list = list() + + # loop over all scan numbers + for index, scan_number in enumerate(self._scanNumberList): + # update state + self.peakStatusSignal.emit(self._expNumber, scan_number, index) + + # merge peak + status, err_msg = self._mainWindow.controller.merge_pts_in_scan( + self._expNumber, scan_number, [], 'q-sample') + + # continue to the next scan if there is something wrong + if status is False: + failed_list.append((scan_number, err_msg)) + continue + + # find peak + self._mainWindow.controller.find_peak(self._expNumber, scan_number) + + # get PeakInfo + peak_info = self._mainWindow.controller.get_peak_info(self._expNumber, scan_number) + assert isinstance(peak_info, r4c.PeakProcessHelper) + + # send signal to main window for peak being added + self.peakAddedSignal.emit(self._expNumber, scan_number) + # END-FOR + + # send signal with unphysical scan number to flag the end of operation. + self.peakStatusSignal.emit(self._expNumber, -1, len(self._scanNumberList)) + + # pop error if there is any scan that is not reduced right + if len(failed_list) > 0: + failed_scans_str = 'Unable to merge scans: ' + sum_error_str = '' + for fail_tup in failed_list: + failed_scans_str += '%d, ' % fail_tup[0] + sum_error_str += '%s\n' % fail_tup[1] + # END-FOR + + self._mainWindow.pop_one_button_dialog(failed_scans_str) + self._mainWindow.pop_one_button_dialog(sum_error_str) + # END-IF + + return + + +class IntegratePeaksThread(QThread): + """ + A thread to integrate peaks + """ + # signal to emit before a merge/integration status: exp number, scan number, progress, mode + peakMergeSignal = QtCore.pyqtSignal(int, int, float, int) + errorSignal = QtCore.pyqtSignal(int, int, str) + + def __init__(self, main_window, exp_number, scan_tuple_list, mask_det, mask_name, norm_type, num_pt_bg_left, + num_pt_bg_right): + """ + + :param main_window: + :param exp_number: + :param scan_tuple_list: list of tuples for scan as (scan number, pt number list, state as merged) + :param mask_det: + :param mask_name: + :param norm_type: type of normalization + :param num_pt_bg_left: number of Pt in the left + :param num_pt_bg_right: number of Pt for background in the right + """ + # start thread + QThread.__init__(self) + + # check + assert main_window is not None, 'Main window cannot be None' + assert isinstance(exp_number, int), 'Experiment number must be an integer.' + assert isinstance(scan_tuple_list, list), 'Scan (info) tuple list must be a list but not %s.' \ + '' % str(type(scan_tuple_list)) + assert isinstance(mask_det, bool), 'Parameter mask_det must be a boolean but not %s.' \ + '' % str(type(mask_det)) + assert isinstance(mask_name, str), 'Name of mask must be a string but not %s.' % str(type(mask_name)) + assert isinstance(norm_type, str), 'Normalization type must be a string but not %s.' \ + '' % str(type(norm_type)) + assert isinstance(num_pt_bg_left, int) and num_pt_bg_left >= 0 + assert isinstance(num_pt_bg_right, int) and num_pt_bg_right >= 0 + + # set values + self._mainWindow = main_window + self._expNumber = exp_number + self._scanTupleList = scan_tuple_list[:] + self._maskDetector = mask_det + self._normalizeType = norm_type + self._selectedMaskName = mask_name + self._numBgPtLeft = num_pt_bg_left + self._numBgPtRight = num_pt_bg_right + + # link signals + self.peakMergeSignal.connect(self._mainWindow.update_merge_status) + self.errorSignal.connect(self._mainWindow.update_merge_error) + + return + + def __del__(self): + """ + Delete signal + :return: + """ + self.wait() + + return + + def run(self): + """ + Execute the thread! + :return: + """ + for index, scan_tup in enumerate(self._scanTupleList): + # check + assert isinstance(scan_tup, tuple) and len(scan_tup) == 3 + scan_number, pt_number_list, merged = scan_tup + + # emit signal for run start (mode 0) + mode = int(0) + self.peakMergeSignal.emit(self._expNumber, scan_number, float(index), mode) + + # merge if not merged + if merged is False: + self._mainWindow.controller.merge_pts_in_scan(exp_no=self._expNumber, scan_no=scan_number, + pt_num_list=pt_number_list, + target_frame='q-sample') + self._mainWindow.ui.tableWidget_mergeScans.set_status(scan_number, 'Merged') + # END-IF + + # calculate peak center + try: + status, ret_obj = self._mainWindow.controller.calculate_peak_center(self._expNumber, scan_number, + pt_number_list) + except RuntimeError as run_err: + status = False + ret_obj = 'RuntimeError: %s.' % str(run_err) + except AssertionError as ass_err: + status = False + ret_obj = 'AssertionError: %s.' % str(ass_err) + + if status: + center_i = ret_obj + else: + error_msg = 'Unable to find peak for exp %d scan %d: %s.' % (self._expNumber, scan_number, str(ret_obj)) + self._mainWindow.controller.set_peak_intensity(self._expNumber, scan_number, 0.) + self._mainWindow.ui.tableWidget_mergeScans.set_peak_intensity(None, scan_number, 0., False) + self._mainWindow.ui.tableWidget_mergeScans.set_status(scan_number, error_msg) + continue + + # check given mask workspace + if self._maskDetector: + self._mainWindow.controller.check_generate_mask_workspace(self._expNumber, scan_number, + self._selectedMaskName) + + # integrate peak + print '[DB...BAD] Normalization: %s; Use Mask = %s, Mask Workspace = %s.' % ( + self._normalizeType, str(self._maskDetector), self._selectedMaskName + ) + status, ret_obj = self._mainWindow.controller.integrate_scan_peaks(exp=self._expNumber, + scan=scan_number, + peak_radius=1.0, + peak_centre=center_i, + merge_peaks=False, + use_mask=self._maskDetector, + normalization=self._normalizeType, + mask_ws_name=self._selectedMaskName) + # handle integration error + if status: + # get PT dict + pt_dict = ret_obj + else: + # integration failed + error_msg = str(ret_obj) + self.errorSignal.emit(self._expNumber, scan_number, error_msg) + continue + + # calculate background value + background_pt_list = pt_number_list[:self._numBgPtLeft] + pt_number_list[-self._numBgPtRight:] + avg_bg_value = self._mainWindow.controller.estimate_background(pt_dict, background_pt_list) + + # correct intensity by background value + intensity_i = self._mainWindow.controller.simple_integrate_peak(pt_dict, avg_bg_value) + + # emit signal to main app for peak intensity value + mode = 1 + self.peakMergeSignal.emit(self._expNumber, scan_number, float(intensity_i), mode) + # END-FOR + + # terminate the process + self.peakMergeSignal.emit(self._expNumber, -1, len(self._scanTupleList), 2) + self._mainWindow.ui.tableWidget_mergeScans.select_all_rows(False) + + return diff --git a/scripts/HFIR_4Circle_Reduction/peakprocesshelper.py b/scripts/HFIR_4Circle_Reduction/peakprocesshelper.py index 63788445a25a2f1e27414f05b7a6db1a375dd12d..73f5dfd8668774e410ff4c52a7418bcf320bae67 100644 --- a/scripts/HFIR_4Circle_Reduction/peakprocesshelper.py +++ b/scripts/HFIR_4Circle_Reduction/peakprocesshelper.py @@ -44,6 +44,7 @@ class PeakProcessHelper(object): self._myPeakWSKey = (None, None, None) self._myPeakIndex = None + self._ptIntensityDict = None self._myLastPeakUB = None @@ -103,7 +104,6 @@ class PeakProcessHelper(object): # END-FOR (i_peak) self._avgPeakCenter = q_sample_sum/weight_sum - print '[DB] Weighted peak center = %s' % str(self._avgPeakCenter) return @@ -159,10 +159,16 @@ class PeakProcessHelper(object): def get_weighted_peak_centres(self): """ Get the peak centers found in peak workspace. Guarantees: the peak centers and its weight (detector counts) are exported - :return: 2 lists: list of 3-tuple (Qx, Qy, Qz) and list of double (Det_Counts) + :return: 2-tuple: list of 3-tuple (Qx, Qy, Qz) + list of double (Det_Counts) """ + # get PeaksWorkspace + if AnalysisDataService.doesExist(self._myPeakWorkspaceName) is False: + raise RuntimeError('PeaksWorkspace %s does ot exit.' % self._myPeakWorkspaceName) + peak_ws = AnalysisDataService.retrieve(self._myPeakWorkspaceName) + # get peak center, peak intensity and etc. peak_center_list = list() peak_intensity_list = list() num_peaks = peak_ws.getNumberPeaks() @@ -184,7 +190,7 @@ class PeakProcessHelper(object): # get SPICE table spice_table_name = get_spice_table_name(self._myExpNumber, self._myScanNumber) assert AnalysisDataService.doesExist(spice_table_name), 'Spice table for exp %d scan %d cannot be found.' \ - '' % (self._myExpNumber, self._myScanNumber) + '' % (self._myExpNumber, self._myScanNumber) spice_table_ws = AnalysisDataService.retrieve(spice_table_name) @@ -264,6 +270,20 @@ class PeakProcessHelper(object): return + def set_pt_intensity(self, pt_intensity_dict): + """ + Set Pt. intensity + :param pt_intensity_dict: + :return: + """ + assert isinstance(pt_intensity_dict, dict) + + print '[DB...BAT] Pt intensity dict keys: ', pt_intensity_dict.keys() + + self._ptIntensityDict = pt_intensity_dict + + return + def get_sigma(self): """ Get peak intensity's sigma :return: @@ -296,9 +316,6 @@ class PeakProcessHelper(object): self._userHKL[1] = mi_k self._userHKL[2] = mi_l - print '[DB] PeakInfo Set User HKL to (%f, %f, %f) ' % (self._userHKL[0], self._userHKL[1], - self._userHKL[2]) - return def get_experiment_info(self): diff --git a/scripts/HFIR_4Circle_Reduction/reduce4circleControl.py b/scripts/HFIR_4Circle_Reduction/reduce4circleControl.py index d17e9fb06edcc4c9de6bdf4f43f816e58ea6c1c6..83d3408397991d9732f37edab855782d68023b47 100644 --- a/scripts/HFIR_4Circle_Reduction/reduce4circleControl.py +++ b/scripts/HFIR_4Circle_Reduction/reduce4circleControl.py @@ -209,7 +209,7 @@ class CWSCDReductionControl(object): if self.has_merged_data(exp_number, scan_number, pt_number_list): pass else: - raise RuntimeError('Data must be merged before') + return False, 'Exp %d Scan %d: data must be merged already.' % (exp_number, scan_number) # Find peak in Q-space merged_ws_name = get_merged_md_name(self._instrumentName, exp_number, scan_number, pt_number_list) @@ -579,7 +579,6 @@ class CWSCDReductionControl(object): return False, 'RuntimeError: %s.' % str(error) # get the information whether there is any k-shift vector specified by user - print '[DB...Prototype] Current k-shift vectors are ... ', self._kShiftDict # form k-shift and peak intensity information scan_kindex_dict = dict() @@ -601,7 +600,11 @@ class CWSCDReductionControl(object): no_shift = len(scan_kindex_dict) == 0 for scan_number in scan_number_list: peak_dict = dict() - peak_dict['hkl'] = self._myPeakInfoDict[(exp_number, scan_number)]. get_current_hkl() + try: + peak_dict['hkl'] = self._myPeakInfoDict[(exp_number, scan_number)]. get_current_hkl() + except RuntimeError as run_err: + return False, str('Peak index error: %s.' % run_err) + peak_dict['intensity'] = self._myPeakInfoDict[(exp_number, scan_number)].get_intensity() peak_dict['sigma'] = self._myPeakInfoDict[(exp_number, scan_number)].get_sigma() if no_shift: @@ -619,7 +622,7 @@ class CWSCDReductionControl(object): except AssertionError as error: return False, 'AssertionError: %s.' % str(error) except RuntimeError as error: - return False, 'RuntimeError; %s.' % str(error) + return False, 'RuntimeError: %s.' % str(error) return True, file_content @@ -673,7 +676,6 @@ class CWSCDReductionControl(object): # Find peak in Q-space merged_ws_name = get_merged_md_name(self._instrumentName, exp_number, scan_number, pt_number_list) peak_ws_name = get_peak_ws_name(exp_number, scan_number, pt_number_list) - print '[DB] Found peaks are output workspace %s.' % peak_ws_name api.FindPeaksMD(InputWorkspace=merged_ws_name, MaxPeaks=10, PeakDistanceThreshold=5., @@ -1110,7 +1112,8 @@ class CWSCDReductionControl(object): def integrate_scan_peaks(self, exp, scan, peak_radius, peak_centre, merge_peaks=True, use_mask=False, - normalization='', mask_ws_name=None): + normalization='', mask_ws_name=None, + scale_factor=1): """ :param exp: :param scan: @@ -1121,6 +1124,7 @@ class CWSCDReductionControl(object): :param use_mask: :param normalization: normalization set up (by time or ...) :param mask_ws_name: mask workspace name or None + :param scale_factor: integrated peaks' scaling factor :return: """ # check @@ -1166,10 +1170,7 @@ class CWSCDReductionControl(object): elif normalization == 'monitor': norm_by_mon = True - print '[DB-INFO] Integrate Pt. with mask workspace %s. Norm by time = %d; Norm by monitor = %d.' \ - '' % (mask_ws_name, norm_by_time, norm_by_mon) - - # VZ-FUTURE: Are you sure ScaleFactor is 1 !!! + # integrate peak of a scan api.IntegratePeaksCWSD(InputWorkspace=md_ws_name, OutputWorkspace=integrated_peak_ws_name, PeakRadius=peak_radius, @@ -1178,13 +1179,12 @@ class CWSCDReductionControl(object): NormalizeByMonitor=norm_by_mon, NormalizeByTime=norm_by_time, MaskWorkspace=mask_ws_name, - ScaleFactor=1) + ScaleFactor=scale_factor) # process the output workspace pt_dict = dict() out_peak_ws = AnalysisDataService.retrieve(integrated_peak_ws_name) num_peaks = out_peak_ws.rowCount() - print '[DB....BAT] There are %d peaks to export!' % num_peaks for i_peak in xrange(num_peaks): peak_i = out_peak_ws.getPeak(i_peak) @@ -1193,6 +1193,11 @@ class CWSCDReductionControl(object): pt_dict[run_number_i] = intensity_i # END-FOR + # store the data into peak info + if (exp, scan) not in self._myPeakInfoDict: + raise RuntimeError('Exp %d Scan %d is not recorded in PeakInfo-Dict' % (exp, scan)) + self._myPeakInfoDict[(exp, scan)].set_pt_intensity(pt_dict) + return True, pt_dict def integrate_peaks_q(self, exp_no, scan_no): @@ -1367,6 +1372,7 @@ class CWSCDReductionControl(object): def load_spice_scan_file(self, exp_no, scan_no, spice_file_name=None): """ Load a SPICE scan file to table workspace and run information matrix workspace. + :param exp_no: :param scan_no: :param spice_file_name: :return: status (boolean), error message (string) @@ -1374,6 +1380,7 @@ class CWSCDReductionControl(object): # Default for exp_no if exp_no is None: exp_no = self._expNumber + print '[DB...BAD] Load Spice Scan File Exp Number = %d, Stored Exp. Number = %d' % (exp_no, self._expNumber) # Check whether the workspace has been loaded assert isinstance(exp_no, int) @@ -1495,7 +1502,6 @@ class CWSCDReductionControl(object): continue pt_list_str += ',%d' % pt # END-FOR (pt) - print '[DB] Pt list = %s' % pt_list_str if pt_list_str == '-1': return False, err_msg @@ -1829,8 +1835,6 @@ class CWSCDReductionControl(object): oriented_lattice.errorc(), oriented_lattice.erroralpha(), oriented_lattice.errorbeta(), oriented_lattice.errorgamma()] - print '[DB-BAT] Refined UB = ', refined_ub_matrix, 'of type', type(refined_ub_matrix) - result_tuple = (peak_ws, refined_ub_matrix, lattice, lattice_error) return result_tuple @@ -2078,7 +2082,6 @@ class CWSCDReductionControl(object): try: ws = self._mySpiceTableDict[(exp_no, scan_no)] except KeyError: - print '[DB] Keys to SPICE TABLE: %s' % str(self._mySpiceTableDict.keys()) return None return ws @@ -2236,10 +2239,8 @@ class CWSCDReductionControl(object): wavelength = get_hb3a_wavelength(m1) if wavelength is None: q_range = 0. - print '[DB-BAT] 2theta = %f, lambda = None, Q = %f' % (two_theta, q_range) else: q_range = 4.*math.pi*math.sin(two_theta/180.*math.pi*0.5)/wavelength - print '[DB-BAT] 2theta = %f, lambda = %f, Q = %f' % (two_theta, wavelength, q_range) # appending to list scan_sum_list.append([max_count, scan_number, max_row, max_h, max_k, max_l, diff --git a/scripts/HFIR_4Circle_Reduction/reduce4circleGUI.py b/scripts/HFIR_4Circle_Reduction/reduce4circleGUI.py index 2874c02a89dc22376d0cbab66d8c16746e717df6..c5a16bb452d5c93352f3594694e6e9c064444613 100644 --- a/scripts/HFIR_4Circle_Reduction/reduce4circleGUI.py +++ b/scripts/HFIR_4Circle_Reduction/reduce4circleGUI.py @@ -9,12 +9,20 @@ import sys import math import csv import time +import datetime import random import numpy from scipy.optimize import curve_fit from PyQt4 import QtCore, QtGui +from PyQt4.QtCore import QThread +try: + _fromUtf8 = QtCore.QString.fromUtf8 +except AttributeError: + def _fromUtf8(s): + return s + try: from mantidqtpython import MantidQt except ImportError as e: @@ -22,16 +30,13 @@ except ImportError as e: else: NO_SCROLL = False -import reduce4circleControl as r4c +# import reduce4circleControl as r4c import guiutility as gutil import fourcircle_utility as hb3a import plot3dwindow +from multi_threads_helpers import * + -try: - _fromUtf8 = QtCore.QString.fromUtf8 -except AttributeError: - def _fromUtf8(s): - return s # import line for the UI python class from ui_MainWindow import Ui_MainWindow @@ -58,10 +63,14 @@ class MainWindow(QtGui.QMainWindow): # Make UI scrollable if NO_SCROLL is False: self._scrollbars = MantidQt.API.WidgetScrollbarDecorator(self) - self._scrollbars.setEnabled(True) # Must follow after setupUi(self)! + self._scrollbars.setEnabled(True) # Must follow after setupUi(self)! self._init_widgets() + # thread + self._myIntegratePeaksThread = None + self._addUBPeaksThread = None + # Mantid configuration self._instrument = str(self.ui.comboBox_instrument.currentText()) # config = ConfigService.Instance() @@ -261,11 +270,26 @@ class MainWindow(QtGui.QMainWindow): self._my3DWindow = None self._refineConfigWindow = None + # Timing and thread 'global' + self._startMeringScans = time.clock() + self._errorMessageEnsemble = '' + # QSettings self.load_settings() return + @property + def controller(self): + """ Parameter controller + """ + assert self._myControl is not None, 'Controller cannot be None.' + assert isinstance(self._myControl, r4c.CWSCDReductionControl), \ + 'My controller must be of type %s, but not %s.' % ('CWSCDReductionControl', + self._myControl.__class__.__name__) + + return self._myControl + def evt_show_survey(self): """ Show survey result @@ -319,7 +343,6 @@ class MainWindow(QtGui.QMainWindow): self.ui.lineEdit_localSpiceDir.setEnabled(True) self.ui.pushButton_browseLocalDataDir.setEnabled(True) - return def _build_peak_info_list(self): @@ -435,48 +458,17 @@ class MainWindow(QtGui.QMainWindow): # get experiment number status, exp_number = gutil.parse_integers_editors(self.ui.lineEdit_exp) - assert status + if not status: + self.pop_one_button_dialog('Unable to get experiment number\n due to %s.' % str(exp_number)) + return # switch to tab-3 self.ui.tabWidget.setCurrentIndex(MainWindow.TabPage['Calculate UB']) - # find peak and add peak - failed_list = list() - for scan_number in scan_number_list: - # merge peak - status, err_msg = self._myControl.merge_pts_in_scan(exp_number, scan_number, [], 'q-sample') - - # continue to the next scan if there is something wrong - if status is False: - failed_list.append((scan_number, err_msg)) - continue - - # find peak - self._myControl.find_peak(exp_number, scan_number) - - # get PeakInfo - peak_info = self._myControl.get_peak_info(exp_number, scan_number) - assert isinstance(peak_info, r4c.PeakProcessHelper) - - # retrieve and set HKL from spice table - peak_info.retrieve_hkl_from_spice_table() - - # add to table - self.set_ub_peak_table(peak_info) - # END-FOR - - # pop error if there is any scan that is not reduced right - if len(failed_list) > 0: - failed_scans_str = 'Unable to merge scans: ' - sum_error_str = '' - for fail_tup in failed_list: - failed_scans_str += '%d, ' % fail_tup[0] - sum_error_str += '%s\n' % fail_tup[1] - # END-FOR - - self.pop_one_button_dialog(failed_scans_str) - self.pop_one_button_dialog(sum_error_str) - # END-FOR + # prototype for a new thread + self.ui.progressBar_add_ub_peaks.setRange(0, len(scan_number_list)) + self._addUBPeaksThread = AddPeaksThread(self, exp_number, scan_number_list) + self._addUBPeaksThread.start() return @@ -524,8 +516,6 @@ class MainWindow(QtGui.QMainWindow): self.pop_one_button_dialog(int_list) return exp_no, scan_no = int_list - print '[DB] Experiment number = ', exp_no - print '[DB] Scan numbers = ', str(scan_no), 'of type ', type(scan_no) # Get HKL from GUI status, float_list = gutil.parse_float_editors([self.ui.lineEdit_H, @@ -819,7 +809,6 @@ class MainWindow(QtGui.QMainWindow): """ # Find out the lines to get deleted row_num_list = self.ui.tableWidget_peaksCalUB.get_selected_rows() - print '[DB] Row %s are selected' % str(row_num_list) # Delete self.ui.tableWidget_peaksCalUB.delete_rows(row_num_list) @@ -980,10 +969,14 @@ class MainWindow(QtGui.QMainWindow): # write user_header = str(self.ui.lineEdit_fpHeader.text()) try: - status, file_content = self._myControl.export_to_fullprof(exp_number, scan_number_list, user_header, fp_name) + status, file_content = self._myControl.export_to_fullprof(exp_number, scan_number_list, + user_header, fp_name) self.ui.plainTextEdit_fpContent.setPlainText(file_content) if status is False: - self.pop_one_button_dialog(file_content) + error_msg = file_content + if error_msg.startswith('Peak index error'): + error_msg = 'You may forget to index peak\n' + error_msg + self.pop_one_button_dialog(error_msg) except AssertionError as a_err: self.pop_one_button_dialog(str(a_err)) return @@ -1109,9 +1102,6 @@ class MainWindow(QtGui.QMainWindow): else: exp_number, scan_number = ret_obj - # mask workspace? - mask_detectors = self.ui.checkBox_applyMask.isChecked() - normalization = str(self.ui.comboBox_ptCountType.currentText()) if normalization.count('Time') > 0: norm_type = 'time' @@ -1129,14 +1119,28 @@ class MainWindow(QtGui.QMainWindow): else: this_peak_centre = ret_obj + # scale factor + try: + intensity_scale_factor = float(self.ui.lineEdit_scaleFactor.text()) + except ValueError: + intensity_scale_factor = 1. + # get masked workspace + mask_name = str(self.ui.comboBox_maskNames2.currentText()) + if mask_name.startswith('No Mask'): + mask_name = None + # mask workspace? + mask_detectors = mask_name is not None + status, ret_obj = self._myControl.integrate_scan_peaks(exp=exp_number, scan=scan_number, peak_radius=1.0, peak_centre=this_peak_centre, merge_peaks=False, use_mask=mask_detectors, - normalization=norm_type) + mask_ws_name=mask_name, + normalization=norm_type, + scale_factor=intensity_scale_factor) # result due to error if status is False: @@ -1148,8 +1152,6 @@ class MainWindow(QtGui.QMainWindow): pt_dict = ret_obj assert isinstance(pt_dict, dict) - print '[DB-BAT] Returned Pt. dict: ', pt_dict - # clear table if self.ui.tableWidget_peakIntegration.rowCount() > 0: self.ui.tableWidget_peakIntegration.remove_all_rows() @@ -1162,7 +1164,8 @@ class MainWindow(QtGui.QMainWindow): intensity_list.append(pt_intensity) status, msg = self.ui.tableWidget_peakIntegration.append_pt(pt, -1, pt_intensity) if not status: - print '[Error!] Unable to add Pt %d due to %s.' % (pt, msg) + error_msg = '[Error!] Unable to add Pt %d due to %s.' % (pt, msg) + self.pop_one_button_dialog(error_msg) # Set up the experiment information to table self.ui.tableWidget_peakIntegration.set_exp_info(exp_number, scan_number) @@ -1216,10 +1219,12 @@ class MainWindow(QtGui.QMainWindow): # background Pt. status, num_bg_pt = gutil.parse_integers_editors(self.ui.lineEdit_numPt4Background, allow_blank=False) - assert status and num_bg_pt > 0, 'Number of Pt number for background must be larger than 0!' + if not status or num_bg_pt == 0: + self.pop_one_button_dialog('Number of Pt number for background must be larger than 0: %s!' % str(num_bg_pt)) + return - # integrate peak - grand_error_message = '' + # get the merging information: each item should be a tuple as (scan number, pt number list, merged) + scan_number_list = list() for row_number in row_number_list: # get scan number and pt numbers scan_number = self.ui.tableWidget_mergeScans.get_scan_number(row_number) @@ -1227,92 +1232,42 @@ class MainWindow(QtGui.QMainWindow): # set intensity to zero and error message if status is False: - error_msg = 'Unable to get Pt. of experiment %d scan %d due to %s.' % ( - exp_number, scan_number, str(pt_number_list)) - self._myControl.set_peak_intensity(exp_number, scan_number, 0.) + error_msg = 'Unable to get Pt. of experiment %d scan %d due to %s.' % (exp_number, scan_number, + str(pt_number_list)) + self.controller.set_peak_intensity(exp_number, scan_number, 0.) self.ui.tableWidget_mergeScans.set_peak_intensity(row_number, scan_number, 0., False) self.ui.tableWidget_mergeScans.set_status(scan_number, error_msg) continue # merge all Pt. of the scan if they are not merged. merged = self.ui.tableWidget_mergeScans.get_merged_status(row_number) - if merged is False: - self._myControl.merge_pts_in_scan(exp_no=exp_number, scan_no=scan_number, pt_num_list=pt_number_list, - target_frame='q-sample') - self.ui.tableWidget_mergeScans.set_status_by_row(row_number, 'Done') - # END-IF - - # calculate peak center - try: - status, ret_obj = self._myControl.calculate_peak_center(exp_number, scan_number, pt_number_list) - except RuntimeError as run_err: - status = False - ret_obj = 'RuntimeError: %s.' % str(run_err) - except AssertionError as ass_err: - status = False - ret_obj = 'AssertionError: %s.' % str(ass_err) - - if status: - center_i = ret_obj - else: - error_msg = 'Unable to find peak for exp %d scan %d: %s.' % (exp_number, scan_number, str(ret_obj)) - self._myControl.set_peak_intensity(exp_number, scan_number, 0.) - self.ui.tableWidget_mergeScans.set_peak_intensity(row_number, scan_number, 0., False) - self.ui.tableWidget_mergeScans.set_status(scan_number, error_msg) - continue - - # mask workspace - # VZ-FUTURE: consider to modify method generate_mask_workspace() such that it can be generalized outside - # loop - if mask_det: - self._myControl.check_generate_mask_workspace(exp_number, scan_number, selected_mask) - - # integrate peak - status, ret_obj = self._myControl.integrate_scan_peaks(exp=exp_number, - scan=scan_number, - peak_radius=1.0, - peak_centre=center_i, - merge_peaks=False, - use_mask=mask_det, - normalization=norm_type, - mask_ws_name=selected_mask) - # handle integration error - if not status: - error_msg = str(ret_obj) - self._myControl.set_peak_intensity(exp_number, scan_number, 0.) - self.ui.tableWidget_mergeScans.set_peak_intensity(row_number, scan_number, 0., False) - self.ui.tableWidget_mergeScans.set_status(scan_number, error_msg) - continue - - pt_dict = ret_obj - - background_pt_list = pt_number_list[:num_bg_pt] + pt_number_list[-num_bg_pt:] - avg_bg_value = self._myControl.estimate_background(pt_dict, background_pt_list) - intensity_i = self._myControl.simple_integrate_peak(pt_dict, avg_bg_value) - - # check intensity value - if intensity_i < 0: - # set to status - error_msg = 'Negative intensity: %.3f' % intensity_i - self.ui.tableWidget_mergeScans.set_status(scan_no=scan_number, status=error_msg) - # reset intensity to 0. - intensity_i = 0. - # set the calculated peak intensity to _peakInfoDict - status, error_msg = self._myControl.set_peak_intensity(exp_number, scan_number, intensity_i) - if status is False: - grand_error_message += error_msg + '\n' - continue - - # set the value to table - self.ui.tableWidget_mergeScans.set_peak_intensity(row_number, None, intensity_i) + # add to list + scan_number_list.append((scan_number, pt_number_list, merged)) + self.ui.tableWidget_mergeScans.set_status_by_row(row_number, 'Waiting') # END-FOR - # pop error message if there is any - if len(grand_error_message) > 0: - self.pop_one_button_dialog(grand_error_message) + # set the progress bar + self.ui.progressBar_mergeScans.setRange(0, len(scan_number_list)) + self.ui.progressBar_mergeScans.setValue(0) + self.ui.progressBar_mergeScans.setTextVisible(True) + self.ui.progressBar_mergeScans.setStatusTip('Hello') + + # process background setup + status, ret_obj = gutil.parse_integers_editors([self.ui.lineEdit_numPt4Background, + self.ui.lineEdit_numPt4BackgroundRight], + allow_blank=False) + if not status: + error_msg = str(ret_obj) + self.pop_one_button_dialog(error_msg) + return + num_pt_bg_left = ret_obj[0] + num_pt_bg_right = ret_obj[1] - self.ui.tableWidget_mergeScans.select_all_rows(False) + self._myIntegratePeaksThread = IntegratePeaksThread(self, exp_number, scan_number_list, + mask_det, selected_mask, norm_type, + num_pt_bg_left, num_pt_bg_right) + self._myIntegratePeaksThread.start() return @@ -1458,10 +1413,12 @@ class MainWindow(QtGui.QMainWindow): # get experiment number and scan number from the table exp_number, scan_number = self.ui.tableWidget_peakIntegration.get_exp_info() + mask_name = str(self.ui.comboBox_maskNames2.currentText()) + masked = not mask_name.startswith('No Mask') has_integrated = self._myControl.has_integrated_peak(exp_number, scan_number, pt_list=None, normalized_by_monitor=norm_by_monitor, normalized_by_time=norm_by_time, - masked=self.ui.checkBox_applyMask.isChecked()) + masked=masked) # integrate and/or plot if has_integrated: @@ -1675,7 +1632,6 @@ class MainWindow(QtGui.QMainWindow): # Process scan_row_list = self.ui.tableWidget_mergeScans.get_selected_scans() - print '[DB] %d scans have been selected to merge.' % len(scan_row_list) frame = str(self.ui.comboBox_mergeScanFrame.currentText()) for tup2 in scan_row_list: # @@ -1961,10 +1917,9 @@ class MainWindow(QtGui.QMainWindow): :return: """ lower_left_c, upper_right_c = self.ui.graphicsView.get_roi() - print '[DB-BAT] Save RIO as [%s, %s]' % (str(lower_left_c), str(upper_right_c)) status, par_val_list = gutil.parse_integers_editors([self.ui.lineEdit_exp, self.ui.lineEdit_run]) - assert status + assert status, str(par_val_list) exp_number = par_val_list[0] scan_number = par_val_list[1] @@ -2102,8 +2057,14 @@ class MainWindow(QtGui.QMainWindow): # calculate HKL from SPICE ub_matrix = self._myControl.get_ub_matrix(exp_number) index_status, ret_tup = self._myControl.index_peak(ub_matrix, scan_i) - assert index_status - hkl_i = ret_tup[0] + if index_status: + hkl_i = ret_tup[0] + else: + # unable to index peak. use fake hkl and set error message + hkl_i = [0, 0, 0] + error_msg = 'Scan %d: %s' % (scan_i, str(ret_tup)) + self.ui.tableWidget_mergeScans.set_status(scan_i, error_msg) + # END-IF-ELSE(index) # END-IF-ELSE (hkl_from_spice) # round @@ -2416,9 +2377,6 @@ class MainWindow(QtGui.QMainWindow): # peak center weight_peak_centers, weight_peak_intensities = peak_info.get_weighted_peak_centres() qx, qy, qz = peak_info.get_peak_centre() - # get peak intensity - intensity = self._myControl.get_peak_integrated_intensity(exp_number, scan_number) - #intensity = 100000 # convert from list to ndarray num_pt_peaks = len(weight_peak_centers) @@ -2436,7 +2394,8 @@ class MainWindow(QtGui.QMainWindow): avg_peak_centre[0][0] = qx avg_peak_centre[0][1] = qy avg_peak_centre[0][2] = qz - avg_peak_intensity[0] = intensity + # integrated peak intensity + avg_peak_intensity[0] = sum(pt_peak_intensity_array) return md_file_name, pt_peak_centre_array, pt_peak_intensity_array, avg_peak_centre, avg_peak_intensity @@ -2832,3 +2791,136 @@ class MainWindow(QtGui.QMainWindow): self.ui.plainTextEdit_rawDataInformation.setPlainText(info) return + + def update_adding_peaks_status(self, exp_number, scan_number, progress): + """ + Update the status for adding peak to UB matrix calculating + :param exp_number: + :param scan_number: + :param progress: + :return: + """ + # show message to bar + if scan_number < 0: + message = 'Peak processing finished' + else: + message = 'Processing experiment %d scan %d starting from %s.' % (exp_number, scan_number, + str(datetime.datetime.now())) + self.ui.statusbar.showMessage(message) + + # update progress bar + self.ui.progressBar_add_ub_peaks.setValue(progress) + + return + + def update_merge_status(self, exp_number, scan_number, sig_value, mode): + """ + update the status of merging/integrating peaks + :param exp_number: + :param scan_number: + :param sig_value: + :param mode: + :return: + """ + if mode == 0: + # start of processing one peak + progress = int(sig_value - 0.5) + if progress == 0: + # run start + self._startMeringScans = time.clock() + self._errorMessageEnsemble = '' + + self.ui.progressBar_mergeScans.setValue(progress) + + elif mode == 1: + # end of processing one peak + intensity = sig_value + + # check intensity value + is_error = False + if intensity < 0: + # set to status + error_msg = 'Negative intensity: %.3f' % intensity + self.ui.tableWidget_mergeScans.set_status(scan_no=scan_number, status=error_msg) + # reset intensity to 0. + intensity = 0. + is_error = True + + # set the calculated peak intensity to _peakInfoDict + status, error_msg = self._myControl.set_peak_intensity(exp_number, scan_number, intensity) + if status: + # set the value to table + self.ui.tableWidget_mergeScans.set_peak_intensity(None, scan_number, intensity) + if not is_error: + self.ui.tableWidget_mergeScans.set_status(scan_number, 'Done') + else: + self._errorMessageEnsemble += error_msg + '\n' + self.ui.tableWidget_mergeScans.set_status(scan_number, error_msg) + + elif mode == 2: + # end of the whole run + progress = int(sig_value+0.5) + self.ui.progressBar_mergeScans.setValue(progress) + + merge_run_end = time.clock() + + elapsed = merge_run_end - self._startMeringScans + message = 'Peak integration is over. Used %.2f seconds' % elapsed + + self.ui.statusbar.showMessage(message) + + # pop error message if there is any + if len(self._errorMessageEnsemble) > 0: + self.pop_one_button_dialog(self._errorMessageEnsemble) + + del self._myIntegratePeaksThread + + return + + def update_merge_error(self, exp_number, scan_number, error_msg): + """ + Update the merge-scan table for error message + :param exp_number: + :param scan_number: + :param error_msg: + :return: + """ + # check + assert isinstance(exp_number, int) + assert isinstance(scan_number, int) + assert isinstance(error_msg, str) + + # set intensity, state to table + self.ui.tableWidget_mergeScans.set_peak_intensity(row_number=None, scan_number=scan_number, + peak_intensity=0., lorentz_corrected=False) + self.ui.tableWidget_mergeScans.set_status(scan_no=scan_number, status=error_msg) + + # set peak value + status, error_msg = self._myControl.set_peak_intensity(exp_number, scan_number, 0.) + if not status: + self.pop_one_button_dialog(error_msg) + + return + + def update_peak_added_info(self, int_msg, int_msg2): + """ + Update the peak-being-added information + :param int_msg: + :param int_msg2: + :return: + """ + # get parameters passed + exp_number = int_msg + scan_number = int_msg2 + + # get PeakInfo + peak_info = self._myControl.get_peak_info(exp_number, scan_number) + assert isinstance(peak_info, r4c.PeakProcessHelper) + + # retrieve and set HKL from spice table + peak_info.retrieve_hkl_from_spice_table() + + # add to table + self.set_ub_peak_table(peak_info) + + return