HLTGlobalStatus.h
Go to the documentation of this file.
1 #ifndef canvas_Persistency_Common_HLTGlobalStatus_h
2 #define canvas_Persistency_Common_HLTGlobalStatus_h
3 
4 /** \class art::HLTGlobalStatus
5  *
6  * The HLT global status, summarising the status of the individual
7  * HLT triggers, is implemented as a vector of HLTPathStatus objects.
8  *
9  * If the user wants map-like indexing of HLT triggers through their
10  * names as key, s/he must use the TriggerNamesService.
11  *
12  * \author Martin Grunewald
13  */
14 
18 #include <ostream>
19 #include <vector>
20 
21 // ----------------------------------------------------------------------
22 
23 namespace art {
24 
26  // Status of each HLT path
27  std::vector<HLTPathStatus> paths_{};
28 
29  public:
30  // Constructor - for n paths
31  HLTGlobalStatus() = default;
32  explicit HLTGlobalStatus(std::size_t const n) : paths_(n) {}
33 
34  // Get number of paths stored
35  std::size_t
36  size() const
37  {
38  return paths_.size();
39  }
40 
41  // Reset status for all paths
42  void
44  {
45  cet::for_all(paths_, [](auto& path) { path.reset(); });
46  }
47 
48  // global "state" variables calculated on the fly!
49 
50  // Was at least one path run?
51  bool
52  wasrun() const
53  {
54  return state_on_demand(0);
55  }
56  // Has at least one path accepted the event? If no paths were
57  // run, or there are no paths, the answer is, "yes."
58  bool
59  accept() const
60  {
61  return state_on_demand(1);
62  }
63  // Has any path encountered an error (exception)
64  bool
65  error() const
66  {
67  return state_on_demand(2);
68  }
69 
70  // get hold of individual elements, using safe indexing with "at" which
71  // throws!
72  HLTPathStatus const&
73  at(std::size_t const i) const
74  {
75  return paths_.at(i);
76  }
78  at(std::size_t const i)
79  {
80  return paths_.at(i);
81  }
82 
83  HLTPathStatus const& operator[](std::size_t const i) const
84  {
85  return paths_.at(i);
86  }
87  HLTPathStatus& operator[](std::size_t const i) { return paths_.at(i); }
88 
89  // Was ith path run?
90  bool
91  wasrun(std::size_t const i) const
92  {
93  return at(i).wasrun();
94  }
95  // Has ith path accepted the event?
96  bool
97  accept(std::size_t const i) const
98  {
99  return at(i).accept();
100  }
101  // Has ith path encountered an error (exception)?
102  bool
103  error(std::size_t const i) const
104  {
105  return at(i).error();
106  }
107 
108  // Get status of ith path
110  state(std::size_t const i) const
111  {
112  return at(i).state();
113  }
114  // Get index (slot position) of module giving the decision of the ith path
115  std::size_t
116  index(std::size_t const i) const
117  {
118  return at(i).index();
119  }
120  // Reset the ith path
121  void
122  reset(std::size_t const i)
123  {
124  at(i).reset();
125  }
126  // swap function
127  void
129  {
130  paths_.swap(other.paths_);
131  }
132  // copy assignment implemented with swap()
133  // Cannot ref-qualify assignment because of GCC_XML.
136  {
137  HLTGlobalStatus temp(rhs);
138  this->swap(temp);
139  return *this;
140  }
141 
142  private:
143  // Global state variable calculated on the fly
144  bool
145  state_on_demand(std::size_t const icase) const
146  {
147  bool flags[3]{false, false, false};
148  for (std::size_t i{}, n{size()}; i != n; ++i) {
149  auto const s = state(i);
150  if (s != hlt::Ready) {
151  flags[0] = true; // at least one trigger was run
152  if (s == hlt::Pass) {
153  flags[1] = true; // at least one trigger accepted
154  } else if (s == hlt::Exception) {
155  flags[2] = true; // at least one trigger with error
156  }
157  }
158  }
159  // Change in semantics of flags[1] vs pre-art: now we accept if
160  // no paths were run.
161  flags[1] |= (!flags[0]) | paths_.empty();
162  return flags[icase];
163  }
164 
165  }; // HLTGlobalStatus
166 
167  // Free swap function
168  inline void
170  {
171  lhs.swap(rhs);
172  }
173 
174  // Formatted printout of trigger table
175  inline std::ostream&
176  operator<<(std::ostream& ost, HLTGlobalStatus const& hlt)
177  {
178  std::vector<std::string> text(4);
179  text[0] = "n";
180  text[1] = "1";
181  text[2] = "0";
182  text[3] = "e";
183  for (std::size_t i{}, n{hlt.size()}; i != n; ++i)
184  ost << text.at(hlt.state(i));
185  return ost;
186  }
187 
188 } // art
189 
190 // ----------------------------------------------------------------------
191 
192 // The standard allows us to specialize std::swap for non-templates.
193 // This ensures that HLTGlobalStatus::swap() will be used in algorithms.
194 
195 namespace std {
196 
197  template <>
198  inline void
200  {
201  lhs.swap(rhs);
202  }
203 }
204 
205 // ======================================================================
206 
207 #endif /* canvas_Persistency_Common_HLTGlobalStatus_h */
208 
209 // Local Variables:
210 // mode: c++
211 // End:
bool error(std::size_t const i) const
std::ostream & operator<<(std::ostream &os, EDAnalyzer::Table< T > const &t)
Definition: EDAnalyzer.h:184
HLTGlobalStatus()=default
bool error() const
Definition: HLTPathStatus.h:84
bool wasrun() const
Definition: HLTPathStatus.h:71
std::vector< HLTPathStatus > paths_
::xsd::cxx::tree::flags flags
Definition: Database.h:214
HLTPathStatus const & operator[](std::size_t const i) const
HLTGlobalStatus & operator=(HLTGlobalStatus const &rhs)
HLTPathStatus const & at(std::size_t const i) const
HLTState
status of a trigger path
Definition: HLTenums.h:14
hlt::HLTState state(std::size_t const i) const
bool wasrun(std::size_t const i) const
const XML_Char * s
Definition: expat.h:262
not [yet] run
Definition: HLTenums.h:15
bool wasrun() const
bool accept(std::size_t const i) const
unsigned int index() const
Definition: HLTPathStatus.h:58
HLTPathStatus & operator[](std::size_t const i)
std::size_t size() const
bool accept() const
Definition: HLTPathStatus.h:78
const std::string path
Definition: plot_BEN.C:43
std::size_t index(std::size_t const i) const
void swap(HLTGlobalStatus &other)
HLTGlobalStatus(std::size_t const n)
bool accept() const
auto for_all(FwdCont &, Func)
Service to store calibration data products (CDP) in the SQLite3 metadatabase of a file...
Definition: FillParentInfo.h:8
accept
Definition: HLTenums.h:16
hlt::HLTState state() const
Definition: HLTPathStatus.h:52
HLTPathStatus & at(std::size_t const i)
void reset(std::size_t const i)
bool state_on_demand(std::size_t const icase) const