CMS 3D CMS Logo

DDPartSelection.cc
Go to the documentation of this file.
6 #include "boost/spirit/include/classic.hpp"
7 
8 namespace boost { namespace spirit { namespace classic { } } } using namespace boost::spirit::classic;
9 
11 {
14  int copyNo_;
16  bool isChild_;
17  std::vector<DDPartSelRegExpLevel>* p_;
18 
19  std::vector<DDPartSelRegExpLevel>* path(std::vector<DDPartSelRegExpLevel>* p=nullptr) {
20  if (p) {
21  p_=p;
22  namespace_="";
23  name_="";
24  copyNo_=0;
25  isCopyNoValid_=false;
26  isChild_=false;
27  }
28  return p_;
29  }
30 };
31 
32 void noNameSpace(char const * /*first*/, char const* /*last*/) {
34 }
35 
36 /* Functor for the parser; it does not consume memory -
37  pointers are only used to store references to memory
38  managed elsewhere
39 */
41 {
43  : c_(DDI::Singleton<DDSelLevelCollector>::instance())
44  { }
45 
46  // parser calls this whenever a selection has been parsed ( //ns:nm[cn], /nm, //ns:nm, .... )
47  void operator() (char const* /*first*/, char const* /*last*/) const {
48  if(c_.path()){
49  if (c_.isCopyNoValid_ && c_.isChild_) {
50  c_.path()->emplace_back(DDPartSelRegExpLevel(c_.namespace_,c_.name_,c_.copyNo_,ddchildposp));
51  //edm::LogInfo("DDPartSelection") << namespace_ << name_ << copyNo_ << ' ' << ddchildposp << std::endl;
52  } else
53  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
57  if (!c_.isCopyNoValid_ && c_.isChild_) {
58  c_.path()->emplace_back(DDPartSelRegExpLevel(c_.namespace_,c_.name_,c_.copyNo_,ddchildlogp));
59  // edm::LogInfo("DDPartSelection") << namespace_ << name_ << copyNo_ << ' ' << ddchildlogp << std::endl;
60  } else
61  if (!c_.isCopyNoValid_ && !c_.isChild_) {
62  c_.path()->emplace_back(DDPartSelRegExpLevel(c_.namespace_,c_.name_,c_.copyNo_,ddanylogp));
63  // edm::LogInfo("DDPartSelection") << namespace_ << name_ << copyNo_ << ' ' << ddanylogp << std::endl;
64  }
65  c_.namespace_="";
66  c_.name_="";
67  c_.isCopyNoValid_=false;
68  }
69  }
70 
72 };
73 
75 {
76 
77  void operator()(char const* first, char const* last) const {
79  if ( (last-first) > 1)
80  sl.isChild_=false;
81  if ( (last-first) ==1 )
82  sl.isChild_=true;
83  //edm::LogInfo("DDPartSelection") << "DDIsChildFtor isChild=" << (last-first) << std::endl;
84  }
85 
86 };
87 
88 
90 {
91 
92  void operator()(char const* first, char const* last) const {
94  sl.namespace_.assign(first,last);
95  // edm::LogInfo("DDPartSelection") << "DDNameSpaceFtor singletonname=" << DDI::Singleton<DDSelLevelCollector>::instance().namespace_ << std::endl;
96  }
97 
99 };
100 
101 
103 {
104 
105  void operator()(char const* first, char const* last) const {
107  sl.name_.assign(first,last);
108  // edm::LogInfo("DDPartSelection") << "DDNameFtor singletonname=" << Singleton<DDSelLevelCollector>::instance().name_ << std::endl;
109  }
110 
111 };
112 
113 
115 {
116 
117  void operator()(int i) const {
119  sl.copyNo_ = i;
120  sl.isCopyNoValid_ = true;
121  // edm::LogInfo("DDPartSelection") << "DDCopyNoFtor ns=" << i;
122  }
123 
124 };
125 
127 struct SpecParParser : public grammar<SpecParParser>
128 {
129  template <typename ScannerT>
130  struct definition
131  {
132  definition(SpecParParser const& /*self*/) {
133 
134  Selection //= FirstStep[selLevelFtor()]
135  //>> *SelectionStep[selLevelFtor()]
136  = +SelectionStep[selLevelFtor()]
137  ;
138 
139  FirstStep = Descendant
140  >> Part
141  ;
142 
143  Part = PartNameCopyNumber
144  | PartName
145  ;
146 
147  PartNameCopyNumber = PartName
148  >> CopyNumber
149  ;
150 
151  SelectionStep = NavigationalElement[isChildFtor()]
152  >> Part
153  ;
154 
155  NavigationalElement = Descendant
156  | Child
157  ;
158 
159  CopyNumber = ch_p('[')
160  >> int_p[copyNoFtor()]
161  >> ch_p(']')
162  ;
163 
164  PartName = NameSpaceName
165  | SimpleName[nameFtor()][&noNameSpace]
166  ;
167 
168  SimpleName = +( alnum_p | ch_p('_') | ch_p('.') | ch_p('*') )
169  ;
170 
171  NameSpaceName = SimpleName[nameSpaceFtor()]
172  >> ':'
173  >> SimpleName[nameFtor()]
174  ;
175 
176  Descendant = ch_p('/')
177  >> ch_p('/')
178  ;
179 
180  Child = ch_p('/')
181  ;
182 
183  }
184 
185  rule<ScannerT> Selection, FirstStep, Part, SelectionStep, NavigationalElement,
186  CopyNumber, PartName, PartNameCopyNumber, NameSpaceName, SimpleName,
187  Descendant, Child;
188 
189  rule<ScannerT> const& start() const { return Selection; }
190 
193  }
194 
196  static DDNameFtor f_;
197  return f_;
198  }
199 
201  static DDNameSpaceFtor f_;
202  return f_;
203  }
204 
206  static DDIsChildFtor f_;
207  return f_;
208  }
209 
211  static DDCopyNoFtor f_;
212  return f_;
213  }
214  };
215 
216 };
217 
219  : lp_(lp), copyno_(c), selectionType_(t)
220 {}
221 
222 void DDTokenize2(const std::string & sel, std::vector<DDPartSelRegExpLevel> & path)
223 {
224  static SpecParParser parser;
226  bool result = parse(sel.c_str(), parser).full;
227  if (!result) {
228  edm::LogError("DDPartSelection") << "DDTokenize2() error in parsing of " << sel << std::endl;
229  }
230 }
231 
232 std::ostream & operator<<(std::ostream & o, const DDPartSelection & p)
233 {
234  DDPartSelection::const_iterator it(p.begin()), ed(p.end());
235  for (; it != ed; ++it) {
236  const DDPartSelectionLevel lv =*it;
237  switch (lv.selectionType_) {
238  case ddanylogp:
239  o << "//" << lv.lp_.ddname();
240  break;
241  case ddanyposp:
242  o << "//" << lv.lp_.ddname() << '[' << lv.copyno_ << ']';
243  break;
244  case ddchildlogp:
245  o << "/" << lv.lp_.ddname();
246  break;
247  case ddchildposp:
248  o << "/" << lv.lp_.ddname() << '[' << lv.copyno_ << ']';
249  break;
250  default:
251  o << "{Syntax ERROR}";
252  }
253  }
254  return o;
255 }
256 
257 std::ostream & operator<<(std::ostream & os, const std::vector<DDPartSelection> & v)
258 {
259  std::vector<DDPartSelection>::const_iterator it(v.begin()), ed(v.end());
260  for (; it != (ed-1); ++it) {
261  os << *it << std::endl;
262  }
263  if ( it != ed ) {
264  ++it;
265  os << *it;
266  }
267  return os;
268 }
269 
270 // explicit template instantiation.
271 
272 template class DDI::Singleton<DDSelLevelFtor>;
273 //template class DDI::Singleton<DDI::Store<DDName, DDSelLevelCollector> >;
275 #include <DetectorDescription/Core/interface/Singleton.icc>
DDSelLevelFtor * selLevelFtor_
DDPartSelectionLevel(const DDLogicalPart &, int, ddselection_type)
std::ostream & operator<<(std::ostream &o, const DDPartSelection &p)
Definition: CLHEP.h:16
void operator()(char const *first, char const *last) const
static PFTauRenderPlugin instance
void operator()(int i) const
DDIsChildFtor & isChildFtor()
static value_type & instance()
void noNameSpace(char const *, char const *)
std::vector< DDPartSelRegExpLevel > * path(std::vector< DDPartSelRegExpLevel > *p=0)
ddselection_type
definition(SpecParParser const &)
Definition: GenABIO.cc:180
void operator()(char const *first, char const *last) const
A DDLogicalPart aggregates information concerning material, solid and sensitveness ...
Definition: DDLogicalPart.h:92
ddselection_type selectionType_
DDSelLevelCollector & c_
rule< ScannerT > const & start() const
def parse(path, config)
Definition: dumpparser.py:13
void DDTokenize2(const std::string &sel, std::vector< DDPartSelRegExpLevel > &path)
Templated helper class to allow a selection on a certain object collection.
void operator()(char const *first, char const *last) const
DDNameSpaceFtor & nameSpaceFtor()
std::vector< DDPartSelRegExpLevel > * p_
DDSelLevelFtor & selLevelFtor()
const N & ddname() const
Definition: DDBase.h:80