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 #include "DataFormats/EcalDetId/interface/EcalTrigTowerDetId.h"
00015
00016 #include "CondTools/Ecal/interface/EcalTPGTowerStatusXMLTranslator.h"
00017 #include "CondTools/Ecal/interface/DOMHelperFunctions.h"
00018 #include "CondTools/Ecal/interface/XMLTags.h"
00019
00020 #include "CondFormats/DataRecord/interface/EcalTPGTowerStatusRcd.h"
00021 #include "CondFormats/EcalObjects/interface/EcalTPGTowerStatus.h"
00022
00023 using namespace XERCES_CPP_NAMESPACE;
00024 using namespace xuti;
00025 using namespace std;
00026
00027 int EcalTPGTowerStatusXMLTranslator::readXML(const std::string& filename,
00028 EcalCondHeader& header,
00029 EcalTPGTowerStatus& record){
00030
00031 std::cout << " TPGTowerStatus should not be filled out from an xml file ..." << std::endl;
00032 XMLPlatformUtils::Initialize();
00033
00034 XercesDOMParser* parser = new XercesDOMParser;
00035 parser->setValidationScheme( XercesDOMParser::Val_Never );
00036 parser->setDoNamespaces( false );
00037 parser->setDoSchema( false );
00038
00039 parser->parse(filename.c_str());
00040
00041 DOMDocument* xmlDoc = parser->getDocument();
00042 if (!xmlDoc) {
00043 std::cout << "EcalTPGTowerStatusXMLTranslator::Error parsing document" << std::endl;
00044 return -1;
00045 }
00046
00047 DOMElement* elementRoot = xmlDoc->getDocumentElement();
00048
00049 xuti::readHeader(elementRoot,header);
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 delete parser;
00070 XMLPlatformUtils::Terminate();
00071 return 0;
00072 }
00073
00074 int EcalTPGTowerStatusXMLTranslator::writeXML(const std::string& filename,
00075 const EcalCondHeader& header,
00076 const EcalTPGTowerStatus& record){
00077 std::fstream fs(filename.c_str(),ios::out);
00078 fs<< dumpXML(header,record);
00079 return 0;
00080 }
00081
00082
00083 std::string EcalTPGTowerStatusXMLTranslator::dumpXML(const EcalCondHeader& header,const EcalTPGTowerStatus& record){
00084
00085 XMLPlatformUtils::Initialize();
00086 DOMImplementation* impl =
00087 DOMImplementationRegistry::getDOMImplementation(fromNative("LS").c_str());
00088
00089 DOMWriter* writer =static_cast<DOMImplementationLS*>(impl)->createDOMWriter( );
00090 writer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true);
00091
00092 DOMDocumentType* doctype = impl->createDocumentType(fromNative("XML").c_str(), 0, 0 );
00093 DOMDocument * doc =
00094 impl->createDocument( 0, fromNative(TPGTowerStatus_tag).c_str(), doctype );
00095
00096 doc->setEncoding(fromNative("UTF-8").c_str() );
00097 doc->setStandalone(true);
00098 doc->setVersion(fromNative("1.0").c_str() );
00099
00100 DOMElement* root = doc->getDocumentElement();
00101
00102 xuti::writeHeader(root,header);
00103 std::cout << "EcalTPGTowerStatusXMLTranslator::dumpXML" << std::endl;
00104 const EcalTPGTowerStatusMap &towerMap = record.getMap();
00105 std::cout << " tower map size " << towerMap.size() << std::endl;
00106 EcalTPGTowerStatusMapIterator it;
00107 for(it = towerMap.begin(); it != towerMap.end(); ++it) {
00108 if((*it).second > 0) {
00109 EcalTrigTowerDetId ttId((*it).first);
00110 std::cout << " TTDetId " << ttId << " eta " << ttId.ieta() << " phi " << ttId.iphi() << std::endl;
00111 uint32_t rawid = ttId;
00112 DOMElement* cellnode=writeCell(root,rawid);
00113 WriteNodeWithValue(cellnode, TPGTowerStatus_tag, 1);
00114 }
00115 }
00116
00117 std::string dump = toNative(writer->writeToString(*root));
00118 doc->release();
00119 return dump;
00120 }
00121
00122 void EcalTPGTowerStatusXMLTranslator::plot(std::string fn, const EcalTPGTowerStatus& record){
00123 std::ofstream fout(fn.c_str());
00124 int valEB[34][72];
00125 for(int line = 0; line < 34; line++)
00126 for(int iphi = 0; iphi < 72; iphi++)
00127 valEB[line][iphi] = 0;
00128
00129 const EcalTPGTowerStatusMap &towerMap = record.getMap();
00130 std::cout << " tower map size " << towerMap.size() << std::endl;
00131 EcalTPGTowerStatusMapIterator it;
00132 for(it = towerMap.begin(); it != towerMap.end(); ++it) {
00133 if((*it).second > 0) {
00134 EcalTrigTowerDetId ttId((*it).first);
00135 int ieta = ttId.ieta();
00136 int line = 17 - ieta;
00137 if(ieta < 0) line--;
00138 int iphi = ttId.iphi() - 1;
00139 valEB[line][iphi] = (*it).second;
00140 }
00141 }
00142 for(int line = 0; line < 34; line++) {
00143 for(int iphi = 0; iphi < 72; iphi++)
00144 fout << valEB[line][iphi] << " ";
00145 fout << std::endl;
00146 if(line == 16) fout << std::endl;
00147 }
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186 return;
00187 }