DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
confaccessor.cpp
Go to the documentation of this file.
1// DUNE DAQ modification notice:
2// This file has been modified from the original ATLAS dbe source for the DUNE DAQ project.
3// Fork baseline commit: dbe-02-12-17 (2022-05-12).
4// Renamed since fork: no.
5
8#include "dbe/Exceptions.hpp"
9#include "dbe/Sorting.hpp"
10#include "dbe/dbaccessor.hpp"
11#include "dbe/messenger.hpp"
12
14#include "dbe/change_enum.hpp"
15#include "dbe/config_api.hpp"
17#include "dbe/version.hpp"
18
20
21#include <QFileInfo>
22#include <QStringList>
23#include <QVector>
24
25#include <functional>
26#include <memory>
27#include <stack>
28#include <unordered_set>
29#include <vector>
30
31using namespace dunedaq::conffwk;
32
34
35//------------------------------------------------------------------------------------------
38{
39 static confaccessor me;
40 return me;
41}
42
43//------------------------------------------------------------------------------------------
44
45//------------------------------------------------------------------------------------------
56
66
67//------------------------------------------------------------------------------------------
68
69//------------------------------------------------------------------------------------------
70bool
72{
74 return ref().this_change_enabled;
75}
76
77void
83
84void
90
91//------------------------------------------------------------------------------------------
92
93//------------------------------------------------------------------------------------------
94void
96{
98 emit object_created(src, obj);
99}
100
101void
103{
104 t_lock l(force_mut);
105 emit object_renamed(src, obj);
106}
107
108void
110{
111 t_lock l(force_mut);
112 emit object_deleted(src, obj);
113}
114
115void
117{
118 t_lock l(force_mut);
119 emit object_changed(src, obj);
120}
121
122//------------------------------------------------------------------------------------------
123
124//------------------------------------------------------------------------------------------
125void
126dbe::confaccessor::GetFileCache(QList<QStringList>& FileCache)
127{
128 IncludedFileCache = FileCache;
129}
130
131//------------------------------------------------------------------------------------------
132
133//------------------------------------------------------------------------------------------
134QString
136{
137 return ref().this_dblocation;
138}
139
140QString
142{
143 return ref().this_resource_location;
144}
145
146//------------------------------------------------------------------------------------------
147
148//------------------------------------------------------------------------------------------
151{
152 static cptr<datahandler> r(ref().editconfig);
153 return r;
154}
155
162
169
170//------------------------------------------------------------------------------------------
171
172//------------------------------------------------------------------------------------------
173int
175{
176 return ref().this_total_objects;
177}
178
179void
181{
182 ref().this_total_objects += i;
183}
184
185void
187{
188 ref().this_total_objects = i;
189}
190
191//------------------------------------------------------------------------------------------
192
193//------------------------------------------------------------------------------------------
194
195template<>
196void
198{
199 static QString const implementation("oksconflibs");
200
201 this_dblocation = location;
202 this_resource_location = implementation + ":" + location;
203
204 setenabled();
205}
206
207template<>
208void
210{
211 this_dblocation = location;
212 static QString const implementation("roksconflibs");
213 this_resource_location = implementation + ":" + location;
214 t_lock l(this_change_enabled_mutex);
215 this_change_enabled = true;
216}
217
218template<>
219void
221{
222 static QString const implementation("rdbconfig");
223 this_resource_location = implementation + ":" + location;
224 this_dblocation = this_resource_location;
225 t_lock l(this_change_enabled_mutex);
226 this_change_enabled = true;
227}
228
229void
230dbe::confaccessor::setdbinfo(QString const& location, dbinfo const itype)
231{
232 switch (itype) {
233
234 case dbinfo::oks:
235 ref().set_dbinfo<dbinfo::oks>(location);
236 break;
237
238 case dbinfo::roks:
239 ref().set_dbinfo<dbinfo::roks>(location);
240 break;
241
242 case dbinfo::rdb:
243 ref().set_dbinfo<dbinfo::rdb>(location);
244 break;
245
246 default:
247 ref().setenabled();
248 break;
249 }
250}
251
252void
253dbe::confaccessor::setdblocation(QString const& Implementation)
254{
255 ref().this_resource_location = Implementation;
256}
257
258bool
260{
261 return dbaccessor::dbptr().get() != nullptr;
262}
263
264//------------------------------------------------------------------------------------------
265
266//------------------------------------------------------------------------------------------
267bool
269{
270 try {
271 if (not fn.endsWith(".schema.xml")) {
272 return dbaccessor::dbptr()->is_writable(fn.toStdString());
273 }
274 } catch (dunedaq::conffwk::Generic const& ex) {
275 ERROR("Not possible to operate on file", dbe::config::errors::parse(ex), "\n\nCheck filename:", fn.toStdString());
276 }
277
278 return false;
279}
280
281//------------------------------------------------------------------------------------------
282void
284{
285 if (ref().get_commands().get()) {
286 ref().get_commands()->clear();
287 t_internal_changes_stack cleared{};
288 ref().get_internal_change_stack()->swap(cleared);
289 }
290}
291
292//------------------------------------------------------------------------------------------
293
294//------------------------------------------------------------------------------------------
295void
297{
298 dbaccessor::dbptr()->abort();
299}
300
301std::list<std::string>
303{
304 std::list<std::string> dbs;
305 dbaccessor::dbptr()->get_updated_dbs(dbs);
306 return dbs;
307}
308//------------------------------------------------------------------------------------------
309
310//------------------------------------------------------------------------------------------
311bool
312dbe::confaccessor::load(bool subscribeToChanges)
313{
314 try {
316
317 if (dbholder::database == nullptr) {
319
320 if (subscribeToChanges == true) {
323 reinterpret_cast<void*>(dbholder::database));
324 }
325 } else {
327 delete dbholder::database;
329 }
330
331 dbholder::database->prefetch_all_data();
332
334 return true;
335 } catch (dunedaq::conffwk::Exception const& e) {
336 FAIL("Database loading failed", dbe::config::errors::parse(e).c_str());
337 return false;
338 }
339}
340
341std::list<std::string>
342dbe::confaccessor::save(const QString& CommitMessage)
343{
344 try {
345 std::list<std::string> tobecommited{};
346
347 if (ref().is_database_loaded()) {
348 dbaccessor::dbptr()->get_updated_dbs(tobecommited);
349 dbaccessor::dbptr()->commit(CommitMessage.toStdString());
350 confaccessor::ref().db_committed(tobecommited, CommitMessage.toStdString());
351 }
352
353 return tobecommited;
354 } catch (dunedaq::conffwk::Exception const& e) {
355 // throw daq::dbe::CouldNotCommitChanges ( ERS_HERE, dbe::config::errors::parse ( e ) );
356 throw daq::dbe::CouldNotCommitChanges(ERS_HERE, "confaccessor", e);
357 }
358}
359
360//------------------------------------------------------------------------------------------
361
362//------------------------------------------------------------------------------------------
363void
365{
366 QString DUNEDAQ_DB_PATH = getenv("DUNEDAQ_DB_PATH");
367 QString GUI_DATA = getenv("OKS_GUI_INIT_DATA");
368
369 QStringList CONFIG_DATABASE = GUI_DATA.split(":", Qt::SkipEmptyParts);
370 QStringList DUNEDAQ_DB_PATH_SPLIT = DUNEDAQ_DB_PATH.split(":", Qt::SkipEmptyParts);
371
372 // We need to read the current configuration ( to retrieve parameters affecting dbe )
373
374 std::vector<std::string> full_path_names;
375
376 for (QString& FileName : CONFIG_DATABASE) {
377
378 for (QString& PATH : DUNEDAQ_DB_PATH_SPLIT) {
379 QFileInfo CheckFile(PATH + "/" + FileName);
380
381 if (CheckFile.exists() and CheckFile.isFile()) {
382 QString fullpathname = PATH + "/" + FileName;
383 full_path_names.push_back(fullpathname.toStdString());
384 }
385 }
386 }
387
388 confaccessor::ref().coreconfig = new ui::config::info(full_path_names);
389}
390
391QList<QStringList>
396
397//------------------------------------------------------------------------------------------
398
399//------------------------------------------------------------------------------------------
400void
401dbe::confaccessor::addfile(std::string const& db, std::string const& fn)
402{
403 if (not enabled()) {
404 throw daq::dbe::ChangeNotAllowed(ERS_HERE);
405 }
406
407 dbaccessor::dbptr()->add_include(db, fn);
408 emit IncludeFileDone();
409}
410
411void
412dbe::confaccessor::removefile(std::string const& db, std::string const& fn)
413{
414 if (not enabled()) {
415 throw daq::dbe::ChangeNotAllowed(ERS_HERE);
416 }
417
418 dbaccessor::dbptr()->remove_include(db, fn);
419 emit RemoveFileDone();
420}
421
422//------------------------------------------------------------------------------------------
423
424//------------------------------------------------------------------------------------------
425void
426dbe::confaccessor::CallbackFunction(std::vector<ConfigurationChange*> const& changes, void* parameter)
427{
428 dbe::confaccessor::ref().docallback(changes, parameter);
429}
430
431void
432dbe::confaccessor::docallback(std::vector<ConfigurationChange*> const& changes, void* parameter)
433{
434 Q_UNUSED(parameter);
435
437 external_change_stack.clear();
438
439 for (ConfigurationChange* Change : changes) {
440 const auto& cl = Change->get_class_name();
441 const auto& mod = Change->get_modified_objs();
442 const auto& cre = Change->get_created_objs();
443 const auto& rem = Change->get_removed_objs();
444
445 external_change_stack.push_back({ cl, mod, cre, rem });
446 }
447
449}
450
451//------------------------------------------------------------------------------------------
452
453//------------------------------------------------------------------------------------------
454void
456{
457 if (dbaccessor::dbptr().get() && ref().CallId != nullptr) {
458 dbaccessor::dbptr()->unsubscribe(ref().CallId);
459 }
460}
461
468
469//------------------------------------------------------------------------------------------
#define ERS_HERE
Definition cptr.hpp:56
cptr(T *p)
Definition cptr.hpp:63
T * get()
Definition cptr.hpp:87
std::lock_guard< t_mutex > t_lock
static int get_total_objects()
datahandler * editconfig
QList< QStringList > IncludedFileCache
void force_emit_object_created(QString const &, dref const)
static cptr< datahandler > gethandler()
cptr< t_internal_changes_stack > t_internal_changes_stack_cptr
void GetFileCache(QList< QStringList > &FileCache)
void object_created(QString const &source, dref const &obj)
static void setdblocation(const QString &Implementation)
void removefile(std::string const &db, std::string const &fn)
static t_undo_stack_cptr get_commands()
static void CallbackFunction(const std::vector< dunedaq::conffwk::ConfigurationChange * > &changes, void *parameter)
static void increase_total_objects(int const i)
static bool is_database_loaded()
cptr< t_undo_stack > t_undo_stack_cptr
void ExternalChangesAccepted()
static void unsubscribe()
t_external_changes_stack external_change_stack
static std::list< std::string > uncommitted_files()
std::stack< t_internal_change, std::vector< t_internal_change > > t_internal_changes_stack
void db_committed(const std::list< std::string > &files, const std::string &msg)
t_undo_stack * sequenced_command_stack
std::shared_ptr< t_internal_changes_stack > internal_change_stack
static bool enabled()
void force_emit_object_deleted(QString const &, dref const)
QList< QStringList > GetIncludedFileCache() const
static void abort()
static cptr< ui::config::info > guiconfig()
static void set_total_objects(int const i)
ui::config::info * coreconfig
static void init()
static void clear_commands()
void force_emit_object_renamed(QString const &, dref const)
void force_emit_object_changed(QString const &, dref const)
void object_deleted(QString const &source, dref const &obj)
void object_renamed(QString const &source, dref const &obj)
static bool check_file_rw(const QString &FileName)
void object_changed(QString const &source, dref const &obj)
static QString dbfullname()
static t_internal_changes_stack_cptr get_internal_change_stack()
static bool load(bool subscribeToChanges=true)
QString this_resource_location
t_mutex this_change_enabled_mutex
static std::list< std::string > save(QString const &)
void docallback(std::vector< dunedaq::conffwk::ConfigurationChange * > const &changes, void *parameter)
void set_dbinfo(QString const &p)
static void setdbinfo(QString const &location, dbinfo const itype=dbinfo::oks)
static confaccessor & ref()
dunedaq::conffwk::Configuration::CallbackId CallId
void addfile(std::string const &db, std::string const &fn)
static QString db_implementation_name()
static cptr< dunedaq::conffwk::Configuration > dbptr()
static cptr< dunedaq::conffwk::Configuration > database_concurrent_ptr
dbe::types::common::type_lock t_lock
static dunedaq::conffwk::Configuration * database
static dbe::types::common::type_mutex database_lock
Describes changes inside a class returned by the notification mechanism.
Definition Change.hpp:43
char const *const dbe_lib_internal_version
conffwk entry point
#define ERROR(...)
Definition messenger.hpp:90
#define FAIL(...)
std::string const parse(ers::Issue const &)
dbinfo
Definition dbinfo.hpp:19
config_object_description dref
msgpack::object obj
#define dbe_compiled_version
Definition version.hpp:22