CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DDLMap.cc
Go to the documentation of this file.
1 /***************************************************************************
2  DDLMap.cc - description
3  -------------------
4  begin : Friday Nov. 21, 2003
5  email : case@ucdhep.ucdavis.edu
6  ***************************************************************************/
7 
8 // Boost parser, spirit, for parsing the std::vector elements.
9 
11 
14 
15 using namespace boost::spirit::classic;
16 
17 // The "real" DDLMap members.
19  : DDXMLElement( myreg )
20 {}
21 
23 {}
24 
25 template <typename ScannerT> struct Mapper::definition
26 {
27  definition(Mapper const& self)
28  {
29  mapSet
30  = ppair[MapPair()]
31  >> *((',' >> ppair)[MapPair()])
32  ;
33 
34  ppair
35  = name
36  >> ch_p('=') >> value
37  ;
38 
39  name
40  = (alpha_p >> *alnum_p)[MapMakeName()]
41  ;
42 
43  value
44  = (+(anychar_p - ','))[MapMakeDouble()]
45  ;
46  }
47 
48  rule<ScannerT> mapSet, ppair, name, value;
49 
50  rule<ScannerT> const&
51  start() const { return mapSet; }
52 };
53 
54 void
55 MapPair::operator() (char const* str, char const* end) const
56 {
57  DDLMap* myDDLMap = dynamic_cast < DDLMap* > (DDLGlobalRegistry::instance().getElement("Map"));
58  myDDLMap->do_pair(str, end);
59 }
60 
61 void
62 MapMakeName::operator() (char const* str, char const* end) const
63 {
64  DDLMap* myDDLMap = dynamic_cast < DDLMap* > (DDLGlobalRegistry::instance().getElement("Map"));
65  myDDLMap->do_makeName(str, end);
66 }
67 
68 void
69 MapMakeDouble::operator() (char const* str, char const* end)const
70 {
71  DDLMap* myDDLMap = dynamic_cast < DDLMap* > (DDLGlobalRegistry::instance().getElement("Map"));
72  myDDLMap->do_makeDouble(str, end);
73 }
74 
75 void
77 {
78  pName = "";
79  pMap.clear() ;
80  //pMapMap.clear(); only the DDLAlgorithm is allowed to clear this guy!
81  pDouble = 0.0;
82  pNameSpace = nmspace;
83 }
84 
85 void
87 {
88  DCOUT_V('P', "DDLMap::processElement started");
89 
90  std::string tTextToParse = getText();
92  std::string tName = atts.find("name")->second;
93 
94  if (tTextToParse.size() == 0)
95  {
96  errorOut("No std::string to parse!");
97  }
98 
99  // NOT IMPLEMENTED YET
100  if (atts.find("type") != atts.end() && atts.find("type")->second == "string")
101  {
102  errorOut("Map of type std::string is not supported yet.");
103  }
104 
105  Mapper mapGrammar;
106 
107  pMap.clear();
108 
109  parse_info<> info = boost::spirit::classic::parse(tTextToParse.c_str(), mapGrammar >> end_p, space_p);
110  if (!info.full)
111  {
112  errorOut("Does not conform to name=value, name=value... etc. of ddl Map element.");
113  }
114 
115  if (parent() == "Algorithm" || parent() == "SpecPar")
116  {
117  pMapMap[tName] = pMap;
118  }
119  else if (parent() == "ConstantsSection" || parent() == "DDDefinition")
120  {
121  dd_map_type * tMap = new dd_map_type;
122  for (std::map<std::string, double>::const_iterator it = pMap.begin(); it != pMap.end(); ++it)
123  {
124  (*tMap)[it->first] = it->second;
125  }
126  DDMap m ( getDDName(pNameSpace) , 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() !=
133  size_t(myRegistry_->evaluator().eval(pNameSpace, nEntries)))
134  {
135  errorOut("Number of entries found in Map text does not match number in attribute nEntries.");
136  }
137  clear();
138 
139  DCOUT_V('P', "DDLMap::processElement completed");
140 }
141 
142 void
143 DDLMap::do_pair( char const* str, char const* end )
144 {
145  pMap[pName] = pDouble;
146 }
147 
148 void
149 DDLMap::do_makeName( char const* str, char const* end )
150 {
151  pName = std::string(str, end);
152 }
153 
154 void
155 DDLMap::do_makeDouble( char const* str, char const* end )
156 {
157  std::string ts(str, end);
159 }
160 
161 void
162 DDLMap::errorOut( const char* str )
163 {
164  std::string msg("\nDDLMap: Failed to parse the following: \n");
165  msg+= std::string(str);
166  msg+="\n as a Map element (comma separated list of name=value).";
167  throwError(msg);
168 }
169 
172 {
173  return pMapMap;
174 }
Definition: DDLMap.h:23
ReadMapType< std::map< std::string, double > > pMapMap
Definition: DDLMap.h:78
void preProcessElement(const std::string &name, const std::string &nmspace, DDCompactView &cpv)
Called by loadAttributes AFTER attributes are loaded.
Definition: DDLMap.cc:76
void processElement(const std::string &name, const std::string &nmspace, DDCompactView &cpv)
Processing the element.
Definition: DDLMap.cc:86
static const TGPicture * info(bool iBackgroundIsBlack)
void operator()(char const *str, char const *end) const
Definition: DDLMap.cc:62
DDLElementRegistry * myRegistry_
Definition: DDXMLElement.h:186
DDLMap(DDLElementRegistry *myreg)
Definition: DDLMap.cc:18
ReadMapType< double > dd_map_type
simply a std::map&lt;std::string,double&gt; supporting an addional operator[] const
Definition: DDMap.h:16
virtual const DDXMLAttribute & getAttributeSet(size_t aIndex=0) const
Get a &quot;row&quot; of attributes, i.e. one attribute set.
Definition: DDXMLElement.cc:79
std::string pNameSpace
Definition: DDLMap.h:81
std::string pName
Definition: DDLMap.h:80
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:171
const std::string & parent(void) const
access to parent element name
type of data representation of DDCompactView
Definition: DDCompactView.h:77
a named constant corresponding to the DDL-XML tag &lt;Constant&gt; and &lt;ConstantsVector&gt; ...
Definition: DDMap.h:19
std::map< std::string, std::string > DDXMLAttribute
Definition: DDXMLElement.h:55
rule< ScannerT > mapSet
Definition: DDLMap.cc:48
static value_type & instance()
rule< ScannerT > name
Definition: DDLMap.cc:48
ClhepEvaluator & evaluator()
definition(Mapper const &self)
Definition: DDLMap.cc:27
void do_makeName(char const *str, char const *end)
Definition: DDLMap.cc:149
void operator()(char const *str, char const *end) const
Definition: DDLMap.cc:69
rule< ScannerT > value
Definition: DDLMap.cc:48
#define end
Definition: vmac.h:37
Definition: DDLMap.h:16
rule< ScannerT > ppair
Definition: DDLMap.cc:48
void do_pair(char const *str, char const *end)
Definition: DDLMap.cc:143
#define DCOUT_V(M_v_Y, M_v_S)
Definition: DDdebug.h:54
DDLMap handles Map container.
Definition: DDLMap.h:58
virtual ~DDLMap(void)
Definition: DDLMap.cc:22
This is a base class for processing XML elements in the DDD.
Definition: DDXMLElement.h:58
double pDouble
Definition: DDLMap.h:79
void errorOut(const char *str)
Definition: DDLMap.cc:162
rule< ScannerT > const & start() const
Definition: DDLMap.cc:51
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:61
void do_makeDouble(char const *str, char const *end)
Definition: DDLMap.cc:155
virtual const DDName getDDName(const std::string &defaultNS, const std::string &attname=std::string("name"), size_t aIndex=0)
Definition: DDXMLElement.cc:86
void operator()(char const *str, char const *end) const
Definition: DDLMap.cc:55
dd_map_type pMap
Definition: DDLMap.h:77
const std::string getText(size_t tindex=0) const
retrieve the text blob.