CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
EcalTPGTowerStatusXMLTranslator.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 
20 
23 
24 using namespace XERCES_CPP_NAMESPACE;
25 using namespace xuti;
26 using namespace std;
27 
29  EcalCondHeader& header,
31  std::cout << " TPGTowerStatus should not be filled out from an xml file ..." << std::endl;
33 
34  XercesDOMParser* parser = new XercesDOMParser;
35  parser->setValidationScheme(XercesDOMParser::Val_Never);
36  parser->setDoNamespaces(false);
37  parser->setDoSchema(false);
38 
39  parser->parse(filename.c_str());
40 
41  DOMDocument* xmlDoc = parser->getDocument();
42  if (!xmlDoc) {
43  std::cout << "EcalTPGTowerStatusXMLTranslator::Error parsing document" << std::endl;
44  return -1;
45  }
46 
47  DOMElement* elementRoot = xmlDoc->getDocumentElement();
48 
49  xuti::readHeader(elementRoot, header);
50 
51  /*
52  int chan = 0;
53  while(cellnode) {
54  int status = -1;
55  DetId detid = readCellId(dynamic_cast<DOMElement*>(cellnode));
56 
57  DOMNode* my_node = getChildNode(cellnode,TPGTowerStatusCode_tag);
58  GetNodeData(my_node, status);
59 
60  record[detid] = status;
61 
62  cellnode = cellnode->getNextSibling();
63 
64  while(cellnode && cellnode->getNodeType() != DOMNode::ELEMENT_NODE)
65  cellnode = cellnode->getNextSibling();
66  chan++;
67  }
68  */
69  delete parser;
71  return 0;
72 }
73 
75  const EcalCondHeader& header,
76  const EcalTPGTowerStatus& record) {
78 
79  std::fstream fs(filename.c_str(), ios::out);
80  fs << dumpXML(header, record);
81 
83 
84  return 0;
85 }
86 
88  unique_ptr<DOMImplementation> impl(DOMImplementationRegistry::getDOMImplementation(cms::xerces::uStr("LS").ptr()));
89 
90  DOMLSSerializer* writer = impl->createLSSerializer();
91  if (writer->getDomConfig()->canSetParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true))
92  writer->getDomConfig()->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true);
93 
94  DOMDocumentType* doctype = impl->createDocumentType(cms::xerces::uStr("XML").ptr(), nullptr, nullptr);
95  DOMDocument* doc = impl->createDocument(nullptr, cms::xerces::uStr(TPGTowerStatus_tag.c_str()).ptr(), doctype);
96 
97  DOMElement* root = doc->getDocumentElement();
98 
99  xuti::writeHeader(root, header);
100  std::cout << "EcalTPGTowerStatusXMLTranslator::dumpXML" << std::endl;
101  const EcalTPGTowerStatusMap& towerMap = record.getMap();
102  std::cout << " tower map size " << towerMap.size() << std::endl;
104  for (it = towerMap.begin(); it != towerMap.end(); ++it) {
105  if ((*it).second > 0) {
106  EcalTrigTowerDetId ttId((*it).first);
107  std::cout << " TTDetId " << ttId << " eta " << ttId.ieta() << " phi " << ttId.iphi() << std::endl;
108  uint32_t rawid = ttId;
109  DOMElement* cellnode = writeCell(root, rawid);
111  }
112  }
113 
114  std::string dump = cms::xerces::toString(writer->writeToString(root));
115  doc->release();
116  doctype->release();
117  writer->release();
118 
119  return dump;
120 }
121 
123  std::ofstream fout(fn.c_str());
124  int valEB[34][72];
125  for (int line = 0; line < 34; line++)
126  for (int iphi = 0; iphi < 72; iphi++)
127  valEB[line][iphi] = 0;
128 
129  const EcalTPGTowerStatusMap& towerMap = record.getMap();
130  std::cout << " tower map size " << towerMap.size() << std::endl;
132  for (it = towerMap.begin(); it != towerMap.end(); ++it) {
133  if ((*it).second > 0) {
134  EcalTrigTowerDetId ttId((*it).first);
135  int ieta = ttId.ieta();
136  int line = 17 - ieta;
137  if (ieta < 0)
138  line--;
139  int iphi = ttId.iphi() - 1; // 0 to 71
140  valEB[line][iphi] = (*it).second;
141  }
142  }
143  for (int line = 0; line < 34; line++) {
144  for (int iphi = 0; iphi < 72; iphi++)
145  fout << valEB[line][iphi] << " ";
146  fout << std::endl;
147  if (line == 16)
148  fout << std::endl;
149  }
150  /*
151 
152  std::cout << " endcap size " << record.endcapItems().size() << std::endl;
153  if (!record.endcapItems().size()) return;
154  int valEE[2][20][20];
155  for(int k = 0 ; k < 2; k++ )
156  for(int ix = 0 ; ix < 20; ix++)
157  for(int iy = 0 ; iy < 20; iy++)
158  valEE[k][ix][iy] = -1;
159  for(uint cellid = 0;
160  cellid < EcalTrigTowerDetId::kEETotalTowers;
161  ++cellid) {
162  if(EcalScDetId::validHashIndex(cellid)) {
163  EcalScDetId rawid = EcalScDetId::unhashIndex(cellid);
164  int ix = rawid.ix() - 1; // 0 to 19
165  int iy = 20 - rawid.iy(); // 0 to 19
166  int side = rawid.zside();
167  int iz = side;
168  if(side == -1) iz = 0;
169  if(ix < 0 || ix > 19) std::cout << " Pb in ix " << ix << std::endl;
170  if(iy < 0 || iy > 19) std::cout << " Pb in iy " << iy << std::endl;
171  valEE[iz][ix][iy] = record[rawid].getStatusCode();
172  }
173  }
174  for(int k = 0 ; k < 2; k++ ) {
175  int iz = -1;
176  if(k == 1) iz = 1;
177  fout << " Side : " << iz << std::endl;
178  for(int line = 0; line < 20; line++) {
179  for(int ix = 0 ; ix < 20; ix++) {
180  if(valEE[k][ix][line] < 0) fout << ". ";
181  else fout << valEE[k][ix][line] << " ";
182  }
183  fout << std::endl;
184  }
185  fout << std::endl;
186  }
187  */
188  return;
189 }
std::map< uint32_t, uint16_t >::const_iterator EcalTPGTowerStatusMapIterator
std::map< uint32_t, uint16_t > EcalTPGTowerStatusMap
void xercesTerminate()
Definition: Xerces.cc:23
void xercesInitialize()
Definition: Xerces.cc:18
unsigned ttId(DetId const &, EcalElectronicsMapping const *)
void WriteNodeWithValue(xercesc::DOMNode *parentNode, const std::string &tag, const T &value)
write a node with
int ieta() const
get the tower ieta
const std::string TPGTowerStatus_tag("EcalTPGTowerStatus")
std::string toString(XMLCh const *toTranscode)
void readHeader(xercesc::DOMNode *parentNode, EcalCondHeader &header)
read header from
static std::string dumpXML(const EcalCondHeader &header, const EcalTPGTowerStatus &record)
void writeHeader(xercesc::DOMNode *parentNode, const EcalCondHeader &header)
write
ZStr< XMLCh > uStr(char const *str)
int iphi() const
get the tower iphi
const std::map< uint32_t, uint16_t > & getMap() const
tuple filename
Definition: lut2db_cfg.py:20
static void plot(std::string, const EcalTPGTowerStatus &record)
tuple cout
Definition: gather_cfg.py:144
xercesc::DOMElement * writeCell(xercesc::DOMNode *node, const DetId &detid)
Append a Cell node with attributes to.
static int readXML(const std::string &filename, EcalCondHeader &header, EcalTPGTowerStatus &record)
static int writeXML(const std::string &filename, const EcalCondHeader &header, const EcalTPGTowerStatus &record)
tuple dump
OutputFilePath = cms.string(&#39;/tmp/zhokin/&#39;), OutputFileExt = cms.string(&#39;&#39;),.