32 #include <xercesc/parsers/XercesDOMParser.hpp> 33 #include <xercesc/dom/DOM.hpp> 34 #include <xercesc/sax/HandlerBase.hpp> 35 #include <xercesc/util/XMLString.hpp> 36 #include <xercesc/util/PlatformUtils.hpp> 109 enum NodeType {
nUnknown, nSkip, nTop, nArm, nRPStation, nRPPot, nRPPlane, nDiamondPlane, nChip, nDiamondCh, nChannel };
115 void ParseXML(
ParseType,
const string &
file,
const std::shared_ptr<TotemDAQMapping>&,
const std::shared_ptr<TotemAnalysisMask>&);
119 const std::shared_ptr<TotemDAQMapping>&,
const std::shared_ptr<TotemAnalysisMask>&);
122 void ParseTreeDiamond(
ParseType, xercesc::DOMNode *,
NodeType,
unsigned int parentID,
123 const std::shared_ptr<TotemDAQMapping>&,
const std::shared_ptr<TotemAnalysisMask>&);
127 string CompleteFileName(
const string &fn);
136 NodeType GetNodeType(xercesc::DOMNode *);
153 void GetChannels(xercesc::DOMNode *
n, std::set<unsigned char> &channels);
157 return ((type == nArm)||(type == nRPStation)||(type == nRPPot)||(type == nRPPlane)||(type == nChip));
162 return ((type == nArm)||(type == nRPStation)||(type == nRPPot)||(type == nDiamondPlane)||(type == nDiamondCh));
166 return ((type==nChip)||(type==nArm));
204 verbosity(conf.getUntrackedParameter<unsigned
int>(
"verbosity", 0)),
205 subSystemName(conf.getUntrackedParameter<
string>(
"subSystem")),
207 currentBlockValid(
false)
209 for (
const auto it : conf.
getParameter<vector<ParameterSet>>(
"configuration"))
214 b.
maskFileNames = it.getParameter< vector<string> >(
"maskFileNames");
219 findingRecord<TotemReadoutRcd>();
228 <<
">> TotemDAQMappingESSourceXML::setIntervalFor(" << key.
name() <<
")";
265 throw cms::Exception(
"TotemDAQMappingESSourceXML::setIntervalFor") <<
266 "No configuration for event " << iosv.
eventID();
291 auto mapping = std::make_shared<TotemDAQMapping>();
292 auto mask = std::make_shared<TotemAnalysisMask>();
297 XMLPlatformUtils::Initialize();
299 catch (
const XMLException& toCatch)
313 XMLPlatformUtils::Terminate();
322 const std::shared_ptr<TotemDAQMapping> &
mapping,
const std::shared_ptr<TotemAnalysisMask> &
mask)
324 unique_ptr<XercesDOMParser>
parser(
new XercesDOMParser());
325 parser->parse(file.c_str());
327 DOMDocument* domDoc = parser->getDocument();
330 throw cms::Exception(
"TotemDAQMappingESSourceXML::ParseXML") <<
"Cannot parse file `" << file
331 <<
"' (domDoc = NULL)." << endl;
333 DOMElement* elementRoot = domDoc->getDocumentElement();
336 throw cms::Exception(
"TotemDAQMappingESSourceXML::ParseXML") <<
"File `" <<
337 file <<
"' is empty." << endl;
347 unsigned int parentID,
const std::shared_ptr<TotemDAQMapping>&
mapping,
348 const std::shared_ptr<TotemAnalysisMask>&
mask)
351 printf(
">> TotemDAQMappingESSourceXML::ParseTreeRP(%s, %u, %u)\n",
cms::xerces::toString(parent->getNodeName()),
352 parentType, parentID);
355 DOMNodeList *
children = parent->getChildNodes();
357 for (
unsigned int i = 0;
i < children->getLength();
i++)
359 DOMNode *
n = children->item(
i);
360 if (n->getNodeType() != DOMNode::ELEMENT_NODE)
376 case nArm: expectedParentType =
nTop;
break;
382 default: expectedParentType =
nUnknown;
break;
385 if (expectedParentType != parentType)
392 unsigned int id = 0, hw_id = 0;
393 bool id_set =
false, hw_id_set =
false;
394 bool fullMask =
false;
395 DOMNamedNodeMap* attr = n->getAttributes();
397 for (
unsigned int j = 0; j < attr->getLength(); j++)
399 DOMNode *
a = attr->item(j);
419 throw cms::Exception(
"TotemDAQMappingESSourceXML::ParseTreeRP") <<
"id not given for element `" 423 throw cms::Exception(
"TotemDAQMappingESSourceXML::ParseTreeRP") <<
"hw_id not given for element `" 427 throw cms::Exception(
"TotemDAQMappingESSourceXML::ParseTreeRP") <<
428 "Plane IDs range from 0 to 9. id = " <<
id <<
" is invalid." << endl;
431 printf(
"\tID found: 0x%x\n",
id);
439 vfatInfo.
hwID = hw_id;
441 const unsigned int armIdx = (parentID / 1000) % 10;
442 const unsigned int stIdx = (parentID / 100) % 10;
443 const unsigned int rpIdx = (parentID / 10) % 10;
444 const unsigned int plIdx = parentID % 10;
448 mapping->insert(framepos, vfatInfo);
456 const unsigned int armIdx = (parentID / 1000) % 10;
457 const unsigned int stIdx = (parentID / 100) % 10;
458 const unsigned int rpIdx = (parentID / 10) % 10;
459 const unsigned int plIdx = parentID % 10;
468 mask->insert(symbId, am);
474 ParseTreeRP(pType, n, type, parentID * 10 +
id, mapping, mask);
481 unsigned int parentID,
const std::shared_ptr<TotemDAQMapping>&
mapping,
482 const std::shared_ptr<TotemAnalysisMask>&
mask)
486 printf(
">> TotemDAQMappingESSourceXML::ParseTreeDiamond(%s, %u, %u)\n",
cms::xerces::toString(parent->getNodeName()),
487 parentType, parentID);
490 DOMNodeList *
children = parent->getChildNodes();
492 for (
unsigned int i = 0;
i < children->getLength();
i++)
494 DOMNode *
n = children->item(
i);
495 if (n->getNodeType() != DOMNode::ELEMENT_NODE)
510 case nArm: expectedParentType =
nTop;
break;
515 default: expectedParentType =
nUnknown;
break;
518 if (expectedParentType != parentType)
525 unsigned int id =0,hw_id = 0;
526 bool id_set =
false,hw_id_set =
false;
527 DOMNamedNodeMap* attr = n->getAttributes();
529 for (
unsigned int j = 0; j < attr->getLength(); j++)
531 DOMNode *
a = attr->item(j);
549 throw cms::Exception(
"TotemDAQMappingESSourceXML::ParseTreeDiamond") <<
"id not given for element `" 554 throw cms::Exception(
"TotemDAQMappingESSourceXML::ParseTreeDiamond") <<
"hw_id not given for element `" 558 throw cms::Exception(
"TotemDAQMappingESSourceXML::ParseTreeDiamond") <<
559 "Plane IDs range from 0 to 3. id = " <<
id <<
" is invalid." << endl;
562 printf(
"\tID found: 0x%x\n",
id);
572 vfatInfo.
hwID = hw_id;
576 unsigned int ArmNum = (parentID/ 10000) % 10;
577 unsigned int StationNum = (parentID / 1000) % 10;
578 unsigned int RpNum = (parentID/ 100) % 10;
579 unsigned int PlaneNum = (parentID % 100) ;
587 mapping->insert(framepos, vfatInfo);
592 unsigned int childId;
594 childId = parentID * 100 +
id;
596 childId = parentID * 10 +
id;
610 unsigned char attributeFlag = 0;
612 DOMNamedNodeMap* attr = chipnode->getAttributes();
613 for (
unsigned int j = 0; j < attr->getLength(); j++)
615 DOMNode *
a = attr->item(j);
628 "Wrong/incomplete DAQ channel specification (attributeFlag = " << attributeFlag <<
")." << endl;
653 if (
Test(n,
"trigger_vfat"))
return nSkip;
655 throw cms::Exception(
"TotemDAQMappingESSourceXML::GetNodeType") <<
"Unknown tag `" 663 DOMNodeList *
children = n->getChildNodes();
664 for (
unsigned int i = 0;
i < children->getLength();
i++)
666 DOMNode *n = children->item(
i);
667 if (n->getNodeType() != DOMNode::ELEMENT_NODE || !
Test(n,
"channel"))
670 DOMNamedNodeMap* attr = n->getAttributes();
672 for (
unsigned int j = 0; j < attr->getLength(); j++)
674 DOMNode *
a = attr->item(j);
688 throw cms::Exception(
"TotemDAQMappingESSourceXML::GetChannels") <<
689 "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
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())
std::string toString(XMLCh const *toTranscode)
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...
std::string fullPath() const
static const std::string tagRPPot
static const std::string tagRPPlane
std::vector< std::string > mappingFileNames
the mapping files
~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