CMS 3D CMS Logo

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==descript) found=true;
12  }
13  if(!found) _codeDefs.emplace_back(descript,code);
14 
15  //_codeDefs[descript] = code;
16 }
17 
18 
19 
20 int ComCodes::getCode(const char* descript)const
21 {
22  int code = 0x0000;
23  char const * const end = descript+strlen(descript);
24  char const * codeKey = descript;
25  char const * token = nullptr;
26  do {
27  token = std::find(codeKey, end, ':');
28 
29  bool found = false;
30  for(auto const& c: _codeDefs) {
31  if(0==c.first.compare(0,std::string::npos,codeKey, token-codeKey)){
32  code |= c.second;
33  found = true;
34  break;
35  }
36  }
37  if(!found) edm::LogWarning("EgHLTComCodes") <<"ComCodes::getCode : Error, Key "<<std::string(codeKey,token-codeKey)<<" not found (likely mistyped, practical upshot is the selection is not what you think it is)";//<<std::endl;
38  codeKey = token+1;
39  } while(token != end);
40  return code;
41 }
42 
43 bool ComCodes::keyComp(const std::pair<std::string,int>& lhs,const std::pair<std::string,int>& rhs)
44 {
45  return lhs.first < rhs.first;
46 }
47 
48 void ComCodes::getCodeName(int code,std::string& id)const
49 {
50  id.clear();
51  for(auto const & _codeDef : _codeDefs){
52  if((code&_codeDef.second)==_codeDef.second){
53  if(!id.empty()) id+=":";//seperating entries by a ':'
54  id+=_codeDef.first;
55  }
56 
57  }
58 
59 }
void setCode(const char *descript, int code)
Definition: EgHLTComCodes.cc:7
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
int getCode(const char *descript) const
std::vector< std::pair< std::string, int > > _codeDefs
Definition: EgHLTComCodes.h:15
#define end
Definition: vmac.h:39
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