CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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>
8 #include <xercesc/util/XMLString.hpp>
9 #include <xercesc/sax/SAXException.hpp>
10 #include <xercesc/framework/LocalFileFormatTarget.hpp>
11 
15 
16 using namespace XERCES_CPP_NAMESPACE;
17 using namespace xuti;
18 using namespace std;
19 
21  EcalCondHeader& header,
23 
24  std::cout << " DAQTowerStatus should not be filled out from an xml file ..." << std::endl;
26 
27  XercesDOMParser* parser = new XercesDOMParser;
28  parser->setValidationScheme( XercesDOMParser::Val_Never );
29  parser->setDoNamespaces( false );
30  parser->setDoSchema( false );
31 
32  parser->parse(filename.c_str());
33 
34  DOMDocument* xmlDoc = parser->getDocument();
35  if (!xmlDoc) {
36  std::cout << "EcalDAQTowerStatusXMLTranslator::Error parsing document" << std::endl;
37  return -1;
38  }
39 
40  DOMElement* elementRoot = xmlDoc->getDocumentElement();
41 
42  xuti::readHeader(elementRoot,header);
43 
44  DOMNode * cellnode = getChildNode(elementRoot,Cell_tag);
45 
46  int chan = 0;
47  while(cellnode) {
48  int status = -1;
49  DetId detid = readCellId(dynamic_cast<DOMElement*>(cellnode));
50 
51  DOMNode* my_node = getChildNode(cellnode,DAQStatusCode_tag);
52  GetNodeData(my_node, status);
53 
54  record[detid] = status;
55 
56  cellnode = cellnode->getNextSibling();
57 
58  while(cellnode && cellnode->getNodeType() != DOMNode::ELEMENT_NODE)
59  cellnode = cellnode->getNextSibling();
60  chan++;
61  }
62 
63  delete parser;
65  return 0;
66  }
67 
69  const EcalCondHeader& header,
70  const EcalDAQTowerStatus& record){
71  std::fstream fs(filename.c_str(),ios::out);
72  fs<< dumpXML(header,record);
73  return 0;
74 }
75 
76 
78 
80  DOMImplementation* impl =
81  DOMImplementationRegistry::getDOMImplementation(fromNative("LS").c_str());
82 
83  DOMWriter* writer =static_cast<DOMImplementationLS*>(impl)->createDOMWriter( );
84  writer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true);
85 
86  DOMDocumentType* doctype = impl->createDocumentType(fromNative("XML").c_str(), 0, 0 );
87  DOMDocument * doc =
88  impl->createDocument( 0, fromNative(DAQTowerStatus_tag).c_str(), doctype );
89 
90  doc->setEncoding(fromNative("UTF-8").c_str() );
91  doc->setStandalone(true);
92  doc->setVersion(fromNative("1.0").c_str() );
93 
94  DOMElement* root = doc->getDocumentElement();
95 
96  xuti::writeHeader(root,header);
97  std::cout << " barrel size " << record.barrelItems().size() << std::endl;
98  if (!record.barrelItems().size()) return std::string();
99  for(uint cellid = 0;
101  ++cellid) {
102  uint32_t rawid = EcalTrigTowerDetId::detIdFromDenseIndex(cellid);
103  if (record.find(rawid) == record.end()) continue;
104  DOMElement* cellnode=writeCell(root,rawid);
105 
106  WriteNodeWithValue(cellnode, DAQStatusCode_tag, record[rawid].getStatusCode());
107  }
108 
109  std::cout << " endcap size " << record.endcapItems().size() << std::endl;
110  if (!record.endcapItems().size()) return std::string();
111  for(uint cellid = 0;
113  ++cellid) {
114  if(!EcalScDetId::validHashIndex(cellid)) continue;
115  uint32_t rawid = EcalScDetId::unhashIndex(cellid);
116 
117  if (record.find(rawid) == record.end()) continue;
118  DOMElement* cellnode=writeCell(root,rawid);
119 
120  WriteNodeWithValue(cellnode, DAQStatusCode_tag, record[rawid].getStatusCode());
121  }
122 
123  std::string dump = toNative(writer->writeToString(*root));
124  doc->release();
125  return dump;
126 }
127 
129  std::ofstream fout(fn.c_str());
130  int valEB[34][72];
131  std::cout << " barrel size " << record.barrelItems().size() << std::endl;
132  if (!record.barrelItems().size()) return;
133  for(uint cellid = 0;
135  ++cellid) {
137  if (record.find(rawid) == record.end()) continue;
138  int ieta = rawid.ieta();
139  int line = 17 - ieta;
140  if(ieta < 0) line--;
141  int iphi = rawid.iphi() - 1; // 0 to 71
142  valEB[line][iphi] = record[rawid].getStatusCode();
143  }
144  for(int line = 0; line < 34; line++) {
145  for(int iphi = 0; iphi < 72; iphi++)
146  fout << valEB[line][iphi] << " ";
147  fout << std::endl;
148  if(line == 16) fout << std::endl;
149  }
150 
151  std::cout << " endcap size " << record.endcapItems().size() << std::endl;
152  if (!record.endcapItems().size()) return;
153  int valEE[2][20][20];
154  for(int k = 0 ; k < 2; k++ )
155  for(int ix = 0 ; ix < 20; ix++)
156  for(int iy = 0 ; iy < 20; iy++)
157  valEE[k][ix][iy] = -1;
158  for(uint cellid = 0;
160  ++cellid) {
161  if(EcalScDetId::validHashIndex(cellid)) {
162  EcalScDetId rawid = EcalScDetId::unhashIndex(cellid);
163  int ix = rawid.ix() - 1; // 0 to 19
164  int iy = 20 - rawid.iy(); // 0 to 19
165  int side = rawid.zside();
166  int iz = side;
167  if(side == -1) iz = 0;
168  if(ix < 0 || ix > 19) std::cout << " Pb in ix " << ix << std::endl;
169  if(iy < 0 || iy > 19) std::cout << " Pb in iy " << iy << std::endl;
170  valEE[iz][ix][iy] = record[rawid].getStatusCode();
171  }
172  }
173  for(int k = 0 ; k < 2; k++ ) {
174  int iz = -1;
175  if(k == 1) iz = 1;
176  fout << " Side : " << iz << std::endl;
177  for(int line = 0; line < 20; line++) {
178  for(int ix = 0 ; ix < 20; ix++) {
179  if(valEE[k][ix][line] < 0) fout << ". ";
180  else fout << valEE[k][ix][line] << " ";
181  }
182  fout << std::endl;
183  }
184  fout << std::endl;
185  }
186 
187  return;
188 }
static EcalTrigTowerDetId detIdFromDenseIndex(uint32_t di)
JetCorrectorParameters::Record record
Definition: classes.h:7
void xercesTerminate()
Definition: Xerces.cc:22
const std::string DAQTowerStatus_tag("EcalDAQTowerStatus")
static EcalScDetId unhashIndex(int hi)
Definition: EcalScDetId.h:118
void xercesInitialize()
Definition: Xerces.cc:17
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)
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
int iy() const
Definition: EcalScDetId.h:77
const std::string DAQStatusCode_tag("DAQStatusCode")
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
static bool validHashIndex(int hi)
Definition: EcalScDetId.h:140
static std::string dumpXML(const EcalCondHeader &header, const EcalDAQTowerStatus &record)
tuple filename
Definition: lut2db_cfg.py:20
XercesString fromNative(const char *str)
Definition: XercesString.h:31
tuple cout
Definition: gather_cfg.py:145
xercesc::DOMElement * writeCell(xercesc::DOMNode *node, const DetId &detid)
Append a Cell node with attributes to.
tuple status
Definition: ntuplemaker.py:245
const DetId readCellId(xercesc::DOMElement *node)
Assuming.
std::string toNative(const XMLCh *str)
Definition: XercesString.h:42