20#include <boost/algorithm/string/classification.hpp>
21#include <boost/algorithm/string/split.hpp>
23#include <Poco/ActiveResult.h>
29#include "tbb/global_control.h"
41#include <boost/mpi.hpp>
52tbb::global_control *GLOBAL_TBB_CONTROL =
nullptr;
58using Kernel::LibraryManagerImpl;
63Kernel::Logger
g_log(
"FrameworkManager");
65const char *PLUGINS_DIR_KEY =
"framework.plugins.directory";
67const char *PLUGINS_EXCLUDE_KEY =
"framework.plugins.exclude";
75void backtraceToStream(std::ostream &os) {
76 void *trace_elems[32];
77 int trace_elem_count(backtrace(trace_elems, 32));
78 char **stack_syms(backtrace_symbols(trace_elems, trace_elem_count));
79 for (
int i = 0; i < trace_elem_count; ++i) {
80 os <<
' ' << stack_syms[i] <<
'\n';
90void terminateHandler() {
91 std::cerr <<
"\n********* UNHANDLED EXCEPTION *********\n";
93 std::rethrow_exception(std::current_exception());
94 }
catch (
const std::exception &exc) {
95 std::cerr <<
" type: " <<
typeid(exc).
name() <<
";\n"
96 <<
" what(): " << exc.what() <<
"\n\n";
98 std::cerr <<
" what(): Unknown exception type. No more information "
101 std::cerr <<
"Backtrace:\n";
102 backtraceToStream(std::cerr);
111 std::set_terminate(terminateHandler);
118 WSAStartup(MAKEWORD(2, 2), &wsaData);
121#if defined(_MSC_VER) && _MSC_VER < 1900
125 _set_output_format(_TWO_DIGIT_EXPONENT);
128 ConfigService::Instance();
133 g_log.
debug() <<
"FrameworkManager created.\n";
138 MPI_Initialized(&initialized);
140 m_mpi_environment = std::make_unique<boost::mpi::environment>(argc, argv);
154 auto maxCores = Kernel::ConfigService::Instance().getValue<
int>(
"MultiThreaded.MaxCores");
155 if (maxCores.value_or(0) > 0) {
165 g_log.
debug() <<
"Setting maximum number of threads to " << nthreads <<
"\n";
167 if (GLOBAL_TBB_CONTROL) {
168 delete GLOBAL_TBB_CONTROL;
171 GLOBAL_TBB_CONTROL =
new tbb::global_control(tbb::global_control::max_allowed_parallelism, nthreads);
193 Kernel::UsageService::Instance().shutdown();
195 delete GLOBAL_TBB_CONTROL;
219 PropertyManagerDataService::Instance().clear();
229 if (
count % 2 == 1) {
230 throw std::runtime_error(
"Must have an even number of parameter/value string arguments");
234 auto alg = AlgorithmManager::Instance().createUnmanaged(algorithmName, -1);
236 if (!alg->isInitialized())
237 throw std::runtime_error(algorithmName +
" was not initialized.");
240 va_start(Params,
count);
241 for (
int i = 0; i <
count; i += 2) {
242 std::string paramName = va_arg(Params,
const char *);
243 std::string paramValue = va_arg(Params,
const char *);
244 alg->setPropertyValue(paramName, paramValue);
263 space = AnalysisDataService::Instance().retrieve(wsName).get();
279 std::shared_ptr<Workspace> ws_sptr;
281 ws_sptr = AnalysisDataService::Instance().retrieve(wsName);
287 std::shared_ptr<WorkspaceGroup> ws_grpsptr = std::dynamic_pointer_cast<WorkspaceGroup>(ws_sptr);
290 AnalysisDataService::Instance().deepRemoveGroup(wsName);
297 AnalysisDataService::Instance().remove(wsName);
301 g_log.
error() <<
"Workspace " << wsName <<
" could not be found.\n";
314 const auto &cfgSvc = Kernel::ConfigService::Instance();
315 const auto pluginDir = cfgSvc.getString(locationKey);
316 if (pluginDir.length() > 0) {
317 std::vector<std::string> excludes;
318 const auto excludeStr = cfgSvc.getString(excludeKey);
319 boost::split(excludes, excludeStr, boost::is_any_of(
";"));
320 g_log.
debug(
"Loading libraries from '" + pluginDir +
"', excluding '" + excludeStr +
"'");
323 g_log.
debug(
"No library directory found in key \"" + locationKey +
"\"");
339 setlocale(LC_NUMERIC,
"C");
344 auto instrumentUpdates = Kernel::ConfigService::Instance().getValue<
bool>(
"UpdateInstrumentDefinitions.OnStartup");
346 if (instrumentUpdates.value_or(
false)) {
350 "instrument definitions.\n";
353 auto newVersionCheck = Kernel::ConfigService::Instance().getValue<
bool>(
"CheckMantidVersion.OnStartup");
354 if (newVersionCheck.value_or(
false)) {
364 auto &configSvc = ConfigService::Instance();
365 auto interval = configSvc.getValue<
int>(
"Usage.BufferCheckInterval");
366 auto &usageSvc = UsageService::Instance();
367 if (interval.value_or(0) > 0) {
368 usageSvc.setInterval(interval.value());
370 auto enabled = configSvc.getValue<
bool>(
"usagereports.enabled");
371 usageSvc.setEnabled(enabled.value_or(
false));
372 usageSvc.registerStartup();
378 auto algDownloadInstrument = Mantid::API::AlgorithmManager::Instance().create(
"DownloadInstrument");
379 algDownloadInstrument->setAlgStartupLogging(
false);
380 algDownloadInstrument->executeAsync();
382 g_log.
debug() <<
"DowndloadInstrument algorithm is not available - cannot "
383 "update instrument definitions.\n";
390 auto algCheckVersion = Mantid::API::AlgorithmManager::Instance().create(
"CheckMantidVersion");
391 algCheckVersion->setAlgStartupLogging(
false);
392 algCheckVersion->executeAsync();
394 g_log.
debug() <<
"CheckMantidVersion algorithm is not available - cannot "
395 "check if a newer version is available.\n";
#define PARALLEL_SET_NUM_THREADS(MaxCores)
#define PARALLEL_GET_MAX_THREADS
Workspace * getWorkspace(const std::string &wsName)
Returns a shared pointer to the workspace requested.
std::shared_ptr< IAlgorithm > exec(const std::string &algorithmName, int count,...)
Creates an algorithm and runs it, with variadic arguments.
void updateInstrumentDefinitions()
Update instrument definitions from github.
void clearPropertyManagers()
Clear memory associated with the PropertyManagers.
void loadPlugins()
Load framework plugins.
void setNumOMPThreads(const int nthreads)
Set the number of OpenMP threads to the given value.
void asynchronousStartupTasks()
Starts asynchronous tasks that are done as part of Start-up.
void loadPluginsUsingKey(const std::string &locationKey, const std::string &excludeKey)
Load a set of plugins using a key from the ConfigService.
void clearInstruments()
Clear memory associated with the IDS.
FrameworkManagerImpl()
Private Constructor.
void clearData()
Clear memory associated with the ADS.
void shutdown()
shuts down and performs clean up tasks
void setGlobalNumericLocaleToC()
Set up the global locale.
int getNumOMPThreads() const
Returns the number of OpenMP threads that will be used.
void checkIfNewerVersionIsAvailable()
check if a newer version of Mantid is available
void setNumOMPThreadsToConfigValue()
Set the number of OpenMP threads to use based on the config value.
void clear()
Clears all memory associated with the AlgorithmManager, ADS & IDS.
bool deleteWorkspace(const std::string &wsName)
Deletes a workspace from the framework.
void clearAlgorithms()
Clear memory associated with the AlgorithmManager.
void setupUsageReporting()
Setup Usage Reporting if enabled.
Base Workspace Abstract Class.
Exception for when an item is not found in a collection.
const char * what() const noexcept override
Writes out the range and limits.
void debug(const std::string &msg)
Logs at debug level.
void notice(const std::string &msg)
Logs at notice level.
void error(const std::string &msg)
Logs at error level.
void information(const std::string &msg)
Logs at information level.
std::shared_ptr< IAlgorithm > IAlgorithm_sptr
shared pointer to Mantid::API::IAlgorithm
Kernel::Logger g_log("ExperimentInfo")
static logger object
MANTID_KERNEL_DLL void initAllocatorOptions()
Initialize platform-dependent options for memory management.
Mantid::Kernel::SingletonHolder< ConfigServiceImpl > ConfigService
Mantid::Kernel::SingletonHolder< LibraryManagerImpl > LibraryManager
Mantid::Kernel::SingletonHolder< UsageServiceImpl > UsageService
Mantid::Kernel::SingletonHolder< PropertyManagerDataServiceImpl > PropertyManagerDataService
Helper class which provides the Collimation Length for SANS instruments.
MANTID_KERNEL_DLL std::string welcomeMessage()
Returns the welcome message for Mantid.