ATLAS Offline Software
PrescaledClockLoader.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 //
7 //NAME: PrescaledClockLoader.cpp
8 //PACKAGE: TrigConfStorage
9 //
10 //AUTHOR: J.Haller (CERN) Johannes.Haller@cern.ch
11 //CREATED: 31. Oct. 2005
12 //
13 //PURPOSE:
14 //
15 //
17 
18 #include "./PrescaledClockLoader.h"
19 
20 #include <CoralBase/Attribute.h>
21 #include <CoralBase/AttributeList.h>
22 
23 #include "RelationalAccess/SchemaException.h"
24 #include "RelationalAccess/ITransaction.h"
25 #include "RelationalAccess/ITable.h"
26 #include "RelationalAccess/ISchema.h"
27 #include "RelationalAccess/ICursor.h"
28 #include "RelationalAccess/IQuery.h"
29 
31 
32 #include <iostream>
33 #include <stdexcept>
34 #include <typeinfo>
35 
37 
38  if(verbose())
39  msg() << "PrescaledClockLoader: Load PrescaledClock with ID = " << pcTarget.id() << std::endl;
40 
41  try {
42 
43  startSession();
44  coral::ITable& table = m_session.nominalSchema().tableHandle( "L1_PRESCALED_CLOCK");
45  coral::IQuery* query = table.newQuery();
46  query->setRowCacheSize( 5 );
47 
48  //Bind list
49  coral::AttributeList bindList;
50  bindList.extend<long>("pcId");
51  std::string cond = "L1PC_ID = :pcId";
52  bindList[0].data<long>() = pcTarget.id();
53  query->setCondition( cond, bindList);
54 
55  //Output data and types
56  coral::AttributeList attList;
57  attList.extend<std::string>( "L1PC_NAME" );
58  attList.extend<int>( "L1PC_VERSION" );
59  attList.extend<int>( "L1PC_CLOCK1" );
60  attList.extend<int>( "L1PC_CLOCK2" );
61  attList.extend<long>( "L1PC_ID" );
62  query->defineOutput(attList);
63 
64  query->addToOutputList( "L1PC_NAME" );
65  query->addToOutputList( "L1PC_VERSION" );
66  query->addToOutputList( "L1PC_CLOCK1" );
67  query->addToOutputList( "L1PC_CLOCK2" );
68  query->addToOutputList( "L1PC_ID" );
69  query->addToOrderList( "L1PC_ID" );
70 
71  coral::ICursor& cursor = query->execute();
72 
73  if ( ! cursor.next() ) {
74  msg() << "PrescaledClockLoader >> No such prescaled clock exists "
75  << pcTarget.id() << std::endl;
76  delete query;
77  commitSession();
78  throw std::runtime_error( "PrescaledClockLoader >> PrescaledClock not available" );
79  }
80 
81  const coral::AttributeList& row = cursor.currentRow();
82  std::string name = row["L1PC_NAME"].data<std::string>();
83  int version = row["L1PC_VERSION"].data<int>();
84  int clock1 = row["L1PC_CLOCK1"].data<int>();
85  int clock2 = row["L1PC_CLOCK2"].data<int>();
86 
87  if ( cursor.next() ) {
88  msg() << "PrescaledClockLoader >> More than one PrescaledClock exists "
89  << pcTarget.id() << std::endl;
90  delete query;
91  commitSession();
92  throw std::runtime_error( "PrescaledClockLoader >> PrescaledClock not available" );
93  }
94 
95  // Fill the object with data
96  pcTarget.setName( name );
97  pcTarget.setVersion( version );
98  pcTarget.setClock1( clock1 );
99  pcTarget.setClock2( clock2 );
100 
101  delete query;
102  commitSession();
103  return true;
104 
105  } catch( const coral::SchemaException& e ) {
106  msg() << "PrescaledClockLoader >> SchemaException: "
107 
108  << e.what() << std::endl;
109  m_session.transaction().rollback();
110  return false;
111 
112  } catch( const std::exception& e ) {
113  msg() << "PrescaledClockLoader >> Standard C++ exception: " << e.what() << std::endl;
114 
115  m_session.transaction().rollback();
116  return false;
117 
118  } catch( ... ) {
119  msg() << "PrescaledClockLoader >> Uknown C++ exception" << std::endl;
120 
121  m_session.transaction().rollback();
122  return false;
123  }
124 }
125 
TrigConf::TrigConfData::setName
void setName(const std::string &name)
Definition: TrigConfData.h:30
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
query_example.row
row
Definition: query_example.py:24
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::PrescaledClockLoader::load
virtual bool load(PrescaledClock &data) override
Definition: PrescaledClockLoader.cxx:36
query
Definition: query.py:1
TrigConf::TrigConfMessaging::msg
MsgStreamTC & msg() const
The standard message stream.
Definition: TrigConfMessaging.h:81
calibdata.exception
exception
Definition: calibdata.py:496
query_example.query
query
Definition: query_example.py:15
TrigConf::name
Definition: HLTChainList.h:35
TrigConf::PrescaledClock::setClock1
void setClock1(int clock1)
Definition: PrescaledClock.h:23
TrigConf::TrigConfData::id
unsigned int id() const
Definition: TrigConfData.h:21
PrescaledClock.h
python.ext.table_printer.table
list table
Definition: table_printer.py:81
TrigConf::PrescaledClock
Definition: PrescaledClock.h:13
TrigConf::DBLoader::commitSession
void commitSession()
commit session if not already done
Definition: DBLoader.cxx:45
get_generator_info.version
version
Definition: get_generator_info.py:33
query_example.cursor
cursor
Definition: query_example.py:21
TrigConf::TrigConfData::setVersion
void setVersion(unsigned int version)
Definition: TrigConfData.h:31
TrigConf::DBLoader::startSession
void startSession()
start session if not already active
Definition: DBLoader.cxx:35
TrigConf::PrescaledClock::setClock2
void setClock2(int clock2)
Definition: PrescaledClock.h:24
PrescaledClockLoader.h