1 #ifndef art_Framework_Services_Registry_detail_ServiceWrapper_h 2 #define art_Framework_Services_Registry_detail_ServiceWrapper_h 15 #include "cetlib/container_algorithms.h" 16 #include "cetlib/metaprogramming.h" 18 #include <type_traits> 22 class ActivityRegistry;
23 class ModuleDescription;
24 class ProducingService;
28 using cet::enable_if_function_exists_t;
31 template <
typename T, ServiceScope SCOPE>
42 std::enable_if_t<std::is_constructible<T,
43 fhicl::ParameterSet const&,
44 ActivityRegistry&>::value,
50 "\n\nart-error: A service that inherits from art::ProducingService\n" 51 " cannot have a constructor that takes an ActivityRegistry&\n" 52 " argument. Contact artists@fnal.gov for guidance.\n");
53 return std::make_shared<T>(ps, areg);
57 std::enable_if_t<!std::is_constructible<T,
63 return std::make_shared<T>(ps);
72 template <
typename T, art::ServiceScope SCOPE>
104 template <
typename U = T>
113 service_ptr_->registerProducts(mpr, productsToProduce, md);
116 template <
typename U = T>
138 template <
typename T>
148 : service_ptrs_{std::move(service_ptrs)}
155 service_ptrs_.reserve(service_ptrs.size());
156 for (
auto&& up : service_ptrs) {
157 service_ptrs_.emplace_back(std::move(up));
164 size_t const nSchedules)
166 service_ptrs_.reserve(nSchedules);
168 for (
size_t iSched{}; iSched < nSchedules; ++iSched,
id =
id.next()) {
169 service_ptrs_.emplace_back(
new T{ps, areg,
id});
176 return *service_ptrs_.at(sID.id());
179 template <
typename U,
184 std::vector<std::shared_ptr<U>> converted_ptrs(service_ptrs_.size());
185 cet::transform_all(service_ptrs_,
186 converted_ptrs.begin(),
187 [](std::shared_ptr<T>
const& ptr_in) {
188 return std::static_pointer_cast<U>(ptr_in);
191 std::move(converted_ptrs));
203 std::vector<std::shared_ptr<T>> service_ptrs_{};
ServiceWrapper(fhicl::ParameterSet const &ps, ActivityRegistry &areg, size_t const nSchedules)
static ScheduleID first()
std::enable_if_t< std::is_base_of< ProducingService, U >::value > doRegisterProducts(MasterProductRegistry &mpr, ProductDescriptions &productsToProduce, ProducingServiceSignals &signals, ModuleDescription const &md)
std::vector< BranchDescription > ProductDescriptions
ServiceWrapper(std::vector< SP > &&service_ptrs)
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
ServiceWrapper & operator=(ServiceWrapper const &)=delete
std::enable_if_t< std::is_constructible< T, fhicl::ParameterSet const &, ActivityRegistry & >::value, std::shared_ptr< T > > makeServiceFrom(fhicl::ParameterSet const &ps, ActivityRegistry &areg)
void registerProducts(MasterProductRegistry &, ProductDescriptions &, ProducingServiceSignals &, ModuleDescription const &) override
ServiceWrapper(fhicl::ParameterSet const &ps, ActivityRegistry &areg)
std::string value(boost::any const &)
std::enable_if_t<!std::is_base_of< ProducingService, U >::value > doRegisterProducts(MasterProductRegistry &, ProductDescriptions &, ProducingServiceSignals &, ModuleDescription const &)
ServiceWrapper< U, SCOPE > * getAs() const
ServiceWrapper(std::shared_ptr< T > &&p)
ServiceWrapper< U, art::ServiceScope::PER_SCHEDULE > * getAs() const
ServiceWrapper(ServiceWrapper const &)=delete
void registerProducts(MasterProductRegistry &mpr, ProductDescriptions &productsToProduce, ProducingServiceSignals &signals, ModuleDescription const &md) override
ServiceWrapper(std::vector< std::shared_ptr< T >> &&service_ptrs)
std::shared_ptr< T > service_ptr_