ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
DetectorDescription
IdDict
src
IdDictMgr.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/IdDictMgr.h
"
6
#include "
IdDict/IdDictDictionary.h
"
7
#include "
Identifier/RangeIterator.h
"
8
#include "
Identifier/MultiRange.h
"
9
#include "
src/Debugger.h
"
10
#include <fstream>
11
#include <iostream>
12
13
#include <stdio.h>
14
#include <cstdlib>
15
#include <atomic>
16
#include <stdexcept>
17
#include <format>
18
19
20
class
TypeIdBuilder
21
{
22
public
:
23
static
int
build_id
();
24
};
25
26
template
<
class
T>
27
class
TypeId
28
{
29
public
:
30
operator
int () {
31
static
const
int
i =
TypeIdBuilder::build_id
();
32
33
return
(i);
34
}
35
};
36
37
int
TypeIdBuilder::build_id
() {
38
static
std::atomic<int> i = 0;
39
40
i++;
41
return
(i);
42
}
43
44
IdDictMgr::IdDictMgr
()
45
:
46
m_resolved_references
(false),
47
m_generated_implementation
(false),
48
m_do_checks
(false),
49
m_do_neighbours
(true) {
50
}
51
52
IdDictMgr::~IdDictMgr
() =
default
;
53
54
const
std::string&
IdDictMgr::tag
()
const
{
55
return
m_tag
;
56
}
57
58
const
std::string&
IdDictMgr::DTD_version
()
const
{
59
return
m_DTD_version
;
60
}
61
62
bool
IdDictMgr::do_checks
()
const
{
63
return
m_do_checks
;
64
}
65
66
void
67
IdDictMgr::set_do_checks
(
bool
do_checks
) {
68
m_do_checks
=
do_checks
;
69
for
(
const
auto
& p :
m_dictionaries
) {
70
p.second->set_do_checks(
do_checks
);
71
}
72
}
73
74
bool
IdDictMgr::do_neighbours
()
const
{
75
return
m_do_neighbours
;
76
}
77
78
void
79
IdDictMgr::set_do_neighbours
(
bool
do_neighbours
) {
80
m_do_neighbours
=
do_neighbours
;
81
for
(
const
auto
& p :
m_dictionaries
) {
82
p.second->set_do_neighbours(
do_neighbours
);
83
}
84
}
85
86
const
std::string&
87
IdDictMgr::find_metadata
(
const
std::string& name)
const
{
88
metadata_map::const_iterator it =
m_metadata
.find(name);
89
static
const
std::string
empty
;
90
if
(it !=
m_metadata
.end())
return
(it->second);
91
else
return
empty
;
92
}
93
94
void
95
IdDictMgr::add_metadata
(
const
std::string& name,
const
std::string& value) {
96
if
(!
m_metadata
.insert(metadata_map::value_type(name, value)).second) {
97
std::cout <<
"IdDictMgr::add_metadata> unable to add name/value "
<< name <<
"/"
<< value << std::endl;
98
}
99
}
100
101
void
102
IdDictMgr::set_DTD_version
(
const
std::string&
DTD_version
) {
103
m_DTD_version
=
DTD_version
;
104
}
105
106
std::vector<const IdDictDictionary*>
IdDictMgr::get_dictionaries
()
const
107
{
108
std::vector<const IdDictDictionary*> out;
109
out.reserve (
m_dictionaries
.size());
110
for
(
const
auto
& p :
m_dictionaries
) {
111
out.push_back (p.second.get());
112
}
113
return
out;
114
}
115
116
const
IdDictDictionary
*
IdDictMgr::find_dictionary
(
const
std::string& name)
const
{
117
auto
it =
m_dictionaries
.find(name);
118
if
(it ==
m_dictionaries
.end())
return
nullptr
;
119
return
it->second.get();
120
}
121
122
IdDictDictionary
*
IdDictMgr::find_dictionary
(
const
std::string& name) {
123
auto
it =
m_dictionaries
.find(name);
124
if
(it ==
m_dictionaries
.end())
return
nullptr
;
125
return
it->second.get();
126
}
127
128
void
IdDictMgr::add_dictionary
(std::unique_ptr<IdDictDictionary> dictionary) {
129
if
(dictionary == 0)
return
;
130
131
const
std::string& name = dictionary->name();
132
133
m_dictionaries
[name] = std::move(dictionary);
134
135
if
(
Debugger::debug
()) {
136
dictionary_map::iterator it;
137
138
for
(
const
auto
& p :
m_dictionaries
) {
139
std::cout <<
"IdDictMgr::add_dictionary> d["
<< p.first <<
"]="
<< p.second.get() << std::endl;
140
}
141
}
142
}
143
144
void
IdDictMgr::add_subdictionary_name
(
const
std::string& name) {
145
m_subdictionary_names
.insert(name);
146
}
147
148
void
IdDictMgr::resolve_references
() {
149
for
(
auto
& p :
m_dictionaries
) {
150
// From mgr, only resolve refs for top-level dictionaries
151
IdDictDictionary
& dictionary = *p.second;
152
if
(
m_subdictionary_names
.find(dictionary.name()) !=
m_subdictionary_names
.end())
continue
;
153
dictionary.resolve_references(*
this
);
154
}
155
}
156
157
void
IdDictMgr::generate_implementation
(std::string_view
tag
) {
158
if
(
Debugger::debug
()) {
159
std::cout <<
"IdDictMgr::generate_implementation>"
<< std::endl;
160
}
161
162
// Must reset the implementation for multiple passes, this resets
163
// the generated flags
164
if
(
m_generated_implementation
&&
tag
!=
m_tag
)
reset_implementation
();
165
166
if
(!
m_generated_implementation
) {
167
m_tag
= std::string(
tag
);
168
for
(
auto
& p :
m_dictionaries
) {
169
// From mgr, only generate impl for top-level dictionaries
170
IdDictDictionary
& dictionary = *p.second;
171
if
(
m_subdictionary_names
.find(dictionary.name()) !=
m_subdictionary_names
.end())
continue
;
172
dictionary.generate_implementation(*
this
,
tag
);
173
}
174
m_generated_implementation
=
true
;
175
}
176
}
177
178
void
IdDictMgr::reset_implementation
() {
179
std::cout <<
"IdDictMgr::reset_implementation"
<< std::endl;
180
181
182
if
(
m_generated_implementation
) {
183
for
(
auto
& p :
m_dictionaries
) {
184
// From mgr, only generate impl for top-level dictionaries
185
IdDictDictionary
& dictionary = *p.second;
186
if
(
m_subdictionary_names
.find(dictionary.name()) !=
m_subdictionary_names
.end())
continue
;
187
dictionary.reset_implementation();
188
}
189
m_generated_implementation
=
false
;
190
}
191
}
192
193
bool
IdDictMgr::verify
()
const
{
194
for
(
auto
& p :
m_dictionaries
) {
195
if
(!p.second->verify())
return
(
false
);
196
}
197
198
return
(
true
);
199
}
200
201
void
IdDictMgr::clear
() {
202
m_dictionaries
.clear();
203
m_resolved_references
=
false
;
204
m_generated_implementation
=
false
;
205
}
Debugger.h
IdDictDictionary.h
IdDictMgr.h
MultiRange.h
RangeIterator.h
empty
static const Attributes_t empty
Definition
XmlStreamer.cxx:16
Debugger::debug
static bool debug()
Definition
Debugger.h:18
IdDictDictionary
Definition
IdDictDictionary.h:33
IdDictMgr::add_dictionary
void add_dictionary(std::unique_ptr< IdDictDictionary > dictionary)
Fillers:
Definition
IdDictMgr.cxx:128
IdDictMgr::tag
const std::string & tag() const
Version tag.
Definition
IdDictMgr.cxx:54
IdDictMgr::resolve_references
void resolve_references()
Construct dictionary after parsing.
Definition
IdDictMgr.cxx:148
IdDictMgr::set_DTD_version
void set_DTD_version(const std::string &DTD_version)
Definition
IdDictMgr.cxx:102
IdDictMgr::generate_implementation
void generate_implementation(std::string_view tag="")
Definition
IdDictMgr.cxx:157
IdDictMgr::add_metadata
void add_metadata(const std::string &name, const std::string &value)
Definition
IdDictMgr.cxx:95
IdDictMgr::set_do_neighbours
void set_do_neighbours(bool do_neighbours)
Definition
IdDictMgr.cxx:79
IdDictMgr::verify
bool verify() const
Definition
IdDictMgr.cxx:193
IdDictMgr::m_metadata
metadata_map m_metadata
Definition
IdDictMgr.h:76
IdDictMgr::do_checks
bool do_checks() const
Check whether or not to do checks for ids.
Definition
IdDictMgr.cxx:62
IdDictMgr::do_neighbours
bool do_neighbours() const
Check whether or not to init neighbours.
Definition
IdDictMgr.cxx:74
IdDictMgr::set_do_checks
void set_do_checks(bool do_checks)
Definition
IdDictMgr.cxx:67
IdDictMgr::get_dictionaries
dictionary_vec get_dictionaries() const
Access to all dictionaries.
Definition
IdDictMgr.cxx:106
IdDictMgr::add_subdictionary_name
void add_subdictionary_name(const std::string &name)
Definition
IdDictMgr.cxx:144
IdDictMgr::m_subdictionary_names
std::set< std::string > m_subdictionary_names
Definition
IdDictMgr.h:77
IdDictMgr::m_dictionaries
dictionary_map m_dictionaries
Definition
IdDictMgr.h:75
IdDictMgr::find_dictionary
const IdDictDictionary * find_dictionary(const std::string &name) const
Access dictionary by name.
Definition
IdDictMgr.cxx:116
IdDictMgr::find_metadata
const std::string & find_metadata(const std::string &name) const
Access to meta data, name/value pairs.
Definition
IdDictMgr.cxx:87
IdDictMgr::IdDictMgr
IdDictMgr()
Definition
IdDictMgr.cxx:44
IdDictMgr::reset_implementation
void reset_implementation()
Reset of implementation.
Definition
IdDictMgr.cxx:178
IdDictMgr::clear
void clear()
Definition
IdDictMgr.cxx:201
IdDictMgr::m_do_neighbours
bool m_do_neighbours
Definition
IdDictMgr.h:81
IdDictMgr::~IdDictMgr
~IdDictMgr()
IdDictMgr::m_tag
std::string m_tag
Definition
IdDictMgr.h:74
IdDictMgr::DTD_version
const std::string & DTD_version() const
DTD version.
Definition
IdDictMgr.cxx:58
IdDictMgr::m_generated_implementation
bool m_generated_implementation
Definition
IdDictMgr.h:79
IdDictMgr::m_do_checks
bool m_do_checks
Definition
IdDictMgr.h:80
IdDictMgr::m_resolved_references
bool m_resolved_references
Definition
IdDictMgr.h:78
IdDictMgr::m_DTD_version
std::string m_DTD_version
Definition
IdDictMgr.h:73
TypeIdBuilder
Definition
IdDictMgr.cxx:21
TypeIdBuilder::build_id
static int build_id()
Definition
IdDictMgr.cxx:37
TypeId
Definition
IdDictMgr.cxx:28
Generated on
for ATLAS Offline Software by
1.17.0