CMS 3D CMS Logo

TableTestModules.cc
Go to the documentation of this file.
4 #include "DataFormats/TestObjects/interface/TableTest.h"
10 
11 #include <cstring>
12 
13 namespace {
14  std::vector<float> doublesToFloats(std::vector<double> const& iDoubles) {
15  std::vector<float> t;
16  t.reserve(iDoubles.size());
17  for (double d : iDoubles) {
18  t.push_back(static_cast<float>(d));
19  }
20  return t;
21  }
22 } // namespace
23 
24 namespace edmtest {
25 
27  public:
29  : anInts_(iConfig.getParameter<std::vector<int>>("anInts")),
30  aFloats_(doublesToFloats(iConfig.getParameter<std::vector<double>>("aFloats"))),
31  aStrings_(iConfig.getParameter<std::vector<std::string>>("aStrings")) {
32  produces<edmtest::TableTest>();
33  }
34 
35  void produce(edm::StreamID, edm::Event& iEvent, edm::EventSetup const&) const final {
36  iEvent.put(std::make_unique<TableTest>(anInts_, aFloats_, aStrings_));
37  }
38 
39  private:
40  const std::vector<int> anInts_;
41  const std::vector<float> aFloats_;
42  const std::vector<std::string> aStrings_;
43  };
44 
46  public:
48  : anInts_(iConfig.getUntrackedParameter<std::vector<int>>("anInts")),
49  aFloats_(doublesToFloats(iConfig.getUntrackedParameter<std::vector<double>>("aFloats"))),
50  aStrings_(iConfig.getUntrackedParameter<std::vector<std::string>>("aStrings")) {
51  tableToken_ = consumes<edmtest::TableTest>(iConfig.getUntrackedParameter<edm::InputTag>("table"));
52  if (anInts_.size() != aFloats_.size() or anInts_.size() != aStrings_.size()) {
53  throw cms::Exception("Configuration") << "anInts_, aFloats_, and aStrings_ must have the same length";
54  }
55  }
56 
57  void analyze(edm::StreamID, edm::Event const& iEvent, edm::EventSetup const&) const final {
58  auto const& t = iEvent.get(tableToken_);
59 
60  auto size = t.size();
61  if (size != anInts_.size()) {
62  throw cms::Exception("RuntimeError")
63  << "Table size (" << size << ") does not equal expected size (" << anInts_.size() << ")";
64  }
65 
66  unsigned int index = 0;
67  for (auto const& row : t) {
68  if (anInts_[index] != row.get<edmtest::AnInt>()) {
69  throw cms::Exception("RuntimeError")
70  << "index " << index << " anInt =" << row.get<edmtest::AnInt>() << " expected " << anInts_[index];
71  }
72  if (aFloats_[index] != row.get<edmtest::AFloat>()) {
73  throw cms::Exception("RuntimeError")
74  << "index " << index << " aFloat =" << row.get<edmtest::AFloat>() << " expected " << aFloats_[index];
75  }
76  if (aStrings_[index] != row.get<edmtest::AString>()) {
77  throw cms::Exception("RuntimeError")
78  << "index " << index << " aString =" << row.get<edmtest::AString>() << " expected " << aStrings_[index];
79  }
80  ++index;
81  }
82  }
83 
84  private:
85  const std::vector<int> anInts_;
86  const std::vector<float> aFloats_;
87  const std::vector<std::string> aStrings_;
89  };
90 
92  public:
94  : edm::global::OutputModuleBase(pset), edm::global::OutputModule<>(pset) {}
95 
96  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
98  desc.setComment("Tests edm::soa::Table.");
99  OutputModule::fillDescription(desc);
100  descriptions.add("tabletestOutput", desc);
101  }
102 
103  private:
104  void write(edm::EventForOutput const& e) override {
105  using namespace edm;
107  for (auto product : keptProducts()[InEvent]) {
108  BranchDescription const* branchDescription = product.first;
109  TypeID const& tid = branchDescription->unwrappedTypeID();
110  EDGetToken const& token = product.second;
111  BasicHandle bh = e.getByToken(token, tid);
112  assert(bh.isValid());
113  auto examiner = bh.wrapper()->tableExaminer();
114  assert(examiner);
115  if (3 != examiner->columnDescriptions().size()) {
116  throw cms::Exception("RuntimeError")
117  << "wrong number of columns, expected 3 got " << examiner->columnDescriptions().size();
118  }
119  for (auto const& c : examiner->columnDescriptions()) {
120  if (0 == std::strcmp(c.first, edmtest::AnInt::label())) {
121  continue;
122  }
123  if (0 == std::strcmp(c.first, edmtest::AFloat::label())) {
124  continue;
125  }
126  if (0 == std::strcmp(c.first, edmtest::AString::label())) {
127  continue;
128  }
129  throw cms::Exception("RuntimeError") << "unknown column " << c.first;
130  }
131  }
132  }
134  void writeRun(edm::RunForOutput const&) override {}
135  };
136 } // namespace edmtest
const std::vector< float > aFloats_
void writeRun(edm::RunForOutput const &) override
void write(edm::EventForOutput const &e) override
TableTestProducer(edm::ParameterSet const &iConfig)
const std::vector< std::string > aStrings_
edm::EDGetTokenT< edmtest::TableTest > tableToken_
TypeID unwrappedTypeID() const
void writeLuminosityBlock(edm::LuminosityBlockForOutput const &) override
assert(be >=bs)
T getUntrackedParameter(std::string const &, T const &) const
char const * label
int iEvent
Definition: GenABIO.cc:224
const std::vector< float > aFloats_
void analyze(edm::StreamID, edm::Event const &iEvent, edm::EventSetup const &) const final
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
TableTestAnalyzer(edm::ParameterSet const &iConfig)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
bool isValid() const noexcept(true)
Definition: BasicHandle.h:69
d
Definition: ztail.py:151
const std::vector< int > anInts_
const std::vector< std::string > aStrings_
SelectedProductsForBranchType const & keptProducts() const
WrapperBase const * wrapper() const noexcept(true)
Definition: BasicHandle.h:73
void add(std::string const &label, ParameterSetDescription const &psetDescription)
const std::vector< int > anInts_
HLT enums.
void produce(edm::StreamID, edm::Event &iEvent, edm::EventSetup const &) const final
TableTestOutputModule(edm::ParameterSet const &pset)
OutputModule(edm::ParameterSet const &iPSet)
Definition: OutputModule.h:30
std::shared_ptr< soa::TableExaminerBase > tableExaminer() const
Definition: WrapperBase.h:55