CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch1/src/DQMOffline/Trigger/src/EgHLTTrigCodes.cc

Go to the documentation of this file.
00001 #include "DQMOffline/Trigger/interface/EgHLTTrigCodes.h"
00002 
00003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00004 
00005 using namespace egHLT;
00006 
00007 TrigCodes::TrigBitSetMap TrigCodes::trigBitSetMap_;
00008 
00009 void TrigCodes::setCodes(std::vector<std::string>& filterNames)
00010 {
00011   if(trigBitSetMap_.size()!=0){
00012     edm::LogWarning("TrigCodes") <<" Warning trigBitSetMap already filled ";
00013   }else{
00014     for(size_t i=0;i<filterNames.size();i++) trigBitSetMap_.setCode(filterNames[i].c_str(),i);
00015     trigBitSetMap_.sort();
00016   }
00017 }
00018 
00019 void TrigCodes::TrigBitSetMap::setCode(const char* descript,int bitNr)
00020 {
00021   if(bitNr<maxNrBits()){
00022     TrigBitSet code;
00023     code.set(bitNr);
00024     setCode(descript,code);
00025   }else{
00026     edm::LogWarning("TrigCodes::TrigBitSetMap") <<" Warning, trying to store at bit "<<bitNr<<" but max nr bits is "<<maxNrBits();
00027   }
00028 }
00029 
00030 void TrigCodes::TrigBitSetMap::setCode(const char* descript,TrigBitSet code)
00031 {
00032   bool found=false;
00033   for(size_t i=0;i<codeDefs_.size() && !found;i++){
00034     if(codeDefs_[i].first.compare(descript)==0) found=true;
00035   }
00036   if(!found) codeDefs_.push_back(std::pair<std::string,TrigBitSet>(descript,code));
00037   //_codeDefs[descript] = code;
00038 }
00039 
00040 
00041 
00042 TrigCodes::TrigBitSet TrigCodes::TrigBitSetMap::getCode(const char* descript)const
00043 { 
00044   //first copy the character string to a local array so we can manipulate it
00045   char localDescript[512];
00046   strcpy(localDescript,descript);
00047   
00048   TrigBitSet code; 
00049   char* codeKey = strtok(localDescript,":");
00050   //  std::map<std::string,int> ::const_iterator mapIt;
00051   while(codeKey!=NULL){
00052     bool found=false;
00053 
00054     for(size_t i=0;i<codeDefs_.size() && !found;i++){
00055       if(codeDefs_[i].first.compare(codeKey)==0){
00056         found=true;
00057         code |= codeDefs_[i].second;
00058 
00059        }
00060     }
00061    
00062     //  if(!found)  edm::LogError("TrigCodes::TrigBitSetMap") <<"TrigCodes::TrigBitSetMap::getCode : Error, Key "<<codeKey<<" not found";
00063     codeKey = strtok(NULL,":"); //getting new substring
00064     
00065   }
00066   return code;
00067 }
00068 
00069 bool TrigCodes::TrigBitSetMap::keyComp(const std::pair<std::string,TrigBitSet>& lhs,const std::pair<std::string,TrigBitSet>& rhs)
00070 {
00071   return lhs.first < rhs.first;
00072 }
00073 
00074 void TrigCodes::TrigBitSetMap::getCodeName(TrigBitSet code,std::string& id)const
00075 {
00076   id.clear();
00077   for(size_t i=0;i<codeDefs_.size();i++){ 
00078     if((code&codeDefs_[i].second)==codeDefs_[i].second){
00079       if(!id.empty()) id+=":";//seperating entries by a ':'
00080       id+=codeDefs_[i].first;
00081     }
00082     
00083   }
00084  
00085 }
00086 
00087 void TrigCodes::TrigBitSetMap::printCodes()
00088 {
00089   std::ostringstream msg;
00090   msg <<" trig bits defined: "<<std::endl;
00091   for(size_t i=0;i<codeDefs_.size();i++) msg <<" key : "<<codeDefs_[i].first<<" bit "<<codeDefs_[i].second<<std::endl;
00092   edm::LogInfo("TrigCodes") <<msg;
00093  
00094 }