13 #include <CoralBase/Attribute.h>
14 #include <CoralBase/AttributeList.h>
16 #include "RelationalAccess/SchemaException.h"
17 #include "RelationalAccess/ITransaction.h"
18 #include "RelationalAccess/ITable.h"
19 #include "RelationalAccess/ISchema.h"
20 #include "RelationalAccess/ICursor.h"
21 #include "RelationalAccess/IQuery.h"
39 #include "boost/lexical_cast.hpp"
45 const unsigned int schema_version_with_zb_fields = 9;
57 unique_ptr<coral::IQuery> query0(m_session.nominalSchema().tableHandle(
"L1_MASTER_TABLE").newQuery());
58 query0->setRowCacheSize( 5 );
62 bindList0.extend<
int>(
"mtId");
63 std::string cond0 =
"L1MT_ID = :mtId";
65 query0->setCondition( cond0, bindList0 );
69 attList0.extend<
int>(
"L1MT_TRIGGER_MENU_ID" );
70 attList0.extend<
long>(
"L1MT_CALO_INFO_ID" );
71 query0->defineOutput(attList0);
72 query0->addToOutputList(
"L1MT_TRIGGER_MENU_ID" );
73 query0->addToOutputList(
"L1MT_CALO_INFO_ID" );
74 coral::ICursor& cursor0 = query0->execute();
76 if ( ! cursor0.next() ) {
79 throw std::runtime_error(
"ThresholdConfigLoader >> ThresholdConfig not available" );
83 menuid = row0[
"L1MT_TRIGGER_MENU_ID"].data<
int>();
84 caloinfoid = row0[
"L1MT_CALO_INFO_ID"].data<
long>();
86 if ( cursor0.next() ) {
88 TRG_MSG_ERROR(
"ThresholdConfigLoader >> More than one Master_Table exists "
91 throw std::runtime_error(
"ThresholdConfigLoader >> Master_Table not available" );
99 unique_ptr<coral::IQuery>
query(m_session.nominalSchema().newQuery());
102 query->addToTableList (
"L1_TM_TO_TT",
"TM2TT" );
103 query->addToTableList (
"L1_TRIGGER_THRESHOLD",
"TT" );
104 query->addToTableList (
"L1_TT_TO_TTV",
"TT2TTV" );
105 query->addToTableList (
"L1_TRIGGER_THRESHOLD_VALUE",
"TTV" );
109 bindList.extend<
int>(
"menuId");
110 bindList[0].data<
int>() = menuid;
111 std::string theCondition =
"";
112 theCondition += std::string(
" TM2TT.L1TM2TT_TRIGGER_MENU_ID = :menuId" );
113 theCondition += std::string(
" AND TM2TT.L1TM2TT_TRIGGER_THRESHOLD_ID = TT.L1TT_ID" );
114 theCondition += std::string(
" AND TT2TTV.L1TT2TTV_TRIGGER_THRESHOLD_ID = TT.L1TT_ID" );
115 theCondition += std::string(
" AND TT2TTV.L1TT2TTV_TRIG_THRES_VALUE_ID = TTV.L1TTV_ID" );
116 query->setCondition( theCondition, bindList );
120 attList.extend<std::string>(
"TM2TT.L1TM2TT_CABLE_NAME" );
121 attList.extend<std::string>(
"TM2TT.L1TM2TT_CABLE_CTPIN" );
122 attList.extend<std::string>(
"TM2TT.L1TM2TT_CABLE_CONNECTOR" );
123 attList.extend<
int> (
"TM2TT.L1TM2TT_CABLE_START" );
124 attList.extend<
int> (
"TM2TT.L1TM2TT_CABLE_END" );
126 attList.extend<
int> (
"TM2TT.L1TM2TT_CABLE_CLOCK" );
128 attList.extend<
int> (
"TT.L1TT_ID" );
129 attList.extend<std::string>(
"TT.L1TT_NAME" );
130 attList.extend<
int> (
"TT.L1TT_VERSION" );
131 attList.extend<std::string>(
"TT.L1TT_TYPE" );
132 attList.extend<
int> (
"TT.L1TT_ACTIVE" );
133 attList.extend<
int> (
"TT.L1TT_MAPPING" );
134 attList.extend<
int> (
"TT.L1TT_BITNUM" );
135 attList.extend<
int> (
"TTV.L1TTV_ID" );
136 attList.extend<std::string>(
"TTV.L1TTV_NAME" );
137 attList.extend<
int> (
"TTV.L1TTV_VERSION" );
138 attList.extend<std::string>(
"TTV.L1TTV_TYPE" );
139 attList.extend<std::string>(
"TTV.L1TTV_PT_CUT" );
140 attList.extend<
int> (
"TTV.L1TTV_ETA_MIN" );
141 attList.extend<
int> (
"TTV.L1TTV_ETA_MAX" );
142 attList.extend<
int> (
"TTV.L1TTV_PHI_MIN" );
143 attList.extend<
int> (
"TTV.L1TTV_PHI_MAX" );
144 attList.extend<std::string>(
"TTV.L1TTV_EM_ISOLATION" );
145 attList.extend<std::string>(
"TTV.L1TTV_HAD_ISOLATION" );
146 attList.extend<std::string>(
"TTV.L1TTV_HAD_VETO" );
147 attList.extend<
int> (
"TTV.L1TTV_WINDOW" );
148 attList.extend<std::string>(
"TTV.L1TTV_PRIORITY" );
152 std::string theOrder =
"";
153 theOrder +=
" TT.L1TT_MAPPING ASC";
154 theOrder +=
", TT.L1TT_ID ASC";
155 theOrder +=
", TTV.L1TTV_PRIORITY ASC";
156 theOrder +=
", TTV.L1TTV_ETA_MAX ASC";
157 query->addToOrderList( theOrder );
160 query->setRowCacheSize(500);
164 unsigned int schema_version = triggerDBSchemaVersion();
167 int nRowsLoop1 = -2009;
168 int nRowsLoop2 = -2010;
174 nRowsLoop1 =
row[
"TT.L1TT_ID"].data<
int>();
175 if (nRowsLoop1 != nRowsLoop2) {
190 string cableName =
row[
"TM2TT.L1TM2TT_CABLE_NAME"].data<std::string>();
191 tt->setCableName (cableName);
192 tt->setCableCtpin (
row[
"TM2TT.L1TM2TT_CABLE_CTPIN"].data<std::string>());
193 tt->setCableConnector(
row[
"TM2TT.L1TM2TT_CABLE_CONNECTOR"].data<std::string>());
194 tt->setCableStart (
row[
"TM2TT.L1TM2TT_CABLE_START"].data<int>());
195 tt->setCableEnd (
row[
"TM2TT.L1TM2TT_CABLE_END"].data<int>());
199 clock =
row[
"TM2TT.L1TM2TT_CABLE_CLOCK"].data<
int>();
204 tt->setId (
row[
"TT.L1TT_ID"].data<int>());
205 tt->setName (
row[
"TT.L1TT_NAME"].data<std::string>());
206 tt->setVersion(
row[
"TT.L1TT_VERSION"].data<int>());
207 string thrtype(
row[
"TT.L1TT_TYPE"].data<std::string>());
208 tt->setType (thrtype);
209 tt->setActive (
row[
"TT.L1TT_ACTIVE"].data<int>());
210 tt->setMapping(
row[
"TT.L1TT_MAPPING"].data<int>());
211 tt->setBitnum(
row[
"TT.L1TT_BITNUM"].data<int>());
212 tt->setInput ( (thrtype==
"TOPO" || thrtype==
"ALFA") ?
"ctpcore" :
"ctpin" );
214 TRG_MSG_VERBOSE(
"ThresholdConfigLoader loading threshold with ID = " <<
tt->id() <<
" for MenuId = " << menuid <<
": ");
217 if(
tt->type() == L1DataDef::rndmType() ||
218 tt->type() == L1DataDef::pclkType() ||
219 tt->type() == L1DataDef::bgrpType() ) {
224 ttv->
setId (
row[
"TTV.L1TTV_ID"].data<int>());
227 ttv->
setName (
row[
"TTV.L1TTV_NAME"].data<std::string>());
229 ttv->
setType (
row[
"TTV.L1TTV_TYPE"].data<std::string>());
230 float ptcut = boost::lexical_cast<float,std::string>(
row[
"TTV.L1TTV_PT_CUT"].data<std::string>());
231 string emisolation =
row[
"TTV.L1TTV_EM_ISOLATION"].data<std::string>();
232 string hadisolation =
row[
"TTV.L1TTV_HAD_ISOLATION"].data<std::string>();
233 string hadveto =
row[
"TTV.L1TTV_HAD_VETO"].data<std::string>();
234 float priority = boost::lexical_cast<float,std::string>(
row[
"TTV.L1TTV_PRIORITY"].data<std::string>());
241 if (ttv->
type() != L1DataDef::emType() &&
242 ttv->
type() != L1DataDef::tauType()) {
243 msg() <<
"ThresholdConfigLoader >> No type match for ttv_id = "
244 << ctv.
id() <<
" " << ttv->
type() << std::endl;
245 throw std::runtime_error(
"ThresholdConfigLoader >> ClusterThresholdValue not available" );
248 if(hadveto==
"USEISOBITS" || boost::lexical_cast<int,std::string>(hadveto)==99 ) {
255 ctv.
setEmIsolation( boost::lexical_cast<float,std::string>(emisolation) );
256 ctv.
setHadIsolation( boost::lexical_cast<float,std::string>(hadisolation) );
257 ctv.
setHadVeto( boost::lexical_cast<float,std::string>(hadveto) );
261 }
catch (std::bad_cast& ex) { }
267 ttv->
type() != L1DataDef::jbType() &&
268 ttv->
type() != L1DataDef::jfType()) {
270 throw std::runtime_error(
"ThresholdConfigLoader >> TriggerThresholdValue not available" );
277 }
catch (std::bad_cast& ex) { }
284 tt->addThresholdValue(ttv);
286 TRG_MSG_DEBUG(
"ThresholdConfigLoader loading thresholdvalue with ID = " << ttv->
id() <<
": " << ttv->
name());
289 nRowsLoop2 =
row[
"TT.L1TT_ID"].data<
int>();
301 if (!m_session.transaction().isActive()) m_session.transaction().start();
302 unique_ptr<coral::IQuery> query1(m_session.nominalSchema().newQuery());
305 query1->addToTableList (
"L1_TM_TO_TT",
"TM2TT" );
306 query1->addToTableList (
"L1_TRIGGER_THRESHOLD",
"TT" );
310 bindList1.extend<
int>(
"menuId");
311 bindList1[0].data<
int>() = menuid;
312 std::string theCondition1 =
"";
313 theCondition1 += std::string(
" TM2TT.L1TM2TT_TRIGGER_MENU_ID = :menuId" );
314 theCondition1 += std::string(
" AND TM2TT.L1TM2TT_TRIGGER_THRESHOLD_ID = TT.L1TT_ID" );
315 query1->setCondition( theCondition1, bindList1 );
319 attList1.extend<std::string>(
"TM2TT.L1TM2TT_CABLE_NAME" );
320 attList1.extend<std::string>(
"TM2TT.L1TM2TT_CABLE_CTPIN" );
321 attList1.extend<std::string>(
"TM2TT.L1TM2TT_CABLE_CONNECTOR" );
322 attList1.extend<
int> (
"TM2TT.L1TM2TT_CABLE_START" );
323 attList1.extend<
int> (
"TM2TT.L1TM2TT_CABLE_END" );
325 attList1.extend<
int> (
"TM2TT.L1TM2TT_CABLE_CLOCK" );
327 attList1.extend<
int> (
"TT.L1TT_ID" );
328 attList1.extend<std::string>(
"TT.L1TT_NAME" );
329 attList1.extend<
int> (
"TT.L1TT_VERSION" );
330 attList1.extend<std::string>(
"TT.L1TT_TYPE" );
331 attList1.extend<
int> (
"TT.L1TT_ACTIVE" );
332 attList1.extend<
int> (
"TT.L1TT_MAPPING" );
333 if(
isRun2() || (schema_version >= schema_version_with_zb_fields) ) {
334 attList1.extend<
int> (
"TT.L1TT_BCDELAY" );
335 attList1.extend<std::string>(
"TT.L1TT_SEED" );
336 attList1.extend<
int> (
"TT.L1TT_SEED_MULTI" );
341 std::string theOrder1 =
"";
342 theOrder1 +=
" TT.L1TT_ID ASC";
343 query1->addToOrderList( theOrder1 );
346 query1->setRowCacheSize(500);
348 coral::ICursor& cursor1 = query1->execute();
355 while (cursor1.next()) {
359 nRowsLoop1 =
row[
"TT.L1TT_ID"].data<
int>();
362 if (nRowsLoop1 != nRowsLoop2) {
380 string cableName =
row[
"TM2TT.L1TM2TT_CABLE_NAME"].data<std::string>();
381 tt->setCableName(cableName);
382 tt->setCableCtpin (
row[
"TM2TT.L1TM2TT_CABLE_CTPIN"].data<std::string>());
383 tt->setCableConnector(
row[
"TM2TT.L1TM2TT_CABLE_CONNECTOR"].data<std::string>());
384 tt->setCableStart (
row[
"TM2TT.L1TM2TT_CABLE_START"].data<int>());
385 tt->setCableEnd (
row[
"TM2TT.L1TM2TT_CABLE_END"].data<int>());
389 clock =
row[
"TM2TT.L1TM2TT_CABLE_CLOCK"].data<
int>();
394 tt->setId (
row[
"TT.L1TT_ID"].data<int>());
395 tt->setName (
row[
"TT.L1TT_NAME"].data<std::string>());
396 tt->setVersion(
row[
"TT.L1TT_VERSION"].data<int>());
397 string thrtype(
row[
"TT.L1TT_TYPE"].data<std::string>());
398 tt->setType (thrtype);
399 tt->setActive (
row[
"TT.L1TT_ACTIVE"].data<int>());
400 tt->setMapping(
row[
"TT.L1TT_MAPPING"].data<int>());
401 tt->setInput ( (thrtype==
"TOPO" || thrtype==
"ALFA") ?
"ctpcore" :
"ctpin" );
405 int bcdelay(-1), seed_multi(-1);
406 std::string seed(
"");
407 if(
isRun2() || (schema_version >= schema_version_with_zb_fields) ) {
408 bcdelay =
row[
"TT.L1TT_BCDELAY"].data<
int>();
409 seed =
row[
"TT.L1TT_SEED"].data<std::string>();
410 seed_multi =
row[
"TT.L1TT_SEED_MULTI"].data<
int>();
412 tt->setBCDelay (bcdelay);
413 tt->setZBSeedingThresholdName (seed);
414 tt->setZBSeedingThresholdMulti(seed_multi);
416 TRG_MSG_VERBOSE(
"ThresholdConfigLoader loading threshold with ID = " <<
tt->id() <<
" for MenuId = " << menuid <<
": ");
423 nRowsLoop2 =
row[
"TT.L1TT_ID"].data<
int>();
428 catch(
const coral::Exception&
e ) {
437 loadCaloInfo(thrConfig, caloinfoid);
455 ((
dynamic_cast<StorageMgr&
>(m_storageMgr)).caloInfoLoader());
458 ci.
setId(caloInfoId);
459 if ( !cildr.
load( ci )) {
461 throw runtime_error(
"ThresholdConfigLoader: Error loading CaloInfo" );
464 TriggerThresholdValue::setCaloInfo(ci);
467 catch(
const coral::Exception&
e ) {