Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:51:56

0001 #include "CondTools/Ecal/interface/EcalAlignmentXMLTranslator.h"
0002 #include "CondTools/Ecal/interface/DOMHelperFunctions.h"
0003 #include "CondFormats/Alignment/interface/Alignments.h"
0004 #include "Utilities/Xerces/interface/Xerces.h"
0005 #include "Utilities/Xerces/interface/XercesStrUtils.h"
0006 #include <xercesc/dom/DOMNode.hpp>
0007 #include <xercesc/dom/DOM.hpp>
0008 #include <xercesc/parsers/XercesDOMParser.hpp>
0009 #include <xercesc/util/XMLString.hpp>
0010 #include <xercesc/sax/SAXException.hpp>
0011 #include <xercesc/framework/LocalFileFormatTarget.hpp>
0012 #include <iostream>
0013 #include <sstream>
0014 #include <fstream>
0015 
0016 using namespace XERCES_CPP_NAMESPACE;
0017 using namespace xuti;
0018 using namespace std;
0019 
0020 int EcalAlignmentXMLTranslator::writeXML(const string& filename,
0021                                          const EcalCondHeader& header,
0022                                          const Alignments& record) {
0023   cms::concurrency::xercesInitialize();
0024 
0025   fstream fs(filename.c_str(), ios::out);
0026   fs << dumpXML(header, record);
0027 
0028   cms::concurrency::xercesTerminate();
0029 
0030   return 0;
0031 }
0032 
0033 string EcalAlignmentXMLTranslator::dumpXML(const EcalCondHeader& header, const Alignments& record) {
0034   unique_ptr<DOMImplementation> impl(DOMImplementationRegistry::getDOMImplementation(cms::xerces::uStr("LS").ptr()));
0035 
0036   DOMLSSerializer* writer = impl->createLSSerializer();
0037   if (writer->getDomConfig()->canSetParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true))
0038     writer->getDomConfig()->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true);
0039 
0040   DOMDocumentType* doctype = impl->createDocumentType(cms::xerces::uStr("XML").ptr(), nullptr, nullptr);
0041   DOMDocument* doc = impl->createDocument(nullptr, cms::xerces::uStr(AlignmentConstant_tag.c_str()).ptr(), doctype);
0042   DOMElement* root = doc->getDocumentElement();
0043 
0044   xuti::writeHeader(root, header);
0045 
0046   for (vector<AlignTransform>::const_iterator it = record.m_align.begin(); it != record.m_align.end(); it++) {
0047     int Id = (*it).rawId();
0048     int sub = (Id >> 24) & 0xF;
0049     stringstream subdet;
0050     if (sub == 2) {
0051       subdet << "EB";
0052       int SM;
0053       int phi = Id & 0x1FF;
0054       //    int eta = (Id>>9)&0x3F;
0055       int side = (Id >> 16) & 1;
0056       if (side == 0) {
0057         subdet << "-";
0058         SM = (phi + 19) / 20;
0059       } else {
0060         subdet << "+";
0061         SM = phi / 20;
0062       }
0063       if (SM < 10)
0064         subdet << "0" << SM;
0065       else
0066         subdet << SM;
0067     } else if (sub == 4) {
0068       subdet << "EE";
0069       //      int y = Id&0x7F;
0070       int x = (Id >> 7) & 0x7F;
0071       //      int Dee = x/70 + 1;
0072       int side = (Id >> 14) & 1;
0073       if (side == 0) {
0074         subdet << "-";
0075       } else {
0076         subdet << "+";
0077       }
0078       //      subdet << "0" << Dee;
0079       if (x == 20)
0080         subdet << "F";
0081       else if (x == 70)
0082         subdet << "N";
0083       else
0084         cout << " strange value for x " << x << endl;  // should never occur
0085     } else if (sub == 6) {
0086       subdet << "ES";
0087       //      int strip = Id&0x3F;
0088       int x = (Id >> 6) & 0x3F;
0089       //      int y = (Id>>12)&0x3F;
0090       int plane = (Id >> 18) & 1;
0091       int side = (Id >> 19) & 1;
0092       if (side == 0)
0093         subdet << "-";
0094       else
0095         subdet << "+";
0096       if (plane)
0097         subdet << "F";
0098       else
0099         subdet << "R";
0100       if (x / 30)
0101         subdet << "F";
0102       else
0103         subdet << "N";
0104     } else
0105       cout << " problem sub = " << sub << endl;
0106     cout << (*it).rawId() << " " << (*it).rotation().getPhi() << " " << (*it).rotation().getTheta() << " "
0107          << (*it).rotation().getPsi() << " " << (*it).translation().x() << " " << (*it).translation().y() << " "
0108          << (*it).translation().z() << endl;
0109     uint32_t rawid = (*it).rawId();
0110     DOMElement* cellnode = root->getOwnerDocument()->createElement(cms::xerces::uStr(Cell_tag.c_str()).ptr());
0111     root->appendChild(cellnode);
0112     cellnode->setAttribute(cms::xerces::uStr(subdet_tag.c_str()).ptr(), cms::xerces::uStr(subdet.str().c_str()).ptr());
0113     xuti::WriteNodeWithValue(cellnode, id_tag, rawid);
0114     xuti::WriteNodeWithValue(cellnode, x_tag, (*it).translation().x());
0115     xuti::WriteNodeWithValue(cellnode, y_tag, (*it).translation().y());
0116     xuti::WriteNodeWithValue(cellnode, z_tag, (*it).translation().z());
0117     xuti::WriteNodeWithValue(cellnode, Phi_tag, (*it).rotation().getPhi());
0118     xuti::WriteNodeWithValue(cellnode, Theta_tag, (*it).rotation().getTheta());
0119     xuti::WriteNodeWithValue(cellnode, Psi_tag, (*it).rotation().getPsi());
0120   }
0121 
0122   std::string dump = cms::xerces::toString(writer->writeToString(root));
0123   doc->release();
0124   doctype->release();
0125   writer->release();
0126 
0127   return dump;
0128 }