17 #include "xercesc/framework/StdOutFormatTarget.hpp"
18 #include "xercesc/framework/LocalFileFormatTarget.hpp"
19 #include "xercesc/parsers/XercesDOMParser.hpp"
20 #include "xercesc/dom/DOM.hpp"
21 #include "xercesc/dom/DOMException.hpp"
22 #include "xercesc/dom/DOMImplementation.hpp"
23 #include "xercesc/sax/HandlerBase.hpp"
24 #include "xercesc/util/XMLString.hpp"
25 #include "xercesc/util/PlatformUtils.hpp"
26 #include "xercesc/util/XercesDefs.hpp"
27 #include "xercesc/util/XercesVersion.hpp"
28 XERCES_CPP_NAMESPACE_USE
30 #if _XERCES_VERSION <30100
31 #include "xercesc/dom/DOMWriter.hpp"
33 #include "xercesc/dom/DOMLSSerializer.hpp"
34 #include "xercesc/dom/DOMLSOutput.hpp"
54 XMLPlatformUtils::Initialize();
57 domImpl = DOMImplementationRegistry::getDOMImplementation(
_toDOMS(
"Range"));
69 unsigned int subVersion = 0;
70 unsigned int mask32bits =
pow(2,32)-1;
72 version = version<<16;
76 std::ostringstream stringStr;
78 stringStr<<
"0x"<<std::hex<<std::setfill(
'0')<<std::setw(8)<<
version;
86 XMLFormatTarget* formTarget =
new LocalFileFormatTarget(fName.c_str());
88 #if _XERCES_VERSION <30100
89 xercesc::DOMWriter* domWriter = (
dynamic_cast<DOMImplementation*
>(
domImpl))->createDOMWriter();
90 if(domWriter->canSetFeature(XMLUni::fgDOMWRTFormatPrettyPrint,
true)){
91 domWriter->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint,
true);
96 xercesc::DOMLSSerializer* theSerializer = (
dynamic_cast<DOMImplementation*
>(
domImpl))->createLSSerializer();
97 if (theSerializer->getDomConfig()->canSetParameter(XMLUni::fgDOMWRTFormatPrettyPrint,
true))
98 theSerializer->getDomConfig()->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint,
true);
99 DOMLSOutput* theOutput = (
dynamic_cast<DOMImplementation*
>(
domImpl))->createLSOutput();
100 theOutput->setByteStream(formTarget);
102 theOutput->release();
103 theSerializer->release();
111 unsigned int mixedEventId){
113 unsigned int eventBx = eventId*2;
115 xercesc::DOMElement *aEvent = 0;
116 xercesc::DOMElement *aBx = 0;
117 std::ostringstream stringStr;
123 aEvent->setAttribute(
_toDOMS(
"iEvent"),
_toDOMS(stringStr.str()));
126 stringStr<<mixedEventId;
127 aEvent->setAttribute(
_toDOMS(
"iMixedEvent"),
_toDOMS(stringStr.str()));
133 aEvent->appendChild(aBx);
142 unsigned int iProcessor,
145 std::ostringstream stringStr;
147 xercesc::DOMElement *aProcessor =
theDoc->createElement(
_toDOMS(
"Processor"));
149 stringStr<<iProcessor;
150 aProcessor->setAttribute(
_toDOMS(
"iProcessor"),
_toDOMS(stringStr.str()));
152 xercesc::DOMElement *aLayer, *aHit;
160 aLayer->setAttribute(
_toDOMS(
"iLayer"),
_toDOMS(stringStr.str()));
161 for(
unsigned int iHit=0;iHit<layerDataPhi.size();++iHit){
167 stringStr<<layerDataPhi[iHit];
170 stringStr<<layerDataEta[iHit];
173 aLayer->appendChild(aHit);
175 if(aLayer->getChildNodes()->getLength()) aProcessor->appendChild(aLayer);
178 aTopElement->appendChild(aProcessor);
185 unsigned int iRefHit,
188 xercesc::DOMElement* aResult =
theDoc->createElement(
_toDOMS(
"Candidate"));
189 std::ostringstream stringStr;
192 aResult->setAttribute(
_toDOMS(
"iRefHit"),
_toDOMS(stringStr.str()));
195 aResult->setAttribute(
_toDOMS(
"ptCode"),
_toDOMS(stringStr.str()));
197 stringStr<<aCand.
phi;
198 aResult->setAttribute(
_toDOMS(
"phiCode"),
_toDOMS(stringStr.str()));
200 stringStr<<aCand.
eta;
201 aResult->setAttribute(
_toDOMS(
"etaCode"),
_toDOMS(stringStr.str()));
204 aResult->setAttribute(
_toDOMS(
"charge"),
_toDOMS(stringStr.str()));
207 aResult->setAttribute(
_toDOMS(
"nHits"),
_toDOMS(stringStr.str()));
209 stringStr<<aCand.
disc;
213 aResult->setAttribute(
_toDOMS(
"iRefLayer"),
_toDOMS(stringStr.str()));
214 aTopElement->appendChild(aResult);
219 unsigned int iRegion,
225 std::ostringstream stringStr;
227 xercesc::DOMElement* aGP =
theDoc->createElement(
_toDOMS(
"GP"));
243 xercesc::DOMElement* aRefLayer =
theDoc->createElement(
_toDOMS(
"Result"));
245 stringStr<<iRefLayer;
246 aRefLayer->setAttribute(
_toDOMS(
"iRefLayer"),
_toDOMS(stringStr.str()));
249 aRefLayer->setAttribute(
_toDOMS(
"iRegion"),
_toDOMS(stringStr.str()));
252 aRefLayer->setAttribute(
_toDOMS(
"iLogicLayer"),
_toDOMS(stringStr.str()));
254 xercesc::DOMElement* aLayer =
theDoc->createElement(
_toDOMS(
"Layer"));
256 stringStr<<iLogicLayer;
257 aLayer->setAttribute(
_toDOMS(
"iLayer"),
_toDOMS(stringStr.str()));
259 stringStr<<results[iLogicLayer][iRefLayer];
261 if(results[iLogicLayer][iRefLayer]) aRefLayer->appendChild(aLayer);
263 if(aRefLayer->getChildNodes()->getLength()) aGP->appendChild(aRefLayer);
265 if(aGP->getChildNodes()->getLength()) aTopElement->appendChild(aGP);
271 std::ostringstream stringStr;
272 xercesc::DOMElement *aLayer=0, *aRefLayer=0, *aPdf=0;
274 xercesc::DOMElement* aGPElement =
theDoc->createElement(
_toDOMS(
"GP"));
277 aGPElement->setAttribute(
_toDOMS(
"iPt"),
_toDOMS(stringStr.str()));
280 aGPElement->setAttribute(
_toDOMS(
"iEta"),
_toDOMS(stringStr.str()));
284 aGPElement->setAttribute(
_toDOMS(
"iPhi"),
_toDOMS(stringStr.str()));
287 aGPElement->setAttribute(
_toDOMS(
"iCharge"),
_toDOMS(stringStr.str()));
289 unsigned int iLayerNew=0;
299 stringStr<<iLayerNew;
302 aLayer->setAttribute(
_toDOMS(
"iLayer"),
_toDOMS(stringStr.str()));
305 aLayer->setAttribute(
_toDOMS(
"nOfPhis"),
_toDOMS(stringStr.str()));
310 stringStr<<meanDistPhi;
311 aRefLayer->setAttribute(
_toDOMS(
"meanDistPhi"),
_toDOMS(stringStr.str()));
314 stringStr<<selDistPhi;
315 aRefLayer->setAttribute(
_toDOMS(
"selDistPhi"),
_toDOMS(stringStr.str()));
316 int selDistPhiShift = 0;
318 stringStr<<selDistPhiShift;
319 aRefLayer->setAttribute(
_toDOMS(
"selDistPhiShift"),
_toDOMS(stringStr.str()));
320 int distMsbPhiShift = 0;
322 stringStr<<distMsbPhiShift;
323 aRefLayer->setAttribute(
_toDOMS(
"distMsbPhiShift"),
_toDOMS(stringStr.str()));
324 aLayer->appendChild(aRefLayer);
330 stringStr<<aGP.
pdfValue(iLayer,iRefLayer,iPdf);
332 aLayer->appendChild(aPdf);
335 aGPElement->appendChild(aLayer);
344 std::ostringstream stringStr;
345 xercesc::DOMElement *aLayer=0, *aRefLayer=0, *aPdf=0;
347 xercesc::DOMElement* aGPElement =
theDoc->createElement(
_toDOMS(
"GP"));
350 aGPElement->setAttribute(
_toDOMS(
"iPt1"),
_toDOMS(stringStr.str()));
354 aGPElement->setAttribute(
_toDOMS(
"iPt2"),
_toDOMS(stringStr.str()));
357 aGPElement->setAttribute(
_toDOMS(
"iEta"),
_toDOMS(stringStr.str()));
361 aGPElement->setAttribute(
_toDOMS(
"iPhi"),
_toDOMS(stringStr.str()));
364 aGPElement->setAttribute(
_toDOMS(
"iCharge"),
_toDOMS(stringStr.str()));
366 unsigned int iLayerNew=0;
376 stringStr<<iLayerNew;
379 aLayer->setAttribute(
_toDOMS(
"iLayer"),
_toDOMS(stringStr.str()));
382 aLayer->setAttribute(
_toDOMS(
"nOfPhis"),
_toDOMS(stringStr.str()));
388 stringStr<<meanDistPhi;
389 aRefLayer->setAttribute(
_toDOMS(
"meanDistPhi"),
_toDOMS(stringStr.str()));
398 stringStr<<selDistPhi;
399 aRefLayer->setAttribute(
_toDOMS(
"selDistPhi"),
_toDOMS(stringStr.str()));
400 int selDistPhiShift = 0;
402 stringStr<<selDistPhiShift;
403 aRefLayer->setAttribute(
_toDOMS(
"selDistPhiShift"),
_toDOMS(stringStr.str()));
404 int distMsbPhiShift = 0;
406 stringStr<<distMsbPhiShift;
407 aRefLayer->setAttribute(
_toDOMS(
"distMsbPhiShift"),
_toDOMS(stringStr.str()));
408 aLayer->appendChild(aRefLayer);
414 stringStr<<aGP1.
pdfValue(iLayer,iRefLayer,iPdf);
417 stringStr<<aGP2.
pdfValue(iLayer,iRefLayer,iPdf);
419 aLayer->appendChild(aPdf);
422 aGPElement->appendChild(aLayer);
433 std::ostringstream stringStr;
434 xercesc::DOMElement *aLayer=0, *aRefLayer=0, *aPdf=0;
436 xercesc::DOMElement* aGPElement =
theDoc->createElement(
_toDOMS(
"GP"));
439 aGPElement->setAttribute(
_toDOMS(
"iPt1"),
_toDOMS(stringStr.str()));
442 aGPElement->setAttribute(
_toDOMS(
"iPt2"),
_toDOMS(stringStr.str()));
445 aGPElement->setAttribute(
_toDOMS(
"iPt3"),
_toDOMS(stringStr.str()));
448 aGPElement->setAttribute(
_toDOMS(
"iPt4"),
_toDOMS(stringStr.str()));
452 aGPElement->setAttribute(
_toDOMS(
"iEta"),
_toDOMS(stringStr.str()));
456 aGPElement->setAttribute(
_toDOMS(
"iPhi"),
_toDOMS(stringStr.str()));
459 aGPElement->setAttribute(
_toDOMS(
"iCharge"),
_toDOMS(stringStr.str()));
461 unsigned int iLayerNew=0;
471 stringStr<<iLayerNew;
474 aLayer->setAttribute(
_toDOMS(
"iLayer"),
_toDOMS(stringStr.str()));
477 aLayer->setAttribute(
_toDOMS(
"nOfPhis"),
_toDOMS(stringStr.str()));
483 stringStr<<meanDistPhi;
484 aRefLayer->setAttribute(
_toDOMS(
"meanDistPhi"),
_toDOMS(stringStr.str()));
493 stringStr<<selDistPhi;
494 aRefLayer->setAttribute(
_toDOMS(
"selDistPhi"),
_toDOMS(stringStr.str()));
495 int selDistPhiShift = 0;
497 stringStr<<selDistPhiShift;
498 aRefLayer->setAttribute(
_toDOMS(
"selDistPhiShift"),
_toDOMS(stringStr.str()));
499 int distMsbPhiShift = 0;
501 stringStr<<distMsbPhiShift;
502 aRefLayer->setAttribute(
_toDOMS(
"distMsbPhiShift"),
_toDOMS(stringStr.str()));
503 aLayer->appendChild(aRefLayer);
509 stringStr<<aGP1.
pdfValue(iLayer,iRefLayer,iPdf);
512 stringStr<<aGP2.
pdfValue(iLayer,iRefLayer,iPdf);
515 stringStr<<aGP3.
pdfValue(iLayer,iRefLayer,iPdf);
518 stringStr<<aGP4.
pdfValue(iLayer,iRefLayer,iPdf);
520 aLayer->appendChild(aPdf);
523 aGPElement->appendChild(aLayer);
531 std::ostringstream stringStr;
533 for(
unsigned int iProcessor=0;iProcessor<6;++iProcessor){
534 xercesc::DOMElement* aProcessorElement =
theDoc->createElement(
_toDOMS(
"Processor"));
536 stringStr<<iProcessor;
537 aProcessorElement->setAttribute(
_toDOMS(
"iProcessor"),
_toDOMS(stringStr.str()));
539 xercesc::DOMElement* aRefLayerElement =
theDoc->createElement(
_toDOMS(
"RefLayer"));
541 stringStr<<iRefLayer;
542 aRefLayerElement->setAttribute(
_toDOMS(
"iRefLayer"),
_toDOMS(stringStr.str()));
545 aRefLayerElement->setAttribute(
_toDOMS(
"iGlobalPhiStart"),
_toDOMS(stringStr.str()));
546 aProcessorElement->appendChild(aRefLayerElement);
548 unsigned int iRefHit = 0;
553 for(
unsigned int iRegion=0;iRegion<6;++iRegion){
554 unsigned int maxHitCount = 0;
555 for(
unsigned int iInput=0;iInput<14;++iInput) {
559 for(
unsigned int iInput=0;iInput<14;++iInput){
561 if(hitCount<maxHitCount*0.1)
continue;
562 xercesc::DOMElement* aRefHitElement =
theDoc->createElement(
_toDOMS(
"RefHit"));
565 aRefHitElement->setAttribute(
_toDOMS(
"iRefHit"),
_toDOMS(stringStr.str()));
567 stringStr<<iRefLayer;
568 aRefHitElement->setAttribute(
_toDOMS(
"iRefLayer"),
_toDOMS(stringStr.str()));
572 aRefHitElement->setAttribute(
_toDOMS(
"iRegion"),
_toDOMS(stringStr.str()));
576 aRefHitElement->setAttribute(
_toDOMS(
"iInput"),
_toDOMS(stringStr.str()));
581 int iPhiMax = iPhiMin+logicRegionSize-1;
583 iPhiMin+=iRegion*logicRegionSize;
584 iPhiMax+=iRegion*logicRegionSize;
588 aRefHitElement->setAttribute(
_toDOMS(
"iPhiMin"),
_toDOMS(stringStr.str()));
592 aRefHitElement->setAttribute(
_toDOMS(
"iPhiMax"),
_toDOMS(stringStr.str()));
597 xercesc::DOMElement* aRefHitElement =
theDoc->createElement(
_toDOMS(
"RefHit"));
600 aRefHitElement->setAttribute(
_toDOMS(
"iRefHit"),
_toDOMS(stringStr.str()));
603 aRefHitElement->setAttribute(
_toDOMS(
"iRefLayer"),
_toDOMS(stringStr.str()));
607 aRefHitElement->setAttribute(
_toDOMS(
"iRegion"),
_toDOMS(stringStr.str()));
611 aRefHitElement->setAttribute(
_toDOMS(
"iInput"),
_toDOMS(stringStr.str()));
618 aRefHitElement->setAttribute(
_toDOMS(
"iPhiMin"),
_toDOMS(stringStr.str()));
622 aRefHitElement->setAttribute(
_toDOMS(
"iPhiMax"),
_toDOMS(stringStr.str()));
624 aProcessorElement->appendChild(aRefHitElement);
629 for(
unsigned int iRegion=0;iRegion<6;++iRegion){
630 xercesc::DOMElement* aRegionElement =
theDoc->createElement(
_toDOMS(
"LogicRegion"));
633 aRegionElement->setAttribute(
_toDOMS(
"iRegion"),
_toDOMS(stringStr.str()));
635 unsigned int iLayerNew = 0;
638 xercesc::DOMElement* aLayerElement =
theDoc->createElement(
_toDOMS(
"Layer"));
642 stringStr<<iLayerNew;
645 aLayerElement->setAttribute(
_toDOMS(
"iLayer"),
_toDOMS(stringStr.str()));
649 if((
int)maxInput-2>=0) begin = maxInput-2;
650 else begin = maxInput;
654 aLayerElement->setAttribute(
_toDOMS(
"iFirstInput"),
_toDOMS(stringStr.str()));
656 stringStr<<
end-begin+1;
657 aLayerElement->setAttribute(
_toDOMS(
"nInputs"),
_toDOMS(stringStr.str()));
658 aRegionElement->appendChild(aLayerElement);
660 aProcessorElement->appendChild(aRegionElement);
669 unsigned int max = 0;
670 unsigned int maxInput = 0;
671 for(
unsigned int iInput=0;iInput<14;++iInput){
672 if(myCounts[iInput]>(
int)max){
673 max = myCounts[iInput];
685 return (iLayer==6 || iLayer==7 || iLayer==9 || iLayer==11 || iLayer==13 || iLayer==15 || iLayer==24);
void writeConnectionsData(const std::vector< std::vector< OMTFConfiguration::vector2D > > &measurements4D)
static unsigned int nLayers
void writeCandidateData(xercesc::DOMElement *aTopElement, unsigned int iRefHit, const InternalObj &aCand)
static vector4D measurements4D
void initialiseXMLDocument(const std::string &docName)
std::string _toString(const XMLCh *toTranscode)
xercesc::DOMElement * writeEventData(xercesc::DOMElement *aTopElement, unsigned int iProcessor, const OMTFinput &aInput)
static int globalPhiStart(unsigned int iProcessor)
const OMTFResult::vector2D & getResults() const
static vector4D measurements4Dref
static unsigned int nPdfAddrBits
void writeResultsData(xercesc::DOMElement *aTopElement, unsigned int iRegion, const Key &aKey, const OMTFResult &aResult)
unsigned int findMaxInput(const OMTFConfiguration::vector1D &myCounts)
XMLCh * transcode(const T &fInput)
static std::vector< std::vector< int > > processorPhiVsRefLayer
std::vector< int > vector1D
static unsigned int nPhiBins
bool removeLayers(unsigned int iLayer)
Utility function to set which layers should be ignored.
static std::vector< int > refToLogicNumber
static unsigned int nPhiBits
xercesc::DOMImplementation * domImpl
std::vector< vector1D > vector2D
static unsigned int nRefLayers
int pdfValue(unsigned int iLayer, unsigned int iRefLayer, unsigned int iBin) const
static unsigned int nRefHits
std::vector< std::vector< double > > tmp
XMLCh * _toDOMS(std::string temp)
void finaliseXMLDocument(const std::string &fName)
xercesc::DOMElement * writeEventHeader(unsigned int eventId, unsigned int mixedEventId=0)
xercesc::DOMDocument * theDoc
int meanDistPhiValue(unsigned int iLayer, unsigned int iRefLayer) const
xercesc::DOMElement * theTopElement
Power< A, B >::type pow(const A &a, const B &b)
void writeGPData(const GoldenPattern &aGP)