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> 108 enum NodeType {
nUnknown, nSkip, nTop, nArm, nRPStation, nRPPot, nRPPlane, nDiamondPlane, nChip, nDiamondCh, nChannel };
114 void ParseXML(
ParseType,
const string &
file,
const std::shared_ptr<TotemDAQMapping>&,
const std::shared_ptr<TotemAnalysisMask>&);
118 const std::shared_ptr<TotemDAQMapping>&,
const std::shared_ptr<TotemAnalysisMask>&);
121 void ParseTreeDiamond(
ParseType, xercesc::DOMNode *,
NodeType,
unsigned int parentID,
122 const std::shared_ptr<TotemDAQMapping>&,
const std::shared_ptr<TotemAnalysisMask>&);
126 string CompleteFileName(
const string &fn);
131 return !(name.compare(xercesc::XMLString::transcode(node->getNodeName())));
135 NodeType GetNodeType(xercesc::DOMNode *);
140 return string(xercesc::XMLString::transcode(parent->getTextContent()));
146 return string(xercesc::XMLString::transcode(node->getNodeValue()));
152 void GetChannels(xercesc::DOMNode *
n, std::set<unsigned char> &channels);
156 return ((type == nArm)||(type == nRPStation)||(type == nRPPot)||(type == nRPPlane)||(type == nChip));
161 return ((type == nArm)||(type == nRPStation)||(type == nRPPot)||(type == nDiamondPlane)||(type == nDiamondCh));
165 return ((type==nChip)||(type==nArm));
203 verbosity(conf.getUntrackedParameter<unsigned
int>(
"verbosity", 0)),
204 subSystemName(conf.getUntrackedParameter<
string>(
"subSystem")),
206 currentBlockValid(
false)
208 for (
const auto it : conf.
getParameter<vector<ParameterSet>>(
"configuration"))
213 b.
maskFileNames = it.getParameter< vector<string> >(
"maskFileNames");
218 findingRecord<TotemReadoutRcd>();
227 <<
">> TotemDAQMappingESSourceXML::setIntervalFor(" << key.
name() <<
")";
262 throw cms::Exception(
"TotemDAQMappingESSourceXML::setIntervalFor") <<
263 "No configuration for event " << iosv.
eventID();
288 auto mapping = std::make_shared<TotemDAQMapping>();
289 auto mask = std::make_shared<TotemAnalysisMask>();
294 XMLPlatformUtils::Initialize();
296 catch (
const XMLException& toCatch)
298 char*
message = XMLString::transcode(toCatch.getMessage());
299 throw cms::Exception(
"TotemDAQMappingESSourceXML") <<
"An XMLException caught with message: " << message <<
".\n";
312 XMLPlatformUtils::Terminate();
321 const std::shared_ptr<TotemDAQMapping> &
mapping,
const std::shared_ptr<TotemAnalysisMask> &
mask)
323 unique_ptr<XercesDOMParser>
parser(
new XercesDOMParser());
324 parser->parse(file.c_str());
326 DOMDocument* domDoc = parser->getDocument();
329 throw cms::Exception(
"TotemDAQMappingESSourceXML::ParseXML") <<
"Cannot parse file `" << file
330 <<
"' (domDoc = NULL)." << endl;
332 DOMElement* elementRoot = domDoc->getDocumentElement();
335 throw cms::Exception(
"TotemDAQMappingESSourceXML::ParseXML") <<
"File `" <<
336 file <<
"' is empty." << endl;
346 unsigned int parentID,
const std::shared_ptr<TotemDAQMapping>&
mapping,
347 const std::shared_ptr<TotemAnalysisMask>&
mask)
350 printf(
">> TotemDAQMappingESSourceXML::ParseTreeRP(%s, %u, %u)\n", XMLString::transcode(parent->getNodeName()),
351 parentType, parentID);
354 DOMNodeList *
children = parent->getChildNodes();
356 for (
unsigned int i = 0;
i < children->getLength();
i++)
358 DOMNode *
n = children->item(
i);
359 if (n->getNodeType() != DOMNode::ELEMENT_NODE)
365 printf(
"\tname = %s, type = %u\n", XMLString::transcode(n->getNodeName()), type);
375 case nArm: expectedParentType =
nTop;
break;
381 default: expectedParentType =
nUnknown;
break;
384 if (expectedParentType != parentType)
386 throw cms::Exception(
"TotemDAQMappingESSourceXML") <<
"Node " << XMLString::transcode(n->getNodeName())
387 <<
" not allowed within " << XMLString::transcode(parent->getNodeName()) <<
" block.\n";
391 unsigned int id = 0, hw_id = 0;
392 bool id_set =
false, hw_id_set =
false;
393 bool fullMask =
false;
394 DOMNamedNodeMap* attr = n->getAttributes();
396 for (
unsigned int j = 0; j < attr->getLength(); j++)
398 DOMNode *
a = attr->item(j);
400 if (!strcmp(XMLString::transcode(a->getNodeName()),
"id"))
402 sscanf(XMLString::transcode(a->getNodeValue()),
"%u", &
id);
406 if (!strcmp(XMLString::transcode(a->getNodeName()),
"hw_id"))
408 sscanf(XMLString::transcode(a->getNodeValue()),
"%x", &hw_id);
412 if (!strcmp(XMLString::transcode(a->getNodeName()),
"full_mask"))
413 fullMask = (strcmp(XMLString::transcode(a->getNodeValue()),
"no") != 0);
418 throw cms::Exception(
"TotemDAQMappingESSourceXML::ParseTreeRP") <<
"id not given for element `" 419 << XMLString::transcode(n->getNodeName()) <<
"'" << endl;
422 throw cms::Exception(
"TotemDAQMappingESSourceXML::ParseTreeRP") <<
"hw_id not given for element `" 423 << XMLString::transcode(n->getNodeName()) <<
"'" << endl;
426 throw cms::Exception(
"TotemDAQMappingESSourceXML::ParseTreeRP") <<
427 "Plane IDs range from 0 to 9. id = " <<
id <<
" is invalid." << endl;
430 printf(
"\tID found: 0x%x\n",
id);
438 vfatInfo.
hwID = hw_id;
440 const unsigned int armIdx = (parentID / 1000) % 10;
441 const unsigned int stIdx = (parentID / 100) % 10;
442 const unsigned int rpIdx = (parentID / 10) % 10;
443 const unsigned int plIdx = parentID % 10;
447 mapping->insert(framepos, vfatInfo);
455 const unsigned int armIdx = (parentID / 1000) % 10;
456 const unsigned int stIdx = (parentID / 100) % 10;
457 const unsigned int rpIdx = (parentID / 10) % 10;
458 const unsigned int plIdx = parentID % 10;
467 mask->insert(symbId, am);
473 ParseTreeRP(pType, n, type, parentID * 10 +
id, mapping, mask);
480 unsigned int parentID,
const std::shared_ptr<TotemDAQMapping>&
mapping,
481 const std::shared_ptr<TotemAnalysisMask>&
mask)
485 printf(
">> TotemDAQMappingESSourceXML::ParseTreeDiamond(%s, %u, %u)\n", XMLString::transcode(parent->getNodeName()),
486 parentType, parentID);
489 DOMNodeList *
children = parent->getChildNodes();
491 for (
unsigned int i = 0;
i < children->getLength();
i++)
493 DOMNode *
n = children->item(
i);
494 if (n->getNodeType() != DOMNode::ELEMENT_NODE)
499 printf(
"\tname = %s, type = %u\n", XMLString::transcode(n->getNodeName()), type);
509 case nArm: expectedParentType =
nTop;
break;
514 default: expectedParentType =
nUnknown;
break;
517 if (expectedParentType != parentType)
519 throw cms::Exception(
"TotemDAQMappingESSourceXML") <<
"Node " << XMLString::transcode(n->getNodeName())
520 <<
" not allowed within " << XMLString::transcode(parent->getNodeName()) <<
" block.\n";
524 unsigned int id =0,hw_id = 0;
525 bool id_set =
false,hw_id_set =
false;
526 DOMNamedNodeMap* attr = n->getAttributes();
528 for (
unsigned int j = 0; j < attr->getLength(); j++)
530 DOMNode *
a = attr->item(j);
532 if (!strcmp(XMLString::transcode(a->getNodeName()),
"id"))
534 sscanf(XMLString::transcode(a->getNodeValue()),
"%u", &
id);
538 if (!strcmp(XMLString::transcode(a->getNodeName()),
"hw_id"))
540 sscanf(XMLString::transcode(a->getNodeValue()),
"%x", &hw_id);
548 throw cms::Exception(
"TotemDAQMappingESSourceXML::ParseTreeDiamond") <<
"id not given for element `" 549 << XMLString::transcode(n->getNodeName()) <<
"'" << endl;
553 throw cms::Exception(
"TotemDAQMappingESSourceXML::ParseTreeDiamond") <<
"hw_id not given for element `" 554 << XMLString::transcode(n->getNodeName()) <<
"'" << endl;
557 throw cms::Exception(
"TotemDAQMappingESSourceXML::ParseTreeDiamond") <<
558 "Plane IDs range from 0 to 3. id = " <<
id <<
" is invalid." << endl;
561 printf(
"\tID found: 0x%x\n",
id);
571 vfatInfo.
hwID = hw_id;
575 unsigned int ArmNum = (parentID/ 10000) % 10;
576 unsigned int StationNum = (parentID / 1000) % 10;
577 unsigned int RpNum = (parentID/ 100) % 10;
578 unsigned int PlaneNum = (parentID % 100) ;
586 mapping->insert(framepos, vfatInfo);
591 unsigned int childId;
593 childId = parentID * 100 +
id;
595 childId = parentID * 10 +
id;
609 unsigned char attributeFlag = 0;
611 DOMNamedNodeMap* attr = chipnode->getAttributes();
612 for (
unsigned int j = 0; j < attr->getLength(); j++)
614 DOMNode *
a = attr->item(j);
615 if (fp.
setXMLAttribute(XMLString::transcode(a->getNodeName()), XMLString::transcode(a->getNodeValue()), attributeFlag) > 1)
618 "Unrecognized tag `" << XMLString::transcode(a->getNodeName()) <<
619 "' or incompatible value `" << XMLString::transcode(a->getNodeValue()) <<
627 "Wrong/incomplete DAQ channel specification (attributeFlag = " << attributeFlag <<
")." << endl;
652 if (
Test(n,
"trigger_vfat"))
return nSkip;
654 throw cms::Exception(
"TotemDAQMappingESSourceXML::GetNodeType") <<
"Unknown tag `" 655 << XMLString::transcode(n->getNodeName()) <<
"'.\n";
662 DOMNodeList *
children = n->getChildNodes();
663 for (
unsigned int i = 0;
i < children->getLength();
i++)
665 DOMNode *n = children->item(
i);
666 if (n->getNodeType() != DOMNode::ELEMENT_NODE || !
Test(n,
"channel"))
669 DOMNamedNodeMap* attr = n->getAttributes();
671 for (
unsigned int j = 0; j < attr->getLength(); j++)
673 DOMNode *
a = attr->item(j);
675 if (!strcmp(XMLString::transcode(a->getNodeName()),
"id"))
678 sscanf(XMLString::transcode(a->getNodeValue()),
"%u", &
id);
687 throw cms::Exception(
"TotemDAQMappingESSourceXML::GetChannels") <<
688 "Channel tags must have an `id' attribute.";
Detector ID class for TOTEM Si strip detectors.
T getParameter(std::string const &) const
EventNumber_t event() const
Contains data on masked channels of a VFAT.
static const std::string tagChannel
bool CommonNode(NodeType type)
string GetNodeContent(xercesc::DOMNode *parent)
returns the content of the node
bool contains(EventRange const &lh, EventID const &rh)
Loads TotemDAQMapping and TotemAnalysisMask from two XML files.
static const std::string tagDiamondPlane
diamond specific tags
const EventID & eventID() const
edm::EventRange validityRange
validity interval
bool RPNode(NodeType type)
EventSetup record for TOTEM readout-related information.
bool currentBlockValid
flag whether the 'currentBlock' index is valid
NodeType
enumeration of XML node types
std::pair< Time_t, Time_t > ValidityInterval
TotemSymbID symbolicID
the symbolic id
void ParseXML(ParseType, const string &file, const std::shared_ptr< TotemDAQMapping > &, const std::shared_ptr< TotemAnalysisMask > &)
parses XML file
NodeType GetNodeType(xercesc::DOMNode *)
determines node type
std::vector< std::string > mappingFileNames
the mapping files
static const std::string tagVFAT
static const std::string tagChip1
COMMON Chip XML tags.
string subSystemName
label of the CTPPS sub-system
void setWhatProduced(T *iThis, const es::Label &iLabel=es::Label())
vector< ConfigBlock > configuration
Symbolic ID describing an entity of a TOTEM subdetector.
ESProducts< T, S > products(const T &i1, const S &i2)
static const std::string tagDiamondCh
EventID startEventID() const
static const std::string tagRPStation
RP XML tags.
TotemFramePosition ChipFramePosition(xercesc::DOMNode *chipnode)
extracts VFAT's DAQ channel from XML attributes
const char * name() const
EventID endEventID() const
std::vector< std::string > maskFileNames
the mask files
bool DiamondNode(NodeType type)
bool fullMask
whether all channels of the VFAT shall be masked
void ParseTreeRP(ParseType, xercesc::DOMNode *, NodeType, unsigned int parentID, const std::shared_ptr< TotemDAQMapping > &, const std::shared_ptr< TotemAnalysisMask > &)
recursive method to extract RP-related information from the DOM tree
unsigned int symbolicID
chip ID, raw integer representation of DetId class
#define DEFINE_FWK_EVENTSETUP_SOURCE(type)
static const std::string tagArm
Common position tags.
unsigned int hwID
the hardware ID (16 bit)
TotemDAQMappingESSourceXML(const edm::ParameterSet &)
string GetNodeValue(xercesc::DOMNode *node)
returns the value of the node
ParseType
whether to parse a mapping of a mask XML
bool Test(xercesc::DOMNode *node, const std::string &name)
returns true iff the node is of the given name
edm::ESProducts< std::shared_ptr< TotemDAQMapping >, std::shared_ptr< TotemAnalysisMask > > produce(const TotemReadoutRcd &)
static const std::string tagAnalysisMask
static const std::string tagChip2
virtual void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue &, edm::ValidityInterval &)
sets infinite validity of this data
std::set< unsigned char > maskedChannels
list of channels to be masked
unsigned int currentBlock
index of the current block in 'configuration' array
Detector ID class for CTPPS Timing Diamond detectors. Bits [19:31] : Assigend in CTPPSDetId Calss Bit...
static const std::string tagRPPot
static const std::string tagRPPlane
std::vector< std::string > mappingFileNames
the mapping files
std::string fullPath() const
~TotemDAQMappingESSourceXML()
void GetChannels(xercesc::DOMNode *n, std::set< unsigned char > &channels)
static bool checkXMLAttributeFlag(unsigned char flag)
returns true if all attributes have been set
Contains mappind data related to a VFAT.
void ParseTreeDiamond(ParseType, xercesc::DOMNode *, NodeType, unsigned int parentID, const std::shared_ptr< TotemDAQMapping > &, const std::shared_ptr< TotemAnalysisMask > &)
recursive method to extract RP-related information from the DOM tree
unsigned char setXMLAttribute(const std::string &attribute, const std::string &value, unsigned char &flag)
string CompleteFileName(const string &fn)
adds the path prefix, if needed