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>
107 enum NodeType {
nUnknown, nSkip, nTop, nArm, nRPStation, nRPPot, nRPPlane, nDiamondPlane, nChip, nDiamondCh, nChannel };
113 void ParseXML(ParseType,
const string &
file,
const boost::shared_ptr<TotemDAQMapping>&,
const boost::shared_ptr<TotemAnalysisMask>&);
116 void ParseTreeRP(ParseType, xercesc::DOMNode *, NodeType,
unsigned int parentID,
117 const boost::shared_ptr<TotemDAQMapping>&,
const boost::shared_ptr<TotemAnalysisMask>&);
120 void ParseTreeDiamond(ParseType, xercesc::DOMNode *, NodeType,
unsigned int parentID,
121 const boost::shared_ptr<TotemDAQMapping>&,
const boost::shared_ptr<TotemAnalysisMask>&);
125 string CompleteFileName(
const string &
fn);
130 return !(name.compare(xercesc::XMLString::transcode(node->getNodeName())));
134 NodeType GetNodeType(xercesc::DOMNode *);
139 return string(xercesc::XMLString::transcode(parent->getTextContent()));
145 return string(xercesc::XMLString::transcode(node->getNodeValue()));
151 void GetChannels(xercesc::DOMNode *
n, std::set<unsigned char> &channels);
155 return ((type == nArm)||(type == nRPStation)||(type == nRPPot)||(type == nRPPlane)||(type == nChip));
160 return ((type == nArm)||(type == nRPStation)||(type == nRPPot)||(type == nDiamondPlane)||(type == nDiamondCh));
164 return ((type==nChip)||(type==nArm));
176 using namespace xercesc;
202 verbosity(conf.getUntrackedParameter<unsigned int>(
"verbosity", 0)),
203 subSystemName(conf.getUntrackedParameter<
string>(
"subSystem")),
205 currentBlockValid(
false)
207 for (
const auto it : conf.
getParameter<vector<ParameterSet>>(
"configuration"))
212 b.
maskFileNames = it.getParameter< vector<string> >(
"maskFileNames");
217 findingRecord<TotemReadoutRcd>();
226 <<
">> TotemDAQMappingESSourceXML::setIntervalFor(" << key.
name() <<
")";
232 for (
unsigned int idx = 0; idx <
configuration.size(); ++idx)
237 EventID startEventID = bl.validityRange.startEventID();
238 if (startEventID ==
EventID(1, 0, 1))
239 startEventID =
EventID(1, 0, 0);
241 if (startEventID <= iosv.
eventID() && iosv.
eventID() <= bl.validityRange.endEventID())
252 <<
", interval=(" << startEventID <<
" - " << bl.validityRange.endEventID() <<
")";
260 throw cms::Exception(
"TotemDAQMappingESSourceXML::setIntervalFor") <<
261 "No configuration for event " << iosv.
eventID();
292 XMLPlatformUtils::Initialize();
294 catch (
const XMLException& toCatch)
296 char*
message = XMLString::transcode(toCatch.getMessage());
297 throw cms::Exception(
"TotemDAQMappingESSourceXML") <<
"An XMLException caught with message: " << message <<
".\n";
310 XMLPlatformUtils::Terminate();
319 const boost::shared_ptr<TotemDAQMapping> &mapping,
const boost::shared_ptr<TotemAnalysisMask> &mask)
321 unique_ptr<XercesDOMParser>
parser(
new XercesDOMParser());
322 parser->parse(file.c_str());
324 DOMDocument* domDoc = parser->getDocument();
327 throw cms::Exception(
"TotemDAQMappingESSourceXML::ParseXML") <<
"Cannot parse file `" << file
328 <<
"' (domDoc = NULL)." << endl;
330 DOMElement* elementRoot = domDoc->getDocumentElement();
333 throw cms::Exception(
"TotemDAQMappingESSourceXML::ParseXML") <<
"File `" <<
334 file <<
"' is empty." << endl;
344 unsigned int parentID,
const boost::shared_ptr<TotemDAQMapping>& mapping,
345 const boost::shared_ptr<TotemAnalysisMask>& mask)
348 printf(
">> TotemDAQMappingESSourceXML::ParseTreeRP(%s, %u, %u)\n", XMLString::transcode(parent->getNodeName()),
349 parentType, parentID);
352 DOMNodeList *children = parent->getChildNodes();
354 for (
unsigned int i = 0;
i < children->getLength();
i++)
356 DOMNode *
n = children->item(
i);
357 if (n->getNodeType() != DOMNode::ELEMENT_NODE)
363 printf(
"\tname = %s, type = %u\n", XMLString::transcode(n->getNodeName()), type);
373 case nArm: expectedParentType =
nTop;
break;
379 default: expectedParentType =
nUnknown;
break;
382 if (expectedParentType != parentType)
384 throw cms::Exception(
"TotemDAQMappingESSourceXML") <<
"Node " << XMLString::transcode(n->getNodeName())
385 <<
" not allowed within " << XMLString::transcode(parent->getNodeName()) <<
" block.\n";
389 unsigned int id = 0, hw_id = 0;
390 bool id_set =
false, hw_id_set =
false;
391 bool fullMask =
false;
392 DOMNamedNodeMap* attr = n->getAttributes();
394 for (
unsigned int j = 0;
j < attr->getLength();
j++)
396 DOMNode *
a = attr->item(
j);
398 if (!strcmp(XMLString::transcode(a->getNodeName()),
"id"))
400 sscanf(XMLString::transcode(a->getNodeValue()),
"%u", &
id);
404 if (!strcmp(XMLString::transcode(a->getNodeName()),
"hw_id"))
406 sscanf(XMLString::transcode(a->getNodeValue()),
"%x", &hw_id);
410 if (!strcmp(XMLString::transcode(a->getNodeName()),
"full_mask"))
411 fullMask = (strcmp(XMLString::transcode(a->getNodeValue()),
"no") != 0);
416 throw cms::Exception(
"TotemDAQMappingESSourceXML::ParseTreeRP") <<
"id not given for element `"
417 << XMLString::transcode(n->getNodeName()) <<
"'" << endl;
420 throw cms::Exception(
"TotemDAQMappingESSourceXML::ParseTreeRP") <<
"hw_id not given for element `"
421 << XMLString::transcode(n->getNodeName()) <<
"'" << endl;
424 throw cms::Exception(
"TotemDAQMappingESSourceXML::ParseTreeRP") <<
425 "Plane IDs range from 0 to 9. id = " <<
id <<
" is invalid." << endl;
428 printf(
"\tID found: 0x%x\n",
id);
436 vfatInfo.
hwID = hw_id;
438 const unsigned int armIdx = (parentID / 1000) % 10;
439 const unsigned int stIdx = (parentID / 100) % 10;
440 const unsigned int rpIdx = (parentID / 10) % 10;
441 const unsigned int plIdx = parentID % 10;
445 mapping->insert(framepos, vfatInfo);
453 const unsigned int armIdx = (parentID / 1000) % 10;
454 const unsigned int stIdx = (parentID / 100) % 10;
455 const unsigned int rpIdx = (parentID / 10) % 10;
456 const unsigned int plIdx = parentID % 10;
465 mask->insert(symbId, am);
471 ParseTreeRP(pType, n, type, parentID * 10 +
id, mapping, mask);
478 unsigned int parentID,
const boost::shared_ptr<TotemDAQMapping>& mapping,
479 const boost::shared_ptr<TotemAnalysisMask>& mask)
483 printf(
">> TotemDAQMappingESSourceXML::ParseTreeDiamond(%s, %u, %u)\n", XMLString::transcode(parent->getNodeName()),
484 parentType, parentID);
487 DOMNodeList *children = parent->getChildNodes();
489 for (
unsigned int i = 0;
i < children->getLength();
i++)
491 DOMNode *
n = children->item(
i);
492 if (n->getNodeType() != DOMNode::ELEMENT_NODE)
497 printf(
"\tname = %s, type = %u\n", XMLString::transcode(n->getNodeName()), type);
507 case nArm: expectedParentType =
nTop;
break;
512 default: expectedParentType =
nUnknown;
break;
515 if (expectedParentType != parentType)
517 throw cms::Exception(
"TotemDAQMappingESSourceXML") <<
"Node " << XMLString::transcode(n->getNodeName())
518 <<
" not allowed within " << XMLString::transcode(parent->getNodeName()) <<
" block.\n";
522 unsigned int id =0,hw_id = 0;
523 bool id_set =
false,hw_id_set =
false;
524 DOMNamedNodeMap* attr = n->getAttributes();
526 for (
unsigned int j = 0;
j < attr->getLength();
j++)
528 DOMNode *
a = attr->item(
j);
530 if (!strcmp(XMLString::transcode(a->getNodeName()),
"id"))
532 sscanf(XMLString::transcode(a->getNodeValue()),
"%u", &
id);
536 if (!strcmp(XMLString::transcode(a->getNodeName()),
"hw_id"))
538 sscanf(XMLString::transcode(a->getNodeValue()),
"%x", &hw_id);
546 throw cms::Exception(
"TotemDAQMappingESSourceXML::ParseTreeDiamond") <<
"id not given for element `"
547 << XMLString::transcode(n->getNodeName()) <<
"'" << endl;
551 throw cms::Exception(
"TotemDAQMappingESSourceXML::ParseTreeDiamond") <<
"hw_id not given for element `"
552 << XMLString::transcode(n->getNodeName()) <<
"'" << endl;
555 throw cms::Exception(
"TotemDAQMappingESSourceXML::ParseTreeDiamond") <<
556 "Plane IDs range from 0 to 3. id = " <<
id <<
" is invalid." << endl;
559 printf(
"\tID found: 0x%x\n",
id);
569 vfatInfo.
hwID = hw_id;
573 unsigned int ArmNum = (parentID/ 10000) % 10;
574 unsigned int StationNum = (parentID / 1000) % 10;
575 unsigned int RpNum = (parentID/ 100) % 10;
576 unsigned int PlaneNum = (parentID % 100) ;
584 mapping->insert(framepos, vfatInfo);
589 unsigned int childId;
591 childId = parentID * 100 + id;
593 childId = parentID * 10 + id;
607 unsigned char attributeFlag = 0;
609 DOMNamedNodeMap* attr = chipnode->getAttributes();
610 for (
unsigned int j = 0;
j < attr->getLength();
j++)
612 DOMNode *
a = attr->item(
j);
613 if (fp.
setXMLAttribute(XMLString::transcode(a->getNodeName()), XMLString::transcode(a->getNodeValue()), attributeFlag) > 1)
616 "Unrecognized tag `" << XMLString::transcode(a->getNodeName()) <<
617 "' or incompatible value `" << XMLString::transcode(a->getNodeValue()) <<
625 "Wrong/incomplete DAQ channel specification (attributeFlag = " << attributeFlag <<
")." << endl;
650 if (
Test(n,
"trigger_vfat"))
return nSkip;
652 throw cms::Exception(
"TotemDAQMappingESSourceXML::GetNodeType") <<
"Unknown tag `"
653 << XMLString::transcode(n->getNodeName()) <<
"'.\n";
660 DOMNodeList *children = n->getChildNodes();
661 for (
unsigned int i = 0;
i < children->getLength();
i++)
663 DOMNode *n = children->item(
i);
664 if (n->getNodeType() != DOMNode::ELEMENT_NODE || !
Test(n,
"channel"))
667 DOMNamedNodeMap* attr = n->getAttributes();
669 for (
unsigned int j = 0;
j < attr->getLength();
j++)
671 DOMNode *
a = attr->item(
j);
673 if (!strcmp(XMLString::transcode(a->getNodeName()),
"id"))
676 sscanf(XMLString::transcode(a->getNodeValue()),
"%u", &
id);
685 throw cms::Exception(
"TotemDAQMappingESSourceXML::GetChannels") <<
686 "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
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
void ParseTreeDiamond(ParseType, xercesc::DOMNode *, NodeType, unsigned int parentID, const boost::shared_ptr< TotemDAQMapping > &, const boost::shared_ptr< TotemAnalysisMask > &)
recursive method to extract RP-related information from the DOM tree
std::pair< Time_t, Time_t > ValidityInterval
TotemSymbID symbolicID
the symbolic id
void ParseXML(ParseType, const string &file, const boost::shared_ptr< TotemDAQMapping > &, const boost::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
The mapping between FramePosition and VFATInfo.
static const std::string tagRPStation
RP XML tags.
TotemFramePosition ChipFramePosition(xercesc::DOMNode *chipnode)
extracts VFAT's DAQ channel from XML attributes
void ParseTreeRP(ParseType, xercesc::DOMNode *, NodeType, unsigned int parentID, const boost::shared_ptr< TotemDAQMapping > &, const boost::shared_ptr< TotemAnalysisMask > &)
recursive method to extract RP-related information from the DOM tree
const char * name() const
std::vector< std::string > maskFileNames
the mask files
bool DiamondNode(NodeType type)
bool fullMask
whether all channels of the VFAT shall be masked
string key
FastSim: produces sample of signal events, overlayed with premixed minbias events.
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 &)
edm::ESProducts< boost::shared_ptr< TotemDAQMapping >, boost::shared_ptr< TotemAnalysisMask > > produce(const TotemReadoutRcd &)
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
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
volatile std::atomic< bool > shutdown_flag false
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.
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