ATLAS Offline Software
Loading...
Searching...
No Matches
Menu.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
9#include <iostream>
10#include <iomanip>
11
12using namespace std;
13using namespace TrigConf;
14
18
20{
21 for (PIT *pit : m_PITs)
22 {
23 delete pit;
24 }
25 for (TIP *tip : m_TIPs)
26 {
27 delete tip;
28 }
30 {
31 delete thrm;
32 }
34 {
35 delete item;
36 }
37}
38
39std::vector<uint16_t>
41 std::vector<uint16_t> bgmask(512);
43 bgmask[item->ctpId()] = item->bunchgroupMask();
44 return bgmask;
45}
46
47
49 // they all work:
50 // pair<item_by_ctpid_iterator, bool> ins = item_by_ctpid().insert(ti);
51 // pair<item_by_name_iterator, bool> ins = item_by_name().insert(ti);
52 pair<ItemContainer::iterator, bool> ins = m_TriggerItemVector.push_back(ti);
53 if(! ins.second) {
54 cerr << "FATAL Menu: insertion of TriggerItem (" << ti->name() << ", ctp ID=" << ti->ctpId() << ") failed, uniqueness constraint violated." << endl;
55 throw runtime_error("Menu insertion of TriggerItem failed");
56 }
57}
58
59
63
65 m_PITs.push_back(pit);
66}
67
68
70 m_TIPs.push_back(tip);
71}
72
73void
74TrigConf::Menu::addLutOutputName(unsigned int lutCounter, const std::string & lutCondition) {
75 if( m_LUT.find(lutCounter) != m_LUT.end()) {
76 cerr << "WARNING Menu: insertion of LUT output (counter " << lutCounter << ", name " << lutCounter << ") failed, uniqueness constraint violated." << endl;
77 return;
78 }
79 m_LUT[lutCounter] = lutCondition;
80}
81
82
84TrigConf::Menu::item(int ctpid) const {
85 const item_by_ctpid_t& byctpid = item_by_ctpid();
86 item_by_ctpid_iterator item = byctpid.find(ctpid);
87 if(item == byctpid.end()) return 0;
88 return *item;
89}
90
92TrigConf::Menu::item(const string& name) const {
93 const item_by_name_t& byname = items().get<tag_name_hash>();
94 item_by_name_iterator item = byname.find(name);
95 if(item == byname.end()) return 0;
96 return *item;
97}
98
102 if( thrm->id()==id ) return thrm;
103 return 0;
104}
105
107TrigConf::Menu::findPIT(unsigned int id) {
108 for(PIT* pit : m_PITs)
109 if( pit->id()==id ) return pit;
110 return 0;
111}
112
114TrigConf::Menu::findTIP(unsigned int id) {
115 for(TIP* tip : m_TIPs)
116 if( tip->id()==id ) return tip;
117 return 0;
118}
119
120
121// another interface to access the TriggerThreshold vector
122const std::vector<TrigConf::TriggerThreshold*>&
124 return m_ThresholdConfig.getThresholdVector();
125}
126
127void
131
132
135 DiffStruct * ds = new DiffStruct("TriggerMenu");
136 ds->check("name", name(), o->name());
137 for(TriggerItem* item : items() ) {
138 TriggerItem* o_item(o->item(item->name()));
139 if(o_item) {
140 ds->addSub( item->compareTo(o_item) );
141 } else {
142 ds->addLeftOnlySub( "TriggerItem", item->name() );
143 }
144 }
145 for(TriggerItem* o_item : o->items()) {
146 const TriggerItem *item = this->item(o_item->name());
147 if(item==0)
148 ds->addRightOnlySub( "TriggerItem", o_item->name() );
149 }
150 if(ds->empty()) {
151 delete ds; ds=0;
152 }
153 return ds;
154}
155
156
157
158
159void
161 m_ThresholdConfig.clear();
162
164 m_TriggerItemVector.clear();
165
166 for( ThresholdMonitor* thrMon : m_ThresholdMonitorVector) delete thrMon;
168
169 for( PIT* pit : m_PITs) delete pit;
170 m_PITs.clear();
171}
172
173
174
175namespace {
176
177 // strict weak ordering: x and y are equivalent if compX(x,y) and compX(y,x) are false
178
179 bool compThr(TriggerThreshold *x, TriggerThreshold *y) {
180 return x->id() < y->id();
181 }
182
183 bool compMon(ThresholdMonitor *x, ThresholdMonitor *y) {
184 if(x->thresholdName() != y->thresholdName() )
185 return x->thresholdName() < y->thresholdName();
186 return x->multiplicity() < y->multiplicity();
187 }
188
189 bool compMonByID(ThresholdMonitor *x, ThresholdMonitor *y) {
190 return x->internalCounter() < y->internalCounter();
191 }
192
193 bool compTIP(TIP *x, TIP *y) {
194 if(x->tipNumber() != y->tipNumber())
195 return x->tipNumber() < y->tipNumber();
196 return x->thresholdBit()<y->thresholdBit();
197 }
198
199 bool compPIT(PIT *x, PIT *y) {
200 if(x->pitNumber() != y->pitNumber())
201 return x->pitNumber() < y->pitNumber();
202 return x->thresholdBit()<y->thresholdBit();
203 }
204
205}
206
207
208
209void
210TrigConf::Menu::print(const std::string& indent, unsigned int detail) const {
211 if(detail>=1) {
212 cout << indent << "Trigger menu "; printNameIdV();
213 cout << indent << " number of pits : " << pitVector().size() << endl;
214 cout << indent << " number of tips : " << tipVector().size() << endl;
215 cout << indent << " number of thresholds : " << m_ThresholdConfig.size() << endl;
216 cout << indent << " number of items : " << m_TriggerItemVector.size() << endl;
217 cout << indent << " number of thr monitors: " << m_ThresholdMonitorVector.size() << endl;
218
219 if(detail>=2) {
220
221 cout << indent << "==================================" << endl;
222 cout << indent << "Trigger Items : " << m_TriggerItemVector.size() << endl;
223 cout << indent << "==================================" << endl;
225 item->print(indent + " ", detail);
226
227 cout << indent << "==================================" << endl;
228 cout << indent << "Trigger Thresholds:" << endl;
229 cout << indent << "==================================" << endl;
230 m_ThresholdConfig.print(indent + " ", detail);
231 }
232
233 if(detail>=3) {
234 cout << indent << "==================================" << endl;
235 cout << indent << " The ThresholdMonitorVector:" << endl;
236 cout << indent << "==================================" << endl;
237 auto sortedMon = m_ThresholdMonitorVector;
238 sort(sortedMon.begin(),sortedMon.end(),compMonByID);
239 for(ThresholdMonitor* thrm : sortedMon)
240 thrm->print(indent + " ", detail);
241 }
242
243 if(detail>=3 && m_PITs.size()>0) {
244 cout << indent << "==================================" << endl;
245 cout << indent << " PITs:" << endl;
246 cout << indent << "==================================" << endl;
247 auto sortedPITs = m_PITs;
248 sort(sortedPITs.begin(),sortedPITs.end(),compPIT);
249 for(PIT* pit : sortedPITs)
250 pit->print(indent + " ");
251 }
252
253 if(detail>=3) {
254 cout << indent << "==================================" << endl;
255 cout << indent << " TIPs:" << endl;
256 cout << indent << "==================================" << endl;
257 auto sortedTIPs = m_TIPs;
258 sort(sortedTIPs.begin(),sortedTIPs.end(),compTIP);
259 for(TIP* tip : sortedTIPs)
260 tip->print(indent + " ");
261 }
262
263 if(detail>=4) {
264 cout << indent << "==================================" << endl;
265 cout << indent << " TriggerType summary:" << endl;
266 cout << indent << "==================================" << endl;
267 for (int i=0; i<8; ++i) {
268 cout << indent << "TriggerType bit " << i << endl;
270 if (item->isTriggerTypeBitOn(i))
271 cout << indent << " " << item->name() << endl;
272 }
273 }
274 if(detail>=4) {
275 cout << indent << "==================================" << endl;
276 cout << indent << " BunchGroup mask summary:" << endl;
277 cout << indent << "==================================" << endl;
278 unsigned int i=0;
279 for ( uint16_t m : bunchgroupMask() )
280 cout << indent << " ctpid=" << setw(3) << i++ << ": bgmask=" << uint2bin(m, 16) << endl;
281 }
282
283 }
284}
285
286
287void
288TrigConf::Menu::writeXMLItems(std::ostream & xmlfile, int indentLevel, int indentWidth) const {
289 indent(xmlfile, indentLevel, indentWidth)
290 << "<TriggerMenu name=\"" << name()
291 << "\" phase=\"lumi\">" << endl;
293 item->writeXML(xmlfile, indentLevel+1, indentWidth);
294 indent(xmlfile, indentLevel, indentWidth) << "</TriggerMenu>" << endl;
295}
296
297
298void
299TrigConf::Menu::writeXMLThresholds(std::ostream & xmlfile, int indentLevel, int indentWidth) const {
300 indent(xmlfile, indentLevel, indentWidth) << "<TriggerThresholdList>" << endl;
301
302 auto sortedThresholds = m_ThresholdConfig.getThresholdVector();
303 sort(sortedThresholds.begin(),sortedThresholds.end(),compThr);
304
305 for(TriggerThreshold* thr: sortedThresholds) {
306 if(!thr->isInternal())
307 thr->writeXML(xmlfile, indentLevel+1, indentWidth);
308 }
309 indent(xmlfile, indentLevel, indentWidth) << "</TriggerThresholdList>" << endl;
310}
311
312void
313TrigConf::Menu::writeXMLMonCounters(std::ostream & xmlfile, int indentLevel, int indentWidth) const {
314 indent(xmlfile, indentLevel, indentWidth) << "<TriggerCounterList>" << endl;
315
316 auto sortedMonitors = m_ThresholdMonitorVector;
317 sort(sortedMonitors.begin(),sortedMonitors.end(),compMon);
318
319 for(const ThresholdMonitor * mon: sortedMonitors)
320 mon->writeXML(xmlfile, indentLevel+1, indentWidth);
321 indent(xmlfile, indentLevel, indentWidth) << "</TriggerCounterList>" << endl;
322}
323
324
325
326// for python
327vector<TriggerItem*>
329 vector<TriggerItem*> it(items().size());
330 copy(items().begin(), items().end(), it.begin());
331 return it;
332}
#define y
#define x
void addTriggerThreshold(TriggerThreshold *tt)
Definition Menu.cxx:128
virtual ~Menu() override
Definition Menu.cxx:19
TriggerItem * item(int ctpid) const
Definition Menu.cxx:84
DiffStruct * compareTo(const Menu *o) const
Definition Menu.cxx:134
void addTriggerItem(TriggerItem *ti)
Definition Menu.cxx:48
const std::vector< TriggerThreshold * > & thresholdVector() const
Definition Menu.cxx:123
std::vector< ThresholdMonitor * > m_ThresholdMonitorVector
Definition Menu.h:118
void addLutOutputName(unsigned int, const std::string &)
Definition Menu.cxx:74
ThresholdConfig m_ThresholdConfig
Definition Menu.h:114
std::vector< TIP * > m_TIPs
Definition Menu.h:120
item_by_ctpid_t & item_by_ctpid()
Definition Menu.h:128
const std::vector< PIT * > & pitVector() const
Definition Menu.h:70
std::vector< TrigConf::TriggerItem * > itemsV() const
Definition Menu.cxx:328
void writeXMLThresholds(std::ostream &xmlfile, int indentLevel=0, int indentWidth=2) const
Definition Menu.cxx:299
void addThresholdMonitor(ThresholdMonitor *thrm)
Definition Menu.cxx:60
void clear()
Definition Menu.cxx:160
void addTip(TIP *tip)
Definition Menu.cxx:69
ThresholdMonitor * findThresholdMonitor(unsigned int id)
Definition Menu.cxx:100
void addPit(PIT *pit)
Definition Menu.cxx:64
int size() const
Definition Menu.h:143
TIP * findTIP(unsigned int id)
Definition Menu.cxx:114
void writeXMLMonCounters(std::ostream &xmlfile, int indentLevel=0, int indentWidth=2) const
Definition Menu.cxx:313
virtual void print(const std::string &indent="", unsigned int detail=1) const override
Definition Menu.cxx:210
std::map< unsigned int, std::string > m_LUT
Definition Menu.h:121
PIT * findPIT(unsigned int id)
Definition Menu.cxx:107
std::vector< uint16_t > bunchgroupMask() const
Definition Menu.cxx:40
std::vector< PIT * > m_PITs
Definition Menu.h:119
void writeXMLItems(std::ostream &xmlfile, int indentLevel=0, int indentWidth=2) const
Definition Menu.cxx:288
const ItemContainer & items() const
Definition Menu.h:140
const std::vector< TIP * > & tipVector() const
Definition Menu.h:71
ItemContainer m_TriggerItemVector
Definition Menu.h:116
std::ostream & indent(std::ostream &o, int lvl, int size) const
const std::string & name() const
void printNameIdV(const std::string &indent="") const
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)
ItemContainer::index< tag_name_hash >::type item_by_name_t
Definition Menu.h:44
ItemContainer::index< tag_name_hash >::type::iterator item_by_name_iterator
Definition Menu.h:45
ItemContainer::index< tag_ctpid >::type item_by_ctpid_t
Definition Menu.h:41
item_by_ctpid_t::iterator item_by_ctpid_iterator
Definition Menu.h:42
STL namespace.
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.