ATLAS Offline Software
TriggerThresholdValueLoader.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 //NAME: TriggerThresholdValueLoader.cpp
8 //PACKAGE: TrigConfStorage
9 //
10 //AUTHOR: J.Haller (CERN) Johannes.Haller@cern.ch
11 //CREATED: 31. Oct. 2005
12 //
13 //PURPOSE:
14 //
15 //UPDATED: 8 Dec 2008 Paul Bell for sqlite access
16 // (use of defineOutput method to set data type)
17 //
19 
20 #include "boost/lexical_cast.hpp"
21 
23 
24 #include <CoralBase/Attribute.h>
25 #include <CoralBase/AttributeList.h>
26 
27 #include "RelationalAccess/SchemaException.h"
28 #include "RelationalAccess/ITransaction.h"
29 #include "RelationalAccess/ITable.h"
30 #include "RelationalAccess/ISchema.h"
31 #include "RelationalAccess/ICursor.h"
32 #include "RelationalAccess/IQuery.h"
33 
40 
41 #include <iostream>
42 #include <stdexcept>
43 #include <typeinfo>
44 
45 using namespace std;
46 
47 bool
49  TRG_MSG_DEBUG("TriggerThresholdValueLoader loading thresholdvalue with ID = " << ttvTarget.id());
50  L1DataDef def;
51 
52  string name = "";
53  string type = "";
54  int version = 0;
55  float ptcut = 0;
56  float priority=0;
57  int phimin = 0;
58  int phimax = 0;
59  int etamin = 0;
60  int etamax = 0;
61  string emisolation = "";
62  string hadisolation = "";
63  string hadveto = "";
64  int window = 0;
65 
66  try {
67  //unsigned int schema = triggerDBSchemaVersion();
68 
69  startSession();
70 
71  coral::ITable& table = m_session.nominalSchema().tableHandle( "L1_TRIGGER_THRESHOLD_VALUE");
72  coral::IQuery* query = table.newQuery();
73  query->setRowCacheSize( 5 );
74 
75  //Bind list
76  coral::AttributeList bindList;
77  bindList.extend<long>("ttvId");
78  std::string cond= "L1TTV_ID = :ttvId";
79  bindList[0].data<long>() = ttvTarget.id();
80  query->setCondition( cond, bindList );
81 
82  //Define the data types
83  coral::AttributeList attList;
84  attList.extend<std::string>( "L1TTV_NAME" );
85  attList.extend<int>( "L1TTV_VERSION" );
86  attList.extend<std::string>( "L1TTV_TYPE" );
87  attList.extend<std::string>( "L1TTV_PT_CUT" );
88  attList.extend<int>( "L1TTV_ETA_MIN" );
89  attList.extend<int>( "L1TTV_ETA_MAX" );
90  attList.extend<int>( "L1TTV_PHI_MIN" );
91  attList.extend<int>( "L1TTV_PHI_MAX" );
92  attList.extend<std::string>( "L1TTV_EM_ISOLATION" );
93  attList.extend<std::string>( "L1TTV_HAD_ISOLATION" );
94  attList.extend<std::string>( "L1TTV_HAD_VETO" );
95  attList.extend<int>( "L1TTV_WINDOW" );
96  attList.extend<std::string>( "L1TTV_PRIORITY" );
97  query->defineOutput(attList);
98  query->addToOutputList( "L1TTV_NAME" );
99  query->addToOutputList( "L1TTV_VERSION" );
100  query->addToOutputList( "L1TTV_TYPE" );
101  query->addToOutputList( "L1TTV_PT_CUT" );
102  query->addToOutputList( "L1TTV_ETA_MIN" );
103  query->addToOutputList( "L1TTV_ETA_MAX" );
104  query->addToOutputList( "L1TTV_PHI_MIN" );
105  query->addToOutputList( "L1TTV_PHI_MAX" );
106  query->addToOutputList( "L1TTV_EM_ISOLATION" );
107  query->addToOutputList( "L1TTV_HAD_ISOLATION" );
108  query->addToOutputList( "L1TTV_HAD_VETO" );
109  query->addToOutputList( "L1TTV_WINDOW" );
110  query->addToOutputList( "L1TTV_PRIORITY" );
111 
112  coral::ICursor& cursor = query->execute();
113  if ( !cursor.next()) {
114  msg() << "TriggerThresholdValueLoader >> No such TriggerThresholdValue exists "
115  << ttvTarget.id() << std::endl;
116  delete query;
117  commitSession();
118  throw std::runtime_error( "TriggerThresholdValueLoader >> TriggerThresholdValue not available" );
119  }
120 
121  const coral::AttributeList& row = cursor.currentRow();
122 
123  name = row["L1TTV_NAME"].data<std::string>();
124  version = row["L1TTV_VERSION"].data<int>();
125  type = row["L1TTV_TYPE"].data<std::string>();
126  ptcut = boost::lexical_cast<float,std::string>(row["L1TTV_PT_CUT"].data<std::string>());
127  etamin = row["L1TTV_ETA_MIN"].data<int>();
128  etamax = row["L1TTV_ETA_MAX"].data<int>();
129  phimin = row["L1TTV_PHI_MIN"].data<int>();
130  phimax = row["L1TTV_PHI_MAX"].data<int>();
131  window = row["L1TTV_WINDOW"].data<int>();
132  priority = boost::lexical_cast<float,std::string>(row["L1TTV_PRIORITY"].data<std::string>());
133  emisolation = row["L1TTV_EM_ISOLATION"].data<std::string>();
134  hadisolation = row["L1TTV_HAD_ISOLATION"].data<std::string>();
135  hadveto = row["L1TTV_HAD_VETO"].data<std::string>();
136 
137 
138  if (cursor.next()) {
139  msg() << "TriggerThresholdValueLoader >> More than one TriggerThresholdValue exists "
140  << ttvTarget.id() << std::endl;
141  delete query;
142  commitSession();
143  throw std::runtime_error( "TriggerThresholdValueLoader >> TriggerThresholdValue not available" );
144  }
145 
146  // Fill the value common for all threshold_value
147  ttvTarget.setName( name );
148  ttvTarget.setVersion( version );
149  ttvTarget.setType( type );
150  ttvTarget.setPtcut( ptcut );
151  ttvTarget.setPriority(priority);
152  delete query;
153  commitSession();
154  //msg() << name << std::endl;
155 
156  }
157  catch( const coral::Exception& e ) {
158  TRG_MSG_ERROR("Caught coral exception: " << e.what() );
159  throw;
160  }
161  catch( const std::exception& e ) {
162  TRG_MSG_ERROR("Caught standard exception: " << e.what() );
163  throw;
164  }
165 
166  try {
167  ClusterThresholdValue& ctvTarget = dynamic_cast<ClusterThresholdValue&>(ttvTarget);
168  if ( type != def.emType() && type != def.tauType()) {
169  msg() << "TriggerThresholdValueLoader >> No type match for ttv_id = "
170  << ctvTarget.id() << " " << type << std::endl;
171  throw std::runtime_error( "TriggerThresholdValueLoader >> ClusterThresholdValue not available" );
172  }
173 
174  cout << "ISO " << emisolation << " " << hadisolation << " " << hadveto << endl;
175 
176  if(hadveto=="USEISOBITS" || boost::lexical_cast<int,std::string>(hadveto)==99 ) {
177  ctvTarget.setIsolationMask( TrigConf::bin2uint(emisolation) );
178  ctvTarget.setUseIsolationMask();
179  } else {
180  ctvTarget.setEmIsolation( boost::lexical_cast<float,std::string>(emisolation) );
181  ctvTarget.setHadIsolation( boost::lexical_cast<float,std::string>(hadisolation) );
182  ctvTarget.setHadVeto( boost::lexical_cast<float,std::string>(hadveto) );
183  ctvTarget.setUseIsolationMask( false );
184  }
185 
186 
187  ctvTarget.setPhiMin( phimin);
188  ctvTarget.setPhiMax( phimax);
189  ctvTarget.setEtaMin( etamin );
190  ctvTarget.setEtaMax( etamax );
191  } catch (std::bad_cast& ex) { }
192 
193  //is it a jet_threshold_value?
194  try {
195  JetThresholdValue& jtvTarget = dynamic_cast<JetThresholdValue&>(ttvTarget);
196 
197  if (type!=def.jetType() && type!=def.jbType() && type!=def.jfType()) {
198  msg() << "TriggerThresholdValueLoader >> No type match for ttv_id = "
199  << jtvTarget.id() << type << std::endl;
200  throw std::runtime_error( "TriggerThresholdValueLoader >> TriggerThresholdValue not available" );
201  }
202  jtvTarget.setPhiMin( phimin );
203  jtvTarget.setPhiMax( phimax );
204  jtvTarget.setEtaMin( etamin );
205  jtvTarget.setEtaMax( etamax );
206  jtvTarget.setWindow( window );
207  } catch (std::bad_cast& ex) {}
208 
209  return true;
210 }
TrigConf::TriggerThresholdValue
Definition: TriggerThresholdValue.h:22
TrigConf::TrigConfData::setName
void setName(const std::string &name)
Definition: TrigConfData.h:30
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
TrigConf::TriggerThresholdValue::setPtcut
void setPtcut(float pt)
Definition: TriggerThresholdValue.h:58
TrigConf::ClusterThresholdValue::setUseIsolationMask
void setUseIsolationMask(bool use=true)
Definition: ClusterThresholdValue.h:43
TrigConf::TriggerThresholdValue::setPhiMax
void setPhiMax(int value)
Definition: TriggerThresholdValue.h:62
TrigConf::ClusterThresholdValue::setHadVeto
void setHadVeto(float v)
Definition: ClusterThresholdValue.h:40
python.selector.AtlRunQuerySelectorLhcOlc.priority
priority
Definition: AtlRunQuerySelectorLhcOlc.py:611
TrigConf::bin2uint
uint32_t bin2uint(const std::string &binary)
Definition: Trigger/TrigConfiguration/TrigConfL1Data/Root/HelperFunctions.cxx:321
python.PyKernel.AttributeList
AttributeList
Definition: PyKernel.py:36
TrigConf::TriggerThresholdValue::setWindow
void setWindow(int value)
Definition: TriggerThresholdValue.h:60
TrigConf::ClusterThresholdValue
Definition: ClusterThresholdValue.h:13
Pythia8_A14_NNPDF23LO_forMGHT_EvtGen.ptcut
float ptcut
Definition: Pythia8_A14_NNPDF23LO_forMGHT_EvtGen.py:9
HelperFunctions.h
MuonThresholdValue.h
query
Definition: query.py:1
TrigConf::L1DataDef
Definition: L1DataDef.h:27
TrigConf::ClusterThresholdValue::setHadIsolation
void setHadIsolation(float v)
Definition: ClusterThresholdValue.h:39
calibdata.exception
exception
Definition: calibdata.py:496
JetThresholdValue.h
TriggerThresholdValue.h
query_example.query
query
Definition: query_example.py:15
TrigConf::name
Definition: HLTChainList.h:35
TrigConf::TrigConfData::id
unsigned int id() const
Definition: TrigConfData.h:21
python.ext.table_printer.table
list table
Definition: table_printer.py:81
TrigConf::TriggerThresholdValue::setEtaMin
void setEtaMin(int value)
Definition: TriggerThresholdValue.h:63
L1DataDef.h
get_generator_info.version
version
Definition: get_generator_info.py:33
TrigConf::TriggerThresholdValue::setPhiMin
void setPhiMin(int value)
Definition: TriggerThresholdValue.h:61
query_example.cursor
cursor
Definition: query_example.py:21
ClusterThresholdValue.h
TrigConf::TriggerThresholdValue::setPriority
void setPriority(float prio)
Definition: TriggerThresholdValue.h:59
TrigConf::JetThresholdValue
Definition: JetThresholdValue.h:12
TrigConf::ClusterThresholdValue::setEmIsolation
void setEmIsolation(float v)
Definition: ClusterThresholdValue.h:38
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
TrigConf::TrigConfData::setVersion
void setVersion(unsigned int version)
Definition: TrigConfData.h:31
TrigConf::TriggerThresholdValueLoader::load
virtual bool load(TriggerThresholdValue &data) override
Definition: TriggerThresholdValueLoader.cxx:48
TrigConf::TriggerThresholdValue::setEtaMax
void setEtaMax(int value)
Definition: TriggerThresholdValue.h:64
LArCellBinning.etamin
etamin
Definition: LArCellBinning.py:137
TrigConf::ClusterThresholdValue::setIsolationMask
void setIsolationMask(uint16_t mask)
Definition: ClusterThresholdValue.h:46
TrigConf::TriggerThresholdValue::setType
void setType(const std::string &type)
Definition: TriggerThresholdValue.h:57
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
TRG_MSG_DEBUG
#define TRG_MSG_DEBUG(x)
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStreamMacros.h:25
TriggerThresholdValueLoader.h