Go to the documentation of this file.00001 #include "DPGAnalysis/SiStripTools/interface/DetIdSelector.h"
00002 #include "DataFormats/DetId/interface/DetId.h"
00003 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00005
00006
00007 DetIdSelector::DetIdSelector():
00008 m_selections(),m_masks()
00009 {}
00010
00011 DetIdSelector::DetIdSelector(const std::string& selstring):
00012 m_selections(),m_masks()
00013 {
00014 addSelection(selstring);
00015 }
00016
00017 DetIdSelector::DetIdSelector(const std::vector<std::string>& selstrings):
00018 m_selections(),m_masks()
00019 {
00020 addSelection(selstrings);
00021 }
00022
00023 DetIdSelector::DetIdSelector(const edm::ParameterSet& selconfig):
00024 m_selections(),m_masks()
00025 {
00026
00027 const std::vector<std::string> selstrings = selconfig.getUntrackedParameter<std::vector<std::string> >("selection");
00028 addSelection(selstrings);
00029
00030 }
00031
00032 void DetIdSelector::addSelection(const std::string& selstring) {
00033
00034 unsigned int selection;
00035 unsigned int mask;
00036
00037 if(selstring.substr(0,2) == "0x") {
00038 sscanf(selstring.c_str(),"%x-%x",&mask,&selection);
00039 }
00040 else {
00041 sscanf(selstring.c_str(),"%u-%u",&mask,&selection);
00042 }
00043
00044 m_selections.push_back(selection);
00045 m_masks.push_back(mask);
00046
00047 LogDebug("Selection added") << "Selection " << selection << " with mask " << mask << " added";
00048
00049 }
00050
00051 void DetIdSelector::addSelection(const std::vector<std::string>& selstrings) {
00052
00053 for(std::vector<std::string>::const_iterator selstring=selstrings.begin();selstring!=selstrings.end();++selstring) {
00054 addSelection(*selstring);
00055 }
00056
00057 }
00058
00059 bool DetIdSelector::isSelected(const unsigned int& rawid) const {
00060
00061 for(unsigned int i=0; i<m_selections.size() ; ++i) {
00062 if((m_masks[i] & rawid) == m_selections[i]) return true;
00063 }
00064
00065 return false;
00066 }
00067
00068 bool DetIdSelector::isSelected(const DetId& detid) const {
00069
00070 return isSelected(detid.rawId());
00071
00072 }
00073
00074
00075