ATLAS Offline Software
ThresholdMonitorLoader.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: ThresholdMonitorLoader.cpp
8 //PACKAGE: TrigConfStorage
9 //
10 //AUTHOR: G.Fischer (DESY) Gordon.Fischer@cern.ch
11 //CREATED: 16. Oct. 2007
12 //
13 //PURPOSE:
14 //UPDATED: 8 Dec 2008 Paul Bell for sqlite access
15 // (use of defineOutput method to set data type)
16 //
18 
19 
22 
23 #include <CoralBase/Attribute.h>
24 #include <CoralBase/AttributeList.h>
25 
26 #include "RelationalAccess/SchemaException.h"
27 #include "RelationalAccess/ITransaction.h"
28 #include "RelationalAccess/ITable.h"
29 #include "RelationalAccess/ISchema.h"
30 #include "RelationalAccess/ICursor.h"
31 #include "RelationalAccess/IQuery.h"
32 
33 
36 
37 #include <sstream>
38 #include <iostream>
39 #include <stdexcept>
40 #include <typeinfo>
41 
42 
44 
45  if(verbose()>=2)
46  msg() << "ThresholdMonitorLoader started loading data via ID. ID = "
47  << tmTarget.id() << " for MenuId = "
48  << m_MenuId << std::endl;
49 
50  try {
51  unsigned int schema = triggerDBSchemaVersion();
52 
53  startSession();
54  coral::ITable& table = m_session.nominalSchema().tableHandle( "L1_TM_TO_TT_MON");
55  coral::IQuery* query = table.newQuery();
56  query->setRowCacheSize( 6 );
57 
58  //Bind list
59  coral::AttributeList bindList;
60  bindList.extend<int>("tmId");
61  bindList.extend<int>("menuId");
62  bindList[0].data<int>() = tmTarget.id();
63  bindList[1].data<int>() = m_MenuId;
64  std::string theCondition = "";
65  theCondition += std::string( " L1TM2TTM_ID = :tmId" );
66  theCondition += std::string( " AND L1TM2TTM_TRIGGER_MENU_ID = :menuId" );
67  query->setCondition( theCondition, bindList );
68 
69  //Output types
70  coral::AttributeList attList;
71  attList.extend<std::string>( "L1TM2TTM_NAME" );
72  attList.extend<long>( "L1TM2TTM_TRIGGER_THRESHOLD_ID" );
73  attList.extend<int>( "L1TM2TTM_INTERNAL_COUNTER" );
74  attList.extend<int>( "L1TM2TTM_MULTIPLICITY" );
75  if(schema <= 6) attList.extend<long>( "L1TM2TTM_BUNCH_GROUP_SET_ID" );
76  if(schema > 6) attList.extend<long>( "L1TM2TTM_BUNCH_GROUP_ID" );
77  attList.extend<std::string>( "L1TM2TTM_COUNTER_TYPE" );
78  query->defineOutput(attList);
79 
80  query->addToOutputList("L1TM2TTM_NAME" );
81  query->addToOutputList("L1TM2TTM_TRIGGER_THRESHOLD_ID" );
82  query->addToOutputList("L1TM2TTM_INTERNAL_COUNTER" );
83  query->addToOutputList("L1TM2TTM_MULTIPLICITY" );
84  if(schema <= 6) query->addToOutputList("L1TM2TTM_BUNCH_GROUP_SET_ID" );
85  else if(schema > 6) query->addToOutputList("L1TM2TTM_BUNCH_GROUP_ID" );
86  query->addToOutputList("L1TM2TTM_COUNTER_TYPE" );
87 
88  coral::ICursor& cursor = query->execute();
89 
90  if ( ! cursor.next() ) {
91  msg() << "ThresholdMonitorLoader >> No such ThresholdMonitor exists "
92  << tmTarget.id() << std::endl;
93  delete query;
94  commitSession();
95  throw std::runtime_error( "ThresholdMonitorLoader >> ThresholdMonitor not available" );
96  }
97 
98  const coral::AttributeList& row = cursor.currentRow();
99  long trigger_threshold_id =0;
100  trigger_threshold_id = row["L1TM2TTM_TRIGGER_THRESHOLD_ID"].data<long>();
101  int internal_counter =0;
102  internal_counter = row["L1TM2TTM_INTERNAL_COUNTER"].data<int>();
103  int multiplicity;
104  multiplicity = row["L1TM2TTM_MULTIPLICITY"].data<int>();
105  long bunch_group_id=0;
106  if(schema <= 6) bunch_group_id = row["L1TM2TTM_BUNCH_GROUP_SET_ID"].data<long>();
107  else if(schema > 6) bunch_group_id = row["L1TM2TTM_BUNCH_GROUP_ID"].data<long>();
108  std::string countertype="";
109  countertype = row["L1TM2TTM_COUNTER_TYPE"].data<std::string>();
110  std::string name="";
111  name = row["L1TM2TTM_NAME"].data<std::string>();
112 
113  // Fill the vector with data
114  tmTarget.setName(name);
115  tmTarget.setThresholdId(trigger_threshold_id);
116  tmTarget.setInternalCounter(internal_counter );
117  tmTarget.setMultiplicity(multiplicity);
118 
119  tmTarget.setCounterType(countertype );
120  tmTarget.setBunchGroupId(bunch_group_id );
121 
122  // now given the threshold id get the name, type, bit,
123  // etc. of the threshold
124  coral::ITable& tableThresh = m_session.nominalSchema().tableHandle( "L1_TRIGGER_THRESHOLD");
125  coral::IQuery* queryThresh = tableThresh.newQuery();
126  queryThresh->setRowCacheSize( 4 );
127 
128  //Binding
129  std::string cond = "L1TT_ID = :threshId";
131  alist.extend<long>("threshId");
132  alist[0].data<long>() = static_cast<long>(trigger_threshold_id);
133  queryThresh->setCondition( cond, alist );
134 
135  //Output and types
136  coral::AttributeList attList1;
137  attList1.extend<std::string>( "L1TT_NAME" );
138  attList1.extend<int>( "L1TT_ACTIVE" );
139  queryThresh->defineOutput(attList1);
140  queryThresh->addToOutputList( "L1TT_NAME" );
141  queryThresh->addToOutputList( "L1TT_ACTIVE" );
142 
143  coral::ICursor& cursorThresh = queryThresh->execute();
144  if ( ! cursorThresh.next() ) {
145  msg() << "ThresholdMonitorLoader >> No such trigger threshold exists : " << trigger_threshold_id << std::endl;
146  delete query;
147  delete queryThresh;
148  commitSession();
149  throw std::runtime_error( "ThresholdMonitorLoader >> TriggerThreshold not available" );
150  }
151 
152  const coral::AttributeList& rowThresh = cursorThresh.currentRow();
153  tmTarget.setThresholdName( rowThresh["L1TT_NAME"].data<std::string>() );
154  tmTarget.setThresholdActive( rowThresh["L1TT_ACTIVE"].data<int>() );
155 
156  // now retrieve the first and last bit of the threshold, and
157  // the ctpin mapping
158  coral::ITable& tableTMTOTT = m_session.nominalSchema().tableHandle( "L1_TM_TO_TT");
159  coral::IQuery* queryTMTOTT = tableTMTOTT.newQuery();
160  queryTMTOTT->setRowCacheSize( 5 );
161 
162  //Binding
163  cond = "L1TM2TT_TRIGGER_THRESHOLD_ID = :ttId AND L1TM2TT_TRIGGER_MENU_ID = :menuId";
164  coral::AttributeList alistTMTOTT;
165  alistTMTOTT.extend<long>("ttId");
166  alistTMTOTT.extend<long>("menuId");
167  alistTMTOTT[0].data<long>() = trigger_threshold_id;
168  alistTMTOTT[1].data<long>() = m_MenuId;
169  queryTMTOTT->setCondition( cond, alistTMTOTT );
170 
171  //Output and types
172  coral::AttributeList attList2;
173  attList2.extend<std::string>( "L1TM2TT_CABLE_CTPIN" );
174  attList2.extend<std::string>( "L1TM2TT_CABLE_CONNECTOR" );
175  attList2.extend<int>( "L1TM2TT_CABLE_START" );
176  attList2.extend<int>( "L1TM2TT_CABLE_END" );
177  queryTMTOTT->defineOutput(attList2);
178  queryTMTOTT->addToOutputList( "L1TM2TT_CABLE_CTPIN" );
179  queryTMTOTT->addToOutputList( "L1TM2TT_CABLE_CONNECTOR" );
180  queryTMTOTT->addToOutputList( "L1TM2TT_CABLE_START" );
181  queryTMTOTT->addToOutputList( "L1TM2TT_CABLE_END" );
182 
183  coral::ICursor& cursorTMTOTT = queryTMTOTT->execute();
184  if ( ! cursorTMTOTT.next() ) {
185  msg() << "ThresholdMonitorLoader >> No such trigger threshold ( " << trigger_threshold_id
186  << " ) or menu ( " << m_MenuId << " ) exists in table L1_TM_TO_TT" << std::endl;
187  delete query;
188  delete queryThresh;
189  delete queryTMTOTT;
190  commitSession();
191  throw std::runtime_error( "ThresholdMonitorLoader >> TriggerThreshold link entry not available" );
192  }
193  const coral::AttributeList& rowTMTOTT = cursorTMTOTT.currentRow();
194 
195  std::string slotString = rowTMTOTT["L1TM2TT_CABLE_CTPIN"].data<std::string>();
196  uint16_t slot = 0;
197  if(slotString.find("SLOT7") != std::string::npos) {
198  slot = 7;
199  } else if(slotString.find("SLOT8") != std::string::npos) {
200  slot = 8;
201  } else if(slotString.find("SLOT9") != std::string::npos) {
202  slot = 9;
203  } else {
204  msg() << "Unknown CTPIN string '" << slotString << "'" << std::endl;
205  delete query;
206  delete queryThresh;
207  delete queryTMTOTT;
208  commitSession();
209  throw std::runtime_error( "ThresholdMonitorLoader: Error loading Counters " );
210  }
211  tmTarget.setCtpinSlot( slot );
212  std::string conString = rowTMTOTT["L1TM2TT_CABLE_CONNECTOR"].data<std::string>();
213  uint16_t con = 99;
214  if(conString.find("CON0") != std::string::npos) {
215  con = 0;
216  } else if(conString.find("CON1") != std::string::npos) {
217  con = 1;
218  } else if(conString.find("CON2") != std::string::npos) {
219  con = 2;
220  } else if(conString.find("CON3") != std::string::npos) {
221  con = 3;
222  } else {
223  msg() << "Unknown CTPIN connector string '" << conString << "'" << std::endl;
224  delete query;
225  delete queryThresh;
226  delete queryTMTOTT;
227  commitSession();
228  throw std::runtime_error( "ThresholdMonitorLoader: Error loading Counters " );
229  }
230  tmTarget.setCtpinConnector(con);
231  tmTarget.setThresholdStartBit( rowTMTOTT["L1TM2TT_CABLE_START"].data<int>() );
232  tmTarget.setThresholdEndBit( rowTMTOTT["L1TM2TT_CABLE_END"].data<int>() );
233 
234  delete query;
235  delete queryThresh;
236  delete queryTMTOTT;
237  commitSession();
238  return true;
239  } catch( const coral::SchemaException& e ) {
240  msg() << "ThresholdMonitorLoader >> SchemaException: "
241 
242  << e.what() << std::endl;
243  m_session.transaction().rollback();
244  return false;
245  } catch( const std::exception& e ) {
246  msg() << "ThresholdMonitorLoader >> Standard C++ exception: " << e.what() << std::endl;
247 
248  m_session.transaction().rollback();
249  return false;
250  } catch( ... ) {
251  msg() << "ThresholdMonitorLoader >> unknown C++ exception" << std::endl;
252 
253  m_session.transaction().rollback();
254  return false;
255  }
256 }
257 
259  m_MenuId = id;
260 }
261 
263  return m_MenuId;
264 }
265 
TrigConf::TrigConfData::setName
void setName(const std::string &name)
Definition: TrigConfData.h:30
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
query_example.row
row
Definition: query_example.py:24
TrigConf::ThresholdMonitor::setCounterType
void setCounterType(const std::string &countertype)
Definition: ThresholdMonitor.h:44
TrigConf::DBLoader::verbose
virtual int verbose() const override
Definition: DBLoader.h:57
TrigConf::DBLoader::triggerDBSchemaVersion
unsigned int triggerDBSchemaVersion()
Definition: DBLoader.cxx:76
ThresholdMonitor.h
python.PyKernel.AttributeList
AttributeList
Definition: PyKernel.py:36
TrigConf::DBLoader::m_session
coral::ISessionProxy & m_session
CORAL interface to database session.
Definition: DBLoader.h:68
TrigConf::ThresholdMonitorLoader::m_MenuId
long m_MenuId
Definition: ThresholdMonitorLoader.h:38
TrigConf::ThresholdMonitor
Definition: ThresholdMonitor.h:18
CheckTagAssociation.schema
schema
Definition: CheckTagAssociation.py:22
query
Definition: query.py:1
xAOD::uint16_t
setWord1 uint16_t
Definition: eFexEMRoI_v1.cxx:88
StorageMgr.h
TrigConf::ThresholdMonitor::setThresholdId
void setThresholdId(const int &id)
Definition: ThresholdMonitor.h:40
TrigConf::TrigConfMessaging::msg
MsgStreamTC & msg() const
The standard message stream.
Definition: TrigConfMessaging.h:81
calibdata.exception
exception
Definition: calibdata.py:496
TrigConf::ThresholdMonitor::setThresholdEndBit
void setThresholdEndBit(const int &bit)
Definition: ThresholdMonitor.h:49
TrigConf::ThresholdMonitor::setInternalCounter
void setInternalCounter(const int &internalcounter)
Definition: ThresholdMonitor.h:42
query_example.query
query
Definition: query_example.py:15
TrigConf::name
Definition: HLTChainList.h:35
TrigConf::ThresholdMonitorLoader::menuId
long menuId()
Definition: ThresholdMonitorLoader.cxx:262
TrigConf::ThresholdMonitorLoader::setMenuId
void setMenuId(const long &id)
Definition: ThresholdMonitorLoader.cxx:258
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:220
TrigConf::TrigConfData::id
unsigned int id() const
Definition: TrigConfData.h:21
TrigConf::ThresholdMonitor::setCtpinConnector
void setCtpinConnector(const uint16_t &con)
Definition: ThresholdMonitor.h:47
TrigConf::ThresholdMonitor::setBunchGroupId
void setBunchGroupId(const int &bunchgroupid)
Definition: ThresholdMonitor.h:43
python.ext.table_printer.table
list table
Definition: table_printer.py:81
L1DataDef.h
collListGuids.alist
alist
Definition: collListGuids.py:68
TrigConf::ThresholdMonitor::setMultiplicity
void setMultiplicity(const int &multiplicity)
Definition: ThresholdMonitor.h:41
TrigConf::DBLoader::commitSession
void commitSession()
commit session if not already done
Definition: DBLoader.cxx:45
query_example.cursor
cursor
Definition: query_example.py:21
TrigConf::DBLoader::startSession
void startSession()
start session if not already active
Definition: DBLoader.cxx:35
TrigConf::ThresholdMonitor::setThresholdStartBit
void setThresholdStartBit(const int &bit)
Definition: ThresholdMonitor.h:48
ThresholdMonitorLoader.h
TrigConf::ThresholdMonitorLoader::load
virtual bool load(ThresholdMonitor &data) override
Definition: ThresholdMonitorLoader.cxx:43
TrigConf::ThresholdMonitor::setCtpinSlot
void setCtpinSlot(const uint16_t &slot)
Definition: ThresholdMonitor.h:46
TrigConf::ThresholdMonitor::setThresholdName
void setThresholdName(const std::string &name)
Definition: ThresholdMonitor.h:45
TrigConf::ThresholdMonitor::setThresholdActive
void setThresholdActive(const bool &active)
Definition: ThresholdMonitor.h:50