CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EgHLTComCodes.cc
Go to the documentation of this file.
2 
4 
5 using namespace egHLT;
6 
7 void ComCodes::setCode(const char* descript,int code)
8 {
9  bool found=false;
10  for(size_t i=0;i<_codeDefs.size() && !found;i++){
11  if(_codeDefs[i].first.compare(descript)==0) found=true;
12  }
13  if(!found) _codeDefs.push_back(std::pair<std::string,int>(descript,code));
14 
15  //_codeDefs[descript] = code;
16 }
17 
18 
19 
20 int ComCodes::getCode(const char* descript)const
21 {
22  //first copy the character string to a local array so we can manipulate it
23  char localDescript[256];
24  strcpy(localDescript,descript);
25 
26  int code = 0x0000;
27  char* codeKey = strtok(localDescript,":");
28  // std::map<std::string,int> ::const_iterator mapIt;
29  while(codeKey!=NULL){
30  bool found=false;
31 
32  for(size_t i=0;i<_codeDefs.size() && !found;i++){
33  if(_codeDefs[i].first.compare(codeKey)==0){
34  found=true;
35  code |= _codeDefs[i].second;
36 
37  }
38  }
39 
40  if(!found) edm::LogWarning("EgHLTComCodes") <<"ComCodes::getCode : Error, Key "<<codeKey<<" not found (likely mistyped, practical upshot is the selection is not what you think it is)";//<<std::endl;
41  codeKey = strtok(NULL,":"); //getting new substring
42 
43  }
44  return code;
45 }
46 
47 bool ComCodes::keyComp(const std::pair<std::string,int>& lhs,const std::pair<std::string,int>& rhs)
48 {
49  return lhs.first < rhs.first;
50 }
51 
52 void ComCodes::getCodeName(int code,std::string& id)const
53 {
54  id.clear();
55  for(size_t i=0;i<_codeDefs.size();i++){
56  if((code&_codeDefs[i].second)==_codeDefs[i].second){
57  if(!id.empty()) id+=":";//seperating entries by a ':'
58  id+=_codeDefs[i].first;
59  }
60 
61  }
62 
63 }
int i
Definition: DBlmapReader.cc:9
void setCode(const char *descript, int code)
Definition: EgHLTComCodes.cc:7
#define NULL
Definition: scimark2.h:8
int getCode(const char *descript) const
U second(std::pair< T, U > const &p)
std::vector< std::pair< std::string, int > > _codeDefs
Definition: EgHLTComCodes.h:15
bool first
Definition: L1TdeRCT.cc:79
static bool keyComp(const std::pair< std::string, int > &lhs, const std::pair< std::string, int > &rhs)
void getCodeName(int code, std::string &id) const