Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
/**
 * \class GlobalObject
 *
 *
 * Description: define an enumeration of L1 GT objects.
 *
 * Implementation:
 *    <TODO: enter implementation details>
 *
 * \author: Vasile Mihai Ghete - HEPHY Vienna
 *
 *
 */

#include "DataFormats/L1TGlobal/interface/GlobalObject.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"

l1t::GlobalObject l1t::GlobalObjectStringToEnum(const std::string& label) {
  l1t::GlobalObject ret = l1t::ObjNull;
  unsigned int nMatches = 0;

  for (auto const& [value, name] : l1t::kGlobalObjectEnumStringPairs) {
    if (name == label) {
      ++nMatches;
      ret = value;
    }
  }

  if (nMatches == 0) {
    edm::LogWarning("l1tGlobalObjectStringToEnum")
        << "Failed to find l1t::GlobalObject corresponding to \"" << label << "\"."
        << " Will return l1t::ObjNull (" << ret << ").";
  } else if (nMatches > 1) {
    edm::LogError("l1tGlobalObjectStringToEnum")
        << "Multiple matches (" << nMatches << ") found for label \"" << label << "\"."
        << " Will return last valid match (" << ret << ")."
        << " Please remove duplicates from l1t::kGlobalObjectEnumStringPairs !!";
  }

  return ret;
}

std::string l1t::GlobalObjectEnumToString(const l1t::GlobalObject& gtObject) {
  std::string ret = "ObjNull";
  unsigned int nMatches = 0;

  for (auto const& [value, name] : l1t::kGlobalObjectEnumStringPairs) {
    if (value == gtObject) {
      ++nMatches;
      ret = name;
    }
  }

  if (nMatches == 0) {
    edm::LogWarning("l1TGtObjectEnumToString") << "Failed to find l1t::GlobalObject with a value of " << gtObject << "."
                                               << " Will return \"" << ret << "\".";
  } else if (nMatches > 1) {
    edm::LogError("l1TGtObjectEnumToString")
        << "Multiple matches (" << nMatches << ") found for l1t::GlobalObject value of " << gtObject
        << ". Will return last valid match (\"" << ret << "\")."
        << " Please remove duplicates from l1t::kGlobalObjectEnumStringPairs !!";
  }

  return ret;
}