Go to the documentation of this file.00001 #ifndef ServiceRegistry_ServiceRegistry_h
00002 #define ServiceRegistry_ServiceRegistry_h
00003
00004
00005
00006
00007
00016
00017
00018
00019
00020
00021
00022 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00023 #include "FWCore/ServiceRegistry/interface/ServiceLegacy.h"
00024 #include "FWCore/ServiceRegistry/interface/ServiceToken.h"
00025 #include "FWCore/ServiceRegistry/interface/ServicesManager.h"
00026
00027
00028 #include <vector>
00029
00030
00031 namespace edm {
00032 class FwkImpl;
00033 namespace serviceregistry {
00034 template< typename T> class ServiceWrapper;
00035 }
00036
00037 class ServiceRegistry {
00038 public:
00039
00040 class Operate {
00041 public:
00042 Operate(ServiceToken const& iToken) :
00043 oldToken_(ServiceRegistry::instance().setContext(iToken)) {}
00044 ~Operate() {
00045 ServiceRegistry::instance().unsetContext(oldToken_);
00046 }
00047
00048
00049 private:
00050 Operate(Operate const&);
00051 Operate const& operator=(Operate const&);
00052 ServiceToken oldToken_;
00053 };
00054
00055 friend class edm::FwkImpl;
00056 friend int main(int argc, char* argv[]);
00057 friend class Operate;
00058
00059 virtual ~ServiceRegistry();
00060
00061
00062 template<typename T>
00063 T& get() const {
00064 if(0 == manager_.get()) {
00065 Exception::throwThis(errors::NotFound,
00066 "Service"
00067 " no ServiceRegistry has been set for this thread");
00068 }
00069 return manager_-> template get<T>();
00070 }
00071
00072 template<typename T>
00073 bool isAvailable() const {
00074 if(0 == manager_.get()) {
00075 Exception::throwThis(errors::NotFound,
00076 "Service"
00077 " no ServiceRegistry has been set for this thread");
00078 }
00079 return manager_-> template isAvailable<T>();
00080 }
00084 ServiceToken presentToken() const;
00085
00086 static ServiceRegistry& instance();
00087
00088
00089
00090 static ServiceToken createServicesFromConfig(std::string const& config);
00091
00092 public:
00093 static ServiceToken createSet(std::vector<ParameterSet>&);
00094 static ServiceToken createSet(std::vector<ParameterSet>&,
00095 ServiceToken,
00096 serviceregistry::ServiceLegacy,
00097 bool associate = true);
00099 template<typename T>
00100 static ServiceToken createContaining(std::auto_ptr<T> iService){
00101 std::vector<edm::ParameterSet> config;
00102 boost::shared_ptr<serviceregistry::ServicesManager> manager(new serviceregistry::ServicesManager(config));
00103 boost::shared_ptr<serviceregistry::ServiceWrapper<T> >
00104 wrapper(new serviceregistry::ServiceWrapper<T>(iService));
00105 manager->put(wrapper);
00106 return manager;
00107 }
00108 template<typename T>
00109 static ServiceToken createContaining(std::auto_ptr<T> iService,
00110 ServiceToken iToken,
00111 serviceregistry::ServiceLegacy iLegacy){
00112 std::vector<edm::ParameterSet> config;
00113 boost::shared_ptr<serviceregistry::ServicesManager> manager(new serviceregistry::ServicesManager(iToken,
00114 iLegacy,
00115 config));
00116 boost::shared_ptr<serviceregistry::ServiceWrapper<T> >
00117 wrapper(new serviceregistry::ServiceWrapper<T>(iService));
00118 manager->put(wrapper);
00119 return manager;
00120 }
00122 template<typename T>
00123 static ServiceToken createContaining(boost::shared_ptr<serviceregistry::ServiceWrapper<T> > iWrapper) {
00124 std::vector<edm::ParameterSet> config;
00125 boost::shared_ptr<serviceregistry::ServicesManager> manager(new serviceregistry::ServicesManager(config));
00126 manager->put(iWrapper);
00127 return manager;
00128 }
00129 template<typename T>
00130 static ServiceToken createContaining(boost::shared_ptr<serviceregistry::ServiceWrapper<T> > iWrapper,
00131 ServiceToken iToken,
00132 serviceregistry::ServiceLegacy iLegacy){
00133 std::vector<edm::ParameterSet> config;
00134 boost::shared_ptr<serviceregistry::ServicesManager> manager(new serviceregistry::ServicesManager(iToken,
00135 iLegacy,
00136 config));
00137 manager->put(iWrapper);
00138 return manager;
00139 }
00140
00141 private:
00142
00143 ServiceToken setContext(ServiceToken const& iNewToken);
00144 void unsetContext(ServiceToken const& iOldToken);
00145
00146 ServiceRegistry();
00147 ServiceRegistry(ServiceRegistry const&);
00148
00149 ServiceRegistry const& operator=(ServiceRegistry const&);
00150
00151
00152 boost::shared_ptr<serviceregistry::ServicesManager> manager_;
00153 };
00154 }
00155
00156 #endif