File indexing completed on 2024-07-24 04:44:53
0001 #ifndef FWCore_TestProcessor_RunFromSource_h
0002 #define FWCore_TestProcessor_RunFromSource_h
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022 #include <string>
0023
0024
0025 #include "FWCore/TestProcessor/interface/TestHandle.h"
0026 #include "FWCore/Framework/interface/RunPrincipal.h"
0027 #include "FWCore/Utilities/interface/TypeID.h"
0028 #include "FWCore/ServiceRegistry/interface/ServiceToken.h"
0029 #include "FWCore/ServiceRegistry/interface/ServiceRegistry.h"
0030
0031
0032
0033 namespace edm {
0034
0035 namespace test {
0036
0037 class RunFromSource {
0038 public:
0039 RunFromSource(std::shared_ptr<RunPrincipal const> iPrincipal, edm::ServiceToken iToken)
0040 : principal_(iPrincipal), token_(iToken) {}
0041
0042
0043 template <typename T>
0044 TestHandle<T> get(std::string const& iModule,
0045 std::string const& iInstanceLabel,
0046 std::string const& iProcess) const {
0047 ServiceRegistry::Operate operate(token_);
0048
0049 auto h = principal_->getByLabel(
0050 edm::PRODUCT_TYPE, edm::TypeID(typeid(T)), iModule, iInstanceLabel, iProcess, nullptr, nullptr, nullptr);
0051 if (h.failedToGet()) {
0052 return TestHandle<T>(std::move(h.whyFailedFactory()));
0053 }
0054 void const* basicWrapper = h.wrapper();
0055 assert(basicWrapper);
0056 Wrapper<T> const* wrapper = static_cast<Wrapper<T> const*>(basicWrapper);
0057 return TestHandle<T>(wrapper->product());
0058 }
0059
0060 RunNumber_t run() const { return principal_->run(); }
0061 RunAuxiliary const& aux() const { return principal_->aux(); }
0062
0063 private:
0064
0065 std::shared_ptr<RunPrincipal const> principal_;
0066 edm::ServiceToken token_;
0067 };
0068 }
0069 }
0070
0071 #endif