103 std::vector<std::string> config;
104 if (!
readDataFile(
"TrigGlobalEfficiencyCorrection/Triggers.cfg", config))
106 std::stringstream
ss;
107 std::string triggerName, token;
109 for (
auto& line : config) {
125 for (std::size_t& leg : def.leg) {
139 <<
"' found in Triggers.cfg");
149 "Unknown trigger leg '"
151 <<
"' (inferred from trigger name) found in Triggers.cfg");
192 else if ((ne + nm) == 1)
199 if (std::count(def.leg.cbegin(), def.leg.cend(), def.leg[0]) == 4) {
203 }
else if (ne + nm == 0 || ne == 3 ||
211 bool sym = (def.leg[0] == def.leg[1] || def.leg[1] == def.leg[2]);
218 else if (ne + nm == 1)
230 else if (ne + nm == 0)
232 else if (ne == 1 && nm == 1)
245 ATH_MSG_ERROR(
"Configuration issue for trigger " << triggerName);
347 std::vector<std::string> config;
348 if (!
readDataFile(
"TrigGlobalEfficiencyCorrection/Hierarchies.cfg", config))
350 std::stringstream
ss;
351 std::string token,
unit;
352 std::map<std::size_t, std::vector<std::size_t> > aliases;
353 for (
auto& line : config) {
357 if (line[0] ==
'[') {
360 Hierarchy{(short)m_hierarchyData.size(), 0, 0.f,
361 std::numeric_limits<float>::max()});
362 if (line[1] ==
'-' && line[2] ==
']')
368 else if (line[1] ==
'<')
372 if (!
ss || sep !=
'-' || (
unit !=
"GeV]" &&
unit !=
"MeV]")) {
373 ATH_MSG_ERROR(
"Unable to parse pT restrictions in Hierarchies.cfg");
376 if (
unit ==
"GeV]") {
378 if (
meta.maxPt < std::numeric_limits<float>::max())
382 while (
ss >> token) {
384 auto itr = aliases.find(
h);
385 if (itr == aliases.end()) {
388 << token <<
"' found in Hierarchies.cfg");
396 if (
ss >> token && token !=
">")
400 success = success &&
meta.nLegs;
403 auto& legs = aliases[
m_hasher(token)];
404 if (
ss >> token && token ==
":=") {
406 while (
ss >> token) {
412 << token <<
"' found in Hierarchies.cfg");
415 if (
ss >> token && token !=
">")
418 success = success && legs.size();
423 ATH_MSG_ERROR(
"Failed parsing line from Hierarchies.cfg:\n" << line);
433 const std::string& version,
434 std::map<std::size_t, std::map<std::size_t, int> >& keysPerLeg) {
436 std::vector<std::string> config;
437 if (!
readDataFile(
"TrigGlobalEfficiencyCorrection/MapKeys.cfg", config))
439 std::stringstream
ss;
441 bool reading =
false;
442 for (
auto& line : config) {
443 std::size_t pos = line.find(
"[VERSION]");
444 if (pos != std::string::npos) {
448 while (std::getline(
ss, token,
',')) {
449 if (token == version) {
463 ATH_MSG_ERROR(
"Malformed line from TrigGlobalEfficiencyCorrection/MapKeys.cfg: " << line);
466 year = 1 << (year - 2015);
468 auto& keys = keysPerLeg[leg];
469 while (
ss >> token) {
471 auto insertion = keys.emplace(
h, year);
472 if (insertion.second)
475 insertion.first->second |= year;
478 if (!keysPerLeg.size()) {
479 ATH_MSG_ERROR(
"Unable to import the available map keys for the version "
487 const std::string& period, std::pair<unsigned, unsigned>& boundaries) {
491 boundaries = itr->second;
495 auto sep = period.find_first_of(
'-');
496 if (sep != std::string::npos) {
497 std::string kwMin = period.substr(0, sep);
498 std::string kwMax = period.substr(sep + 1);
503 boundaries = std::minmax({itrMin->second.first, itrMax->second.first,
504 itrMin->second.second, itrMax->second.second});
509 boundaries = std::minmax(std::stoi(kwMin), std::stoi(kwMax));
514 ATH_MSG_ERROR(
"Unable to understand the period/range " << period);
547 const std::string& triggerString,
bool& success) {
549 if (s.find(
"|||") != std::string::npos) {
551 << triggerString <<
"'");
557 auto i = s.find(
"||");
558 if (i == std::string::npos)
562 if (s ==
"" || s ==
"|") {
564 << triggerString <<
"'");
568 std::vector<TrigDef> triggers;
569 std::set<std::size_t> hashes;
570 std::stringstream
ss(s);
571 while (std::getline(
ss, s,
'|')) {
577 << s <<
"' found while parsing trigger combination");
581 if (!hashes.insert(trig).second) {
583 << s <<
"' is present more than once in the combination");
587 triggers.push_back(itr->second);
589 success = success && triggers.size();
594 const std::map<std::string, std::string>& triggerCombination,
595 const std::string& version, std::map<std::string, std::string>& legsPerKey,
602 std::map<std::size_t, int> legs;
604 for (
auto& kv : triggerCombination) {
612 for (
int k = 0; k < 32; ++k) {
615 itrPeriod->second.first <= itr->second.second &&
616 itrPeriod->second.second >= itr->second.first) {
623 for (
auto& trig : triggers) {
624 for (std::size_t leg : trig.leg) {
626 auto insertion = legs.emplace(leg, years);
627 if (!insertion.second)
628 insertion.first->second |= years;
637 std::map<std::size_t, std::map<std::size_t, int> > allKeys;
640 std::map<std::size_t, std::vector<std::size_t> > allLegsPerKey;
641 std::set<std::size_t> legsWithMultipleKeys;
642 bool sameKeyForAllyears =
true;
643 while (legs.size()) {
644 allLegsPerKey.clear();
645 for (
auto& kvLegs : legs)
647 std::size_t leg = kvLegs.first;
648 int years = kvLegs.second;
649 auto itrKeys = allKeys.find(leg);
650 if (itrKeys != allKeys.end()) {
651 for (
auto& kvKeys : itrKeys->second)
653 auto y = (kvKeys.second & years);
655 (!sameKeyForAllyears &&
659 auto insertion = allLegsPerKey.emplace(
660 kvKeys.first, std::vector<std::size_t>{leg});
661 if (!insertion.second)
662 insertion.first->second.push_back(leg);
667 "Sorry, no idea what the map key should be for the trigger leg '"
668 <<
m_dictionary.at(leg) <<
"', manual configuration is needed");
675 if (!allLegsPerKey.size()) {
676 if (sameKeyForAllyears) {
677 sameKeyForAllyears =
false;
684 using T =
decltype(allLegsPerKey)::value_type;
685 auto itrKey = std::max_element(
686 allLegsPerKey.begin(), allLegsPerKey.end(),
687 [](T&
x, T&
y) { return x.second.size() < y.second.size(); });
688 std::string& strLegs = legsPerKey[
m_dictionary.at(itrKey->first)];
689 for (std::size_t leg : itrKey->second) {
690 int& wantedYears = legs.at(leg);
691 int supportedYears = (allKeys.at(leg).at(itrKey->first)) & wantedYears;
692 if (supportedYears != wantedYears || legsWithMultipleKeys.count(leg)) {
693 legsWithMultipleKeys.insert(leg);
694 for (
int i = 0; i < 32; ++i) {
695 if (supportedYears & (1u << i)) {
696 if (strLegs.length() && strLegs.back() !=
',')
699 m_dictionary.at(leg) +
"[" + std::to_string(2015 + i) +
"]";
703 if (strLegs.length() && strLegs.back() !=
',')
707 if (supportedYears == wantedYears)
710 wantedYears &= ~supportedYears;
715 for (
auto& kv : legs) {
716 legsPerKey.emplace(std::to_string(legsPerKey.size()),
720 for (
auto& [key, legs] : legsPerKey) {
724 "Some of the requested triggers will result in "
725 "a default scale factor of 1 being returned");
734 std::vector<ImportData::TrigDef>& triggers) {
736 std::set<std::size_t> extraItems;
737 std::vector<ImportData::TrigDef> updatedTriggers;
738 for (
auto& trig : triggers) {
740 std::size_t pos = 0, len = name.find(
"_OR_");
741 if (len == std::string::npos) {
742 updatedTriggers.emplace_back(trig);
746 std::string item = name.substr(pos, len);
750 ATH_MSG_ERROR(
"while listing triggers for trigger matching; trigger \""
751 << item <<
"\" extracted from \"" << name
752 <<
"\" is not recognized");
755 if (extraItems.emplace(
h).second)
756 updatedTriggers.emplace_back(def->second);
757 if (len == std::string::npos)
760 len = name.find(
"_OR_", pos);
761 if (len != std::string::npos)
765 triggers.swap(updatedTriggers);