ATLAS Offline Software
Loading...
Searching...
No Matches
BunchGroupLoader.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#include "./DBHelper.h"
7
9
10#include <iostream>
11#include <stdexcept>
12#include <typeinfo>
13
14using namespace std;
15
17
18 TRG_MSG_DEBUG("Loading BunchGroup with ID = " << bgTarget.id());
19
20 try {
22 if(isRun1()) {
23 unique_ptr<coral::IQuery> query( m_session.nominalSchema().tableHandle( "L1_BUNCH_GROUP").newQuery() );
24 query->setRowCacheSize( 5 );
25
26 //Bind list
27 coral::AttributeList bindList;
28 bindList.extend<long>("bgId");
29 std::string cond = "L1BG_ID = :bgId";
30 bindList[0].data<long>() = bgTarget.id();
31 query->setCondition( cond, bindList );
32
33 //Output data and types
34 coral::AttributeList attList;
35 attList.extend<std::string>( "L1BG_NAME" );
36 attList.extend<int>( "L1BG_VERSION" );
37 fillQuery(query.get(),attList);
38
39 coral::ICursor& cursor = query->execute();
40
41 if ( ! cursor.next() ) {
42 TRG_MSG_ERROR("No bunchgroup exists with ID " << bgTarget.id());
44 throw std::runtime_error( "BunchGroupLoader >> BunchGroup not available" );
45 }
46
47 const coral::AttributeList& row = cursor.currentRow();
48 std::string name = row["L1BG_NAME"].data<std::string>();
49 int version = row["L1BG_VERSION"].data<int>();
50
51 // fill the object with data
52 bgTarget.setName( name );
53 bgTarget.setVersion( version );
54 }
55
56
57 {
58 // now touch the l1_bg_to_b table to get the bunches.
59 unique_ptr<coral::IQuery> q( m_session.nominalSchema().tableHandle( "L1_BG_TO_B").newQuery() );
60 q->setRowCacheSize( 5 );
61
62 //binding
63 coral::AttributeList bindList;
64 bindList.extend<long>("bgId");
65 bindList[0].data<long>() = bgTarget.id();
66 q->setCondition( "L1BG2B_BUNCH_GROUP_ID = :bgId", bindList );
67
68 //Output data and types
69 coral::AttributeList attList;
70 attList.extend<int>( "L1BG2B_BUNCH_NUMBER" );
71 fillQuery(q.get(),attList);
72
73 coral::ICursor& cursor = q->execute();
74
75 while( cursor.next() ) {
76 const coral::AttributeList& row = cursor.currentRow();
77 bgTarget.addBunch( row["L1BG2B_BUNCH_NUMBER"].data<int>() );
78 }
79
80 }
82 }
83 catch( const coral::Exception& e ) {
84 TRG_MSG_ERROR("Coral::Exception: " << e.what());
85 m_session.transaction().rollback();
86 throw;
87 }
88
89 return true;
90
91}
92
93
94
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
virtual bool load(BunchGroup &data) override
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
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
Definition query.py:1
STL namespace.