ATLAS Offline Software
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 
5 #include "./BunchGroupLoader.h"
6 #include "./DBHelper.h"
7 
9 
10 #include <iostream>
11 #include <stdexcept>
12 #include <typeinfo>
13 
14 using namespace std;
15 
17 
18  TRG_MSG_DEBUG("Loading BunchGroup with ID = " << bgTarget.id());
19 
20  try {
21  startSession();
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());
43  commitSession();
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  }
81  commitSession();
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 
TrigConf::TrigConfData::setName
void setName(const std::string &name)
Definition: TrigConfData.h:30
TrigConf::BunchGroup
Definition: BunchGroup.h:17
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
TRG_MSG_ERROR
#define TRG_MSG_ERROR(x)
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStreamMacros.h:29
query_example.row
row
Definition: query_example.py:24
DBHelper.h
TrigConf::fillQuery
void fillQuery(coral::IQuery *q, coral::AttributeList &attList)
Definition: DBHelper.cxx:13
python.PyKernel.AttributeList
AttributeList
Definition: PyKernel.py:36
BunchGroupLoader.h
query
Definition: query.py:1
query_example.query
query
Definition: query_example.py:15
TrigConf::name
Definition: HLTChainList.h:35
BunchGroup.h
TrigConf::TrigConfData::id
unsigned int id() const
Definition: TrigConfData.h:21
TrigConf::BunchGroupLoader::load
virtual bool load(BunchGroup &data) override
Definition: BunchGroupLoader.cxx:16
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::BunchGroup::addBunch
void addBunch(int)
Definition: BunchGroup.cxx:17
extractSporadic.q
list q
Definition: extractSporadic.py:98
TRG_MSG_DEBUG
#define TRG_MSG_DEBUG(x)
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStreamMacros.h:25