CMS 3D CMS Logo

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