ATLAS Offline Software
Loading...
Searching...
No Matches
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
29using namespace std;
30
31namespace {
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
48bool
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
59
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(std::move(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 }
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
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
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
unsigned int triggerDBSchemaVersion()
Definition DBLoader.cxx:76
void startSession()
start session if not already active
Definition DBLoader.cxx:35
virtual bool load(HLTPrescaleSet &hltpss) override
HLT chain configuration information.
size_t size(HLTLevel level=HLT) const
HLTPrescale & thePrescale(unsigned int chain_counter, HLTLevel level)
HLTPrescale & setPassThrough(float pass_through)
Definition HLTPrescale.h:47
HLTPrescale & setPrescale(float prescale)
Definition HLTPrescale.h:46
unsigned int id() const
void setName(const std::string &name)
void setVersion(unsigned int version)
std::unique_ptr< MVAUtils::BDT > convert(TMVA::MethodBDT *bdt, bool isRegression=true, bool useYesNoLeaf=false)
HLTLevel str2lvl(const std::string &level)
Definition HLTLevel.h:14
void fillQuery(coral::IQuery *q, coral::AttributeList &attList)
Definition DBHelper.cxx:13
fail(message)
STL namespace.