ATLAS Offline Software
Loading...
Searching...
No Matches
IdDictDictionary.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 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 <memory>
16
17
18class IdDictField;
19class IdDictLabel;
20class IdDictSubRegion;
21class IdDictRegion;
22class IdDictGroup;
23class IdDictMgr;
24
25class MultiRange;
27class IdDictDictEntry;
28
29
30
32public:
33 using value_type = Identifier::value_type;
34 using size_type = Identifier::size_type;
35
36 // ==================================
37 //** @name Constructor/destructor
38 // @{
39
41 IdDictDictionary (const std::string& name,
42 const std::string& version = "",
43 const std::string& date = "",
44 const std::string& author = "");
46
47
49 // ==================================
50 //** @name Simple accessors.
51 // @{
52
54 const std::string& name() const;
55
57 const std::string& version() const;
58
60 size_t n_regions() const;
61
63 const IdDictRegion& region(size_t i) const;
64
66 const std::string& file_name() const;
67
69 const std::string& dict_tag() const;
70
71
73 // ==================================
74 //** @name Search for field/label/region by name.
75 // @{
76
77 const IdDictField* find_field (const std::string& name) const;
78 IdDictField* find_field (const std::string& name);
79 const IdDictLabel* find_label (const std::string& field, const std::string& label) const;
80 int get_label_value (const std::string& field, const std::string& label, int& value) const; // > 0 == error
81 IdDictSubRegion* find_subregion (const std::string& subregion_name);
82 const IdDictRegion* find_region (const std::string& region_name) const;
83 IdDictRegion* find_region (const std::string& region_name, const std::string& group_name);
84 const IdDictRegion* find_region (const std::string& region_name, const std::string& group_name) const;
85 IdDictGroup* find_group (const std::string& group_name);
86 const IdDictGroup* find_group (const std::string& group_name) const;
87
88
90 // ==================================
91 //** @name Find first region that matches id
92 // @{
93
94 int find_region(const ExpandedIdentifier& id, size_type& index) const;
95 const IdDictRegion* find_region(const ExpandedIdentifier& id) const;
96 const IdDictRegion* find_region(const ExpandedIdentifier& id,const std::string& group_name) const;
97
98
100 // ==================================
101 //** @name Methods used to initialize the object.
102 // @{
103
105 const std::vector<IdDictRegion*>& all_regions();
106
107 IdDictField* add_field (std::unique_ptr<IdDictField> field);
108 IdDictSubRegion* add_subregion (std::unique_ptr<IdDictSubRegion> subregion);
109 void add_dictentry (std::unique_ptr<IdDictDictEntry> entry);
111 void add_subdictionary_name (const std::string& name);
112 void set_parent_dict (IdDictDictionary* parent_dict);
113
115 void set_file_name (const std::string& name);
116
118 void set_dict_tag (const std::string& tag);
119
120 void resolve_references (IdDictMgr& idd);
121 void generate_implementation (const IdDictMgr& idd, const std::string& tag = "");
122 void reset_implementation ();
123 bool verify () const;
124 void sort ();
125 void clear ();
126
128 void integrate_bits ();
129
130
132 // ==================================
133 //** @name Range building
134 // @{
135
138
144 const Range& prefix = Range(),
145 const std::string& last_field = "") const;
146
152
154 const std::string& group_name,
155 const Range& prefix = Range(),
156 const std::string& last_field = "") const;
157
158
160 // ==================================
161 //** @name Packing and unpacking
162 // @{
163
176 int pack32 (const ExpandedIdentifier& id,
177 size_t index1,
178 size_t index2,
179 Identifier& packedId) const;
180
198 int pack32 (const int* fields,
199 size_t index1,
200 size_t index2,
201 size_t region_index,
202 Identifier& packedId,
203 size_t first_field_index=0) const;
204
208 int reset (size_t index1,
209 size_t index2,
210 size_t region_index,
211 Identifier& packedId) const;
212
213
214
222 int unpack (const std::string& group,
223 const Identifier& id,
224 const ExpandedIdentifier& prefix,
225 size_t index2,
226 ExpandedIdentifier& unpackedId) const;
227
235 int unpack (const std::string& group,
236 const Identifier& id,
237 const ExpandedIdentifier& prefix,
238 size_t index2,
239 const std::string& sep,
240 std::string& unpackedId) const;
241
250 int unpack (const Identifier& id,
251 size_t first_field_index,
252 size_t field_index,
253 size_t region_index,
254 int& field) const;
255
256
265 int copy (const Identifier& idin,
266 size_t first_field_index,
267 size_t begin_field_index,
268 size_t end_field_index,
269 size_t region_index,
270 Identifier& idout) const;
271
272
274 // ==================================
275 //** @name Configuration and diagnostics
276 // @{
277
281 bool do_checks () const;
282 void set_do_checks (bool do_checks);
283
287 bool do_neighbours () const;
289
291 void dump() const;
292
293
295
296private:
297 std::string m_name{};
298 std::string m_version{};
299 std::string m_date{};
300 std::string m_author{};
301
302 using entries_type = std::vector<IdDictDictEntry*>;
303 using entries_it = entries_type::iterator;
304 using entries_const_it = entries_type::const_iterator;
305
306 using regions_type = std::vector<IdDictRegion*>;
307 using regions_it = regions_type::iterator;
308 using regions_const_it = regions_type::const_iterator;
309
310 using groups_type = std::vector<IdDictGroup*>;
311 using groups_it = groups_type::iterator;
312 using groups_const_it = groups_type::const_iterator;
313
314 std::map<std::string, std::unique_ptr<IdDictField> > m_fields;
315 std::map<std::string, std::unique_ptr<IdDictSubRegion> > m_subregions;
316 std::vector<IdDictRegion*> m_regions; // corresponding regions for REs
317 std::vector<IdDictRegion*> m_all_regions; // all regions
318 std::vector<std::unique_ptr<IdDictGroup> > m_groups;
319 std::vector<std::string> m_subdictionary_names;
321
322 std::string m_file_name{};
323 std::string m_dict_tag{};
325 bool m_do_checks{false};
326 bool m_do_neighbours{true};
327};
328
329//-------------------
330// inline definitions
331//-------------------
332
333// Dictionary name.
334inline
335const std::string&
337{
338 return m_name;
339}
340
341
342// Dictionary version.
343inline
344const std::string&
346{
347 return m_version;
348}
349
350
351// Access region by index.
352inline
353const IdDictRegion&
355{
356 return *m_regions.at(i);
357}
358
359
360// Number of regions
361inline
362size_t
364{
365 return m_regions.size();
366}
367
368
369// Access to file name
370inline const std::string&
372 return m_file_name;
373}
374
375
377inline const std::string&
379 return m_dict_tag;
380}
381
382
384inline void
387}
388
389
391inline void
392IdDictDictionary::set_dict_tag(const std::string& tag){
393 m_dict_tag = tag;
394}
395
396
398inline
399const std::vector<IdDictRegion*>& IdDictDictionary::all_regions()
400{
401 return m_all_regions;
402}
403
404
405#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.
void generate_implementation(const IdDictMgr &idd, const std::string &tag="")
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)
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:58
std::string label(const std::string &format, int i)
Definition label.h:19
Definition index.py:1