CMS 3D CMS Logo

EcalDAQTowerStatusXMLTranslator.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>
9 #include <xercesc/util/XMLString.hpp>
10 #include <xercesc/sax/SAXException.hpp>
11 #include <xercesc/framework/LocalFileFormatTarget.hpp>
12 
16 
17 using namespace XERCES_CPP_NAMESPACE;
18 using namespace xuti;
19 using namespace std;
20 
24  std::cout << " DAQTowerStatus should not be filled out from an xml file ..." << std::endl;
26 
27  XercesDOMParser* parser = new XercesDOMParser;
28  parser->setValidationScheme(XercesDOMParser::Val_Never);
29  parser->setDoNamespaces(false);
30  parser->setDoSchema(false);
31 
32  parser->parse(filename.c_str());
33 
34  DOMDocument* xmlDoc = parser->getDocument();
35  if (!xmlDoc) {
36  std::cout << "EcalDAQTowerStatusXMLTranslator::Error parsing document" << std::endl;
37  return -1;
38  }
39 
40  DOMElement* elementRoot = xmlDoc->getDocumentElement();
41 
42  xuti::readHeader(elementRoot, header);
43 
44  DOMNode* cellnode = getChildNode(elementRoot, Cell_tag);
45 
46  while (cellnode) {
47  int status = -1;
48  DetId detid = readCellId(dynamic_cast<DOMElement*>(cellnode));
49 
50  DOMNode* my_node = getChildNode(cellnode, DAQStatusCode_tag);
51  GetNodeData(my_node, status);
52 
53  record[detid] = status;
54 
55  cellnode = cellnode->getNextSibling();
56 
57  while (cellnode && cellnode->getNodeType() != DOMNode::ELEMENT_NODE)
58  cellnode = cellnode->getNextSibling();
59  }
60 
61  delete parser;
63  return 0;
64 }
65 
67  const EcalCondHeader& header,
68  const EcalDAQTowerStatus& record) {
70 
71  std::fstream fs(filename.c_str(), ios::out);
72  fs << dumpXML(header, record);
73 
75 
76  return 0;
77 }
78 
80  unique_ptr<DOMImplementation> impl(DOMImplementationRegistry::getDOMImplementation(cms::xerces::uStr("LS").ptr()));
81 
82  DOMLSSerializer* writer = impl->createLSSerializer();
83  if (writer->getDomConfig()->canSetParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true))
84  writer->getDomConfig()->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true);
85 
86  DOMDocumentType* doctype = impl->createDocumentType(cms::xerces::uStr("XML").ptr(), nullptr, nullptr);
87  DOMDocument* doc = impl->createDocument(nullptr, cms::xerces::uStr(DAQTowerStatus_tag.c_str()).ptr(), doctype);
88 
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, DAQStatusCode_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, DAQStatusCode_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 << valEE[k][ix][line] << " ";
187  }
188  fout << std::endl;
189  }
190  fout << std::endl;
191  }
192 
193  return;
194 }
static EcalTrigTowerDetId detIdFromDenseIndex(uint32_t di)
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
const std::string DAQTowerStatus_tag("EcalDAQTowerStatus")
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
static int writeXML(const std::string &filename, const EcalCondHeader &header, const EcalDAQTowerStatus &record)
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 DAQStatusCode_tag("DAQStatusCode")
Definition: DetId.h:17
static int readXML(const std::string &filename, EcalCondHeader &header, EcalDAQTowerStatus &record)
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 void plot(std::string, const EcalDAQTowerStatus &record)
static bool validHashIndex(int hi)
Definition: EcalScDetId.h:139
static std::string dumpXML(const EcalCondHeader &header, const EcalDAQTowerStatus &record)
xercesc::DOMElement * writeCell(xercesc::DOMNode *node, const DetId &detid)
Append a Cell node with attributes to.
int iphi() const
get the tower iphi
const DetId readCellId(xercesc::DOMElement *node)
Assuming.
int ix() const
Definition: EcalScDetId.h:70