CMS 3D CMS Logo

TestAlpakaObjectAnalyzer.cc
Go to the documentation of this file.
1 #include <cassert>
2 
14 
16 public:
18  : source_{config.getParameter<edm::InputTag>("source")}, token_{consumes(source_)} {
19  if (std::string const& eb = config.getParameter<std::string>("expectBackend"); not eb.empty()) {
22  }
23  }
24 
25  void analyze(edm::StreamID sid, edm::Event const& event, edm::EventSetup const&) const override {
26  portabletest::TestHostObject const& product = event.get(token_);
27 
28  auto const& value = product.value();
29  {
30  edm::LogInfo msg("TestAlpakaObjectAnalyzer");
31  msg << source_.encode() << ".data() at " << product.data() << '\n';
32  msg << source_.encode() << ".buffer().data() at " << product.buffer().data() << '\n';
33  msg << source_.encode() << ".value() = {\n";
34  msg << " .x: " << value.x << '\n';
35  msg << " .y: " << value.y << '\n';
36  msg << " .z: " << value.z << '\n';
37  msg << " .id: " << value.id << '\n';
38  msg << "}\n";
39  }
40 
41  // check that the product data is held in the product buffer
42  assert(product.buffer().data() == product.data());
43 
44  // check that the product content is as expected
45  assert(value.x == 5.);
46  assert(value.y == 12.);
47  assert(value.z == 13.);
48  assert(value.id == 42);
49 
50  // check that the backend is as expected
51  if (expectBackend_) {
52  auto backend = static_cast<cms::alpakatools::Backend>(event.get(backendToken_));
53  if (expectBackend_ != backend) {
54  throw cms::Exception("Assert") << "Expected input backend " << cms::alpakatools::toString(*expectBackend_)
55  << ", got " << cms::alpakatools::toString(backend);
56  }
57  }
58  }
59 
60  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
62  desc.add<edm::InputTag>("source");
63  desc.add<std::string>("expectBackend", "")
64  ->setComment(
65  "Expected backend of the input collection. Empty value means to not perform the check. Default: empty "
66  "string");
67  descriptions.addWithDefaultLabel(desc);
68  }
69 
70 private:
74  std::optional<cms::alpakatools::Backend> expectBackend_;
75 };
76 
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
std::string encode() const
Definition: InputTag.cc:159
void analyze(edm::StreamID sid, edm::Event const &event, edm::EventSetup const &) const override
const edm::EDGetTokenT< portabletest::TestHostObject > token_
std::optional< cms::alpakatools::Backend > expectBackend_
Definition: config.py:1
std::string const & label() const
Definition: InputTag.h:36
assert(be >=bs)
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
std::string_view toString(Backend backend)
Definition: Backend.cc:24
Backend toBackend(std::string_view name)
Definition: Backend.cc:13
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Definition: value.py:1
tuple msg
Definition: mps_check.py:286
edm::EDGetTokenT< unsigned short > backendToken_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::string const & process() const
Definition: InputTag.h:40
TestAlpakaObjectAnalyzer(edm::ParameterSet const &config)
Definition: event.py:1