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 
17 using namespace XERCES_CPP_NAMESPACE;
18 using namespace xuti;
19 using namespace std;
20 
22  const EcalCondHeader& header,
23  const Alignments& record) {
25 
26  fstream fs(filename.c_str(),ios::out);
27  fs<< dumpXML(header,record);
28 
30 
31  return 0;
32 }
33 
35  const Alignments& record) {
36 
37  unique_ptr<DOMImplementation> impl( DOMImplementationRegistry::getDOMImplementation( cms::xerces::uStr("LS").ptr()));
38 
39  DOMLSSerializer* writer = impl->createLSSerializer();
40  if( writer->getDomConfig()->canSetParameter( XMLUni::fgDOMWRTFormatPrettyPrint, true ))
41  writer->getDomConfig()->setParameter( XMLUni::fgDOMWRTFormatPrettyPrint, true );
42 
43  DOMDocumentType* doctype = impl->createDocumentType( cms::xerces::uStr("XML").ptr(), 0, 0 );
44  DOMDocument* doc = impl->createDocument( 0, cms::xerces::uStr(AlignmentConstant_tag.c_str()).ptr(), doctype );
45  DOMElement* root = doc->getDocumentElement();
46 
47  xuti::writeHeader(root,header);
48 
49  for ( vector<AlignTransform>::const_iterator it = record.m_align.begin();
50  it != record.m_align.end(); it++ ) {
51  int Id = (*it).rawId();
52  int sub = (Id>>24)&0xF;
53  stringstream subdet;
54  if(sub == 2) {
55  subdet << "EB";
56  int SM ;
57  int phi = Id&0x1FF;
58  // int eta = (Id>>9)&0x3F;
59  int side = (Id>>16)&1;
60  if(side == 0) {
61  subdet << "-";
62  SM = (phi + 19)/20;
63  }
64  else{
65  subdet << "+";
66  SM = phi/20;
67  }
68  if(SM < 10) subdet << "0" << SM;
69  else subdet << SM;
70  }
71  else if(sub == 4) {
72  subdet << "EE";
73  // int y = Id&0x7F;
74  int x = (Id>>7)&0x7F;
75  // int Dee = x/70 + 1;
76  int side = (Id>>14)&1;
77  if(side == 0) {
78  subdet << "-";
79  }
80  else{
81  subdet << "+";
82  }
83  // subdet << "0" << Dee;
84  if(x == 20) subdet << "F";
85  else if(x == 70) subdet << "N";
86  else cout << " strange value for x " << x << endl; // should never occur
87  }
88  else if(sub == 6) {
89  subdet << "ES";
90  // int strip = Id&0x3F;
91  int x = (Id>>6)&0x3F;
92  // int y = (Id>>12)&0x3F;
93  int plane = (Id>>18)&1;
94  int side = (Id>>19)&1;
95  if(side == 0) subdet << "-";
96  else subdet << "+";
97  if(plane) subdet << "F";
98  else subdet << "R";
99  if(x/30) subdet << "F";
100  else subdet << "N";
101  }
102  else cout << " problem sub = " << sub << endl;
103  cout << (*it).rawId()
104  << " " << (*it).rotation().getPhi()
105  << " " << (*it).rotation().getTheta()
106  << " " << (*it).rotation().getPsi()
107  << " " << (*it).translation().x()
108  << " " << (*it).translation().y()
109  << " " << (*it).translation().z()
110  << endl;
111  uint32_t rawid = (*it).rawId();
112  DOMElement* cellnode =
113  root->getOwnerDocument()->createElement( cms::xerces::uStr(Cell_tag.c_str()).ptr());
114  root->appendChild(cellnode);
115  cellnode->setAttribute( cms::xerces::uStr(subdet_tag.c_str()).ptr(),
116  cms::xerces::uStr(subdet.str().c_str()).ptr());
117  xuti::WriteNodeWithValue(cellnode, id_tag, rawid);
118  xuti::WriteNodeWithValue(cellnode, x_tag, (*it).translation().x());
119  xuti::WriteNodeWithValue(cellnode, y_tag, (*it).translation().y());
120  xuti::WriteNodeWithValue(cellnode, z_tag, (*it).translation().z());
121  xuti::WriteNodeWithValue(cellnode, Phi_tag, (*it).rotation().getPhi());
122  xuti::WriteNodeWithValue(cellnode, Theta_tag, (*it).rotation().getTheta());
123  xuti::WriteNodeWithValue(cellnode, Psi_tag, (*it).rotation().getPsi());
124  }
125 
126  std::string dump = cms::xerces::toString( writer->writeToString( root ));
127  doc->release();
128  doctype->release();
129  writer->release();
130 
131  return dump;
132 }
133 
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)
T x() const
Cartesian x coordinate.
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")