CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DDPartSelection.cc
Go to the documentation of this file.
5 
6 #include "boost/spirit/include/classic.hpp"
7 
8 // Message logger.
10 
11 #include <map>
12 
13 namespace boost { namespace spirit { namespace classic { } } } using namespace boost::spirit::classic;
14 
16 {
19  int copyNo_;
21  bool isChild_;
22  std::vector<DDPartSelRegExpLevel>* p_;
23 
24  std::vector<DDPartSelRegExpLevel>* path(std::vector<DDPartSelRegExpLevel>* p=0) {
25  if (p) {
26  p_=p;
27  namespace_="";
28  name_="";
29  copyNo_=0;
30  isCopyNoValid_=false;
31  isChild_=false;
32  }
33  return p_;
34  }
35 };
36 
37 
38 void noNameSpace(char const * /*first*/, char const* /*last*/) {
40 }
41 /* Functor for the parser; it does not consume memory -
42  pointers are only used to store references to memory
43  managed elsewhere
44 */
46 {
48  : c_(DDI::Singleton<DDSelLevelCollector>::instance())
49  { }
50 
51  // parser calls this whenever a selection has been parsed ( //ns:nm[cn], /nm, //ns:nm, .... )
52  void operator() (char const* /*first*/, char const* /*last*/) const {
53  if(c_.path()){
54  if (c_.isCopyNoValid_ && c_.isChild_) {
55  c_.path()->push_back(DDPartSelRegExpLevel(c_.namespace_,c_.name_,c_.copyNo_,ddchildposp));
56  //edm::LogInfo("DDPartSelection") << namespace_ << name_ << copyNo_ << ' ' << ddchildposp << std::endl;
57  } else
58  if (c_.isCopyNoValid_ && !c_.isChild_) {
59  c_.path()->push_back(DDPartSelRegExpLevel(c_.namespace_,c_.name_,c_.copyNo_,ddanyposp));
60  // edm::LogInfo("DDPartSelection") << namespace_ << name_ << copyNo_ << ' ' << ddanyposp << std::endl;
61  } else
62  if (!c_.isCopyNoValid_ && c_.isChild_) {
63  c_.path()->push_back(DDPartSelRegExpLevel(c_.namespace_,c_.name_,c_.copyNo_,ddchildlogp));
64  // edm::LogInfo("DDPartSelection") << namespace_ << name_ << copyNo_ << ' ' << ddchildlogp << std::endl;
65  } else
66  if (!c_.isCopyNoValid_ && !c_.isChild_) {
67  c_.path()->push_back(DDPartSelRegExpLevel(c_.namespace_,c_.name_,c_.copyNo_,ddanylogp));
68  // edm::LogInfo("DDPartSelection") << namespace_ << name_ << copyNo_ << ' ' << ddanylogp << std::endl;
69  }
70  c_.namespace_="";
71  c_.name_="";
72  c_.isCopyNoValid_=false;
73  }
74  }
75 
77 };
78 
80 {
81 
82  void operator()(char const* first, char const* last) const {
84  if ( (last-first) > 1)
85  sl.isChild_=false;
86  if ( (last-first) ==1 )
87  sl.isChild_=true;
88  //edm::LogInfo("DDPartSelection") << "DDIsChildFtor isChild=" << (last-first) << std::endl;
89  }
90 
91 };
92 
93 
95 {
96 
97  void operator()(char const* first, char const* last) const {
99  sl.namespace_.assign(first,last);
100  // edm::LogInfo("DDPartSelection") << "DDNameSpaceFtor singletonname=" << DDI::Singleton<DDSelLevelCollector>::instance().namespace_ << std::endl;
101  }
102 
104 };
105 
106 
108 {
109 
110  void operator()(char const* first, char const* last) const {
112  sl.name_.assign(first,last);
113  // edm::LogInfo("DDPartSelection") << "DDNameFtor singletonname=" << Singleton<DDSelLevelCollector>::instance().name_ << std::endl;
114  }
115 
116 };
117 
118 
120 {
121 
122  void operator()(int i) const {
124  sl.copyNo_ = i;
125  sl.isCopyNoValid_ = true;
126  // edm::LogInfo("DDPartSelection") << "DDCopyNoFtor ns=" << i;
127  }
128 
129 };
130 
132 struct SpecParParser : public grammar<SpecParParser>
133 {
134  template <typename ScannerT>
135  struct definition
136  {
137  definition(SpecParParser const& /*self*/) {
138 
139  Selection //= FirstStep[selLevelFtor()]
140  //>> *SelectionStep[selLevelFtor()]
141  = +SelectionStep[selLevelFtor()]
142  ;
143 
144  FirstStep = Descendant
145  >> Part
146  ;
147 
148  Part = PartNameCopyNumber
149  | PartName
150  ;
151 
152  PartNameCopyNumber = PartName
153  >> CopyNumber
154  ;
155 
156  SelectionStep = NavigationalElement[isChildFtor()]
157  >> Part
158  ;
159 
160  NavigationalElement = Descendant
161  | Child
162  ;
163 
164  CopyNumber = ch_p('[')
165  >> int_p[copyNoFtor()]
166  >> ch_p(']')
167  ;
168 
169  PartName = NameSpaceName
170  | SimpleName[nameFtor()][&noNameSpace]
171  ;
172 
173  SimpleName = +( alnum_p | ch_p('_') | ch_p('.') | ch_p('*') )
174  ;
175 
176  NameSpaceName = SimpleName[nameSpaceFtor()]
177  >> ':'
178  >> SimpleName[nameFtor()]
179  ;
180 
181  Descendant = ch_p('/')
182  >> ch_p('/')
183  ;
184 
185  Child = ch_p('/')
186  ;
187 
188  }
189 
190  rule<ScannerT> Selection, FirstStep, Part, SelectionStep, NavigationalElement,
191  CopyNumber, PartName, PartNameCopyNumber, NameSpaceName, SimpleName,
192  Descendant, Child;
193 
194  rule<ScannerT> const& start() const { return Selection; }
195 
198  }
199 
201  static DDNameFtor f_;
202  return f_;
203  }
204 
206  static DDNameSpaceFtor f_;
207  return f_;
208  }
209 
211  static DDIsChildFtor f_;
212  return f_;
213  }
214 
216  static DDCopyNoFtor f_;
217  return f_;
218  }
219  };
220 
221 };
222 
224  : lp_(lp), copyno_(c), selectionType_(t)
225 {}
226 
227 void DDTokenize2(const std::string & sel, std::vector<DDPartSelRegExpLevel> & path)
228 {
229  static SpecParParser parser;
231  bool result = parse(sel.c_str(), parser).full;
232  if (!result) {
233  edm::LogError("DDPartSelection") << "DDTokenize2() error in parsing of " << sel << std::endl;
234  }
235 }
236 
237 std::ostream & operator<<(std::ostream & o, const DDPartSelection & p)
238 {
239  DDPartSelection::const_iterator it(p.begin()), ed(p.end());
240  for (; it != ed; ++it) {
241  const DDPartSelectionLevel lv =*it;
242  switch (lv.selectionType_) {
243  case ddanylogp:
244  o << "//" << lv.lp_.ddname();
245  break;
246  case ddanyposp:
247  o << "//" << lv.lp_.ddname() << '[' << lv.copyno_ << ']';
248  break;
249  case ddchildlogp:
250  o << "/" << lv.lp_.ddname();
251  break;
252  case ddchildposp:
253  o << "/" << lv.lp_.ddname() << '[' << lv.copyno_ << ']';
254  break;
255  default:
256  o << "{Syntax ERROR}";
257  }
258  }
259  return o;
260 }
261 
262 std::ostream & operator<<(std::ostream & os, const std::vector<DDPartSelection> & v)
263 {
264  std::vector<DDPartSelection>::const_iterator it(v.begin()), ed(v.end());
265  for (; it != (ed-1); ++it) {
266  os << *it << std::endl;
267  }
268  if ( it != ed ) {
269  ++it;
270  os << *it;
271  }
272  return os;
273 }
274 
275 // explicit template instantiation.
276 
277 template class DDI::Singleton<DDSelLevelFtor>;
278 //template class DDI::Singleton<DDI::Store<DDName, DDSelLevelCollector> >;
280 #include <DetectorDescription/Base/interface/Singleton.icc>
DDSelLevelFtor * selLevelFtor_
int i
Definition: DBlmapReader.cc:9
DDPartSelectionLevel(const DDLogicalPart &, int, ddselection_type)
void operator()(char const *first, char const *last) const
Evaluator * parse(const T &text)
static PFTauRenderPlugin instance
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:187
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
tuple result
Definition: query.py:137
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:88
ddselection_type selectionType_
DDSelLevelCollector & c_
rule< ScannerT > const & start() const
void DDTokenize2(const std::string &selectionString, std::vector< DDPartSelRegExpLevel > &result)
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