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