Go to the documentation of this file.00001 #ifndef ServiceRegistry_ServicesManager_h
00002 #define ServiceRegistry_ServicesManager_h
00003
00004
00005
00006
00007
00016
00017
00018
00019
00020
00021
00022 #include "FWCore/ServiceRegistry/interface/ActivityRegistry.h"
00023 #include "FWCore/ServiceRegistry/interface/ServiceLegacy.h"
00024 #include "FWCore/ServiceRegistry/interface/ServiceMakerBase.h"
00025 #include "FWCore/ServiceRegistry/interface/ServiceWrapper.h"
00026 #include "FWCore/Utilities/interface/EDMException.h"
00027 #include "FWCore/Utilities/interface/TypeIDBase.h"
00028
00029
00030 #include "boost/shared_ptr.hpp"
00031
00032 #include <cassert>
00033 #include <vector>
00034
00035
00036 namespace edm {
00037 class ParameterSet;
00038 class ServiceToken;
00039
00040 namespace serviceregistry {
00041
00042 class ServicesManager {
00043 public:
00044 struct MakerHolder {
00045 MakerHolder(boost::shared_ptr<ServiceMakerBase> iMaker,
00046 ParameterSet& iPSet,
00047 ActivityRegistry&) ;
00048 bool add(ServicesManager&) const;
00049
00050 boost::shared_ptr<ServiceMakerBase> maker_;
00051 ParameterSet* pset_;
00052 ActivityRegistry* registry_;
00053 mutable bool wasAdded_;
00054 };
00055 typedef std::map<TypeIDBase, boost::shared_ptr<ServiceWrapperBase> > Type2Service;
00056 typedef std::map<TypeIDBase, MakerHolder> Type2Maker;
00057
00058 ServicesManager(std::vector<ParameterSet>& iConfiguration);
00059
00064 ServicesManager(ServiceToken iToken,
00065 ServiceLegacy iLegacy,
00066 std::vector<ParameterSet>& iConfiguration,
00067 bool associate = true);
00068
00069 ~ServicesManager();
00070
00071
00072 template<typename T>
00073 T& get() const {
00074 Type2Service::const_iterator itFound = type2Service_.find(TypeIDBase(typeid(T)));
00075 Type2Maker::const_iterator itFoundMaker ;
00076 if(itFound == type2Service_.end()) {
00077
00078 if(0 == type2Maker_.get() ||
00079 type2Maker_->end() == (itFoundMaker = type2Maker_->find(TypeIDBase(typeid(T))))) {
00080 Exception::throwThis(errors::NotFound,
00081 "Service Request unable to find requested service with compiler type name '",
00082 typeid(T).name(),
00083 "'.\n");
00084 } else {
00085 itFoundMaker->second.add(const_cast<ServicesManager&>(*this));
00086 itFound = type2Service_.find(TypeIDBase(typeid(T)));
00087
00088 assert(itFound != type2Service_.end());
00089 }
00090 }
00091
00092 boost::shared_ptr<ServiceWrapper<T> > ptr(boost::dynamic_pointer_cast<ServiceWrapper<T> >(itFound->second));
00093 assert(0 != ptr.get());
00094 return ptr->get();
00095 }
00096
00098 template<typename T>
00099 bool isAvailable() const {
00100 Type2Service::const_iterator itFound = type2Service_.find(TypeIDBase(typeid(T)));
00101 Type2Maker::const_iterator itFoundMaker ;
00102 if(itFound == type2Service_.end()) {
00103
00104 if(0 == type2Maker_.get() ||
00105 type2Maker_->end() == (itFoundMaker = type2Maker_->find(TypeIDBase(typeid(T))))) {
00106 return false;
00107 } else {
00108
00109
00110 itFoundMaker->second.add(const_cast<ServicesManager&>(*this));
00111 itFound = type2Service_.find(TypeIDBase(typeid(T)));
00112
00113 assert(itFound != type2Service_.end());
00114 }
00115 }
00116 return true;
00117 }
00118
00119
00120
00121
00123 template<typename T>
00124 bool put(boost::shared_ptr<ServiceWrapper<T> > iPtr) {
00125 Type2Service::const_iterator itFound = type2Service_.find(TypeIDBase(typeid(T)));
00126 if(itFound != type2Service_.end()) {
00127 return false;
00128 }
00129 type2Service_[ TypeIDBase(typeid(T)) ] = iPtr;
00130 actualCreationOrder_.push_back(TypeIDBase(typeid(T)));
00131 return true;
00132 }
00133
00135 void connect(ActivityRegistry& iOther);
00136
00138 void connectTo(ActivityRegistry& iOther);
00139
00141 void copySlotsTo(ActivityRegistry&);
00143 void copySlotsFrom(ActivityRegistry&);
00144
00145 private:
00146 ServicesManager(ServicesManager const&);
00147
00148 ServicesManager const& operator=(ServicesManager const&);
00149
00150 void fillListOfMakers(std::vector<ParameterSet>&);
00151 void createServices();
00152
00153
00154
00155
00156
00157
00158 boost::shared_ptr<ServicesManager> associatedManager_;
00159
00160 ActivityRegistry registry_;
00161 Type2Service type2Service_;
00162 std::auto_ptr<Type2Maker> type2Maker_;
00163 std::vector<TypeIDBase> requestedCreationOrder_;
00164 std::vector<TypeIDBase> actualCreationOrder_;
00165 };
00166 }
00167 }
00168
00169 #endif