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 
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 }
XercesStrUtils.h
submitPVValidationJobs.dump
dump
Definition: submitPVValidationJobs.py:55
EcalCondTools.dumpXML
def dumpXML(db, tag, since, filename='dump.xml')
Definition: EcalCondTools.py:44
xuti::writeHeader
void writeHeader(xercesc::DOMNode *parentNode, const EcalCondHeader &header)
write
Definition: DOMHelperFunctions.cc:151
boostedTaus_cff.doc
doc
Definition: boostedTaus_cff.py:20
gather_cfg.cout
cout
Definition: gather_cfg.py:144
EcalAlignmentXMLTranslator::writeXML
static int writeXML(const std::string &filename, const EcalCondHeader &header, const Alignments &record)
Definition: EcalAlignmentXMLTranslator.cc:20
Alignments.h
cscNeutronWriter_cfi.writer
writer
Definition: cscNeutronWriter_cfi.py:6
cms::xerces::toString
std::string toString(XMLCh const *toTranscode)
Definition: XercesStrUtils.h:35
xuti::id_tag
const std::string id_tag("id")
xuti::WriteNodeWithValue
void WriteNodeWithValue(xercesc::DOMNode *parentNode, const std::string &tag, const T &value)
write a node with
Definition: DOMHelperFunctions.h:46
XERCES_CPP_NAMESPACE
Definition: XmlConfigParser.h:12
corrVsCorr.filename
filename
Definition: corrVsCorr.py:123
xuti::Theta_tag
const std::string Theta_tag("Theta")
xuti::x_tag
const std::string x_tag("x")
xuti::Psi_tag
const std::string Psi_tag("Psi")
DOMHelperFunctions.h
EcalCondHeader
Definition: EcalCondHeader.h:16
xuti::Phi_tag
const std::string Phi_tag("Phi")
EcalAlignmentXMLTranslator::dumpXML
static std::string dumpXML(const EcalCondHeader &header, const Alignments &record)
Definition: EcalAlignmentXMLTranslator.cc:33
Xerces.h
cms::concurrency::xercesTerminate
void xercesTerminate()
Definition: Xerces.cc:23
xuti
Definition: DOMHelperFunctions.h:21
root
Definition: RooFitFunction.h:10
cms::xerces::uStr
ZStr< XMLCh > uStr(char const *str)
Definition: XercesStrUtils.h:31
AlCaHarvesting_cff.record
record
Definition: AlCaHarvesting_cff.py:42
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
EcalAlignmentXMLTranslator.h
impl
Definition: trackAlgoPriorityOrder.h:18
std
Definition: JetResolutionObject.h:76
xuti::AlignmentConstant_tag
const std::string AlignmentConstant_tag("EcalAlignmentConstant")
RecoTauValidation_cfi.header
header
Definition: RecoTauValidation_cfi.py:291
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
xuti::subdet_tag
const std::string subdet_tag("SubDet")
cms::concurrency::xercesInitialize
void xercesInitialize()
Definition: Xerces.cc:18
Alignments
Definition: Alignments.h:10
xuti::Cell_tag
const std::string Cell_tag("cell")
xuti::z_tag
const std::string z_tag("z")
xuti::y_tag
const std::string y_tag("y")