ATLAS Offline Software
TriggerThresholdLoader.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
7 #include "./DBHelper.h"
9 
19 
20 #include "boost/lexical_cast.hpp"
21 
22 #include <sstream>
23 #include <iostream>
24 #include <stdexcept>
25 #include <typeinfo>
26 
27 using namespace std;
28 
29 bool
31 
32  const unsigned int schema_version_with_zb_fields = 9;
33 
34  TRG_MSG_DEBUG("TriggerThresholdLoader loading threshold with ID = "
35  << ttTarget.id() << " for MenuId = "
36  << m_MenuId << ": ")
37  unsigned int schema_version = triggerDBSchemaVersion();
38 
39  try {
40  startSession();
41 
42  {
43  unique_ptr<coral::IQuery> query(m_session.nominalSchema().tableHandle( "L1_TRIGGER_THRESHOLD").newQuery());
44  query->setRowCacheSize( 5 );
45 
46  //Bind list
47  coral::AttributeList bindList;
48  bindList.extend<long>("ttId");
49  std::string cond= "L1TT_ID = :ttId";
50  bindList[0].data<long>() = ttTarget.id();
51  query->setCondition( cond, bindList );
52 
53  //Output data and types
54  coral::AttributeList attList;
55  attList.extend<std::string>( "L1TT_NAME" );
56  attList.extend<int>( "L1TT_VERSION" );
57  attList.extend<std::string>( "L1TT_TYPE" );
58  attList.extend<int>( "L1TT_ACTIVE" );
59  attList.extend<int>( "L1TT_MAPPING" );
60  if( (isRun1() && schema_version >= schema_version_with_zb_fields) || isRun2() ) {
61  attList.extend<int>( "L1TT_BCDELAY" );
62  attList.extend<std::string>( "L1TT_SEED" );
63  attList.extend<int>( "L1TT_SEED_MULTI" );
64  }
65  fillQuery(query.get(),attList);
66 
67  coral::ICursor& cursor = query->execute();
68 
69  if ( ! cursor.next() ) {
70  TRG_MSG_ERROR("No TriggerThreshold exists with ID " << ttTarget.id());
71  commitSession();
72  throw std::runtime_error( "TriggerThresholdLoader >> TriggerThreshold not available" );
73  }
74 
75  const coral::AttributeList& row = cursor.currentRow();
76 
77  std::string name = row["L1TT_NAME"].data<std::string>();
78  int version = row["L1TT_VERSION"].data<int>();
79  std::string type = row["L1TT_TYPE"].data<std::string>();
80  int active = row["L1TT_ACTIVE"].data<int>();
81  int mapping = row["L1TT_MAPPING"].data<int>();
82 
83  // zero bias related
84  int bcdelay(-1), seed_multi(-1);
85  std::string seed("");
86  if( (isRun1() && schema_version >= schema_version_with_zb_fields) || isRun2() ) {
87  bcdelay = row["L1TT_BCDELAY"].data<int>();
88  seed = row["L1TT_SEED"].data<std::string>();
89  seed_multi = row["L1TT_SEED_MULTI"].data<int>();
90  }
91 
92  TRG_MSG_DEBUG(name << " " << version << " " << type << " " << active << " " << mapping);
93 
94  // Fill the object with data
95  ttTarget.setName ( name );
96  ttTarget.setVersion( version );
97  ttTarget.setType ( type );
98  ttTarget.setInput ( (type=="TOPO" || type=="ALFA") ? "ctpcore" : "ctpin" );
99  ttTarget.setActive ( active );
100 
101  ttTarget.setZBSeedingThresholdName(seed);
102  ttTarget.setZBSeedingThresholdMulti(seed_multi);
103  ttTarget.setBCDelay(bcdelay);
104 
105  if(ttTarget.isInternal()) {
106  string::size_type pos = name.find_first_of("0123456789");
107  mapping = boost::lexical_cast<int,string>(name.substr(pos));
108  }
109  ttTarget.setMapping( mapping );
110  }
111 
112 
113  //==================================================
114  // now get the cable info from TM_TT
115  if(loadCableInfo()) {
116 
117  unique_ptr<coral::IQuery> query(m_session.nominalSchema().tableHandle( "L1_TM_TO_TT").newQuery());
118  query->setRowCacheSize( 5 );
119 
120  //Bind list
121  coral::AttributeList bindList;
122  std::string cond = "L1TM2TT_TRIGGER_THRESHOLD_ID = :ttId";
123  cond += " AND L1TM2TT_TRIGGER_MENU_ID = :menuId";
124  bindList.extend<long>("ttId");
125  bindList.extend<int>("menuId");
126  bindList[0].data<long>() = ttTarget.id();
127  bindList[1].data<int>() = m_MenuId;
128  query->setCondition( cond, bindList );
129 
130  //Define the data types
131  coral::AttributeList attList;
132  attList.extend<std::string>( "L1TM2TT_CABLE_NAME" );
133  attList.extend<std::string>( "L1TM2TT_CABLE_CTPIN" );
134  attList.extend<std::string>( "L1TM2TT_CABLE_CONNECTOR" );
135  attList.extend<int>( "L1TM2TT_CABLE_START" );
136  attList.extend<int>( "L1TM2TT_CABLE_END" );
137  fillQuery(query.get(),attList);
138 
139  coral::ICursor& cursor = query->execute();
140 
141  if ( ! cursor.next() ) {
142  TRG_MSG_ERROR("No such combination in L1_TM_TO_TT: TT ID "<< ttTarget.id() << ", menu ID " << m_MenuId);
143  commitSession();
144  throw std::runtime_error( "TriggerThresholdLoader >> "
145  "TMTI combination not availbale in TM_TT" );
146  }
147 
148  const coral::AttributeList& row = cursor.currentRow();
149  std::string cable_name = row["L1TM2TT_CABLE_NAME"].data<std::string>();
150  std::string cable_ctpin = row["L1TM2TT_CABLE_CTPIN"].data<std::string>();
151  std::string cable_connector = row["L1TM2TT_CABLE_CONNECTOR"].data<std::string>();
152  int cable_start = row["L1TM2TT_CABLE_START"].data<int>();
153  int cable_end = row["L1TM2TT_CABLE_END"].data<int>();
154 
155  ttTarget.setCableName(cable_name);
156  ttTarget.setCableCtpin(cable_ctpin);
157  ttTarget.setCableConnector(cable_connector);
158  ttTarget.setCableStart(cable_start);
159  ttTarget.setCableEnd(cable_end);
160 
161  }
162 
163  if( ! ttTarget.isInternal() ) { // no trigger threshold values exist for internal triggers
164 
165  //=================================================================
166  // now get the TTVs from TT_TTV:
167  coral::ITable& table = m_session.nominalSchema().tableHandle( "L1_TT_TO_TTV");
168  coral::IQuery* query = table.newQuery();
169  query->setRowCacheSize(5);
170 
171  //Bind list
172  coral::AttributeList bindList;
173  bindList.extend<long>("ttId");
174  std::string cond = "L1TT2TTV_TRIGGER_THRESHOLD_ID = :ttId";
175  bindList[0].data<long>() = ttTarget.id();
176  query->setCondition( cond, bindList );
177 
178  //Output data and types
179  coral::AttributeList attList;
180  attList.extend<long>( "L1TT2TTV_TRIG_THRES_VALUE_ID" );
181  query->defineOutput(attList);
182  query->addToOutputList( "L1TT2TTV_TRIG_THRES_VALUE_ID" );
183 
184  coral::ICursor& cursor = query->execute();
185 
186  std::vector<long> vec_ttv_id;
187  while( cursor.next() ) {
188  const coral::AttributeList& row = cursor.currentRow();
189  vec_ttv_id.push_back((long)row["L1TT2TTV_TRIG_THRES_VALUE_ID"].data<long>());
190  }
191 
192  unsigned int numberofvalues = vec_ttv_id.size();
193 
195  ((dynamic_cast<StorageMgr&>(m_storageMgr)).triggerThresholdValueLoader());
196  ttvldr.setVerbose(verbose());
197  for (unsigned int i=0; i<numberofvalues; ++i) {
198 
199  TriggerThresholdValue* ttv = 0;
200  if ( ttTarget.type() == L1DataDef::emType() ||
201  ttTarget.type() == L1DataDef::tauType() ) {
202  ttv = new ClusterThresholdValue();
203  } else if (ttTarget.type()==L1DataDef::jetType() ||
204  ttTarget.type()==L1DataDef::jbType() ||
205  ttTarget.type()==L1DataDef::jfType()) {
206  ttv = new JetThresholdValue();
207  } else if (ttTarget.type() ==L1DataDef::muonType()) {
208  ttv = new MuonThresholdValue();
209  } else if (ttTarget.type() == L1DataDef::jeType() ||
210  ttTarget.type() == L1DataDef::xeType() ||
211  ttTarget.type() == L1DataDef::teType()) {
212  ttv = new EtThresholdValue();
213  } else if (ttTarget.type() == L1DataDef::xsType()) {
214  ttv = new XsThresholdValue();
215  } else if (ttTarget.type() == L1DataDef::nimType() ||
216  ttTarget.type() == L1DataDef::mbtsType() ||
217  ttTarget.type() == L1DataDef::mbtssiType() ||
218  ttTarget.type() == L1DataDef::calreqType() ||
219  ttTarget.type() == L1DataDef::zdcType() ||
220  ttTarget.type() == L1DataDef::trtType() ||
221  ttTarget.type() == L1DataDef::bcmType() ||
222  ttTarget.type() == L1DataDef::bcmcmbType() ||
223  ttTarget.type() == L1DataDef::lucidType()) {
224  ttv = new NimThresholdValue();
225  } else {
226  msg() << "TriggerThresholdLoader: not supported type "
227  << ttTarget.id() << " type is " << ttTarget.type() << std::endl;
228  delete query;
229  delete ttv;
230  commitSession();
231  throw std::runtime_error("TriggerThresholdLoader: not supported type" );
232  }
233  ttv->setId(vec_ttv_id[i]);
234  if ( !ttvldr.load( *ttv ) ) {
235  msg() << "TriggerThresholdLoader: Error loading TriggerThreshodValue "
236  << ttv->id() << std::endl;
237  delete ttv;
238  ttv = 0;
239  delete query;
240  commitSession();
241  throw std::runtime_error("TriggerThresholdLoader: Error loading TriggerThreshodValue " );
242  } else {
243  // fill the vector
244  ttTarget.addThresholdValue(ttv);
245  }
246  }
247  }
248 
249  commitSession();
250  return true;
251  } catch( const coral::SchemaException& e ) {
252  msg() << "TriggerThresholdLoader: SchemaException: "
253  << e.what() << std::endl;
254  m_session.transaction().rollback();
255  return false;
256  } catch( const std::exception& e ) {
257  msg() << "TriggerThresholdLoader >> Standard C++ exception: " << e.what() << std::endl;
258 
259  m_session.transaction().rollback();
260  return false;
261  } catch( ... ) {
262  msg() << "TriggerThresholdLoader >> unknown C++ exception" << std::endl;
263 
264  m_session.transaction().rollback();
265  return false;
266  }
267 }
268 
269 void
271  m_MenuId = id;
272 }
273 
274 int
276  return m_MenuId;
277 }
278 
TrigConf::TriggerThresholdValue
Definition: TriggerThresholdValue.h:22
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::TriggerThreshold::setInput
void setInput(const std::string &input)
Definition: TriggerThreshold.cxx:69
TrigConf::NimThresholdValue
Definition: NimThresholdValue.h:11
TrigConf::DBLoader::setVerbose
virtual void setVerbose(int v) override
Definition: DBLoader.h:58
TrigConf::TriggerThreshold::isInternal
bool isInternal() const
Definition: TriggerThreshold.cxx:77
TrigConf::TriggerThreshold::setActive
void setActive(bool x)
Definition: TriggerThreshold.h:51
DBHelper.h
TrigConf::TriggerThresholdLoader::load
virtual bool load(TriggerThreshold &data) override
Definition: TriggerThresholdLoader.cxx:30
TrigConf::fillQuery
void fillQuery(coral::IQuery *q, coral::AttributeList &attList)
Definition: DBHelper.cxx:13
TrigConf::XsThresholdValue
Definition: XsThresholdValue.h:11
python.PyKernel.AttributeList
AttributeList
Definition: PyKernel.py:36
find_tgc_unfilled_channelids.mapping
mapping
Definition: find_tgc_unfilled_channelids.py:17
TrigConf::ClusterThresholdValue
Definition: ClusterThresholdValue.h:13
TrigConf::StorageMgr
Database Storage Manager, controls the database session and the different loader classes for DB acces...
Definition: StorageMgr.h:23
XsThresholdValue.h
TrigConf::TriggerThreshold::setType
void setType(L1DataDef::TriggerType type)
Definition: TriggerThreshold.cxx:56
MuonThresholdValue.h
query
Definition: query.py:1
TrigConf::TriggerThreshold::setBCDelay
void setBCDelay(int bcdelay)
Definition: TriggerThreshold.h:62
TrigConf::TriggerThresholdValueLoader
Definition: TriggerThresholdValueLoader.h:13
TrigConf::TriggerThreshold::type
const std::string & type() const
Definition: TriggerThreshold.h:31
TrigConf::TriggerThreshold::setCableName
void setCableName(const std::string &cablename)
Definition: TriggerThreshold.h:53
TrigConf::TriggerThreshold::setZBSeedingThresholdMulti
void setZBSeedingThresholdMulti(int seedmulti)
Definition: TriggerThreshold.h:61
TrigConf::TriggerThresholdLoader::setMenuId
void setMenuId(const int &id)
Definition: TriggerThresholdLoader.cxx:270
Trk::active
@ active
Definition: Layer.h:48
StorageMgr.h
lumiFormat.i
int i
Definition: lumiFormat.py:92
TrigConf::TriggerThreshold::addThresholdValue
void addThresholdValue(TriggerThresholdValue *value)
Definition: TriggerThreshold.cxx:119
calibdata.exception
exception
Definition: calibdata.py:496
TriggerThresholdLoader.h
TrigConf::TriggerThreshold::setZBSeedingThresholdName
void setZBSeedingThresholdName(const std::string &seed)
Definition: TriggerThreshold.h:60
JetThresholdValue.h
TriggerThreshold.h
TrigConf::TrigConfData::setId
void setId(unsigned int id)
Definition: TrigConfData.h:29
TriggerThresholdValue.h
TrigConf::MuonThresholdValue
Definition: MuonThresholdValue.h:11
query_example.query
query
Definition: query_example.py:15
TrigConf::name
Definition: HLTChainList.h:35
TrigConf::TriggerThreshold::setMapping
void setMapping(int m)
Definition: TriggerThreshold.h:52
TrigConf::TriggerThreshold::setCableEnd
void setCableEnd(int cable)
Definition: TriggerThreshold.h:57
python.TrigConfigSvcUtils.isRun2
def isRun2(cursor, schemaname)
Definition: TrigConfigSvcUtils.py:290
NimThresholdValue.h
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:194
TrigConf::TrigConfData::id
unsigned int id() const
Definition: TrigConfData.h:21
TrigConf::TriggerThreshold::setCableCtpin
void setCableCtpin(const std::string &cablectpin)
Definition: TriggerThreshold.h:54
TrigConf::EtThresholdValue
Definition: EtThresholdValue.h:11
python.ext.table_printer.table
list table
Definition: table_printer.py:81
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
L1DataDef.h
get_generator_info.version
version
Definition: get_generator_info.py:33
TrigConf::TriggerThresholdLoader::menuId
int menuId()
Definition: TriggerThresholdLoader.cxx:275
EtThresholdValue.h
ConvertOldUJHistosToNewHistos.jetType
string jetType
Definition: ConvertOldUJHistosToNewHistos.py:121
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
query_example.cursor
cursor
Definition: query_example.py:21
ClusterThresholdValue.h
TrigConf::JetThresholdValue
Definition: JetThresholdValue.h:12
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
python.TriggerHandler.verbose
verbose
Definition: TriggerHandler.py:297
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::TriggerThreshold::setCableStart
void setCableStart(int cable)
Definition: TriggerThreshold.h:56
TrigConf::TriggerThreshold
Definition: TriggerThreshold.h:20
TrigConf::TriggerThreshold::setCableConnector
void setCableConnector(const std::string &connector)
Definition: TriggerThreshold.h:55
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