ATLAS Offline Software
HLTChainLoader.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "./HLTChainLoader.h"
6 
13 
14 #include <charconv>
15 #include <string_view>
16 
17 #include "./DBHelper.h"
18 
19 using namespace std;
20 
21 bool
23  m_smk=frame.smk();
24 
25  m_schemaversion = triggerDBSchemaVersion();
26  TRG_MSG_INFO("Loading HLT chains");
27 
29 
30  try {
31  startSession ();
32  loadChains( chains );
33  loadGroups( chains );
34  loadTypes( chains );
35  loadStreams( chains );
36  loadSignatures( chains );
37  commitSession();
38  }
39  catch( const coral::Exception& e ) {
40  TRG_MSG_ERROR("Coral::Exception: " << e.what());
41  m_session.transaction().rollback();
42  throw;
43  }
44 
45  chains.setEFLowerChainCounter();
46 
47  return true;
48 }
49 
50 
51 void
53 
54  TRG_MSG_INFO("Loading chains with SMK " << m_smk);
55 
56  std::unique_ptr< coral::IQuery > q( m_session.nominalSchema().newQuery() );
57 
58  //Set the tables that are used
59  q->addToTableList ( "SUPER_MASTER_TABLE", "SM" );
60  q->addToTableList ( "HLT_MASTER_TABLE", "HM" );
61  q->addToTableList ( "HLT_TRIGGER_MENU", "TM" );
62  q->addToTableList ( "HLT_TM_TO_TC", "TM2TC" );
63  q->addToTableList ( "HLT_TRIGGER_CHAIN", "TC" );
64 
65  //Bind list
66  coral::AttributeList bindList;
67  bindList.extend<int>("smid");
68  bindList[0].data<int>() = (int)m_smk;
69 
70  string theCondition = "";
71  theCondition += string( " SM.SMT_ID = :smid");
72  theCondition += string( " AND HM.HMT_ID = SM.SMT_HLT_MASTER_TABLE_ID" );
73  theCondition += string( " AND TM.HTM_ID = HM.HMT_TRIGGER_MENU_ID" );
74  theCondition += string( " AND TM.HTM_ID = TM2TC.HTM2TC_TRIGGER_MENU_ID " );
75  theCondition += string( " AND TC.HTC_ID = TM2TC.HTM2TC_TRIGGER_CHAIN_ID" );
76 
77  q->setCondition( theCondition, bindList );
78 
79  //Output data and types
80  coral::AttributeList attList;
81  attList.extend<long> ( "TC.HTC_ID" );
82  attList.extend<string>( "TC.HTC_NAME" );
83  attList.extend<string>( "TC.HTC_LOWER_CHAIN_NAME" );
84  if(isRun1()) {
85  attList.extend<string>( "TC.HTC_L2_OR_EF" );
86  attList.extend<string>( "TC.HTC_RERUN_PRESCALE" );
87  }
88  attList.extend<int> ( "TC.HTC_CHAIN_COUNTER" );
89  attList.extend<int> ( "TC.HTC_VERSION" );
90  fillQuery(q.get(),attList);
91 
92  // the ordering
93  string theOrder = "";
94  if(isRun1()) {
95  theOrder += " TC.HTC_L2_OR_EF DESC, ";
96  }
97  theOrder += " TC.HTC_CHAIN_COUNTER ASC";
98  q->addToOrderList( theOrder );
99 
100  // process the query
101  q->setDistinct();
102  coral::ICursor& cursor = q->execute();
103 
104  while ( cursor.next() ) {
105  const coral::AttributeList& row = cursor.currentRow();
106 
107  long chainId = row["TC.HTC_ID"].data<long>();
108  int counter = row["TC.HTC_CHAIN_COUNTER"].data<int>();
109  int version = row["TC.HTC_VERSION"].data<int>();
110  string name = rmtilde(row["TC.HTC_NAME"].data<string>());
111  string lower_chain_name = rmtilde(row["TC.HTC_LOWER_CHAIN_NAME"].data<string>());
112 
113  // level
114  string level = "HLT";
115  if(isRun1()) {
116  level = rmtilde(row["TC.HTC_L2_OR_EF"].data<string>());
117  if(level=="HL") level="HLT";
118  }
119 
120  HLTChain* ch = new HLTChain( name, counter, version, level, lower_chain_name, 0, std::vector<HLTSignature*>() );
121 
122  // rerun ps from the chain table only in run 1
123  if(isRun1()) {
124  float rerunps = 0;
125  string rerunps_s = rmtilde(row["TC.HTC_RERUN_PRESCALE"].data<string>());
126  std::string_view rerunps_sv = rerunps_s;
127  auto [ptr, ec] = std::from_chars(rerunps_sv.data(), rerunps_sv.data() + rerunps_sv.size(), rerunps, std::chars_format::general);
128  if (ec != std::errc()) {
129  rerunps = 0; // fallback or handle error
130  }
131  if(rerunps>=0)
132  ch->set_rerun_prescale(rerunps);
133  }
134 
135  ch->setId(chainId);
136  chainlist.addHLTChain(ch);
137  }
138  cursor.close();
139 
140  TRG_MSG_INFO("Loaded " << chainlist.size() << " chains");
141 
142 }
143 
144 
145 namespace {
146  void
147  defineChainSubQuery( coral::IQuery* q, std::string& theCondition, coral::AttributeList& bindings, int smk, coral::AttributeList& output) {
148 
149  q->addToTableList ( "SUPER_MASTER_TABLE", "SM" );
150  q->addToTableList ( "HLT_MASTER_TABLE", "HM" );
151  q->addToTableList ( "HLT_TM_TO_TC", "TM2TC" );
152  q->addToTableList ( "HLT_TRIGGER_CHAIN", "TC" );
153 
154  theCondition += string( " SM.SMT_ID = :smid" );
155  theCondition += string( " AND SM.SMT_HLT_MASTER_TABLE_ID = HM.HMT_ID" );
156  theCondition += string( " AND HM.HMT_TRIGGER_MENU_ID = TM2TC.HTM2TC_TRIGGER_MENU_ID " );
157  theCondition += string( " AND TC.HTC_ID = TM2TC.HTM2TC_TRIGGER_CHAIN_ID" );
158 
159  bindings.extend<int>("smid");
160  bindings[0].data<int>() = smk;
161 
162  output.extend<string>( "TC.HTC_NAME" );
163  }
164 }
165 
166 
167 
168 void
170 
171  std::unique_ptr< coral::IQuery > q( m_session.nominalSchema().newQuery() );
172  string theCondition("");
173  coral::AttributeList bindings, output;
174 
175  defineChainSubQuery( q.get(), theCondition, bindings, m_smk, output);
176 
177  q->addToTableList ( "HLT_TRIGGER_GROUP", "GR" );
178 
179  theCondition += string( " AND GR.HTG_TRIGGER_CHAIN_ID = TM2TC.HTM2TC_TRIGGER_CHAIN_ID" );
180 
181  q->setCondition( theCondition, bindings );
182 
183  output.extend<string>( "GR.HTG_NAME" );
184 
185  fillQuery(q.get(), output);
186 
187  q->setDistinct();
188  coral::ICursor& cursor = q->execute();
189 
190  uint count(0);
191  while ( cursor.next() ) {
192  ++count;
193  const coral::AttributeList& row = cursor.currentRow();
194  string name = rmtilde(row["TC.HTC_NAME"].data<string>());
195  string grname = rmtilde(row["GR.HTG_NAME"].data<string>());
196  chainlist.chain(name)->addGroup(grname);
197  }
198  cursor.close();
199 
200  TRG_MSG_INFO("Loaded " << count << " groups");
201 
202 }
203 
204 
205 
206 
207 void
209 
210  std::unique_ptr< coral::IQuery > q( m_session.nominalSchema().newQuery() );
211  string theCondition("");
212  coral::AttributeList bindings, output;
213 
214  defineChainSubQuery( q.get(), theCondition, bindings, m_smk, output);
215 
216  q->addToTableList ( "HLT_TRIGGER_TYPE", "TT" );
217 
218  theCondition += string( " AND TT.HTT_TRIGGER_CHAIN_ID = TM2TC.HTM2TC_TRIGGER_CHAIN_ID" );
219 
220  q->setCondition( theCondition, bindings );
221 
222  output.extend<int>( "TT.HTT_TYPEBIT" );
223 
224  fillQuery(q.get(), output);
225 
226  q->setDistinct();
227  coral::ICursor& cursor = q->execute();
228 
229  uint count(0);
230  while ( cursor.next() ) {
231  ++count;
232  const coral::AttributeList& row = cursor.currentRow();
233  string name = rmtilde(row["TC.HTC_NAME"].data<string>());
234  int triggertype = row["TT.HTT_TYPEBIT"].data<int>();
235  chainlist.chain(name)->triggerTypeList().push_back(new HLTTriggerType(triggertype));
236  }
237  cursor.close();
238 
239  TRG_MSG_INFO("Loaded " << count << " trigger types");
240 }
241 
242 
243 void
245 
246  std::unique_ptr< coral::IQuery > q( m_session.nominalSchema().newQuery() );
247  string theCondition("");
248  coral::AttributeList bindings, output;
249 
250  defineChainSubQuery( q.get(), theCondition, bindings, m_smk, output);
251 
252  q->addToTableList ( "HLT_TC_TO_TR", "TC2TR" );
253  q->addToTableList ( "HLT_TRIGGER_STREAM", "TR" );
254 
255  theCondition += string( " AND TC2TR.HTC2TR_TRIGGER_CHAIN_ID = TC.HTC_ID" );
256  theCondition += string( " AND TC2TR.HTC2TR_TRIGGER_STREAM_ID = TR.HTR_ID" );
257 
258  output.extend<string>( "TC2TR.HTC2TR_TRIGGER_STREAM_PRESCALE");
259  output.extend<string>( "TR.HTR_NAME" );
260  output.extend<string>( "TR.HTR_TYPE" );
261  output.extend<int>( "TR.HTR_OBEYLB" );
262 
263  fillQuery(q.get(), output);
264 
265  q->setCondition( theCondition, bindings );
266 
267  q->setDistinct();
268  coral::ICursor& cursor = q->execute();
269 
270  uint count(0);
271  while ( cursor.next() ) {
272  ++count;
273  const coral::AttributeList& row = cursor.currentRow();
274  string chainname = rmtilde(row["TC.HTC_NAME"].data<string>());
275  string prescale_str = rmtilde(row["TC2TR.HTC2TR_TRIGGER_STREAM_PRESCALE"].data<string>());
276  string streamname = rmtilde(row["TR.HTR_NAME"].data<string>());
277  string type = rmtilde(row["TR.HTR_TYPE"].data<string>());
278  bool obeyLB = row["TR.HTR_OBEYLB"].data<int>();
279  int prescale = 1;
280  std::string_view prescale_str_view = prescale_str;
281  auto [ptr, ec] = std::from_chars(prescale_str_view.data(), prescale_str_view.data() + prescale_str_view.size(), prescale);
282  if (ec != std::errc()) {
283  prescale = 1;
284  }
285  chainlist.chain(chainname)->addStream( new HLTStreamTag(streamname, type, obeyLB, prescale) );
286  }
287  cursor.close();
288 
289  TRG_MSG_INFO("Loaded " << count << " streams");
290 }
291 
292 
293 void
295 
296  std::unique_ptr< coral::IQuery > q( m_session.nominalSchema().newQuery() );
297  string theCondition("");
298  coral::AttributeList bindings, output;
299 
300  defineChainSubQuery( q.get(), theCondition, bindings, m_smk, output);
301 
302  q->addToTableList ( "HLT_TC_TO_TS", "TC2TS" );
303  q->addToTableList ( "HLT_TRIGGER_SIGNATURE", "TS" );
304  q->addToTableList ( "HLT_TS_TO_TE", "TS2TE" );
305  q->addToTableList ( "HLT_TRIGGER_ELEMENT", "TE" );
306 
307 
308  theCondition += string( " AND TC2TS.HTC2TS_TRIGGER_CHAIN_ID = TC.HTC_ID" );
309  theCondition += string( " AND TC2TS.HTC2TS_TRIGGER_SIGNATURE_ID = TS.HTS_ID" );
310  theCondition += string( " AND TC2TS.HTC2TS_TRIGGER_SIGNATURE_ID = TS2TE.HTS2TE_TRIGGER_SIGNATURE_ID" );
311  theCondition += string( " AND TE.HTE_ID = TS2TE.HTS2TE_TRIGGER_ELEMENT_ID" );
312  theCondition += string( " AND TS2TE.HTS2TE_ELEMENT_COUNTER>=0" ); // counter<0 are for TE's that are only input TEs for a menu
313 
314  output.extend<int>( "TC2TS.HTC2TS_SIGNATURE_COUNTER" );
315  output.extend<int>( "TS2TE.HTS2TE_ELEMENT_COUNTER" );
316  output.extend<int>( "TS.HTS_LOGIC" );
317  output.extend<int>( "TE.HTE_ID" );
318  output.extend<string>( "TE.HTE_NAME" );
319  fillQuery(q.get(), output);
320 
321  q->setCondition( theCondition, bindings );
322 
323  q->setDistinct();
324 
325  q->addToOrderList( "TC.HTC_NAME" );
326  q->addToOrderList( "TC2TS.HTC2TS_SIGNATURE_COUNTER" );
327  q->addToOrderList( "TS2TE.HTS2TE_ELEMENT_COUNTER" );
328 
329  coral::ICursor& cursor = q->execute();
330 
331  uint count(0);
332  while ( cursor.next() ) {
333  ++count;
334 
335  const coral::AttributeList& row = cursor.currentRow();
336 
337  string chainname = rmtilde(row["TC.HTC_NAME"].data<string>());
338  vector<HLTSignature*>& sig_list = chainlist.chain(chainname)->signatureList();
339 
340  unsigned int sig_counter = (unsigned int)row["TC2TS.HTC2TS_SIGNATURE_COUNTER"].data<int>();
341  if( sig_list.size() < sig_counter+1 )
342  sig_list.resize( sig_counter+1, 0 );
343 
344  if( sig_list[sig_counter] == 0) {
345  int logic = row["TS.HTS_LOGIC"].data<int>();
346  sig_list[sig_counter] = new HLTSignature(sig_counter, logic, std::vector<HLTTriggerElement*>());
347  sig_list[sig_counter]->set_label( chainname + "_" + std::to_string(sig_counter) );
348  }
349 
350  HLTSignature* sig = sig_list[sig_counter];
351  vector<HLTTriggerElement*>& te_list = sig->outputTEs();
352 
353  unsigned int te_counter = (unsigned int)row["TS2TE.HTS2TE_ELEMENT_COUNTER"].data<int>();
354  if( te_list.size() < te_counter+1 )
355  te_list.resize( te_counter+1, 0 );
356 
357  if( te_list[te_counter] == 0) {
358  int te_id = row["TE.HTE_ID"].data<int>();
359  string te_name = row["TE.HTE_NAME"].data<string>();
360  te_list[te_counter] = new HLTTriggerElement(te_id, te_name);
361  }
362 
363  }
364  cursor.close();
365 
366  TRG_MSG_INFO("Loaded " << count << " signatures");
367 
368  // remove 0 pointers from signature list of each chain to keep old
369  // behavior, would be nicer if 0's were kept and step could be
370  // accessed by index (to be seen)
371  for(HLTChain* ch : chainlist) {
372  vector<HLTSignature*>& s = ch->signatureList();
373  s.erase(remove(s.begin(), s.end(), (HLTSignature*)0), s.end());
374  }
375 
376 }
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
TRG_MSG_ERROR
#define TRG_MSG_ERROR(x)
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStreamMacros.h:29
sendEI_SPB.ch
ch
Definition: sendEI_SPB.py:35
HLTChainList.h
TrigConf::HLTChainLoader::loadStreams
void loadStreams(HLTChainList &chainlist)
Definition: HLTChainLoader.cxx:244
TrigConf::HLTChainLoader::loadChains
void loadChains(HLTChainList &chainlist)
Definition: HLTChainLoader.cxx:52
RunEBWeightsComputation.smk
smk
Definition: RunEBWeightsComputation.py:87
TrigConf::HLTChain::triggerTypeList
std::vector< HLTTriggerType * > & triggerTypeList()
Definition: TrigConfHLTData/TrigConfHLTData/HLTChain.h:89
TrigConf::HLTChain::addGroup
void addGroup(const std::string &group)
Definition: TrigConfHLTData/TrigConfHLTData/HLTChain.h:131
DBHelper.h
TrigConf::fillQuery
void fillQuery(coral::IQuery *q, coral::AttributeList &attList)
Definition: DBHelper.cxx:13
keylayer_zslicemap.row
row
Definition: keylayer_zslicemap.py:155
TrigConf::HLTChain::addStream
void addStream(HLTStreamTag *)
Definition: TrigConfHLTData/Root/HLTChain.cxx:238
python.PyKernel.AttributeList
AttributeList
Definition: PyKernel.py:36
dbg::ptr
void * ptr(T *p)
Definition: SGImplSvc.cxx:74
TrigConf::HLTChain
HLT chain configuration information.
Definition: TrigConfHLTData/TrigConfHLTData/HLTChain.h:35
TrigConf::HLTChain::signatureList
std::vector< HLTSignature * > & signatureList()
Definition: TrigConfHLTData/TrigConfHLTData/HLTChain.h:108
trigbs_dumpPrescaleBits.HLTChain
HLTChain
Definition: trigbs_dumpPrescaleBits.py:41
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
XMLtoHeader.count
count
Definition: XMLtoHeader.py:84
python.iconfTool.models.loaders.level
level
Definition: loaders.py:20
PixelModuleFeMask_create_db.remove
string remove
Definition: PixelModuleFeMask_create_db.py:83
uint
unsigned int uint
Definition: LArOFPhaseFill.cxx:20
checkCorrelInHIST.cursor
cursor
Definition: checkCorrelInHIST.py:26
TrigConf::HLTSignature
HLT signature configuration information.
Definition: HLTSignature.h:29
TrigConf::HLTChainList
list of all HLT chains in a trigger menu
Definition: HLTChainList.h:56
HLTStreamTag.h
TrigConf::HLTTriggerType
HLT trigger type configuration information.
Definition: HLTTriggerType.h:22
TrigConf::HLTChainList::chain
HLTChain * chain(const std::string &chainname) const
access the chain by name returns null-pointer if chain not found
Definition: HLTChainList.cxx:52
HLTSignature.h
python.BuildSignatureFlags.sig
sig
Definition: BuildSignatureFlags.py:221
TrigConf::HLTChainList::addHLTChain
bool addHLTChain(HLTChain *ch)
adds an HLTChain to the menu
Definition: HLTChainList.cxx:42
TrigConf::name
Definition: HLTChainList.h:35
TRG_MSG_INFO
#define TRG_MSG_INFO(x)
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStreamMacros.h:27
merge.output
output
Definition: merge.py:16
TrigConf::TrigConfData::smk
unsigned int smk() const
Definition: TrigConfData.h:20
TrigConf::counter
Definition: HLTChainList.h:37
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
TrigConf::HLTChainLoader::loadSignatures
void loadSignatures(HLTChainList &chainlist)
Definition: HLTChainLoader.cxx:294
HLTFrame.h
TrigConf::HLTTriggerElement
HLT trigger element configuration information.
Definition: HLTTriggerElement.h:26
TrigConf::HLTChainLoader::loadGroups
void loadGroups(HLTChainList &chainlist)
Definition: HLTChainLoader.cxx:169
HLTTriggerElement.h
TrigConf::HLTStreamTag
HLT stream configuration information.
Definition: HLTStreamTag.h:23
TrigConf::HLTChainLoader::loadTypes
void loadTypes(HLTChainList &chainlist)
Definition: HLTChainLoader.cxx:208
TrigConf::rmtilde
std::string rmtilde(const std::string &input)
Definition: DBHelper.h:24
python.copyTCTOutput.chains
chains
Definition: copyTCTOutput.py:78
TrigConf::HLTFrame
The HLT trigger menu,.
Definition: HLTFrame.h:33
get_generator_info.version
version
Definition: get_generator_info.py:33
python.CaloAddPedShiftConfig.int
int
Definition: CaloAddPedShiftConfig.py:45
HLTTriggerType.h
python.SystemOfUnits.s
float s
Definition: SystemOfUnits.py:147
extractSporadic.q
list q
Definition: extractSporadic.py:97
TrigConf::HLTChainLoader::load
virtual bool load(HLTFrame &frame)
Definition: HLTChainLoader.cxx:22
TrigConf::HLTFrame::theHLTChainList
HLTChainList & theHLTChainList()
accessor to the list of HLT chains
Definition: HLTFrame.h:44
HLTChainLoader.h