Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "DQMOffline/Trigger/interface/EgHLTTrigCodes.h"
0002 
0003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0004 
0005 const int egHLT::TrigCodes::maxNrBits_;
0006 
0007 using namespace egHLT;
0008 
0009 TrigCodes* TrigCodes::makeCodes(std::vector<std::string>& filterNames) {
0010   auto* p = new TrigCodes();
0011 
0012   for (size_t i = 0; i < filterNames.size(); i++) {
0013     p->setCode(filterNames[i].c_str(), i);
0014   }
0015   p->sort();
0016 
0017   return p;
0018 }
0019 
0020 void TrigCodes::setCode(const char* descript, int bitNr) {
0021   if (bitNr < maxNrBits_) {
0022     TrigBitSet code;
0023     code.set(bitNr);
0024     setCode(descript, code);
0025   } else {
0026     edm::LogWarning("TrigCodes::TrigBitSetMap")
0027         << " Warning, trying to store at bit " << bitNr << " but max nr bits is " << maxNrBits_;
0028   }
0029 }
0030 
0031 void TrigCodes::setCode(const char* descript, TrigBitSet code) {
0032   bool found = false;
0033   for (size_t i = 0; i < codeDefs_.size() && !found; i++) {
0034     if (codeDefs_[i].first == descript)
0035       found = true;
0036   }
0037   if (!found)
0038     codeDefs_.emplace_back(descript, code);
0039   //_codeDefs[descript] = code;
0040 }
0041 
0042 TrigCodes::TrigBitSet TrigCodes::getCode(const char* descript) const {
0043   TrigBitSet code;
0044 
0045   char const* const end = descript + strlen(descript);
0046   char const* codeKey = descript;
0047   char const* token = nullptr;
0048   do {
0049     token = std::find(codeKey, end, ':');
0050 
0051     for (auto const& c : codeDefs_) {
0052       if (0 == c.first.compare(0, std::string::npos, codeKey, token - codeKey)) {
0053         code |= c.second;
0054         break;
0055       }
0056     }
0057     codeKey = token + 1;
0058   } while (token != end);
0059   return code;
0060 }
0061 
0062 bool TrigCodes::keyComp(const std::pair<std::string, TrigBitSet>& lhs, const std::pair<std::string, TrigBitSet>& rhs) {
0063   return lhs.first < rhs.first;
0064 }
0065 
0066 void TrigCodes::getCodeName(TrigBitSet code, std::string& id) const {
0067   id.clear();
0068   for (auto const& codeDef : codeDefs_) {
0069     if ((code & codeDef.second) == codeDef.second) {
0070       if (!id.empty())
0071         id += ":";  //seperating entries by a ':'
0072       id += codeDef.first;
0073     }
0074   }
0075 }
0076 
0077 void TrigCodes::printCodes() {
0078   std::ostringstream msg;
0079   msg << " trig bits defined: " << std::endl;
0080   for (auto& codeDef : codeDefs_)
0081     msg << " key : " << codeDef.first << " bit " << codeDef.second << std::endl;
0082   edm::LogInfo("TrigCodes") << msg.str();
0083 }