CMS 3D CMS Logo

List of all members | Public Member Functions | Private Types | Private Attributes
FWXMLConfigParser Class Reference

#include <FWXMLConfigParser.h>

Inheritance diagram for FWXMLConfigParser:
SimpleSAXParser

Public Member Functions

FWConfigurationconfig (void)
 
void data (const std::string &data) override
 
void debug_config_state_machine (const char *where, const std::string &tag, int state)
 
void endElement (const std::string &tag) override
 
 FWXMLConfigParser (std::istream &f)
 
void pushConfig (Attributes &attributes)
 
void startElement (const std::string &tag, Attributes &attributes) override
 
- Public Member Functions inherited from SimpleSAXParser
void parse (void)
 
 SimpleSAXParser (std::istream &f)
 
virtual ~SimpleSAXParser ()
 

Private Types

enum  STATES {
  IN_BEGIN_DOCUMENT, IN_PUSHED_CONFIG, IN_POPPED_CONFIG, IN_BEGIN_STRING,
  IN_STORED_STRING
}
 

Private Attributes

std::vector< std::pair< std::string, FWConfiguration * > > m_configs
 
std::string m_currentConfigName
 
std::unique_ptr< FWConfigurationm_first
 
enum STATES m_state
 

Additional Inherited Members

- Public Types inherited from SimpleSAXParser
typedef std::vector< AttributeAttributes
 
enum  PARSER_STATES {
  IN_DOCUMENT, IN_BEGIN_TAG, IN_DONE, IN_BEGIN_ELEMENT,
  IN_ELEMENT_WHITESPACE, IN_END_ELEMENT, IN_ATTRIBUTE_KEY, IN_END_TAG,
  IN_DATA, IN_BEGIN_ATTRIBUTE_VALUE, IN_STRING, IN_END_ATTRIBUTE_VALUE,
  IN_STRING_ENTITY, IN_DATA_ENTITY
}
 

Detailed Description

Helper class which reads the XML configuration and constructs the FWConfiguration classes.

State machine for the parser can be found by cut and pasting the following in graphviz.

digraph { IN_BEGIN_DOCUMENT->IN_PUSHED_CONFIG [label = "beginElement(config)"]

IN_PUSHED_CONFIG->IN_PUSHED_CONFIG [label = "beginElement(config)"] IN_PUSHED_CONFIG->IN_POPPED_CONFIG [label = "endElement(config)"] IN_PUSHED_CONFIG->IN_BEGIN_STRING [label = "beginElement(string)"]

IN_POPPED_CONFIG->IN_PUSHED_CONFIG [label = "beginElement(config)"] IN_POPPED_CONFIG->IN_POPPED_CONFIG [label = "endElement(config)"] IN_POPPED_CONFIG->DONE [label = "top level config popped"]

IN_BEGIN_STRING->IN_STORED_STRING [label = "data()"]; IN_BEGIN_STRING->IN_PUSHED_CONFIG [label = "endElement(string)"]

IN_STORED_STRING->IN_PUSHED_CONFIG [label = "endElement(string)"] }

Definition at line 32 of file FWXMLConfigParser.h.

Member Enumeration Documentation

◆ STATES

Enumerator
IN_BEGIN_DOCUMENT 
IN_PUSHED_CONFIG 
IN_POPPED_CONFIG 
IN_BEGIN_STRING 
IN_STORED_STRING 

Definition at line 33 of file FWXMLConfigParser.h.

Constructor & Destructor Documentation

◆ FWXMLConfigParser()

FWXMLConfigParser::FWXMLConfigParser ( std::istream &  f)
inline

Definition at line 36 of file FWXMLConfigParser.h.

Member Function Documentation

◆ config()

FWConfiguration* FWXMLConfigParser::config ( void  )
inline

The parsed configuration. Notice that the parser owns it and destroys it when destroyed.

Definition at line 132 of file FWXMLConfigParser.h.

132 { return m_first.get(); }

References m_first.

◆ data()

void FWXMLConfigParser::data ( const std::string &  data)
inlineoverridevirtual

Executes any transaction in the state machine which happens when the xml parser finds some data (i.e. text) between tags This is mainly used to handle <string> element contents but also whitespace between tags.

Reimplemented from SimpleSAXParser.

Definition at line 118 of file FWXMLConfigParser.h.

118  {
120  // We ignore whitespace but complain about any text which is not
121  // in the <string> tag.
122  if (m_state == IN_BEGIN_STRING) {
123  m_configs.back().second->addValue(data);
125  } else if (strspn(data.c_str(), " \t\n") != data.size())
126  throw ParserError("Unexpected text " + data);
127  }

References debug_config_state_machine(), IN_BEGIN_STRING, IN_STORED_STRING, m_configs, and m_state.

◆ debug_config_state_machine()

void FWXMLConfigParser::debug_config_state_machine ( const char *  where,
const std::string &  tag,
int  state 
)
inline

Definition at line 134 of file FWXMLConfigParser.h.

134  {
135 #ifdef FW_CONFIG_PARSER_DEBUG
136  static char *debug_states[] = {
137  "IN_BEGIN_DOCUMENT", "IN_PUSHED_CONFIG", "IN_POPPED_CONFIG", "IN_BEGIN_STRING", "IN_STORED_STRING"};
138 
139  std::cerr << " " << where << " tag/data " << tag << "in state " << debug_states[state] << std::endl;
140 #endif
141  }

References EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0::cerr, and GlobalPosition_Frontier_DevDB_cff::tag.

Referenced by data(), endElement(), and startElement().

◆ endElement()

void FWXMLConfigParser::endElement ( const std::string &  tag)
inlineoverridevirtual

Executes any transaction in the state machine which happens when the xml parser closes an element.

Notice that we need to do addKeyValue on endElement (and carry around the FWConfigutation name) because of the "copy by value" policy of addKeyValue addition which would add empty FWConfiguration objects if done on startElement.

Reimplemented from SimpleSAXParser.

Definition at line 92 of file FWXMLConfigParser.h.

92  {
95  if (tag != "config")
96  throw ParserError("Wrong closing tag found " + tag);
97 
98  FWConfiguration *current = m_configs.back().second;
99  std::string key = m_configs.back().first;
100  m_configs.pop_back();
101  if (!m_configs.empty())
102  m_configs.back().second->addKeyValue(key, *current);
104  } else if (m_state == IN_BEGIN_STRING && tag == "string") {
105  m_configs.back().second->addValue("");
107  } else if (m_state == IN_STORED_STRING && tag == "string")
109  else
110  throw ParserError("Wrong closing tag found " + tag);
111  }

References debug_config_state_machine(), IN_BEGIN_STRING, IN_POPPED_CONFIG, IN_PUSHED_CONFIG, IN_STORED_STRING, crabWrapper::key, m_configs, m_state, AlCaHLTBitMon_QueryRunRegistry::string, and GlobalPosition_Frontier_DevDB_cff::tag.

◆ pushConfig()

void FWXMLConfigParser::pushConfig ( Attributes attributes)
inline

Pushes the configuration on stack eventually

Definition at line 39 of file FWXMLConfigParser.h.

39  {
41  int version = 0;
42  for (size_t i = 0, e = attributes.size(); i != e; ++i) {
43  Attribute &attr = attributes[i];
44  if (attr.key == "name")
45  name = attr.value;
46  else if (attr.key == "version") {
47  char *endptr;
48  version = strtol(attr.value.c_str(), &endptr, 10);
49  if (endptr == attr.value.c_str())
50  throw ParserError("Version must be an integer.");
51  } else
52  throw ParserError("Unexpected attribute " + attr.key);
53  }
54  m_configs.push_back(std::make_pair(name, new FWConfiguration(version)));
55  }

References MillePedeFileConverter_cfg::e, mps_fire::i, SimpleSAXParser::Attribute::key, m_configs, Skims_PA_cff::name, AlCaHLTBitMon_QueryRunRegistry::string, SimpleSAXParser::Attribute::value, and BeamSplash_cfg::version.

Referenced by startElement().

◆ startElement()

void FWXMLConfigParser::startElement ( const std::string &  tag,
Attributes attributes 
)
inlineoverridevirtual

Executes any transaction in the state machine which happens when the xml parser finds an new element.

Reimplemented from SimpleSAXParser.

Definition at line 60 of file FWXMLConfigParser.h.

60  {
62  if (m_state == IN_BEGIN_DOCUMENT) {
63  if (tag != "config")
64  throw ParserError("Expecting toplevel <config> tag");
65  pushConfig(attributes);
66  m_first.reset(m_configs.back().second);
68  } else if (m_state == IN_PUSHED_CONFIG) {
69  if (tag == "config")
70  pushConfig(attributes);
71  else if (tag == "string")
73  else
74  throw ParserError("Unexpected element " + tag);
75  } else if (m_state == IN_POPPED_CONFIG) {
76  if (tag != "config")
77  throw ParserError("Unexpected element " + tag);
78  pushConfig(attributes);
80  } else
81  throw ParserError("Wrong opening tag found " + tag);
82  }

References debug_config_state_machine(), IN_BEGIN_DOCUMENT, IN_BEGIN_STRING, IN_POPPED_CONFIG, IN_PUSHED_CONFIG, m_configs, m_first, m_state, pushConfig(), and GlobalPosition_Frontier_DevDB_cff::tag.

Member Data Documentation

◆ m_configs

std::vector<std::pair<std::string, FWConfiguration *> > FWXMLConfigParser::m_configs
private

Definition at line 144 of file FWXMLConfigParser.h.

Referenced by data(), endElement(), pushConfig(), and startElement().

◆ m_currentConfigName

std::string FWXMLConfigParser::m_currentConfigName
private

Definition at line 148 of file FWXMLConfigParser.h.

◆ m_first

std::unique_ptr<FWConfiguration> FWXMLConfigParser::m_first
private

Definition at line 146 of file FWXMLConfigParser.h.

Referenced by config(), and startElement().

◆ m_state

enum STATES FWXMLConfigParser::m_state
private

Definition at line 145 of file FWXMLConfigParser.h.

Referenced by data(), endElement(), and startElement().

mps_fire.i
i
Definition: mps_fire.py:428
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
FWXMLConfigParser::m_configs
std::vector< std::pair< std::string, FWConfiguration * > > m_configs
Definition: FWXMLConfigParser.h:144
SimpleSAXParser::SimpleSAXParser
SimpleSAXParser(std::istream &f)
Definition: SimpleSAXParser.h:110
FWXMLConfigParser::m_state
enum STATES m_state
Definition: FWXMLConfigParser.h:145
FWXMLConfigParser::IN_PUSHED_CONFIG
Definition: FWXMLConfigParser.h:33
FWXMLConfigParser::debug_config_state_machine
void debug_config_state_machine(const char *where, const std::string &tag, int state)
Definition: FWXMLConfigParser.h:134
GlobalPosition_Frontier_DevDB_cff.tag
tag
Definition: GlobalPosition_Frontier_DevDB_cff.py:11
FWXMLConfigParser::pushConfig
void pushConfig(Attributes &attributes)
Definition: FWXMLConfigParser.h:39
FWXMLConfigParser::IN_BEGIN_STRING
Definition: FWXMLConfigParser.h:33
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
FWXMLConfigParser::m_first
std::unique_ptr< FWConfiguration > m_first
Definition: FWXMLConfigParser.h:146
FWXMLConfigParser::IN_POPPED_CONFIG
Definition: FWXMLConfigParser.h:33
RunInfoPI::state
state
Definition: RunInfoPayloadInspectoHelper.h:16
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
FWXMLConfigParser::IN_STORED_STRING
Definition: FWXMLConfigParser.h:33
FWConfiguration
Definition: FWConfiguration.h:31
FWXMLConfigParser::data
void data(const std::string &data) override
Definition: FWXMLConfigParser.h:118
crabWrapper.key
key
Definition: crabWrapper.py:19
EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.cerr
cerr
Definition: EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.py:8
BeamSplash_cfg.version
version
Definition: BeamSplash_cfg.py:45
FWXMLConfigParser::IN_BEGIN_DOCUMENT
Definition: FWXMLConfigParser.h:33
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37