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