CMS 3D CMS Logo

EgHLTTrigCodes.cc
Go to the documentation of this file.
2 
4 
6 
7 using namespace egHLT;
8 
9 TrigCodes* TrigCodes::makeCodes(std::vector<std::string>& filterNames) {
10  auto* p = new TrigCodes();
11 
12  for (size_t i = 0; i < filterNames.size(); i++) {
13  p->setCode(filterNames[i].c_str(), i);
14  }
15  p->sort();
16 
17  return p;
18 }
19 
20 void TrigCodes::setCode(const char* descript, int bitNr) {
21  if (bitNr < maxNrBits_) {
22  TrigBitSet code;
23  code.set(bitNr);
24  setCode(descript, code);
25  } else {
26  edm::LogWarning("TrigCodes::TrigBitSetMap")
27  << " Warning, trying to store at bit " << bitNr << " but max nr bits is " << maxNrBits_;
28  }
29 }
30 
31 void TrigCodes::setCode(const char* descript, TrigBitSet code) {
32  bool found = false;
33  for (size_t i = 0; i < codeDefs_.size() && !found; i++) {
34  if (codeDefs_[i].first == descript)
35  found = true;
36  }
37  if (!found)
38  codeDefs_.emplace_back(descript, code);
39  //_codeDefs[descript] = code;
40 }
41 
42 TrigCodes::TrigBitSet TrigCodes::getCode(const char* descript) const {
43  TrigBitSet code;
44 
45  char const* const end = descript + strlen(descript);
46  char const* codeKey = descript;
47  char const* token = nullptr;
48  do {
49  token = std::find(codeKey, end, ':');
50 
51  for (auto const& c : codeDefs_) {
52  if (0 == c.first.compare(0, std::string::npos, codeKey, token - codeKey)) {
53  code |= c.second;
54  break;
55  }
56  }
57  codeKey = token + 1;
58  } while (token != end);
59  return code;
60 }
61 
62 bool TrigCodes::keyComp(const std::pair<std::string, TrigBitSet>& lhs, const std::pair<std::string, TrigBitSet>& rhs) {
63  return lhs.first < rhs.first;
64 }
65 
67  id.clear();
68  for (auto const& codeDef : codeDefs_) {
69  if ((code & codeDef.second) == codeDef.second) {
70  if (!id.empty())
71  id += ":"; //seperating entries by a ':'
72  id += codeDef.first;
73  }
74  }
75 }
76 
78  std::ostringstream msg;
79  msg << " trig bits defined: " << std::endl;
80  for (auto& codeDef : codeDefs_)
81  msg << " key : " << codeDef.first << " bit " << codeDef.second << std::endl;
82  edm::LogInfo("TrigCodes") << msg.str();
83 }
void setCode(const char *descript, TrigBitSet code)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
static TrigCodes * makeCodes(std::vector< std::string > &filterNames)
std::vector< std::pair< std::string, TrigBitSet > > codeDefs_
Log< level::Info, false > LogInfo
TrigCodes()=default
tuple msg
Definition: mps_check.py:286
static const int maxNrBits_
void getCodeName(TrigBitSet code, std::string &id) const
TrigBitSet getCode(const char *descript) const
Log< level::Warning, false > LogWarning
std::bitset< maxNrBits_ > TrigBitSet
static bool keyComp(const std::pair< std::string, TrigBitSet > &lhs, const std::pair< std::string, TrigBitSet > &rhs)