CMS 3D CMS Logo

EcalDCSTowerStatusXMLTranslator.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <iomanip>
3 #include <sstream>
4 #include <fstream>
5 #include <xercesc/dom/DOMNode.hpp>
6 #include <xercesc/dom/DOM.hpp>
7 #include <xercesc/parsers/XercesDOMParser.hpp>
10 #include <xercesc/util/XMLString.hpp>
11 #include <xercesc/sax/SAXException.hpp>
12 #include <xercesc/framework/LocalFileFormatTarget.hpp>
13 
17 
18 using namespace XERCES_CPP_NAMESPACE;
19 using namespace xuti;
20 using namespace std;
21 
25  std::cout << " DCSTowerStatus should not be filled out from an xml file ..." << std::endl;
27 
28  XercesDOMParser* parser = new XercesDOMParser;
29  parser->setValidationScheme(XercesDOMParser::Val_Never);
30  parser->setDoNamespaces(false);
31  parser->setDoSchema(false);
32 
33  parser->parse(filename.c_str());
34 
35  DOMDocument* xmlDoc = parser->getDocument();
36  if (!xmlDoc) {
37  std::cout << "EcalDCSTowerStatusXMLTranslator::Error parsing document" << std::endl;
38  return -1;
39  }
40 
41  DOMElement* elementRoot = xmlDoc->getDocumentElement();
42 
43  xuti::readHeader(elementRoot, header);
44 
45  DOMNode* cellnode = getChildNode(elementRoot, Cell_tag);
46 
47  while (cellnode) {
48  int status = -1;
49  DetId detid = readCellId(dynamic_cast<DOMElement*>(cellnode));
50 
51  DOMNode* my_node = getChildNode(cellnode, DCSStatusCode_tag);
52  GetNodeData(my_node, status);
53 
54  record[detid] = status;
55 
56  cellnode = cellnode->getNextSibling();
57 
58  while (cellnode && cellnode->getNodeType() != DOMNode::ELEMENT_NODE)
59  cellnode = cellnode->getNextSibling();
60  }
61 
62  delete parser;
64  return 0;
65 }
66 
68  const EcalCondHeader& header,
69  const EcalDCSTowerStatus& record) {
71 
72  std::fstream fs(filename.c_str(), ios::out);
73  fs << dumpXML(header, record);
74 
76 
77  return 0;
78 }
79 
81  unique_ptr<DOMImplementation> impl(DOMImplementationRegistry::getDOMImplementation(cms::xerces::uStr("LS").ptr()));
82 
83  DOMLSSerializer* writer = impl->createLSSerializer();
84  if (writer->getDomConfig()->canSetParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true))
85  writer->getDomConfig()->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true);
86 
87  DOMDocumentType* doctype = impl->createDocumentType(cms::xerces::uStr("XML").ptr(), nullptr, nullptr);
88  DOMDocument* doc = impl->createDocument(nullptr, cms::xerces::uStr(DCSTowerStatus_tag.c_str()).ptr(), doctype);
89  DOMElement* root = doc->getDocumentElement();
90 
92  std::cout << " barrel size " << record.barrelItems().size() << std::endl;
93  if (record.barrelItems().empty())
94  return std::string();
95  for (uint cellid = 0; cellid < EcalTrigTowerDetId::kEBTotalTowers; ++cellid) {
96  uint32_t rawid = EcalTrigTowerDetId::detIdFromDenseIndex(cellid);
97  if (record.find(rawid) == record.end())
98  continue;
99  DOMElement* cellnode = writeCell(root, rawid);
100 
101  WriteNodeWithValue(cellnode, DCSStatusCode_tag, record[rawid].getStatusCode());
102  }
103 
104  std::cout << " endcap size " << record.endcapItems().size() << std::endl;
105  if (record.endcapItems().empty())
106  return std::string();
107  for (uint cellid = 0; cellid < EcalTrigTowerDetId::kEETotalTowers; ++cellid) {
108  if (!EcalScDetId::validHashIndex(cellid))
109  continue;
110  uint32_t rawid = EcalScDetId::unhashIndex(cellid);
111 
112  if (record.find(rawid) == record.end())
113  continue;
114  DOMElement* cellnode = writeCell(root, rawid);
115 
116  WriteNodeWithValue(cellnode, DCSStatusCode_tag, record[rawid].getStatusCode());
117  }
118 
119  std::string dump = cms::xerces::toString(writer->writeToString(root));
120  doc->release();
121  doctype->release();
122  writer->release();
123 
124  return dump;
125 }
126 
128  std::ofstream fout(fn.c_str());
129  int valEB[34][72];
130  std::cout << " barrel size " << record.barrelItems().size() << std::endl;
131  if (record.barrelItems().empty())
132  return;
133  for (uint cellid = 0; cellid < EcalTrigTowerDetId::kEBTotalTowers; ++cellid) {
135  if (record.find(rawid) == record.end())
136  continue;
137  int ieta = rawid.ieta();
138  int line = 17 - ieta;
139  if (ieta < 0)
140  line--;
141  int iphi = rawid.iphi() - 1; // 0 to 71
142  valEB[line][iphi] = record[rawid].getStatusCode();
143  }
144  for (int line = 0; line < 34; line++) {
145  for (int iphi = 0; iphi < 72; iphi++)
146  fout << valEB[line][iphi] << " ";
147  fout << std::endl;
148  if (line == 16)
149  fout << std::endl;
150  }
151 
152  std::cout << " endcap size " << record.endcapItems().size() << std::endl;
153  if (record.endcapItems().empty())
154  return;
155  int valEE[2][20][20];
156  for (int k = 0; k < 2; k++)
157  for (int ix = 0; ix < 20; ix++)
158  for (int iy = 0; iy < 20; iy++)
159  valEE[k][ix][iy] = -1;
160  for (uint cellid = 0; cellid < EcalTrigTowerDetId::kEETotalTowers; ++cellid) {
161  if (EcalScDetId::validHashIndex(cellid)) {
162  EcalScDetId rawid = EcalScDetId::unhashIndex(cellid);
163  int ix = rawid.ix() - 1; // 0 to 19
164  int iy = 20 - rawid.iy(); // 0 to 19
165  int side = rawid.zside();
166  int iz = side;
167  if (side == -1)
168  iz = 0;
169  if (ix < 0 || ix > 19)
170  std::cout << " Pb in ix " << ix << std::endl;
171  if (iy < 0 || iy > 19)
172  std::cout << " Pb in iy " << iy << std::endl;
173  valEE[iz][ix][iy] = record[rawid].getStatusCode();
174  }
175  }
176  for (int k = 0; k < 2; k++) {
177  int iz = -1;
178  if (k == 1)
179  iz = 1;
180  fout << " Side : " << iz << std::endl;
181  for (int line = 0; line < 20; line++) {
182  for (int ix = 0; ix < 20; ix++) {
183  if (valEE[k][ix][line] < 0)
184  fout << " . ";
185  else
186  fout << setw(2) << valEE[k][ix][line] << " ";
187  }
188  fout << std::endl;
189  }
190  fout << std::endl;
191  }
192 
193  return;
194 }
static int readXML(const std::string &filename, EcalCondHeader &header, EcalDCSTowerStatus &record)
static EcalTrigTowerDetId detIdFromDenseIndex(uint32_t di)
const std::string DCSTowerStatus_tag("EcalDCSTowerStatus")
int zside() const
Definition: EcalScDetId.h:64
def dumpXML(db, tag, since, filename='dump.xml')
int ieta() const
get the tower ieta
void xercesTerminate()
Definition: Xerces.cc:23
static void plot(std::string, const EcalDCSTowerStatus &record)
static EcalScDetId unhashIndex(int hi)
Definition: EcalScDetId.h:117
void xercesInitialize()
Definition: Xerces.cc:18
void WriteNodeWithValue(xercesc::DOMNode *parentNode, const std::string &tag, const T &value)
write a node with
std::string toString(XMLCh const *toTranscode)
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
ZStr< XMLCh > uStr(char const *str)
int iy() const
Definition: EcalScDetId.h:76
const std::string DCSStatusCode_tag("DCSStatusCode")
Definition: DetId.h:17
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 int writeXML(const std::string &filename, const EcalCondHeader &header, const EcalDCSTowerStatus &record)
static bool validHashIndex(int hi)
Definition: EcalScDetId.h:139
xercesc::DOMElement * writeCell(xercesc::DOMNode *node, const DetId &detid)
Append a Cell node with attributes to.
static std::string dumpXML(const EcalCondHeader &header, const EcalDCSTowerStatus &record)
int iphi() const
get the tower iphi
const DetId readCellId(xercesc::DOMElement *node)
Assuming.
int ix() const
Definition: EcalScDetId.h:70