CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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>
8 #include <xercesc/util/XMLString.hpp>
9 #include <xercesc/sax/SAXException.hpp>
10 #include <xercesc/framework/LocalFileFormatTarget.hpp>
11 
15 
19 
22 
23 using namespace XERCES_CPP_NAMESPACE;
24 using namespace xuti;
25 using namespace std;
26 
28  EcalCondHeader& header,
30 
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){
77  std::fstream fs(filename.c_str(),ios::out);
78  fs<< dumpXML(header,record);
79  return 0;
80 }
81 
82 
84 
86  DOMImplementation* impl =
87  DOMImplementationRegistry::getDOMImplementation(fromNative("LS").c_str());
88 
89  DOMWriter* writer =static_cast<DOMImplementationLS*>(impl)->createDOMWriter( );
90  writer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true);
91 
92  DOMDocumentType* doctype = impl->createDocumentType(fromNative("XML").c_str(), 0, 0 );
93  DOMDocument * doc =
94  impl->createDocument( 0, fromNative(TPGTowerStatus_tag).c_str(), doctype );
95 
96  doc->setEncoding(fromNative("UTF-8").c_str() );
97  doc->setStandalone(true);
98  doc->setVersion(fromNative("1.0").c_str() );
99 
100  DOMElement* root = doc->getDocumentElement();
101 
102  xuti::writeHeader(root,header);
103  std::cout << "EcalTPGTowerStatusXMLTranslator::dumpXML" << std::endl;
104  const EcalTPGTowerStatusMap &towerMap = record.getMap();
105  std::cout << " tower map size " << towerMap.size() << std::endl;
107  for(it = towerMap.begin(); it != towerMap.end(); ++it) {
108  if((*it).second > 0) {
109  EcalTrigTowerDetId ttId((*it).first);
110  std::cout << " TTDetId " << ttId << " eta " << ttId.ieta() << " phi " << ttId.iphi() << std::endl;
111  uint32_t rawid = ttId;
112  DOMElement* cellnode=writeCell(root,rawid);
114  }
115  }
116 
117  std::string dump = toNative(writer->writeToString(*root));
118  doc->release();
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) line--;
138  int iphi = ttId.iphi() - 1; // 0 to 71
139  valEB[line][iphi] = (*it).second;
140  }
141  }
142  for(int line = 0; line < 34; line++) {
143  for(int iphi = 0; iphi < 72; iphi++)
144  fout << valEB[line][iphi] << " ";
145  fout << std::endl;
146  if(line == 16) fout << std::endl;
147  }
148  /*
149 
150  std::cout << " endcap size " << record.endcapItems().size() << std::endl;
151  if (!record.endcapItems().size()) return;
152  int valEE[2][20][20];
153  for(int k = 0 ; k < 2; k++ )
154  for(int ix = 0 ; ix < 20; ix++)
155  for(int iy = 0 ; iy < 20; iy++)
156  valEE[k][ix][iy] = -1;
157  for(uint cellid = 0;
158  cellid < EcalTrigTowerDetId::kEETotalTowers;
159  ++cellid) {
160  if(EcalScDetId::validHashIndex(cellid)) {
161  EcalScDetId rawid = EcalScDetId::unhashIndex(cellid);
162  int ix = rawid.ix() - 1; // 0 to 19
163  int iy = 20 - rawid.iy(); // 0 to 19
164  int side = rawid.zside();
165  int iz = side;
166  if(side == -1) iz = 0;
167  if(ix < 0 || ix > 19) std::cout << " Pb in ix " << ix << std::endl;
168  if(iy < 0 || iy > 19) std::cout << " Pb in iy " << iy << std::endl;
169  valEE[iz][ix][iy] = record[rawid].getStatusCode();
170  }
171  }
172  for(int k = 0 ; k < 2; k++ ) {
173  int iz = -1;
174  if(k == 1) iz = 1;
175  fout << " Side : " << iz << std::endl;
176  for(int line = 0; line < 20; line++) {
177  for(int ix = 0 ; ix < 20; ix++) {
178  if(valEE[k][ix][line] < 0) fout << ". ";
179  else fout << valEE[k][ix][line] << " ";
180  }
181  fout << std::endl;
182  }
183  fout << std::endl;
184  }
185  */
186  return;
187 }
std::map< uint32_t, uint16_t >::const_iterator EcalTPGTowerStatusMapIterator
std::map< uint32_t, uint16_t > EcalTPGTowerStatusMap
JetCorrectorParameters::Record record
Definition: classes.h:7
void xercesTerminate()
Definition: Xerces.cc:22
void xercesInitialize()
Definition: Xerces.cc:17
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")
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
tuple doc
Definition: asciidump.py:381
tuple out
Definition: dbtoconf.py:99
int iphi() const
get the tower iphi
const std::map< uint32_t, uint16_t > & getMap() const
tuple filename
Definition: lut2db_cfg.py:20
XercesString fromNative(const char *str)
Definition: XercesString.h:31
static void plot(std::string, const EcalTPGTowerStatus &record)
tuple cout
Definition: gather_cfg.py:121
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)
std::string toNative(const XMLCh *str)
Definition: XercesString.h:42
string root
initialization
Definition: dbtoconf.py:70