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");
57 <<
"returning empty L1TGlobalPrescalesVetosFract object";
58 return std::make_unique<const L1TGlobalPrescalesVetosFract>();
62 unsigned int m_numberPhysTriggers = 512;
65 std::unordered_map<std::string, int, std::hash<std::string>> algoName2bit;
67 std::string uGTtscKey = objectKey.substr(0, objectKey.find(
':'));
68 std::string uGTrsKey = objectKey.substr(objectKey.find(
':') + 1, std::string::npos);
73 std::vector<std::string> queryStrings;
74 queryStrings.push_back(
"L1_MENU");
81 edm::LogError(
"L1-O2O") <<
"Cannot get UGT_KEYS.L1_MENU for ID = " << uGTtscKey <<
" ";
83 throw std::runtime_error(
"SummaryForFunctionManager: uGTrs | Faulty | Broken key");
86 <<
"returning empty L1TGlobalPrescalesVetosFract object";
87 return std::make_unique<const L1TGlobalPrescalesVetosFract>();
94 edm::LogInfo(
"L1-O2O: L1TGlobalPrescalesVetosOnlineProd") <<
"Producing L1TUtmTriggerMenu with key =" << l1_menu_key;
96 if (uGTtscKey.empty()) {
97 edm::LogError(
"L1-O2O: L1TGlobalPrescalesVetosOnlineProd") <<
"TSC key is empty, returning";
99 throw std::runtime_error(
"SummaryForFunctionManager: uGTrs | Faulty | Empty objectKey");
102 <<
"returning empty L1TGlobalPrescalesVetosFract object";
103 return std::make_unique<const L1TGlobalPrescalesVetosFract>();
107 std::vector<std::string> queryColumns;
108 queryColumns.push_back(
"CONF");
115 <<
"Cannot get UGT_L1_MENU.CONF for ID = " << l1_menu_key;
117 throw std::runtime_error(
"SummaryForFunctionManager: uGTrs | Faulty | Broken key");
120 <<
"returning empty L1TGlobalPrescalesVetosFract object";
121 return std::make_unique<const L1TGlobalPrescalesVetosFract>();
128 std::istringstream iss(l1Menu);
130 std::shared_ptr<L1TUtmTriggerMenu> pMenu(
131 const_cast<L1TUtmTriggerMenu *>(reinterpret_cast<const L1TUtmTriggerMenu *>(tmeventsetup::getTriggerMenu(iss))));
133 for (
const auto &
algo : pMenu->getAlgorithmMap())
134 algoName2bit[
algo.first] =
algo.second.getIndex();
137 queryColumns.clear();
138 queryColumns.push_back(
"ALGOBX_MASK");
139 queryColumns.push_back(
"ALGO_FINOR_MASK");
140 queryColumns.push_back(
"ALGO_FINOR_VETO");
141 queryColumns.push_back(
"ALGO_PRESCALE");
143 std::string prescale_key, bxmask_key, mask_key, vetomask_key;
144 std::string xmlPayload_prescale, xmlPayload_mask_algobx, xmlPayload_mask_finor, xmlPayload_mask_veto;
146 std::map<std::string, std::string> subKeys =
148 prescale_key = subKeys[
"ALGO_PRESCALE"];
149 bxmask_key = subKeys[
"ALGOBX_MASK"];
150 mask_key = subKeys[
"ALGO_FINOR_MASK"];
151 vetomask_key = subKeys[
"ALGO_FINOR_VETO"];
153 xmlPayload_mask_algobx =
156 xmlPayload_mask_veto =
158 }
catch (std::runtime_error &
e) {
159 edm::LogError(
"L1-O2O: L1TGlobalPrescalesVetosOnlineProd") <<
e.what();
161 throw std::runtime_error(
std::string(
"SummaryForFunctionManager: uGTrs | Faulty | ") +
e.what());
164 <<
"returning empty L1TGlobalPrescalesVetosFract object";
165 return std::make_unique<const L1TGlobalPrescalesVetosFract>();
171 output1 << xmlPayload_prescale;
174 output2 << xmlPayload_mask_finor;
177 output3 << xmlPayload_mask_algobx;
179 std::ofstream output4(
std::string(
"/tmp/").
append(vetomask_key.substr(0, vetomask_key.find(
'/'))).append(
".xml"));
180 output4 << xmlPayload_mask_veto;
185 std::vector<std::vector<double>>
prescales;
186 std::vector<unsigned int> triggerMasks;
187 std::vector<int> triggerVetoMasks;
188 std::map<int, std::vector<int>> triggerAlgoBxMaskAlgoTrig;
194 ts_prescale.
addProcessor(
"uGtProcessor",
"uGtProcessor",
"-1",
"-1");
201 const std::map<std::string, l1t::Parameter> &settings_prescale = ts_prescale.
getParameters(
"uGtProcessor");
202 std::map<std::string, unsigned int> prescaleColumns = settings_prescale.at(
"prescales").getColumnIndices();
204 unsigned int numColumns_prescale = prescaleColumns.size();
205 int nPrescaleSets = numColumns_prescale - 1;
206 std::vector<std::string> algoNames =
207 settings_prescale.at(
"prescales").getTableColumn<
std::string>(
"algo/prescale-index");
209 if (nPrescaleSets > 0) {
211 for (
int iSet = 0; iSet < nPrescaleSets; iSet++) {
212 prescales.push_back(std::vector<double>());
213 for (
unsigned int iBit = 0; iBit < m_numberPhysTriggers; ++iBit) {
214 double inputDefaultPrescale = 0;
215 prescales[iSet].push_back(inputDefaultPrescale);
219 for (
auto &
col : prescaleColumns) {
222 int iSet =
col.second - 1;
223 std::vector<double> prescalesForSet =
224 settings_prescale.at(
"prescales").getTableColumn<
double>(
col.first.c_str());
225 for (
unsigned int row = 0; row < prescalesForSet.size(); row++) {
226 double prescale = prescalesForSet[row];
228 unsigned int algoBit = algoName2bit[
algoName];
233 }
catch (std::runtime_error &
e) {
235 throw std::runtime_error(
std::string(
"SummaryForFunctionManager: uGTrs | Faulty | ") +
e.what());
238 <<
"returning empty L1TGlobalPrescalesVetosFract object";
239 return std::make_unique<const L1TGlobalPrescalesVetosFract>();
249 ts_mask_finor.
addProcessor(
"uGtProcessor",
"uGtProcessor",
"-1",
"-1");
256 const std::map<std::string, l1t::Parameter> &settings_mask_finor = ts_mask_finor.
getParameters(
"uGtProcessor");
258 std::vector<std::string> algo_mask_finor = settings_mask_finor.at(
"finorMask").getTableColumn<
std::string>(
"algo");
259 std::vector<unsigned int> mask_mask_finor =
260 settings_mask_finor.at(
"finorMask").getTableColumn<
unsigned int>(
"mask");
263 unsigned int default_finor_mask = 1;
264 auto default_finor_row = std::find_if(algo_mask_finor.cbegin(), algo_mask_finor.cend(), [](
const std::string &
s) {
266 return strcasecmp(
"all",
s.c_str()) == 0;
268 if (default_finor_row == algo_mask_finor.cend()) {
270 <<
"\nWarning: No default found in FinOR mask xml, use 1 (unmasked) as default" << std::endl;
272 default_finor_mask = mask_mask_finor[
std::distance(algo_mask_finor.cbegin(), default_finor_row)];
275 for (
unsigned int iAlg = 0; iAlg < m_numberPhysTriggers; iAlg++)
276 triggerMasks.push_back(default_finor_mask);
278 for (
unsigned int row = 0; row < algo_mask_finor.size(); row++) {
280 if (strcasecmp(
"all",
algoName.c_str()) == 0)
282 unsigned int algoBit = algoName2bit[
algoName];
283 unsigned int mask = mask_mask_finor[row];
284 if (algoBit < m_numberPhysTriggers)
285 triggerMasks[algoBit] = mask;
287 }
catch (std::runtime_error &
e) {
289 throw std::runtime_error(
std::string(
"SummaryForFunctionManager: uGTrs | Faulty | ") +
e.what());
292 <<
"returning empty L1TGlobalPrescalesVetosFract object";
293 return std::make_unique<const L1TGlobalPrescalesVetosFract>();
303 ts_mask_veto.
addProcessor(
"uGtProcessor",
"uGtProcessor",
"-1",
"-1");
310 const std::map<std::string, l1t::Parameter> &settings_mask_veto = ts_mask_veto.
getParameters(
"uGtProcessor");
311 std::vector<std::string> algo_mask_veto = settings_mask_veto.at(
"vetoMask").getTableColumn<
std::string>(
"algo");
312 std::vector<unsigned int> veto_mask_veto = settings_mask_veto.at(
"vetoMask").getTableColumn<
unsigned int>(
"veto");
315 unsigned int default_veto_mask = 1;
316 auto default_veto_row = std::find_if(algo_mask_veto.cbegin(), algo_mask_veto.cend(), [](
const std::string &
s) {
318 return strcasecmp(
"all",
s.c_str()) == 0;
320 if (default_veto_row == algo_mask_veto.cend()) {
322 <<
"\nWarning: No default found in Veto mask xml, use 0 (unvetoed) as default" << std::endl;
324 default_veto_mask = veto_mask_veto[
std::distance(algo_mask_veto.cbegin(), default_veto_row)];
327 for (
unsigned int iAlg = 0; iAlg < m_numberPhysTriggers; iAlg++)
328 triggerVetoMasks.push_back(default_veto_mask);
330 for (
unsigned int row = 0; row < algo_mask_veto.size(); row++) {
332 if (strcasecmp(
"all",
algoName.c_str()) == 0)
334 unsigned int algoBit = algoName2bit[
algoName];
335 unsigned int veto = veto_mask_veto[row];
336 if (algoBit < m_numberPhysTriggers)
337 triggerVetoMasks[algoBit] =
int(
veto);
339 }
catch (std::runtime_error &
e) {
341 throw std::runtime_error(
std::string(
"SummaryForFunctionManager: uGTrs | Faulty | ") +
e.what());
344 <<
"returning empty L1TGlobalPrescalesVetosFract object";
345 return std::make_unique<const L1TGlobalPrescalesVetosFract>();
352 unsigned int m_bx_mask_default = 1;
354 std::vector<std::string> bx_algo_name;
355 std::vector<std::string> bx_range;
356 std::vector<unsigned int> bx_mask;
361 ts_mask_algobx.
addProcessor(
"uGtProcessor",
"uGtProcessor",
"-1",
"-1");
368 const std::map<std::string, l1t::Parameter> &settings_mask_algobx = ts_mask_algobx.
getParameters(
"uGtProcessor");
369 bx_algo_name = settings_mask_algobx.at(
"algorithmBxMask").getTableColumn<
std::string>(
"algo");
370 bx_range = settings_mask_algobx.at(
"algorithmBxMask").getTableColumn<
std::string>(
"range");
371 bx_mask = settings_mask_algobx.at(
"algorithmBxMask").getTableColumn<
unsigned int>(
"mask");
372 }
catch (std::runtime_error &
e) {
374 throw std::runtime_error(
std::string(
"SummaryForFunctionManager: uGTrs | Faulty | ") +
e.what());
377 <<
"returning empty L1TGlobalPrescalesVetosFract object";
378 return std::make_unique<const L1TGlobalPrescalesVetosFract>();
382 int default_bxmask_row = -1;
383 typedef std::pair<unsigned long, unsigned long> Range_t;
386 bool operator()(
const Range_t &
a,
const Range_t &
b)
const {
return a.first <
b.first; }
388 std::map<std::string, std::set<Range_t, RangeComp_t>> non_default_bx_ranges;
390 for (
unsigned int row = 0; row < bx_algo_name.size(); row++) {
394 bool broadcastAlgo =
false;
395 bool broadcastRange =
false;
396 if (strcasecmp(
"all", s1.c_str()) == 0)
397 broadcastAlgo =
true;
398 if (strcasecmp(
"all", s2.c_str()) == 0)
399 broadcastRange =
true;
401 if (broadcastAlgo && broadcastRange) {
404 <<
"\nWarning: ALL-ALL row is not the first one, ignore it assuming 1 (unmasked) as the default"
408 if (default_bxmask_row >= 0) {
410 <<
"\nWarning: multiple ALL-ALL rows found, using the first" << std::endl;
413 default_bxmask_row = row;
414 m_bx_mask_default = bx_mask[row];
419 if (broadcastRange) {
423 char *dash =
nullptr;
424 first = strtoul(s2.data(), &dash, 0);
425 while (*dash !=
'\0' && *dash !=
'-')
427 last = (*dash !=
'\0' ? strtoul(++dash, &dash, 0) :
first);
435 <<
"\nWarning: parsing " << s2 <<
" as [" <<
first <<
"," <<
last <<
"] range" << std::endl;
439 <<
"\nWarning: start of interval is out of range: " << s2 <<
", skipping the row" << std::endl;
445 <<
"\nWarning: end of interval is out of range: " << s2 <<
", force [" <<
first <<
"," <<
last <<
"] range"
450 <<
"\nWarning: inverse/spillover range " << s2 <<
", accounting for circular orbit as [0," <<
last
451 <<
"] & [" <<
first <<
",3563]" << std::endl;
455 std::vector<std::string>
algos;
456 std::vector<std::pair<unsigned long, unsigned long>> orderedRanges;
458 if (!broadcastAlgo) {
459 algos.push_back(bx_algo_name[row]);
460 orderedRanges.push_back(std::make_pair(
first,
last));
462 for (
const auto &
i : non_default_bx_ranges) {
464 orderedRanges.push_back(std::make_pair(
first,
last));
468 if (!broadcastAlgo) {
469 algos.push_back(bx_algo_name[row]);
470 algos.push_back(bx_algo_name[row]);
471 orderedRanges.push_back(std::make_pair(0,
last));
472 orderedRanges.push_back(std::make_pair(
first, 3563));
474 for (
const auto &
i : non_default_bx_ranges) {
477 orderedRanges.push_back(std::make_pair(0,
last));
478 orderedRanges.push_back(std::make_pair(
first, 3563));
485 unsigned int first = orderedRanges[
item].first;
486 unsigned int last = orderedRanges[
item].second;
488 std::set<Range_t, RangeComp_t> &
ranges = non_default_bx_ranges[
algoName];
502 std::set<Range_t>::iterator curr =
ranges.end();
503 std::set<Range_t>::iterator succ =
505 std::set<Range_t>::iterator pred = succ;
506 if (pred !=
ranges.begin())
511 if ((pred ==
ranges.end() || pred->second <
first) && (succ ==
ranges.end() || succ->first >
last)) {
513 if (m_bx_mask_default != bx_mask[row])
518 Range_t newPred, newSucc;
519 bool modifiedPred =
false, gapInPred =
false, modifiedSucc =
false, dropSucc =
false;
521 if (pred !=
ranges.end() && pred->second >=
first && pred->second <=
last) {
522 if (m_bx_mask_default != bx_mask[row]) {
523 if (
last == pred->second) {
525 modifiedPred =
false;
528 newPred.first = pred->first;
529 newPred.second =
last;
534 newPred.first = pred->first;
535 newPred.second =
first - 1;
541 if (pred !=
ranges.end() && pred->second >
first && pred->second >
last) {
542 if (m_bx_mask_default != bx_mask[row]) {
544 modifiedPred =
false;
547 newPred.first =
first;
548 newPred.second =
last;
554 if (succ !=
ranges.end() && succ->first <=
last) {
555 if (m_bx_mask_default != bx_mask[row]) {
557 newSucc.first =
first;
558 newSucc.second = succ->second;
561 newSucc.first =
last + 1;
562 newSucc.second = succ->second;
563 if (newSucc.first > 3563 || newSucc.first > newSucc.second)
569 if (modifiedPred && modifiedSucc && newPred.second >= newSucc.first) {
571 newPred.second = newSucc.second;
572 newSucc.first = newPred.first;
573 ranges.erase(pred, ++succ);
574 curr =
ranges.insert(newPred).first;
580 curr =
ranges.insert(newPred).first;
583 Range_t
r1(pred->first, newPred.first - 1);
584 Range_t
r2(newPred.second + 1, pred->second);
594 curr =
ranges.insert(newSucc).first;
601 if (curr !=
ranges.end()) {
602 std::set<Range_t, RangeComp_t>::iterator last_covered =
ranges.upper_bound(std::make_pair(curr->second, 0));
603 if (last_covered !=
ranges.begin())
606 last_covered =
ranges.end();
608 if (last_covered !=
ranges.end() && last_covered->first != curr->first) {
610 if (curr->second < last_covered->second) {
612 Range_t newRange(curr->first, last_covered->second);
614 curr =
ranges.insert(newRange).first;
616 ranges.erase(++curr, last_covered);
622 if (default_bxmask_row < 0) {
624 <<
"\nWarning: No default found in BX mask xml, used 1 (unmasked) as default" << std::endl;
627 for (
auto &
algo : non_default_bx_ranges) {
629 unsigned int algoBit = algoName2bit[
algoName];
632 triggerAlgoBxMaskAlgoTrig[
bx].push_back(algoBit);
637 for (
unsigned int iSet = 0; iSet <
prescales.size(); iSet++) {
638 for (
unsigned int iBit = 0; iBit <
prescales[iSet].size(); iBit++) {
640 if (iBit >= triggerMasks.size()) {
642 <<
"\nWarning: algoBit in prescale table >= triggerMasks.size() "
643 <<
"\nWarning: no information on masking bit or not, setting as unmasked " << std::endl;
645 prescales[iSet][iBit] *= triggerMasks[iBit];
654 data_.setBxMaskDefault(m_bx_mask_default);
656 data_.setTriggerMaskVeto(triggerVetoMasks);
657 data_.setTriggerAlgoBxMask(triggerAlgoBxMaskAlgoTrig);
659 auto payload = std::make_unique<const L1TGlobalPrescalesVetosFract>(*data_.getWriteInstance());
661 edm::LogInfo(
"L1-O2O: L1TCaloParamsOnlineProd") <<
"SummaryForFunctionManager: uGTrs | OK | All looks good";