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> 116 enum NodeType {
nUnknown, nSkip, nTop, nArm, nRPStation, nRPPot, nRPPlane, nDiamondPlane, nChip, nDiamondCh, nChannel, nSampicBoard, nSampicChannel, nTotemTimingPlane, nTotemTimingCh };
122 void ParseXML(
ParseType,
const string &
file,
const std::shared_ptr<TotemDAQMapping>&,
const std::shared_ptr<TotemAnalysisMask>&);
126 const std::shared_ptr<TotemDAQMapping>&,
const std::shared_ptr<TotemAnalysisMask>&);
129 void ParseTreeDiamond(
ParseType, xercesc::DOMNode *,
NodeType,
unsigned int parentID,
130 const std::shared_ptr<TotemDAQMapping>&,
const std::shared_ptr<TotemAnalysisMask>&);
133 void ParseTreeTotemTiming(
ParseType, xercesc::DOMNode *,
NodeType,
unsigned int parentID,
134 const std::shared_ptr<TotemDAQMapping>&,
const std::shared_ptr<TotemAnalysisMask>&);
138 string CompleteFileName(
const string &fn);
147 NodeType GetNodeType(xercesc::DOMNode *);
164 void GetChannels(xercesc::DOMNode *
n, std::set<unsigned char> &channels);
168 return ((type == nArm)||(type == nRPStation)||(type == nRPPot)||(type == nRPPlane)||(type == nChip));
173 return ((type == nArm)||(type == nRPStation)||(type == nRPPot)||(type == nDiamondPlane)||(type == nDiamondCh));
178 return ((type == nArm)||(type == nRPStation)||(type == nRPPot)||(type == nSampicBoard)||(type == nSampicChannel)||(type == nTotemTimingPlane)||(type == nTotemTimingCh));
183 return ((type==nChip)||(type==nArm));
226 verbosity(conf.getUntrackedParameter<unsigned
int>(
"verbosity", 0)),
227 subSystemName(conf.getUntrackedParameter<
string>(
"subSystem")),
229 currentBlockValid(
false)
231 for (
const auto it : conf.
getParameter<vector<ParameterSet>>(
"configuration"))
236 b.
maskFileNames = it.getParameter< vector<string> >(
"maskFileNames");
241 findingRecord<TotemReadoutRcd>();
250 <<
">> TotemDAQMappingESSourceXML::setIntervalFor(" << key.
name() <<
")";
287 throw cms::Exception(
"TotemDAQMappingESSourceXML::setIntervalFor") <<
288 "No configuration for event " << iosv.
eventID();
313 auto mapping = std::make_shared<TotemDAQMapping>();
314 auto mask = std::make_shared<TotemAnalysisMask>();
319 XMLPlatformUtils::Initialize();
321 catch (
const XMLException& toCatch)
335 XMLPlatformUtils::Terminate();
344 const std::shared_ptr<TotemDAQMapping> &
mapping,
const std::shared_ptr<TotemAnalysisMask> &
mask)
346 unique_ptr<XercesDOMParser>
parser(
new XercesDOMParser());
347 parser->parse(file.c_str());
349 DOMDocument* domDoc = parser->getDocument();
352 throw cms::Exception(
"TotemDAQMappingESSourceXML::ParseXML") <<
"Cannot parse file `" << file
353 <<
"' (domDoc = NULL).";
355 DOMElement* elementRoot = domDoc->getDocumentElement();
358 throw cms::Exception(
"TotemDAQMappingESSourceXML::ParseXML") <<
"File `" <<
359 file <<
"' is empty.";
371 unsigned int parentID,
const std::shared_ptr<TotemDAQMapping>&
mapping,
372 const std::shared_ptr<TotemAnalysisMask>&
mask)
375 printf(
">> TotemDAQMappingESSourceXML::ParseTreeRP(%s, %u, %u)\n",
cms::xerces::toString(parent->getNodeName()),
376 parentType, parentID);
379 DOMNodeList *
children = parent->getChildNodes();
381 for (
unsigned int i = 0;
i < children->getLength();
i++)
383 DOMNode *
n = children->item(
i);
384 if (n->getNodeType() != DOMNode::ELEMENT_NODE)
400 case nArm: expectedParentType =
nTop;
break;
406 default: expectedParentType =
nUnknown;
break;
409 if (expectedParentType != parentType)
416 unsigned int id = 0, hw_id = 0;
417 bool id_set =
false, hw_id_set =
false;
418 bool fullMask =
false;
419 DOMNamedNodeMap* attr = n->getAttributes();
421 for (
unsigned int j = 0; j < attr->getLength(); j++)
423 DOMNode *
a = attr->item(j);
443 throw cms::Exception(
"TotemDAQMappingESSourceXML::ParseTreeRP") <<
"id not given for element `" 447 throw cms::Exception(
"TotemDAQMappingESSourceXML::ParseTreeRP") <<
"hw_id not given for element `" 451 throw cms::Exception(
"TotemDAQMappingESSourceXML::ParseTreeRP") <<
452 "Plane IDs range from 0 to 9. id = " <<
id <<
" is invalid.";
455 printf(
"\tID found: 0x%x\n",
id);
463 vfatInfo.
hwID = hw_id;
465 const unsigned int armIdx = (parentID / 1000) % 10;
466 const unsigned int stIdx = (parentID / 100) % 10;
467 const unsigned int rpIdx = (parentID / 10) % 10;
468 const unsigned int plIdx = parentID % 10;
472 mapping->insert(framepos, vfatInfo);
480 const unsigned int armIdx = (parentID / 1000) % 10;
481 const unsigned int stIdx = (parentID / 100) % 10;
482 const unsigned int rpIdx = (parentID / 10) % 10;
483 const unsigned int plIdx = parentID % 10;
492 mask->insert(symbId, am);
498 ParseTreeRP(pType, n, type, parentID * 10 +
id, mapping, mask);
505 unsigned int parentID,
const std::shared_ptr<TotemDAQMapping>&
mapping,
506 const std::shared_ptr<TotemAnalysisMask>&
mask)
510 printf(
">> TotemDAQMappingESSourceXML::ParseTreeDiamond(%s, %u, %u)\n",
cms::xerces::toString(parent->getNodeName()),
511 parentType, parentID);
514 DOMNodeList *
children = parent->getChildNodes();
516 for (
unsigned int i = 0;
i < children->getLength();
i++)
518 DOMNode *
n = children->item(
i);
519 if (n->getNodeType() != DOMNode::ELEMENT_NODE)
534 case nArm: expectedParentType =
nTop;
break;
539 default: expectedParentType =
nUnknown;
break;
542 if (expectedParentType != parentType)
549 unsigned int id =0,hw_id = 0;
550 bool id_set =
false,hw_id_set =
false;
551 DOMNamedNodeMap* attr = n->getAttributes();
553 for (
unsigned int j = 0; j < attr->getLength(); j++)
555 DOMNode *
a = attr->item(j);
573 throw cms::Exception(
"TotemDAQMappingESSourceXML::ParseTreeDiamond") <<
"id not given for element `" 577 throw cms::Exception(
"TotemDAQMappingESSourceXML::ParseTreeDiamond") <<
"hw_id not given for element `" 581 throw cms::Exception(
"TotemDAQMappingESSourceXML::ParseTreeDiamond") <<
582 "Plane IDs range from 0 to 3. id = " <<
id <<
" is invalid.";
585 printf(
"\tID found: 0x%x\n",
id);
595 vfatInfo.
hwID = hw_id;
599 unsigned int ArmNum = (parentID/ 10000) % 10;
600 unsigned int StationNum = (parentID / 1000) % 10;
601 unsigned int RpNum = (parentID/ 100) % 10;
602 unsigned int PlaneNum = (parentID % 100) ;
610 mapping->insert(framepos, vfatInfo);
615 unsigned int childId;
617 childId = parentID * 100 +
id;
619 childId = parentID * 10 +
id;
631 unsigned int parentID,
const std::shared_ptr<TotemDAQMapping>&
mapping,
632 const std::shared_ptr<TotemAnalysisMask>&
mask)
634 DOMNodeList *
children = parent->getChildNodes();
637 for (
unsigned int i = 0;
i < children->getLength();
i++)
639 DOMNode *
child = children->item(
i);
644 DOMNamedNodeMap* attr = parent->getAttributes();
645 for (
unsigned int j = 0; j < attr->getLength(); j++)
647 DOMNode *
a = attr->item(j);
655 unsigned int hwId = 0;
656 attr = child->getAttributes();
657 for (
unsigned int j = 0; j < attr->getLength(); j++)
659 DOMNode *
a = attr->item(j);
670 for (
unsigned int i = 0;
i < children->getLength();
i++)
672 DOMNode *
n = children->item(
i);
673 if (n->getNodeType() != DOMNode::ELEMENT_NODE)
685 case nArm: expectedParentType =
nTop;
break;
692 default: expectedParentType =
nUnknown;
break;
695 if (expectedParentType != parentType)
704 DOMNamedNodeMap* attr = n->getAttributes();
707 for (
unsigned int j = 0; j < attr->getLength(); j++)
709 DOMNode *
a = attr->item(j);
721 throw cms::Exception(
"TotemDAQMappingESSourceXML::ParseTreeTotemTiming") <<
"id not given for element `" 724 throw cms::Exception(
"TotemDAQMappingESSourceXML::ParseTreeTotemTiming") <<
725 "SampicBoard IDs range from 0 to 5. id = " <<
id <<
" is invalid.";
734 unsigned int ArmNum = (parentID/ 10000) % 10;
735 unsigned int StationNum = (parentID / 1000) % 10;
736 unsigned int RpNum = (parentID/ 100) % 10;
740 mapping->insert(framepos, vfatInfo);
745 unsigned int childId;
747 childId = parentID * 100 +
id;
749 childId = parentID * 10 +
id;
761 unsigned char attributeFlag = 0;
763 DOMNamedNodeMap* attr = chipnode->getAttributes();
764 for (
unsigned int j = 0; j < attr->getLength(); j++)
766 DOMNode *
a = attr->item(j);
779 "Wrong/incomplete DAQ channel specification (attributeFlag = " << attributeFlag <<
").";
810 if (
Test(n,
"trigger_vfat"))
return nSkip;
812 throw cms::Exception(
"TotemDAQMappingESSourceXML::GetNodeType") <<
"Unknown tag `" 820 DOMNodeList *
children = n->getChildNodes();
821 for (
unsigned int i = 0;
i < children->getLength();
i++)
823 DOMNode *n = children->item(
i);
824 if (n->getNodeType() != DOMNode::ELEMENT_NODE || !
Test(n,
"channel"))
827 DOMNamedNodeMap* attr = n->getAttributes();
829 for (
unsigned int j = 0; j < attr->getLength(); j++)
831 DOMNode *
a = attr->item(j);
845 throw cms::Exception(
"TotemDAQMappingESSourceXML::GetChannels") <<
846 "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
bool TotemTimingNode(NodeType type)
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
static const std::string tagSampicCh
NodeType GetNodeType(xercesc::DOMNode *)
determines node type
std::vector< std::string > mappingFileNames
the mapping files
LuminosityBlockNumber_t luminosityBlock() const
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())
ESProducts< std::remove_reference_t< TArgs >... > products(TArgs &&...args)
void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue &, edm::ValidityInterval &) override
sets infinite validity of this data
std::string toString(XMLCh const *toTranscode)
vector< ConfigBlock > configuration
Symbolic ID describing an entity of a TOTEM subdetector.
static const std::string tagTotemTimingPlane
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
Hw Id mapping for Totem Timing (dynamical mapping in Sampic)
#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
void ParseTreeTotemTiming(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
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
std::set< unsigned char > maskedChannels
list of channels to be masked
unsigned int currentBlock
index of the current block in 'configuration' array
static const std::string tagSampicBoard
totem timing specific tags
Detector ID class for CTPPS Timing Diamond detectors. Bits [19:31] : Assigend in CTPPSDetId Calss Bit...
std::string fullPath() const
static const std::string tagRPPot
static const std::string tagRPPlane
std::vector< std::string > mappingFileNames
the mapping files
static const std::string tagTotemTimingCh
~TotemDAQMappingESSourceXML() override
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
Detector ID class for CTPPS Totem Timing detectors. Bits [19:31] : Assigend in CTPPSDetId Calss Bits ...