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_set.hpp" // checked
8#include "dbe/config_api_graph.hpp" // checked
9#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//------------------------------------------------------------------------------------------
23 tref object, dunedaq::conffwk::relationship_t const & relation,
24 std::vector<std::string> const & object_names_tolink, QUuid const & src,
25 QUndoCommand * parent )
26 : onobject ( object, parent, src ),
27 this_relation ( relation ),
29 dbe::config::api::graph::linked::through::relation<std::vector<tref>> ( object, relation ) )
30{
31 try
32 {
33 for ( std::string const & oname : object_names_tolink )
34 {
35 try
36 {
38 { oname, relation.p_type } ) );
39 }
40 catch ( daq::dbe::config_object_retrieval_result_is_null const & ex )
41 {
42 // Actually there is no need to handle this error here ,
43 // since the object will not be added to the result list of references,
44 // and can be safely ignored
45 }
46 }
47 }
48 catch ( dunedaq::conffwk::Exception const & e )
49 {
50 failed();
51 throw daq::dbe::ObjectChangeWasNotSuccessful ( ERS_HERE, dbe::config::errors::parse ( e ) );
52 }
53
54 setText (
55 QObject::tr ( "Relation %1 of object %2 was updated." ).arg (
56 this_relation.p_name.c_str() ).arg ( object.UID().c_str() ) );
57}
58//------------------------------------------------------------------------------------------
59
60//------------------------------------------------------------------------------------------
62{
63 try
64 {
65 if ( redoable() )
66 {
67 failed();
71 toggle();
72 }
73 }
74 catch ( dunedaq::conffwk::Exception const & e )
75 {
76 throw daq::dbe::ObjectChangeWasNotSuccessful ( ERS_HERE, config::errors::parse ( e ) );
77 }
78 catch ( daq::dbe::config_object_retrieval_result_is_null const & ex )
79 {
80 FAIL ( "Operation did not complete because a lookup in the underlying database failed",
81 ex.what() );
82 throw daq::dbe::ObjectChangeWasNotSuccessful ( ERS_HERE, ex );
83 }
84
85}
86//------------------------------------------------------------------------------------------
87
88//------------------------------------------------------------------------------------------
90{
91 try
92 {
93 if ( undoable() )
94 {
95 failed();
99 toggle();
100 }
101 }
102 catch ( dunedaq::conffwk::Exception const & e )
103 {
104 failed();
105 throw daq::dbe::ObjectChangeWasNotSuccessful ( ERS_HERE, dbe::config::errors::parse ( e ) );
106 }
107 catch ( daq::dbe::config_object_retrieval_result_is_null const & ex )
108 {
109 FAIL ( "Operation did not complete because a lookup in the underlying database failed",
110 ex.what() );
111 throw daq::dbe::ObjectChangeWasNotSuccessful ( ERS_HERE, ex );
112 }
113
114}
115//------------------------------------------------------------------------------------------
116
117//------------------------------------------------------------------------------------------
118dbe::actions::file::add::add ( std::string const & db_file,
119 std::string const & include_file,
120 QUuid const & src, QUndoCommand * parent )
121 : state ( parent, src ),
122 m_db_file ( db_file ),
123 m_include_file ( include_file )
124{
125 setText (
126 QObject::tr ( "Add Include File %1 to %2" ).arg (
127 QFileInfo ( QString ( m_include_file.c_str() ) ).fileName() ).arg (
128 QFileInfo ( QString ( m_db_file.c_str() ) ).fileName() ) );
129}
130//------------------------------------------------------------------------------------------
131
132//------------------------------------------------------------------------------------------
134{
135 try
136 {
137 if ( undoable() )
138 {
140 }
141 }
142 catch ( dunedaq::conffwk::Exception const & e )
143 {
144 failed();
145 throw daq::dbe::DatabaseChangeNotSuccessful ( ERS_HERE, dbe::config::errors::parse ( e ) );
146 }
147}
148//------------------------------------------------------------------------------------------
149
150//------------------------------------------------------------------------------------------
152{
153 try
154 {
155 if ( redoable() )
156 {
157 failed();
159 toggle();
160 }
161 }
162 catch ( dunedaq::conffwk::Exception const & e )
163 {
164 throw daq::dbe::DatabaseChangeNotSuccessful ( ERS_HERE, dbe::config::errors::parse ( e ) );
165 }
166}
167//------------------------------------------------------------------------------------------
168
169//------------------------------------------------------------------------------------------
170dbe::actions::file::remove::remove ( std::string & db_file, std::string & include_file,
171 QUuid const & src, QUndoCommand * parent )
172 : state ( parent, src ),
173 m_db_file ( db_file ),
174 m_include_file ( include_file )
175{
176 setText (
177 QObject::tr ( "Remove Include File %1 to %2" ).arg (
178 QFileInfo ( QString ( m_include_file.c_str() ) ).fileName() ).arg (
179 QFileInfo ( QString ( m_db_file.c_str() ) ).fileName() ) );
180}
181
183{
184 try
185 {
186 if ( undoable() )
187 {
188 failed();
190 toggle();
191 }
192 }
193 catch ( dunedaq::conffwk::Exception const & e )
194 {
195 throw daq::dbe::DatabaseChangeNotSuccessful ( ERS_HERE, dbe::config::errors::parse ( e ) );
196 }
197}
198
200{
201 try
202 {
203 if ( redoable() )
204 {
205 failed();
207 toggle();
208 }
209 }
210 catch ( dunedaq::conffwk::Exception const & e )
211 {
212 throw daq::dbe::DatabaseChangeNotSuccessful ( ERS_HERE, dbe::config::errors::parse ( e ) );
213 }
214}
215//------------------------------------------------------------------------------------------
216
217//------------------------------------------------------------------------------------------
219 QUuid const & src, QUndoCommand * parent )
220 : state ( parent, src ),
221 this_object_key ( img )
222{
223 setText (
224 QObject::tr ( "Creation of : Object %2@%1 " ).arg ( this_object_key.ref.this_class.c_str() )
225 .arg ( this_object_key.ref.this_name.c_str() ) );
226}
227
229{
230 try
231 {
232 if ( undoable() )
233 {
234 failed();
235 // notify for the objects that have been actually removed
237 [&] ( dref const obj )
238 {
239 confaccessor::ref().force_emit_object_deleted ( source().toString(), obj );
240 };
241
243 inner::dbcontroller::get ( this_object_key.ref ), deletion );
244 toggle();
245 }
246 }
247 catch ( dunedaq::conffwk::Exception const & e )
248 {
249 throw daq::dbe::ObjectChangeWasNotSuccessful ( ERS_HERE, dbe::config::errors::parse ( e ) );
250 }
251 catch ( daq::dbe::config_object_retrieval_result_is_null const & e )
252 {
253 throw daq::dbe::ObjectChangeWasNotSuccessful ( ERS_HERE, e );
254 }
255}
256
258{
259 try
260 {
261 if ( redoable() )
262 {
263 failed();
266 source().toString(), inner::dbcontroller::get ( this_object_key.ref ) );
267 toggle();
268 }
269 }
270 catch ( dunedaq::conffwk::Exception const & e )
271 {
272 throw daq::dbe::ObjectChangeWasNotSuccessful ( ERS_HERE, dbe::config::errors::parse ( e ) );
273 }
274}
275//------------------------------------------------------------------------------------------
276
277//------------------------------------------------------------------------------------------
279 QUndoCommand * parent )
280 : onobject ( anobject, parent, uuid )
281{
282 setText (
283 QObject::tr ( "Delete object of class %1 with ID %2" ).arg (
284 ( this->checkedref().class_name() ).c_str() ).arg (
285 ( this->checkedref().UID() ).c_str() ) );
286}
287
291
293{
294 try
295 {
296 if ( undoable() )
297 {
298 failed();
299 gref::config_action_notifiable creation = [&] ( dref obj )
300 {
301 confaccessor::ref().force_emit_object_created ( source().toString(), obj );
302 };
303
305 toggle();
306 }
307 }
308 catch ( dunedaq::conffwk::Exception const & e )
309 {
310 throw daq::dbe::ObjectChangeWasNotSuccessful ( ERS_HERE, dbe::config::errors::parse ( e ) );
311 }
312 catch ( daq::dbe::config_object_retrieval_result_is_null const & ex )
313 {
314 FAIL ( "Operation did not complete because a lookup in the underlying database failed",
315 ex.what() );
316 throw daq::dbe::ObjectChangeWasNotSuccessful ( ERS_HERE, ex );
317 }
318
319}
320
322{
323 try
324 {
325 if ( redoable() and not checkedref().is_null() )
326 {
327 failed();
328 // notify for the objects that have been actually removed
329 gref::config_action_notifiable deletion = [&] ( dref const obj )
330 {
331 confaccessor::ref().force_emit_object_deleted ( source().toString(), obj );
332 };
333
335 decltype ( this_remainder ) ::t_extractor > ( checkedref(), deletion );
336 toggle();
337 }
338 }
339 catch ( dunedaq::conffwk::Exception const & e )
340 {
341 throw daq::dbe::ObjectChangeWasNotSuccessful ( ERS_HERE, dbe::config::errors::parse ( e ) );
342 }
343 catch ( daq::dbe::config_object_retrieval_result_is_null const & ex )
344 {
345 FAIL ( "Operation did not complete because a lookup in the underlying database failed",
346 ex.what() );
347 throw daq::dbe::ObjectChangeWasNotSuccessful ( ERS_HERE, ex );
348 }
349
350}
351
352//------------------------------------------------------------------------------------------
353dbe::actions::object::rename::rename ( tref object, std::string const & Id,
354 QUuid const & src,
355 QUndoCommand * parent )
356 : onobject ( object, parent, src ),
357 oldname ( this->checkedref().UID() ),
358 newname ( Id )
359{
360 setText (
361 QObject::tr ( "Object changed ID from %1 to %2" ).arg ( this->checkedref().UID().c_str() )
362 .arg ( newname.c_str() ) );
363}
364//------------------------------------------------------------------------------------------
365
366//------------------------------------------------------------------------------------------
368{
369 try
370 {
371 if ( redoable() )
372 {
373 failed();
374 dref object_before_change ( checkedref() );
376
377 confaccessor::ref().force_emit_object_renamed ( source().toString(), object_before_change );
378
379 std::vector<tref> tonotify
380 { this->checkedref().referenced_by ( "*", false ) };
381
382 std::for_each ( tonotify.begin(), tonotify.end(), [&] ( tref const & x )
383 {
384 confaccessor::ref().force_emit_object_changed ( source().toString(), x );
385 } );
386 toggle();
387 }
388 }
389 catch ( dunedaq::conffwk::Exception const & e )
390 {
391 throw daq::dbe::ObjectChangeWasNotSuccessful ( ERS_HERE, dbe::config::errors::parse ( e ) );
392 }
393 catch ( daq::dbe::config_object_retrieval_result_is_null const & e )
394 {
395 FAIL ( "Operation did not complete because a lookup in the underlying database failed",
396 e.what() );
397 throw daq::dbe::ObjectChangeWasNotSuccessful ( ERS_HERE, e );
398 }
399
400}
401//------------------------------------------------------------------------------------------
402
403//------------------------------------------------------------------------------------------
405{
406 try
407 {
408 if ( undoable() )
409 {
410 failed();
411 dref object_before_rename ( checkedref() );
413 confaccessor::ref().force_emit_object_renamed ( source().toString(), object_before_rename );
414
415 std::vector<tref> tonotify = checkedref().referenced_by ( "*", false );
416
417 std::for_each ( tonotify.begin(), tonotify.end(), [&] ( tref const & x )
418 {
419 confaccessor::ref().force_emit_object_changed ( source().toString(), x );
420 } );
421 toggle();
422 }
423 }
424 catch ( dunedaq::conffwk::Exception const & e )
425 {
426 throw daq::dbe::ObjectChangeWasNotSuccessful ( ERS_HERE, dbe::config::errors::parse ( e ) );
427 }
428 catch ( daq::dbe::config_object_retrieval_result_is_null const & e )
429 {
430 FAIL ( "Operation did not complete because a lookup in the underlying database failed",
431 e.what() );
432 throw daq::dbe::ObjectChangeWasNotSuccessful ( ERS_HERE, e );
433 }
434
435}
436//------------------------------------------------------------------------------------------
437
438//------------------------------------------------------------------------------------------
439dbe::actions::object::move::move ( tref object, std::string const & filename,
440 QUuid const & src, QUndoCommand * parent )
441 : onobject ( object, parent, src ),
442 source_file ( this->checkedref().contained_in() ),
444{
445 setText (
446 QObject::tr ( "Object changed from file %1 to %2" ).arg ( source_file.c_str() ).arg (
447 destination_file.c_str() ) );
448}
449//------------------------------------------------------------------------------------------
450
451//------------------------------------------------------------------------------------------
455//------------------------------------------------------------------------------------------
456
457//------------------------------------------------------------------------------------------
459{
460 try
461 {
462 if ( redoable() )
463 {
464 failed();
466 emit confaccessor::ref().force_emit_object_changed ( source().toString(), this->checkedref() );
467 toggle();
468 }
469 }
470 catch ( dunedaq::conffwk::Exception const & e )
471 {
472 throw daq::dbe::ObjectChangeWasNotSuccessful ( ERS_HERE, dbe::config::errors::parse ( e ) );
473 }
474 catch ( daq::dbe::config_object_retrieval_result_is_null const & e )
475 {
476 FAIL ( "Operation did not complete because a lookup in the underlying database failed",
477 e.what() );
478 throw daq::dbe::ObjectChangeWasNotSuccessful ( ERS_HERE, e );
479 }
480}
481//------------------------------------------------------------------------------------------
482
483//------------------------------------------------------------------------------------------
485{
486 try
487 {
488 if ( undoable() )
489 {
490 failed();
492 toggle();
493 }
494 }
495 catch ( dunedaq::conffwk::Exception const & e )
496 {
497 throw daq::dbe::ObjectChangeWasNotSuccessful ( ERS_HERE, dbe::config::errors::parse ( e ) );
498 }
499 catch ( daq::dbe::config_object_retrieval_result_is_null const & e )
500 {
501 FAIL ( "Operation did not complete because a lookup in the underlying database failed",
502 e.what() );
503 throw daq::dbe::ObjectChangeWasNotSuccessful ( ERS_HERE, e );
504 }
505
506}
507//------------------------------------------------------------------------------------------
508
509//------------------------------------------------------------------------------------------
510dbe::actions::onobject::onobject ( tref obj, QUndoCommand * parent, QUuid const & uuid )
511 : dbe::actions::state ( parent, uuid ),
512 this_object ( obj )
513{
514}
515//------------------------------------------------------------------------------------------
516
517//------------------------------------------------------------------------------------------
519{
520 return this_object.ref();
521}
522//------------------------------------------------------------------------------------------
523
524//------------------------------------------------------------------------------------------
525dbe::actions::state::state ( QUndoCommand * parent, QUuid const & uuid )
526 : QUndoCommand ( parent ),
527 uuid ( uuid ),
528 rewind ( true ),
529 forward ( true ),
530 invalid ( false )
531{
532}
533
535{
536 invalid = not invalid;
537 rewind = not rewind;
538 forward = not forward;
539}
540
542{
543 invalid = true;
544 rewind = false;
545 forward = false;
546}
547
549{
550 return not invalid;
551}
552
554{
555 rewind = state;
556}
557
559{
560 forward = state;
561}
562
564{
565 return rewind and not invalid;
566}
567
569{
570 return forward and not invalid;
571}
572
573QUuid const & dbe::actions::state::source() const
574{
575 return uuid;
576}
577
579{
580 return redoable();
581}
582
584{
585 return undoable();
586}
587
589{
590 // TODO evaluate: is this command that reloads the configuration object from the database really needed?
591}
592
593//------------------------------------------------------------------------------------------
594
#define ERS_HERE
add(std::string const &db_file, std::string const &include_file, QUuid const &src=0, QUndoCommand *parent=0)
Definition Command.cpp:118
std::string m_include_file
Definition Command.hpp:184
remove(std::string &db_file, std::string &include_file, QUuid const &src=0, QUndoCommand *parent=0)
Definition Command.cpp:170
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:147
std::vector< tref > this_current_neighbors
Definition Command.hpp:146
dunedaq::conffwk::relationship_t this_relation
Definition Command.hpp:145
create(dbe::t_config_object_preimage const &img, QUuid const &src=0, QUndoCommand *parent=0)
Definition Command.cpp:218
dbe::t_config_object_preimage this_object_key
Definition Command.hpp:100
move(tref ObjectChanged, std::string const &File, QUuid const &src=0, QUndoCommand *parent=nullptr)
Definition Command.cpp:439
remove(tref item, QUuid const &uuid=0, QUndoCommand *parent=0)
Definition Command.cpp:278
rename(tref object, std::string const &Id, QUuid const &src=0, QUndoCommand *parent=nullptr)
Definition Command.cpp:353
tref checkedref() const
Definition Command.cpp:518
onobject(tref obj, QUndoCommand *parent=nullptr, QUuid const &uuid=0)
Definition Command.cpp:510
void setundoable(bool s=true) const
Definition Command.cpp:553
bool canRedo() const
Definition Command.cpp:578
void reload() const
Definition Command.cpp:588
bool undoable() const
Definition Command.cpp:563
bool canUndo() const
Definition Command.cpp:583
bool isvalid() const
Definition Command.cpp:548
void setredoable(bool s=true) const
Definition Command.cpp:558
void failed() const
Definition Command.cpp:541
bool redoable() const
Definition Command.cpp:568
state(QUndoCommand *parent=nullptr, QUuid const &uuid=0)
Definition Command.cpp:525
QUuid const & source() const
Definition Command.cpp:573
QUuid const uuid
Definition Command.hpp:37
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)
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:35
config_object_preimage< std::string > t_config_object_preimage
config_object_description dref