23#include "boost/algorithm/string.hpp"
36 if(
menu.smk()<=0)
return false;
52 catch(
const coral::Exception& e ) {
57 catch(
const std::exception& e ) {
72 .triggerThresholdLoader() );
78 std::map<int,TriggerThreshold*> thresholdNotFoundCache;
80 unique_ptr< coral::IQuery >
query(
m_session.nominalSchema().newQuery() );
81 query->addToTableList (
"L1_TM_TO_TI",
"TM2TI" );
82 query->addToTableList (
"L1_TRIGGER_ITEM",
"TI" );
83 query->addToTableList (
"L1_TI_TO_TT",
"TI2TT" );
86 coral::AttributeList bindList;
87 bindList.extend<
int>(
"menuId");
88 bindList[0].data<
int>() =
menu.id();
90 std::string theCondition =
"";
91 theCondition += std::string(
" TM2TI.L1TM2TI_TRIGGER_MENU_ID = :menuId" );
92 theCondition += std::string(
" AND TM2TI.L1TM2TI_TRIGGER_ITEM_ID = TI.L1TI_ID" );
93 theCondition += std::string(
" AND TI2TT.L1TI2TT_TRIGGER_ITEM_ID = TI.L1TI_ID" );
95 query->setCondition( theCondition, bindList );
98 coral::AttributeList attList;
99 attList.extend<
int> (
"TI.L1TI_ID" );
100 attList.extend<std::string>(
"TI.L1TI_NAME" );
101 attList.extend<
int> (
"TI.L1TI_VERSION" );
103 attList.extend<
int> (
"TI.L1TI_PARTITION" );
104 attList.extend<
string> (
"TI.L1TI_MONITOR" );
106 attList.extend<
int> (
"TI.L1TI_CTP_ID" );
107 attList.extend<std::string>(
"TI.L1TI_PRIORITY" );
108 attList.extend<std::string>(
"TI.L1TI_DEFINITION" );
109 attList.extend<
int> (
"TI.L1TI_TRIGGER_TYPE" );
110 attList.extend<
int> (
"TI2TT.L1TI2TT_TRIGGER_THRESHOLD_ID" );
111 attList.extend<
int> (
"TI2TT.L1TI2TT_POSITION" );
112 attList.extend<
int> (
"TI2TT.L1TI2TT_MULTIPLICITY" );
116 std::string theOrder =
"";
118 theOrder +=
" TI.L1TI_CTP_ID ASC";
120 theOrder +=
", TI2TT.L1TI2TT_POSITION ASC";
121 query->addToOrderList( theOrder );
124 query->setRowCacheSize(500);
126 query->setDistinct();
128 coral::ICursor& cursor =
query->execute();
132 map<int,vector<ThrInfo> > item_thrInfo;
135 while (cursor.next()) {
137 const coral::AttributeList& row = cursor.currentRow();
138 int ctpid = row[
"TI.L1TI_CTP_ID"].data<
int>();
142 item->setCtpId (ctpid);
143 item->setId (row[
"TI.L1TI_ID"].
data<int>());
145 item->setVersion (row[
"TI.L1TI_VERSION"].
data<int>());
147 item->setPartition (row[
"TI.L1TI_PARTITION"].
data<int>());
148 string mon = row[
"TI.L1TI_MONITOR"].data<
string>();
149 unsigned short monMask = 0;
151 const short TBP = 0x1;
152 const short TAP = 0x2;
153 const short TAV = 0x4;
155 vector<string> monLfHf;
156 boost::split(monLfHf, mon, boost::is_any_of(
":|"));
159 if(monLfHf.size()==4 && monLfHf[0]==
"LF" && monLfHf[2]==
"HF" && monLfHf[1].size()==3 && monLfHf[3].size()==3) {
161 if( monLfHf[1][2]==
'1' ) monMask |= TBP;
162 if( monLfHf[1][1]==
'1' ) monMask |= TAP;
163 if( monLfHf[1][0]==
'1' ) monMask |= TAV;
165 if( monLfHf[3][2]==
'1' ) monMask |= TBP << 3;
166 if( monLfHf[3][1]==
'1' ) monMask |= TAP << 3;
167 if( monLfHf[3][0]==
'1' ) monMask |= TAV << 3;
170 if(mon.find(
"TBP") != string::npos) monMask |= TBP;
171 if(mon.find(
"TAP") != string::npos) monMask |= TAP;
172 if(mon.find(
"TAV") != string::npos) monMask |= TAV;
174 item->setMonitor( monMask );
177 string priority = row[
"TI.L1TI_PRIORITY"].data<
string>();
178 if(priority==
"0" || priority==
"HIGH") {
179 item->setComplexDeadtime(0);
180 }
else if(priority==
"1" || priority==
"LOW") {
181 item->setComplexDeadtime(1);
183 item->setDefinition (row[
"TI.L1TI_DEFINITION"].
data<string>());
184 item->setTriggerType(row[
"TI.L1TI_TRIGGER_TYPE"].
data<int>());
185 menu.addTriggerItem(item);
187 msg() <<
"MenuLoader: Created Item " << item->name() <<
" with CTPID " << item->ctpId() << endl;
188 item_thrInfo[ctpid] = vector<ThrInfo>();
189 ctpIDs.push_back(ctpid);
193 thr_info.
thrId = row[
"TI2TT.L1TI2TT_TRIGGER_THRESHOLD_ID"].data<
int>();
194 thr_info.
thrPos = row[
"TI2TT.L1TI2TT_POSITION"].data<
int>();
195 thr_info.
thrMult = row[
"TI2TT.L1TI2TT_MULTIPLICITY"].data<
int>();
196 thr_info.
thr =
menu.thresholdConfig().findTriggerThreshold(thr_info.
thrId);
197 if(thr_info.
thr==0) {
201 if ( ! ttldr.
load( *thr_info.
thr ) ) {
202 msg() <<
"MenuLoader: Error loading TriggerThreshold " << thr_info.
thrId << endl;
203 throw runtime_error(
"MenuLoader::loadItems: error loading TriggerThreshold " );
205 menu.thresholdConfig().addTriggerThreshold(thr_info.
thr);
207 item_thrInfo[ctpid].push_back(thr_info);
211 for(
int ctpid : ctpIDs) {
214 msg() <<
"MenuLoader: Number of thresholds for item " << titem->
name()
215 <<
": " << item_thrInfo[ctpid].size() <<
" - definition: " << titem->
definition() << endl;
228 unsigned int n = logic.
parse(definition);
230 msg() <<
"Error parsing item definition : " << definition << std::endl;
233 unsigned int size = thr_infos.size();
235 msg() <<
"Total number of elements are different: "
236 <<
" input=" << size <<
", parsed=" << n << endl;
248 const std::vector<std::shared_ptr<LogicExpression>> & sub_logics = def.
subLogics();
250 switch (def.
state()) {
253 unsigned int pos =
static_cast<unsigned int>(std::stoul(def.
element()));
268 for(
auto sl : sub_logics)
272 if(sub_logics.size()>0) {
274 for(
auto sl : sub_logics)
280 for(
auto sl : sub_logics)
301 unique_ptr< coral::IQuery > q(
m_session.nominalSchema().newQuery());
302 q->addToTableList (
"L1_TM_TO_TT_MON",
"TM2TTM" );
303 q->addToTableList (
"L1_TRIGGER_THRESHOLD",
"TT" );
304 q->addToTableList (
"L1_TM_TO_TT",
"TM2TT" );
307 coral::AttributeList bindings;
308 bindings.extend<
int>(
"menuId");
309 bindings[0].data<
int>() =
menu.id();
312 cond +=
" TM2TTM.L1TM2TTM_TRIGGER_MENU_ID = :menuId";
313 cond +=
" AND TM2TT.L1TM2TT_TRIGGER_MENU_ID = :menuId";
314 cond +=
" AND TM2TTM.L1TM2TTM_TRIGGER_THRESHOLD_ID = TM2TT.L1TM2TT_TRIGGER_THRESHOLD_ID";
315 cond +=
" AND TM2TT.L1TM2TT_TRIGGER_THRESHOLD_ID = TT.L1TT_ID";
317 q->setCondition( cond, bindings );
320 coral::AttributeList output;
321 output.extend<std::string>(
"TM2TTM.L1TM2TTM_NAME" );
322 output.extend<
int> (
"TM2TTM.L1TM2TTM_TRIGGER_THRESHOLD_ID" );
323 output.extend<
int> (
"TM2TTM.L1TM2TTM_INTERNAL_COUNTER" );
324 output.extend<
int> (
"TM2TTM.L1TM2TTM_MULTIPLICITY" );
325 output.extend<
long> (
"TM2TTM.L1TM2TTM_BUNCH_GROUP_ID" );
326 output.extend<std::string>(
"TM2TTM.L1TM2TTM_COUNTER_TYPE" );
327 output.extend<std::string>(
"TT.L1TT_NAME" );
328 output.extend<
int> (
"TT.L1TT_ACTIVE" );
329 output.extend<std::string>(
"TM2TT.L1TM2TT_CABLE_CTPIN" );
330 output.extend<std::string>(
"TM2TT.L1TM2TT_CABLE_CONNECTOR" );
331 output.extend<
int> (
"TM2TT.L1TM2TT_CABLE_START" );
332 output.extend<
int> (
"TM2TT.L1TM2TT_CABLE_END" );
335 q->setRowCacheSize(500);
337 coral::ICursor& cursor = q->execute();
340 while (cursor.next()) {
341 const coral::AttributeList& row = cursor.currentRow();
353 string slotString = row[
"TM2TT.L1TM2TT_CABLE_CTPIN"].data<std::string>();
354 uint16_t slot = slotString[4]-
'0';
355 if(slot<7 || slot>9) {
356 TRG_MSG_ERROR(
"Unknown CTPIN string '" << slotString <<
"'");
357 throw runtime_error(
"MenuLoader (ThresholdMonitor): Error loading Monitoring counters " );
361 string conString = row[
"TM2TT.L1TM2TT_CABLE_CONNECTOR"].data<std::string>();
362 uint16_t con = conString[3]-
'0';
364 TRG_MSG_ERROR(
"Unknown CTPIN connector string '" << conString <<
"'");
365 throw runtime_error(
"MenuLoader (ThresholdMonitor): Error loading Monitoring counters " );
370 menu.addThresholdMonitor(tm);
391 if ( !thrldr->
load(
menu.thresholdConfig() ) ) {
393 throw runtime_error(
"MenuLoader: Error loading ThresholdConfig " );
398 if(
menu.pitVector().size() ==
menu.tipVector().size() ) {
415 set<int> tipNumbersUsed;
418 unique_ptr< coral::IQuery > q(
m_session.nominalSchema().newQuery() );
419 q->addToTableList (
"L1_TM_TO_TT",
"TM2TT" );
420 q->addToTableList (
"L1_PITS",
"PITS" );
423 coral::AttributeList bindings;
424 bindings.extend<
int>(
"menuId");
425 bindings[0].data<
int>() =
menu.id();
427 std::string cond(
"TM2TT.L1TM2TT_TRIGGER_MENU_ID = :menuId");
428 cond +=
" AND PITS.L1PIT_TM_TO_TT_ID = TM2TT.L1TM2TT_ID";
429 q->setCondition( cond, bindings );
435 coral::AttributeList attList;
436 attList.extend<
int>(
"TM2TT.L1TM2TT_TRIGGER_THRESHOLD_ID" );
437 attList.extend<
int>(
"TM2TT.L1TM2TT_ID" );
438 attList.extend<
int>(
"PITS.L1PIT_PIT_NUMBER" );
439 attList.extend<
int>(
"PITS.L1PIT_THRESHOLD_BIT" );
442 uint npits(0), ntips(0);
444 coral::ICursor& cursor = q->execute();
445 while (cursor.next()) {
446 const coral::AttributeList& row = cursor.currentRow();
448 int ttid = row[
"TM2TT.L1TM2TT_TRIGGER_THRESHOLD_ID"].data<
int>();
449 int tmtott = row[
"TM2TT.L1TM2TT_ID"].data<
int>();
450 int tipnum = row[
"PITS.L1PIT_PIT_NUMBER"].data<
int>();
451 int bitnum = row[
"PITS.L1PIT_THRESHOLD_BIT"].data<
int>();
456 string slotString = tt->cableCtpin();
458 if( boost::iequals( slotString,
"CTPCORE" ) ) {
461 slot = slotString[4]-
'0';
463 if(slot<7 || slot>10) {
465 throw runtime_error(
"MenuLoader: Error loading PITs " );
468 string conString = tt->cableConnector();
469 uint16_t con = conString[3]-
'0';
470 uint16_t conMax = slot==10 ? 2 : 3;
472 TRG_MSG_ERROR(
"Unknown CTPIN CONNECTOR '" << conString <<
"'");
473 throw runtime_error(
"MenuLoader: Error loading PITs " );
493 if(tipNumbersUsed.count(tipnum) > 0) {
494 tipnum = tipnum + 160;
496 tipNumbersUsed.insert(tipnum);
519 TRG_MSG_INFO(
"Loaded " << npits <<
" PITs and " << ntips <<
" TIPs");
520 TRG_MSG_INFO(
"Menu has " <<
menu.pitVector().size() <<
" PITs and " <<
menu.tipVector().size() <<
" TIPs");
531 unsigned int ntips(0);
536 const string & conn = thr->cableConnector();
538 unsigned int connector = conn[3]-
'0';
539 unsigned int cableOffset = 320 + connector * 64;
540 unsigned int cableBit = (
unsigned int) thr->cableStart();
541 unsigned int clock = thr->clock();
542 unsigned int tipNumber = 2*cableBit + clock + cableOffset;
564 TRG_MSG_INFO(
"Number of TIPs from direct input thresholds " << ntips );
577 menu.setCaloInfo(ci);
588 unique_ptr< coral::IQuery > q(
m_session.nominalSchema().newQuery() );
589 q->addToTableList (
"SUPER_MASTER_TABLE",
"SM" );
590 q->addToTableList (
"L1_MASTER_TABLE",
"MT" );
591 q->addToTableList (
"L1_TRIGGER_MENU",
"TM" );
594 coral::AttributeList bindings;
595 bindings.extend<
int>(
"smk");
596 bindings[0].data<
int>() =
menu.smk();
598 string condition(
"");
599 condition +=
"SM.SMT_ID = :smk";
600 condition +=
" AND SM.SMT_L1_MASTER_TABLE_ID = MT.L1MT_ID";
601 condition +=
" AND MT.L1MT_TRIGGER_MENU_ID = TM.L1TM_ID";
602 q->setCondition( condition , bindings );
605 coral::AttributeList attList;
606 attList.extend<
int>(
"TM.L1TM_ID");
607 attList.extend<
string>(
"TM.L1TM_NAME");
608 attList.extend<
int>(
"TM.L1TM_VERSION");
609 attList.extend<
int>(
"MT.L1MT_ID" );
612 coral::ICursor& cursor = q->execute();
613 if ( ! cursor.next() ) {
615 throw runtime_error(
"MenuLoader: ERROR trigger menu not available" );
619 const coral::AttributeList& row = cursor.currentRow();
623 menu.thresholdConfig().setLvl1MasterTableId( row[
"MT.L1MT_ID"].
data<int>() );
char data[hepevt_bytes_allocation_ATLAS]
StorageMgr & m_storageMgr
reference to the storage manager
virtual MSGTC::Level outputLevel() const override
void commitSession()
commit session if not already done
virtual void setLevel(MSGTC::Level lvl) override
access to output stream
coral::ISessionProxy & m_session
CORAL interface to database session.
void startSession()
start session if not already active
static const char kAND
AND of sub-logics.
static const char kOPEN
empty logic but may have sub-logics.
const std::string & element() const
static const char kNOT
NOT of a sub-logic. (only one sub-logic)
static const char kELEMENT
simple element.
const LogicV_t & subLogics() const
int totalNumberOfElements() const
static const char kOR
OR of sub-logics.
virtual int parse(const std::string &expr, bool enclosed=false)
void setTriggerThresholdId(const int &id)
void setCtpinConnector(const uint16_t &id)
void setTmToTtId(const int &tmtottid)
void setThresholdActive(const bool &a)
void setCableBit(const uint16_t &num)
void setThresholdBit(const uint16_t &num)
void setThresholdName(const std::string &name)
void setCtpinSlot(const uint16_t &id)
void setPitNumber(const uint16_t &pitnumber)
void setThresholdMapping(const int16_t &m)
Database Storage Manager, controls the database session and the different loader classes for DB acces...
void setTmToTtId(const int &tmtottid)
void setThresholdName(const std::string &name)
void setTriggerThresholdId(const int &id)
void setTipNumber(const uint16_t &tipnumber)
uint16_t tipNumber() const
void setThresholdMapping(const int16_t &m)
void setConnector(const uint16_t &id)
void setThresholdActive(const bool &a)
void setSlot(const uint16_t &id)
void setThresholdBit(const uint16_t &num)
void setClock(const int &clock)
void setCableBit(const uint16_t &num)
void setIsDirect(const bool &a)
TriggerDB loader of the LVL1 trigger threshold configuration.
virtual bool load(ThresholdConfig &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)
void setId(unsigned int id)
void setName(const std::string &name)
const std::string & name() const
void setPosition(int pos)
void setMultiplicity(int mult)
void addChild(TriggerItemNode *node)
void setTriggerThreshold(TriggerThreshold *thr)
void setTopNode(TriggerItemNode *ptrnode)
const std::string & definition() const
TriggerDB loader of the LVL1 trigger thresholds.
void setLoadCableInfo(bool b)
void setMenuId(const int &id)
virtual bool load(TriggerThreshold &data) override
void fillQuery(coral::IQuery *q, coral::AttributeList &attList)