MarlinMT  0.1.0
marlinmt::XMLConfigReader Class Reference

XMLConfigReader plugin Read an XML file and populate the configuration with sections and parameters. More...

Inherits marlinmt::ConfigReader.

Public Member Functions

void init (const std::string &desc) override
 Initialize the parser. More...
 
void read (Configuration &cfg) override
 Read the configuration and populate the configuration object. More...
 
- Public Member Functions inherited from marlinmt::ConfigReader
virtual ~ConfigReader ()=default
 Default destructor. More...
 

Private Member Functions

void parseSection (TiXmlElement *parentElement, const std::string &name, Configuration &cfg, bool addAttributes, bool throwIfNotFound) const
 Parse a configuration section from the parent XML element. More...
 
void parseExecuteSection (TiXmlElement *parentElement, Configuration &cfg) const
 Parse the <execute> section and populate the configuration object accordingly. More...
 
void resolveGroupSections (TiXmlElement *rootElement) const
 Resolve the <group> sections. More...
 
void parseProcessorParameters (TiXmlElement *parent, Configuration &cfg) const
 Parse all the processor parameter sections in the parent XML element. More...
 
std::string getAttribute (const TiXmlElement *element, const std::string &name) const
 Helper method to get a XML element attribute as string. More...
 
void parseConstants (TiXmlDocument *idoc, Configuration &cfg) const
 Parse the <constants> section. More...
 
void parseConstant (TiXmlElement *element, Configuration &cfg) const
 Parse a single <constant> element. More...
 
void processIncludeElements (TiXmlElement *element, const Configuration &cfg) const
 Process all XML elements recursively. More...
 
void processIncludeElement (TiXmlElement *element, const Configuration &cfg, TiXmlDocument &document) const
 Process a single XML element. More...
 
void checkForNestedIncludes (const TiXmlNode *node) const
 Check recursively for XML element in the node. More...
 
void parametersFromXMLElement (const TiXmlElement *element, const Configuration &cfg, ConfigSection &section, bool addAttributes, const std::string &replacePrefix="") const
 Read the <parameter> XML elements form the parent XML element. More...
 
void processConditions (TiXmlNode *current, const std::string &aCondition) const
 Treat the conditions for a XML node. More...
 
void replaceGroups (TiXmlNode *processorsParent, TiXmlNode *section) const
 Replace the <group> tags in the execute section by the corresponding processors. More...
 
TiXmlNode * findElement (TiXmlNode *node, const std::string &tag, const std::string &attribute, const std::string &value) const
 Find a particular XML node by matching tag, and a specific attribute value. More...
 
std::optional< std::string > getReplacementParameter (const std::string &arg, const Configuration &config) const
 

Private Attributes

std::string _fname {}
 The input/output file name. More...
 

Detailed Description

XMLConfigReader plugin Read an XML file and populate the configuration with sections and parameters.

Definition at line 26 of file XMLConfigReader.cc.

Member Function Documentation

◆ checkForNestedIncludes()

void marlinmt::XMLConfigReader::checkForNestedIncludes ( const TiXmlNode *  node) const
private

Check recursively for XML element in the node.

Throw if an include element is found.

Parameters
nodethe parent element to check

Definition at line 508 of file XMLConfigReader.cc.

References MARLINMT_THROW_T.

Referenced by processIncludeElement().

◆ findElement()

TiXmlNode * marlinmt::XMLConfigReader::findElement ( TiXmlNode *  node,
const std::string &  tag,
const std::string &  attribute,
const std::string &  value 
) const
private

Find a particular XML node by matching tag, and a specific attribute value.

For example:

<parameter name="Value">

corresponds to:

findElement( parent, "parameter", "name", "Value" )
Parameters
nodethe parent node
tagthe child XML element tag
attributethe attribute key to match
valuethe attribute value to match

Definition at line 648 of file XMLConfigReader.cc.

Referenced by replaceGroups().

◆ getAttribute()

std::string marlinmt::XMLConfigReader::getAttribute ( const TiXmlElement *  element,
const std::string &  name 
) const
private

Helper method to get a XML element attribute as string.

Throw an exception if not found

Parameters
elementthe XML element
namethe attribute name

Definition at line 358 of file XMLConfigReader.cc.

References _fname, and MARLINMT_THROW_T.

Referenced by parametersFromXMLElement(), parseConstant(), parseExecuteSection(), parseProcessorParameters(), processConditions(), processIncludeElement(), and replaceGroups().

◆ getReplacementParameter()

std::optional< std::string > marlinmt::XMLConfigReader::getReplacementParameter ( const std::string &  arg,
const Configuration config 
) const
private

◆ init()

void marlinmt::XMLConfigReader::init ( const std::string &  desc)
overridevirtual

Initialize the parser.

The descriptor string can be e.g:

  • file name
  • database description
Parameters
desca descriptor string

Implements marlinmt::ConfigReader.

Definition at line 188 of file XMLConfigReader.cc.

References _fname.

◆ parametersFromXMLElement()

void marlinmt::XMLConfigReader::parametersFromXMLElement ( const TiXmlElement *  element,
const Configuration cfg,
ConfigSection section,
bool  addAttributes,
const std::string &  replacePrefix = "" 
) const
private

Read the <parameter> XML elements form the parent XML element.

Add a new or overwrite an existing parameter in the input config section. The flag addAttributes specifies whether the XML element attributes should be imported as parameters. For example:

<superHero name="Batman">
...
</superHero>

will add a parameter 'SuperHeroName' with the value 'Batman' to the list of parameters

Parameters
elementthe parent XML element containing parameter tags
cfgthe configuration object for constants resolution
sectionthe section to populate with parameters
addAttributeswhether to add the XML element attributes in the list of parameters
replacePrefixthe section prefix for replacement parameters

Definition at line 521 of file XMLConfigReader.cc.

References getAttribute(), getReplacementParameter(), MARLINMT_RETHROW, marlinmt::Configuration::replaceConstants(), and marlinmt::ConfigSection::setParameter().

Referenced by parseProcessorParameters(), and parseSection().

◆ parseConstant()

void marlinmt::XMLConfigReader::parseConstant ( TiXmlElement *  element,
Configuration cfg 
) const
private

Parse a single <constant> element.

Add a constant to the configuration object

Parameters
elementthe constant XML element
cfgthe configuration object to populate

Definition at line 411 of file XMLConfigReader.cc.

References marlinmt::Configuration::addConstant(), getAttribute(), getReplacementParameter(), MARLINMT_RETHROW, marlinmt::Configuration::replaceConstants(), and marlinmt::book::Flags::value().

Referenced by parseConstants().

◆ parseConstants()

void marlinmt::XMLConfigReader::parseConstants ( TiXmlDocument *  idoc,
Configuration cfg 
) const
private

Parse the <constants> section.

Populate the configuration object with constants. Also parse elements contained in the <constants> element (only).

Parameters
idocthe input XML document
cfgthe configuration object to populate

Definition at line 368 of file XMLConfigReader.cc.

References parseConstant(), and processIncludeElement().

Referenced by read().

◆ parseExecuteSection()

void marlinmt::XMLConfigReader::parseExecuteSection ( TiXmlElement *  parentElement,
Configuration cfg 
) const
private

Parse the <execute> section and populate the configuration object accordingly.

Parameters
parentElementthe parent element of the <execute> section
cfgthe configuration object to populate

Definition at line 259 of file XMLConfigReader.cc.

References _fname, marlinmt::Configuration::createSection(), getAttribute(), getReplacementParameter(), MARLINMT_RETHROW, MARLINMT_THROW_T, processConditions(), marlinmt::Configuration::replaceConstants(), and replaceGroups().

Referenced by read().

◆ parseProcessorParameters()

void marlinmt::XMLConfigReader::parseProcessorParameters ( TiXmlElement *  parent,
Configuration cfg 
) const
private

Parse all the processor parameter sections in the parent XML element.

Create a global config section 'processors' and add every processor parameters in a separate sub section.

Parameters
parentthe parent XML element of the <processor> tags
cfgthe configuration object to populate

Definition at line 333 of file XMLConfigReader.cc.

References marlinmt::Configuration::createSection(), getAttribute(), MARLINMT_RETHROW_T, MARLINMT_THROW_T, and parametersFromXMLElement().

Referenced by read().

◆ parseSection()

void marlinmt::XMLConfigReader::parseSection ( TiXmlElement *  parentElement,
const std::string &  name,
Configuration cfg,
bool  addAttributes,
bool  throwIfNotFound 
) const
private

Parse a configuration section from the parent XML element.

Parameters
parentElementthe parent XML element of the config
namethe XML element tag to read
cfgthe configuration object to populate
addAttributeswhether to add the XML element attributes in the parameters
throwIfNotFoundwhether to throw if the section if not found

Definition at line 244 of file XMLConfigReader.cc.

References _fname, marlinmt::Configuration::createSection(), MARLINMT_THROW_T, and parametersFromXMLElement().

Referenced by read().

◆ processConditions()

void marlinmt::XMLConfigReader::processConditions ( TiXmlNode *  current,
const std::string &  aCondition 
) const
private

Treat the conditions for a XML node.

Parameters
currentthe input XML node
aConditionthe condition string to parse

Definition at line 567 of file XMLConfigReader.cc.

References getAttribute(), and MARLINMT_RETHROW.

Referenced by parseExecuteSection().

◆ processIncludeElement()

void marlinmt::XMLConfigReader::processIncludeElement ( TiXmlElement *  element,
const Configuration cfg,
TiXmlDocument &  document 
) const
private

Process a single XML element.

Resolve the 'ref' location and load the XML document. Check for nested include XML element which not allowed for the current implementation.

Parameters
elementthe XML element to process
cfgthe configuration for constant resolution
documentthe include document object to receive

Definition at line 476 of file XMLConfigReader.cc.

References _fname, checkForNestedIncludes(), getAttribute(), MARLINMT_RETHROW, MARLINMT_THROW_T, and marlinmt::Configuration::replaceConstants().

Referenced by parseConstants(), and processIncludeElements().

◆ processIncludeElements()

void marlinmt::XMLConfigReader::processIncludeElements ( TiXmlElement *  element,
const Configuration cfg 
) const
private

Process all XML elements recursively.

Import the XML tree of the include reference in-place in the current XML tree.

Parameters
elementthe current XML element to parse
cfgthe configuration object for constants replacement

Definition at line 441 of file XMLConfigReader.cc.

References processIncludeElement().

Referenced by read().

◆ read()

void marlinmt::XMLConfigReader::read ( Configuration cfg)
overridevirtual

Read the configuration and populate the configuration object.

Parameters
cfgthe configuration object to populate

Implements marlinmt::ConfigReader.

Definition at line 194 of file XMLConfigReader.cc.

References _fname, MARLINMT_THROW_T, parseConstants(), parseExecuteSection(), parseProcessorParameters(), parseSection(), processIncludeElements(), and resolveGroupSections().

◆ replaceGroups()

void marlinmt::XMLConfigReader::replaceGroups ( TiXmlNode *  processorsParent,
TiXmlNode *  section 
) const
private

Replace the <group> tags in the execute section by the corresponding processors.

Parameters
processorsParentthe XML element containing the list of groups
sectionthe execute XML element section

Definition at line 614 of file XMLConfigReader.cc.

References findElement(), getAttribute(), MARLINMT_RETHROW, and MARLINMT_THROW_T.

Referenced by parseExecuteSection().

◆ resolveGroupSections()

void marlinmt::XMLConfigReader::resolveGroupSections ( TiXmlElement *  rootElement) const
private

Resolve the <group> sections.

Add common group parameter to every processor in the group

Parameters
rootElementthe XML parent element (the <marlinmt> root element)

Definition at line 306 of file XMLConfigReader.cc.

Referenced by read().

Member Data Documentation

◆ _fname

std::string marlinmt::XMLConfigReader::_fname {}
private

The input/output file name.

Definition at line 182 of file XMLConfigReader.cc.

Referenced by getAttribute(), init(), parseExecuteSection(), parseSection(), processIncludeElement(), and read().


The documentation for this class was generated from the following file: