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 {
11  auto *p = new TrigCodes();
12 
13  for (size_t i=0;i<filterNames.size();i++) {
14  p->setCode(filterNames[i].c_str(),i);
15  }
16  p->sort();
17 
18  return p;
19 }
20 
21 void TrigCodes::setCode(const char* descript,int bitNr)
22 {
23  if(bitNr < maxNrBits_){
24  TrigBitSet code;
25  code.set(bitNr);
26  setCode(descript,code);
27  }else{
28  edm::LogWarning("TrigCodes::TrigBitSetMap") <<" Warning, trying to store at bit "<<bitNr<<" but max nr bits is "<<maxNrBits_;
29  }
30 }
31 
32 void TrigCodes::setCode(const char* descript,TrigBitSet code)
33 {
34  bool found=false;
35  for(size_t i=0;i<codeDefs_.size() && !found;i++){
36  if(codeDefs_[i].first==descript) found=true;
37  }
38  if(!found) codeDefs_.emplace_back(descript,code);
39  //_codeDefs[descript] = code;
40 }
41 
42 
43 
44 TrigCodes::TrigBitSet TrigCodes::getCode(const char* descript)const
45 {
46  TrigBitSet code;
47 
48  char const * const end = descript+strlen(descript);
49  char const * codeKey = descript;
50  char const * token = nullptr;
51  do {
52  token = std::find(codeKey, end, ':');
53 
54  for(auto const& c: codeDefs_) {
55  if(0==c.first.compare(0,std::string::npos,codeKey, token-codeKey)){
56  code |= c.second;
57  break;
58  }
59  }
60  codeKey = token+1;
61  } while(token != end);
62  return code;
63 }
64 
65 bool TrigCodes::keyComp(const std::pair<std::string,TrigBitSet>& lhs,const std::pair<std::string,TrigBitSet>& rhs)
66 {
67  return lhs.first < rhs.first;
68 }
69 
71 {
72  id.clear();
73  for(auto const & codeDef : codeDefs_){
74  if((code&codeDef.second)==codeDef.second){
75  if(!id.empty()) id+=":";//seperating entries by a ':'
76  id+=codeDef.first;
77  }
78 
79  }
80 
81 }
82 
84 {
85  std::ostringstream msg;
86  msg <<" trig bits defined: "<<std::endl;
87  for(auto & codeDef : codeDefs_) msg <<" key : "<<codeDef.first<<" bit "<<codeDef.second<<std::endl;
88  edm::LogInfo("TrigCodes") << msg.str();
89 
90 }
TrigBitSet getCode(const char *descript) const
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:20
static TrigCodes * makeCodes(std::vector< std::string > &filterNames)
#define end
Definition: vmac.h:39
std::vector< std::pair< std::string, TrigBitSet > > codeDefs_
TrigCodes()=default
tuple msg
Definition: mps_check.py:285
static const int maxNrBits_
void getCodeName(TrigBitSet code, std::string &id) const
std::bitset< maxNrBits_ > TrigBitSet
static bool keyComp(const std::pair< std::string, TrigBitSet > &lhs, const std::pair< std::string, TrigBitSet > &rhs)