otsdaq  v1_01_04
 All Classes Namespaces Functions
DataManagerSingleton.h
1 #ifndef _ots_DataManagerSingleton_h_
2 #define _ots_DataManagerSingleton_h_
3 
4 #include "otsdaq-core/DataManager/DataManager.h"
5 #include <map>
6 #include <string>
7 #include <cassert>
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, supervisorApplicationUID);
21  if(theInstances_.find(instanceUID) != theInstances_.end())
22  {
23  delete theInstances_[instanceUID];
24  theInstances_.erase(theInstances_.find(instanceUID));
25  }
26  }
27 
28  template <class C>
29  static C* getInstance (const ConfigurationTree& configurationTree, const std::string& supervisorConfigurationPath, const std::string& instanceUID)
30  {
31  if ( theInstances_.find(instanceUID) == theInstances_.end())
32  {
33  __COUT__ << "Creating supervisor application: " << instanceUID << " POINTER: " << theInstances_[instanceUID] << std::endl;
34  theInstances_[instanceUID] = static_cast<DataManager*>(new C(configurationTree, supervisorConfigurationPath));
35  std::cout << __COUT_HDR_FL__ << "Creating supervisor application: " << instanceUID << " POINTER: " << theInstances_[instanceUID] << std::endl;
36  }
37  else
38  __COUT__ << "An instance of " << instanceUID << " already exists so your input parameters are ignored!" << std::endl;
39 
40  return static_cast<C*>(theInstances_[instanceUID]);
41  }
42 
43  static DataManager* getInstance (std::string instanceUID)
44  {
45  if ( theInstances_.find(instanceUID) == theInstances_.end())
46  {
47  __COUT__ << "Can't find supervisor application " << instanceUID << std::endl;
48  __SS__ << "An instance of the class MUST already exists so I am crashing!" << std::endl;
49  __COUT__ << "\n" << ss.str();
50  assert(0);
51  throw std::runtime_error(ss.str());
52  }
53  else
54  __COUT__ << "An instance of " << instanceUID << " already exists so your input parameters are ignored!" << std::endl;
55 
56  return theInstances_[instanceUID];
57  }
58 private:
59  DataManagerSingleton(void){;}
60  ~DataManagerSingleton(void){;}
61  static std::map<std::string, DataManager*> theInstances_;
62  //static std::string composeUniqueName(std::string supervisorContextUID, std::string supervisorApplicationUID){return supervisorContextUID+supervisorApplicationUID;}
63 
64 };
65 
66 //std::map<std::string, DataManager*> DataManagerSingleton::theInstances_;
67 }
68 #endif