Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-09 03:14:47

0001 #include "Calibration/HcalCalibAlgos/interface/HcalConstantsXMLWriter.h"
0002 
0003 // Write the new XML object: needed includes
0004 
0005 // Xerces-C
0006 #include <xercesc/dom/DOMNode.hpp>
0007 #include <xercesc/dom/DOM.hpp>
0008 #include <xercesc/dom/DOMCharacterData.hpp>
0009 #include <xercesc/parsers/XercesDOMParser.hpp>
0010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0011 #include "Utilities/Xerces/interface/Xerces.h"
0012 #include <xercesc/framework/LocalFileFormatTarget.hpp>
0013 #include <xercesc/util/XMLUni.hpp>
0014 #include <xercesc/util/XMLURL.hpp>
0015 
0016 #include "CondTools/Hcal/interface/StreamOutFormatTarget.h"
0017 #include <sstream>
0018 #include <string>
0019 
0020 using namespace xercesc;
0021 
0022 HcalConstantsXMLWriter::HcalConstantsXMLWriter() {}
0023 HcalConstantsXMLWriter::~HcalConstantsXMLWriter() {}
0024 void HcalConstantsXMLWriter::writeXML(std::string& newfile0,
0025                                       const std::vector<int>& detvec,
0026                                       const std::vector<int>& etavec,
0027                                       const std::vector<int>& phivec,
0028                                       const std::vector<int>& depthvec,
0029                                       const std::vector<float>& scalevec) {
0030   int nn = newfile0.size();
0031   char newfile[99];
0032   for (int i = 0; i < nn; i++) {
0033     newfile[i] = newfile0[i];
0034   }
0035   char const* fend = "\0";
0036   newfile[nn] = *fend;
0037 
0038   edm::LogVerbatim("HcalCalib") << " New file " << newfile << std::endl;
0039 
0040   std::filebuf fb;
0041   fb.open(newfile, std::ios::out);
0042   std::ostream fOut(&fb);
0043 
0044   XMLCh tempStr[100];
0045 
0046   XMLString::transcode("Core", tempStr, 99);
0047   std::unique_ptr<DOMImplementation> mDom(DOMImplementationRegistry::getDOMImplementation(tempStr));
0048 
0049   XMLString::transcode("CalibrationConstants", tempStr, 99);
0050   mDoc = mDom->createDocument(nullptr,   // root element namespace URI.
0051                               tempStr,   // root element name
0052                               nullptr);  // document type object (DTD).
0053 
0054   StreamOutFormatTarget formTarget(fOut);
0055   DOMLSSerializer* domWriter = mDom->createLSSerializer();
0056   domWriter->getDomConfig()->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true);
0057   DOMElement* root = mDoc->getDocumentElement();
0058 
0059   XMLString::transcode("Hcal", tempStr, 99);
0060   DOMElement* rootelem = mDoc->createElement(tempStr);
0061   root->appendChild(rootelem);
0062 
0063   XMLString::transcode("Cell", tempStr, 99);
0064   std::vector<DOMElement*> theDOMVec;
0065 
0066   for (unsigned int i = 0; i < detvec.size(); i++) {
0067     theDOMVec.push_back(mDoc->createElement(tempStr));
0068     newCellLine(theDOMVec[i], detvec[i], etavec[i], phivec[i], depthvec[i], scalevec[i]);
0069     rootelem->appendChild(theDOMVec[i]);
0070   }
0071 
0072   edm::LogVerbatim("HcalCalib") << " Write Doc " << theDOMVec.size();
0073   DOMLSOutput* output = mDom->createLSOutput();
0074   output->setByteStream(&formTarget);
0075   domWriter->write(mDoc, output);
0076   edm::LogVerbatim("HcalCalib") << " End of Writting ";
0077   mDoc->release();
0078   output->release();
0079   domWriter->release();
0080 }
0081 
0082 void HcalConstantsXMLWriter::newCellLine(DOMElement* detelem, int det, int eta, int phi, int depth, float scale) {
0083   XMLCh tempStr[100];
0084   XMLString::transcode("det_index", tempStr, 99);
0085   DOMAttr* attrdet = mDoc->createAttribute(tempStr);
0086 
0087   XMLString::transcode("eta_index", tempStr, 99);
0088   DOMAttr* attreta = mDoc->createAttribute(tempStr);
0089 
0090   XMLString::transcode("phi_index", tempStr, 99);
0091   DOMAttr* attrphi = mDoc->createAttribute(tempStr);
0092 
0093   XMLString::transcode("depth_index", tempStr, 99);
0094   DOMAttr* attrdepth = mDoc->createAttribute(tempStr);
0095 
0096   XMLString::transcode("scale_factor", tempStr, 99);
0097   DOMAttr* attrscale = mDoc->createAttribute(tempStr);
0098 
0099   std::ostringstream ost;
0100   ost << det;
0101   attrdet->setValue(XMLString::transcode(ost.str().c_str()));
0102   detelem->setAttributeNode(attrdet);
0103 
0104   std::ostringstream ost1;
0105   ost1 << eta;
0106   attreta->setValue(XMLString::transcode(ost1.str().c_str()));
0107   //DOMAttr* attr3 = detelem->setAttributeNode(attreta);
0108   detelem->setAttributeNode(attreta);
0109 
0110   std::ostringstream ost2;
0111   ost2 << phi;
0112   attrphi->setValue(XMLString::transcode(ost2.str().c_str()));
0113   //DOMAttr* attr4 = detelem->setAttributeNode(attrphi);
0114   detelem->setAttributeNode(attrphi);
0115 
0116   std::ostringstream ost3;
0117   ost3 << depth;
0118   attrdepth->setValue(XMLString::transcode(ost3.str().c_str()));
0119   //DOMAttr* attr5 = detelem->setAttributeNode(attrdepth);
0120   detelem->setAttributeNode(attrdepth);
0121 
0122   std::ostringstream ost4;
0123   ost4 << scale;
0124   attrscale->setValue(XMLString::transcode(ost4.str().c_str()));
0125   //DOMAttr* attr6 = detelem->setAttributeNode(attrscale);
0126   detelem->setAttributeNode(attrscale);
0127 }