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  //first copy the character string to a local array so we can manipulate it
47  char localDescript[512];
48  strcpy(localDescript,descript);
49 
50  TrigBitSet code;
51  char* codeKey = strtok(localDescript,":");
52  // std::map<std::string,int> ::const_iterator mapIt;
53  while(codeKey!=nullptr){
54  bool found=false;
55 
56  for(size_t i=0;i<codeDefs_.size() && !found;i++){
57  if(codeDefs_[i].first==codeKey){
58  found=true;
59  code |= codeDefs_[i].second;
60 
61  }
62  }
63 
64  // if(!found) edm::LogError("TrigCodes::TrigBitSetMap") <<"TrigCodes::TrigBitSetMap::getCode : Error, Key "<<codeKey<<" not found";
65  codeKey = strtok(nullptr,":"); //getting new substring
66 
67  }
68  return code;
69 }
70 
71 bool TrigCodes::keyComp(const std::pair<std::string,TrigBitSet>& lhs,const std::pair<std::string,TrigBitSet>& rhs)
72 {
73  return lhs.first < rhs.first;
74 }
75 
77 {
78  id.clear();
79  for(auto const & codeDef : codeDefs_){
80  if((code&codeDef.second)==codeDef.second){
81  if(!id.empty()) id+=":";//seperating entries by a ':'
82  id+=codeDef.first;
83  }
84 
85  }
86 
87 }
88 
90 {
91  std::ostringstream msg;
92  msg <<" trig bits defined: "<<std::endl;
93  for(auto & codeDef : codeDefs_) msg <<" key : "<<codeDef.first<<" bit "<<codeDef.second<<std::endl;
94  edm::LogInfo("TrigCodes") << msg.str();
95 
96 }
TrigBitSet getCode(const char *descript) const
void setCode(const char *descript, TrigBitSet code)
static TrigCodes * makeCodes(std::vector< std::string > &filterNames)
std::vector< std::pair< std::string, TrigBitSet > > codeDefs_
TrigCodes()=default
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)