File indexing completed on 2024-07-24 04:44:53
0001 #ifndef FWCore_TestProcessor_EventFromSource_h
0002 #define FWCore_TestProcessor_EventFromSource_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/EventPrincipal.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 class EventFromSourcePrincipal;
0035
0036 namespace test {
0037
0038 class EventFromSource {
0039 public:
0040 EventFromSource(EventPrincipal const& iPrincipal, edm::ServiceToken iToken)
0041 : principal_(&iPrincipal), token_(iToken) {}
0042
0043
0044 template <typename T>
0045 TestHandle<T> get(std::string const& iModule,
0046 std::string const& iInstanceLabel,
0047 std::string const& iProcess) const {
0048 ServiceRegistry::Operate operate(token_);
0049
0050 auto h = principal_->getByLabel(
0051 edm::PRODUCT_TYPE, edm::TypeID(typeid(T)), iModule, iInstanceLabel, iProcess, nullptr, nullptr, nullptr);
0052 if (h.failedToGet()) {
0053 return TestHandle<T>(std::move(h.whyFailedFactory()));
0054 }
0055 void const* basicWrapper = h.wrapper();
0056 assert(basicWrapper);
0057 Wrapper<T> const* wrapper = static_cast<Wrapper<T> const*>(basicWrapper);
0058 return TestHandle<T>(wrapper->product());
0059 }
0060
0061 RunNumber_t run() const { return principal_->run(); }
0062 LuminosityBlockNumber_t luminosityBlock() const { return principal_->luminosityBlock(); }
0063 EventNumber_t event() const { return principal_->aux().event(); }
0064 EventAuxiliary const& aux() const { return principal_->aux(); }
0065
0066 private:
0067
0068 EventPrincipal const* principal_;
0069 edm::ServiceToken token_;
0070 };
0071 }
0072 }
0073
0074 #endif