ATLAS Offline Software
Menu.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "TrigConfL1Data/Menu.h"
9 #include <iostream>
10 #include <iomanip>
11 
12 using namespace std;
13 using namespace TrigConf;
14 
16  : L1DataBaseclass()
17 {}
18 
20 {
21  for (PIT *pit : m_PITs)
22  {
23  delete pit;
24  }
25  for (TIP *tip : m_TIPs)
26  {
27  delete tip;
28  }
29  for (ThresholdMonitor *thrm : m_ThresholdMonitorVector)
30  {
31  delete thrm;
32  }
33  for (TriggerItem *item : m_TriggerItemVector)
34  {
35  delete item;
36  }
37 }
38 
39 std::vector<uint16_t>
41  std::vector<uint16_t> bgmask(512);
42  for(TriggerItem * item : item_by_ctpid() )
43  bgmask[item->ctpId()] = item->bunchgroupMask();
44  return bgmask;
45 }
46 
47 #ifndef __COVERITY__
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 #endif
59 
61  m_ThresholdMonitorVector.push_back(thrm);
62 }
63 
65  m_PITs.push_back(pit);
66 }
67 
68 
70  m_TIPs.push_back(tip);
71 }
72 
73 void
74 TrigConf::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 
84 TrigConf::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 
92 TrigConf::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 
101  for(ThresholdMonitor* thrm : m_ThresholdMonitorVector)
102  if( thrm->id()==id ) return thrm;
103  return 0;
104 }
105 
107 TrigConf::Menu::findPIT(unsigned int id) {
108  for(PIT* pit : m_PITs)
109  if( pit->id()==id ) return pit;
110  return 0;
111 }
112 
114 TrigConf::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
122 const std::vector<TrigConf::TriggerThreshold*>&
124  return m_ThresholdConfig.getThresholdVector();
125 }
126 
127 void
129  m_ThresholdConfig.addTriggerThreshold(tt);
130 }
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 #ifndef __COVERITY__
159 void
161  m_ThresholdConfig.clear();
162 
163  for( TriggerItem* item : m_TriggerItemVector) delete item;
164  m_TriggerItemVector.clear();
165 
166  for( ThresholdMonitor* thrMon : m_ThresholdMonitorVector) delete thrMon;
167  m_ThresholdMonitorVector.clear();
168 
169  for( PIT* pit : m_PITs) delete pit;
170  m_PITs.clear();
171 }
172 #endif
173 
174 
175 namespace {
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 
209 #ifndef __COVERITY__
210 void
211 TrigConf::Menu::print(const std::string& indent, unsigned int detail) const {
212  if(detail>=1) {
213  cout << indent << "Trigger menu "; printNameIdV();
214  cout << indent << " number of pits : " << pitVector().size() << endl;
215  cout << indent << " number of tips : " << tipVector().size() << endl;
216  cout << indent << " number of thresholds : " << m_ThresholdConfig.size() << endl;
217  cout << indent << " number of items : " << m_TriggerItemVector.size() << endl;
218  cout << indent << " number of thr monitors: " << m_ThresholdMonitorVector.size() << endl;
219 
220  if(detail>=2) {
221 
222  cout << indent << "==================================" << endl;
223  cout << indent << "Trigger Items : " << m_TriggerItemVector.size() << endl;
224  cout << indent << "==================================" << endl;
225  for(TriggerItem* item : m_TriggerItemVector)
226  item->print(indent + " ", detail);
227 
228  cout << indent << "==================================" << endl;
229  cout << indent << "Trigger Thresholds:" << endl;
230  cout << indent << "==================================" << endl;
231  m_ThresholdConfig.print(indent + " ", detail);
232  }
233 
234  if(detail>=3) {
235  cout << indent << "==================================" << endl;
236  cout << indent << " The ThresholdMonitorVector:" << endl;
237  cout << indent << "==================================" << endl;
238  auto sortedMon = m_ThresholdMonitorVector;
239  sort(sortedMon.begin(),sortedMon.end(),compMonByID);
240  for(ThresholdMonitor* thrm : sortedMon)
241  thrm->print(indent + " ", detail);
242  }
243 
244  if(detail>=3 && m_PITs.size()>0) {
245  cout << indent << "==================================" << endl;
246  cout << indent << " PITs:" << endl;
247  cout << indent << "==================================" << endl;
248  auto sortedPITs = m_PITs;
249  sort(sortedPITs.begin(),sortedPITs.end(),compPIT);
250  for(PIT* pit : sortedPITs)
251  pit->print(indent + " ");
252  }
253 
254  if(detail>=3) {
255  cout << indent << "==================================" << endl;
256  cout << indent << " TIPs:" << endl;
257  cout << indent << "==================================" << endl;
258  auto sortedTIPs = m_TIPs;
259  sort(sortedTIPs.begin(),sortedTIPs.end(),compTIP);
260  for(TIP* tip : sortedTIPs)
261  tip->print(indent + " ");
262  }
263 
264  if(detail>=4) {
265  cout << indent << "==================================" << endl;
266  cout << indent << " TriggerType summary:" << endl;
267  cout << indent << "==================================" << endl;
268  for (int i=0; i<8; ++i) {
269  cout << indent << "TriggerType bit " << i << endl;
270  for(TriggerItem* item : m_TriggerItemVector)
271  if (item->isTriggerTypeBitOn(i))
272  cout << indent << " " << item->name() << endl;
273  }
274  }
275  if(detail>=4) {
276  cout << indent << "==================================" << endl;
277  cout << indent << " BunchGroup mask summary:" << endl;
278  cout << indent << "==================================" << endl;
279  unsigned int i=0;
280  for ( uint16_t m : bunchgroupMask() )
281  cout << indent << " ctpid=" << setw(3) << i++ << ": bgmask=" << uint2bin(m, 16) << endl;
282  }
283 
284  }
285 }
286 
287 
288 void
289 TrigConf::Menu::writeXMLItems(std::ostream & xmlfile, int indentLevel, int indentWidth) const {
290  indent(xmlfile, indentLevel, indentWidth)
291  << "<TriggerMenu name=\"" << name()
292  << "\" phase=\"lumi\">" << endl;
293  for(TriggerItem* item: m_TriggerItemVector)
294  item->writeXML(xmlfile, indentLevel+1, indentWidth);
295  indent(xmlfile, indentLevel, indentWidth) << "</TriggerMenu>" << endl;
296 }
297 #endif
298 
299 
300 void
301 TrigConf::Menu::writeXMLThresholds(std::ostream & xmlfile, int indentLevel, int indentWidth) const {
302  indent(xmlfile, indentLevel, indentWidth) << "<TriggerThresholdList>" << endl;
303 
304  auto sortedThresholds = m_ThresholdConfig.getThresholdVector();
305  sort(sortedThresholds.begin(),sortedThresholds.end(),compThr);
306 
307  for(TriggerThreshold* thr: sortedThresholds) {
308  if(!thr->isInternal())
309  thr->writeXML(xmlfile, indentLevel+1, indentWidth);
310  }
311  indent(xmlfile, indentLevel, indentWidth) << "</TriggerThresholdList>" << endl;
312 }
313 
314 void
315 TrigConf::Menu::writeXMLMonCounters(std::ostream & xmlfile, int indentLevel, int indentWidth) const {
316  indent(xmlfile, indentLevel, indentWidth) << "<TriggerCounterList>" << endl;
317 
318  auto sortedMonitors = m_ThresholdMonitorVector;
319  sort(sortedMonitors.begin(),sortedMonitors.end(),compMon);
320 
321  for(const ThresholdMonitor * mon: sortedMonitors)
322  mon->writeXML(xmlfile, indentLevel+1, indentWidth);
323  indent(xmlfile, indentLevel, indentWidth) << "</TriggerCounterList>" << endl;
324 }
325 
326 
327 
328 // for python
329 vector<TriggerItem*>
330 Menu::itemsV() const {
331  vector<TriggerItem*> it(items().size());
332  copy(items().begin(), items().end(), it.begin());
333  return it;
334 }
TriggerItem.h
checkxAOD.ds
ds
Definition: Tools/PyUtils/bin/checkxAOD.py:260
TrigConf::TriggerItem::ctpId
int ctpId() const
Definition: TriggerItem.h:34
TrigConf::Menu::addPit
void addPit(PIT *pit)
Definition: Menu.cxx:64
TrigConf::TrigConfData::name
const std::string & name() const
Definition: TrigConfData.h:22
TrigConf::PIT
Definition: PIT.h:13
python.SystemOfUnits.m
int m
Definition: SystemOfUnits.py:91
TrigConf::item_by_name_t
ItemContainer::index< tag_name_hash >::type item_by_name_t
Definition: Menu.h:44
TrigConf::Menu::bunchgroupMask
std::vector< uint16_t > bunchgroupMask() const
Definition: Menu.cxx:40
TrigConf::Menu::findThresholdMonitor
ThresholdMonitor * findThresholdMonitor(unsigned int id)
Definition: Menu.cxx:100
TrigConf::Menu::print
virtual void print(const std::string &indent="", unsigned int detail=1) const override
Definition: Menu.cxx:211
TrigConf::TIP
Definition: TIP.h:13
TrigConf::DiffStruct
Definition: DiffStruct.h:14
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
TrigConf::Menu::writeXMLThresholds
void writeXMLThresholds(std::ostream &xmlfile, int indentLevel=0, int indentWidth=2) const
Definition: Menu.cxx:301
skel.it
it
Definition: skel.GENtoEVGEN.py:396
detail
Definition: extract_histogram_tag.cxx:14
Menu.h
TrigConf::Menu::item
TriggerItem * item(int ctpid) const
Definition: Menu.cxx:84
TrigConf::item_by_ctpid_t
ItemContainer::index< tag_ctpid >::type item_by_ctpid_t
Definition: Menu.h:41
TrigConf::Menu::thresholdVector
const std::vector< TriggerThreshold * > & thresholdVector() const
Definition: Menu.cxx:123
DiffStruct.h
x
#define x
std::sort
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
Definition: DVL_algorithms.h:554
HelperFunctions.h
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
TrigConf::ThresholdMonitor
Definition: ThresholdMonitor.h:18
TrigConf
Forward iterator to traverse the main components of the trigger configuration.
Definition: Config.h:22
PyPoolBrowser.item
item
Definition: PyPoolBrowser.py:129
TrigConf::Menu
Definition: Menu.h:49
TrigConf::Menu::clear
void clear()
Definition: Menu.cxx:160
geometry_dat_to_json.indent
indent
Definition: geometry_dat_to_json.py:36
xAOD::uint16_t
setWord1 uint16_t
Definition: eFexEMRoI_v1.cxx:93
lumiFormat.i
int i
Definition: lumiFormat.py:85
TrigConf::Menu::findPIT
PIT * findPIT(unsigned int id)
Definition: Menu.cxx:107
TrigConf::Menu::itemsV
std::vector< TrigConf::TriggerItem * > itemsV() const
Definition: Menu.cxx:330
TrigConf::Menu::compareTo
DiffStruct * compareTo(const Menu *o) const
Definition: Menu.cxx:134
TrigConf::Menu::addLutOutputName
void addLutOutputName(unsigned int, const std::string &)
Definition: Menu.cxx:74
TrigConf::uint2bin
std::string uint2bin(uint32_t uinteger, uint16_t width)
Definition: Trigger/TrigConfiguration/TrigConfL1Data/Root/HelperFunctions.cxx:332
TrigConf::Menu::addTriggerThreshold
void addTriggerThreshold(TriggerThreshold *tt)
Definition: Menu.cxx:128
TrigConf::name
Definition: HLTChainList.h:35
TrigConf::Menu::addTip
void addTip(TIP *tip)
Definition: Menu.cxx:69
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
TrigConf::item_by_ctpid_iterator
item_by_ctpid_t::iterator item_by_ctpid_iterator
Definition: Menu.h:42
TrigJetMonitorAlgorithm.items
items
Definition: TrigJetMonitorAlgorithm.py:79
item
Definition: ItemListSvc.h:43
TrigConf::Menu::addThresholdMonitor
void addThresholdMonitor(ThresholdMonitor *thrm)
Definition: Menu.cxx:60
y
#define y
TrigConf::item_by_name_iterator
ItemContainer::index< tag_name_hash >::type::iterator item_by_name_iterator
Definition: Menu.h:45
TrigConf::Menu::items
const ItemContainer & items() const
Definition: Menu.h:140
plotBeamSpotMon.mon
mon
Definition: plotBeamSpotMon.py:67
TrigConf::Menu::writeXMLMonCounters
void writeXMLMonCounters(std::ostream &xmlfile, int indentLevel=0, int indentWidth=2) const
Definition: Menu.cxx:315
TrigConf::L1DataBaseclass
Definition: L1DataBaseclass.h:22
TrigConf::tag_name_hash
Definition: Menu.h:31
TrigConf::Menu::findTIP
TIP * findTIP(unsigned int id)
Definition: Menu.cxx:114
TrigConf::Menu::~Menu
virtual ~Menu() override
Definition: Menu.cxx:19
TrigConf::Menu::addTriggerItem
void addTriggerItem(TriggerItem *ti)
Definition: Menu.cxx:48
calibdata.copy
bool copy
Definition: calibdata.py:27
TrigConf::Menu::Menu
Menu()
Definition: Menu.cxx:15
TrigConf::Menu::writeXMLItems
void writeXMLItems(std::ostream &xmlfile, int indentLevel=0, int indentWidth=2) const
Definition: Menu.cxx:289
TrigConf::Menu::size
int size() const
Definition: Menu.h:143
TrigConf::TriggerThreshold
Definition: TriggerThreshold.h:20
TileDCSDataPlotter.tt
tt
Definition: TileDCSDataPlotter.py:874
TrigConf::TriggerItem
Definition: TriggerItem.h:25