CMS 3D CMS Logo

TestCUDAProducerCPU.cc
Go to the documentation of this file.
7 
8 #include <chrono>
9 #include <random>
10 #include <thread>
11 
13 public:
14  explicit TestCUDAProducerCPU(edm::ParameterSet const& iConfig);
15  ~TestCUDAProducerCPU() override = default;
16 
17  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
18 
19  void produce(edm::StreamID id, edm::Event& iEvent, edm::EventSetup const& iSetup) const override;
20 
21 private:
25 };
26 
28  : label_{iConfig.getParameter<std::string>("@module_label")}, dstToken_{produces<int>()} {
29  auto srcTag = iConfig.getParameter<edm::InputTag>("src");
30  if (!srcTag.label().empty()) {
31  srcToken_ = consumes<int>(srcTag);
32  }
33 }
34 
37  desc.add<edm::InputTag>("src", edm::InputTag())->setComment("Optional source of another TestCUDAProducerCPU.");
38  descriptions.addWithDefaultLabel(desc);
39  descriptions.setComment("This EDProducer is part of the TestCUDAProducer* family. It models a CPU algorithm.");
40 }
41 
43  edm::LogVerbatim("TestCUDAProducerCPU")
44  << label_ << " TestCUDAProducerCPU::produce begin event " << iEvent.id().event() << " stream " << id;
45 
46  int input = 0;
47  if (!srcToken_.isUninitialized()) {
48  input = iEvent.get(srcToken_);
49  }
50 
51  std::random_device r;
52  std::mt19937 gen(r());
53  auto dist = std::uniform_real_distribution<>(0.2, 1.5);
54  auto dur = dist(gen);
55  edm::LogVerbatim("TestCUDAProducerCPU")
56  << " Task (CPU) for event " << iEvent.id().event() << " in stream " << id << " will take " << dur << " seconds";
57  std::this_thread::sleep_for(std::chrono::seconds(1) * dur);
58 
59  unsigned int const output = input + id * 100 + iEvent.id().event();
60 
61  iEvent.emplace(dstToken_, output);
62 
63  edm::LogVerbatim("TestCUDAProducerCPU") << label_ << " TestCUDAProducerCPU::produce end event " << iEvent.id().event()
64  << " stream " << id << " result " << output;
65 }
66 
Log< level::Info, true > LogVerbatim
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
std::string const label_
double seconds()
constexpr bool isUninitialized() const noexcept
Definition: EDGetToken.h:104
static std::string const input
Definition: EdmProvDump.cc:50
edm::EDGetTokenT< int > srcToken_
int iEvent
Definition: GenABIO.cc:224
edm::EDPutTokenT< int > const dstToken_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
def gen(fragment, howMuch)
Production test section ####.
void setComment(std::string const &value)
TestCUDAProducerCPU(edm::ParameterSet const &iConfig)
~TestCUDAProducerCPU() override=default
void produce(edm::StreamID id, edm::Event &iEvent, edm::EventSetup const &iSetup) const override
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: output.py:1