Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include <iostream>
0002 #include <sstream>
0003 #include <fstream>
0004 #include <xercesc/dom/DOMNode.hpp>
0005 #include <xercesc/dom/DOM.hpp>
0006 #include <xercesc/parsers/XercesDOMParser.hpp>
0007 #include "Utilities/Xerces/interface/Xerces.h"
0008 #include "Utilities/Xerces/interface/XercesStrUtils.h"
0009 #include <xercesc/util/XMLString.hpp>
0010 #include <xercesc/sax/SAXException.hpp>
0011 #include <xercesc/framework/LocalFileFormatTarget.hpp>
0012 
0013 #include "DataFormats/DetId/interface/DetId.h"
0014 #include "DataFormats/EcalDetId/interface/EcalSubdetector.h"
0015 
0016 #include "CondTools/Ecal/interface/EcalTPGStripStatusXMLTranslator.h"
0017 #include "CondTools/Ecal/interface/DOMHelperFunctions.h"
0018 #include "CondTools/Ecal/interface/XMLTags.h"
0019 
0020 #include "CondFormats/DataRecord/interface/EcalTPGStripStatusRcd.h"
0021 
0022 using namespace XERCES_CPP_NAMESPACE;
0023 using namespace xuti;
0024 using namespace std;
0025 
0026 int EcalTPGStripStatusXMLTranslator::readXML(const std::string& filename,
0027                                              EcalCondHeader& header,
0028                                              EcalTPGStripStatus& record) {
0029   std::cout << " TPGStripStatus should not be filled out from an xml file ..." << std::endl;
0030   cms::concurrency::xercesInitialize();
0031 
0032   XercesDOMParser* parser = new XercesDOMParser;
0033   parser->setValidationScheme(XercesDOMParser::Val_Never);
0034   parser->setDoNamespaces(false);
0035   parser->setDoSchema(false);
0036 
0037   parser->parse(filename.c_str());
0038 
0039   DOMDocument* xmlDoc = parser->getDocument();
0040   if (!xmlDoc) {
0041     std::cout << "EcalTPGStripStatusXMLTranslator::Error parsing document" << std::endl;
0042     return -1;
0043   }
0044 
0045   DOMElement* elementRoot = xmlDoc->getDocumentElement();
0046 
0047   xuti::readHeader(elementRoot, header);
0048 
0049   delete parser;
0050   cms::concurrency::xercesTerminate();
0051   return 0;
0052 }
0053 
0054 int EcalTPGStripStatusXMLTranslator::writeXML(const std::string& filename,
0055                                               const EcalCondHeader& header,
0056                                               const EcalTPGStripStatus& record) {
0057   cms::concurrency::xercesInitialize();
0058 
0059   std::fstream fs(filename.c_str(), ios::out);
0060   fs << dumpXML(header, record);
0061 
0062   cms::concurrency::xercesTerminate();
0063 
0064   return 0;
0065 }
0066 
0067 std::string EcalTPGStripStatusXMLTranslator::dumpXML(const EcalCondHeader& header, const EcalTPGStripStatus& record) {
0068   unique_ptr<DOMImplementation> impl(DOMImplementationRegistry::getDOMImplementation(cms::xerces::uStr("LS").ptr()));
0069 
0070   DOMLSSerializer* writer = impl->createLSSerializer();
0071   if (writer->getDomConfig()->canSetParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true))
0072     writer->getDomConfig()->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true);
0073 
0074   DOMDocumentType* doctype = impl->createDocumentType(cms::xerces::uStr("XML").ptr(), nullptr, nullptr);
0075   DOMDocument* doc = impl->createDocument(nullptr, cms::xerces::uStr(TPGStripStatus_tag.c_str()).ptr(), doctype);
0076   DOMElement* root = doc->getDocumentElement();
0077 
0078   xuti::writeHeader(root, header);
0079   std::string TCC_tag("TCC");
0080   std::string TT_tag("TT");
0081   std::string ST_tag("ST");
0082   const EcalTPGStripStatusMap& stripMap = record.getMap();
0083   std::cout << "EcalTPGStripStatusXMLTranslator::dumpXML strip map size " << stripMap.size() << std::endl;
0084   EcalTPGStripStatusMapIterator itSt;
0085   for (itSt = stripMap.begin(); itSt != stripMap.end(); ++itSt) {
0086     if (itSt->second > 0) {
0087       int tccid = itSt->first / 8192 & 0x7F;
0088       int tt = itSt->first / 64 & 0x7F;
0089       int pseudostrip = itSt->first / 8 & 0x7;
0090       //      std::cout << "Bad strip ID = " << itSt->first
0091       //        << " TCC " << tccid << " TT " << tt << " ST " << pseudostrip
0092       //        << ", status = " << itSt->second << std::endl;
0093       DOMElement* cell_node = root->getOwnerDocument()->createElement(cms::xerces::uStr(Cell_tag.c_str()).ptr());
0094       stringstream value_s;
0095       value_s << tccid;
0096       cell_node->setAttribute(cms::xerces::uStr(TCC_tag.c_str()).ptr(), cms::xerces::uStr(value_s.str().c_str()).ptr());
0097       value_s.str("");
0098       value_s << tt;
0099       cell_node->setAttribute(cms::xerces::uStr(TT_tag.c_str()).ptr(), cms::xerces::uStr(value_s.str().c_str()).ptr());
0100       value_s.str("");
0101       value_s << pseudostrip;
0102       cell_node->setAttribute(cms::xerces::uStr(ST_tag.c_str()).ptr(), cms::xerces::uStr(value_s.str().c_str()).ptr());
0103       root->appendChild(cell_node);
0104 
0105       WriteNodeWithValue(cell_node, TPGStripStatus_tag, 1);
0106     }
0107   }
0108 
0109   std::string dump = cms::xerces::toString(writer->writeToString(root));
0110   doc->release();
0111   doctype->release();
0112   writer->release();
0113   return dump;
0114 }