CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_8_patch3/src/CondTools/Ecal/src/EcalAlignmentXMLTranslator.cc

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