CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EgHLTTrigCodes.cc
Go to the documentation of this file.
2 
4 
5 using namespace egHLT;
6 
8 
9 void TrigCodes::setCodes(std::vector<std::string>& filterNames)
10 {
11  if(trigBitSetMap_.size()!=0){
12  edm::LogWarning("TrigCodes") <<" Warning trigBitSetMap already filled ";
13  }else{
14  for(size_t i=0;i<filterNames.size();i++) trigBitSetMap_.setCode(filterNames[i].c_str(),i);
16  }
17 }
18 
19 void TrigCodes::TrigBitSetMap::setCode(const char* descript,int bitNr)
20 {
21  if(bitNr<maxNrBits()){
22  TrigBitSet code;
23  code.set(bitNr);
24  setCode(descript,code);
25  }else{
26  edm::LogWarning("TrigCodes::TrigBitSetMap") <<" Warning, trying to store at bit "<<bitNr<<" but max nr bits is "<<maxNrBits();
27  }
28 }
29 
30 void TrigCodes::TrigBitSetMap::setCode(const char* descript,TrigBitSet code)
31 {
32  bool found=false;
33  for(size_t i=0;i<codeDefs_.size() && !found;i++){
34  if(codeDefs_[i].first.compare(descript)==0) found=true;
35  }
36  if(!found) codeDefs_.push_back(std::pair<std::string,TrigBitSet>(descript,code));
37  //_codeDefs[descript] = code;
38 }
39 
40 
41 
43 {
44  //first copy the character string to a local array so we can manipulate it
45  char localDescript[512];
46  strcpy(localDescript,descript);
47 
48  TrigBitSet code;
49  char* codeKey = strtok(localDescript,":");
50  // std::map<std::string,int> ::const_iterator mapIt;
51  while(codeKey!=NULL){
52  bool found=false;
53 
54  for(size_t i=0;i<codeDefs_.size() && !found;i++){
55  if(codeDefs_[i].first.compare(codeKey)==0){
56  found=true;
57  code |= codeDefs_[i].second;
58 
59  }
60  }
61 
62  // if(!found) edm::LogError("TrigCodes::TrigBitSetMap") <<"TrigCodes::TrigBitSetMap::getCode : Error, Key "<<codeKey<<" not found";
63  codeKey = strtok(NULL,":"); //getting new substring
64 
65  }
66  return code;
67 }
68 
69 bool TrigCodes::TrigBitSetMap::keyComp(const std::pair<std::string,TrigBitSet>& lhs,const std::pair<std::string,TrigBitSet>& rhs)
70 {
71  return lhs.first < rhs.first;
72 }
73 
74 void TrigCodes::TrigBitSetMap::getCodeName(TrigBitSet code,std::string& id)const
75 {
76  id.clear();
77  for(size_t i=0;i<codeDefs_.size();i++){
78  if((code&codeDefs_[i].second)==codeDefs_[i].second){
79  if(!id.empty()) id+=":";//seperating entries by a ':'
80  id+=codeDefs_[i].first;
81  }
82 
83  }
84 
85 }
86 
88 {
89  std::ostringstream msg;
90  msg <<" trig bits defined: "<<std::endl;
91  for(size_t i=0;i<codeDefs_.size();i++) msg <<" key : "<<codeDefs_[i].first<<" bit "<<codeDefs_[i].second<<std::endl;
92  edm::LogInfo("TrigCodes") <<msg;
93 
94 }
static int maxNrBits()
int i
Definition: DBlmapReader.cc:9
static bool keyComp(const std::pair< std::string, TrigBitSet > &lhs, const std::pair< std::string, TrigBitSet > &rhs)
void getCodeName(TrigBitSet code, std::string &id) const
#define NULL
Definition: scimark2.h:8
U second(std::pair< T, U > const &p)
bool first
Definition: L1TdeRCT.cc:94
void setCode(const char *descript, TrigBitSet code)
static TrigBitSetMap trigBitSetMap_
static void setCodes(std::vector< std::string > &filterNames)
TrigBitSet getCode(const char *descript) const
std::bitset< maxNrBits_ > TrigBitSet