Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:13:37

0001 #include "DQMOffline/Trigger/interface/EgHLTComCodes.h"
0002 
0003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0004 
0005 using namespace egHLT;
0006 
0007 void ComCodes::setCode(const char* descript, int code) {
0008   bool found = false;
0009   for (size_t i = 0; i < _codeDefs.size() && !found; i++) {
0010     if (_codeDefs[i].first == descript)
0011       found = true;
0012   }
0013   if (!found)
0014     _codeDefs.emplace_back(descript, code);
0015 
0016   //_codeDefs[descript] = code;
0017 }
0018 
0019 int ComCodes::getCode(const char* descript) const {
0020   int code = 0x0000;
0021   char const* const end = descript + strlen(descript);
0022   char const* codeKey = descript;
0023   char const* token = nullptr;
0024   do {
0025     token = std::find(codeKey, end, ':');
0026 
0027     bool found = false;
0028     for (auto const& c : _codeDefs) {
0029       if (0 == c.first.compare(0, std::string::npos, codeKey, token - codeKey)) {
0030         code |= c.second;
0031         found = true;
0032         break;
0033       }
0034     }
0035     if (!found)
0036       edm::LogWarning("EgHLTComCodes")
0037           << "ComCodes::getCode : Error, Key " << std::string(codeKey, token - codeKey)
0038           << " not found (likely mistyped, practical upshot is the selection is not what you think it is)";  //<<std::endl;
0039     codeKey = token + 1;
0040   } while (token != end);
0041   return code;
0042 }
0043 
0044 bool ComCodes::keyComp(const std::pair<std::string, int>& lhs, const std::pair<std::string, int>& rhs) {
0045   return lhs.first < rhs.first;
0046 }
0047 
0048 void ComCodes::getCodeName(int code, std::string& id) const {
0049   id.clear();
0050   for (auto const& _codeDef : _codeDefs) {
0051     if ((code & _codeDef.second) == _codeDef.second) {
0052       if (!id.empty())
0053         id += ":";  //seperating entries by a ':'
0054       id += _codeDef.first;
0055     }
0056   }
0057 }