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"
49 edm::LogInfo(
"L1-O2O: L1TGlobalPrescalesVetosOnlineProd")
50 <<
"Producing L1TGlobalPrescalesVetos with TSC:RS key = " << objectKey;
52 if (objectKey.empty()) {
54 throw std::runtime_error(
"SummaryForFunctionManager: uGTrs | Faulty | Empty objectKey");
56 edm::LogError(
"L1-O2O: L1TGlobalPrescalesVetosOnlineProd") <<
"returning empty L1TGlobalPrescalesVetos object";
57 return std::make_unique<const L1TGlobalPrescalesVetos>();
61 unsigned int m_numberPhysTriggers = 512;
64 std::unordered_map<std::string, int, std::hash<std::string>> algoName2bit;
66 std::string uGTtscKey = objectKey.substr(0, objectKey.find(
":"));
67 std::string uGTrsKey = objectKey.substr(objectKey.find(
":") + 1, std::string::npos);
72 std::vector<std::string> queryStrings;
73 queryStrings.push_back(
"L1_MENU");
80 edm::LogError(
"L1-O2O") <<
"Cannot get UGT_KEYS.L1_MENU for ID = " << uGTtscKey <<
" ";
82 throw std::runtime_error(
"SummaryForFunctionManager: uGTrs | Faulty | Broken key");
84 edm::LogError(
"L1-O2O: L1TGlobalPrescalesVetosOnlineProd") <<
"returning empty L1TGlobalPrescalesVetos object";
85 return std::make_unique<const L1TGlobalPrescalesVetos>();
92 edm::LogInfo(
"L1-O2O: L1TGlobalPrescalesVetosOnlineProd") <<
"Producing L1TUtmTriggerMenu with key =" << l1_menu_key;
94 if (uGTtscKey.empty()) {
95 edm::LogError(
"L1-O2O: L1TGlobalPrescalesVetosOnlineProd") <<
"TSC key is empty, returning";
97 throw std::runtime_error(
"SummaryForFunctionManager: uGTrs | Faulty | Empty objectKey");
99 edm::LogError(
"L1-O2O: L1TGlobalPrescalesVetosOnlineProd") <<
"returning empty L1TGlobalPrescalesVetos object";
100 return std::make_unique<const L1TGlobalPrescalesVetos>();
104 std::vector<std::string> queryColumns;
105 queryColumns.push_back(
"CONF");
112 <<
"Cannot get UGT_L1_MENU.CONF for ID = " << l1_menu_key;
114 throw std::runtime_error(
"SummaryForFunctionManager: uGTrs | Faulty | Broken key");
116 edm::LogError(
"L1-O2O: L1TGlobalPrescalesVetosOnlineProd") <<
"returning empty L1TGlobalPrescalesVetos object";
117 return std::make_unique<const L1TGlobalPrescalesVetos>();
124 std::istringstream iss(l1Menu);
126 std::shared_ptr<L1TUtmTriggerMenu> pMenu(
127 const_cast<L1TUtmTriggerMenu *>(reinterpret_cast<const L1TUtmTriggerMenu *>(tmeventsetup::getTriggerMenu(iss))));
129 for (
auto algo : pMenu->getAlgorithmMap())
130 algoName2bit[
algo.first] =
algo.second.getIndex();
133 queryColumns.clear();
134 queryColumns.push_back(
"ALGOBX_MASK");
135 queryColumns.push_back(
"ALGO_FINOR_MASK");
136 queryColumns.push_back(
"ALGO_FINOR_VETO");
137 queryColumns.push_back(
"ALGO_PRESCALE");
139 std::string prescale_key, bxmask_key, mask_key, vetomask_key;
140 std::string xmlPayload_prescale, xmlPayload_mask_algobx, xmlPayload_mask_finor, xmlPayload_mask_veto;
142 std::map<std::string, std::string> subKeys =
144 prescale_key = subKeys[
"ALGO_PRESCALE"];
145 bxmask_key = subKeys[
"ALGOBX_MASK"];
146 mask_key = subKeys[
"ALGO_FINOR_MASK"];
147 vetomask_key = subKeys[
"ALGO_FINOR_VETO"];
149 xmlPayload_mask_algobx =
152 xmlPayload_mask_veto =
154 }
catch (std::runtime_error &
e) {
155 edm::LogError(
"L1-O2O: L1TGlobalPrescalesVetosOnlineProd") <<
e.what();
157 throw std::runtime_error(
std::string(
"SummaryForFunctionManager: uGTrs | Faulty | ") +
e.what());
159 edm::LogError(
"L1-O2O: L1TGlobalPrescalesVetosOnlineProd") <<
"returning empty L1TGlobalPrescalesVetos object";
160 return std::make_unique<const L1TGlobalPrescalesVetos>();
166 output1 << xmlPayload_prescale;
169 output2 << xmlPayload_mask_finor;
172 output3 << xmlPayload_mask_algobx;
174 std::ofstream output4(
std::string(
"/tmp/").
append(vetomask_key.substr(0, vetomask_key.find(
"/"))).append(
".xml"));
175 output4 << xmlPayload_mask_veto;
181 std::vector<unsigned int> triggerMasks;
182 std::vector<int> triggerVetoMasks;
183 std::map<int, std::vector<int>> triggerAlgoBxMaskAlgoTrig;
189 ts_prescale.
addProcessor(
"uGtProcessor",
"uGtProcessor",
"-1",
"-1");
196 const std::map<std::string, l1t::Parameter> &settings_prescale = ts_prescale.
getParameters(
"uGtProcessor");
197 std::map<std::string, unsigned int> prescaleColumns = settings_prescale.at(
"prescales").getColumnIndices();
199 unsigned int numColumns_prescale = prescaleColumns.size();
200 int nPrescaleSets = numColumns_prescale - 1;
201 std::vector<std::string> algoNames =
202 settings_prescale.at(
"prescales").getTableColumn<
std::string>(
"algo/prescale-index");
204 if (nPrescaleSets > 0) {
206 for (
int iSet = 0; iSet < nPrescaleSets; iSet++) {
208 for (
unsigned int iBit = 0; iBit < m_numberPhysTriggers; ++iBit) {
209 int inputDefaultPrescale = 0;
210 prescales[iSet].push_back(inputDefaultPrescale);
214 for (
auto &
col : prescaleColumns) {
217 int iSet =
col.second - 1;
218 std::vector<unsigned int> prescalesForSet =
219 settings_prescale.at(
"prescales").getTableColumn<
unsigned int>(
col.first.c_str());
220 for (
unsigned int row = 0; row < prescalesForSet.size(); row++) {
221 unsigned int prescale = prescalesForSet[row];
223 unsigned int algoBit = algoName2bit[
algoName];
228 }
catch (std::runtime_error &
e) {
230 throw std::runtime_error(
std::string(
"SummaryForFunctionManager: uGTrs | Faulty | ") +
e.what());
232 edm::LogError(
"L1-O2O: L1TGlobalPrescalesVetosOnlineProd") <<
"returning empty L1TGlobalPrescalesVetos object";
233 return std::make_unique<const L1TGlobalPrescalesVetos>();
243 ts_mask_finor.
addProcessor(
"uGtProcessor",
"uGtProcessor",
"-1",
"-1");
250 const std::map<std::string, l1t::Parameter> &settings_mask_finor = ts_mask_finor.
getParameters(
"uGtProcessor");
252 std::vector<std::string> algo_mask_finor = settings_mask_finor.at(
"finorMask").getTableColumn<
std::string>(
"algo");
253 std::vector<unsigned int> mask_mask_finor =
254 settings_mask_finor.at(
"finorMask").getTableColumn<
unsigned int>(
"mask");
257 unsigned int default_finor_mask = 1;
258 auto default_finor_row = std::find_if(algo_mask_finor.cbegin(), algo_mask_finor.cend(), [](
const std::string &
s) {
260 return strcasecmp(
"all",
s.c_str()) == 0;
262 if (default_finor_row == algo_mask_finor.cend()) {
264 <<
"\nWarning: No default found in FinOR mask xml, use 1 (unmasked) as default" << std::endl;
266 default_finor_mask = mask_mask_finor[
std::distance(algo_mask_finor.cbegin(), default_finor_row)];
269 for (
unsigned int iAlg = 0; iAlg < m_numberPhysTriggers; iAlg++)
270 triggerMasks.push_back(default_finor_mask);
272 for (
unsigned int row = 0; row < algo_mask_finor.size(); row++) {
274 if (strcasecmp(
"all",
algoName.c_str()) == 0)
276 unsigned int algoBit = algoName2bit[
algoName];
277 unsigned int mask = mask_mask_finor[row];
278 if (algoBit < m_numberPhysTriggers)
279 triggerMasks[algoBit] = mask;
281 }
catch (std::runtime_error &
e) {
283 throw std::runtime_error(
std::string(
"SummaryForFunctionManager: uGTrs | Faulty | ") +
e.what());
285 edm::LogError(
"L1-O2O: L1TGlobalPrescalesVetosOnlineProd") <<
"returning empty L1TGlobalPrescalesVetos object";
286 return std::make_unique<const L1TGlobalPrescalesVetos>();
296 ts_mask_veto.
addProcessor(
"uGtProcessor",
"uGtProcessor",
"-1",
"-1");
303 const std::map<std::string, l1t::Parameter> &settings_mask_veto = ts_mask_veto.
getParameters(
"uGtProcessor");
304 std::vector<std::string> algo_mask_veto = settings_mask_veto.at(
"vetoMask").getTableColumn<
std::string>(
"algo");
305 std::vector<unsigned int> veto_mask_veto = settings_mask_veto.at(
"vetoMask").getTableColumn<
unsigned int>(
"veto");
308 unsigned int default_veto_mask = 1;
309 auto default_veto_row = std::find_if(algo_mask_veto.cbegin(), algo_mask_veto.cend(), [](
const std::string &
s) {
311 return strcasecmp(
"all",
s.c_str()) == 0;
313 if (default_veto_row == algo_mask_veto.cend()) {
315 <<
"\nWarning: No default found in Veto mask xml, use 0 (unvetoed) as default" << std::endl;
317 default_veto_mask = veto_mask_veto[
std::distance(algo_mask_veto.cbegin(), default_veto_row)];
320 for (
unsigned int iAlg = 0; iAlg < m_numberPhysTriggers; iAlg++)
321 triggerVetoMasks.push_back(default_veto_mask);
323 for (
unsigned int row = 0; row < algo_mask_veto.size(); row++) {
325 if (strcasecmp(
"all",
algoName.c_str()) == 0)
327 unsigned int algoBit = algoName2bit[
algoName];
328 unsigned int veto = veto_mask_veto[row];
329 if (algoBit < m_numberPhysTriggers)
330 triggerVetoMasks[algoBit] =
int(
veto);
332 }
catch (std::runtime_error &
e) {
334 throw std::runtime_error(
std::string(
"SummaryForFunctionManager: uGTrs | Faulty | ") +
e.what());
336 edm::LogError(
"L1-O2O: L1TGlobalPrescalesVetosOnlineProd") <<
"returning empty L1TGlobalPrescalesVetos object";
337 return std::make_unique<const L1TGlobalPrescalesVetos>();
344 unsigned int m_bx_mask_default = 1;
346 std::vector<std::string> bx_algo_name;
347 std::vector<std::string> bx_range;
348 std::vector<unsigned int> bx_mask;
353 ts_mask_algobx.
addProcessor(
"uGtProcessor",
"uGtProcessor",
"-1",
"-1");
360 const std::map<std::string, l1t::Parameter> &settings_mask_algobx = ts_mask_algobx.
getParameters(
"uGtProcessor");
361 bx_algo_name = settings_mask_algobx.at(
"algorithmBxMask").getTableColumn<
std::string>(
"algo");
362 bx_range = settings_mask_algobx.at(
"algorithmBxMask").getTableColumn<
std::string>(
"range");
363 bx_mask = settings_mask_algobx.at(
"algorithmBxMask").getTableColumn<
unsigned int>(
"mask");
364 }
catch (std::runtime_error &
e) {
366 throw std::runtime_error(
std::string(
"SummaryForFunctionManager: uGTrs | Faulty | ") +
e.what());
368 edm::LogError(
"L1-O2O: L1TGlobalPrescalesVetosOnlineProd") <<
"returning empty L1TGlobalPrescalesVetos object";
369 return std::make_unique<const L1TGlobalPrescalesVetos>();
373 int default_bxmask_row = -1;
374 typedef std::pair<unsigned long, unsigned long> Range_t;
377 bool operator()(
const Range_t &
a,
const Range_t &
b)
const {
return a.first <
b.first; }
379 std::map<std::string, std::set<Range_t, RangeComp_t>> non_default_bx_ranges;
381 for (
unsigned int row = 0; row < bx_algo_name.size(); row++) {
385 bool broadcastAlgo =
false;
386 bool broadcastRange =
false;
387 if (strcasecmp(
"all", s1.c_str()) == 0)
388 broadcastAlgo =
true;
389 if (strcasecmp(
"all",
s2.c_str()) == 0)
390 broadcastRange =
true;
392 if (broadcastAlgo && broadcastRange) {
395 <<
"\nWarning: ALL-ALL row is not the first one, ignore it assuming 1 (unmasked) as the default"
399 if (default_bxmask_row >= 0) {
401 <<
"\nWarning: multiple ALL-ALL rows found, using the first" << std::endl;
404 default_bxmask_row = row;
405 m_bx_mask_default = bx_mask[row];
410 if (broadcastRange) {
414 char *dash =
nullptr;
415 first = strtoul(
s2.data(), &dash, 0);
416 while (*dash !=
'\0' && *dash !=
'-')
418 last = (*dash !=
'\0' ? strtoul(++dash, &dash, 0) :
first);
426 <<
"\nWarning: parsing " <<
s2 <<
" as [" <<
first <<
"," <<
last <<
"] range" << std::endl;
430 <<
"\nWarning: start of interval is out of range: " <<
s2 <<
", skipping the row" << std::endl;
436 <<
"\nWarning: end of interval is out of range: " <<
s2 <<
", force [" <<
first <<
"," <<
last <<
"] range"
441 <<
"\nWarning: inverse/spillover range " <<
s2 <<
", accounting for circular orbit as [0," <<
last
442 <<
"] & [" <<
first <<
",3563]" << std::endl;
446 std::vector<std::string>
algos;
447 std::vector<std::pair<unsigned long, unsigned long>> orderedRanges;
449 if (!broadcastAlgo) {
450 algos.push_back(bx_algo_name[row]);
451 orderedRanges.push_back(std::make_pair(
first,
last));
453 for (
const auto &
i : non_default_bx_ranges) {
455 orderedRanges.push_back(std::make_pair(
first,
last));
459 if (!broadcastAlgo) {
460 algos.push_back(bx_algo_name[row]);
461 algos.push_back(bx_algo_name[row]);
462 orderedRanges.push_back(std::make_pair(0,
last));
463 orderedRanges.push_back(std::make_pair(
first, 3563));
465 for (
const auto &
i : non_default_bx_ranges) {
468 orderedRanges.push_back(std::make_pair(0,
last));
469 orderedRanges.push_back(std::make_pair(
first, 3563));
476 unsigned int first = orderedRanges[
item].first;
477 unsigned int last = orderedRanges[
item].second;
479 std::set<Range_t, RangeComp_t> &
ranges = non_default_bx_ranges[
algoName];
493 std::set<Range_t>::iterator curr =
ranges.end();
494 std::set<Range_t>::iterator succ =
496 std::set<Range_t>::iterator pred = succ;
497 if (pred !=
ranges.begin())
502 if ((pred ==
ranges.end() || pred->second <
first) && (succ ==
ranges.end() || succ->first >
last)) {
504 if (m_bx_mask_default != bx_mask[row])
509 Range_t newPred, newSucc;
510 bool modifiedPred =
false, gapInPred =
false, modifiedSucc =
false, dropSucc =
false;
512 if (pred !=
ranges.end() && pred->second >=
first && pred->second <=
last) {
513 if (m_bx_mask_default != bx_mask[row]) {
514 if (
last == pred->second) {
516 modifiedPred =
false;
519 newPred.first = pred->first;
520 newPred.second =
last;
525 newPred.first = pred->first;
526 newPred.second =
first - 1;
532 if (pred !=
ranges.end() && pred->second >
first && pred->second >
last) {
533 if (m_bx_mask_default != bx_mask[row]) {
535 modifiedPred =
false;
538 newPred.first =
first;
539 newPred.second =
last;
545 if (succ !=
ranges.end() && succ->first <=
last) {
546 if (m_bx_mask_default != bx_mask[row]) {
548 newSucc.first =
first;
549 newSucc.second = succ->second;
552 newSucc.first =
last + 1;
553 newSucc.second = succ->second;
554 if (newSucc.first > 3563 || newSucc.first > newSucc.second)
560 if (modifiedPred && modifiedSucc && newPred.second >= newSucc.first) {
562 newPred.second = newSucc.second;
563 newSucc.first = newPred.first;
564 ranges.erase(pred, ++succ);
565 curr =
ranges.insert(newPred).first;
571 curr =
ranges.insert(newPred).first;
574 Range_t
r1(pred->first, newPred.first - 1);
575 Range_t
r2(newPred.second + 1, pred->second);
585 curr =
ranges.insert(newSucc).first;
592 if (curr !=
ranges.end()) {
593 std::set<Range_t, RangeComp_t>::iterator last_covered =
ranges.upper_bound(std::make_pair(curr->second, 0));
594 if (last_covered !=
ranges.begin())
597 last_covered =
ranges.end();
599 if (last_covered !=
ranges.end() && last_covered->first != curr->first) {
601 if (curr->second < last_covered->second) {
603 Range_t newRange(curr->first, last_covered->second);
605 curr =
ranges.insert(newRange).first;
607 ranges.erase(++curr, last_covered);
613 if (default_bxmask_row < 0) {
615 <<
"\nWarning: No default found in BX mask xml, used 1 (unmasked) as default" << std::endl;
618 for (
auto &
algo : non_default_bx_ranges) {
620 unsigned int algoBit = algoName2bit[
algoName];
623 triggerAlgoBxMaskAlgoTrig[
bx].push_back(algoBit);
628 for (
unsigned int iSet = 0; iSet <
prescales.size(); iSet++) {
629 for (
unsigned int iBit = 0; iBit <
prescales[iSet].size(); iBit++) {
631 if (iBit >= triggerMasks.size()) {
633 <<
"\nWarning: algoBit in prescale table >= triggerMasks.size() "
634 <<
"\nWarning: no information on masking bit or not, setting as unmasked " << std::endl;
636 prescales[iSet][iBit] *= triggerMasks[iBit];
652 edm::LogInfo(
"L1-O2O: L1TCaloParamsOnlineProd") <<
"SummaryForFunctionManager: uGTrs | OK | All looks good";