evio  6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
EvioXMLDictionary.h
Go to the documentation of this file.
1 //
2 // Copyright 2020, Jefferson Science Associates, LLC.
3 // Subject to the terms in the LICENSE file found in the top-level directory.
4 //
5 // EPSCI Group
6 // Thomas Jefferson National Accelerator Facility
7 // 12000, Jefferson Ave, Newport News, VA 23606
8 // (757)-269-7100
9 
10 
11 #ifndef EVIO_6_0_EVIOXMLDICTIONARY_H
12 #define EVIO_6_0_EVIOXMLDICTIONARY_H
13 
14 
15 #include <stdexcept>
16 #include <string>
17 #include <regex>
18 #include <iostream>
19 #include <iterator>
20 #include <unordered_map>
21 #include <vector>
22 #include <sstream>
23 #include <algorithm>
24 
25 #include "EvioDictionaryEntry.h"
26 #include "EvioException.h"
27 #include "Util.h"
28 #include "BaseStructure.h"
29 #include "pugixml.hpp"
30 
31 
32 namespace evio {
33 
34 
56 
57  private:
58 
60  static const std::string DICT_TOP_LEVEL;
61 
63  static const std::string ENTRY;
64 
66  static const std::string ENTRY_ALT;
67 
69  static const std::string ENTRY_BANK;
70 
72  static const std::string ENTRY_LEAF;
73 
75  static const std::string DESCRIPTION;
76 
78  static const std::string FORMAT;
79 
81  static const std::string TYPE;
82 
84  static const std::string NAME;
85 
87  static const std::string TAG;
88 
90  static const std::string NUM;
91 
97  static std::regex pattern_regex;
98 
103  std::string const delimiter = ".";
104 
105  pugi::xml_document doc;
106 
107  public:
108 
115  std::unordered_map<std::shared_ptr<EvioDictionaryEntry>, std::string> tagNumMap;
116 
123  std::unordered_map<std::shared_ptr<EvioDictionaryEntry>, std::string> tagOnlyMap;
124 
131  std::unordered_map<std::shared_ptr<EvioDictionaryEntry>, std::string> tagRangeMap;
132 
133 
134  private:
135 
142  std::unordered_map<std::string, std::shared_ptr<EvioDictionaryEntry>> reverseMap;
143 
149  std::unordered_map<std::string, std::shared_ptr<EvioDictionaryEntry>> tagNumReverseMap;
150 
155  pugi::xml_node topLevelDoc;
156 
161  std::string stringRepresentation;
162 
163 
164  public:
165 
166 
167  static const std::string &NO_NAME_STRING();
168 
169  explicit EvioXMLDictionary(std::string const &path);
170  EvioXMLDictionary(std::string const &xml, int dummy);
171 
172 
173  void parseXML(pugi::xml_parse_result &domDocument);
174 
175  size_t size() const;
176 
177  const std::unordered_map<std::string, std::shared_ptr<EvioDictionaryEntry>> &getMap() const;
178 
179 
180  private:
181 
182 
183  void addHierarchicalDictEntries(std::vector<pugi::xml_node> &kidList,
184  std::string const &parentName);
185 
186  public:
187 
188  std::string getName(std::shared_ptr<BaseStructure> &structure);
189  std::string getName(uint16_t tag);
190  std::string getName(uint16_t tag, uint8_t num);
191  std::string getName(uint16_t tag, uint8_t num, uint16_t tagEnd);
192  std::string getName(uint16_t tag, uint8_t num, uint16_t tagEnd,
193  uint16_t pTag, uint8_t pNum, uint16_t pTagEnd);
194  std::string getName(uint16_t tag, uint8_t num, uint16_t tagEnd,
195  uint16_t pTag, uint8_t pNum, uint16_t pTagEnd,
196  bool numValid = true, bool parentValid = false,
197  bool parentNumValid = false);
198 
199 
200  private:
201 
202 
203  std::string getName(std::shared_ptr<EvioDictionaryEntry> key);
204  std::shared_ptr<EvioDictionaryEntry> entryLookupByData(uint16_t tag, uint8_t num, uint16_t tagEnd);
205  std::shared_ptr<EvioDictionaryEntry> entryLookupByName(std::string const &name);
206 
207 
208  public:
209 
210 
211  std::string getDescription(uint16_t tag, uint8_t num);
212  std::string getDescription(uint16_t tag, uint8_t num, uint16_t tagEnd);
213  std::string getDescription(std::string const &name);
214 
215  std::string getFormat(uint16_t tag, uint8_t num);
216  std::string getFormat(uint16_t tag, uint8_t num, uint16_t tagEnd);
217  std::string getFormat(std::string const &name);
218 
219  DataType getType(uint16_t tag, uint8_t num);
220  DataType getType(uint16_t tag, uint8_t num, uint16_t tagEnd);
221  DataType getType(std::string const &name);
222 
223  bool getTagNum(std::string const &name, uint16_t *tag, uint8_t *num, uint16_t *tagEnd);
224  bool getTag(std::string const &name, uint16_t *tag);
225  bool getTagEnd(std::string const &name, uint16_t *tagEnd);
226 
227  bool getNum(std::string const &name, uint8_t *num);
228 
229 
230  std::string toString();
231  };
232 
233 }
234 
235 
236 #endif //EVIO_6_0_EVIOXMLDICTIONARY_H
std::unordered_map< std::shared_ptr< EvioDictionaryEntry >, std::string > tagOnlyMap
Some dictionary entries have only a tag and no num.
Definition: EvioXMLDictionary.h:123
bool getNum(std::string const &name, uint8_t *num)
Returns the num corresponding to the name of a dictionary entry.
Definition: EvioXMLDictionary.cpp:1528
size_t size() const
Get the number of entries in this dictionary.
Definition: EvioXMLDictionary.cpp:470
static const std::string & NO_NAME_STRING()
Get a string used to indicate that no name can be determined.
Definition: EvioXMLDictionary.cpp:61
EvioXMLDictionary(std::string const &path)
Create an EvioXMLDictionary from an xml file.
Definition: EvioXMLDictionary.cpp:70
const std::unordered_map< std::string, std::shared_ptr< EvioDictionaryEntry > > & getMap() const
Get the map in which the key is the entry name and the value is an object containing its data (tag...
Definition: EvioXMLDictionary.cpp:479
std::string getFormat(uint16_t tag, uint8_t num)
Returns the format, if any, associated with the given tag and num.
Definition: EvioXMLDictionary.cpp:1366
void parseXML(pugi::xml_parse_result &domDocument)
Create an EvioXMLDictionary from an xml Document object.
Definition: EvioXMLDictionary.cpp:114
std::string toString()
Get a string representation of the dictionary.
Definition: EvioXMLDictionary.cpp:1543
bool getTagEnd(std::string const &name, uint16_t *tagEnd)
Returns the tagEnd corresponding to the name of a dictionary entry.
Definition: EvioXMLDictionary.cpp:1508
DataType getType(uint16_t tag, uint8_t num)
Returns the type, if any, associated with the given tag and num.
Definition: EvioXMLDictionary.cpp:1412
bool getTag(std::string const &name, uint16_t *tag)
Returns the tag corresponding to the name of a dictionary entry.
Definition: EvioXMLDictionary.cpp:1489
std::string getName(std::shared_ptr< BaseStructure > &structure)
Returns the name of a given evio structure.
Definition: EvioXMLDictionary.cpp:849
Numerical values associated with evio data types.
Definition: DataType.h:32
std::string getDescription(uint16_t tag, uint8_t num)
Returns the description, if any, associated with the given tag and num.
Definition: EvioXMLDictionary.cpp:1320
std::unordered_map< std::shared_ptr< EvioDictionaryEntry >, std::string > tagRangeMap
Some dictionary entries have only a tag range and no num.
Definition: EvioXMLDictionary.h:131
This was developed to read the xml dictionary that Maurizio uses for GEMC.
Definition: EvioXMLDictionary.h:55
std::unordered_map< std::shared_ptr< EvioDictionaryEntry >, std::string > tagNumMap
This is the heart of the dictionary in which a key is composed of a tag/num pair &amp; other entry data a...
Definition: EvioXMLDictionary.h:115
bool getTagNum(std::string const &name, uint16_t *tag, uint8_t *num, uint16_t *tagEnd)
Returns the tag/num/tagEnd values, in an Integer object array, corresponding to the name of a diction...
Definition: EvioXMLDictionary.cpp:1470