CMS 3D CMS Logo

EcalTPGCrystalStatusXMLTranslator.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 
15 
19 
22 
23 using namespace XERCES_CPP_NAMESPACE;
24 using namespace xuti;
25 using namespace std;
26 
28  const EcalCondHeader& header,
31 
32  std::fstream fs(filename.c_str(),ios::out);
33  fs<< dumpXML(header,record);
34 
36 
37  return 0;
38 }
39 
41 
42  unique_ptr<DOMImplementation> impl( DOMImplementationRegistry::getDOMImplementation(cms::xerces::uStr("LS").ptr()));
43 
44  DOMLSSerializer* writer = impl->createLSSerializer();
45  if( writer->getDomConfig()->canSetParameter( XMLUni::fgDOMWRTFormatPrettyPrint, true ))
46  writer->getDomConfig()->setParameter( XMLUni::fgDOMWRTFormatPrettyPrint, true );
47  DOMDocumentType* doctype = impl->createDocumentType(cms::xerces::uStr("XML").ptr(), nullptr, nullptr );
48  DOMDocument * doc =
49  impl->createDocument( nullptr, cms::xerces::uStr(TPGCrystalStatus_tag.c_str()).ptr(), doctype );
50 
51  DOMElement* root = doc->getDocumentElement();
52 
53  xuti::writeHeader(root,header);
54 
55  const int kSides = 2;
56  const int kBarlRings = EBDetId::MAX_IETA;
57  const int kBarlWedges = EBDetId::MAX_IPHI;
58  const int kEndcWedgesX = EEDetId::IX_MAX;
59  const int kEndcWedgesY = EEDetId::IY_MAX;
60 
61  std::cout << "EcalTPGCrystalStatusXMLTranslator::dumpXML" << std::endl;
62  for (int sign=0; sign < kSides; sign++) {
63  int thesign = sign==1 ? 1:-1;
64 
65  for (int ieta=0; ieta<kBarlRings; ieta++) {
66  for (int iphi=0; iphi<kBarlWedges; iphi++) {
67  EBDetId id((ieta+1)*thesign, iphi+1);
68  if(record[id.rawId()].getStatusCode() > 0) {
69  DOMElement* cellnode=writeCell(root, id);
70  WriteNodeWithValue(cellnode, TPGCrystalStatus_tag, record[id.rawId()].getStatusCode());
71  }
72  } // iphi
73  } // ieta
74 
75  for (int ix=0; ix<kEndcWedgesX; ix++) {
76  for (int iy=0; iy<kEndcWedgesY; iy++) {
77  if (! EEDetId::validDetId(ix+1,iy+1,thesign)) continue;
78  EEDetId id(ix+1,iy+1,thesign);
79  if(record[id.rawId()].getStatusCode() > 0) {
80  DOMElement* cellnode=writeCell(root, id);
81  WriteNodeWithValue(cellnode, TPGCrystalStatus_tag, record[id.rawId()].getStatusCode());
82  }
83  } // iy
84  } // ix
85  } // side
86 
87  std::string dump = cms::xerces::toString(writer->writeToString( root ));
88  doc->release();
89  doctype->release();
90  writer->release();
91 
92  return dump;
93 }
def dumpXML(db, tag, since, filename='dump.xml')
static std::string dumpXML(const EcalCondHeader &header, const EcalTPGCrystalStatus &record)
JetCorrectorParameters::Record record
Definition: classes.h:7
void xercesTerminate()
Definition: Xerces.cc:23
static const int kBarlRings
static const int kSides
void xercesInitialize()
Definition: Xerces.cc:18
void WriteNodeWithValue(xercesc::DOMNode *parentNode, const std::string &tag, const T &value)
write a node with
static const int kBarlWedges
std::string toString(XMLCh const *toTranscode)
static const int kEndcWedgesX
void writeHeader(xercesc::DOMNode *parentNode, const EcalCondHeader &header)
write
const std::string TPGCrystalStatus_tag("EcalTPGCrystalStatus")
ZStr< XMLCh > uStr(char const *str)
static const int IX_MAX
Definition: EEDetId.h:302
Definition: dump.py:1
static const int MAX_IPHI
Definition: EBDetId.h:144
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
Definition: EEDetId.h:248
static const int MAX_IETA
Definition: EBDetId.h:143
static const int IY_MAX
Definition: EEDetId.h:306
static int writeXML(const std::string &filename, const EcalCondHeader &header, const EcalTPGCrystalStatus &record)
xercesc::DOMElement * writeCell(xercesc::DOMNode *node, const DetId &detid)
Append a Cell node with attributes to.
static const int kEndcWedgesY