CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalTPGStripStatusXMLTranslator.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 
14 
18 
20 
21 using namespace XERCES_CPP_NAMESPACE;
22 using namespace xuti;
23 using namespace std;
24 
28 
29  std::cout << " TPGStripStatus should not be filled out from an xml file ..." << std::endl;
30  XMLPlatformUtils::Initialize();
31 
32  XercesDOMParser* parser = new XercesDOMParser;
33  parser->setValidationScheme( XercesDOMParser::Val_Never );
34  parser->setDoNamespaces( false );
35  parser->setDoSchema( false );
36 
37  parser->parse(filename.c_str());
38 
39  DOMDocument* xmlDoc = parser->getDocument();
40  if (!xmlDoc) {
41  std::cout << "EcalTPGStripStatusXMLTranslator::Error parsing document" << std::endl;
42  return -1;
43  }
44 
45  DOMElement* elementRoot = xmlDoc->getDocumentElement();
46 
47  xuti::readHeader(elementRoot,header);
48 
49  delete parser;
50  XMLPlatformUtils::Terminate();
51  return 0;
52  }
53 
55  const EcalCondHeader& header,
56  const EcalTPGStripStatus& record){
57  std::fstream fs(filename.c_str(),ios::out);
58  fs<< dumpXML(header,record);
59  return 0;
60 }
61 
62 
64 
65  XMLPlatformUtils::Initialize();
66  DOMImplementation* impl =
67  DOMImplementationRegistry::getDOMImplementation(fromNative("LS").c_str());
68 
69  DOMWriter* writer =static_cast<DOMImplementationLS*>(impl)->createDOMWriter( );
70  writer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true);
71 
72  DOMDocumentType* doctype = impl->createDocumentType(fromNative("XML").c_str(), 0, 0 );
73  DOMDocument * doc =
74  impl->createDocument( 0, fromNative(TPGStripStatus_tag).c_str(), doctype );
75 
76  doc->setEncoding(fromNative("UTF-8").c_str() );
77  doc->setStandalone(true);
78  doc->setVersion(fromNative("1.0").c_str() );
79 
80  DOMElement* root = doc->getDocumentElement();
81 
82  xuti::writeHeader(root,header);
83  std::string TCC_tag("TCC");
84  std::string TT_tag("TT");
85  std::string ST_tag("ST");
86  const EcalTPGStripStatusMap &stripMap = record.getMap();
87  std::cout << "EcalTPGStripStatusXMLTranslator::dumpXML strip map size " << stripMap.size() << std::endl;
89  for(itSt = stripMap.begin(); itSt != stripMap.end(); ++itSt) {
90  if(itSt->second > 0) {
91  int tccid = itSt->first/8192 & 0x7F;
92  int tt = itSt->first/64 & 0x7F;
93  int pseudostrip = itSt->first/8 & 0x7;
94  // std::cout << "Bad strip ID = " << itSt->first
95  // << " TCC " << tccid << " TT " << tt << " ST " << pseudostrip
96  // << ", status = " << itSt->second << std::endl;
97  DOMElement* cell_node =
98  root->getOwnerDocument()->createElement( fromNative(Cell_tag).c_str());
99  stringstream value_s;
100  value_s << tccid ;
101  cell_node->setAttribute(fromNative(TCC_tag).c_str(),
102  fromNative(value_s.str()).c_str());
103  value_s.str("");
104  value_s << tt ;
105  cell_node->setAttribute(fromNative(TT_tag).c_str(),
106  fromNative(value_s.str()).c_str());
107  value_s.str("");
108  value_s << pseudostrip;
109  cell_node->setAttribute(fromNative(ST_tag).c_str(),
110  fromNative(value_s.str()).c_str());
111  root->appendChild(cell_node);
112 
113  WriteNodeWithValue(cell_node, TPGStripStatus_tag, 1);
114  }
115  }
116 
117  std::string dump = toNative(writer->writeToString(*root));
118  doc->release();
119  return dump;
120 }
JetCorrectorParameters::Record record
Definition: classes.h:11
const std::map< uint32_t, uint16_t > & getMap() const
static int readXML(const std::string &filename, EcalCondHeader &header, EcalTPGStripStatus &record)
void WriteNodeWithValue(xercesc::DOMNode *parentNode, const std::string &tag, const T &value)
write a node with
void readHeader(xercesc::DOMNode *parentNode, EcalCondHeader &header)
read header from
const std::string Cell_tag("cell")
void writeHeader(xercesc::DOMNode *parentNode, const EcalCondHeader &header)
write
tuple doc
Definition: asciidump.py:381
static std::string dumpXML(const EcalCondHeader &header, const EcalTPGStripStatus &record)
tuple out
Definition: dbtoconf.py:99
const std::string TPGStripStatus_tag("EcalTPGStripStatus")
tuple filename
Definition: lut2db_cfg.py:20
XercesString fromNative(const char *str)
Definition: XercesString.h:31
tuple cout
Definition: gather_cfg.py:121
std::map< uint32_t, uint16_t > EcalTPGStripStatusMap
static int writeXML(const std::string &filename, const EcalCondHeader &header, const EcalTPGStripStatus &record)
std::string toNative(const XMLCh *str)
Definition: XercesString.h:42
std::map< uint32_t, uint16_t >::const_iterator EcalTPGStripStatusMapIterator
string root
initialization
Definition: dbtoconf.py:70