AlgorithmManager.h 3.39 KB
Newer Older
1
2
3
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2007 ISIS Rutherford Appleton Laboratory UKRI,
4
5
//   NScD Oak Ridge National Laboratory, European Spallation Source,
//   Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6
// SPDX - License - Identifier: GPL - 3.0 +
7
#pragma once
8
9
10
11

//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
LamarMoore's avatar
LamarMoore committed
12
#include "MantidAPI/Algorithm.h"
13
#include "MantidAPI/DllConfig.h"
14
#include "MantidKernel/SingletonHolder.h"
LamarMoore's avatar
LamarMoore committed
15
#include <Poco/NotificationCenter.h>
16

17
18
19
20
#include <deque>
#include <mutex>
#include <string>

21
22
namespace Mantid {
namespace API {
23

24
25
26
27
28
29
30
31
//----------------------------------------------------------------------------
/// Class for when an algorithm is starting asynchronously
class AlgorithmStartingNotification : public Poco::Notification {
public:
  AlgorithmStartingNotification(IAlgorithm_sptr alg)
      : Poco::Notification(), m_alg(alg) {}
  /// Returns the algorithm that is starting
  IAlgorithm_sptr getAlgorithm() const { return m_alg; }
32

33
34
35
private:
  IAlgorithm_sptr m_alg; ///< Algorithm
};
36
37

//----------------------------------------------------------------------------
38
/** The AlgorithmManagerImpl class is responsible for controlling algorithm
39
40
    instances. It incorporates the algorithm factory and initializes algorithms.
 */
41
class MANTID_API_DLL AlgorithmManagerImpl {
42
public:
43
  /// Creates a managed algorithm with the option of choosing a version
44
45
  IAlgorithm_sptr create(const std::string &algName, const int &version = -1,
                         bool makeProxy = true);
46
  /// Creates an unmanaged algorithm with the option of choosing a version
47
48
  boost::shared_ptr<Algorithm> createUnmanaged(const std::string &algName,
                                               const int &version = -1) const;
49

Russell Taylor's avatar
Russell Taylor committed
50
  std::size_t size() const;
51
  void setMaxAlgorithms(int n);
52

53
  IAlgorithm_sptr getAlgorithm(AlgorithmID id) const;
54
  void removeById(AlgorithmID id);
55
56

  std::vector<IAlgorithm_const_sptr> runningInstances() const;
57
58
  std::vector<IAlgorithm_const_sptr>
  runningInstancesOf(const std::string &algorithmName) const;
59

60
61
  /// Sends notifications to observers. Observers can subscribe to
  /// notificationCenter
62
63
64
65
  /// using Poco::NotificationCenter::addObserver(...)
  Poco::NotificationCenter notificationCenter;
  void notifyAlgorithmStarting(AlgorithmID id);

Russell Taylor's avatar
Russell Taylor committed
66
  void clear();
67
  void cancelAll();
Nick Draper's avatar
Nick Draper committed
68
  void shutdown();
69

70
71
72
73
74
75
private:
  friend struct Mantid::Kernel::CreateUsingNew<AlgorithmManagerImpl>;

  AlgorithmManagerImpl();
  ~AlgorithmManagerImpl();

76
  /// Unimplemented copy constructor
77
  AlgorithmManagerImpl(const AlgorithmManagerImpl &);
78
  /// Unimplemented assignment operator
79
  AlgorithmManagerImpl &operator=(const AlgorithmManagerImpl &);
80
81

  /// The maximum size of the algorithm store
82
  int m_max_no_algs;
83
  /// The list of managed algorithms
84
85
  std::deque<IAlgorithm_sptr>
      m_managed_algs; ///<  pointers to managed algorithms [policy???]
86
  /// Mutex for modifying/accessing the m_managed_algs member.
87
  mutable std::mutex m_managedMutex;
88
89
};

90
using AlgorithmManager = Mantid::Kernel::SingletonHolder<AlgorithmManagerImpl>;
91
92

} // namespace API
93
} // Namespace Mantid
94

95
96
97
namespace Mantid {
namespace Kernel {
EXTERN_MANTID_API template class MANTID_API_DLL
Anton Piccardo-Selg's avatar
Anton Piccardo-Selg committed
98
    Mantid::Kernel::SingletonHolder<Mantid::API::AlgorithmManagerImpl>;
99
}
LamarMoore's avatar
LamarMoore committed
100
} // namespace Mantid