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  << " m @ " << view.metadata().addressOf_m() << " = { ... {" << view[1].m()(1, Eigen::all) << " } ... } \n";
75  msg << std::hex << " [y - x] = 0x"
76  << reinterpret_cast<intptr_t>(view.metadata().addressOf_y()) -
77  reinterpret_cast<intptr_t>(view.metadata().addressOf_x())
78  << " [z - y] = 0x"
79  << reinterpret_cast<intptr_t>(view.metadata().addressOf_z()) -
80  reinterpret_cast<intptr_t>(view.metadata().addressOf_y())
81  << " [id - z] = 0x"
82  << reinterpret_cast<intptr_t>(view.metadata().addressOf_id()) -
83  reinterpret_cast<intptr_t>(view.metadata().addressOf_z())
84  << " [r - id] = 0x"
85  << reinterpret_cast<intptr_t>(view.metadata().addressOf_r()) -
86  reinterpret_cast<intptr_t>(view.metadata().addressOf_id())
87  << " [m - r] = 0x"
88  << reinterpret_cast<intptr_t>(view.metadata().addressOf_m()) -
89  reinterpret_cast<intptr_t>(view.metadata().addressOf_r());
90 
91  const portabletest::Matrix matrix{{1, 2, 3, 4, 5, 6}, {2, 4, 6, 8, 10, 12}, {3, 6, 9, 12, 15, 18}};
92  assert(view.r() == 1.);
93  for (int32_t i = 0; i < view.metadata().size(); ++i) {
94  auto vi = view[i];
95  assert(vi.x() == 0.);
96  assert(vi.y() == 0.);
97  assert(vi.z() == 0.);
98  assert(vi.id() == i);
99  //assert(vi.m() == matrix * i);
100  }
101  }
102 
105  desc.add<edm::InputTag>("source");
106  descriptions.addWithDefaultLabel(desc);
107  }
108 
109 private:
112 };
113 
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:13
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:79
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
long double T
Definition: event.py:1