00001 #ifndef _ots_DataManagerSingleton_h_
00002 #define _ots_DataManagerSingleton_h_
00003
00004 #include "otsdaq-core/DataManager/DataManager.h"
00005 #include <map>
00006 #include <string>
00007 #include <cassert>
00008
00009 namespace ots
00010 {
00011 class ConfigurationTree;
00012
00013
00014 class DataManagerSingleton
00015 {
00016 public:
00017
00018 static void deleteInstance (std::string instanceUID)
00019 {
00020
00021 if(theInstances_.find(instanceUID) != theInstances_.end())
00022 {
00023 delete theInstances_[instanceUID];
00024 theInstances_.erase(theInstances_.find(instanceUID));
00025 }
00026 }
00027
00028 template <class C>
00029 static C* getInstance (const ConfigurationTree& configurationTree, const std::string& supervisorConfigurationPath, const std::string& instanceUID)
00030 {
00031 if ( theInstances_.find(instanceUID) == theInstances_.end())
00032 {
00033 __MOUT__ << "Creating supervisor application: " << instanceUID << " POINTER: " << theInstances_[instanceUID] << std::endl;
00034 theInstances_[instanceUID] = static_cast<DataManager*>(new C(configurationTree, supervisorConfigurationPath));
00035 std::cout << __COUT_HDR_FL__ << "Creating supervisor application: " << instanceUID << " POINTER: " << theInstances_[instanceUID] << std::endl;
00036 }
00037 else
00038 __MOUT__ << "An instance of " << instanceUID << " already exists so your input parameters are ignored!" << std::endl;
00039
00040 return static_cast<C*>(theInstances_[instanceUID]);
00041 }
00042
00043 static DataManager* getInstance (std::string instanceUID)
00044 {
00045 if ( theInstances_.find(instanceUID) == theInstances_.end())
00046 {
00047 __MOUT__ << "Can't find supervisor application " << instanceUID << std::endl;
00048 __SS__ << "An instance of the class MUST already exists so I am crashing!" << std::endl;
00049 __MOUT__ << "\n" << ss.str();
00050 assert(0);
00051 throw std::runtime_error(ss.str());
00052 }
00053 else
00054 __MOUT__ << "An instance of " << instanceUID << " already exists so your input parameters are ignored!" << std::endl;
00055
00056 return theInstances_[instanceUID];
00057 }
00058 private:
00059 DataManagerSingleton(void){;}
00060 ~DataManagerSingleton(void){;}
00061 static std::map<std::string, DataManager*> theInstances_;
00062
00063
00064 };
00065
00066
00067 }
00068 #endif