ATLAS Offline Software
IdDictMgr.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3  */
4 
5 // $Header: /DetectorDescription/IdDict/src/IdDictMgr.cxx,v 1.43 2008-12-09 09:49:43 dquarrie Exp $
6 
7 #include "IdDict/IdDictDefs.h"
10 #include "src/Debugger.h"
11 #include <fstream>
12 #include <iostream>
13 
14 #include <stdio.h>
15 #include <cstdlib>
16 #include <atomic>
17 #include <stdexcept>
18 #include <format>
19 
20 
22 {
23 public:
24  static int build_id();
25 };
26 
27 template <class T>
28 class TypeId
29 {
30 public:
31  operator int () {
32  static const int i = TypeIdBuilder::build_id();
33 
34  return(i);
35  }
36 };
37 
39  static std::atomic<int> i = 0;
40 
41  i++;
42  return(i);
43 }
44 
46  :
47  m_resolved_references(false),
48  m_generated_implementation(false),
49  m_do_checks(false),
50  m_do_neighbours(true) {
51 }
52 
54  clear();
55 }
56 
57 const std::string& IdDictMgr::tag() const {
58  return m_tag;
59 }
60 
61 const std::string& IdDictMgr::DTD_version() const {
62  return m_DTD_version;
63 }
64 
65 bool IdDictMgr::do_checks() const {
66  return m_do_checks;
67 }
68 
69 void
70 IdDictMgr::set_do_checks(bool do_checks) {
72  for (const auto& p : m_dictionaries) {
73  IdDictDictionary* d = p.second;
74  d->set_do_checks(do_checks);
75  }
76 }
77 
79  return m_do_neighbours;
80 }
81 
82 void
83 IdDictMgr::set_do_neighbours(bool do_neighbours) {
85  for (const auto& p : m_dictionaries) {
86  IdDictDictionary* d = p.second;
87  d->set_do_neighbours(do_neighbours);
88  }
89 }
90 
91 const std::string&
92 IdDictMgr::find_metadata(const std::string& name) const {
93  metadata_map::const_iterator it = m_metadata.find(name);
94  static const std::string empty;
95  if (it != m_metadata.end()) return(it->second);
96  else return empty;
97 }
98 
99 void
100 IdDictMgr::add_metadata(const std::string& name, const std::string& value) {
101  if (!m_metadata.insert(metadata_map::value_type(name, value)).second) {
102  std::cout << "IdDictMgr::add_metadata> unable to add name/value " << name << "/" << value << std::endl;
103  }
104 }
105 
106 void
107 IdDictMgr::set_DTD_version(const std::string& DTD_version) {
109 }
110 
112  return(m_dictionaries);
113 }
114 
116  dictionary_map::const_iterator it;
117 
118  it = m_dictionaries.find(name);
119 
120  if (it == m_dictionaries.end()) return(0);
121 
122  return((*it).second);
123 }
124 
126  if (dictionary == 0) return;
127 
128  std::string& name = dictionary->m_name;
129 
130  // Delete entry if already there
132  if (it != m_dictionaries.end()) delete (*it).second;
133 
135 
136  if (Debugger::debug()) {
138 
139  for (it = m_dictionaries.begin(); it != m_dictionaries.end(); ++it) {
140  std::string s = (*it).first;
141  IdDictDictionary* d = (*it).second;
142 
143  std::cout << "IdDictMgr::add_dictionary> d[" << s << "]=" << d << std::endl;
144  }
145  }
146 }
147 
148 void IdDictMgr::add_subdictionary_name(const std::string& name) {
149  m_subdictionary_names.insert(name);
150 }
151 
154 
155  for (it = m_dictionaries.begin(); it != m_dictionaries.end(); ++it) {
156  // From mgr, only resolve refs for top-level dictionaries
157  IdDictDictionary* dictionary = (*it).second;
158  if (m_subdictionary_names.find(dictionary->m_name) != m_subdictionary_names.end()) continue;
159  dictionary->resolve_references(*this);
160  }
161 }
162 
163 void IdDictMgr::generate_implementation(const std::string& tag) {
164  if (Debugger::debug()) {
165  std::cout << "IdDictMgr::generate_implementation>" << std::endl;
166  }
167 
168  // Must reset the implementation for multiple passes, this resets
169  // the generated flags
171 
173  m_tag = tag;
175  for (it = m_dictionaries.begin(); it != m_dictionaries.end(); ++it) {
176  // From mgr, only generate impl for top-level dictionaries
177  IdDictDictionary* dictionary = (*it).second;
178  if (m_subdictionary_names.find(dictionary->m_name) != m_subdictionary_names.end()) continue;
179  dictionary->generate_implementation(*this, tag);
180  }
182  }
183 }
184 
186  std::cout << "IdDictMgr::reset_implementation" << std::endl;
187 
188 
191  for (it = m_dictionaries.begin(); it != m_dictionaries.end(); ++it) {
192  // From mgr, only generate impl for top-level dictionaries
193  IdDictDictionary* dictionary = (*it).second;
194  if (m_subdictionary_names.find(dictionary->m_name) != m_subdictionary_names.end()) continue;
195  dictionary->reset_implementation();
196  }
198  }
199 }
200 
201 bool IdDictMgr::verify() const {
202  dictionary_map::const_iterator it;
203 
204  for (it = m_dictionaries.begin(); it != m_dictionaries.end(); ++it) {
205  const IdDictDictionary* dictionary = (*it).second;
206  if (!dictionary->verify()) return(false);
207  }
208 
209  return(true);
210 }
211 
214 
215  for (it = m_dictionaries.begin(); it != m_dictionaries.end(); ++it) {
216  IdDictDictionary* dictionary = (*it).second;
217  dictionary->clear();
218  delete dictionary;
219  }
220 
221  m_dictionaries.clear();
222  m_resolved_references = false;
224 }
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
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:152
IdDictMgr::verify
bool verify() const
Definition: IdDictMgr.cxx:201
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
IdDictMgr::m_metadata
metadata_map m_metadata
Definition: IdDictMgr.h:70
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
hist_file_dump.d
d
Definition: hist_file_dump.py:137
IdDictMgr::set_do_checks
void set_do_checks(bool do_checks)
Definition: IdDictMgr.cxx:70
skel.it
it
Definition: skel.GENtoEVGEN.py:396
IdDictMgr::get_dictionary_map
const dictionary_map & get_dictionary_map() const
Access to all dictionaries.
Definition: IdDictMgr.cxx:111
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:92
IdDictMgr::m_dictionaries
dictionary_map m_dictionaries
Definition: IdDictMgr.h:69
Debugger.h
empty
bool empty(TH1 *h)
Definition: computils.cxx:295
IdDictMgr::m_DTD_version
std::string m_DTD_version
Definition: IdDictMgr.h:67
TypeIdBuilder
Definition: IdDictMgr.cxx:22
IdDictDefs.h
IdDictMgr::IdDictMgr
IdDictMgr()
Definition: IdDictMgr.cxx:45
TypeIdBuilder::build_id
static int build_id()
Definition: IdDictMgr.cxx:38
IdDictMgr::set_do_neighbours
void set_do_neighbours(bool do_neighbours)
Definition: IdDictMgr.cxx:83
IdDictMgr::find_dictionary
IdDictDictionary * find_dictionary(const std::string &name) const
Access dictionary by name.
Definition: IdDictMgr.cxx:115
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
IdDictMgr::add_subdictionary_name
void add_subdictionary_name(const std::string &name)
Definition: IdDictMgr.cxx:148
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:78
IdDictMgr::m_do_checks
bool m_do_checks
Definition: IdDictMgr.h:74
IdDictMgr::reset_implementation
void reset_implementation()
Reset of implementation.
Definition: IdDictMgr.cxx:185
IdDictMgr::add_dictionary
void add_dictionary(IdDictDictionary *dictionary)
Fillers:
Definition: IdDictMgr.cxx:125
IdDictMgr::~IdDictMgr
~IdDictMgr()
Definition: IdDictMgr.cxx:53
master.dictionary
dictionary
Definition: master.py:47
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
RangeIterator.h
MultiRange.h
IdDictDictionary
Definition: IdDictDictionary.h:30
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:107
IdDictMgr::clear
void clear()
Definition: IdDictMgr.cxx:212
TypeId
Definition: IdDictMgr.cxx:29
IdDictMgr::do_checks
bool do_checks() const
Check whether or not to do checks for ids.
Definition: IdDictMgr.cxx:65
IdDictMgr::DTD_version
const std::string & DTD_version() const
DTD version.
Definition: IdDictMgr.cxx:61
CaloCondBlobAlgs_fillNoiseFromASCII.tag
string tag
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:24
IdDictMgr::tag
const std::string & tag() const
Version tag.
Definition: IdDictMgr.cxx:57
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:100
IdDictMgr::generate_implementation
void generate_implementation(const std::string &tag="")
Definition: IdDictMgr.cxx:163