Belle II Software light-2406-ragdoll
TRGSummary.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/TRGSummary.h>
9
10#include <framework/logging/Logger.h>
11#include <framework/database/DBObjPtr.h>
12#include <mdst/dbobjects/TRGGDLDBInputBits.h>
13#include <mdst/dbobjects/TRGGDLDBFTDLBits.h>
14
15#include <TROOT.h>
16#include <TColor.h>
17
18#include <sstream>
19#include <stdexcept>
20
21using namespace Belle2;
22
23TRGSummary::TRGSummary(unsigned int inputBits[10],
24 unsigned int ftdlBits[10],
25 unsigned int psnmBits[10],
26 ETimingType timType)
27{
28 for (int i = 0; i < 10; i++) {
29 m_inputBits[i] = inputBits[i];
30 m_ftdlBits[i] = ftdlBits[i];
31 m_psnmBits[i] = psnmBits[i];
32 }
33 m_timType = timType;
34}
35
36bool TRGSummary::test() const
37{
38 for (unsigned int word = 0; word < c_ntrgWords; word++) {
39 if (m_psnmBits[word] != 0) return true;
40 }
41 return false;
42}
43
44bool TRGSummary::testInput(unsigned int bit) const
45{
46 if (bit >= c_trgWordSize * c_ntrgWords) {
47 B2ERROR("Requested input trigger bit number is out of range" << LogVar("bit", bit));
48 throw std::out_of_range("The requested input trigger bit is out of range: " + std::to_string(bit));
49 }
50 int iWord = bit / c_trgWordSize;
51 int iBit = bit % c_trgWordSize;
52 return (m_inputBits[iWord] & (1u << iBit)) != 0;
53}
54
55bool TRGSummary::testFtdl(unsigned int bit) const
56{
57 if (bit >= c_trgWordSize * c_ntrgWords) {
58 B2ERROR("Requested ftdl trigger bit number is out of range" << LogVar("bit", bit));
59 throw std::out_of_range("The requested FTDL trigger bit is out of range: " + std::to_string(bit));
60 }
61 int iWord = bit / c_trgWordSize;
62 int iBit = bit % c_trgWordSize;
63 return (m_ftdlBits[iWord] & (1u << iBit)) != 0;
64}
65
66bool TRGSummary::testPsnm(unsigned int bit) const
67{
68 if (bit >= c_trgWordSize * c_ntrgWords) {
69 B2ERROR("Requested psnm trigger bit number is out of range" << LogVar("bit", bit));
70 throw std::out_of_range("The requested PSNM trigger bit is out of range: " + std::to_string(bit));
71 }
72 int iWord = bit / c_trgWordSize;
73 int iBit = bit % c_trgWordSize;
74 return (m_psnmBits[iWord] & (1u << iBit)) != 0;
75}
76
77unsigned int TRGSummary::getInputBitNumber(const std::string& name) const
78{
79 // Instead of returning a magic number, let's throw an exception:
80 // this will help us to distinguish "trigger not fired" cases
81 // from "trigger not found" at analysis level.
82 static DBObjPtr<TRGGDLDBInputBits> inputBits;
83
84 if (not inputBits) {
85 B2WARNING("The mapping of input trigger names does not exist in the given globaltags");
86 throw std::runtime_error("No input trigger map in the given globaltags");
87 }
88
89 for (unsigned int bit = 0; bit < c_trgWordSize * c_ntrgWords; bit++) {
90 if (std::string(inputBits->getinbitname((int)bit)) == name) {
91 return bit;
92 }
93 }
94
95 B2WARNING("The requested input trigger name does not exist" << LogVar("name", name));
96 throw std::invalid_argument("The requested input trigger name does not exist: " + name);
97}
98
99unsigned int TRGSummary::getOutputBitNumber(const std::string& name) const
100{
101 // Instead of returning a magic number, let's throw an exception:
102 // this will help us to distinguish "trigger not fired" cases
103 // from "trigger not found" at analysis level.
104 static DBObjPtr<TRGGDLDBFTDLBits> ftdlBits;
105
106 if (not ftdlBits) {
107 B2WARNING("The mapping of output trigger names does not exist in the given globaltags");
108 throw std::runtime_error("No input trigger map in the given globaltags");
109 }
110
111 for (unsigned int bit = 0; bit < c_trgWordSize * c_ntrgWords; bit++) {
112 if (std::string(ftdlBits->getoutbitname((int)bit)) == name) {
113 return bit;
114 }
115 }
116
117 B2WARNING("The requested output trigger name does not exist" << LogVar("name", name));
118 // Instead of returning a magic number, let's throw an exception:
119 // this will help us to distinguish "trigger not fired" cases
120 // from "trigger not found" at analysis level.
121 throw std::invalid_argument("The requested input trigger name does not exist: " + name);
122}
123
124std::string TRGSummary::getInfoHTML() const
125{
126 std::stringstream htmlOutput;
127
128 htmlOutput << "<table>";
129 htmlOutput
130 << "<tr><td></td><td bgcolor='#cccccc'>GDL Input</td><td bgcolor='#cccccc' colspan='2'>GDL Output</td></tr>";
131 htmlOutput
132 << "<tr><td>Bit</td><td>Input Bits</td><td>Final Trg DL</td><td>Prescaled Trg and Mask</td></tr>";
133
134 for (unsigned int currentBit = 0;
135 currentBit < (c_ntrgWords * c_trgWordSize); currentBit++) {
136 htmlOutput << "<tr>";
137
138 const auto currentWord = currentBit / c_trgWordSize;
139 const auto currentBitInWord = currentBit % c_trgWordSize;
140
141 const auto ftdlBit =
142 (getFtdlBits(currentWord) & ((unsigned int)1 << currentBitInWord)) > 0;
143 const auto psnmBit =
144 (getPsnmBits(currentWord) & ((unsigned int)1 << currentBitInWord)) > 0;
145 const auto inputBit = (getInputBits(currentWord)
146 & ((unsigned int)1 << currentBitInWord)) > 0;
147
148 htmlOutput << "<td>" << currentBit << "(word " << currentWord << " bit "
149 << currentBitInWord << ")</td>";
150 htmlOutput << outputBitWithColor(inputBit);
151 htmlOutput << outputBitWithColor(ftdlBit);
152 htmlOutput << outputBitWithColor(psnmBit);
153 htmlOutput << "</tr>";
154 }
155 htmlOutput << "</table>";
156
157 return htmlOutput.str();
158}
159
160
162std::string TRGSummary::outputBitWithColor(bool bit) const
163{
164 const std::string colorNeutral = gROOT->GetColor(kWhite)->AsHexString();
165 const std::string colorAccept = gROOT->GetColor(kGreen)->AsHexString();
166
167 std::string color = bit > 0 ? colorAccept : colorNeutral;
168 std::stringstream outStream;
169 outStream << "<td bgcolor=\"" << color << "\">" << bit << "</td>";
170 return outStream.str();
171}
Class for accessing objects in the database.
Definition: DBObjPtr.h:21
static const unsigned int c_trgWordSize
size of a l1 trigger word
Definition: TRGSummary.h:37
unsigned int m_ftdlBits[c_ntrgWords]
ftdl (Final Trigger Decision Logic) bits.
Definition: TRGSummary.h:254
bool test() const
check whether any psnm bit is set
Definition: TRGSummary.cc:36
std::string outputBitWithColor(bool bit) const
return the td part of an HTML table with green of the bit is > 0
Definition: TRGSummary.cc:162
bool testPsnm(unsigned int bit) const
check whether a psnm bit is set
Definition: TRGSummary.cc:66
std::string getInfoHTML() const override
Return a short summary of this object's contents in HTML format.
Definition: TRGSummary.cc:124
unsigned int m_inputBits[c_ntrgWords]
input bits from subdetectors
Definition: TRGSummary.h:251
ETimingType
types of trigger timing source defined in b2tt firmware
Definition: TRGSummary.h:43
unsigned int m_psnmBits[c_ntrgWords]
psnm (PreScale aNd Mask) bits.
Definition: TRGSummary.h:259
TRGSummary()=default
default constructor: xxx
unsigned int getFtdlBits(const unsigned i) const
get ftdl bits (directly determined by the trigger conditions)
Definition: TRGSummary.h:195
ETimingType m_timType
types of trigger timing source defined in b2tt firmware
Definition: TRGSummary.h:262
unsigned int getInputBits(const unsigned i) const
get input bits
Definition: TRGSummary.h:186
unsigned int getOutputBitNumber(const std::string &name) const
get number of an output trigger bit
Definition: TRGSummary.cc:99
unsigned int getInputBitNumber(const std::string &name) const
get number of an input trigger bit
Definition: TRGSummary.cc:77
static const unsigned int c_ntrgWords
number of l1 trigger words
Definition: TRGSummary.h:40
unsigned int getPsnmBits(const unsigned i) const
get psnm bits (prescaled ftdl bits)
Definition: TRGSummary.h:204
bool testInput(unsigned int bit) const
check whether an input bit is set
Definition: TRGSummary.cc:44
bool testFtdl(unsigned int bit) const
check whether a ftdl bit is set
Definition: TRGSummary.cc:55
Class to store variables with their name which were sent to the logging service.
Abstract base class for different kinds of events.
Definition: ClusterUtils.h:24