TestResultAnalyzer_module.cc
Go to the documentation of this file.
6 #include "cetlib_except/exception.h"
8 
9 #include <algorithm>
10 #include <cassert>
11 #include <iterator>
12 #include <numeric>
13 #include <string>
14 
15 namespace arttest {
16  class TestResultAnalyzer;
17 }
18 
20 public:
21  explicit TestResultAnalyzer(fhicl::ParameterSet const&);
22 
23  void analyze(art::Event const& e) override;
24  void endJob() override;
25 
26 private:
27  int passed_{};
28  int failed_{};
29  bool dump_;
30  int numbits_;
31 };
32 
34  : art::EDAnalyzer{ps}
35  , dump_{ps.get<bool>("dump", false)}
36  , numbits_{ps.get<int>("numbits", -1)}
37 {
38  consumesMany<art::TriggerResults>();
39 }
40 
41 void
43 {
44  typedef std::vector<art::Handle<art::TriggerResults>> Trig;
45  Trig prod;
46  e.getManyByType(prod);
47 
48  if (prod.size() == 0)
49  return;
50  if (prod.size() > 1) {
51  mf::LogWarning("MultipleTriggerResults")
52  << "More than one trigger result in the event, using first one.";
53  }
54 
55  if (prod[0]->accept())
56  ++passed_;
57  else
58  ++failed_;
59 
60  if (numbits_ < 0)
61  return;
62 
63  unsigned int numbits = numbits_;
64  if (numbits != prod[0]->size()) {
65  throw cet::exception("WrongNumberBits")
66  << "Should have " << numbits << ", got " << prod[0]->size()
67  << " in TriggerResults\n";
68  }
69 }
70 
71 void
73 {
74  mf::LogAbsolute("TestResultAnalyzerReport")
75  << "passed=" << passed_ << " failed=" << failed_ << "\n";
76 }
77 
TestResultAnalyzer(fhicl::ParameterSet const &)
static const double ps
Definition: Units.h:103
void analyze(art::Event const &e) override
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:27
const double e
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:68
void getManyByType(std::vector< Handle< PROD >> &results) const
Definition: DataViewImpl.h:518
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
MaybeLogger_< ELseverityLevel::ELsev_severe, true > LogAbsolute
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33