DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
Command.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
6#include "dbe/Command.hpp"
7#include "dbe/config_api_graph.hpp" // checked
8#include "dbe/config_api_set.hpp" // checked
10#include "dbe/confobject_desc.hpp" // checked
12#include "dbe/dbcontroller.hpp"
13#include "dbe/messenger.hpp"
14
16
17#include <QFileInfo>
18
19#include <algorithm>
20
21//------------------------------------------------------------------------------------------
24 std::vector<std::string> const& object_names_tolink,
25 QUuid const& src,
26 QUndoCommand* parent)
27 : onobject(object, parent, src)
28 , this_relation(relation)
29 , this_current_neighbors(dbe::config::api::graph::linked::through::relation<std::vector<tref>>(object, relation))
30{
31 try {
32 for (std::string const& oname : object_names_tolink) {
33 try {
34 this_target_neighbors.push_back(inner::dbcontroller::get({ oname, relation.p_type }));
35 } catch (daq::dbe::config_object_retrieval_result_is_null const& ex) {
36 // Actually there is no need to handle this error here ,
37 // since the object will not be added to the result list of references,
38 // and can be safely ignored
39 }
40 }
41 } catch (dunedaq::conffwk::Exception const& e) {
42 failed();
43 throw daq::dbe::ObjectChangeWasNotSuccessful(ERS_HERE, dbe::config::errors::parse(e));
44 }
45
46 setText(
47 QObject::tr("Relation %1 of object %2 was updated.").arg(this_relation.p_name.c_str()).arg(object.UID().c_str()));
48}
49//------------------------------------------------------------------------------------------
50
51//------------------------------------------------------------------------------------------
52void
54{
55 try {
56 if (redoable()) {
57 failed();
60 toggle();
61 }
62 } catch (dunedaq::conffwk::Exception const& e) {
63 throw daq::dbe::ObjectChangeWasNotSuccessful(ERS_HERE, config::errors::parse(e));
64 } catch (daq::dbe::config_object_retrieval_result_is_null const& ex) {
65 FAIL("Operation did not complete because a lookup in the underlying database failed", ex.what());
66 throw daq::dbe::ObjectChangeWasNotSuccessful(ERS_HERE, ex);
67 }
68}
69//------------------------------------------------------------------------------------------
70
71//------------------------------------------------------------------------------------------
72void
74{
75 try {
76 if (undoable()) {
77 failed();
80 toggle();
81 }
82 } catch (dunedaq::conffwk::Exception const& e) {
83 failed();
84 throw daq::dbe::ObjectChangeWasNotSuccessful(ERS_HERE, dbe::config::errors::parse(e));
85 } catch (daq::dbe::config_object_retrieval_result_is_null const& ex) {
86 FAIL("Operation did not complete because a lookup in the underlying database failed", ex.what());
87 throw daq::dbe::ObjectChangeWasNotSuccessful(ERS_HERE, ex);
88 }
89}
90//------------------------------------------------------------------------------------------
91
92//------------------------------------------------------------------------------------------
93dbe::actions::file::add::add(std::string const& db_file,
94 std::string const& include_file,
95 QUuid const& src,
96 QUndoCommand* parent)
97 : state(parent, src)
98 , m_db_file(db_file)
99 , m_include_file(include_file)
100{
101 setText(QObject::tr("Add Include File %1 to %2")
102 .arg(QFileInfo(QString(m_include_file.c_str())).fileName())
103 .arg(QFileInfo(QString(m_db_file.c_str())).fileName()));
104}
105//------------------------------------------------------------------------------------------
106
107//------------------------------------------------------------------------------------------
108void
110{
111 try {
112 if (undoable()) {
114 }
115 } catch (dunedaq::conffwk::Exception const& e) {
116 failed();
117 throw daq::dbe::DatabaseChangeNotSuccessful(ERS_HERE, dbe::config::errors::parse(e));
118 }
119}
120//------------------------------------------------------------------------------------------
121
122//------------------------------------------------------------------------------------------
123void
125{
126 try {
127 if (redoable()) {
128 failed();
130 toggle();
131 }
132 } catch (dunedaq::conffwk::Exception const& e) {
133 throw daq::dbe::DatabaseChangeNotSuccessful(ERS_HERE, dbe::config::errors::parse(e));
134 }
135}
136//------------------------------------------------------------------------------------------
137
138//------------------------------------------------------------------------------------------
140 std::string& include_file,
141 QUuid const& src,
142 QUndoCommand* parent)
143 : state(parent, src)
144 , m_db_file(db_file)
145 , m_include_file(include_file)
146{
147 setText(QObject::tr("Remove Include File %1 from %2")
148 .arg(QFileInfo(QString(m_include_file.c_str())).fileName())
149 .arg(QFileInfo(QString(m_db_file.c_str())).fileName()));
150}
151
152void
154{
155 try {
156 if (undoable()) {
157 failed();
159 toggle();
160 }
161 } catch (dunedaq::conffwk::Exception const& e) {
162 throw daq::dbe::DatabaseChangeNotSuccessful(ERS_HERE, dbe::config::errors::parse(e));
163 }
164}
165
166void
168{
169 try {
170 if (redoable()) {
171 failed();
173 toggle();
174 }
175 } catch (dunedaq::conffwk::Exception const& e) {
176 throw daq::dbe::DatabaseChangeNotSuccessful(ERS_HERE, dbe::config::errors::parse(e));
177 }
178}
179//------------------------------------------------------------------------------------------
180
181//------------------------------------------------------------------------------------------
182dbe::actions::object::create::create(dbe::t_config_object_preimage const& img, QUuid const& src, QUndoCommand* parent)
183 : state(parent, src)
184 , this_object_key(img)
185{
186 setText(QObject::tr("Creation of : Object %2@%1 ")
187 .arg(this_object_key.ref.this_class.c_str())
188 .arg(this_object_key.ref.this_name.c_str()));
189}
190
191void
193{
194 try {
195 if (undoable()) {
196 failed();
197 // notify for the objects that have been actually removed
200 };
201
204 toggle();
205 }
206 } catch (dunedaq::conffwk::Exception const& e) {
207 throw daq::dbe::ObjectChangeWasNotSuccessful(ERS_HERE, dbe::config::errors::parse(e));
208 } catch (daq::dbe::config_object_retrieval_result_is_null const& e) {
209 throw daq::dbe::ObjectChangeWasNotSuccessful(ERS_HERE, e);
210 }
211}
212
213void
215{
216 try {
217 if (redoable()) {
218 failed();
221 toggle();
222 }
223 } catch (dunedaq::conffwk::Exception const& e) {
224 throw daq::dbe::ObjectChangeWasNotSuccessful(ERS_HERE, dbe::config::errors::parse(e));
225 }
226}
227//------------------------------------------------------------------------------------------
228
229//------------------------------------------------------------------------------------------
230dbe::actions::object::remove::remove(tref anobject, QUuid const& uuid, QUndoCommand* parent)
231 : onobject(anobject, parent, uuid)
232{
233 setText(QObject::tr("Delete object of class %1 with ID %2")
234 .arg((this->checkedref().class_name()).c_str())
235 .arg((this->checkedref().UID()).c_str()));
236}
237
239
240void
242{
243 try {
244 if (undoable()) {
245 failed();
246 gref::config_action_notifiable creation = [&](dref obj) {
248 };
249
251 toggle();
252 }
253 } catch (dunedaq::conffwk::Exception const& e) {
254 throw daq::dbe::ObjectChangeWasNotSuccessful(ERS_HERE, dbe::config::errors::parse(e));
255 } catch (daq::dbe::config_object_retrieval_result_is_null const& ex) {
256 FAIL("Operation did not complete because a lookup in the underlying database failed", ex.what());
257 throw daq::dbe::ObjectChangeWasNotSuccessful(ERS_HERE, ex);
258 }
259}
260
261void
263{
264 try {
265 if (redoable() and not checkedref().is_null()) {
266 failed();
267 // notify for the objects that have been actually removed
268 gref::config_action_notifiable deletion = [&](dref const obj) {
270 };
271
274 toggle();
275 }
276 } catch (dunedaq::conffwk::Exception const& e) {
277 throw daq::dbe::ObjectChangeWasNotSuccessful(ERS_HERE, dbe::config::errors::parse(e));
278 } catch (daq::dbe::config_object_retrieval_result_is_null const& ex) {
279 FAIL("Operation did not complete because a lookup in the underlying database failed", ex.what());
280 throw daq::dbe::ObjectChangeWasNotSuccessful(ERS_HERE, ex);
281 }
282}
283
284//------------------------------------------------------------------------------------------
285dbe::actions::object::rename::rename(tref object, std::string const& Id, QUuid const& src, QUndoCommand* parent)
286 : onobject(object, parent, src)
287 , oldname(this->checkedref().UID())
288 , newname(Id)
289{
290 setText(QObject::tr("Object changed ID from %1 to %2").arg(this->checkedref().UID().c_str()).arg(newname.c_str()));
291}
292//------------------------------------------------------------------------------------------
293
294//------------------------------------------------------------------------------------------
295void
297{
298 try {
299 if (redoable()) {
300 failed();
301 dref object_before_change(checkedref());
303
304 confaccessor::ref().force_emit_object_renamed(source().toString(), object_before_change);
305
306 std::vector<tref> tonotify{ this->checkedref().referenced_by("*", false) };
307
308 std::for_each(tonotify.begin(), tonotify.end(), [&](tref const& x) {
309 confaccessor::ref().force_emit_object_changed(source().toString(), x);
310 });
311 toggle();
312 }
313 } catch (dunedaq::conffwk::Exception const& e) {
314 throw daq::dbe::ObjectChangeWasNotSuccessful(ERS_HERE, dbe::config::errors::parse(e));
315 } catch (daq::dbe::config_object_retrieval_result_is_null const& e) {
316 FAIL("Operation did not complete because a lookup in the underlying database failed", e.what());
317 throw daq::dbe::ObjectChangeWasNotSuccessful(ERS_HERE, e);
318 }
319}
320//------------------------------------------------------------------------------------------
321
322//------------------------------------------------------------------------------------------
323void
325{
326 try {
327 if (undoable()) {
328 failed();
329 dref object_before_rename(checkedref());
331 confaccessor::ref().force_emit_object_renamed(source().toString(), object_before_rename);
332
333 std::vector<tref> tonotify = checkedref().referenced_by("*", false);
334
335 std::for_each(tonotify.begin(), tonotify.end(), [&](tref const& x) {
336 confaccessor::ref().force_emit_object_changed(source().toString(), x);
337 });
338 toggle();
339 }
340 } catch (dunedaq::conffwk::Exception const& e) {
341 throw daq::dbe::ObjectChangeWasNotSuccessful(ERS_HERE, dbe::config::errors::parse(e));
342 } catch (daq::dbe::config_object_retrieval_result_is_null const& e) {
343 FAIL("Operation did not complete because a lookup in the underlying database failed", e.what());
344 throw daq::dbe::ObjectChangeWasNotSuccessful(ERS_HERE, e);
345 }
346}
347//------------------------------------------------------------------------------------------
348
349//------------------------------------------------------------------------------------------
350dbe::actions::object::move::move(tref object, std::string const& filename, QUuid const& src, QUndoCommand* parent)
351 : onobject(object, parent, src)
352 , source_file(this->checkedref().contained_in())
354{
355 setText(QObject::tr("Object changed from file %1 to %2").arg(source_file.c_str()).arg(destination_file.c_str()));
356}
357//------------------------------------------------------------------------------------------
358
359//------------------------------------------------------------------------------------------
361//------------------------------------------------------------------------------------------
362
363//------------------------------------------------------------------------------------------
364void
366{
367 try {
368 if (redoable()) {
369 failed();
371 emit confaccessor::ref().force_emit_object_changed(source().toString(), this -> checkedref());
372 toggle();
373 }
374 } catch (dunedaq::conffwk::Exception const& e) {
375 throw daq::dbe::ObjectChangeWasNotSuccessful(ERS_HERE, dbe::config::errors::parse(e));
376 } catch (daq::dbe::config_object_retrieval_result_is_null const& e) {
377 FAIL("Operation did not complete because a lookup in the underlying database failed", e.what());
378 throw daq::dbe::ObjectChangeWasNotSuccessful(ERS_HERE, e);
379 }
380}
381//------------------------------------------------------------------------------------------
382
383//------------------------------------------------------------------------------------------
384void
386{
387 try {
388 if (undoable()) {
389 failed();
391 toggle();
392 }
393 } catch (dunedaq::conffwk::Exception const& e) {
394 throw daq::dbe::ObjectChangeWasNotSuccessful(ERS_HERE, dbe::config::errors::parse(e));
395 } catch (daq::dbe::config_object_retrieval_result_is_null const& e) {
396 FAIL("Operation did not complete because a lookup in the underlying database failed", e.what());
397 throw daq::dbe::ObjectChangeWasNotSuccessful(ERS_HERE, e);
398 }
399}
400//------------------------------------------------------------------------------------------
401
402//------------------------------------------------------------------------------------------
403dbe::actions::onobject::onobject(tref obj, QUndoCommand* parent, QUuid const& uuid)
404 : dbe::actions::state(parent, uuid)
405 , this_object(obj)
406{
407}
408//------------------------------------------------------------------------------------------
409
410//------------------------------------------------------------------------------------------
413{
414 return this_object.ref();
415}
416//------------------------------------------------------------------------------------------
417
418//------------------------------------------------------------------------------------------
419dbe::actions::state::state(QUndoCommand* parent, QUuid const& uuid)
420 : QUndoCommand(parent)
421 , uuid(uuid)
422 , rewind(true)
423 , forward(true)
424 , invalid(false)
425{
426}
427
428void
430{
431 invalid = not invalid;
432 rewind = not rewind;
433 forward = not forward;
434}
435
436void
438{
439 invalid = true;
440 rewind = false;
441 forward = false;
442}
443
444bool
446{
447 return not invalid;
448}
449
450void
455
456void
461
462bool
464{
465 return rewind and not invalid;
466}
467
468bool
470{
471 return forward and not invalid;
472}
473
474QUuid const&
476{
477 return uuid;
478}
479
480bool
482{
483 return redoable();
484}
485
486bool
488{
489 return undoable();
490}
491
492void
494{
495 // TODO evaluate: is this command that reloads the configuration object from the database really needed?
496}
497
498//------------------------------------------------------------------------------------------
#define ERS_HERE
add(std::string const &db_file, std::string const &include_file, QUuid const &src=0, QUndoCommand *parent=0)
Definition Command.cpp:93
std::string m_include_file
Definition Command.hpp:175
remove(std::string &db_file, std::string &include_file, QUuid const &src=0, QUndoCommand *parent=0)
Definition Command.cpp:139
changerefs(tref object, dunedaq::conffwk::relationship_t const &relation, std::vector< std::string > const &object_names_tolink, QUuid const &src=0, QUndoCommand *Parent=nullptr)
Definition Command.cpp:22
std::vector< tref > this_target_neighbors
Definition Command.hpp:141
std::vector< tref > this_current_neighbors
Definition Command.hpp:140
dunedaq::conffwk::relationship_t this_relation
Definition Command.hpp:139
create(dbe::t_config_object_preimage const &img, QUuid const &src=0, QUndoCommand *parent=0)
Definition Command.cpp:182
dbe::t_config_object_preimage this_object_key
Definition Command.hpp:94
move(tref ObjectChanged, std::string const &File, QUuid const &src=0, QUndoCommand *parent=nullptr)
Definition Command.cpp:350
remove(tref item, QUuid const &uuid=0, QUndoCommand *parent=0)
Definition Command.cpp:230
rename(tref object, std::string const &Id, QUuid const &src=0, QUndoCommand *parent=nullptr)
Definition Command.cpp:285
tref checkedref() const
Definition Command.cpp:412
onobject(tref obj, QUndoCommand *parent=nullptr, QUuid const &uuid=0)
Definition Command.cpp:403
void setundoable(bool s=true) const
Definition Command.cpp:451
bool canRedo() const
Definition Command.cpp:481
void reload() const
Definition Command.cpp:493
bool undoable() const
Definition Command.cpp:463
bool canUndo() const
Definition Command.cpp:487
bool isvalid() const
Definition Command.cpp:445
void setredoable(bool s=true) const
Definition Command.cpp:457
void failed() const
Definition Command.cpp:437
bool redoable() const
Definition Command.cpp:469
state(QUndoCommand *parent=nullptr, QUuid const &uuid=0)
Definition Command.cpp:419
QUuid const & source() const
Definition Command.cpp:475
QUuid const uuid
Definition Command.hpp:34
void force_emit_object_created(QString const &, dref const)
void removefile(std::string const &db, std::string const &fn)
void force_emit_object_deleted(QString const &, dref const)
void force_emit_object_renamed(QString const &, dref const)
void force_emit_object_changed(QString const &, dref const)
static confaccessor & ref()
void addfile(std::string const &db, std::string const &fn)
dunedaq::conffwk::ConfigObject & ref(bool check_null=true) const
static configobject::gref< T > delete_object_request(configobject::tref const &obj)
static configobject::tref move_object_request(configobject::tref objref, std::string const &destfile)
static configobject::tref get(dbe::cokey const &desc)
static configobject::tref rename_object_request(configobject::tref objref, std::string const &newname)
static configobject::tref create_object_request(dbe::t_config_object_preimage const &rep)
conffwk entry point
#define FAIL(...)
void relation(dbe::inner::configobject::tref src, dunedaq::conffwk::relationship_t const &edge, std::vector< dbe::inner::configobject::tref > const &targets)
std::string const parse(ers::Issue const &)
Include QT Headers.
inner::configobject::tref tref
Definition tref.hpp:36
config_object_preimage< std::string > t_config_object_preimage
config_object_description dref