ATLAS Offline Software
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 
13 #include <boost/lexical_cast.hpp>
14 
15 using namespace std;
16 
18 
19  TRG_MSG_INFO("Start loading data with ID = " << rdTarget.id());
20 
21  try {
22  startSession();
23 
24  unique_ptr<coral::IQuery> q(m_session.nominalSchema().tableHandle( "L1_RANDOM").newQuery());
25  q->setRowCacheSize( 5 );
26 
27  coral::AttributeList bindList;
28  bindList.extend<long>("rdId");
29  bindList[0].data<long>() = rdTarget.id();
30 
31  q->setCondition( "L1R_ID = :rdId", bindList );
32 
33  //Output data and types
34  coral::AttributeList attList;
35  if(isRun1()) {
36  attList.extend<std::string>( "L1R_NAME" );
37  attList.extend<int>( "L1R_VERSION" );
38  attList.extend<long>( "L1R_RATE1" );
39  attList.extend<long>( "L1R_RATE2" );
40  } else {
41  attList.extend<string>( "L1R_CUT0" );
42  attList.extend<string>( "L1R_CUT1" );
43  attList.extend<string>( "L1R_CUT2" );
44  attList.extend<string>( "L1R_CUT3" );
45  }
46  fillQuery(q.get(), attList);
47 
48  coral::ICursor& cursor = q->execute();
49 
50  if ( ! cursor.next() ) {
51  TRG_MSG_ERROR("No such random exists " << rdTarget.id());
52  commitSession();
53  throw std::runtime_error( "RandomLoader >> Random not available" );
54  }
55 
56  const coral::AttributeList& row = cursor.currentRow();
57  if(isRun1()) {
58  std::string name = row["L1R_NAME"].data<std::string>();
59  int version = row["L1R_VERSION"].data<int>();
60  long rate1 = row["L1R_RATE1"].data<long>();
61  long rate2 = row["L1R_RATE2"].data<long>();
62  // Fill the object with data
63  rdTarget.setName( name );
64  rdTarget.setVersion( version );
65  rdTarget.setRate1( rate1 );
66  rdTarget.setRate2( rate2 );
67  } else {
68  string cut0 = row["L1R_CUT0"].data<string>();
69  string cut1 = row["L1R_CUT1"].data<string>();
70  string cut2 = row["L1R_CUT2"].data<string>();
71  string cut3 = row["L1R_CUT3"].data<string>();
72  // Fill the object with data
73  rdTarget.setCut( 0, boost::lexical_cast<uint32_t,string>( cut0 ) );
74  rdTarget.setCut( 1, boost::lexical_cast<uint32_t,string>( cut1 ) );
75  rdTarget.setCut( 2, boost::lexical_cast<uint32_t,string>( cut2 ) );
76  rdTarget.setCut( 3, boost::lexical_cast<uint32_t,string>( cut3 ) );
77  }
78 
79  if ( cursor.next() ) {
80  TRG_MSG_ERROR("More than one Random exists " << rdTarget.id());
81  commitSession();
82  throw std::runtime_error( "RandomLoader >> Random not available" );
83  }
84 
85  commitSession();
86  return true;
87  }
88  catch( const coral::Exception& e ) {
89  TRG_MSG_ERROR("Coral::Exception: " << e.what());
90  m_session.transaction().rollback();
91  throw;
92  }
93 }
TrigConf::Random::setRate2
void setRate2(int rate)
Definition: TrigConfiguration/TrigConfL1Data/TrigConfL1Data/Random.h:32
TrigConf::TrigConfData::setName
void setName(const std::string &name)
Definition: TrigConfData.h:30
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
TrigConf::Random::setRate1
void setRate1(int rate)
Definition: TrigConfiguration/TrigConfL1Data/TrigConfL1Data/Random.h:31
DBHelper.h
TrigConf::fillQuery
void fillQuery(coral::IQuery *q, coral::AttributeList &attList)
Definition: DBHelper.cxx:13
python.PyKernel.AttributeList
AttributeList
Definition: PyKernel.py:36
Random.h
RandomLoader.h
TrigConf::Random
Definition: TrigConfiguration/TrigConfL1Data/TrigConfL1Data/Random.h:16
TrigConf::name
Definition: HLTChainList.h:35
TRG_MSG_INFO
#define TRG_MSG_INFO(x)
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStreamMacros.h:27
TrigConf::TrigConfData::id
unsigned int id() const
Definition: TrigConfData.h:21
TrigConf::RandomLoader::load
virtual bool load(Random &data) override
Definition: RandomLoader.cxx:17
get_generator_info.version
version
Definition: get_generator_info.py:33
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
query_example.cursor
cursor
Definition: query_example.py:21
PlotCalibFromCool.cut1
cut1
Definition: PlotCalibFromCool.py:709
TrigConf::TrigConfData::setVersion
void setVersion(unsigned int version)
Definition: TrigConfData.h:31
extractSporadic.q
list q
Definition: extractSporadic.py:98
PlotCalibFromCool.cut0
cut0
Definition: PlotCalibFromCool.py:698
TrigConf::Random::setCut
void setCut(uint32_t idx, uint32_t cut)
Definition: TrigConfiguration/TrigConfL1Data/TrigConfL1Data/Random.h:30