ATLAS Offline Software
HLTPrescaleSetLoader.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 #include "./DBHelper.h"
8 
10 
11 #include <CoralBase/Attribute.h>
12 #include <CoralBase/AttributeList.h>
13 
14 #include "RelationalAccess/SchemaException.h"
15 #include "RelationalAccess/ITransaction.h"
16 #include "RelationalAccess/ITable.h"
17 #include "RelationalAccess/ISchema.h"
18 #include "RelationalAccess/ICursor.h"
19 #include "RelationalAccess/IQuery.h"
20 
21 #include <algorithm>
22 #include <iostream>
23 #include <iomanip>
24 #include <sstream>
25 #include <memory>
26 
27 #include <sys/time.h>
28 
29 using namespace std;
30 
31 namespace {
32  //Need to convert any tildas to empty strings
33  template <class T>
34  bool from_string(T& t,const std::string& s,std::ios_base& (*f)(std::ios_base&))
35  {
36  std::istringstream iss(s);
37  return !(iss >> f >> t).fail();
38  }
39  bool convert(const string & prescale_s, float& prescale_f){
40  return from_string<float>(prescale_f, std::string(prescale_s), std::dec);
41  }
42  std::string CheckTilda(const std::string& input){
43  return (input=="~")?"":input;
44  }
45 }
46 
47 
48 bool
50 
51  using std::string;
52 
53  TRG_MSG_INFO("Started loading data with HLT PSK: " << hltpss.id());
54 
55  //Find if old or new schema is being used:
56  try {
57 
58  triggerDBSchemaVersion();
59 
60  startSession();
61 
62  unique_ptr< coral::IQuery > q( m_session.nominalSchema().newQuery() );
63 
64  //Set the tables that are used
65  q->addToTableList ( "HLT_PRESCALE_SET", "PS" );
66  q->addToTableList ( "HLT_PRESCALE", "PR" );
67 
68  //printTable(m_session.nominalSchema().tableHandle( "HLT_PRESCALE"));
69 
70  //Bind list
71  coral::AttributeList bindList;
72  bindList.extend<int>("psid");
73  bindList[0].data<int>() = (int)hltpss.id();
74 
75  // selection condition
76  string theCondition = " PS.HPS_ID = :psid";
77  theCondition += " AND PS.HPS_ID = PR.HPR_PRESCALE_SET_ID";
78  q->setCondition( theCondition, bindList );
79 
80  // output data
81  coral::AttributeList attList;
82  attList.extend<string>( "PS.HPS_NAME" );
83  attList.extend<int> ( "PS.HPS_VERSION" );
84  if(isRun1()) {
85  attList.extend<string>( "PR.HPR_L2_OR_EF" );
86  attList.extend<string>( "PR.HPR_PASS_THROUGH_RATE" );
87  attList.extend<string>( "PR.HPR_PRESCALE" );
88  } else {
89  attList.extend<float> ( "PR.HPR_VALUE" );
90  attList.extend<string> ( "PR.HPR_TYPE" );
91  attList.extend<string> ( "PR.HPR_CONDITION" );
92  }
93  attList.extend<int> ( "PR.HPR_CHAIN_COUNTER" );
94 
95  fillQuery(q.get(),attList);
96 
97  // the ordering
98  string theOrder = "";
99  if(isRun1()) {
100  theOrder = " PR.HPR_L2_OR_EF DESC, PR.HPR_CHAIN_COUNTER ASC";
101  } else {
102  theOrder += "PR.HPR_CHAIN_COUNTER ASC";
103  }
104  q->addToOrderList( theOrder );
105 
106 
107  q->setRowCacheSize(1000);
108  q->setDistinct();
109 
110  // process the query
111  coral::ICursor& cursor = q->execute();
112 
113  bool pssnameset = false;
114 
115 
116  // fill chain info list
117  while (cursor.next()) {
118 
119  const coral::AttributeList& row = cursor.currentRow();
120 
121  if(!pssnameset) {
122  string pssname = CheckTilda(row["PS.HPS_NAME"].data<string>());
123  int pssversion = row["PS.HPS_VERSION"].data<int>();
124  hltpss.setName(pssname);
125  hltpss.setVersion(pssversion);
126  pssnameset=true;
127  }
128 
129  string level = isRun1() ? row["PR.HPR_L2_OR_EF"].data<string>() : "HLT";
130  int counter = row["PR.HPR_CHAIN_COUNTER"].data<int>();
131 
132  // this is faster than boost::lexical_cast string->float:
133  if(isRun1()) {
134  float ps(-999);
135  float pt(-999);
136  std::string prescaleStr = row["PR.HPR_PRESCALE"].data<string>();
137  if(prescaleStr=="-0" || prescaleStr=="na" ) prescaleStr = "-1";
138  if (!convert(prescaleStr, ps)) {
139  TRG_MSG_WARNING("Could not convert prescale string '" << prescaleStr << "' of chain " << counter << " to float");
140  }
141 
142  std::string passThroughStr = row["PR.HPR_PASS_THROUGH_RATE"].data<string>();
143  if (!convert(passThroughStr, pt)) {
144  TRG_MSG_WARNING("Could not convert passthrough string '" << passThroughStr << "' of chain " << counter << " to float");
145  }
146 
147  if(level=="L2" || level=="l2" || level=="EF" || level=="ef" || level=="hlt" || level=="HLT" || level=="") {
148  hltpss.thePrescale( counter, str2lvl(level) )
149  .setPrescale(ps)
150  .setPassThrough(pt);
151  } else {
152  std::string streamnametype(level);
153  // sanity check: stream name and type are separated by ':'
154  if(streamnametype.rfind(':')==std::string::npos)
155  streamnametype += ":" + streamnametype;
156  }
157  } else {
158  // RUN 2
159  float value = row["PR.HPR_VALUE"].data<float>();
160  string pstype = row["PR.HPR_TYPE"].data<string>();
161  string pscondition = row["PR.HPR_CONDITION"].data<string>();
162 
163  TRG_MSG_DEBUG("Loaded prescales:"<< setw(4) << right << counter << " : " << pstype << " (" << pscondition << ") => " << value );
164 
165  auto& thePS = hltpss.thePrescale( counter, str2lvl("HLT") );
166 
167  if(pstype=="Prescale") {
168  thePS.setPrescale(value);
169  } else if (pstype=="Pass_Through") {
170  thePS.setPassThrough(value);
171  } else if (pstype=="ReRun") {
172  if(pscondition=="0") pscondition="";
173  thePS.setRerunPrescale(pscondition,value);
174  } else if (pstype=="Stream") {
175  // pscontition : stream name
176  thePS.setStreamPrescale(pscondition,value);
177  } else {
178  TRG_MSG_WARNING("Could not interpret this entry in the prescale set table: counter " << counter << " : " << pstype << " (" << pscondition << ") => " << value);
179  }
180  }
181  }
182 
183  if(isRun1()) {
184  TRG_MSG_INFO("Loaded " << hltpss.size(L2) << " L2 prescales and " << hltpss.size(EF) << " EF prescales.");
185  } else {
186  TRG_MSG_INFO("Loaded " << hltpss.size() << " HLT prescales");
187  }
188  commitSession();
189  }
190  catch (const coral::SchemaException& e) {
191  TRG_MSG_ERROR("HLTPrescaleSetLoader >> IRelationalException: " << e.what());
192  m_session.transaction().rollback();
193  return false;
194  }
195  catch (const std::exception& e) {
196  TRG_MSG_ERROR("HLTPrescaleSetLoader >> Standard C++ exception: " << e.what());
197  m_session.transaction().rollback();
198  return false;
199  }
200  catch (...) {
201  TRG_MSG_ERROR("HLTPrescaleSetLoader >> unknown C++ exception");
202  m_session.transaction().rollback();
203  return false;
204  }
205 
206  return true;
207 
208 }
209 
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
python.CaloRecoConfig.f
f
Definition: CaloRecoConfig.py:127
Trk::L2
@ L2
Definition: AlignModuleList.h:32
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
TrigConf::HLTPrescaleSetLoader::load
virtual bool load(HLTPrescaleSet &hltpss) override
Definition: HLTPrescaleSetLoader.cxx:49
DBHelper.h
test_pyathena.pt
pt
Definition: test_pyathena.py:11
TrigConf::fillQuery
void fillQuery(coral::IQuery *q, coral::AttributeList &attList)
Definition: DBHelper.cxx:13
athena.value
value
Definition: athena.py:122
TRT_PAI_gasdata::EF
const float EF[NF]
Energy levels for Fluor.
Definition: TRT_PAI_gasdata.h:271
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
python.PyKernel.AttributeList
AttributeList
Definition: PyKernel.py:36
TrigConf::str2lvl
HLTLevel str2lvl(const std::string &level)
Definition: HLTLevel.h:14
python.iconfTool.models.loaders.level
level
Definition: loaders.py:20
TrigConf::HLTPrescale::setPassThrough
HLTPrescale & setPassThrough(float pass_through)
Definition: HLTPrescale.h:47
TrigConf::HLTPrescaleSet::thePrescale
HLTPrescale & thePrescale(unsigned int chain_counter, HLTLevel level)
Definition: HLTPrescaleSet.cxx:53
PlotPulseshapeFromCool.input
input
Definition: PlotPulseshapeFromCool.py:106
calibdata.exception
exception
Definition: calibdata.py:496
HLTPrescaleSetLoader.h
TrigConf::HLTPrescaleSet::size
size_t size(HLTLevel level=HLT) const
Definition: HLTPrescaleSet.h:52
TrigConf::HLTPrescaleSet
HLT chain configuration information.
Definition: HLTPrescaleSet.h:31
TRG_MSG_INFO
#define TRG_MSG_INFO(x)
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStreamMacros.h:27
TRG_MSG_WARNING
#define TRG_MSG_WARNING(x)
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStreamMacros.h:28
TrigConf::counter
Definition: HLTChainList.h:37
TrigConf::TrigConfData::id
unsigned int id() const
Definition: TrigConfData.h:21
TMVAToMVAUtils::convert
std::unique_ptr< MVAUtils::BDT > convert(TMVA::MethodBDT *bdt, bool isRegression=true, bool useYesNoLeaf=false)
Definition: TMVAToMVAUtils.h:114
TrigConf::HLTPrescale::setPrescale
HLTPrescale & setPrescale(float prescale)
Definition: HLTPrescale.h:46
HLTPrescaleSet.h
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
query_example.cursor
cursor
Definition: query_example.py:21
TrigConf::HLTPrescale::setRerunPrescale
HLTPrescale & setRerunPrescale(const std::string &targetName, float ps)
Definition: HLTPrescale.cxx:29
TrigConf::TrigConfData::setVersion
void setVersion(unsigned int version)
Definition: TrigConfData.h:31
extractSporadic.q
list q
Definition: extractSporadic.py:98
TrigConf::HLTPrescale::setStreamPrescale
HLTPrescale & setStreamPrescale(const std::string &streamName, float ps)
Definition: HLTPrescale.cxx:23
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35
TRG_MSG_DEBUG
#define TRG_MSG_DEBUG(x)
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStreamMacros.h:25
beamspotman.fail
def fail(message)
Definition: beamspotman.py:201