CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalAlignmentXMLTranslator.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <sstream>
3 #include <fstream>
4 #include <xercesc/dom/DOMNode.hpp>
5 #include <xercesc/dom/DOM.hpp>
6 #include <xercesc/parsers/XercesDOMParser.hpp>
7 #include <xercesc/util/PlatformUtils.hpp>
8 #include <xercesc/util/XMLString.hpp>
9 #include <xercesc/sax/SAXException.hpp>
10 #include <xercesc/framework/LocalFileFormatTarget.hpp>
11 
15 
16 using namespace XERCES_CPP_NAMESPACE;
17 using namespace xuti;
18 
20  const EcalCondHeader& header,
21  const Alignments& record){
22  fstream fs(filename.c_str(),ios::out);
23  fs<< dumpXML(header,record);
24  return 0;
25 }
26 
28  const Alignments& record){
29 
30  XMLPlatformUtils::Initialize();
31 
32  DOMImplementation* impl =
33  DOMImplementationRegistry::getDOMImplementation(fromNative("LS").c_str());
34 
35  DOMWriter* writer =static_cast<DOMImplementationLS*>(impl)->createDOMWriter( );
36  writer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true);
37 
38  DOMDocumentType* doctype = impl->createDocumentType(fromNative("XML").c_str(), 0, 0 );
39  DOMDocument * doc =
40  impl->createDocument( 0, fromNative(AlignmentConstant_tag).c_str(), doctype );
41 
42 
43  doc->setEncoding(fromNative("UTF-8").c_str() );
44  doc->setStandalone(true);
45  doc->setVersion(fromNative("1.0").c_str() );
46 
47  DOMElement* root = doc->getDocumentElement();
48 
49  xuti::writeHeader(root,header);
50 
51  for ( vector<AlignTransform>::const_iterator it = record.m_align.begin();
52  it != record.m_align.end(); it++ ) {
53  int Id = (*it).rawId();
54  int sub = (Id>>24)&0xF;
55  stringstream subdet;
56  if(sub == 2) {
57  subdet << "EB";
58  int SM ;
59  int phi = Id&0x1FF;
60  // int eta = (Id>>9)&0x3F;
61  int side = (Id>>16)&1;
62  if(side == 0) {
63  subdet << "-";
64  SM = (phi + 19)/20;
65  }
66  else{
67  subdet << "+";
68  SM = phi/20;
69  }
70  if(SM < 10) subdet << "0" << SM;
71  else subdet << SM;
72  }
73  else if(sub == 4) {
74  subdet << "EE";
75  // int y = Id&0x7F;
76  int x = (Id>>7)&0x7F;
77  // int Dee = x/70 + 1;
78  int side = (Id>>14)&1;
79  if(side == 0) {
80  subdet << "-";
81  }
82  else{
83  subdet << "+";
84  }
85  // subdet << "0" << Dee;
86  if(x == 20) subdet << "F";
87  else if(x == 70) subdet << "N";
88  else cout << " strange value for x " << x << endl; // should never occur
89  }
90  else if(sub == 6) {
91  subdet << "ES";
92  // int strip = Id&0x3F;
93  int x = (Id>>6)&0x3F;
94  // int y = (Id>>12)&0x3F;
95  int plane = (Id>>18)&1;
96  int side = (Id>>19)&1;
97  if(side == 0) subdet << "-";
98  else subdet << "+";
99  if(plane) subdet << "F";
100  else subdet << "R";
101  if(x/30) subdet << "F";
102  else subdet << "N";
103  }
104  else cout << " problem sub = " << sub << endl;
105  cout << (*it).rawId()
106  << " " << (*it).rotation().getPhi()
107  << " " << (*it).rotation().getTheta()
108  << " " << (*it).rotation().getPsi()
109  << " " << (*it).translation().x()
110  << " " << (*it).translation().y()
111  << " " << (*it).translation().z()
112  << endl;
113  uint32_t rawid = (*it).rawId();
114  DOMElement* cellnode =
115  root->getOwnerDocument()->createElement( fromNative(Cell_tag).c_str());
116  root->appendChild(cellnode);
117  cellnode->setAttribute(fromNative(subdet_tag).c_str(),
118  fromNative(subdet.str()).c_str());
119  xuti::WriteNodeWithValue(cellnode, id_tag, rawid);
120  xuti::WriteNodeWithValue(cellnode, x_tag, (*it).translation().x());
121  xuti::WriteNodeWithValue(cellnode, y_tag, (*it).translation().y());
122  xuti::WriteNodeWithValue(cellnode, z_tag, (*it).translation().z());
123  xuti::WriteNodeWithValue(cellnode, Phi_tag, (*it).rotation().getPhi());
124  xuti::WriteNodeWithValue(cellnode, Theta_tag, (*it).rotation().getTheta());
125  xuti::WriteNodeWithValue(cellnode, Psi_tag, (*it).rotation().getPsi());
126  }
127 
128  string dump = toNative(writer->writeToString(*root));
129  doc->release();
130  return dump;
131 }
132 
JetCorrectorParameters::Record record
Definition: classes.h:11
const std::string Phi_tag("Phi")
const std::string x_tag("x")
const std::string id_tag("id")
std::vector< AlignTransform > m_align
Definition: Alignments.h:14
void WriteNodeWithValue(xercesc::DOMNode *parentNode, const std::string &tag, const T &value)
write a node with
static string dumpXML(const EcalCondHeader &header, const Alignments &record)
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
const std::string z_tag("z")
tuple doc
Definition: asciidump.py:381
const std::string Psi_tag("Psi")
tuple out
Definition: dbtoconf.py:99
tuple filename
Definition: lut2db_cfg.py:20
XercesString fromNative(const char *str)
Definition: XercesString.h:31
tuple cout
Definition: gather_cfg.py:41
const std::string Theta_tag("Theta")
std::string toNative(const XMLCh *str)
Definition: XercesString.h:42
const std::string AlignmentConstant_tag("EcalAlignmentConstant")
string root
initialization
Definition: dbtoconf.py:70
Definition: DDAxes.h:10