CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalChannelStatusXMLTranslator.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 
12 
15 
18 
19 using namespace XERCES_CPP_NAMESPACE;
20 using namespace xuti;
21 using namespace std;
22 
23 
24 
25 
26 
28  EcalCondHeader& header,
30 
31 
32 
33  XMLPlatformUtils::Initialize();
34 
35  XercesDOMParser* parser = new XercesDOMParser;
36  parser->setValidationScheme( XercesDOMParser::Val_Never );
37  parser->setDoNamespaces( false );
38  parser->setDoSchema( false );
39 
40  parser->parse(filename.c_str());
41 
42  DOMDocument* xmlDoc = parser->getDocument();
43  if (!xmlDoc) {
44  std::cout << "EcalChannelStatusXMLTranslator::Error parsing document" << std::endl;
45  return -1;
46  }
47 
48  DOMElement* elementRoot = xmlDoc->getDocumentElement();
49 
50  xuti::readHeader(elementRoot,header);
51 
52  DOMNode * cellnode = getChildNode(elementRoot,Cell_tag);
53 
54  while(cellnode)
55  {
56  uint16_t csc = 0;
57 
58  DetId detid = readCellId(dynamic_cast<DOMElement*>(cellnode));
59 
60  DOMNode* c_node = getChildNode(cellnode,ChannelStatusCode_tag);
61  GetNodeData(c_node,csc);
62 
64  record[detid] = ecalCSC;
65 
66  cellnode = cellnode->getNextSibling();
67 
68  while(cellnode && cellnode->getNodeType() != DOMNode::ELEMENT_NODE)
69  cellnode = cellnode->getNextSibling();
70 
71 
72  }
73 
74  delete parser;
75  XMLPlatformUtils::Terminate();
76  return 0;
77 
78 
79 }
80 
81 
82 
83 
84 
86  const EcalCondHeader& header,
87  const EcalChannelStatus& record){
88  std::fstream fs(filename.c_str(),ios::out);
89  fs<< dumpXML(header,record);
90  return 0;
91  }
92 
93 
95  const EcalCondHeader& header,
96  const EcalChannelStatus& record){
97 
98 
99  XMLPlatformUtils::Initialize();
100 
101  DOMImplementation* impl =
102  DOMImplementationRegistry::getDOMImplementation(fromNative("LS").c_str());
103 
104  DOMWriter* writer =static_cast<DOMImplementationLS*>(impl)->createDOMWriter( );
105  writer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true);
106 
107  DOMDocumentType* doctype = impl->createDocumentType( fromNative("XML").c_str(), 0, 0 );
108  DOMDocument * doc =
109  impl->createDocument( 0, fromNative(ChannelStatus_tag).c_str(), doctype );
110 
111 
112  doc->setEncoding(fromNative("UTF-8").c_str() );
113  doc->setStandalone(true);
114  doc->setVersion(fromNative("1.0").c_str() );
115 
116 
117  DOMElement* root = doc->getDocumentElement();
118 
119  xuti::writeHeader(root,header);
120 
121  for(int cellid = EBDetId::MIN_HASH;
123  ++cellid)
124  {
125 
126  uint32_t rawid = EBDetId::unhashIndex(cellid);
127 
128  if(!record[rawid].getStatusCode()) continue;
129 
130 
131  DOMElement* cellnode = writeCell(root,rawid);
132 
133  WriteNodeWithValue(cellnode,ChannelStatusCode_tag,record[rawid].getStatusCode());
134 
135 
136  }
137 
138 
139 
140 
141  for(int cellid = 0;
143  ++cellid)
144  {
145 
146  if(!EEDetId::validHashIndex(cellid)) continue;
147 
148  uint32_t rawid = EEDetId::unhashIndex(cellid);
149 
150  if(!record[rawid].getStatusCode()) continue;
151 
152  DOMElement* cellnode = writeCell(root,rawid);
153  WriteNodeWithValue(cellnode,ChannelStatusCode_tag,record[rawid].getStatusCode());
154 
155  }
156 
157 
158  std::string dump= toNative(writer->writeToString(*root));
159  doc->release();
160  // XMLPlatformUtils::Terminate();
161 
162  return dump;
163 
164 }
static int writeXML(const std::string &filename, const EcalCondHeader &header, const EcalChannelStatus &record)
JetCorrectorParameters::Record record
Definition: classes.h:13
static int readXML(const std::string &filename, EcalCondHeader &header, EcalChannelStatus &record)
static EEDetId unhashIndex(int hi)
Definition: EEDetId.cc:99
static std::string dumpXML(const EcalCondHeader &header, const EcalChannelStatus &record)
void WriteNodeWithValue(xercesc::DOMNode *parentNode, const std::string &tag, const T &value)
write a node with
static bool validHashIndex(int i)
Definition: EEDetId.h:240
const std::string ChannelStatusCode_tag("ChannelStatusCode")
void readHeader(xercesc::DOMNode *parentNode, EcalCondHeader &header)
read header from
static const int MIN_HASH
Definition: EBDetId.h:157
const std::string Cell_tag("cell")
void writeHeader(xercesc::DOMNode *parentNode, const EcalCondHeader &header)
write
tuple doc
Definition: asciidump.py:381
tuple out
Definition: dbtoconf.py:99
Definition: DetId.h:20
void GetNodeData(xercesc::DOMNode *node, T &value)
get the node data
xercesc::DOMNode * getChildNode(xercesc::DOMNode *node, const std::string &nodename)
get the child of
const std::string ChannelStatus_tag("EcalChannelStatus")
static EBDetId unhashIndex(int hi)
get a DetId from a compact index for arrays
Definition: EBDetId.h:115
tuple filename
Definition: lut2db_cfg.py:20
XercesString fromNative(const char *str)
Definition: XercesString.h:31
tuple cout
Definition: gather_cfg.py:121
xercesc::DOMElement * writeCell(xercesc::DOMNode *node, const DetId &detid)
Append a Cell node with attributes to.
const DetId readCellId(xercesc::DOMElement *node)
Assuming.
std::string toNative(const XMLCh *str)
Definition: XercesString.h:42
string root
initialization
Definition: dbtoconf.py:70