CMS 3D CMS Logo

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 
28 int
32 
33  std::cout << " TPGTowerStatus should not be filled out from an xml file ..." << std::endl;
35 
36  XercesDOMParser* parser = new XercesDOMParser;
37  parser->setValidationScheme( XercesDOMParser::Val_Never );
38  parser->setDoNamespaces( false );
39  parser->setDoSchema( false );
40 
41  parser->parse(filename.c_str());
42 
43  DOMDocument* xmlDoc = parser->getDocument();
44  if (!xmlDoc) {
45  std::cout << "EcalTPGTowerStatusXMLTranslator::Error parsing document" << std::endl;
46  return -1;
47  }
48 
49  DOMElement* elementRoot = xmlDoc->getDocumentElement();
50 
51  xuti::readHeader(elementRoot,header);
52 
53  /*
54  int chan = 0;
55  while(cellnode) {
56  int status = -1;
57  DetId detid = readCellId(dynamic_cast<DOMElement*>(cellnode));
58 
59  DOMNode* my_node = getChildNode(cellnode,TPGTowerStatusCode_tag);
60  GetNodeData(my_node, status);
61 
62  record[detid] = status;
63 
64  cellnode = cellnode->getNextSibling();
65 
66  while(cellnode && cellnode->getNodeType() != DOMNode::ELEMENT_NODE)
67  cellnode = cellnode->getNextSibling();
68  chan++;
69  }
70  */
71  delete parser;
73  return 0;
74 }
75 
76 int
78  const EcalCondHeader& header,
79  const EcalTPGTowerStatus& record){
81 
82  std::fstream fs(filename.c_str(),ios::out);
83  fs<< dumpXML(header,record);
84 
86 
87  return 0;
88 }
89 
91 
92  unique_ptr<DOMImplementation> impl( DOMImplementationRegistry::getDOMImplementation(cms::xerces::uStr("LS").ptr()));
93 
94  DOMLSSerializer* writer = impl->createLSSerializer();
95  if( writer->getDomConfig()->canSetParameter( XMLUni::fgDOMWRTFormatPrettyPrint, true ))
96  writer->getDomConfig()->setParameter( XMLUni::fgDOMWRTFormatPrettyPrint, true );
97 
98  DOMDocumentType* doctype = impl->createDocumentType(cms::xerces::uStr("XML").ptr(), 0, 0 );
99  DOMDocument * doc =
100  impl->createDocument( 0, cms::xerces::uStr(TPGTowerStatus_tag.c_str()).ptr(), doctype );
101 
102  DOMElement* root = doc->getDocumentElement();
103 
104  xuti::writeHeader(root,header);
105  std::cout << "EcalTPGTowerStatusXMLTranslator::dumpXML" << std::endl;
106  const EcalTPGTowerStatusMap &towerMap = record.getMap();
107  std::cout << " tower map size " << towerMap.size() << std::endl;
109  for(it = towerMap.begin(); it != towerMap.end(); ++it) {
110  if((*it).second > 0) {
111  EcalTrigTowerDetId ttId((*it).first);
112  std::cout << " TTDetId " << ttId << " eta " << ttId.ieta() << " phi " << ttId.iphi() << std::endl;
113  uint32_t rawid = ttId;
114  DOMElement* cellnode=writeCell(root,rawid);
116  }
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  for(int line = 0; line < 34; line++)
131  for(int iphi = 0; iphi < 72; iphi++)
132  valEB[line][iphi] = 0;
133 
134  const EcalTPGTowerStatusMap &towerMap = record.getMap();
135  std::cout << " tower map size " << towerMap.size() << std::endl;
137  for(it = towerMap.begin(); it != towerMap.end(); ++it) {
138  if((*it).second > 0) {
139  EcalTrigTowerDetId ttId((*it).first);
140  int ieta = ttId.ieta();
141  int line = 17 - ieta;
142  if(ieta < 0) line--;
143  int iphi = ttId.iphi() - 1; // 0 to 71
144  valEB[line][iphi] = (*it).second;
145  }
146  }
147  for(int line = 0; line < 34; line++) {
148  for(int iphi = 0; iphi < 72; iphi++)
149  fout << valEB[line][iphi] << " ";
150  fout << std::endl;
151  if(line == 16) fout << std::endl;
152  }
153  /*
154 
155  std::cout << " endcap size " << record.endcapItems().size() << std::endl;
156  if (!record.endcapItems().size()) return;
157  int valEE[2][20][20];
158  for(int k = 0 ; k < 2; k++ )
159  for(int ix = 0 ; ix < 20; ix++)
160  for(int iy = 0 ; iy < 20; iy++)
161  valEE[k][ix][iy] = -1;
162  for(uint cellid = 0;
163  cellid < EcalTrigTowerDetId::kEETotalTowers;
164  ++cellid) {
165  if(EcalScDetId::validHashIndex(cellid)) {
166  EcalScDetId rawid = EcalScDetId::unhashIndex(cellid);
167  int ix = rawid.ix() - 1; // 0 to 19
168  int iy = 20 - rawid.iy(); // 0 to 19
169  int side = rawid.zside();
170  int iz = side;
171  if(side == -1) iz = 0;
172  if(ix < 0 || ix > 19) std::cout << " Pb in ix " << ix << std::endl;
173  if(iy < 0 || iy > 19) std::cout << " Pb in iy " << iy << std::endl;
174  valEE[iz][ix][iy] = record[rawid].getStatusCode();
175  }
176  }
177  for(int k = 0 ; k < 2; k++ ) {
178  int iz = -1;
179  if(k == 1) 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) fout << ". ";
184  else fout << valEE[k][ix][line] << " ";
185  }
186  fout << std::endl;
187  }
188  fout << std::endl;
189  }
190  */
191  return;
192 }
std::map< uint32_t, uint16_t >::const_iterator EcalTPGTowerStatusMapIterator
std::map< uint32_t, uint16_t > EcalTPGTowerStatusMap
def dumpXML(db, tag, since, filename='dump.xml')
JetCorrectorParameters::Record record
Definition: classes.h:7
void xercesTerminate()
Definition: Xerces.cc:23
void xercesInitialize()
Definition: Xerces.cc:18
unsigned ttId(DetId 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
static void plot(std::string, const EcalTPGTowerStatus &record)
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)