CMS 3D CMS Logo

TransformAsyncIntProducer.cc
Go to the documentation of this file.
4 #include "DataFormats/TestObjects/interface/ToyProducts.h"
6 
7 #include <thread>
8 namespace edmtest {
9  class TransformAsyncIntProducer : public edm::global::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  noPut_(iPSet.getParameter<bool>("noPut")) {
21  putToken_ = produces<IntProduct>();
22  bool check = iPSet.getUntrackedParameter<bool>("checkTransformNotCalled");
23  registerTransformAsync(
24  putToken_,
25  [offset = transformOffset_, check](auto const& iFrom, auto iTask) {
26  if (check) {
27  throw cms::Exception("TransformShouldNotBeCalled");
28  }
29  WorkCache ret;
30  ret.thread_ = std::make_shared<std::thread>([iTask] { usleep(100000); });
31  ret.value_ = IntProduct(iFrom.value + offset);
32  return ret;
33  },
34  [](auto const& iFrom) {
35  iFrom.thread_->join();
36  return iFrom.value_;
37  },
38  "transform");
39  }
40 
41  void produce(edm::StreamID, edm::Event& iEvent, edm::EventSetup const&) const override {
42  if (not noPut_) {
43  iEvent.emplace(putToken_, iEvent.get(getToken_).value + offset_);
44  }
45  }
48  pset.add<edm::InputTag>("get");
49  pset.add<unsigned int>("offset", 0);
50  pset.add<unsigned int>("transformOffset", 1);
51  pset.addUntracked<bool>("checkTransformNotCalled", false);
52  pset.add<bool>("noPut", false);
53 
54  desc.addDefault(pset);
55  }
56 
57  private:
60  const unsigned int offset_;
61  const unsigned int transformOffset_;
62  const bool noPut_;
63  };
64 } // namespace edmtest
65 
void produce(edm::StreamID, edm::Event &iEvent, edm::EventSetup const &) const override
ret
prodAgent to be discontinued
const edm::EDGetTokenT< IntProduct > getToken_
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
T getUntrackedParameter(std::string const &, T const &) const
int iEvent
Definition: GenABIO.cc:224
static void fillDescriptions(edm::ConfigurationDescriptions &desc)
edm::EDPutTokenT< IntProduct > putToken_
TransformAsyncIntProducer(edm::ParameterSet const &iPSet)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
HLT enums.