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"
48tbb::global_control *GLOBAL_TBB_CONTROL =
nullptr;
54using Kernel::LibraryManagerImpl;
59Kernel::Logger
g_log(
"FrameworkManager");
61const char *PLUGINS_DIR_KEY =
"framework.plugins.directory";
63const char *PLUGINS_EXCLUDE_KEY =
"framework.plugins.exclude";
71void backtraceToStream(std::ostream &os) {
72 void *trace_elems[32];
73 int trace_elem_count(backtrace(trace_elems, 32));
74 char **stack_syms(backtrace_symbols(trace_elems, trace_elem_count));
75 for (
int i = 0; i < trace_elem_count; ++i) {
76 os <<
' ' << stack_syms[i] <<
'\n';
86void terminateHandler() {
87 std::cerr <<
"\n********* UNHANDLED EXCEPTION *********\n";
89 std::rethrow_exception(std::current_exception());
90 }
catch (
const std::exception &exc) {
91 std::cerr <<
" type: " <<
typeid(exc).
name() <<
";\n"
92 <<
" what(): " << exc.what() <<
"\n\n";
94 std::cerr <<
" what(): Unknown exception type. No more information "
97 std::cerr <<
"Backtrace:\n";
98 backtraceToStream(std::cerr);
107 std::set_terminate(terminateHandler);
114 WSAStartup(MAKEWORD(2, 2), &wsaData);
117#if defined(_MSC_VER) && _MSC_VER < 1900
121 _set_output_format(_TWO_DIGIT_EXPONENT);
124 ConfigService::Instance();
129 g_log.
debug() <<
"FrameworkManager created.\n";
144 auto maxCores = Kernel::ConfigService::Instance().getValue<
int>(
"MultiThreaded.MaxCores");
145 if (maxCores.value_or(0) > 0) {
155 g_log.
debug() <<
"Setting maximum number of threads to " << nthreads <<
"\n";
157 if (GLOBAL_TBB_CONTROL) {
158 delete GLOBAL_TBB_CONTROL;
161 GLOBAL_TBB_CONTROL =
new tbb::global_control(tbb::global_control::max_allowed_parallelism, nthreads);
183 Kernel::UsageService::Instance().shutdown();
185 delete GLOBAL_TBB_CONTROL;
209 PropertyManagerDataService::Instance().clear();
219 if (
count % 2 == 1) {
220 throw std::runtime_error(
"Must have an even number of parameter/value string arguments");
224 auto alg = AlgorithmManager::Instance().createUnmanaged(algorithmName, -1);
226 if (!alg->isInitialized())
227 throw std::runtime_error(algorithmName +
" was not initialized.");
230 va_start(Params,
count);
231 for (
int i = 0; i <
count; i += 2) {
232 std::string paramName = va_arg(Params,
const char *);
233 std::string paramValue = va_arg(Params,
const char *);
234 alg->setPropertyValue(paramName, paramValue);
253 space = AnalysisDataService::Instance().retrieve(wsName).get();
269 std::shared_ptr<Workspace> ws_sptr;
271 ws_sptr = AnalysisDataService::Instance().retrieve(wsName);
277 std::shared_ptr<WorkspaceGroup> ws_grpsptr = std::dynamic_pointer_cast<WorkspaceGroup>(ws_sptr);
280 AnalysisDataService::Instance().deepRemoveGroup(wsName);
287 AnalysisDataService::Instance().remove(wsName);
291 g_log.
error() <<
"Workspace " << wsName <<
" could not be found.\n";
304 const auto &cfgSvc = Kernel::ConfigService::Instance();
305 const auto pluginDir = cfgSvc.getString(locationKey);
306 if (pluginDir.length() > 0) {
307 std::vector<std::string> excludes;
308 const auto excludeStr = cfgSvc.getString(excludeKey);
309 boost::split(excludes, excludeStr, boost::is_any_of(
";"));
310 g_log.
debug(
"Loading libraries from '" + pluginDir +
"', excluding '" + excludeStr +
"'");
313 g_log.
debug(
"No library directory found in key \"" + locationKey +
"\"");
329 setlocale(LC_NUMERIC,
"C");
334 auto instrumentUpdates = Kernel::ConfigService::Instance().getValue<
bool>(
"UpdateInstrumentDefinitions.OnStartup");
336 if (instrumentUpdates.value_or(
false)) {
340 "instrument definitions.\n";
343 auto newVersionCheck = Kernel::ConfigService::Instance().getValue<
bool>(
"CheckMantidVersion.OnStartup");
344 if (newVersionCheck.value_or(
false)) {
354 auto &configSvc = ConfigService::Instance();
355 auto interval = configSvc.getValue<
int>(
"Usage.BufferCheckInterval");
356 auto &usageSvc = UsageService::Instance();
357 if (interval.value_or(0) > 0) {
358 usageSvc.setInterval(interval.value());
360 auto enabled = configSvc.getValue<
bool>(
"usagereports.enabled");
361 usageSvc.setEnabled(enabled.value_or(
false));
362 usageSvc.registerStartup();
368 auto algDownloadInstrument = Mantid::API::AlgorithmManager::Instance().create(
"DownloadInstrument");
369 algDownloadInstrument->setAlgStartupLogging(
false);
370 algDownloadInstrument->executeAsync();
372 g_log.
debug() <<
"DowndloadInstrument algorithm is not available - cannot "
373 "update instrument definitions.\n";
380 auto algCheckVersion = Mantid::API::AlgorithmManager::Instance().create(
"CheckMantidVersion");
381 algCheckVersion->setAlgStartupLogging(
false);
382 algCheckVersion->executeAsync();
384 g_log.
debug() <<
"CheckMantidVersion algorithm is not available - cannot "
385 "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.