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