CMS 3D CMS Logo

DDLSAX2FileHandler.cc
Go to the documentation of this file.
6 
7 using namespace cms::xerces;
8 
9 class DDCompactView;
10 
11 // XERCES_CPP_NAMESPACE_USE
12 
14  init();
15 }
16 
18  namesMap_.emplace_back("*** root ***");
19  names_.emplace_back(namesMap_.size() - 1);
20 }
21 
23 
24 void DDLSAX2FileHandler::startElement(const XMLCh* const uri,
25  const XMLCh* const localname,
26  const XMLCh* const qname,
27  const Attributes& attrs) {
28  std::string myElementName(cStr(qname).ptr());
29  size_t i = 0;
30  for (; i < namesMap_.size(); ++i) {
31  if (myElementName == namesMap_.at(i)) {
32  names_.emplace_back(i);
33  break;
34  }
35  }
36  if (i >= namesMap_.size()) {
37  namesMap_.emplace_back(myElementName);
38  names_.emplace_back(namesMap_.size() - 1);
39  }
40 
41  auto myElement = registry_.getElement(myElementName);
42 
43  unsigned int numAtts = attrs.getLength();
44  std::vector<std::string> attrNames, attrValues;
45 
46  for (unsigned int i = 0; i < numAtts; ++i) {
47  attrNames.emplace_back(std::string(cStr(attrs.getLocalName(i)).ptr()));
48  attrValues.emplace_back(std::string(cStr(attrs.getValue(i)).ptr()));
49  }
50 
51  myElement->loadAttributes(myElementName, attrNames, attrValues, nmspace_, cpv_);
52  // initialize text
53  myElement->loadText(std::string());
54 }
55 
56 void DDLSAX2FileHandler::endElement(const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname) {
57  std::string ts(cStr(qname).ptr());
58  const std::string& myElementName = self();
59 
60  auto myElement = registry_.getElement(myElementName);
61 
62  std::string nmspace = nmspace_;
63  // The need for processElement to have the nmspace so that it can
64  // do the necessary gymnastics made things more complicated in the
65  // effort to allow fully user-controlled namespaces. So the "magic"
66  // trick of setting nmspace to "!" is used :(... I don't like this magic trick
67  // -- Michael Case 2008-11-06
68  // OPTIMISE in the near future, like the current nmspace_ impl.
69  // just set nmspace_ to "!" from Parser based on userNS_ so
70  // userNS_ is set by parser ONCE and no if nec. here. MEC: 2009-06-22
71  if (userNS_) {
72  nmspace = "!";
73  }
74 
75  DDCurrentNamespace::ns() = nmspace;
76  // tell the element it's parent name for recording/reporting purposes
77  myElement->setParent(parent());
78  myElement->setSelf(self());
79  myElement->processElement(myElementName, nmspace, cpv_);
80 
81  names_.pop_back();
82 }
83 
84 void DDLSAX2FileHandler::characters(const XMLCh* const chars, const XMLSize_t length) {
85  auto myElement = registry_.getElement(self());
86  std::string inString = "";
87  for (XMLSize_t i = 0; i < length; ++i) {
88  char s = chars[i];
89  inString = inString + s;
90  }
91  if (myElement->gotText())
92  myElement->appendText(inString);
93  else
94  myElement->loadText(inString);
95 }
96 
97 void DDLSAX2FileHandler::comment(const XMLCh* const chars, const XMLSize_t length) {}
98 
101 }
102 
104  if (names_.size() > 2) {
105  return namesMap_.at(names_.at(names_.size() - 2));
106  }
107  return namesMap_[0]; //.at(names_.at(0));
108 }
109 
111  if (names_.size() > 1) {
112  return namesMap_.at(names_.at(names_.size() - 1));
113  }
114  return namesMap_[0]; //.at(names_.at(0));
115 }
virtual const std::string & parent() const
void comment(const XMLCh *chars, XMLSize_t length) override
int init
Definition: HydjetWrapper.h:64
static std::string & ns()
DDLElementRegistry & registry_
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:81
ROOT::VecOps::RVec< UChar_t > chars
Definition: Resolutions.cc:6
ClhepEvaluator & evaluator()
~DDLSAX2FileHandler() override
std::shared_ptr< DDXMLElement > getElement(const std::string &name)
THE most important part. Getting the pointer to a given element type.
ZStr< char > cStr(XMLCh const *str)
std::vector< size_t > names_
void createDDConstants() const
creates all DDConstant from the evaluator which has been already &#39;filled&#39; in the first scan of the do...
std::string nmspace_
std::vector< std::string > namesMap_
static void createConstantsFromEvaluator(ClhepEvaluator &)
creates all DDConstants from the variables of the ClhepEvaluator
Definition: DDConstant.cc:27
DDCompactView & cpv_
virtual const std::string & self() const
void endElement(const XMLCh *uri, const XMLCh *localname, const XMLCh *qname) override
XERCES_CPP_NAMESPACE::Attributes Attributes
The main class for processing parsed elements.
void startElement(const XMLCh *uri, const XMLCh *localname, const XMLCh *qname, const Attributes &attrs) override
DDLSAX2FileHandler(DDCompactView &cpv, DDLElementRegistry &)
void characters(const XMLCh *chars, XMLSize_t length) override