ParentageRegistry_t.cc
Go to the documentation of this file.
1 #define BOOST_TEST_MODULE (ParentageRegistry_t)
2 #include "boost/test/unit_test.hpp"
3 
8 #include "hep_concurrency/simultaneous_function_spawner.h"
9 
10 #include <string>
11 #include <vector>
12 
13 using namespace art;
14 using namespace std::string_literals;
15 
16 BOOST_AUTO_TEST_SUITE(ParentageTest)
17 
18 BOOST_AUTO_TEST_CASE(concurrent_insertion_reading)
19 {
20  using ParentNames = std::vector<std::string>;
21  using ParentProductIDs = std::vector<ProductID>;
22 
23  std::vector<ParentProductIDs> setsOfParents;
24  {
25  std::vector<ParentNames> setsOfParentNames{
26  {"p1a", "p1b", "p1c"}, {"p2a", "p2b", "p2c", "p2d"}, {"p3a", "p3b"}};
27  cet::transform_all(setsOfParentNames,
28  std::back_inserter(setsOfParents),
29  [](auto const& parentNames) {
30  ParentProductIDs pids;
32  parentNames,
33  std::back_inserter(pids),
34  [](auto const& name) { return ProductID{name}; });
35  return pids;
36  });
37  }
38 
39  // From branch-names to parentages
40  std::vector<Parentage> parentages;
41  cet::transform_all(setsOfParents,
42  std::back_inserter(parentages),
43  [](auto const& parents) { return Parentage{parents}; });
44 
45  // Insert parentages in parallel
46  {
47  std::vector<std::function<void()>> tasks;
49  parentages, std::back_inserter(tasks), [](auto const& p) {
50  return [&p] { ParentageRegistry::emplace(p.id(), p); };
51  });
52  hep::concurrency::simultaneous_function_spawner sfs{tasks};
53  }
54 
55  BOOST_REQUIRE(ParentageRegistry::get().size() == parentages.size());
56 
57  // Retrieve histories in parallel
58  {
59  std::vector<Parentage> retrievedParentages(parentages.size());
60  std::vector<std::function<void()>> tasks;
62  parentages,
63  [&retrievedParentages, &tasks](std::size_t const i, auto const& h) {
64  auto& entry = retrievedParentages[i];
65  tasks.push_back([&h, &entry] {
66  Parentage retrievedParentage;
67  ParentageRegistry::get(h.id(), retrievedParentage);
68  entry = std::move(retrievedParentage);
69  });
70  });
71  hep::concurrency::simultaneous_function_spawner sfs{tasks};
72  BOOST_TEST(parentages == retrievedParentages);
73  }
74 }
75 
76 BOOST_AUTO_TEST_SUITE_END()
static QCString name
Definition: declinfo.cpp:673
QList< Entry > entry
void for_all_with_index(FwdCont &, Func)
BOOST_AUTO_TEST_CASE(concurrent_insertion_reading)
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
static collection_type const & get()
def move(depos, offset)
Definition: depos.py:107
p
Definition: test.py:223
auto transform_all(Container &, OutputIt, UnaryOp)
static auto emplace(value_type const &value)