ATLAS Offline Software
IdDictMgr.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3  */
4 
5 #include "IdDict/IdDictMgr.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 
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 
38  static std::atomic<int> i = 0;
39 
40  i++;
41  return(i);
42 }
43 
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) {
69  for (const auto& p : m_dictionaries) {
70  p.second->set_do_checks(do_checks);
71  }
72 }
73 
75  return m_do_neighbours;
76 }
77 
78 void
79 IdDictMgr::set_do_neighbours(bool 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) {
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 
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()) {
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 
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(const std::string& 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
165 
167  m_tag = 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  }
175  }
176 }
177 
179  std::cout << "IdDictMgr::reset_implementation" << std::endl;
180 
181 
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  }
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 
202  m_dictionaries.clear();
203  m_resolved_references = false;
205 }
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
IdDictMgr.h
IdDictMgr::resolve_references
void resolve_references()
Construct dictionary after parsing.
Definition: IdDictMgr.cxx:148
IdDictMgr::verify
bool verify() const
Definition: IdDictMgr.cxx:193
IdDictMgr::m_metadata
metadata_map m_metadata
Definition: IdDictMgr.h:75
IdDictDictionary.h
IdDictMgr::set_do_checks
void set_do_checks(bool do_checks)
Definition: IdDictMgr.cxx:67
skel.it
it
Definition: skel.GENtoEVGEN.py:407
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:70
athena.value
value
Definition: athena.py:124
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::m_dictionaries
dictionary_map m_dictionaries
Definition: IdDictMgr.h:74
Debugger.h
IdDictMgr::m_DTD_version
std::string m_DTD_version
Definition: IdDictMgr.h:72
TypeIdBuilder
Definition: IdDictMgr.cxx:21
IdDictMgr::IdDictMgr
IdDictMgr()
Definition: IdDictMgr.cxx:44
IdDictMgr::get_dictionaries
dictionary_vec get_dictionaries() const
Access to all dictionaries.
Definition: IdDictMgr.cxx:106
TypeIdBuilder::build_id
static int build_id()
Definition: IdDictMgr.cxx:37
IdDictMgr::set_do_neighbours
void set_do_neighbours(bool do_neighbours)
Definition: IdDictMgr.cxx:79
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:209
IdDictMgr::add_subdictionary_name
void add_subdictionary_name(const std::string &name)
Definition: IdDictMgr.cxx:144
lumiFormat.i
int i
Definition: lumiFormat.py:85
IdDictMgr::add_dictionary
void add_dictionary(std::unique_ptr< IdDictDictionary > dictionary)
Fillers:
Definition: IdDictMgr.cxx:128
IdDictMgr::m_resolved_references
bool m_resolved_references
Definition: IdDictMgr.h:77
Debugger::debug
static bool debug()
Definition: Debugger.h:18
IdDictMgr::do_neighbours
bool do_neighbours() const
Check whether or not to init neighbours.
Definition: IdDictMgr.cxx:74
IdDictMgr::m_do_checks
bool m_do_checks
Definition: IdDictMgr.h:79
IdDictMgr::reset_implementation
void reset_implementation()
Reset of implementation.
Definition: IdDictMgr.cxx:178
IdDictMgr::~IdDictMgr
~IdDictMgr()
master.dictionary
dictionary
Definition: master.py:47
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
RangeIterator.h
MultiRange.h
IdDictDictionary
Definition: IdDictDictionary.h:31
IdDictMgr::find_dictionary
const IdDictDictionary * find_dictionary(const std::string &name) const
Access dictionary by name.
Definition: IdDictMgr.cxx:116
python.CaloAddPedShiftConfig.int
int
Definition: CaloAddPedShiftConfig.py:45
IdDictMgr::m_do_neighbours
bool m_do_neighbours
Definition: IdDictMgr.h:80
IdDictMgr::set_DTD_version
void set_DTD_version(const std::string &DTD_version)
Definition: IdDictMgr.cxx:102
IdDictMgr::clear
void clear()
Definition: IdDictMgr.cxx:201
TypeId
Definition: IdDictMgr.cxx:28
IdDictMgr::do_checks
bool do_checks() const
Check whether or not to do checks for ids.
Definition: IdDictMgr.cxx:62
IdDictMgr::DTD_version
const std::string & DTD_version() const
DTD version.
Definition: IdDictMgr.cxx:58
CaloCondBlobAlgs_fillNoiseFromASCII.tag
string tag
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:23
IdDictMgr::tag
const std::string & tag() const
Version tag.
Definition: IdDictMgr.cxx:54
IdDictMgr::m_generated_implementation
bool m_generated_implementation
Definition: IdDictMgr.h:78
IdDictMgr::m_subdictionary_names
std::set< std::string > m_subdictionary_names
Definition: IdDictMgr.h:76
IdDictMgr::m_tag
std::string m_tag
Definition: IdDictMgr.h:73
IdDictMgr::add_metadata
void add_metadata(const std::string &name, const std::string &value)
Definition: IdDictMgr.cxx:95
IdDictMgr::generate_implementation
void generate_implementation(const std::string &tag="")
Definition: IdDictMgr.cxx:157