CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
DetIdSelector.cc
Go to the documentation of this file.
5 
6 DetIdSelector::DetIdSelector() : m_selections(), m_masks() {}
7 
8 DetIdSelector::DetIdSelector(const std::string& selstring) : m_selections(), m_masks() { addSelection(selstring); }
9 
10 DetIdSelector::DetIdSelector(const std::vector<std::string>& selstrings) : m_selections(), m_masks() {
11  addSelection(selstrings);
12 }
13 
14 DetIdSelector::DetIdSelector(const edm::ParameterSet& selconfig) : m_selections(), m_masks() {
15  const std::vector<std::string> selstrings = selconfig.getUntrackedParameter<std::vector<std::string> >("selection");
16  addSelection(selstrings);
17 }
18 
19 void DetIdSelector::addSelection(const std::string& selstring) {
20  unsigned int selection;
21  unsigned int mask;
22 
23  if (selstring.substr(0, 2) == "0x") {
24  sscanf(selstring.c_str(), "%x-%x", &mask, &selection);
25  } else {
26  sscanf(selstring.c_str(), "%u-%u", &mask, &selection);
27  }
28 
29  m_selections.push_back(selection);
30  m_masks.push_back(mask);
31 
32  LogDebug("Selection added") << "Selection " << selection << " with mask " << mask << " added";
33 }
34 
35 void DetIdSelector::addSelection(const std::vector<std::string>& selstrings) {
36  for (std::vector<std::string>::const_iterator selstring = selstrings.begin(); selstring != selstrings.end();
37  ++selstring) {
38  addSelection(*selstring);
39  }
40 }
41 
42 bool DetIdSelector::isSelected(const unsigned int& rawid) const {
43  for (unsigned int i = 0; i < m_selections.size(); ++i) {
44  if ((m_masks[i] & rawid) == m_selections[i])
45  return true;
46  }
47 
48  return false;
49 }
50 
51 bool DetIdSelector::isSelected(const DetId& detid) const { return isSelected(detid.rawId()); }
52 
53 bool DetIdSelector::operator()(const DetId& detid) const { return isSelected(detid.rawId()); }
54 
55 bool DetIdSelector::operator()(const unsigned int& rawid) const { return isSelected(rawid); }
bool isSelected(const DetId &detid) const
selection
main part
Definition: corrVsCorr.py:100
std::vector< unsigned int > m_masks
Definition: DetIdSelector.h:30
T getUntrackedParameter(std::string const &, T const &) const
std::vector< unsigned int > m_selections
Definition: DetIdSelector.h:29
Definition: DetId.h:17
bool operator()(const DetId &detid) const
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
void addSelection(const std::string &selstring)
#define LogDebug(id)