CMS 3D CMS Logo

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>
11 #include <xercesc/framework/LocalFileFormatTarget.hpp>
12 #include <xercesc/util/XMLUni.hpp>
13 #include <xercesc/util/XMLURL.hpp>
14 
15 
17 #include <sstream>
18 #include <string>
19 using namespace std;
20 using namespace xercesc;
21 
23 {
24 }
26 {
27 }
28 void HcalConstantsXMLWriter::writeXML(string& newfile0,const vector<int>& detvec,const vector<int>& etavec,const vector<int>& phivec,const vector<int>& depthvec,const vector<float>& scalevec)
29 {
30  int nn = newfile0.size();
31  char newfile[99];
32  for (int i = 0; i < nn; i++)
33  {
34  newfile[i]=newfile0[i];
35  }
36  char const* fend="\0";
37  newfile[nn] = *fend;
38 
39  cout<<" New file "<<newfile<<endl;
40 
41  filebuf fb;
42  fb.open (newfile,ios::out);
43  ostream fOut(&fb);
44 
45  XMLCh tempStr[100];
46 
47  XMLString::transcode ("Core",tempStr,99);
48  unique_ptr<DOMImplementation> mDom( DOMImplementationRegistry::getDOMImplementation (tempStr));
49 
50  XMLString::transcode("CalibrationConstants", tempStr, 99);
51  mDoc = mDom->createDocument(
52  nullptr, // root element namespace URI.
53  tempStr, // root element name
54  nullptr); // document type object (DTD).
55 
56  StreamOutFormatTarget formTarget (fOut);
57  DOMLSSerializer* domWriter = mDom->createLSSerializer();
58  domWriter->getDomConfig()->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true);
59  DOMElement* root = mDoc->getDocumentElement();
60 
61  XMLString::transcode("Hcal", tempStr, 99);
62  DOMElement* rootelem = mDoc->createElement (tempStr);
63  root->appendChild(rootelem);
64 
65  XMLString::transcode("Cell", tempStr, 99);
66  vector<DOMElement*> theDOMVec;
67 
68  for(unsigned int i=0; i<detvec.size();i++)
69  {
70  theDOMVec.push_back(mDoc->createElement (tempStr));
71  newCellLine(theDOMVec[i],detvec[i],etavec[i],phivec[i],depthvec[i],scalevec[i]);
72  rootelem->appendChild(theDOMVec[i]);
73  }
74 
75  cout<<" Write Doc "<<theDOMVec.size()<<endl;
76  DOMLSOutput* output= mDom->createLSOutput();
77  output->setByteStream(&formTarget);
78  domWriter->write (mDoc, output);
79  cout<<" End of Writting "<<endl;
80  mDoc->release ();
81  output->release();
82  domWriter->release();
83 }
84 
85 void HcalConstantsXMLWriter::newCellLine(DOMElement* detelem, int det, int eta, int phi, int depth, float scale)
86 {
87  XMLCh tempStr[100];
88  XMLString::transcode("det_index", tempStr, 99);
89  DOMAttr* attrdet = mDoc->createAttribute(tempStr);
90 
91  XMLString::transcode("eta_index", tempStr, 99);
92  DOMAttr* attreta = mDoc->createAttribute(tempStr);
93 
94  XMLString::transcode("phi_index", tempStr, 99);
95  DOMAttr* attrphi = mDoc->createAttribute(tempStr) ;
96 
97  XMLString::transcode("depth_index", tempStr, 99);
98  DOMAttr* attrdepth = mDoc->createAttribute(tempStr) ;
99 
100  XMLString::transcode("scale_factor", tempStr, 99);
101  DOMAttr* attrscale = mDoc->createAttribute(tempStr) ;
102 
103  ostringstream ost;
104  ost <<det;
105  attrdet->setValue(XMLString::transcode(ost.str().c_str()));
106  detelem->setAttributeNode(attrdet);
107 
108  ostringstream ost1;
109  ost1 <<eta;
110  attreta->setValue(XMLString::transcode(ost1.str().c_str()));
111  //DOMAttr* attr3 = detelem->setAttributeNode(attreta);
112  detelem->setAttributeNode(attreta);
113 
114  ostringstream ost2;
115  ost2 <<phi;
116  attrphi->setValue(XMLString::transcode(ost2.str().c_str()));
117  //DOMAttr* attr4 = detelem->setAttributeNode(attrphi);
118  detelem->setAttributeNode(attrphi);
119 
120  ostringstream ost3;
121  ost3 <<depth;
122  attrdepth->setValue(XMLString::transcode(ost3.str().c_str()));
123  //DOMAttr* attr5 = detelem->setAttributeNode(attrdepth);
124  detelem->setAttributeNode(attrdepth);
125 
126  ostringstream ost4;
127  ost4 << scale;
128  attrscale->setValue(XMLString::transcode(ost4.str().c_str()));
129  //DOMAttr* attr6 = detelem->setAttributeNode(attrscale);
130  detelem->setAttributeNode(attrscale);
131 
132 }
133 
134 
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 > &)