Marlin
01.17.01
|
XML parser for Marlin steering files. More...
#include <XMLParser.h>
Classes | |
class | LCTokenizer |
Helper class for XMLParser. More... | |
Public Member Functions | |
XMLParser (const std::string &fileName, bool forCCheck=false) | |
virtual | ~XMLParser () |
void | setCmdLineParameters (const CommandLineParametersMap &cmdlineparams) |
set command line parameters More... | |
void | parse () |
Parse the input file. More... | |
std::shared_ptr< StringParameters > | getParameters (const std::string §ionName) const |
Return the StringParameters for the section as read from the xml file. More... | |
void | write (const std::string &filen) const |
Write the parsed XML tree in an other file. More... | |
![]() | |
virtual | ~IParser () |
Protected Member Functions | |
void | parametersFromNode (TiXmlNode *section, std::map< std::string, std::string > &constants, std::pair< unsigned, unsigned > *typeCount=0) |
Extracts all parameters from the given node and adss them to the current StringParameters object. More... | |
const char * | getAttribute (TiXmlNode *node, const std::string &name) |
Return named attribute - throws ParseException if attribute doesn't exist. More... | |
void | replacegroups (TiXmlNode *section) |
Helper method - replaces all <group> tag with corresponding <processor> tags. More... | |
TiXmlNode * | findElement (TiXmlNode *node, const std::string &type, const std::string &attribute, const std::string &value) |
Helper method - finds child element of node with given type and attribute value. More... | |
void | processconditions (TiXmlNode *current, const std::string &conditions) |
Helper method - recursively moves processors from <if> tags to top level (<execute>) and adds corresponding conditions attribute. More... | |
void | processIncludeElements (TiXmlElement *element, const std::map< std::string, std::string > &constants) |
Helper method - recursively replace all with the corresponding file content. More... | |
void | processIncludeElement (TiXmlElement *element, const std::map< std::string, std::string > &constants, TiXmlDocument &document) |
void | processConstants (TiXmlNode *node, std::map< std::string, std::string > &constants) |
void | processConstant (TiXmlElement *element, std::map< std::string, std::string > &constants) |
std::string & | performConstantReplacement (std::string &value, const std::map< std::string, std::string > &constants) |
void | checkForNestedIncludes (const TiXmlNode *node) |
Protected Attributes | |
StringParametersMap | _map {} |
StringParameters * | _current |
std::unique_ptr< TiXmlDocument > | _doc {} |
std::string | _fileName |
Private Member Functions | |
XMLParser ()=delete | |
XMLParser (const marlin::XMLParser &)=delete | |
XMLParser & | operator= (const marlin::XMLParser &)=delete |
Private Attributes | |
bool | _forCCheck |
CommandLineParametersMap | _cmdlineparams {} |
XML parser for Marlin steering files.
Marlin XML steering files have the following form (use Marlin -x > example.xml to generate a template steering file):
<marlin> <execute> [1] ... // the processors and processor groups to be executed </execute> <global> [1] ... // global parameter section </global> <processor> [n] ... // definition of the processor and its parameters </processor> <group> [m] ... // a group of processors <processor> [k] ... // definition of the processor and its parameters </processor> </group> </marlin>
where the numbers enclosed in "[]" denote how many elements of the given type are allowed or required, n,m,k = [0,1,2,...].
The <execute/> section defines the processors that are to be called in the order specified. The Processor::processEvent() method is only called if the relevant condition (<if condition="A"/>) is fullfilled. Conditions can be arbitrary logical expressions formed of [!,(,&&,||,),value], e.g.
( A && ( B || !C ) ) || ( !B && D ), where the keys A,B,C,D can be either procesor names (Processor::setReturnValue(bool val) ) or processor names followed by a string ( Processor::setReturnValue(const std::string &name, bool val) ).
In the following example the Pflow processor is only called for events where the EventSelection processor has returnd true and the TwoJetAnalysis is is then in turn only called for events identified as having tow jets by the Pflow processor
<execute> <processor name="MyAIDAProcessor"/> <processor name="EventSelection"/> <if condition="EventSelection"> <processor name="Pflow"/> <if condition="Pflow.TwoJet"> <group name="TwoJetAnalysis"/> </if> </if> <processor name="MyLCIOOutputProcessor"/> </execute>
The <global> section defines the global paramters:
<global> <parameter name="LCIOInputFiles">dd_rec.slcio </parameter> <parameter name="LCIOInputFiles">../tt500_all_set1_12.slcio </parameter> <parameter name="MaxRecordNumber" value="5001" /> <parameter name="SupressCheck" value="false" /> </global>
Parameters can be either specified as the content of the <parameter/> tag or in the value-attribute of the tag !
The <processor name="..." type="..." > section defines the processor and its parameters, where name and type are required attibutes, e.g.
<processor name="EventSelection" type="SelectionProcessor"> <parameter name="EnergyCut" type="float">50.0</parameter> </processor>
Note: the parameter's type-attribute is optional.
Processor sections can be enclosed in a <group/> tag, where parameters defined outside any <processor/> tag are group parameters valid for all processors in the group, .e.g.
<group> <parameter name="PtCut" value="0.03"> <processor name="TrackFinding" type="TrackFinder"/> <processor name="TrackFitting" type="KalmanProcessor"> <parameter name="UseDAF" value="true"> <processor> </group>
Definition at line 106 of file XMLParser.h.
marlin::XMLParser::XMLParser | ( | const std::string & | fileName, |
bool | forCCheck = false |
||
) |
Definition at line 17 of file XMLParser.cc.
|
virtual |
Definition at line 21 of file XMLParser.cc.
|
privatedelete |
|
privatedelete |
|
protected |
Definition at line 692 of file XMLParser.cc.
References TiXmlNode::FirstChildElement(), TiXmlNode::GetDocument(), TiXmlNode::NextSiblingElement(), std::stringstream::str(), and TiXmlNode::Value().
Referenced by processIncludeElement().
|
protected |
Helper method - finds child element of node with given type and attribute value.
Definition at line 946 of file XMLParser.cc.
References TiXmlElement::Attribute(), TiXmlNode::IterateChildren(), and TiXmlNode::ToElement().
Referenced by replacegroups().
|
protected |
Return named attribute - throws ParseException if attribute doesn't exist.
Definition at line 315 of file XMLParser.cc.
References _fileName, TiXmlElement::Attribute(), std::string::c_str(), std::stringstream::str(), TiXmlNode::ToElement(), and TiXmlNode::Value().
Referenced by parametersFromNode(), parse(), processconditions(), and replacegroups().
|
virtual |
Return the StringParameters for the section as read from the xml file.
Implements marlin::IParser.
Definition at line 511 of file XMLParser.cc.
References _map.
|
privatedelete |
|
protected |
Extracts all parameters from the given node and adss them to the current StringParameters object.
Definition at line 336 of file XMLParser.cc.
References _cmdlineparams, _current, marlin::StringParameters::add(), TiXmlElement::Attribute(), std::string::begin(), std::string::compare(), std::string::end(), std::map< K, T >::end(), std::endl(), std::string::erase(), std::map< K, T >::erase(), std::map< K, T >::find(), std::pair::first, TiXmlNode::FirstChild(), std::for_each(), getAttribute(), TiXmlNode::IterateChildren(), performConstantReplacement(), std::vector< T >::push_back(), std::pair::second, TiXmlElement::SetAttribute(), TiXmlNode::SetValue(), TiXmlNode::ToElement(), and TiXmlNode::Value().
Referenced by parse().
|
virtual |
Parse the input file.
Implements marlin::IParser.
Definition at line 24 of file XMLParser.cc.
References _cmdlineparams, _current, _doc, _fileName, _forCCheck, _map, marlin::StringParameters::add(), std::map< K, T >::begin(), std::vector< T >::begin(), std::set< K >::clear(), TiXmlNode::Clone(), std::vector< T >::end(), std::map< K, T >::end(), std::set< K >::end(), std::endl(), TiXmlDocument::ErrorCol(), TiXmlDocument::ErrorDesc(), TiXmlDocument::ErrorRow(), std::set< K >::find(), std::pair::first, TiXmlNode::FirstChild(), TiXmlNode::FirstChildElement(), getAttribute(), std::set< K >::insert(), TiXmlNode::InsertBeforeChild(), TiXmlNode::InsertEndChild(), TiXmlNode::IterateChildren(), TiXmlDocument::LoadFile(), TiXmlNode::NextSiblingElement(), parametersFromNode(), performConstantReplacement(), processconditions(), processConstants(), processIncludeElements(), std::vector< T >::push_back(), TiXmlNode::RemoveChild(), replacegroups(), TiXmlDocument::RootElement(), std::pair::second, std::map< K, T >::size(), std::string::size(), std::stringstream::str(), and TiXmlNode::Value().
|
protected |
Definition at line 864 of file XMLParser.cc.
References std::map< K, T >::end(), std::string::find(), std::map< K, T >::find(), std::string::find_first_of(), std::string::replace(), std::stringstream::str(), and std::string::substr().
Referenced by parametersFromNode(), parse(), processConstant(), and processIncludeElement().
|
protected |
Helper method - recursively moves processors from <if> tags to top level (<execute>) and adds corresponding conditions attribute.
Definition at line 524 of file XMLParser.cc.
References TiXmlElement::Attribute(), TiXmlNode::Clone(), std::string::find(), getAttribute(), TiXmlNode::InsertBeforeChild(), TiXmlNode::IterateChildren(), TiXmlNode::Parent(), TiXmlNode::RemoveChild(), TiXmlElement::SetAttribute(), std::string::size(), TiXmlNode::ToElement(), and TiXmlNode::Value().
Referenced by parse().
|
protected |
Definition at line 774 of file XMLParser.cc.
References _cmdlineparams, TiXmlElement::Attribute(), std::string::compare(), std::map< K, T >::end(), std::endl(), std::string::erase(), std::map< K, T >::find(), TiXmlNode::FirstChild(), std::map< K, T >::insert(), performConstantReplacement(), TiXmlElement::SetAttribute(), TiXmlNode::SetValue(), std::stringstream::str(), and TiXmlNode::Value().
Referenced by processConstants().
|
protected |
Definition at line 709 of file XMLParser.cc.
References _cmdlineparams, std::map< K, T >::end(), std::map< K, T >::erase(), std::map< K, T >::find(), TiXmlNode::FirstChildElement(), TiXmlNode::InsertAfterChild(), TiXmlNode::NextSiblingElement(), processConstant(), processIncludeElement(), TiXmlNode::RemoveChild(), and TiXmlNode::Value().
Referenced by parse().
|
protected |
Definition at line 626 of file XMLParser.cc.
References _fileName, TiXmlElement::Attribute(), checkForNestedIncludes(), std::endl(), TiXmlDocument::ErrorCol(), TiXmlDocument::ErrorDesc(), TiXmlDocument::ErrorRow(), std::string::find_last_of(), TiXmlDocument::LoadFile(), performConstantReplacement(), std::stringstream::str(), std::string::substr(), and TiXmlNode::Value().
Referenced by processConstants(), and processIncludeElements().
|
protected |
Helper method - recursively replace all with the corresponding file content.
Definition at line 583 of file XMLParser.cc.
References TiXmlNode::FirstChildElement(), TiXmlNode::InsertAfterChild(), TiXmlNode::NextSiblingElement(), processIncludeElement(), TiXmlNode::RemoveChild(), and TiXmlNode::Value().
Referenced by parse().
|
protected |
Helper method - replaces all <group> tag with corresponding <processor> tags.
Definition at line 899 of file XMLParser.cc.
References _doc, TiXmlElement::Attribute(), std::endl(), findElement(), getAttribute(), TiXmlNode::InsertBeforeChild(), TiXmlNode::IterateChildren(), TiXmlNode::RemoveChild(), TiXmlDocument::RootElement(), TiXmlElement::SetAttribute(), TiXmlNode::ToElement(), and TiXmlNode::Value().
Referenced by parse().
|
inlinevirtual |
set command line parameters
Implements marlin::IParser.
Definition at line 155 of file XMLParser.h.
References _cmdlineparams.
|
virtual |
Write the parsed XML tree in an other file.
Implements marlin::IParser.
Definition at line 306 of file XMLParser.cc.
References _doc, and TiXmlDocument::SaveFile().
|
private |
Definition at line 216 of file XMLParser.h.
Referenced by parametersFromNode(), parse(), processConstant(), processConstants(), and setCmdLineParameters().
|
protected |
Definition at line 205 of file XMLParser.h.
Referenced by parametersFromNode(), and parse().
|
protected |
Definition at line 206 of file XMLParser.h.
Referenced by parse(), replacegroups(), and write().
|
protected |
Definition at line 208 of file XMLParser.h.
Referenced by getAttribute(), parse(), and processIncludeElement().
|
private |
Definition at line 214 of file XMLParser.h.
Referenced by parse().
|
mutableprotected |
Definition at line 204 of file XMLParser.h.
Referenced by getParameters(), and parse().