ATLAS Offline Software
Loading...
Searching...
No Matches
DeadTimeLoader.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: DeadTimeLoader.cpp
8//PACKAGE: TTrigConfStorage
9//
10//AUTHOR: J.Haller (CERN) Johannes.Haller@cern.ch
11//CREATED: 31. Oct. 2005
12//
13//PURPOSE:
14//UPDATED: 8 Dec 2008 Paul Bell for sqlite access
15// (use of defineOutput method to set data type)
16//
18
19#include "./DeadTimeLoader.h"
20
21#include <CoralBase/Attribute.h>
22#include <CoralBase/AttributeList.h>
23
24#include "RelationalAccess/SchemaException.h"
25#include "RelationalAccess/ITransaction.h"
26#include "RelationalAccess/ITable.h"
27#include "RelationalAccess/ISchema.h"
28#include "RelationalAccess/ICursor.h"
29#include "RelationalAccess/IQuery.h"
30
32
33#include <iostream>
34#include <stdexcept>
35#include <typeinfo>
36
37using std::string;
38
40 if(verbose())
41 msg() << "DeadTimeLoader: Start loading data via ID. ID=" << dtTarget.id() << std::endl;
42
43 try {
45
46 coral::ITable& table = m_session.nominalSchema().tableHandle( "L1_DEAD_TIME");
47 coral::IQuery* query = table.newQuery();
48 query->setRowCacheSize( 5 );
49
50 //Bind list
51 coral::AttributeList bindList;
52 bindList.extend<long>("dtId");
53 std::string cond = "L1DT_ID = :dtId";
54 bindList[0].data<long>() = dtTarget.id();
55 query->setCondition( cond, bindList );
56
57 //Output data and types
58 coral::AttributeList attList;
59 attList.extend<int>( "L1DT_VERSION" );
60 attList.extend<string>( "L1DT_NAME" );
61 attList.extend<int>( "L1DT_SIMPLE" );
62 attList.extend<int>( "L1DT_COMPLEX1_LEVEL" );
63 attList.extend<int>( "L1DT_COMPLEX1_RATE" );
64 attList.extend<int>( "L1DT_COMPLEX2_LEVEL" );
65 attList.extend<int>( "L1DT_COMPLEX2_RATE" );
66 attList.extend<long>( "L1DT_ID" );
67 query->defineOutput(attList);
68
69 query->addToOutputList( "L1DT_VERSION" );
70 query->addToOutputList( "L1DT_NAME" );
71 query->addToOutputList( "L1DT_SIMPLE" );
72 query->addToOutputList( "L1DT_COMPLEX1_LEVEL" );
73 query->addToOutputList( "L1DT_COMPLEX1_RATE" );
74 query->addToOutputList( "L1DT_COMPLEX2_LEVEL" );
75 query->addToOutputList( "L1DT_COMPLEX2_RATE" );
76 query->addToOutputList( "L1DT_ID" );
77 query->addToOrderList( "L1DT_ID" );
78
79 coral::ICursor& cursor = query->execute();
80
81 if ( ! cursor.next() ) {
82 msg() << "DeadTimeLoader >> No such deadtime exists " << dtTarget.id() << std::endl;
83 delete query;
85 throw std::runtime_error( "DeadTimeLoader >> DeadTime not available" );
86 }
87
88 const coral::AttributeList& row = cursor.currentRow();
89 std::string name = row["L1DT_NAME"].data<std::string>();
90 int version = row["L1DT_VERSION"].data<int>();
91 int simple = row["L1DT_SIMPLE"].data<int>();
92 int complex1_level = row["L1DT_COMPLEX1_LEVEL"].data<int>();
93 int complex1_rate = row["L1DT_COMPLEX1_RATE"].data<int>();
94 int complex2_level = row["L1DT_COMPLEX2_LEVEL"].data<int>();
95 int complex2_rate = row["L1DT_COMPLEX2_RATE"].data<int>();
96
97 if ( cursor.next() ) {
98 msg() << "DeadTimeLoader >> More than one DeadTime exists "
99 << dtTarget.id() << std::endl;
101 throw std::runtime_error( "DeadTimeLoader >> DeadTime not available" );
102 }
103
104 // fill the object with data
105 dtTarget.setName( name );
106 dtTarget.setVersion( version );
107 dtTarget.setSimple( simple );
108 dtTarget.setComplex1Level( complex1_level );
109 dtTarget.setComplex1Rate( complex1_rate );
110 dtTarget.setComplex2Level( complex2_level );
111 dtTarget.setComplex2Rate( complex2_rate );
112
113 delete query;
115 return true;
116 } catch( const coral::SchemaException& e ) {
117 msg() << "DeadTimeLoader >> SchemaException: "
118 << e.what() << std::endl;
119 m_session.transaction().rollback();
120 return false;
121 } catch( const std::exception& e ) {
122 msg() << "DeadTimeLoader >> Standard C++ exception: " << e.what() << std::endl;
123 m_session.transaction().rollback();
124 return false;
125 } catch( ... ) {
126 msg() << "DeadTimeLoader >> Unknown C++ exception" << std::endl;
127 m_session.transaction().rollback();
128 return false;
129 }
130
131}
132
virtual int verbose() const override
Definition DBLoader.h:57
void commitSession()
commit session if not already done
Definition DBLoader.cxx:45
coral::ISessionProxy & m_session
CORAL interface to database session.
Definition DBLoader.h:68
void startSession()
start session if not already active
Definition DBLoader.cxx:35
virtual bool load(DeadTime &data) override
void setComplex1Rate(int i)
Definition DeadTime.h:28
void setComplex2Rate(int i)
Definition DeadTime.h:30
void setComplex2Level(int i)
Definition DeadTime.h:29
void setComplex1Level(int i)
Definition DeadTime.h:27
void setSimple(int i)
Definition DeadTime.h:26
unsigned int id() const
void setName(const std::string &name)
void setVersion(unsigned int version)
MsgStreamTC & msg() const
The standard message stream.
Definition query.py:1