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 
6 
7 using namespace egHLT;
8 
9 TrigCodes* TrigCodes::makeCodes(std::vector<std::string>& filterNames)
10 {
11  TrigCodes *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.compare(descript)==0) found=true;
37  }
38  if(!found) codeDefs_.push_back(std::pair<std::string,TrigBitSet>(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!=NULL){
54  bool found=false;
55 
56  for(size_t i=0;i<codeDefs_.size() && !found;i++){
57  if(codeDefs_[i].first.compare(codeKey)==0){
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(NULL,":"); //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(size_t i=0;i<codeDefs_.size();i++){
80  if((code&codeDefs_[i].second)==codeDefs_[i].second){
81  if(!id.empty()) id+=":";//seperating entries by a ':'
82  id+=codeDefs_[i].first;
83  }
84 
85  }
86 
87 }
88 
90 {
91  std::ostringstream msg;
92  msg <<" trig bits defined: "<<std::endl;
93  for(size_t i=0;i<codeDefs_.size();i++) msg <<" key : "<<codeDefs_[i].first<<" bit "<<codeDefs_[i].second<<std::endl;
94  edm::LogInfo("TrigCodes") << msg.str();
95 
96 }
int i
Definition: DBlmapReader.cc:9
TrigBitSet getCode(const char *descript) const
#define NULL
Definition: scimark2.h:8
void setCode(const char *descript, TrigBitSet code)
static TrigCodes * makeCodes(std::vector< std::string > &filterNames)
U second(std::pair< T, U > const &p)
std::vector< std::pair< std::string, TrigBitSet > > codeDefs_
static const int maxNrBits_
void getCodeName(TrigBitSet code, std::string &id) const
static bool keyComp(const std::pair< std::string, TrigBitSet > &lhs, const std::pair< std::string, TrigBitSet > &rhs)
std::bitset< maxNrBits_ > TrigBitSet