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>&);
117 void ParseTreeRP(ParseType, xercesc::DOMNode *, NodeType,
unsigned int parentID,
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);
135 NodeType GetNodeType(xercesc::DOMNode *);
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));
177 using namespace xercesc;
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() <<
")";
264 throw cms::Exception(
"TotemDAQMappingESSourceXML::setIntervalFor") <<
265 "No configuration for event " << iosv.
eventID();
290 auto mapping = std::make_shared<TotemDAQMapping>();
291 auto mask = std::make_shared<TotemAnalysisMask>();
296 XMLPlatformUtils::Initialize();
298 catch (
const XMLException& toCatch)
301 throw cms::Exception(
"TotemDAQMappingESSourceXML") <<
"An XMLException caught with message: " << message <<
".\n";
314 XMLPlatformUtils::Terminate();
323 const std::shared_ptr<TotemDAQMapping> &mapping,
const std::shared_ptr<TotemAnalysisMask> &mask)
325 unique_ptr<XercesDOMParser>
parser(
new XercesDOMParser());
326 parser->parse(file.c_str());
328 DOMDocument* domDoc = parser->getDocument();
331 throw cms::Exception(
"TotemDAQMappingESSourceXML::ParseXML") <<
"Cannot parse file `" << file
332 <<
"' (domDoc = NULL)." << endl;
334 DOMElement* elementRoot = domDoc->getDocumentElement();
337 throw cms::Exception(
"TotemDAQMappingESSourceXML::ParseXML") <<
"File `" <<
338 file <<
"' is empty." << endl;
348 unsigned int parentID,
const std::shared_ptr<TotemDAQMapping>& mapping,
349 const std::shared_ptr<TotemAnalysisMask>& mask)
352 printf(
">> TotemDAQMappingESSourceXML::ParseTreeRP(%s, %u, %u)\n",
XMLString::transcode(parent->getNodeName()),
353 parentType, parentID);
356 DOMNodeList *children = parent->getChildNodes();
358 for (
unsigned int i = 0;
i < children->getLength();
i++)
360 DOMNode *
n = children->item(
i);
361 if (n->getNodeType() != DOMNode::ELEMENT_NODE)
377 case nArm: expectedParentType =
nTop;
break;
383 default: expectedParentType =
nUnknown;
break;
386 if (expectedParentType != parentType)
393 unsigned int id = 0, hw_id = 0;
394 bool id_set =
false, hw_id_set =
false;
395 bool fullMask =
false;
396 DOMNamedNodeMap* attr = n->getAttributes();
398 for (
unsigned int j = 0;
j < attr->getLength();
j++)
400 DOMNode *
a = attr->item(
j);
420 throw cms::Exception(
"TotemDAQMappingESSourceXML::ParseTreeRP") <<
"id not given for element `"
424 throw cms::Exception(
"TotemDAQMappingESSourceXML::ParseTreeRP") <<
"hw_id not given for element `"
428 throw cms::Exception(
"TotemDAQMappingESSourceXML::ParseTreeRP") <<
429 "Plane IDs range from 0 to 9. id = " <<
id <<
" is invalid." << endl;
432 printf(
"\tID found: 0x%x\n",
id);
440 vfatInfo.
hwID = hw_id;
442 const unsigned int armIdx = (parentID / 1000) % 10;
443 const unsigned int stIdx = (parentID / 100) % 10;
444 const unsigned int rpIdx = (parentID / 10) % 10;
445 const unsigned int plIdx = parentID % 10;
449 mapping->insert(framepos, vfatInfo);
457 const unsigned int armIdx = (parentID / 1000) % 10;
458 const unsigned int stIdx = (parentID / 100) % 10;
459 const unsigned int rpIdx = (parentID / 10) % 10;
460 const unsigned int plIdx = parentID % 10;
469 mask->insert(symbId, am);
475 ParseTreeRP(pType, n, type, parentID * 10 +
id, mapping, mask);
482 unsigned int parentID,
const std::shared_ptr<TotemDAQMapping>& mapping,
483 const std::shared_ptr<TotemAnalysisMask>& mask)
487 printf(
">> TotemDAQMappingESSourceXML::ParseTreeDiamond(%s, %u, %u)\n",
XMLString::transcode(parent->getNodeName()),
488 parentType, parentID);
491 DOMNodeList *children = parent->getChildNodes();
493 for (
unsigned int i = 0;
i < children->getLength();
i++)
495 DOMNode *
n = children->item(
i);
496 if (n->getNodeType() != DOMNode::ELEMENT_NODE)
511 case nArm: expectedParentType =
nTop;
break;
516 default: expectedParentType =
nUnknown;
break;
519 if (expectedParentType != parentType)
526 unsigned int id =0,hw_id = 0;
527 bool id_set =
false,hw_id_set =
false;
528 DOMNamedNodeMap* attr = n->getAttributes();
530 for (
unsigned int j = 0;
j < attr->getLength();
j++)
532 DOMNode *
a = attr->item(
j);
550 throw cms::Exception(
"TotemDAQMappingESSourceXML::ParseTreeDiamond") <<
"id not given for element `"
555 throw cms::Exception(
"TotemDAQMappingESSourceXML::ParseTreeDiamond") <<
"hw_id not given for element `"
559 throw cms::Exception(
"TotemDAQMappingESSourceXML::ParseTreeDiamond") <<
560 "Plane IDs range from 0 to 3. id = " <<
id <<
" is invalid." << endl;
563 printf(
"\tID found: 0x%x\n",
id);
573 vfatInfo.
hwID = hw_id;
577 unsigned int ArmNum = (parentID/ 10000) % 10;
578 unsigned int StationNum = (parentID / 1000) % 10;
579 unsigned int RpNum = (parentID/ 100) % 10;
580 unsigned int PlaneNum = (parentID % 100) ;
588 mapping->insert(framepos, vfatInfo);
593 unsigned int childId;
595 childId = parentID * 100 + id;
597 childId = parentID * 10 + id;
611 unsigned char attributeFlag = 0;
613 DOMNamedNodeMap* attr = chipnode->getAttributes();
614 for (
unsigned int j = 0;
j < attr->getLength();
j++)
616 DOMNode *
a = attr->item(
j);
629 "Wrong/incomplete DAQ channel specification (attributeFlag = " << attributeFlag <<
")." << endl;
654 if (
Test(n,
"trigger_vfat"))
return nSkip;
656 throw cms::Exception(
"TotemDAQMappingESSourceXML::GetNodeType") <<
"Unknown tag `"
664 DOMNodeList *children = n->getChildNodes();
665 for (
unsigned int i = 0;
i < children->getLength();
i++)
667 DOMNode *n = children->item(
i);
668 if (n->getNodeType() != DOMNode::ELEMENT_NODE || !
Test(n,
"channel"))
671 DOMNamedNodeMap* attr = n->getAttributes();
673 for (
unsigned int j = 0;
j < attr->getLength();
j++)
675 DOMNode *
a = attr->item(
j);
689 throw cms::Exception(
"TotemDAQMappingESSourceXML::GetChannels") <<
690 "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())
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
XMLCh * transcode(const T &fInput)
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
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.
tuple idx
DEBUGGING if hasattr(process,"trackMonIterativeTracking2012"): print "trackMonIterativeTracking2012 D...
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
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.
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