CMS 3D CMS Logo

DDPartSelection.cc
Go to the documentation of this file.
6 #include "boost/spirit/include/classic.hpp"
7 
8 namespace boost {
9  namespace spirit {
10  namespace classic {}
11  } // namespace spirit
12 } // namespace boost
13 using namespace boost::spirit::classic;
14 
18  int copyNo_;
20  bool isChild_;
21  std::vector<DDPartSelRegExpLevel>* p_;
22 
23  std::vector<DDPartSelRegExpLevel>* path(std::vector<DDPartSelRegExpLevel>* p = nullptr) {
24  if (p) {
25  p_ = p;
26  namespace_ = "";
27  name_ = "";
28  copyNo_ = 0;
29  isCopyNoValid_ = false;
30  isChild_ = false;
31  }
32  return p_;
33  }
34 };
35 
36 void noNameSpace(char const* /*first*/, char const* /*last*/) {
38 }
39 
40 /* Functor for the parser; it does not consume memory -
41  pointers are only used to store references to memory
42  managed elsewhere
43 */
45  DDSelLevelFtor() : c_(DDI::Singleton<DDSelLevelCollector>::instance()) {}
46 
47  // parser calls this whenever a selection has been parsed ( //ns:nm[cn], /nm, //ns:nm, .... )
48  void operator()(char const* /*first*/, char const* /*last*/) const {
49  if (c_.path()) {
50  if (c_.isCopyNoValid_ && c_.isChild_) {
51  c_.path()->emplace_back(DDPartSelRegExpLevel(c_.namespace_, c_.name_, c_.copyNo_, ddchildposp));
52  //edm::LogInfo("DDPartSelection") << namespace_ << name_ << copyNo_ << ' ' << ddchildposp << std::endl;
53  } else if (c_.isCopyNoValid_ && !c_.isChild_) {
54  c_.path()->emplace_back(DDPartSelRegExpLevel(c_.namespace_, c_.name_, c_.copyNo_, ddanyposp));
55  // edm::LogInfo("DDPartSelection") << namespace_ << name_ << copyNo_ << ' ' << ddanyposp << std::endl;
56  } else if (!c_.isCopyNoValid_ && c_.isChild_) {
57  c_.path()->emplace_back(DDPartSelRegExpLevel(c_.namespace_, c_.name_, c_.copyNo_, ddchildlogp));
58  // edm::LogInfo("DDPartSelection") << namespace_ << name_ << copyNo_ << ' ' << ddchildlogp << std::endl;
59  } else if (!c_.isCopyNoValid_ && !c_.isChild_) {
60  c_.path()->emplace_back(DDPartSelRegExpLevel(c_.namespace_, c_.name_, c_.copyNo_, ddanylogp));
61  // edm::LogInfo("DDPartSelection") << namespace_ << name_ << copyNo_ << ' ' << ddanylogp << std::endl;
62  }
63  c_.namespace_ = "";
64  c_.name_ = "";
65  c_.isCopyNoValid_ = false;
66  }
67  }
68 
70 };
71 
72 struct DDIsChildFtor {
73  void operator()(char const* first, char const* last) const {
75  if ((last - first) > 1)
76  sl.isChild_ = false;
77  if ((last - first) == 1)
78  sl.isChild_ = true;
79  //edm::LogInfo("DDPartSelection") << "DDIsChildFtor isChild=" << (last-first) << std::endl;
80  }
81 };
82 
84  void operator()(char const* first, char const* last) const {
86  sl.namespace_.assign(first, last);
87  // edm::LogInfo("DDPartSelection") << "DDNameSpaceFtor singletonname=" << DDI::Singleton<DDSelLevelCollector>::instance().namespace_ << std::endl;
88  }
89 
91 };
92 
93 struct DDNameFtor {
94  void operator()(char const* first, char const* last) const {
96  sl.name_.assign(first, last);
97  // edm::LogInfo("DDPartSelection") << "DDNameFtor singletonname=" << Singleton<DDSelLevelCollector>::instance().name_ << std::endl;
98  }
99 };
100 
101 struct DDCopyNoFtor {
102  void operator()(int i) const {
104  sl.copyNo_ = i;
105  sl.isCopyNoValid_ = true;
106  // edm::LogInfo("DDPartSelection") << "DDCopyNoFtor ns=" << i;
107  }
108 };
109 
111 struct SpecParParser : public grammar<SpecParParser> {
112  template <typename ScannerT>
113  struct definition {
114  definition(SpecParParser const& /*self*/) {
115  Selection //= FirstStep[selLevelFtor()]
116  //>> *SelectionStep[selLevelFtor()]
117  = +SelectionStep[selLevelFtor()];
118 
119  FirstStep = Descendant >> Part;
120 
121  Part = PartNameCopyNumber | PartName;
122 
123  PartNameCopyNumber = PartName >> CopyNumber;
124 
125  SelectionStep = NavigationalElement[isChildFtor()] >> Part;
126 
127  NavigationalElement = Descendant | Child;
128 
129  CopyNumber = ch_p('[') >> int_p[copyNoFtor()] >> ch_p(']');
130 
131  PartName = NameSpaceName | SimpleName[nameFtor()][&noNameSpace];
132 
133  SimpleName = +(alnum_p | ch_p('_') | ch_p('.') | ch_p('*'));
134 
135  NameSpaceName = SimpleName[nameSpaceFtor()] >> ':' >> SimpleName[nameFtor()];
136 
137  Descendant = ch_p('/') >> ch_p('/');
138 
139  Child = ch_p('/');
140  }
141 
142  rule<ScannerT> Selection, FirstStep, Part, SelectionStep, NavigationalElement, CopyNumber, PartName,
143  PartNameCopyNumber, NameSpaceName, SimpleName, Descendant, Child;
144 
145  rule<ScannerT> const& start() const { return Selection; }
146 
148 
150  static DDNameFtor f_;
151  return f_;
152  }
153 
155  static DDNameSpaceFtor f_;
156  return f_;
157  }
158 
160  static DDIsChildFtor f_;
161  return f_;
162  }
163 
165  static DDCopyNoFtor f_;
166  return f_;
167  }
168  };
169 };
170 
172  : lp_(lp), copyno_(c), selectionType_(t) {}
173 
174 void DDTokenize2(const std::string& sel, std::vector<DDPartSelRegExpLevel>& path) {
175  static SpecParParser parser;
177  bool result = parse(sel.c_str(), parser).full;
178  if (!result) {
179  edm::LogError("DDPartSelection") << "DDTokenize2() error in parsing of " << sel << std::endl;
180  }
181 }
182 
183 std::ostream& operator<<(std::ostream& o, const DDPartSelection& p) {
184  DDPartSelection::const_iterator it(p.begin()), ed(p.end());
185  for (; it != ed; ++it) {
186  const DDPartSelectionLevel lv = *it;
187  switch (lv.selectionType_) {
188  case ddanylogp:
189  o << "//" << lv.lp_.ddname();
190  break;
191  case ddanyposp:
192  o << "//" << lv.lp_.ddname() << '[' << lv.copyno_ << ']';
193  break;
194  case ddchildlogp:
195  o << "/" << lv.lp_.ddname();
196  break;
197  case ddchildposp:
198  o << "/" << lv.lp_.ddname() << '[' << lv.copyno_ << ']';
199  break;
200  default:
201  o << "{Syntax ERROR}";
202  }
203  }
204  return o;
205 }
206 
207 std::ostream& operator<<(std::ostream& os, const std::vector<DDPartSelection>& v) {
208  std::vector<DDPartSelection>::const_iterator it(v.begin()), ed(v.end());
209  for (; it != (ed - 1); ++it) {
210  os << *it << std::endl;
211  }
212  if (it != ed) {
213  ++it;
214  os << *it;
215  }
216  return os;
217 }
218 
219 // explicit template instantiation.
220 
221 template class DDI::Singleton<DDSelLevelFtor>;
222 //template class DDI::Singleton<DDI::Store<DDName, DDSelLevelCollector> >;
224 #include <DetectorDescription/Core/interface/Singleton.icc>
DDSelLevelCollector::p_
std::vector< DDPartSelRegExpLevel > * p_
Definition: DDPartSelection.cc:21
DDNameFtor::operator()
void operator()(char const *first, char const *last) const
Definition: DDPartSelection.cc:94
DDI
Definition: DDCompactView.h:25
mps_fire.i
i
Definition: mps_fire.py:428
MessageLogger.h
DDSelLevelFtor::operator()
void operator()(char const *, char const *) const
Definition: DDPartSelection.cc:48
noNameSpace
void noNameSpace(char const *, char const *)
Definition: DDPartSelection.cc:36
ddanyposp
Definition: DDPartSelection.h:16
boost::spirit::classic
Definition: DDPartSelection.cc:10
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
DDI::Singleton
Definition: Singleton.h:6
electronAnalyzer_cfi.Selection
Selection
Definition: electronAnalyzer_cfi.py:21
DDSelLevelFtor
Definition: DDPartSelection.cc:44
DDSelLevelCollector::path
std::vector< DDPartSelRegExpLevel > * path(std::vector< DDPartSelRegExpLevel > *p=nullptr)
Definition: DDPartSelection.cc:23
writedatasetfile.parser
parser
Definition: writedatasetfile.py:7
DDPartSelection
Definition: DDPartSelection.h:37
full
Definition: GenABIO.cc:168
findQualityFiles.v
v
Definition: findQualityFiles.py:179
DDSelLevelFtor::c_
DDSelLevelCollector & c_
Definition: DDPartSelection.cc:69
boost
Definition: CLHEP.h:16
dqmdumpme.first
first
Definition: dqmdumpme.py:55
DDCopyNoFtor::operator()
void operator()(int i) const
Definition: DDPartSelection.cc:102
SpecParParser
Definition: DDPartSelection.cc:111
DDPartSelection.h
EcalTangentSkim_cfg.o
o
Definition: EcalTangentSkim_cfg.py:36
Selection
Definition: Selection.h:6
dqmdumpme.last
last
Definition: dqmdumpme.py:56
SpecParParser::definition::nameFtor
DDNameFtor & nameFtor()
Definition: DDPartSelection.cc:149
ddchildposp
Definition: DDPartSelection.h:18
DDCopyNoFtor
Definition: DDPartSelection.cc:101
DDPartSelectionLevel::lp_
DDLogicalPart lp_
Definition: DDPartSelection.h:32
operator<<
std::ostream & operator<<(std::ostream &o, const DDPartSelection &p)
Definition: DDPartSelection.cc:183
SpecParParser::definition::nameSpaceFtor
DDNameSpaceFtor & nameSpaceFtor()
Definition: DDPartSelection.cc:154
DDPartSelRegExpLevel
Definition: DDPartSelection.h:21
DDPartSelectionLevel::selectionType_
ddselection_type selectionType_
Definition: DDPartSelection.h:34
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
DDPartSelectionLevel::copyno_
int copyno_
Definition: DDPartSelection.h:33
ddselection_type
ddselection_type
Definition: DDPartSelection.h:11
SpecParParser::definition::selLevelFtor
DDSelLevelFtor & selLevelFtor()
Definition: DDPartSelection.cc:147
DDPartSelectionLevel
Definition: DDPartSelection.h:30
dumpparser.parse
def parse(path, config)
Definition: dumpparser.py:13
DDBase::ddname
const N & ddname() const
Definition: DDBase.h:61
DDI::Singleton::instance
static value_type & instance()
DDNameSpaceFtor::operator()
void operator()(char const *first, char const *last) const
Definition: DDPartSelection.cc:84
DDLogicalPart
A DDLogicalPart aggregates information concerning material, solid and sensitveness ....
Definition: DDLogicalPart.h:93
DDSelLevelCollector::namespace_
std::string namespace_
Definition: DDPartSelection.cc:16
SpecParParser::definition::SimpleName
rule< ScannerT > SimpleName
Definition: DDPartSelection.cc:142
SpecParParser::definition
Definition: DDPartSelection.cc:113
DDSelLevelCollector::name_
std::string name_
Definition: DDPartSelection.cc:17
ddanylogp
Definition: DDPartSelection.h:15
SpecParParser::definition::start
rule< ScannerT > const & start() const
Definition: DDPartSelection.cc:145
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
DDLogicalPart.h
SpecParParser::definition::copyNoFtor
DDCopyNoFtor & copyNoFtor()
Definition: DDPartSelection.cc:164
DDSelLevelCollector::isChild_
bool isChild_
Definition: DDPartSelection.cc:20
instance
static PFTauRenderPlugin instance
Definition: PFTauRenderPlugin.cc:70
DDSelLevelCollector
Definition: DDPartSelection.cc:15
DDTokenize2
void DDTokenize2(const std::string &sel, std::vector< DDPartSelRegExpLevel > &path)
Definition: DDPartSelection.cc:174
Singleton.h
DDNameSpaceFtor::selLevelFtor_
DDSelLevelFtor * selLevelFtor_
Definition: DDPartSelection.cc:90
DDNameSpaceFtor
Definition: DDPartSelection.cc:83
DDNameFtor
Definition: DDPartSelection.cc:93
DDSelLevelCollector::copyNo_
int copyNo_
Definition: DDPartSelection.cc:18
DDName.h
SpecParParser::definition::isChildFtor
DDIsChildFtor & isChildFtor()
Definition: DDPartSelection.cc:159
SelectionStep
Templated helper class to allow a selection on a certain object collection.
Definition: TopDQMHelpers.h:237
DDPartSelectionLevel::DDPartSelectionLevel
DDPartSelectionLevel(const DDLogicalPart &, int, ddselection_type)
Definition: DDPartSelection.cc:171
ddchildlogp
Definition: DDPartSelection.h:17
DDIsChildFtor
Definition: DDPartSelection.cc:72
DDSelLevelFtor::DDSelLevelFtor
DDSelLevelFtor()
Definition: DDPartSelection.cc:45
mps_fire.result
result
Definition: mps_fire.py:311
castor_dqm_sourceclient_file_cfg.path
path
Definition: castor_dqm_sourceclient_file_cfg.py:37
DDIsChildFtor::operator()
void operator()(char const *first, char const *last) const
Definition: DDPartSelection.cc:73
EgammaValidation_Wenu_cff.sel
sel
Definition: EgammaValidation_Wenu_cff.py:33
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
SpecParParser::definition::definition
definition(SpecParParser const &)
Definition: DDPartSelection.cc:114
DDSelLevelCollector::isCopyNoValid_
bool isCopyNoValid_
Definition: DDPartSelection.cc:19