33 #include <xercesc/parsers/XercesDOMParser.hpp>
34 #include <xercesc/dom/DOM.hpp>
35 #include <xercesc/sax/HandlerBase.hpp>
36 #include <xercesc/util/XMLString.hpp>
37 #include <xercesc/util/PlatformUtils.hpp>
135 void ParseXML(ParseType,
137 const std::unique_ptr<TotemDAQMapping> &,
138 const std::unique_ptr<TotemAnalysisMask> &);
141 void ParseTreeRP(ParseType,
144 unsigned int parentID,
145 const std::unique_ptr<TotemDAQMapping> &,
146 const std::unique_ptr<TotemAnalysisMask> &);
149 void ParseTreeDiamond(ParseType,
152 unsigned int parentID,
153 const std::unique_ptr<TotemDAQMapping> &,
154 const std::unique_ptr<TotemAnalysisMask> &);
157 void ParseTreeTotemTiming(ParseType,
160 unsigned int parentID,
161 const std::unique_ptr<TotemDAQMapping> &,
162 const std::unique_ptr<TotemAnalysisMask> &);
166 string CompleteFileName(
const string &
fn);
174 NodeType GetNodeType(xercesc::DOMNode *);
185 void GetChannels(xercesc::DOMNode *
n, std::set<unsigned char> &
channels);
188 return ((
type == nArm) || (
type == nRPStation) || (
type == nRPPot) || (
type == nRPPlane) || (
type == nChip));
192 return ((
type == nArm) || (
type == nRPStation) || (
type == nRPPot) || (
type == nDiamondPlane) ||
193 (
type == nDiamondCh));
197 return ((
type == nArm) || (
type == nRPStation) || (
type == nRPPot) || (
type == nSampicBoard) ||
198 (
type == nSampicChannel) || (
type == nTotemTimingPlane) || (
type == nTotemTimingCh));
214 using namespace xercesc;
245 :
verbosity(conf.getUntrackedParameter<unsigned
int>(
"verbosity", 0)),
248 currentBlockValid(
false) {
249 for (
const auto &it : conf.
getParameter<vector<ParameterSet>>(
"configuration")) {
251 b.validityRange = it.getParameter<
EventRange>(
"validityRange");
252 b.mappingFileNames = it.getParameter<vector<string>>(
"mappingFileNames");
253 b.maskFileNames = it.getParameter<vector<string>>(
"maskFileNames");
258 findingRecord<TotemReadoutRcd>();
266 LogVerbatim(
"TotemDAQMappingESSourceXML") <<
">> TotemDAQMappingESSourceXML::setIntervalFor(" <<
key.name() <<
")";
280 if (
range.startEventID().luminosityBlock() == 0 &&
range.startEventID().event() == 1)
292 <<
range.startEventID() <<
" - " <<
range.endEventID() <<
")";
299 throw cms::Exception(
"TotemDAQMappingESSourceXML::setIntervalFor")
300 <<
"No configuration for event " << iosv.
eventID();
321 auto mapping = std::make_unique<TotemDAQMapping>();
322 auto mask = std::make_unique<TotemAnalysisMask>();
326 XMLPlatformUtils::Initialize();
327 }
catch (
const XMLException &toCatch) {
341 XMLPlatformUtils::Terminate();
351 const std::unique_ptr<TotemDAQMapping> &
mapping,
352 const std::unique_ptr<TotemAnalysisMask> &mask) {
353 unique_ptr<XercesDOMParser>
parser(
new XercesDOMParser());
356 DOMDocument *domDoc =
parser->getDocument();
360 <<
"Cannot parse file `" <<
file <<
"' (domDoc = NULL).";
362 DOMElement *elementRoot = domDoc->getDocumentElement();
365 throw cms::Exception(
"TotemDAQMappingESSourceXML::ParseXML") <<
"File `" <<
file <<
"' is empty.";
379 unsigned int parentID,
380 const std::unique_ptr<TotemDAQMapping> &
mapping,
381 const std::unique_ptr<TotemAnalysisMask> &mask) {
383 printf(
">> TotemDAQMappingESSourceXML::ParseTreeRP(%s, %u, %u)\n",
391 for (
unsigned int i = 0;
i <
children->getLength();
i++) {
393 if (
n->getNodeType() != DOMNode::ELEMENT_NODE)
409 expectedParentType =
nTop;
412 expectedParentType =
nArm;
418 expectedParentType =
nRPPot;
424 expectedParentType =
nChip;
431 if (expectedParentType != parentType) {
438 unsigned int id = 0, hw_id = 0;
439 bool id_set =
false, hw_id_set =
false;
440 bool fullMask =
false;
441 DOMNamedNodeMap *attr =
n->getAttributes();
443 for (
unsigned int j = 0;
j < attr->getLength();
j++) {
444 DOMNode *
a = attr->item(
j);
471 <<
"Plane IDs range from 0 to 9. id = " <<
id <<
" is invalid.";
474 printf(
"\tID found: 0x%x\n",
id);
481 vfatInfo.
hwID = hw_id;
483 const unsigned int armIdx = (parentID / 1000) % 10;
484 const unsigned int stIdx = (parentID / 100) % 10;
485 const unsigned int rpIdx = (parentID / 10) % 10;
486 const unsigned int plIdx = parentID % 10;
490 mapping->insert(framepos, vfatInfo);
497 const unsigned int armIdx = (parentID / 1000) % 10;
498 const unsigned int stIdx = (parentID / 100) % 10;
499 const unsigned int rpIdx = (parentID / 10) % 10;
500 const unsigned int plIdx = parentID % 10;
509 mask->insert(symbId, am);
524 unsigned int parentID,
525 const std::unique_ptr<TotemDAQMapping> &
mapping,
526 const std::unique_ptr<TotemAnalysisMask> &mask) {
528 printf(
">> TotemDAQMappingESSourceXML::ParseTreeDiamond(%s, %u, %u)\n",
536 for (
unsigned int i = 0;
i <
children->getLength();
i++) {
538 if (
n->getNodeType() != DOMNode::ELEMENT_NODE)
553 expectedParentType =
nTop;
556 expectedParentType =
nArm;
562 expectedParentType =
nRPPot;
572 if (expectedParentType != parentType) {
579 unsigned int id = 0, hw_id = 0;
580 bool id_set =
false, hw_id_set =
false;
581 DOMNamedNodeMap *attr =
n->getAttributes();
583 for (
unsigned int j = 0;
j < attr->getLength();
j++) {
584 DOMNode *
a = attr->item(
j);
599 throw cms::Exception(
"TotemDAQMappingESSourceXML::ParseTreeDiamond")
603 throw cms::Exception(
"TotemDAQMappingESSourceXML::ParseTreeDiamond")
607 throw cms::Exception(
"TotemDAQMappingESSourceXML::ParseTreeDiamond")
608 <<
"Plane IDs range from 0 to 3. id = " <<
id <<
" is invalid.";
611 printf(
"\tID found: 0x%x\n",
id);
619 vfatInfo.
hwID = hw_id;
622 unsigned int ArmNum = (parentID / 10000) % 10;
623 unsigned int StationNum = (parentID / 1000) % 10;
624 unsigned int RpNum = (parentID / 100) % 10;
625 unsigned int PlaneNum = (parentID % 100);
630 mapping->insert(framepos, vfatInfo);
635 unsigned int childId;
637 childId = parentID * 100 +
id;
639 childId = parentID * 10 +
id;
650 unsigned int parentID,
651 const std::unique_ptr<TotemDAQMapping> &
mapping,
652 const std::unique_ptr<TotemAnalysisMask> &mask) {
656 for (
unsigned int i = 0;
i <
children->getLength();
i++) {
662 DOMNamedNodeMap *attr =
parent->getAttributes();
663 for (
unsigned int j = 0;
j < attr->getLength();
j++) {
664 DOMNode *
a = attr->item(
j);
671 unsigned int hwId = 0;
672 attr =
child->getAttributes();
673 for (
unsigned int j = 0;
j < attr->getLength();
j++) {
674 DOMNode *
a = attr->item(
j);
685 for (
unsigned int i = 0;
i <
children->getLength();
i++) {
687 if (
n->getNodeType() != DOMNode::ELEMENT_NODE)
699 expectedParentType =
nTop;
702 expectedParentType =
nArm;
708 expectedParentType =
nRPPot;
714 expectedParentType =
nRPPot;
724 if (expectedParentType != parentType) {
733 DOMNamedNodeMap *attr =
n->getAttributes();
735 for (
unsigned int j = 0;
j < attr->getLength();
j++) {
736 DOMNode *
a = attr->item(
j);
746 throw cms::Exception(
"TotemDAQMappingESSourceXML::ParseTreeTotemTiming")
749 throw cms::Exception(
"TotemDAQMappingESSourceXML::ParseTreeTotemTiming")
750 <<
"SampicBoard IDs range from 0 to 5. id = " <<
id <<
" is invalid.";
757 unsigned int ArmNum = (parentID / 10000) % 10;
758 unsigned int StationNum = (parentID / 1000) % 10;
759 unsigned int RpNum = (parentID / 100) % 10;
764 mapping->insert(framepos, vfatInfo);
769 unsigned int childId;
771 childId = parentID * 100 +
id;
773 childId = parentID * 10 +
id;
783 unsigned char attributeFlag = 0;
785 DOMNamedNodeMap *attr = chipnode->getAttributes();
786 for (
unsigned int j = 0;
j < attr->getLength();
j++) {
787 DOMNode *
a = attr->item(
j);
788 if (
fp.setXMLAttribute(
796 if (!
fp.checkXMLAttributeFlag(attributeFlag)) {
798 <<
"Wrong/incomplete DAQ channel specification (attributeFlag = " << attributeFlag <<
").";
840 if (
Test(
n,
"trigger_vfat"))
850 DOMNodeList *
children =
n->getChildNodes();
851 for (
unsigned int i = 0;
i <
children->getLength();
i++) {
853 if (
n->getNodeType() != DOMNode::ELEMENT_NODE || !
Test(
n,
"channel"))
856 DOMNamedNodeMap *attr =
n->getAttributes();
858 for (
unsigned int j = 0;
j < attr->getLength();
j++) {
859 DOMNode *
a = attr->item(
j);
871 throw cms::Exception(
"TotemDAQMappingESSourceXML::GetChannels") <<
"Channel tags must have an `id' attribute.";