Macros | Functions
ParentageRegistry_t.cc File Reference
#include "boost/test/unit_test.hpp"
#include "canvas/Persistency/Provenance/Parentage.h"
#include "canvas/Persistency/Provenance/ParentageRegistry.h"
#include "canvas/Persistency/Provenance/ProductID.h"
#include "cetlib/container_algorithms.h"
#include "hep_concurrency/simultaneous_function_spawner.h"
#include <string>
#include <vector>

Go to the source code of this file.

Macros

#define BOOST_TEST_MODULE   (ParentageRegistry_t)
 

Functions

 BOOST_AUTO_TEST_CASE (concurrent_insertion_reading)
 

Macro Definition Documentation

#define BOOST_TEST_MODULE   (ParentageRegistry_t)

Definition at line 1 of file ParentageRegistry_t.cc.

Function Documentation

BOOST_AUTO_TEST_CASE ( concurrent_insertion_reading  )

Definition at line 18 of file ParentageRegistry_t.cc.

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 }
static QCString name
Definition: declinfo.cpp:673
QList< Entry > entry
void for_all_with_index(FwdCont &, Func)
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
def move(depos, offset)
Definition: depos.py:107
p
Definition: test.py:223
auto transform_all(Container &, OutputIt, UnaryOp)
auto const & get(AssnsNode< L, R, D > const &r)
Definition: AssnsNode.h:115