Macros | Functions
ProcessHistoryRegistry_t.cc File Reference
#include "boost/test/unit_test.hpp"
#include "art/Persistency/Provenance/ProcessHistoryRegistry.h"
#include "art/Version/GetReleaseVersion.h"
#include "canvas/Persistency/Provenance/ProcessHistory.h"
#include "cetlib/container_algorithms.h"
#include "fhiclcpp/ParameterSet.h"
#include "hep_concurrency/simultaneous_function_spawner.h"
#include <string>

Go to the source code of this file.

Macros

#define BOOST_TEST_MODULE   (ProcessHistoryRegistry_t)
 

Functions

 BOOST_AUTO_TEST_CASE (concurrent_insertion_reading)
 

Macro Definition Documentation

#define BOOST_TEST_MODULE   (ProcessHistoryRegistry_t)

Definition at line 1 of file ProcessHistoryRegistry_t.cc.

Function Documentation

BOOST_AUTO_TEST_CASE ( concurrent_insertion_reading  )

Definition at line 37 of file ProcessHistoryRegistry_t.cc.

38 {
39  std::vector<ProcessConfiguration> pcs;
40  pcs.push_back(makeProcessConfiguration("p1", "m1"));
41  pcs.push_back(makeProcessConfiguration("p2", "m2"));
42  pcs.push_back(makeProcessConfiguration("pA", "mA"));
43  pcs.push_back(makeProcessConfiguration("pB", "mB"));
44 
45  auto makeProcessHistory = [&pcs](std::size_t const first,
46  std::size_t const last) {
47  ProcessHistory ph;
48  ph.push_back(pcs.at(first));
49  ph.push_back(pcs.at(last));
50  return ph;
51  };
52 
53  std::vector<ProcessHistory> histories;
54  histories.push_back(makeProcessHistory(0, 1));
55  histories.push_back(makeProcessHistory(0, 3));
56  histories.push_back(makeProcessHistory(2, 1));
57  histories.push_back(makeProcessHistory(2, 3));
58 
59  // Insert histories in parallel
60  {
61  std::vector<std::function<void()>> tasks;
62  cet::transform_all(histories, std::back_inserter(tasks), [](auto const& h) {
63  return [&h] { ProcessHistoryRegistry::emplace(h.id(), h); };
64  });
65  hep::concurrency::simultaneous_function_spawner sfs{tasks};
66  }
67 
68  BOOST_TEST_REQUIRE(ProcessHistoryRegistry::get().size() == histories.size());
69 
70  // Retrieve histories in parallel
71  {
72  std::vector<ProcessHistory> retrievedHistories(histories.size());
73  std::vector<std::function<void()>> tasks;
75  histories,
76  [&retrievedHistories, &tasks](std::size_t const i, auto const& h) {
77  auto& entry = retrievedHistories[i];
78  tasks.push_back([&h, &entry] {
79  ProcessHistory retrievedHistory;
80  ProcessHistoryRegistry::get(h.id(), retrievedHistory);
81  entry = std::move(retrievedHistory);
82  });
83  });
84  hep::concurrency::simultaneous_function_spawner sfs{tasks};
85  BOOST_TEST(histories == retrievedHistories);
86  }
87 }
QList< Entry > entry
void for_all_with_index(FwdCont &, Func)
BOOST_TEST_REQUIRE(static_cast< bool >(inFile))
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
def move(depos, offset)
Definition: depos.py:107
auto transform_all(Container &, OutputIt, UnaryOp)
auto const & get(AssnsNode< L, R, D > const &r)
Definition: AssnsNode.h:115
void push_back(const_reference t)