CMS 3D CMS Logo

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