Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-06-11 04:37:10

0001 #include "DataFormats/Common/interface/Handle.h"
0002 #include "DataFormats/TestObjects/interface/ToyProducts.h"
0003 #include "FWCore/Concurrency/interface/WaitingTaskWithArenaHolder.h"
0004 #include "FWCore/Framework/interface/Event.h"
0005 #include "FWCore/Framework/interface/stream/EDFilter.h"
0006 #include "FWCore/Framework/interface/MakerMacros.h"
0007 #include "FWCore/Integration/test/WaitingService.h"
0008 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0009 #include "FWCore/ServiceRegistry/interface/Service.h"
0010 #include "FWCore/Utilities/interface/EDGetToken.h"
0011 #include "FWCore/Utilities/interface/InputTag.h"
0012 
0013 #include <memory>
0014 #include <vector>
0015 
0016 namespace edm {
0017   class EventSetup;
0018 }
0019 
0020 namespace edmtest {
0021 
0022   class AcquireIntStreamFilter : public edm::stream::EDFilter<edm::ExternalWork> {
0023   public:
0024     explicit AcquireIntStreamFilter(edm::ParameterSet const& pset);
0025     ~AcquireIntStreamFilter() override;
0026     void acquire(edm::Event const&, edm::EventSetup const&, edm::WaitingTaskWithArenaHolder) override;
0027     bool filter(edm::Event&, edm::EventSetup const&) override;
0028 
0029   private:
0030     std::vector<edm::EDGetTokenT<IntProduct>> m_getTokens;
0031     edm::EDGetTokenT<IntProduct> m_tokenForProduce;
0032     test_acquire::Token m_token;
0033   };
0034 
0035   AcquireIntStreamFilter::AcquireIntStreamFilter(edm::ParameterSet const& pset)
0036       : m_token{edm::Service<test_acquire::WaitingService>()->getToken()} {
0037     for (auto const& tag : pset.getParameter<std::vector<edm::InputTag>>("tags")) {
0038       m_getTokens.emplace_back(consumes<IntProduct>(tag));
0039     }
0040     m_tokenForProduce = consumes<IntProduct>(pset.getParameter<edm::InputTag>("produceTag"));
0041     produces<IntProduct>();
0042   }
0043 
0044   AcquireIntStreamFilter::~AcquireIntStreamFilter() {}
0045 
0046   void AcquireIntStreamFilter::acquire(edm::Event const& event,
0047                                        edm::EventSetup const&,
0048                                        edm::WaitingTaskWithArenaHolder holder) {
0049     test_acquire::Cache* cache = edm::Service<test_acquire::WaitingService>()->getCache(m_token);
0050     cache->retrieved().clear();
0051     cache->processed().clear();
0052 
0053     for (auto const& token : m_getTokens) {
0054       cache->retrieved().push_back(event.get(token).value);
0055     }
0056 
0057     edm::Service<test_acquire::WaitingService>()->requestValuesAsync(
0058         m_token, &cache->retrieved(), &cache->processed(), holder);
0059   }
0060 
0061   bool AcquireIntStreamFilter::filter(edm::Event& event, edm::EventSetup const&) {
0062     int sum = 0;
0063     test_acquire::Cache* cache = edm::Service<test_acquire::WaitingService>()->getCache(m_token);
0064     for (auto v : cache->processed()) {
0065       sum += v;
0066     }
0067     event.put(std::make_unique<IntProduct>(sum));
0068 
0069     // This part is here only for the Parentage test.
0070     (void)event.get(m_tokenForProduce);
0071 
0072     return true;
0073   }
0074 }  // namespace edmtest
0075 using edmtest::AcquireIntStreamFilter;
0076 DEFINE_FWK_MODULE(AcquireIntStreamFilter);