tdaq-develop-2025-02-12
DataManagerSingleton.h
1 #ifndef _ots_DataManagerSingleton_h_
2 #define _ots_DataManagerSingleton_h_
3 
4 #include <cassert>
5 #include <map>
6 #include <string>
7 #include "otsdaq/DataManager/DataManager.h"
8 
9 namespace ots
10 {
11 class ConfigurationTree;
12 
13 //====================================================================================
15 {
16  public:
18  static void deleteInstance(std::string instanceUID)
19  {
20  // std::string instanceUID = composeUniqueName(supervisorContextUID,
21  // supervisorApplicationUID);
22  if(theInstances_.find(instanceUID) != theInstances_.end())
23  {
24  delete theInstances_[instanceUID];
25  theInstances_.erase(theInstances_.find(instanceUID));
26  }
27  }
28 
29  template<class C>
30  static C* getInstance(const ConfigurationTree& configurationTree,
31  const std::string& supervisorConfigurationPath,
32  const std::string& instanceUID)
33  {
34  if(theInstances_.find(instanceUID) == theInstances_.end())
35  {
36  __COUT__ << "Creating supervisor application UID: " << instanceUID
37  << " POINTER: " << theInstances_[instanceUID] << std::endl;
38  theInstances_[instanceUID] = static_cast<DataManager*>(
39  new C(configurationTree, supervisorConfigurationPath));
40  __COUT__ << "Creating supervisor application UID: " << instanceUID
41  << " POINTER: " << theInstances_[instanceUID] << std::endl;
42  }
43  else
44  __COUT__ << "An instance of application UID " << instanceUID
45  << " already exists so your input parameters are ignored!"
46  << std::endl;
47 
48  return static_cast<C*>(theInstances_[instanceUID]);
49  }
50 
51  static DataManager* getInstance(std::string instanceUID)
52  {
53  if(theInstances_.find(instanceUID) == theInstances_.end())
54  {
55  __COUT__ << "Can't find supervisor application UID " << instanceUID
56  << std::endl;
57 
58  __SS__ << "An instance of the class MUST already exists so I am crashing!"
59  << std::endl;
60  __SS_THROW__;
61  }
62  else
63  __COUT__ << "An instance of application UID " << instanceUID
64  << " already exists so your input parameters are ignored!"
65  << std::endl;
66 
67  return theInstances_[instanceUID];
68  }
69 
70  private:
71  DataManagerSingleton(void) { ; }
72  ~DataManagerSingleton(void) { ; }
73  static std::map<std::string, DataManager*> theInstances_;
74  // static std::string composeUniqueName(std::string supervisorContextUID, std::string
76 };
77 
78 } // namespace ots
79 #endif
static void deleteInstance(std::string instanceUID)
There is no way I can realize that the singletonized class has been deleted!