ATLAS Offline Software
Loading...
Searching...
No Matches
TriggerItemNode.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
7
8#include <iomanip>
9#include <iostream>
10#include <string>
11#include <cstdlib>
12#include <inttypes.h>
13#include <stdexcept>
14#include <sys/types.h>
15
16using namespace std;
17using namespace TrigConf;
18
19
28
29
34
37 if(type=="AND") return TriggerItemNode::AND;
38 if(type=="OR") return TriggerItemNode::OR;
39 if(type=="NOT") return TriggerItemNode::NOT;
40 if(type=="OBJ") return TriggerItemNode::OBJ;
41 if(type=="TriggerCondition") return TriggerItemNode::OBJ;
42 if(type=="InternalTrigger") return TriggerItemNode::OBJ;
44}
45
48 if(c=='&') return TriggerItemNode::AND;
49 if(c=='|') return TriggerItemNode::OR;
50 if(c=='!') return TriggerItemNode::NOT;
52}
53
54std::string
56 static const std::string typelabel[] = {"OBJ", "NOT", "AND", "OR", "UNDEF"};
57 return typelabel[type];
58}
59
60
61bool
65
66bool
70
71void
73 if(thr->isInternal()) {
74 // from the database internal triggers are also loaded as TriggerThresholds
75 setInternalTrigger(thr->name());
76 } else {
78 m_InternalTrigger.second = 0;
79 }
80 m_Threshold = thr;
81 m_ThresholdName = thr->name();
82}
83
84void
86 unsigned int thresholdNumber) {
87 m_InternalTrigger.first = x;
88 m_InternalTrigger.second = thresholdNumber;
89 m_ThresholdName = L1DataDef::typeConfig(x).name + std::to_string(thresholdNumber);
90 m_Threshold = 0;
91}
92
93void
95
96 string::size_type pos = name.find_first_of("0123456789");
97
99
100 if( ! L1DataDef::typeConfig(tt).internal ) {
101 cerr << "TriggerItemNode::setInternalTrigger: type " << name << " is not an internal trigger" << endl;
102 throw runtime_error("TriggerItemNode::setInternalTrigger: type is not an internal trigger");
103 }
104 m_InternalTrigger.first = tt;
105 m_InternalTrigger.second = static_cast<unsigned int>(std::stoul(name.substr(pos)));
107 m_Threshold = 0;
108}
109
110
111void
113 if(type() == OBJ)
114 throw std::runtime_error("TriggerItemNode::addChild: trying to add child to leaf node");
115 m_Children.push_back(node);
116}
117
118void
119TrigConf::TriggerItemNode::getAllFinalNodes(std::vector<const TriggerItemNode*>& vec) const {
120 if(type() == OBJ) {
121 vec.push_back(this);
122 } else {
124 node->getAllFinalNodes(vec);
125 }
126}
127
128void
129TrigConf::TriggerItemNode::getAllThresholds(std::vector<const TriggerThreshold*>& vec) const {
130 if(type() == OBJ) {
131 if(!isInternalTrigger()) {
132 if(m_Threshold) vec.push_back(m_Threshold);
133 }
134 } else {
136 node->getAllThresholds(vec);
137 }
138}
139
140// returns a bit-pattern for the bunchgroups
141void
143 unsigned int max_bgrp = L1DataDef::typeConfig(L1DataDef::BGRP).max;
144 if(vec.size() < max_bgrp) vec.resize( max_bgrp );
145 if(type() == OBJ) {
147 vec[m_InternalTrigger.second] = true;
148 } else {
150 node->getAllBunchGroups(vec);
151 }
152}
153
154// returns a bit-pattern for the just as the previous one but as uint16
155void
157 if(type() == OBJ) {
159 uint16_t mask(0x1);
160 bgmask |= (mask << m_InternalTrigger.second);
161 }
162 } else {
164 node->getBunchGroupsMask(bgmask);
165 }
166}
167
168void
169TrigConf::TriggerItemNode::getAllBunchGroups(std::vector<unsigned int>& vec) const {
170 if(type() == OBJ) {
172 vec.push_back(m_InternalTrigger.second);
173 } else {
175 node->getAllBunchGroups(vec);
176 }
177}
178
179void
180TrigConf::TriggerItemNode::getAllRandomTriggers(std::vector<unsigned int>& vec) const {
181 if(type() == OBJ) {
183 vec.push_back(m_InternalTrigger.second);
184 } else {
186 node->getAllRandomTriggers(vec);
187 }
188}
189
190void
192 if(type() == OBJ) {
194 vec.push_back(m_InternalTrigger.second);
195 } else {
197 node->getAllPrescaledClockTriggers(vec);
198 }
199 return;
200}
201
202void
203TrigConf::TriggerItemNode::writeXML(std::ostream & xmlfile, int indentLevel, int indentWidth, bool /*omitDelimiter*/) const {
204 if (m_NodeType == OBJ) {
205
206 if(isInternalTrigger()) {
207 indent(xmlfile, indentLevel, indentWidth)
208 << "<InternalTrigger name=\"" << m_ThresholdName << "\"/>" << endl;
209 } else {
210 indent(xmlfile, indentLevel, indentWidth)
211 << "<TriggerCondition multi=\"" << m_Multiplicity
212 << "\" name=\"" << m_ThresholdName << "_x" << m_Multiplicity
213 << "\" triggerthreshold=\"" << m_ThresholdName << "\"/>" << endl;
214 }
215
216 } else if (m_NodeType == AND || m_NodeType == OR) {
217
218 std::string logic = (m_NodeType==AND?"AND":"OR");
219 indent(xmlfile, indentLevel, indentWidth) << "<" << logic << ">" << endl;
221 node->writeXML(xmlfile, indentLevel+1, indentWidth);
222 indent(xmlfile, indentLevel, indentWidth) << "</"<<logic<<">" << endl;
223
224 } else if (m_NodeType == NOT) {
225
226 indent(xmlfile, indentLevel, indentWidth) << "<NOT>" << endl;
227 children()[0]->writeXML(xmlfile, indentLevel+1, indentWidth);
228 indent(xmlfile, indentLevel, indentWidth) << "</NOT>" << endl;
229
230 }
231}
232
233
234void
235TrigConf::TriggerItemNode::buildLogic(std::vector<std::string> & conditionList,
236 std::string & logic) const {
237
238 if (m_NodeType == OBJ) {
239 std::string condition("");
240 if (m_Threshold) {
244 std::string name = m_Threshold->name();
245 name += "_x" + std::to_string(m_Multiplicity);
246 condition += '0' + m_Multiplicity;
247 condition += "," + name;
248 condition += "," + m_Threshold->name();
249 } else {
250 condition = m_Threshold->name();
251 }
252 } else {
253 condition = thresholdName();
254 }
255 uint32_t pos = conditionList.size()+1;
256 if(pos>9) logic += '0'+pos/10;
257 logic += '0'+pos%10;
258 conditionList.push_back(std::move(condition));
259 } else if (m_NodeType == AND || m_NodeType == OR) {
260 logic += "(";
261 bool first = true;
262 for(TriggerItemNode *node : children()) {
263 if(!first) { logic += (m_NodeType==AND?"&":"|"); } else { first=false; }
264 node->buildLogic(conditionList, logic);
265 }
266 logic += ")";
267 } else if (m_NodeType == NOT) {
268 logic += "!";
269 children()[0]->buildLogic(conditionList, logic);
270 }
271
272}
273
274
275void
276TrigConf::TriggerItemNode::print(const std::string& indent, unsigned int detail) const {
277 cout << indent << "TriggerItemNode: " << endl;
278 cout << indent << " type : " << (type()==OBJ?"OBJ":(type()==AND?"AND":(type()==OR?"OR":"NOT"))) << endl;
279 cout << indent << " position : " << m_Position << endl;
280
281 if (m_NodeType == OBJ) {
282 cout << indent << " multiplicity: " << m_Multiplicity << endl;
283 if (m_Threshold) {
284 cout << indent << " threshold : " << m_Threshold->name() << endl;
285 m_Threshold->print(indent + indent, detail);
286 } else if(isInternalTrigger()) {
287 cout << indent << " InternalTrigger: "
288 << thresholdName() << endl;
289 } else {
290 cout << indent << thresholdName() << endl;
291 }
292 }
293 else {
295 cout << indent << " subnode : " << endl;
296 node->print(indent + indent);
297 }
298 }
299}
300
301std::ostream& TrigConf::TriggerItemNode::indent(std::ostream& o, int lvl, int size) const {
302 if(lvl*size==0) return o;
303 o << std::setw(lvl*size) << " ";
304 return o;
305}
306
307
308std::ostream &
309TrigConf::operator<<(std::ostream & o, const TrigConf::TriggerItemNode & node) {
310 o << " TriggerItemNode: " << endl;
311 o << " type : " << (node.type()==TriggerItemNode::OBJ? "OBJ" : (node.type()==TriggerItemNode::AND?"AND":(node.type()==TriggerItemNode::OR?"OR":"NOT"))) << endl;
312 o << " position : " << node.position() << endl;
313
314 if (node.type() == TriggerItemNode::OBJ) {
315 o << " multiplicity: " << node.multiplicity() << endl;
316 if ( node.triggerThreshold() ) {
317 o << " threshold : " << node.thresholdName() << endl
318 << node.triggerThreshold();
319 } else if( node.isInternalTrigger() ) {
320 o << " InternalTrigger: " << node.thresholdName() << endl;
321 } else {
322 o << node.thresholdName() << endl;
323 }
324 }
325 else {
326 for(TriggerItemNode* subnode: node.children()) {
327 o << " subnodes : " << *subnode << endl;
328 }
329 }
330 return o;
331}
332
333string
335 stringstream s;
336 s << *this;
337 return s.str();
338}
std::vector< size_t > vec
#define x
node * subnode(node *np, const std::string &name)
check whether a subnode with this name already exists
Definition addnode.cxx:20
static TriggerType stringAsType(const std::string &type)
Definition L1DataDef.h:51
static TriggerTypeConfig & typeConfig(TriggerType tt)
static NodeType typeFromChar(const char &c)
std::ostream & indent(std::ostream &o, int lvl, int size) const
const std::vector< TriggerItemNode * > & children() const
std::pair< L1DataDef::TriggerType, unsigned int > InternalType_t
static NodeType typeFromString(const std::string &)
std::vector< TriggerItemNode * > m_Children
L1DataDef::TriggerType internalTriggerType() const
void getAllPrescaledClockTriggers(std::vector< unsigned int > &) const
const std::string & thresholdName() const
void getAllBunchGroups(std::vector< bool > &) const
static std::string typeAsString(NodeType)
void setInternalTrigger(L1DataDef::TriggerType x, unsigned int thresholdNumber)
void getAllRandomTriggers(std::vector< unsigned int > &) const
virtual std::string __str__() const
void getAllFinalNodes(std::vector< const TriggerItemNode * > &) const
InternalType_t m_InternalTrigger
void getBunchGroupsMask(uint16_t &bgmask) const
void addChild(TriggerItemNode *node)
TriggerThreshold * m_Threshold
void writeXML(std::ostream &xmlfile, int indentLevel=0, int indentWidth=2, bool omitDelimiter=false) const
void buildLogic(std::vector< std::string > &conditionList, std::string &logic) const
void getAllThresholds(std::vector< const TriggerThreshold * > &) const
void setTriggerThreshold(TriggerThreshold *thr)
void print(const std::string &indent="", unsigned int detail=1) const
Definition node.h:24
void type(TYPE t)
Definition node.h:51
static std::vector< std::string > xmlfile
Definition iLumiCalc.h:29
Forward iterator to traverse the main components of the trigger configuration.
Definition Config.h:22
std::ostream & operator<<(std::ostream &os, const TrigConf::IsolationLegacy &iso)
STL namespace.