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