CMS 3D CMS Logo

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