5 #include <unordered_map> 8 #include "tmEventSetup/tmEventSetup.hh" 9 #include "tmEventSetup/esTriggerMenu.hh" 10 #include "tmEventSetup/esAlgorithm.hh" 11 #include "tmEventSetup/esCondition.hh" 12 #include "tmEventSetup/esObject.hh" 13 #include "tmEventSetup/esCut.hh" 14 #include "tmEventSetup/esScale.hh" 15 #include "tmGrammar/Algorithm.hh" 48 edm::LogInfo(
"L1-O2O: L1TGlobalPrescalesVetosOnlineProd")
49 <<
"Producing L1TGlobalPrescalesVetos with TSC:RS key = " << objectKey;
51 if (objectKey.empty()) {
53 throw std::runtime_error(
"SummaryForFunctionManager: uGTrs | Faulty | Empty objectKey");
55 edm::LogError(
"L1-O2O: L1TGlobalPrescalesVetosOnlineProd") <<
"returning empty L1TGlobalPrescalesVetos object";
56 return std::make_unique<const L1TGlobalPrescalesVetos>();
60 unsigned int m_numberPhysTriggers = 512;
63 std::unordered_map<std::string, int, std::hash<std::string>> algoName2bit;
65 std::string uGTtscKey = objectKey.substr(0, objectKey.find(
":"));
66 std::string uGTrsKey = objectKey.substr(objectKey.find(
":") + 1, std::string::npos);
71 std::vector<std::string> queryStrings;
72 queryStrings.push_back(
"L1_MENU");
79 edm::LogError(
"L1-O2O") <<
"Cannot get UGT_KEYS.L1_MENU for ID = " << uGTtscKey <<
" ";
81 throw std::runtime_error(
"SummaryForFunctionManager: uGTrs | Faulty | Broken key");
83 edm::LogError(
"L1-O2O: L1TGlobalPrescalesVetosOnlineProd") <<
"returning empty L1TGlobalPrescalesVetos object";
84 return std::make_unique<const L1TGlobalPrescalesVetos>();
91 edm::LogInfo(
"L1-O2O: L1TGlobalPrescalesVetosOnlineProd") <<
"Producing L1TUtmTriggerMenu with key =" << l1_menu_key;
93 if (uGTtscKey.empty()) {
94 edm::LogError(
"L1-O2O: L1TGlobalPrescalesVetosOnlineProd") <<
"TSC key is empty, returning";
96 throw std::runtime_error(
"SummaryForFunctionManager: uGTrs | Faulty | Empty objectKey");
98 edm::LogError(
"L1-O2O: L1TGlobalPrescalesVetosOnlineProd") <<
"returning empty L1TGlobalPrescalesVetos object";
99 return std::make_unique<const L1TGlobalPrescalesVetos>();
103 std::vector<std::string> queryColumns;
104 queryColumns.push_back(
"CONF");
111 <<
"Cannot get UGT_L1_MENU.CONF for ID = " << l1_menu_key;
113 throw std::runtime_error(
"SummaryForFunctionManager: uGTrs | Faulty | Broken key");
115 edm::LogError(
"L1-O2O: L1TGlobalPrescalesVetosOnlineProd") <<
"returning empty L1TGlobalPrescalesVetos object";
116 return std::make_unique<const L1TGlobalPrescalesVetos>();
123 std::istringstream iss(l1Menu);
125 std::shared_ptr<L1TUtmTriggerMenu> pMenu(
126 const_cast<L1TUtmTriggerMenu *>(reinterpret_cast<const L1TUtmTriggerMenu *>(tmeventsetup::getTriggerMenu(iss))));
128 for (
auto algo : pMenu->getAlgorithmMap())
129 algoName2bit[
algo.first] =
algo.second.getIndex();
132 queryColumns.clear();
133 queryColumns.push_back(
"ALGOBX_MASK");
134 queryColumns.push_back(
"ALGO_FINOR_MASK");
135 queryColumns.push_back(
"ALGO_FINOR_VETO");
136 queryColumns.push_back(
"ALGO_PRESCALE");
138 std::string prescale_key, bxmask_key, mask_key, vetomask_key;
139 std::string xmlPayload_prescale, xmlPayload_mask_algobx, xmlPayload_mask_finor, xmlPayload_mask_veto;
141 std::map<std::string, std::string> subKeys =
143 prescale_key = subKeys[
"ALGO_PRESCALE"];
144 bxmask_key = subKeys[
"ALGOBX_MASK"];
145 mask_key = subKeys[
"ALGO_FINOR_MASK"];
146 vetomask_key = subKeys[
"ALGO_FINOR_VETO"];
148 xmlPayload_mask_algobx =
151 xmlPayload_mask_veto =
153 }
catch (std::runtime_error &
e) {
154 edm::LogError(
"L1-O2O: L1TGlobalPrescalesVetosOnlineProd") << e.what();
156 throw std::runtime_error(
std::string(
"SummaryForFunctionManager: uGTrs | Faulty | ") + e.what());
158 edm::LogError(
"L1-O2O: L1TGlobalPrescalesVetosOnlineProd") <<
"returning empty L1TGlobalPrescalesVetos object";
159 return std::make_unique<const L1TGlobalPrescalesVetos>();
165 output1 << xmlPayload_prescale;
168 output2 << xmlPayload_mask_finor;
171 output3 << xmlPayload_mask_algobx;
173 std::ofstream output4(
std::string(
"/tmp/").
append(vetomask_key.substr(0, vetomask_key.find(
"/"))).append(
".xml"));
174 output4 << xmlPayload_mask_veto;
180 std::vector<unsigned int> triggerMasks;
181 std::vector<int> triggerVetoMasks;
182 std::map<int, std::vector<int>> triggerAlgoBxMaskAlgoTrig;
188 ts_prescale.
addProcessor(
"uGtProcessor",
"uGtProcessor",
"-1",
"-1");
195 const std::map<std::string, l1t::Parameter> &settings_prescale = ts_prescale.
getParameters(
"uGtProcessor");
196 std::map<std::string, unsigned int> prescaleColumns = settings_prescale.at(
"prescales").getColumnIndices();
198 unsigned int numColumns_prescale = prescaleColumns.size();
199 int nPrescaleSets = numColumns_prescale - 1;
200 std::vector<std::string> algoNames =
201 settings_prescale.at(
"prescales").getTableColumn<
std::string>(
"algo/prescale-index");
203 if (nPrescaleSets > 0) {
205 for (
int iSet = 0; iSet < nPrescaleSets; iSet++) {
206 prescales.push_back(std::vector<int>());
207 for (
unsigned int iBit = 0; iBit < m_numberPhysTriggers; ++iBit) {
208 int inputDefaultPrescale = 0;
209 prescales[iSet].push_back(inputDefaultPrescale);
213 for (
auto &
col : prescaleColumns) {
216 int iSet =
col.second - 1;
217 std::vector<unsigned int> prescalesForSet =
218 settings_prescale.at(
"prescales").getTableColumn<
unsigned int>(
col.first.c_str());
219 for (
unsigned int row = 0; row < prescalesForSet.size(); row++) {
220 unsigned int prescale = prescalesForSet[row];
222 unsigned int algoBit = algoName2bit[
algoName];
223 prescales[iSet][algoBit] = prescale;
227 }
catch (std::runtime_error &e) {
229 throw std::runtime_error(
std::string(
"SummaryForFunctionManager: uGTrs | Faulty | ") + e.what());
231 edm::LogError(
"L1-O2O: L1TGlobalPrescalesVetosOnlineProd") <<
"returning empty L1TGlobalPrescalesVetos object";
232 return std::make_unique<const L1TGlobalPrescalesVetos>();
242 ts_mask_finor.
addProcessor(
"uGtProcessor",
"uGtProcessor",
"-1",
"-1");
249 const std::map<std::string, l1t::Parameter> &settings_mask_finor = ts_mask_finor.
getParameters(
"uGtProcessor");
251 std::vector<std::string> algo_mask_finor = settings_mask_finor.at(
"finorMask").getTableColumn<
std::string>(
"algo");
252 std::vector<unsigned int> mask_mask_finor =
253 settings_mask_finor.at(
"finorMask").getTableColumn<
unsigned int>(
"mask");
256 unsigned int default_finor_mask = 1;
257 auto default_finor_row = std::find_if(algo_mask_finor.cbegin(), algo_mask_finor.cend(), [](
const std::string &
s) {
259 return strcasecmp(
"all",
s.c_str()) == 0;
261 if (default_finor_row == algo_mask_finor.cend()) {
263 <<
"\nWarning: No default found in FinOR mask xml, use 1 (unmasked) as default" << std::endl;
265 default_finor_mask = mask_mask_finor[
std::distance(algo_mask_finor.cbegin(), default_finor_row)];
268 for (
unsigned int iAlg = 0; iAlg < m_numberPhysTriggers; iAlg++)
269 triggerMasks.push_back(default_finor_mask);
271 for (
unsigned int row = 0; row < algo_mask_finor.size(); row++) {
273 if (strcasecmp(
"all", algoName.c_str()) == 0)
275 unsigned int algoBit = algoName2bit[
algoName];
276 unsigned int mask = mask_mask_finor[row];
277 if (algoBit < m_numberPhysTriggers)
278 triggerMasks[algoBit] = mask;
280 }
catch (std::runtime_error &e) {
282 throw std::runtime_error(
std::string(
"SummaryForFunctionManager: uGTrs | Faulty | ") + e.what());
284 edm::LogError(
"L1-O2O: L1TGlobalPrescalesVetosOnlineProd") <<
"returning empty L1TGlobalPrescalesVetos object";
285 return std::make_unique<const L1TGlobalPrescalesVetos>();
295 ts_mask_veto.
addProcessor(
"uGtProcessor",
"uGtProcessor",
"-1",
"-1");
302 const std::map<std::string, l1t::Parameter> &settings_mask_veto = ts_mask_veto.
getParameters(
"uGtProcessor");
303 std::vector<std::string> algo_mask_veto = settings_mask_veto.at(
"vetoMask").getTableColumn<
std::string>(
"algo");
304 std::vector<unsigned int> veto_mask_veto = settings_mask_veto.at(
"vetoMask").getTableColumn<
unsigned int>(
"veto");
307 unsigned int default_veto_mask = 1;
308 auto default_veto_row = std::find_if(algo_mask_veto.cbegin(), algo_mask_veto.cend(), [](
const std::string &
s) {
310 return strcasecmp(
"all",
s.c_str()) == 0;
312 if (default_veto_row == algo_mask_veto.cend()) {
314 <<
"\nWarning: No default found in Veto mask xml, use 0 (unvetoed) as default" << std::endl;
316 default_veto_mask = veto_mask_veto[
std::distance(algo_mask_veto.cbegin(), default_veto_row)];
319 for (
unsigned int iAlg = 0; iAlg < m_numberPhysTriggers; iAlg++)
320 triggerVetoMasks.push_back(default_veto_mask);
322 for (
unsigned int row = 0; row < algo_mask_veto.size(); row++) {
324 if (strcasecmp(
"all", algoName.c_str()) == 0)
326 unsigned int algoBit = algoName2bit[
algoName];
327 unsigned int veto = veto_mask_veto[row];
328 if (algoBit < m_numberPhysTriggers)
329 triggerVetoMasks[algoBit] =
int(veto);
331 }
catch (std::runtime_error &e) {
333 throw std::runtime_error(
std::string(
"SummaryForFunctionManager: uGTrs | Faulty | ") + e.what());
335 edm::LogError(
"L1-O2O: L1TGlobalPrescalesVetosOnlineProd") <<
"returning empty L1TGlobalPrescalesVetos object";
336 return std::make_unique<const L1TGlobalPrescalesVetos>();
343 unsigned int m_bx_mask_default = 1;
345 std::vector<std::string> bx_algo_name;
346 std::vector<std::string> bx_range;
347 std::vector<unsigned int> bx_mask;
352 ts_mask_algobx.
addProcessor(
"uGtProcessor",
"uGtProcessor",
"-1",
"-1");
359 const std::map<std::string, l1t::Parameter> &settings_mask_algobx = ts_mask_algobx.
getParameters(
"uGtProcessor");
360 bx_algo_name = settings_mask_algobx.at(
"algorithmBxMask").getTableColumn<
std::string>(
"algo");
361 bx_range = settings_mask_algobx.at(
"algorithmBxMask").getTableColumn<
std::string>(
"range");
362 bx_mask = settings_mask_algobx.at(
"algorithmBxMask").getTableColumn<
unsigned int>(
"mask");
363 }
catch (std::runtime_error &e) {
365 throw std::runtime_error(
std::string(
"SummaryForFunctionManager: uGTrs | Faulty | ") + e.what());
367 edm::LogError(
"L1-O2O: L1TGlobalPrescalesVetosOnlineProd") <<
"returning empty L1TGlobalPrescalesVetos object";
368 return std::make_unique<const L1TGlobalPrescalesVetos>();
372 int default_bxmask_row = -1;
373 typedef std::pair<unsigned long, unsigned long> Range_t;
376 bool operator()(
const Range_t &
a,
const Range_t &
b)
const {
return a.first < b.first; }
378 std::map<std::string, std::set<Range_t, RangeComp_t>> non_default_bx_ranges;
380 for (
unsigned int row = 0; row < bx_algo_name.size(); row++) {
384 bool broadcastAlgo =
false;
385 bool broadcastRange =
false;
386 if (strcasecmp(
"all", s1.c_str()) == 0)
387 broadcastAlgo =
true;
388 if (strcasecmp(
"all", s2.c_str()) == 0)
389 broadcastRange =
true;
391 if (broadcastAlgo && broadcastRange) {
394 <<
"\nWarning: ALL-ALL row is not the first one, ignore it assuming 1 (unmasked) as the default" 398 if (default_bxmask_row >= 0) {
400 <<
"\nWarning: multiple ALL-ALL rows found, using the first" << std::endl;
403 default_bxmask_row = row;
404 m_bx_mask_default = bx_mask[row];
409 if (broadcastRange) {
413 char *dash =
nullptr;
414 first = strtoul(s2.data(), &dash, 0);
415 while (*dash !=
'\0' && *dash !=
'-')
417 last = (*dash !=
'\0' ? strtoul(++dash, &dash, 0) :
first);
425 <<
"\nWarning: parsing " << s2 <<
" as [" << first <<
"," <<
last <<
"] range" << std::endl;
429 <<
"\nWarning: start of interval is out of range: " << s2 <<
", skipping the row" << std::endl;
435 <<
"\nWarning: end of interval is out of range: " << s2 <<
", force [" << first <<
"," <<
last <<
"] range" 440 <<
"\nWarning: inverse/spillover range " << s2 <<
", accounting for circular orbit as [0," <<
last 441 <<
"] & [" << first <<
",3563]" << std::endl;
445 std::vector<std::string>
algos;
446 std::vector<std::pair<unsigned long, unsigned long>> orderedRanges;
448 if (!broadcastAlgo) {
449 algos.push_back(bx_algo_name[row]);
450 orderedRanges.push_back(std::make_pair(first,
last));
452 for (
const auto &
i : non_default_bx_ranges) {
453 algos.push_back(
i.first);
454 orderedRanges.push_back(std::make_pair(first,
last));
458 if (!broadcastAlgo) {
459 algos.push_back(bx_algo_name[row]);
460 algos.push_back(bx_algo_name[row]);
461 orderedRanges.push_back(std::make_pair(0,
last));
462 orderedRanges.push_back(std::make_pair(first, 3563));
464 for (
const auto &
i : non_default_bx_ranges) {
465 algos.push_back(
i.first);
466 algos.push_back(
i.first);
467 orderedRanges.push_back(std::make_pair(0,
last));
468 orderedRanges.push_back(std::make_pair(first, 3563));
473 for (
unsigned int item = 0;
item < algos.size();
item++) {
475 unsigned int first = orderedRanges[
item].first;
476 unsigned int last = orderedRanges[
item].second;
478 std::set<Range_t, RangeComp_t> &
ranges = non_default_bx_ranges[
algoName];
492 std::set<Range_t>::iterator curr = ranges.end();
493 std::set<Range_t>::iterator succ =
494 ranges.lower_bound(std::make_pair(first, last));
495 std::set<Range_t>::iterator pred = succ;
496 if (pred != ranges.begin())
501 if ((pred == ranges.end() || pred->second <
first) && (succ == ranges.end() || succ->first >
last)) {
503 if (m_bx_mask_default != bx_mask[row])
504 curr = ranges.insert(std::make_pair(first, last)).first;
508 Range_t newPred, newSucc;
509 bool modifiedPred =
false, gapInPred =
false, modifiedSucc =
false, dropSucc =
false;
511 if (pred != ranges.end() && pred->second >= first && pred->second <=
last) {
512 if (m_bx_mask_default != bx_mask[row]) {
513 if (last == pred->second) {
515 modifiedPred =
false;
518 newPred.first = pred->first;
519 newPred.second =
last;
524 newPred.first = pred->first;
525 newPred.second = first - 1;
531 if (pred != ranges.end() && pred->second > first && pred->second >
last) {
532 if (m_bx_mask_default != bx_mask[row]) {
534 modifiedPred =
false;
537 newPred.first =
first;
538 newPred.second =
last;
544 if (succ != ranges.end() && succ->first <=
last) {
545 if (m_bx_mask_default != bx_mask[row]) {
547 newSucc.first =
first;
548 newSucc.second = succ->second;
551 newSucc.first = last + 1;
552 newSucc.second = succ->second;
553 if (newSucc.first > 3563 || newSucc.first > newSucc.second)
559 if (modifiedPred && modifiedSucc && newPred.second >= newSucc.first) {
561 newPred.second = newSucc.second;
562 newSucc.first = newPred.first;
563 ranges.erase(pred, ++succ);
564 curr = ranges.insert(newPred).first;
570 curr = ranges.insert(newPred).first;
573 Range_t
r1(pred->first, newPred.first - 1);
574 Range_t
r2(newPred.second + 1, pred->second);
584 curr = ranges.insert(newSucc).first;
591 if (curr != ranges.end()) {
592 std::set<Range_t, RangeComp_t>::iterator last_covered = ranges.upper_bound(std::make_pair(curr->second, 0));
593 if (last_covered != ranges.begin())
596 last_covered = ranges.end();
598 if (last_covered != ranges.end() && last_covered->first != curr->first) {
600 if (curr->second < last_covered->second) {
602 Range_t newRange(curr->first, last_covered->second);
604 curr = ranges.insert(newRange).first;
606 ranges.erase(++curr, last_covered);
612 if (default_bxmask_row < 0) {
614 <<
"\nWarning: No default found in BX mask xml, used 1 (unmasked) as default" << std::endl;
617 for (
const std::pair<
std::string, std::set<Range_t, RangeComp_t>> &
algo : non_default_bx_ranges) {
619 unsigned int algoBit = algoName2bit[
algoName];
622 triggerAlgoBxMaskAlgoTrig[
bx].push_back(algoBit);
627 for (
unsigned int iSet = 0; iSet < prescales.size(); iSet++) {
628 for (
unsigned int iBit = 0; iBit < prescales[iSet].size(); iBit++) {
630 if (iBit >= triggerMasks.size()) {
632 <<
"\nWarning: algoBit in prescale table >= triggerMasks.size() " 633 <<
"\nWarning: no information on masking bit or not, setting as unmasked " << std::endl;
635 prescales[iSet][iBit] *= triggerMasks[iBit];
651 edm::LogInfo(
"L1-O2O: L1TCaloParamsOnlineProd") <<
"SummaryForFunctionManager: uGTrs | OK | All looks good";
T getParameter(std::string const &) const
L1TGlobalPrescalesVetosOnlineProd(const edm::ParameterSet &)
void setConfigured(bool state=true) noexcept
std::unique_ptr< const L1TGlobalPrescalesVetos > newObject(const std::string &objectKey, const L1TGlobalPrescalesVetosO2ORcd &record) override
bool fillVariable(const std::string &columnName, T &outputVariable) const
void setPrescaleFactorTable(std::vector< std::vector< int > > value)
const QueryResults singleAttribute(const T &data) const
l1t::OMDSReader m_omdsReader
void readDOMFromString(const std::string &str, xercesc::DOMDocument *&doc)
static std::map< std::string, std::string > fetch(const std::vector< std::string > &queryColumns, const std::string &table, const std::string &key, l1t::OMDSReader &m_omdsReader)
const QueryResults basicQuery(const std::vector< std::string > &columnNames, const std::string &schemaName, const std::string &tableName, const std::string &conditionLHS="", const QueryResults conditionRHS=QueryResults(), const std::string &conditionRHSName="")
void setTriggerMaskVeto(std::vector< int > value)
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
~L1TGlobalPrescalesVetosOnlineProd(void) override
const std::map< std::string, Parameter > & getParameters(const char *processor) const
void setBxMaskDefault(int value)
void readRootElement(TriggerSystem &aTriggerSystem, const std::string &sysId="")
void addProcessor(const char *processor, const char *role, const char *crate, const char *slot)
void setTriggerAlgoBxMask(std::map< int, std::vector< int > > value)
L1TGlobalPrescalesVetos * getWriteInstance()