test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalWeightGroupXMLTranslator.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>
8 #include <xercesc/util/XMLString.hpp>
9 #include <xercesc/sax/SAXException.hpp>
10 #include <xercesc/framework/LocalFileFormatTarget.hpp>
11 
12 
13 
17 
18 using namespace XERCES_CPP_NAMESPACE;
19 using namespace xuti;
20 using namespace std;
21 
22 
23 
25  EcalCondHeader& header,
27 
29 
30  XercesDOMParser* parser = new XercesDOMParser;
31  parser->setValidationScheme( XercesDOMParser::Val_Never );
32  parser->setDoNamespaces( false );
33  parser->setDoSchema( false );
34 
35  parser->parse(filename.c_str());
36 
37  DOMDocument* xmlDoc = parser->getDocument();
38  if (!xmlDoc) {
39  std::cout << "EcalWeightGroupXMLTranslator::Error parsing document" << std::endl;
40  return -1;
41  }
42 
43  DOMElement* elementRoot = xmlDoc->getDocumentElement();
44 
45  xuti::readHeader(elementRoot,header);
46  // get the first cell node
47  DOMNode * cellnode=getChildNode(elementRoot,Cell_tag);
48 
49  // loop on cell nodes
50  while (cellnode){
51 
52  unsigned int group=0;
53 
54  // read id
55  DetId detid= readCellId(dynamic_cast<DOMElement*> (cellnode));
56 
57  // read constant
58  DOMNode * c_node = getChildNode(cellnode,WeightGroup_tag);
59  GetNodeData(c_node,group);
60 
61 
62  // fill record
63  record[detid]=EcalXtalGroupId(group);
64 
65 
66  // get next cell
67  cellnode= cellnode->getNextSibling();
68 
69  while (cellnode&& cellnode->getNodeType( ) != DOMNode::ELEMENT_NODE)
70  cellnode= cellnode->getNextSibling();
71 
72 
73  }
74 
75 
76  delete parser;
78  return 0;
79 
80 }
81 
82 
83 
84 
85 
87  const EcalCondHeader& header,
89  std::fstream fs(filename.c_str(),ios::out);
90  fs<< dumpXML(header,record);
91  return 0;
92 
93 }
94 
95 
96 
100 
102 
103  DOMImplementation* impl =
104  DOMImplementationRegistry::getDOMImplementation(fromNative("LS").c_str());
105 
106  DOMWriter* writer =static_cast<DOMImplementationLS*>(impl)->createDOMWriter( );
107  writer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true);
108 
109  DOMDocumentType* doctype = impl->createDocumentType( fromNative("XML").c_str(), 0, 0 );
110  DOMDocument * doc =
111  impl->createDocument( 0, fromNative(WeightGroups_tag).c_str(), doctype );
112 
113 
114  doc->setEncoding(fromNative("UTF-8").c_str() );
115  doc->setStandalone(true);
116  doc->setVersion(fromNative("1.0").c_str() );
117 
118 
119  DOMElement* root = doc->getDocumentElement();
120 
121  xuti::writeHeader(root,header);
122 
123  for (int cellid = EBDetId::MIN_HASH;
125  ++cellid){// loop on EB cells
126 
127  uint32_t rawid= EBDetId::unhashIndex(cellid);
128 
129  //if (!record[rawid]) continue; // cell absent from original record
130 
131  DOMElement* cellnode=writeCell(root,rawid);
132 
133  WriteNodeWithValue(cellnode,WeightGroup_tag,record[rawid].id());
134 
135 
136  } // loop on EB cells
137 
138 
139 
140  for (int cellid = 0;
142  ++cellid){// loop on EE cells
143 
144  if (!EEDetId::validHashIndex(cellid)) continue;
145 
146  uint32_t rawid= EEDetId::unhashIndex(cellid);
147  //xif (!record[rawid]) continue; // cell absent from original record
148 
149 
150  DOMElement* cellnode=writeCell(root,rawid);
151  WriteNodeWithValue(cellnode,WeightGroup_tag,record[rawid].id());
152 
153  } // loop on EE cells
154 
155 
156  std::string dump= toNative(writer->writeToString(*root));
157  doc->release();
158  // cms::concurrency::xercesTerminate();
159 
160  return dump;
161 
162 }
JetCorrectorParameters::Record record
Definition: classes.h:7
void xercesTerminate()
Definition: Xerces.cc:22
void xercesInitialize()
Definition: Xerces.cc:17
static EEDetId unhashIndex(int hi)
Definition: EEDetId.cc:99
static int writeXML(const std::string &filename, const EcalCondHeader &header, const EcalWeightXtalGroups &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:239
const std::string WeightGroup_tag("EcalWeightGroup")
void readHeader(xercesc::DOMNode *parentNode, EcalCondHeader &header)
read header from
static int readXML(const std::string &filename, EcalCondHeader &header, EcalWeightXtalGroups &record)
static const int MIN_HASH
Definition: EBDetId.h:156
const std::string Cell_tag("cell")
void writeHeader(xercesc::DOMNode *parentNode, const EcalCondHeader &header)
write
const std::string WeightGroups_tag("EcalWeightGroups")
static std::string dumpXML(const EcalCondHeader &header, const EcalWeightXtalGroups &record)
Definition: DetId.h:18
tuple group
Definition: watchdog.py:82
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
static EBDetId unhashIndex(int hi)
get a DetId from a compact index for arrays
Definition: EBDetId.h:114
tuple filename
Definition: lut2db_cfg.py:20
XercesString fromNative(const char *str)
Definition: XercesString.h:31
tuple cout
Definition: gather_cfg.py:145
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