Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-07-24 04:44:53

0001 #ifndef FWCore_TestProcessor_EventFromSource_h
0002 #define FWCore_TestProcessor_EventFromSource_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     FWCore/TestProcessor
0006 // Class  :     EventFromSource
0007 //
0008 /**\class EventFromSource EventFromSource.h "EventFromSource.h"
0009 
0010  Description: [one line class summary]
0011 
0012  Usage:
0013     <usage>
0014 
0015 */
0016 //
0017 // Original Author:  Chris Jones
0018 //         Created:  Mon, 30 Apr 2018 18:51:27 GMT
0019 //
0020 
0021 // system include files
0022 #include <string>
0023 
0024 // user include files
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 // forward declarations
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       // ---------- const member functions ---------------------
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       // ---------- member data --------------------------------
0068       EventPrincipal const* principal_;
0069       edm::ServiceToken token_;
0070     };
0071   }  // namespace test
0072 }  // namespace edm
0073 
0074 #endif