SAMMetadataConcurrentTest_module.cc
Go to the documentation of this file.
10 
11 #include <string>
12 #include <vector>
13 
14 using namespace std;
15 using namespace std::string_literals;
16 
17 namespace {
18 
19  auto
20  mockMetadata()
21  {
23  for (unsigned i{}; i != 10; ++i) {
24  auto const str_index = std::to_string(i);
25  result.emplace_back("k" + str_index, "v" + str_index);
26  }
27  return result;
28  }
29 
30  class SAMMetadataConcurrentTest : public art::EDAnalyzer {
31  public:
32  struct Config {
33  };
34  using Parameters = art::EDAnalyzer::Table<Config>;
35  explicit SAMMetadataConcurrentTest(Parameters const& p) : art::EDAnalyzer{p}
36  {}
37 
38  private:
39  void analyze(art::Event const&) override{};
40 
41  void
42  beginJob() override
43  {
44  vector<function<void()>> tasks;
45  auto mockMD = mockMetadata();
46  // Cannot yet create a ServiceHandle on a different thread.
47  // Will create the handle and share it across all threads.
49  cet::transform_all(mockMD, back_inserter(tasks), [&md](auto const& pr) {
50  return [&md, &pr] { md->addMetadataString(pr.first, pr.second); };
51  });
53  }
54 
55  void
56  endJob() override
57  {
60  ->getMetadata(coll);
61  cet::sort_all(coll);
62 
63  // Check that 'file_type' and 'process_name' were automatically
64  // inserted. Then remove so that we can check the pairs that
65  // were inserted by us.
66  using value_type = decltype(coll)::value_type;
67 
68  auto const& process_name =
70  {}
71  ->getProcessName();
72 
73  auto file_type_it = cet::find_in_all(
74  coll, value_type{"file_type", cet::canonical_string("unknown")});
75  BOOST_REQUIRE(file_type_it != coll.cend());
76  coll.erase(file_type_it);
77 
78  auto process_name_it = cet::find_in_all(
79  coll, value_type{"process_name", cet::canonical_string(process_name)});
80  BOOST_REQUIRE(process_name_it != coll.cend());
81  coll.erase(process_name_it);
82 
83  auto const& mockMD = mockMetadata();
84  BOOST_CHECK_EQUAL(coll.size(), mockMD.size());
85  for (auto c = coll.cbegin(), m = mockMD.cbegin(); c != coll.cend();
86  ++c, ++m) {
87  BOOST_CHECK_EQUAL(c->first, m->first);
88  BOOST_CHECK_EQUAL(c->second, cet::canonical_string(m->second));
89  }
90  }
91  };
92 
93 } // namespace
94 
95 DEFINE_ART_MODULE(SAMMetadataConcurrentTest)
def analyze(root, level, gtrees, gbranches, doprint)
Definition: rootstat.py:67
static const double m
Definition: Units.h:79
std::vector< std::pair< std::string, std::string >> collection_type
STL namespace.
void addMetadataString(std::string const &key, std::string const &value)
void sort_all(RandCont &)
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:68
void beginJob()
Definition: Breakpoints.cc:14
auto transform_all(Container &, OutputIt, UnaryOp)
BOOST_REQUIRE(inFile)
p
Definition: test.py:228
bool canonical_string(std::string const &str, std::string &result)
auto find_in_all(FwdCont &, Datum const &)
std::string to_string(ModuleType const mt)
Definition: ModuleType.h:34