Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:52:03

0001 #include <iostream>
0002 #include <sstream>
0003 #include <fstream>
0004 
0005 #include "CondFormats/EcalObjects/interface/EcalTPGLinearizationConst.h"
0006 #include "CondTools/Ecal/interface/EcalTPGLinearizationConstXMLTranslator.h"
0007 
0008 #include "CondTools/Ecal/interface/DOMHelperFunctions.h"
0009 #include "CondTools/Ecal/interface/XMLTags.h"
0010 #include "Utilities/Xerces/interface/Xerces.h"
0011 #include "Utilities/Xerces/interface/XercesStrUtils.h"
0012 
0013 using namespace XERCES_CPP_NAMESPACE;
0014 using namespace xuti;
0015 using namespace std;
0016 
0017 int EcalTPGLinearizationConstXMLTranslator::writeXML(const std::string& filename,
0018                                                      const EcalCondHeader& header,
0019                                                      const EcalTPGLinearizationConst& record) {
0020   cms::concurrency::xercesInitialize();
0021 
0022   std::fstream fs(filename.c_str(), ios::out);
0023   fs << dumpXML(header, record);
0024 
0025   cms::concurrency::xercesTerminate();
0026 
0027   return 0;
0028 }
0029 
0030 std::string EcalTPGLinearizationConstXMLTranslator::dumpXML(const EcalCondHeader& header,
0031                                                             const EcalTPGLinearizationConst& record) {
0032   unique_ptr<DOMImplementation> impl(DOMImplementationRegistry::getDOMImplementation(cms::xerces::uStr("LS").ptr()));
0033 
0034   DOMLSSerializer* writer = impl->createLSSerializer();
0035   if (writer->getDomConfig()->canSetParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true))
0036     writer->getDomConfig()->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true);
0037 
0038   DOMDocumentType* doctype = impl->createDocumentType(cms::xerces::uStr("XML").ptr(), nullptr, nullptr);
0039   DOMDocument* doc = impl->createDocument(nullptr, cms::xerces::uStr(Linearization_tag.c_str()).ptr(), doctype);
0040   DOMElement* root = doc->getDocumentElement();
0041 
0042   xuti::writeHeader(root, header);
0043 
0044   // open also a flat text file
0045   std::ofstream fout;
0046   fout.open("Linearization.txt");
0047 
0048   for (int cellid = EBDetId::MIN_HASH; cellid < EBDetId::kSizeForDenseIndexing; ++cellid) {
0049     uint32_t rawid = EBDetId::unhashIndex(cellid);
0050 
0051     DOMElement* cellnode = writeCell(root, rawid);
0052 
0053     float m12 = (record)[rawid].mult_x12;
0054     float s12 = (record)[rawid].shift_x12;
0055     float m6 = (record)[rawid].mult_x6;
0056     float s6 = (record)[rawid].shift_x6;
0057     float m1 = (record)[rawid].mult_x1;
0058     float s1 = (record)[rawid].shift_x1;
0059 
0060     WriteNodeWithValue(cellnode, Linearization_m12_tag, m12);
0061     WriteNodeWithValue(cellnode, Linearization_m6_tag, m6);
0062     WriteNodeWithValue(cellnode, Linearization_m1_tag, m1);
0063     WriteNodeWithValue(cellnode, Linearization_s12_tag, s12);
0064     WriteNodeWithValue(cellnode, Linearization_s6_tag, s6);
0065     WriteNodeWithValue(cellnode, Linearization_s1_tag, s1);
0066     fout << rawid << " " << m12 << " " << m6 << " " << m1 << " " << s12 << " " << s6 << " " << s1 << "\n";
0067   }
0068 
0069   for (int cellid = 0; cellid < EEDetId::kSizeForDenseIndexing; ++cellid) {
0070     if (!EEDetId::validHashIndex(cellid))
0071       continue;
0072 
0073     uint32_t rawid = EEDetId::unhashIndex(cellid);
0074 
0075     DOMElement* cellnode = writeCell(root, rawid);
0076 
0077     float m12 = (record)[rawid].mult_x12;
0078     float s12 = (record)[rawid].shift_x12;
0079     float m6 = (record)[rawid].mult_x6;
0080     float s6 = (record)[rawid].shift_x6;
0081     float m1 = (record)[rawid].mult_x1;
0082     float s1 = (record)[rawid].shift_x1;
0083 
0084     WriteNodeWithValue(cellnode, Linearization_m12_tag, m12);
0085     WriteNodeWithValue(cellnode, Linearization_m6_tag, m6);
0086     WriteNodeWithValue(cellnode, Linearization_m1_tag, m1);
0087     WriteNodeWithValue(cellnode, Linearization_s12_tag, s12);
0088     WriteNodeWithValue(cellnode, Linearization_s6_tag, s6);
0089     WriteNodeWithValue(cellnode, Linearization_s1_tag, s1);
0090     fout << rawid << " " << m12 << " " << m6 << " " << m1 << " " << s12 << " " << s6 << " " << s1 << "\n";
0091   }
0092   fout.close();
0093   std::string dump = cms::xerces::toString(writer->writeToString(root));
0094   doc->release();
0095   doctype->release();
0096   writer->release();
0097 
0098   return dump;
0099 }