CMS 3D CMS Logo

ComCodes.cc

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

Generated on Tue Jun 9 17:34:09 2009 for CMSSW by  doxygen 1.5.4