ATLAS Offline Software
HLTFrameLoader.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "./HLTFrameLoader.h"
6 #include "./HLTChainLoader.h"
7 #include "./HLTSequenceLoader.h"
9 #include "./DBHelper.h"
10 
14 
15 
16 #include <CoralBase/Attribute.h>
17 #include <CoralBase/AttributeList.h>
18 
19 #include "RelationalAccess/ITable.h"
20 #include "RelationalAccess/ISchema.h"
21 #include "RelationalAccess/ICursor.h"
22 #include "RelationalAccess/IQuery.h"
23 
24 #include <iostream>
25 #include <iomanip>
26 #include <sstream>
27 using namespace std;
28 
29 bool
31 
32  unsigned int smk = frame.smk();
33  if(smk==0) return false;
34 
35  TRG_MSG_INFO("Loading HLT menu for SMK " << smk);
36 
37  typedef pair<unsigned int, unsigned int> lbnpsk_t;
38  vector<lbnpsk_t> reqested_prescale_keys = frame.getPrescaleSetCollection().prescale_keys();
39 
40  // always start a clean HLTFrame
41  frame.clear();
42 
43  // set the keys
44  frame.setSMK(smk);
45 
46  try {
47  set<unsigned int> connected_psk = GetConnectedPSKs(smk);
48 
49  loadSMT(frame);
50 
51  HLTSequenceLoader seqldr(m_storageMgr, m_session);
52  seqldr.setLevel(outputLevel());
53  seqldr.load(frame);
54 
55  HLTChainLoader chldr(m_storageMgr, m_session);
56  chldr.setLevel(outputLevel());
57  chldr.load(frame);
58 
59  // prescale set collection
60  bool all_connected(true);
61  TRG_MSG_INFO("Requested to load prescale sets: ");
62  for( lbnpsk_t lbnpsk: reqested_prescale_keys) {
63  unsigned int psk = lbnpsk.second;
64  bool is_connected = psk!=0 && connected_psk.find(psk)!=connected_psk.end();
65  TRG_MSG_INFO("LB " << setw(3) << right << lbnpsk.first << " : " << lbnpsk.second);
66  if(!is_connected) {
67  TRG_MSG_ERROR("prescale key " << lbnpsk.second << " is not connected to SMK");
68  all_connected = false;
69  }
70  }
71 
72  if(all_connected) {
73  frame.thePrescaleSetCollection().set_prescale_keys_to_load( reqested_prescale_keys );
74 
75  HLTPrescaleSetCollectionLoader pssldr(m_storageMgr, m_session);
76  pssldr.setLevel(outputLevel());
77  //pssldr.setLevel(MSGTC::DEBUG);
78  pssldr.load(frame.thePrescaleSetCollection());
79 
80 
81 
82  // by default assign the single prescale set
83  if(frame.getPrescaleSetCollection().size()==1) {
84  HLTPrescaleSet* singlePrescaleSet(frame.getPrescaleSetCollection().sets().begin()->pss);
85  // for backward compatibility we first copy the unconditional chain rerun prescale to the prescale set
86  for(HLTChain* ch: frame.theHLTChainList()) {
87  pair<bool, float> rrps = ch->rerun_prescale("");
88  if(rrps.first) {
89  singlePrescaleSet->thePrescale(ch->chain_counter(), ch->level_enum()).setRerunPrescale("",rrps.second);
90  }
91  }
92  frame.theHLTChainList().applyPrescaleSet(singlePrescaleSet);
93  }
94 
95  } else {
96  TRG_MSG_ERROR("Not all requested HLT prescale keys are connected to the SMK");
97  stringstream s;
98  for(int psk: connected_psk) {
99  s << psk << ", ";
100  }
101  TRG_MSG_INFO("these HLT PSK are connected to SMK " << smk << ": " << s.str());
102  throw runtime_error("HLTFrameLoader: not all requested HLT prescale keys are connected to the SMK");
103  }
104 
105  //merge chainlist
106  if( frame.mergedHLT() ) {
107  bool needMerging(false);
108  for( const TrigConf::HLTChain* chain : frame.getHLTChainList() ) {
109  if(chain->level_enum() != TrigConf::HLT)
110  needMerging = true;
111  }
112 
113  if(needMerging) {
114  TRG_MSG_DEBUG("Call merging of " << frame.getHLTChainList().size() << " L2 and EF chains");
115  HLTTEUtils::mergeHLTChainList2(frame);
116  }
117  }
118 
119  //frame.print();
120  }
121  catch (const std::exception& e) {
122  TRG_MSG_ERROR("exception " << e.what());
123  throw;
124  }
125 
126 
127 
128  return true;
129 }
130 
131 
132 // load SM name, version, and description for SMK
133 void
135  startSession();
136  unique_ptr< coral::IQuery > q( m_session.nominalSchema().tableHandle( "SUPER_MASTER_TABLE").newQuery() );
137 
138  std::string cond = "SMT_ID = :smId";
139  coral::AttributeList bindings;
140  bindings.extend<int>("smId");
141  bindings[0].data<int>() = frame.smk();
142  q->setCondition( cond, bindings );
143 
144  coral::AttributeList attList;
145  attList.extend<std::string>( "SMT_NAME" );
146  attList.extend<int> ( "SMT_VERSION" );
147  attList.extend<std::string>( "SMT_COMMENT" );
148  fillQuery(q.get(), attList);
149 
150 
151  coral::ICursor& cursor = q->execute();
152  while (cursor.next()) {
153  const coral::AttributeList& row = cursor.currentRow();
154  string name = row["SMT_NAME" ].data<std::string>();
155  int version = row["SMT_VERSION"].data<int>();
156  string comment = row["SMT_COMMENT"].data<std::string>();
157 
158  frame.setName( name );
159  frame.setComment( comment );
160  frame.setVersion( version );
161  }
162  commitSession();
163 }
164 
165 
166 set<unsigned int>
168  set<unsigned int> connected_psks;
169 
170  startSession();
171  unique_ptr< coral::IQuery > q( m_session.nominalSchema().newQuery() );
172 
173  q->addToTableList( "SUPER_MASTER_TABLE", "SMT" );
174  q->addToTableList( "HLT_MASTER_TABLE", "HMT" );
175  q->addToTableList( "HLT_TRIGGER_MENU", "HTM" );
176  q->addToTableList( "HLT_TM_TO_PS", "HM2PS" );
177 
178  coral::AttributeList bindings;
179  bindings.extend<int>("smid");
180  bindings[0].data<int>() = smk;
181 
182  string theCondition("");
183  theCondition += string( " SMT.SMT_ID = :smid");
184  theCondition += string( " AND SMT.SMT_HLT_MASTER_TABLE_ID = HMT.HMT_ID" );
185  theCondition += string( " AND HMT.HMT_TRIGGER_MENU_ID = HTM.HTM_ID" );
186  theCondition += string( " AND HTM.HTM_ID = HM2PS.HTM2PS_TRIGGER_MENU_ID" );
187 
188 
189  q->setCondition( theCondition, bindings );
190 
191  //Don't really want anything back, just want to see there is one entry
192  coral::AttributeList attList;
193  attList.extend<int>( "HM2PS.HTM2PS_PRESCALE_SET_ID" );
194  fillQuery(q.get(),attList);
195 
196  coral::ICursor& cursor = q->execute();
197 
198  while (cursor.next()) {
199  const coral::AttributeList& row = cursor.currentRow();
200  int psk = row["HM2PS.HTM2PS_PRESCALE_SET_ID"].data<int>();
201  connected_psks.insert(psk);
202  }
203 
204  commitSession();
205 
206  stringstream ss;
207  for(int psk : connected_psks)
208  ss << psk << ", ";
209 
210  TRG_MSG_INFO( "To SMK " << smk << " connected HLT prescale keys are " << ss.str() );
211 
212  return connected_psks;
213 }
214 
TrigConf::TrigConfData::setName
void setName(const std::string &name)
Definition: TrigConfData.h:30
TRG_MSG_ERROR
#define TRG_MSG_ERROR(x)
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStreamMacros.h:29
query_example.row
row
Definition: query_example.py:24
sendEI_SPB.ch
ch
Definition: sendEI_SPB.py:35
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
runLayerRecalibration.chain
chain
Definition: runLayerRecalibration.py:175
PowhegControl_ttHplus_NLO.ss
ss
Definition: PowhegControl_ttHplus_NLO.py:83
TrigConf::HLTPrescaleSetCollection::size
size_t size() const
number of prescale sets
Definition: HLTPrescaleSetCollection.h:50
RunEBWeightsComputation.smk
smk
Definition: RunEBWeightsComputation.py:87
TrigConf::HLTFrameLoader::load
virtual bool load(HLTFrame &data) override
Definition: HLTFrameLoader.cxx:30
TrigConf::HLTSequenceLoader
TriggerDB loader of the HLT signatures.
Definition: HLTSequenceLoader.h:17
TrigConf::HLTFrame::clear
void clear()
clear chains, sequences and prescales
Definition: HLTFrame.cxx:32
HLTPrescaleSetCollectionLoader.h
DBHelper.h
TrigConf::HLTFrame::thePrescaleSetCollection
HLTPrescaleSetCollection & thePrescaleSetCollection()
Definition: HLTFrame.h:46
TrigConf::fillQuery
void fillQuery(coral::IQuery *q, coral::AttributeList &attList)
Definition: DBHelper.cxx:13
python.PyKernel.AttributeList
AttributeList
Definition: PyKernel.py:36
HLTSequenceLoader.h
TrigConf::HLTChain
HLT chain configuration information.
Definition: TrigConfHLTData/TrigConfHLTData/HLTChain.h:35
HLTFrameLoader.h
TrigConf::DBLoader::setLevel
virtual void setLevel(MSGTC::Level lvl) override
access to output stream
Definition: DBLoader.cxx:60
TrigConf::HLTPrescaleSetCollection::prescale_keys
std::vector< std::pair< unsigned int, unsigned int > > prescale_keys() const
Definition: HLTPrescaleSetCollection.cxx:125
TrigConf::HLT
@ HLT
Definition: HLTLevel.h:12
HLTUtils.h
TrigConf::HLTPrescaleSet::thePrescale
HLTPrescale & thePrescale(unsigned int chain_counter, HLTLevel level)
Definition: HLTPrescaleSet.cxx:53
TrigConf::HLTFrameLoader::loadSMT
void loadSMT(HLTFrame &frame)
Definition: HLTFrameLoader.cxx:134
TrigConf::TrigConfData::setSMK
void setSMK(int id)
Definition: TrigConfData.h:28
TrigConf::HLTFrameLoader::GetConnectedPSKs
std::set< unsigned int > GetConnectedPSKs(unsigned int smk)
Definition: HLTFrameLoader.cxx:167
TrigConf::HLTPrescaleSetCollection::sets
std::list< cont > & sets()
Definition: HLTPrescaleSetCollection.h:67
TrigConf::HLTPrescaleSetCollectionLoader
Definition: HLTPrescaleSetCollectionLoader.h:29
calibdata.exception
exception
Definition: calibdata.py:496
TrigConf::TrigConfData::setComment
void setComment(const std::string &c)
Definition: TrigConfData.h:32
TrigConf::HLTPrescaleSet
HLT chain configuration information.
Definition: HLTPrescaleSet.h:31
TrigConf::name
Definition: HLTChainList.h:35
TRG_MSG_INFO
#define TRG_MSG_INFO(x)
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStreamMacros.h:27
CaloCondBlobAlgs_fillNoiseFromASCII.comment
string comment
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:27
TrigConf::HLTChainList::applyPrescaleSet
void applyPrescaleSet(const HLTPrescaleSet *pss)
set prescales of all chains
Definition: HLTChainList.cxx:70
TrigConf::TrigConfData::smk
unsigned int smk() const
Definition: TrigConfData.h:20
TrigConf::HLTChainLoader
TriggerDB loader of the HLT signatures.
Definition: HLTChainLoader.h:17
HLTFrame.h
python.TrigPSCPythonDbSetup.outputLevel
outputLevel
Definition: TrigPSCPythonDbSetup.py:30
HLTPrescaleSet.h
TrigConf::HLTFrame
The HLT trigger menu,.
Definition: HLTFrame.h:33
get_generator_info.version
version
Definition: get_generator_info.py:33
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
query_example.cursor
cursor
Definition: query_example.py:21
TrigConf::HLTPrescaleSetCollectionLoader::load
virtual bool load(HLTPrescaleSetCollection &psc)
Definition: HLTPrescaleSetCollectionLoader.cxx:100
TrigConf::HLTPrescale::setRerunPrescale
HLTPrescale & setRerunPrescale(const std::string &targetName, float ps)
Definition: HLTPrescale.cxx:29
TrigConf::HLTFrame::getHLTChainList
const HLTChainList & getHLTChainList() const
const accessor to the list of HLT chains
Definition: HLTFrame.h:49
TrigConf::TrigConfData::setVersion
void setVersion(unsigned int version)
Definition: TrigConfData.h:31
TrigConf::HLTPrescaleSetCollection::set_prescale_keys_to_load
void set_prescale_keys_to_load(const std::vector< std::pair< unsigned int, unsigned int > > &)
Definition: HLTPrescaleSetCollection.cxx:141
extractSporadic.q
list q
Definition: extractSporadic.py:98
TrigConf::HLTFrame::getPrescaleSetCollection
const HLTPrescaleSetCollection & getPrescaleSetCollection() const
Definition: HLTFrame.h:51
TrigConf::HLTChainLoader::load
virtual bool load(HLTFrame &frame)
Definition: HLTChainLoader.cxx:21
TrigConf::HLTFrame::theHLTChainList
HLTChainList & theHLTChainList()
accessor to the list of HLT chains
Definition: HLTFrame.h:44
TrigConf::HLTSequenceLoader::load
virtual bool load(HLTFrame &frame)
Definition: HLTSequenceLoader.cxx:19
TRG_MSG_DEBUG
#define TRG_MSG_DEBUG(x)
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStreamMacros.h:25
TrigConf::HLTFrame::mergedHLT
bool mergedHLT() const
Definition: HLTFrame.h:53
HLTChainLoader.h