Go to the documentation of this file.00001 #include <iostream>
00002 #include <sstream>
00003 #include <fstream>
00004 #include <xercesc/dom/DOMNode.hpp>
00005 #include <xercesc/dom/DOM.hpp>
00006 #include <xercesc/parsers/XercesDOMParser.hpp>
00007 #include <xercesc/util/PlatformUtils.hpp>
00008 #include <xercesc/util/XMLString.hpp>
00009 #include <xercesc/sax/SAXException.hpp>
00010 #include <xercesc/framework/LocalFileFormatTarget.hpp>
00011
00012 #include "CondFormats/Alignment/interface/Alignments.h"
00013 #include "CondTools/Ecal/interface/EcalAlignmentXMLTranslator.h"
00014 #include "CondTools/Ecal/interface/DOMHelperFunctions.h"
00015
00016 using namespace XERCES_CPP_NAMESPACE;
00017 using namespace xuti;
00018
00019 int EcalAlignmentXMLTranslator::writeXML(const string& filename,
00020 const EcalCondHeader& header,
00021 const Alignments& record){
00022 fstream fs(filename.c_str(),ios::out);
00023 fs<< dumpXML(header,record);
00024 return 0;
00025 }
00026
00027 string EcalAlignmentXMLTranslator::dumpXML(const EcalCondHeader& header,
00028 const Alignments& record){
00029
00030 XMLPlatformUtils::Initialize();
00031
00032 DOMImplementation* impl =
00033 DOMImplementationRegistry::getDOMImplementation(fromNative("LS").c_str());
00034
00035 DOMWriter* writer =static_cast<DOMImplementationLS*>(impl)->createDOMWriter( );
00036 writer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true);
00037
00038 DOMDocumentType* doctype = impl->createDocumentType(fromNative("XML").c_str(), 0, 0 );
00039 DOMDocument * doc =
00040 impl->createDocument( 0, fromNative(AlignmentConstant_tag).c_str(), doctype );
00041
00042
00043 doc->setEncoding(fromNative("UTF-8").c_str() );
00044 doc->setStandalone(true);
00045 doc->setVersion(fromNative("1.0").c_str() );
00046
00047 DOMElement* root = doc->getDocumentElement();
00048
00049 xuti::writeHeader(root,header);
00050
00051 for ( vector<AlignTransform>::const_iterator it = record.m_align.begin();
00052 it != record.m_align.end(); it++ ) {
00053 int Id = (*it).rawId();
00054 int sub = (Id>>24)&0xF;
00055 stringstream subdet;
00056 if(sub == 2) {
00057 subdet << "EB";
00058 int SM ;
00059 int phi = Id&0x1FF;
00060
00061 int side = (Id>>16)&1;
00062 if(side == 0) {
00063 subdet << "-";
00064 SM = (phi + 19)/20;
00065 }
00066 else{
00067 subdet << "+";
00068 SM = phi/20;
00069 }
00070 if(SM < 10) subdet << "0" << SM;
00071 else subdet << SM;
00072 }
00073 else if(sub == 4) {
00074 subdet << "EE";
00075
00076 int x = (Id>>7)&0x7F;
00077
00078 int side = (Id>>14)&1;
00079 if(side == 0) {
00080 subdet << "-";
00081 }
00082 else{
00083 subdet << "+";
00084 }
00085
00086 if(x == 20) subdet << "F";
00087 else if(x == 70) subdet << "N";
00088 else cout << " strange value for x " << x << endl;
00089 }
00090 else if(sub == 6) {
00091 subdet << "ES";
00092
00093 int x = (Id>>6)&0x3F;
00094
00095 int plane = (Id>>18)&1;
00096 int side = (Id>>19)&1;
00097 if(side == 0) subdet << "-";
00098 else subdet << "+";
00099 if(plane) subdet << "F";
00100 else subdet << "R";
00101 if(x/30) subdet << "F";
00102 else subdet << "N";
00103 }
00104 else cout << " problem sub = " << sub << endl;
00105 cout << (*it).rawId()
00106 << " " << (*it).rotation().getPhi()
00107 << " " << (*it).rotation().getTheta()
00108 << " " << (*it).rotation().getPsi()
00109 << " " << (*it).translation().x()
00110 << " " << (*it).translation().y()
00111 << " " << (*it).translation().z()
00112 << endl;
00113 uint32_t rawid = (*it).rawId();
00114 DOMElement* cellnode =
00115 root->getOwnerDocument()->createElement( fromNative(Cell_tag).c_str());
00116 root->appendChild(cellnode);
00117 cellnode->setAttribute(fromNative(subdet_tag).c_str(),
00118 fromNative(subdet.str()).c_str());
00119 xuti::WriteNodeWithValue(cellnode, id_tag, rawid);
00120 xuti::WriteNodeWithValue(cellnode, x_tag, (*it).translation().x());
00121 xuti::WriteNodeWithValue(cellnode, y_tag, (*it).translation().y());
00122 xuti::WriteNodeWithValue(cellnode, z_tag, (*it).translation().z());
00123 xuti::WriteNodeWithValue(cellnode, Phi_tag, (*it).rotation().getPhi());
00124 xuti::WriteNodeWithValue(cellnode, Theta_tag, (*it).rotation().getTheta());
00125 xuti::WriteNodeWithValue(cellnode, Psi_tag, (*it).rotation().getPsi());
00126 }
00127
00128 string dump = toNative(writer->writeToString(*root));
00129 doc->release();
00130 return dump;
00131 }
00132