ATLAS Offline Software
TrigDBMenuLoader.cxx
Go to the documentation of this file.
1 // Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
2 
3 #include "./TrigDBHelper.h"
5 
6 TrigConf::TrigDBMenuLoader::TrigDBMenuLoader(const std::string & connection) :
7  TrigDBLoader("TrigDBMenuLoader", connection)
8 {
9  /*
10  L1 menu queries
11  */
12  { // for schema version 1
13  auto & q = m_l1queries[1];
14  // tables
15  q.addToTableList ( "SUPER_MASTER_TABLE", "SMT" );
16  q.addToTableList ( "L1_MASTER_TABLE", "L1MT" );
17  // bind vars
18  q.extendBinding<int>("smk");
19  // conditions
20  q.extendCondition("SMT.SMT_ID = :smk");
21  q.extendCondition(" AND SMT.SMT_L1_MASTER_TABLE_ID = L1MT.L1MT_ID");
22  // attributes
23  q.extendOutput<std::string>( "SMT.SMT_NAME" );
24  q.extendOutput<int> ( "SMT.SMT_L1_MASTER_TABLE_ID" );
25  q.extendOutput<coral::Blob>( "L1MT.L1MT_MENU" );
26  // the field with the data
27  q.setDataName("L1MT.L1MT_MENU");
28  }
29  { // for schema version 2
30  auto & q = m_l1queries[2];
31  // tables
32  q.addToTableList ( "SUPER_MASTER_TABLE", "SMT" );
33  q.addToTableList ( "L1_MENU", "L1TM" );
34  // bind vars
35  q.extendBinding<int>("smk");
36  // conditions
37  q.extendCondition("SMT.SMT_ID = :smk");
38  q.extendCondition(" AND SMT.SMT_L1_MENU_ID = L1TM.L1TM_ID");
39  // attributes
40  q.extendOutput<std::string>( "SMT.SMT_NAME" );
41  q.extendOutput<int> ( "SMT.SMT_VERSION" );
42  q.extendOutput<int> ( "SMT.SMT_L1_MENU_ID" );
43  q.extendOutput<coral::Blob>( "L1TM.L1TM_DATA" );
44  // the field with the data
45  q.setDataName("L1TM.L1TM_DATA");
46  }
47 
48  /*
49  HLT menu queries
50  */
51  { // for schema version 1
52  auto & q = m_hltqueries[1];
53  // tables
54  q.addToTableList ( "SUPER_MASTER_TABLE", "SMT" );
55  q.addToTableList ( "HLT_MASTER_TABLE", "HMT" );
56  // bind vars
57  q.extendBinding<int>("smk");
58  // conditions
59  q.extendCondition("SMT.SMT_ID = :smk");
60  q.extendCondition(" AND SMT.SMT_HLT_MASTER_TABLE_ID = HMT.HMT_ID");
61  // attributes
62  q.extendOutput<std::string>( "SMT.SMT_NAME" );
63  q.extendOutput<int> ( "SMT.SMT_HLT_MASTER_TABLE_ID" );
64  q.extendOutput<coral::Blob>( "HMT.HMT_MENU" );
65  // the field with the data
66  q.setDataName("HMT.HMT_MENU");
67  }
68  { // for schema version 2
69  auto & q = m_hltqueries[2];
70  // tables
71  q.addToTableList ( "SUPER_MASTER_TABLE", "SMT" );
72  q.addToTableList ( "HLT_MENU", "HTM" );
73  // bind vars
74  q.extendBinding<int>("smk");
75  // conditions
76  q.extendCondition("SMT.SMT_ID = :smk");
77  q.extendCondition(" AND SMT.SMT_HLT_MENU_ID = HTM.HTM_ID");
78  // attributes
79  q.extendOutput<std::string>( "SMT.SMT_NAME" );
80  q.extendOutput<int> ( "SMT.SMT_VERSION" );
81  q.extendOutput<int> ( "SMT.SMT_HLT_MENU_ID" );
82  q.extendOutput<coral::Blob>( "HTM.HTM_DATA" );
83  // the field with the data
84  q.setDataName("HTM.HTM_DATA");
85  }
86 }
87 
88 
89 // Destructor defined here because QueryDefinition is an incomplete type in the header
91 
92 bool
95  const std::string & outFileName ) const
96 {
97  auto session = createDBSession();
98  session->transaction().start( /*bool readonly=*/ true);
99  const size_t sv = schemaVersion(session.get());
100  QueryDefinition qdef = getQueryDefinition(sv, m_l1queries);
101  try {
102  qdef.setBoundValue<int>("smk", smk);
103  auto q = qdef.createQuery( session.get() );
104  auto & cursor = q->execute();
105  if ( ! cursor.next() ) {
106  TRG_MSG_ERROR("Tried reading L1 menu, but SuperMasterKey " << smk << " is not available" );
107  throw TrigConf::NoSMKException("TrigDBMenuLoader (L1Menu): SMK " + std::to_string(smk) + " not available");
108  }
109  const coral::AttributeList& row = cursor.currentRow();
110  const coral::Blob& dataBlob = row[qdef.dataName()].data<coral::Blob>();
111  writeRawFile( dataBlob, outFileName );
112  blobToPtree( dataBlob, l1menu );
113  }
114  catch(coral::QueryException & ex) {
115  TRG_MSG_ERROR("When reading L1 menu for SMK " << smk << " a coral::QueryException was caught ( " << ex.what() <<" )" );
116  throw TrigConf::QueryException("TrigDBMenuLoader (L1Menu): " + std::string(ex.what()));
117  }
118  return true;
119 }
120 
121 
122 bool
124  boost::property_tree::ptree & hltmenu,
125  const std::string & outFileName ) const
126 {
127  auto session = createDBSession();
128  session->transaction().start( /*bool readonly=*/ true);
129  const size_t sv = schemaVersion(session.get());
130  QueryDefinition qdef = getQueryDefinition(sv, m_hltqueries);
131  try {
132  qdef.setBoundValue<int>("smk", smk);
133  auto q = qdef.createQuery( session.get() );
134  auto & cursor = q->execute();
135  if ( ! cursor.next() ) {
136  TRG_MSG_ERROR("Tried reading HLT menu, but SuperMasterKey " << smk << " is not available" );
137  throw TrigConf::NoSMKException("TrigDBMenuLoader (HLTMenu): SMK " + std::to_string(smk) + " not available");
138  }
139  const coral::AttributeList& row = cursor.currentRow();
140  const coral::Blob& dataBlob = row[qdef.dataName()].data<coral::Blob>();
141  writeRawFile( dataBlob, outFileName );
142  blobToPtree( dataBlob, hltmenu );
143  }
144  catch(coral::QueryException & ex) {
145  TRG_MSG_ERROR("When reading HLT menu for SMK " << smk << " a coral::QueryException was caught ( " << ex.what() <<" )" );
146  throw TrigConf::QueryException("TrigDBMenuLoader (HLTMenu): " + std::string(ex.what()));
147  }
148  return true;
149 }
150 
151 
152 bool
154  const std::string & outFileName ) const
155 {
157  loadL1Menu( smk, ptl1, outFileName );
158  try {
159  l1menu.setData(std::move(ptl1));
160  l1menu.setSMK(smk);
161  }
162  catch(std::exception & ex) {
163  l1menu.clear();
164  TRG_MSG_ERROR("When reading L1 menu for SMK " << smk << " a parsing error occured ( " << ex.what() <<" )" );
165  throw TrigConf::ParsingException("TrigDBMenuLoader: parsing error " + std::string(ex.what()));
166  }
167  return true;
168 }
169 
170 
171 bool
173  const std::string & outFileName ) const
174 {
176  loadHLTMenu( smk, pthlt, outFileName );
177  try {
178  hltmenu.setData(std::move(pthlt));
179  hltmenu.setSMK(smk);
180  }
181  catch(std::exception & ex) {
182  hltmenu.clear();
183  TRG_MSG_ERROR("When reading HLT menu for SMK " << smk << " a parsing error occured ( " << ex.what() <<" )" );
184  throw TrigConf::ParsingException("TrigDBMenuLoader: parsing error " + std::string(ex.what()));
185  }
186  return true;
187 }
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
TrigConf::TrigDBMenuLoader::m_l1queries
std::map< size_t, QueryDefinition > m_l1queries
Definition: TrigDBMenuLoader.h:81
TrigConf::HLTMenu
HLT menu configuration.
Definition: HLTMenu.h:21
RunEBWeightsComputation.smk
smk
Definition: RunEBWeightsComputation.py:87
TrigConf::TrigDBMenuLoader::loadHLTMenu
bool loadHLTMenu(unsigned int smk, boost::property_tree::ptree &hltmenu, const std::string &outFileName="") const
Load HLT menu content from the Trigger DB into two ptrees for a given SuperMasterKey (SMK)
Definition: TrigDBMenuLoader.cxx:123
TrigConf::NoSMKException
Definition: Trigger/TrigConfiguration/TrigConfIO/TrigConfIO/Exceptions.h:31
TrigConf::TrigDBLoader
Loader of trigger configurations from Json files.
Definition: TrigDBLoader.h:33
TrigConf::TrigDBMenuLoader::TrigDBMenuLoader
TrigDBMenuLoader(const std::string &connection)
Constructor.
Definition: TrigDBMenuLoader.cxx:6
python.subdetectors.tile.Blob
Blob
Definition: tile.py:17
TrigConf::L1Menu
L1 menu configuration.
Definition: L1Menu.h:28
python.PyKernel.AttributeList
AttributeList
Definition: PyKernel.py:36
TrigConf::HLTMenu::setSMK
void setSMK(unsigned int psk)
Definition: HLTMenu.cxx:46
TrigConf::QueryDefinition
Definition: TrigDBHelper.h:28
TrigConf::DataStructure::setData
void setData(const ptree &data)
Setting the configuration data.
Definition: DataStructure.cxx:39
TrigConf::QueryDefinition::setBoundValue
void setBoundValue(const std::string &fieldName, const T &value)
Definition: TrigDBHelper.h:75
DumpGeoConfig.outFileName
string outFileName
Definition: DumpGeoConfig.py:238
TrigConf::TrigDBMenuLoader::loadL1Menu
bool loadL1Menu(unsigned int smk, boost::property_tree::ptree &l1menu, const std::string &outFileName="") const
Load L1 menu content from the Trigger DB into a ptree for a given SuperMasterKey (SMK)
Definition: TrigDBMenuLoader.cxx:93
calibdata.exception
exception
Definition: calibdata.py:496
TrigConf::QueryDefinition::createQuery
std::unique_ptr< coral::IQuery > createQuery(coral::ISessionProxy *session)
Definition: TrigDBHelper.cxx:10
TrigConf::HLTMenu::clear
virtual void clear() override
Clearing the configuration data.
Definition: HLTMenu.cxx:29
TrigConf::ParsingException
Definition: Trigger/TrigConfiguration/TrigConfIO/TrigConfIO/Exceptions.h:51
ptree
boost::property_tree::ptree ptree
Definition: JsonFileLoader.cxx:16
TrigConf::QueryException
Definition: Trigger/TrigConfiguration/TrigConfIO/TrigConfIO/Exceptions.h:21
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
TrigConf::TrigDBMenuLoader::m_hltqueries
std::map< size_t, QueryDefinition > m_hltqueries
Definition: TrigDBMenuLoader.h:82
query_example.cursor
cursor
Definition: query_example.py:21
TrigConf::blobToPtree
void blobToPtree(const coral::Blob &blob, boost::property_tree::ptree &pt)
Definition: TrigDBHelper.cxx:58
LArCellConditions.sv
bool sv
Definition: LArCellConditions.py:45
python.XMLReader.l1menu
l1menu
Definition: XMLReader.py:73
extractSporadic.q
list q
Definition: extractSporadic.py:98
TrigDBHelper.h
TrigConf::QueryDefinition::dataName
const std::string & dataName()
Definition: TrigDBHelper.h:51
TrigDBMenuLoader.h
TrigConf::TrigDBMenuLoader::~TrigDBMenuLoader
virtual ~TrigDBMenuLoader() override
Destructor - cannot be defined here because QueryDefinition is an incomplete type.