DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
dbe
include
dbe
change_enum.hpp
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: yes (from dbe/change_enum.hpp to include/dbe/change_enum.hpp).
5
6
/*
7
* change_enum.hpp
8
*
9
* Created on: Nov 10, 2015
10
* Author: lgeorgop
11
*/
12
13
#ifndef DBE_CHANGE_ENUM_HPP_
14
#define DBE_CHANGE_ENUM_HPP_
15
16
#include "
dbe/Command.hpp
"
17
#include "
dbe/Exceptions.hpp
"
18
#include "
dbe/confaccessor.hpp
"
19
#include "
dbe/config_api_get.hpp
"
20
#include "
dbe/config_api_set.hpp
"
21
#include "
dbe/messenger.hpp
"
22
23
#include "
conffwk/ConfigObject.hpp
"
24
#include "
conffwk/Errors.hpp
"
25
#include "
conffwk/Schema.hpp
"
26
27
#include <QtCore/qobject.h>
28
#include <QtCore/qstring.h>
29
#include <QtCore/qstringlist.h>
30
31
#include <string>
32
33
namespace
dbe
{
34
namespace
actions
{
35
//------------------------------------------------------------------------------------------
36
template
<
typename
T>
37
class
ChangeEnum
:
public
onobject
38
{
39
public
:
40
ChangeEnum
(
tref
Object,
dunedaq::conffwk::attribute_t
AttributeData, T NewValueData, QUndoCommand* parent =
nullptr
);
41
void
undo
();
42
void
redo
();
43
44
private
:
45
T
OldValue
;
46
T
NewValue
;
47
dunedaq::conffwk::attribute_t
Attribute
;
48
bool
Success
;
49
};
50
51
template
<
typename
T>
52
ChangeEnum<T>::ChangeEnum
(
tref
Object,
53
dunedaq::conffwk::attribute_t
AttributeData,
54
T NewValueData,
55
QUndoCommand* parent)
56
:
onobject
(Object, parent)
57
,
NewValue
(NewValueData)
58
,
Attribute
(AttributeData)
59
,
Success
(true)
60
{
61
try
{
62
QStringList Data{
dbe::config::api::get::attribute::list<QStringList>
(Object,
Attribute
) };
63
OldValue
=
convert::to<T>
(Data);
64
}
catch
(dunedaq::conffwk::Exception
const
& e) {
65
Q_UNUSED(e)
66
}
67
68
setText(
69
QObject::tr(
"Attribute %1 of object %2 was updated."
).arg(AttributeData.
p_name
.c_str()).arg(Object.
UID
().c_str()));
70
}
71
72
template
<
typename
T>
73
void
74
ChangeEnum<T>::undo
()
75
{
76
try
{
77
if
(
isvalid
()) {
78
failed
();
79
dbe::config::api::set::noactions::anenum
(this->
checkedref
(),
Attribute
,
OldValue
);
80
toggle
();
81
}
82
}
catch
(dunedaq::conffwk::Exception
const
& e) {
83
Success
=
false
;
84
throw
daq::dbe::ObjectChangeWasNotSuccessful(
ERS_HERE
, 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
template
<
typename
T>
92
void
93
ChangeEnum<T>::redo
()
94
{
95
try
{
96
if
(
isvalid
()) {
97
failed
();
98
99
QStringList Data{
dbe::config::api::get::attribute::list<QStringList>
(this->
checkedref
(),
Attribute
) };
100
101
OldValue
=
convert::to<T>
(Data,
Attribute
.p_int_format);
102
103
dbe::config::api::set::noactions::anenum
(this->
checkedref
(),
Attribute
,
NewValue
);
104
105
toggle
();
106
}
107
}
catch
(dunedaq::conffwk::Exception
const
& e) {
108
Success
=
false
;
109
throw
daq::dbe::ObjectChangeWasNotSuccessful(
ERS_HERE
, e);
110
}
catch
(daq::dbe::config_object_retrieval_result_is_null
const
& ex) {
111
FAIL
(
"Operation did not complete because a lookup in the underlying database failed"
, ex.what());
112
throw
daq::dbe::ObjectChangeWasNotSuccessful(
ERS_HERE
, ex);
113
}
114
}
115
//------------------------------------------------------------------------------------------
116
}
117
}
// namespace dbe
118
#endif
/* DBE_CHANGE_ENUM_HPP_ */
Command.hpp
ConfigObject.hpp
Errors.hpp
Exceptions.hpp
ERS_HERE
#define ERS_HERE
Definition
LocalContext.hpp:127
dbe::actions::ChangeEnum::undo
void undo()
Definition
change_enum.hpp:74
dbe::actions::ChangeEnum::OldValue
T OldValue
Definition
change_enum.hpp:45
dbe::actions::ChangeEnum::redo
void redo()
Definition
change_enum.hpp:93
dbe::actions::ChangeEnum::NewValue
T NewValue
Definition
change_enum.hpp:46
dbe::actions::ChangeEnum::Success
bool Success
Definition
change_enum.hpp:48
dbe::actions::ChangeEnum::Attribute
dunedaq::conffwk::attribute_t Attribute
Definition
change_enum.hpp:47
dbe::actions::ChangeEnum::ChangeEnum
ChangeEnum(tref Object, dunedaq::conffwk::attribute_t AttributeData, T NewValueData, QUndoCommand *parent=nullptr)
Definition
change_enum.hpp:52
dbe::actions::onobject::checkedref
tref checkedref() const
Definition
Command.cpp:412
dbe::actions::onobject::onobject
onobject(tref obj, QUndoCommand *parent=nullptr, QUuid const &uuid=0)
Definition
Command.cpp:403
dbe::actions::state::toggle
void toggle()
Definition
Command.cpp:429
dbe::actions::state::isvalid
bool isvalid() const
Definition
Command.cpp:445
dbe::actions::state::failed
void failed() const
Definition
Command.cpp:437
dbe::config::api::get::attribute::list
static T list(dbe::inner::configobject::tref obj, dunedaq::conffwk::attribute_t const &attr)
Definition
config_api_get.cpp:160
dbe::inner::configobject::ref_interface::UID
std::string UID() const
Definition
config_reference.hpp:178
confaccessor.hpp
Schema.hpp
config_api_get.hpp
config_api_set.hpp
messenger.hpp
FAIL
#define FAIL(...)
Definition
messenger.hpp:129
dbe::actions
Definition
change_attribute.hpp:35
dbe::config::api::set::noactions::anenum
void anenum(inner::configobject::tref Object, dunedaq::conffwk::attribute_t const &AttributeData, T NewValueData, bool NotEmit=false)
Definition
config_api.hpp:150
dbe::convert::to
T to(QStringList const &DataList)
Definition
Conversion.hpp:114
dbe
Include QT Headers.
Definition
BatchChangeWidget.hpp:16
dbe::tref
inner::configobject::tref tref
Definition
tref.hpp:36
dunedaq::conffwk::attribute_t
Definition
Schema.hpp:60
dunedaq::conffwk::attribute_t::p_name
std::string p_name
Definition
Schema.hpp:62
Generated on
for DUNE-DAQ by
1.18.0