CMS 3D CMS Logo

TestPortableAnalyzer.cc
Go to the documentation of this file.
1 #include <cassert>
2 
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 } // namespace
52 
54 public:
56  : source_{config.getParameter<edm::InputTag>("source")}, token_{consumes(source_)} {}
57 
58  void analyze(edm::Event const& event, edm::EventSetup const&) override {
59  cudatest::TestHostCollection const& product = event.get(token_);
60 
61  auto const& view = product.const_view();
62  for (int32_t i = 0; i < view.metadata().size(); ++i) {
63  assert(view[i].id() == i);
64  }
65 
66  edm::LogInfo msg("TestPortableAnalyzer");
67  msg << source_.encode() << ".size() = " << view.metadata().size() << '\n';
68  msg << " data @ " << product.buffer().get() << ",\n"
69  << " x @ " << view.metadata().addressOf_x() << " = " << Column(view.x(), view.metadata().size()) << ",\n"
70  << " y @ " << view.metadata().addressOf_y() << " = " << Column(view.y(), view.metadata().size()) << ",\n"
71  << " z @ " << view.metadata().addressOf_z() << " = " << Column(view.z(), view.metadata().size()) << ",\n"
72  << " id @ " << view.metadata().addressOf_id() << " = " << Column(view.id(), view.metadata().size()) << ",\n"
73  << " r @ " << view.metadata().addressOf_r() << " = " << view.r() << '\n'
74  << " flags @ " << view.metadata().addressOf_flags() << " = " << Column(view.flags(), view.metadata().size())
75  << ",\n"
76  << " m @ " << view.metadata().addressOf_m() << " = { ... {" << view[1].m()(1, Eigen::indexing::all)
77  << " } ... } \n";
78  msg << std::hex << " [y - x] = 0x"
79  << reinterpret_cast<intptr_t>(view.metadata().addressOf_y()) -
80  reinterpret_cast<intptr_t>(view.metadata().addressOf_x())
81  << " [z - y] = 0x"
82  << reinterpret_cast<intptr_t>(view.metadata().addressOf_z()) -
83  reinterpret_cast<intptr_t>(view.metadata().addressOf_y())
84  << " [id - z] = 0x"
85  << reinterpret_cast<intptr_t>(view.metadata().addressOf_id()) -
86  reinterpret_cast<intptr_t>(view.metadata().addressOf_z())
87  << " [r - id] = 0x"
88  << reinterpret_cast<intptr_t>(view.metadata().addressOf_r()) -
89  reinterpret_cast<intptr_t>(view.metadata().addressOf_id())
90  << " [flags - r] = 0x"
91  << reinterpret_cast<intptr_t>(view.metadata().addressOf_flags()) -
92  reinterpret_cast<intptr_t>(view.metadata().addressOf_r())
93  << " [m - flags] = 0x"
94  << reinterpret_cast<intptr_t>(view.metadata().addressOf_m()) -
95  reinterpret_cast<intptr_t>(view.metadata().addressOf_flags());
96 
97  const portabletest::Matrix matrix{{1, 2, 3, 4, 5, 6}, {2, 4, 6, 8, 10, 12}, {3, 6, 9, 12, 15, 18}};
98  const portabletest::Array flags = {{6, 4, 2, 0}};
99 
100  assert(view.r() == 1.);
101  for (int32_t i = 0; i < view.metadata().size(); ++i) {
102  auto vi = view[i];
103  assert(vi.x() == 0.);
104  assert(vi.y() == 0.);
105  assert(vi.z() == 0.);
106  assert(vi.id() == i);
107  assert(vi.flags() == flags);
108  assert(vi.m() == matrix * i);
109  }
110  }
111 
114  desc.add<edm::InputTag>("source");
115  descriptions.addWithDefaultLabel(desc);
116  }
117 
118 private:
121 };
122 
size
Write out results.
const edm::EDGetTokenT< cudatest::TestHostCollection > token_
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
const edm::InputTag source_
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:19
TestPortableAnalyzer(edm::ParameterSet const &config)
Definition: config.py:1
assert(be >=bs)
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
void analyze(edm::Event const &event, edm::EventSetup const &) override
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
ConstView const & const_view() const
tuple msg
Definition: mps_check.py:286
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
long double T
Definition: event.py:1