CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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>
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  mDom = DOMImplementationRegistry::getDOMImplementation (tempStr);
49 
50  XMLString::transcode("CalibrationConstants", tempStr, 99);
51  mDoc = mDom->createDocument(
52  0, // root element namespace URI.
53  tempStr, // root element name
54  0); // document type object (DTD).
55 
56  StreamOutFormatTarget formTarget (fOut);
57  DOMWriter* domWriter = mDom->createDOMWriter();
58  domWriter->setFeature(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  domWriter->writeNode (&formTarget, *mDoc);
77  cout<<" End of Writting "<<endl;
78  mDoc->release ();
79 }
80 
81 void HcalConstantsXMLWriter::newCellLine(DOMElement* detelem, int det, int eta, int phi, int depth, float scale)
82 {
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  ostringstream ost;
100  ost <<det;
101  attrdet->setValue(XMLString::transcode(ost.str().c_str()));
102  detelem->setAttributeNode(attrdet);
103 
104  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  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  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  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 
128 }
129 
130 
int i
Definition: DBlmapReader.cc:9
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:48
XMLCh * transcode(const T &fInput)
tuple out
Definition: dbtoconf.py:99
tuple cout
Definition: gather_cfg.py:121
string root
initialization
Definition: dbtoconf.py:70