ATLAS Offline Software
MasterTableLoader.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
8 
9 #include "./DBHelper.h"
10 
11 #include "./MasterTableLoader.h"
13 #include "./CTPConfigLoader.h"
15 #include "./MuctpiLoader.h"
16 #include "L1TopoMenuLoader.h"
17 
18 using namespace std;
19 
20 bool
21 TrigConf::MasterTableLoader::loadMasterKeys(int SuperMasterKey, int& Lvl1MasterKey, std::string & menuName) {
22  try {
23 
24  startSession();
25 
26  coral::ITable& table = m_session.nominalSchema().tableHandle( "SUPER_MASTER_TABLE");
27  coral::IQuery* query = table.newQuery();
28  query->setRowCacheSize( 5 );
29 
30  //Bind list
31  coral::AttributeList bindList;
32  bindList.extend<int>("smtid");
33  bindList[0].data<int>() = SuperMasterKey;
34  query->setCondition( "SMT_ID = :smtid" , bindList );
35 
36  //Output data and types
37  coral::AttributeList attList;
38  attList.extend<int>( "SMT_L1_MASTER_TABLE_ID" );
39  attList.extend<std::string>( "SMT_NAME" );
40  query->defineOutput(attList);
41  query->addToOutputList( "SMT_L1_MASTER_TABLE_ID" );
42  query->addToOutputList( "SMT_NAME" );
43 
44  coral::ICursor& cursor = query->execute();
45 
46  if ( ! cursor.next() ) {
47  msg() << "MasterTableLoader >> No such SuperMaster key exists " << SuperMasterKey << std::endl;
48  delete query;
49  commitSession();
50  throw std::runtime_error( "MasterTableLoader >> SuperMasterKey not available" );
51  }
52 
53  const coral::AttributeList& row = cursor.currentRow();
54  Lvl1MasterKey = row["SMT_L1_MASTER_TABLE_ID"].data<int>();
55  menuName = row["SMT_NAME"].data<std::string>();
56 
57  delete query;
58  commitSession();
59  }
60  catch( const coral::SchemaException& e ) {
61  msg() << "BunchGroupLoader >> SchemaException: " << e.what() << std::endl;
62  m_session.transaction().rollback();
63  throw;
64  } catch( const std::exception& e ) {
65  msg() << "BunchGroupLoader >> Standard C++ exception: " << e.what() << std::endl;
66  m_session.transaction().rollback();
67  throw;
68  } catch( ... ) {
69  msg() << "BunchGroupLoader >> Unknown C++ exception" << std::endl;
70  m_session.transaction().rollback();
71  throw;
72  }
73  return true;
74 }
75 
76 bool
78 
79  if ( !thrcfg.lvl1MasterTableId() ) {
80  int SuperMasterKey = thrcfg.superMasterTableId();
81  if(SuperMasterKey==0) {
82  msg() << "MasterTableLoader: Error loading ThresholdConfig" << std::endl;
83  msg() << ">>no super- or lvl1- master key is specified" << std::endl;
84  return false;
85  }
86  int Lvl1MasterKey(0);
87  std::string menuName{""};
88  loadMasterKeys(SuperMasterKey, Lvl1MasterKey, menuName);
89  thrcfg.setLvl1MasterTableId(Lvl1MasterKey);
90  }
91  try {
92  ThresholdConfigLoader& thrLoader =
93  dynamic_cast<ThresholdConfigLoader&>(m_storageMgr.thresholdConfigLoader());
94  thrLoader.setVerbose(DBLoader::verbose());
95  return thrLoader.load(thrcfg);
96  } catch (std::bad_cast& ex) {
97  msg() << "Caught exception in MasterTableLoader : "
98  << ex.what() << std::endl;
99  return false;
100  }
101 }
102 
103 bool
105 
106  if ( !ctpc.lvl1MasterTableId() ) {
107  int SuperMasterKey = ctpc.superMasterTableId();
108  if(SuperMasterKey==0) {
109  msg() << "MasterTableLoader: Error loading CTPConfig" << std::endl;
110  msg() << ">>no super- or lvl1- master key is specified" << std::endl;
111  return false;
112  }
113  int Lvl1MasterKey(0);
114 
115  msg() << "Load L1 master key" << std::endl;
116  std::string menuName{""};
117  loadMasterKeys(SuperMasterKey, Lvl1MasterKey, menuName);
118 
119  msg() << "Loaded L1 master key" << Lvl1MasterKey << std::endl;
120 
121  ctpc.setLvl1MasterTableId(Lvl1MasterKey);
122  ctpc.setName(menuName);
123  }
124  try {
125  CTPConfigLoader& ctpLoader =
126  dynamic_cast<CTPConfigLoader&>(m_storageMgr.ctpConfigLoader());
127  ctpLoader.setLevel(outputLevel());
128  try {
129  return ctpLoader.load(ctpc);
130  } catch ( const std::exception& e ) {
131  msg() << "MasterTableLoader >> Failed to load CTPConfig: "
132  << e.what() << std::endl;
133  return false;
134  }
135  } catch (std::bad_cast& ex) {
136  msg() << "Caught exception in MasterTableLoader : "
137  << ex.what() << std::endl;
138  return false;
139  }
140 }
141 
142 bool
144 
145  if ( !m.lvl1MasterTableId() ) {
146  int SuperMasterKey = m.superMasterTableId();
147  if(SuperMasterKey==0) {
148  msg() << "MasterTableLoader: Error loading Muctpi since no L1MasterKey nor a SMK is specified" << std::endl;
149  return false;
150  }
151  int Lvl1MasterKey(0);
152  std::string menuName{""};
153  loadMasterKeys(SuperMasterKey, Lvl1MasterKey, menuName);
154  m.setLvl1MasterTableId(Lvl1MasterKey);
155  }
156  try {
157  MuctpiLoader& muctpiLoader = dynamic_cast<MuctpiLoader&>( m_storageMgr.muctpiLoader() );
158  muctpiLoader.setLevel(outputLevel());
159  return muctpiLoader.load(m);
160  } catch (std::bad_cast& ex) {
161  msg() << "Caught exception in MasterTableLoader : "
162  << ex.what() << std::endl;
163  return false;
164  }
165 }
166 
168  try {
169  L1TopoMenuLoader& l1topoLoader = dynamic_cast<L1TopoMenuLoader&>(m_storageMgr.l1topoMenuLoader());
170  l1topoLoader.setLevel(outputLevel());
171  return l1topoLoader.load(l1topo);
172  } catch (std::exception& ex) {
173  msg() << "Caught exception in MasterTableLoader : "
174  << ex.what() << std::endl;
175  return false;
176  }
177 }
178 
179 
180 int
182 
183  msg() << "MasterTableLoader loading mt_id for next run " << std::endl;
184 
185  try {
186 
187  if ( ! m_session.transaction().isActive() )
188  m_session.transaction().start(true);
189 
190  coral::AttributeList emptyBindVariableList0;
191  coral::ITable& table0 = m_session.nominalSchema().tableHandle( "TRIGGER_NEXT_RUN");
192  coral::IQuery* query0 = table0.newQuery();
193  query0->setRowCacheSize( 5 );
194 
195  std::string whereclause0= "TNR_ID = 1";
196 
197  query0->setCondition( whereclause0, emptyBindVariableList0 );
198 
199  query0->addToOutputList( "TNR_SUPER_MASTER_TABLE_ID" );
200 
201  coral::ICursor& cursor0 = query0->execute();
202 
203  if ( ! cursor0.next() ) {
204  msg() << "MasterTableLoader >> No Entry in NEXT_RUN Table " << std::endl;
205  delete query0;
206 
207  throw std::runtime_error( "MasterTableLoader >> no entry in NEXT_RUN table" );
208  }
209 
210  const coral::AttributeList& row0 = cursor0.currentRow();
211  int supermastertableid = 0;
212  supermastertableid = row0["TNR_SUPER_MASTER_TABLE_ID"].data<int>();
213 
214  if ( cursor0.next() ) {
215  msg() << "MasterTableLoader >> More than one entry in NEXT_RUNtable" << std::endl;
216  delete query0;
217 
218  throw std::runtime_error( "MasterTableLoader >> More than one entry in NEXT_RUNtable" );
219  }
220 
221  // now get the master_table_id from the super_master_table
222 
223  msg() << "MasterTableLoader>> getting data for super_mt_id = " << supermastertableid << std::endl;
224 
225  coral::ITable& table = m_session.nominalSchema().tableHandle( "SUPER_MASTER_TABLE");
226 
227  unique_ptr< coral::IQuery > query( table.newQuery() );
228  query->setRowCacheSize( 5 );
229  coral::AttributeList emptyBindVariableList;
230 
231  std::string os= "SMT_ID = ";
232  std::ostringstream lStringOS;
233  lStringOS << supermastertableid;
234  os += lStringOS.str();
235 
236  query->setCondition( os , emptyBindVariableList );
237 
238  query->addToOutputList( "SMT_L1_MASTER_TABLE_ID" );
239 
240  coral::ICursor& cursor = query->execute();
241 
242  if ( ! cursor.next() ) {
243  msg() << "MasterTableLoader >> No such Super_Master_table exists " << supermastertableid << std::endl;
244  delete query0;
245 
246  throw std::runtime_error( "MasterTableLoader >> No such Super_Master_table exists " );
247  }
248 
249  const coral::AttributeList& row = cursor.currentRow();
250  int mt_id = 0;
251  mt_id = row["SMT_L1_MASTER_TABLE_ID"].data<int>();
252 
253  if ( cursor.next() ) {
254  msg() << "MasterTableLoader >> More than one Super_Master_table exists "
255  << supermastertableid << std::endl;
256  throw std::runtime_error( "MasterTableLoader >> More than one Super_Master_table exists " );
257  }
258  delete query0;
259  return mt_id;
260  }
261  catch( const coral::SchemaException& e )
262  {
263  msg() << "CTPConfigLoader >> SchemaException: "
264  << e.what() << std::endl;
265  m_session.transaction().rollback();
266  return false;
267  }
268  catch( const std::exception& e )
269  {
270  msg() << "CTPConfigLoader >> Standard C++ exception: " << e.what() << std::endl;
271  m_session.transaction().rollback();
272  return false;
273  }
274  catch( ... )
275  {
276  msg() << "CTPConfigLoader >> unknown C++ exception" << std::endl;
277  m_session.transaction().rollback();
278  return false;
279  }
280 
281  return true;
282 }
283 
TrigConf::TrigConfData::setName
void setName(const std::string &name)
Definition: TrigConfData.h:30
query_example.row
row
Definition: query_example.py:24
TrigConf::ThresholdConfigLoader::load
virtual bool load(ThresholdConfig &data) override
Definition: ThresholdConfigLoader.cxx:43
TrigConf::Muctpi
Definition: Muctpi.h:12
TrigConf::ThresholdConfig
Definition: ThresholdConfig.h:17
CTPConfig.h
TrigConf::MuctpiLoader::load
virtual bool load(Muctpi &data) override
Definition: MuctpiLoader.cxx:38
python.SystemOfUnits.m
int m
Definition: SystemOfUnits.py:91
CTPConfigOnlineLoader.h
TrigConf::DBLoader::setVerbose
virtual void setVerbose(int v) override
Definition: DBLoader.h:58
ThresholdConfigLoader.h
DBHelper.h
python.PyKernel.AttributeList
AttributeList
Definition: PyKernel.py:36
MasterTableLoader.h
TrigConf::DBLoader::setLevel
virtual void setLevel(MSGTC::Level lvl) override
access to output stream
Definition: DBLoader.cxx:60
TrigConf::MuctpiLoader
Definition: MuctpiLoader.h:26
ThresholdConfig.h
query
Definition: query.py:1
TrigConf::L1DataBaseclass::lvl1MasterTableId
unsigned int lvl1MasterTableId() const
Definition: L1DataBaseclass.h:30
MuctpiLoader.h
CTPConfigLoader.h
TrigConf::ThresholdConfigLoader
TriggerDB loader of the LVL1 trigger threshold configuration.
Definition: ThresholdConfigLoader.h:26
TrigConf::L1TopoMenuLoader
TriggerDB loader of the HLT menu.
Definition: L1TopoMenuLoader.h:17
calibdata.exception
exception
Definition: calibdata.py:496
TrigConf::TrigConfData::superMasterTableId
int superMasterTableId() const
Definition: TrigConfData.h:19
TrigConf::L1DataBaseclass::setLvl1MasterTableId
void setLvl1MasterTableId(unsigned int id)
Definition: L1DataBaseclass.h:31
ReadFromCoolCompare.os
os
Definition: ReadFromCoolCompare.py:231
query_example.query
query
Definition: query_example.py:15
TrigConf::CTPConfigLoader
Definition: CTPConfigLoader.h:13
L1TopoMenuLoader.h
TrigConf::CTPConfigLoader::load
virtual bool load(CTPConfig &data) override
Definition: CTPConfigLoader.cxx:25
python.ext.table_printer.table
list table
Definition: table_printer.py:81
TrigConf::MasterTableLoader::mt_id_for_next_run
int mt_id_for_next_run()
next run configuration key (depreciated)
Definition: MasterTableLoader.cxx:181
python.TrigPSCPythonDbSetup.outputLevel
outputLevel
Definition: TrigPSCPythonDbSetup.py:30
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
query_example.cursor
cursor
Definition: query_example.py:21
TrigConf::L1TopoMenuLoader::load
virtual bool load(TXC::L1TopoMenu &) override
Definition: L1TopoMenuLoader.cxx:26
python.TriggerHandler.verbose
verbose
Definition: TriggerHandler.py:297
TrigConf::CTPConfig
Definition: CTPConfig.h:27
TrigConf::MasterTableLoader::loadMasterKeys
bool loadMasterKeys(int SuperMasterKey, int &Lvl1MasterKey, std::string &menuName)
Definition: MasterTableLoader.cxx:21
TrigConf::MasterTableLoader::load
bool load(ThresholdConfig &thrcfg) override
Load the LVL1 trigger thresholds from the configuration source.
Definition: MasterTableLoader.cxx:77
TXC::L1TopoMenu
Definition: L1TopoMenu.h:25
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
Muctpi.h