CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
HcalConstantsXMLWriter.cc
Go to the documentation of this file.
2 
3 // Write the new XML object: needed includes
4 
5 // Xerces-C
6 #include <xercesc/dom/DOMNode.hpp>
7 #include <xercesc/dom/DOM.hpp>
8 #include <xercesc/dom/DOMCharacterData.hpp>
9 #include <xercesc/parsers/XercesDOMParser.hpp>
12 #include <xercesc/framework/LocalFileFormatTarget.hpp>
13 #include <xercesc/util/XMLUni.hpp>
14 #include <xercesc/util/XMLURL.hpp>
15 
17 #include <sstream>
18 #include <string>
19 
20 using namespace xercesc;
21 
25  const std::vector<int>& detvec,
26  const std::vector<int>& etavec,
27  const std::vector<int>& phivec,
28  const std::vector<int>& depthvec,
29  const std::vector<float>& scalevec) {
30  int nn = newfile0.size();
31  char newfile[99];
32  for (int i = 0; i < nn; i++) {
33  newfile[i] = newfile0[i];
34  }
35  char const* fend = "\0";
36  newfile[nn] = *fend;
37 
38  edm::LogVerbatim("HcalCalib") << " New file " << newfile << std::endl;
39 
40  std::filebuf fb;
41  fb.open(newfile, std::ios::out);
42  std::ostream fOut(&fb);
43 
44  XMLCh tempStr[100];
45 
46  XMLString::transcode("Core", tempStr, 99);
47  std::unique_ptr<DOMImplementation> mDom(DOMImplementationRegistry::getDOMImplementation(tempStr));
48 
49  XMLString::transcode("CalibrationConstants", tempStr, 99);
50  mDoc = mDom->createDocument(nullptr, // root element namespace URI.
51  tempStr, // root element name
52  nullptr); // document type object (DTD).
53 
54  StreamOutFormatTarget formTarget(fOut);
55  DOMLSSerializer* domWriter = mDom->createLSSerializer();
56  domWriter->getDomConfig()->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true);
57  DOMElement* root = mDoc->getDocumentElement();
58 
59  XMLString::transcode("Hcal", tempStr, 99);
60  DOMElement* rootelem = mDoc->createElement(tempStr);
61  root->appendChild(rootelem);
62 
63  XMLString::transcode("Cell", tempStr, 99);
64  std::vector<DOMElement*> theDOMVec;
65 
66  for (unsigned int i = 0; i < detvec.size(); i++) {
67  theDOMVec.push_back(mDoc->createElement(tempStr));
68  newCellLine(theDOMVec[i], detvec[i], etavec[i], phivec[i], depthvec[i], scalevec[i]);
69  rootelem->appendChild(theDOMVec[i]);
70  }
71 
72  edm::LogVerbatim("HcalCalib") << " Write Doc " << theDOMVec.size();
73  DOMLSOutput* output = mDom->createLSOutput();
74  output->setByteStream(&formTarget);
75  domWriter->write(mDoc, output);
76  edm::LogVerbatim("HcalCalib") << " End of Writting ";
77  mDoc->release();
78  output->release();
79  domWriter->release();
80 }
81 
82 void HcalConstantsXMLWriter::newCellLine(DOMElement* detelem, int det, int eta, int phi, int depth, float scale) {
83  XMLCh tempStr[100];
84  XMLString::transcode("det_index", tempStr, 99);
85  DOMAttr* attrdet = mDoc->createAttribute(tempStr);
86 
87  XMLString::transcode("eta_index", tempStr, 99);
88  DOMAttr* attreta = mDoc->createAttribute(tempStr);
89 
90  XMLString::transcode("phi_index", tempStr, 99);
91  DOMAttr* attrphi = mDoc->createAttribute(tempStr);
92 
93  XMLString::transcode("depth_index", tempStr, 99);
94  DOMAttr* attrdepth = mDoc->createAttribute(tempStr);
95 
96  XMLString::transcode("scale_factor", tempStr, 99);
97  DOMAttr* attrscale = mDoc->createAttribute(tempStr);
98 
99  std::ostringstream ost;
100  ost << det;
101  attrdet->setValue(XMLString::transcode(ost.str().c_str()));
102  detelem->setAttributeNode(attrdet);
103 
104  std::ostringstream ost1;
105  ost1 << eta;
106  attreta->setValue(XMLString::transcode(ost1.str().c_str()));
107  //DOMAttr* attr3 = detelem->setAttributeNode(attreta);
108  detelem->setAttributeNode(attreta);
109 
110  std::ostringstream ost2;
111  ost2 << phi;
112  attrphi->setValue(XMLString::transcode(ost2.str().c_str()));
113  //DOMAttr* attr4 = detelem->setAttributeNode(attrphi);
114  detelem->setAttributeNode(attrphi);
115 
116  std::ostringstream ost3;
117  ost3 << depth;
118  attrdepth->setValue(XMLString::transcode(ost3.str().c_str()));
119  //DOMAttr* attr5 = detelem->setAttributeNode(attrdepth);
120  detelem->setAttributeNode(attrdepth);
121 
122  std::ostringstream ost4;
123  ost4 << scale;
124  attrscale->setValue(XMLString::transcode(ost4.str().c_str()));
125  //DOMAttr* attr6 = detelem->setAttributeNode(attrscale);
126  detelem->setAttributeNode(attrscale);
127 }
Log< level::Info, true > LogVerbatim
void newCellLine(xercesc::DOMElement *, int, int, int, int, float)
void writeXML(std::string &, const std::vector< int > &, const std::vector< int > &, const std::vector< int > &, const std::vector< int > &, const std::vector< float > &)
tuple newfile
Definition: runonSM.py:49
int32_t *__restrict__ nn