CMS 3D CMS Logo

SiPixelConfigWriter.cc
Go to the documentation of this file.
2 
4 #include <memory>
5 
6 using namespace xercesc;
7 using namespace std;
8 //
9 // -- Constructor
10 //
12 //
13 // -- Destructor
14 //
16 //
17 // -- Initialize XML
18 //
20  try {
22  } catch (const XMLException &toCatch) {
23  cout << "Problem to initialise XML !!! " << endl;
24  return false;
25  }
26  unique_ptr<DOMImplementation> domImpl(DOMImplementationRegistry::getDOMImplementation(qtxml::_toDOMS("Range")));
27  if (domImpl == nullptr)
28  return false;
29  theDomWriter = domImpl->createLSSerializer();
30  if (theDomWriter == nullptr)
31  return false;
32  if (theDomWriter->getDomConfig()->canSetParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true))
33  theDomWriter->getDomConfig()->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true);
34  theDoc = domImpl->createDocument(nullptr, qtxml::_toDOMS("Layouts"), nullptr);
35  if (theDoc == nullptr)
36  return false;
37  theTopElement = theDoc->getDocumentElement();
38  theTopElement->appendChild(theDoc->createTextNode(qtxml::_toDOMS("\n")));
39  theOutput = domImpl->createLSOutput();
40  if (theOutput == nullptr)
41  return false;
42  return true;
43 }
44 //
45 // -- Add an Element
46 //
48  theLastLayout = theDoc->createElement(qtxml::_toDOMS("layout"));
49  theLastLayout->setAttribute(qtxml::_toDOMS("name"), qtxml::_toDOMS(name));
50  theTopElement->appendChild(theLastLayout);
51 }
52 //
53 // -- Add an Element
54 //
56  theLastLayout->appendChild(theDoc->createTextNode(qtxml::_toDOMS("\n")));
57 
58  theLastRow = theDoc->createElement(qtxml::_toDOMS("row"));
59  theLastLayout->appendChild(theLastRow);
60  theLastLayout->appendChild(theDoc->createTextNode(qtxml::_toDOMS("\n")));
61 }
62 //
63 // -- Add an Element with Children
64 //
65 void SiPixelConfigWriter::createColumn(string &element, string &name) {
66  theLastRow->appendChild(theDoc->createTextNode(qtxml::_toDOMS("\n")));
67  DOMElement *e1 = theDoc->createElement(qtxml::_toDOMS("column"));
68  theLastRow->appendChild(e1);
69 
70  DOMElement *e2 = theDoc->createElement(qtxml::_toDOMS(element));
71  e2->setAttribute(qtxml::_toDOMS("name"), qtxml::_toDOMS(name));
72  e1->appendChild(e2);
73 }
74 //
75 // -- Write to File
76 //
78  XMLFormatTarget *formTarget = new LocalFileFormatTarget(fname.c_str());
79  theOutput->setByteStream(formTarget);
80  theDomWriter->write(theTopElement, theOutput);
81  delete formTarget;
82  theOutput->release();
83  theDoc->release();
84  theDomWriter->release();
85 }
bool init()
Write XML file.
~SiPixelConfigWriter()
Destructor.
void write(std::string &fname)
void createColumn(std::string &element, std::string &name)
void xercesInitialize()
Definition: Xerces.cc:18
XMLCh * _toDOMS(std::string temp)
string fname
main script
void createLayout(std::string &name)