CMS 3D CMS Logo

TestAlpakaAnalyzer.cc
Go to the documentation of this file.
1 #include <cassert>
2 
3 #include "DataFormats/PortableTestObjects/interface/TestHostCollection.h"
14 
15 namespace {
16 
17  template <typename T>
18  class Column {
19  public:
20  Column(T const* data, size_t size) : data_(data), size_(size) {}
21 
22  void print(std::ostream& out) const {
23  std::stringstream buffer;
24  buffer << "{ ";
25  if (size_ > 0) {
26  buffer << data_[0];
27  }
28  if (size_ > 1) {
29  buffer << ", " << data_[1];
30  }
31  if (size_ > 2) {
32  buffer << ", " << data_[2];
33  }
34  if (size_ > 3) {
35  buffer << ", ...";
36  }
37  buffer << '}';
38  out << buffer.str();
39  }
40 
41  private:
42  T const* const data_;
43  size_t const size_;
44  };
45 
46  template <typename T>
47  std::ostream& operator<<(std::ostream& out, Column<T> const& column) {
48  column.print(out);
49  return out;
50  }
51 
52  template <typename T>
53  void checkViewAddresses(T const& view) {
54  assert(view.metadata().addressOf_x() == view.x());
55  assert(view.metadata().addressOf_x() == &view.x(0));
56  assert(view.metadata().addressOf_x() == &view[0].x());
57  assert(view.metadata().addressOf_y() == view.y());
58  assert(view.metadata().addressOf_y() == &view.y(0));
59  assert(view.metadata().addressOf_y() == &view[0].y());
60  assert(view.metadata().addressOf_z() == view.z());
61  assert(view.metadata().addressOf_z() == &view.z(0));
62  assert(view.metadata().addressOf_z() == &view[0].z());
63  assert(view.metadata().addressOf_id() == view.id());
64  assert(view.metadata().addressOf_id() == &view.id(0));
65  assert(view.metadata().addressOf_id() == &view[0].id());
66  assert(view.metadata().addressOf_m() == view.m());
67  assert(view.metadata().addressOf_m() == &view.m(0).coeffRef(0, 0));
68  assert(view.metadata().addressOf_m() == &view[0].m().coeffRef(0, 0));
69  assert(view.metadata().addressOf_r() == &view.r());
70  //assert(view.metadata().addressOf_r() == &view.r(0)); // cannot access a scalar with an index
71  //assert(view.metadata().addressOf_r() == &view[0].r()); // cannot access a scalar via a SoA row-like accessor
72  }
73 
74 } // namespace
75 
77 public:
79  : source_{config.getParameter<edm::InputTag>("source")},
81  expectSize_(config.getParameter<int>("expectSize")) {}
82 
83  void analyze(edm::StreamID sid, edm::Event const& event, edm::EventSetup const&) const override {
84  portabletest::TestHostCollection const& product = event.get(token_);
85  auto const& view = product.const_view();
86  auto& mview = product.view();
87  auto const& cmview = product.view();
88 
89  if (expectSize_ >= 0 and expectSize_ != view.metadata().size()) {
90  throw cms::Exception("Assert") << "Expected input collection size " << expectSize_ << ", got "
91  << view.metadata().size();
92  }
93 
94  {
95  edm::LogInfo msg("TestAlpakaAnalyzer");
96  msg << source_.encode() << ".size() = " << view.metadata().size() << '\n';
97  msg << " data @ " << product.buffer().data() << ",\n"
98  << " x @ " << view.metadata().addressOf_x() << " = " << Column(view.x(), view.metadata().size()) << ",\n"
99  << " y @ " << view.metadata().addressOf_y() << " = " << Column(view.y(), view.metadata().size()) << ",\n"
100  << " z @ " << view.metadata().addressOf_z() << " = " << Column(view.z(), view.metadata().size()) << ",\n"
101  << " id @ " << view.metadata().addressOf_id() << " = " << Column(view.id(), view.metadata().size())
102  << ",\n"
103  << " r @ " << view.metadata().addressOf_r() << " = " << view.r() << '\n'
104  << " m @ " << view.metadata().addressOf_m() << " = { ... {" << view[1].m()(1, Eigen::all)
105  << " } ... } \n";
106  msg << std::hex << " [y - x] = 0x"
107  << reinterpret_cast<intptr_t>(view.metadata().addressOf_y()) -
108  reinterpret_cast<intptr_t>(view.metadata().addressOf_x())
109  << " [z - y] = 0x"
110  << reinterpret_cast<intptr_t>(view.metadata().addressOf_z()) -
111  reinterpret_cast<intptr_t>(view.metadata().addressOf_y())
112  << " [id - z] = 0x"
113  << reinterpret_cast<intptr_t>(view.metadata().addressOf_id()) -
114  reinterpret_cast<intptr_t>(view.metadata().addressOf_z())
115  << " [r - id] = 0x"
116  << reinterpret_cast<intptr_t>(view.metadata().addressOf_r()) -
117  reinterpret_cast<intptr_t>(view.metadata().addressOf_id())
118  << " [m - r] = 0x"
119  << reinterpret_cast<intptr_t>(view.metadata().addressOf_m()) -
120  reinterpret_cast<intptr_t>(view.metadata().addressOf_r());
121  }
122 
123  checkViewAddresses(view);
124  checkViewAddresses(mview);
125  checkViewAddresses(cmview);
126 
127  const portabletest::Matrix matrix{{1, 2, 3, 4, 5, 6}, {2, 4, 6, 8, 10, 12}, {3, 6, 9, 12, 15, 18}};
128  assert(view.r() == 1.);
129  for (int32_t i = 0; i < view.metadata().size(); ++i) {
130  auto vi = view[i];
131  assert(vi.x() == 0.);
132  assert(vi.y() == 0.);
133  assert(vi.z() == 0.);
134  assert(vi.id() == i);
135  assert(vi.m() == matrix * i);
136  }
137  }
138 
141  desc.add<edm::InputTag>("source");
142  desc.add<int>("expectSize", -1)
143  ->setComment("Expected size of the input collection. Values < 0 mean the check is not performed. Default: -1");
144  descriptions.addWithDefaultLabel(desc);
145  }
146 
147 private:
150  const int expectSize_;
151 };
152 
size
Write out results.
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
const edm::EDGetTokenT< portabletest::TestHostCollection > token_
def all(container)
workaround iterator generators for ROOT classes
Definition: cmstools.py:25
std::string encode() const
Definition: InputTag.cc:159
Eigen::Matrix< double, 3, 6 > Matrix
Definition: TestSoA.h:13
void analyze(edm::StreamID sid, edm::Event const &event, edm::EventSetup const &) const override
Definition: config.py:1
assert(be >=bs)
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
ConstView const & const_view() const
const edm::InputTag source_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
tuple msg
Definition: mps_check.py:286
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
TestAlpakaAnalyzer(edm::ParameterSet const &config)
long double T
Definition: event.py:1