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 
26  std::cout << " DCSTowerStatus 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 << "EcalDCSTowerStatusXMLTranslator::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,DCSStatusCode_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 
71  const EcalCondHeader& header,
72  const EcalDCSTowerStatus& record){
74 
75  std::fstream fs(filename.c_str(),ios::out);
76  fs<< dumpXML(header,record);
77 
79 
80  return 0;
81 }
82 
84 
85  unique_ptr<DOMImplementation> impl( DOMImplementationRegistry::getDOMImplementation(cms::xerces::uStr("LS").ptr()));
86 
87  DOMLSSerializer* writer = impl->createLSSerializer();
88  if( writer->getDomConfig()->canSetParameter( XMLUni::fgDOMWRTFormatPrettyPrint, true ))
89  writer->getDomConfig()->setParameter( XMLUni::fgDOMWRTFormatPrettyPrint, true );
90 
91  DOMDocumentType* doctype = impl->createDocumentType( cms::xerces::uStr("XML").ptr(), nullptr, nullptr );
92  DOMDocument* doc = impl->createDocument( nullptr, cms::xerces::uStr(DCSTowerStatus_tag.c_str()).ptr(), doctype );
93  DOMElement* root = doc->getDocumentElement();
94 
95  xuti::writeHeader(root,header);
96  std::cout << " barrel size " << record.barrelItems().size() << std::endl;
97  if (record.barrelItems().empty()) return std::string();
98  for(uint cellid = 0;
100  ++cellid) {
101  uint32_t rawid = EcalTrigTowerDetId::detIdFromDenseIndex(cellid);
102  if (record.find(rawid) == record.end()) continue;
103  DOMElement* cellnode=writeCell(root,rawid);
104 
105  WriteNodeWithValue(cellnode, DCSStatusCode_tag, record[rawid].getStatusCode());
106  }
107 
108  std::cout << " endcap size " << record.endcapItems().size() << std::endl;
109  if (record.endcapItems().empty()) return std::string();
110  for(uint cellid = 0;
112  ++cellid) {
113  if(!EcalScDetId::validHashIndex(cellid)) continue;
114  uint32_t rawid = EcalScDetId::unhashIndex(cellid);
115 
116  if (record.find(rawid) == record.end()) continue;
117  DOMElement* cellnode=writeCell(root,rawid);
118 
119  WriteNodeWithValue(cellnode, DCSStatusCode_tag, record[rawid].getStatusCode());
120  }
121 
122  std::string dump = cms::xerces::toString( writer->writeToString( root ));
123  doc->release();
124  doctype->release();
125  writer->release();
126 
127  return dump;
128 }
129 
131  std::ofstream fout(fn.c_str());
132  int valEB[34][72];
133  std::cout << " barrel size " << record.barrelItems().size() << std::endl;
134  if (record.barrelItems().empty()) return;
135  for(uint cellid = 0;
137  ++cellid) {
139  if (record.find(rawid) == record.end()) continue;
140  int ieta = rawid.ieta();
141  int line = 17 - ieta;
142  if(ieta < 0) line--;
143  int iphi = rawid.iphi() - 1; // 0 to 71
144  valEB[line][iphi] = record[rawid].getStatusCode();
145  }
146  for(int line = 0; line < 34; line++) {
147  for(int iphi = 0; iphi < 72; iphi++)
148  fout << valEB[line][iphi] << " ";
149  fout << std::endl;
150  if(line == 16) fout << std::endl;
151  }
152 
153  std::cout << " endcap size " << record.endcapItems().size() << std::endl;
154  if (record.endcapItems().empty()) 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;
162  ++cellid) {
163  if(EcalScDetId::validHashIndex(cellid)) {
164  EcalScDetId rawid = EcalScDetId::unhashIndex(cellid);
165  int ix = rawid.ix() - 1; // 0 to 19
166  int iy = 20 - rawid.iy(); // 0 to 19
167  int side = rawid.zside();
168  int iz = side;
169  if(side == -1) iz = 0;
170  if(ix < 0 || ix > 19) std::cout << " Pb in ix " << ix << std::endl;
171  if(iy < 0 || iy > 19) std::cout << " Pb in iy " << iy << std::endl;
172  valEE[iz][ix][iy] = record[rawid].getStatusCode();
173  }
174  }
175  for(int k = 0 ; k < 2; k++ ) {
176  int iz = -1;
177  if(k == 1) iz = 1;
178  fout << " Side : " << iz << std::endl;
179  for(int line = 0; line < 20; line++) {
180  for(int ix = 0 ; ix < 20; ix++) {
181  if(valEE[k][ix][line] < 0) fout << " . ";
182  else fout << setw(2) << valEE[k][ix][line] << " ";
183  }
184  fout << std::endl;
185  }
186  fout << std::endl;
187  }
188 
189  return;
190 }
static int readXML(const std::string &filename, EcalCondHeader &header, EcalDCSTowerStatus &record)
static EcalTrigTowerDetId detIdFromDenseIndex(uint32_t di)
const std::string DCSTowerStatus_tag("EcalDCSTowerStatus")
def dumpXML(db, tag, since, filename='dump.xml')
JetCorrectorParameters::Record record
Definition: classes.h:7
void xercesTerminate()
Definition: Xerces.cc:23
static void plot(std::string, const EcalDCSTowerStatus &record)
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
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 DCSStatusCode_tag("DCSStatusCode")
int k[5][pyjets_maxn]
Definition: DetId.h:18
int iphi() const
get the tower iphi
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
def uint(string)
static int writeXML(const std::string &filename, const EcalCondHeader &header, const EcalDCSTowerStatus &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
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)
const DetId readCellId(xercesc::DOMElement *node)
Assuming.