Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef FWCore_TestProcessor_RunFromSource_h
0002 #define FWCore_TestProcessor_RunFromSource_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     FWCore/TestProcessor
0006 // Class  :     RunFromSource
0007 //
0008 /**\class RunFromSource RunFromSource.h "RunFromSource.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/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 // forward declarations
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       // ---------- const member functions ---------------------
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       // ---------- member data --------------------------------
0065       std::shared_ptr<RunPrincipal const> principal_;
0066       edm::ServiceToken token_;
0067     };
0068   }  // namespace test
0069 }  // namespace edm
0070 
0071 #endif