CMS 3D CMS Logo

TransformAsyncIntStreamProducer.cc
Go to the documentation of this file.
4 #include "DataFormats/TestObjects/interface/ToyProducts.h"
6 
7 #include <thread>
8 namespace edmtest {
9  class TransformAsyncIntStreamProducer : public edm::stream::EDProducer<edm::Transformer> {
10  public:
11  struct WorkCache {
12  std::shared_ptr<std::thread> thread_;
13  IntProduct value_;
14  };
15 
17  : getToken_(consumes(iPSet.getParameter<edm::InputTag>("get"))),
18  offset_(iPSet.getParameter<unsigned int>("offset")),
19  transformOffset_(iPSet.getParameter<unsigned int>("transformOffset")) {
20  putToken_ = produces<IntProduct>();
21  bool check = iPSet.getUntrackedParameter<bool>("checkTransformNotCalled");
22  registerTransformAsync(
23  putToken_,
24  [offset = transformOffset_, check](auto const& iFrom, auto iTask) {
25  if (check) {
26  throw cms::Exception("TransformShouldNotBeCalled");
27  }
28  WorkCache ret;
29  ret.thread_ = std::make_shared<std::thread>([iTask] { usleep(100000); });
30  ret.value_ = IntProduct(iFrom.value + offset);
31  return ret;
32  },
33  [](auto const& iFrom) {
34  iFrom.thread_->join();
35  return iFrom.value_;
36  },
37  "transform");
38  }
39 
40  void produce(edm::Event& iEvent, edm::EventSetup const&) override {
41  iEvent.emplace(putToken_, iEvent.get(getToken_).value + offset_);
42  }
45  pset.add<edm::InputTag>("get");
46  pset.add<unsigned int>("offset", 0);
47  pset.add<unsigned int>("transformOffset", 1);
48  pset.addUntracked<bool>("checkTransformNotCalled", false);
49 
50  desc.addDefault(pset);
51  }
52 
53  private:
56  const unsigned int offset_;
57  const unsigned int transformOffset_;
58  };
59 } // namespace edmtest
60 
TransformAsyncIntStreamProducer(edm::ParameterSet const &iPSet)
ret
prodAgent to be discontinued
static void fillDescriptions(edm::ConfigurationDescriptions &desc)
T getUntrackedParameter(std::string const &, T const &) const
int iEvent
Definition: GenABIO.cc:224
void produce(edm::Event &iEvent, edm::EventSetup const &) override
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
HLT enums.