ATLAS Offline Software
Loading...
Searching...
No Matches
IdDictDictionaryRef.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4
6#include "IdDict/IdDictMgr.h"
10#include "Identifier/Range.h"
12#include "IdDict/IdDictRange.h"
14
23
31
34
36 IdDictDictionary& dictionary,
37 IdDictRegion& /*region*/) {
40 if (m_dictionary) {
41 m_dictionary->resolve_references(idd);
42 m_dictionary->set_parent_dict (&dictionary);
43 }
45 }
46}
47
49 IdDictDictionary& dictionary,
50 IdDictRegion& region,
51 const std::string& tag) {
53 if (m_dictionary) {
55 // Propagate information to referenced dictionary:
56 //
57 // 1) Loop over ranges in this region and add them to the
58 // referenced dictionary, then propagate the generate
59 // implementation
60
61 // 2) Duplicate the regions of the current dictionary in
62 // referenced dictionary. Only the top level range(s) need
63 // to be propagated to correctly calculate the bits of the
64 // upper levels.
65
66 // Save a vector of entries to prepend, inverting their order
67 std::vector<IdDictRegionEntry*> prepend_entries;
68 for (const std::unique_ptr<IdDictRegionEntry>& entry : region.entries()) {
69 if (this == entry.get()) break; // end when we get to the dictionary (this)
70 // If this is a range entry, add a duplicate to all
71 // regions in the subdictionary
72 IdDictRange* range = dynamic_cast<IdDictRange*> (entry.get());
73 if (range) {
74 prepend_entries.insert(prepend_entries.begin(), entry.get());
75 }
76 }
77
78
79
80
81 // Now prepend list to each region and generate each region
82 for (IdDictRegion* region2 : m_dictionary->all_regions()) {
83 for (IdDictRegionEntry* entry : prepend_entries) {
84 IdDictRange* range = dynamic_cast<IdDictRange*> (entry);
85 if (range) {
86 region2->prepend_entry(std::make_unique<IdDictRangeRef> (*range));
87 }
88 }
89 }
90
91 // Now copy all prefixes into new regions in the
92 // referenced dictionary
93 if (prepend_entries.size() > 0) {
94 // Save region number
95 const IdDictRegion& region2 = *m_dictionary->all_regions().back();
96 size_t region_number = region2.index() + 1;
97
98 // Loop over all regions of current dict, add to ref dict (m_dictionary)
99 for (IdDictRegion* region3 : dictionary.all_regions()) {
100 auto new_region = std::make_unique<IdDictRegion> ("dummy", "dummy", "");
101
102 new_region->set_index (region_number++);
103
104 // Now add in only the ranges
105 size_t i = 0;
106 for (const std::unique_ptr<IdDictRegionEntry>& entry : region3->entries()) {
107 if (i++ >= prepend_entries.size()) continue;
108
109 IdDictRange* range = dynamic_cast<IdDictRange*> (entry.get());
110 if (range) {
111 new_region->add_entry(std::make_unique<IdDictRangeRef> (*range));
112 }
113 }
114
115 // to all region vectors
116 m_dictionary->add_region(new_region.get());
117 // to the entries of the dictionary
118 m_dictionary->add_dictentry(std::move(new_region));
119 }
120 }
122 }
123 m_dictionary->generate_implementation(idd, tag);
125 } else {
126 std::cout <<
127 "IdDictDictionaryRef::generate_implementation: - WARNING no dictionary named " << m_dictionary_name << " found, cannot generate implementation "
128 << std::endl;
129 }
130 }
131}
132
135 m_dictionary->reset_implementation();
137 }
138}
139
141 return(true);
142}
143
146
147 return(result);
148}
virtual void resolve_references(IdDictMgr &idd, IdDictDictionary &dictionary, IdDictRegion &region) override
virtual Range build_range() const override
IdDictDictionaryRef(const std::string &dictionary_name)
IdDictDictionary * m_dictionary
virtual bool verify() const override
virtual void reset_implementation() override
virtual void generate_implementation(const IdDictMgr &idd, IdDictDictionary &dictionary, IdDictRegion &region, const std::string &tag="") override
const std::string & dictionary_name() const
const IdDictDictionary * find_dictionary(const std::string &name) const
Access dictionary by name.
const std::vector< std::unique_ptr< IdDictRegionEntry > > & entries()
Non-const access to entry pointers.
size_t index() const
A Range describes the possible ranges for the field values of an ExpandedIdentifier.