ATLAS Offline Software
PrioritySetLoader.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 "./PrioritySetLoader.h"
6 
7 #include <CoralBase/Attribute.h>
8 #include <CoralBase/AttributeList.h>
9 
10 #include "RelationalAccess/SchemaException.h"
11 #include "RelationalAccess/ITransaction.h"
12 #include "RelationalAccess/ITable.h"
13 #include "RelationalAccess/ICursor.h"
14 #include "RelationalAccess/IQuery.h"
15 #include "RelationalAccess/ISchema.h"
16 #include "RelationalAccess/ITableDescription.h"
17 
18 #include <string>
19 #include <iostream>
20 #include <sstream>
21 #include <stdexcept>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <typeinfo>
25 
26 bool
28 
29  msg() << "PrioritySetLoader started loading data via MasterID = " << psTarget.lvl1MasterTableId() << std::endl;
30  try {
31 
32  startSession();
33  // will create a view into the query result; this saves us one C++ class
34  coral::IQuery* Query = m_session.nominalSchema().newQuery();
35 
36  // set the tables that are used
37  Query->addToTableList ( "L1_TRIGGER_ITEM", "TI" );
38  Query->addToTableList ( "L1_TM_TO_TI", "TMTI");
39  Query->addToTableList ( "L1_MASTER_TABLE", "MT" );
40 
41  // Bind list
42  coral::AttributeList bindList;
43  bindList.extend<int>("mtId");
44  bindList[0].data<int>() = psTarget.lvl1MasterTableId();
45  std::string theCondition = "";
46  theCondition += std::string( " MT.L1MT_ID = :mtId" );
47  theCondition += std::string( " AND MT.L1MT_TRIGGER_MENU_ID = TMTI.L1TM2TI_TRIGGER_MENU_ID" );
48  theCondition += std::string( " AND TMTI.L1TM2TI_TRIGGER_ITEM_ID = TI.L1TI_ID" );
49  Query->setCondition( theCondition, bindList );
50 
51  // the table columns of the output and their types
52  coral::AttributeList attList;
53  attList.extend<long>( "TI.L1TI_CTP_ID" );
54  attList.extend<std::string>( "TI.L1TI_PRIORITY" );
55  Query->defineOutput(attList);
56  Query->addToOutputList( "TI.L1TI_CTP_ID" );
57  Query->addToOutputList( "TI.L1TI_PRIORITY" );
58 
59  // the ordering
60  std::string theOrder = "";
61  theOrder += " TI.L1TI_CTP_ID";
62  // theOrder += " L1_TM_TO_TI.L1TM2TI_CTP_ID";
63  Query->addToOrderList( theOrder );
64 
65  // process the query
66  coral::ICursor& Cursor = Query->execute();
67  std::vector<std::string> prio(PrioritySet::N_PRIORITIES,std::string("HIGH"));
68  while (Cursor.next()) {
69  const coral::AttributeList& row = Cursor.currentRow();
70  if(verbose()>1)
71  row.toOutputStream( msg() ) << std::endl;
72  long ctp_id = row["TI.L1TI_CTP_ID"].data<long>();
73  prio.at(ctp_id) = row["TI.L1TI_PRIORITY"].data<std::string>();
74  }
75  psTarget.setPriorities( prio );
76  delete Query;
77  commitSession();
78  return true;
79  } catch (const coral::SchemaException& e) {
80  msg() << "PrioritySetLoader >> SchemaException: "
81  << e.what() << std::endl;
82  m_session.transaction().rollback();
83  return false;
84  } catch (const std::exception& e) {
85  msg() << "PrioritySetLoader >> Standard C++ exception: " << e.what() << std::endl;
86  m_session.transaction().rollback();
87  return false;
88  } catch (...) {
89  msg() << "PrioritySetLoader >> unknown C++ exception" << std::endl;
90  m_session.transaction().rollback();
91  return false;
92 
93  }
94 
95 }
TrigConf::PrioritySet
Definition: PrioritySet.h:14
query_example.row
row
Definition: query_example.py:24
TrigConf::PrioritySetLoader::load
virtual bool load(PrioritySet &data) override
Definition: PrioritySetLoader.cxx:27
TrigConf::DBLoader::verbose
virtual int verbose() const override
Definition: DBLoader.h:57
python.PyKernel.AttributeList
AttributeList
Definition: PyKernel.py:36
TrigConf::DBLoader::m_session
coral::ISessionProxy & m_session
CORAL interface to database session.
Definition: DBLoader.h:68
TrigConf::L1DataBaseclass::lvl1MasterTableId
unsigned int lvl1MasterTableId() const
Definition: L1DataBaseclass.h:30
TrigConf::TrigConfMessaging::msg
MsgStreamTC & msg() const
The standard message stream.
Definition: TrigConfMessaging.h:81
calibdata.exception
exception
Definition: calibdata.py:496
TrigConf::PrioritySet::setPriorities
void setPriorities(const std::string p[], const unsigned int size)
Definition: PrioritySet.cxx:16
PrioritySetLoader.h
TrigConf::DBLoader::commitSession
void commitSession()
commit session if not already done
Definition: DBLoader.cxx:45
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
TrigConf::DBLoader::startSession
void startSession()
start session if not already active
Definition: DBLoader.cxx:35
TrigConf::PrioritySet::N_PRIORITIES
static const unsigned int N_PRIORITIES
Definition: PrioritySet.h:18