ATLAS Offline Software
Loading...
Searching...
No Matches
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
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;
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";
130 coral::AttributeList alist;
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;
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;
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;
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;
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;
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
265
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
virtual int verbose() const override
Definition DBLoader.h:57
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(ThresholdMonitor &data) override
void setCtpinSlot(const uint16_t &slot)
void setThresholdStartBit(const int &bit)
void setInternalCounter(const int &internalcounter)
void setThresholdName(const std::string &name)
void setBunchGroupId(const int &bunchgroupid)
void setMultiplicity(const int &multiplicity)
void setThresholdEndBit(const int &bit)
void setCtpinConnector(const uint16_t &con)
void setThresholdActive(const bool &active)
void setThresholdId(const int &id)
void setCounterType(const std::string &countertype)
unsigned int id() const
void setName(const std::string &name)
MsgStreamTC & msg() const
The standard message stream.
Definition query.py:1