otsdaq  v2_05_02_indev
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:
17  // There is no way I can realize that the singletonized class has been deleted!
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, const std::string& supervisorConfigurationPath, const std::string& instanceUID)
31  {
32  if(theInstances_.find(instanceUID) == theInstances_.end())
33  {
34  __COUT__ << "Creating supervisor application UID: " << instanceUID << " POINTER: " << theInstances_[instanceUID] << std::endl;
35  theInstances_[instanceUID] = static_cast<DataManager*>(new C(configurationTree, supervisorConfigurationPath));
36  __COUT__ << "Creating supervisor application UID: " << instanceUID << " POINTER: " << theInstances_[instanceUID] << std::endl;
37  }
38  else
39  __COUT__ << "An instance of application UID " << instanceUID << " already exists so your input parameters are ignored!" << std::endl;
40 
41  return static_cast<C*>(theInstances_[instanceUID]);
42  }
43 
44  static DataManager* getInstance(std::string instanceUID)
45  {
46  if(theInstances_.find(instanceUID) == theInstances_.end())
47  {
48  __COUT__ << "Can't find supervisor application UID " << instanceUID << std::endl;
49 
50  __SS__ << "An instance of the class MUST already exists so I am crashing!" << std::endl;
51  __SS_THROW__;
52  }
53  else
54  __COUT__ << "An instance of application UID " << instanceUID << " already exists so your input parameters are ignored!" << std::endl;
55 
56  return theInstances_[instanceUID];
57  }
58 
59  private:
60  DataManagerSingleton(void) { ; }
61  ~DataManagerSingleton(void) { ; }
62  static std::map<std::string, DataManager*> theInstances_;
63  // static std::string composeUniqueName(std::string supervisorContextUID, std::string
64  // supervisorApplicationUID){return supervisorContextUID+supervisorApplicationUID;}
65 };
66 
67 } // namespace ots
68 #endif