CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
XMLEventWriter Class Reference

#include <XMLEventWriter.h>

Inheritance diagram for XMLEventWriter:
IOMTFEmulationObserver

Public Member Functions

void addProcesorData (std::string key, boost::property_tree::ptree &procDataTree) override
 
void endJob () override
 
void observeEventBegin (const edm::Event &iEvent) override
 
void observeEventEnd (const edm::Event &iEvent, std::unique_ptr< l1t::RegionalMuonCandBxCollection > &finalCandidates) override
 
void observeProcesorBegin (unsigned int iProcessor, l1t::tftype mtfType) override
 
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
 
 XMLEventWriter (const OMTFConfiguration *aOMTFConfig, std::string fName)
 
 ~XMLEventWriter () override
 
- Public Member Functions inherited from IOMTFEmulationObserver
virtual void beginRun (edm::EventSetup const &eventSetup)
 
 IOMTFEmulationObserver ()
 
virtual ~IOMTFEmulationObserver ()
 

Private Attributes

unsigned int eventId = 0
 
unsigned int eventNum = 0
 
boost::property_tree::ptree * eventTree = nullptr
 
std::string fName
 
const OMTFConfigurationomtfConfig
 
boost::property_tree::ptree procTree
 
boost::property_tree::ptree tree
 

Detailed Description

Definition at line 22 of file XMLEventWriter.h.

Constructor & Destructor Documentation

◆ XMLEventWriter()

XMLEventWriter::XMLEventWriter ( const OMTFConfiguration aOMTFConfig,
std::string  fName 
)

Definition at line 21 of file XMLEventWriter.cc.

References eventNum, OMTFConfiguration::patternsVersion(), and BeamSplash_cfg::version.

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 };
unsigned int eventNum
unsigned int patternsVersion() const
std::string fName
Definition: tree.py:1
const OMTFConfiguration * omtfConfig

◆ ~XMLEventWriter()

XMLEventWriter::~XMLEventWriter ( )
override

Definition at line 38 of file XMLEventWriter.cc.

38 {}

Member Function Documentation

◆ addProcesorData()

void XMLEventWriter::addProcesorData ( std::string  key,
boost::property_tree::ptree &  procDataTree 
)
inlineoverridevirtual

Reimplemented from IOMTFEmulationObserver.

Definition at line 30 of file XMLEventWriter.h.

References submitPVResolutionJobs::key, and procTree.

30  {
31  procTree.add_child(key, procDataTree);
32  }
key
prepare the HTCondor submission files and eventually submit them
boost::property_tree::ptree procTree

◆ endJob()

void XMLEventWriter::endJob ( void  )
overridevirtual

Implements IOMTFEmulationObserver.

Definition at line 222 of file XMLEventWriter.cc.

References fName, and MCScenario_CRAFT1_22X::write_xml().

222  {
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 }
def write_xml(scenario, fileName)
Log< level::Info, false > LogInfo
std::string fName
Definition: tree.py:1

◆ observeEventBegin()

void XMLEventWriter::observeEventBegin ( const edm::Event iEvent)
overridevirtual

Reimplemented from IOMTFEmulationObserver.

Definition at line 204 of file XMLEventWriter.cc.

References eventId, eventNum, eventTree, and iEvent.

204  {
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 }
int iEvent
Definition: GenABIO.cc:224
unsigned int eventNum
unsigned int eventId
boost::property_tree::ptree * eventTree
Definition: tree.py:1

◆ observeEventEnd()

void XMLEventWriter::observeEventEnd ( const edm::Event iEvent,
std::unique_ptr< l1t::RegionalMuonCandBxCollection > &  finalCandidates 
)
overridevirtual

Reimplemented from IOMTFEmulationObserver.

Definition at line 219 of file XMLEventWriter.cc.

220  {}

◆ observeProcesorBegin()

void XMLEventWriter::observeProcesorBegin ( unsigned int  iProcessor,
l1t::tftype  mtfType 
)
overridevirtual

Reimplemented from IOMTFEmulationObserver.

Definition at line 40 of file XMLEventWriter.cc.

References makeMuonMisalignmentScenario::endcap, eventNum, OmtfName::name(), l1t::omtf_neg, l1t::omtf_pos, omtfConfig, OmtfName::position(), and procTree.

40  {
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 }
unsigned int eventNum
boost::property_tree::ptree procTree
const OMTFConfiguration * omtfConfig

◆ observeProcesorEmulation()

void XMLEventWriter::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 
)
overridevirtual

Dump only regions, where a candidate was found

Implements IOMTFEmulationObserver.

Definition at line 56 of file XMLEventWriter.cc.

References makeMuonMisalignmentScenario::endcap, eventNum, eventTree, input, OMTFConfiguration::nLayers(), OMTFConfiguration::nPhiBins(), l1t::omtf_neg, l1t::omtf_pos, omtfConfig, and procTree.

61  {
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 }
static std::string const input
Definition: EdmProvDump.cc:50
unsigned int nPhiBins() const
unsigned int eventNum
unsigned int nLayers() const
boost::property_tree::ptree * eventTree
boost::property_tree::ptree procTree
const OMTFConfiguration * omtfConfig

Member Data Documentation

◆ eventId

unsigned int XMLEventWriter::eventId = 0
private

Definition at line 61 of file XMLEventWriter.h.

Referenced by ntupleDataFormat.Event::eventIdStr(), and observeEventBegin().

◆ eventNum

unsigned int XMLEventWriter::eventNum = 0
private

◆ eventTree

boost::property_tree::ptree* XMLEventWriter::eventTree = nullptr
private

Definition at line 53 of file XMLEventWriter.h.

Referenced by observeEventBegin(), and observeProcesorEmulation().

◆ fName

std::string XMLEventWriter::fName
private

Definition at line 57 of file XMLEventWriter.h.

Referenced by endJob().

◆ omtfConfig

const OMTFConfiguration* XMLEventWriter::omtfConfig
private

Definition at line 49 of file XMLEventWriter.h.

Referenced by observeProcesorBegin(), and observeProcesorEmulation().

◆ procTree

boost::property_tree::ptree XMLEventWriter::procTree
private

◆ tree

boost::property_tree::ptree XMLEventWriter::tree
private