CMS 3D CMS Logo

DetIdSelector.cc
Go to the documentation of this file.
5 
6 
8  m_selections(),m_masks()
9 {}
10 
13 {
14  addSelection(selstring);
15 }
16 
17 DetIdSelector::DetIdSelector(const std::vector<std::string>& selstrings):
19 {
20  addSelection(selstrings);
21 }
22 
25 {
26 
27  const std::vector<std::string> selstrings = selconfig.getUntrackedParameter<std::vector<std::string> >("selection");
28  addSelection(selstrings);
29 
30 }
31 
32 void DetIdSelector::addSelection(const std::string& selstring) {
33 
34  unsigned int selection;
35  unsigned int mask;
36 
37  if(selstring.substr(0,2) == "0x") {
38  sscanf(selstring.c_str(),"%x-%x",&mask,&selection);
39  }
40  else {
41  sscanf(selstring.c_str(),"%u-%u",&mask,&selection);
42  }
43 
44  m_selections.push_back(selection);
45  m_masks.push_back(mask);
46 
47  LogDebug("Selection added") << "Selection " << selection << " with mask " << mask << " added";
48 
49 }
50 
51 void DetIdSelector::addSelection(const std::vector<std::string>& selstrings) {
52 
53  for(std::vector<std::string>::const_iterator selstring=selstrings.begin();selstring!=selstrings.end();++selstring) {
54  addSelection(*selstring);
55  }
56 
57 }
58 
59 bool DetIdSelector::isSelected(const unsigned int& rawid) const {
60 
61  for(unsigned int i=0; i<m_selections.size() ; ++i) {
62  if((m_masks[i] & rawid) == m_selections[i]) return true;
63  }
64 
65  return false;
66 }
67 
68 bool DetIdSelector::isSelected(const DetId& detid) const {
69 
70  return isSelected(detid.rawId());
71 
72 }
73 
74 bool DetIdSelector::operator()(const DetId& detid) const {
75 
76  return isSelected(detid.rawId());
77 
78 }
79 
80 bool DetIdSelector::operator()(const unsigned int& rawid) const {
81 
82  return isSelected(rawid);
83 
84 }
85 
86 
87 
#define LogDebug(id)
bool operator()(const DetId &detid) const
T getUntrackedParameter(std::string const &, T const &) const
selection
main part
Definition: corrVsCorr.py:98
bool isSelected(const DetId &detid) const
std::vector< unsigned int > m_masks
Definition: DetIdSelector.h:31
uint32_t rawId() const
get the raw id
Definition: DetId.h:44
std::vector< unsigned int > m_selections
Definition: DetIdSelector.h:30
Definition: DetId.h:18
void addSelection(const std::string &selstring)