CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalPedestalsXMLTranslator.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 
17 
18 
19 using namespace XERCES_CPP_NAMESPACE;
20 using namespace xuti;
21 using namespace std;
22 
24  EcalCondHeader& header,
26 
27  XMLPlatformUtils::Initialize();
28 
29  XercesDOMParser* parser = new XercesDOMParser;
30  parser->setValidationScheme( XercesDOMParser::Val_Never );
31  parser->setDoNamespaces( false );
32  parser->setDoSchema( false );
33 
34  parser->parse(filename.c_str());
35 
36  DOMDocument* xmlDoc = parser->getDocument();
37  if (!xmlDoc) {
38  std::cout << "EcalPedestalsXMLTranslator::Error parsing document" << std::endl;
39  return -1;
40  }
41 
42  DOMElement* elementRoot = xmlDoc->getDocumentElement();
43 
44  xuti::readHeader(elementRoot,header);
45 
46  DOMNode * cellnode = getChildNode(elementRoot,Cell_tag);
47 
48  int chan = 0;
49  while(cellnode) {
50  // std::cout << " Channel " << chan << std::endl;
51  float mean12 = 0;
52  float mean6 = 0;
53  float mean1 = 0;
54  float rms12 = 0;
55  float rms6 = 0;
56  float rms1 = 0;
57  DetId detid = readCellId(dynamic_cast<DOMElement*>(cellnode));
58  // std::cout << " readCell Id Channel " << chan << " tag " << mean12_tag << std::endl;
59 
60  DOMNode* mean12_node = getChildNode(cellnode,mean12_tag);
61  GetNodeData(mean12_node,mean12);
62  // std::cout << " tag " << mean12_tag << " mean12 " << mean12 << std::endl;
63 
64  DOMNode* mean6_node = getChildNode(cellnode,mean6_tag);
65  GetNodeData(mean6_node,mean6);
66  // std::cout << " tag " << mean6_tag << " mean6 " << mean6 << std::endl;
67 
68  DOMNode* mean1_node = getChildNode(cellnode,mean1_tag);
69  GetNodeData(mean1_node,mean1);
70  // std::cout << " tag " << mean1_tag << " mean1 " << mean1 << std::endl;
71 
72  DOMNode* rms12_node = getChildNode(cellnode,rms12_tag);
73  GetNodeData(rms12_node,rms12);
74  // std::cout << " tag 12 " << rms12_tag << " rms 12 " << rms12 << std::endl;
75 
76  DOMNode* rms6_node = getChildNode(cellnode,rms6_tag);
77  GetNodeData(rms6_node,rms6);
78  // std::cout << " tag 6 " << rms6_tag << " rms 6 " << rms6 << std::endl;
79 
80  DOMNode* rms1_node = getChildNode(cellnode,rms1_tag);
81  // std::cout << " tag 1 " << rms1_tag << std::endl;
82 
83  GetNodeData(rms1_node,rms1);
84  // std::cout << " Channel " << chan << " mean12 " << mean12 << " rms 1 " << rms1 << std::endl;
85  record[detid].mean_x12 = mean12;
86  record[detid].mean_x6 = mean6;
87  record[detid].mean_x1 = mean1;
88  record[detid].rms_x12 = rms12;
89  record[detid].rms_x6 = rms6;
90  record[detid].rms_x1 = rms1;
91 
92  cellnode = cellnode->getNextSibling();
93 
94  while(cellnode && cellnode->getNodeType() != DOMNode::ELEMENT_NODE)
95  cellnode = cellnode->getNextSibling();
96  chan++;
97  }
98 
99  delete parser;
100  XMLPlatformUtils::Terminate();
101  std::cout << " nb of channels found in xml file " << chan << std::endl;
102  return 0;
103  }
104 
106  const EcalCondHeader& header,
107  const EcalPedestals& record){
108  std::fstream fs(filename.c_str(),ios::out);
109  fs<< dumpXML(header,record);
110  return 0;
111 }
112 
113 
115 
116  XMLPlatformUtils::Initialize();
117  DOMImplementation* impl =
118  DOMImplementationRegistry::getDOMImplementation(fromNative("LS").c_str());
119 
120  DOMWriter* writer =static_cast<DOMImplementationLS*>(impl)->createDOMWriter( );
121  writer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true);
122 
123  DOMDocumentType* doctype = impl->createDocumentType(fromNative("XML").c_str(), 0, 0 );
124  DOMDocument * doc =
125  impl->createDocument( 0, fromNative(Pedestals_tag).c_str(), doctype );
126 
127  doc->setEncoding(fromNative("UTF-8").c_str() );
128  doc->setStandalone(true);
129  doc->setVersion(fromNative("1.0").c_str() );
130 
131  DOMElement* root = doc->getDocumentElement();
132 
133  xuti::writeHeader(root,header);
134  if (!record.barrelItems().size()) return std::string();
135  for(int cellid = EBDetId::MIN_HASH;
137  ++cellid) {
138  uint32_t rawid = EBDetId::unhashIndex(cellid);
139 
140  if (record.find(rawid) == record.end()) continue;
141  if(!record[rawid].mean_x12 && !record[rawid].rms_x12) continue;
142 
143  DOMElement* cellnode=writeCell(root,rawid);
144 
145  WriteNodeWithValue(cellnode,mean12_tag,record[rawid].mean_x12);
146  WriteNodeWithValue(cellnode,mean6_tag,record[rawid].mean_x6);
147  WriteNodeWithValue(cellnode,mean1_tag,record[rawid].mean_x1);
148  WriteNodeWithValue(cellnode,rms12_tag,record[rawid].rms_x12);
149  WriteNodeWithValue(cellnode,rms6_tag,record[rawid].rms_x6);
150  WriteNodeWithValue(cellnode,rms1_tag,record[rawid].rms_x1);
151  }
152 
153  if (!record.endcapItems().size()) return std::string();
154  for(int cellid = 0;
156  ++cellid) {
157  if(!EEDetId::validHashIndex(cellid)) continue;
158 
159  uint32_t rawid = EEDetId::unhashIndex(cellid);
160 
161  if (record.find(rawid) == record.end()) continue;
162  if(!record[rawid].mean_x12 && !record[rawid].rms_x12) continue;
163 
164  DOMElement* cellnode=writeCell(root,rawid);
165 
166  WriteNodeWithValue(cellnode,mean12_tag,record[rawid].mean_x12);
167  WriteNodeWithValue(cellnode,mean6_tag,record[rawid].mean_x6);
168  WriteNodeWithValue(cellnode,mean1_tag,record[rawid].mean_x1);
169  WriteNodeWithValue(cellnode,rms12_tag,record[rawid].rms_x12);
170  WriteNodeWithValue(cellnode,rms6_tag,record[rawid].rms_x6);
171  WriteNodeWithValue(cellnode,rms1_tag,record[rawid].rms_x1);
172  }
173 
174  std::string dump= toNative(writer->writeToString(*root));
175  doc->release();
176  return dump;
177 }
const std::string mean12_tag("mean_x12")
static int readXML(const std::string &filename, EcalCondHeader &header, EcalPedestals &record)
JetCorrectorParameters::Record record
Definition: classes.h:13
const Items & barrelItems() const
static EEDetId unhashIndex(int hi)
Definition: EEDetId.cc:99
const std::string mean1_tag("mean_x1")
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
static std::string dumpXML(const EcalCondHeader &header, const EcalPedestals &record)
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")
const std::string Pedestals_tag("EcalPedestals")
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 mean6_tag("mean_x6")
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
const_iterator find(uint32_t rawId) const
XercesString fromNative(const char *str)
Definition: XercesString.h:31
const std::string rms12_tag("rms_x12")
const std::string rms6_tag("rms_x6")
tuple cout
Definition: gather_cfg.py:121
const_iterator end() const
xercesc::DOMElement * writeCell(xercesc::DOMNode *node, const DetId &detid)
Append a Cell node with attributes to.
const Items & endcapItems() const
static int writeXML(const std::string &filename, const EcalCondHeader &header, const EcalPedestals &record)
const std::string rms1_tag("rms_x1")
const DetId readCellId(xercesc::DOMElement *node)
Assuming.
std::string toNative(const XMLCh *str)
Definition: XercesString.h:42
string root
initialization
Definition: dbtoconf.py:70