$treeview $search $mathjax $extrastylesheet
otsdaq
v2_03_00
$projectbrief
|
$projectbrief
|
$searchbox |
00001 #ifndef _ots_DataManagerSingleton_h_ 00002 #define _ots_DataManagerSingleton_h_ 00003 00004 #include <cassert> 00005 #include <map> 00006 #include <string> 00007 #include "otsdaq-core/DataManager/DataManager.h" 00008 00009 namespace ots 00010 { 00011 class ConfigurationTree; 00012 00013 //==================================================================================== 00014 class DataManagerSingleton 00015 { 00016 public: 00017 // There is no way I can realize that the singletonized class has been deleted! 00018 static void deleteInstance(std::string instanceUID) 00019 { 00020 // std::string instanceUID = composeUniqueName(supervisorContextUID, 00021 // supervisorApplicationUID); 00022 if(theInstances_.find(instanceUID) != theInstances_.end()) 00023 { 00024 delete theInstances_[instanceUID]; 00025 theInstances_.erase(theInstances_.find(instanceUID)); 00026 } 00027 } 00028 00029 template<class C> 00030 static C* getInstance(const ConfigurationTree& configurationTree, 00031 const std::string& supervisorConfigurationPath, 00032 const std::string& instanceUID) 00033 { 00034 if(theInstances_.find(instanceUID) == theInstances_.end()) 00035 { 00036 __COUT__ << "Creating supervisor application UID: " << instanceUID 00037 << " POINTER: " << theInstances_[instanceUID] << std::endl; 00038 theInstances_[instanceUID] = static_cast<DataManager*>( 00039 new C(configurationTree, supervisorConfigurationPath)); 00040 __COUT__ << "Creating supervisor application UID: " << instanceUID 00041 << " POINTER: " << theInstances_[instanceUID] << std::endl; 00042 } 00043 else 00044 __COUT__ << "An instance of application UID " << instanceUID 00045 << " already exists so your input parameters are ignored!" 00046 << std::endl; 00047 00048 return static_cast<C*>(theInstances_[instanceUID]); 00049 } 00050 00051 static DataManager* getInstance(std::string instanceUID) 00052 { 00053 if(theInstances_.find(instanceUID) == theInstances_.end()) 00054 { 00055 __COUT__ << "Can't find supervisor application UID " << instanceUID 00056 << std::endl; 00057 00058 __SS__ << "An instance of the class MUST already exists so I am crashing!" 00059 << std::endl; 00060 __SS_THROW__; 00061 } 00062 else 00063 __COUT__ << "An instance of application UID " << instanceUID 00064 << " already exists so your input parameters are ignored!" 00065 << std::endl; 00066 00067 return theInstances_[instanceUID]; 00068 } 00069 00070 private: 00071 DataManagerSingleton(void) { ; } 00072 ~DataManagerSingleton(void) { ; } 00073 static std::map<std::string, DataManager*> theInstances_; 00074 // static std::string composeUniqueName(std::string supervisorContextUID, std::string 00075 // supervisorApplicationUID){return supervisorContextUID+supervisorApplicationUID;} 00076 }; 00077 00078 } // namespace ots 00079 #endif