CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DetIdSelector.cc
Go to the documentation of this file.
5 
6 
8  m_selections(),m_masks()
9 {}
10 
11 DetIdSelector::DetIdSelector(const std::string& selstring):
12  m_selections(),m_masks()
13 {
14  addSelection(selstring);
15 }
16 
17 DetIdSelector::DetIdSelector(const std::vector<std::string>& selstrings):
18  m_selections(),m_masks()
19 {
20  addSelection(selstrings);
21 }
22 
24  m_selections(),m_masks()
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 
69 
70  return isSelected(detid.rawId());
71 
72 }
73 
74 
75 
#define LogDebug(id)
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
selection
main part
Definition: corrVsCorr.py:98
bool isSelected(const DetId &detid) const
std::vector< unsigned int > m_masks
Definition: DetIdSelector.h:29
uint32_t rawId() const
get the raw id
Definition: DetId.h:45
std::vector< unsigned int > m_selections
Definition: DetIdSelector.h:28
Definition: DetId.h:20
void addSelection(const std::string &selstring)