CMS 3D CMS Logo

EcalAlignmentXMLTranslator.cc
Go to the documentation of this file.
6 #include <xercesc/dom/DOMNode.hpp>
7 #include <xercesc/dom/DOM.hpp>
8 #include <xercesc/parsers/XercesDOMParser.hpp>
9 #include <xercesc/util/XMLString.hpp>
10 #include <xercesc/sax/SAXException.hpp>
11 #include <xercesc/framework/LocalFileFormatTarget.hpp>
12 #include <iostream>
13 #include <sstream>
14 #include <fstream>
15 
16 using namespace XERCES_CPP_NAMESPACE;
17 using namespace xuti;
18 using namespace std;
19 
21  const EcalCondHeader& header,
22  const Alignments& record) {
24 
25  fstream fs(filename.c_str(), ios::out);
26  fs << dumpXML(header, record);
27 
29 
30  return 0;
31 }
32 
34  unique_ptr<DOMImplementation> impl(DOMImplementationRegistry::getDOMImplementation(cms::xerces::uStr("LS").ptr()));
35 
36  DOMLSSerializer* writer = impl->createLSSerializer();
37  if (writer->getDomConfig()->canSetParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true))
38  writer->getDomConfig()->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true);
39 
40  DOMDocumentType* doctype = impl->createDocumentType(cms::xerces::uStr("XML").ptr(), nullptr, nullptr);
41  DOMDocument* doc = impl->createDocument(nullptr, cms::xerces::uStr(AlignmentConstant_tag.c_str()).ptr(), doctype);
42  DOMElement* root = doc->getDocumentElement();
43 
44  xuti::writeHeader(root, header);
45 
46  for (vector<AlignTransform>::const_iterator it = record.m_align.begin(); it != record.m_align.end(); it++) {
47  int Id = (*it).rawId();
48  int sub = (Id >> 24) & 0xF;
49  stringstream subdet;
50  if (sub == 2) {
51  subdet << "EB";
52  int SM;
53  int phi = Id & 0x1FF;
54  // int eta = (Id>>9)&0x3F;
55  int side = (Id >> 16) & 1;
56  if (side == 0) {
57  subdet << "-";
58  SM = (phi + 19) / 20;
59  } else {
60  subdet << "+";
61  SM = phi / 20;
62  }
63  if (SM < 10)
64  subdet << "0" << SM;
65  else
66  subdet << SM;
67  } else if (sub == 4) {
68  subdet << "EE";
69  // int y = Id&0x7F;
70  int x = (Id >> 7) & 0x7F;
71  // int Dee = x/70 + 1;
72  int side = (Id >> 14) & 1;
73  if (side == 0) {
74  subdet << "-";
75  } else {
76  subdet << "+";
77  }
78  // subdet << "0" << Dee;
79  if (x == 20)
80  subdet << "F";
81  else if (x == 70)
82  subdet << "N";
83  else
84  cout << " strange value for x " << x << endl; // should never occur
85  } else if (sub == 6) {
86  subdet << "ES";
87  // int strip = Id&0x3F;
88  int x = (Id >> 6) & 0x3F;
89  // int y = (Id>>12)&0x3F;
90  int plane = (Id >> 18) & 1;
91  int side = (Id >> 19) & 1;
92  if (side == 0)
93  subdet << "-";
94  else
95  subdet << "+";
96  if (plane)
97  subdet << "F";
98  else
99  subdet << "R";
100  if (x / 30)
101  subdet << "F";
102  else
103  subdet << "N";
104  } else
105  cout << " problem sub = " << sub << endl;
106  cout << (*it).rawId() << " " << (*it).rotation().getPhi() << " " << (*it).rotation().getTheta() << " "
107  << (*it).rotation().getPsi() << " " << (*it).translation().x() << " " << (*it).translation().y() << " "
108  << (*it).translation().z() << endl;
109  uint32_t rawid = (*it).rawId();
110  DOMElement* cellnode = root->getOwnerDocument()->createElement(cms::xerces::uStr(Cell_tag.c_str()).ptr());
111  root->appendChild(cellnode);
112  cellnode->setAttribute(cms::xerces::uStr(subdet_tag.c_str()).ptr(), cms::xerces::uStr(subdet.str().c_str()).ptr());
113  xuti::WriteNodeWithValue(cellnode, id_tag, rawid);
114  xuti::WriteNodeWithValue(cellnode, x_tag, (*it).translation().x());
115  xuti::WriteNodeWithValue(cellnode, y_tag, (*it).translation().y());
116  xuti::WriteNodeWithValue(cellnode, z_tag, (*it).translation().z());
117  xuti::WriteNodeWithValue(cellnode, Phi_tag, (*it).rotation().getPhi());
118  xuti::WriteNodeWithValue(cellnode, Theta_tag, (*it).rotation().getTheta());
119  xuti::WriteNodeWithValue(cellnode, Psi_tag, (*it).rotation().getPsi());
120  }
121 
122  std::string dump = cms::xerces::toString(writer->writeToString(root));
123  doc->release();
124  doctype->release();
125  writer->release();
126 
127  return dump;
128 }
def dumpXML(db, tag, since, filename='dump.xml')
JetCorrectorParameters::Record record
Definition: classes.h:7
void xercesTerminate()
Definition: Xerces.cc:23
const std::string Phi_tag("Phi")
const std::string x_tag("x")
const std::string id_tag("id")
void xercesInitialize()
Definition: Xerces.cc:18
std::vector< AlignTransform > m_align
Definition: Alignments.h:19
void WriteNodeWithValue(xercesc::DOMNode *parentNode, const std::string &tag, const T &value)
write a node with
static std::string dumpXML(const EcalCondHeader &header, const Alignments &record)
std::string toString(XMLCh const *toTranscode)
static int writeXML(const std::string &filename, const EcalCondHeader &header, const Alignments &record)
const std::string y_tag("y")
const std::string Cell_tag("cell")
const std::string subdet_tag("SubDet")
void writeHeader(xercesc::DOMNode *parentNode, const EcalCondHeader &header)
write
ZStr< XMLCh > uStr(char const *str)
const std::string z_tag("z")
const std::string Psi_tag("Psi")
const std::string Theta_tag("Theta")
const std::string AlignmentConstant_tag("EcalAlignmentConstant")