DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
conffwk
src
DalRegistry.cpp
Go to the documentation of this file.
1
#include "
conffwk/DalObject.hpp
"
2
#include "
conffwk/Schema.hpp
"
3
4
namespace
dunedaq
{
5
namespace
conffwk
{
6
7
//-----------------------------------------------------------------------------
8
DalRegistry::DalRegistry
(
conffwk::Configuration
& confdb)
9
:
m_confdb
(confdb)
10
{
11
}
12
13
//-----------------------------------------------------------------------------
14
DalRegistry::~DalRegistry
() {}
15
16
// //-----------------------------------------------------------------------------
17
// std::deque<std::set<std::string>>
18
// DalRegistry::find_class_domains() {
19
20
// std::deque<std::set<std::string>> domains;
21
22
// std::deque<dunedaq::conffwk::class_t> seeds;
23
// for (const auto& c : m_confdb.get_class_list()) {
24
// auto ci = m_confdb._get_class_info(c);
25
// if (ci.p_superclasses.empty())
26
// seeds.push_back(ci);
27
// }
28
29
// for (const auto& ci : seeds) {
30
// // Make a candidate domain based using the seed subclasses
31
// std::set<std::string> class_domain;
32
// class_domain.insert(ci.p_name);
33
// class_domain.insert(ci.p_subclasses.begin(), ci.p_subclasses.end());
34
35
// // Look for overlaps with other domains
36
// std::deque<std::set<std::string>> overlapping;
37
// for (auto& d : domains) {
38
// std::set<std::string> intersection;
39
// std::set_intersection(d.begin(), d.end(), class_domain.begin(), class_domain.end(), std::inserter(intersection,
40
// intersection.begin()));
41
// // non-zero intersection, overlap found
42
// if (intersection.size() > 0) {
43
// overlapping.push_back(d);
44
// }
45
// }
46
47
// // If overlapping are found, add all overlapping to
48
// // the new domain and remove them from the domain list
49
// if (!overlapping.empty()) {
50
// for (auto& d : overlapping) {
51
// // merge the existing cluster in class_domain
52
// class_domain.insert(d.begin(), d.end());
53
// // Remove the old cluster from the list
54
// auto it = std::find(domains.begin(), domains.end(), d);
55
// if (it != domains.end()) {
56
// domains.erase(it);
57
// }
58
// }
59
// }
60
61
// domains.push_back(class_domain);
62
// }
63
64
// return domains;
65
// }
66
67
//-----------------------------------------------------------------------------
68
void
69
DalRegistry::update_class_domain_map
()
70
{
71
72
m_class_domain_map
.clear();
73
74
auto
domains =
m_confdb
.
find_class_domains
();
75
// TODO: keep a local copy of the domains
76
for
(
size_t
i(0); i < domains.size(); ++i) {
77
const
auto
& dom = domains[i];
78
for
(
const
auto
& class_name : dom) {
79
m_class_domain_map
[&conffwk::DalFactory::instance().get_known_class_name_ref(class_name)] = i;
80
TLOG_DEBUG
(9) <<
" - "
<< class_name <<
" : "
<< i;
81
}
82
}
83
}
84
85
//-----------------------------------------------------------------------------
86
void
87
DalRegistry::clear
()
88
{
89
for
(
const
auto
& [index, domain] :
m_cache_domains
) {
90
91
for
(
const
auto
& [uid, ptr] : domain.cache) {
92
delete
ptr;
93
}
94
}
95
96
m_class_domain_map
.clear();
97
}
98
99
//-----------------------------------------------------------------------------
100
DalObject
*
101
DalRegistry::get
(
ConfigObject
&
obj
,
bool
upcast_unregistered)
102
{
103
104
// Find the class domain of T
105
auto
it_dom =
m_class_domain_map
.find(&DalFactory::instance().get_known_class_name_ref(
obj
.class_name()));
106
107
// Class not known, this should not happen
108
if
(it_dom ==
m_class_domain_map
.end()) {
109
throw
dunedaq::conffwk::NotFound(
ERS_HERE
,
"class"
,
obj
.class_name().c_str());
110
}
111
112
auto
& domain =
m_cache_domains
[it_dom->second];
113
114
DalObject
*& result(domain.cache[
obj
.m_impl->m_id]);
115
if
(result ==
nullptr
) {
116
117
result = DalFactory::instance().make(*
this
,
obj
, upcast_unregistered);
118
119
}
else
if
(
obj
.m_impl != result->
p_obj
.
m_impl
) {
120
121
std::lock_guard<std::mutex> scoped_lock(result->
m_mutex
);
122
result->
set
(
obj
);
// update implementation object; to be used in case if the object is re-created
123
}
124
125
return
result;
126
}
127
128
//-----------------------------------------------------------------------------
129
std::vector<const DalObject*>
130
DalRegistry::get
(std::vector<ConfigObject>& objs,
bool
upcast_unregistered)
131
{
132
std::vector<const DalObject*> result;
133
134
for
(
auto
& i : objs)
135
if
(
DalObject
* o = this->
get
(i, upcast_unregistered))
136
result.push_back(o);
137
138
return
result;
139
}
140
141
//-----------------------------------------------------------------------------
142
void
143
DalRegistry::update
(
const
std::string& class_name,
144
const
std::vector<std::string>& modified,
145
const
std::vector<std::string>& removed,
146
const
std::vector<std::string>& created)
147
{
148
149
// Find the class domain of T
150
auto
it_dom =
m_class_domain_map
.find(&DalFactory::instance().get_known_class_name_ref(class_name));
151
152
// Class not known, this should not happen
153
if
(it_dom ==
m_class_domain_map
.end()) {
154
throw
dunedaq::conffwk::NotFound(
ERS_HERE
,
"class"
, class_name.c_str());
155
}
156
157
// get the correct cache domain
158
auto
& domain =
m_cache_domains
[it_dom->second];
159
160
for
(
const
auto
& [uid, ptr] : domain.cache) {
161
162
// Check if the ptr class is derived from class_name
163
m_confdb
.
is_superclass_of
(ptr->class_name(), class_name);
164
165
if
(!ptr)
166
continue
;
167
168
bool
update
= ((std::find(modified.begin(), modified.end(), ptr->UID()) != modified.end()) or
169
(std::find(removed.begin(), removed.end(), ptr->UID()) != removed.end()) or
170
(std::find(created.begin(), created.end(), ptr->UID()) != created.end()));
171
172
if
(!
update
)
173
continue
;
174
175
std::lock_guard<std::mutex> scoped_lock(domain.mutex);
176
ptr->p_was_read =
false
;
177
}
178
}
179
180
//-----------------------------------------------------------------------------
181
void
182
DalRegistry::unread_all
()
183
{
184
185
for
(
const
auto
& [dom_id, domain] :
m_cache_domains
) {
186
187
std::lock_guard<std::mutex> scoped_lock(domain.mutex);
188
189
for
(
const
auto
& [
id
, ptr] : domain.cache) {
190
ptr->p_was_read =
false
;
191
}
192
}
193
}
194
195
//-----------------------------------------------------------------------------
196
void
197
DalRegistry::_rename_object
(std::string class_name, std::string old_id, std::string new_id)
198
{
199
// Find the class domain of T
200
auto
it_dom =
m_class_domain_map
.find(&DalFactory::instance().get_known_class_name_ref(class_name));
201
202
// Class not known, this should not happen
203
if
(it_dom ==
m_class_domain_map
.end()) {
204
throw
dunedaq::conffwk::NotFound(
ERS_HERE
, class_name.c_str(), old_id.c_str());
205
}
206
207
auto
& domain =
m_cache_domains
[it_dom->second];
208
209
auto
it = domain.cache.find(old_id);
210
if
(it == domain.cache.end())
211
return
;
212
213
domain.cache[new_id] = it->second;
214
domain.cache.erase(it);
215
216
std::lock_guard<std::mutex> scoped_lock(it->second->m_mutex);
217
it->second->p_UID = new_id;
218
}
219
220
}
// namespace conffwk
221
}
// namespace dunedaq
DalObject.hpp
ERS_HERE
#define ERS_HERE
Definition
LocalContext.hpp:127
dunedaq::conffwk::ConfigObject
Represents database objects.
Definition
ConfigObject.hpp:54
dunedaq::conffwk::ConfigObject::m_impl
ConfigObjectImpl * m_impl
Definition
ConfigObject.hpp:593
dunedaq::conffwk::Configuration::find_class_domains
std::deque< std::set< std::string > > find_class_domains()
Definition
Configuration.cpp:647
dunedaq::conffwk::Configuration::is_superclass_of
bool is_superclass_of(const std::string &target, const std::string &source) noexcept
dunedaq::conffwk::DalObject
The base class for any generated DAL object.
Definition
DalObject.hpp:51
dunedaq::conffwk::DalObject::set
void set(const ConfigObject &o) noexcept
Definition
DalObject.hpp:218
dunedaq::conffwk::DalObject::m_mutex
std::mutex m_mutex
Used to protect changes of DAL object.
Definition
DalObject.hpp:100
dunedaq::conffwk::DalObject::p_obj
ConfigObject p_obj
Config object used by given template object.
Definition
DalObject.hpp:109
dunedaq::conffwk::DalRegistry::~DalRegistry
~DalRegistry()
Definition
DalRegistry.cpp:14
dunedaq::conffwk::DalRegistry::get
DalObject * get(ConfigObject &obj, bool upcast_unregistered=false)
Definition
DalRegistry.cpp:101
dunedaq::conffwk::DalRegistry::update
void update(const std::vector< std::string > &modified, const std::vector< std::string > &removed, const std::vector< std::string > &created)
Update cache of objects in case of modification.
Definition
DalRegistry.hxx:225
dunedaq::conffwk::DalRegistry::_rename_object
void _rename_object(std::string class_name, std::string old_id, std::string new_id)
Rename object of given template class (multi-thread unsafe).
Definition
DalRegistry.cpp:197
dunedaq::conffwk::DalRegistry::clear
void clear()
Clear the content of the registy.
Definition
DalRegistry.cpp:87
dunedaq::conffwk::DalRegistry::DalRegistry
DalRegistry(Configuration &confdb)
Construct a new Dal Registry object.
Definition
DalRegistry.cpp:8
dunedaq::conffwk::DalRegistry::unread_all
void unread_all()
Set the status of all objects in cache to unread.
Definition
DalRegistry.cpp:182
dunedaq::conffwk::DalRegistry::m_class_domain_map
conffwk::fmap< uint > m_class_domain_map
Definition
DalRegistry.hpp:232
dunedaq::conffwk::DalRegistry::update_class_domain_map
void update_class_domain_map()
Definition
DalRegistry.cpp:69
dunedaq::conffwk::DalRegistry::m_cache_domains
std::unordered_map< uint, DalDomain > m_cache_domains
Definition
DalRegistry.hpp:234
dunedaq::conffwk::DalRegistry::m_confdb
Configuration & m_confdb
Definition
DalRegistry.hpp:226
dunedaq::conffwk::DalRegistry::DalObject
friend class DalObject
Definition
DalRegistry.hpp:21
Schema.hpp
TLOG_DEBUG
#define TLOG_DEBUG(lvl,...)
Definition
Logging.hpp:116
conffwk.Configuration
Definition
Configuration.py:1
dunedaq::conffwk
Definition
test_circular_dependency.hpp:5
dunedaq
The DUNE-DAQ namespace.
Definition
cib_utilities.cpp:5
dunedaq::obj
msgpack::object obj
Definition
Serialization.hpp:252
Generated on
for DUNE-DAQ by
1.18.0