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> 103 enum NodeType {
nUnknown, nSkip, nTop, nArm, nRPStation, nRPPot, nRPixPlane, nROC, nPixel };
109 void ParseXML(
ParseType,
const string &
file,
const std::unique_ptr<CTPPSPixelDAQMapping>&,
const std::unique_ptr<CTPPSPixelAnalysisMask>&);
114 void ParseTreePixel(
ParseType, xercesc::DOMNode *,
NodeType,
unsigned int parentID,
115 const std::unique_ptr<CTPPSPixelDAQMapping>&,
const std::unique_ptr<CTPPSPixelAnalysisMask>&);
119 string CompleteFileName(
const string &fn);
128 NodeType GetNodeType(xercesc::DOMNode *);
145 void GetPixels(xercesc::DOMNode *
n, std::set<std::pair<unsigned char, unsigned char> > &pixels);
149 return ((type == nArm)||(type == nRPStation)||(type == nRPPot)||(type == nRPixPlane)||(type == nROC));
181 verbosity(conf.getUntrackedParameter<unsigned
int>(
"verbosity", 0)),
182 subSystemName(conf.getUntrackedParameter<
string>(
"subSystem")),
184 currentBlockValid(
false)
186 for (
const auto it : conf.
getParameter<vector<ParameterSet>>(
"configuration"))
191 b.
maskFileNames = it.getParameter< vector<string> >(
"maskFileNames");
196 findingRecord<CTPPSPixelAnalysisMaskRcd>();
199 findingRecord<CTPPSPixelDAQMappingRcd>();
202 LogVerbatim(
"CTPPSPixelDAQMappingESSourceXML") <<
" Inside CTPPSPixelDAQMappingESSourceXML";
211 <<
">> CTPPSPixelDAQMappingESSourceXML::setIntervalFor(" << key.
name() <<
")";
221 EventID startEventID = bl.validityRange.startEventID();
222 if (startEventID ==
EventID(1, 0, 1))
223 startEventID =
EventID(1, 0, 0);
225 if (startEventID <= iosv.
eventID() && iosv.
eventID() <= bl.validityRange.endEventID())
236 <<
", interval=(" << startEventID <<
" - " << bl.validityRange.endEventID() <<
")";
244 throw cms::Exception(
"CTPPSPixelDAQMappingESSourceXML::setIntervalFor") <<
245 "No configuration for event " << iosv.
eventID();
269 auto mapping = std::make_unique<CTPPSPixelDAQMapping>();
270 auto mask = std::make_unique<CTPPSPixelAnalysisMask>();
295 auto mapping = std::make_unique<CTPPSPixelDAQMapping>();
296 auto mask = std::make_unique<CTPPSPixelAnalysisMask>();
321 const std::unique_ptr<CTPPSPixelDAQMapping> &
mapping,
const std::unique_ptr<CTPPSPixelAnalysisMask> &
mask)
323 unique_ptr<XercesDOMParser>
parser(
new XercesDOMParser());
324 parser->parse(file.c_str());
326 DOMDocument* domDoc = parser->getDocument();
329 throw cms::Exception(
"CTPPSPixelDAQMappingESSourceXML::ParseXML") <<
"Cannot parse file `" << file
330 <<
"' (domDoc = NULL)." << endl;
332 DOMElement* elementRoot = domDoc->getDocumentElement();
335 throw cms::Exception(
"CTPPSPixelDAQMappingESSourceXML::ParseXML") <<
"File `" <<
336 file <<
"' is empty." << endl;
346 unsigned int parentID,
const std::unique_ptr<CTPPSPixelDAQMapping>&
mapping,
347 const std::unique_ptr<CTPPSPixelAnalysisMask>&
mask)
350 printf(
">> CTPPSPixelDAQMappingESSourceXML::ParseTreeRP(%s, %u, %u)\n",
cms::xerces::toString(parent->getNodeName()),
351 parentType, parentID);
354 DOMNodeList *
children = parent->getChildNodes();
356 for (
unsigned int i = 0;
i < children->getLength();
i++)
358 DOMNode *
n = children->item(
i);
359 if (n->getNodeType() != DOMNode::ELEMENT_NODE)
375 case nArm: expectedParentType =
nTop;
break;
380 case nPixel: expectedParentType =
nROC;
break;
381 default: expectedParentType =
nUnknown;
break;
384 if (expectedParentType != parentType)
393 bool fullMask =
false;
394 DOMNamedNodeMap* attr = n->getAttributes();
396 for (
unsigned int j = 0; j < attr->getLength(); j++)
398 DOMNode *
a = attr->item(j);
412 throw cms::Exception(
"CTPPSPixelDAQMappingESSourceXML::ParseTreePixel") <<
"id not given for element `" 416 throw cms::Exception(
"CTPPSPixelDAQMappingESSourceXML::ParseTreePixel") <<
417 "Plane IDs range from 0 to 5. id = " <<
id <<
" is invalid." << endl;
420 printf(
"\tID found: %u\n",
id);
430 const unsigned int armIdx = (parentID / 1000) % 10;
431 const unsigned int stIdx = (parentID / 100) % 10;
432 const unsigned int rpIdx = (parentID / 10) % 10;
433 const unsigned int plIdx = parentID % 10;
437 mapping->insert(framepos, rocInfo);
445 const unsigned int armIdx = (parentID / 1000) % 10;
446 const unsigned int stIdx = (parentID / 100) % 10;
447 const unsigned int rpIdx = (parentID / 10) % 10;
448 const unsigned int plIdx = parentID % 10;
460 mask->insert(symbId, am);
466 ParseTreePixel(pType, n, type, parentID * 10 +
id, mapping, mask);
476 unsigned char attributeFlag = 0;
478 DOMNamedNodeMap* attr = chipnode->getAttributes();
479 for (
unsigned int j = 0; j < attr->getLength(); j++)
481 DOMNode *
a = attr->item(j);
495 "Wrong/incomplete DAQ channel specification (attributeFlag = " << attributeFlag <<
")." << endl;
514 throw cms::Exception(
"CTPPSPixelDAQMappingESSourceXML::GetNodeType") <<
"Unknown tag `" 522 DOMNodeList *
children = n->getChildNodes();
523 for (
unsigned int i = 0;
i < children->getLength();
i++)
525 DOMNode *n = children->item(
i);
526 if (n->getNodeType() != DOMNode::ELEMENT_NODE || !
Test(n,
"pixel"))
529 DOMNamedNodeMap* attr = n->getAttributes();
530 bool pixelSet =
false;
533 std::pair<unsigned int, unsigned int> currentPixel;
534 for (
unsigned int j = 0; j < attr->getLength(); j++)
536 DOMNode *
a = attr->item(j);
540 unsigned int row = 0;
542 currentPixel.first = row;
547 unsigned int col = 0;
549 currentPixel.second =
col;
553 pixelSet = rowSet & colSet;
555 pixels.insert(currentPixel);
564 throw cms::Exception(
"CTPPSPixelDAQMappingESSourceXML::GetChannels") <<
565 "Channel tags must have a row or col attribute.";
string GetNodeContent(xercesc::DOMNode *parent)
returns the content of the node
T getParameter(std::string const &) const
EventNumber_t event() const
CTPPSPixelDAQMappingESSourceXML(const edm::ParameterSet &)
Contains mappind data related to a ROC.
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
const EventID & eventID() 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
unsigned char setXMLAttribute(const std::string &attribute, const std::string &value, unsigned char &flag)
void setWhatProduced(T *iThis, const es::Label &iLabel=es::Label())
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)
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
const char * name() const
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
static bool checkXMLAttributeFlag(unsigned char flag)
returns true if all attributes have been set
#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
void GetPixels(xercesc::DOMNode *n, std::set< std::pair< unsigned char, unsigned char > > &pixels)
static const std::string tagPixel
static const std::string tagArm
Common position tags.
void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue &, edm::ValidityInterval &) override
sets infinite validity of this data
std::string fullPath() const
static const std::string tagRPPot
std::set< std::pair< unsigned char, unsigned char > > maskedPixels
list of channels to be masked
NodeType GetNodeType(xercesc::DOMNode *)
determines node type