CMS 3D CMS Logo

XMLEventWriter.cc
Go to the documentation of this file.
1 /*
2  * XMLEventWriter.cc
3  *
4  * Created on: Oct 12, 2017
5  * Author: kbunkow
6  */
7 
14 
16 
17 #include <boost/property_tree/xml_parser.hpp>
18 
19 #include <bitset>
20 
22  : omtfConfig(aOMTFConfig), fName(fName) {
23  //std::string fName = "OMTF";
24  eventNum = 0;
25 
26  unsigned int version = aOMTFConfig->patternsVersion();
27  const unsigned int mask16bits = 0xFFFF;
28 
29  version &= mask16bits;
30 
31  std::ostringstream stringStr;
32  stringStr.str("");
33  stringStr << "0x" << std::hex << std::setfill('0') << std::setw(4) << version;
34 
35  tree.put("OMTF.<xmlattr>.version", stringStr.str());
36 };
37 
39 
40 void XMLEventWriter::observeProcesorBegin(unsigned int iProcessor, l1t::tftype mtfType) {
41  if (eventNum > 5000)
42  return;
43 
44  procTree.clear();
45 
46  int endcap = (mtfType == l1t::omtf_neg) ? -1 : ((mtfType == l1t::omtf_pos) ? +1 : 0);
47  OmtfName board(iProcessor, endcap, omtfConfig);
48  procTree.add("<xmlattr>.board", board.name());
49  procTree.add("<xmlattr>.iProcessor", iProcessor);
50 
51  std::ostringstream stringStr;
52  stringStr << (board.position() == 1 ? "+" : "") << board.position();
53  procTree.add("<xmlattr>.position", stringStr.str());
54 }
55 
56 void XMLEventWriter::observeProcesorEmulation(unsigned int iProcessor,
57  l1t::tftype mtfType,
58  const std::shared_ptr<OMTFinput>& input,
59  const AlgoMuons& algoCandidates,
60  const AlgoMuons& gbCandidates,
61  const std::vector<l1t::RegionalMuonCand>& candMuons) {
62  if (eventNum > 5000)
63  return;
64 
65  int endcap = (mtfType == l1t::omtf_neg) ? -1 : ((mtfType == l1t::omtf_pos) ? +1 : 0);
66  OmtfName board(iProcessor, endcap, omtfConfig);
67 
68  if (candMuons.empty())
69  return;
70 
71  for (unsigned int iLayer = 0; iLayer < omtfConfig->nLayers(); ++iLayer) {
72  boost::property_tree::ptree layerTree;
73 
74  for (unsigned int iHit = 0; iHit < input->getMuonStubs()[iLayer].size(); ++iHit) {
75  int hitPhi = input->getPhiHw(iLayer, iHit);
76  if (hitPhi >= (int)omtfConfig->nPhiBins())
77  continue;
78 
79  auto& hitTree = layerTree.add("Hit", "");
80 
81  hitTree.add("<xmlattr>.iInput", iHit);
82  hitTree.add("<xmlattr>.iEta", input->getHitEta(iLayer, iHit));
83  hitTree.add("<xmlattr>.iPhi", hitPhi);
84 
85  //in the firmware the hit quality is taken from link data only for the DT stubs
86  //for the CSC and RPC 1 means the hit is valid, 0 - not.
87  //in the input it is still worth to have the actual quality of the CSC and RPC
88  //Because it might be used in the neural network
89  if (iLayer >= 6)
90  hitTree.add("<xmlattr>.iQual", 1);
91  else
92  hitTree.add("<xmlattr>.iQual", input->getHitQual(iLayer, iHit));
93  }
94 
95  if (!layerTree.empty()) {
96  layerTree.add("<xmlattr>.iLayer", iLayer);
97  procTree.add_child("Layer", layerTree);
98  }
99  }
100 
101  for (auto& algoCand : algoCandidates) {
103  if (algoCand->isValid()) {
104  auto& algoMuonTree = procTree.add("AlgoMuon", "");
105  algoMuonTree.add("<xmlattr>.charge", algoCand->getChargeConstr());
106  algoMuonTree.add("<xmlattr>.disc", algoCand->getDisc());
107  algoMuonTree.add("<xmlattr>.pdfSumConstr", algoCand->getGpResultConstr().getPdfSum());
108  algoMuonTree.add("<xmlattr>.pdfSumUnconstr", algoCand->getGpResultUnconstr().getPdfSumUnconstr());
109  algoMuonTree.add("<xmlattr>.etaCode", algoCand->getEtaHw());
110  algoMuonTree.add("<xmlattr>.iRefHit", algoCand->getRefHitNumber());
111  algoMuonTree.add("<xmlattr>.iRefLayer", algoCand->getRefLayer());
112 
113  //algoMuonTree.add("<xmlattr>.layers", std::bitset<18>(algoCand->getFiredLayerBits()));
114 
115  algoMuonTree.add("<xmlattr>.layersConstr", std::bitset<18>(algoCand->getGpResultConstr().getFiredLayerBits()));
116  algoMuonTree.add("<xmlattr>.layersUnconstr",
117  std::bitset<18>(algoCand->getGpResultUnconstr().getFiredLayerBits()));
118 
119  algoMuonTree.add("<xmlattr>.nHits", algoCand->getQ());
120 
121  algoMuonTree.add("<xmlattr>.firedCntConstr", algoCand->getGpResultConstr().getFiredLayerCnt());
122  algoMuonTree.add("<xmlattr>.firedCntUnconstr", algoCand->getGpResultUnconstr().getFiredLayerCnt());
123 
124  algoMuonTree.add("<xmlattr>.patNumConstr", algoCand->getHwPatternNumConstr());
125  algoMuonTree.add("<xmlattr>.patNumUnconstr", algoCand->getHwPatternNumUnconstr());
126 
127  algoMuonTree.add("<xmlattr>.phiCode", algoCand->getPhi());
128 
129  algoMuonTree.add("<xmlattr>.phiConstr", algoCand->getGpResultConstr().getPhi());
130  algoMuonTree.add("<xmlattr>.phiUnConstr", algoCand->getGpResultUnconstr().getPhi());
131 
132  algoMuonTree.add("<xmlattr>.phiRHit", algoCand->getPhiRHit());
133 
134  //in the firmware, the algoMuon has no pt nor upt yet,
135  //only the pattern number, which is converted to the hwpt in the ghostbuster
136  algoMuonTree.add("<xmlattr>.ptCodeConstr", algoCand->getPtConstr());
137  algoMuonTree.add("<xmlattr>.ptCodeUnconstr", algoCand->getPtUnconstr());
138 
139  auto& gpResultTree = algoMuonTree.add("gpResultConstr", "");
140  auto& gpResultConstr = algoCand->getGpResultConstr();
141 
142  gpResultTree.add("<xmlattr>.patNum", algoCand->getHwPatternNumConstr());
143  gpResultTree.add("<xmlattr>.pdfSum", gpResultConstr.getPdfSum());
144 
145  for (unsigned int iLogicLayer = 0; iLogicLayer < gpResultConstr.getStubResults().size(); ++iLogicLayer) {
146  auto& layerTree = gpResultTree.add("layer", "");
147  layerTree.add("<xmlattr>.num", iLogicLayer);
148  auto pdfBin = gpResultConstr.getStubResults()[iLogicLayer].getPdfBin();
149  if (pdfBin == 5400)
150  pdfBin = 0;
151  layerTree.add("<xmlattr>.pdfBin", pdfBin);
152  layerTree.add("<xmlattr>.pdfVal", gpResultConstr.getStubResults()[iLogicLayer].getPdfVal());
153  layerTree.add("<xmlattr>.fired", gpResultConstr.isLayerFired(iLogicLayer));
154  }
155 
156  if (algoCand->getGpResultUnconstr().isValid()) {
157  auto& gpResultTree = algoMuonTree.add("gpResultUnconstr", "");
158  auto& gpResult = algoCand->getGpResultUnconstr();
159 
160  gpResultTree.add("<xmlattr>.patNum", algoCand->getHwPatternNumUnconstr());
161  gpResultTree.add("<xmlattr>.pdfSum", gpResult.getPdfSumUnconstr());
162 
163  for (unsigned int iLogicLayer = 0; iLogicLayer < gpResult.getStubResults().size(); ++iLogicLayer) {
164  auto& layerTree = gpResultTree.add("layer", "");
165  layerTree.add("<xmlattr>.num", iLogicLayer);
166  auto pdfBin = gpResult.getStubResults()[iLogicLayer].getPdfBin();
167  if (pdfBin == 5400)
168  pdfBin = 0;
169  layerTree.add("<xmlattr>.pdfBin", pdfBin);
170  layerTree.add("<xmlattr>.pdfVal", gpResult.getStubResults()[iLogicLayer].getPdfVal());
171  layerTree.add("<xmlattr>.fired", gpResult.isLayerFired(iLogicLayer));
172  }
173  }
174  }
175  }
176 
177  for (auto& candMuon : candMuons) {
178  auto& candMuonTree = procTree.add("CandMuon", "");
179  candMuonTree.add("<xmlattr>.hwEta", candMuon.hwEta());
180  candMuonTree.add("<xmlattr>.hwPhi", candMuon.hwPhi());
181  candMuonTree.add("<xmlattr>.hwPt", candMuon.hwPt());
182  candMuonTree.add("<xmlattr>.hwUPt", candMuon.hwPtUnconstrained());
183  candMuonTree.add("<xmlattr>.hwQual", candMuon.hwQual());
184  candMuonTree.add("<xmlattr>.hwSign", candMuon.hwSign());
185  candMuonTree.add("<xmlattr>.hwSignValid", candMuon.hwSignValid());
186  candMuonTree.add("<xmlattr>.hwTrackAddress", std::bitset<29>(candMuon.trackAddress().at(0)));
187  candMuonTree.add("<xmlattr>.link", candMuon.link());
188  candMuonTree.add("<xmlattr>.processor", candMuon.processor());
189 
190  std::ostringstream stringStr;
191  if (candMuon.trackFinderType() == l1t::omtf_neg)
192  stringStr << "OMTF_NEG";
193  else if (candMuon.trackFinderType() == l1t::omtf_pos)
194  stringStr << "OMTF_POS";
195  else
196  stringStr << candMuon.trackFinderType();
197  candMuonTree.add("<xmlattr>.trackFinderType", stringStr.str());
198  }
199 
200  if (!procTree.empty())
201  eventTree->add_child("Processor", procTree);
202 }
203 
205  eventNum++;
206  if (eventNum > 5000)
207  //due to some bug if more events is written the memory consumption s very big and program crashes
208  return;
209  //currentElement = xmlWriter.writeEventHeader(iEvent.id().event());
210  eventId = iEvent.id().event();
211 
212  eventTree = &(tree.add("OMTF.Event", ""));
213  eventTree->add("<xmlattr>.iEvent", eventId);
214 
215  eventTree = &(eventTree->add("bx", ""));
216  eventTree->add("<xmlattr>.iBx", 2 * eventId);
217 }
218 
220  std::unique_ptr<l1t::RegionalMuonCandBxCollection>& finalCandidates) {}
221 
223  edm::LogInfo("l1tOmtfEventPrint") << "XMLEventWriter::endJob() - writing the data to the xml - starting";
225  fName, tree, std::locale(), boost::property_tree::xml_parser::xml_writer_make_settings<std::string>(' ', 2));
226  edm::LogInfo("l1tOmtfEventPrint") << "XMLEventWriter::endJob() - writing the data to the xml - done";
227 }
void observeProcesorEmulation(unsigned int iProcessor, l1t::tftype mtfType, const std::shared_ptr< OMTFinput > &input, const AlgoMuons &algoCandidates, const AlgoMuons &gbCandidates, const std::vector< l1t::RegionalMuonCand > &candMuons) override
static std::string const input
Definition: EdmProvDump.cc:50
int iEvent
Definition: GenABIO.cc:224
unsigned int nPhiBins() const
unsigned int eventNum
unsigned int patternsVersion() const
unsigned int nLayers() const
def write_xml(scenario, fileName)
Log< level::Info, false > LogInfo
std::string fName
int position() const
Definition: OmtfName.cc:82
std::string name() const
Definition: OmtfName.cc:51
std::vector< AlgoMuonPtr > AlgoMuons
Definition: AlgoMuon.h:183
void endJob() override
unsigned int eventId
boost::property_tree::ptree * eventTree
void observeEventEnd(const edm::Event &iEvent, std::unique_ptr< l1t::RegionalMuonCandBxCollection > &finalCandidates) override
XMLEventWriter(const OMTFConfiguration *aOMTFConfig, std::string fName)
boost::property_tree::ptree procTree
Definition: tree.py:1
void observeEventBegin(const edm::Event &iEvent) override
~XMLEventWriter() override
const OMTFConfiguration * omtfConfig
void observeProcesorBegin(unsigned int iProcessor, l1t::tftype mtfType) override