19 #include "xercesc/framework/StdOutFormatTarget.hpp" 20 #include "xercesc/framework/LocalFileFormatTarget.hpp" 21 #include "xercesc/parsers/XercesDOMParser.hpp" 22 #include "xercesc/dom/DOM.hpp" 23 #include "xercesc/dom/DOMException.hpp" 24 #include "xercesc/dom/DOMImplementation.hpp" 25 #include "xercesc/sax/HandlerBase.hpp" 26 #include "xercesc/util/XMLString.hpp" 27 #include "xercesc/util/PlatformUtils.hpp" 28 #include "xercesc/util/XercesDefs.hpp" 29 #include "xercesc/util/XercesVersion.hpp" 32 #if _XERCES_VERSION < 30100 33 #include "xercesc/dom/DOMWriter.hpp" 35 #include "xercesc/dom/DOMLSSerializer.hpp" 36 #include "xercesc/dom/DOMLSOutput.hpp" 83 XMLCh* buff = XMLString::transcode(
temp.c_str());
89 XMLPlatformUtils::Initialize();
92 domImpl = DOMImplementationRegistry::getDOMImplementation(
_toDOMS(
"Range"));
103 unsigned int mask16bits = 0xFFFF;
107 std::ostringstream stringStr;
109 stringStr <<
"0x" << std::hex << std::setfill(
'0') << std::setw(4) <<
version;
115 XMLFormatTarget* formTarget =
new LocalFileFormatTarget(
fName.c_str());
117 #if _XERCES_VERSION < 30100 118 xercesc::DOMWriter* domWriter = (
dynamic_cast<DOMImplementation*
>(
domImpl))->createDOMWriter();
119 if (domWriter->canSetFeature(XMLUni::fgDOMWRTFormatPrettyPrint,
true)) {
120 domWriter->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint,
true);
125 xercesc::DOMLSSerializer* theSerializer = (
dynamic_cast<DOMImplementation*
>(
domImpl))->createLSSerializer();
126 if (theSerializer->getDomConfig()->canSetParameter(XMLUni::fgDOMWRTFormatPrettyPrint,
true))
127 theSerializer->getDomConfig()->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint,
true);
128 DOMLSOutput* theOutput = (
dynamic_cast<DOMImplementation*
>(
domImpl))->createLSOutput();
129 theOutput->setByteStream(formTarget);
131 theOutput->release();
132 theSerializer->release();
140 unsigned int eventBx = eventId * 2;
142 xercesc::DOMElement* aEvent =
nullptr;
143 xercesc::DOMElement* aBx =
nullptr;
144 std::ostringstream stringStr;
149 stringStr << eventId;
150 aEvent->setAttribute(
_toDOMS(
"iEvent"),
_toDOMS(stringStr.str()));
153 stringStr << mixedEventId;
154 aEvent->setAttribute(
_toDOMS(
"iMixedEvent"),
_toDOMS(stringStr.str()));
158 stringStr << eventBx;
160 aEvent->appendChild(aBx);
171 std::ostringstream stringStr;
173 xercesc::DOMElement* aProcessor =
theDoc->createElement(
_toDOMS(
"Processor"));
176 unsigned int iProcessor = board.
processor();
178 stringStr << iProcessor;
179 aProcessor->setAttribute(
_toDOMS(
"iProcessor"),
_toDOMS(stringStr.str()));
184 aProcessor->setAttribute(
_toDOMS(
"position"),
_toDOMS(stringStr.str()));
186 xercesc::DOMElement *aLayer, *aHit;
194 aLayer->setAttribute(
_toDOMS(
"iLayer"),
_toDOMS(stringStr.str()));
195 for (
unsigned int iHit = 0; iHit < layerDataPhi.size(); ++iHit) {
201 stringStr << layerDataPhi[iHit];
208 aLayer->appendChild(aHit);
210 if (aLayer->getChildNodes()->getLength())
211 aProcessor->appendChild(aLayer);
214 aTopElement->appendChild(aProcessor);
220 xercesc::DOMElement* aResult =
theDoc->createElement(
_toDOMS(
"AlgoMuon"));
221 std::ostringstream stringStr;
223 stringStr << iRefHit;
224 aResult->setAttribute(
_toDOMS(
"iRefHit"),
_toDOMS(stringStr.str()));
226 stringStr << aCand.
getPt();
227 aResult->setAttribute(
_toDOMS(
"ptCode"),
_toDOMS(stringStr.str()));
229 stringStr << aCand.
getPhi();
230 aResult->setAttribute(
_toDOMS(
"phiCode"),
_toDOMS(stringStr.str()));
233 aResult->setAttribute(
_toDOMS(
"etaCode"),
_toDOMS(stringStr.str()));
236 aResult->setAttribute(
_toDOMS(
"charge"),
_toDOMS(stringStr.str()));
238 stringStr << aCand.
getQ();
239 aResult->setAttribute(
_toDOMS(
"nHits"),
_toDOMS(stringStr.str()));
245 aResult->setAttribute(
_toDOMS(
"iRefLayer"),
_toDOMS(stringStr.str()));
247 stringStr << std::bitset<18>(aCand.
getHits());
248 aResult->setAttribute(
_toDOMS(
"layers"),
_toDOMS(stringStr.str()));
251 aResult->setAttribute(
_toDOMS(
"phiRHit"),
_toDOMS(stringStr.str()));
254 aResult->setAttribute(
_toDOMS(
"patNum"),
_toDOMS(stringStr.str()));
256 aTopElement->appendChild(aResult);
261 xercesc::DOMElement* aResult =
theDoc->createElement(
_toDOMS(
"CandMuon"));
262 std::ostringstream stringStr;
264 stringStr << aCand.
hwPt();
267 stringStr << aCand.
hwPhi();
268 aResult->setAttribute(
_toDOMS(
"hwPhi"),
_toDOMS(stringStr.str()));
270 stringStr << aCand.
hwEta();
271 aResult->setAttribute(
_toDOMS(
"hwEta"),
_toDOMS(stringStr.str()));
273 stringStr << aCand.
hwSign();
274 aResult->setAttribute(
_toDOMS(
"hwSign"),
_toDOMS(stringStr.str()));
277 aResult->setAttribute(
_toDOMS(
"hwSignValid"),
_toDOMS(stringStr.str()));
279 stringStr << aCand.
hwQual();
280 aResult->setAttribute(
_toDOMS(
"hwQual"),
_toDOMS(stringStr.str()));
283 stringStr << std::bitset<29>(hwAddrMap[0]);
284 aResult->setAttribute(
_toDOMS(
"hwTrackAddress"),
_toDOMS(stringStr.str()));
286 stringStr << aCand.
link();
290 aResult->setAttribute(
_toDOMS(
"processor"),
_toDOMS(stringStr.str()));
293 stringStr <<
"OMTF_NEG";
295 stringStr <<
"OMTF_POS";
298 aResult->setAttribute(
_toDOMS(
"trackFinderType"),
_toDOMS(stringStr.str()));
299 aTopElement->appendChild(aResult);
306 unsigned int iRegion,
311 std::ostringstream stringStr;
313 xercesc::DOMElement* aGP =
theDoc->createElement(
_toDOMS(
"GP"));
329 xercesc::DOMElement* aRefLayer =
theDoc->createElement(
_toDOMS(
"Result"));
331 stringStr << iRefLayer;
332 aRefLayer->setAttribute(
_toDOMS(
"iRefLayer"),
_toDOMS(stringStr.str()));
334 stringStr << iRegion;
335 aRefLayer->setAttribute(
_toDOMS(
"iRegion"),
_toDOMS(stringStr.str()));
338 aRefLayer->setAttribute(
_toDOMS(
"iLogicLayer"),
_toDOMS(stringStr.str()));
340 xercesc::DOMElement* aLayer =
theDoc->createElement(
_toDOMS(
"Layer"));
342 stringStr << iLogicLayer;
343 aLayer->setAttribute(
_toDOMS(
"iLayer"),
_toDOMS(stringStr.str()));
345 stringStr <<
results[iLogicLayer][iRefLayer];
347 if (
results[iLogicLayer][iRefLayer])
348 aRefLayer->appendChild(aLayer);
350 if (aRefLayer->getChildNodes()->getLength())
351 aGP->appendChild(aRefLayer);
353 if (aGP->getChildNodes()->getLength())
354 aTopElement->appendChild(aGP);
359 std::ostringstream stringStr;
360 xercesc::DOMElement *aLayer =
nullptr, *aRefLayer =
nullptr, *aPdf =
nullptr;
362 xercesc::DOMElement* aGPElement =
theDoc->createElement(
_toDOMS(
"GP"));
365 aGPElement->setAttribute(
_toDOMS(
"iPt"),
_toDOMS(stringStr.str()));
369 aGPElement->setAttribute(
_toDOMS(
"iEta"),
_toDOMS(stringStr.str()));
372 aGPElement->setAttribute(
_toDOMS(
"iPhi"),
_toDOMS(stringStr.str()));
375 aGPElement->setAttribute(
_toDOMS(
"iCharge"),
_toDOMS(stringStr.str()));
384 aLayer->setAttribute(
_toDOMS(
"iLayer"),
_toDOMS(stringStr.str()));
386 stringStr << nOfPhis;
387 aLayer->setAttribute(
_toDOMS(
"nOfPhis"),
_toDOMS(stringStr.str()));
392 stringStr << meanDistPhi;
393 aRefLayer->setAttribute(
_toDOMS(
"meanDistPhi"),
_toDOMS(stringStr.str()));
396 stringStr << selDistPhi;
397 aRefLayer->setAttribute(
_toDOMS(
"selDistPhi"),
_toDOMS(stringStr.str()));
398 int selDistPhiShift = 0;
400 stringStr << selDistPhiShift;
401 aRefLayer->setAttribute(
_toDOMS(
"selDistPhiShift"),
_toDOMS(stringStr.str()));
402 int distMsbPhiShift = 0;
404 stringStr << distMsbPhiShift;
405 aRefLayer->setAttribute(
_toDOMS(
"distMsbPhiShift"),
_toDOMS(stringStr.str()));
406 aLayer->appendChild(aRefLayer);
412 stringStr << aGP.
pdfValue(iLayer, iRefLayer, iPdf);
414 aLayer->appendChild(aPdf);
417 aGPElement->appendChild(aLayer);
427 std::ostringstream stringStr;
428 xercesc::DOMElement *aLayer =
nullptr, *aRefLayer =
nullptr, *aPdf =
nullptr;
430 xercesc::DOMElement* aGPElement =
theDoc->createElement(
_toDOMS(
"GP"));
434 aGPElement->setAttribute(
_toDOMS(
"iPt1"),
_toDOMS(stringStr.str()));
438 aGPElement->setAttribute(
_toDOMS(
"iPt2"),
_toDOMS(stringStr.str()));
442 aGPElement->setAttribute(
_toDOMS(
"iPt3"),
_toDOMS(stringStr.str()));
446 aGPElement->setAttribute(
_toDOMS(
"iPt4"),
_toDOMS(stringStr.str()));
451 aGPElement->setAttribute(
_toDOMS(
"iEta"),
_toDOMS(stringStr.str()));
454 aGPElement->setAttribute(
_toDOMS(
"iPhi"),
_toDOMS(stringStr.str()));
458 aGPElement->setAttribute(
_toDOMS(
"iCharge"),
_toDOMS(stringStr.str()));
467 aLayer->setAttribute(
_toDOMS(
"iLayer"),
_toDOMS(stringStr.str()));
469 stringStr << nOfPhis;
470 aLayer->setAttribute(
_toDOMS(
"nOfPhis"),
_toDOMS(stringStr.str()));
476 stringStr << meanDistPhi;
477 aRefLayer->setAttribute(
_toDOMS(
"meanDistPhi"),
_toDOMS(stringStr.str()));
486 stringStr << selDistPhi;
487 aRefLayer->setAttribute(
_toDOMS(
"selDistPhi"),
_toDOMS(stringStr.str()));
488 int selDistPhiShift = 0;
490 stringStr << selDistPhiShift;
491 aRefLayer->setAttribute(
_toDOMS(
"selDistPhiShift"),
_toDOMS(stringStr.str()));
492 int distMsbPhiShift = 0;
494 stringStr << distMsbPhiShift;
495 aRefLayer->setAttribute(
_toDOMS(
"distMsbPhiShift"),
_toDOMS(stringStr.str()));
496 aLayer->appendChild(aRefLayer);
502 stringStr << aGP1.
pdfValue(iLayer, iRefLayer, iPdf);
505 stringStr << aGP2.
pdfValue(iLayer, iRefLayer, iPdf);
508 stringStr << aGP3.
pdfValue(iLayer, iRefLayer, iPdf);
511 stringStr << aGP4.
pdfValue(iLayer, iRefLayer, iPdf);
513 aLayer->appendChild(aPdf);
516 aGPElement->appendChild(aLayer);
523 const std::vector<std::vector<OMTFConfiguration::vector2D> >& measurements4D) {
524 std::ostringstream stringStr;
526 for (
unsigned int iProcessor = 0; iProcessor < 6; ++iProcessor) {
527 xercesc::DOMElement* aProcessorElement =
theDoc->createElement(
_toDOMS(
"Processor"));
529 stringStr << iProcessor;
530 aProcessorElement->setAttribute(
_toDOMS(
"iProcessor"),
_toDOMS(stringStr.str()));
532 xercesc::DOMElement* aRefLayerElement =
theDoc->createElement(
_toDOMS(
"RefLayer"));
534 stringStr << iRefLayer;
535 aRefLayerElement->setAttribute(
_toDOMS(
"iRefLayer"),
_toDOMS(stringStr.str()));
538 aRefLayerElement->setAttribute(
_toDOMS(
"iGlobalPhiStart"),
_toDOMS(stringStr.str()));
539 aProcessorElement->appendChild(aRefLayerElement);
541 unsigned int iRefHit = 0;
544 for (
unsigned int iRegion = 0; iRegion < 6; ++iRegion) {
545 unsigned int maxHitCount = 0;
546 for (
unsigned int iInput = 0; iInput < 14; ++iInput) {
550 for (
unsigned int iInput = 0; iInput < 14; ++iInput) {
552 if (hitCount < maxHitCount * 0.1)
554 xercesc::DOMElement* aRefHitElement =
theDoc->createElement(
_toDOMS(
"RefHit"));
556 stringStr << iRefHit;
557 aRefHitElement->setAttribute(
_toDOMS(
"iRefHit"),
_toDOMS(stringStr.str()));
559 stringStr << iRefLayer;
560 aRefHitElement->setAttribute(
_toDOMS(
"iRefLayer"),
_toDOMS(stringStr.str()));
563 stringStr << iRegion;
564 aRefHitElement->setAttribute(
_toDOMS(
"iRegion"),
_toDOMS(stringStr.str()));
568 aRefHitElement->setAttribute(
_toDOMS(
"iInput"),
_toDOMS(stringStr.str()));
574 int iPhiMax = iPhiMin + logicRegionSize - 1;
576 iPhiMin += iRegion * logicRegionSize;
577 iPhiMax += iRegion * logicRegionSize;
580 stringStr << iPhiMin;
581 aRefHitElement->setAttribute(
_toDOMS(
"iPhiMin"),
_toDOMS(stringStr.str()));
584 stringStr << iPhiMax;
585 aRefHitElement->setAttribute(
_toDOMS(
"iPhiMax"),
_toDOMS(stringStr.str()));
586 if (iRefHit < myOMTFConfig->nRefHits())
587 aProcessorElement->appendChild(aRefHitElement);
591 xercesc::DOMElement* aRefHitElement =
theDoc->createElement(
_toDOMS(
"RefHit"));
593 stringStr << iRefHit;
594 aRefHitElement->setAttribute(
_toDOMS(
"iRefHit"),
_toDOMS(stringStr.str()));
597 aRefHitElement->setAttribute(
_toDOMS(
"iRefLayer"),
_toDOMS(stringStr.str()));
601 aRefHitElement->setAttribute(
_toDOMS(
"iRegion"),
_toDOMS(stringStr.str()));
605 aRefHitElement->setAttribute(
_toDOMS(
"iInput"),
_toDOMS(stringStr.str()));
611 stringStr << iPhiMin;
612 aRefHitElement->setAttribute(
_toDOMS(
"iPhiMin"),
_toDOMS(stringStr.str()));
615 stringStr << iPhiMax;
616 aRefHitElement->setAttribute(
_toDOMS(
"iPhiMax"),
_toDOMS(stringStr.str()));
618 aProcessorElement->appendChild(aRefHitElement);
623 for (
unsigned int iRegion = 0; iRegion < 6; ++iRegion) {
624 xercesc::DOMElement* aRegionElement =
theDoc->createElement(
_toDOMS(
"LogicRegion"));
626 stringStr << iRegion;
627 aRegionElement->setAttribute(
_toDOMS(
"iRegion"),
_toDOMS(stringStr.str()));
630 xercesc::DOMElement* aLayerElement =
theDoc->createElement(
_toDOMS(
"Layer"));
632 stringStr << iLogicLayer;
634 aLayerElement->setAttribute(
_toDOMS(
"iLayer"),
_toDOMS(stringStr.str()));
638 unsigned int begin = 0,
end = 0;
639 if ((
int)maxInput - 2 >= 0)
640 begin = maxInput - 2;
646 aLayerElement->setAttribute(
_toDOMS(
"iFirstInput"),
_toDOMS(stringStr.str()));
648 stringStr <<
end - begin + 1;
649 aLayerElement->setAttribute(
_toDOMS(
"nInputs"),
_toDOMS(stringStr.str()));
650 aRegionElement->appendChild(aLayerElement);
652 aProcessorElement->appendChild(aRegionElement);
660 unsigned int max = 0;
661 unsigned int maxInput = 0;
662 for (
unsigned int iInput = 0; iInput < 14; ++iInput) {
663 if (myCounts[iInput] > (
int)
max) {
664 max = myCounts[iInput];
const int hwPhi() const
Get compressed local phi (returned int * 2*pi/576 = local phi in rad)
std::string _toString(XMLCh const *toTranscode)
void writeConnectionsData(const std::vector< std::vector< OMTFConfiguration::vector2D > > &measurements4D)
XMLConfigWriter(const OMTFConfiguration *aOMTFConfig)
const OMTFResult::vector2D & getResults() const
const std::vector< std::vector< int > > & getProcessorPhiVsRefLayer() const
void initialiseXMLDocument(const std::string &docName)
const int link() const
Get link on which the MicroGMT receives the candidate.
const int processor() const
Get processor ID on which the candidate was found (0..5 for OMTF/EMTF; 0..11 for BMTF) ...
XMLCh * _toDOMS(std::string temp)
xercesc::DOMElement * writeEventData(xercesc::DOMElement *aTopElement, const OmtfName &board, const OMTFinput &aInput)
unsigned int eta2Bits(unsigned int eta)
unsigned int getPatternNumber() const
const int hwPt() const
Get compressed pT (returned int * 0.5 = pT (GeV))
const int hwQual() const
Get quality code.
const int hwEta() const
Get compressed eta (returned int * 0.010875 = eta)
unsigned int nRefHits() const
int pdfValue(unsigned int iLayer, unsigned int iRefLayer, unsigned int iBin) const
xercesc::DOMDocument * theDoc
unsigned int nPhiBins() const
unsigned int patternsVersion() const
xercesc::DOMElement * theTopElement
void writeResultsData(xercesc::DOMElement *aTopElement, unsigned int iRegion, const Key &aKey, const OMTFResult &aResult)
unsigned int nPdfAddrBits() const
const tftype trackFinderType() const
Get track-finder which found the muon (bmtf, emtf_pos/emtf_neg or omtf_pos/omtf_neg) ...
unsigned int findMaxInput(const OMTFConfiguration::vector1D &myCounts)
Abs< T >::type abs(const T &t)
std::vector< int > vector1D
unsigned int nLayers() const
const std::vector< int > & getRefToLogicNumber() const
void writeCandMuon(xercesc::DOMElement *aTopElement, const l1t::RegionalMuonCand &aCand)
const int hwSign() const
Get charge sign bit (charge = (-1)^(sign))
int globalPhiStart(unsigned int iProcessor) const
unsigned int nRefLayers() const
unsigned int nPhiBits() const
std::vector< vector1D > vector2D
const std::map< int, int > & trackAddress() const
Get the track address (identifies track primitives used for reconstruction)
const int hwSignValid() const
Get charge sign valid bit (0 - not valid (high pT muon); 1 - valid)
const OMTFConfiguration * myOMTFConfig
unsigned int processor() const
void finaliseXMLDocument(const std::string &fName)
xercesc::DOMImplementation * domImpl
void writeAlgoMuon(xercesc::DOMElement *aTopElement, unsigned int iRefHit, const AlgoMuon &aMuon)
int meanDistPhiValue(unsigned int iLayer, unsigned int iRefLayer) const
xercesc::DOMElement * writeEventHeader(unsigned int eventId, unsigned int mixedEventId=0)
vector4D & getMeasurements4Dref()
void writeGPData(const GoldenPattern &aGP)
vector4D & getMeasurements4D()