23 #include "boost/lexical_cast.hpp"
24 #include "boost/algorithm/string.hpp"
37 if(
menu.smk()<=0)
return false;
41 loadMenuAttributes(
menu);
53 catch(
const coral::Exception&
e ) {
73 .triggerThresholdLoader() );
79 std::map<int,TriggerThreshold*> thresholdNotFoundCache;
81 unique_ptr< coral::IQuery >
query( m_session.nominalSchema().newQuery() );
82 query->addToTableList (
"L1_TM_TO_TI",
"TM2TI" );
83 query->addToTableList (
"L1_TRIGGER_ITEM",
"TI" );
84 query->addToTableList (
"L1_TI_TO_TT",
"TI2TT" );
88 bindList.extend<
int>(
"menuId");
89 bindList[0].data<
int>() =
menu.id();
91 std::string theCondition =
"";
92 theCondition += std::string(
" TM2TI.L1TM2TI_TRIGGER_MENU_ID = :menuId" );
93 theCondition += std::string(
" AND TM2TI.L1TM2TI_TRIGGER_ITEM_ID = TI.L1TI_ID" );
94 theCondition += std::string(
" AND TI2TT.L1TI2TT_TRIGGER_ITEM_ID = TI.L1TI_ID" );
96 query->setCondition( theCondition, bindList );
100 attList.extend<
int> (
"TI.L1TI_ID" );
101 attList.extend<std::string>(
"TI.L1TI_NAME" );
102 attList.extend<
int> (
"TI.L1TI_VERSION" );
104 attList.extend<
int> (
"TI.L1TI_PARTITION" );
105 attList.extend<
string> (
"TI.L1TI_MONITOR" );
107 attList.extend<
int> (
"TI.L1TI_CTP_ID" );
108 attList.extend<std::string>(
"TI.L1TI_PRIORITY" );
109 attList.extend<std::string>(
"TI.L1TI_DEFINITION" );
110 attList.extend<
int> (
"TI.L1TI_TRIGGER_TYPE" );
111 attList.extend<
int> (
"TI2TT.L1TI2TT_TRIGGER_THRESHOLD_ID" );
112 attList.extend<
int> (
"TI2TT.L1TI2TT_POSITION" );
113 attList.extend<
int> (
"TI2TT.L1TI2TT_MULTIPLICITY" );
117 std::string theOrder =
"";
119 theOrder +=
" TI.L1TI_CTP_ID ASC";
121 theOrder +=
", TI2TT.L1TI2TT_POSITION ASC";
122 query->addToOrderList( theOrder );
125 query->setRowCacheSize(500);
127 query->setDistinct();
133 map<int,vector<ThrInfo> > item_thrInfo;
139 int ctpid =
row[
"TI.L1TI_CTP_ID"].data<
int>();
143 item->setCtpId (ctpid);
144 item->setId (
row[
"TI.L1TI_ID"].data<int>());
145 item->setName (
row[
"TI.L1TI_NAME"].data<string>());
146 item->setVersion (
row[
"TI.L1TI_VERSION"].data<int>());
148 item->setPartition (
row[
"TI.L1TI_PARTITION"].data<int>());
149 string mon =
row[
"TI.L1TI_MONITOR"].data<
string>();
150 unsigned short monMask = 0;
152 const short TBP = 0x1;
153 const short TAP = 0x2;
154 const short TAV = 0x4;
156 vector<string> monLfHf;
160 if(monLfHf.size()==4 && monLfHf[0]==
"LF" && monLfHf[2]==
"HF" && monLfHf[1].size()==3 && monLfHf[3].size()==3) {
162 if( monLfHf[1][2]==
'1' ) monMask |= TBP;
163 if( monLfHf[1][1]==
'1' ) monMask |= TAP;
164 if( monLfHf[1][0]==
'1' ) monMask |= TAV;
166 if( monLfHf[3][2]==
'1' ) monMask |= TBP << 3;
167 if( monLfHf[3][1]==
'1' ) monMask |= TAP << 3;
168 if( monLfHf[3][0]==
'1' ) monMask |= TAV << 3;
171 if(
mon.find(
"TBP") != string::npos) monMask |= TBP;
172 if(
mon.find(
"TAP") != string::npos) monMask |= TAP;
173 if(
mon.find(
"TAV") != string::npos) monMask |= TAV;
175 item->setMonitor( monMask );
178 string priority =
row[
"TI.L1TI_PRIORITY"].data<
string>();
180 item->setComplexDeadtime(0);
182 item->setComplexDeadtime(1);
184 item->setDefinition (
row[
"TI.L1TI_DEFINITION"].data<string>());
185 item->setTriggerType(
row[
"TI.L1TI_TRIGGER_TYPE"].data<int>());
188 msg() <<
"MenuLoader: Created Item " <<
item->name() <<
" with CTPID " <<
item->ctpId() << endl;
189 item_thrInfo[ctpid] = vector<ThrInfo>();
190 ctpIDs.push_back(ctpid);
194 thr_info.
thrId =
row[
"TI2TT.L1TI2TT_TRIGGER_THRESHOLD_ID"].data<
int>();
195 thr_info.
thrPos =
row[
"TI2TT.L1TI2TT_POSITION"].data<
int>();
196 thr_info.
thrMult =
row[
"TI2TT.L1TI2TT_MULTIPLICITY"].data<
int>();
197 thr_info.
thr =
menu.thresholdConfig().findTriggerThreshold(thr_info.
thrId);
198 if(thr_info.
thr==0) {
202 if ( ! ttldr.
load( *thr_info.
thr ) ) {
203 msg() <<
"MenuLoader: Error loading TriggerThreshold " << thr_info.
thrId << endl;
204 throw runtime_error(
"MenuLoader::loadItems: error loading TriggerThreshold " );
206 menu.thresholdConfig().addTriggerThreshold(thr_info.
thr);
208 item_thrInfo[ctpid].push_back(thr_info);
212 for(
int ctpid : ctpIDs) {
215 msg() <<
"MenuLoader: Number of thresholds for item " << titem->
name()
216 <<
": " << item_thrInfo[ctpid].size() <<
" - definition: " << titem->
definition() << endl;
229 unsigned int n = logic.
parse(definition);
231 msg() <<
"Error parsing item definition : " << definition << std::endl;
234 unsigned int size = thr_infos.size();
236 msg() <<
"Total number of elements are different: "
237 <<
" input=" <<
size <<
", parsed=" <<
n << endl;
242 return constructTree(logic, thr_infos);
249 const std::vector<std::shared_ptr<LogicExpression>> & sub_logics = def.
subLogics();
251 switch (def.
state()) {
252 case LogicExpression::kELEMENT: {
254 unsigned int pos = boost::lexical_cast<unsigned int,std::string>(def.
element());
266 case LogicExpression::kAND:
267 case LogicExpression::kOPEN:
269 for(
auto sl : sub_logics)
270 top_node->
addChild( constructTree(*sl, thr_infos) );
272 case LogicExpression::kOR:
273 if(sub_logics.size()>0) {
275 for(
auto sl : sub_logics)
276 top_node->
addChild( constructTree(*sl, thr_infos) );
279 case LogicExpression::kNOT:
281 for(
auto sl : sub_logics)
282 top_node->
addChild( constructTree(*sl, thr_infos) );
296 m_env == MenuLoader::CTP ||
297 m_env == MenuLoader::CTPOnl ||
298 m_env == MenuLoader::COOLL1) )
return;
302 unique_ptr< coral::IQuery >
q(m_session.nominalSchema().newQuery());
303 q->addToTableList (
"L1_TM_TO_TT_MON",
"TM2TTM" );
304 q->addToTableList (
"L1_TRIGGER_THRESHOLD",
"TT" );
305 q->addToTableList (
"L1_TM_TO_TT",
"TM2TT" );
309 bindings.extend<
int>(
"menuId");
310 bindings[0].data<
int>() =
menu.id();
313 cond +=
" TM2TTM.L1TM2TTM_TRIGGER_MENU_ID = :menuId";
314 cond +=
" AND TM2TT.L1TM2TT_TRIGGER_MENU_ID = :menuId";
315 cond +=
" AND TM2TTM.L1TM2TTM_TRIGGER_THRESHOLD_ID = TM2TT.L1TM2TT_TRIGGER_THRESHOLD_ID";
316 cond +=
" AND TM2TT.L1TM2TT_TRIGGER_THRESHOLD_ID = TT.L1TT_ID";
318 q->setCondition( cond, bindings );
322 output.extend<std::string>(
"TM2TTM.L1TM2TTM_NAME" );
323 output.extend<
int> (
"TM2TTM.L1TM2TTM_TRIGGER_THRESHOLD_ID" );
324 output.extend<
int> (
"TM2TTM.L1TM2TTM_INTERNAL_COUNTER" );
325 output.extend<
int> (
"TM2TTM.L1TM2TTM_MULTIPLICITY" );
326 output.extend<
long> (
"TM2TTM.L1TM2TTM_BUNCH_GROUP_ID" );
327 output.extend<std::string>(
"TM2TTM.L1TM2TTM_COUNTER_TYPE" );
328 output.extend<std::string>(
"TT.L1TT_NAME" );
329 output.extend<
int> (
"TT.L1TT_ACTIVE" );
330 output.extend<std::string>(
"TM2TT.L1TM2TT_CABLE_CTPIN" );
331 output.extend<std::string>(
"TM2TT.L1TM2TT_CABLE_CONNECTOR" );
332 output.extend<
int> (
"TM2TT.L1TM2TT_CABLE_START" );
333 output.extend<
int> (
"TM2TT.L1TM2TT_CABLE_END" );
336 q->setRowCacheSize(500);
338 coral::ICursor&
cursor =
q->execute();
345 tm->
setName (
row[
"TM2TTM.L1TM2TTM_NAME"].data<string>());
354 string slotString =
row[
"TM2TT.L1TM2TT_CABLE_CTPIN"].data<std::string>();
356 if(slot<7 || slot>9) {
357 TRG_MSG_ERROR(
"Unknown CTPIN string '" << slotString <<
"'");
358 throw runtime_error(
"MenuLoader (ThresholdMonitor): Error loading Monitoring counters " );
362 string conString =
row[
"TM2TT.L1TM2TT_CABLE_CONNECTOR"].data<std::string>();
365 TRG_MSG_ERROR(
"Unknown CTPIN connector string '" << conString <<
"'");
366 throw runtime_error(
"MenuLoader (ThresholdMonitor): Error loading Monitoring counters " );
371 menu.addThresholdMonitor(tm);
392 if ( !thrldr->
load(
menu.thresholdConfig() ) ) {
394 throw runtime_error(
"MenuLoader: Error loading ThresholdConfig " );
399 if(
menu.pitVector().size() ==
menu.tipVector().size() ) {
403 createTipFromDirectThresholds(
menu);
413 m_env == MenuLoader::CTPOnl ||
414 m_env == MenuLoader::COOLL1) )
return;
416 set<int> tipNumbersUsed;
419 unique_ptr< coral::IQuery >
q( m_session.nominalSchema().newQuery() );
420 q->addToTableList (
"L1_TM_TO_TT",
"TM2TT" );
421 q->addToTableList (
"L1_PITS",
"PITS" );
425 bindings.extend<
int>(
"menuId");
426 bindings[0].data<
int>() =
menu.id();
428 std::string cond(
"TM2TT.L1TM2TT_TRIGGER_MENU_ID = :menuId");
429 cond +=
" AND PITS.L1PIT_TM_TO_TT_ID = TM2TT.L1TM2TT_ID";
430 q->setCondition( cond, bindings );
437 attList.extend<
int>(
"TM2TT.L1TM2TT_TRIGGER_THRESHOLD_ID" );
438 attList.extend<
int>(
"TM2TT.L1TM2TT_ID" );
439 attList.extend<
int>(
"PITS.L1PIT_PIT_NUMBER" );
440 attList.extend<
int>(
"PITS.L1PIT_THRESHOLD_BIT" );
443 uint npits(0), ntips(0);
445 coral::ICursor&
cursor =
q->execute();
449 int ttid =
row[
"TM2TT.L1TM2TT_TRIGGER_THRESHOLD_ID"].data<
int>();
450 int tmtott =
row[
"TM2TT.L1TM2TT_ID"].data<
int>();
451 int tipnum =
row[
"PITS.L1PIT_PIT_NUMBER"].data<
int>();
452 int bitnum =
row[
"PITS.L1PIT_THRESHOLD_BIT"].data<
int>();
457 string slotString =
tt->cableCtpin();
459 if( boost::iequals( slotString,
"CTPCORE" ) ) {
462 slot = slotString[4]-
'0';
464 if(slot<7 || slot>10) {
466 throw runtime_error(
"MenuLoader: Error loading PITs " );
469 string conString =
tt->cableConnector();
473 TRG_MSG_ERROR(
"Unknown CTPIN CONNECTOR '" << conString <<
"'");
474 throw runtime_error(
"MenuLoader: Error loading PITs " );
494 if(tipNumbersUsed.count(tipnum) > 0) {
495 tipnum = tipnum + 160;
497 tipNumbersUsed.insert(tipnum);
520 TRG_MSG_INFO(
"Loaded " << npits <<
" PITs and " << ntips <<
" TIPs");
521 TRG_MSG_INFO(
"Menu has " <<
menu.pitVector().size() <<
" PITs and " <<
menu.tipVector().size() <<
" TIPs");
532 unsigned int ntips(0);
535 if(thr->ttype()==L1DataDef::TOPO || thr->ttype()==L1DataDef::ALFA) {
537 const string &
conn = thr->cableConnector();
539 unsigned int connector =
conn[3]-
'0';
540 unsigned int cableOffset = 320 + connector * 64;
541 unsigned int cableBit = (
unsigned int) thr->cableStart();
542 unsigned int clock = thr->clock();
543 unsigned int tipNumber = 2*cableBit + clock + cableOffset;
565 TRG_MSG_INFO(
"Number of TIPs from direct input thresholds " << ntips );
576 m_storageMgr.caloInfoLoader().setLevel(
outputLevel());
577 m_storageMgr.caloInfoLoader().load(ci);
578 menu.setCaloInfo(ci);
589 unique_ptr< coral::IQuery >
q( m_session.nominalSchema().newQuery() );
590 q->addToTableList (
"SUPER_MASTER_TABLE",
"SM" );
591 q->addToTableList (
"L1_MASTER_TABLE",
"MT" );
592 q->addToTableList (
"L1_TRIGGER_MENU",
"TM" );
596 bindings.extend<
int>(
"smk");
597 bindings[0].data<
int>() =
menu.smk();
601 condition +=
" AND SM.SMT_L1_MASTER_TABLE_ID = MT.L1MT_ID";
602 condition +=
" AND MT.L1MT_TRIGGER_MENU_ID = TM.L1TM_ID";
607 attList.extend<
int>(
"TM.L1TM_ID");
608 attList.extend<
string>(
"TM.L1TM_NAME");
609 attList.extend<
int>(
"TM.L1TM_VERSION");
610 attList.extend<
int>(
"MT.L1MT_ID" );
613 coral::ICursor&
cursor =
q->execute();
616 throw runtime_error(
"MenuLoader: ERROR trigger menu not available" );
621 menu.setId (
row[
"TM.L1TM_ID"].data<int>() );
622 menu.setName (
row[
"TM.L1TM_NAME"].data<string>() );
623 menu.setVersion(
row[
"TM.L1TM_VERSION"].data<int>() );
624 menu.thresholdConfig().setLvl1MasterTableId(
row[
"MT.L1MT_ID"].data<int>() );