30 #include <xercesc/parsers/XercesDOMParser.hpp> 31 #include <xercesc/dom/DOM.hpp> 32 #include <xercesc/sax/HandlerBase.hpp> 33 #include <xercesc/util/XMLString.hpp> 34 #include <xercesc/util/PlatformUtils.hpp> 102 enum NodeType {
nUnknown, nSkip, nTop, nArm, nRPStation, nRPPot, nRPixPlane, nROC, nPixel };
108 void ParseXML(
ParseType,
const string &
file,
const std::unique_ptr<CTPPSPixelDAQMapping>&,
const std::unique_ptr<CTPPSPixelAnalysisMask>&);
113 void ParseTreePixel(
ParseType, xercesc::DOMNode *,
NodeType,
unsigned int parentID,
114 const std::unique_ptr<CTPPSPixelDAQMapping>&,
const std::unique_ptr<CTPPSPixelAnalysisMask>&);
118 string CompleteFileName(
const string &fn);
123 return !(name.compare(xercesc::XMLString::transcode(node->getNodeName())));
127 NodeType GetNodeType(xercesc::DOMNode *);
132 return string(xercesc::XMLString::transcode(parent->getTextContent()));
138 return string(xercesc::XMLString::transcode(node->getNodeValue()));
144 void GetPixels(xercesc::DOMNode *
n, std::set<std::pair<unsigned char, unsigned char> > &
pixels);
148 return ((type == nArm)||(type == nRPStation)||(type == nRPPot)||(type == nRPixPlane)||(type == nROC));
180 verbosity(conf.getUntrackedParameter<unsigned
int>(
"verbosity", 0)),
181 subSystemName(conf.getUntrackedParameter<
string>(
"subSystem")),
183 currentBlockValid(
false)
185 for (
const auto it : conf.
getParameter<vector<ParameterSet>>(
"configuration"))
190 b.
maskFileNames = it.getParameter< vector<string> >(
"maskFileNames");
195 findingRecord<CTPPSPixelAnalysisMaskRcd>();
198 findingRecord<CTPPSPixelDAQMappingRcd>();
201 LogVerbatim(
"CTPPSPixelDAQMappingESSourceXML") <<
" Inside CTPPSPixelDAQMappingESSourceXML";
210 <<
">> CTPPSPixelDAQMappingESSourceXML::setIntervalFor(" << key.
name() <<
")";
220 EventID startEventID = bl.validityRange.startEventID();
221 if (startEventID ==
EventID(1, 0, 1))
222 startEventID =
EventID(1, 0, 0);
224 if (startEventID <= iosv.
eventID() && iosv.
eventID() <= bl.validityRange.endEventID())
235 <<
", interval=(" << startEventID <<
" - " << bl.validityRange.endEventID() <<
")";
243 throw cms::Exception(
"CTPPSPixelDAQMappingESSourceXML::setIntervalFor") <<
244 "No configuration for event " << iosv.
eventID();
268 auto mapping = std::make_unique<CTPPSPixelDAQMapping>();
269 auto mask = std::make_unique<CTPPSPixelAnalysisMask>();
294 auto mapping = std::make_unique<CTPPSPixelDAQMapping>();
295 auto mask = std::make_unique<CTPPSPixelAnalysisMask>();
320 const std::unique_ptr<CTPPSPixelDAQMapping> &
mapping,
const std::unique_ptr<CTPPSPixelAnalysisMask> &
mask)
322 unique_ptr<XercesDOMParser>
parser(
new XercesDOMParser());
323 parser->parse(file.c_str());
325 DOMDocument* domDoc = parser->getDocument();
328 throw cms::Exception(
"CTPPSPixelDAQMappingESSourceXML::ParseXML") <<
"Cannot parse file `" << file
329 <<
"' (domDoc = NULL)." << endl;
331 DOMElement* elementRoot = domDoc->getDocumentElement();
334 throw cms::Exception(
"CTPPSPixelDAQMappingESSourceXML::ParseXML") <<
"File `" <<
335 file <<
"' is empty." << endl;
345 unsigned int parentID,
const std::unique_ptr<CTPPSPixelDAQMapping>&
mapping,
346 const std::unique_ptr<CTPPSPixelAnalysisMask>&
mask)
349 printf(
">> CTPPSPixelDAQMappingESSourceXML::ParseTreeRP(%s, %u, %u)\n", XMLString::transcode(parent->getNodeName()),
350 parentType, parentID);
353 DOMNodeList *
children = parent->getChildNodes();
355 for (
unsigned int i = 0;
i < children->getLength();
i++)
357 DOMNode *
n = children->item(
i);
358 if (n->getNodeType() != DOMNode::ELEMENT_NODE)
364 printf(
"\tname = %s, type = %u\n", XMLString::transcode(n->getNodeName()), type);
374 case nArm: expectedParentType =
nTop;
break;
379 case nPixel: expectedParentType =
nROC;
break;
380 default: expectedParentType =
nUnknown;
break;
383 if (expectedParentType != parentType)
385 throw cms::Exception(
"CTPPSPixelDAQMappingESSourceXML") <<
"Node " << XMLString::transcode(n->getNodeName())
386 <<
" not allowed within " << XMLString::transcode(parent->getNodeName()) <<
" block.\n";
392 bool fullMask =
false;
393 DOMNamedNodeMap* attr = n->getAttributes();
395 for (
unsigned int j = 0; j < attr->getLength(); j++)
397 DOMNode *
a = attr->item(j);
399 if (!strcmp(XMLString::transcode(a->getNodeName()),
"id"))
401 sscanf(XMLString::transcode(a->getNodeValue()),
"%u", &
id);
405 if (!strcmp(XMLString::transcode(a->getNodeName()),
"full_mask"))
406 fullMask = (strcmp(XMLString::transcode(a->getNodeValue()),
"no") != 0);
411 throw cms::Exception(
"CTPPSPixelDAQMappingESSourceXML::ParseTreePixel") <<
"id not given for element `" 412 << XMLString::transcode(n->getNodeName()) <<
"'" << endl;
415 throw cms::Exception(
"CTPPSPixelDAQMappingESSourceXML::ParseTreePixel") <<
416 "Plane IDs range from 0 to 5. id = " <<
id <<
" is invalid." << endl;
419 printf(
"\tID found: %u\n",
id);
429 const unsigned int armIdx = (parentID / 1000) % 10;
430 const unsigned int stIdx = (parentID / 100) % 10;
431 const unsigned int rpIdx = (parentID / 10) % 10;
432 const unsigned int plIdx = parentID % 10;
436 mapping->insert(framepos, rocInfo);
444 const unsigned int armIdx = (parentID / 1000) % 10;
445 const unsigned int stIdx = (parentID / 100) % 10;
446 const unsigned int rpIdx = (parentID / 10) % 10;
447 const unsigned int plIdx = parentID % 10;
459 mask->insert(symbId, am);
465 ParseTreePixel(pType, n, type, parentID * 10 +
id, mapping, mask);
475 unsigned char attributeFlag = 0;
477 DOMNamedNodeMap* attr = chipnode->getAttributes();
478 for (
unsigned int j = 0; j < attr->getLength(); j++)
480 DOMNode *
a = attr->item(j);
482 if (fp.
setXMLAttribute(XMLString::transcode(a->getNodeName()), XMLString::transcode(a->getNodeValue()), attributeFlag) > 1)
485 "Unrecognized tag `" << XMLString::transcode(a->getNodeName()) <<
486 "' or incompatible value `" << XMLString::transcode(a->getNodeValue()) <<
494 "Wrong/incomplete DAQ channel specification (attributeFlag = " << attributeFlag <<
")." << endl;
513 throw cms::Exception(
"CTPPSPixelDAQMappingESSourceXML::GetNodeType") <<
"Unknown tag `" 514 << XMLString::transcode(n->getNodeName()) <<
"'.\n";
521 DOMNodeList *
children = n->getChildNodes();
522 for (
unsigned int i = 0;
i < children->getLength();
i++)
524 DOMNode *n = children->item(
i);
525 if (n->getNodeType() != DOMNode::ELEMENT_NODE || !
Test(n,
"pixel"))
528 DOMNamedNodeMap* attr = n->getAttributes();
529 bool pixelSet =
false;
532 std::pair<unsigned int, unsigned int> currentPixel;
533 for (
unsigned int j = 0; j < attr->getLength(); j++)
535 DOMNode *
a = attr->item(j);
537 if (!strcmp(XMLString::transcode(a->getNodeName()),
"row"))
539 unsigned int row = 0;
540 sscanf(XMLString::transcode(a->getNodeValue()),
"%u", &row);
541 currentPixel.first = row;
544 if (!strcmp(XMLString::transcode(a->getNodeName()),
"col"))
546 unsigned int col = 0;
547 sscanf(XMLString::transcode(a->getNodeValue()),
"%u", &col);
548 currentPixel.second =
col;
552 pixelSet = rowSet & colSet;
554 pixels.insert(currentPixel);
563 throw cms::Exception(
"CTPPSPixelDAQMappingESSourceXML::GetChannels") <<
564 "Channel tags must have a row or col attribute.";
string GetNodeContent(xercesc::DOMNode *parent)
returns the content of the node
T getParameter(std::string const &) const
EventNumber_t event() const
CTPPSPixelDAQMappingESSourceXML(const edm::ParameterSet &)
Contains mappind data related to a ROC.
string subSystemName
label of the CTPPS sub-system
bool PixelNode(NodeType type)
void ParseTreePixel(ParseType, xercesc::DOMNode *, NodeType, unsigned int parentID, const std::unique_ptr< CTPPSPixelDAQMapping > &, const std::unique_ptr< CTPPSPixelAnalysisMask > &)
recursive method to extract Pixel-related information from the DOM tree
vector< ConfigBlock > configuration
std::vector< std::string > mappingFileNames
the mapping files
const EventID & eventID() const
static const std::string tagROC
static const unsigned int offsetROCinDetId
std::unique_ptr< CTPPSPixelAnalysisMask > produceCTPPSPixelAnalysisMask(const CTPPSPixelAnalysisMaskRcd &)
CTPPSPixelFramePosition ChipFramePosition(xercesc::DOMNode *chipnode)
extracts VFAT's DAQ channel from XML attributes
ParseType
whether to parse a mapping of a mask XML
static const std::string tagAnalysisMask
NodeType
enumeration of XML node types
std::pair< Time_t, Time_t > ValidityInterval
string CompleteFileName(const string &fn)
adds the path prefix, if needed
unsigned char setXMLAttribute(const std::string &attribute, const std::string &value, unsigned char &flag)
void setWhatProduced(T *iThis, const es::Label &iLabel=es::Label())
Contains data on masked channels of a ROC.
uint32_t iD
the symbolic id
static const std::string tagRPixPlane
Loads CTPPSPixelDAQMapping and CTPPSPixelAnalysisMask from two XML files.
std::unique_ptr< CTPPSPixelDAQMapping > produceCTPPSPixelDAQMapping(const CTPPSPixelDAQMappingRcd &)
bool fullMask
whether all channels of the ROC shall be masked
unsigned int currentBlock
index of the current block in 'configuration' array
std::vector< std::string > mappingFileNames
the mapping files
const char * name() const
void ParseXML(ParseType, const string &file, const std::unique_ptr< CTPPSPixelDAQMapping > &, const std::unique_ptr< CTPPSPixelAnalysisMask > &)
parses XML file
static const std::string tagRPStation
RP XML tags.
edm::EventRange validityRange
validity interval
bool Test(xercesc::DOMNode *node, const std::string &name)
returns true iff the node is of the given name
static bool checkXMLAttributeFlag(unsigned char flag)
returns true if all attributes have been set
#define DEFINE_FWK_EVENTSETUP_SOURCE(type)
bool currentBlockValid
flag whether the 'currentBlock' index is valid
std::vector< std::string > maskFileNames
the mask files
string GetNodeValue(xercesc::DOMNode *node)
returns the value of the node
void GetPixels(xercesc::DOMNode *n, std::set< std::pair< unsigned char, unsigned char > > &pixels)
static const std::string tagPixel
static const std::string tagArm
Common position tags.
~CTPPSPixelDAQMappingESSourceXML()
std::string fullPath() const
static const std::string tagRPPot
virtual void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue &, edm::ValidityInterval &)
sets infinite validity of this data
std::set< std::pair< unsigned char, unsigned char > > maskedPixels
list of channels to be masked
NodeType GetNodeType(xercesc::DOMNode *)
determines node type