Busy_module.cc
Go to the documentation of this file.
1 #include "boost/test/unit_test.hpp"
2 
7 #include "fhiclcpp/types/Atom.h"
8 
9 #include <chrono>
10 
11 namespace {
12  using namespace std::chrono;
13  auto now = steady_clock::now;
14 
15  class Busy : public art::SharedAnalyzer {
16  public:
17  struct Config {
18  fhicl::Atom<unsigned> numEvents{
19  fhicl::Name{"numEvents"},
20  fhicl::Comment{"Number of events to be processed by module."}};
21  fhicl::Atom<double> waitFor{
22  fhicl::Name{"waitFor"},
23  fhicl::Comment{"Duration (in seconds) for which the analyze function "
24  "should execute."}};
25  };
26  using Parameters = Table<Config>;
27  explicit Busy(Parameters const& p, art::ProcessingFrame const&)
28  : SharedAnalyzer{p}, nEvents_{p().numEvents()}, waitFor_{p().waitFor()}
29  {
30  async<art::InEvent>();
31  }
32 
33  private:
34  void
35  beginJob(art::ProcessingFrame const&) override
36  {
37  begin_ = now();
38  }
39 
40  void
41  analyze(art::Event const&, art::ProcessingFrame const&) override
42  {
43  auto const begin = now();
44  while (duration_cast<seconds>(now() - begin).count() < waitFor_) {
45  }
46  }
47 
48  void
49  endJob(art::ProcessingFrame const&) override
50  {
51  auto const time_taken = duration_cast<seconds>(now() - begin_).count();
52  auto const n_schedules = art::Globals::instance()->nschedules();
53  auto const expected_lower_limit = (waitFor_ * nEvents_) / n_schedules;
54  BOOST_TEST(time_taken >= expected_lower_limit);
55  }
56 
57  unsigned int const nEvents_;
58  double const waitFor_;
59  using time_point_t = std::chrono::steady_clock::time_point;
60  time_point_t begin_;
61  };
62 }
63 
def analyze(root, level, gtrees, gbranches, doprint)
Definition: rootstat.py:69
typename config_impl< T >::type Config
Definition: ModuleMacros.h:52
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
void beginJob()
Definition: Breakpoints.cc:14
ScheduleID::size_type nschedules() const
Definition: Globals.cc:24
second seconds
Alias for common language habits.
Definition: spacetime.h:88
p
Definition: test.py:223
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:72
static Globals * instance()
Definition: Globals.cc:17