Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:04:32

0001 /**
0002  * \class GlobalObject
0003  *
0004  *
0005  * Description: define an enumeration of L1 GT objects.
0006  *
0007  * Implementation:
0008  *    <TODO: enter implementation details>
0009  *
0010  * \author: Vasile Mihai Ghete - HEPHY Vienna
0011  *
0012  *
0013  */
0014 
0015 #include "DataFormats/L1TGlobal/interface/GlobalObject.h"
0016 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0017 
0018 l1t::GlobalObject l1t::GlobalObjectStringToEnum(const std::string& label) {
0019   l1t::GlobalObject ret = l1t::ObjNull;
0020   unsigned int nMatches = 0;
0021 
0022   for (auto const& [value, name] : l1t::kGlobalObjectEnumStringPairs) {
0023     if (name == label) {
0024       ++nMatches;
0025       ret = value;
0026     }
0027   }
0028 
0029   if (nMatches == 0) {
0030     edm::LogWarning("l1tGlobalObjectStringToEnum")
0031         << "Failed to find l1t::GlobalObject corresponding to \"" << label << "\"."
0032         << " Will return l1t::ObjNull (" << ret << ").";
0033   } else if (nMatches > 1) {
0034     edm::LogError("l1tGlobalObjectStringToEnum")
0035         << "Multiple matches (" << nMatches << ") found for label \"" << label << "\"."
0036         << " Will return last valid match (" << ret << ")."
0037         << " Please remove duplicates from l1t::kGlobalObjectEnumStringPairs !!";
0038   }
0039 
0040   return ret;
0041 }
0042 
0043 std::string l1t::GlobalObjectEnumToString(const l1t::GlobalObject& gtObject) {
0044   std::string ret = "ObjNull";
0045   unsigned int nMatches = 0;
0046 
0047   for (auto const& [value, name] : l1t::kGlobalObjectEnumStringPairs) {
0048     if (value == gtObject) {
0049       ++nMatches;
0050       ret = name;
0051     }
0052   }
0053 
0054   if (nMatches == 0) {
0055     edm::LogWarning("l1TGtObjectEnumToString") << "Failed to find l1t::GlobalObject with a value of " << gtObject << "."
0056                                                << " Will return \"" << ret << "\".";
0057   } else if (nMatches > 1) {
0058     edm::LogError("l1TGtObjectEnumToString")
0059         << "Multiple matches (" << nMatches << ") found for l1t::GlobalObject value of " << gtObject
0060         << ". Will return last valid match (\"" << ret << "\")."
0061         << " Please remove duplicates from l1t::kGlobalObjectEnumStringPairs !!";
0062   }
0063 
0064   return ret;
0065 }