CMS 3D CMS Logo

FWXMLConfigParser.h
Go to the documentation of this file.
1 #ifndef Fireworks_Core_FWXMLConfigParser
2 #define Fireworks_Core_FWXMLConfigParser
3 #include <istream>
4 #include <iostream>
6 
8 
34 
35 public:
37 
39  void pushConfig(Attributes &attributes) {
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  }
56 
60  void startElement(const std::string &tag, Attributes &attributes) override {
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  }
83 
92  void endElement(const std::string &tag) override {
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  }
112 
118  void data(const std::string &data) override {
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  }
128 
132  FWConfiguration *config(void) { return m_first.get(); }
133 
134  void debug_config_state_machine(const char *where, const std::string &tag, int state) {
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  }
142 
143 private:
144  std::vector<std::pair<std::string, FWConfiguration *> > m_configs;
146  std::unique_ptr<FWConfiguration> m_first;
147  // unsigned int m_currentConfigVersion;
149 };
150 #endif
mps_fire.i
i
Definition: mps_fire.py:428
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
FWXMLConfigParser::config
FWConfiguration * config(void)
Definition: FWXMLConfigParser.h:132
FWXMLConfigParser::m_currentConfigName
std::string m_currentConfigName
Definition: FWXMLConfigParser.h:148
FWXMLConfigParser::m_configs
std::vector< std::pair< std::string, FWConfiguration * > > m_configs
Definition: FWXMLConfigParser.h:144
SimpleSAXParser::Attribute
Definition: SimpleSAXParser.h:71
FWXMLConfigParser::m_state
enum STATES m_state
Definition: FWXMLConfigParser.h:145
FWXMLConfigParser::IN_PUSHED_CONFIG
Definition: FWXMLConfigParser.h:33
FWXMLConfigParser
Definition: FWXMLConfigParser.h:32
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
SimpleSAXParser::Attribute::key
std::string key
Definition: SimpleSAXParser.h:72
FWXMLConfigParser::m_first
std::unique_ptr< FWConfiguration > m_first
Definition: FWXMLConfigParser.h:146
FWXMLConfigParser::startElement
void startElement(const std::string &tag, Attributes &attributes) override
Definition: FWXMLConfigParser.h:60
SimpleSAXParser::Attribute::value
std::string value
Definition: SimpleSAXParser.h:73
FWXMLConfigParser::IN_POPPED_CONFIG
Definition: FWXMLConfigParser.h:33
SimpleSAXParser
Definition: SimpleSAXParser.h:69
FWXMLConfigParser::STATES
STATES
Definition: FWXMLConfigParser.h:33
RunInfoPI::state
state
Definition: RunInfoPayloadInspectoHelper.h:16
FWXMLConfigParser::endElement
void endElement(const std::string &tag) override
Definition: FWXMLConfigParser.h:92
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
FWXMLConfigParser::IN_STORED_STRING
Definition: FWXMLConfigParser.h:33
FWConfiguration
Definition: FWConfiguration.h:31
SimpleSAXParser.h
FWXMLConfigParser::data
void data(const std::string &data) override
Definition: FWXMLConfigParser.h:118
SimpleSAXParser::Attributes
std::vector< Attribute > Attributes
Definition: SimpleSAXParser.h:82
crabWrapper.key
key
Definition: crabWrapper.py:19
SimpleSAXParser::ParserError
Definition: SimpleSAXParser.h:83
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
FWXMLConfigParser::FWXMLConfigParser
FWXMLConfigParser(std::istream &f)
Definition: FWXMLConfigParser.h:36
FWConfiguration.h
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37