CMS 3D CMS Logo

DDLMap.cc
Go to the documentation of this file.
4 
5 // Boost parser, spirit, for parsing the std::vector elements.
6 #include "boost/spirit/home/classic/core/non_terminal/grammar.hpp"
7 #include "boost/spirit/include/classic.hpp"
8 
9 #include <cstddef>
10 #include <utility>
11 
12 class DDCompactView;
13 
14 class MapPair {
15 public:
16  MapPair(DDLMap* iMap) : map_{iMap} {};
17  void operator()(char const* str, char const* end) const;
18 
19 private:
21 };
22 
23 class MapMakeName {
24 public:
25  MapMakeName(DDLMap* iMap) : map_{iMap} {};
26  void operator()(char const* str, char const* end) const;
27 
28 private:
30 };
31 
33 public:
34  MapMakeDouble(DDLMap* iMap) : map_{iMap} {};
35  void operator()(char const* str, char const* end) const;
36 
37 private:
39 };
40 
41 class Mapper : public boost::spirit::classic::grammar<Mapper> {
42 public:
43  Mapper(DDLMap* iMap) : map_{iMap} {};
44  template <typename ScannerT>
45  struct definition;
46 
47  MapPair mapPair() const { return MapPair(map_); }
48  MapMakeName mapMakeName() const { return MapMakeName(map_); }
50 
51 private:
53 };
54 
55 namespace boost {
56  namespace spirit {
57  namespace classic {}
58  } // namespace spirit
59 } // namespace boost
60 
61 using namespace boost::spirit::classic;
62 
64 
65 template <typename ScannerT>
66 struct Mapper::definition {
67  definition(Mapper const& self) {
68  mapSet = ppair[self.mapPair()] >> *((',' >> ppair)[self.mapPair()]);
69 
70  ppair = name >> ch_p('=') >> value;
71 
72  name = (alpha_p >> *alnum_p)[self.mapMakeName()];
73 
74  value = (+(anychar_p - ','))[self.mapMakeDouble()];
75  }
76 
77  rule<ScannerT> mapSet, ppair, name, value;
78 
79  rule<ScannerT> const& start() const { return mapSet; }
80 };
81 
82 void MapPair::operator()(char const* str, char const* end) const { map_->do_pair(str, end); }
83 
84 void MapMakeName::operator()(char const* str, char const* end) const { map_->do_makeName(str, end); }
85 
86 void MapMakeDouble::operator()(char const* str, char const* end) const { map_->do_makeDouble(str, end); }
87 
89  pName = "";
90  pMap.clear();
91  //pMapMap.clear(); only the DDLAlgorithm is allowed to clear this guy!
92  pDouble = 0.0;
93  pNameSpace = nmspace;
94 }
95 
96 void DDLMap::processElement(const std::string& name, const std::string& nmspace, DDCompactView& cpv) {
97  std::string tTextToParse = getText();
99  std::string tName = atts.find("name")->second;
100 
101  if (tTextToParse.empty()) {
102  errorOut("No std::string to parse!");
103  }
104 
105  // NOT IMPLEMENTED YET
106  if (atts.find("type") != atts.end() && atts.find("type")->second == "string") {
107  errorOut("Map of type std::string is not supported yet.");
108  }
109 
110  Mapper mapGrammar{this};
111 
112  pMap.clear();
113 
114  parse_info<> info = boost::spirit::classic::parse(tTextToParse.c_str(), mapGrammar >> end_p, space_p);
115  if (!info.full) {
116  errorOut("Does not conform to name=value, name=value... etc. of ddl Map element.");
117  }
118 
119  if (parent() == "Algorithm" || parent() == "SpecPar") {
120  pMapMap[tName] = pMap;
121  } else if (parent() == "ConstantsSection" || parent() == "DDDefinition") {
122  dd_map_type tMap;
123  for (std::map<std::string, double>::const_iterator it = pMap.begin(); it != pMap.end(); ++it) {
124  tMap[it->first] = it->second;
125  }
126  DDMap m(getDDName(pNameSpace), std::make_unique<dd_map_type>(tMap));
127  // clear the map of maps, because in these elements we only have ONE at a time.
128  pMapMap.clear();
129  }
130 
131  std::string nEntries = atts.find("nEntries")->second;
132  if (pMap.size() != size_t(myRegistry_->evaluator().eval(pNameSpace, nEntries))) {
133  errorOut("Number of entries found in Map text does not match number in attribute nEntries.");
134  }
135  clear();
136 }
137 
138 void DDLMap::do_pair(char const* str, char const* end) { pMap[pName] = pDouble; }
139 
140 void DDLMap::do_makeName(char const* str, char const* end) { pName = std::string(str, end); }
141 
142 void DDLMap::do_makeDouble(char const* str, char const* end) {
143  std::string ts(str, end);
145 }
146 
147 void DDLMap::errorOut(const char* str) {
148  std::string msg("\nDDLMap: Failed to parse the following: \n");
149  msg += std::string(str);
150  msg += "\n as a Map element (comma separated list of name=value).";
151  throwError(msg);
152 }
153 
DDMap
a named constant corresponding to the DDL-XML tag <Constant> and <ConstantsVector>
Definition: DDMap.h:22
DDXMLElement::parent
const std::string & parent(void) const
access to parent element name
Definition: DDXMLElement.cc:201
DDXMLElement::clear
virtual void clear(void)
clear this element's contents.
Definition: DDXMLElement.cc:40
Mapper::Mapper
Mapper(DDLMap *iMap)
Definition: DDLMap.cc:43
DDLMap::errorOut
void errorOut(const char *str)
Definition: DDLMap.cc:147
DDLMap::do_makeName
void do_makeName(char const *str, char const *end)
Definition: DDLMap.cc:140
DDLMap::do_makeDouble
void do_makeDouble(char const *str, char const *end)
Definition: DDLMap.cc:142
MapMakeName::map_
DDLMap * map_
Definition: DDLMap.cc:29
DDLMap::do_pair
void do_pair(char const *str, char const *end)
Definition: DDLMap.cc:138
DDLMap.h
DDLMap::pMapMap
ReadMapType< std::map< std::string, double > > pMapMap
Definition: DDLMap.h:48
DDXMLElement::throwError
void throwError(const std::string &keyMessage) const
format std::string for throw an error.
Definition: DDXMLElement.cc:209
boost::spirit::classic
Definition: DDPartSelection.cc:10
MapMakeName::operator()
void operator()(char const *str, char const *end) const
Definition: DDLMap.cc:84
ClhepEvaluator.h
Mapper::definition::mapSet
rule< ScannerT > mapSet
Definition: DDLMap.cc:77
simpleEdmComparison.tName
tName
Definition: simpleEdmComparison.py:125
Mapper::mapPair
MapPair mapPair() const
Definition: DDLMap.cc:47
DDLElementRegistry
The main class for processing parsed elements.
Definition: DDLElementRegistry.h:23
DDXMLElement::end
virtual std::vector< DDXMLAttribute >::const_iterator end(void)
Definition: DDXMLElement.cc:191
info
static const TGPicture * info(bool iBackgroundIsBlack)
Definition: FWCollectionSummaryWidget.cc:153
mps_check.msg
tuple msg
Definition: mps_check.py:285
MapPair::map_
DDLMap * map_
Definition: DDLMap.cc:20
MapMakeDouble::operator()
void operator()(char const *str, char const *end) const
Definition: DDLMap.cc:86
boost
Definition: CLHEP.h:16
Mapper
Definition: DDLMap.cc:41
DDXMLElement::getAttributeSet
virtual const DDXMLAttribute & getAttributeSet(size_t aIndex=0) const
Get a "row" of attributes, i.e. one attribute set.
Definition: DDXMLElement.cc:54
DDLElementRegistry::evaluator
ClhepEvaluator & evaluator()
Definition: DDLElementRegistry.h:42
Mapper::definition::definition
definition(Mapper const &self)
Definition: DDLMap.cc:67
MapMakeName
Definition: DDLMap.cc:23
DDLMap::preProcessElement
void preProcessElement(const std::string &name, const std::string &nmspace, DDCompactView &cpv) override
Called by loadAttributes AFTER attributes are loaded.
Definition: DDLMap.cc:88
DDLMap::getMapOfMaps
ReadMapType< std::map< std::string, double > > & getMapOfMaps(void)
Definition: DDLMap.cc:154
visualization-live-secondInstance_cfg.m
m
Definition: visualization-live-secondInstance_cfg.py:79
DDCompactView
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:81
Mapper::definition
Definition: DDLMap.cc:45
mps_fire.end
end
Definition: mps_fire.py:242
str
#define str(s)
Definition: TestProcessor.cc:53
MapMakeDouble
Definition: DDLMap.cc:32
MapMakeDouble::MapMakeDouble
MapMakeDouble(DDLMap *iMap)
Definition: DDLMap.cc:34
MapMakeDouble::map_
DDLMap * map_
Definition: DDLMap.cc:38
DDXMLAttribute
std::map< std::string, std::string > DDXMLAttribute
Definition: DDXMLElement.h:45
MapPair
Definition: DDLMap.cc:14
Mapper::definition::start
rule< ScannerT > const & start() const
Definition: DDLMap.cc:79
dumpparser.parse
def parse(path, config)
Definition: dumpparser.py:13
MapMakeName::MapMakeName
MapMakeName(DDLMap *iMap)
Definition: DDLMap.cc:25
Mapper::mapMakeDouble
MapMakeDouble mapMakeDouble() const
Definition: DDLMap.cc:49
DDLMap::pDouble
double pDouble
Definition: DDLMap.h:49
DDXMLElement
This is a base class for processing XML elements in the DDD.
Definition: DDXMLElement.h:48
Mapper::definition::ppair
rule< ScannerT > ppair
Definition: DDLMap.cc:77
Mapper::definition::name
rule< ScannerT > name
Definition: DDLMap.cc:77
value
Definition: value.py:1
DDLMap::pNameSpace
std::string pNameSpace
Definition: DDLMap.h:51
Mapper::mapMakeName
MapMakeName mapMakeName() const
Definition: DDLMap.cc:48
Mapper::definition::value
rule< ScannerT > value
Definition: DDLMap.cc:77
DDLElementRegistry.h
DDLMap
DDLMap handles Map container.
Definition: DDLMap.h:33
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
DDLMap::pName
std::string pName
Definition: DDLMap.h:50
DDXMLElement::getDDName
const virtual DDName getDDName(const std::string &defaultNS, const std::string &attname=std::string("name"), size_t aIndex=0)
Definition: DDXMLElement.cc:56
ReadMapType< double >
DDLMap::processElement
void processElement(const std::string &name, const std::string &nmspace, DDCompactView &cpv) override
Processing the element.
Definition: DDLMap.cc:96
DDLMap::pMap
dd_map_type pMap
Definition: DDLMap.h:47
MapPair::MapPair
MapPair(DDLMap *iMap)
Definition: DDLMap.cc:16
DDXMLElement::getText
const std::string getText(size_t tindex=0) const
retrieve the text blob.
Definition: DDXMLElement.cc:145
Mapper::map_
DDLMap * map_
Definition: DDLMap.cc:52
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
DDXMLElement::myRegistry_
DDLElementRegistry * myRegistry_
Definition: DDXMLElement.h:173
ClhepEvaluator::eval
double eval(const std::string &ns, const std::string &expr)
Definition: ClhepEvaluator.cc:85
MapPair::operator()
void operator()(char const *str, char const *end) const
Definition: DDLMap.cc:82
DDLMap::DDLMap
DDLMap(DDLElementRegistry *myreg)
Definition: DDLMap.cc:63