ATLAS Offline Software
Loading...
Searching...
No Matches
TriggerItem.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3*/
4
9
10#include <iostream>
11#include <iomanip>
12#include <stdexcept>
13#include <algorithm>
14
15using namespace std;
16using namespace TrigConf;
17
20 m_Definition( "" ),
21 m_TopNode( nullptr ),
22 m_CtpId( -1 ),
23 m_TriggerType( 0 ),
24 m_Partition( 0 ),
25 m_Monitor( 0 )
26{}
27
31
32
33uint16_t
35 uint16_t bgmask(0);
36 if( m_TopNode ) {
37 m_TopNode->getBunchGroupsMask(bgmask);
38 }
39 return bgmask;
40}
41
42
45 DiffStruct * ds = new DiffStruct("TriggerItem");
46 ds->check("ctpid", ctpId(), o->ctpId());
47 ds->check("definition", definition(), o->definition());
48 ds->check("complex_deadtime", complex_deadtime(), o->complex_deadtime());
49 ds->check("triggertype", triggerType(), o->triggerType());
50 if(!ds->empty()) {
51 ds->name = name();
52 } else {
53 delete ds; ds=0;
54 }
55 return ds;
56}
57
58
59void
60TriggerItem::writeXML(std::ostream & xmlfile, int indentLevel, int indentWidth) const {
61
62
63
64
65 string final_def = m_Definition;
66 bool end=false;
67 string::size_type index=0;
68 while(!end){
69 std::string::size_type pos=final_def.find('&',index);
70 if(pos!= std::string::npos){
71 end=false;
72 index = pos+1;
73 //do the replace
74 final_def.replace(pos, 1, "&amp;");
75 }else{
76 end=true;
77 index=0;
78 }
79 }
80
81 indent(xmlfile, indentLevel, indentWidth)
82 << "<TriggerItem ctpid=\"" << m_CtpId
83 << "\" partition=\"" << partition()
84 << "\" name=\"" << name()
85 << "\" complex_deadtime=\"" << complex_deadtime()
86 << "\" definition=\"" << final_def
87 << "\" trigger_type=\"" << TrigConf::uint2bin(m_TriggerType, partition()==1 ? 8 : 4) << "\"";
88 if(monitor()!=0) {
89 string s("LF:");
90 s += (monitor() & 0x04 ? '1' : '0');
91 s += (monitor() & 0x02 ? '1' : '0');
92 s += (monitor() & 0x01 ? '1' : '0');
93 s += "|HF:";
94 s += (monitor() & 0x20 ? '1' : '0');
95 s += (monitor() & 0x10 ? '1' : '0');
96 s += (monitor() & 0x08 ? '1' : '0');
97 xmlfile << " monitor=\"" << s << "\"";
98 }
99 xmlfile << ">" << endl;
100
101 if (m_TopNode)
102 m_TopNode->writeXML(xmlfile, indentLevel+1, indentWidth);
103
104 indent(xmlfile, indentLevel, indentWidth) << "</TriggerItem>" << endl;
105}
106
107
108void
109TriggerItem::buildLogic(std::string & logic, std::vector<std::string> & conditionList) const {
110 if (m_TopNode)
111 m_TopNode->buildLogic(conditionList, logic);
112}
113
114
115void
116TriggerItem::setCondition(const string& logic,
117 const vector<string>& conditions,
118 const vector<TriggerThreshold*>& thrs) {
119 // logic is a string like "!(1|2)&(3|4)"
120 // vector of conditions of length equal the largest number in logic string (e.g 4)
121 // a condition can be either a single name for internal triggers or a komma separated list of multiplicity, conditions name and threshold name
122 // thrs is a list of thresholds
123
124 m_Definition = "("+logic+")";
125
126 try {
127 m_TopNode = TrigConf::parse(logic, conditions, thrs);
128 }
129 catch(const exception& e) {
130 cout << "WARNING: Could not set condition of triggeritem " << name() << " because: " << e.what() << endl;
131 }
132}
133
134
135void
136TriggerItem::print(const std::string& indent, unsigned int detail) const {
137 if(detail<3) {
138 cout << indent << "TriggerItem ctpid = " << m_CtpId << " ";
139 printNameIdV();
140 } else {
141 cout << indent << "==================================" << endl;
142 cout << indent << "TriggerItem:";
144 cout << indent << "Complex Deadtime: " << m_ComplexDeadtime << endl;
145 cout << indent << "Definition: " << m_Definition << endl;
146 cout << indent << "CTP_id : " << m_CtpId << endl;
147 cout << indent << "TriggerType(hex): 0x" << std::hex << m_TriggerType << std::dec << endl;
148 cout << indent << "Bunchgroup mask : " << uint2bin(bunchgroupMask(), 16) << endl;
149 cout << indent << "Monitor : " << monitor() << endl;
150 if(detail>=4) {
151 if (m_TopNode) m_TopNode->print(indent,detail);
152 else cout << indent << "TopNode is NULL pointer" << endl;
153 }
154 }
155}
156
157
158std::ostream &
159TrigConf::operator<<(std::ostream & o, const TrigConf::TriggerItem & item) {
160 o << "TriggerItem: " << (const TrigConfData&)item;
161 o << " Complex Deadtime: " << item.m_ComplexDeadtime << endl;
162 o << " Definition: " << item.m_Definition << endl;
163 o << " CTP_id: " << item.m_CtpId << endl;
164 o << " TriggerType(hex): " << hex << item.m_TriggerType << dec << endl;
165 if (item.topNode()) o << *item.topNode();
166 else o << " No TopNode" << endl;
167 return o;
168}
169
170
171string
173 stringstream s;
174 s << *this;
175 return s.str();
176}
std::ostream & indent(std::ostream &o, int lvl, int size) const
const std::string & name() const
void printNameIdV(const std::string &indent="") const
TrigConfData(const std::string &name="")
std::string m_Definition
Definition TriggerItem.h:70
unsigned short m_Monitor
Definition TriggerItem.h:75
unsigned int complex_deadtime() const
Definition TriggerItem.h:31
virtual void print(const std::string &indent="", unsigned int detail=1) const override
void buildLogic(std::string &logic, std::vector< std::string > &conditionList) const
DiffStruct * compareTo(const TriggerItem *o) const
unsigned int m_ComplexDeadtime
Definition TriggerItem.h:69
uint16_t bunchgroupMask() const
std::string __str__() const override
void writeXML(std::ostream &xmlfile, int indentLevel=0, int indentWidth=2) const
const std::string & definition() const
Definition TriggerItem.h:32
unsigned int m_TriggerType
Definition TriggerItem.h:73
void setCondition(const std::string &logic, const std::vector< std::string > &conditions, const std::vector< TrigConf::TriggerThreshold * > &thrs)
unsigned int partition() const
Definition TriggerItem.h:35
unsigned short monitor() const
Definition TriggerItem.h:37
unsigned int m_Partition
Definition TriggerItem.h:74
virtual ~TriggerItem() override
unsigned int triggerType() const
Definition TriggerItem.h:33
TriggerItemNode * m_TopNode
Definition TriggerItem.h:71
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::string uint2bin(uint32_t uinteger, uint16_t width)
std::ostream & operator<<(std::ostream &os, const TrigConf::IsolationLegacy &iso)
std::vector< std::string > parse(std::string names)
Definition index.py:1
STL namespace.