CMS 3D CMS Logo

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); }
mps_fire.i
i
Definition: mps_fire.py:428
MessageLogger.h
DetIdSelector::operator()
bool operator()(const DetId &detid) const
Definition: DetIdSelector.cc:53
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
DetIdSelector.h
DetIdSelector::addSelection
void addSelection(const std::string &selstring)
Definition: DetIdSelector.cc:19
DetId
Definition: DetId.h:17
DetIdSelector::DetIdSelector
DetIdSelector()
Definition: DetIdSelector.cc:6
corrVsCorr.selection
selection
main part
Definition: corrVsCorr.py:100
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
edm::ParameterSet
Definition: ParameterSet.h:47
DetIdSelector::m_selections
std::vector< unsigned int > m_selections
Definition: DetIdSelector.h:29
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
DetId.h
DetIdSelector::m_masks
std::vector< unsigned int > m_masks
Definition: DetIdSelector.h:30
ParameterSet.h
DetIdSelector::isSelected
bool isSelected(const DetId &detid) const
Definition: DetIdSelector.cc:51