CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/DQMOffline/Trigger/src/EgHLTComCodes.cc

Go to the documentation of this file.
00001 #include "DQMOffline/Trigger/interface/EgHLTComCodes.h"
00002 
00003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00004 
00005 using namespace egHLT;
00006 
00007 void ComCodes::setCode(const char* descript,int code)
00008 {
00009   bool found=false;
00010   for(size_t i=0;i<_codeDefs.size() && !found;i++){
00011     if(_codeDefs[i].first.compare(descript)==0) found=true;
00012   }
00013   if(!found) _codeDefs.push_back(std::pair<std::string,int>(descript,code));
00014  
00015   //_codeDefs[descript] = code;
00016 }
00017 
00018 
00019 
00020 int ComCodes::getCode(const char* descript)const
00021 { 
00022   //first copy the character string to a local array so we can manipulate it
00023   char localDescript[256];
00024   strcpy(localDescript,descript);
00025   
00026   int code = 0x0000; 
00027   char* codeKey = strtok(localDescript,":");
00028   //  std::map<std::string,int> ::const_iterator mapIt;
00029   while(codeKey!=NULL){
00030     bool found=false;
00031 
00032     for(size_t i=0;i<_codeDefs.size() && !found;i++){
00033       if(_codeDefs[i].first.compare(codeKey)==0){
00034         found=true;
00035         code |= _codeDefs[i].second;
00036 
00037        }
00038     }
00039    
00040     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;
00041     codeKey = strtok(NULL,":"); //getting new substring
00042     
00043   }
00044   return code;
00045 }
00046 
00047 bool ComCodes::keyComp(const std::pair<std::string,int>& lhs,const std::pair<std::string,int>& rhs)
00048 {
00049   return lhs.first < rhs.first;
00050 }
00051 
00052 void ComCodes::getCodeName(int code,std::string& id)const
00053 {
00054   id.clear();
00055   for(size_t i=0;i<_codeDefs.size();i++){ 
00056     if((code&_codeDefs[i].second)==_codeDefs[i].second){
00057       if(!id.empty()) id+=":";//seperating entries by a ':'
00058       id+=_codeDefs[i].first;
00059     }
00060     
00061   }
00062  
00063 }