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 
53  clear();
54 }
55 
56 const std::string& IdDictMgr::tag() const {
57  return m_tag;
58 }
59 
60 const std::string& IdDictMgr::DTD_version() const {
61  return m_DTD_version;
62 }
63 
64 bool IdDictMgr::do_checks() const {
65  return m_do_checks;
66 }
67 
68 void
69 IdDictMgr::set_do_checks(bool do_checks) {
71  for (const auto& p : m_dictionaries) {
72  IdDictDictionary* d = p.second;
73  d->set_do_checks(do_checks);
74  }
75 }
76 
78  return m_do_neighbours;
79 }
80 
81 void
82 IdDictMgr::set_do_neighbours(bool do_neighbours) {
84  for (const auto& p : m_dictionaries) {
85  IdDictDictionary* d = p.second;
86  d->set_do_neighbours(do_neighbours);
87  }
88 }
89 
90 const std::string&
91 IdDictMgr::find_metadata(const std::string& name) const {
92  metadata_map::const_iterator it = m_metadata.find(name);
93  static const std::string empty;
94  if (it != m_metadata.end()) return(it->second);
95  else return empty;
96 }
97 
98 void
99 IdDictMgr::add_metadata(const std::string& name, const std::string& value) {
100  if (!m_metadata.insert(metadata_map::value_type(name, value)).second) {
101  std::cout << "IdDictMgr::add_metadata> unable to add name/value " << name << "/" << value << std::endl;
102  }
103 }
104 
105 void
106 IdDictMgr::set_DTD_version(const std::string& DTD_version) {
108 }
109 
111  return(m_dictionaries);
112 }
113 
115  dictionary_map::const_iterator it;
116 
117  it = m_dictionaries.find(name);
118 
119  if (it == m_dictionaries.end()) return(0);
120 
121  return((*it).second);
122 }
123 
125  if (dictionary == 0) return;
126 
127  const std::string& name = dictionary->name();
128 
129  // Delete entry if already there
131  if (it != m_dictionaries.end()) delete (*it).second;
132 
134 
135  if (Debugger::debug()) {
137 
138  for (it = m_dictionaries.begin(); it != m_dictionaries.end(); ++it) {
139  std::string s = (*it).first;
140  IdDictDictionary* d = (*it).second;
141 
142  std::cout << "IdDictMgr::add_dictionary> d[" << s << "]=" << d << std::endl;
143  }
144  }
145 }
146 
147 void IdDictMgr::add_subdictionary_name(const std::string& name) {
148  m_subdictionary_names.insert(name);
149 }
150 
153 
154  for (it = m_dictionaries.begin(); it != m_dictionaries.end(); ++it) {
155  // From mgr, only resolve refs for top-level dictionaries
156  IdDictDictionary* dictionary = (*it).second;
157  if (m_subdictionary_names.find(dictionary->name()) != m_subdictionary_names.end()) continue;
158  dictionary->resolve_references(*this);
159  }
160 }
161 
162 void IdDictMgr::generate_implementation(const std::string& tag) {
163  if (Debugger::debug()) {
164  std::cout << "IdDictMgr::generate_implementation>" << std::endl;
165  }
166 
167  // Must reset the implementation for multiple passes, this resets
168  // the generated flags
170 
172  m_tag = tag;
174  for (it = m_dictionaries.begin(); it != m_dictionaries.end(); ++it) {
175  // From mgr, only generate impl for top-level dictionaries
176  IdDictDictionary* dictionary = (*it).second;
177  if (m_subdictionary_names.find(dictionary->name()) != m_subdictionary_names.end()) continue;
178  dictionary->generate_implementation(*this, tag);
179  }
181  }
182 }
183 
185  std::cout << "IdDictMgr::reset_implementation" << std::endl;
186 
187 
190  for (it = m_dictionaries.begin(); it != m_dictionaries.end(); ++it) {
191  // From mgr, only generate impl for top-level dictionaries
192  IdDictDictionary* dictionary = (*it).second;
193  if (m_subdictionary_names.find(dictionary->name()) != m_subdictionary_names.end()) continue;
194  dictionary->reset_implementation();
195  }
197  }
198 }
199 
200 bool IdDictMgr::verify() const {
201  dictionary_map::const_iterator it;
202 
203  for (it = m_dictionaries.begin(); it != m_dictionaries.end(); ++it) {
204  const IdDictDictionary* dictionary = (*it).second;
205  if (!dictionary->verify()) return(false);
206  }
207 
208  return(true);
209 }
210 
213 
214  for (it = m_dictionaries.begin(); it != m_dictionaries.end(); ++it) {
215  IdDictDictionary* dictionary = (*it).second;
216  dictionary->clear();
217  delete dictionary;
218  }
219 
220  m_dictionaries.clear();
221  m_resolved_references = false;
223 }
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
IdDictMgr.h
IdDictMgr::dictionary_map
std::map< std::string, IdDictDictionary * > dictionary_map
Definition: IdDictMgr.h:16
IdDictMgr::resolve_references
void resolve_references()
Construct dictionary after parsing.
Definition: IdDictMgr.cxx:151
IdDictMgr::verify
bool verify() const
Definition: IdDictMgr.cxx:200
IdDictMgr::m_metadata
metadata_map m_metadata
Definition: IdDictMgr.h:70
hist_file_dump.d
d
Definition: hist_file_dump.py:142
IdDictDictionary.h
IdDictMgr::set_do_checks
void set_do_checks(bool do_checks)
Definition: IdDictMgr.cxx:69
skel.it
it
Definition: skel.GENtoEVGEN.py:407
IdDictMgr::get_dictionary_map
const dictionary_map & get_dictionary_map() const
Access to all dictionaries.
Definition: IdDictMgr.cxx:110
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:91
IdDictMgr::m_dictionaries
dictionary_map m_dictionaries
Definition: IdDictMgr.h:69
Debugger.h
IdDictMgr::m_DTD_version
std::string m_DTD_version
Definition: IdDictMgr.h:67
TypeIdBuilder
Definition: IdDictMgr.cxx:21
IdDictMgr::IdDictMgr
IdDictMgr()
Definition: IdDictMgr.cxx:44
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:82
IdDictMgr::find_dictionary
IdDictDictionary * find_dictionary(const std::string &name) const
Access dictionary by name.
Definition: IdDictMgr.cxx:114
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:209
IdDictMgr::add_subdictionary_name
void add_subdictionary_name(const std::string &name)
Definition: IdDictMgr.cxx:147
lumiFormat.i
int i
Definition: lumiFormat.py:85
IdDictMgr::m_resolved_references
bool m_resolved_references
Definition: IdDictMgr.h:72
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:77
IdDictMgr::m_do_checks
bool m_do_checks
Definition: IdDictMgr.h:74
IdDictMgr::reset_implementation
void reset_implementation()
Reset of implementation.
Definition: IdDictMgr.cxx:184
IdDictMgr::add_dictionary
void add_dictionary(IdDictDictionary *dictionary)
Fillers:
Definition: IdDictMgr.cxx:124
IdDictMgr::~IdDictMgr
~IdDictMgr()
Definition: IdDictMgr.cxx:52
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:30
python.CaloAddPedShiftConfig.int
int
Definition: CaloAddPedShiftConfig.py:45
IdDictMgr::m_do_neighbours
bool m_do_neighbours
Definition: IdDictMgr.h:75
IdDictMgr::set_DTD_version
void set_DTD_version(const std::string &DTD_version)
Definition: IdDictMgr.cxx:106
python.SystemOfUnits.s
float s
Definition: SystemOfUnits.py:147
IdDictMgr::clear
void clear()
Definition: IdDictMgr.cxx:211
TypeId
Definition: IdDictMgr.cxx:28
IdDictMgr::do_checks
bool do_checks() const
Check whether or not to do checks for ids.
Definition: IdDictMgr.cxx:64
IdDictMgr::DTD_version
const std::string & DTD_version() const
DTD version.
Definition: IdDictMgr.cxx:60
CaloCondBlobAlgs_fillNoiseFromASCII.tag
string tag
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:23
IdDictMgr::tag
const std::string & tag() const
Version tag.
Definition: IdDictMgr.cxx:56
IdDictMgr::m_generated_implementation
bool m_generated_implementation
Definition: IdDictMgr.h:73
IdDictMgr::m_subdictionary_names
std::set< std::string > m_subdictionary_names
Definition: IdDictMgr.h:71
IdDictMgr::m_tag
std::string m_tag
Definition: IdDictMgr.h:68
IdDictMgr::add_metadata
void add_metadata(const std::string &name, const std::string &value)
Definition: IdDictMgr.cxx:99
IdDictMgr::generate_implementation
void generate_implementation(const std::string &tag="")
Definition: IdDictMgr.cxx:162