Go to the documentation of this file.00001 #include "Calibration/HcalCalibAlgos/interface/HcalConstantsXMLWriter.h"
00002
00003
00004
00005
00006 #include <xercesc/dom/DOMNode.hpp>
00007 #include <xercesc/dom/DOM.hpp>
00008 #include <xercesc/dom/DOMCharacterData.hpp>
00009 #include <xercesc/parsers/XercesDOMParser.hpp>
00010 #include <xercesc/util/PlatformUtils.hpp>
00011 #include <xercesc/framework/LocalFileFormatTarget.hpp>
00012 #include <xercesc/util/XMLUni.hpp>
00013 #include <xercesc/util/XMLURL.hpp>
00014
00015
00016 #include "CondTools/Hcal/interface/StreamOutFormatTarget.h"
00017 #include <sstream>
00018 #include <string>
00019 using namespace std;
00020 using namespace xercesc;
00021
00022 HcalConstantsXMLWriter::HcalConstantsXMLWriter()
00023 {
00024 }
00025 HcalConstantsXMLWriter::~HcalConstantsXMLWriter()
00026 {
00027 }
00028 void HcalConstantsXMLWriter::writeXML(string& newfile0, vector<int> detvec,vector<int> etavec,vector<int> phivec, vector<int> depthvec,vector<float> scalevec)
00029 {
00030 int nn = newfile0.size();
00031 char newfile[99];
00032 for (int i = 0; i < nn; i++)
00033 {
00034 newfile[i]=newfile0[i];
00035 }
00036 char const* fend="\0";
00037 newfile[nn] = *fend;
00038
00039 cout<<" New file "<<newfile<<endl;
00040
00041 filebuf fb;
00042 fb.open (newfile,ios::out);
00043 ostream fOut(&fb);
00044
00045 XMLCh tempStr[100];
00046
00047 XMLString::transcode ("Core",tempStr,99);
00048 mDom = DOMImplementationRegistry::getDOMImplementation (tempStr);
00049
00050 XMLString::transcode("CalibrationConstants", tempStr, 99);
00051 mDoc = mDom->createDocument(
00052 0,
00053 tempStr,
00054 0);
00055
00056 StreamOutFormatTarget formTarget (fOut);
00057 DOMWriter* domWriter = mDom->createDOMWriter();
00058 domWriter->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true);
00059 DOMElement* root = mDoc->getDocumentElement();
00060
00061 XMLString::transcode("Hcal", tempStr, 99);
00062 DOMElement* rootelem = mDoc->createElement (tempStr);
00063 root->appendChild(rootelem);
00064
00065 XMLString::transcode("Cell", tempStr, 99);
00066 vector<DOMElement*> theDOMVec;
00067
00068 for(unsigned int i=0; i<detvec.size();i++)
00069 {
00070 theDOMVec.push_back(mDoc->createElement (tempStr));
00071 newCellLine(theDOMVec[i],detvec[i],etavec[i],phivec[i],depthvec[i],scalevec[i]);
00072 rootelem->appendChild(theDOMVec[i]);
00073 }
00074
00075 cout<<" Write Doc "<<theDOMVec.size()<<endl;
00076 domWriter->writeNode (&formTarget, *mDoc);
00077 cout<<" End of Writting "<<endl;
00078 mDoc->release ();
00079 }
00080
00081 void HcalConstantsXMLWriter::newCellLine(DOMElement* detelem, int det, int eta, int phi, int depth, float scale)
00082 {
00083 XMLCh tempStr[100];
00084 XMLString::transcode("det_index", tempStr, 99);
00085 DOMAttr* attrdet = mDoc->createAttribute(tempStr);
00086
00087 XMLString::transcode("eta_index", tempStr, 99);
00088 DOMAttr* attreta = mDoc->createAttribute(tempStr);
00089
00090 XMLString::transcode("phi_index", tempStr, 99);
00091 DOMAttr* attrphi = mDoc->createAttribute(tempStr) ;
00092
00093 XMLString::transcode("depth_index", tempStr, 99);
00094 DOMAttr* attrdepth = mDoc->createAttribute(tempStr) ;
00095
00096 XMLString::transcode("scale_factor", tempStr, 99);
00097 DOMAttr* attrscale = mDoc->createAttribute(tempStr) ;
00098
00099 ostringstream ost;
00100 ost <<det;
00101 attrdet->setValue(XMLString::transcode(ost.str().c_str()));
00102 detelem->setAttributeNode(attrdet);
00103
00104 ostringstream ost1;
00105 ost1 <<eta;
00106 attreta->setValue(XMLString::transcode(ost1.str().c_str()));
00107
00108 detelem->setAttributeNode(attreta);
00109
00110 ostringstream ost2;
00111 ost2 <<phi;
00112 attrphi->setValue(XMLString::transcode(ost2.str().c_str()));
00113
00114 detelem->setAttributeNode(attrphi);
00115
00116 ostringstream ost3;
00117 ost3 <<depth;
00118 attrdepth->setValue(XMLString::transcode(ost3.str().c_str()));
00119
00120 detelem->setAttributeNode(attrdepth);
00121
00122 ostringstream ost4;
00123 ost4 << scale;
00124 attrscale->setValue(XMLString::transcode(ost4.str().c_str()));
00125
00126 detelem->setAttributeNode(attrscale);
00127
00128 }
00129
00130