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 
21 int
25 
26  std::cout << " DAQTowerStatus should not be filled out from an xml file ..." << std::endl;
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 << "EcalDAQTowerStatusXMLTranslator::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  int status = -1;
51  DetId detid = readCellId(dynamic_cast<DOMElement*>(cellnode));
52 
53  DOMNode* my_node = getChildNode(cellnode,DAQStatusCode_tag);
54  GetNodeData(my_node, status);
55 
56  record[detid] = status;
57 
58  cellnode = cellnode->getNextSibling();
59 
60  while(cellnode && cellnode->getNodeType() != DOMNode::ELEMENT_NODE)
61  cellnode = cellnode->getNextSibling();
62  chan++;
63  }
64 
65  delete parser;
67  return 0;
68  }
69 
70 int
72  const EcalCondHeader& header,
73  const EcalDAQTowerStatus& record) {
74 
76 
77  std::fstream fs(filename.c_str(),ios::out);
78  fs<< dumpXML(header,record);
79 
81 
82  return 0;
83 }
84 
85 
88 
89  unique_ptr<DOMImplementation> impl( DOMImplementationRegistry::getDOMImplementation( cms::xerces::uStr("LS").ptr()));
90 
91  DOMLSSerializer* writer = impl->createLSSerializer();
92  if( writer->getDomConfig()->canSetParameter( XMLUni::fgDOMWRTFormatPrettyPrint, true ))
93  writer->getDomConfig()->setParameter( XMLUni::fgDOMWRTFormatPrettyPrint, true );
94 
95  DOMDocumentType* doctype = impl->createDocumentType( cms::xerces::uStr("XML").ptr(), nullptr, nullptr );
96  DOMDocument* doc =
97  impl->createDocument( nullptr, cms::xerces::uStr( DAQTowerStatus_tag.c_str()).ptr(), doctype );
98 
99  DOMElement* root = doc->getDocumentElement();
100 
101  xuti::writeHeader(root,header);
102  std::cout << " barrel size " << record.barrelItems().size() << std::endl;
103  if (record.barrelItems().empty()) return std::string();
104  for(uint cellid = 0;
106  ++cellid) {
107  uint32_t rawid = EcalTrigTowerDetId::detIdFromDenseIndex(cellid);
108  if (record.find(rawid) == record.end()) continue;
109  DOMElement* cellnode=writeCell(root,rawid);
110 
111  WriteNodeWithValue(cellnode, DAQStatusCode_tag, record[rawid].getStatusCode());
112  }
113 
114  std::cout << " endcap size " << record.endcapItems().size() << std::endl;
115  if (record.endcapItems().empty()) return std::string();
116  for(uint cellid = 0;
118  ++cellid) {
119  if(!EcalScDetId::validHashIndex(cellid)) continue;
120  uint32_t rawid = EcalScDetId::unhashIndex(cellid);
121 
122  if (record.find(rawid) == record.end()) continue;
123  DOMElement* cellnode = writeCell(root,rawid);
124 
125  WriteNodeWithValue(cellnode, DAQStatusCode_tag, record[rawid].getStatusCode());
126  }
127 
128  std::string dump = cms::xerces::toString(writer->writeToString( root ));
129  doc->release();
130  doctype->release();
131  writer->release();
132 
133  return dump;
134 }
135 
137  std::ofstream fout(fn.c_str());
138  int valEB[34][72];
139  std::cout << " barrel size " << record.barrelItems().size() << std::endl;
140  if (record.barrelItems().empty()) return;
141  for(uint cellid = 0;
143  ++cellid) {
145  if (record.find(rawid) == record.end()) continue;
146  int ieta = rawid.ieta();
147  int line = 17 - ieta;
148  if(ieta < 0) line--;
149  int iphi = rawid.iphi() - 1; // 0 to 71
150  valEB[line][iphi] = record[rawid].getStatusCode();
151  }
152  for(int line = 0; line < 34; line++) {
153  for(int iphi = 0; iphi < 72; iphi++)
154  fout << valEB[line][iphi] << " ";
155  fout << std::endl;
156  if(line == 16) fout << std::endl;
157  }
158 
159  std::cout << " endcap size " << record.endcapItems().size() << std::endl;
160  if (record.endcapItems().empty()) return;
161  int valEE[2][20][20];
162  for(int k = 0 ; k < 2; k++ )
163  for(int ix = 0 ; ix < 20; ix++)
164  for(int iy = 0 ; iy < 20; iy++)
165  valEE[k][ix][iy] = -1;
166  for(uint cellid = 0;
168  ++cellid) {
169  if(EcalScDetId::validHashIndex(cellid)) {
170  EcalScDetId rawid = EcalScDetId::unhashIndex(cellid);
171  int ix = rawid.ix() - 1; // 0 to 19
172  int iy = 20 - rawid.iy(); // 0 to 19
173  int side = rawid.zside();
174  int iz = side;
175  if(side == -1) iz = 0;
176  if(ix < 0 || ix > 19) std::cout << " Pb in ix " << ix << std::endl;
177  if(iy < 0 || iy > 19) std::cout << " Pb in iy " << iy << std::endl;
178  valEE[iz][ix][iy] = record[rawid].getStatusCode();
179  }
180  }
181  for(int k = 0 ; k < 2; k++ ) {
182  int iz = -1;
183  if(k == 1) iz = 1;
184  fout << " Side : " << iz << std::endl;
185  for(int line = 0; line < 20; line++) {
186  for(int ix = 0 ; ix < 20; ix++) {
187  if(valEE[k][ix][line] < 0) fout << ". ";
188  else fout << valEE[k][ix][line] << " ";
189  }
190  fout << std::endl;
191  }
192  fout << std::endl;
193  }
194 
195  return;
196 }
static EcalTrigTowerDetId detIdFromDenseIndex(uint32_t di)
def dumpXML(db, tag, since, filename='dump.xml')
JetCorrectorParameters::Record record
Definition: classes.h:7
void xercesTerminate()
Definition: Xerces.cc:23
const std::string DAQTowerStatus_tag("EcalDAQTowerStatus")
static EcalScDetId unhashIndex(int hi)
Definition: EcalScDetId.h:118
void xercesInitialize()
Definition: Xerces.cc:18
const_iterator find(uint32_t rawId) const
void WriteNodeWithValue(xercesc::DOMNode *parentNode, const std::string &tag, const T &value)
write a node with
int ieta() const
get the tower ieta
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
int ix() const
Definition: EcalScDetId.h:71
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:77
const std::string DAQStatusCode_tag("DAQStatusCode")
int k[5][pyjets_maxn]
Definition: DetId.h:18
int iphi() const
get the tower iphi
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)
int zside() const
Definition: EcalScDetId.h:65
chan
lumi = TPaveText(lowX+0.38, lowY+0.061, lowX+0.45, lowY+0.161, "NDC") lumi.SetBorderSize( 0 ) lumi...
static bool validHashIndex(int hi)
Definition: EcalScDetId.h:140
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.
const DetId readCellId(xercesc::DOMElement *node)
Assuming.