CMS 3D CMS Logo

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