Belle II Software development
SoftwareTriggerResult.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8#include <mdst/dataobjects/SoftwareTriggerResult.h>
9#include <boost/algorithm/string/replace.hpp>
10
11#include <TROOT.h>
12#include <TColor.h>
13
14using namespace Belle2;
15
17void SoftwareTriggerResult::addResult(const std::string& triggerIdentifier, SoftwareTriggerCutResult result,
18 SoftwareTriggerCutResult nonPrescalesResult)
19{
20 m_results[triggerIdentifier] = std::make_pair(static_cast<int>(result), static_cast<int>(nonPrescalesResult));
21}
22
23std::pair<SoftwareTriggerCutResult, SoftwareTriggerCutResult> SoftwareTriggerResult::getResultPair(
24 const std::string& triggerIdentifier) const
25{
26 auto pair = m_results.at(triggerIdentifier);
27 return {static_cast<SoftwareTriggerCutResult>(pair.first), static_cast<SoftwareTriggerCutResult>(pair.second)};
28}
29
30SoftwareTriggerCutResult SoftwareTriggerResult::getResult(const std::string& triggerIdentifier) const
31{
32 return getResultPair(triggerIdentifier).first;
33}
34
37{
38 return getResultPair(triggerIdentifier).second;
39}
40
41std::map<std::string, int> SoftwareTriggerResult::getResults() const
42{
43 std::map<std::string, int> result;
44 // cppcheck-suppress unassignedVariable ; cppcheck doesn't understand the assignment in the range-based for loop
45 for (const auto& [key, valuePair] : m_results) {
46 result[key] = valuePair.first;
47 }
48 return result;
49}
50
51std::map<std::string, int> SoftwareTriggerResult::getNonPrescaledResults() const
52{
53 std::map<std::string, int> result;
54 // cppcheck-suppress unassignedVariable ; cppcheck doesn't understand the assignment in the range-based for loop
55 for (const auto& [key, valuePair] : m_results) {
56 result[key] = valuePair.second;
57 }
58 return result;
59}
60
63{
64 m_results.clear();
65}
66
68{
69 std::stringstream out;
70 out << "<table>";
71
72 const std::string colorNeutral = gROOT->GetColor(kWhite)->AsHexString();
73 const std::string colorReject = gROOT->GetColor(kRed)->AsHexString();
74 const std::string colorAccept = gROOT->GetColor(kGreen)->AsHexString();
75
76 for (const auto& result : m_results) {
77 out << "<tr>";
78 std::string name = result.first;
79 boost::replace_all(name, "software_trigger_cut&", "");
80 boost::replace_all(name, "&", "/");
81 const int value = result.second.first;
82
83 auto thisColor = colorNeutral;
84 if (value > 0) {
85 thisColor = colorAccept;
86 } else if (value < 0) {
87 thisColor = colorReject;
88 }
89
90 out << "<td>" << name << "</td>";
91 out << "<td bgcolor=\"" << thisColor << "\">" << value << "</td>";
92 out << "</tr>";
93 }
94 out << "</table>";
95 return out.str();
96}
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.
std::map< std::string, std::pair< int, int > > m_results
Internal storage of the cut decisions with names.
SoftwareTriggerCutResult getResult(const std::string &triggerIdentifier) const
Return the cut result with the given name or throw an error if no result is there.
std::string getInfoHTML() const override
Return a short summary of this object's contents in HTML format.
std::map< std::string, int > getResults() const
Return all stored cut tags with their results as a map identifier -> cut result.
void addResult(const std::string &triggerIdentifier, SoftwareTriggerCutResult result, SoftwareTriggerCutResult nonPrescaledResult=SoftwareTriggerCutResult::c_noResult)
Add a new cut result to the storage or override the result with the same name.
std::map< std::string, int > getNonPrescaledResults() const
Return all stored cut tags with their non-prescaled results as a map identifier -> cut result.
void clear()
Clear all results.
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...
SoftwareTriggerCutResult
Enumeration with all possible results of the SoftwareTriggerCut.
Abstract base class for different kinds of events.