Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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/EcalTPGCrystalStatusXMLTranslator.h"
0017 #include "CondTools/Ecal/interface/DOMHelperFunctions.h"
0018 #include "CondTools/Ecal/interface/XMLTags.h"
0019 
0020 #include "CondFormats/DataRecord/interface/EcalTPGCrystalStatusRcd.h"
0021 #include "CondFormats/EcalObjects/interface/EcalTPGCrystalStatus.h"
0022 
0023 using namespace XERCES_CPP_NAMESPACE;
0024 using namespace xuti;
0025 using namespace std;
0026 
0027 int EcalTPGCrystalStatusXMLTranslator::writeXML(const std::string& filename,
0028                                                 const EcalCondHeader& header,
0029                                                 const EcalTPGCrystalStatus& record) {
0030   cms::concurrency::xercesInitialize();
0031 
0032   std::fstream fs(filename.c_str(), ios::out);
0033   fs << dumpXML(header, record);
0034 
0035   cms::concurrency::xercesTerminate();
0036 
0037   return 0;
0038 }
0039 
0040 std::string EcalTPGCrystalStatusXMLTranslator::dumpXML(const EcalCondHeader& header,
0041                                                        const EcalTPGCrystalStatus& record) {
0042   unique_ptr<DOMImplementation> impl(DOMImplementationRegistry::getDOMImplementation(cms::xerces::uStr("LS").ptr()));
0043 
0044   DOMLSSerializer* writer = impl->createLSSerializer();
0045   if (writer->getDomConfig()->canSetParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true))
0046     writer->getDomConfig()->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true);
0047   DOMDocumentType* doctype = impl->createDocumentType(cms::xerces::uStr("XML").ptr(), nullptr, nullptr);
0048   DOMDocument* doc = impl->createDocument(nullptr, cms::xerces::uStr(TPGCrystalStatus_tag.c_str()).ptr(), doctype);
0049 
0050   DOMElement* root = doc->getDocumentElement();
0051 
0052   xuti::writeHeader(root, header);
0053 
0054   const int kSides = 2;
0055   const int kBarlRings = EBDetId::MAX_IETA;
0056   const int kBarlWedges = EBDetId::MAX_IPHI;
0057   const int kEndcWedgesX = EEDetId::IX_MAX;
0058   const int kEndcWedgesY = EEDetId::IY_MAX;
0059 
0060   std::cout << "EcalTPGCrystalStatusXMLTranslator::dumpXML" << std::endl;
0061   for (int sign = 0; sign < kSides; sign++) {
0062     int thesign = sign == 1 ? 1 : -1;
0063 
0064     for (int ieta = 0; ieta < kBarlRings; ieta++) {
0065       for (int iphi = 0; iphi < kBarlWedges; iphi++) {
0066         EBDetId id((ieta + 1) * thesign, iphi + 1);
0067         if (record[id.rawId()].getStatusCode() > 0) {
0068           DOMElement* cellnode = writeCell(root, id);
0069           WriteNodeWithValue(cellnode, TPGCrystalStatus_tag, record[id.rawId()].getStatusCode());
0070         }
0071       }  // iphi
0072     }    // ieta
0073 
0074     for (int ix = 0; ix < kEndcWedgesX; ix++) {
0075       for (int iy = 0; iy < kEndcWedgesY; iy++) {
0076         if (!EEDetId::validDetId(ix + 1, iy + 1, thesign))
0077           continue;
0078         EEDetId id(ix + 1, iy + 1, thesign);
0079         if (record[id.rawId()].getStatusCode() > 0) {
0080           DOMElement* cellnode = writeCell(root, id);
0081           WriteNodeWithValue(cellnode, TPGCrystalStatus_tag, record[id.rawId()].getStatusCode());
0082         }
0083       }  // iy
0084     }    // ix
0085   }      // side
0086 
0087   std::string dump = cms::xerces::toString(writer->writeToString(root));
0088   doc->release();
0089   doctype->release();
0090   writer->release();
0091 
0092   return dump;
0093 }