CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch1/src/CondTools/Ecal/src/EcalTPGCrystalStatusXMLTranslator.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 "DataFormats/DetId/interface/DetId.h"
00013 #include "DataFormats/EcalDetId/interface/EcalSubdetector.h"
00014 
00015 #include "CondTools/Ecal/interface/EcalTPGCrystalStatusXMLTranslator.h"
00016 #include "CondTools/Ecal/interface/DOMHelperFunctions.h"
00017 #include "CondTools/Ecal/interface/XMLTags.h"
00018 
00019 #include "CondFormats/DataRecord/interface/EcalTPGCrystalStatusRcd.h"
00020 #include "CondFormats/EcalObjects/interface/EcalTPGCrystalStatus.h"
00021 
00022 using namespace XERCES_CPP_NAMESPACE;
00023 using namespace xuti;
00024 using namespace std;
00025 
00026 int EcalTPGCrystalStatusXMLTranslator::writeXML(const std::string& filename, 
00027                                                 const EcalCondHeader& header,
00028                                                 const EcalTPGCrystalStatus& record){
00029   std::fstream fs(filename.c_str(),ios::out);
00030   fs<< dumpXML(header,record);
00031   return 0;  
00032 }
00033 
00034 std::string EcalTPGCrystalStatusXMLTranslator::dumpXML(const EcalCondHeader& header,const EcalTPGCrystalStatus& record){
00035 
00036   XMLPlatformUtils::Initialize();
00037   DOMImplementation*  impl =
00038     DOMImplementationRegistry::getDOMImplementation(fromNative("LS").c_str());
00039 
00040   DOMWriter* writer =static_cast<DOMImplementationLS*>(impl)->createDOMWriter( );
00041   writer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true);
00042 
00043   DOMDocumentType* doctype = impl->createDocumentType(fromNative("XML").c_str(), 0, 0 );
00044   DOMDocument *    doc = 
00045     impl->createDocument( 0, fromNative(TPGCrystalStatus_tag).c_str(), doctype );
00046 
00047   doc->setEncoding(fromNative("UTF-8").c_str() );
00048   doc->setStandalone(true);
00049   doc->setVersion(fromNative("1.0").c_str() );
00050 
00051   DOMElement* root = doc->getDocumentElement();
00052 
00053   xuti::writeHeader(root,header);
00054 
00055   const int kSides       = 2;
00056   const int kBarlRings   = EBDetId::MAX_IETA;
00057   const int kBarlWedges  = EBDetId::MAX_IPHI;
00058   const int kEndcWedgesX = EEDetId::IX_MAX;
00059   const int kEndcWedgesY = EEDetId::IY_MAX;
00060 
00061   std::cout << "EcalTPGCrystalStatusXMLTranslator::dumpXML" << std::endl;
00062   for (int sign=0; sign < kSides; sign++) {
00063     int thesign = sign==1 ? 1:-1;
00064 
00065     for (int ieta=0; ieta<kBarlRings; ieta++) {
00066       for (int iphi=0; iphi<kBarlWedges; iphi++) {
00067         EBDetId id((ieta+1)*thesign, iphi+1);
00068         if(record[id.rawId()].getStatusCode() > 0) {
00069           DOMElement* cellnode=writeCell(root, id);
00070           WriteNodeWithValue(cellnode, TPGCrystalStatus_tag, record[id.rawId()].getStatusCode());
00071         }
00072       }  // iphi
00073     }   // ieta
00074 
00075     for (int ix=0; ix<kEndcWedgesX; ix++) {
00076       for (int iy=0; iy<kEndcWedgesY; iy++) {
00077         if (! EEDetId::validDetId(ix+1,iy+1,thesign)) continue;
00078         EEDetId id(ix+1,iy+1,thesign);
00079         if(record[id.rawId()].getStatusCode() > 0) {
00080           DOMElement* cellnode=writeCell(root, id);
00081           WriteNodeWithValue(cellnode, TPGCrystalStatus_tag, record[id.rawId()].getStatusCode());
00082         }
00083       }  // iy
00084     }   // ix
00085   }    // side
00086 
00087   std::string dump = toNative(writer->writeToString(*root)); 
00088   doc->release(); 
00089   return dump;
00090 }