CMS 3D CMS Logo

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>
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 
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) {
72 
73  std::fstream fs(filename.c_str(), ios::out);
74  fs << dumpXML(header, record);
75 
77 
78  return 0;
79 }
80 
82  unique_ptr<DOMImplementation> impl(DOMImplementationRegistry::getDOMImplementation(cms::xerces::uStr("LS").ptr()));
83 
84  DOMLSSerializer* writer = impl->createLSSerializer();
85  if (writer->getDomConfig()->canSetParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true))
86  writer->getDomConfig()->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true);
87 
88  DOMDocumentType* doctype = impl->createDocumentType(cms::xerces::uStr("XML").ptr(), nullptr, nullptr);
89  DOMDocument* doc = impl->createDocument(nullptr, cms::xerces::uStr(DAQTowerStatus_tag.c_str()).ptr(), doctype);
90 
91  DOMElement* root = doc->getDocumentElement();
92 
94  std::cout << " barrel size " << record.barrelItems().size() << std::endl;
95  if (record.barrelItems().empty())
96  return std::string();
97  for (uint cellid = 0; cellid < EcalTrigTowerDetId::kEBTotalTowers; ++cellid) {
98  uint32_t rawid = EcalTrigTowerDetId::detIdFromDenseIndex(cellid);
99  if (record.find(rawid) == record.end())
100  continue;
101  DOMElement* cellnode = writeCell(root, rawid);
102 
103  WriteNodeWithValue(cellnode, DAQStatusCode_tag, record[rawid].getStatusCode());
104  }
105 
106  std::cout << " endcap size " << record.endcapItems().size() << std::endl;
107  if (record.endcapItems().empty())
108  return std::string();
109  for (uint cellid = 0; cellid < EcalTrigTowerDetId::kEETotalTowers; ++cellid) {
110  if (!EcalScDetId::validHashIndex(cellid))
111  continue;
112  uint32_t rawid = EcalScDetId::unhashIndex(cellid);
113 
114  if (record.find(rawid) == record.end())
115  continue;
116  DOMElement* cellnode = writeCell(root, rawid);
117 
118  WriteNodeWithValue(cellnode, DAQStatusCode_tag, record[rawid].getStatusCode());
119  }
120 
121  std::string dump = cms::xerces::toString(writer->writeToString(root));
122  doc->release();
123  doctype->release();
124  writer->release();
125 
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().empty())
134  return;
135  for (uint cellid = 0; cellid < EcalTrigTowerDetId::kEBTotalTowers; ++cellid) {
137  if (record.find(rawid) == record.end())
138  continue;
139  int ieta = rawid.ieta();
140  int line = 17 - ieta;
141  if (ieta < 0)
142  line--;
143  int iphi = rawid.iphi() - 1; // 0 to 71
144  valEB[line][iphi] = record[rawid].getStatusCode();
145  }
146  for (int line = 0; line < 34; line++) {
147  for (int iphi = 0; iphi < 72; iphi++)
148  fout << valEB[line][iphi] << " ";
149  fout << std::endl;
150  if (line == 16)
151  fout << std::endl;
152  }
153 
154  std::cout << " endcap size " << record.endcapItems().size() << std::endl;
155  if (record.endcapItems().empty())
156  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; cellid < EcalTrigTowerDetId::kEETotalTowers; ++cellid) {
163  if (EcalScDetId::validHashIndex(cellid)) {
164  EcalScDetId rawid = EcalScDetId::unhashIndex(cellid);
165  int ix = rawid.ix() - 1; // 0 to 19
166  int iy = 20 - rawid.iy(); // 0 to 19
167  int side = rawid.zside();
168  int iz = side;
169  if (side == -1)
170  iz = 0;
171  if (ix < 0 || ix > 19)
172  std::cout << " Pb in ix " << ix << std::endl;
173  if (iy < 0 || iy > 19)
174  std::cout << " Pb in iy " << iy << std::endl;
175  valEE[iz][ix][iy] = record[rawid].getStatusCode();
176  }
177  }
178  for (int k = 0; k < 2; k++) {
179  int iz = -1;
180  if (k == 1)
181  iz = 1;
182  fout << " Side : " << iz << std::endl;
183  for (int line = 0; line < 20; line++) {
184  for (int ix = 0; ix < 20; ix++) {
185  if (valEE[k][ix][line] < 0)
186  fout << ". ";
187  else
188  fout << valEE[k][ix][line] << " ";
189  }
190  fout << std::endl;
191  }
192  fout << std::endl;
193  }
194 
195  return;
196 }
xuti::getChildNode
xercesc::DOMNode * getChildNode(xercesc::DOMNode *node, const std::string &nodename)
get the child of
XercesStrUtils.h
common_cff.doc
doc
Definition: common_cff.py:54
EcalTrigTowerDetId::iphi
int iphi() const
get the tower iphi
Definition: EcalTrigTowerDetId.h:52
EcalCondTools.dumpXML
def dumpXML(db, tag, since, filename='dump.xml')
Definition: EcalCondTools.py:44
xuti::writeHeader
void writeHeader(xercesc::DOMNode *parentNode, const EcalCondHeader &header)
write
Definition: DOMHelperFunctions.cc:151
xuti::writeCell
xercesc::DOMElement * writeCell(xercesc::DOMNode *node, const DetId &detid)
Append a Cell node with attributes to.
Definition: DOMHelperFunctions.cc:71
EcalDAQTowerStatusXMLTranslator::plot
static void plot(std::string, const EcalDAQTowerStatus &record)
Definition: EcalDAQTowerStatusXMLTranslator.cc:129
mps_update.status
status
Definition: mps_update.py:69
xuti::DAQStatusCode_tag
const std::string DAQStatusCode_tag("DAQStatusCode")
EcalScDetId::zside
int zside() const
Definition: EcalScDetId.h:64
gather_cfg.cout
cout
Definition: gather_cfg.py:144
EcalScDetId::unhashIndex
static EcalScDetId unhashIndex(int hi)
Definition: EcalScDetId.h:117
GlobalPosition_Frontier_DevDB_cff.record
record
Definition: GlobalPosition_Frontier_DevDB_cff.py:10
writedatasetfile.parser
parser
Definition: writedatasetfile.py:7
cscNeutronWriter_cfi.writer
writer
Definition: cscNeutronWriter_cfi.py:6
EcalTrigTowerDetId
Definition: EcalTrigTowerDetId.h:14
parallelization.uint
uint
Definition: parallelization.py:124
LEDCalibrationChannels.iphi
iphi
Definition: LEDCalibrationChannels.py:64
EcalDAQTowerStatusXMLTranslator::readXML
static int readXML(const std::string &filename, EcalCondHeader &header, EcalDAQTowerStatus &record)
Definition: EcalDAQTowerStatusXMLTranslator.cc:21
EcalCondTowerObjectContainer
Definition: EcalCondTowerObjectContainer.h:13
DetId
Definition: DetId.h:17
cms::xerces::toString
std::string toString(XMLCh const *toTranscode)
Definition: XercesStrUtils.h:34
EcalDAQTowerStatusXMLTranslator::dumpXML
static std::string dumpXML(const EcalCondHeader &header, const EcalDAQTowerStatus &record)
Definition: EcalDAQTowerStatusXMLTranslator.cc:81
xuti::WriteNodeWithValue
void WriteNodeWithValue(xercesc::DOMNode *parentNode, const std::string &tag, const T &value)
write a node with
Definition: DOMHelperFunctions.h:46
EcalDAQTowerStatusXMLTranslator.h
EcalScDetId
Definition: EcalScDetId.h:24
XERCES_CPP_NAMESPACE
Definition: XmlConfigParser.h:12
corrVsCorr.filename
filename
Definition: corrVsCorr.py:123
dqmdumpme.k
k
Definition: dqmdumpme.py:60
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
xuti::DAQTowerStatus_tag
const std::string DAQTowerStatus_tag("EcalDAQTowerStatus")
LEDCalibrationChannels.ieta
ieta
Definition: LEDCalibrationChannels.py:63
DOMHelperFunctions.h
EcalCondHeader
Definition: EcalCondHeader.h:16
groupFilesInBlocks.fout
fout
Definition: groupFilesInBlocks.py:162
FrontierConditions_GlobalTag_cff.dump
dump
Definition: FrontierConditions_GlobalTag_cff.py:12
Xerces.h
EcalScDetId::validHashIndex
static bool validHashIndex(int hi)
Definition: EcalScDetId.h:139
cms::concurrency::xercesTerminate
void xercesTerminate()
Definition: Xerces.cc:23
EcalScDetId::iy
int iy() const
Definition: EcalScDetId.h:76
xuti
Definition: DOMHelperFunctions.h:21
root
Definition: RooFitFunction.h:10
cms::xerces::uStr
ZStr< XMLCh > uStr(char const *str)
Definition: XercesStrUtils.h:30
EcalTrigTowerDetId::ieta
int ieta() const
get the tower ieta
Definition: EcalTrigTowerDetId.h:44
EcalTrigTowerDetId::kEBTotalTowers
Definition: EcalTrigTowerDetId.h:116
impl
Definition: trackAlgoPriorityOrder.h:18
std
Definition: JetResolutionObject.h:76
officialStyle.chan
chan
lumi = TPaveText(lowX+0.38, lowY+0.061, lowX+0.45, lowY+0.161, "NDC") lumi.SetBorderSize( 0 ) lumi....
Definition: officialStyle.py:106
personalPlayback.fn
fn
Definition: personalPlayback.py:515
EcalTrigTowerDetId::detIdFromDenseIndex
static EcalTrigTowerDetId detIdFromDenseIndex(uint32_t di)
Definition: EcalTrigTowerDetId.cc:104
EcalTrigTowerDetId::kEETotalTowers
Definition: EcalTrigTowerDetId.h:118
RecoTauValidation_cfi.header
header
Definition: RecoTauValidation_cfi.py:292
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
xuti::readCellId
const DetId readCellId(xercesc::DOMElement *node)
Assuming.
Definition: DOMHelperFunctions.cc:24
XMLTags.h
EcalDAQTowerStatusXMLTranslator::writeXML
static int writeXML(const std::string &filename, const EcalCondHeader &header, const EcalDAQTowerStatus &record)
Definition: EcalDAQTowerStatusXMLTranslator.cc:68
mps_splice.line
line
Definition: mps_splice.py:76
cms::concurrency::xercesInitialize
void xercesInitialize()
Definition: Xerces.cc:18
xuti::readHeader
void readHeader(xercesc::DOMNode *parentNode, EcalCondHeader &header)
read header from
Definition: DOMHelperFunctions.cc:164
xuti::Cell_tag
const std::string Cell_tag("cell")
EcalScDetId::ix
int ix() const
Definition: EcalScDetId.h:70
xuti::GetNodeData
void GetNodeData(xercesc::DOMNode *node, T &value)
get the node data
Definition: DOMHelperFunctions.h:38