ATLAS Offline Software
Loading...
Searching...
No Matches
RandomLoader.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 "./RandomLoader.h"
6#include "./DBHelper.h"
8
9#include <iostream>
10#include <stdexcept>
11#include <typeinfo>
12
13using namespace std;
14
16
17 TRG_MSG_INFO("Start loading data with ID = " << rdTarget.id());
18
19 try {
21
22 unique_ptr<coral::IQuery> q(m_session.nominalSchema().tableHandle( "L1_RANDOM").newQuery());
23 q->setRowCacheSize( 5 );
24
25 coral::AttributeList bindList;
26 bindList.extend<long>("rdId");
27 bindList[0].data<long>() = rdTarget.id();
28
29 q->setCondition( "L1R_ID = :rdId", bindList );
30
31 //Output data and types
32 coral::AttributeList attList;
33 if(isRun1()) {
34 attList.extend<std::string>( "L1R_NAME" );
35 attList.extend<int>( "L1R_VERSION" );
36 attList.extend<long>( "L1R_RATE1" );
37 attList.extend<long>( "L1R_RATE2" );
38 } else {
39 attList.extend<string>( "L1R_CUT0" );
40 attList.extend<string>( "L1R_CUT1" );
41 attList.extend<string>( "L1R_CUT2" );
42 attList.extend<string>( "L1R_CUT3" );
43 }
44 fillQuery(q.get(), attList);
45
46 coral::ICursor& cursor = q->execute();
47
48 if ( ! cursor.next() ) {
49 TRG_MSG_ERROR("No such random exists " << rdTarget.id());
51 throw std::runtime_error( "RandomLoader >> Random not available" );
52 }
53
54 const coral::AttributeList& row = cursor.currentRow();
55 if(isRun1()) {
56 std::string name = row["L1R_NAME"].data<std::string>();
57 int version = row["L1R_VERSION"].data<int>();
58 long rate1 = row["L1R_RATE1"].data<long>();
59 long rate2 = row["L1R_RATE2"].data<long>();
60 // Fill the object with data
61 rdTarget.setName( name );
62 rdTarget.setVersion( version );
63 rdTarget.setRate1( rate1 );
64 rdTarget.setRate2( rate2 );
65 } else {
66 string cut0 = row["L1R_CUT0"].data<string>();
67 string cut1 = row["L1R_CUT1"].data<string>();
68 string cut2 = row["L1R_CUT2"].data<string>();
69 string cut3 = row["L1R_CUT3"].data<string>();
70 // Fill the object with data
71 rdTarget.setCut(0, static_cast<uint32_t>(std::stoul(cut0)));
72 rdTarget.setCut(1, static_cast<uint32_t>(std::stoul(cut1)));
73 rdTarget.setCut(2, static_cast<uint32_t>(std::stoul(cut2)));
74 rdTarget.setCut(3, static_cast<uint32_t>(std::stoul(cut3)));
75 }
76
77 if ( cursor.next() ) {
78 TRG_MSG_ERROR("More than one Random exists " << rdTarget.id());
80 throw std::runtime_error( "RandomLoader >> Random not available" );
81 }
82
84 return true;
85 }
86 catch( const coral::Exception& e ) {
87 TRG_MSG_ERROR("Coral::Exception: " << e.what());
88 m_session.transaction().rollback();
89 throw;
90 }
91}
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(Random &data) override
unsigned int id() const
void setName(const std::string &name)
void setVersion(unsigned int version)
void fillQuery(coral::IQuery *q, coral::AttributeList &attList)
Definition DBHelper.cxx:13
STL namespace.