31 #include <xercesc/parsers/XercesDOMParser.hpp>
32 #include <xercesc/dom/DOM.hpp>
33 #include <xercesc/sax/HandlerBase.hpp>
34 #include <xercesc/util/XMLString.hpp>
35 #include <xercesc/util/PlatformUtils.hpp>
97 enum NodeType {
nUnknown, nSkip, nTop, nArm, nRPStation, nRPPot, nRPixPlane, nROC, nPixel };
103 void ParseXML(ParseType,
105 const std::unique_ptr<CTPPSPixelDAQMapping> &,
106 const std::unique_ptr<CTPPSPixelAnalysisMask> &);
109 void ParseTreePixel(ParseType,
112 unsigned int parentID,
113 const std::unique_ptr<CTPPSPixelDAQMapping> &,
114 const std::unique_ptr<CTPPSPixelAnalysisMask> &);
118 string CompleteFileName(
const string &
fn);
126 NodeType GetNodeType(xercesc::DOMNode *);
137 void GetPixels(xercesc::DOMNode *
n, std::set<std::pair<unsigned char, unsigned char>> &pixels);
140 return ((
type == nArm) || (
type == nRPStation) || (
type == nRPPot) || (
type == nRPixPlane) || (
type == nROC));
154 using namespace xercesc;
172 :
verbosity(conf.getUntrackedParameter<unsigned
int>(
"verbosity", 0)),
175 currentBlockValid(
false) {
176 for (
const auto &it : conf.
getParameter<vector<ParameterSet>>(
"configuration")) {
178 b.validityRange = it.getParameter<
EventRange>(
"validityRange");
179 b.mappingFileNames = it.getParameter<vector<string>>(
"mappingFileNames");
180 b.maskFileNames = it.getParameter<vector<string>>(
"maskFileNames");
185 findingRecord<CTPPSPixelAnalysisMaskRcd>();
188 findingRecord<CTPPSPixelDAQMappingRcd>();
190 LogVerbatim(
"CTPPSPixelDAQMappingESSourceXML") <<
" Inside CTPPSPixelDAQMappingESSourceXML";
197 <<
">> CTPPSPixelDAQMappingESSourceXML::setIntervalFor(" <<
key.name() <<
")";
206 EventID startEventID = bl.validityRange.startEventID();
207 if (startEventID ==
EventID(1, 0, 1))
208 startEventID =
EventID(1, 0, 0);
210 if (startEventID <= iosv.
eventID() && iosv.
eventID() <= bl.validityRange.endEventID()) {
219 << startEventID <<
" - " << bl.validityRange.endEventID() <<
")";
226 throw cms::Exception(
"CTPPSPixelDAQMappingESSourceXML::setIntervalFor")
227 <<
"No configuration for event " << iosv.
eventID();
242 auto mapping = std::make_unique<CTPPSPixelDAQMapping>();
243 auto mask = std::make_unique<CTPPSPixelAnalysisMask>();
268 auto mapping = std::make_unique<CTPPSPixelDAQMapping>();
269 auto mask = std::make_unique<CTPPSPixelAnalysisMask>();
295 const std::unique_ptr<CTPPSPixelDAQMapping> &
mapping,
296 const std::unique_ptr<CTPPSPixelAnalysisMask> &mask) {
297 unique_ptr<XercesDOMParser>
parser(
new XercesDOMParser());
300 DOMDocument *domDoc =
parser->getDocument();
304 <<
"Cannot parse file `" <<
file <<
"' (domDoc = NULL)." << endl;
306 DOMElement *elementRoot = domDoc->getDocumentElement();
309 throw cms::Exception(
"CTPPSPixelDAQMappingESSourceXML::ParseXML") <<
"File `" <<
file <<
"' is empty." << endl;
319 unsigned int parentID,
320 const std::unique_ptr<CTPPSPixelDAQMapping> &
mapping,
321 const std::unique_ptr<CTPPSPixelAnalysisMask> &mask) {
323 printf(
">> CTPPSPixelDAQMappingESSourceXML::ParseTreeRP(%s, %u, %u)\n",
331 for (
unsigned int i = 0;
i <
children->getLength();
i++) {
333 if (
n->getNodeType() != DOMNode::ELEMENT_NODE)
349 expectedParentType =
nTop;
352 expectedParentType =
nArm;
358 expectedParentType =
nRPPot;
364 expectedParentType =
nROC;
371 if (expectedParentType != parentType) {
380 bool fullMask =
false;
381 DOMNamedNodeMap *attr =
n->getAttributes();
383 for (
unsigned int j = 0;
j < attr->getLength();
j++) {
384 DOMNode *
a = attr->item(
j);
397 throw cms::Exception(
"CTPPSPixelDAQMappingESSourceXML::ParseTreePixel")
401 throw cms::Exception(
"CTPPSPixelDAQMappingESSourceXML::ParseTreePixel")
402 <<
"Plane IDs range from 0 to 5. id = " <<
id <<
" is invalid." << endl;
405 printf(
"\tID found: %u\n",
id);
414 const unsigned int armIdx = (parentID / 1000) % 10;
415 const unsigned int stIdx = (parentID / 100) % 10;
416 const unsigned int rpIdx = (parentID / 10) % 10;
417 const unsigned int plIdx = parentID % 10;
421 mapping->insert(framepos, rocInfo);
428 const unsigned int armIdx = (parentID / 1000) % 10;
429 const unsigned int stIdx = (parentID / 100) % 10;
430 const unsigned int rpIdx = (parentID / 10) % 10;
431 const unsigned int plIdx = parentID % 10;
441 mask->insert(symbId, am);
455 unsigned char attributeFlag = 0;
457 DOMNamedNodeMap *attr = chipnode->getAttributes();
458 for (
unsigned int j = 0;
j < attr->getLength();
j++) {
459 DOMNode *
a = attr->item(
j);
461 if (
fp.setXMLAttribute(
469 if (!
fp.checkXMLAttributeFlag(attributeFlag)) {
471 <<
"Wrong/incomplete DAQ channel specification (attributeFlag = " << attributeFlag <<
")." << endl;
494 throw cms::Exception(
"CTPPSPixelDAQMappingESSourceXML::GetNodeType")
501 set<std::pair<unsigned char, unsigned char>> &pixels) {
502 DOMNodeList *
children =
n->getChildNodes();
503 for (
unsigned int i = 0;
i <
children->getLength();
i++) {
505 if (
n->getNodeType() != DOMNode::ELEMENT_NODE || !
Test(
n,
"pixel"))
508 DOMNamedNodeMap *attr =
n->getAttributes();
509 bool pixelSet =
false;
512 std::pair<unsigned int, unsigned int> currentPixel;
513 for (
unsigned int j = 0;
j < attr->getLength();
j++) {
514 DOMNode *
a = attr->item(
j);
517 unsigned int row = 0;
519 currentPixel.first = row;
523 unsigned int col = 0;
525 currentPixel.second =
col;
529 pixelSet = rowSet & colSet;
531 pixels.insert(currentPixel);
537 throw cms::Exception(
"CTPPSPixelDAQMappingESSourceXML::GetChannels")
538 <<
"Channel tags must have a row or col attribute.";