ATLAS Offline Software
TriggerItemNode.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 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 
16 #include <boost/lexical_cast.hpp>
17 
18 using namespace std;
19 using namespace TrigConf;
20 
21 
23  m_NodeType(type),
24  m_ThresholdName(""),
25  m_Position(0),
26  m_Multiplicity(0),
27  m_Threshold(0),
28  m_InternalTrigger(InternalType_t(L1DataDef::UNDEF,0))
29 {}
30 
31 
33  for(TriggerItemNode * node : m_Children)
34  delete node;
35 }
36 
39  if(type=="AND") return TriggerItemNode::AND;
40  if(type=="OR") return TriggerItemNode::OR;
41  if(type=="NOT") return TriggerItemNode::NOT;
42  if(type=="OBJ") return TriggerItemNode::OBJ;
43  if(type=="TriggerCondition") return TriggerItemNode::OBJ;
44  if(type=="InternalTrigger") return TriggerItemNode::OBJ;
46 }
47 
50  if(c=='&') return TriggerItemNode::AND;
51  if(c=='|') return TriggerItemNode::OR;
52  if(c=='!') return TriggerItemNode::NOT;
54 }
55 
56 std::string
58  static const std::string typelabel[] = {"OBJ", "NOT", "AND", "OR", "UNDEF"};
59  return typelabel[type];
60 }
61 
62 
63 bool
65  return m_InternalTrigger.first == L1DataDef::UNDEF;
66 }
67 
68 bool
70  return m_InternalTrigger.first != L1DataDef::UNDEF;
71 }
72 
73 void
75  if(thr->isInternal()) {
76  // from the database internal triggers are also loaded as TriggerThresholds
77  setInternalTrigger(thr->name());
78  } else {
79  m_InternalTrigger.first = L1DataDef::UNDEF;
80  m_InternalTrigger.second = 0;
81  }
82  m_Threshold = thr;
83  m_ThresholdName = thr->name();
84 }
85 
86 void
88  unsigned int thresholdNumber) {
89  m_InternalTrigger.first = x;
90  m_InternalTrigger.second = thresholdNumber;
91  m_ThresholdName = L1DataDef::typeConfig(x).name + boost::lexical_cast<string,unsigned int>(thresholdNumber);
92  m_Threshold = 0;
93 }
94 
95 void
97 
98  string::size_type pos = name.find_first_of("0123456789");
99 
101 
102  if( ! L1DataDef::typeConfig(tt).internal ) {
103  cerr << "TriggerItemNode::setInternalTrigger: type " << name << " is not an internal trigger" << endl;
104  throw runtime_error("TriggerItemNode::setInternalTrigger: type is not an internal trigger");
105  }
106  m_InternalTrigger.first = tt;
107  m_InternalTrigger.second = boost::lexical_cast<unsigned int,string>(name.substr(pos));
108  m_ThresholdName = name;
109  m_Threshold = 0;
110 }
111 
112 
113 void
115  if(type() == OBJ)
116  throw std::runtime_error("TriggerItemNode::addChild: trying to add child to leaf node");
117  m_Children.push_back(node);
118 }
119 
120 void
121 TrigConf::TriggerItemNode::getAllFinalNodes(std::vector<const TriggerItemNode*>& vec) const {
122  if(type() == OBJ) {
123  vec.push_back(this);
124  } else {
125  for(TriggerItemNode * node : m_Children)
126  node->getAllFinalNodes(vec);
127  }
128 }
129 
130 void
131 TrigConf::TriggerItemNode::getAllThresholds(std::vector<const TriggerThreshold*>& vec) const {
132  if(type() == OBJ) {
133  if(!isInternalTrigger()) {
134  if(m_Threshold) vec.push_back(m_Threshold);
135  }
136  } else {
137  for(TriggerItemNode * node : m_Children)
138  node->getAllThresholds(vec);
139  }
140 }
141 
142 // returns a bit-pattern for the bunchgroups
143 void
145  unsigned int max_bgrp = L1DataDef::typeConfig(L1DataDef::BGRP).max;
146  if(vec.size() < max_bgrp) vec.resize( max_bgrp );
147  if(type() == OBJ) {
148  if(internalTriggerType() == L1DataDef::BGRP)
149  vec[m_InternalTrigger.second] = true;
150  } else {
151  for(TriggerItemNode * node : m_Children)
152  node->getAllBunchGroups(vec);
153  }
154 }
155 
156 // returns a bit-pattern for the just as the previous one but as uint16
157 void
159  if(type() == OBJ) {
160  if(internalTriggerType() == L1DataDef::BGRP) {
161  uint16_t mask(0x1);
162  bgmask |= (mask << m_InternalTrigger.second);
163  }
164  } else {
165  for(TriggerItemNode * node : m_Children)
166  node->getBunchGroupsMask(bgmask);
167  }
168 }
169 
170 void
171 TrigConf::TriggerItemNode::getAllBunchGroups(std::vector<unsigned int>& vec) const {
172  if(type() == OBJ) {
173  if(internalTriggerType() == L1DataDef::BGRP)
174  vec.push_back(m_InternalTrigger.second);
175  } else {
176  for(TriggerItemNode * node : m_Children)
177  node->getAllBunchGroups(vec);
178  }
179 }
180 
181 void
182 TrigConf::TriggerItemNode::getAllRandomTriggers(std::vector<unsigned int>& vec) const {
183  if(type() == OBJ) {
184  if(internalTriggerType() == L1DataDef::RNDM)
185  vec.push_back(m_InternalTrigger.second);
186  } else {
187  for(TriggerItemNode * node : m_Children)
188  node->getAllRandomTriggers(vec);
189  }
190 }
191 
192 void
194  if(type() == OBJ) {
195  if(internalTriggerType() == L1DataDef::PCLK)
196  vec.push_back(m_InternalTrigger.second);
197  } else {
198  for(TriggerItemNode * node : m_Children)
199  node->getAllPrescaledClockTriggers(vec);
200  }
201  return;
202 }
203 
204 void
205 TrigConf::TriggerItemNode::writeXML(std::ostream & xmlfile, int indentLevel, int indentWidth, bool /*omitDelimiter*/) const {
206  if (m_NodeType == OBJ) {
207 
208  if(isInternalTrigger()) {
209  indent(xmlfile, indentLevel, indentWidth)
210  << "<InternalTrigger name=\"" << m_ThresholdName << "\"/>" << endl;
211  } else {
212  indent(xmlfile, indentLevel, indentWidth)
213  << "<TriggerCondition multi=\"" << m_Multiplicity
214  << "\" name=\"" << m_ThresholdName << "_x" << m_Multiplicity
215  << "\" triggerthreshold=\"" << m_ThresholdName << "\"/>" << endl;
216  }
217 
218  } else if (m_NodeType == AND || m_NodeType == OR) {
219 
220  std::string logic = (m_NodeType==AND?"AND":"OR");
221  indent(xmlfile, indentLevel, indentWidth) << "<" << logic << ">" << endl;
222  for(TriggerItemNode *node : children())
223  node->writeXML(xmlfile, indentLevel+1, indentWidth);
224  indent(xmlfile, indentLevel, indentWidth) << "</"<<logic<<">" << endl;
225 
226  } else if (m_NodeType == NOT) {
227 
228  indent(xmlfile, indentLevel, indentWidth) << "<NOT>" << endl;
229  children()[0]->writeXML(xmlfile, indentLevel+1, indentWidth);
230  indent(xmlfile, indentLevel, indentWidth) << "</NOT>" << endl;
231 
232  }
233 }
234 
235 
236 void
237 TrigConf::TriggerItemNode::buildLogic(std::vector<std::string> & conditionList,
238  std::string & logic) const {
239 
240  if (m_NodeType == OBJ) {
241  std::string condition("");
242  if (m_Threshold) {
243  if( m_Threshold->type() != L1DataDef::rndmType() &&
244  m_Threshold->type() != L1DataDef::pclkType() &&
245  m_Threshold->type() != L1DataDef::bgrpType()) {
246  std::string name = m_Threshold->name();
247  name += "_x" + std::to_string(m_Multiplicity);
248  condition += '0' + m_Multiplicity;
249  condition += "," + name;
250  condition += "," + m_Threshold->name();
251  } else {
252  condition = m_Threshold->name();
253  }
254  } else {
255  condition = thresholdName();
256  }
257  uint32_t pos = conditionList.size()+1;
258  if(pos>9) logic += '0'+pos/10;
259  logic += '0'+pos%10;
260  conditionList.push_back(condition);
261  } else if (m_NodeType == AND || m_NodeType == OR) {
262  logic += "(";
263  bool first = true;
264  for(TriggerItemNode *node : children()) {
265  if(!first) { logic += (m_NodeType==AND?"&":"|"); } else { first=false; }
266  node->buildLogic(conditionList, logic);
267  }
268  logic += ")";
269  } else if (m_NodeType == NOT) {
270  logic += "!";
271  children()[0]->buildLogic(conditionList, logic);
272  }
273 
274 }
275 
276 
277 void
278 TrigConf::TriggerItemNode::print(const std::string& indent, unsigned int detail) const {
279  cout << indent << "TriggerItemNode: " << endl;
280  cout << indent << " type : " << (type()==OBJ?"OBJ":(type()==AND?"AND":(type()==OR?"OR":"NOT"))) << endl;
281  cout << indent << " position : " << m_Position << endl;
282 
283  if (m_NodeType == OBJ) {
284  cout << indent << " multiplicity: " << m_Multiplicity << endl;
285  if (m_Threshold) {
286  cout << indent << " threshold : " << m_Threshold->name() << endl;
287  m_Threshold->print(indent + indent, detail);
288  } else if(isInternalTrigger()) {
289  cout << indent << " InternalTrigger: "
290  << thresholdName() << endl;
291  } else {
292  cout << indent << thresholdName() << endl;
293  }
294  }
295  else {
296  for(TriggerItemNode * node : m_Children) {
297  cout << indent << " subnode : " << endl;
298  node->print(indent + indent);
299  }
300  }
301 }
302 
303 std::ostream& TrigConf::TriggerItemNode::indent(std::ostream& o, int lvl, int size) const {
304  if(lvl*size==0) return o;
305  o << std::setw(lvl*size) << " ";
306  return o;
307 }
308 
309 
310 std::ostream &
311 TrigConf::operator<<(std::ostream & o, const TrigConf::TriggerItemNode & node) {
312  o << " TriggerItemNode: " << endl;
313  o << " type : " << (node.type()==TriggerItemNode::OBJ? "OBJ" : (node.type()==TriggerItemNode::AND?"AND":(node.type()==TriggerItemNode::OR?"OR":"NOT"))) << endl;
314  o << " position : " << node.position() << endl;
315 
316  if (node.type() == TriggerItemNode::OBJ) {
317  o << " multiplicity: " << node.multiplicity() << endl;
318  if ( node.triggerThreshold() ) {
319  o << " threshold : " << node.thresholdName() << endl
320  << node.triggerThreshold();
321  } else if( node.isInternalTrigger() ) {
322  o << " InternalTrigger: " << node.thresholdName() << endl;
323  } else {
324  o << node.thresholdName() << endl;
325  }
326  }
327  else {
328  for(TriggerItemNode* subnode: node.children()) {
329  o << " subnodes : " << *subnode << endl;
330  }
331  }
332  return o;
333 }
334 
335 string
337  stringstream s;
338  s << *this;
339  return s.str();
340 }
TrigConf::TriggerItemNode::setInternalTrigger
void setInternalTrigger(L1DataDef::TriggerType x, unsigned int thresholdNumber)
Definition: TriggerItemNode.cxx:87
node::type
void type(TYPE t)
Definition: node.h:49
plotBeamSpotCompare.x1
x1
Definition: plotBeamSpotCompare.py:216
TrigConf::TriggerItemNode::print
void print(const std::string &indent="", unsigned int detail=1) const
Definition: TriggerItemNode.cxx:278
TrigConf::L1DataDef::typeConfig
static TriggerTypeConfig & typeConfig(TriggerType tt)
Definition: L1DataDef.cxx:145
TrigConf::TriggerItemNode::InternalType_t
std::pair< L1DataDef::TriggerType, unsigned int > InternalType_t
Definition: TriggerItemNode.h:32
TrigConf::operator<<
std::ostream & operator<<(std::ostream &os, const TrigConf::IsolationLegacy &iso)
Definition: L1ThresholdBase.cxx:339
TrigConf::TrigConfData::name
const std::string & name() const
Definition: TrigConfData.h:22
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
TrigConf::TriggerItemNode::indent
std::ostream & indent(std::ostream &o, int lvl, int size) const
Definition: TriggerItemNode.cxx:303
TrigConf::L1DataDef::PCLK
@ PCLK
Definition: L1DataDef.h:38
TrigConf::TriggerItemNode::OBJ
@ OBJ
Definition: TriggerItemNode.h:24
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
TrigConf::TriggerItemNode::getAllThresholds
void getAllThresholds(std::vector< const TriggerThreshold * > &) const
Definition: TriggerItemNode.cxx:131
TrigConf::TriggerThreshold::isInternal
bool isInternal() const
Definition: TriggerThreshold.cxx:77
TrigConf::TriggerItemNode::getAllRandomTriggers
void getAllRandomTriggers(std::vector< unsigned int > &) const
Definition: TriggerItemNode.cxx:182
TrigConf::TriggerItemNode::getAllPrescaledClockTriggers
void getAllPrescaledClockTriggers(std::vector< unsigned int > &) const
Definition: TriggerItemNode.cxx:193
TrigConf::TriggerItemNode::setTriggerThreshold
void setTriggerThreshold(TriggerThreshold *thr)
Definition: TriggerItemNode.cxx:74
TrigConf::TriggerItemNode::writeXML
void writeXML(std::ostream &xmlfile, int indentLevel=0, int indentWidth=2, bool omitDelimiter=false) const
Definition: TriggerItemNode.cxx:205
Root::AND
@ AND
Definition: TGRLCollection.h:32
TrigConf::TriggerItemNode::TriggerItemNode
TriggerItemNode(NodeType)
Definition: TriggerItemNode.cxx:22
detail
Definition: extract_histogram_tag.cxx:14
LArG4GenerateShowerLib.condition
condition
Definition: LArG4GenerateShowerLib.py:19
TrigConf::TriggerItemNode::addChild
void addChild(TriggerItemNode *node)
Definition: TriggerItemNode.cxx:114
TrigConf::JetWindowSize::UNDEF
@ UNDEF
Definition: TriggerThresholdValue.h:17
TrigConf::TriggerItemNode::OR
@ OR
Definition: TriggerItemNode.h:24
vec
std::vector< size_t > vec
Definition: CombinationsGeneratorTest.cxx:12
TrigConf::TriggerItemNode
Definition: TriggerItemNode.h:22
TrigConf::TriggerItemNode::getAllFinalNodes
void getAllFinalNodes(std::vector< const TriggerItemNode * > &) const
Definition: TriggerItemNode.cxx:121
TrigConf::L1DataDef::TriggerTypeConfig::name
std::string name
Definition: L1DataDef.h:46
x
#define x
subnode
node * subnode(node *np, const std::string &name)
check whether a subnode with this name already exists
Definition: addnode.cxx:17
python.utils.AtlRunQueryLookup.mask
string mask
Definition: AtlRunQueryLookup.py:460
TrigConf
Forward iterator to traverse the main components of the trigger configuration.
Definition: Config.h:22
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
TrigConf::L1DataDef::stringAsType
static TriggerType stringAsType(const std::string &type)
Definition: L1DataDef.h:62
TrigConf::L1DataDef
Definition: L1DataDef.h:27
TrigConf::TriggerItemNode::~TriggerItemNode
virtual ~TriggerItemNode()
Definition: TriggerItemNode.cxx:32
geometry_dat_to_json.indent
indent
Definition: geometry_dat_to_json.py:18
TrigConf::L1DataDef::RNDM
@ RNDM
Definition: L1DataDef.h:38
xAOD::uint16_t
setWord1 uint16_t
Definition: eFexEMRoI_v1.cxx:88
TrigConf::TriggerItemNode::isInternalTrigger
bool isInternalTrigger() const
Definition: TriggerItemNode.cxx:69
TrigConf::TriggerItemNode::NodeType
NodeType
Definition: TriggerItemNode.h:24
TrigConf::TriggerItemNode::UNDEF
@ UNDEF
Definition: TriggerItemNode.h:24
TrigConf::TriggerItemNode::AND
@ AND
Definition: TriggerItemNode.h:24
TrigConf::TriggerItemNode::getBunchGroupsMask
void getBunchGroupsMask(uint16_t &bgmask) const
Definition: TriggerItemNode.cxx:158
TrigConf::TriggerItemNode::__str__
virtual std::string __str__() const
Definition: TriggerItemNode.cxx:336
TriggerThreshold.h
TrigConf::TriggerItemNode::buildLogic
void buildLogic(std::vector< std::string > &conditionList, std::string &logic) const
Definition: TriggerItemNode.cxx:237
PyPoolBrowser.node
node
Definition: PyPoolBrowser.py:131
TrigConf::name
Definition: HLTChainList.h:35
TrigConf::TriggerItemNode::typeFromChar
static NodeType typeFromChar(const char &c)
Definition: TriggerItemNode.cxx:49
TrigConf::TriggerItemNode::getAllBunchGroups
void getAllBunchGroups(std::vector< bool > &) const
Definition: TriggerItemNode.cxx:144
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
TrigConf::TriggerItemNode::typeAsString
static std::string typeAsString(NodeType)
Definition: TriggerItemNode.cxx:57
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
TrigConf::L1DataDef::UNDEF
@ UNDEF
Definition: L1DataDef.h:39
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
TrigConf::L1DataDef::TriggerTypeConfig::max
unsigned int max
Definition: L1DataDef.h:47
TrigConf::L1DataDef::TriggerType
TriggerType
Definition: L1DataDef.h:30
TrigConf::TriggerItemNode::typeFromString
static NodeType typeFromString(const std::string &)
Definition: TriggerItemNode.cxx:38
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
DeMoScan.first
bool first
Definition: DeMoScan.py:534
Root::OR
@ OR
Definition: TGRLCollection.h:32
python.DecayParser.children
children
Definition: DecayParser.py:32
TrigConf::TriggerItemNode::isThreshold
bool isThreshold() const
Definition: TriggerItemNode.cxx:64
TrigConf::TriggerThreshold
Definition: TriggerThreshold.h:20
TileDCSDataPlotter.tt
tt
Definition: TileDCSDataPlotter.py:874
python.compressB64.c
def c
Definition: compressB64.py:93
node
Definition: memory_hooks-stdcmalloc.h:74
TrigConf::TriggerItemNode::NOT
@ NOT
Definition: TriggerItemNode.h:24
TrigConf::L1DataDef::BGRP
@ BGRP
Definition: L1DataDef.h:38
TriggerItemNode.h