Belle II Software  release-05-02-19
SoftwareTriggerResult.cc
1 #include <mdst/dataobjects/SoftwareTriggerResult.h>
2 #include <boost/algorithm/string/replace.hpp>
3 
4 #include <TROOT.h>
5 #include <TColor.h>
6 
7 using namespace Belle2;
8 
10 void SoftwareTriggerResult::addResult(const std::string& triggerIdentifier, const SoftwareTriggerCutResult& result,
11  const SoftwareTriggerCutResult& nonPrescalesResult)
12 {
13  m_results[triggerIdentifier] = std::make_pair(static_cast<int>(result), static_cast<int>(nonPrescalesResult));
14 }
15 
16 std::pair<SoftwareTriggerCutResult, SoftwareTriggerCutResult> SoftwareTriggerResult::getResultPair(
17  const std::string& triggerIdentifier) const
18 {
19  auto pair = m_results.at(triggerIdentifier);
20  return {static_cast<SoftwareTriggerCutResult>(pair.first), static_cast<SoftwareTriggerCutResult>(pair.second)};
21 }
22 
23 SoftwareTriggerCutResult SoftwareTriggerResult::getResult(const std::string& triggerIdentifier) const
24 {
25  return getResultPair(triggerIdentifier).first;
26 }
27 
30 {
31  return getResultPair(triggerIdentifier).second;
32 }
33 
34 std::map<std::string, int> SoftwareTriggerResult::getResults() const
35 {
36  std::map<std::string, int> result;
37  for (const auto& [key, valuePair] : m_results) {
38  result[key] = valuePair.first;
39  }
40  return result;
41 }
42 
43 std::map<std::string, int> SoftwareTriggerResult::getNonPrescaledResults() const
44 {
45  std::map<std::string, int> result;
46  for (const auto& [key, valuePair] : m_results) {
47  result[key] = valuePair.second;
48  }
49  return result;
50 }
51 
54 {
55  m_results.clear();
56 }
57 
59 {
60  std::stringstream out;
61  out << "<table>";
62 
63  const std::string colorNeutral = gROOT->GetColor(kWhite)->AsHexString();
64  const std::string colorReject = gROOT->GetColor(kRed)->AsHexString();
65  const std::string colorAccept = gROOT->GetColor(kGreen)->AsHexString();
66 
67  for (const auto& result : m_results) {
68  out << "<tr>";
69  std::string name = result.first;
70  boost::replace_all(name, "software_trigger_cut&", "");
71  boost::replace_all(name, "&", "/");
72  const int value = result.second.first;
73 
74  auto thisColor = colorNeutral;
75  if (value > 0) {
76  thisColor = colorAccept;
77  } else if (value < 0) {
78  thisColor = colorReject;
79  }
80 
81  out << "<td>" << name << "</td>";
82  out << "<td bgcolor=\"" << thisColor << "\">" << value << "</td>";
83  out << "</tr>";
84  }
85  out << "</table>";
86  return out.str();
87 }
Belle2::SoftwareTriggerResult::getNonPrescaledResults
std::map< std::string, int > getNonPrescaledResults() const
Return all stored cut tags with their non-prescaled results as a map identifier -> cut result.
Definition: SoftwareTriggerResult.cc:43
Belle2::SoftwareTriggerResult::getInfoHTML
std::string getInfoHTML() const override
Return a short summary of this object's contents in HTML format.
Definition: SoftwareTriggerResult.cc:58
Belle2::SoftwareTriggerResult::m_results
std::map< std::string, std::pair< int, int > > m_results
Internal storage of the cut decisions with names.
Definition: SoftwareTriggerResult.h:90
Belle2::SoftwareTriggerResult::addResult
void addResult(const std::string &triggerIdentifier, const SoftwareTriggerCutResult &result, const SoftwareTriggerCutResult &nonPrescaledResult=SoftwareTriggerCutResult::c_noResult)
Add a new cut result to the storage or override the result with the same name.
Definition: SoftwareTriggerResult.cc:10
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::SoftwareTriggerResult::clear
void clear()
Clear all results.
Definition: SoftwareTriggerResult.cc:53
Belle2::SoftwareTriggerResult::getResults
std::map< std::string, int > getResults() const
Return all stored cut tags with their results as a map identifier -> cut result.
Definition: SoftwareTriggerResult.cc:34
Belle2::SoftwareTriggerResult::getNonPrescaledResult
SoftwareTriggerCutResult getNonPrescaledResult(const std::string &triggerIdentifier) const
Return the non-prescaled cut result with the given name or throw an error if no result is there.
Definition: SoftwareTriggerResult.cc:29
Belle2::SoftwareTriggerCutResult
SoftwareTriggerCutResult
Enumeration with all possible results of the SoftwareTriggerCut.
Definition: SoftwareTriggerResult.h:31
Belle2::SoftwareTriggerResult::getResult
SoftwareTriggerCutResult getResult(const std::string &triggerIdentifier) const
Return the cut result with the given name or throw an error if no result is there.
Definition: SoftwareTriggerResult.cc:23
Belle2::SoftwareTriggerResult::getResultPair
std::pair< SoftwareTriggerCutResult, SoftwareTriggerCutResult > getResultPair(const std::string &triggerIdentifier) const
Return the cut result and the non-prescaled cut result with the given name or throw an error if no re...
Definition: SoftwareTriggerResult.cc:16