ATLAS Offline Software
TrigMonAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // C/C++
6 #include <iostream>
7 #include <sstream>
8 
12 
13 namespace AlgBits
14 {
15  const uint32_t maskCache = 0x80; // bit used to set caching state
16  const uint32_t maskPos = 0x7f; // mask bottom 7 bits
17 }
18 
19 
20 //--------------------------------------------------------------------------------------
22  :m_byte(1, 0)
23 {
24 }
25 
26 //--------------------------------------------------------------------------------------
27 TrigMonAlg::TrigMonAlg(unsigned int position, bool is_cached)
28  :m_byte(1, 0)
29 {
30  if(position < 128) {
31  m_byte[0] = position;
32  }
33  else {
34  REPORT_MESSAGE_WITH_CONTEXT(MSG::ERROR, "TrigMonAlg")
35  << "ctor error! Position is out of allowed range.";
36  }
37 
38  if(is_cached) {
39  //
40  // Set top bit for caching state
41  //
43  }
44 }
45 
46 //--------------------------------------------------------------------------------------
48 {
49  //
50  // Save start and stop time for one algorithm call
51  //
52  if(isCached()) {
53  REPORT_MESSAGE_WITH_CONTEXT(MSG::ERROR, "TrigMonAlg")
54  << "addTimers error! Cached algorithm has no timers.";
55  return;
56  }
57  else if(!m_word.empty()) {
58  REPORT_MESSAGE_WITH_CONTEXT(MSG::ERROR, "TrigMonAlg")
59  << "addTimers error! Timers already added!";
60  return;
61  }
62 
63  m_word.push_back(tbeg.getEncoded());
64  m_word.push_back(tend.getEncoded());
65 }
66 
67 //--------------------------------------------------------------------------------------
68 void TrigMonAlg::addRoiId(unsigned int roi_id)
69 {
70  //
71  // Add roid id, check that id is less than 256
72  //
73  if(roi_id < 256) {
74  m_byte.push_back(static_cast<uint8_t>(roi_id));
75  }
76  else if (roi_id == 256) {
77  REPORT_MESSAGE_WITH_CONTEXT(MSG::ERROR, "TrigMonAlg")
78  << "addRoiId error! RoiId value is out of range! (only reported for ID=256)";
79  }
80 }
81 
82 //--------------------------------------------------------------------------------------
83 void TrigMonAlg::addWord(unsigned int word)
84 {
85  //
86  // Save start and stop time for one algorithm call
87  //
88  if(m_word.size() != 2 && !isCached()) {
89  REPORT_MESSAGE_WITH_CONTEXT(MSG::ERROR, "TrigMonAlg")
90  << "addWord error! Timers must be added first.";
91  return;
92  }
93 
94  m_word.push_back(word);
95 }
96 
97 //--------------------------------------------------------------------------------------
99 {
100  //
101  // Return algorithm position with top bit set to zero
102  //
103  return (m_byte[0] & AlgBits::maskPos);
104 }
105 
106 //--------------------------------------------------------------------------------------
108 {
109  //
110  // Get number of RoIs
111  //
112  return m_byte.size()-1;
113 }
114 
115 //--------------------------------------------------------------------------------------
116 uint8_t TrigMonAlg::getRoiId(unsigned int i) const
117 {
118  //
119  // Return roi id
120  //
121  if(i+1 < m_byte.size()) return m_byte[i+1];
122 
123  return Trig::getRoiId_Unknown();
124 }
125 
126 //--------------------------------------------------------------------------------------
127 const std::set<uint8_t> TrigMonAlg::getRoiIdSet() const
128 {
129  //
130  // Return set of all roi ids
131  //
132  return std::set<uint8_t>(m_byte.begin()+1, m_byte.end());
133 }
134 
135 //--------------------------------------------------------------------------------------
137 {
138  //
139  // check top bit for caching state
140  //
141  return (m_byte[0] & AlgBits::maskCache);
142 }
143 
144 //--------------------------------------------------------------------------------------
146 {
147  //
148  // check top bit for caching state
149  //
150  return !isCached();
151 }
152 
153 //--------------------------------------------------------------------------------------
155 {
156  //
157  // This function only make sense when timers exists, so first check isCalled()=false
158  //
159  if(!isCached() && m_word.size() >= 2) {
160  return TrigMonTimer(m_word[0]);
161  }
162 
163  return TrigMonTimer(0);
164 }
165 
166 //--------------------------------------------------------------------------------------
168 {
169  //
170  // This function only make sense when timers exists, so first check isCalled()=true
171  //
172  if(!isCached() && m_word.size() >= 2) {
173  return TrigMonTimer(m_word[1]);
174  }
175 
176  return TrigMonTimer(0);
177 }
178 
179 //--------------------------------------------------------------------------------------
180 std::string str(const TrigMonAlg &o)
181 {
182  std::stringstream s;
183  s << "TrigMonAlg: called=" << o.isCalled()
184  << " cached=" << o.isCached()
185  << " timer=" << o.elapsed()
186  << " rois=";
187 
188  for(unsigned int i = 0; i < o.getNRoi(); ++i) {
189  s << " " << int(o.getRoiId(i)) << "\n";
190  }
191 
192  return s.str();
193 }
AlgBits::maskPos
const uint32_t maskPos
Definition: TrigMonAlg.cxx:16
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
TrigMonAlg::isCached
bool isCached() const
Definition: TrigMonAlg.cxx:136
str
std::string str(const TrigMonAlg &o)
Definition: TrigMonAlg.cxx:180
xAOD::uint8_t
uint8_t
Definition: Muon_v1.cxx:575
TrigMonAlg::getRoiId
uint8_t getRoiId(unsigned int i=0) const
Definition: TrigMonAlg.cxx:116
TrigMonAlg::getNRoi
uint8_t getNRoi() const
Definition: TrigMonAlg.cxx:107
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
TrigMonAlg::addRoiId
void addRoiId(unsigned int roiId)
Definition: TrigMonAlg.cxx:68
roi_id
std::vector< QString > roi_id
Definition: VP1TriggerHandleL1.cxx:38
TrigMonAlg::elapsed
double elapsed() const
Definition: TrigMonAlg.h:57
TrigMonTimer
Definition: TrigMonTimer.h:27
TrigMonAlg::getRoiIdSet
const std::set< uint8_t > getRoiIdSet() const
Definition: TrigMonAlg.cxx:127
TrigMonAlg::addWord
void addWord(unsigned int word)
Definition: TrigMonAlg.cxx:83
python.TriggerHandler.tend
string tend
Definition: TriggerHandler.py:300
TrigMonAlg::stop
const TrigMonTimer stop() const
Definition: TrigMonAlg.cxx:167
lumiFormat.i
int i
Definition: lumiFormat.py:92
TrigMonAlg::m_word
std::vector< uint32_t > m_word
Definition: TrigMonAlg.h:63
Trig::getRoiId_Unknown
uint8_t getRoiId_Unknown()
Definition: TrigMonRoi.h:89
TrigMonAlg::m_byte
std::vector< uint8_t > m_byte
Definition: TrigMonAlg.h:62
TrigMonAlg::addTimer
void addTimer(const TrigMonTimer &tbeg, const TrigMonTimer &tend)
Definition: TrigMonAlg.cxx:47
REPORT_MESSAGE_WITH_CONTEXT
#define REPORT_MESSAGE_WITH_CONTEXT(LVL, CONTEXT_NAME)
Report a message, with an explicitly specified context name.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:345
TrigMonAlg::isCalled
bool isCalled() const
Definition: TrigMonAlg.cxx:145
TrigMonAlg.h
AlgBits::maskCache
const uint32_t maskCache
Definition: TrigMonAlg.cxx:15
errorcheck.h
Helpers for checking error return status codes and reporting errors.
TrigMonRoi.h
TrigMonAlg::start
const TrigMonTimer start() const
Definition: TrigMonAlg.cxx:154
AlgBits
Definition: TrigMonAlg.cxx:14
TrigMonAlg::TrigMonAlg
TrigMonAlg()
Definition: TrigMonAlg.cxx:21
TrigMonAlg::getPosition
uint8_t getPosition() const
Definition: TrigMonAlg.cxx:98
TrigMonAlg
Summary of single agorithm execution. Algorithm is identified by position within parent sequence....
Definition: TrigMonAlg.h:30
TrigMonTimer::getEncoded
uint32_t getEncoded() const
Definition: TrigMonTimer.h:38