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 }
XercesStrUtils.h
init
int init
Definition: HydjetWrapper.h:64
DDCurrentNamespace.h
mps_fire.i
i
Definition: mps_fire.py:428
DDLSAX2FileHandler::self
virtual const std::string & self() const
Definition: DDLSAX2FileHandler.cc:110
cms::xerces
Definition: XercesStrUtils.h:14
DDLSAX2FileHandler::endElement
void endElement(const XMLCh *uri, const XMLCh *localname, const XMLCh *qname) override
Definition: DDLSAX2FileHandler.cc:56
DDLElementRegistry
The main class for processing parsed elements.
Definition: DDLElementRegistry.h:23
DDLSAX2FileHandler::cpv_
DDCompactView & cpv_
Definition: DDLSAX2FileHandler.h:64
cms::xerces::cStr
ZStr< char > cStr(XMLCh const *str)
Definition: XercesStrUtils.h:32
DDLElementRegistry::evaluator
ClhepEvaluator & evaluator()
Definition: DDLElementRegistry.h:42
alignCSCRings.s
s
Definition: alignCSCRings.py:92
DDLSAX2FileHandler::~DDLSAX2FileHandler
~DDLSAX2FileHandler() override
Definition: DDLSAX2FileHandler.cc:22
DDLSAX2FileHandler::characters
void characters(const XMLCh *chars, XMLSize_t length) override
Definition: DDLSAX2FileHandler.cc:84
DDCompactView
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:81
DDLSAX2FileHandler::DDLSAX2FileHandler
DDLSAX2FileHandler(DDCompactView &cpv, DDLElementRegistry &)
Definition: DDLSAX2FileHandler.cc:13
DDLSAX2FileHandler::comment
void comment(const XMLCh *chars, XMLSize_t length) override
Definition: DDLSAX2FileHandler.cc:97
DDLSAX2FileHandler::init
void init()
Definition: DDLSAX2FileHandler.cc:17
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
DDLSAX2Handler::userNS_
bool userNS_
Definition: DDLSAX2Handler.h:85
DDLSAX2Handler::nmspace_
std::string nmspace_
Definition: DDLSAX2Handler.h:86
DDLSAX2FileHandler::parent
virtual const std::string & parent() const
Definition: DDLSAX2FileHandler.cc:103
DDLSAX2FileHandler::namesMap_
std::vector< std::string > namesMap_
Definition: DDLSAX2FileHandler.h:62
DDLElementRegistry::getElement
std::shared_ptr< DDXMLElement > getElement(const std::string &name)
THE most important part. Getting the pointer to a given element type.
Definition: DDLElementRegistry.cc:42
DDLSAX2Handler::Attributes
XERCES_CPP_NAMESPACE::Attributes Attributes
Definition: DDLSAX2Handler.h:29
DDXMLElement.h
DDCurrentNamespace::ns
static std::string & ns()
Definition: DDCurrentNamespace.cc:3
DDLSAX2FileHandler::startElement
void startElement(const XMLCh *uri, const XMLCh *localname, const XMLCh *qname, const Attributes &attrs) override
Definition: DDLSAX2FileHandler.cc:24
DDLSAX2FileHandler::names_
std::vector< size_t > names_
Definition: DDLSAX2FileHandler.h:63
DDLSAX2FileHandler.h
DDLSAX2FileHandler::registry_
DDLElementRegistry & registry_
Definition: DDLSAX2FileHandler.h:65
DDConstant.h
DDLSAX2FileHandler::createDDConstants
void createDDConstants() const
creates all DDConstant from the evaluator which has been already 'filled' in the first scan of the do...
Definition: DDLSAX2FileHandler.cc:99
DDConstant::createConstantsFromEvaluator
static void createConstantsFromEvaluator(ClhepEvaluator &)
creates all DDConstants from the variables of the ClhepEvaluator
Definition: DDConstant.cc:27