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> 97 enum NodeType {
nUnknown, nSkip, nTop, nArm, nRPStation, nRPPot, nRPixPlane, nROC, nPixel };
103 void ParseXML(ParseType,
105 const std::unique_ptr<CTPPSPixelDAQMapping> &,
106 const std::unique_ptr<CTPPSPixelAnalysisMask> &);
109 void ParseTreePixel(ParseType,
112 unsigned int parentID,
113 const std::unique_ptr<CTPPSPixelDAQMapping> &,
114 const std::unique_ptr<CTPPSPixelAnalysisMask> &);
118 string CompleteFileName(
const string &
fn);
126 NodeType GetNodeType(xercesc::DOMNode *);
137 void GetPixels(xercesc::DOMNode *
n, std::set<std::pair<unsigned char, unsigned char>> &pixels);
140 return ((
type == nArm) || (
type == nRPStation) || (
type == nRPPot) || (
type == nRPixPlane) || (
type == nROC));
172 :
verbosity(conf.getUntrackedParameter<unsigned
int>(
"verbosity", 0)),
175 currentBlockValid(
false) {
176 for (
const auto &it : conf.
getParameter<vector<ParameterSet>>(
"configuration")) {
178 b.validityRange = it.getParameter<
EventRange>(
"validityRange");
179 b.mappingFileNames = it.getParameter<vector<string>>(
"mappingFileNames");
180 b.maskFileNames = it.getParameter<vector<string>>(
"maskFileNames");
185 findingRecord<CTPPSPixelAnalysisMaskRcd>();
188 findingRecord<CTPPSPixelDAQMappingRcd>();
190 LogVerbatim(
"CTPPSPixelDAQMappingESSourceXML") <<
" Inside CTPPSPixelDAQMappingESSourceXML";
197 <<
">> CTPPSPixelDAQMappingESSourceXML::setIntervalFor(" <<
key.name() <<
")";
206 EventID startEventID = bl.validityRange.startEventID();
207 if (startEventID ==
EventID(1, 0, 1))
208 startEventID =
EventID(1, 0, 0);
210 if (startEventID <= iosv.
eventID() && iosv.
eventID() <= bl.validityRange.endEventID()) {
219 << startEventID <<
" - " << bl.validityRange.endEventID() <<
")";
226 throw cms::Exception(
"CTPPSPixelDAQMappingESSourceXML::setIntervalFor")
227 <<
"No configuration for event " << iosv.
eventID();
242 auto mapping = std::make_unique<CTPPSPixelDAQMapping>();
243 auto mask = std::make_unique<CTPPSPixelAnalysisMask>();
268 auto mapping = std::make_unique<CTPPSPixelDAQMapping>();
269 auto mask = std::make_unique<CTPPSPixelAnalysisMask>();
295 const std::unique_ptr<CTPPSPixelDAQMapping> &
mapping,
296 const std::unique_ptr<CTPPSPixelAnalysisMask> &
mask) {
297 unique_ptr<XercesDOMParser>
parser(
new XercesDOMParser());
300 DOMDocument *domDoc =
parser->getDocument();
304 <<
"Cannot parse file `" <<
file <<
"' (domDoc = NULL)." << endl;
306 DOMElement *elementRoot = domDoc->getDocumentElement();
309 throw cms::Exception(
"CTPPSPixelDAQMappingESSourceXML::ParseXML") <<
"File `" <<
file <<
"' is empty." << endl;
319 unsigned int parentID,
320 const std::unique_ptr<CTPPSPixelDAQMapping> &
mapping,
321 const std::unique_ptr<CTPPSPixelAnalysisMask> &
mask) {
323 printf(
">> CTPPSPixelDAQMappingESSourceXML::ParseTreeRP(%s, %u, %u)\n",
331 for (
unsigned int i = 0;
i <
children->getLength();
i++) {
333 if (
n->getNodeType() != DOMNode::ELEMENT_NODE)
349 expectedParentType =
nTop;
352 expectedParentType =
nArm;
358 expectedParentType =
nRPPot;
364 expectedParentType =
nROC;
371 if (expectedParentType != parentType) {
380 bool fullMask =
false;
381 DOMNamedNodeMap *attr =
n->getAttributes();
383 for (
unsigned int j = 0;
j < attr->getLength();
j++) {
384 DOMNode *
a = attr->item(
j);
397 throw cms::Exception(
"CTPPSPixelDAQMappingESSourceXML::ParseTreePixel")
401 throw cms::Exception(
"CTPPSPixelDAQMappingESSourceXML::ParseTreePixel")
402 <<
"Plane IDs range from 0 to 5. id = " <<
id <<
" is invalid." << endl;
405 printf(
"\tID found: %u\n",
id);
414 const unsigned int armIdx = (parentID / 1000) % 10;
415 const unsigned int stIdx = (parentID / 100) % 10;
416 const unsigned int rpIdx = (parentID / 10) % 10;
417 const unsigned int plIdx = parentID % 10;
421 mapping->insert(framepos, rocInfo);
428 const unsigned int armIdx = (parentID / 1000) % 10;
429 const unsigned int stIdx = (parentID / 100) % 10;
430 const unsigned int rpIdx = (parentID / 10) % 10;
431 const unsigned int plIdx = parentID % 10;
441 mask->insert(symbId, am);
455 unsigned char attributeFlag = 0;
457 DOMNamedNodeMap *attr = chipnode->getAttributes();
458 for (
unsigned int j = 0;
j < attr->getLength();
j++) {
459 DOMNode *
a = attr->item(
j);
461 if (
fp.setXMLAttribute(
469 if (!
fp.checkXMLAttributeFlag(attributeFlag)) {
471 <<
"Wrong/incomplete DAQ channel specification (attributeFlag = " << attributeFlag <<
")." << endl;
494 throw cms::Exception(
"CTPPSPixelDAQMappingESSourceXML::GetNodeType")
501 set<std::pair<unsigned char, unsigned char>> &pixels) {
502 DOMNodeList *
children =
n->getChildNodes();
503 for (
unsigned int i = 0;
i <
children->getLength();
i++) {
505 if (
n->getNodeType() != DOMNode::ELEMENT_NODE || !
Test(
n,
"pixel"))
508 DOMNamedNodeMap *attr =
n->getAttributes();
509 bool pixelSet =
false;
512 std::pair<unsigned int, unsigned int> currentPixel;
513 for (
unsigned int j = 0;
j < attr->getLength();
j++) {
514 DOMNode *
a = attr->item(
j);
517 unsigned int row = 0;
519 currentPixel.first = row;
523 unsigned int col = 0;
525 currentPixel.second =
col;
529 pixelSet = rowSet & colSet;
531 pixels.insert(currentPixel);
537 throw cms::Exception(
"CTPPSPixelDAQMappingESSourceXML::GetChannels")
538 <<
"Channel tags must have a row or col attribute.";
string GetNodeContent(xercesc::DOMNode *parent)
returns the content of the node
Log< level::Info, true > LogVerbatim
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
CTPPSPixelDAQMappingESSourceXML(const edm::ParameterSet &)
Contains mappind data related to a ROC.
T getParameter(std::string const &) const
string subSystemName
label of the CTPPS sub-system
bool PixelNode(NodeType type)
void ParseTreePixel(ParseType, xercesc::DOMNode *, NodeType, unsigned int parentID, const std::unique_ptr< CTPPSPixelDAQMapping > &, const std::unique_ptr< CTPPSPixelAnalysisMask > &)
recursive method to extract Pixel-related information from the DOM tree
vector< ConfigBlock > configuration
std::vector< std::string > mappingFileNames
the mapping files
std::string fullPath() const
static const std::string tagROC
static const unsigned int offsetROCinDetId
std::unique_ptr< CTPPSPixelAnalysisMask > produceCTPPSPixelAnalysisMask(const CTPPSPixelAnalysisMaskRcd &)
CTPPSPixelFramePosition ChipFramePosition(xercesc::DOMNode *chipnode)
extracts VFAT's DAQ channel from XML attributes
ParseType
whether to parse a mapping of a mask XML
static const std::string tagAnalysisMask
NodeType
enumeration of XML node types
std::pair< Time_t, Time_t > ValidityInterval
string CompleteFileName(const string &fn)
adds the path prefix, if needed
Contains data on masked channels of a ROC.
uint32_t iD
the symbolic id
static const std::string tagRPixPlane
std::string toString(XMLCh const *toTranscode)
void GetPixels(xercesc::DOMNode *n, std::set< std::pair< unsigned char, unsigned char >> &pixels)
Loads CTPPSPixelDAQMapping and CTPPSPixelAnalysisMask from two XML files.
std::unique_ptr< CTPPSPixelDAQMapping > produceCTPPSPixelDAQMapping(const CTPPSPixelDAQMappingRcd &)
bool fullMask
whether all channels of the ROC shall be masked
unsigned int currentBlock
index of the current block in 'configuration' array
std::vector< std::string > mappingFileNames
the mapping files
void ParseXML(ParseType, const string &file, const std::unique_ptr< CTPPSPixelDAQMapping > &, const std::unique_ptr< CTPPSPixelAnalysisMask > &)
parses XML file
static const std::string tagRPStation
RP XML tags.
edm::EventRange validityRange
validity interval
bool Test(xercesc::DOMNode *node, const std::string &name)
returns true iff the node is of the given name
#define DEFINE_FWK_EVENTSETUP_SOURCE(type)
~CTPPSPixelDAQMappingESSourceXML() override
bool currentBlockValid
flag whether the 'currentBlock' index is valid
std::vector< std::string > maskFileNames
the mask files
string GetNodeValue(xercesc::DOMNode *node)
returns the value of the node
static const std::string tagPixel
static const std::string tagArm
Common position tags.
const EventID & eventID() const
void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue &, edm::ValidityInterval &) override
sets infinite validity of this data
static const std::string tagRPPot
EventNumber_t event() const
std::set< std::pair< unsigned char, unsigned char > > maskedPixels
list of channels to be masked
NodeType GetNodeType(xercesc::DOMNode *)
determines node type