ATLAS Offline Software
Loading...
Searching...
No Matches
IdDictDictionary.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef IDDICT_IdDictDictionary_H
6#define IDDICT_IdDictDictionary_H
7
8
9#include "Identifier/Identifier.h" //typedef
10#include "Identifier/Range.h" //member
12
13#include <vector>
14#include <string>
15#include <string_view>
16#include <memory>
17#include <map>
18
19
20class IdDictField;
21class IdDictLabel;
22class IdDictSubRegion;
23class IdDictRegion;
24class IdDictGroup;
25class IdDictMgr;
26
27class MultiRange;
29class IdDictDictEntry;
30
31
32
34public:
35 using value_type = Identifier::value_type;
36 using size_type = Identifier::size_type;
37
38 // ==================================
39 //** @name Constructor/destructor
40 // @{
41
43 IdDictDictionary (const std::string& name,
44 const std::string& version = "",
45 const std::string& date = "",
46 const std::string& author = "");
48
49
51 // ==================================
52 //** @name Simple accessors.
53 // @{
54
56 const std::string& name() const;
57
59 const std::string& version() const;
60
62 size_t n_regions() const;
63
65 const IdDictRegion& region(size_t i) const;
66
68 const std::string& file_name() const;
69
71 const std::string& dict_tag() const;
72
73
75 // ==================================
76 //** @name Search for field/label/region by name.
77 // @{
78
79 const IdDictField* find_field (const std::string& name) const;
80 IdDictField* find_field (const std::string& name);
81 const IdDictLabel* find_label (const std::string& field, const std::string& label) const;
82 int get_label_value (const std::string& field, const std::string& label, int& value) const; // > 0 == error
83 IdDictSubRegion* find_subregion (const std::string& subregion_name);
84 const IdDictRegion* find_region (const std::string& region_name) const;
85 IdDictRegion* find_region (const std::string& region_name, const std::string& group_name);
86 const IdDictRegion* find_region (const std::string& region_name, const std::string& group_name) const;
87 IdDictGroup* find_group (const std::string& group_name);
88 const IdDictGroup* find_group (const std::string& group_name) const;
89
90
92 // ==================================
93 //** @name Find first region that matches id
94 // @{
95
96 int find_region(const ExpandedIdentifier& id, size_type& index) const;
97 const IdDictRegion* find_region(const ExpandedIdentifier& id) const;
98 const IdDictRegion* find_region(const ExpandedIdentifier& id,const std::string& group_name) const;
99
100
102 // ==================================
103 //** @name Methods used to initialize the object.
104 // @{
105
107 const std::vector<IdDictRegion*>& all_regions();
108
109 IdDictField* add_field (std::unique_ptr<IdDictField> field);
110 IdDictSubRegion* add_subregion (std::unique_ptr<IdDictSubRegion> subregion);
111 void add_dictentry (std::unique_ptr<IdDictDictEntry> entry);
113 void add_subdictionary_name (const std::string& name);
114 void set_parent_dict (IdDictDictionary* parent_dict);
115
117 void set_file_name (const std::string& name);
118
120 void set_dict_tag (const std::string& tag);
121
122 void resolve_references (IdDictMgr& idd);
123 void generate_implementation (const IdDictMgr& idd, std::string_view tag = "");
124 void reset_implementation ();
125 bool verify () const;
126 void sort ();
127 void clear ();
128
130 void integrate_bits ();
131
132
134 // ==================================
135 //** @name Range building
136 // @{
137
140
146 const Range& prefix = Range(),
147 const std::string& last_field = "") const;
148
154
156 const std::string& group_name,
157 const Range& prefix = Range(),
158 const std::string& last_field = "") const;
159
160
162 // ==================================
163 //** @name Packing and unpacking
164 // @{
165
178 int pack32 (const ExpandedIdentifier& id,
179 size_t index1,
180 size_t index2,
181 Identifier& packedId) const;
182
200 int pack32 (const int* fields,
201 size_t index1,
202 size_t index2,
203 size_t region_index,
204 Identifier& packedId,
205 size_t first_field_index=0) const;
206
210 int reset (size_t index1,
211 size_t index2,
212 size_t region_index,
213 Identifier& packedId) const;
214
215
216
224 int unpack (const std::string& group,
225 const Identifier& id,
226 const ExpandedIdentifier& prefix,
227 size_t index2,
228 ExpandedIdentifier& unpackedId) const;
229
237 int unpack (const std::string& group,
238 const Identifier& id,
239 const ExpandedIdentifier& prefix,
240 size_t index2,
241 const std::string& sep,
242 std::string& unpackedId) const;
243
252 int unpack (const Identifier& id,
253 size_t first_field_index,
254 size_t field_index,
255 size_t region_index,
256 int& field) const;
257
258
267 int copy (const Identifier& idin,
268 size_t first_field_index,
269 size_t begin_field_index,
270 size_t end_field_index,
271 size_t region_index,
272 Identifier& idout) const;
273
274
276 // ==================================
277 //** @name Configuration and diagnostics
278 // @{
279
283 bool do_checks () const;
284 void set_do_checks (bool do_checks);
285
289 bool do_neighbours () const;
291
293 void dump() const;
294
295
297
298private:
299 std::string m_name{};
300 std::string m_version{};
301 std::string m_date{};
302 std::string m_author{};
303
304 using entries_type = std::vector<IdDictDictEntry*>;
305 using entries_it = entries_type::iterator;
306 using entries_const_it = entries_type::const_iterator;
307
308 using regions_type = std::vector<IdDictRegion*>;
309 using regions_it = regions_type::iterator;
310 using regions_const_it = regions_type::const_iterator;
311
312 using groups_type = std::vector<IdDictGroup*>;
313 using groups_it = groups_type::iterator;
314 using groups_const_it = groups_type::const_iterator;
315
316 std::map<std::string, std::unique_ptr<IdDictField> > m_fields;
317 std::map<std::string, std::unique_ptr<IdDictSubRegion> > m_subregions;
318 std::vector<IdDictRegion*> m_regions; // corresponding regions for REs
319 std::vector<IdDictRegion*> m_all_regions; // all regions
320 std::vector<std::unique_ptr<IdDictGroup> > m_groups;
321 std::vector<std::string> m_subdictionary_names;
323
324 std::string m_file_name{};
325 std::string m_dict_tag{};
327 bool m_do_checks{false};
328 bool m_do_neighbours{true};
329};
330
331//-------------------
332// inline definitions
333//-------------------
334
335// Dictionary name.
336inline
337const std::string&
339{
340 return m_name;
341}
342
343
344// Dictionary version.
345inline
346const std::string&
348{
349 return m_version;
350}
351
352
353// Access region by index.
354inline
355const IdDictRegion&
357{
358 return *m_regions.at(i);
359}
360
361
362// Number of regions
363inline
364size_t
366{
367 return m_regions.size();
368}
369
370
371// Access to file name
372inline const std::string&
374 return m_file_name;
375}
376
377
379inline const std::string&
381 return m_dict_tag;
382}
383
384
386inline void
389}
390
391
393inline void
394IdDictDictionary::set_dict_tag(const std::string& tag){
395 m_dict_tag = tag;
396}
397
398
400inline
401const std::vector<IdDictRegion*>& IdDictDictionary::all_regions()
402{
403 return m_all_regions;
404}
405
406
407#endif
bool verify() const
Here, we verify global constraints : (this must only be applied after the resolve_references and gene...
std::vector< std::unique_ptr< IdDictGroup > > m_groups
groups_type::iterator groups_it
bool do_checks() const
Checks are performed by default in debug compilation and NOT in optimized compilation.
IdDictSubRegion * add_subregion(std::unique_ptr< IdDictSubRegion > subregion)
int unpack(const std::string &group, const Identifier &id, const ExpandedIdentifier &prefix, size_t index2, ExpandedIdentifier &unpackedId) const
Unpack the value_type id to an expanded Identifier for a given group, considering the provided prefix...
std::map< std::string, std::unique_ptr< IdDictField > > m_fields
void resolve_references(IdDictMgr &idd)
void dump() const
Dump regions and trees for each group.
void add_dictentry(std::unique_ptr< IdDictDictEntry > entry)
regions_type::iterator regions_it
const IdDictLabel * find_label(const std::string &field, const std::string &label) const
IdDictDictionary * m_parent_dict
void set_do_checks(bool do_checks)
std::vector< IdDictDictEntry * > entries_type
Identifier::size_type size_type
MultiRange build_multirange() const
Get MultiRange for full dictionary.
std::vector< IdDictGroup * > groups_type
void set_do_neighbours(bool do_neighbours)
entries_type::iterator entries_it
std::map< std::string, std::unique_ptr< IdDictSubRegion > > m_subregions
const std::string & version() const
Dictionary version.
int get_label_value(const std::string &field, const std::string &label, int &value) const
void set_file_name(const std::string &name)
Set file name.
groups_type::const_iterator groups_const_it
IdDictSubRegion * find_subregion(const std::string &subregion_name)
const std::string & dict_tag() const
Access to the dictionary tag.
std::vector< IdDictRegion * > m_regions
IdDictGroup * find_group(const std::string &group_name)
std::string m_file_name
const std::vector< IdDictRegion * > & all_regions()
Non-const access to vector of all regions.
int copy(const Identifier &idin, size_t first_field_index, size_t begin_field_index, size_t end_field_index, size_t region_index, Identifier &idout) const
Copy a number of fields of the value_type id into another value_type id.
void integrate_bits()
Set up integral of bits for efficient unpacking.
const std::string & name() const
Dictionary name.
void set_parent_dict(IdDictDictionary *parent_dict)
void generate_implementation(const IdDictMgr &idd, std::string_view tag="")
std::vector< IdDictRegion * > m_all_regions
size_t n_regions() const
Number of contained regions.
Identifier::value_type value_type
IdDictField * add_field(std::unique_ptr< IdDictField > field)
const IdDictField * find_field(const std::string &name) const
const std::string & file_name() const
Access to file name.
int pack32(const ExpandedIdentifier &id, size_t index1, size_t index2, Identifier &packedId) const
Pack to 32bits the subset of id between (inclusive) index1 and index2 - this is generic,...
int reset(size_t index1, size_t index2, size_t region_index, Identifier &packedId) const
Reset fields from index1 to index2.
const IdDictRegion * find_region(const std::string &region_name) const
std::vector< std::string > m_subdictionary_names
entries_type::const_iterator entries_const_it
const IdDictRegion & region(size_t i) const
Region at index i.
void add_region(IdDictRegion *region)
void add_subdictionary_name(const std::string &name)
regions_type::const_iterator regions_const_it
bool do_neighbours() const
Neighbour initialization is performed by default One can switch or query this mode for any idHelper w...
void set_dict_tag(const std::string &tag)
Set the dictionary tag.
std::vector< IdDictRegion * > regions_type
A MultiRange combines several Ranges.
Definition MultiRange.h:17
A Range describes the possible ranges for the field values of an ExpandedIdentifier.
std::string date()
sadly, includes a return at the end
Definition hcg.cxx:60
std::string label(const std::string &format, int i)
Definition label.h:19
Definition index.py:1