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