Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:01:17

0001 #include "CommonTools/UtilAlgos/interface/DetIdSelector.h"
0002 #include "DataFormats/DetId/interface/DetId.h"
0003 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0005 
0006 DetIdSelector::DetIdSelector() : m_selections(), m_masks() {}
0007 
0008 DetIdSelector::DetIdSelector(const std::string& selstring) : m_selections(), m_masks() { addSelection(selstring); }
0009 
0010 DetIdSelector::DetIdSelector(const std::vector<std::string>& selstrings) : m_selections(), m_masks() {
0011   addSelection(selstrings);
0012 }
0013 
0014 DetIdSelector::DetIdSelector(const edm::ParameterSet& selconfig) : m_selections(), m_masks() {
0015   const std::vector<std::string> selstrings = selconfig.getUntrackedParameter<std::vector<std::string> >("selection");
0016   addSelection(selstrings);
0017 }
0018 
0019 void DetIdSelector::addSelection(const std::string& selstring) {
0020   unsigned int selection;
0021   unsigned int mask;
0022 
0023   if (selstring.substr(0, 2) == "0x") {
0024     sscanf(selstring.c_str(), "%x-%x", &mask, &selection);
0025   } else {
0026     sscanf(selstring.c_str(), "%u-%u", &mask, &selection);
0027   }
0028 
0029   m_selections.push_back(selection);
0030   m_masks.push_back(mask);
0031 
0032   LogDebug("Selection added") << "Selection " << selection << " with mask " << mask << " added";
0033 }
0034 
0035 void DetIdSelector::addSelection(const std::vector<std::string>& selstrings) {
0036   for (std::vector<std::string>::const_iterator selstring = selstrings.begin(); selstring != selstrings.end();
0037        ++selstring) {
0038     addSelection(*selstring);
0039   }
0040 }
0041 
0042 bool DetIdSelector::isSelected(const unsigned int& rawid) const {
0043   for (unsigned int i = 0; i < m_selections.size(); ++i) {
0044     if ((m_masks[i] & rawid) == m_selections[i])
0045       return true;
0046   }
0047 
0048   return false;
0049 }
0050 
0051 bool DetIdSelector::isSelected(const DetId& detid) const { return isSelected(detid.rawId()); }
0052 
0053 bool DetIdSelector::operator()(const DetId& detid) const { return isSelected(detid.rawId()); }
0054 
0055 bool DetIdSelector::operator()(const unsigned int& rawid) const { return isSelected(rawid); }